Mania++
 All Classes Functions Variables Pages
Player.h
1 #ifndef PLAYER_H_
2 #define PLAYER_H_
3 
4 #include "../GbxRemote/Response/GbxResponse.h"
5 
6 //* Player
10 struct Player
11 {
12  // === Mania++ information ===
13  int Id = 0;
14  std::vector<int> CurrentCheckpoints;
16  // === Basic information ===
17  int PlayerId;
18  int TeamId;
20  std::string Login;
21  std::string NickName;
24  int Flags;
28  // === Detailed information ===
29  std::string IPAddress;
31  int UploadRate;
33  std::string Language;
35  bool IsSpectator;
38  std::string ClientVersion;
39  std::string ClubLink;
40  std::string Path;
41  std::string Country;
47  {
48  CurrentCheckpoints = std::vector<int>();
49  }
50 
56  Player(std::map<std::string, GbxResponseParameter> serverStruct)
57  {
58  CurrentCheckpoints = std::vector<int>();
59  if(serverStruct.find("Login") != serverStruct.end())
60  {
61  setBasicInfo(serverStruct);
62  }
63  }
64 
70  void PlayerDetailed(std::map<std::string, GbxResponseParameter> serverStruct)
71  {
72  if(serverStruct.find("Language") != serverStruct.end())
73  {
74  setDetailedInfo(serverStruct);
75  }
76  }
77 
83  void SetId(int id)
84  {
85  Id = id;
86  }
87 
88 private:
94  void setBasicInfo(std::map<std::string, GbxResponseParameter> serverStruct)
95  {
96  PlayerId = atoi(serverStruct.find("PlayerId")->second.GetString().c_str());
97  TeamId = atoi(serverStruct.find("TeamId")->second.GetString().c_str());
98 
99  Login = serverStruct.find("Login")->second.GetString();
100  NickName = serverStruct.find("NickName")->second.GetString();
101 
102  SpectatorStatus = atoi(serverStruct.find("SpectatorStatus")->second.GetString().c_str());
103  Flags = atoi(serverStruct.find("Flags")->second.GetString().c_str());
104 
105  LadderRanking = atoi(serverStruct.find("LadderRanking")->second.GetString().c_str());
106  }
107 
113  void setDetailedInfo(std::map<std::string, GbxResponseParameter> serverStruct)
114  {
115  IPAddress = serverStruct.find("IPAddress")->second.GetString();
116  DownloadRate = atoi(serverStruct.find("DownloadRate")->second.GetString().c_str());
117  UploadRate = atoi(serverStruct.find("UploadRate")->second.GetString().c_str());
118 
119  Language = serverStruct.find("Language")->second.GetString();
120 
121  std::istringstream(serverStruct.find("IsSpectator")->second.GetString()) >> IsSpectator;
122  std::istringstream(serverStruct.find("IsInOfficialMode")->second.GetString()) >> IsInOfficialMode;
123 
124  ClientVersion = serverStruct.find("ClientVersion")->second.GetString();
125  ClubLink = serverStruct.find("ClubLink")->second.GetString();
126 
127  std::string path = serverStruct.find("Path")->second.GetString().substr(6); // Remove World|
128  Path = path; // Remove World|
129 
130  std::vector<std::string> continents = { "Europe|", "Africa|", "Asia|", "Middle East|", "North America|", "South America|", "Oceania|" };
131  for(int continentId = 0; continentId < continents.size(); continentId++)
132  {
133  std::string continent = continents.at(continentId);
134  std::string::size_type i = path.find(continent);
135  if (i != std::string::npos)
136  path.erase(i, continent.length());
137  }
138 
139  Country = path;
140  }
141 };
142 
143 #endif // PLAYER_H_
int SpectatorStatus
Spectator status of player.
Definition: Player.h:23
int UploadRate
Upload rate in Kbps.
Definition: Player.h:31
bool IsInOfficialMode
Is in official mode?
Definition: Player.h:36
void PlayerDetailed(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Player.h:70
Player(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Player.h:56
std::string Language
Application language.
Definition: Player.h:33
int LadderRanking
Current ladder ranking of the player.
Definition: Player.h:26
std::string ClientVersion
Client version (f.e. 'v2015-06-18_15_10 (3.3.0)').
Definition: Player.h:38
std::string Country
Path without continent.
Definition: Player.h:41
Contains all information about a player in easy-to-use format.
Definition: Player.h:10
std::string NickName
Player nickname.
Definition: Player.h:21
void setDetailedInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the detailed player information from the struct.
Definition: Player.h:113
std::string ClubLink
Club URL (website, entered by player).
Definition: Player.h:39
std::vector< int > CurrentCheckpoints
Checkpoint passes on current try.
Definition: Player.h:14
int DownloadRate
Download rate in Kbps.
Definition: Player.h:30
int Flags
Player flags.
Definition: Player.h:24
bool IsSpectator
Is in spectatormode?
Definition: Player.h:35
void SetId(int id)
Set database identifier value.
Definition: Player.h:83
std::string IPAddress
IP Address of the player.
Definition: Player.h:29
std::string Path
Player location without "world".
Definition: Player.h:40
std::string Login
Player login.
Definition: Player.h:20
void setBasicInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the basic player information from the struct.
Definition: Player.h:94
Player()
Constructs a Player object without input.
Definition: Player.h:46
int PlayerId
Player identifier (on server).
Definition: Player.h:17
int TeamId
Team identifier (on server).
Definition: Player.h:18
int Id
Player identifier (on database).
Definition: Player.h:13