SuperTuxKart
Loading...
Searching...
No Matches
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.
 

Public Member Functions

 PlayerProfile (const core::stringw &name, bool is_guest=false)
 Constructor to create a new player that didn't exist before.
 
 PlayerProfile (const XMLNode *node)
 Constructor to deserialize player data that was saved to a XML file.
 
void save (UTFWriter &out)
 Writes the data for this player to the specified UTFWriter.
 
void loadRemainingData (const XMLNode *node)
 This function loads the achievement and story mode data.
 
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.
 
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.
 
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.
 
void clearSession (bool save=true)
 Unsets any saved session data.
 
void addIcon ()
 Creates an icon for a player if non exist so far.
 
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.
 
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.
 
void setName (const core::stringw &name)
 Sets the name of this player.
 
const core::stringw & getName () const
 Returns the name of this player.
 
bool isGuestAccount () const
 Returns true if this player is a guest account.
 
const core::stringw & getLastOnlineName () const
 Returns the last used online name.
 
void setLastOnlineName (const core::stringw &name)
 Sets the last used online name.
 
unsigned int getUniqueID () const
 Returns the unique id of this player.
 
bool isLocked (const std::string &feature) const
 Returnes if the feature (kart, track) is locked.
 
void computeActive ()
 Returns all active challenges.
 
std::vector< const ChallengeData * > getRecentlyCompletedChallenges ()
 Returns the list of recently completed challenges.
 
void setCurrentChallenge (const std::string &name)
 Sets the currently active challenge.
 
void grandPrixFinished ()
 Callback when a GP is finished (to test if a challenge was fulfilled).
 
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.
 
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.
 
StoryModeStatusgetStoryModeStatus ()
 
int getSavedUserId () const
 If a session was saved, return the id of the saved user.
 
const std::string & getSavedToken () const
 If a session was saved, return the token to use.
 
bool wasOnlineLastTime () const
 Returns if the last time this player was used it was used online or offline.
 
void setWasOnlineLastTime (bool b)
 Sets if this player was logged in last time it was used.
 
bool rememberPassword () const
 Returns if the last time this player was used it was used online or offline.
 
void setRememberPassword (bool b)
 Sets if this player was logged in last time it was used.
 
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).
 
bool m_is_guest_account
 True if this account is a guest account.
 
int m_use_frequency
 Counts how often this player was used (always -1 for guests).
 
unsigned int m_unique_id
 A unique number for this player, used to link it to challenges etc.
 
std::string m_icon_filename
 Absolute path of the icon file for this player.
 
bool m_saved_session
 True if this user has a saved session.
 
int m_saved_user_id
 If a session was saved, this will be the online user id to use.
 
std::string m_saved_token
 The token of the saved session.
 
core::stringw m_last_online_name
 The online user name used last (empty if not used online).
 
bool m_last_was_online
 True if the last time this player was used as online.
 
bool m_remember_password
 True if the login data are saved.
 
float m_default_kart_color
 Default kart color (in hue) used in game, 0.0f to use the original.
 
StoryModeStatusm_story_mode_status
 The complete challenge state.
 
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.

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.

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

◆ getOnlineId()

virtual uint32_t PlayerProfile::getOnlineId ( ) const
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ getOnlineState()

virtual PlayerProfile::OnlineState PlayerProfile::getOnlineState ( ) const
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ getProfile()

virtual Online::OnlineProfile * PlayerProfile::getProfile ( ) const
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ incrementUseFrequency()

void PlayerProfile::incrementUseFrequency ( )

Increments how often that account was used.

Guest accounts are not counted.

◆ isLoggedIn()

virtual bool PlayerProfile::isLoggedIn ( ) const
inlinevirtual

Reimplemented in Online::OnlinePlayerProfile.

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

◆ requestPoll()

virtual void PlayerProfile::requestPoll ( ) const
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ requestSavedSession()

virtual void PlayerProfile::requestSavedSession ( )
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ requestSignIn()

virtual void PlayerProfile::requestSignIn ( const irr::core::stringw &  username,
const irr::core::stringw &  password 
)
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ requestSignOut()

virtual void PlayerProfile::requestSignOut ( )
pure virtual

Implemented in Online::OnlinePlayerProfile.

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

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

◆ signIn()

virtual void PlayerProfile::signIn ( bool  success,
const XMLNode input 
)
pure virtual

Implemented in Online::OnlinePlayerProfile.

◆ signOut()

virtual void PlayerProfile::signOut ( bool  success,
const XMLNode input,
const irr::core::stringw &  info 
)
pure virtual

Implemented in Online::OnlinePlayerProfile.


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