A special class that manages all local player accounts.
More...
#include <player_manager.hpp>
|
void | save () |
| Saves all player profiles to players.xml.
|
|
void | initRemainingData () |
| The 2nd loading stage.
|
|
unsigned int | getUniqueId () const |
| This returns a unique id.
|
|
void | addDefaultPlayer () |
| Called when no player profiles exists.
|
|
PlayerProfile * | addNewPlayer (const irr::core::stringw &name) |
| Adds a new player to the list of all players.
|
|
void | createGuestPlayers (int n) |
| Makes sure at least n guest players exist.
|
|
void | deletePlayer (PlayerProfile *player) |
| Deletes a player profile from the list of all profiles.
|
|
void | setCurrentPlayer (PlayerProfile *player) |
| Sets the current player.
|
|
const PlayerProfile * | getPlayerById (unsigned int id) |
| Returns a PlayerProfile with a given id.
|
|
void | enforceCurrentPlayer () |
| This function makes sure that a current player is defined.
|
|
unsigned int | getNumNonGuestPlayers () const |
| Returns the number of 'real' (non-guest) players.
|
|
PlayerProfile * | getPlayer (const irr::core::stringw &name) |
| Returns a player with a given name.
|
|
unsigned int | getNumPlayers () const |
| Returns the number of players in the config file.
|
|
const PlayerProfile * | getPlayer (unsigned int n) const |
| Returns a player with a given unique id.
|
|
PlayerProfile * | getPlayer (unsigned int n) |
| Returns a player with a given unique id.
|
|
|
static void | create () |
| Create the instance of the player manager.
|
|
static PlayerManager * | get () |
| Static singleton get function.
|
|
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.
|
|
static unsigned int | getCurrentOnlineId () |
| Returns the online id of the current player.
|
|
static bool | isCurrentLoggedIn () |
| Returns whether a user is signed in or not.
|
|
static Online::OnlineProfile * | getCurrentOnlineProfile () |
| 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.
|
|
static void | requestOnlinePoll () |
| Sends a request to the server to see if any new information is available.
|
|
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.
|
|
static PlayerProfile * | getCurrentPlayer () |
| Returns the current player.
|
|
static AchievementsStatus * | getCurrentAchievementsStatus () |
| A handy shortcut funtion.
|
|
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.
|
|
static void | resetAchievementData (unsigned int achievement_data_id) |
| Reset an achievement data for current player.
|
|
static void | onRaceEnd (bool restart) |
| Reset achievements which have to be done in one race.
|
|
static void | trackEvent (std::string track_ident, AchievementsStatus::TrackData event) |
| Transmit an incrementation request of one of the track event counters.
|
|
static void | resetKartHits (int num_karts) |
|
static void | addKartHit (int kart_id) |
|
|
void | load () |
| Manages the loading of saved player data from the players.xml file.
|
|
| PlayerManager () |
| Constructor.
|
|
| ~PlayerManager () |
| Destructor.
|
|
|
PtrVector< PlayerProfile > | m_all_players |
|
PlayerProfile * | m_current_player |
| A pointer to the current player.
|
|
const XMLNode * | m_player_data |
| Saves the XML tree from players.xml for use in the 2nd loading stage (initRemainingData).
|
|
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.
◆ 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.
◆ getPlayer()
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. |
◆ 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.
◆ 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 |
The documentation for this class was generated from the following files: