SuperTuxKart
Public Types | Public Member Functions | Private Attributes | List of all members
PlayerProfile Class Referenceabstract

Class for managing player profiles (name, usage frequency, etc.). More...

#include <player_profile.hpp>

Inheritance diagram for PlayerProfile:
Inheritance graph
[legend]

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...
 
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::OnlineProfilegetProfile () 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 ChallengeStatusgetCurrentChallengeStatus () const
 Returns the current challenge for this player. More...
 
const ChallengeStatusgetChallengeStatus (const std::string &id)
 
unsigned int getNumEasyTrophies () const
 
unsigned int getNumMediumTrophies () const
 
unsigned int getNumHardTrophies () const
 
unsigned int getNumBestTrophies () const
 
AchievementsStatusgetAchievementsStatus ()
 
bool hasSavedSession () const
 Returns true if a session was saved for this player. More...
 
StoryModeStatusgetStoryModeStatus ()
 
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...
 
StoryModeStatusm_story_mode_status
 The complete challenge state. More...
 
AchievementsStatusm_achievements_status
 

Detailed Description

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.

Member Enumeration Documentation

◆ OnlineState

The online state a player can be in.

Constructor & Destructor Documentation

◆ PlayerProfile() [1/2]

PlayerProfile::PlayerProfile ( const core::stringw &  name,
bool  is_guest = false 
)

Constructor to create a new player that didn't exist before.

Parameters
nameName of the player.
is_guestTrue if this is a guest account.

◆ PlayerProfile() [2/2]

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.

Parameters
nodeThe XML node representing this player.

Member Function Documentation

◆ addIcon()

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).

Precondition
This function must only be called after all karts are read in.

◆ clearSession()

void PlayerProfile::clearSession ( bool  save = true)

Unsets any saved session data.

◆ computeActive()

void PlayerProfile::computeActive ( )
inline

Returns all active challenges.

◆ getCurrentChallengeStatus()

const ChallengeStatus* PlayerProfile::getCurrentChallengeStatus ( ) const
inline

Returns the current challenge for this player.

◆ getIconFilename()

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).

◆ getLastOnlineName()

const core::stringw& PlayerProfile::getLastOnlineName ( ) const
inline

Returns the last used online name.

◆ getName()

const core::stringw& PlayerProfile::getName ( ) const
inline

Returns the name of this player.

◆ getRecentlyCompletedChallenges()

std::vector<const ChallengeData*> PlayerProfile::getRecentlyCompletedChallenges ( )
inline

Returns the list of recently completed challenges.

◆ getSavedToken()

const std::string& PlayerProfile::getSavedToken ( ) const
inline

If a session was saved, return the token to use.

◆ getSavedUserId()

int PlayerProfile::getSavedUserId ( ) const
inline

If a session was saved, return the id of the saved user.

◆ getUniqueID()

unsigned int PlayerProfile::getUniqueID ( ) const
inline

Returns the unique id of this player.

◆ grandPrixFinished()

void PlayerProfile::grandPrixFinished ( )
inline

Callback when a GP is finished (to test if a challenge was fulfilled).

◆ hasSavedSession()

bool PlayerProfile::hasSavedSession ( ) const
inline

Returns true if a session was saved for this player.

◆ incrementUseFrequency()

void PlayerProfile::incrementUseFrequency ( )

Increments how often that account was used.

Guest accounts are not counted.

◆ isGuestAccount()

bool PlayerProfile::isGuestAccount ( ) const
inline

Returns true if this player is a guest account.

◆ isLocked()

bool PlayerProfile::isLocked ( const std::string &  feature) const
inline

Returnes if the feature (kart, track) is locked.

◆ loadRemainingData()

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.

◆ raceFinished()

void PlayerProfile::raceFinished ( )

Notification of a finished race, which can trigger fulfilling challenges.

◆ rememberPassword()

bool PlayerProfile::rememberPassword ( ) const
inline

Returns if the last time this player was used it was used online or offline.

◆ save()

void PlayerProfile::save ( UTFWriter out)

Writes the data for this player to the specified UTFWriter.

Parameters
outThe utf writer to write the data to.

◆ saveSession()

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.

Parameters
user_idId of the online profile.
tokenToken used for authentication.

◆ setCurrentChallenge()

void PlayerProfile::setCurrentChallenge ( const std::string &  name)
inline

Sets the currently active challenge.

◆ setLastOnlineName()

void PlayerProfile::setLastOnlineName ( const core::stringw &  name)
inline

Sets the last used online name.

◆ setName()

void PlayerProfile::setName ( const core::stringw &  name)
inline

Sets the name of this player.

◆ setRememberPassword()

void PlayerProfile::setRememberPassword ( bool  b)
inline

Sets if this player was logged in last time it was used.

◆ setUserDetails()

virtual void PlayerProfile::setUserDetails ( std::shared_ptr< Online::HTTPRequest request,
const std::string &  action,
const std::string &  url_path = "" 
) const
pure virtual

Abstract virtual classes, to be implemented by the OnlinePlayer.

Implemented in Online::OnlinePlayerProfile.

◆ setWasOnlineLastTime()

void PlayerProfile::setWasOnlineLastTime ( bool  b)
inline

Sets if this player was logged in last time it was used.

◆ wasOnlineLastTime()

bool PlayerProfile::wasOnlineLastTime ( ) const
inline

Returns if the last time this player was used it was used online or offline.

Member Data Documentation

◆ m_default_kart_color

float PlayerProfile::m_default_kart_color
private

Default kart color (in hue) used in game, 0.0f to use the original.

◆ m_icon_filename

std::string PlayerProfile::m_icon_filename
private

Absolute path of the icon file for this player.

◆ m_is_guest_account

bool PlayerProfile::m_is_guest_account
private

True if this account is a guest account.

◆ m_last_online_name

core::stringw PlayerProfile::m_last_online_name
private

The online user name used last (empty if not used online).

◆ m_last_was_online

bool PlayerProfile::m_last_was_online
private

True if the last time this player was used as online.

◆ m_local_name

core::stringw PlayerProfile::m_local_name
private

The name of the player (wide string, so it can be in native language).

◆ m_remember_password

bool PlayerProfile::m_remember_password
private

True if the login data are saved.

◆ m_saved_session

bool PlayerProfile::m_saved_session
private

True if this user has a saved session.

◆ m_saved_token

std::string PlayerProfile::m_saved_token
private

The token of the saved session.

◆ m_saved_user_id

int PlayerProfile::m_saved_user_id
private

If a session was saved, this will be the online user id to use.

◆ m_story_mode_status

StoryModeStatus* PlayerProfile::m_story_mode_status
private

The complete challenge state.

◆ m_unique_id

unsigned int PlayerProfile::m_unique_id
private

A unique number for this player, used to link it to challenges etc.

◆ m_use_frequency

int PlayerProfile::m_use_frequency
private

Counts how often this player was used (always -1 for guests).


The documentation for this class was generated from the following files: