diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index ba27671c81..7a72b558d7 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -373,7 +373,7 @@ public class NetClient implements ApplicationListener{ @Remote(called = Loc.client, variants = Variant.one) public static void connect(String ip, int port){ - if(!steam && ip.startsWith("steam:")) return; + if(!steam && (ip.startsWith("steam:") || ip.startsWith("steamserver:"))) return; netClient.disconnectQuietly(); logic.reset(); diff --git a/desktop/src/mindustry/desktop/steam/SNet.java b/desktop/src/mindustry/desktop/steam/SNet.java index ca40d5d58c..2086794469 100644 --- a/desktop/src/mindustry/desktop/steam/SNet.java +++ b/desktop/src/mindustry/desktop/steam/SNet.java @@ -133,6 +133,38 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback, }catch(NumberFormatException e){ throw new IOException("Invalid Steam ID: " + lobbyname); } + }else if (ip.startsWith("steamserver:")){ + String server = ip.substring("steamserver:".length()); + try{ + SteamID serverID = SteamID.createFromNativeHandle(Long.parseLong(server)); + if(!serverID.isValid()) throw new IOException("Invalid Steam ID structure: " + server); + + Core.app.post(() -> { + currentLobby = null; + currentServer = serverID; + + // Run success + if(success != null) success.run(); + + // Connect + Connect con = new Connect(); + con.addressTCP = "steam:" + currentServer.getAccountID(); + + net.setClientConnected(); + net.handleClientReceived(con); + Core.app.post(() -> { // TODO: This gets hidden and I can't figure out how to not do so. + ui.loadfrag.show("@connecting"); + ui.loadfrag.setButton(() -> { + ui.loadfrag.hide(); + netClient.disconnectQuietly(); + }); + }); + + Log.info("Initiated direct Steam P2P connection to server: @", currentServer.getAccountID()); + }); + }catch(NumberFormatException e){ + throw new IOException("Failed to parse server Steam ID: " + server); + } }else{ provider.connectClient(ip, port, success); } @@ -165,13 +197,11 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback, @Override public void disconnectClient(){ if(isSteamClient()){ - if(currentLobby != null){ - smat.leaveLobby(currentLobby); - snet.closeP2PSessionWithUser(currentServer); - currentServer = null; - currentLobby = null; - net.handleClientReceived(new Disconnect()); - } + if(currentLobby != null) smat.leaveLobby(currentLobby); + snet.closeP2PSessionWithUser(currentServer); + currentServer = null; + currentLobby = null; + net.handleClientReceived(new Disconnect()); }else{ provider.disconnectClient(); } @@ -411,6 +441,13 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback, }else if(steamIDRemote.equals(currentServer)){ Log.info("Disconnected! @: @", steamIDRemote.getAccountID(), sessionError); net.handleClientReceived(new Disconnect()); + + Core.app.post(() -> { + ui.loadfrag.hide(); + ui.showErrorMessage(Core.bundle.format("cantconnect", sessionError.name())); + net.handleClientReceived(new Disconnect()); + currentServer = null; + }); } }