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

128 lines
2.5 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*);
2015-12-27 22:02:30 -05:00
struct ServerInfo
{
Network::Address Addr;
std::string Hostname;
std::string Mapname;
std::string Gametype;
std::string Mod;
2016-01-01 11:36:47 -05:00
std::string Shortversion;
2015-12-27 22:02:30 -05:00
int Clients;
int MaxClients;
bool Password;
int Ping;
int MatchType;
bool Hardcore;
};
ServerList();
~ServerList();
const char* GetName() { return "ServerList"; };
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];
struct
{
uint32_t IP;
uint16_t Port;
};
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] == '\\');
}
};
#pragma pack(pop)
2015-12-27 22:02:30 -05:00
struct Container
{
struct ServerContainer
{
bool Sent;
int SendTime;
std::string Challenge;
Network::Address Target;
};
2015-12-28 11:52:13 -05:00
bool AwatingList;
int AwaitTime;
2015-12-28 09:46:08 -05:00
int SentCount;
int SendCount;
2015-12-28 11:52:13 -05:00
2015-12-27 22:02:30 -05:00
Network::Address Host;
std::vector<ServerContainer> Servers;
std::mutex Mutex;
};
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
};
}