forked from mirrors/0ad
Always use STUN for hosting games using the lobby
This makes using STUN mandatory for games hosted using the multiplayer lobby. The motivation for that is a reduction in complexity, because right now if STUN is disabled we use a home-grown STUN-like logic, which got implemented before Pyrogenesis got STUN support. That home-grown logic relies on a custom ejabberd module (mod_ipstamp), which inserts the external IP-address of a host in the response messages when a host registers a game. Originally mod_ipstamp was also used to inform all potential players of a hosts IP-address, however that has already been removed to let hosts to only share their IP-address with players actually joining their game. Removing the home-grown logic and instead always relying on STUN removes complexity in Pyrogenesis and the lobby server and also eases hosting games for players, as they don't have to figure out anymore whether they need to enable STUN or not. These changes shouldn't negatively impact the ability of Pyrogenesis to handle different types of NAT or broken networks. There is one difference though: While the custom logic using mod_ipstamp utilized TCP as transport protocol, the STUN implementation in Pyrogenesis currently uses UDP. That doesn't allow hosts with UDP-connectivity issues to resolve their external IP-address anymore, however without UDP-connectivity they aren't able to successfully host games anyway, as the actual game updates are transferred using UDP as well.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -65,7 +65,7 @@ bool HasNetClient()
|
||||
return !!g_NetClient;
|
||||
}
|
||||
|
||||
void StartNetworkHost(const ScriptRequest& rq, const CStrW& playerName, const u16 serverPort, bool useSTUN,
|
||||
void StartNetworkHost(const ScriptRequest& rq, const CStrW& playerName, const u16 serverPort,
|
||||
const CStr& password, const bool continueSavedGame, bool storeReplay)
|
||||
{
|
||||
ENSURE(!g_NetClient);
|
||||
@@ -84,20 +84,12 @@ void StartNetworkHost(const ScriptRequest& rq, const CStrW& playerName, const u1
|
||||
}
|
||||
|
||||
// In lobby, we send our public ip and port on request to the players who want to connect.
|
||||
// Thus we need to know our public IP. Use STUN if that's available,
|
||||
// otherwise, the lobby's reponse to the game registration stanza will tell us our public IP.
|
||||
if (hasLobby)
|
||||
// Thus we need to know our public IP and use STUN to get it.
|
||||
if (hasLobby && !g_NetServer->SetConnectionData())
|
||||
{
|
||||
if (!useSTUN)
|
||||
// Don't store IP - the lobby bot will send it later.
|
||||
// (if a client tries to connect before it's setup, they'll be disconnected)
|
||||
g_NetServer->SetConnectionData("", serverPort);
|
||||
else if (!g_NetServer->SetConnectionDataViaSTUN())
|
||||
{
|
||||
ScriptException::Raise(rq, "Failed to host via STUN.");
|
||||
SAFE_DELETE(g_NetServer);
|
||||
return;
|
||||
}
|
||||
ScriptException::Raise(rq, "Failed to resolve public IP-address.");
|
||||
SAFE_DELETE(g_NetServer);
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate a secret to identify the host client.
|
||||
@@ -134,7 +126,7 @@ void StartNetworkHost(const ScriptRequest& rq, const CStrW& playerName, const u1
|
||||
g_NetClient->SetGamePassword(hashedPass);
|
||||
}
|
||||
|
||||
g_NetClient->SetupServerData("127.0.0.1", serverPort, false);
|
||||
g_NetClient->SetupServerData("127.0.0.1", serverPort);
|
||||
g_NetClient->SetControllerSecret(secret);
|
||||
|
||||
if (!g_NetClient->SetupConnection(nullptr))
|
||||
@@ -154,7 +146,7 @@ void StartNetworkJoin(const ScriptRequest& rq, const CStrW& playerName, const CS
|
||||
g_Game = new CGame(storeReplay);
|
||||
g_NetClient = new CNetClient(g_Game);
|
||||
g_NetClient->SetUserName(playerName);
|
||||
g_NetClient->SetupServerData(serverAddress, serverPort, false);
|
||||
g_NetClient->SetupServerData(serverAddress, serverPort);
|
||||
|
||||
if (!g_NetClient->SetupConnection(nullptr))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user