mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
made server info requests more strict
Conflicts: src/engine/client/serverbrowser.cpp
This commit is contained in:
parent
e592d1b1fa
commit
b9e4c7e979
|
@ -54,7 +54,7 @@ CServerBrowser::CServerBrowser()
|
||||||
m_NumPlayers = 0;
|
m_NumPlayers = 0;
|
||||||
|
|
||||||
// the token is to keep server refresh separated from each other
|
// the token is to keep server refresh separated from each other
|
||||||
m_CurrentToken = 1;
|
m_CurrentLanToken = 1;
|
||||||
|
|
||||||
m_ServerlistType = 0;
|
m_ServerlistType = 0;
|
||||||
m_BroadcastTime = 0;
|
m_BroadcastTime = 0;
|
||||||
|
@ -143,8 +143,8 @@ bool CServerBrowser::CServerFilter::SortCompareName(int Index1, int Index2) cons
|
||||||
CServerEntry *a = m_pServerBrowser->m_ppServerlist[Index1];
|
CServerEntry *a = m_pServerBrowser->m_ppServerlist[Index1];
|
||||||
CServerEntry *b = m_pServerBrowser->m_ppServerlist[Index2];
|
CServerEntry *b = m_pServerBrowser->m_ppServerlist[Index2];
|
||||||
// make sure empty entries are listed last
|
// make sure empty entries are listed last
|
||||||
return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp_nocase(a->m_Info.m_aName, b->m_Info.m_aName) < 0 :
|
return (a->m_InfoState == CServerEntry::STATE_READY && b->m_InfoState == CServerEntry::STATE_READY) || (a->m_InfoState != CServerEntry::STATE_READY && b->m_InfoState != CServerEntry::STATE_READY) ? str_comp_nocase(a->m_Info.m_aName, b->m_Info.m_aName) < 0 :
|
||||||
a->m_GotInfo ? true : false;
|
a->m_InfoState == CServerEntry::STATE_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServerBrowser::CServerFilter::SortCompareMap(int Index1, int Index2) const
|
bool CServerBrowser::CServerFilter::SortCompareMap(int Index1, int Index2) const
|
||||||
|
@ -426,7 +426,7 @@ void CServerBrowser::SetInfo(CServerEntry *pEntry, const CServerInfo &Info)
|
||||||
|
|
||||||
m_NumPlayers += pEntry->m_Info.m_NumPlayers;
|
m_NumPlayers += pEntry->m_Info.m_NumPlayers;
|
||||||
|
|
||||||
pEntry->m_GotInfo = 1;
|
pEntry->m_InfoState = CServerEntry::STATE_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr)
|
CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr)
|
||||||
|
@ -437,6 +437,8 @@ CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr)
|
||||||
|
|
||||||
// set the info
|
// set the info
|
||||||
pEntry->m_Addr = Addr;
|
pEntry->m_Addr = Addr;
|
||||||
|
pEntry->m_InfoState = CServerEntry::STATE_INVALID;
|
||||||
|
pEntry->m_CurrentToken = rand()%CServerEntry::MAX_TOKEN;
|
||||||
pEntry->m_Info.m_NetAddr = Addr;
|
pEntry->m_Info.m_NetAddr = Addr;
|
||||||
|
|
||||||
pEntry->m_Info.m_Latency = 999;
|
pEntry->m_Info.m_Latency = 999;
|
||||||
|
@ -510,13 +512,13 @@ void CServerBrowser::Set(const NETADDR &Addr, int Type, int Token, const CServer
|
||||||
}*/
|
}*/
|
||||||
else if(Type == SET_TOKEN)
|
else if(Type == SET_TOKEN)
|
||||||
{
|
{
|
||||||
if(Token != m_CurrentToken)
|
if(m_ServerlistType == IServerBrowser::TYPE_LAN && Token != m_CurrentLanToken)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pEntry = Find(Addr);
|
pEntry = Find(Addr);
|
||||||
if(!pEntry)
|
if(!pEntry && m_ServerlistType == IServerBrowser::TYPE_LAN)
|
||||||
pEntry = Add(Addr);
|
pEntry = Add(Addr);
|
||||||
if(pEntry)
|
if(pEntry && pEntry->m_InfoState == CServerEntry::STATE_PENDING && Token == pEntry->m_CurrentToken)
|
||||||
{
|
{
|
||||||
SetInfo(pEntry, *pInfo);
|
SetInfo(pEntry, *pInfo);
|
||||||
if(m_ServerlistType == IServerBrowser::TYPE_LAN)
|
if(m_ServerlistType == IServerBrowser::TYPE_LAN)
|
||||||
|
@ -548,7 +550,7 @@ void CServerBrowser::Refresh(int Type)
|
||||||
m_NumRequests = 0;
|
m_NumRequests = 0;
|
||||||
|
|
||||||
// next token
|
// next token
|
||||||
m_CurrentToken = (m_CurrentToken+1)&0xff;
|
m_CurrentLanToken = (m_CurrentLanToken+1)&0xff;
|
||||||
|
|
||||||
//
|
//
|
||||||
m_ServerlistType = Type;
|
m_ServerlistType = Type;
|
||||||
|
@ -560,7 +562,7 @@ void CServerBrowser::Refresh(int Type)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
mem_copy(Buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO));
|
mem_copy(Buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO));
|
||||||
Buffer[sizeof(SERVERBROWSE_GETINFO)] = m_CurrentToken;
|
Buffer[sizeof(SERVERBROWSE_GETINFO)] = m_CurrentLanToken;
|
||||||
|
|
||||||
/* do the broadcast version */
|
/* do the broadcast version */
|
||||||
Packet.m_ClientID = -1;
|
Packet.m_ClientID = -1;
|
||||||
|
@ -605,7 +607,7 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_copy(Buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO));
|
mem_copy(Buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO));
|
||||||
Buffer[sizeof(SERVERBROWSE_GETINFO)] = m_CurrentToken;
|
Buffer[sizeof(SERVERBROWSE_GETINFO)] = pEntry->m_CurrentToken;
|
||||||
|
|
||||||
Packet.m_ClientID = -1;
|
Packet.m_ClientID = -1;
|
||||||
Packet.m_Address = Addr;
|
Packet.m_Address = Addr;
|
||||||
|
@ -616,7 +618,10 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons
|
||||||
m_pNetClient->Send(&Packet);
|
m_pNetClient->Send(&Packet);
|
||||||
|
|
||||||
if(pEntry)
|
if(pEntry)
|
||||||
|
{
|
||||||
pEntry->m_RequestTime = time_get();
|
pEntry->m_RequestTime = time_get();
|
||||||
|
pEntry->m_InfoState = CServerEntry::STATE_PENDING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerBrowser::Request(const NETADDR &Addr) const
|
void CServerBrowser::Request(const NETADDR &Addr) const
|
||||||
|
|
|
@ -19,9 +19,18 @@ public:
|
||||||
class CServerEntry
|
class CServerEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STATE_INVALID=0,
|
||||||
|
STATE_PENDING,
|
||||||
|
STATE_READY,
|
||||||
|
MAX_TOKEN=0xFF
|
||||||
|
};
|
||||||
|
|
||||||
NETADDR m_Addr;
|
NETADDR m_Addr;
|
||||||
int64 m_RequestTime;
|
int64 m_RequestTime;
|
||||||
int m_GotInfo;
|
int m_InfoState;
|
||||||
|
int m_CurrentToken; // the token is to keep server refresh separated from each other
|
||||||
CServerInfo m_Info;
|
CServerInfo m_Info;
|
||||||
|
|
||||||
CServerEntry *m_pNextIp; // ip hashed list
|
CServerEntry *m_pNextIp; // ip hashed list
|
||||||
|
@ -160,7 +169,7 @@ private:
|
||||||
int m_NumPlayers;
|
int m_NumPlayers;
|
||||||
|
|
||||||
// the token is to keep server refresh separated from each other
|
// the token is to keep server refresh separated from each other
|
||||||
int m_CurrentToken;
|
int m_CurrentLanToken;
|
||||||
|
|
||||||
int m_ServerlistType;
|
int m_ServerlistType;
|
||||||
int64 m_BroadcastTime;
|
int64 m_BroadcastTime;
|
||||||
|
|
Loading…
Reference in a new issue