SuperTuxKart
|
Class for managing player profiles (name, usage frequency, etc.). More...
#include <player_profile.hpp>
Public Types | |
enum | OnlineState { OS_SIGNED_OUT = 0, OS_SIGNED_IN, OS_GUEST, OS_SIGNING_IN, OS_SIGNING_OUT } |
The online state a player can be in. More... | |
Public Member Functions | |
PlayerProfile (const core::stringw &name, bool is_guest=false) | |
Constructor to create a new player that didn't exist before. More... | |
PlayerProfile (const XMLNode *node) | |
Constructor to deserialize player data that was saved to a XML file. More... | |
void | save (UTFWriter &out) |
Writes the data for this player to the specified UTFWriter. More... | |
void | loadRemainingData (const XMLNode *node) |
This function loads the achievement and story mode data. More... | |
void | initRemainingData () |
Initialises the story- and achievement data structure in case of the first start of STK. | |
void | incrementUseFrequency () |
Increments how often that account was used. More... | |
int | getUseFrequency () const |
bool | operator< (const PlayerProfile &other) |
Comparison used to sort players. | |
void | raceFinished () |
Notification of a finished race, which can trigger fulfilling challenges. More... | |
void | saveSession (int user_id, const std::string &token) |
Saves the online data, so that it will automatically re-connect next time this profile is loaded. More... | |
void | clearSession (bool save=true) |
Unsets any saved session data. More... | |
void | addIcon () |
Creates an icon for a player if non exist so far. More... | |
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. More... | |
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 void | 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 |
const std::string | getIconFilename () const |
Returns the name of the icon file for this player. More... | |
void | setName (const core::stringw &name) |
Sets the name of this player. More... | |
const core::stringw & | getName () const |
Returns the name of this player. More... | |
bool | isGuestAccount () const |
Returns true if this player is a guest account. More... | |
const core::stringw & | getLastOnlineName () const |
Returns the last used online name. More... | |
void | setLastOnlineName (const core::stringw &name) |
Sets the last used online name. More... | |
unsigned int | getUniqueID () const |
Returns the unique id of this player. More... | |
bool | isLocked (const std::string &feature) const |
Returnes if the feature (kart, track) is locked. More... | |
void | computeActive () |
Returns all active challenges. More... | |
std::vector< const ChallengeData * > | getRecentlyCompletedChallenges () |
Returns the list of recently completed challenges. More... | |
void | setCurrentChallenge (const std::string &name) |
Sets the currently active challenge. More... | |
void | grandPrixFinished () |
Callback when a GP is finished (to test if a challenge was fulfilled). More... | |
unsigned int | getNumCompletedChallenges () const |
unsigned int | getPoints () const |
unsigned int | getPointsBefore () const |
unsigned int | getNextUnlockPoints () const |
void | setFirstTime (bool b) |
bool | isFirstTime () const |
void | setFinished () |
bool | isFinished () const |
void | setSpeedrunFinished () |
bool | isSpeedrunFinished () |
void | setStoryModeTimer (int ms) |
int | getStoryModeTimer () |
void | setSpeedrunTimer (int ms) |
int | getSpeedrunTimer () |
void | clearUnlocked () |
const ChallengeStatus * | getCurrentChallengeStatus () const |
Returns the current challenge for this player. More... | |
const ChallengeStatus * | getChallengeStatus (const std::string &id) |
unsigned int | getNumEasyTrophies () const |
unsigned int | getNumMediumTrophies () const |
unsigned int | getNumHardTrophies () const |
unsigned int | getNumBestTrophies () const |
AchievementsStatus * | getAchievementsStatus () |
bool | hasSavedSession () const |
Returns true if a session was saved for this player. More... | |
StoryModeStatus * | getStoryModeStatus () |
int | getSavedUserId () const |
If a session was saved, return the id of the saved user. More... | |
const std::string & | getSavedToken () const |
If a session was saved, return the token to use. More... | |
bool | wasOnlineLastTime () const |
Returns if the last time this player was used it was used online or offline. More... | |
void | setWasOnlineLastTime (bool b) |
Sets if this player was logged in last time it was used. More... | |
bool | rememberPassword () const |
Returns if the last time this player was used it was used online or offline. More... | |
void | setRememberPassword (bool b) |
Sets if this player was logged in last time it was used. More... | |
void | setDefaultKartColor (float c) |
float | getDefaultKartColor () const |
Private Attributes | |
core::stringw | m_local_name |
The name of the player (wide string, so it can be in native language). More... | |
bool | m_is_guest_account |
True if this account is a guest account. More... | |
int | m_use_frequency |
Counts how often this player was used (always -1 for guests). More... | |
unsigned int | m_unique_id |
A unique number for this player, used to link it to challenges etc. More... | |
std::string | m_icon_filename |
Absolute path of the icon file for this player. More... | |
bool | m_saved_session |
True if this user has a saved session. More... | |
int | m_saved_user_id |
If a session was saved, this will be the online user id to use. More... | |
std::string | m_saved_token |
The token of the saved session. More... | |
core::stringw | m_last_online_name |
The online user name used last (empty if not used online). More... | |
bool | m_last_was_online |
True if the last time this player was used as online. More... | |
bool | m_remember_password |
True if the login data are saved. More... | |
float | m_default_kart_color |
Default kart color (in hue) used in game, 0.0f to use the original. More... | |
StoryModeStatus * | m_story_mode_status |
The complete challenge state. More... | |
AchievementsStatus * | m_achievements_status |
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.
The online state a player can be in.
PlayerProfile::PlayerProfile | ( | const core::stringw & | name, |
bool | is_guest = false |
||
) |
Constructor to create a new player that didn't exist before.
name | Name of the player. |
is_guest | True if this is a guest account. |
PlayerProfile::PlayerProfile | ( | const XMLNode * | node | ) |
Constructor to deserialize player data that was saved to a XML file.
The constructor will only load the main player data (like name, id, saved online data), but not the achievements and story mode data. Reason is that the achievement and story mode data depends on other data to be read first (challenges and achievement files), which in turn can only be created later in the startup process (they depend on e.g. all tracks to be known). On the other hand, automatic login needs to happen asap (i.e. as soon as the network thread is started) to avoid the player having to wait for the login to finish , which needs the main player data (i.e. the default player, and saved session data). So the constructor only reads this data, the rest of the player data is handled in loadRemainingData later in the initialisation process.
node | The XML node representing this player. |
void PlayerProfile::addIcon | ( | ) |
Creates an icon for a player if non exist so far.
It takes the unique player id modulo the number of karts to pick an icon from the karts. It then uses the unique number plus the extentsion of the original icon as the file name (it's not possible to use the player name, since the name is in utf-16, but typically the file systems are not, resulting in incorrect file names). The icon is then copied to the user config directory, so that it can be replaced by an icon made by the user. If there should be an error copying the file, the icon filename is set to "". Every time stk is started, it will try to fix missing icons (which allows it to start from old/incompatible config files).
void PlayerProfile::clearSession | ( | bool | save = true | ) |
Unsets any saved session data.
|
inline |
Returns all active challenges.
|
inline |
Returns the current challenge for this player.
const std::string PlayerProfile::getIconFilename | ( | ) | const |
Returns the name of the icon file for this player.
If the player icon file is undefined, it returns a "?" mark texture. Note, getAsset does not return a reference, but only a temporary string. So we must return a copy of the string (not a reference to).
|
inline |
Returns the last used online name.
|
inline |
Returns the name of this player.
|
inline |
Returns the list of recently completed challenges.
|
inline |
If a session was saved, return the token to use.
|
inline |
If a session was saved, return the id of the saved user.
|
inline |
Returns the unique id of this player.
|
inline |
Callback when a GP is finished (to test if a challenge was fulfilled).
|
inline |
Returns true if a session was saved for this player.
void PlayerProfile::incrementUseFrequency | ( | ) |
Increments how often that account was used.
Guest accounts are not counted.
|
inline |
Returns true if this player is a guest account.
|
inline |
Returnes if the feature (kart, track) is locked.
void PlayerProfile::loadRemainingData | ( | const XMLNode * | node | ) |
This function loads the achievement and story mode data.
These can only be loaded after the UnlockManager is created, which needs the karts and tracks to be loaded first.
void PlayerProfile::raceFinished | ( | ) |
Notification of a finished race, which can trigger fulfilling challenges.
|
inline |
Returns if the last time this player was used it was used online or offline.
void PlayerProfile::save | ( | UTFWriter & | out | ) |
Writes the data for this player to the specified UTFWriter.
out | The utf writer to write the data to. |
void PlayerProfile::saveSession | ( | int | user_id, |
const std::string & | token | ||
) |
Saves the online data, so that it will automatically re-connect next time this profile is loaded.
user_id | Id of the online profile. |
token | Token used for authentication. |
|
inline |
Sets the currently active challenge.
|
inline |
Sets the last used online name.
|
inline |
Sets the name of this player.
|
inline |
Sets if this player was logged in last time it was used.
|
pure virtual |
Abstract virtual classes, to be implemented by the OnlinePlayer.
Implemented in Online::OnlinePlayerProfile.
|
inline |
Sets if this player was logged in last time it was used.
|
inline |
Returns if the last time this player was used it was used online or offline.
|
private |
Default kart color (in hue) used in game, 0.0f to use the original.
|
private |
Absolute path of the icon file for this player.
|
private |
True if this account is a guest account.
|
private |
The online user name used last (empty if not used online).
|
private |
True if the last time this player was used as online.
|
private |
The name of the player (wide string, so it can be in native language).
|
private |
True if the login data are saved.
|
private |
True if this user has a saved session.
|
private |
The token of the saved session.
|
private |
If a session was saved, this will be the online user id to use.
|
private |
The complete challenge state.
|
private |
A unique number for this player, used to link it to challenges etc.
|
private |
Counts how often this player was used (always -1 for guests).