diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 0bcadde8f..723a0f841 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -2805,7 +2805,7 @@ void CClient::Update() m_CurrentServerInfoRequestTime >= 0 && time_get() > m_CurrentServerInfoRequestTime) { - m_ServerBrowser.RequestCurrentServer(m_ServerAddress, nullptr, nullptr); + m_ServerBrowser.RequestCurrentServer(m_ServerAddress); m_CurrentServerInfoRequestTime = time_get() + time_freq() * 2; } @@ -2824,7 +2824,7 @@ void CClient::Update() m_CurrentServerPingUuid = RandomUuid(); if(!m_ServerCapabilities.m_PingEx) { - m_ServerBrowser.RequestCurrentServer(m_ServerAddress, &m_CurrentServerPingBasicToken, &m_CurrentServerPingToken); + m_ServerBrowser.RequestCurrentServerWithRandomToken(m_ServerAddress, &m_CurrentServerPingBasicToken, &m_CurrentServerPingToken); } else { diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index aa36db592..eef100513 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -822,7 +822,7 @@ void CServerBrowser::Refresh(int Type) } } -void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry, int *pBasicToken, int *pToken) const +void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry, int *pBasicToken, int *pToken, bool RandomToken) const { unsigned char Buffer[sizeof(SERVERBROWSE_GETINFO) + 1]; CNetChunk Packet; @@ -837,6 +837,15 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry, int } int Token = GenerateToken(Addr); + if(RandomToken) + { + int AvoidBasicToken = GetBasicToken(Token); + do + { + secure_random_fill(&Token, sizeof(Token)); + Token &= 0xffffff; + } while(GetBasicToken(Token) == AvoidBasicToken); + } if(pToken) { *pToken = Token; @@ -893,9 +902,14 @@ void CServerBrowser::RequestImpl64(const NETADDR &Addr, CServerEntry *pEntry) co pEntry->m_RequestTime = time_get(); } -void CServerBrowser::RequestCurrentServer(const NETADDR &Addr, int *pBasicToken, int *pToken) const +void CServerBrowser::RequestCurrentServer(const NETADDR &Addr) const { - RequestImpl(Addr, nullptr, pBasicToken, pToken); + RequestImpl(Addr, nullptr, nullptr, nullptr, false); +} + +void CServerBrowser::RequestCurrentServerWithRandomToken(const NETADDR &Addr, int *pBasicToken, int *pToken) const +{ + RequestImpl(Addr, nullptr, pBasicToken, pToken, true); } void CServerBrowser::SetCurrentServerPing(const NETADDR &Addr, int Ping) @@ -1189,7 +1203,7 @@ void CServerBrowser::Update(bool ForceResort) if(pEntry->m_Request64Legacy) RequestImpl64(pEntry->m_Addr, pEntry); else - RequestImpl(pEntry->m_Addr, pEntry, nullptr, nullptr); + RequestImpl(pEntry->m_Addr, pEntry, nullptr, nullptr, false); } Count++; diff --git a/src/engine/client/serverbrowser.h b/src/engine/client/serverbrowser.h index 7a81aee38..125d16d71 100644 --- a/src/engine/client/serverbrowser.h +++ b/src/engine/client/serverbrowser.h @@ -132,7 +132,8 @@ public: // void Update(bool ForceResort); void Set(const NETADDR &Addr, int Type, int Token, const CServerInfo *pInfo); - void RequestCurrentServer(const NETADDR &Addr, int *pBasicToken, int *pToken) const; + void RequestCurrentServer(const NETADDR &Addr) const; + void RequestCurrentServerWithRandomToken(const NETADDR &Addr, int *pBasicToken, int *pToken) const; void SetCurrentServerPing(const NETADDR &Addr, int Ping); void SetBaseInfo(class CNetClient *pClient, const char *pNetVersion); @@ -221,7 +222,7 @@ private: void RemoveRequest(CServerEntry *pEntry); - void RequestImpl(const NETADDR &Addr, CServerEntry *pEntry, int *pBasicToken, int *pToken) const; + void RequestImpl(const NETADDR &Addr, CServerEntry *pEntry, int *pBasicToken, int *pToken, bool RandomToken) const; void RegisterCommands(); static void Con_LeakIpAddress(IConsole::IResult *pResult, void *pUserData);