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"
24 #include "utils/leak_check.hpp"
25 #include "utils/no_copy.hpp"
26 #include "utils/types.hpp"
27 
28 #include <irrString.h>
29 using namespace irr;
30 
31 #include <string>
32 
33 class AchievementsStatus;
34 namespace Online
35 {
36  class CurrentUser;
37  class HTTPRequest;
38  class OnlineProfile;
39  class XMLRequest;
40 }
41 class UTFWriter;
42 
53 class PlayerProfile : public NoCopy
54 {
55 public:
58  {
59  OS_SIGNED_OUT = 0,
60  OS_SIGNED_IN,
61  OS_GUEST,
62  OS_SIGNING_IN,
63  OS_SIGNING_OUT
64  };
65 
66 
67 private:
68  LEAK_CHECK()
69 
70 #ifdef DEBUG
71  unsigned int m_magic_number;
72 #endif
73 
76  core::stringw m_local_name;
77 
80 
83 
85  unsigned int m_unique_id;
86 
88  std::string m_icon_filename;
89 
92 
95 
97  std::string m_saved_token;
98 
100  core::stringw m_last_online_name;
101 
104 
107 
110 
113 
114  AchievementsStatus *m_achievements_status;
115 
116 public:
117 
118  PlayerProfile(const core::stringw &name, bool is_guest = false);
119  PlayerProfile(const XMLNode *node);
120  virtual ~PlayerProfile();
121  void save(UTFWriter &out);
122  void loadRemainingData(const XMLNode *node);
123  void initRemainingData();
124  void incrementUseFrequency();
125  int getUseFrequency() const { return m_use_frequency; }
126  bool operator<(const PlayerProfile &other);
127  void raceFinished();
128  void saveSession(int user_id, const std::string &token);
129  void clearSession(bool save=true);
130  void addIcon();
131 
133  virtual void setUserDetails(std::shared_ptr<Online::HTTPRequest> request,
134  const std::string &action,
135  const std::string &url_path = "") const = 0;
136  virtual uint32_t getOnlineId() const = 0;
137  virtual PlayerProfile::OnlineState getOnlineState() const = 0;
138  virtual Online::OnlineProfile* getProfile() const = 0;
139  virtual void requestPoll() const = 0;
140  virtual void requestSavedSession() = 0;
141  virtual void requestSignIn(const irr::core::stringw &username,
142  const irr::core::stringw &password) = 0;
143  virtual void signIn(bool success, const XMLNode * input) = 0;
144  virtual void signOut(bool success, const XMLNode * input,
145  const irr::core::stringw &info) = 0;
146  virtual void requestSignOut() = 0;
147  virtual bool isLoggedIn() const { return false; }
148  const std::string getIconFilename() const;
149  // ----------------------------------------------------------------------------------------
151  void setName(const core::stringw& name)
152  {
153  #ifdef DEBUG
154  assert(m_magic_number == 0xABCD1234);
155  #endif
156  m_local_name = name;
157  } // setName
158 
159  // ----------------------------------------------------------------------------------------
161  const core::stringw& getName() const
162  {
163  assert(m_magic_number == 0xABCD1234);
164  return m_local_name;
165  } // getName
166 
167  // ----------------------------------------------------------------------------------------
169  bool isGuestAccount() const
170  {
171  #ifdef DEBUG
172  assert(m_magic_number == 0xABCD1234);
173  #endif
174  return m_is_guest_account;
175  } // isGuestAccount
176  // ----------------------------------------------------------------------------------------
178  const core::stringw& getLastOnlineName() const
179  {
180  return m_last_online_name;
181  } // getLastOnlineName
182  // ----------------------------------------------------------------------------------------
184  void setLastOnlineName(const core::stringw &name)
185  {
186  m_last_online_name = name;
187  } // setLastOnlineName
188  // ----------------------------------------------------------------------------------------
190  unsigned int getUniqueID() const { return m_unique_id; }
191  // ----------------------------------------------------------------------------------------
193  bool isLocked(const std::string &feature) const
194  {
195  return m_story_mode_status->isLocked(feature);
196  } // isLocked
197  // ----------------------------------------------------------------------------------------
199  void computeActive() { m_story_mode_status->computeActive(); }
200  // ----------------------------------------------------------------------------------------
202  std::vector<const ChallengeData*> getRecentlyCompletedChallenges()
203  {
204  return m_story_mode_status->getRecentlyCompletedChallenges();
205  } // getRecently Completed Challenges
206  // ----------------------------------------------------------------------------------------
208  void setCurrentChallenge(const std::string &name)
209  {
210  m_story_mode_status->setCurrentChallenge(name);
211  } // setCurrentChallenge
212  // ----------------------------------------------------------------------------------------
215  void grandPrixFinished() { m_story_mode_status->grandPrixFinished(); }
216  // ----------------------------------------------------------------------------------------
217  unsigned int getNumCompletedChallenges() const { return m_story_mode_status->getNumCompletedChallenges(); }
218  // ----------------------------------------------------------------------------------------
219  unsigned int getPoints() const { return m_story_mode_status->getPoints(); }
220  // ----------------------------------------------------------------------------------------
221  unsigned int getPointsBefore() const { return m_story_mode_status->getPointsBefore(); }
222  // ----------------------------------------------------------------------------------------
223  unsigned int getNextUnlockPoints() const { return m_story_mode_status->getNextUnlockPoints(); }
224  // ----------------------------------------------------------------------------------------
225  void setFirstTime(bool b) { m_story_mode_status->setFirstTime(b); }
226  // ----------------------------------------------------------------------------------------
227  bool isFirstTime() const { return m_story_mode_status->isFirstTime(); }
228  // ----------------------------------------------------------------------------------------
229  void setFinished() { m_story_mode_status->setFinished(); }
230  // ----------------------------------------------------------------------------------------
231  bool isFinished() const { return m_story_mode_status->isFinished(); }
232  // ----------------------------------------------------------------------------------------
233  void setSpeedrunFinished() { m_story_mode_status->setSpeedrunFinished(); }
234  // ----------------------------------------------------------------------------------------
235  bool isSpeedrunFinished() { return m_story_mode_status->isSpeedrunFinished(); }
236  // ----------------------------------------------------------------------------------------
237  void setStoryModeTimer(int ms) { m_story_mode_status->setStoryModeTimer(ms); }
238  // ----------------------------------------------------------------------------------------
239  int getStoryModeTimer() { return m_story_mode_status->getStoryModeTimer(); }
240  // ----------------------------------------------------------------------------------------
241  void setSpeedrunTimer(int ms) { m_story_mode_status->setSpeedrunTimer(ms); }
242  // ----------------------------------------------------------------------------------------
243  int getSpeedrunTimer() { return m_story_mode_status->getSpeedrunTimer(); }
244  // ----------------------------------------------------------------------------------------
245  void clearUnlocked()
246  {
247  m_story_mode_status->clearUnlocked();
248  }
249  // ----------------------------------------------------------------------------------------
252  {
253  return m_story_mode_status->getCurrentChallengeStatus();
254  } // getCurrentChallengeStatus
255  // ----------------------------------------------------------------------------------------
256  const ChallengeStatus* getChallengeStatus(const std::string &id)
257  {
258  return m_story_mode_status->getChallengeStatus(id);
259  } // getChallengeStatus
260  // ----------------------------------------------------------------------------------------
261  unsigned int getNumEasyTrophies() const
262  {
263  return m_story_mode_status->getNumEasyTrophies();
264  } // getNumEasyTrophies
265  // ----------------------------------------------------------------------------------------
266  unsigned int getNumMediumTrophies() const
267  {
268  return m_story_mode_status->getNumMediumTrophies();
269  } // getNumEasyTrophies
270  // -----------------------------------------------------------------------
271  unsigned int getNumHardTrophies() const
272  {
273  return m_story_mode_status->getNumHardTrophies();
274  } // getNumHardTrophies
275  unsigned int getNumBestTrophies() const
276  {
277  return m_story_mode_status->getNumBestTrophies();
278  } // getNumBestTrophies
279  // ----------------------------------------------------------------------------------------
280  AchievementsStatus* getAchievementsStatus()
281  {
282  return m_achievements_status;
283  } // getAchievementsStatus
284  // ----------------------------------------------------------------------------------------
286  bool hasSavedSession() const { return m_saved_session; }
287  // ----------------------------------------------------------------------------------------
288  StoryModeStatus* getStoryModeStatus() { return m_story_mode_status; }
289  // ----------------------------------------------------------------------------------------
291  int getSavedUserId() const
292  {
293  assert(m_saved_session);
294  return m_saved_user_id;
295  } // getSavedUserId
296  // ----------------------------------------------------------------------------------------
298  const std::string& getSavedToken() const
299  {
300  assert(m_saved_session);
301  return m_saved_token;
302  } // getSavedToken
303  // ----------------------------------------------------------------------------------------
306  bool wasOnlineLastTime() const { return m_last_was_online; }
307  // ----------------------------------------------------------------------------------------
309  void setWasOnlineLastTime(bool b) { m_last_was_online = b; }
310  // ----------------------------------------------------------------------------------------
313  bool rememberPassword() const { return m_remember_password; }
314  // ----------------------------------------------------------------------------------------
316  void setRememberPassword(bool b) { m_remember_password = b; }
317  // ----------------------------------------------------------------------------------------
318  void setDefaultKartColor(float c) { m_default_kart_color = c; }
319  // ----------------------------------------------------------------------------------------
320  float getDefaultKartColor() const { return m_default_kart_color; }
321 
322 }; // class PlayerProfile
323 
324 #endif
325 
326 /*EOF*/
const ChallengeStatus * getChallengeStatus(const std::string &id) const
Returns a challenge given the challenge id.
Definition: story_mode_status.hpp:179
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
unsigned int getUniqueID() const
Returns the unique id of this player.
Definition: player_profile.hpp:190
std::vector< const ChallengeData * > getRecentlyCompletedChallenges()
Returns the list of recently completed challenges.
Definition: player_profile.hpp:202
const std::string & getSavedToken() const
If a session was saved, return the token to use.
Definition: player_profile.hpp:298
void setWasOnlineLastTime(bool b)
Sets if this player was logged in last time it was used.
Definition: player_profile.hpp:309
utility class used to write wide (UTF-16 or UTF-32, depending of size of wchar_t) XML files ...
Definition: utf_writer.hpp:34
OnlineState
The online state a player can be in.
Definition: player_profile.hpp:57
void computeActive()
Returns all active challenges.
Definition: player_profile.hpp:199
bool hasSavedSession() const
Returns true if a session was saved for this player.
Definition: player_profile.hpp:286
void setCurrentChallenge(const std::string &name)
Sets the currently active challenge.
Definition: player_profile.hpp:208
bool m_saved_session
True if this user has a saved session.
Definition: player_profile.hpp:91
void setName(const core::stringw &name)
Sets the name of this player.
Definition: player_profile.hpp:151
bool isFirstTime() const
Returns if this is the first time the intro is shown.
Definition: story_mode_status.hpp:145
int getNumCompletedChallenges() const
Returns the number of completed challenges.
Definition: story_mode_status.hpp:114
bool m_is_guest_account
True if this account is a guest account.
Definition: player_profile.hpp:79
const ChallengeStatus * getCurrentChallengeStatus() const
Returns the current challenge for this player.
Definition: player_profile.hpp:251
bool isGuestAccount() const
Returns true if this player is a guest account.
Definition: player_profile.hpp:169
void setFirstTime(bool ft)
Sets if this is the first time the intro is shown.
Definition: story_mode_status.hpp:142
void grandPrixFinished()
This is called when a GP is finished.
Definition: story_mode_status.cpp:305
int m_use_frequency
Counts how often this player was used (always -1 for guests).
Definition: player_profile.hpp:82
bool rememberPassword() const
Returns if the last time this player was used it was used online or offline.
Definition: player_profile.hpp:313
bool isLocked(const std::string &feature) const
Returnes if the feature (kart, track) is locked.
Definition: player_profile.hpp:193
void setRememberPassword(bool b)
Sets if this player was logged in last time it was used.
Definition: player_profile.hpp:316
Definition: three_d_animation.hpp:32
const core::stringw & getName() const
Returns the name of this player.
Definition: player_profile.hpp:161
core::stringw m_local_name
The name of the player (wide string, so it can be in native language).
Definition: player_profile.hpp:76
int getNumHardTrophies() const
Returns the number of fulfilled challenges at hard level.
Definition: story_mode_status.hpp:136
float m_default_kart_color
Default kart color (in hue) used in game, 0.0f to use the original.
Definition: player_profile.hpp:109
Declares the general types that are used by the network.
bool m_remember_password
True if the login data are saved.
Definition: player_profile.hpp:106
int m_saved_user_id
If a session was saved, this will be the online user id to use.
Definition: player_profile.hpp:94
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
bool m_last_was_online
True if the last time this player was used as online.
Definition: player_profile.hpp:103
void setCurrentChallenge(const std::string &challenge_id)
Set the current challenge (or NULL if no challenge is done).
Definition: story_mode_status.cpp:265
int getSavedUserId() const
If a session was saved, return the id of the saved user.
Definition: player_profile.hpp:291
This class keeps tracks of all achievements of one player.
Definition: achievements_status.hpp:42
void setSpeedrunFinished()
Sets if the player has finished a valid speedrun.
Definition: story_mode_status.hpp:154
void clearUnlocked()
Clear the list of recently unlocked challenges.
Definition: story_mode_status.hpp:111
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:53
The state of a challenge for one player.
Definition: challenge_status.hpp:52
void setStoryModeTimer(int milliseconds)
Sets the story mode timer.
Definition: story_mode_status.hpp:160
const core::stringw & getLastOnlineName() const
Returns the last used online name.
Definition: player_profile.hpp:178
void setFinished()
Sets if the player has beaten Nolock.
Definition: story_mode_status.hpp:148
std::string m_saved_token
The token of the saved session.
Definition: player_profile.hpp:97
unsigned int m_unique_id
A unique number for this player, used to link it to challenges etc.
Definition: player_profile.hpp:85
bool wasOnlineLastTime() const
Returns if the last time this player was used it was used online or offline.
Definition: player_profile.hpp:306
int getPointsBefore() const
Returns the number of points before the previous point increase.
Definition: story_mode_status.hpp:124
This class contains the progression through challenges for the story mode.
Definition: story_mode_status.hpp:48
bool isFinished() const
Returns if the player has beaten Nolock.
Definition: story_mode_status.hpp:151
utility class used to parse XML files
Definition: xml_node.hpp:47
std::string m_icon_filename
Absolute path of the icon file for this player.
Definition: player_profile.hpp:88
Definition: player_manager.hpp:35
Class that represents an online profile.
Definition: online_profile.hpp:41
const std::vector< const ChallengeData * > getRecentlyCompletedChallenges()
Returns the list of recently unlocked features (e.g.
Definition: story_mode_status.hpp:108
core::stringw m_last_online_name
The online user name used last (empty if not used online).
Definition: player_profile.hpp:100
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
bool isSpeedrunFinished() const
Returns if the player has finished a valid speedrun.
Definition: story_mode_status.hpp:157
int getNumBestTrophies() const
Returns the number of fulfilled challenges at best level.
Definition: story_mode_status.hpp:139
void setLastOnlineName(const core::stringw &name)
Sets the last used online name.
Definition: player_profile.hpp:184
void grandPrixFinished()
Callback when a GP is finished (to test if a challenge was fulfilled).
Definition: player_profile.hpp:215
StoryModeStatus * m_story_mode_status
The complete challenge state.
Definition: player_profile.hpp:112
int getPoints() const
Returns the number of points accumulated.
Definition: story_mode_status.hpp:121
int getNextUnlockPoints() const
Returns the number of points needed by the next unlockable.
Definition: story_mode_status.hpp:127