Index: source/network/NetClient.h =================================================================== --- source/network/NetClient.h +++ source/network/NetClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -327,7 +327,7 @@ CNetClientTurnManager* m_ClientTurnManager; /// Unique-per-game identifier of this client, used to identify the sender of simulation commands - u32 m_HostID; + u32 m_ClientId; /// True if the player is currently rejoining or has already rejoined the game. bool m_Rejoin; Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -86,7 +86,7 @@ CNetClient::CNetClient(CGame* game) : m_Session(NULL), 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_ServerAddress(), m_ServerPort(0), @@ -707,9 +707,9 @@ CNetClient* client = static_cast(context); CAuthenticateResultMessage* message = static_cast(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_IsController = message->m_IsController; @@ -806,7 +806,7 @@ player = client->m_PlayerAssignments[client->m_GUID].m_PlayerID; 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. const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface(); Index: source/network/NetClientTurnManager.cpp =================================================================== --- source/network/NetClientTurnManager.cpp +++ source/network/NetClientTurnManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -102,7 +102,7 @@ void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg) { // Command received from the server - store it for later execution - AddCommand(msg->m_Client, msg->m_Player, msg->m_Data, msg->m_Turn); + AddCommand(msg->m_ClientId, msg->m_Player, msg->m_Data, msg->m_Turn); } void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, const std::vector& playerNames) Index: source/network/NetMessage.h =================================================================== --- source/network/NetMessage.h +++ source/network/NetMessage.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -114,7 +114,7 @@ { public: CSimulationMessage(const ScriptInterface& scriptInterface); - CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data); + CSimulationMessage(const ScriptInterface& scriptInterface, u32 clientId, i32 player, u32 turn, JS::HandleValue data); /** The compiler can't create a copy constructor because of the PersistentRooted member, * so we have to write it manually. @@ -127,7 +127,7 @@ virtual size_t GetSerializedLength() const; virtual CStr ToString() const; - u32 m_Client; + u32 m_ClientId; i32 m_Player; u32 m_Turn; JS::PersistentRooted m_Data; Index: source/network/NetMessageSim.cpp =================================================================== --- source/network/NetMessageSim.cpp +++ source/network/NetMessageSim.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -117,16 +117,16 @@ m_Data.init(rq.cx); } -CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) : +CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 clientId, i32 player, u32 turn, JS::HandleValue data) : CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), - m_Client(client), m_Player(player), m_Turn(turn) + m_ClientId(clientId), m_Player(player), m_Turn(turn) { ScriptRequest rq(scriptInterface); m_Data.init(rq.cx, data); } CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) : - m_Client(orig.m_Client), + m_ClientId(orig.m_ClientId), m_Player(orig.m_Player), m_ScriptInterface(orig.m_ScriptInterface), m_Turn(orig.m_Turn), @@ -142,7 +142,7 @@ // TODO: ought to represent common commands more efficiently u8* pos = CNetMessage::Serialize(pBuffer); CBufferBinarySerializer serializer(m_ScriptInterface, pos); - serializer.NumberU32_Unbounded("client", m_Client); + serializer.NumberU32_Unbounded("client", m_ClientId); serializer.NumberI32_Unbounded("player", m_Player); serializer.NumberU32_Unbounded("turn", m_Turn); @@ -157,7 +157,7 @@ const u8* pos = CNetMessage::Deserialize(pStart, pEnd); std::istringstream stream(std::string(pos, pEnd)); CStdDeserializer deserializer(m_ScriptInterface, stream); - deserializer.NumberU32_Unbounded("client", m_Client); + deserializer.NumberU32_Unbounded("client", m_ClientId); deserializer.NumberI32_Unbounded("player", m_Player); deserializer.NumberU32_Unbounded("turn", m_Turn); deserializer.ScriptVal("command", &m_Data); @@ -169,7 +169,7 @@ // TODO: serializing twice is stupidly inefficient - we should just // do it once, store the result, and use it here and in Serialize CLengthBinarySerializer serializer(m_ScriptInterface); - serializer.NumberU32_Unbounded("client", m_Client); + serializer.NumberU32_Unbounded("client", m_ClientId); serializer.NumberI32_Unbounded("player", m_Player); serializer.NumberU32_Unbounded("turn", m_Turn); @@ -184,7 +184,7 @@ std::string source = Script::ToString(ScriptRequest(m_ScriptInterface), const_cast(&m_Data)); std::stringstream stream; - stream << "CSimulationMessage { m_Client: " << m_Client << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }"; + stream << "CSimulationMessage { m_ClientId: " << m_ClientId << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }"; return CStr(stream.str()); } Index: source/network/NetMessages.h =================================================================== --- source/network/NetMessages.h +++ source/network/NetMessages.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -127,7 +127,7 @@ START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT) NMT_FIELD_INT(m_Code, u32, 4) - NMT_FIELD_INT(m_HostID, u32, 2) + NMT_FIELD_INT(m_ClientId, u32, 2) NMT_FIELD_INT(m_IsController, u8, 1) NMT_FIELD(CStrW, m_Message) END_NMT_CLASS() Index: source/network/NetServer.h =================================================================== --- source/network/NetServer.h +++ source/network/NetServer.h @@ -373,7 +373,7 @@ */ std::vector m_PausingPlayers; - u32 m_NextHostID; + u32 m_NextClientId; CNetServerTurnManager* m_ServerTurnManager; Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -96,8 +96,8 @@ { NONCOPYABLE(CNetFileReceiveTask_ServerRejoin); public: - CNetFileReceiveTask_ServerRejoin(CNetServerWorker& server, u32 hostID) - : m_Server(server), m_RejoinerHostID(hostID) + CNetFileReceiveTask_ServerRejoin(CNetServerWorker& server, u32 clientId) + : m_Server(server), m_RejoinerClientId(clientId) { } @@ -110,7 +110,7 @@ CNetServerSession* session = NULL; for (CNetServerSession* serverSession : m_Server.m_Sessions) { - if (serverSession->GetHostID() == m_RejoinerHostID) + if (serverSession->GetClientId() == m_RejoinerClientId) { session = serverSession; break; @@ -137,7 +137,7 @@ private: CNetServerWorker& m_Server; - u32 m_RejoinerHostID; + u32 m_RejoinerClientId; }; /* @@ -149,7 +149,7 @@ m_LobbyAuth(useLobbyAuth), m_Shutdown(false), m_ScriptInterface(NULL), - m_NextHostID(1), m_Host(NULL), m_ControllerGUID(), m_Stats(NULL), + m_NextClientId(1u), m_Host(NULL), m_ControllerGUID(), m_Stats(NULL), m_LastConnectionCheck(0) { m_State = SERVER_STATE_UNCONNECTED; @@ -750,7 +750,7 @@ RemovePlayer(session->GetGUID()); if (m_ServerTurnManager && session->GetCurrState() != NSS_JOIN_SYNCING) - m_ServerTurnManager->UninitialiseClient(session->GetHostID()); + m_ServerTurnManager->UninitialiseClient(session->GetClientId()); // TODO: ought to switch the player controlled by that client // back to AI control, or something? @@ -1124,14 +1124,14 @@ return true; } - u32 newHostID = server.m_NextHostID++; + u32 newClientId = server.m_NextClientId++; session->SetUserName(username); - session->SetHostID(newHostID); + session->SetClientId(newClientId); CAuthenticateResultMessage authenticateResult; authenticateResult.m_Code = isRejoining ? ARC_OK_REJOINING : ARC_OK; - authenticateResult.m_HostID = newHostID; + authenticateResult.m_ClientId = newClientId; authenticateResult.m_Message = L"Logged in"; authenticateResult.m_IsController = 0; @@ -1161,7 +1161,7 @@ CNetServerSession* sourceSession = server.m_Sessions.at(0); sourceSession->GetFileTransferer().StartTask( - std::shared_ptr(new CNetFileReceiveTask_ServerRejoin(server, newHostID)) + std::shared_ptr(new CNetFileReceiveTask_ServerRejoin(server, newClientId)) ); session->SetNextState(NSS_JOIN_SYNCING); @@ -1410,7 +1410,7 @@ // Tell the turn manager to expect commands from this new client // Special case: the controller shouldn't be treated as an observer in any case. bool isObserver = server.m_PlayerAssignments[session->GetGUID()].m_PlayerID == -1 && server.m_ControllerGUID != session->GetGUID(); - server.m_ServerTurnManager->InitialiseClient(session->GetHostID(), readyTurn, isObserver); + server.m_ServerTurnManager->InitialiseClient(session->GetClientId(), readyTurn, isObserver); // Tell the client that everything has finished loading and it should start now CLoadedGameMessage loaded; @@ -1541,7 +1541,7 @@ { // Special case: the controller shouldn't be treated as an observer in any case. bool isObserver = m_PlayerAssignments[session->GetGUID()].m_PlayerID == -1 && m_ControllerGUID != session->GetGUID(); - m_ServerTurnManager->InitialiseClient(session->GetHostID(), 0, isObserver); + m_ServerTurnManager->InitialiseClient(session->GetClientId(), 0, isObserver); } m_State = SERVER_STATE_LOADING; Index: source/network/NetServerTurnManager.h =================================================================== --- source/network/NetServerTurnManager.h +++ source/network/NetServerTurnManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -48,12 +48,12 @@ * Inform the turn manager of a new client * @param observer - whether this client is an observer. */ - void InitialiseClient(int client, u32 turn, bool observer); + void InitialiseClient(u32 clientId, u32 turn, bool observer); /** - * Inform the turn manager that a previously-initialised client has left the game. + * Inform the turn manager that a previously-initialised clientId has left the game. */ - void UninitialiseClient(int client); + void UninitialiseClient(u32 clientId); void SetTurnLength(u32 msecs); Index: source/network/NetServerTurnManager.cpp =================================================================== --- source/network/NetServerTurnManager.cpp +++ source/network/NetServerTurnManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -47,26 +47,26 @@ void CNetServerTurnManager::NotifyFinishedClientCommands(CNetServerSession& session, u32 turn) { - int client = session.GetHostID(); + u32 clientId = session.GetClientId(); - NETSERVERTURN_LOG("NotifyFinishedClientCommands(client=%d, turn=%d)\n", client, turn); + NETSERVERTURN_LOG("NotifyFinishedClientCommands(clientId=%d, turn=%d)\n", clientId, turn); - // Must be a client we've already heard of - ENSURE(m_ClientsData.find(client) != m_ClientsData.end()); + // Must be a clientId we've already heard of + ENSURE(m_ClientsData.find(clientId) != m_ClientsData.end()); // Clients must advance one turn at a time - if (turn != m_ClientsData[client].readyTurn + 1) + if (turn != m_ClientsData[clientId].readyTurn + 1) { LOGERROR("NotifyFinishedClientCommands: Client %d (%s) is ready for turn %d, but expected %d", - client, + clientId, utf8_from_wstring(session.GetUserName()).c_str(), turn, - m_ClientsData[client].readyTurn + 1); + m_ClientsData[clientId].readyTurn + 1); session.Disconnect(NDR_INCORRECT_READY_TURN_COMMANDS); } - m_ClientsData[client].readyTurn = turn; + m_ClientsData[clientId].readyTurn = turn; // Check whether this was the final client to become ready CheckClientsReady(); @@ -107,29 +107,29 @@ void CNetServerTurnManager::NotifyFinishedClientUpdate(CNetServerSession& session, u32 turn, const CStr& hash) { - int client = session.GetHostID(); + u32 clientId = session.GetClientId(); const CStrW& playername = session.GetUserName(); // Clients must advance one turn at a time - if (turn != m_ClientsData[client].simulatedTurn + 1) + if (turn != m_ClientsData[clientId].simulatedTurn + 1) { LOGERROR("NotifyFinishedClientUpdate: Client %d (%s) is ready for turn %d, but expected %d", - client, + clientId, utf8_from_wstring(playername).c_str(), turn, - m_ClientsData[client].simulatedTurn + 1); + m_ClientsData[clientId].simulatedTurn + 1); session.Disconnect(NDR_INCORRECT_READY_TURN_SIMULATED); } - m_ClientsData[client].simulatedTurn = turn; + m_ClientsData[clientId].simulatedTurn = turn; // Check for OOS only if in sync if (m_HasSyncError) return; - m_ClientsData[client].playerName = playername; - m_ClientStateHashes[turn][client] = hash; + m_ClientsData[clientId].playerName = playername; + m_ClientStateHashes[turn][clientId] = hash; // Find the newest turn which we know all clients have simulated u32 newest = std::numeric_limits::max(); @@ -181,27 +181,27 @@ m_ClientStateHashes.erase(m_ClientStateHashes.begin(), m_ClientStateHashes.lower_bound(newest+1)); } -void CNetServerTurnManager::InitialiseClient(int client, u32 turn, bool observer) +void CNetServerTurnManager::InitialiseClient(u32 clientId, u32 turn, bool observer) { - NETSERVERTURN_LOG("InitialiseClient(client=%d, turn=%d)\n", client, turn); + NETSERVERTURN_LOG("InitialiseClient(clientId=%d, turn=%d)\n", clientId, turn); - ENSURE(m_ClientsData.find(client) == m_ClientsData.end()); - Client& data = m_ClientsData[client]; + ENSURE(m_ClientsData.find(clientId) == m_ClientsData.end()); + Client& data = m_ClientsData[clientId]; data.readyTurn = turn + COMMAND_DELAY_MP - 1; data.simulatedTurn = turn; data.isObserver = observer; } -void CNetServerTurnManager::UninitialiseClient(int client) +void CNetServerTurnManager::UninitialiseClient(u32 clientId) { - NETSERVERTURN_LOG("UninitialiseClient(client=%d)\n", client); + NETSERVERTURN_LOG("UninitialiseClient(clientId=%d)\n", clientId); - ENSURE(m_ClientsData.find(client) != m_ClientsData.end()); - bool checkOOS = m_ClientsData[client].isOOS; - m_ClientsData.erase(client); + ENSURE(m_ClientsData.find(clientId) != m_ClientsData.end()); + bool checkOOS = m_ClientsData[clientId].isOOS; + m_ClientsData.erase(clientId); // Check whether we're ready for the next turn now that we're not - // waiting for this client any more + // waiting for this clientId any more CheckClientsReady(); // Check whether we're still OOS. Index: source/network/NetSession.h =================================================================== --- source/network/NetSession.h +++ source/network/NetSession.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -166,8 +166,8 @@ const CStrW& GetUserName() const { return m_UserName; } void SetUserName(const CStrW& name) { m_UserName = name; } - u32 GetHostID() const { return m_HostID; } - void SetHostID(u32 id) { m_HostID = id; } + u32 GetClientId() const { return m_ClientId; } + void SetClientId(u32 id) { m_ClientId = id; } u32 GetIPAddress() const; @@ -212,7 +212,7 @@ CStr m_GUID; CStrW m_UserName; - u32 m_HostID; + u32 m_ClientId; CStr m_Password; }; Index: source/network/NetSession.cpp =================================================================== --- source/network/NetSession.cpp +++ source/network/NetSession.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -234,7 +234,7 @@ } CNetServerSession::CNetServerSession(CNetServerWorker& server, ENetPeer* peer) : - m_Server(server), m_FileTransferer(this), m_Peer(peer), m_HostID(0), m_GUID(), m_UserName() + m_Server(server), m_FileTransferer(this), m_Peer(peer), m_ClientId(0), m_GUID(), m_UserName() { } Index: source/network/tests/test_NetMessage.h =================================================================== --- source/network/tests/test_NetMessage.h +++ source/network/tests/test_NetMessage.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,7 +35,7 @@ Script::SetPropertyInt(rq, val, 0, 4); CSimulationMessage msg(script, 1, 2, 3, val); - TS_ASSERT_STR_EQUALS(msg.ToString(), "CSimulationMessage { m_Client: 1, m_Player: 2, m_Turn: 3, m_Data: [4] }"); + TS_ASSERT_STR_EQUALS(msg.ToString(), "CSimulationMessage { m_ClientId: 1, m_Player: 2, m_Turn: 3, m_Data: [4] }"); size_t len = msg.GetSerializedLength(); u8* buf = new u8[len+1]; @@ -44,7 +44,7 @@ TS_ASSERT_EQUALS(buf[len], '!'); CNetMessage* msg2 = CNetMessageFactory::CreateMessage(buf, len, script); - TS_ASSERT_STR_EQUALS(((CSimulationMessage*)msg2)->ToString(), "CSimulationMessage { m_Client: 1, m_Player: 2, m_Turn: 3, m_Data: [4] }"); + TS_ASSERT_STR_EQUALS(((CSimulationMessage*)msg2)->ToString(), "CSimulationMessage { m_ClientId: 1, m_Player: 2, m_Turn: 3, m_Data: [4] }"); delete msg2; delete[] buf;