ddnet/src/engine/serverbrowser.h

178 lines
4.3 KiB
C
Raw Normal View History

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. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_SERVERBROWSER_H
#define ENGINE_SERVERBROWSER_H
2020-06-18 16:29:27 +00:00
#include <engine/map.h>
#include <engine/shared/protocol.h>
2010-05-29 07:25:38 +00:00
#include "kernel.h"
2018-08-23 07:57:35 +00:00
#define DDNET_INFO "ddnet-info.json"
class CUIElement;
2010-05-29 07:25:38 +00:00
class CServerInfo
{
public:
Add client-side HTTP server info Summary ======= The idea of this is that clients will not have to ping each server for server infos which takes long, leaks the client's IP address even to servers the user does not join and is a DoS vector of the game servers for attackers. For the Internet, DDNet and KoG tab, the server list is entirely fetched from the master server, filtering out servers that don't belong into the list. The favorites tab is also supposed to work that way, except for servers that are marked as "also ping this server if it's not in the master server list". The LAN tab continues to broadcast the server info packet to find servers in the LAN. How does it work? ================= The client ships with a list of master server list URLs. On first start, the client checks which of these work and selects the fastest one. Querying the server list is a HTTP GET request on that URL. The response is a JSON document that contains server infos, server addresses as URLs and an approximate location. It can also contain a legacy server list which is a list of bare IP addresses similar to the functionality the old master servers provided via UDP. This allows us to backtrack on the larger update if it won't work out. Lost functionality ================== (also known as user-visible changes) Since the client doesn't ping each server in the list anymore, it has no way of knowing its latency to the servers. This is alleviated a bit by providing an approximate location for each server (continent) so the client only has to know its own location for approximating pings.
2018-07-11 20:46:04 +00:00
enum
{
LOC_UNKNOWN = 0,
LOC_AFRICA,
LOC_ASIA,
LOC_AUSTRALIA,
LOC_EUROPE,
LOC_NORTH_AMERICA,
LOC_SOUTH_AMERICA,
// Special case China because it has an exceptionally bad
// connection to the outside due to the Great Firewall of
// China:
// https://en.wikipedia.org/w/index.php?title=Great_Firewall&oldid=1019589632
LOC_CHINA,
Add client-side HTTP server info Summary ======= The idea of this is that clients will not have to ping each server for server infos which takes long, leaks the client's IP address even to servers the user does not join and is a DoS vector of the game servers for attackers. For the Internet, DDNet and KoG tab, the server list is entirely fetched from the master server, filtering out servers that don't belong into the list. The favorites tab is also supposed to work that way, except for servers that are marked as "also ping this server if it's not in the master server list". The LAN tab continues to broadcast the server info packet to find servers in the LAN. How does it work? ================= The client ships with a list of master server list URLs. On first start, the client checks which of these work and selects the fastest one. Querying the server list is a HTTP GET request on that URL. The response is a JSON document that contains server infos, server addresses as URLs and an approximate location. It can also contain a legacy server list which is a list of bare IP addresses similar to the functionality the old master servers provided via UDP. This allows us to backtrack on the larger update if it won't work out. Lost functionality ================== (also known as user-visible changes) Since the client doesn't ping each server in the list anymore, it has no way of knowing its latency to the servers. This is alleviated a bit by providing an approximate location for each server (continent) so the client only has to know its own location for approximating pings.
2018-07-11 20:46:04 +00:00
NUM_LOCS,
};
class CClient
2010-05-29 07:25:38 +00:00
{
public:
char m_aName[MAX_NAME_LENGTH];
char m_aClan[MAX_CLAN_LENGTH];
int m_Country;
2010-05-29 07:25:38 +00:00
int m_Score;
bool m_Player;
2011-08-11 08:59:14 +00:00
2011-06-26 15:10:13 +00:00
int m_FriendState;
};
2010-05-29 07:25:38 +00:00
int m_ServerIndex;
int m_Type;
2021-06-23 05:05:49 +00:00
uint64_t m_ReceivedPackets;
int m_NumReceivedClients;
2010-05-29 07:25:38 +00:00
NETADDR m_NetAddr;
2010-05-29 07:25:38 +00:00
int m_QuickSearchHit;
2011-06-26 15:10:13 +00:00
int m_FriendState;
int m_MaxClients;
int m_NumClients;
2010-05-29 07:25:38 +00:00
int m_MaxPlayers;
int m_NumPlayers;
int m_Flags;
bool m_Favorite;
bool m_Official;
Add client-side HTTP server info Summary ======= The idea of this is that clients will not have to ping each server for server infos which takes long, leaks the client's IP address even to servers the user does not join and is a DoS vector of the game servers for attackers. For the Internet, DDNet and KoG tab, the server list is entirely fetched from the master server, filtering out servers that don't belong into the list. The favorites tab is also supposed to work that way, except for servers that are marked as "also ping this server if it's not in the master server list". The LAN tab continues to broadcast the server info packet to find servers in the LAN. How does it work? ================= The client ships with a list of master server list URLs. On first start, the client checks which of these work and selects the fastest one. Querying the server list is a HTTP GET request on that URL. The response is a JSON document that contains server infos, server addresses as URLs and an approximate location. It can also contain a legacy server list which is a list of bare IP addresses similar to the functionality the old master servers provided via UDP. This allows us to backtrack on the larger update if it won't work out. Lost functionality ================== (also known as user-visible changes) Since the client doesn't ping each server in the list anymore, it has no way of knowing its latency to the servers. This is alleviated a bit by providing an approximate location for each server (continent) so the client only has to know its own location for approximating pings.
2018-07-11 20:46:04 +00:00
int m_Location;
bool m_LatencyIsEstimated;
2010-05-29 07:25:38 +00:00
int m_Latency; // in ms
int m_HasRank;
2010-05-29 07:25:38 +00:00
char m_aGameType[16];
char m_aName[64];
2020-06-18 16:29:27 +00:00
char m_aMap[MAX_MAP_LENGTH];
int m_MapCrc;
int m_MapSize;
2010-05-29 07:25:38 +00:00
char m_aVersion[32];
char m_aAddress[NETADDR_MAXSTRSIZE];
2022-01-02 01:27:37 +00:00
CClient m_aClients[SERVERINFO_MAX_CLIENTS];
2018-10-29 21:03:57 +00:00
mutable int m_NumFilteredPlayers;
2020-10-12 10:29:47 +00:00
mutable CUIElement *m_pUIElement;
Add client-side HTTP server info Summary ======= The idea of this is that clients will not have to ping each server for server infos which takes long, leaks the client's IP address even to servers the user does not join and is a DoS vector of the game servers for attackers. For the Internet, DDNet and KoG tab, the server list is entirely fetched from the master server, filtering out servers that don't belong into the list. The favorites tab is also supposed to work that way, except for servers that are marked as "also ping this server if it's not in the master server list". The LAN tab continues to broadcast the server info packet to find servers in the LAN. How does it work? ================= The client ships with a list of master server list URLs. On first start, the client checks which of these work and selects the fastest one. Querying the server list is a HTTP GET request on that URL. The response is a JSON document that contains server infos, server addresses as URLs and an approximate location. It can also contain a legacy server list which is a list of bare IP addresses similar to the functionality the old master servers provided via UDP. This allows us to backtrack on the larger update if it won't work out. Lost functionality ================== (also known as user-visible changes) Since the client doesn't ping each server in the list anymore, it has no way of knowing its latency to the servers. This is alleviated a bit by providing an approximate location for each server (continent) so the client only has to know its own location for approximating pings.
2018-07-11 20:46:04 +00:00
static int EstimateLatency(int Loc1, int Loc2);
static bool ParseLocation(int *pResult, const char *pString);
2010-05-29 07:25:38 +00:00
};
bool IsVanilla(const CServerInfo *pInfo);
bool IsCatch(const CServerInfo *pInfo);
bool IsInsta(const CServerInfo *pInfo);
bool IsFNG(const CServerInfo *pInfo);
2014-12-10 02:39:15 +00:00
bool IsRace(const CServerInfo *pInfo);
bool IsFastCap(const CServerInfo *pInfo);
2014-12-10 02:39:15 +00:00
bool IsDDRace(const CServerInfo *pInfo);
bool IsDDNet(const CServerInfo *pInfo);
bool IsBlockWorlds(const CServerInfo *pInfo);
2020-09-24 10:01:12 +00:00
bool IsCity(const CServerInfo *pInfo);
2014-12-10 02:39:15 +00:00
bool Is64Player(const CServerInfo *pInfo);
bool IsPlus(const CServerInfo *pInfo);
2014-12-10 02:39:15 +00:00
2010-05-29 07:25:38 +00:00
class IServerBrowser : public IInterface
{
MACRO_INTERFACE("serverbrowser", 0)
public:
/* Constants: Server Browser Sorting
SORT_NAME - Sort by name.
SORT_PING - Sort by ping.
SORT_MAP - Sort by map
SORT_GAMETYPE - Sort by game type. DM, TDM etc.
SORT_NUMPLAYERS - Sort after how many players there are on the server.
*/
enum
{
2010-05-29 07:25:38 +00:00
SORT_NAME = 0,
SORT_PING,
SORT_MAP,
SORT_GAMETYPE,
SORT_NUMPLAYERS,
QUICK_SERVERNAME = 1,
QUICK_PLAYER = 2,
QUICK_MAPNAME = 4,
TYPE_NONE = 0,
TYPE_INTERNET = 1,
TYPE_LAN = 2,
TYPE_FAVORITES = 3,
TYPE_DDNET = 4,
TYPE_KOG = 5,
2010-05-29 07:25:38 +00:00
SET_MASTER_ADD = 1,
2010-05-29 07:25:38 +00:00
SET_FAV_ADD,
2014-09-13 14:36:25 +00:00
SET_DDNET_ADD,
SET_KOG_ADD,
SET_TOKEN,
Add client-side HTTP server info Summary ======= The idea of this is that clients will not have to ping each server for server infos which takes long, leaks the client's IP address even to servers the user does not join and is a DoS vector of the game servers for attackers. For the Internet, DDNet and KoG tab, the server list is entirely fetched from the master server, filtering out servers that don't belong into the list. The favorites tab is also supposed to work that way, except for servers that are marked as "also ping this server if it's not in the master server list". The LAN tab continues to broadcast the server info packet to find servers in the LAN. How does it work? ================= The client ships with a list of master server list URLs. On first start, the client checks which of these work and selects the fastest one. Querying the server list is a HTTP GET request on that URL. The response is a JSON document that contains server infos, server addresses as URLs and an approximate location. It can also contain a legacy server list which is a list of bare IP addresses similar to the functionality the old master servers provided via UDP. This allows us to backtrack on the larger update if it won't work out. Lost functionality ================== (also known as user-visible changes) Since the client doesn't ping each server in the list anymore, it has no way of knowing its latency to the servers. This is alleviated a bit by providing an approximate location for each server (continent) so the client only has to know its own location for approximating pings.
2018-07-11 20:46:04 +00:00
SET_HTTPINFO,
NETWORK_DDNET = 0,
NETWORK_KOG = 1,
NUM_NETWORKS,
2010-05-29 07:25:38 +00:00
};
virtual void Refresh(int Type) = 0;
Add client-side HTTP server info Summary ======= The idea of this is that clients will not have to ping each server for server infos which takes long, leaks the client's IP address even to servers the user does not join and is a DoS vector of the game servers for attackers. For the Internet, DDNet and KoG tab, the server list is entirely fetched from the master server, filtering out servers that don't belong into the list. The favorites tab is also supposed to work that way, except for servers that are marked as "also ping this server if it's not in the master server list". The LAN tab continues to broadcast the server info packet to find servers in the LAN. How does it work? ================= The client ships with a list of master server list URLs. On first start, the client checks which of these work and selects the fastest one. Querying the server list is a HTTP GET request on that URL. The response is a JSON document that contains server infos, server addresses as URLs and an approximate location. It can also contain a legacy server list which is a list of bare IP addresses similar to the functionality the old master servers provided via UDP. This allows us to backtrack on the larger update if it won't work out. Lost functionality ================== (also known as user-visible changes) Since the client doesn't ping each server in the list anymore, it has no way of knowing its latency to the servers. This is alleviated a bit by providing an approximate location for each server (continent) so the client only has to know its own location for approximating pings.
2018-07-11 20:46:04 +00:00
virtual bool IsGettingServerlist() const = 0;
virtual bool IsRefreshing() const = 0;
virtual int LoadingProgression() const = 0;
2010-05-29 07:25:38 +00:00
virtual int NumServers() const = 0;
virtual int Players(const CServerInfo &Item) const = 0;
virtual int Max(const CServerInfo &Item) const = 0;
2010-05-29 07:25:38 +00:00
virtual int NumSortedServers() const = 0;
virtual const CServerInfo *SortedGet(int Index) const = 0;
virtual bool GotInfo(const NETADDR &Addr) const = 0;
2010-05-29 07:25:38 +00:00
virtual bool IsFavorite(const NETADDR &Addr) const = 0;
virtual bool IsFavoritePingAllowed(const NETADDR &Addr) const = 0;
2010-05-29 07:25:38 +00:00
virtual void AddFavorite(const NETADDR &Addr) = 0;
virtual void FavoriteAllowPing(const NETADDR &Addr, bool AllowPing) = 0;
2010-05-29 07:25:38 +00:00
virtual void RemoveFavorite(const NETADDR &Addr) = 0;
2014-09-19 21:52:09 +00:00
virtual int NumCountries(int Network) = 0;
virtual int GetCountryFlag(int Network, int Index) = 0;
virtual const char *GetCountryName(int Network, int Index) = 0;
2014-12-14 15:45:18 +00:00
virtual int NumTypes(int Network) = 0;
virtual const char *GetType(int Network, int Index) = 0;
2014-12-14 15:45:18 +00:00
virtual void DDNetFilterAdd(char *pFilter, const char *pName) = 0;
virtual void DDNetFilterRem(char *pFilter, const char *pName) = 0;
virtual bool DDNetFiltered(char *pFilter, const char *pName) = 0;
virtual void CountryFilterClean(int Network) = 0;
virtual void TypeFilterClean(int Network) = 0;
virtual int GetCurrentType() = 0;
virtual const char *GetTutorialServer() = 0;
2010-05-29 07:25:38 +00:00
};
#endif