SuperTuxKart
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PlayerManager Class Reference

A special class that manages all local player accounts. More...

#include <player_manager.hpp>

Inheritance diagram for PlayerManager:
Inheritance graph
[legend]

Public Member Functions

void save ()
 Saves all player profiles to players.xml.
 
void initRemainingData ()
 The 2nd loading stage. More...
 
unsigned int getUniqueId () const
 This returns a unique id. More...
 
void addDefaultPlayer ()
 Called when no player profiles exists. More...
 
PlayerProfileaddNewPlayer (const irr::core::stringw &name)
 Adds a new player to the list of all players. More...
 
void createGuestPlayers (int n)
 Makes sure at least n guest players exist. More...
 
void deletePlayer (PlayerProfile *player)
 Deletes a player profile from the list of all profiles.
 
void setCurrentPlayer (PlayerProfile *player)
 Sets the current player. More...
 
const PlayerProfilegetPlayerById (unsigned int id)
 Returns a PlayerProfile with a given id. More...
 
void enforceCurrentPlayer ()
 This function makes sure that a current player is defined. More...
 
unsigned int getNumNonGuestPlayers () const
 Returns the number of 'real' (non-guest) players.
 
PlayerProfilegetPlayer (const irr::core::stringw &name)
 Returns a player with a given name. More...
 
unsigned int getNumPlayers () const
 Returns the number of players in the config file. More...
 
const PlayerProfilegetPlayer (unsigned int n) const
 Returns a player with a given unique id. More...
 
PlayerProfilegetPlayer (unsigned int n)
 Returns a player with a given unique id. More...
 

Static Public Member Functions

static void create ()
 Create the instance of the player manager. More...
 
static PlayerManagerget ()
 Static singleton get function. More...
 
static void destroy ()
 
static void setUserDetails (std::shared_ptr< Online::HTTPRequest > request, const std::string &action, const std::string &php_name="")
 Adds the login credential to a http request. More...
 
static unsigned int getCurrentOnlineId ()
 Returns the online id of the current player. More...
 
static bool isCurrentLoggedIn ()
 Returns whether a user is signed in or not. More...
 
static Online::OnlineProfilegetCurrentOnlineProfile ()
 Returns the current online profile (which is the list of all achievements and friends).
 
static PlayerProfile::OnlineState getCurrentOnlineState ()
 Returns the online state of the current player. More...
 
static void requestOnlinePoll ()
 Sends a request to the server to see if any new information is available. More...
 
static void resumeSavedSession ()
 Reconnect to the server using the saved session data.
 
static void onSTKQuit ()
 Sends a message to the server that the client has been closed, if a user is signed in.
 
static void requestSignOut ()
 Signs the current user out.
 
static void requestSignIn (const irr::core::stringw &username, const irr::core::stringw &password)
 Create a signin request. More...
 
static PlayerProfilegetCurrentPlayer ()
 Returns the current player. More...
 
static AchievementsStatusgetCurrentAchievementsStatus ()
 A handy shortcut funtion. More...
 
static void increaseAchievement (unsigned int achievement_data_id, int increase=1)
 A handy shortcut to increase points for an achievement data of the current player. More...
 
static void resetAchievementData (unsigned int achievement_data_id)
 Reset an achievement data for current player. More...
 
static void onRaceEnd (bool restart)
 Reset achievements which have to be done in one race. More...
 
static void trackEvent (std::string track_ident, AchievementsStatus::TrackData event)
 Transmit an incrementation request of one of the track event counters. More...
 
static void resetKartHits (int num_karts)
 
static void addKartHit (int kart_id)
 

Private Member Functions

void load ()
 Manages the loading of saved player data from the players.xml file. More...
 
 PlayerManager ()
 Constructor.
 
 ~PlayerManager ()
 Destructor.
 

Private Attributes

PtrVector< PlayerProfilem_all_players
 
PlayerProfilem_current_player
 A pointer to the current player. More...
 
const XMLNodem_player_data
 Saves the XML tree from players.xml for use in the 2nd loading stage (initRemainingData). More...
 

Static Private Attributes

static PlayerManagerm_player_manager = NULL
 

Detailed Description

A special class that manages all local player accounts.

It reads all player accounts from the players.xml file in the user config directory. For each player an instance of PlayerProfile is created, which keeps track of story mode progress, achievements and other data. It also keeps track of the currently logged in player. It includes several handy static functions which avoid long call sequences, e.g.: PlayerManager::getCurrentOnlineId() which is just: PlayerManager::get()->getCurrentUser()->getID();

Member Function Documentation

◆ addDefaultPlayer()

void PlayerManager::addDefaultPlayer ( )

Called when no player profiles exists.

It creates two players: one guest player, and one non-guest player for which it tries to guess a name based on environment variables.

◆ addNewPlayer()

PlayerProfile * PlayerManager::addNewPlayer ( const irr::core::stringw &  name)

Adds a new player to the list of all players.

Parameters
nameName of the new player.

◆ create()

void PlayerManager::create ( )
static

Create the instance of the player manager.

Also make sure that at least one player is defined (and if not, create a default player and a guest player).

◆ createGuestPlayers()

void PlayerManager::createGuestPlayers ( int  n)

Makes sure at least n guest players exist.

This is used by the multiplayer KartSelection screen to make sure enough guest players can be picked by the players.

Parameters
nMinimum number of guest players that must exist.

