Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/scripting/JSInterface_Network.cpp
Show First 20 Lines • Show All 92 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)) | ||||
{ | |||||
ScriptException::Raise(rq, "Failed to start server"); | |||||
SAFE_DELETE(g_NetServer); | |||||
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. | // otherwise, the lobby's reponse to the game registration stanza will tell us our public IP. | ||||
if (hasLobby) | if (hasLobby) | ||||
{ | { | ||||
CStr ip; | |||||
if (!useSTUN) | if (!useSTUN) | ||||
// Don't store IP - the lobby bot will send it later. | // 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) | // (if a client tries to connect before it's setup, they'll be disconnected) | ||||
g_NetServer->SetConnectionData("", serverPort, false); | g_NetServer->SetConnectionData("", serverPort); | ||||
else | else if (!g_NetServer->SetConnectionDataViaSTUN()) | ||||
{ | |||||
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 host via STUN."); | ||||
SAFE_DELETE(g_NetServer); | SAFE_DELETE(g_NetServer); | ||||
return; | return; | ||||
} | } | ||||
g_NetServer->SetConnectionData(ip, port, true); | |||||
} | |||||
} | |||||
if (!g_NetServer->SetupConnection(serverPort)) | |||||
{ | |||||
ScriptException::Raise(rq, "Failed to start server"); | |||||
SAFE_DELETE(g_NetServer); | |||||
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(); | ||||
// We will get hashed password from clients, so hash it once for server | // We will get hashed password from clients, so hash it once for server | ||||
CStr hashedPass = HashPassword(password); | CStr hashedPass = HashPassword(password); | ||||
g_NetServer->SetPassword(hashedPass); | g_NetServer->SetPassword(hashedPass); | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator