From 03270131e5f837b99c39ec9d1a24d9593ec781da Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 17 Mar 2021 11:17:13 -0400 Subject: [PATCH] Prevent race conditions and clean up server forwarding --- .../connect/proxy/GeyserProxySession.java | 40 +----------------- .../GeyserProxyUpstreamPacketHandler.java | 5 ++- .../network/remote/RemoteServer.java | 42 ------------------- 3 files changed, 6 insertions(+), 81 deletions(-) delete mode 100644 src/main/java/org/geysermc/connector/network/remote/RemoteServer.java diff --git a/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java b/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java index 9ef3163..f6909bb 100644 --- a/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java +++ b/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java @@ -36,14 +36,12 @@ import org.geysermc.connector.network.session.auth.AuthData; public class GeyserProxySession extends GeyserSession { - private final GeyserConnector connector; private final BedrockServerSession bedrockServerSession; @Getter private Player player; public GeyserProxySession(GeyserConnector connector, BedrockServerSession bedrockServerSession) { super(connector, bedrockServerSession); - this.connector = connector; this.bedrockServerSession = bedrockServerSession; } @@ -60,41 +58,7 @@ public class GeyserProxySession extends GeyserSession { } @Override - public void authenticate(String username, String password) { - if (player != null && player.getCurrentServer() != null) { - // Set the remote server info for the player - connector.getRemoteServer().setAddress(player.getCurrentServer().getAddress()); - connector.getRemoteServer().setPort(player.getCurrentServer().getPort()); - - connector.setAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); - - super.authenticate(username, password); - } else { - // Disconnect the player if they haven't picked a server on the master server list - bedrockServerSession.disconnect("Please connect to the master server and pick a server first!"); - } - } - - @Override - public void authenticateWithMicrosoftCode() { - if (player != null && player.getCurrentServer() != null) { - // Set the remote server info for the player - connector.getRemoteServer().setAddress(player.getCurrentServer().getAddress()); - connector.getRemoteServer().setPort(player.getCurrentServer().getPort()); - - connector.setAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); - - super.authenticateWithMicrosoftCode(); - } else { - // Disconnect the player if they haven't picked a server on the master server list - bedrockServerSession.disconnect("Please connect to the master server and pick a server first!"); - } - } - - @Override - public void login() { - connector.setAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); - - super.login(); + protected void disableSrvResolving() { + // Do nothing } } diff --git a/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java b/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java index 4f74d58..3396f0a 100644 --- a/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java +++ b/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java @@ -40,7 +40,10 @@ public class GeyserProxyUpstreamPacketHandler extends UpstreamPacketHandler { @Override public boolean handle(SetLocalPlayerAsInitializedPacket packet) { - connector.setAuthType(((GeyserProxySession) session).getPlayer().getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); + Player player = ((GeyserProxySession) session).getPlayer(); + session.setRemoteAddress(player.getCurrentServer().getAddress()); + session.setRemotePort(player.getCurrentServer().getPort()); + session.setRemoteAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); return super.handle(packet); } diff --git a/src/main/java/org/geysermc/connector/network/remote/RemoteServer.java b/src/main/java/org/geysermc/connector/network/remote/RemoteServer.java deleted file mode 100644 index 7cfcf8f..0000000 --- a/src/main/java/org/geysermc/connector/network/remote/RemoteServer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/GeyserConnect - */ - -package org.geysermc.connector.network.remote; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -/** - * This is super hacky but I guess it works - */ -@Getter -@Setter -@AllArgsConstructor -public class RemoteServer { - - private String address; - private int port; -} \ No newline at end of file