◆ enforceCurrentPlayer()

void PlayerManager::enforceCurrentPlayer ( )

This function makes sure that a current player is defined.

This is called when a screen skipping command line option is given (-N, -R, ...), in which case there might not be a current player (if no default player is set in players.xml, i.e. the 'remember be' option was not picked ). Since a lot of code depends on having a local player, just set the most frequently used non-guest to be the current player.

◆ get()

static PlayerManager* PlayerManager::get ( )
inlinestatic

Static singleton get function.

◆ getCurrentAchievementsStatus()

static AchievementsStatus* PlayerManager::getCurrentAchievementsStatus ( )
inlinestatic

A handy shortcut funtion.

◆ getCurrentOnlineId()

unsigned int PlayerManager::getCurrentOnlineId ( )
static

Returns the online id of the current player.

Precondition
User logged in (which is asserted in getID()).

◆ getCurrentOnlineState()

PlayerProfile::OnlineState PlayerManager::getCurrentOnlineState ( )
static

Returns the online state of the current player.

It can be logged out, logging in, logged in, logging out, logged out, or guest.

◆ getCurrentPlayer()

static PlayerProfile* PlayerManager::getCurrentPlayer ( )
inlinestatic

Returns the current player.

◆ getNumPlayers()

unsigned int PlayerManager::getNumPlayers ( ) const
inline

Returns the number of players in the config file.

◆ getPlayer() [1/3]

PlayerProfile * PlayerManager::getPlayer ( const irr::core::stringw &  name)

Returns a player with a given name.

Returns
The player profile or NULL if the name was not found.
Parameters
nameThe name to search for.

◆ getPlayer() [2/3]

const PlayerProfile* PlayerManager::getPlayer ( unsigned int  n) const
inline

Returns a player with a given unique id.

◆ getPlayer() [3/3]

PlayerProfile* PlayerManager::getPlayer ( unsigned int  n)
inline

Returns a player with a given unique id.

◆ getPlayerById()

const PlayerProfile * PlayerManager::getPlayerById ( unsigned int  id)

Returns a PlayerProfile with a given id.

It searches linearly through the list of all players.

Returns
The profile, or NULL if no such profile exists.
Parameters
idThe id of the player to look for.

◆ getUniqueId()

unsigned int PlayerManager::getUniqueId ( ) const

This returns a unique id.

This is 1 + largest id used so far.

◆ increaseAchievement()

static void PlayerManager::increaseAchievement ( unsigned int  achievement_data_id,
int  increase = 1 
)
inlinestatic

A handy shortcut to increase points for an achievement data of the current player.

Parameters
achievement_data_idThe achievement data id
increaseHow much to increase the current value.

◆ initRemainingData()

void PlayerManager::initRemainingData ( )

The 2nd loading stage.

During this stage achievements and story mode data is initialised for each player. In case of existing player (i.e. not first time start of stk) the data is read from the players.xml file, in case of a first time start new/empty data structures for the players (which were created by default) are created.

◆ isCurrentLoggedIn()

bool PlayerManager::isCurrentLoggedIn ( )
static

Returns whether a user is signed in or not.

◆ load()

void PlayerManager::load ( )
private

Manages the loading of saved player data from the players.xml file.

This function create the XML tree from the file, and then creates the instances of PlayerProfile which read each node.

◆ onRaceEnd()

static void PlayerManager::onRaceEnd ( bool  restart)
inlinestatic

Reset achievements which have to be done in one race.

Parameters
restart- if the race has been restarted

◆ requestOnlinePoll()

void PlayerManager::requestOnlinePoll ( )
static

Sends a request to the server to see if any new information is available.

(online friends, notifications, etc.).

◆ requestSignIn()

void PlayerManager::requestSignIn ( const irr::core::stringw &  username,
const irr::core::stringw &  password 
)
static

Create a signin request.

Parameters
usernameName of user.
passwordPassword.
save_sessionIf true, the login credential will be saved to allow a password-less login.
request_nowImmediately submit this request to the RequestManager.

◆ resetAchievementData()

static void PlayerManager::resetAchievementData ( unsigned int  achievement_data_id)
inlinestatic

Reset an achievement data for current player.

Parameters
achievement_data_idThe achievement data id

◆ setCurrentPlayer()

void PlayerManager::setCurrentPlayer ( PlayerProfile player)

Sets the current player.

This is the player that is used for story mode and achievements.

Parameters
Playerprofile to be the current player.

◆ setUserDetails()

void PlayerManager::setUserDetails ( std::shared_ptr< Online::HTTPRequest request,
const std::string &  action,
const std::string &  php_name = "" 
)
static

Adds the login credential to a http request.

It sets the name of the script to invokce, token, and user id.

Parameters
requestThe http request.
actionIf not empty, the action to be set.

◆ trackEvent()

static void PlayerManager::trackEvent ( std::string  track_ident,
AchievementsStatus::TrackData  event 
)
inlinestatic

Transmit an incrementation request of one of the track event counters.

Parameters
track_ident- the internal name of the track
event- the type of counter to increment

Member Data Documentation

◆ m_current_player

PlayerProfile* PlayerManager::m_current_player
private

A pointer to the current player.

◆ m_player_data

const XMLNode* PlayerManager::m_player_data
private

Saves the XML tree from players.xml for use in the 2nd loading stage (initRemainingData).


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