Mania++
 All Classes Functions Variables Pages
Player.h
1 #ifndef PLAYER_H_
2 #define PLAYER_H_
3 
4 #include "../GbxRemote/Response/GbxResponse.h"
5 #include "../Permissions/Permission.h"
6 
7 //* Player
11 struct Player
12 {
13  // === Mania++ information ===
14  int Id = 0;
15  std::vector<int> CurrentCheckpoints;
16  time_t JoinedAt;
17  Permission AccessLevel = User;
19  // === Basic information ===
20  int PlayerId;
21  int TeamId;
23  std::string Login;
24  std::string NickName;
27  int Flags;
31  // === Detailed information ===
32  std::string IPAddress;
34  int UploadRate;
36  std::string Language;
38  bool IsSpectator;
41  std::string ClientVersion;
42  std::string ClubLink;
43  std::string Path;
44  std::string Country;
50  {
51  CurrentCheckpoints = std::vector<int>();
52  }
53 
59  Player(std::map<std::string, GbxResponseParameter> serverStruct)
60  {
61  CurrentCheckpoints = std::vector<int>();
62  if(serverStruct.find("Login") != serverStruct.end())
63  {
64  setBasicInfo(serverStruct);
65  }
66  }
67 
73  void SetBasic(std::map<std::string, GbxResponseParameter> serverStruct)
74  {
75  if(serverStruct.find("Login") != serverStruct.end())
76  {
77  setBasicInfo(serverStruct);
78  }
79  }
80 
86  void PlayerDetailed(std::map<std::string, GbxResponseParameter> serverStruct)
87  {
88  if(serverStruct.find("Language") != serverStruct.end())
89  {
90  setDetailedInfo(serverStruct);
91  }
92  }
93 
99  void SetId(int id)
100  {
101  Id = id;
102  }
103 
104 private:
110  void setBasicInfo(std::map<std::string, GbxResponseParameter> serverStruct)
111  {
112  PlayerId = atoi(serverStruct.find("PlayerId")->second.GetString().c_str());
113  TeamId = atoi(serverStruct.find("TeamId")->second.GetString().c_str());
114 
115  Login = serverStruct.find("Login")->second.GetString();
116  NickName = serverStruct.find("NickName")->second.GetString();
117 
118  SpectatorStatus = atoi(serverStruct.find("SpectatorStatus")->second.GetString().c_str());
119  Flags = atoi(serverStruct.find("Flags")->second.GetString().c_str());
120 
121  LadderRanking = atoi(serverStruct.find("LadderRanking")->second.GetString().c_str());
122  }
123 
129  void setDetailedInfo(std::map<std::string, GbxResponseParameter> serverStruct)
130  {
131  IPAddress = serverStruct.find("IPAddress")->second.GetString();
132  DownloadRate = atoi(serverStruct.find("DownloadRate")->second.GetString().c_str());
133  UploadRate = atoi(serverStruct.find("UploadRate")->second.GetString().c_str());
134 
135  Language = serverStruct.find("Language")->second.GetString();
136 
137  std::istringstream(serverStruct.find("IsSpectator")->second.GetString()) >> IsSpectator;
138  std::istringstream(serverStruct.find("IsInOfficialMode")->second.GetString()) >> IsInOfficialMode;
139 
140  ClientVersion = serverStruct.find("ClientVersion")->second.GetString();
141  ClubLink = serverStruct.find("ClubLink")->second.GetString();
142 
143  std::string path = serverStruct.find("Path")->second.GetString().substr(6); // Remove World|
144  Path = path; // Remove World|
145 
146  std::vector<std::string> continents = { "Europe|", "Africa|", "Asia|", "Middle East|", "North America|", "South America|", "Oceania|" };
147  for(int continentId = 0; continentId < continents.size(); continentId++)
148  {
149  std::string continent = continents.at(continentId);
150  std::string::size_type i = path.find(continent);
151  if (i != std::string::npos)
152  path.erase(i, continent.length());
153  }
154 
155  Country = path;
156  }
157 };
158 
159 #endif // PLAYER_H_
int SpectatorStatus
Spectator status of player.
Definition: Player.h:26
int UploadRate
Upload rate in Kbps.
Definition: Player.h:34
bool IsInOfficialMode
Is in official mode?
Definition: Player.h:39
void PlayerDetailed(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Player.h:86
void SetBasic(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Player.h:73
Player(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Player.h:59
std::string Language
Application language.
Definition: Player.h:36
int LadderRanking
Current ladder ranking of the player.
Definition: Player.h:29
Permission AccessLevel
Permission level.
Definition: Player.h:17
std::string ClientVersion
Client version (f.e. 'v2015-06-18_15_10 (3.3.0)').
Definition: Player.h:41
std::string Country
Path without continent.
Definition: Player.h:44
Contains all information about a player in easy-to-use format.
Definition: Player.h:11
std::string NickName
Player nickname.
Definition: Player.h:24
void setDetailedInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the detailed player information from the struct.
Definition: Player.h:129
std::string ClubLink
Club URL (website, entered by player).
Definition: Player.h:42
std::vector< int > CurrentCheckpoints
Checkpoint passes on current try.
Definition: Player.h:15
int DownloadRate
Download rate in Kbps.
Definition: Player.h:33
int Flags
Player flags.
Definition: Player.h:27
bool IsSpectator
Is in spectatormode?
Definition: Player.h:38
void SetId(int id)
Set database identifier value.
Definition: Player.h:99
std::string IPAddress
IP Address of the player.
Definition: Player.h:32
time_t JoinedAt
The timestamp on join.
Definition: Player.h:16
std::string Path
Player location without "world".
Definition: Player.h:43
std::string Login
Player login.
Definition: Player.h:23
void setBasicInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the basic player information from the struct.
Definition: Player.h:110
Player()
Constructs a Player object without input.
Definition: Player.h:49
int PlayerId
Player identifier (on server).
Definition: Player.h:20
int TeamId
Team identifier (on server).
Definition: Player.h:21
int Id
Player identifier (on database).
Definition: Player.h:14