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
|
|
|
|
|
2022-05-23 18:16:18 +00:00
|
|
|
#include <base/types.h>
|
2020-06-18 16:29:27 +00:00
|
|
|
#include <engine/map.h>
|
2011-03-16 11:37:41 +00:00
|
|
|
#include <engine/shared/protocol.h>
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
|
2023-09-17 11:31:41 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-08-23 07:57:35 +00:00
|
|
|
#define DDNET_INFO "ddnet-info.json"
|
|
|
|
|
2022-01-02 03:27:29 +00:00
|
|
|
class CUIElement;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CServerInfo
|
|
|
|
{
|
|
|
|
public:
|
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,
|
2021-04-24 13:48:27 +00:00
|
|
|
// 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,
|
2018-07-11 20:46:04 +00:00
|
|
|
NUM_LOCS,
|
|
|
|
};
|
|
|
|
|
2022-10-11 19:52:27 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CLIENT_SCORE_KIND_UNSPECIFIED,
|
|
|
|
CLIENT_SCORE_KIND_POINTS,
|
|
|
|
CLIENT_SCORE_KIND_TIME,
|
|
|
|
CLIENT_SCORE_KIND_TIME_BACKCOMPAT,
|
|
|
|
};
|
|
|
|
|
2011-03-20 14:33:49 +00:00
|
|
|
class CClient
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-03-16 11:37:41 +00:00
|
|
|
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;
|
2011-03-20 14:33:49 +00:00
|
|
|
bool m_Player;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2023-01-07 08:20:25 +00:00
|
|
|
// skin info
|
|
|
|
char m_aSkin[24 + 1];
|
|
|
|
bool m_CustomSkinColors;
|
|
|
|
int m_CustomSkinColorBody;
|
|
|
|
int m_CustomSkinColorFeet;
|
|
|
|
|
2011-06-26 15:10:13 +00:00
|
|
|
int m_FriendState;
|
|
|
|
};
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
int m_ServerIndex;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2017-03-29 10:56:13 +00:00
|
|
|
int m_Type;
|
2021-06-23 05:05:49 +00:00
|
|
|
uint64_t m_ReceivedPackets;
|
2017-03-29 10:56:13 +00:00
|
|
|
int m_NumReceivedClients;
|
|
|
|
|
2022-05-23 18:16:18 +00:00
|
|
|
int m_NumAddresses;
|
|
|
|
NETADDR m_aAddresses[MAX_SERVER_ADDRESSES];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_QuickSearchHit;
|
2011-06-26 15:10:13 +00:00
|
|
|
int m_FriendState;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-20 14:33:49 +00:00
|
|
|
int m_MaxClients;
|
|
|
|
int m_NumClients;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_MaxPlayers;
|
|
|
|
int m_NumPlayers;
|
|
|
|
int m_Flags;
|
2022-10-11 19:52:27 +00:00
|
|
|
int m_ClientScoreKind;
|
2022-05-23 18:16:18 +00:00
|
|
|
TRISTATE m_Favorite;
|
|
|
|
TRISTATE m_FavoriteAllowPing;
|
2019-03-19 06:46:48 +00:00
|
|
|
bool m_Official;
|
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
|
2017-08-30 19:34:01 +00:00
|
|
|
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];
|
2017-03-29 10:56:13 +00:00
|
|
|
int m_MapCrc;
|
|
|
|
int m_MapSize;
|
2010-05-29 07:25:38 +00:00
|
|
|
char m_aVersion[32];
|
2022-05-23 18:16:18 +00:00
|
|
|
char m_aAddress[MAX_SERVER_ADDRESSES * NETADDR_MAXSTRSIZE];
|
2022-01-02 01:27:37 +00:00
|
|
|
CClient m_aClients[SERVERINFO_MAX_CLIENTS];
|
2023-09-17 11:18:49 +00:00
|
|
|
int m_NumFilteredPlayers;
|
2020-10-12 10:29:47 +00:00
|
|
|
|
2018-07-11 20:46:04 +00:00
|
|
|
static int EstimateLatency(int Loc1, int Loc2);
|
|
|
|
static bool ParseLocation(int *pResult, const char *pString);
|
2023-01-06 20:14:26 +00:00
|
|
|
void InfoToString(char *pBuffer, int BufferSize) const;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2023-09-17 11:31:41 +00:00
|
|
|
class CCommunityCountryServer
|
|
|
|
{
|
|
|
|
NETADDR m_Address;
|
|
|
|
char m_aTypeName[32];
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCommunityCountryServer(NETADDR Address, const char *pTypeName) :
|
|
|
|
m_Address(Address)
|
|
|
|
{
|
|
|
|
str_copy(m_aTypeName, pTypeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NETADDR Address() const { return m_Address; }
|
|
|
|
const char *TypeName() const { return m_aTypeName; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCommunityCountry
|
|
|
|
{
|
|
|
|
friend class CServerBrowser;
|
|
|
|
|
|
|
|
char m_aName[256];
|
|
|
|
int m_FlagId;
|
|
|
|
std::vector<CCommunityCountryServer> m_vServers;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCommunityCountry(const char *pName, int FlagId) :
|
|
|
|
m_FlagId(FlagId)
|
|
|
|
{
|
|
|
|
str_copy(m_aName, pName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Name() const { return m_aName; }
|
|
|
|
int FlagId() const { return m_FlagId; }
|
|
|
|
const std::vector<CCommunityCountryServer> &Servers() const { return m_vServers; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCommunityType
|
|
|
|
{
|
|
|
|
char m_aName[32];
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCommunityType(const char *pName)
|
|
|
|
{
|
|
|
|
str_copy(m_aName, pName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Name() const { return m_aName; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCommunity
|
|
|
|
{
|
|
|
|
friend class CServerBrowser;
|
|
|
|
|
|
|
|
char m_aId[32];
|
|
|
|
char m_aName[64];
|
|
|
|
char m_aJsonServersKey[32];
|
|
|
|
std::vector<CCommunityCountry> m_vCountries;
|
|
|
|
std::vector<CCommunityType> m_vTypes;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCommunity(const char *pId, const char *pName, const char *pJsonServersKey)
|
|
|
|
{
|
|
|
|
str_copy(m_aId, pId);
|
|
|
|
str_copy(m_aName, pName);
|
|
|
|
str_copy(m_aJsonServersKey, pJsonServersKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Id() const { return m_aId; }
|
|
|
|
const char *Name() const { return m_aName; }
|
|
|
|
const char *JsonServersKey() const { return m_aJsonServersKey; }
|
|
|
|
const std::vector<CCommunityCountry> &Countries() const { return m_vCountries; }
|
|
|
|
const std::vector<CCommunityType> &Types() const { return m_vTypes; }
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
SORT_NAME = 0,
|
|
|
|
SORT_PING,
|
|
|
|
SORT_MAP,
|
|
|
|
SORT_GAMETYPE,
|
|
|
|
SORT_NUMPLAYERS,
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
QUICK_SERVERNAME = 1,
|
|
|
|
QUICK_PLAYER = 2,
|
|
|
|
QUICK_MAPNAME = 4,
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2023-09-20 14:57:08 +00:00
|
|
|
TYPE_INTERNET = 0,
|
|
|
|
TYPE_LAN,
|
|
|
|
TYPE_FAVORITES,
|
|
|
|
TYPE_DDNET,
|
|
|
|
TYPE_KOG,
|
|
|
|
NUM_TYPES,
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2023-09-17 11:31:41 +00:00
|
|
|
// TODO: remove integer community index and used string IDs instead
|
2020-09-26 19:41:58 +00:00
|
|
|
NETWORK_DDNET = 0,
|
|
|
|
NETWORK_KOG = 1,
|
2019-03-24 22:15:38 +00:00
|
|
|
NUM_NETWORKS,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2023-09-17 11:31:41 +00:00
|
|
|
static constexpr const char *COMMUNITY_DDNET = "ddnet";
|
|
|
|
|
2022-09-25 12:37:24 +00:00
|
|
|
static constexpr const char *SEARCH_EXCLUDE_TOKEN = ";";
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Refresh(int Type) = 0;
|
2018-07-11 20:46:04 +00:00
|
|
|
virtual bool IsGettingServerlist() const = 0;
|
2010-11-17 11:43:24 +00:00
|
|
|
virtual bool IsRefreshing() const = 0;
|
2010-10-30 16:56:57 +00:00
|
|
|
virtual int LoadingProgression() const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int NumServers() const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2018-08-21 07:03:29 +00:00
|
|
|
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;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2023-09-17 11:31:41 +00:00
|
|
|
virtual const std::vector<CCommunity> &Communities() const = 0;
|
|
|
|
virtual const CCommunity *Community(const char *pCommunityId) const = 0;
|
2014-12-14 15:45:18 +00:00
|
|
|
|
2023-06-13 19:09:26 +00:00
|
|
|
virtual void DDNetFilterAdd(char *pFilter, int FilterSize, const char *pName) const = 0;
|
|
|
|
virtual void DDNetFilterRem(char *pFilter, int FilterSize, const char *pName) const = 0;
|
|
|
|
virtual bool DDNetFiltered(const char *pFilter, const char *pName) const = 0;
|
2023-09-17 11:31:41 +00:00
|
|
|
virtual void CountryFilterClean(int CommunityIndex) = 0;
|
|
|
|
virtual void TypeFilterClean(int CommunityIndex) = 0;
|
2015-05-11 19:51:06 +00:00
|
|
|
virtual int GetCurrentType() = 0;
|
2022-02-21 00:04:49 +00:00
|
|
|
virtual const char *GetTutorialServer() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|