BF2MC-Matchmaker
gameserver.cpp
1 #include <string>
2 #include <arpa/inet.h>
3 #include <mysql/mysql_time.h>
4 
5 #include <util.h>
6 #include <logger.h>
7 #include <browsing/constants.h>
8 
9 #include <battlefield/gameserver.h>
10 
11 std::unordered_map<std::string, Battlefield::GameServer::SetterFunc> Battlefield::GameServer::SetterMap = {
12  {"localip0", &Battlefield::GameServer::SetLocalIp },
13  {"localport", &Battlefield::GameServer::SetLocalPort },
14  {"natneg", &Battlefield::GameServer::SetNatNeg },
15  {"gamename", &Battlefield::GameServer::SetGameName },
16  {"hostname", &Battlefield::GameServer::SetHostName },
17  {"hostport", &Battlefield::GameServer::SetHostPort },
18  {"gamever", &Battlefield::GameServer::SetGameVersion },
19  {"cl", &Battlefield::GameServer::SetClientVersion },
20  {"rv", &Battlefield::GameServer::SetRV },
21  {"map", &Battlefield::GameServer::SetMap },
22  {"mc", &Battlefield::GameServer::SetMapCycling },
23  {"mapname", &Battlefield::GameServer::SetMapName },
24  {"gc", &Battlefield::GameServer::SetGC },
25  {"gametype", &Battlefield::GameServer::SetGameType },
26  {"gamevariant", &Battlefield::GameServer::SetGameVariant },
27  {"numplayers", &Battlefield::GameServer::SetNumPlayers },
28  {"maxplayers", &Battlefield::GameServer::SetMaxPlayers },
29  {"numteams", &Battlefield::GameServer::SetNumTeams },
30  {"gamemode", &Battlefield::GameServer::SetGameMode },
31  {"teamplay", &Battlefield::GameServer::SetTeamplay },
32  {"fraglimit", &Battlefield::GameServer::SetFlagLimit },
33  {"teamfraglimit", &Battlefield::GameServer::SetTeamFragLimit },
34  {"timelimit", &Battlefield::GameServer::SetTimeLimit },
35  {"timeelapsed", &Battlefield::GameServer::SetTimeElapsed },
36  {"password", &Battlefield::GameServer::SetPassword },
37  {"nr", &Battlefield::GameServer::SetMinRank },
38  {"xr", &Battlefield::GameServer::SetMaxRank },
39  {"ff", &Battlefield::GameServer::SetFriendlyFire },
40  {"sr", &Battlefield::GameServer::SetStatsTracking },
41  {"rc", &Battlefield::GameServer::SetReconfigurable },
42  {"ni", &Battlefield::GameServer::SetMinIpRange },
43  {"xi", &Battlefield::GameServer::SetMaxIpRange },
44  {"qm", &Battlefield::GameServer::SetQM },
45  {"region", &Battlefield::GameServer::SetRegion },
46  {"c0", &Battlefield::GameServer::SetClan1Id },
47  {"c1", &Battlefield::GameServer::SetClan2Id },
48  {"n0", &Battlefield::GameServer::SetClan1Name },
49  {"n1", &Battlefield::GameServer::SetClan2Name },
50  {"c0c", &Battlefield::GameServer::SetClan1Claimed },
51  {"c1c", &Battlefield::GameServer::SetClan2Claimed },
52 };
53 
55 {
56  this->SetIp("168.119.189.149");
57  this->SetPort(3658);
58  this->SetFlag(FLAG_UNSOLICITED_UDP | FLAG_PRIVATE_IP | FLAG_ICMP_IP | FLAG_NONSTANDARD_PORT | FLAG_NONSTANDARD_PRIVATE_PORT);
59 }
60 
61 bool Battlefield::GameServer::SetId(int id)
62 {
63  this->_id = id;
64  return true;
65 }
66 
67 void Battlefield::GameServer::GetIpArray(uint8_t* ip) const
68 {
69  inet_pton(AF_INET, this->_ip.c_str(), ip);
70 }
71 
72 bool Battlefield::GameServer::SetIp(const std::string& ip)
73 {
74  this->_ip = ip;
75  return true;
76 }
77 
78 bool Battlefield::GameServer::SetPort(uint16_t port)
79 {
80  this->_port = port;
81  return true;
82 }
83 
84 bool Battlefield::GameServer::SetFlag(uint8_t flag)
85 {
86  this->_flag = flag;
87  return true;
88 }
89 
90 bool Battlefield::GameServer::SetLocalIp(const std::string& localip)
91 {
92  this->_localip0 = localip;
93  return true;
94 }
95 
96 bool Battlefield::GameServer::SetLocalPort(uint16_t localport)
97 {
98  this->_localport = localport;
99  return true;
100 }
101 
102 bool Battlefield::GameServer::SetLocalPort(const std::string& str_localport)
103 {
104  try
105  {
106  uint16_t localport = static_cast<uint16_t>(std::stoul(str_localport));
107 
108  return this->SetLocalPort(localport);
109  }
110  catch(...) {};
111 
112  return false;
113 }
114 
115 bool Battlefield::GameServer::SetNatNeg(uint8_t natneg)
116 {
117  this->_natneg = natneg;
118  return true;
119 }
120 
121 bool Battlefield::GameServer::SetNatNeg(const std::string& str_natneg)
122 {
123  try
124  {
125  uint8_t natneg = static_cast<uint8_t>(std::stoul(str_natneg));
126 
127  return this->SetNatNeg(natneg);
128  }
129  catch(...) {};
130 
131  return false;
132 }
133 
134 bool Battlefield::GameServer::SetGameName(const std::string& gamename)
135 {
136  this->_gamename = gamename;
137  return true;
138 }
139 
140 bool Battlefield::GameServer::SetHostName(const std::string& hostname)
141 {
142  this->_hostname = hostname;
143  return true;
144 }
145 
146 bool Battlefield::GameServer::SetHostPort(uint16_t hostport)
147 {
148  this->_hostport = hostport;
149  return true;
150 }
151 
152 bool Battlefield::GameServer::SetHostPort(const std::string& str_hostport)
153 {
154  try
155  {
156  uint16_t hostport = static_cast<uint16_t>(std::stoul(str_hostport));
157 
158  return this->SetHostPort(hostport);
159  }
160  catch(...) {};
161 
162  return false;
163 }
164 
165 bool Battlefield::GameServer::SetGameVersion(const std::string& gamever)
166 {
167  this->_gamever = gamever;
168  return true;
169 }
170 
171 bool Battlefield::GameServer::SetClientVersion(const std::string& clientver)
172 {
173  this->_cl = clientver;
174  return true;
175 }
176 
177 bool Battlefield::GameServer::SetRV(const std::string& rv)
178 {
179  this->_rv = rv;
180  return true;
181 }
182 
183 bool Battlefield::GameServer::SetMap(const std::string& map)
184 {
185  this->_map = map;
186  return true;
187 }
188 
189 bool Battlefield::GameServer::SetMapCycling(uint8_t mc)
190 {
191  this->_mc = mc;
192  return true;
193 }
194 
195 bool Battlefield::GameServer::SetMapCycling(const std::string& str_mc)
196 {
197  try
198  {
199  uint8_t mc = static_cast<uint8_t>(std::stoul(str_mc));
200 
201  return this->SetMapCycling(mc);
202  }
203  catch(...) {};
204 
205  return false;
206 }
207 
208 bool Battlefield::GameServer::SetMapName(uint8_t mapname)
209 {
210  this->_mapname = mapname;
211  return true;
212 }
213 
214 bool Battlefield::GameServer::SetMapName(const std::string& str_mapname)
215 {
216  try
217  {
218  uint8_t mapname = static_cast<uint8_t>(std::stoul(str_mapname));
219 
220  return this->SetMapName(mapname);
221  }
222  catch(...) {};
223 
224  return false;
225 }
226 
227 bool Battlefield::GameServer::SetGC(uint8_t gc)
228 {
229  this->_gc = gc;
230  return true;
231 }
232 
233 bool Battlefield::GameServer::SetGC(const std::string& str_gc)
234 {
235  try
236  {
237  uint8_t gc = static_cast<uint8_t>(std::stoul(str_gc));
238 
239  return this->SetGC(gc);
240  }
241  catch(...) {};
242 
243  return false;
244 }
245 
246 bool Battlefield::GameServer::SetGameType(const std::string& gametype)
247 {
248  this->_gametype = gametype;
249  return true;
250 }
251 
252 bool Battlefield::GameServer::SetGameVariant(const std::string& gamevariant)
253 {
254  this->_gamevariant = gamevariant;
255  return true;
256 }
257 
258 bool Battlefield::GameServer::SetNumPlayers(uint8_t numplayers)
259 {
260  this->_numplayers = numplayers;
261  return true;
262 }
263 
264 bool Battlefield::GameServer::SetNumPlayers(const std::string& str_numplayers)
265 {
266  try
267  {
268  uint8_t numplayers = static_cast<uint8_t>(std::stoul(str_numplayers));
269 
270  return this->SetNumPlayers(numplayers);
271  }
272  catch(...) {};
273 
274  return false;
275 }
276 
277 bool Battlefield::GameServer::SetMaxPlayers(uint8_t maxplayers)
278 {
279  this->_maxplayers = maxplayers;
280  return true;
281 }
282 
283 bool Battlefield::GameServer::SetMaxPlayers(const std::string& str_maxplayers)
284 {
285  try
286  {
287  uint8_t maxplayers = static_cast<uint8_t>(std::stoul(str_maxplayers));
288 
289  return this->SetMaxPlayers(maxplayers);
290  }
291  catch(...) {};
292 
293  return false;
294 }
295 
296 bool Battlefield::GameServer::SetNumTeams(uint8_t numteams)
297 {
298  this->_numteams = numteams;
299  return true;
300 }
301 
302 bool Battlefield::GameServer::SetNumTeams(const std::string& str_numteams)
303 {
304  try
305  {
306  uint8_t numteams = static_cast<uint8_t>(std::stoul(str_numteams));
307 
308  return this->SetNumTeams(numteams);
309  }
310  catch(...) {};
311 
312  return false;
313 }
314 
315 bool Battlefield::GameServer::SetGameMode(const std::string& gamemode)
316 {
317  this->_gamemode = gamemode;
318  return true;
319 }
320 
321 bool Battlefield::GameServer::SetTeamplay(uint8_t teamplay)
322 {
323  this->_teamplay = teamplay;
324  return true;
325 }
326 
327 bool Battlefield::GameServer::SetTeamplay(const std::string& str_teamplay)
328 {
329  try
330  {
331  uint8_t teamplay = static_cast<uint8_t>(std::stoul(str_teamplay));
332 
333  return this->SetTeamplay(teamplay);
334  }
335  catch(...) {};
336 
337  return false;
338 }
339 
340 bool Battlefield::GameServer::SetFlagLimit(uint8_t fraglimit)
341 {
342  this->_fraglimit = fraglimit;
343  return true;
344 }
345 
346 bool Battlefield::GameServer::SetFlagLimit(const std::string& str_fraglimit)
347 {
348  try
349  {
350  uint8_t fraglimit = static_cast<uint8_t>(std::stoul(str_fraglimit));
351 
352  return this->SetFlagLimit(fraglimit);
353  }
354  catch(...) {};
355 
356  return false;
357 }
358 
359 bool Battlefield::GameServer::SetTeamFragLimit(uint8_t teamfraglimit)
360 {
361  this->_teamfraglimit = teamfraglimit;
362  return true;
363 }
364 
365 bool Battlefield::GameServer::SetTeamFragLimit(const std::string& str_teamfraglimit)
366 {
367  try
368  {
369  uint8_t teamfraglimit = static_cast<uint8_t>(std::stoul(str_teamfraglimit));
370 
371  return this->SetTeamFragLimit(teamfraglimit);
372  }
373  catch(...) {};
374 
375  return false;
376 }
377 
378 bool Battlefield::GameServer::SetTimeLimit(uint16_t timelimit)
379 {
380  this->_timelimit = timelimit;
381  return true;
382 }
383 
384 bool Battlefield::GameServer::SetTimeLimit(const std::string& str_timelimit)
385 {
386  try
387  {
388  uint16_t timelimit = static_cast<uint16_t>(std::stoul(str_timelimit));
389 
390  return this->SetTimeLimit(timelimit);
391  }
392  catch(...) {};
393 
394  return false;
395 }
396 
397 bool Battlefield::GameServer::SetTimeElapsed(uint16_t timeelapsed)
398 {
399  this->_timeelapsed = timeelapsed;
400  return true;
401 }
402 
403 bool Battlefield::GameServer::SetTimeElapsed(const std::string& str_timeelapsed)
404 {
405  try
406  {
407  uint16_t timeelapsed = static_cast<uint16_t>(std::stoul(str_timeelapsed));
408 
409  return this->SetTimeElapsed(timeelapsed);
410  }
411  catch(...) {};
412 
413  return false;
414 }
415 
416 bool Battlefield::GameServer::SetPassword(uint8_t password)
417 {
418  this->_password = password;
419  return true;
420 }
421 
422 bool Battlefield::GameServer::SetPassword(const std::string& str_password)
423 {
424  try
425  {
426  uint8_t password = static_cast<uint8_t>(std::stoul(str_password));
427 
428  return this->SetPassword(password);
429  }
430  catch(...) {};
431 
432  return false;
433 }
434 
435 bool Battlefield::GameServer::SetMinRank(uint8_t nr)
436 {
437  this->_nr = nr;
438  return true;
439 }
440 
441 bool Battlefield::GameServer::SetMinRank(const std::string& str_nr)
442 {
443  try
444  {
445  uint8_t nr = static_cast<uint8_t>(std::stoul(str_nr));
446 
447  return this->SetMinRank(nr);
448  }
449  catch(...) {};
450 
451  return false;
452 }
453 
454 bool Battlefield::GameServer::SetMaxRank(uint8_t xr)
455 {
456  this->_xr = xr;
457  return true;
458 }
459 
460 bool Battlefield::GameServer::SetMaxRank(const std::string& str_xr)
461 {
462  try
463  {
464  uint8_t xr = static_cast<uint8_t>(std::stoul(str_xr));
465 
466  return this->SetMaxRank(xr);
467  }
468  catch(...) {};
469 
470  return false;
471 }
472 
473 bool Battlefield::GameServer::SetFriendlyFire(uint8_t ff)
474 {
475  this->_ff = ff;
476  return true;
477 }
478 
479 bool Battlefield::GameServer::SetFriendlyFire(const std::string& str_ff)
480 {
481  try
482  {
483  uint8_t ff = static_cast<uint8_t>(std::stoul(str_ff));
484 
485  return this->SetFriendlyFire(ff);
486  }
487  catch(...) {};
488 
489  return false;
490 }
491 
492 bool Battlefield::GameServer::SetStatsTracking(uint8_t sr)
493 {
494  this->_sr = sr;
495  return true;
496 }
497 
498 bool Battlefield::GameServer::SetStatsTracking(const std::string& str_sr)
499 {
500  try
501  {
502  uint8_t sr = static_cast<uint8_t>(std::stoul(str_sr));
503 
504  return this->SetStatsTracking(sr);
505  }
506  catch(...) {};
507 
508  return false;
509 }
510 
511 bool Battlefield::GameServer::SetReconfigurable(uint8_t rc)
512 {
513  this->_rc = rc;
514  return true;
515 }
516 
517 bool Battlefield::GameServer::SetReconfigurable(const std::string& str_rc)
518 {
519  try
520  {
521  uint8_t rc = static_cast<uint8_t>(std::stoul(str_rc));
522 
523  return this->SetReconfigurable(rc);
524  }
525  catch(...) {};
526 
527  return false;
528 }
529 
530 bool Battlefield::GameServer::SetMinIpRange(int64_t ni)
531 {
532  this->_ni = ni;
533  return true;
534 }
535 
536 bool Battlefield::GameServer::SetMinIpRange(const std::string& str_ni)
537 {
538  try
539  {
540  int64_t ni = static_cast<int64_t>(std::stoll(str_ni));
541 
542  return this->SetMinIpRange(ni);
543  }
544  catch(...) {};
545 
546  return false;
547 }
548 
549 bool Battlefield::GameServer::SetMaxIpRange(int64_t xi)
550 {
551  this->_xi = xi;
552  return true;
553 }
554 
555 bool Battlefield::GameServer::SetMaxIpRange(const std::string& str_xi)
556 {
557  try
558  {
559  int64_t xi = static_cast<int64_t>(std::stoll(str_xi));
560 
561  return this->SetMaxIpRange(xi);
562  }
563  catch(...) {};
564 
565  return false;
566 }
567 
568 bool Battlefield::GameServer::SetQM(uint8_t qm)
569 {
570  this->_qm = qm;
571  return true;
572 }
573 
574 bool Battlefield::GameServer::SetQM(const std::string& str_qm)
575 {
576  try
577  {
578  uint8_t qm = static_cast<uint8_t>(std::stoul(str_qm));
579 
580  return this->SetQM(qm);
581  }
582  catch(...) {};
583 
584  return false;
585 }
586 
587 bool Battlefield::GameServer::SetRegion(uint64_t region)
588 {
589  this->_region = region;
590  return true;
591 }
592 
593 bool Battlefield::GameServer::SetRegion(const std::string& str_region)
594 {
595  try
596  {
597  uint64_t region = static_cast<uint64_t>(std::stoull(str_region));
598 
599  return this->SetRegion(region);
600  }
601  catch(...) {};
602 
603  return false;
604 }
605 
606 // Clan
607 bool Battlefield::GameServer::SetClan1Id(int c0)
608 {
609  this->_c0 = c0;
610  return true;
611 }
612 
613 bool Battlefield::GameServer::SetClan1Id(const std::string& str_c0)
614 {
615  try
616  {
617  int c0 = std::stoi(str_c0);
618 
619  return this->SetClan1Id(c0);
620  }
621  catch(...) {};
622 
623  return false;
624 }
625 
626 bool Battlefield::GameServer::SetClan2Id(int c1)
627 {
628  this->_c1 = c1;
629  return true;
630 }
631 
632 bool Battlefield::GameServer::SetClan2Id(const std::string& str_c1)
633 {
634  try
635  {
636  int c1 = std::stoi(str_c1);
637 
638  return this->SetClan2Id(c1);
639  }
640  catch(...) {};
641 
642  return false;
643 }
644 
645 bool Battlefield::GameServer::SetClan1Name(const std::string& n0)
646 {
647  this->_n0 = n0;
648  return true;
649 }
650 
651 bool Battlefield::GameServer::SetClan2Name(const std::string& n1)
652 {
653  this->_n1 = n1;
654  return true;
655 }
656 
657 bool Battlefield::GameServer::SetClan1Claimed(uint8_t c0c)
658 {
659  this->_c0c = c0c;
660  return true;
661 }
662 
663 bool Battlefield::GameServer::SetClan1Claimed(const std::string& str_c0c)
664 {
665  try
666  {
667  uint8_t c0c = static_cast<uint8_t>(std::stoul(str_c0c));
668 
669  return this->SetClan1Claimed(c0c);
670  }
671  catch(...) {};
672 
673  return false;
674 }
675 
676 bool Battlefield::GameServer::SetClan2Claimed(uint8_t c1c)
677 {
678  this->_c1c = c1c;
679  return true;
680 }
681 
682 bool Battlefield::GameServer::SetClan2Claimed(const std::string& str_c1c)
683 {
684  try
685  {
686  uint8_t c1c = static_cast<uint8_t>(std::stoul(str_c1c));
687 
688  return this->SetClan2Claimed(c1c);
689  }
690  catch(...) {};
691 
692  return false;
693 }
694 
695 bool Battlefield::GameServer::SetTeam1Name(const std::string& team0)
696 {
697  this->_team0 = team0;
698  return true;
699 }
700 
701 bool Battlefield::GameServer::SetTeam2Name(const std::string& team1)
702 {
703  this->_team1 = team1;
704  return true;
705 }
706 
707 bool Battlefield::GameServer::SetTeam1Score(int16_t score0)
708 {
709  this->_score0 = score0;
710  return true;
711 }
712 
713 bool Battlefield::GameServer::SetTeam1Score(const std::string& str_score0)
714 {
715  try
716  {
717  int16_t score0 = static_cast<int16_t>(std::stoi(str_score0));
718 
719  return this->SetTeam1Score(score0);
720  }
721  catch(...) {};
722 
723  return false;
724 }
725 
726 bool Battlefield::GameServer::SetTeam2Score(int16_t score1)
727 {
728  this->_score1 = score1;
729  return true;
730 }
731 
732 bool Battlefield::GameServer::SetTeam2Score(const std::string& str_score1)
733 {
734  try
735  {
736  int16_t score1 = static_cast<int16_t>(std::stoi(str_score1));
737 
738  return this->SetTeam2Score(score1);
739  }
740  catch(...) {};
741 
742  return false;
743 }
744 
745 bool Battlefield::GameServer::SetUpdatedAt(MYSQL_TIME updated_at)
746 {
747  this->_updated_at = Util::Time::GetDateTime(updated_at);
748 
749  return true;
750 }
751 
752 bool Battlefield::GameServer::SetVerified(bool verified)
753 {
754  this->_verified = verified;
755  return true;
756 }
757 
758 bool Battlefield::GameServer::SetVerified(uint8_t verified)
759 {
760  return this->SetVerified(verified == 1);
761 }
762 
764 {
765  this->_players.push_back(gsplayer);
766 }
767 
769 {
770  struct tm timeinfo = {};
771 
772  if (strptime(this->GetUpdatedAt().c_str(), "%Y-%m-%d %H:%M:%S %Z", &timeinfo) != nullptr)
773  {
774  std::chrono::system_clock::time_point current_time_point = std::chrono::system_clock::now();
775  std::chrono::system_clock::time_point two_minutes_ago = current_time_point - std::chrono::minutes(2);
776 
777  // get time_t
778  std::time_t current_time = std::chrono::system_clock::to_time_t(current_time_point);
779  std::time_t two_minutes_ago_time = std::chrono::system_clock::to_time_t(two_minutes_ago);
780  std::time_t target_time = std::mktime(&timeinfo);
781 
782  //Logger::debug("target_time: " + std::string(std::ctime(&target_time)));
783  //Logger::debug("current_time: " + std::string(std::ctime(&current_time)));
784  //Logger::debug("two_minutes_ago_time: " + std::string(std::ctime(&two_minutes_ago_time)));
785 
786  return (std::difftime(target_time, current_time) <= 0 && std::difftime(target_time, two_minutes_ago_time) >= 0);
787  }
788 
789  return false;
790 }
791 
792 void Battlefield::GameServer::Debug()
793 {
794  Logger::debug("============================");
795  Logger::debug("id = " + std::to_string(this->GetId()));
796  Logger::debug("ip = " + this->GetIp());
797  Logger::debug("port = " + std::to_string(this->GetPort()));
798  Logger::debug("flag = " + std::to_string(this->GetFlag()));
799  Logger::debug("localip0 = " + this->GetLocalIp());
800  Logger::debug("localport = " + std::to_string(this->GetLocalPort()));
801  Logger::debug("natneg = " + std::to_string(this->GetNatNeg()));
802  Logger::debug("gamename = " + this->GetGameName());
803  Logger::debug("hostname = " + this->GetHostName());
804  Logger::debug("hostport = " + std::to_string(this->GetHostPort()));
805  Logger::debug("gamever = " + this->GetGameVersion());
806  Logger::debug("cl = " + this->GetClientVersion());
807  Logger::debug("rv = " + this->GetRV());
808  Logger::debug("map = " + this->GetMap());
809  Logger::debug("mc = " + std::to_string(this->GetMapCycling()));
810  Logger::debug("mapname = " + std::to_string(this->GetMapName()));
811  Logger::debug("gc = " + std::to_string(this->GetGC()));
812  Logger::debug("gametype = " + this->GetGameType());
813  Logger::debug("gamevariant = " + this->GetGameVariant());
814  Logger::debug("numplayers = " + std::to_string(this->GetNumPlayers()));
815  Logger::debug("maxplayers = " + std::to_string(this->GetMaxPlayers()));
816  Logger::debug("numteams = " + std::to_string(this->GetNumTeams()));
817  Logger::debug("gamemode = " + this->GetGameMode());
818  Logger::debug("teamplay = " + std::to_string(this->GetTeamplay()));
819  Logger::debug("fraglimit = " + std::to_string(this->GetFlagLimit()));
820  Logger::debug("teamfraglimit = " + std::to_string(this->GetTeamFragLimit()));
821  Logger::debug("timelimit = " + std::to_string(this->GetTimeLimit()));
822  Logger::debug("timeelapsed = " + std::to_string(this->GetTimeElapsed()));
823  Logger::debug("password = " + std::to_string(this->GetPassword()));
824  Logger::debug("nr = " + std::to_string(this->GetMinRank()));
825  Logger::debug("xr = " + std::to_string(this->GetMaxRank()));
826  Logger::debug("ff = " + std::to_string(this->GetFriendlyFire()));
827  Logger::debug("sr = " + std::to_string(this->GetStatsTracking()));
828  Logger::debug("rc = " + std::to_string(this->GetReconfigurable()));
829  Logger::debug("ni = " + std::to_string(this->GetMinIpRange()));
830  Logger::debug("xi = " + std::to_string(this->GetMaxIpRange()));
831  Logger::debug("qm = " + std::to_string(this->GetQM()));
832  Logger::debug("region = " + std::to_string(this->GetRegion()));
833  Logger::debug("c0 = " + std::to_string(this->GetClan1Id()));
834  Logger::debug("c1 = " + std::to_string(this->GetClan2Id()));
835  Logger::debug("n0 = " + this->GetClan1Name());
836  Logger::debug("n1 = " + this->GetClan2Name());
837  Logger::debug("c0c = " + std::to_string(this->GetClan1Claimed()));
838  Logger::debug("c1c = " + std::to_string(this->GetClan2Claimed()));
839  Logger::debug("team0 = " + this->GetTeam1Name());
840  Logger::debug("score0 = " + std::to_string(this->GetTeam1Score()));
841  Logger::debug("team1 = " + this->GetTeam2Name());
842  Logger::debug("score1 = " + std::to_string(this->GetTeam2Score()));
843 }
844 
845 // GameServerPlayer
846 
847 bool Battlefield::GameServerPlayer::SetId(int id)
848 {
849  this->_id = id;
850  return true;
851 }
852 
853 bool Battlefield::GameServerPlayer::SetName(const std::string& name)
854 {
855  this->_name = name;
856  return true;
857 }
858 
859 bool Battlefield::GameServerPlayer::SetScore(int16_t score)
860 {
861  this->_score = score;
862  return true;
863 }
864 
865 bool Battlefield::GameServerPlayer::SetScore(const std::string& str_score)
866 {
867  try
868  {
869  int16_t score = static_cast<int16_t>(std::stoi(str_score));
870 
871  return this->SetScore(score);
872  }
873  catch(...) {};
874 
875  return false;
876 }
877 
878 bool Battlefield::GameServerPlayer::SetSkill(const std::string& skill)
879 {
880  this->_skill = skill;
881  return true;
882 }
883 
884 bool Battlefield::GameServerPlayer::SetPing(uint8_t ping)
885 {
886  this->_ping = ping;
887  return true;
888 }
889 
890 bool Battlefield::GameServerPlayer::SetPing(const std::string& str_ping)
891 {
892  try
893  {
894  uint8_t ping = static_cast<uint8_t>(std::stoul(str_ping));
895 
896  return this->SetPing(ping);
897  }
898  catch(...) {};
899 
900  return false;
901 }
902 
903 bool Battlefield::GameServerPlayer::SetTeam(uint8_t team)
904 {
905  this->_team = team;
906  return true;
907 }
908 
909 bool Battlefield::GameServerPlayer::SetTeam(const std::string& str_team)
910 {
911  try
912  {
913  uint8_t team = static_cast<uint8_t>(std::stoul(str_team));
914 
915  return this->SetTeam(team);
916  }
917  catch(...) {};
918 
919  return false;
920 }
921 
922 bool Battlefield::GameServerPlayer::SetDeaths(uint16_t deaths)
923 {
924  this->_deaths = deaths;
925  return true;
926 }
927 
928 bool Battlefield::GameServerPlayer::SetDeaths(const std::string& str_deaths)
929 {
930  try
931  {
932  uint16_t deaths = static_cast<uint16_t>(std::stoul(str_deaths));
933 
934  return this->SetDeaths(deaths);
935  }
936  catch(...) {};
937 
938  return false;
939 }
940 
941 bool Battlefield::GameServerPlayer::SetProfileId(int profileid)
942 {
943  this->_profileid = profileid;
944  return true;
945 }
946 
947 bool Battlefield::GameServerPlayer::SetProfileId(const std::string& str_profileid)
948 {
949  try
950  {
951  int profileid = std::stoi(str_profileid);
952 
953  return this->SetProfileId(profileid);
954  }
955  catch(...) {};
956 
957  return false;
958 }
959 
Represents a player in a game server.
Definition: gameserver.h:385
void useExample()
Performs an example operation using the GameServer class.
Definition: gameserver.cpp:54
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