Changeset View
Changeset View
Standalone View
Standalone View
source/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), | ||||
Mercury: Are we casting -1 to unsigned here? That seems like it should be a compiler error. | |||||
MercuryAuthorUnsubmitted Done Inline ActionsI think we can safely change this to 0. The Id 1 is assigned to the game host. (uint32_t)-1 == 4294967295 Which is guess is just as good as 0 for a null value but still looks weird. Mercury: I think we can safely change this to 0. The Id 1 is assigned to the game host.
```
(uint32_t)… | |||||
MercuryAuthorUnsubmitted Done Inline ActionsWe also cast negative literals to unsigned in these files: Mercury: We also cast negative literals to unsigned in these files:
ps/Profiler2.cpp… | |||||
MercuryAuthorUnsubmitted Done Inline ActionsIn test_sqrt.h it seems to be on purpose. In Profiler2 it can't be fixed because 0 is a possible value. In NetClient I think we should use NULL instead. More descriptive of what is going on. Mercury: In test_sqrt.h it seems to be on purpose. In Profiler2 it can't be fixed because 0 is a… | |||||
phositUnsubmitted Not Done Inline ActionsCasting -1 to an unsigned is common practice for a "undefined" state were 0 is a valid value: https://en.cppreference.com/w/cpp/string/basic_string/npos phosit: Casting `-1` to an unsigned is common practice for a "undefined" state were 0 is a valid value… | |||||
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: host=%u, %s", message->m_ClientId, utf8_from_wstring(message->m_Message)); | ||||
phositUnsubmitted Done Inline ActionsWhy not clientID=%u? phosit: Why not `clientID=%u`? | |||||
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
Are we casting -1 to unsigned here? That seems like it should be a compiler error.