Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetClient.cpp
Show All 30 Lines | |||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Compress.h" | #include "ps/Compress.h" | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
CNetClient *g_NetClient = NULL; | CNetClient *g_NetClient = nullptr; | ||||
/** | /** | ||||
* Async task for receiving the initial game state when rejoining an | * Async task for receiving the initial game state when rejoining an | ||||
* in-progress network game. | * in-progress network game. | ||||
*/ | */ | ||||
class CNetFileReceiveTask_ClientRejoin : public CNetFileReceiveTask | class CNetFileReceiveTask_ClientRejoin : public CNetFileReceiveTask | ||||
{ | { | ||||
NONCOPYABLE(CNetFileReceiveTask_ClientRejoin); | NONCOPYABLE(CNetFileReceiveTask_ClientRejoin); | ||||
Show All 15 Lines | virtual void OnComplete() | ||||
m_Client.HandleMessage(&start); | m_Client.HandleMessage(&start); | ||||
} | } | ||||
private: | private: | ||||
CNetClient& m_Client; | CNetClient& m_Client; | ||||
}; | }; | ||||
CNetClient::CNetClient(CGame* game, bool isLocalClient) : | CNetClient::CNetClient(CGame* game, bool isLocalClient) : | ||||
m_Session(NULL), | m_Session(nullptr), | ||||
m_UserName(L"anonymous"), | m_UserName(L"anonymous"), | ||||
m_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game), | m_HostID((u32)-1), m_ClientTurnManager(nullptr), m_Game(game), | ||||
m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetContext()), | m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetContext()), | ||||
m_IsLocalClient(isLocalClient), | m_IsLocalClient(isLocalClient), | ||||
m_LastConnectionCheck(0), | m_LastConnectionCheck(0), | ||||
m_Rejoin(false) | m_Rejoin(false) | ||||
{ | { | ||||
m_Game->SetTurnManager(NULL); // delete the old local turn manager so we don't accidentally use it | m_Game->SetTurnManager(nullptr); // delete the old local turn manager so we don't accidentally use it | ||||
void* context = this; | void* context = this; | ||||
JS_AddExtraGCRootsTracer(GetScriptInterface().GetJSRuntime(), CNetClient::Trace, this); | JS_AddExtraGCRootsTracer(GetScriptInterface().GetJSRuntime(), CNetClient::Trace, this); | ||||
// Set up transitions for session | // Set up transitions for session | ||||
AddTransition(NCS_UNCONNECTED, (uint)NMT_CONNECT_COMPLETE, NCS_CONNECT, (void*)&OnConnect, context); | AddTransition(NCS_UNCONNECTED, (uint)NMT_CONNECT_COMPLETE, NCS_CONNECT, (void*)&OnConnect, context); | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | bool CNetClient::SendMessage(const CNetMessage* message) | ||||
if (!m_Session) | if (!m_Session) | ||||
return false; | return false; | ||||
return m_Session->SendMessage(message); | return m_Session->SendMessage(message); | ||||
} | } | ||||
void CNetClient::HandleConnect() | void CNetClient::HandleConnect() | ||||
{ | { | ||||
Update((uint)NMT_CONNECT_COMPLETE, NULL); | Update((uint)NMT_CONNECT_COMPLETE, nullptr); | ||||
} | } | ||||
void CNetClient::HandleDisconnect(u32 reason) | void CNetClient::HandleDisconnect(u32 reason) | ||||
{ | { | ||||
JSContext* cx = GetScriptInterface().GetContext(); | JSContext* cx = GetScriptInterface().GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue msg(cx); | JS::RootedValue msg(cx); | ||||
▲ Show 20 Lines • Show All 600 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator