13
0
geforkt von Mirrors/Velocity

More reliably tear down connections and fire DisconnectEvent. Fixes #111

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-10-09 19:02:15 -04:00
Ursprung 222e90a9f0
Commit 7578aa27a9
3 geänderte Dateien mit 17 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -202,7 +202,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override
public void disconnected() {
player.teardown();
server.getEventManager().fireAndForget(new DisconnectEvent(player));
}
@Override

Datei anzeigen

@ -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

Datei anzeigen

@ -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();
}
}
}