3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Merge remote-tracking branch 'origin/feature/floodgate-transfer-players'

Dieser Commit ist enthalten in:
Tim203 2021-09-24 20:38:03 +02:00
Commit e8ddac64b4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 064EE9F5BF7C3EE8

Datei anzeigen

@ -28,6 +28,9 @@ package org.geysermc.connector.network.translators.java;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
import com.google.common.base.Charsets;
import com.nukkitx.protocol.bedrock.packet.TransferPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.GeyserLogger;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -40,6 +43,8 @@ import java.nio.charset.StandardCharsets;
@Translator(packet = ServerPluginMessagePacket.class)
public class JavaPluginMessageTranslator extends PacketTranslator<ServerPluginMessagePacket> {
private final GeyserLogger logger = GeyserConnector.getInstance().getLogger();
@Override
public void translate(GeyserSession session, ServerPluginMessagePacket packet) {
// The only plugin messages it has to listen for are Floodgate plugin messages
@ -75,6 +80,27 @@ public class JavaPluginMessageTranslator extends PacketTranslator<ServerPluginMe
session.sendDownstreamPacket(new ClientPluginMessagePacket(channel, finalData));
});
session.sendForm(form);
} else if (channel.equals("floodgate:transfer")) {
byte[] data = packet.getData();
// port, 4 bytes. remaining data, address.
if (data.length < 5) {
throw new NullPointerException("Transfer data should be at least 5 bytes long");
}
int port = data[0] << 24 | (data[1] & 0xFF) << 16 | (data[2] & 0xFF) << 8 | data[3] & 0xFF;
String address = new String(data, 4, data.length - 4);
if (logger.isDebug()) {
logger.info("Transferring client to: " + address + ":" + port);
}
TransferPacket transferPacket = new TransferPacket();
transferPacket.setAddress(address);
transferPacket.setPort(port);
session.sendUpstreamPacket(transferPacket);
}
}
}