1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#ifndef ENGINE_CLIENT_SRVBROWSE_H
#define ENGINE_CLIENT_SRVBROWSE_H
#include <engine/serverbrowser.h>
class CServerBrowser : public IServerBrowser
{
public:
class CServerEntry
{
public:
NETADDR m_Addr;
int64 m_RequestTime;
int m_GotInfo;
CServerInfo m_Info;
CServerEntry *m_pNextIp; // ip hashed list
CServerEntry *m_pPrevReq; // request list
CServerEntry *m_pNextReq;
};
enum
{
MAX_FAVORITES=256
};
CServerBrowser();
// interface functions
void Refresh(int Type);
bool IsRefreshingMasters() const;
int NumServers() const { return m_NumServers; }
int NumSortedServers() const { return m_NumSortedServers; }
const CServerInfo *SortedGet(int Index) const;
bool IsFavorite(const NETADDR &Addr) const;
void AddFavorite(const NETADDR &Addr);
void RemoveFavorite(const NETADDR &Addr);
//
void Update();
void Set(const NETADDR &Addr, int Type, int Token, const CServerInfo *pInfo);
void Request(const NETADDR &Addr) const;
void SetBaseInfo(class CNetClient *pClient, const char *pNetVersion);
private:
CNetClient *m_pNetClient;
IMasterServer *m_pMasterServer;
char m_aNetVersion[128];
CHeap m_ServerlistHeap;
CServerEntry **m_ppServerlist;
int *m_pSortedServerlist;
NETADDR m_aFavoriteServers[MAX_FAVORITES];
int m_NumFavoriteServers;
CServerEntry *m_aServerlistIp[256]; // ip hash list
CServerEntry *m_pFirstReqServer; // request list
CServerEntry *m_pLastReqServer;
int m_NumRequests;
int m_NeedRefresh;
int m_NumSortedServers;
int m_NumSortedServersCapacity;
int m_NumServers;
int m_NumServerCapacity;
int m_Sorthash;
char m_aFilterString[64];
char m_aFilterGametypeString[128];
// the token is to keep server refresh separated from each other
int m_CurrentToken;
int m_ServerlistType;
int64 m_BroadcastTime;
// sorting criterions
bool SortCompareName(int Index1, int Index2) const;
bool SortCompareMap(int Index1, int Index2) const;
bool SortComparePing(int Index1, int Index2) const;
bool SortCompareGametype(int Index1, int Index2) const;
bool SortCompareProgression(int Index1, int Index2) const;
bool SortCompareNumPlayers(int Index1, int Index2) const;
//
void Filter();
void Sort();
int SortHash() const;
CServerEntry *Find(const NETADDR &Addr);
CServerEntry *Add(const NETADDR &Addr);
void RemoveRequest(CServerEntry *pEntry);
void QueueRequest(CServerEntry *pEntry);
void RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) const;
void SetInfo(CServerEntry *pEntry, const CServerInfo &Info);
static void ConfigSaveCallback(IConfig *pConfig, void *pUserData);
};
#endif
|