13
0
geforkt von Mirrors/Velocity

Handle plugin channel registrations during initial connect as well.

Fixes #193
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-04-24 21:28:43 -04:00
Ursprung 1661cece2d
Commit 632d0b6ba8
2 geänderte Dateien mit 46 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -50,7 +50,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientPlaySessionHandler implements MinecraftSessionHandler { public class ClientPlaySessionHandler implements MinecraftSessionHandler {
private static final Logger logger = LogManager.getLogger(ClientPlaySessionHandler.class); private static final Logger logger = LogManager.getLogger(ClientPlaySessionHandler.class);
private static final int MAX_PLUGIN_CHANNELS = 1024; static final int MAX_PLUGIN_CHANNELS = 1024;
private final ConnectedPlayer player; private final ConnectedPlayer player;
private boolean spawned = false; private boolean spawned = false;
@ -63,6 +63,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
public ClientPlaySessionHandler(VelocityServer server, ConnectedPlayer player) { public ClientPlaySessionHandler(VelocityServer server, ConnectedPlayer player) {
this.player = player; this.player = player;
this.server = server; this.server = server;
if (player.getMinecraftConnection().getSessionHandler()
instanceof InitialConnectSessionHandler) {
this.knownChannels.addAll(((InitialConnectSessionHandler) player.getMinecraftConnection()
.getSessionHandler()).getKnownChannels());
}
} }
@Override @Override

Datei anzeigen

@ -1,22 +1,56 @@
package com.velocitypowered.proxy.connection.client; package com.velocitypowered.proxy.connection.client;
import static com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler.MAX_PLUGIN_CHANNELS;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class InitialConnectSessionHandler implements MinecraftSessionHandler { public class InitialConnectSessionHandler implements MinecraftSessionHandler {
private final ConnectedPlayer player; private final ConnectedPlayer player;
private final Set<String> knownChannels;
InitialConnectSessionHandler(ConnectedPlayer player) { InitialConnectSessionHandler(ConnectedPlayer player) {
this.player = player; this.player = player;
this.knownChannels = new HashSet<>();
} }
@Override @Override
public boolean handle(PluginMessage packet) { public boolean handle(PluginMessage packet) {
VelocityServerConnection serverConn = player.getConnectionInFlight(); VelocityServerConnection serverConn = player.getConnectionInFlight();
if (serverConn != null) { if (serverConn != null) {
if (!player.getPhase().handle(player, packet, serverConn)) { if (player.getPhase().handle(player, packet, serverConn)) {
return true;
}
if (PluginMessageUtil.isRegister(packet)) {
List<String> actuallyRegistered = new ArrayList<>();
List<String> channels = PluginMessageUtil.getChannels(packet);
for (String channel : channels) {
if (knownChannels.size() >= MAX_PLUGIN_CHANNELS && !knownChannels.contains(channel)) {
throw new IllegalStateException("Too many plugin message channels registered");
}
if (knownChannels.add(channel)) {
actuallyRegistered.add(channel);
}
}
if (!actuallyRegistered.isEmpty()) {
PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(serverConn
.ensureConnected().getProtocolVersion(), actuallyRegistered);
serverConn.ensureConnected().write(newRegisterPacket);
}
} else if (PluginMessageUtil.isUnregister(packet)) {
List<String> channels = PluginMessageUtil.getChannels(packet);
knownChannels.removeAll(channels);
serverConn.ensureConnected().write(packet);
} else {
serverConn.ensureConnected().write(packet); serverConn.ensureConnected().write(packet);
} }
} }
@ -28,4 +62,8 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler {
// the user cancelled the login process // the user cancelled the login process
player.teardown(); player.teardown();
} }
Set<String> getKnownChannels() {
return knownChannels;
}
} }