A special class that manages all local player accounts.
More...
#include <player_manager.hpp>
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();
◆ 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
-
name | Name 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
-
n | Minimum 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 singleton get function.
◆ getCurrentAchievementsStatus()
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()
Returns the online state of the current player.
It can be logged out, logging in, logged in, logging out, logged out, or guest.
◆ getCurrentPlayer()
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
-
name | The 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]
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
-
id | The 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_id | The achievement data id |
increase | How 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
-
username | Name of user. |
password | Password. |
save_session | If true, the login credential will be saved to allow a password-less login. |
request_now | Immediately 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_id | The achievement data id |
◆ setCurrentPlayer()
Sets the current player.
This is the player that is used for story mode and achievements.
- Parameters
-
Player | profile 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
-
request | The http request. |
action | If 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 |
◆ m_current_player
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: