-
Notifications
You must be signed in to change notification settings - Fork 1k
/
player_profile.hpp
286 lines (257 loc) · 11.2 KB
/
player_profile.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2013 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PLAYER_PROFILE_HPP
#define HEADER_PLAYER_PROFILE_HPP
#include "challenges/story_mode_status.hpp"
#include "utils/leak_check.hpp"
#include "utils/no_copy.hpp"
#include "utils/types.hpp"
#include <irrString.h>
using namespace irr;
#include <string>
class AchievementsStatus;
namespace Online
{
class CurrentUser;
class HTTPRequest;
class OnlineProfile;
class XMLRequest;
}
class UTFWriter;
/** Class for managing player profiles (name, usage frequency,
* etc.). All PlayerProfiles are managed by the PlayerManager.
* A PlayerProfile keeps track of the story mode progress using an instance
* of StoryModeStatus, and achievements with AchievementsStatus. All data
* is saved in the players.xml file.
* This class also defines the interface for handling online data. All of
* the online handling is done in the derived class OnlinePlayerProfile,
* where the interface is fully implemented.
* \ingroup config
*/
class PlayerProfile : public NoCopy
{
public:
/** The online state a player can be in. */
enum OnlineState
{
OS_SIGNED_OUT = 0,
OS_SIGNED_IN,
OS_GUEST,
OS_SIGNING_IN,
OS_SIGNING_OUT
};
private:
LEAK_CHECK()
/** The name of the player (wide string, so it can be in native
* language). */
core::stringw m_local_name;
/** True if this account is a guest account. */
bool m_is_guest_account;
#ifdef DEBUG
unsigned int m_magic_number;
#endif
/** Counts how often this player was used (always -1 for guests). */
int m_use_frequency;
/** A unique number for this player, used to link it to challenges etc. */
unsigned int m_unique_id;
/** Absolute path of the icon file for this player. */
std::string m_icon_filename;
/** True if this user has a saved session. */
bool m_saved_session;
/** If a session was saved, this will be the online user id to use. */
int m_saved_user_id;
/** The token of the saved session. */
std::string m_saved_token;
/** The online user name used last (empty if not used online). */
core::stringw m_last_online_name;
/** True if the last time this player was used as online. */
bool m_last_was_online;
/** True if the login data are saved. */
bool m_remember_password;
/** The complete challenge state. */
StoryModeStatus *m_story_mode_status;
AchievementsStatus *m_achievements_status;
public:
PlayerProfile(const core::stringw &name, bool is_guest = false);
PlayerProfile(const XMLNode *node);
virtual ~PlayerProfile();
void save(UTFWriter &out);
void loadRemainingData(const XMLNode *node);
void initRemainingData();
void incrementUseFrequency();
bool operator<(const PlayerProfile &other);
void raceFinished();
void saveSession(int user_id, const std::string &token);
void clearSession();
void addIcon();
/** Abstract virtual classes, to be implemented by the OnlinePlayer. */
virtual void setUserDetails(Online::HTTPRequest *request,
const std::string &action,
const std::string &php_script = "") const = 0;
virtual uint32_t getOnlineId() const = 0;
virtual PlayerProfile::OnlineState getOnlineState() const = 0;
virtual Online::OnlineProfile* getProfile() const = 0;
virtual void requestPoll() const = 0;
virtual void requestSavedSession() = 0;
virtual Online::XMLRequest* requestSignIn(const irr::core::stringw &username,
const irr::core::stringw &password) = 0;
virtual void signIn(bool success, const XMLNode * input) = 0;
virtual void signOut(bool success, const XMLNode * input,
const irr::core::stringw &info) = 0;
virtual void requestSignOut() = 0;
virtual bool isLoggedIn() const { return false; }
const std::string getIconFilename() const;
// ------------------------------------------------------------------------
/** Sets the name of this player. */
void setName(const core::stringw& name)
{
#ifdef DEBUG
assert(m_magic_number == 0xABCD1234);
#endif
m_local_name = name;
} // setName
// ------------------------------------------------------------------------
/** Returns the name of this player. */
core::stringw getName() const
{
assert(m_magic_number == 0xABCD1234);
return m_local_name.c_str();
} // getName
// ------------------------------------------------------------------------
/** Returns true if this player is a guest account. */
bool isGuestAccount() const
{
#ifdef DEBUG
assert(m_magic_number == 0xABCD1234);
#endif
return m_is_guest_account;
} // isGuestAccount
// ------------------------------------------------------------------------
/** Returns the last used online name. */
const core::stringw& getLastOnlineName() const
{
return m_last_online_name;
} // getLastOnlineName
// ------------------------------------------------------------------------
/** Sets the last used online name. */
void setLastOnlineName(const core::stringw &name)
{
m_last_online_name = name;
} // setLastOnlineName
// ------------------------------------------------------------------------
/** Returns the unique id of this player. */
unsigned int getUniqueID() const { return m_unique_id; }
// ------------------------------------------------------------------------
/** Returnes if the feature (kart, track) is locked. */
bool isLocked(const std::string &feature) const
{
return m_story_mode_status->isLocked(feature);
} // isLocked
// ------------------------------------------------------------------------
/** Returns all active challenges. */
void computeActive() { m_story_mode_status->computeActive(); }
// ------------------------------------------------------------------------
/** Returns the list of recently completed challenges. */
std::vector<const ChallengeData*> getRecentlyCompletedChallenges()
{
return m_story_mode_status->getRecentlyCompletedChallenges();
} // getRecently Completed Challenges
// ------------------------------------------------------------------------
/** Sets the currently active challenge. */
void setCurrentChallenge(const std::string &name)
{
m_story_mode_status->setCurrentChallenge(name);
} // setCurrentChallenge
// ------------------------------------------------------------------------
/** Callback when a GP is finished (to test if a challenge was
* fulfilled). */
void grandPrixFinished() { m_story_mode_status->grandPrixFinished(); }
// ------------------------------------------------------------------------
unsigned int getPoints() const { return m_story_mode_status->getPoints(); }
// ------------------------------------------------------------------------
void setFirstTime(bool b) { m_story_mode_status->setFirstTime(b); }
// ------------------------------------------------------------------------
bool isFirstTime() const { return m_story_mode_status->isFirstTime(); }
// ------------------------------------------------------------------------
void clearUnlocked() { m_story_mode_status->clearUnlocked(); }
// ------------------------------------------------------------------------
/** Returns the current challenge for this player. */
const ChallengeStatus* getCurrentChallengeStatus() const
{
return m_story_mode_status->getCurrentChallengeStatus();
} // getCurrentChallengeStatus
// ------------------------------------------------------------------------
const ChallengeStatus* getChallengeStatus(const std::string &id)
{
return m_story_mode_status->getChallengeStatus(id);
} // getChallengeStatus
// ------------------------------------------------------------------------
unsigned int getNumEasyTrophies() const
{
return m_story_mode_status->getNumEasyTrophies();
} // getNumEasyTrophies
// ------------------------------------------------------------------------
unsigned int getNumMediumTrophies() const
{
return m_story_mode_status->getNumMediumTrophies();
} // getNumEasyTrophies
// -----------------------------------------------------------------------
unsigned int getNumHardTrophies() const
{
return m_story_mode_status->getNumHardTrophies();
} // getNumHardTropies
// ------------------------------------------------------------------------
AchievementsStatus* getAchievementsStatus()
{
return m_achievements_status;
} // getAchievementsStatus
// ------------------------------------------------------------------------
/** Returns true if a session was saved for this player. */
bool hasSavedSession() const { return m_saved_session; }
// ------------------------------------------------------------------------
/** If a session was saved, return the id of the saved user. */
int getSavedUserId() const
{
assert(m_saved_session);
return m_saved_user_id;
} // getSavedUserId
// ------------------------------------------------------------------------
/** If a session was saved, return the token to use. */
const std::string& getSavedToken() const
{
assert(m_saved_session);
return m_saved_token;
} // getSavedToken
// ------------------------------------------------------------------------
/** Returns if the last time this player was used it was used online or
* offline. */
bool wasOnlineLastTime() const { return m_last_was_online; }
// ------------------------------------------------------------------------
/** Sets if this player was logged in last time it was used. */
void setWasOnlineLastTime(bool b) { m_last_was_online = b; }
// ------------------------------------------------------------------------
/** Returns if the last time this player was used it was used online or
* offline. */
bool rememberPassword() const { return m_remember_password; }
// ------------------------------------------------------------------------
/** Sets if this player was logged in last time it was used. */
void setRememberPassword(bool b) { m_remember_password = b; }
// ------------------------------------------------------------------------
}; // class PlayerProfile
#endif
/*EOF*/