From d2bf8d65130195d318ada25067764214a6f266b0 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Fri, 21 Jan 2022 22:13:35 +0100 Subject: [PATCH] Rename `Client` to `Conn` (suggestion by deen) --- src/engine/client.h | 28 +++--- src/engine/client/client.cpp | 166 ++++++++++++++++----------------- src/engine/client/client.h | 10 +- src/game/client/gameclient.cpp | 26 +++--- src/game/client/gameclient.h | 2 +- 5 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/engine/client.h b/src/engine/client.h index a9100cfe0..4394e6dd2 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -64,10 +64,10 @@ public: enum { - CLIENT_MAIN = 0, - CLIENT_DUMMY, - CLIENT_CONTACT, - NUM_CLIENTS, + CONN_MAIN = 0, + CONN_DUMMY, + CONN_CONTACT, + NUM_CONNS, }; /* Constants: Client States @@ -94,13 +94,13 @@ public: inline int State() const { return m_State; } // tick time access - inline int PrevGameTick(int Client) const { return m_PrevGameTick[Client]; } - inline int GameTick(int Client) const { return m_CurGameTick[Client]; } - inline int PredGameTick(int Client) const { return m_PredTick[Client]; } - inline float IntraGameTick(int Client) const { return m_GameIntraTick[Client]; } - inline float PredIntraGameTick(int Client) const { return m_PredIntraTick[Client]; } - inline float IntraGameTickSincePrev(int Client) const { return m_GameIntraTickSincePrev[Client]; } - inline float GameTickTime(int Client) const { return m_GameTickTime[Client]; } + inline int PrevGameTick(int Conn) const { return m_PrevGameTick[Conn]; } + inline int GameTick(int Conn) const { return m_CurGameTick[Conn]; } + inline int PredGameTick(int Conn) const { return m_PredTick[Conn]; } + inline float IntraGameTick(int Conn) const { return m_GameIntraTick[Conn]; } + inline float PredIntraGameTick(int Conn) const { return m_PredIntraTick[Conn]; } + inline float IntraGameTickSincePrev(int Conn) const { return m_GameIntraTickSincePrev[Conn]; } + inline float GameTickTime(int Conn) const { return m_GameTickTime[Conn]; } inline int GameTickSpeed() const { return m_GameTickSpeed; } // other time access @@ -142,7 +142,7 @@ public: virtual void Notify(const char *pTitle, const char *pMessage) = 0; // networking - virtual void EnterGame(int Client) = 0; + virtual void EnterGame(int Conn) = 0; // virtual const char *MapDownloadName() const = 0; @@ -181,7 +181,7 @@ public: virtual void SnapSetStaticsize(int ItemType, int Size) = 0; - virtual int SendMsg(int Client, CMsgPacker *pMsg, int Flags) = 0; + virtual int SendMsg(int Conn, CMsgPacker *pMsg, int Flags) = 0; virtual int SendMsgActive(CMsgPacker *pMsg, int Flags) = 0; template @@ -251,7 +251,7 @@ public: virtual void OnUpdate() = 0; virtual void OnStateChange(int NewState, int OldState) = 0; virtual void OnConnected() = 0; - virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int Client, bool Dummy) = 0; + virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int Conn, bool Dummy) = 0; virtual void OnPredict() = 0; virtual void OnActivateEditor() = 0; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 6cb25a618..7293b5e99 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -422,7 +422,7 @@ static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer) return false; } -int CClient::SendMsg(int Client, CMsgPacker *pMsg, int Flags) +int CClient::SendMsg(int Conn, CMsgPacker *pMsg, int Flags) { CNetChunk Packet; @@ -444,7 +444,7 @@ int CClient::SendMsg(int Client, CMsgPacker *pMsg, int Flags) if(Flags & MSGFLAG_FLUSH) Packet.m_Flags |= NETSENDFLAG_FLUSH; - if((Flags & MSGFLAG_RECORD) && Client == g_Config.m_ClDummy) + if((Flags & MSGFLAG_RECORD) && Conn == g_Config.m_ClDummy) { for(auto &i : m_DemoRecorder) if(i.IsRecording()) @@ -453,7 +453,7 @@ int CClient::SendMsg(int Client, CMsgPacker *pMsg, int Flags) if(!(Flags & MSGFLAG_NOSEND)) { - m_NetClient[Client].Send(&Packet); + m_NetClient[Conn].Send(&Packet); } return 0; @@ -470,24 +470,24 @@ void CClient::SendInfo() MsgVer.AddRaw(&m_ConnectionID, sizeof(m_ConnectionID)); MsgVer.AddInt(GameClient()->DDNetVersion()); MsgVer.AddString(GameClient()->DDNetVersionStr(), 0); - SendMsg(CLIENT_MAIN, &MsgVer, MSGFLAG_VITAL); + SendMsg(CONN_MAIN, &MsgVer, MSGFLAG_VITAL); CMsgPacker Msg(NETMSG_INFO, true); Msg.AddString(GameClient()->NetVersion(), 128); Msg.AddString(m_Password, 128); - SendMsg(CLIENT_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); } -void CClient::SendEnterGame(int Client) +void CClient::SendEnterGame(int Conn) { CMsgPacker Msg(NETMSG_ENTERGAME, true); - SendMsg(Client, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(Conn, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); } void CClient::SendReady() { CMsgPacker Msg(NETMSG_READY, true); - SendMsg(CLIENT_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); } void CClient::SendMapRequest() @@ -500,7 +500,7 @@ void CClient::SendMapRequest() m_MapdownloadFileTemp = Storage()->OpenFile(m_aMapdownloadFilenameTemp, IOFLAG_WRITE, IStorage::TYPE_SAVE); CMsgPacker Msg(NETMSG_REQUEST_MAP_DATA, true); Msg.AddInt(m_MapdownloadChunk); - SendMsg(CLIENT_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); } void CClient::RconAuth(const char *pName, const char *pPassword) @@ -690,17 +690,17 @@ void CClient::OnEnterGame(bool Dummy) GameClient()->OnEnterGame(); } -void CClient::EnterGame(int Client) +void CClient::EnterGame(int Conn) { if(State() == IClient::STATE_DEMOPLAYBACK) return; - m_CodeRunAfterJoin[Client] = false; + m_CodeRunAfterJoin[Conn] = false; // now we will wait for two snapshots // to finish the connection - SendEnterGame(Client); - OnEnterGame(Client); + SendEnterGame(Conn); + OnEnterGame(Conn); ServerInfoRequest(); // fresh one for timeout protection m_CurrentServerNextPingTime = time_get() + time_freq() / 2; @@ -767,12 +767,12 @@ void CClient::Connect(const char *pAddress, const char *pPassword) } ServerInfoRequest(); - if(net_host_lookup(m_aServerAddressStr, &m_ServerAddress, m_NetClient[CLIENT_MAIN].NetType()) != 0) + if(net_host_lookup(m_aServerAddressStr, &m_ServerAddress, m_NetClient[CONN_MAIN].NetType()) != 0) { char aBufMsg[256]; str_format(aBufMsg, sizeof(aBufMsg), "could not find the address of %s, connecting to localhost", aBuf); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBufMsg); - net_host_lookup("localhost", &m_ServerAddress, m_NetClient[CLIENT_MAIN].NetType()); + net_host_lookup("localhost", &m_ServerAddress, m_NetClient[CONN_MAIN].NetType()); } if(m_SendPassword) @@ -797,7 +797,7 @@ void CClient::Connect(const char *pAddress, const char *pPassword) { m_ServerAddress.type = NETTYPE_WEBSOCKET_IPV4; } - m_NetClient[CLIENT_MAIN].Connect(&m_ServerAddress); + m_NetClient[CONN_MAIN].Connect(&m_ServerAddress); SetState(IClient::STATE_CONNECTING); for(int i = 0; i < RECORDER_MAX; i++) @@ -826,7 +826,7 @@ void CClient::DisconnectWithReason(const char *pReason) m_ServerSentCapabilities = false; m_UseTempRconCommands = 0; m_pConsole->DeregisterTempAll(); - m_NetClient[CLIENT_MAIN].Disconnect(pReason); + m_NetClient[CONN_MAIN].Disconnect(pReason); SetState(IClient::STATE_OFFLINE); m_pMap->Unload(); m_CurrentServerPingInfoType = -1; @@ -893,7 +893,7 @@ void CClient::DummyConnect() if(m_LastDummyConnectTime > 0 && m_LastDummyConnectTime + GameTickSpeed() * 5 > GameTick(g_Config.m_ClDummy)) return; - if(m_NetClient[CLIENT_MAIN].State() != NET_CONNSTATE_ONLINE && m_NetClient[CLIENT_MAIN].State() != NET_CONNSTATE_PENDING) + if(m_NetClient[CONN_MAIN].State() != NET_CONNSTATE_ONLINE && m_NetClient[CONN_MAIN].State() != NET_CONNSTATE_PENDING) return; if(m_DummyConnected || !DummyAllowed()) @@ -909,7 +909,7 @@ void CClient::DummyConnect() g_Config.m_ClDummyHammer = 0; //connecting to the server - m_NetClient[CLIENT_DUMMY].Connect(&m_ServerAddress); + m_NetClient[CONN_DUMMY].Connect(&m_ServerAddress); } void CClient::DummyDisconnect(const char *pReason) @@ -917,7 +917,7 @@ void CClient::DummyDisconnect(const char *pReason) if(!m_DummyConnected) return; - m_NetClient[CLIENT_DUMMY].Disconnect(pReason); + m_NetClient[CONN_DUMMY].Disconnect(pReason); g_Config.m_ClDummy = 0; m_RconAuthed[1] = 0; m_aSnapshots[1][SNAP_CURRENT] = 0; @@ -1157,7 +1157,7 @@ const char *CClient::DummyName() const const char *CClient::ErrorString() const { - return m_NetClient[CLIENT_MAIN].ErrorString(); + return m_NetClient[CONN_MAIN].ErrorString(); } void CClient::Render() @@ -1579,7 +1579,7 @@ static CServerCapabilities GetServerCapabilities(int Version, int Flags) return Result; } -void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) +void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy) { CUnpacker Unpacker; Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize); @@ -1597,7 +1597,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) } else if(Result == UNPACKMESSAGE_ANSWER) { - SendMsg(Client, &Packer, MSGFLAG_VITAL); + SendMsg(Conn, &Packer, MSGFLAG_VITAL); } if(Sys) @@ -1756,7 +1756,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) CMsgPacker Msg(NETMSG_REQUEST_MAP_DATA, true); Msg.AddInt(m_MapdownloadChunk); - SendMsg(CLIENT_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_MAIN, &Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH); if(g_Config.m_Debug) { @@ -1781,7 +1781,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) else if(Msg == NETMSG_PING) { CMsgPacker Msg(NETMSG_PING_REPLY, true); - SendMsg(Client, &Msg, 0); + SendMsg(Conn, &Msg, 0); } else if(Msg == NETMSG_PINGEX) { @@ -1792,9 +1792,9 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) } CMsgPacker Msg(NETMSG_PONGEX, true); Msg.AddRaw(pID, sizeof(*pID)); - SendMsg(Client, &Msg, MSGFLAG_FLUSH); + SendMsg(Conn, &Msg, MSGFLAG_FLUSH); } - else if(Client == CLIENT_MAIN && Msg == NETMSG_PONGEX) + else if(Conn == CONN_MAIN && Msg == NETMSG_PONGEX) { CUuid *pID = (CUuid *)Unpacker.GetRaw(sizeof(*pID)); if(Unpacker.Error()) @@ -1844,7 +1844,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) if(Unpacker.Error() == 0) GameClient()->OnRconLine(pLine); } - else if(Client == CLIENT_MAIN && Msg == NETMSG_PING_REPLY) + else if(Conn == CONN_MAIN && Msg == NETMSG_PING_REPLY) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "latency %.2f", (time_get() - m_PingStartTime) * 1000 / (float)time_freq()); @@ -1860,10 +1860,10 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) int64_t Target = 0; for(int k = 0; k < 200; k++) { - if(m_aInputs[Client][k].m_Tick == InputPredTick) + if(m_aInputs[Conn][k].m_Tick == InputPredTick) { - Target = m_aInputs[Client][k].m_PredictedTime + (Now - m_aInputs[Client][k].m_Time); - Target = Target - (int64_t)((TimeLeft / 1000.0f) * time_freq()) + m_aInputs[Client][k].m_PredictionMargin; + Target = m_aInputs[Conn][k].m_PredictedTime + (Now - m_aInputs[Conn][k].m_Time); + Target = Target - (int64_t)((TimeLeft / 1000.0f) * time_freq()) + m_aInputs[Conn][k].m_PredictionMargin; break; } } @@ -1906,18 +1906,18 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) if(Unpacker.Error() || NumParts < 1 || NumParts > CSnapshot::MAX_PARTS || Part < 0 || Part >= NumParts || PartSize < 0 || PartSize > MAX_SNAPSHOT_PACKSIZE) return; - if(GameTick >= m_CurrentRecvTick[Client]) + if(GameTick >= m_CurrentRecvTick[Conn]) { - if(GameTick != m_CurrentRecvTick[Client]) + if(GameTick != m_CurrentRecvTick[Conn]) { - m_SnapshotParts[Client] = 0; - m_CurrentRecvTick[Client] = GameTick; + m_SnapshotParts[Conn] = 0; + m_CurrentRecvTick[Conn] = GameTick; } mem_copy((char *)m_aSnapshotIncomingData + Part * MAX_SNAPSHOT_PACKSIZE, pData, clamp(PartSize, 0, (int)sizeof(m_aSnapshotIncomingData) - Part * MAX_SNAPSHOT_PACKSIZE)); - m_SnapshotParts[Client] |= 1 << Part; + m_SnapshotParts[Conn] |= 1 << Part; - if(m_SnapshotParts[Client] == (unsigned)((1 << NumParts) - 1)) + if(m_SnapshotParts[Conn] == (unsigned)((1 << NumParts) - 1)) { static CSnapshot Emptysnap; CSnapshot *pDeltaShot = &Emptysnap; @@ -1927,7 +1927,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) const int CompleteSize = (NumParts - 1) * MAX_SNAPSHOT_PACKSIZE + PartSize; // reset snapshoting - m_SnapshotParts[Client] = 0; + m_SnapshotParts[Conn] = 0; // find snapshot that we should use as delta Emptysnap.Clear(); @@ -1935,7 +1935,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) // find delta if(DeltaTick >= 0) { - int DeltashotSize = m_SnapshotStorage[Client].Get(DeltaTick, 0, &pDeltaShot, 0); + int DeltashotSize = m_SnapshotStorage[Conn].Get(DeltaTick, 0, &pDeltaShot, 0); if(DeltashotSize < 0) { @@ -1950,7 +1950,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) // ack snapshot // TODO: combine this with the input message - m_AckGameTick[Client] = -1; + m_AckGameTick[Conn] = -1; return; } } @@ -1992,7 +1992,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) if(m_SnapCrcErrors > 10) { // to many errors, send reset - m_AckGameTick[Client] = -1; + m_AckGameTick[Conn] = -1; SendInput(); m_SnapCrcErrors = 0; } @@ -2006,14 +2006,14 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) // purge old snapshots int PurgeTick = DeltaTick; - if(m_aSnapshots[Client][SNAP_PREV] && m_aSnapshots[Client][SNAP_PREV]->m_Tick < PurgeTick) - PurgeTick = m_aSnapshots[Client][SNAP_PREV]->m_Tick; - if(m_aSnapshots[Client][SNAP_CURRENT] && m_aSnapshots[Client][SNAP_CURRENT]->m_Tick < PurgeTick) - PurgeTick = m_aSnapshots[Client][SNAP_CURRENT]->m_Tick; - m_SnapshotStorage[Client].PurgeUntil(PurgeTick); + if(m_aSnapshots[Conn][SNAP_PREV] && m_aSnapshots[Conn][SNAP_PREV]->m_Tick < PurgeTick) + PurgeTick = m_aSnapshots[Conn][SNAP_PREV]->m_Tick; + if(m_aSnapshots[Conn][SNAP_CURRENT] && m_aSnapshots[Conn][SNAP_CURRENT]->m_Tick < PurgeTick) + PurgeTick = m_aSnapshots[Conn][SNAP_CURRENT]->m_Tick; + m_SnapshotStorage[Conn].PurgeUntil(PurgeTick); // add new - m_SnapshotStorage[Client].Add(GameTick, time_get(), SnapSize, pTmpBuffer3, 1); + m_SnapshotStorage[Conn].Add(GameTick, time_get(), SnapSize, pTmpBuffer3, 1); // for antiping: if the projectile netobjects from the server contains extra data, this is removed and the original content restored before recording demo unsigned char aExtraInfoRemoved[CSnapshot::MAX_SIZE]; @@ -2031,12 +2031,12 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) } // apply snapshot, cycle pointers - m_ReceivedSnapshots[Client]++; + m_ReceivedSnapshots[Conn]++; - m_CurrentRecvTick[Client] = GameTick; + m_CurrentRecvTick[Conn] = GameTick; // we got two snapshots until we see us self as connected - if(m_ReceivedSnapshots[Client] == 2) + if(m_ReceivedSnapshots[Conn] == 2) { // start at 200ms and work from there if(!Dummy) @@ -2045,9 +2045,9 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) m_PredictedTime.SetAdjustSpeed(1, 1000.0f); m_PredictedTime.UpdateMargin(PredictionMargin() * time_freq() / 1000); } - m_GameTime[Client].Init((GameTick - 1) * time_freq() / 50); - m_aSnapshots[Client][SNAP_PREV] = m_SnapshotStorage[Client].m_pFirst; - m_aSnapshots[Client][SNAP_CURRENT] = m_SnapshotStorage[Client].m_pLast; + m_GameTime[Conn].Init((GameTick - 1) * time_freq() / 50); + m_aSnapshots[Conn][SNAP_PREV] = m_SnapshotStorage[Conn].m_pFirst; + m_aSnapshots[Conn][SNAP_CURRENT] = m_SnapshotStorage[Conn].m_pLast; if(!Dummy) { m_LocalStartTime = time_get(); @@ -2064,15 +2064,15 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) } // adjust game time - if(m_ReceivedSnapshots[Client] > 2) + if(m_ReceivedSnapshots[Conn] > 2) { - int64_t Now = m_GameTime[Client].Get(time_get()); + int64_t Now = m_GameTime[Conn].Get(time_get()); int64_t TickStart = GameTick * time_freq() / 50; int64_t TimeLeft = (TickStart - Now) * 1000 / time_freq(); - m_GameTime[Client].Update(&m_GametimeMarginGraph, (GameTick - 1) * time_freq() / 50, TimeLeft, 0); + m_GameTime[Conn].Update(&m_GametimeMarginGraph, (GameTick - 1) * time_freq() / 50, TimeLeft, 0); } - if(m_ReceivedSnapshots[Client] > 50 && !m_CodeRunAfterJoin[Client]) + if(m_ReceivedSnapshots[Conn] > 50 && !m_CodeRunAfterJoin[Conn]) { if(m_ServerCapabilities.m_ChatTimeoutCode || ShouldSendChatTimeoutCodeHeuristic()) { @@ -2081,26 +2081,26 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) char aBuf[256]; if(g_Config.m_ClRunOnJoin[0]) { - str_format(aBuf, sizeof(aBuf), "/mc;timeout %s;%s", m_aTimeoutCodes[Client], g_Config.m_ClRunOnJoin); + str_format(aBuf, sizeof(aBuf), "/mc;timeout %s;%s", m_aTimeoutCodes[Conn], g_Config.m_ClRunOnJoin); } else { - str_format(aBuf, sizeof(aBuf), "/timeout %s", m_aTimeoutCodes[Client]); + str_format(aBuf, sizeof(aBuf), "/timeout %s", m_aTimeoutCodes[Conn]); } Msg.m_pMessage = aBuf; CMsgPacker Packer(Msg.MsgID(), false); Msg.Pack(&Packer); - SendMsg(Client, &Packer, MSGFLAG_VITAL); + SendMsg(Conn, &Packer, MSGFLAG_VITAL); } - m_CodeRunAfterJoin[Client] = true; + m_CodeRunAfterJoin[Conn] = true; } // ack snapshot - m_AckGameTick[Client] = GameTick; + m_AckGameTick[Conn] = GameTick; } } } - else if(Client == CLIENT_MAIN && Msg == NETMSG_RCONTYPE) + else if(Conn == CONN_MAIN && Msg == NETMSG_RCONTYPE) { bool UsernameReq = Unpacker.GetInt() & 1; GameClient()->OnRconType(UsernameReq); @@ -2118,7 +2118,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy) DemoRecorder.RecordMessage(pPacket->m_pData, pPacket->m_DataSize); } - GameClient()->OnMessage(Msg, &Unpacker, Client, Dummy); + GameClient()->OnMessage(Msg, &Unpacker, Conn, Dummy); } } } @@ -2319,26 +2319,26 @@ void CClient::PumpNetwork() if(State() != IClient::STATE_DEMOPLAYBACK) { // check for errors - if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITTING && m_NetClient[CLIENT_MAIN].State() == NETSTATE_OFFLINE) + if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITTING && m_NetClient[CONN_MAIN].State() == NETSTATE_OFFLINE) { SetState(IClient::STATE_OFFLINE); Disconnect(); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "offline error='%s'", m_NetClient[CLIENT_MAIN].ErrorString()); + str_format(aBuf, sizeof(aBuf), "offline error='%s'", m_NetClient[CONN_MAIN].ErrorString()); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf, ClientNetworkErrPrintColor); } if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITTING && m_DummyConnected && - m_NetClient[CLIENT_DUMMY].State() == NETSTATE_OFFLINE) + m_NetClient[CONN_DUMMY].State() == NETSTATE_OFFLINE) { DummyDisconnect(0); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "offline dummy error='%s'", m_NetClient[CLIENT_DUMMY].ErrorString()); + str_format(aBuf, sizeof(aBuf), "offline dummy error='%s'", m_NetClient[CONN_DUMMY].ErrorString()); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf, ClientNetworkErrPrintColor); } // - if(State() == IClient::STATE_CONNECTING && m_NetClient[CLIENT_MAIN].State() == NETSTATE_ONLINE) + if(State() == IClient::STATE_CONNECTING && m_NetClient[CONN_MAIN].State() == NETSTATE_ONLINE) { // we switched to online m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", "connected, sending info", ClientNetworkPrintColor); @@ -2349,7 +2349,7 @@ void CClient::PumpNetwork() // process packets CNetChunk Packet; - for(int i = 0; i < NUM_CLIENTS; i++) + for(int i = 0; i < NUM_CONNS; i++) { while(m_NetClient[i].Recv(&Packet)) { @@ -2404,7 +2404,7 @@ void CClient::OnDemoPlayerMessage(void *pData, int Size) } if(!Sys) - GameClient()->OnMessage(Msg, &Unpacker, CLIENT_MAIN, false); + GameClient()->OnMessage(Msg, &Unpacker, CONN_MAIN, false); } /* const IDemoPlayer::CInfo *client_demoplayer_getinfo() @@ -2632,7 +2632,7 @@ void CClient::Update() { CMsgPacker Msg(NETMSG_PINGEX, true); Msg.AddRaw(&m_CurrentServerPingUuid, sizeof(m_CurrentServerPingUuid)); - SendMsg(CLIENT_MAIN, &Msg, MSGFLAG_FLUSH); + SendMsg(CONN_MAIN, &Msg, MSGFLAG_FLUSH); } m_CurrentServerCurrentPingTime = Now; m_CurrentServerNextPingTime = Now + 600 * Freq; // ping every 10 minutes @@ -2783,7 +2783,7 @@ void CClient::InitInterfaces() m_DemoEditor.Init(m_pGameClient->NetVersion(), &m_SnapshotDelta, m_pConsole, m_pStorage); - m_ServerBrowser.SetBaseInfo(&m_NetClient[CLIENT_CONTACT], m_pGameClient->NetVersion()); + m_ServerBrowser.SetBaseInfo(&m_NetClient[CONN_CONTACT], m_pGameClient->NetVersion()); HttpInit(m_pStorage); @@ -2876,7 +2876,7 @@ void CClient::Run() } for(unsigned int i = 0; i < sizeof(m_NetClient) / sizeof(m_NetClient[0]); i++) { - BindAddr.port = i == CLIENT_MAIN ? g_Config.m_ClPort : i == CLIENT_DUMMY ? g_Config.m_ClDummyPort : g_Config.m_ClContactPort; + BindAddr.port = i == CONN_MAIN ? g_Config.m_ClPort : i == CONN_DUMMY ? g_Config.m_ClDummyPort : g_Config.m_ClContactPort; while(BindAddr.port == 0 || !m_NetClient[i].Open(BindAddr, 0)) { BindAddr.port = (secure_rand() % 64511) + 1024; @@ -2986,7 +2986,7 @@ void CClient::Run() } // progress on dummy connect if security token handshake skipped/passed - if(m_DummySendConnInfo && !m_NetClient[CLIENT_DUMMY].SecurityTokenUnknown()) + if(m_DummySendConnInfo && !m_NetClient[CONN_DUMMY].SecurityTokenUnknown()) { m_DummySendConnInfo = false; @@ -2995,26 +2995,26 @@ void CClient::Run() MsgVer.AddRaw(&m_ConnectionID, sizeof(m_ConnectionID)); MsgVer.AddInt(GameClient()->DDNetVersion()); MsgVer.AddString(GameClient()->DDNetVersionStr(), 0); - SendMsg(CLIENT_DUMMY, &MsgVer, MSGFLAG_VITAL); + SendMsg(CONN_DUMMY, &MsgVer, MSGFLAG_VITAL); CMsgPacker MsgInfo(NETMSG_INFO, true); MsgInfo.AddString(GameClient()->NetVersion(), 128); MsgInfo.AddString(m_Password, 128); - SendMsg(CLIENT_DUMMY, &MsgInfo, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_DUMMY, &MsgInfo, MSGFLAG_VITAL | MSGFLAG_FLUSH); // update netclient - m_NetClient[CLIENT_DUMMY].Update(); + m_NetClient[CONN_DUMMY].Update(); // send ready CMsgPacker MsgReady(NETMSG_READY, true); - SendMsg(CLIENT_DUMMY, &MsgReady, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_DUMMY, &MsgReady, MSGFLAG_VITAL | MSGFLAG_FLUSH); // startinfo GameClient()->SendDummyInfo(true); // send enter game an finish the connection CMsgPacker MsgEnter(NETMSG_ENTERGAME, true); - SendMsg(CLIENT_DUMMY, &MsgEnter, MSGFLAG_VITAL | MSGFLAG_FLUSH); + SendMsg(CONN_DUMMY, &MsgEnter, MSGFLAG_VITAL | MSGFLAG_FLUSH); } // update input @@ -3196,7 +3196,7 @@ void CClient::Run() { SleepTimeInMicroSeconds = ((int64_t)1000000 / (int64_t)g_Config.m_ClRefreshRate) - (Now - LastTime); if(SleepTimeInMicroSeconds > (int64_t)0) - net_socket_read_wait(m_NetClient[CLIENT_MAIN].m_Socket, SleepTimeInMicroSeconds); + net_socket_read_wait(m_NetClient[CONN_MAIN].m_Socket, SleepTimeInMicroSeconds); Slept = true; } if(Slept) @@ -3301,7 +3301,7 @@ void CClient::Con_Ping(IConsole::IResult *pResult, void *pUserData) CClient *pSelf = (CClient *)pUserData; CMsgPacker Msg(NETMSG_PING, true); - pSelf->SendMsg(CLIENT_MAIN, &Msg, 0); + pSelf->SendMsg(CONN_MAIN, &Msg, 0); pSelf->m_PingStartTime = time_get(); } @@ -3573,7 +3573,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType) io_close(File); Disconnect(); - m_NetClient[CLIENT_MAIN].ResetErrorString(); + m_NetClient[CONN_MAIN].ResetErrorString(); // try to start playback m_DemoPlayer.SetListener(this); diff --git a/src/engine/client/client.h b/src/engine/client/client.h index c796f60bc..fa61394fc 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -116,7 +116,7 @@ class CClient : public IClient, public CDemoPlayer::IListener NUM_SNAPSHOT_TYPES = 2, }; - class CNetClient m_NetClient[NUM_CLIENTS]; + class CNetClient m_NetClient[NUM_CONNS]; class CDemoPlayer m_DemoPlayer; class CDemoRecorder m_DemoRecorder[RECORDER_MAX]; class CDemoEditor m_DemoEditor; @@ -299,12 +299,12 @@ public: CClient(); // ----- send functions ----- - virtual int SendMsg(int Client, CMsgPacker *pMsg, int Flags); + virtual int SendMsg(int Conn, CMsgPacker *pMsg, int Flags); // Send via the currently active client (main/dummy) virtual int SendMsgActive(CMsgPacker *pMsg, int Flags); void SendInfo(); - void SendEnterGame(int Client); + void SendEnterGame(int Conn); void SendReady(); void SendMapRequest(); @@ -333,7 +333,7 @@ public: // called when the map is loaded and we should init for a new round void OnEnterGame(bool Dummy); - virtual void EnterGame(int Client); + virtual void EnterGame(int Conn); virtual void Connect(const char *pAddress, const char *pPassword = NULL); void DisconnectWithReason(const char *pReason); @@ -377,7 +377,7 @@ public: void ProcessConnlessPacket(CNetChunk *pPacket); void ProcessServerInfo(int Type, NETADDR *pFrom, const void *pData, int DataSize); - void ProcessServerPacket(CNetChunk *pPacket, int Client, bool Dummy); + void ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy); void ResetMapDownload(); void FinishMapDownload(); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index bdf26e04b..12b6fe1d4 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -659,7 +659,7 @@ void CGameClient::OnRelease() m_All.m_paComponents[i]->OnRelease(); } -void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Client, bool Dummy) +void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dummy) { // special messages if(MsgId == NETMSGTYPE_SV_TUNEPARAMS) @@ -682,9 +682,9 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Client, bool Du m_ServerMode = SERVERMODE_PURE; - m_ReceivedTuning[Client] = true; + m_ReceivedTuning[Conn] = true; // apply new tuning - m_Tuning[Client] = NewTuning; + m_Tuning[Conn] = NewTuning; return; } @@ -717,7 +717,7 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Client, bool Du if(MsgId == NETMSGTYPE_SV_READYTOENTER) { - this->Client()->EnterGame(Client); + Client()->EnterGame(Conn); } else if(MsgId == NETMSGTYPE_SV_EMOTICON) { @@ -725,8 +725,8 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Client, bool Du // apply m_aClients[pMsg->m_ClientID].m_Emoticon = pMsg->m_Emoticon; - m_aClients[pMsg->m_ClientID].m_EmoticonStartTick = this->Client()->GameTick(Client); - m_aClients[pMsg->m_ClientID].m_EmoticonStartFraction = this->Client()->IntraGameTickSincePrev(Client); + m_aClients[pMsg->m_ClientID].m_EmoticonStartTick = Client()->GameTick(Conn); + m_aClients[pMsg->m_ClientID].m_EmoticonStartFraction = Client()->IntraGameTickSincePrev(Conn); } else if(MsgId == NETMSGTYPE_SV_SOUNDGLOBAL) { @@ -1579,7 +1579,7 @@ void CGameClient::OnNewSnapshot() { continue; } - if(i == IClient::CLIENT_DUMMY && !Client()->DummyConnected()) + if(i == IClient::CONN_DUMMY && !Client()->DummyConnected()) { continue; } @@ -1620,9 +1620,9 @@ void CGameClient::OnNewSnapshot() CMsgPacker Packer(Msg.MsgID(), false); Msg.Pack(&Packer); if(ZoomToSend != m_LastZoom) - Client()->SendMsg(IClient::CLIENT_MAIN, &Packer, MSGFLAG_VITAL); + Client()->SendMsg(IClient::CONN_MAIN, &Packer, MSGFLAG_VITAL); if(Client()->DummyConnected()) - Client()->SendMsg(IClient::CLIENT_DUMMY, &Packer, MSGFLAG_VITAL); + Client()->SendMsg(IClient::CONN_DUMMY, &Packer, MSGFLAG_VITAL); m_LastZoom = ZoomToSend; m_LastScreenAspect = Graphics()->ScreenAspect(); } @@ -2022,7 +2022,7 @@ void CGameClient::SendInfo(bool Start) Msg.m_ColorFeet = g_Config.m_ClPlayerColorFeet; CMsgPacker Packer(Msg.MsgID(), false); Msg.Pack(&Packer); - Client()->SendMsg(IClient::CLIENT_MAIN, &Packer, MSGFLAG_VITAL); + Client()->SendMsg(IClient::CONN_MAIN, &Packer, MSGFLAG_VITAL); m_CheckInfo[0] = -1; } else @@ -2037,7 +2037,7 @@ void CGameClient::SendInfo(bool Start) Msg.m_ColorFeet = g_Config.m_ClPlayerColorFeet; CMsgPacker Packer(Msg.MsgID(), false); Msg.Pack(&Packer); - Client()->SendMsg(IClient::CLIENT_MAIN, &Packer, MSGFLAG_VITAL); + Client()->SendMsg(IClient::CONN_MAIN, &Packer, MSGFLAG_VITAL); m_CheckInfo[0] = Client()->GameTickSpeed(); } } @@ -2056,7 +2056,7 @@ void CGameClient::SendDummyInfo(bool Start) Msg.m_ColorFeet = g_Config.m_ClDummyColorFeet; CMsgPacker Packer(Msg.MsgID(), false); Msg.Pack(&Packer); - Client()->SendMsg(IClient::CLIENT_DUMMY, &Packer, MSGFLAG_VITAL); + Client()->SendMsg(IClient::CONN_DUMMY, &Packer, MSGFLAG_VITAL); m_CheckInfo[1] = -1; } else @@ -2071,7 +2071,7 @@ void CGameClient::SendDummyInfo(bool Start) Msg.m_ColorFeet = g_Config.m_ClDummyColorFeet; CMsgPacker Packer(Msg.MsgID(), false); Msg.Pack(&Packer); - Client()->SendMsg(IClient::CLIENT_DUMMY, &Packer, MSGFLAG_VITAL); + Client()->SendMsg(IClient::CONN_DUMMY, &Packer, MSGFLAG_VITAL); m_CheckInfo[1] = Client()->GameTickSpeed(); } } diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 0cdbf1ece..a989ec595 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -457,7 +457,7 @@ public: virtual void OnInit(); virtual void OnConsoleInit(); virtual void OnStateChange(int NewState, int OldState); - virtual void OnMessage(int MsgId, CUnpacker *pUnpacker, int Client, bool Dummy); + virtual void OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dummy); virtual void InvalidateSnapshot(); virtual void OnNewSnapshot(); virtual void OnPredict();