Changeset View
Changeset View
Standalone View
Standalone View
source/network/scripting/JSInterface_Network.cpp
Show All 33 Lines | u16 JSI_Network::GetDefaultPort(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | ||||
return PS_DEFAULT_PORT; | return PS_DEFAULT_PORT; | ||||
} | } | ||||
JS::Value JSI_Network::FindStunEndpoint(ScriptInterface::CxPrivate* pCxPrivate, int port) | JS::Value JSI_Network::FindStunEndpoint(ScriptInterface::CxPrivate* pCxPrivate, int port) | ||||
{ | { | ||||
return StunClient::FindStunEndpointHost(*(pCxPrivate->pScriptInterface), port); | return StunClient::FindStunEndpointHost(*(pCxPrivate->pScriptInterface), port); | ||||
} | } | ||||
void JSI_Network::StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& playerName, const u16 serverPort) | void JSI_Network::StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& playerName, const u16 serverPort, const CStr& hostName, bool useLobbyAuth) | ||||
elexis: "hosting playername" is still a bad name because we have a second variable that holds a… | |||||
Not Done Inline ActionsDon't get your issue Imarok: Don't get your issue | |||||
Not Done Inline ActionsplayerName is the name of the host too, so it's more confusing than it needs to be. elexis: playerName is the name of the host too, so it's more confusing than it needs to be. | |||||
{ | { | ||||
ENSURE(!g_NetClient); | ENSURE(!g_NetClient); | ||||
ENSURE(!g_NetServer); | ENSURE(!g_NetServer); | ||||
ENSURE(!g_Game); | ENSURE(!g_Game); | ||||
g_NetServer = new CNetServer(); | g_NetServer = new CNetServer(useLobbyAuth); | ||||
if (!g_NetServer->SetupConnection(serverPort)) | if (!g_NetServer->SetupConnection(serverPort)) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Failed to start server"); | pCxPrivate->pScriptInterface->ReportError("Failed to start server"); | ||||
SAFE_DELETE(g_NetServer); | SAFE_DELETE(g_NetServer); | ||||
return; | return; | ||||
} | } | ||||
g_Game = new CGame(); | g_Game = new CGame(); | ||||
g_NetClient = new CNetClient(g_Game, true); | g_NetClient = new CNetClient(g_Game, true); | ||||
g_NetClient->SetUserName(playerName); | g_NetClient->SetUserName(playerName); | ||||
g_NetClient->SetHostingPlayerName(hostName); | |||||
if (!g_NetClient->SetupConnection("127.0.0.1", serverPort)) | if (!g_NetClient->SetupConnection("127.0.0.1", serverPort)) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | ||||
SAFE_DELETE(g_NetClient); | SAFE_DELETE(g_NetClient); | ||||
SAFE_DELETE(g_Game); | SAFE_DELETE(g_Game); | ||||
} | } | ||||
} | } | ||||
Show All 34 Lines | if (g_XmppClient && useSTUN) | ||||
delete stunEndpoint; | delete stunEndpoint; | ||||
SDL_Delay(1000); | SDL_Delay(1000); | ||||
} | } | ||||
g_Game = new CGame(); | g_Game = new CGame(); | ||||
g_NetClient = new CNetClient(g_Game, false); | g_NetClient = new CNetClient(g_Game, false); | ||||
g_NetClient->SetUserName(playerName); | g_NetClient->SetUserName(playerName); | ||||
g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); | |||||
if (g_XmppClient && useSTUN) | if (g_XmppClient && useSTUN) | ||||
StunClient::SendHolePunchingMessages(enetClient, serverAddress.c_str(), serverPort); | StunClient::SendHolePunchingMessages(enetClient, serverAddress.c_str(), serverPort); | ||||
if (!g_NetClient->SetupConnection(serverAddress, serverPort, enetClient)) | if (!g_NetClient->SetupConnection(serverAddress, serverPort, enetClient)) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | ||||
SAFE_DELETE(g_NetClient); | SAFE_DELETE(g_NetClient); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | void JSI_Network::SetTurnLength(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int length) | ||||
else | else | ||||
LOGERROR("Only network host can change turn length"); | LOGERROR("Only network host can change turn length"); | ||||
} | } | ||||
void JSI_Network::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void JSI_Network::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<u16, &GetDefaultPort>("GetDefaultPort"); | scriptInterface.RegisterFunction<u16, &GetDefaultPort>("GetDefaultPort"); | ||||
scriptInterface.RegisterFunction<JS::Value, int, &FindStunEndpoint>("FindStunEndpoint"); | scriptInterface.RegisterFunction<JS::Value, int, &FindStunEndpoint>("FindStunEndpoint"); | ||||
scriptInterface.RegisterFunction<void, CStrW, u16, &StartNetworkHost>("StartNetworkHost"); | scriptInterface.RegisterFunction<void, CStrW, u16, CStr, bool, &StartNetworkHost>("StartNetworkHost"); | ||||
scriptInterface.RegisterFunction<void, CStrW, CStr, u16, bool, CStr, &StartNetworkJoin>("StartNetworkJoin"); | scriptInterface.RegisterFunction<void, CStrW, CStr, u16, bool, CStr, &StartNetworkJoin>("StartNetworkJoin"); | ||||
scriptInterface.RegisterFunction<void, &DisconnectNetworkGame>("DisconnectNetworkGame"); | scriptInterface.RegisterFunction<void, &DisconnectNetworkGame>("DisconnectNetworkGame"); | ||||
scriptInterface.RegisterFunction<CStr, &GetPlayerGUID>("GetPlayerGUID"); | scriptInterface.RegisterFunction<CStr, &GetPlayerGUID>("GetPlayerGUID"); | ||||
scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); | scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); | ||||
scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); | scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); | ||||
scriptInterface.RegisterFunction<void, int, CStr, &AssignNetworkPlayer>("AssignNetworkPlayer"); | scriptInterface.RegisterFunction<void, int, CStr, &AssignNetworkPlayer>("AssignNetworkPlayer"); | ||||
scriptInterface.RegisterFunction<void, CStrW, bool, &KickPlayer>("KickPlayer"); | scriptInterface.RegisterFunction<void, CStrW, bool, &KickPlayer>("KickPlayer"); | ||||
scriptInterface.RegisterFunction<void, CStrW, &SendNetworkChat>("SendNetworkChat"); | scriptInterface.RegisterFunction<void, CStrW, &SendNetworkChat>("SendNetworkChat"); | ||||
scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady"); | scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady"); | ||||
scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); | scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); | ||||
scriptInterface.RegisterFunction<void, &StartNetworkGame>("StartNetworkGame"); | scriptInterface.RegisterFunction<void, &StartNetworkGame>("StartNetworkGame"); | ||||
scriptInterface.RegisterFunction<void, int, &SetTurnLength>("SetTurnLength"); | scriptInterface.RegisterFunction<void, int, &SetTurnLength>("SetTurnLength"); | ||||
} | } |
Wildfire Games · Phabricator
"hosting playername" is still a bad name because we have a second variable that holds a "hosting playername".
Distinguish it by adding the lobby word.