BF2MC-Matchmaker
gameserver.h
1 #ifndef BATTLEFIELD_GAMESERVER_H
2 #define BATTLEFIELD_GAMESERVER_H
3 
4 #include <cstdint>
5 #include <vector>
6 #include <string>
7 #include <unordered_map>
8 
17 struct MYSQL_TIME;
18 
19 namespace Battlefield
20 {
29  class GameServer;
30 
39  class GameServerPlayer;
40 
47  typedef std::vector<GameServer> GameServers;
48 
55  typedef std::vector<GameServerPlayer> GameServerPlayers;
56 
62  class GameServer
63  {
64  public:
74  enum class Regions : uint64_t
75  {
76  Unknown = 0,
77  America = 1,
78  Asia = 2048,
79  Europe = 65536
80  };
81 
85  enum class MapCyclingOptions : uint8_t
86  {
87  Unknown = 0,
89  AllMaps = 2,
90  AssaultMaps = 3,
91  IncursionMaps = 4,
92  DominationMaps = 5
93  };
94 
95  private:
96  int _id = -1;
97  std::string _ip = "";
98  uint16_t _port = 3658;
99  uint8_t _flag = 59;
101  // See reference: https://documentation.help/GameSpy-SDK/Gamespy%20Query%20and%20Reporting%202%20SDK.html
102  std::string _localip0 = "";
103  uint16_t _localport = 3658;
104  uint8_t _natneg = 0;
105  std::string _gamename = "";
106  std::string _hostname = "";
107  uint16_t _hostport = 3658;
109  std::string _gamever = "V1.31a";
110  std::string _cl = "";
111  std::string _rv = "";
113  std::string _map = "";
114  uint8_t _mc = 0;
115  uint8_t _mapname = 0;
117  uint8_t _gc = 0;
123  std::string _gametype = "";
124 
125  std::string _gamevariant = "";
126  uint8_t _numplayers = 0;
127  uint8_t _maxplayers = 0;
128  uint8_t _numteams = 0;
139  std::string _gamemode = "";
140 
146  uint8_t _teamplay = 0;
147 
148  uint8_t _fraglimit = 0;
149  uint8_t _teamfraglimit = 0;
150  uint16_t _timelimit = 0;
151  uint16_t _timeelapsed = 0;
152  uint8_t _password = 0;
153  uint8_t _nr = 0;
154  uint8_t _xr = 0;
155  uint8_t _ff = 0;
156  uint8_t _sr = 0;
157  uint8_t _rc = 0;
158  int64_t _ni = 0;
159  int64_t _xi = 0;
166  uint8_t _qm = 0;
167 
168  uint64_t _region = 1;
170  // Clan
171  int _c0 = -1;
172  int _c1 = -1;
173  std::string _n0 = "";
174  std::string _n1 = "";
175  uint8_t _c0c = 0;
176  uint8_t _c1c = 0;
178  // Team
179  std::string _team0 = "";
180  std::string _team1 = "";
181  int16_t _score0 = 0;
182  int16_t _score1 = 0;
184  std::string _updated_at = "";
185  bool _verified = false;
187  std::vector<GameServerPlayer> _players;
189  public:
190  typedef bool (Battlefield::GameServer::*SetterFunc)(const std::string&);
191 
192  static std::unordered_map<std::string, SetterFunc> SetterMap;
193 
194  public:
195  int GetId() const { return this->_id; }
196  std::string GetIp() const { return this->_ip; }
197  void GetIpArray(uint8_t* ip) const;
198  uint16_t GetPort() const { return this->_port; }
199  uint8_t GetFlag() const { return this->_flag; }
200  std::string GetLocalIp() const { return this->_localip0; }
201  uint16_t GetLocalPort() const { return this->_localport; }
202  uint8_t GetNatNeg() const { return this->_natneg; }
203  std::string GetGameName() const { return this->_gamename; }
204  std::string GetHostName() const { return this->_hostname; }
205  uint16_t GetHostPort() const { return this->_hostport; }
206  std::string GetGameVersion() const { return this->_gamever; }
207  std::string GetClientVersion() const { return this->_cl; }
208  std::string GetRV() const { return this->_rv; }
209  std::string GetMap() const { return this->_map; }
210  uint8_t GetMapCycling() const { return this->_mc; }
211  uint8_t GetMapName() const { return this->_mapname; }
212  uint8_t GetGC() const { return this->_gc; }
213  std::string GetGameType() const { return this->_gametype; }
214  std::string GetGameVariant() const { return this->_gamevariant; }
215  uint8_t GetNumPlayers() const { return this->_numplayers; }
216  uint8_t GetMaxPlayers() const { return this->_maxplayers; }
217  uint8_t GetNumTeams() const { return this->_numteams; }
218  std::string GetGameMode() const { return this->_gamemode; }
219  uint8_t GetTeamplay() const { return this->_teamplay; }
220  uint8_t GetFlagLimit() const { return this->_fraglimit; }
221  uint8_t GetTeamFragLimit() const { return this->_teamfraglimit; }
222  uint16_t GetTimeLimit() const { return this->_timelimit; }
223  uint16_t GetTimeElapsed() const { return this->_timeelapsed; }
224  uint8_t GetPassword() const { return this->_password; }
225  uint8_t GetMinRank() const { return this->_nr; }
226  uint8_t GetMaxRank() const { return this->_xr; }
227  uint8_t GetFriendlyFire() const { return this->_ff; }
228  uint8_t GetStatsTracking() const { return this->_sr; }
229  uint8_t GetReconfigurable() const { return this->_rc; }
230  int64_t GetMinIpRange() const { return this->_ni; }
231  int64_t GetMaxIpRange() const { return this->_xi; }
232  uint8_t GetQM() const { return this->_qm; }
233  uint64_t GetRegion() const { return this->_region; }
234  // Clan
235  int GetClan1Id() const { return this->_c0; }
236  int GetClan2Id() const { return this->_c1; }
237  std::string GetClan1Name() const { return this->_n0; }
238  std::string GetClan2Name() const { return this->_n1; }
239  uint8_t GetClan1Claimed() const { return this->_c0c; }
240  uint8_t GetClan2Claimed() const { return this->_c1c; }
241  // Team
242  std::string GetTeam1Name() const { return this->_team0; }
243  std::string GetTeam2Name() const { return this->_team1; }
244  int16_t GetTeam1Score() const { return this->_score0; }
245  int16_t GetTeam2Score() const { return this->_score1; }
246 
247  std::string GetUpdatedAt() const { return this->_updated_at; }
248  bool isVerified() const { return this->_verified; }
249 
250  GameServerPlayers GetPlayers() const { return this->_players; }
251 
252  bool SetId(int id);
253  bool SetIp(const std::string& ip);
254  bool SetPort(uint16_t port);
255  bool SetFlag(uint8_t flag);
256  bool SetLocalIp(const std::string& localip);
257  bool SetLocalPort(uint16_t localport);
258  bool SetLocalPort(const std::string& str_localport);
259  bool SetNatNeg(uint8_t natneg);
260  bool SetNatNeg(const std::string& str_natneg);
261  bool SetGameName(const std::string& gamename);
262  bool SetHostName(const std::string& hostname);
263  bool SetHostPort(uint16_t hostport);
264  bool SetHostPort(const std::string& str_hostport);
265  bool SetGameVersion(const std::string& gamever);
266  bool SetClientVersion(const std::string& clientver);
267  bool SetRV(const std::string& rv);
268  bool SetMap(const std::string& map);
269  bool SetMapCycling(uint8_t mc);
270  bool SetMapCycling(const std::string& str_mc);
271  bool SetMapName(uint8_t mapname);
272  bool SetMapName(const std::string& str_mapname);
273  bool SetGC(uint8_t gc);
274  bool SetGC(const std::string& str_gc);
275  bool SetGameType(const std::string& gametype);
276  bool SetGameVariant(const std::string& gamevariant);
277  bool SetNumPlayers(uint8_t numplayers);
278  bool SetNumPlayers(const std::string& str_numplayers);
279  bool SetMaxPlayers(uint8_t maxplayers);
280  bool SetMaxPlayers(const std::string& str_maxplayers);
281  bool SetNumTeams(uint8_t numteams);
282  bool SetNumTeams(const std::string& str_numteams);
283  bool SetGameMode(const std::string& gamemode);
284  bool SetTeamplay(uint8_t teamplay);
285  bool SetTeamplay(const std::string& str_teamplay);
286  bool SetFlagLimit(uint8_t fraglimit);
287  bool SetFlagLimit(const std::string& str_fraglimit);
288  bool SetTeamFragLimit(uint8_t teamfraglimit);
289  bool SetTeamFragLimit(const std::string& str_teamfraglimit);
290  bool SetTimeLimit(uint16_t timelimit);
291  bool SetTimeLimit(const std::string& str_timelimit);
292  bool SetTimeElapsed(uint16_t timeelapsed);
293  bool SetTimeElapsed(const std::string& str_timeelapsed);
294  bool SetPassword(uint8_t password);
295  bool SetPassword(const std::string& str_password);
296  bool SetMinRank(uint8_t nr);
297  bool SetMinRank(const std::string& str_nr);
298  bool SetMaxRank(uint8_t xr);
299  bool SetMaxRank(const std::string& str_xr);
300  bool SetFriendlyFire(uint8_t ff);
301  bool SetFriendlyFire(const std::string& str_ff);
302  bool SetStatsTracking(uint8_t sr);
303  bool SetStatsTracking(const std::string& str_sr);
304  bool SetReconfigurable(uint8_t rc);
305  bool SetReconfigurable(const std::string& str_rc);
306  bool SetMinIpRange(int64_t ni);
307  bool SetMinIpRange(const std::string& str_ni);
308  bool SetMaxIpRange(int64_t xi);
309  bool SetMaxIpRange(const std::string& str_xi);
310  bool SetQM(uint8_t qm);
311  bool SetQM(const std::string& str_qm);
312  bool SetRegion(uint64_t region);
313  bool SetRegion(const std::string& str_region);
314 
315  // Clan
316  bool SetClan1Id(int c0);
317  bool SetClan1Id(const std::string& str_c0);
318  bool SetClan2Id(int c1);
319  bool SetClan2Id(const std::string& str_c1);
320  bool SetClan1Name(const std::string& n0);
321  bool SetClan2Name(const std::string& n1);
322  bool SetClan1Claimed(uint8_t c0c);
323  bool SetClan1Claimed(const std::string& str_c0c);
324  bool SetClan2Claimed(uint8_t c1c);
325  bool SetClan2Claimed(const std::string& str_c1c);
326 
327  // Team
328  bool SetTeam1Name(const std::string& team0);
329  bool SetTeam2Name(const std::string& team1);
330  bool SetTeam1Score(int16_t score0);
331  bool SetTeam1Score(const std::string& str_score0);
332  bool SetTeam2Score(int16_t score1);
333  bool SetTeam2Score(const std::string& str_score1);
334 
335  bool SetUpdatedAt(MYSQL_TIME updated_at);
336  bool SetVerified(bool verified);
337  bool SetVerified(uint8_t verified);
338 
344  void AddPlayer(const GameServerPlayer& gsplayer);
345 
366  bool IsAlive();
367 
376  void useExample();
377 
378  void Debug();
379  };
380 
385  {
386  private:
387  int _id = -1;
388  std::string _name = "";
389  int16_t _score = 0;
390  std::string _skill = "";
391  uint8_t _ping = 0;
392  uint8_t _team = 0;
393  uint16_t _deaths = 0;
394  int _profileid = -1;
396  public:
397  int GetId() const { return this->_id; }
398  std::string GetName() const { return this->_name; }
399  int16_t GetScore() const { return this->_score; }
400  std::string GetSkill() const { return this->_skill; }
401  uint8_t GetPing() const { return this->_ping; }
402  uint8_t GetTeam() const { return this->_team; }
403  uint16_t GetDeaths() const { return this->_deaths; }
404  int GetProfileId() const { return this->_profileid; }
405 
406  bool SetId(int id);
407  bool SetName(const std::string& name);
408  bool SetScore(int16_t score);
409  bool SetScore(const std::string& str_score);
410  bool SetSkill(const std::string& skill);
411  bool SetPing(uint8_t ping);
412  bool SetPing(const std::string& str_ping);
413  bool SetTeam(uint8_t team);
414  bool SetTeam(const std::string& str_team);
415  bool SetDeaths(uint16_t deaths);
416  bool SetDeaths(const std::string& str_deaths);
417  bool SetProfileId(int profileid);
418  bool SetProfileId(const std::string& str_profileid);
419  };
420 }
421 
422 #endif // BATTLEFIELD_GAMESERVER_H
Represents a player in a game server.
Definition: gameserver.h:385
Class representing game server information.
Definition: gameserver.h:63
std::string _updated_at
Definition: gameserver.h:184
void useExample()
Performs an example operation using the GameServer class.
Definition: gameserver.cpp:54
std::vector< GameServerPlayer > _players
Definition: gameserver.h:187
bool IsAlive()
Checks if the game server is alive.
Definition: gameserver.cpp:768
void AddPlayer(const GameServerPlayer &gsplayer)
Adds a player to the game server.
Definition: gameserver.cpp:763
Regions
Enumeration defining regions where a game server can be located.
Definition: gameserver.h:75
MapCyclingOptions
Enumeration defining the map cycling options.
Definition: gameserver.h:86
std::string _gamevariant
Definition: gameserver.h:125