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
|
|
|
|
2022-06-16 17:50:46 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
|
2021-04-21 14:54:42 +00:00
|
|
|
#include <engine/console.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/serverbrowser.h>
|
Make sure headers compile standalone
Not planning to do this automatically, but at least cleaning it up once
provides some benefit. Every header should include what it uses.
$ for i in src/**/*.h; do j=${i#"src/"}; echo $j; echo "#include <$j>\nint main() { return 0; }" | /usr/bin/c++ -DCONF_OPENSSL -DCONF_SQL -DCONF_VIDEORECORDER -DCONF_WAVPACK_CLOSE_FILE -DCONF_WAVPACK_OPEN_FILE_INPUT_EX -DGAME_RELEASE_VERSION=\"15.0.5\" -DGLEW_STATIC -D_FORTIFY_SOURCE=2 -I/usr/include/freetype2 -I/usr/include/opus -I/usr/include/SDL2 -I/usr/include/wavpack -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -Isrc -I/usr/include/mysql -I/home/deen/sys/include/ -O2 -g -DNDEBUG -fdiagnostics-color=always -fstack-protector-all -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wformat=2 -Wno-nullability-completeness -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -std=gnu++11 -o /dev/null -x c++ -; done
Ignored: tuning.h, variables.h, config_common.h, mapitems_ex_types.h, mapbugs_list.h, protocol7.h, teehistorian_ex_chunks.h, protocol_ex_msgs.h, config.h, config_variables.h, external, keynames.h
2020-09-26 08:23:33 +00:00
|
|
|
#include <engine/shared/config.h>
|
2021-12-24 11:17:46 +00:00
|
|
|
#include <engine/shared/http.h>
|
2017-09-03 15:36:51 +00:00
|
|
|
#include <engine/shared/memheap.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-06-16 17:50:46 +00:00
|
|
|
class CNetClient;
|
|
|
|
class IConfigManager;
|
2018-07-11 20:46:04 +00:00
|
|
|
class IServerBrowserHttp;
|
2021-04-17 14:05:24 +00:00
|
|
|
class IServerBrowserPingCache;
|
2018-07-11 20:46:04 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CServerBrowser : public IServerBrowser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class CServerEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NETADDR m_Addr;
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t m_RequestTime;
|
2021-04-21 14:54:42 +00:00
|
|
|
bool m_RequestIgnoreInfo;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_GotInfo;
|
2017-03-29 10:56:13 +00:00
|
|
|
bool m_Request64Legacy;
|
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;
|
|
|
|
};
|
|
|
|
|
2019-03-24 22:15:38 +00:00
|
|
|
struct CNetworkCountry
|
2014-09-18 14:13:06 +00:00
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_SERVERS = 1024
|
|
|
|
};
|
|
|
|
|
|
|
|
char m_aName[256];
|
2014-09-19 21:52:09 +00:00
|
|
|
int m_FlagID;
|
2022-06-15 19:09:09 +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;
|
|
|
|
|
2020-09-26 19:41:58 +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)
|
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
m_vServers[m_NumServers] = Addr;
|
2014-12-14 15:45:18 +00:00
|
|
|
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
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
MAX_FAVORITES = 2048,
|
2020-10-10 23:00:56 +00:00
|
|
|
MAX_COUNTRIES = 32,
|
2020-09-26 19:41:58 +00:00
|
|
|
MAX_TYPES = 32,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2019-03-24 22:15:38 +00:00
|
|
|
struct CNetwork
|
|
|
|
{
|
|
|
|
CNetworkCountry m_aCountries[MAX_COUNTRIES];
|
|
|
|
int m_NumCountries;
|
|
|
|
|
|
|
|
char m_aTypes[MAX_TYPES][32];
|
|
|
|
int m_NumTypes;
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CServerBrowser();
|
2017-09-03 15:36:51 +00:00
|
|
|
virtual ~CServerBrowser();
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
// interface functions
|
2022-05-17 20:13:44 +00:00
|
|
|
void Refresh(int Type) override;
|
|
|
|
bool IsRefreshing() const override;
|
|
|
|
bool IsGettingServerlist() const override;
|
|
|
|
int LoadingProgression() const override;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
int NumServers() const override { return m_NumServers; }
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
int Players(const CServerInfo &Item) const override
|
2018-08-21 07:03:29 +00:00
|
|
|
{
|
|
|
|
return g_Config.m_BrFilterSpectators ? Item.m_NumPlayers : Item.m_NumClients;
|
|
|
|
}
|
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
int Max(const CServerInfo &Item) const override
|
2018-08-21 07:03:29 +00:00
|
|
|
{
|
|
|
|
return g_Config.m_BrFilterSpectators ? Item.m_MaxPlayers : Item.m_MaxClients;
|
|
|
|
}
|
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
int NumSortedServers() const override { return m_NumSortedServers; }
|
|
|
|
const CServerInfo *SortedGet(int Index) const override;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
bool GotInfo(const NETADDR &Addr) const override;
|
|
|
|
bool IsFavorite(const NETADDR &Addr) const override;
|
|
|
|
bool IsFavoritePingAllowed(const NETADDR &Addr) const override;
|
|
|
|
void AddFavorite(const NETADDR &Addr) override;
|
|
|
|
void FavoriteAllowPing(const NETADDR &Addr, bool AllowPing) override;
|
|
|
|
void RemoveFavorite(const NETADDR &Addr) override;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
const char *GetTutorialServer() override;
|
2017-08-30 19:34:01 +00:00
|
|
|
void LoadDDNetRanks();
|
2019-03-19 06:57:09 +00:00
|
|
|
void RecheckOfficial();
|
2017-09-03 15:36:51 +00:00
|
|
|
void LoadDDNetServers();
|
|
|
|
void LoadDDNetInfoJson();
|
|
|
|
const json_value *LoadDDNetInfo();
|
2017-08-30 19:34:01 +00:00
|
|
|
int HasRank(const char *pMap);
|
2022-05-17 20:13:44 +00:00
|
|
|
int NumCountries(int Network) override { return m_aNetworks[Network].m_NumCountries; }
|
|
|
|
int GetCountryFlag(int Network, int Index) override { return m_aNetworks[Network].m_aCountries[Index].m_FlagID; }
|
|
|
|
const char *GetCountryName(int Network, int Index) override { return m_aNetworks[Network].m_aCountries[Index].m_aName; }
|
2014-12-14 15:45:18 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
int NumTypes(int Network) override { return m_aNetworks[Network].m_NumTypes; }
|
|
|
|
const char *GetType(int Network, int Index) override { return m_aNetworks[Network].m_aTypes[Index]; }
|
2014-12-14 15:45:18 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
void DDNetFilterAdd(char *pFilter, const char *pName) override;
|
|
|
|
void DDNetFilterRem(char *pFilter, const char *pName) override;
|
|
|
|
bool DDNetFiltered(char *pFilter, const char *pName) override;
|
|
|
|
void CountryFilterClean(int Network) override;
|
|
|
|
void TypeFilterClean(int Network) override;
|
2014-12-14 15:45:18 +00:00
|
|
|
|
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);
|
2021-06-09 15:29:06 +00:00
|
|
|
void RequestCurrentServer(const NETADDR &Addr) const;
|
|
|
|
void RequestCurrentServerWithRandomToken(const NETADDR &Addr, int *pBasicToken, int *pToken) const;
|
2021-04-23 21:12:16 +00:00
|
|
|
void SetCurrentServerPing(const NETADDR &Addr, int Ping);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void SetBaseInfo(class CNetClient *pClient, const char *pNetVersion);
|
2021-06-02 22:27:00 +00:00
|
|
|
void OnInit();
|
2010-05-29 07:25:38 +00:00
|
|
|
|
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);
|
2022-05-17 20:13:44 +00:00
|
|
|
int GetCurrentType() override { return m_ServerlistType; }
|
2014-01-08 05:15:56 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
private:
|
|
|
|
CNetClient *m_pNetClient;
|
2010-08-17 22:06:00 +00:00
|
|
|
class IConsole *m_pConsole;
|
2018-07-11 20:46:04 +00:00
|
|
|
class IEngine *m_pEngine;
|
2011-03-23 12:06:35 +00:00
|
|
|
class IFriends *m_pFriends;
|
2021-04-17 14:05:24 +00:00
|
|
|
class IStorage *m_pStorage;
|
2010-05-29 07:25:38 +00:00
|
|
|
char m_aNetVersion[128];
|
|
|
|
|
2018-07-11 20:46:04 +00:00
|
|
|
bool m_RefreshingHttp = false;
|
|
|
|
IServerBrowserHttp *m_pHttp = nullptr;
|
2021-04-17 14:05:24 +00:00
|
|
|
IServerBrowserPingCache *m_pPingCache = nullptr;
|
2021-05-13 00:46:28 +00:00
|
|
|
const char *m_pHttpPrevBestUrl = nullptr;
|
2018-07-11 20:46:04 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CHeap m_ServerlistHeap;
|
|
|
|
CServerEntry **m_ppServerlist;
|
|
|
|
int *m_pSortedServerlist;
|
|
|
|
|
|
|
|
NETADDR m_aFavoriteServers[MAX_FAVORITES];
|
2021-05-12 19:06:08 +00:00
|
|
|
bool m_aFavoriteServersAllowPing[MAX_FAVORITES];
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_NumFavoriteServers;
|
|
|
|
|
2019-03-24 22:15:38 +00:00
|
|
|
CNetwork m_aNetworks[NUM_NETWORKS];
|
2021-04-24 16:06:42 +00:00
|
|
|
int m_OwnLocation = CServerInfo::LOC_UNKNOWN;
|
2017-09-03 15:36:51 +00:00
|
|
|
|
|
|
|
json_value *m_pDDNetInfo;
|
2014-12-14 15:45:18 +00:00
|
|
|
|
2022-06-30 22:36:32 +00:00
|
|
|
CServerEntry *m_apServerlistIp[256]; // ip hash list
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
CServerEntry *m_pFirstReqServer; // request list
|
|
|
|
CServerEntry *m_pLastReqServer;
|
|
|
|
int m_NumRequests;
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2021-07-08 17:18:01 +00:00
|
|
|
// used instead of g_Config.br_max_requests to get more servers
|
2013-12-31 02:18:37 +00:00
|
|
|
int m_CurrentMaxRequests;
|
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
|
|
|
int m_ServerlistType;
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t m_BroadcastTime;
|
2017-10-14 19:58:23 +00:00
|
|
|
unsigned char m_aTokenSeed[16];
|
|
|
|
|
2020-12-22 10:13:51 +00:00
|
|
|
bool m_SortOnNextUpdate;
|
|
|
|
|
2021-05-12 19:06:08 +00:00
|
|
|
int FindFavorite(const NETADDR &Addr) const;
|
|
|
|
|
2017-10-14 19:58:23 +00:00
|
|
|
int GenerateToken(const NETADDR &Addr) const;
|
|
|
|
static int GetBasicToken(int Token);
|
|
|
|
static int GetExtraToken(int Token);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2017-10-14 19:58:23 +00:00
|
|
|
// sorting criteria
|
2010-05-29 07:25:38 +00:00
|
|
|
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;
|
2020-08-24 21:23:37 +00:00
|
|
|
bool SortCompareNumPlayersAndPing(int Index1, int Index2) const;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
void Filter();
|
|
|
|
void Sort();
|
|
|
|
int SortHash() const;
|
|
|
|
|
2021-07-08 17:18:01 +00:00
|
|
|
void CleanUp();
|
|
|
|
|
2018-07-11 20:46:04 +00:00
|
|
|
void UpdateFromHttp();
|
2010-05-29 07:25:38 +00:00
|
|
|
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);
|
|
|
|
|
2021-06-09 15:29:06 +00:00
|
|
|
void RequestImpl(const NETADDR &Addr, CServerEntry *pEntry, int *pBasicToken, int *pToken, bool RandomToken) const;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-04-21 14:54:42 +00:00
|
|
|
void RegisterCommands();
|
|
|
|
static void Con_LeakIpAddress(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void SetInfo(CServerEntry *pEntry, const CServerInfo &Info);
|
2022-01-22 12:44:22 +00:00
|
|
|
void SetLatency(NETADDR Addr, int Latency);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-01-10 12:47:07 +00:00
|
|
|
static void ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|