Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 13:30:17 +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
|
@Override
|
||||||
public void disconnected() {
|
public void disconnected() {
|
||||||
player.teardown();
|
player.teardown();
|
||||||
server.getEventManager().fireAndForget(new DisconnectEvent(player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.connection.client;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonObject;
|
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.KickedFromServerEvent;
|
||||||
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||||
@ -410,6 +411,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
connectedServer.disconnect();
|
connectedServer.disconnect();
|
||||||
}
|
}
|
||||||
server.unregisterConnection(this);
|
server.unregisterConnection(this);
|
||||||
|
server.getEventManager().fireAndForget(new DisconnectEvent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,6 +50,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
private ServerLogin login;
|
private ServerLogin login;
|
||||||
private byte[] verify;
|
private byte[] verify;
|
||||||
private int playerInfoId;
|
private int playerInfoId;
|
||||||
|
private ConnectedPlayer connectedPlayer;
|
||||||
|
|
||||||
public LoginSessionHandler(VelocityServer server, MinecraftConnection inbound, InboundConnection apiInbound) {
|
public LoginSessionHandler(VelocityServer server, MinecraftConnection inbound, InboundConnection apiInbound) {
|
||||||
this.server = Preconditions.checkNotNull(server, "server");
|
this.server = Preconditions.checkNotNull(server, "server");
|
||||||
@ -196,6 +197,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
// Initiate a regular connection and move over to it.
|
// Initiate a regular connection and move over to it.
|
||||||
ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), inbound,
|
ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), inbound,
|
||||||
apiInbound.getVirtualHost().orElse(null));
|
apiInbound.getVirtualHost().orElse(null));
|
||||||
|
this.connectedPlayer = player;
|
||||||
|
|
||||||
return server.getEventManager().fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
|
return server.getEventManager().fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
|
||||||
.thenCompose(event -> {
|
.thenCompose(event -> {
|
||||||
@ -212,7 +214,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
if (!event.getResult().isAllowed()) {
|
if (!event.getResult().isAllowed()) {
|
||||||
// The component is guaranteed to be provided if the connection was denied.
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +231,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
return;
|
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();
|
int threshold = server.getConfiguration().getCompressionThreshold();
|
||||||
if (threshold >= 0) {
|
if (threshold >= 0) {
|
||||||
inbound.write(new SetCompression(threshold));
|
inbound.write(new SetCompression(threshold));
|
||||||
@ -243,10 +250,6 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
inbound.setAssociation(player);
|
inbound.setAssociation(player);
|
||||||
inbound.setState(StateRegistry.PLAY);
|
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);
|
logger.info("{} has connected", player);
|
||||||
inbound.setSessionHandler(new InitialConnectSessionHandler(player));
|
inbound.setSessionHandler(new InitialConnectSessionHandler(player));
|
||||||
server.getEventManager().fire(new PostLoginEvent(player)).thenRun(() -> player.createConnectionRequest(toTry.get()).fireAndForget());
|
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) {
|
public void handleUnknown(ByteBuf buf) {
|
||||||
throw new IllegalStateException("Unknown data " + ByteBufUtil.hexDump(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