mirror of
https://github.com/GeyserMC/GeyserConnect.git
synced 2025-06-26 14:15:22 +02:00
Add support for offline servers
This commit is contained in:
parent
1ecc9dcc6a
commit
166006594b
4 changed files with 63 additions and 3 deletions
|
@ -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
|
- [ ] Stop Geyser server after its idle for a while
|
||||||
- [x] Config file
|
- [x] Config file
|
||||||
- [x] Fix server images not loading straight away on Win10
|
- [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
|
- [x] Add option to add a bedrock server
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
package org.geysermc.connect.proxy;
|
package org.geysermc.connect.proxy;
|
||||||
|
|
||||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
|
import org.geysermc.common.AuthType;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connect.MasterServer;
|
import org.geysermc.connect.MasterServer;
|
||||||
|
@ -52,6 +53,9 @@ public class GeyserProxySession extends GeyserSession {
|
||||||
// Set the remote server info for the player
|
// Set the remote server info for the player
|
||||||
connector.getRemoteServer().setAddress(player.getCurrentServer().getAddress());
|
connector.getRemoteServer().setAddress(player.getCurrentServer().getAddress());
|
||||||
connector.getRemoteServer().setPort(player.getCurrentServer().getPort());
|
connector.getRemoteServer().setPort(player.getCurrentServer().getPort());
|
||||||
|
|
||||||
|
connector.setAuthType(player.getCurrentServer().isOnline() ? AuthType.ONLINE : AuthType.OFFLINE);
|
||||||
|
|
||||||
super.authenticate(username, password);
|
super.authenticate(username, password);
|
||||||
}else{
|
}else{
|
||||||
// Disconnect the player if they haven't picked a server on the master server list
|
// 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
|
@Override
|
||||||
public void setAuthenticationData(AuthData authData) {
|
public void setAuthenticationData(AuthData authData) {
|
||||||
super.setAuthenticationData(authData);
|
super.setAuthenticationData(authData);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,6 @@ package org.geysermc.connect.proxy;
|
||||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.network.ConnectorServerEventHandler;
|
import org.geysermc.connector.network.ConnectorServerEventHandler;
|
||||||
import org.geysermc.connector.network.UpstreamPacketHandler;
|
|
||||||
import org.geysermc.connect.MasterServer;
|
import org.geysermc.connect.MasterServer;
|
||||||
import org.geysermc.connect.utils.Player;
|
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?
|
// This doesn't clean up the old packet handler, so may cause a memory leak?
|
||||||
GeyserProxySession session = new GeyserProxySession(connector, bedrockServerSession);
|
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
|
// Add another disconnect handler to remove the player on final disconnect
|
||||||
bedrockServerSession.addDisconnectHandler(disconnectReason -> {
|
bedrockServerSession.addDisconnectHandler(disconnectReason -> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue