Changed all calls to CurrentUser::getID() to PlayerManager::getCurrentOnlineId().

This commit is contained in:
hiker 2014-04-11 16:06:51 +10:00
parent 00e85b4637
commit 071aa01f35
9 changed files with 39 additions and 18 deletions

View File

@ -20,10 +20,10 @@
#ifndef HEADER_ACHIEVEMENTS_SLOT_HPP
#define HEADER_ACHIEVEMENTS_SLOT_HPP
#include "utils/types.hpp"
#include "achievements/achievement.hpp"
#include "online/request_manager.hpp"
#include "online/xml_request.hpp"
#include "utils/types.hpp"
#include <irrString.h>
#include <string>

View File

@ -53,6 +53,10 @@ void PlayerManager::setUserDetails(Online::HTTPRequest *request,
{
get()->getCurrentUser()->setUserDetails(request, action, php_name);
}
unsigned int PlayerManager::getCurrentOnlineId()
{
return getCurrentUser()->getID();
} // getCurrentOnlineId
// ============================================================================
/** Constructor.

View File

@ -33,16 +33,21 @@ class AchievementsStatus;
namespace online
{
class HTTPRequest;
class CurrentUser;
class CurrentUser;
class HTTPRequest;
}
class PlayerProfile;
/** A special class that manages all local player accounts. It reads all player
* accounts from the players.xml file in the user config directory. It also
* keeps track of the currently logged in player. For each player an instance
* of PlayerProfile is created, which keeps track of story mode progress,
* achievements and other data.
* 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();
*/
class PlayerManager : public NoCopy
{
@ -106,6 +111,11 @@ public:
return get()->m_current_player->getCurrentUser();
} // getCurrentUser
// ------------------------------------------------------------------------
/** Returns the online id of the current player.
* \pre User logged in (which is asserted in getID()).
*/
static unsigned int getCurrentOnlineId();
// ------------------------------------------------------------------------
PlayerProfile *getPlayer(const irr::core::stringw &name);
// ------------------------------------------------------------------------
/** Returns the number of players in the config file.*/

View File

@ -234,7 +234,7 @@ void ClientLobbyRoomProtocol::update()
{
NetworkString ns;
// 1 (connection request), 4 (size of id), global id
ns.ai8(1).ai8(4).ai32(PlayerManager::getCurrentUser()->getID());
ns.ai8(1).ai8(4).ai32(PlayerManager::getCurrentOnlineId());
m_listener->sendMessage(this, ns);
m_state = REQUESTING_CONNECTION;
}
@ -296,7 +296,7 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
uint32_t global_id = data.gui32(1);
uint8_t race_id = data.gui8(6);
if (global_id == PlayerManager::getCurrentUser()->getID())
if (global_id == PlayerManager::getCurrentOnlineId())
{
Log::error("ClientLobbyRoomProtocol", "The server notified me that i'm a new player in the room (not normal).");
}
@ -369,7 +369,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
STKPeer* peer = *(event->peer);
uint32_t global_id = data.gui32(8);
if (global_id == PlayerManager::getCurrentUser()->getID())
if (global_id == PlayerManager::getCurrentOnlineId())
{
Log::info("ClientLobbyRoomProtocol", "The server accepted the connection.");

View File

@ -33,6 +33,8 @@
#include <string>
#include <assert.h>
class PlayerManager;
namespace Online
{
@ -94,6 +96,12 @@ namespace Online
void signIn (bool success, const XMLNode * input);
void signOut (bool success, const XMLNode * input);
// For now declare functions that will become part of PlayerManager
// or Playerprofile to be private, and give only PlayerManager
// access to them. FIXME
friend class PlayerManager;
uint32_t getID() const;
public:
CurrentUser();
void setUserDetails(HTTPRequest *request,
@ -112,7 +120,6 @@ namespace Online
void requestPoll() const;
irr::core::stringw getUserName() const;
uint32_t getID() const;
// ----------------------------------------------------------------
/** Returns the user state. */
const UserState getUserState() const { return m_state; }

View File

@ -114,7 +114,7 @@ OnlineProfile::OnlineProfile(const XMLNode * xml, ConstructorType type)
xml->get("id", &m_id );
xml->get("user_name", &m_username);
m_is_current_user = (m_id == PlayerManager::getCurrentUser()->getID());
m_is_current_user = (m_id == PlayerManager::getCurrentOnlineId());
m_state = S_READY;
} // OnlineProfile(XMLNode)

View File

@ -139,12 +139,12 @@ void NotificationDialog::onUpdate(float dt)
{
if(type == T_Friends)
{
ProfileManager::get()->setVisiting(PlayerManager::getCurrentUser()->getID());
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->pushScreen(OnlineProfileFriends::getInstance());
}
else if (type == T_Achievements)
{
ProfileManager::get()->setVisiting(PlayerManager::getCurrentUser()->getID());
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->pushScreen(OnlineProfileAchievements::getInstance());
}
}

View File

@ -160,8 +160,8 @@ void MainMenuScreen::onUpdate(float delta)
else // now must be either logging in or logging out
m_online->setDeactivated();
m_online->setLabel(PlayerManager::getCurrentUser()->getID() ? _("Online")
: _("Login" ) );
m_online->setLabel(PlayerManager::getCurrentOnlineId() ? _("Online")
: _("Login" ) );
IconButtonWidget* addons_icon = getWidget<IconButtonWidget>("addons");
if (addons_icon != NULL)
{
@ -405,7 +405,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
"\"Allow STK to connect to the Internet\"."));
return;
}
if (PlayerManager::getCurrentUser()->getID())
if (PlayerManager::getCurrentOnlineId())
StateManager::get()->pushScreen(OnlineScreen::getInstance());
else
StateManager::get()->pushScreen(LoginScreen::getInstance());

View File

@ -231,7 +231,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
}
else if (selection == m_profile_widget->m_properties[PROP_ID])
{
ProfileManager::get()->setVisiting(PlayerManager::getCurrentUser()->getID());
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->pushScreen(OnlineProfileOverview::getInstance());
}
else if (selection == m_find_server_widget->m_properties[PROP_ID])