mirror of
https://github.com/GeyserMC/GeyserConnect.git
synced 2025-06-26 14:15:22 +02:00
Prevent race conditions and clean up server forwarding
This commit is contained in:
parent
61bcc6a75d
commit
03270131e5
3 changed files with 6 additions and 81 deletions
|
@ -36,14 +36,12 @@ import org.geysermc.connector.network.session.auth.AuthData;
|
||||||
|
|
||||||
public class GeyserProxySession extends GeyserSession {
|
public class GeyserProxySession extends GeyserSession {
|
||||||
|
|
||||||
private final GeyserConnector connector;
|
|
||||||
private final BedrockServerSession bedrockServerSession;
|
private final BedrockServerSession bedrockServerSession;
|
||||||
@Getter
|
@Getter
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
public GeyserProxySession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
|
public GeyserProxySession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
|
||||||
super(connector, bedrockServerSession);
|
super(connector, bedrockServerSession);
|
||||||
this.connector = connector;
|
|
||||||
this.bedrockServerSession = bedrockServerSession;
|
this.bedrockServerSession = bedrockServerSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,41 +58,7 @@ public class GeyserProxySession extends GeyserSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void authenticate(String username, String password) {
|
protected void disableSrvResolving() {
|
||||||
if (player != null && player.getCurrentServer() != null) {
|
// Do nothing
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,10 @@ public class GeyserProxyUpstreamPacketHandler extends UpstreamPacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
|
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);
|
return super.handle(packet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue