Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
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:
Ursprung
40b2c9993b
Commit
5524f3b720
@ -1,6 +1,7 @@
|
|||||||
package com.velocitypowered.proxy.connection.client;
|
package com.velocitypowered.proxy.connection.client;
|
||||||
|
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
|
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.connection.PluginMessageEvent;
|
||||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||||
@ -72,11 +73,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
public void activated() {
|
public void activated() {
|
||||||
Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player
|
Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player
|
||||||
.getProtocolVersion());
|
.getProtocolVersion());
|
||||||
PluginMessage register = PluginMessageUtil.constructChannelsPacket(player.getProtocolVersion(),
|
if (!channels.isEmpty()) {
|
||||||
channels);
|
PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels);
|
||||||
player.getMinecraftConnection().write(register);
|
player.getMinecraftConnection().write(register);
|
||||||
player.getKnownChannels().addAll(channels);
|
player.getKnownChannels().addAll(channels);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(KeepAlive packet) {
|
public boolean handle(KeepAlive packet) {
|
||||||
@ -366,8 +368,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
// Tell the server about this client's plugin message channels.
|
// Tell the server about this client's plugin message channels.
|
||||||
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
|
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
|
||||||
if (!player.getKnownChannels().isEmpty()) {
|
if (!player.getKnownChannels().isEmpty()) {
|
||||||
serverMc.delayedWrite(PluginMessageUtil.constructChannelsPacket(serverVersion,
|
serverMc.delayedWrite(constructChannelsPacket(serverVersion, player.getKnownChannels()));
|
||||||
player.getKnownChannels()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -93,6 +93,11 @@ public class PluginMessageUtil {
|
|||||||
checkNotNull(message, "message");
|
checkNotNull(message, "message");
|
||||||
checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s",
|
checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s",
|
||||||
message.getChannel());
|
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);
|
String channels = new String(message.getData(), StandardCharsets.UTF_8);
|
||||||
return ImmutableList.copyOf(channels.split("\0"));
|
return ImmutableList.copyOf(channels.split("\0"));
|
||||||
}
|
}
|
||||||
@ -103,10 +108,10 @@ public class PluginMessageUtil {
|
|||||||
* @param channels the channels to register
|
* @param channels the channels to register
|
||||||
* @return the plugin message to send
|
* @return the plugin message to send
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion,
|
public static PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion,
|
||||||
Collection<String> channels) {
|
Collection<String> channels) {
|
||||||
Preconditions.checkNotNull(channels, "channels");
|
Preconditions.checkNotNull(channels, "channels");
|
||||||
|
Preconditions.checkArgument(channels.size() > 0, "no channels specified");
|
||||||
String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0
|
String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0
|
||||||
? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
|
? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
|
||||||
PluginMessage message = new PluginMessage();
|
PluginMessage message = new PluginMessage();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren