13
0
geforkt von Mirrors/Velocity

Ensure empty (un)register packets are never sent.

Bukkit 1.13+, in particular, doesn't seem to like it very much. This was
also a bug in ViaVersion.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-05-17 18:16:28 -04:00
Ursprung 40b2c9993b
Commit 5524f3b720
2 geänderte Dateien mit 13 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,7 @@
package com.velocitypowered.proxy.connection.client;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.constructChannelsPacket;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent;
@ -72,11 +73,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
public void activated() {
Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player
.getProtocolVersion());
PluginMessage register = PluginMessageUtil.constructChannelsPacket(player.getProtocolVersion(),
channels);
if (!channels.isEmpty()) {
PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels);
player.getMinecraftConnection().write(register);
player.getKnownChannels().addAll(channels);
}
}
@Override
public boolean handle(KeepAlive packet) {
@ -366,8 +368,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Tell the server about this client's plugin message channels.
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
if (!player.getKnownChannels().isEmpty()) {
serverMc.delayedWrite(PluginMessageUtil.constructChannelsPacket(serverVersion,
player.getKnownChannels()));
serverMc.delayedWrite(constructChannelsPacket(serverVersion, player.getKnownChannels()));
}
// If we had plugin messages queued during login/FML handshake, send them now.

Datei anzeigen

@ -93,6 +93,11 @@ public class PluginMessageUtil {
checkNotNull(message, "message");
checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s",
message.getChannel());
if (message.getData().length == 0) {
// If we try to split this, we will get an one-element array with the empty string, which
// has caused issues with 1.13+ compatibility. Just return an empty list.
return ImmutableList.of();
}
String channels = new String(message.getData(), StandardCharsets.UTF_8);
return ImmutableList.copyOf(channels.split("\0"));
}
@ -103,10 +108,10 @@ public class PluginMessageUtil {
* @param channels the channels to register
* @return the plugin message to send
*/
public static PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion,
Collection<String> channels) {
Preconditions.checkNotNull(channels, "channels");
Preconditions.checkArgument(channels.size() > 0, "no channels specified");
String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0
? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
PluginMessage message = new PluginMessage();