diff --git a/README.md b/README.md index 93e4b26..d795c75 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,5 @@ GeyserConnect is a server that Minecraft: Bedrock Edition clients can connect to - [ ] Stop Geyser server after its idle for a while - [x] Config file - [x] Fix server images not loading straight away on Win10 -- [ ] Per server online/offline mode (50%) +- [x] Per server online/offline mode - [x] Add option to add a bedrock server diff --git a/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java b/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java index b819c9d..2b233f2 100644 --- a/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java +++ b/src/main/java/org/geysermc/connect/proxy/GeyserProxySession.java @@ -27,6 +27,7 @@ package org.geysermc.connect.proxy; import com.nukkitx.protocol.bedrock.BedrockServerSession; +import org.geysermc.common.AuthType; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connect.MasterServer; @@ -52,6 +53,9 @@ public class GeyserProxySession extends GeyserSession { // 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 @@ -59,6 +63,14 @@ public class GeyserProxySession extends GeyserSession { } } + @Override + public void login() { + Player player = MasterServer.getInstance().getPlayers().get(getAuthData().getXboxUUID()); + connector.setAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); + + super.login(); + } + @Override public void setAuthenticationData(AuthData authData) { super.setAuthenticationData(authData); diff --git a/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java b/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java new file mode 100644 index 0000000..89cef9c --- /dev/null +++ b/src/main/java/org/geysermc/connect/proxy/GeyserProxyUpstreamPacketHandler.java @@ -0,0 +1,49 @@ +/* + * 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.connect.proxy; + +import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; +import org.geysermc.common.AuthType; +import org.geysermc.connect.MasterServer; +import org.geysermc.connect.utils.Player; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.UpstreamPacketHandler; +import org.geysermc.connector.network.session.GeyserSession; + +public class GeyserProxyUpstreamPacketHandler extends UpstreamPacketHandler { + public GeyserProxyUpstreamPacketHandler(GeyserConnector connector, GeyserSession session) { + super(connector, session); + } + + @Override + public boolean handle(SetLocalPlayerAsInitializedPacket packet) { + Player player = MasterServer.getInstance().getPlayers().get(session.getAuthData().getXboxUUID()); + connector.setAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE); + + return super.handle(packet); + } +} diff --git a/src/main/java/org/geysermc/connect/proxy/ProxyConnectorServerEventHandler.java b/src/main/java/org/geysermc/connect/proxy/ProxyConnectorServerEventHandler.java index ccabf7b..ba19dee 100644 --- a/src/main/java/org/geysermc/connect/proxy/ProxyConnectorServerEventHandler.java +++ b/src/main/java/org/geysermc/connect/proxy/ProxyConnectorServerEventHandler.java @@ -29,7 +29,6 @@ package org.geysermc.connect.proxy; import com.nukkitx.protocol.bedrock.BedrockServerSession; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.ConnectorServerEventHandler; -import org.geysermc.connector.network.UpstreamPacketHandler; import org.geysermc.connect.MasterServer; import org.geysermc.connect.utils.Player; @@ -49,7 +48,7 @@ public class ProxyConnectorServerEventHandler extends ConnectorServerEventHandle // This doesn't clean up the old packet handler, so may cause a memory leak? GeyserProxySession session = new GeyserProxySession(connector, bedrockServerSession); - bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, session)); + bedrockServerSession.setPacketHandler(new GeyserProxyUpstreamPacketHandler(connector, session)); // Add another disconnect handler to remove the player on final disconnect bedrockServerSession.addDisconnectHandler(disconnectReason -> {