Implemented Floodgate's 'packet' plugin message

This commit is contained in:
Tim203 2021-12-16 00:19:51 +01:00
parent 90442a8922
commit a4399f0c1e
No known key found for this signature in database
GPG key ID: 064EE9F5BF7C3EE8
2 changed files with 31 additions and 12 deletions

View file

@ -25,19 +25,22 @@
package org.geysermc.geyser.translator.protocol.java;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCustomPayloadPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
import com.google.common.base.Charsets;
import com.nukkitx.protocol.bedrock.packet.TransferPacket;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import com.nukkitx.protocol.bedrock.packet.UnknownPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.geysermc.cumulus.Form;
import org.geysermc.cumulus.Forms;
import org.geysermc.cumulus.util.FormType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import java.nio.charset.StandardCharsets;
@ -62,8 +65,7 @@ public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCus
FormType type = FormType.getByOrdinal(data[0]);
if (type == null) {
throw new NullPointerException(
"Got type " + data[0] + " which isn't a valid form type!");
throw new NullPointerException("Got type " + data[0] + " which isn't a valid form type!");
}
String dataString = new String(data, 3, data.length - 3, Charsets.UTF_8);
@ -84,8 +86,7 @@ public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCus
} else if (channel.equals("floodgate:transfer")) {
byte[] data = packet.getData();
// port, 4 bytes. remaining data, address.
// port (4 bytes), address (remaining data)
if (data.length < 5) {
throw new NullPointerException("Transfer data should be at least 5 bytes long");
}
@ -101,6 +102,24 @@ public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCus
transferPacket.setAddress(address);
transferPacket.setPort(port);
session.sendUpstreamPacket(transferPacket);
} else if (channel.equals("floodgate:packet")) {
logger.debug("A packet has been sent using the Floodgate api");
byte[] data = packet.getData();
// packet id, packet data
if (data.length < 2) {
throw new IllegalStateException("Packet data should be at least 2 bytes long");
}
int packetId = data[0];
ByteBuf packetData = Unpooled.wrappedBuffer(data, 1, data.length - 1);
var toSend = new UnknownPacket();
toSend.setPacketId(packetId);
toSend.setPayload(packetData);
session.sendUpstreamPacket(toSend);
}
}
}

View file

@ -45,7 +45,7 @@ public class PluginMessageUtils {
.put(data)
.array();
FLOODGATE_REGISTER_DATA = (SKIN_CHANNEL + "\0floodgate:form").getBytes(Charsets.UTF_8);
FLOODGATE_REGISTER_DATA = (SKIN_CHANNEL + "\0floodgate:form\0floodgate:transfer\0floodgate:packet").getBytes(Charsets.UTF_8);
}
/**