2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2011-03-27 16:00:54 +00:00
|
|
|
#ifndef ENGINE_CLIENT_SERVERBROWSER_H
|
|
|
|
#define ENGINE_CLIENT_SERVERBROWSER_H
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#include <engine/serverbrowser.h>
|
|
|
|
|
|
|
|
class CServerBrowser : public IServerBrowser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class CServerEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NETADDR m_Addr;
|
|
|
|
int64 m_RequestTime;
|
|
|
|
int m_GotInfo;
|
2017-03-29 10:56:13 +00:00
|
|
|
bool m_Request64Legacy;
|
|
|
|
int m_ExtraToken;
|
2010-05-29 07:25:38 +00:00
|
|
|
CServerInfo m_Info;
|
|
|
|
|
|
|
|
CServerEntry *m_pNextIp; // ip hashed list
|
|
|
|
|
|
|
|
CServerEntry *m_pPrevReq; // request list
|
|
|
|
CServerEntry *m_pNextReq;
|
|
|
|
};
|
|
|
|
|
2014-09-18 14:13:06 +00:00
|
|
|
class CDDNetCountry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_SERVERS = 1024
|
|
|
|
};
|
|
|
|
|
|
|
|
char m_aName[256];
|
2014-09-19 21:52:09 +00:00
|
|
|
int m_FlagID;
|
2014-09-18 14:13:06 +00:00
|
|
|
NETADDR m_aServers[MAX_SERVERS];
|
2014-12-14 15:45:18 +00:00
|
|
|
char m_aTypes[MAX_SERVERS][32];
|
2014-09-18 14:13:06 +00:00
|
|
|
int m_NumServers;
|
|
|
|
|
2014-09-19 21:52:09 +00:00
|
|
|
void Reset() { m_NumServers = 0; m_FlagID = -1; m_aName[0] = '\0'; };
|
2014-12-14 15:45:18 +00:00
|
|
|
/*void Add(NETADDR Addr, char* pType) {
|
|
|
|
if (m_NumServers < MAX_SERVERS)
|
|
|
|
{
|
|
|
|
m_aServers[m_NumServers] = Addr;
|
|
|
|
str_copy(m_aTypes[m_NumServers], pType, sizeof(m_aTypes[0]));
|
|
|
|
m_NumServers++;
|
|
|
|
}
|
|
|
|
};*/
|
2014-09-18 14:13:06 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
enum
|
|
|
|
{
|
2014-09-13 14:36:25 +00:00
|
|
|
MAX_FAVORITES=2048,
|
2014-09-18 14:13:06 +00:00
|
|
|
MAX_DDNET_COUNTRIES=16,
|
2014-12-14 15:45:18 +00:00
|
|
|
MAX_DDNET_TYPES=32,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CServerBrowser();
|
|
|
|
|
|
|
|
// interface functions
|
|
|
|
void Refresh(int Type);
|
2010-11-17 11:43:24 +00:00
|
|
|
bool IsRefreshing() const;
|
2010-05-29 07:25:38 +00:00
|
|
|
bool IsRefreshingMasters() const;
|
2010-10-30 16:56:57 +00:00
|
|
|
int LoadingProgression() const;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-09-13 14:36:25 +00:00
|
|
|
void LoadDDNet();
|
2014-09-19 21:52:09 +00:00
|
|
|
int NumDDNetCountries() { return m_NumDDNetCountries; };
|
|
|
|
int GetDDNetCountryFlag(int Index) { return m_aDDNetCountries[Index].m_FlagID; };
|
|
|
|
const char *GetDDNetCountryName(int Index) { return m_aDDNetCountries[Index].m_aName; };
|
2014-12-14 15:45:18 +00:00
|
|
|
|
|
|
|
int NumDDNetTypes() { return m_NumDDNetTypes; };
|
|
|
|
const char *GetDDNetType(int Index) { return m_aDDNetTypes[Index]; };
|
|
|
|
|
|
|
|
void DDNetFilterAdd(char *pFilter, const char *pName);
|
|
|
|
void DDNetFilterRem(char *pFilter, const char *pName);
|
|
|
|
bool DDNetFiltered(char *pFilter, const char *pName);
|
2014-09-19 21:52:09 +00:00
|
|
|
void DDNetCountryFilterClean();
|
2014-12-14 15:45:18 +00:00
|
|
|
void DDNetTypeFilterClean();
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
//
|
2011-03-18 18:03:13 +00:00
|
|
|
void Update(bool ForceResort);
|
2010-05-29 07:25:38 +00:00
|
|
|
void Set(const NETADDR &Addr, int Type, int Token, const CServerInfo *pInfo);
|
2017-03-29 10:56:13 +00:00
|
|
|
void RequestCurrentServer(const NETADDR &Addr) const;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void SetBaseInfo(class CNetClient *pClient, const char *pNetVersion);
|
|
|
|
|
2014-01-14 20:40:55 +00:00
|
|
|
void RequestImpl64(const NETADDR &Addr, CServerEntry *pEntry) const;
|
|
|
|
void QueueRequest(CServerEntry *pEntry);
|
2014-01-08 05:15:56 +00:00
|
|
|
CServerEntry *Find(const NETADDR &Addr);
|
2015-05-11 19:51:06 +00:00
|
|
|
int GetCurrentType() { return m_ServerlistType; };
|
2014-01-08 05:15:56 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
private:
|
|
|
|
CNetClient *m_pNetClient;
|
|
|
|
IMasterServer *m_pMasterServer;
|
2010-08-17 22:06:00 +00:00
|
|
|
class IConsole *m_pConsole;
|
2011-03-23 12:06:35 +00:00
|
|
|
class IFriends *m_pFriends;
|
2010-05-29 07:25:38 +00:00
|
|
|
char m_aNetVersion[128];
|
|
|
|
|
|
|
|
CHeap m_ServerlistHeap;
|
|
|
|
CServerEntry **m_ppServerlist;
|
|
|
|
int *m_pSortedServerlist;
|
|
|
|
|
|
|
|
NETADDR m_aFavoriteServers[MAX_FAVORITES];
|
|
|
|
int m_NumFavoriteServers;
|
|
|
|
|
2014-09-18 14:13:06 +00:00
|
|
|
CDDNetCountry m_aDDNetCountries[MAX_DDNET_COUNTRIES];
|
|
|
|
int m_NumDDNetCountries;
|
2014-09-13 14:36:25 +00:00
|
|
|
|
2014-12-14 15:45:18 +00:00
|
|
|
char m_aDDNetTypes[MAX_DDNET_TYPES][32];
|
|
|
|
int m_NumDDNetTypes;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CServerEntry *m_aServerlistIp[256]; // ip hash list
|
|
|
|
|
|
|
|
CServerEntry *m_pFirstReqServer; // request list
|
|
|
|
CServerEntry *m_pLastReqServer;
|
|
|
|
int m_NumRequests;
|
2013-12-31 01:34:33 +00:00
|
|
|
int m_MasterServerCount;
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2013-12-31 02:18:37 +00:00
|
|
|
//used instead of g_Config.br_max_requests to get more servers
|
|
|
|
int m_CurrentMaxRequests;
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2013-12-31 01:34:33 +00:00
|
|
|
int m_LastPacketTick;
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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];
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// the token is to keep server refresh separated from each other
|
|
|
|
int m_CurrentToken;
|
|
|
|
|
|
|
|
int m_ServerlistType;
|
|
|
|
int64 m_BroadcastTime;
|
2017-03-29 10:56:13 +00:00
|
|
|
int m_BroadcastExtraToken;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
// 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 SortCompareNumPlayers(int Index1, int Index2) const;
|
2011-03-20 14:33:49 +00:00
|
|
|
bool SortCompareNumClients(int Index1, int Index2) const;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
void Filter();
|
|
|
|
void Sort();
|
|
|
|
int SortHash() const;
|
|
|
|
|
|
|
|
CServerEntry *Add(const NETADDR &Addr);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void RemoveRequest(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
|