Skip to content

Commit

Permalink
Fix sessions still being held by Geyser when they are TransferPacket'…
Browse files Browse the repository at this point in the history
…ed to a bedrock server
  • Loading branch information
Konicai committed Aug 5, 2024
1 parent 2d6117a commit c35bd6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/geysermc/extension/connect/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public PacketHandler(GeyserConnect geyserConnect, GeyserSession session, Bedrock

@Override
public void onDisconnect(String reason) {
if (session.getAuthData() != null) {
geyserConnect.logger().info(Utils.displayName(session) + " has disconnected (" + reason + ")");
ServerManager.unloadServers(session);
}
// The user has disconnected without having connected to an actual server. If they have connected to
// a server (transfer packet or geyser proxy), then the original packet handler has been restored.
ServerManager.unloadServers(session);
originalPacketHandler.onDisconnect(reason);
}

@Override
Expand Down Expand Up @@ -155,12 +155,12 @@ public PacketSignal handle(NetworkStackLatencyPacket packet) {

@Override
public PacketSignal handle(ResourcePackClientResponsePacket packet) {
return originalPacketHandler.handle(packet);
return originalPacketHandler.handle(packet); // relies on state in the original handler
}

@Override
public PacketSignal handle(ResourcePackChunkRequestPacket packet) {
return originalPacketHandler.handle(packet);
return originalPacketHandler.handle(packet); // relies on state in the original handler
}
}

13 changes: 7 additions & 6 deletions src/main/java/org/geysermc/extension/connect/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,20 @@ public static void sendToServer(GeyserSession session, BedrockPacketHandler orig
GeyserConnect.instance().logger().info("Sending " + Utils.displayName(session) + " to " + server.title());
GeyserConnect.instance().logger().debug(server.toString());

// Save the player's servers since we are changing packet handlers
// (and they are going to disconnect if it is a bedrock server)
ServerManager.unloadServers(session);

// Restore the original packet handler
session.getUpstream().getSession().setPacketHandler(originalPacketHandler);

if (server.bedrock()) {
// Send them to the bedrock server
TransferPacket transferPacket = new TransferPacket();
transferPacket.setAddress(server.address());
transferPacket.setPort(server.port());
session.sendUpstreamPacket(transferPacket);
} else {
// Save the players servers since we are changing packet handlers
ServerManager.unloadServers(session);

// Restore the original packet handler
session.getUpstream().getSession().setPacketHandler(originalPacketHandler);

// Set the remote server and un-initialize the session
session.remoteServer(server);
session.getUpstream().setInitialized(false);
Expand Down

0 comments on commit c35bd6d

Please sign in to comment.