Add dedicated steam server support (#12166)

* Add dedicated steam server support.

* Fixup

* Add cancel button
This commit is contained in:
buthed010203
2026-06-20 20:18:27 -04:00
committed by GitHub
parent 479b3854ba
commit 45e44fd8bc
2 changed files with 45 additions and 8 deletions
+1 -1
View File
@@ -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();
+44 -7
View File
@@ -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;
});
}
}