Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetClient.cpp
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | virtual void OnComplete() | ||||
CGameStartMessage start; | CGameStartMessage start; | ||||
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) : | ||||
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_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game), | ||||
m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetGeneralJSContext()), | m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetGeneralJSContext()), | ||||
m_IsLocalClient(isLocalClient), | |||||
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 87 Lines • ▼ Show 20 Lines | void CNetClient::SetHostingPlayerName(const CStr& hostingPlayerName) | ||||
m_HostingPlayerName = hostingPlayerName; | m_HostingPlayerName = hostingPlayerName; | ||||
} | } | ||||
void CNetClient::SetGamePassword(const CStr& hashedPassword) | void CNetClient::SetGamePassword(const CStr& hashedPassword) | ||||
{ | { | ||||
m_Password = hashedPassword; | m_Password = hashedPassword; | ||||
} | } | ||||
void CNetClient::SetControllerSecret(const std::string& secret) | |||||
{ | |||||
m_ControllerSecret = secret; | |||||
} | |||||
bool CNetClient::SetupConnection(ENetHost* enetClient) | bool CNetClient::SetupConnection(ENetHost* enetClient) | ||||
{ | { | ||||
CNetClientSession* session = new CNetClientSession(*this); | CNetClientSession* session = new CNetClientSession(*this); | ||||
bool ok = session->Connect(m_ServerAddress, m_ServerPort, m_IsLocalClient, enetClient); | bool ok = session->Connect(m_ServerAddress, m_ServerPort, enetClient); | ||||
SetAndOwnSession(session); | SetAndOwnSession(session); | ||||
m_PollingThread = std::thread(Threading::HandleExceptions<CNetClientSession::RunNetLoop>::Wrapper, m_Session); | m_PollingThread = std::thread(Threading::HandleExceptions<CNetClientSession::RunNetLoop>::Wrapper, m_Session); | ||||
return ok; | return ok; | ||||
} | } | ||||
void CNetClient::SetupServerData(CStr address, u16 port, bool stun) | void CNetClient::SetupServerData(CStr address, u16 port, bool stun) | ||||
{ | { | ||||
ENSURE(!m_Session); | ENSURE(!m_Session); | ||||
▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | void CNetClient::LoadFinished() | ||||
SendMessage(&loaded); | SendMessage(&loaded); | ||||
} | } | ||||
void CNetClient::SendAuthenticateMessage() | void CNetClient::SendAuthenticateMessage() | ||||
{ | { | ||||
CAuthenticateMessage authenticate; | CAuthenticateMessage authenticate; | ||||
authenticate.m_Name = m_UserName; | authenticate.m_Name = m_UserName; | ||||
authenticate.m_Password = m_Password; | authenticate.m_Password = m_Password; | ||||
authenticate.m_IsLocalClient = m_IsLocalClient; | authenticate.m_ControllerSecret = m_ControllerSecret; | ||||
SendMessage(&authenticate); | SendMessage(&authenticate); | ||||
} | } | ||||
bool CNetClient::OnConnect(void* context, CFsmEvent* event) | bool CNetClient::OnConnect(void* context, CFsmEvent* event) | ||||
{ | { | ||||
ENSURE(event->GetType() == (uint)NMT_CONNECT_COMPLETE); | ENSURE(event->GetType() == (uint)NMT_CONNECT_COMPLETE); | ||||
CNetClient* client = static_cast<CNetClient*>(context); | CNetClient* client = static_cast<CNetClient*>(context); | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | bool CNetClient::OnAuthenticate(void* context, CFsmEvent* event) | ||||
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: host=%u, %s", message->m_HostID, utf8_from_wstring(message->m_Message)); | ||||
client->m_HostID = message->m_HostID; | client->m_HostID = message->m_HostID; | ||||
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->PushGuiMessage( | client->PushGuiMessage( | ||||
"type", "netstatus", | "type", "netstatus", | ||||
"status", "authenticated", | "status", "authenticated", | ||||
"rejoining", client->m_Rejoin); | "rejoining", client->m_Rejoin); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 281 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator