Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
More reliably tear down connections and fire DisconnectEvent. Fixes #111
Dieser Commit ist enthalten in:
Ursprung
222e90a9f0
Commit
7578aa27a9
@ -202,7 +202,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public void disconnected() {
|
||||
player.teardown();
|
||||
server.getEventManager().fireAndForget(new DisconnectEvent(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.connection.client;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
@ -410,6 +411,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
connectedServer.disconnect();
|
||||
}
|
||||
server.unregisterConnection(this);
|
||||
server.getEventManager().fireAndForget(new DisconnectEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,6 +50,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
private ServerLogin login;
|
||||
private byte[] verify;
|
||||
private int playerInfoId;
|
||||
private ConnectedPlayer connectedPlayer;
|
||||
|
||||
public LoginSessionHandler(VelocityServer server, MinecraftConnection inbound, InboundConnection apiInbound) {
|
||||
this.server = Preconditions.checkNotNull(server, "server");
|
||||
@ -196,6 +197,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
// Initiate a regular connection and move over to it.
|
||||
ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), inbound,
|
||||
apiInbound.getVirtualHost().orElse(null));
|
||||
this.connectedPlayer = player;
|
||||
|
||||
return server.getEventManager().fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
|
||||
.thenCompose(event -> {
|
||||
@ -212,7 +214,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
if (!event.getResult().isAllowed()) {
|
||||
// The component is guaranteed to be provided if the connection was denied.
|
||||
inbound.closeWith(Disconnect.create(event.getResult().getReason().get()));
|
||||
player.disconnect(event.getResult().getReason().get());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -229,6 +231,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!server.registerConnection(player)) {
|
||||
inbound.closeWith(Disconnect.create(TextComponent.of("You are already on this proxy!", TextColor.RED)));
|
||||
return;
|
||||
}
|
||||
|
||||
int threshold = server.getConfiguration().getCompressionThreshold();
|
||||
if (threshold >= 0) {
|
||||
inbound.write(new SetCompression(threshold));
|
||||
@ -243,10 +250,6 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
inbound.setAssociation(player);
|
||||
inbound.setState(StateRegistry.PLAY);
|
||||
|
||||
if (!server.registerConnection(player)) {
|
||||
inbound.closeWith(Disconnect.create(TextComponent.of("You are already on this proxy!", TextColor.RED)));
|
||||
}
|
||||
|
||||
logger.info("{} has connected", player);
|
||||
inbound.setSessionHandler(new InitialConnectSessionHandler(player));
|
||||
server.getEventManager().fire(new PostLoginEvent(player)).thenRun(() -> player.createConnectionRequest(toTry.get()).fireAndForget());
|
||||
@ -256,4 +259,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
public void handleUnknown(ByteBuf buf) {
|
||||
throw new IllegalStateException("Unknown data " + ByteBufUtil.hexDump(buf));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
if (connectedPlayer != null) {
|
||||
connectedPlayer.teardown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren