diff --git a/src/achievements/achievements_status.hpp b/src/achievements/achievements_status.hpp index 585be071d..faf234fc7 100644 --- a/src/achievements/achievements_status.hpp +++ b/src/achievements/achievements_status.hpp @@ -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 #include diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 5bfa00db6..608644be5 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -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. diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index bec15f499..8f8c5ecbd 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -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.*/ diff --git a/src/network/protocols/client_lobby_room_protocol.cpp b/src/network/protocols/client_lobby_room_protocol.cpp index 1c2119b8c..aa06c1268 100644 --- a/src/network/protocols/client_lobby_room_protocol.cpp +++ b/src/network/protocols/client_lobby_room_protocol.cpp @@ -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."); diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index dcc014165..64466c7dd 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -33,6 +33,8 @@ #include #include +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; } diff --git a/src/online/online_profile.cpp b/src/online/online_profile.cpp index b375617aa..3d1164609 100644 --- a/src/online/online_profile.cpp +++ b/src/online/online_profile.cpp @@ -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) diff --git a/src/states_screens/dialogs/notification_dialog.cpp b/src/states_screens/dialogs/notification_dialog.cpp index 87e895c1a..8119cfa9f 100644 --- a/src/states_screens/dialogs/notification_dialog.cpp +++ b/src/states_screens/dialogs/notification_dialog.cpp @@ -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()); } } diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index c9fd9010e..cca4f39ee 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -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("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()); diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index cfb8eaf42..874246f7c 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -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])