Changeset View
Changeset View
Standalone View
Standalone View
network/NetClient.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
private: | private: | ||||
CNetClient& m_Client; | CNetClient& m_Client; | ||||
CStr m_InitAttributes; | CStr m_InitAttributes; | ||||
}; | }; | ||||
CNetClient::CNetClient(CGame* game) : | CNetClient::CNetClient(CGame* game) : | ||||
m_Session(NULL), | m_Session(NULL), | ||||
m_UserName(L"anonymous"), | m_UserName(L"anonymous"), | ||||
m_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game), | m_ClientId((u32)-1), m_ClientTurnManager(NULL), m_Game(game), | ||||
m_LastConnectionCheck(0), | m_LastConnectionCheck(0), | ||||
m_ServerAddress(), | m_ServerAddress(), | ||||
m_ServerPort(0), | m_ServerPort(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(NULL); // delete the old local turn manager so we don't accidentally use it | ||||
void* context = this; | void* context = this; | ||||
▲ Show 20 Lines • Show All 604 Lines • ▼ Show 20 Lines | |||||
bool CNetClient::OnAuthenticate(void* context, CFsmEvent* event) | bool CNetClient::OnAuthenticate(void* context, CFsmEvent* event) | ||||
{ | { | ||||
ENSURE(event->GetType() == (uint)NMT_AUTHENTICATE_RESULT); | ENSURE(event->GetType() == (uint)NMT_AUTHENTICATE_RESULT); | ||||
CNetClient* client = static_cast<CNetClient*>(context); | CNetClient* client = static_cast<CNetClient*>(context); | ||||
CAuthenticateResultMessage* message = static_cast<CAuthenticateResultMessage*>(event->GetParamRef()); | CAuthenticateResultMessage* message = static_cast<CAuthenticateResultMessage*>(event->GetParamRef()); | ||||
LOGMESSAGE("Net: Authentication result: host=%u, %s", message->m_HostID, utf8_from_wstring(message->m_Message)); | LOGMESSAGE("Net: Authentication result: clientId=%u, %s", message->m_ClientId, utf8_from_wstring(message->m_Message)); | ||||
client->m_HostID = message->m_HostID; | client->m_ClientId = message->m_ClientId; | ||||
client->m_Rejoin = message->m_Code == ARC_OK_REJOINING; | client->m_Rejoin = message->m_Code == ARC_OK_REJOINING; | ||||
client->m_IsController = message->m_IsController; | client->m_IsController = message->m_IsController; | ||||
client->PushGuiMessage( | client->PushGuiMessage( | ||||
"type", "netstatus", | "type", "netstatus", | ||||
"status", "authenticated", | "status", "authenticated", | ||||
"rejoining", client->m_Rejoin); | "rejoining", client->m_Rejoin); | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | bool CNetClient::OnGameStart(void* context, CFsmEvent* event) | ||||
CGameStartMessage* message = static_cast<CGameStartMessage*>(event->GetParamRef()); | CGameStartMessage* message = static_cast<CGameStartMessage*>(event->GetParamRef()); | ||||
// Find the player assigned to our GUID | // Find the player assigned to our GUID | ||||
int player = -1; | int player = -1; | ||||
if (client->m_PlayerAssignments.find(client->m_GUID) != client->m_PlayerAssignments.end()) | if (client->m_PlayerAssignments.find(client->m_GUID) != client->m_PlayerAssignments.end()) | ||||
player = client->m_PlayerAssignments[client->m_GUID].m_PlayerID; | player = client->m_PlayerAssignments[client->m_GUID].m_PlayerID; | ||||
client->m_ClientTurnManager = new CNetClientTurnManager( | client->m_ClientTurnManager = new CNetClientTurnManager( | ||||
*client->m_Game->GetSimulation2(), *client, client->m_HostID, client->m_Game->GetReplayLogger()); | *client->m_Game->GetSimulation2(), *client, client->m_ClientId, client->m_Game->GetReplayLogger()); | ||||
// Parse init attributes. | // Parse init attributes. | ||||
const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface(); | const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface(); | ||||
ScriptRequest rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
JS::RootedValue initAttribs(rq.cx); | JS::RootedValue initAttribs(rq.cx); | ||||
Script::ParseJSON(rq, message->m_InitAttributes, &initAttribs); | Script::ParseJSON(rq, message->m_InitAttributes, &initAttribs); | ||||
client->m_Game->SetPlayerID(player); | client->m_Game->SetPlayerID(player); | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator