Changeset View
Changeset View
Standalone View
Standalone View
source/network/scripting/JSInterface_Network.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
ENSURE(!g_NetClient); | ENSURE(!g_NetClient); | ||||
ENSURE(!g_NetServer); | ENSURE(!g_NetServer); | ||||
ENSURE(!g_Game); | ENSURE(!g_Game); | ||||
// 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. | // 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; | bool hasLobby = !!g_XmppClient; | ||||
g_NetServer = new CNetServer(hasLobby); | 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, | if (!g_NetServer->SetupConnection(serverPort)) | ||||
// 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."); | ScriptException::Raise(rq, "Failed to start server"); | ||||
SAFE_DELETE(g_NetServer); | SAFE_DELETE(g_NetServer); | ||||
return; | return; | ||||
} | } | ||||
g_NetServer->SetConnectionData(ip, port, true); | |||||
} | |||||
} | |||||
if (!g_NetServer->SetupConnection(serverPort)) | // When hosting in the lobby, we'll need to know our public IP to perform hole-punching. | ||||
wraitii: Pretty sure this could fail, because it didn't re-use the enet socket. | |||||
// If using STUN, we can use that to query it, so do this immediately. | |||||
// Otherwise, we'll rely on the lobby game registration stanza response. | |||||
Done Inline Actionslobby wraitii: lobby | |||||
if (hasLobby && useSTUN && !g_NetServer->SetConnectionDataViaSTUN()) | |||||
{ | { | ||||
ScriptException::Raise(rq, "Failed to start server"); | ScriptException::Raise(rq, "Failed to start server"); | ||||
SAFE_DELETE(g_NetServer); | SAFE_DELETE(g_NetServer); | ||||
return; | return; | ||||
} | } | ||||
// Generate a secret to identify the host client. | // Generate a secret to identify the host client. | ||||
std::string secret = ps_generate_guid(); | std::string secret = ps_generate_guid(); | ||||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Pretty sure this could fail, because it didn't re-use the enet socket.