13
0
geforkt von Mirrors/Velocity

Clean up some plugin message channel code

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-29 01:28:07 -04:00
Ursprung f569a07b2e
Commit f04599ae68
2 geänderte Dateien mit 9 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -44,13 +44,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void activated() { public void activated() {
PluginMessage message; PluginMessage register = PluginMessageUtil.constructChannelsPacket(player.getProtocolVersion(), server.getChannelRegistrar().getModernChannelIds());
if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) { player.getConnection().write(register);
message = PluginMessageUtil.constructChannelsPacket("minecraft:register", server.getChannelRegistrar().getModernChannelIds());
} else {
message = PluginMessageUtil.constructChannelsPacket("REGISTER", server.getChannelRegistrar().getIdsForLegacyConnections());
}
player.getConnection().write(message);
} }
@Override @Override
@ -213,10 +208,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
toRegister.addAll(server.getChannelRegistrar().getIdsForLegacyConnections()); toRegister.addAll(server.getChannelRegistrar().getIdsForLegacyConnections());
} }
if (!toRegister.isEmpty()) { if (!toRegister.isEmpty()) {
String channel = player.getConnection().getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13 ?
"minecraft:register" : "REGISTER";
player.getConnectedServer().getConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket( player.getConnectedServer().getConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket(
channel, toRegister)); player.getConnection().getProtocolVersion(), toRegister));
} }
// If we had plugin messages queued during login/FML handshake, send them now. // If we had plugin messages queued during login/FML handshake, send them now.
@ -267,7 +260,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
if (actuallyRegistered.size() > 0) { if (actuallyRegistered.size() > 0) {
PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(packet.getChannel(), actuallyRegistered); PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(player.getProtocolVersion(), actuallyRegistered);
player.getConnectedServer().getConnection().write(newRegisterPacket); player.getConnectedServer().getConnection().write(newRegisterPacket);
} }
} else if (PluginMessageUtil.isMCUnregister(packet)) { } else if (PluginMessageUtil.isMCUnregister(packet)) {

Datei anzeigen

@ -2,6 +2,7 @@ package com.velocitypowered.proxy.protocol.util;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -37,12 +38,11 @@ public enum PluginMessageUtil {
return ImmutableList.copyOf(channels.split("\0")); return ImmutableList.copyOf(channels.split("\0"));
} }
public static PluginMessage constructChannelsPacket(String channel, Collection<String> channels) { public static PluginMessage constructChannelsPacket(int protocolVersion, Collection<String> channels) {
Preconditions.checkNotNull(channel, "channel"); Preconditions.checkNotNull(channels, "channels");
Preconditions.checkNotNull(channel, "channels"); String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:register" : "REGISTER";
PluginMessage message = new PluginMessage(); PluginMessage message = new PluginMessage();
message.setChannel(channel); message.setChannel(channelName);
message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8)); message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8));
return message; return message;
} }