iw4x-client/src/Components/Modules/ServerList.hpp

136 lines
2.6 KiB
C++
Raw Normal View History

2015-12-27 22:02:30 -05:00
namespace Components
{
class ServerList : public Component
{
public:
2016-01-02 09:19:34 -05:00
typedef int(SortCallback)(const void*, const void*);
2016-06-30 13:38:48 -04:00
class ServerInfo
2015-12-27 22:02:30 -05:00
{
2016-06-30 13:38:48 -04:00
public:
Network::Address addr;
std::string hostname;
std::string mapname;
std::string gametype;
std::string mod;
std::string shortversion;
int clients;
int maxClients;
bool password;
int ping;
int matchType;
int securityLevel;
bool hardcore;
bool svRunning;
2015-12-27 22:02:30 -05:00
};
ServerList();
2016-08-15 10:40:30 -04:00
~ServerList();
2016-09-16 05:04:28 -04:00
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* getName() { return "ServerList"; };
2016-08-15 10:40:30 -04:00
#endif
2015-12-27 22:02:30 -05:00
static void Refresh();
2016-01-03 19:30:15 -05:00
static void RefreshVisibleList();
static void UpdateVisibleList();
2016-01-04 04:54:31 -05:00
static void InsertRequest(Network::Address address, bool acquireMutex = true);
2015-12-27 22:02:30 -05:00
static void Insert(Network::Address address, Utils::InfoString info);
2016-01-07 20:20:55 -05:00
static ServerInfo* GetCurrentServer();
2016-01-03 18:00:07 -05:00
static bool IsFavouriteList();
static bool IsOfflineList();
static bool IsOnlineList();
2015-12-27 22:02:30 -05:00
private:
enum Column
{
Password,
2016-01-03 19:30:15 -05:00
Matchtype,
2015-12-27 22:02:30 -05:00
Hostname,
Mapname,
Players,
Gametype,
2016-01-03 19:30:15 -05:00
Mod,
2015-12-27 22:02:30 -05:00
Ping,
};
2015-12-28 08:53:20 -05:00
#pragma pack(push, 1)
union MasterEntry
{
char token[7];
2015-12-28 08:53:20 -05:00
struct
{
uint32_t ip;
uint16_t port;
2015-12-28 08:53:20 -05:00
};
bool IsEndToken()
{
2015-12-28 09:46:08 -05:00
// End of transmission or file token
return (token[0] == 'E' && token[1] == 'O' && (token[2] == 'T' || token[2] == 'F'));
2015-12-28 08:53:20 -05:00
}
bool HasSeparator()
{
return (token[6] == '\\');
2015-12-28 08:53:20 -05:00
}
};
#pragma pack(pop)
2016-06-30 13:38:48 -04:00
class Container
2015-12-27 22:02:30 -05:00
{
2016-06-30 13:38:48 -04:00
public:
class ServerContainer
2015-12-27 22:02:30 -05:00
{
2016-06-30 13:38:48 -04:00
public:
bool sent;
int sendTime;
std::string challenge;
Network::Address target;
2015-12-27 22:02:30 -05:00
};
bool awatingList;
int awaitTime;
2015-12-28 11:52:13 -05:00
int sentCount;
int sendCount;
2015-12-28 11:52:13 -05:00
Network::Address host;
std::vector<ServerContainer> servers;
std::mutex mutex;
2015-12-27 22:02:30 -05:00
};
2016-01-10 06:25:31 -05:00
static unsigned int GetServerCount();
static const char* GetServerText(unsigned int index, int column);
2016-01-02 09:19:34 -05:00
static const char* GetServerText(ServerInfo* server, int column);
2016-01-10 06:25:31 -05:00
static void SelectServer(unsigned int index);
2015-12-27 22:02:30 -05:00
2016-01-03 19:30:15 -05:00
static void UpdateSource();
2016-01-07 15:28:39 -05:00
static void UpdateGameType();
2016-01-03 19:30:15 -05:00
2015-12-28 09:46:08 -05:00
static void Frame();
2016-01-02 09:23:04 -05:00
static void SortList();
2016-01-02 09:19:34 -05:00
2016-01-08 09:31:26 -05:00
static void LoadFavourties();
static void StoreFavourite(std::string server);
2016-01-10 06:25:31 -05:00
static ServerInfo* GetServer(unsigned int index);
2016-01-08 13:08:35 -05:00
static std::vector<ServerInfo>* GetList();
2016-01-02 09:19:34 -05:00
static int SortKey;
static bool SortAsc;
2015-12-28 08:08:46 -05:00
static unsigned int CurrentServer;
2015-12-27 22:02:30 -05:00
static Container RefreshContainer;
2016-01-03 18:00:07 -05:00
2015-12-27 22:02:30 -05:00
static std::vector<ServerInfo> OnlineList;
2016-01-03 18:00:07 -05:00
static std::vector<ServerInfo> OfflineList;
static std::vector<ServerInfo> FavouriteList;
2016-01-10 06:25:31 -05:00
static std::vector<unsigned int> VisibleList;
2015-12-27 22:02:30 -05:00
};
}