mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-27 15:31:40 +00:00
StunClient code cleanup: use enet functions, endianness
Instead of using platform-specific sockets, use enet_socket* functions
(which ends up doing the same).
Clean up some confusing APIs, removing the distinction between finding
the public IP for the host/join.
Fix endianness support & use simpler code.
Refs D364 / 61261d14fc (and some subsequent fixing diffs).
Differential Revision: https://code.wildfiregames.com/D3970
This was SVN commit r25453.
This commit is contained in:
@@ -98,29 +98,6 @@ void StartNetworkHost(const ScriptRequest& rq, const CStrW& playerName, const u1
|
||||
// Always use lobby authentication for lobby matches to prevent impersonation and smurfing, in particular through mods that implemented an UI for arbitrary or other players nicknames.
|
||||
bool hasLobby = !!g_XmppClient;
|
||||
g_NetServer = new CNetServer(hasLobby);
|
||||
// In lobby, we send our public ip and port on request to the players, who want to connect.
|
||||
// In either case we need to know our public IP. If using STUN, we'll use that,
|
||||
// otherwise, the lobby's reponse to the game registration stanza will tell us our public IP.
|
||||
if (hasLobby)
|
||||
{
|
||||
CStr ip;
|
||||
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, false);
|
||||
else
|
||||
{
|
||||
u16 port = serverPort;
|
||||
// This is using port variable to store return value, do not pass serverPort itself.
|
||||
if (!StunClient::FindStunEndpointHost(ip, port))
|
||||
{
|
||||
ScriptException::Raise(rq, "Failed to host via STUN.");
|
||||
SAFE_DELETE(g_NetServer);
|
||||
return;
|
||||
}
|
||||
g_NetServer->SetConnectionData(ip, port, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_NetServer->SetupConnection(serverPort))
|
||||
{
|
||||
@@ -129,6 +106,23 @@ void StartNetworkHost(const ScriptRequest& rq, const CStrW& playerName, const u1
|
||||
return;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a secret to identify the host client.
|
||||
std::string secret = ps_generate_guid();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user