Register floodgate:transfer plugin channel (#2896)

* Register floodgate:transfer channel

* Don't warn on unknown channel
This commit is contained in:
Konicai 2022-03-19 20:56:34 -04:00 committed by GitHub
parent b81ad3f0db
commit 87d70be10d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 26 deletions

View file

@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.session.GeyserSession;
@ -48,8 +49,6 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import static org.geysermc.geyser.util.PluginMessageUtils.getSkinChannel;
public final class FloodgateSkinUploader {
private final ObjectMapper JACKSON = new ObjectMapper();
private final List<String> skinQueue = new ArrayList<>();
@ -126,7 +125,7 @@ public final class FloodgateSkinUploader {
byte[] bytes = (value + '\0' + signature)
.getBytes(StandardCharsets.UTF_8);
PluginMessageUtils.sendMessage(session, getSkinChannel(), bytes);
PluginMessageUtils.sendMessage(session, PluginMessageChannels.SKIN, bytes);
}
break;
case LOG_MESSAGE:

View file

@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCu
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCustomPayloadPacket;
import com.google.common.base.Charsets;
import com.nukkitx.protocol.bedrock.packet.TransferPacket;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.session.auth.AuthType;
@ -54,7 +55,7 @@ public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCus
String channel = packet.getChannel();
if (channel.equals("floodgate:form")) {
if (channel.equals(PluginMessageChannels.FORM)) {
byte[] data = packet.getData();
// receive: first byte is form type, second and third are the id, remaining is the form data
@ -81,7 +82,7 @@ public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCus
});
session.sendForm(form);
} else if (channel.equals("floodgate:transfer")) {
} else if (channel.equals(PluginMessageChannels.TRANSFER)) {
byte[] data = packet.getData();
// port, 4 bytes. remaining data, address.

View file

@ -32,6 +32,7 @@ import com.nukkitx.protocol.bedrock.data.PlayerPermission;
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket;
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.auth.AuthType;
@ -102,7 +103,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
// register the plugin messaging channels used in Floodgate
if (session.getRemoteAuthType() == AuthType.FLOODGATE) {
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket("minecraft:register", PluginMessageUtils.getFloodgateRegisterData()));
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket("minecraft:register", PluginMessageChannels.getFloodgateRegisterData()));
}
if (!newDimension.equals(session.getDimension())) {

View file

@ -33,9 +33,7 @@ import org.geysermc.geyser.session.GeyserSession;
import java.nio.ByteBuffer;
public class PluginMessageUtils {
private static final String SKIN_CHANNEL = "floodgate:skin";
private static final byte[] GEYSER_BRAND_DATA;
private static final byte[] FLOODGATE_REGISTER_DATA;
static {
byte[] data = GeyserImpl.NAME.getBytes(Charsets.UTF_8);
@ -44,8 +42,6 @@ public class PluginMessageUtils {
.put(writeVarInt(data.length))
.put(data)
.array();
FLOODGATE_REGISTER_DATA = (SKIN_CHANNEL + "\0floodgate:form").getBytes(Charsets.UTF_8);
}
/**
@ -57,22 +53,6 @@ public class PluginMessageUtils {
return GEYSER_BRAND_DATA;
}
/**
* Get the prebuilt register data as a byte array
*
* @return the register data of the Floodgate channels
*/
public static byte[] getFloodgateRegisterData() {
return FLOODGATE_REGISTER_DATA;
}
/**
* Returns the skin channel used in Floodgate
*/
public static String getSkinChannel() {
return SKIN_CHANNEL;
}
public static void sendMessage(GeyserSession session, String channel, byte[] data) {
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket(channel, data));
}