Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-24 15:20:35 +01:00
Handle plugin channel registrations during initial connect as well.
Fixes #193
Dieser Commit ist enthalten in:
Ursprung
1661cece2d
Commit
632d0b6ba8
@ -50,7 +50,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
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 boolean spawned = false;
|
||||
@ -63,6 +63,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
public ClientPlaySessionHandler(VelocityServer server, ConnectedPlayer player) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
|
||||
if (player.getMinecraftConnection().getSessionHandler()
|
||||
instanceof InitialConnectSessionHandler) {
|
||||
this.knownChannels.addAll(((InitialConnectSessionHandler) player.getMinecraftConnection()
|
||||
.getSessionHandler()).getKnownChannels());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,22 +1,56 @@
|
||||
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.backend.VelocityServerConnection;
|
||||
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 {
|
||||
|
||||
private final ConnectedPlayer player;
|
||||
private final Set<String> knownChannels;
|
||||
|
||||
InitialConnectSessionHandler(ConnectedPlayer player) {
|
||||
this.player = player;
|
||||
this.knownChannels = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(PluginMessage packet) {
|
||||
VelocityServerConnection serverConn = player.getConnectionInFlight();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -28,4 +62,8 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler {
|
||||
// the user cancelled the login process
|
||||
player.teardown();
|
||||
}
|
||||
|
||||
Set<String> getKnownChannels() {
|
||||
return knownChannels;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren