Changeset View
Changeset View
Standalone View
Standalone View
source/network/scripting/JSInterface_Network.cpp
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | void JSI_Network::StartNetworkHost(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, const u16 serverPort, const CStr& hostLobbyName, bool useSTUN, const CStr& password) | ||||
{ | { | ||||
ScriptRequest rq(pCmptPrivate->pScriptInterface); | ScriptRequest rq(pCmptPrivate->pScriptInterface); | ||||
ScriptException::Raise(rq, "Failed to start server"); | ScriptException::Raise(rq, "Failed to start server"); | ||||
SAFE_DELETE(g_NetServer); | SAFE_DELETE(g_NetServer); | ||||
return; | return; | ||||
} | } | ||||
// 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 | ||||
g_NetServer->SetPassword(HashPassword(password)); | CStr hashedPass = HashPassword(password); | ||||
g_NetServer->SetPassword(hashedPass); | |||||
g_Game = new CGame(true); | g_Game = new CGame(true); | ||||
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(hostLobbyName); | g_NetClient->SetHostingPlayerName(hostLobbyName); | ||||
g_NetClient->SetGamePassword(hashedPass); | |||||
g_NetClient->SetupServerData("127.0.0.1", serverPort, false); | g_NetClient->SetupServerData("127.0.0.1", serverPort, false); | ||||
if (!g_NetClient->SetupConnection(nullptr)) | if (!g_NetClient->SetupConnection(nullptr)) | ||||
{ | { | ||||
ScriptRequest rq(pCmptPrivate->pScriptInterface); | ScriptRequest rq(pCmptPrivate->pScriptInterface); | ||||
ScriptException::Raise(rq, "Failed to connect to server"); | ScriptException::Raise(rq, "Failed to connect to server"); | ||||
SAFE_DELETE(g_NetClient); | SAFE_DELETE(g_NetClient); | ||||
SAFE_DELETE(g_Game); | SAFE_DELETE(g_Game); | ||||
Show All 23 Lines | |||||
void JSI_Network::StartNetworkJoinLobby(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, const CStr& hostJID, const CStr& password) | void JSI_Network::StartNetworkJoinLobby(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, const CStr& hostJID, const CStr& password) | ||||
{ | { | ||||
ENSURE(!!g_XmppClient); | ENSURE(!!g_XmppClient); | ||||
ENSURE(!g_NetClient); | ENSURE(!g_NetClient); | ||||
ENSURE(!g_NetServer); | ENSURE(!g_NetServer); | ||||
ENSURE(!g_Game); | ENSURE(!g_Game); | ||||
CStr hashedPass = HashPassword(password); | |||||
g_Game = new CGame(true); | g_Game = new CGame(true); | ||||
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("@"))); | g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); | ||||
g_XmppClient->SendIqGetConnectionData(hostJID, HashPassword(password).c_str()); | g_NetClient->SetGamePassword(hashedPass); | ||||
g_XmppClient->SendIqGetConnectionData(hostJID, hashedPass.c_str()); | |||||
} | } | ||||
void JSI_Network::DisconnectNetworkGame(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | void JSI_Network::DisconnectNetworkGame(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
// TODO: we ought to do async reliable disconnections | // TODO: we ought to do async reliable disconnections | ||||
SAFE_DELETE(g_NetServer); | SAFE_DELETE(g_NetServer); | ||||
SAFE_DELETE(g_NetClient); | SAFE_DELETE(g_NetClient); | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator