SuperTuxKart
player_profile.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2010-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_PLAYER_PROFILE_HPP
20 #define HEADER_PLAYER_PROFILE_HPP
21 
22 #include "challenges/story_mode_status.hpp"
23 #include "config/favorite_status.hpp"
25 #include "utils/leak_check.hpp"
26 #include "utils/no_copy.hpp"
27 #include "utils/types.hpp"
28 
29 #include <irrString.h>
30 using namespace irr;
31 
32 #include <string>
33 
34 class AchievementsStatus;
35 namespace Online
36 {
37  class CurrentUser;
38  class HTTPRequest;
39  class OnlineProfile;
40  class XMLRequest;
41 }
42 class UTFWriter;
43 
54 class PlayerProfile : public NoCopy
55 {
56 public:
59  {
60  OS_SIGNED_OUT = 0,
61  OS_SIGNED_IN,
62  OS_GUEST,
63  OS_SIGNING_IN,
64  OS_SIGNING_OUT
65  };
66 
67 
68 private:
69  LEAK_CHECK()
70 
71 #ifdef DEBUG
72  unsigned int m_magic_number;
73 #endif
74 
77  core::stringw m_local_name;
78 
81 
84 
86  unsigned int m_unique_id;
87 
89  std::string m_icon_filename;
90 
93 
96 
98  std::string m_saved_token;
99 
101  core::stringw m_last_online_name;
102 
105 
108 
111 
114 
117 
120 
123 
124 public:
125 
126  PlayerProfile(const core::stringw &name, bool is_guest = false);
127  PlayerProfile(const XMLNode *node);
128  virtual ~PlayerProfile();
129  void save(UTFWriter &out);
130  void loadRemainingData(const XMLNode *node);
131  void initRemainingData();
132  void incrementUseFrequency();
133  int getUseFrequency() const { return m_use_frequency; }
134  bool operator<(const PlayerProfile &other);
135  void raceFinished();
136  void saveSession(int user_id, const std::string &token);
137  void clearSession(bool save=true);
138  void addIcon();
139 
141  virtual void setUserDetails(std::shared_ptr<Online::HTTPRequest> request,
142  const std::string &action,
143  const std::string &url_path = "") const = 0;
144  virtual uint32_t getOnlineId() const = 0;
145  virtual PlayerProfile::OnlineState getOnlineState() const = 0;
146  virtual Online::OnlineProfile* getProfile() const = 0;
147  virtual void requestPoll() const = 0;
148  virtual void requestSavedSession() = 0;
149  virtual void requestSignIn(const irr::core::stringw &username,
150  const irr::core::stringw &password) = 0;
151  virtual void signIn(bool success, const XMLNode * input) = 0;
152  virtual void signOut(bool success, const XMLNode * input,
153  const irr::core::stringw &info) = 0;
154  virtual void requestSignOut() = 0;
155  virtual bool isLoggedIn() const { return false; }
156  const std::string getIconFilename() const;
157  // ----------------------------------------------------------------------------------------
159  void setName(const core::stringw& name)
160  {
161  #ifdef DEBUG
162  assert(m_magic_number == 0xABCD1234);
163  #endif
164  m_local_name = name;
165  } // setName
166 
167  // ----------------------------------------------------------------------------------------
169  const core::stringw& getName() const
170  {
171  #ifdef DEBUG
172  assert(m_magic_number == 0xABCD1234);
173  #endif
174  return m_local_name;
175  } // getName
176 
177  // ----------------------------------------------------------------------------------------
179  bool isGuestAccount() const
180  {
181  #ifdef DEBUG
182  assert(m_magic_number == 0xABCD1234);
183  #endif
184  return m_is_guest_account;
185  } // isGuestAccount
186  // ----------------------------------------------------------------------------------------
188  const core::stringw& getLastOnlineName() const
189  {
190  return m_last_online_name;
191  } // getLastOnlineName
192  // ----------------------------------------------------------------------------------------
194  void setLastOnlineName(const core::stringw &name)
195  {
196  m_last_online_name = name;
197  } // setLastOnlineName
198  // ----------------------------------------------------------------------------------------
200  unsigned int getUniqueID() const { return m_unique_id; }
201  // ----------------------------------------------------------------------------------------
203  bool isLocked(const std::string &feature) const
204  {
205  return m_story_mode_status->isLocked(feature);
206  } // isLocked
207  // ----------------------------------------------------------------------------------------
209  void computeActive() { m_story_mode_status->computeActive(); }
210  // ----------------------------------------------------------------------------------------
212  std::vector<const ChallengeData*> getRecentlyCompletedChallenges()
213  {
214  return m_story_mode_status->getRecentlyCompletedChallenges();
215  } // getRecently Completed Challenges
216  // ----------------------------------------------------------------------------------------
218  void setCurrentChallenge(const std::string &name)
219  {
220  m_story_mode_status->setCurrentChallenge(name);
221  } // setCurrentChallenge
222  // ----------------------------------------------------------------------------------------
225  void grandPrixFinished() { m_story_mode_status->grandPrixFinished(); }
226  // ----------------------------------------------------------------------------------------
227  unsigned int getNumCompletedChallenges() const { return m_story_mode_status->getNumCompletedChallenges(); }
228  // ----------------------------------------------------------------------------------------
229  unsigned int getPoints() const { return m_story_mode_status->getPoints(); }
230  // ----------------------------------------------------------------------------------------
231  unsigned int getPointsBefore() const { return m_story_mode_status->getPointsBefore(); }
232  // ----------------------------------------------------------------------------------------
233  unsigned int getNextUnlockPoints() const { return m_story_mode_status->getNextUnlockPoints(); }
234  // ----------------------------------------------------------------------------------------
235  void setFirstTime(bool b) { m_story_mode_status->setFirstTime(b); }
236  // ----------------------------------------------------------------------------------------
237  bool isFirstTime() const { return m_story_mode_status->isFirstTime(); }
238  // ----------------------------------------------------------------------------------------
239  void setFinished() { m_story_mode_status->setFinished(); }
240  // ----------------------------------------------------------------------------------------
241  bool isFinished() const { return m_story_mode_status->isFinished(); }
242  // ----------------------------------------------------------------------------------------
243  void setSpeedrunFinished() { m_story_mode_status->setSpeedrunFinished(); }
244  // ----------------------------------------------------------------------------------------
245  bool isSpeedrunFinished() { return m_story_mode_status->isSpeedrunFinished(); }
246  // ----------------------------------------------------------------------------------------
247  void setStoryModeTimer(int ms) { m_story_mode_status->setStoryModeTimer(ms); }
248  // ----------------------------------------------------------------------------------------
249  int getStoryModeTimer() { return m_story_mode_status->getStoryModeTimer(); }
250  // ----------------------------------------------------------------------------------------
251  void setSpeedrunTimer(int ms) { m_story_mode_status->setSpeedrunTimer(ms); }
252  // ----------------------------------------------------------------------------------------
253  int getSpeedrunTimer() { return m_story_mode_status->getSpeedrunTimer(); }
254  // ----------------------------------------------------------------------------------------
255  void clearUnlocked()
256  {
257  m_story_mode_status->clearUnlocked();
258  }
259  // ----------------------------------------------------------------------------------------
262  {
263  return m_story_mode_status->getCurrentChallengeStatus();
264  } // getCurrentChallengeStatus
265  // ----------------------------------------------------------------------------------------
266  const ChallengeStatus* getChallengeStatus(const std::string &id)
267  {
268  return m_story_mode_status->getChallengeStatus(id);
269  } // getChallengeStatus
270  // ----------------------------------------------------------------------------------------
271  unsigned int getNumEasyTrophies() const
272  {
273  return m_story_mode_status->getNumEasyTrophies();
274  } // getNumEasyTrophies
275  // ----------------------------------------------------------------------------------------
276  unsigned int getNumMediumTrophies() const
277  {
278  return m_story_mode_status->getNumMediumTrophies();
279  } // getNumEasyTrophies
280  // -----------------------------------------------------------------------
281  unsigned int getNumHardTrophies() const
282  {
283  return m_story_mode_status->getNumHardTrophies();
284  } // getNumHardTrophies
285  unsigned int getNumBestTrophies() const
286  {
287  return m_story_mode_status->getNumBestTrophies();
288  } // getNumBestTrophies
289  // ----------------------------------------------------------------------------------------
290  AchievementsStatus* getAchievementsStatus()
291  {
292  return m_achievements_status;
293  } // getAchievementsStatus
294  // ----------------------------------------------------------------------------------------
296  bool hasSavedSession() const { return m_saved_session; }
297  // ----------------------------------------------------------------------------------------
298  StoryModeStatus* getStoryModeStatus() { return m_story_mode_status; }
299  // ----------------------------------------------------------------------------------------
300  FavoriteStatus* getFavoriteTrackStatus() { return m_favorite_track_status; }
301  // ----------------------------------------------------------------------------------------
302  FavoriteStatus* getFavoriteKartStatus() { return m_favorite_kart_status; }
303  // ----------------------------------------------------------------------------------------
304  bool isFavoriteTrack(std::string ident)
305  {
306  return m_favorite_track_status->isFavorite(ident);
307  }
308  void addFavoriteTrack(std::string ident, std::string group =
309  FavoriteStatus::DEFAULT_FAVORITE_GROUP_NAME)
310  {
311  m_favorite_track_status->addFavorite(ident, group);
312  }
313  void removeFavoriteTrack(std::string ident, std::string group =
314  FavoriteStatus::DEFAULT_FAVORITE_GROUP_NAME)
315  {
316  m_favorite_track_status->removeFavorite(ident, group);
317  }
318  // ----------------------------------------------------------------------------------------
319  bool isFavoriteKart(std::string ident)
320  {
321  return m_favorite_kart_status->isFavorite(ident);
322  }
323  void addFavoriteKart(std::string ident, std::string group =
324  FavoriteStatus::DEFAULT_FAVORITE_GROUP_NAME)
325  {
326  m_favorite_kart_status->addFavorite(ident, group);
327  }
328  void removeFavoriteKart(std::string ident, std::string group =
329  FavoriteStatus::DEFAULT_FAVORITE_GROUP_NAME)
330  {
331  m_favorite_kart_status->removeFavorite(ident, group);
332  }
333  // ----------------------------------------------------------------------------------------
335  int getSavedUserId() const
336  {
337  assert(m_saved_session);
338  return m_saved_user_id;
339  } // getSavedUserId
340  // ----------------------------------------------------------------------------------------
342  const std::string& getSavedToken() const
343  {
344  assert(m_saved_session);
345  return m_saved_token;
346  } // getSavedToken
347  // ----------------------------------------------------------------------------------------
350  bool wasOnlineLastTime() const { return m_last_was_online; }
351  // ----------------------------------------------------------------------------------------
353  void setWasOnlineLastTime(bool b) { m_last_was_online = b; }
354  // ----------------------------------------------------------------------------------------
357  bool rememberPassword() const { return m_remember_password; }
358  // ----------------------------------------------------------------------------------------
360  void setRememberPassword(bool b) { m_remember_password = b; }
361  // ----------------------------------------------------------------------------------------
362  void setDefaultKartColor(float c) { m_default_kart_color = c; }
363  // ----------------------------------------------------------------------------------------
364  float getDefaultKartColor() const { return m_default_kart_color; }
365 
366 }; // class PlayerProfile
367 
368 #endif
369 
370 /*EOF*/
This class keeps tracks of all achievements of one player.
Definition: achievements_status.hpp:43
The state of a challenge for one player.
Definition: challenge_status.hpp:53
Class for storing the current favorites/custom groups of karts and tracks.
Definition: favorite_status.hpp:43
bool isFavorite(std::string ident)
Adds a new favorite track to this player profile and to the group of favorite tracks of the Track Man...
Definition: favorite_status.cpp:69
void addFavorite(std::string ident, std::string group=DEFAULT_FAVORITE_GROUP_NAME)
Adds a new favorite track to this player profile and to the group of favorite tracks of the Track Man...
Definition: favorite_status.cpp:79
void removeFavorite(std::string ident, std::string group=DEFAULT_FAVORITE_GROUP_NAME)
Removes a favorite track from this player profile and from the group of favorite tracks of the Track ...
Definition: favorite_status.cpp:88
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Class that represents an online profile.
Definition: online_profile.hpp:42
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:55
unsigned int getUniqueID() const
Returns the unique id of this player.
Definition: player_profile.hpp:200
void grandPrixFinished()
Callback when a GP is finished (to test if a challenge was fulfilled).
Definition: player_profile.hpp:225
bool hasSavedSession() const
Returns true if a session was saved for this player.
Definition: player_profile.hpp:296
bool m_saved_session
True if this user has a saved session.
Definition: player_profile.hpp:92
const core::stringw & getName() const
Returns the name of this player.
Definition: player_profile.hpp:169
AchievementsStatus * m_achievements_status
The complete achievement data.
Definition: player_profile.hpp:116
int getSavedUserId() const
If a session was saved, return the id of the saved user.
Definition: player_profile.hpp:335
void setCurrentChallenge(const std::string &name)
Sets the currently active challenge.
Definition: player_profile.hpp:218
int m_use_frequency
Counts how often this player was used (always -1 for guests).
Definition: player_profile.hpp:83
void setLastOnlineName(const core::stringw &name)
Sets the last used online name.
Definition: player_profile.hpp:194
const std::string & getSavedToken() const
If a session was saved, return the token to use.
Definition: player_profile.hpp:342
std::string m_icon_filename
Absolute path of the icon file for this player.
Definition: player_profile.hpp:89
const core::stringw & getLastOnlineName() const
Returns the last used online name.
Definition: player_profile.hpp:188
StoryModeStatus * m_story_mode_status
The complete challenge state.
Definition: player_profile.hpp:113
std::string m_saved_token
The token of the saved session.
Definition: player_profile.hpp:98
void setName(const core::stringw &name)
Sets the name of this player.
Definition: player_profile.hpp:159
void setRememberPassword(bool b)
Sets if this player was logged in last time it was used.
Definition: player_profile.hpp:360
bool m_last_was_online
True if the last time this player was used as online.
Definition: player_profile.hpp:104
FavoriteStatus * m_favorite_kart_status
The favorite karts selected by this player.
Definition: player_profile.hpp:122
core::stringw m_local_name
The name of the player (wide string, so it can be in native language).
Definition: player_profile.hpp:77
const ChallengeStatus * getCurrentChallengeStatus() const
Returns the current challenge for this player.
Definition: player_profile.hpp:261
OnlineState
The online state a player can be in.
Definition: player_profile.hpp:59
bool isLocked(const std::string &feature) const
Returnes if the feature (kart, track) is locked.
Definition: player_profile.hpp:203
bool isGuestAccount() const
Returns true if this player is a guest account.
Definition: player_profile.hpp:179
std::vector< const ChallengeData * > getRecentlyCompletedChallenges()
Returns the list of recently completed challenges.
Definition: player_profile.hpp:212
unsigned int m_unique_id
A unique number for this player, used to link it to challenges etc.
Definition: player_profile.hpp:86
bool m_is_guest_account
True if this account is a guest account.
Definition: player_profile.hpp:80
void setWasOnlineLastTime(bool b)
Sets if this player was logged in last time it was used.
Definition: player_profile.hpp:353
float m_default_kart_color
Default kart color (in hue) used in game, 0.0f to use the original.
Definition: player_profile.hpp:110
void computeActive()
Returns all active challenges.
Definition: player_profile.hpp:209
bool rememberPassword() const
Returns if the last time this player was used it was used online or offline.
Definition: player_profile.hpp:357
FavoriteStatus * m_favorite_track_status
The favorite tracks selected by this player.
Definition: player_profile.hpp:119
int m_saved_user_id
If a session was saved, this will be the online user id to use.
Definition: player_profile.hpp:95
bool wasOnlineLastTime() const
Returns if the last time this player was used it was used online or offline.
Definition: player_profile.hpp:350
virtual void setUserDetails(std::shared_ptr< Online::HTTPRequest > request, const std::string &action, const std::string &url_path="") const =0
Abstract virtual classes, to be implemented by the OnlinePlayer.
core::stringw m_last_online_name
The online user name used last (empty if not used online).
Definition: player_profile.hpp:101
bool m_remember_password
True if the login data are saved.
Definition: player_profile.hpp:107
This class contains the progression through challenges for the story mode.
Definition: story_mode_status.hpp:49
int getNumCompletedChallenges() const
Returns the number of completed challenges.
Definition: story_mode_status.hpp:114
void setCurrentChallenge(const std::string &challenge_id)
Set the current challenge (or NULL if no challenge is done).
Definition: story_mode_status.cpp:265
const std::vector< const ChallengeData * > getRecentlyCompletedChallenges()
Returns the list of recently unlocked features (e.g.
Definition: story_mode_status.hpp:108
void grandPrixFinished()
This is called when a GP is finished.
Definition: story_mode_status.cpp:305
int getNumBestTrophies() const
Returns the number of fulfilled challenges at best level.
Definition: story_mode_status.hpp:139
void setSpeedrunTimer(int milliseconds)
Sets the story mode timer.
Definition: story_mode_status.hpp:168
int getNumEasyTrophies() const
Returns the number of fulfilled challenges at easy level.
Definition: story_mode_status.hpp:130
void setSpeedrunFinished()
Sets if the player has finished a valid speedrun.
Definition: story_mode_status.hpp:154
int getNumHardTrophies() const
Returns the number of fulfilled challenges at hard level.
Definition: story_mode_status.hpp:136
bool isFirstTime() const
Returns if this is the first time the intro is shown.
Definition: story_mode_status.hpp:145
int getSpeedrunTimer()
Gets the speedrun timer This is designed to be used on loading and once story mode is completed ; it ...
Definition: story_mode_status.hpp:173
int getNextUnlockPoints() const
Returns the number of points needed by the next unlockable.
Definition: story_mode_status.hpp:127
void setFirstTime(bool ft)
Sets if this is the first time the intro is shown.
Definition: story_mode_status.hpp:142
const ChallengeStatus * getChallengeStatus(const std::string &id) const
Returns a challenge given the challenge id.
Definition: story_mode_status.hpp:179
int getStoryModeTimer()
Gets the story mode timer This is designed to be used on loading and once story mode is completed ; i...
Definition: story_mode_status.hpp:165
int getPoints() const
Returns the number of points accumulated.
Definition: story_mode_status.hpp:121
int getPointsBefore() const
Returns the number of points before the previous point increase.
Definition: story_mode_status.hpp:124
bool isFinished() const
Returns if the player has beaten Nolock.
Definition: story_mode_status.hpp:151
void clearUnlocked()
Clear the list of recently unlocked challenges.
Definition: story_mode_status.hpp:111
void setFinished()
Sets if the player has beaten Nolock.
Definition: story_mode_status.hpp:148
bool isSpeedrunFinished() const
Returns if the player has finished a valid speedrun
Definition: story_mode_status.hpp:157
void setStoryModeTimer(int milliseconds)
Sets the story mode timer.
Definition: story_mode_status.hpp:160
utility class used to write wide (UTF-16 or UTF-32, depending of size of wchar_t) XML files
Definition: utf_writer.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48
Declares the general types that are used by the network.