Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-25 15:50:19 +01:00
Small cleanup in TransitionSessionHandler
Dieser Commit ist enthalten in:
Ursprung
4fb7e02326
Commit
7944544606
@ -10,6 +10,7 @@ import com.velocitypowered.proxy.connection.ConnectionTypes;
|
|||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler;
|
import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
|
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
|
||||||
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
|
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
|
||||||
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
|
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
|
||||||
@ -69,19 +70,21 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
|||||||
MinecraftConnection smc = serverConn.ensureConnected();
|
MinecraftConnection smc = serverConn.ensureConnected();
|
||||||
VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer();
|
VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer();
|
||||||
|
|
||||||
|
final ConnectedPlayer player = serverConn.getPlayer();
|
||||||
|
|
||||||
if (existingConnection != null) {
|
if (existingConnection != null) {
|
||||||
// Shut down the existing server connection.
|
// Shut down the existing server connection.
|
||||||
serverConn.getPlayer().setConnectedServer(null);
|
player.setConnectedServer(null);
|
||||||
existingConnection.disconnect();
|
existingConnection.disconnect();
|
||||||
|
|
||||||
// Send keep alive to try to avoid timeouts
|
// Send keep alive to try to avoid timeouts
|
||||||
serverConn.getPlayer().sendKeepAlive();
|
player.sendKeepAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The goods are in hand! We got JoinGame. Let's transition completely to the new state.
|
// The goods are in hand! We got JoinGame. Let's transition completely to the new state.
|
||||||
smc.setAutoReading(false);
|
smc.setAutoReading(false);
|
||||||
server.getEventManager()
|
server.getEventManager()
|
||||||
.fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer(),
|
.fire(new ServerConnectedEvent(player, serverConn.getServer(),
|
||||||
existingConnection != null ? existingConnection.getServer() : null))
|
existingConnection != null ? existingConnection.getServer() : null))
|
||||||
.whenCompleteAsync((x, error) -> {
|
.whenCompleteAsync((x, error) -> {
|
||||||
// Make sure we can still transition (player might have disconnected here).
|
// Make sure we can still transition (player might have disconnected here).
|
||||||
@ -93,17 +96,15 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
// Change the client to use the ClientPlaySessionHandler if required.
|
// Change the client to use the ClientPlaySessionHandler if required.
|
||||||
ClientPlaySessionHandler playHandler;
|
ClientPlaySessionHandler playHandler;
|
||||||
if (serverConn.getPlayer().getConnection().getSessionHandler()
|
if (player.getConnection().getSessionHandler() instanceof ClientPlaySessionHandler) {
|
||||||
instanceof ClientPlaySessionHandler) {
|
playHandler = (ClientPlaySessionHandler) player.getConnection().getSessionHandler();
|
||||||
playHandler = (ClientPlaySessionHandler) serverConn.getPlayer().getConnection()
|
|
||||||
.getSessionHandler();
|
|
||||||
} else {
|
} else {
|
||||||
playHandler = new ClientPlaySessionHandler(server, serverConn.getPlayer());
|
playHandler = new ClientPlaySessionHandler(server, player);
|
||||||
serverConn.getPlayer().getConnection().setSessionHandler(playHandler);
|
player.getConnection().setSessionHandler(playHandler);
|
||||||
}
|
}
|
||||||
playHandler.handleBackendJoinGame(packet, serverConn);
|
playHandler.handleBackendJoinGame(packet, serverConn);
|
||||||
|
|
||||||
// Strap on the correct session handler for the server. We will have nothing more to do
|
// Set the new play session handler for the server. We will have nothing more to do
|
||||||
// with this connection once this task finishes up.
|
// with this connection once this task finishes up.
|
||||||
smc.setSessionHandler(new BackendPlaySessionHandler(server, serverConn));
|
smc.setSessionHandler(new BackendPlaySessionHandler(server, serverConn));
|
||||||
|
|
||||||
@ -114,15 +115,15 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
|||||||
serverConn.getPlayer().setConnectedServer(serverConn);
|
serverConn.getPlayer().setConnectedServer(serverConn);
|
||||||
|
|
||||||
// We're done! :)
|
// We're done! :)
|
||||||
server.getEventManager().fireAndForget(new ServerPostConnectEvent(serverConn.getPlayer(),
|
server.getEventManager().fireAndForget(new ServerPostConnectEvent(player,
|
||||||
existingConnection == null ? null : existingConnection.getServer()));
|
existingConnection == null ? null : existingConnection.getServer()));
|
||||||
resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer()));
|
resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer()));
|
||||||
}, smc.eventLoop())
|
}, smc.eventLoop())
|
||||||
.exceptionally(exc -> {
|
.exceptionally(exc -> {
|
||||||
logger.error("Unable to switch to new server {} for {}",
|
logger.error("Unable to switch to new server {} for {}",
|
||||||
serverConn.getServerInfo().getName(),
|
serverConn.getServerInfo().getName(),
|
||||||
serverConn.getPlayer().getUsername(), exc);
|
player.getUsername(), exc);
|
||||||
serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
player.disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||||
resultFuture.completeExceptionally(exc);
|
resultFuture.completeExceptionally(exc);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren