Refactored e to Event
[twcon.git] / src / engine / client / srvbrowse.h
blob876627bfaec16050114c3d0add084b98d87ea748
1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef ENGINE_CLIENT_SRVBROWSE_H
4 #define ENGINE_CLIENT_SRVBROWSE_H
6 #include <engine/serverbrowser.h>
8 class CServerBrowser : public IServerBrowser
10 public:
11 class CServerEntry
13 public:
14 NETADDR m_Addr;
15 int64 m_RequestTime;
16 int m_GotInfo;
17 CServerInfo m_Info;
19 CServerEntry *m_pNextIp; // ip hashed list
21 CServerEntry *m_pPrevReq; // request list
22 CServerEntry *m_pNextReq;
25 enum
27 MAX_FAVORITES=256
30 CServerBrowser();
32 // interface functions
33 void Refresh(int Type);
34 bool IsRefreshing() const;
35 bool IsRefreshingMasters() const;
36 int LoadingProgression() const;
38 int NumServers() const { return m_NumServers; }
40 int NumSortedServers() const { return m_NumSortedServers; }
41 const CServerInfo *SortedGet(int Index) const;
43 bool IsFavorite(const NETADDR &Addr) const;
44 void AddFavorite(const NETADDR &Addr);
45 void RemoveFavorite(const NETADDR &Addr);
48 void Update(bool ForceResort);
49 void Set(const NETADDR &Addr, int Type, int Token, const CServerInfo *pInfo);
50 void Request(const NETADDR &Addr) const;
52 void SetBaseInfo(class CNetClient *pClient, const char *pNetVersion);
54 private:
55 CNetClient *m_pNetClient;
56 IMasterServer *m_pMasterServer;
57 class IConsole *m_pConsole;
58 class IFriends *m_pFriends;
59 char m_aNetVersion[128];
61 CHeap m_ServerlistHeap;
62 CServerEntry **m_ppServerlist;
63 int *m_pSortedServerlist;
65 NETADDR m_aFavoriteServers[MAX_FAVORITES];
66 int m_NumFavoriteServers;
68 CServerEntry *m_aServerlistIp[256]; // ip hash list
70 CServerEntry *m_pFirstReqServer; // request list
71 CServerEntry *m_pLastReqServer;
72 int m_NumRequests;
74 int m_NeedRefresh;
76 int m_NumSortedServers;
77 int m_NumSortedServersCapacity;
78 int m_NumServers;
79 int m_NumServerCapacity;
81 int m_Sorthash;
82 char m_aFilterString[64];
83 char m_aFilterGametypeString[128];
85 // the token is to keep server refresh separated from each other
86 int m_CurrentToken;
88 int m_ServerlistType;
89 int64 m_BroadcastTime;
91 // sorting criterions
92 bool SortCompareName(int Index1, int Index2) const;
93 bool SortCompareMap(int Index1, int Index2) const;
94 bool SortComparePing(int Index1, int Index2) const;
95 bool SortCompareGametype(int Index1, int Index2) const;
96 bool SortCompareNumPlayers(int Index1, int Index2) const;
97 bool SortCompareNumClients(int Index1, int Index2) const;
100 void Filter();
101 void Sort();
102 int SortHash() const;
104 CServerEntry *Find(const NETADDR &Addr);
105 CServerEntry *Add(const NETADDR &Addr);
107 void RemoveRequest(CServerEntry *pEntry);
108 void QueueRequest(CServerEntry *pEntry);
110 void RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) const;
112 void SetInfo(CServerEntry *pEntry, const CServerInfo &Info);
114 static void ConfigSaveCallback(IConfig *pConfig, void *pUserData);
117 #endif