Removed CurrentUser usage from all files except PlayerManager

and PlayerProfile.
This commit is contained in:
hiker 2014-04-16 11:13:35 +10:00
parent 1a908b254f
commit 447ca89c0a
45 changed files with 146 additions and 102 deletions

View File

@ -25,7 +25,6 @@
#include "config/player_profile.hpp"
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "online/current_user.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"

View File

@ -26,7 +26,6 @@
#include "utils/log.hpp"
#include "utils/ptr_vector.hpp"
#include "utils/translation.hpp"
#include "online/current_user.hpp"
#include <sstream>
#include <fstream>

View File

@ -83,6 +83,72 @@ PlayerManager::OnlineState PlayerManager::getCurrentOnlineState()
{
return (OnlineState)getCurrentUser()->getUserState();
} // getCurrentOnlineState
// ----------------------------------------------------------------------------
/** Returns the online name of this player.
*/
const irr::core::stringw& PlayerManager::getCurrentOnlineUserName()
{
if (getCurrentOnlineState() == OS_SIGNED_IN ||
getCurrentOnlineState() == OS_GUEST )
return getCurrentOnlineProfile()->getUserName();
static core::stringw not_signed_in = _("Currently not signed in");
return not_signed_in;
} // getCurrentOnlineUserName
// ----------------------------------------------------------------------------
/** Sends a request to the server to see if any new information is
* available. (online friends, notifications, etc.).
*/
void PlayerManager::requestOnlinePoll()
{
getCurrentUser()->requestPoll();
} // requestOnlinePoll
// ----------------------------------------------------------------------------
/** Reconnect to the server using the saved session data.
*/
void PlayerManager::resumeSavedSession()
{
getCurrentUser()->requestSavedSession();
} // resumeSavedSession
// ----------------------------------------------------------------------------
/** Sends a message to the server that the client has been closed, if a
* user is signed in.
*/
void PlayerManager::onSTKQuit()
{
getCurrentUser()->onSTKQuit();
} // onSTKQuit
// ----------------------------------------------------------------------------
/** Create a signin request.
* \param username Name of user.
* \param password Password.
* \param save_session If true, the login credential will be saved to
* allow a password-less login.
* \param request_now Immediately submit this request to the
* RequestManager.
*/
Online::XMLRequest *PlayerManager::requestSignIn(const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session,
bool request_now)
{
return getCurrentUser()->requestSignIn(username, password, save_session,
request_now);
} // requestSignIn
// ----------------------------------------------------------------------------
/** Signs the current user out.
*/
void PlayerManager::requestSignOut()
{
getCurrentUser()->requestSignOut();
} // requestSignOut
// ----------------------------------------------------------------------------
/** Returns the current online profile (which is the list of all achievements
* and friends).

View File

@ -36,6 +36,7 @@ namespace Online
class CurrentUser;
class HTTPRequest;
class OnlineProfile;
class XMLRequest;
}
class PlayerProfile;
@ -113,6 +114,15 @@ public:
};
static OnlineState getCurrentOnlineState();
static const irr::core::stringw& getCurrentOnlineUserName();
static void requestOnlinePoll();
static void resumeSavedSession();
static void onSTKQuit();
static void requestSignOut();
static Online::XMLRequest *requestSignIn(const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session,
bool request_now = true);
// ------------------------------------------------------------------------
/** Returns the current player. */
@ -125,6 +135,7 @@ public:
{
return get()->m_current_player->getCurrentUser();
} // getCurrentUser
// ------------------------------------------------------------------------
PlayerProfile *getPlayer(const irr::core::stringw &name);
// ------------------------------------------------------------------------

View File

@ -39,7 +39,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
m_name = name;
m_local_name = name;
m_is_guest_account = is_guest;
m_use_frequency = is_guest ? -1 : 0;
m_unique_id = PlayerManager::get()->getUniqueId();
@ -76,7 +76,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
m_achievements_status = NULL;
m_current_user = new Online::CurrentUser();
node->get("name", &m_name );
node->get("name", &m_local_name );
node->get("guest", &m_is_guest_account);
node->get("use-frequency", &m_use_frequency );
node->get("unique-id", &m_unique_id );
@ -132,7 +132,7 @@ void PlayerProfile::initRemainingData()
*/
void PlayerProfile::save(UTFWriter &out)
{
out << L" <player name=\"" << m_name
out << L" <player name=\"" << m_local_name
<< L"\" guest=\"" << m_is_guest_account
<< L"\" use-frequency=\"" << m_use_frequency << L"\"\n";

View File

@ -47,7 +47,7 @@ private:
/** The name of the player (wide string, so it can be in native
* language). */
core::stringw m_name;
core::stringw m_local_name;
/** True if this account is a guest account. */
bool m_is_guest_account;
@ -103,7 +103,7 @@ public:
#ifdef DEBUG
assert(m_magic_number == 0xABCD1234);
#endif
m_name = name;
m_local_name = name;
} // setName
// ------------------------------------------------------------------------
@ -111,7 +111,7 @@ public:
core::stringw getName() const
{
assert(m_magic_number == 0xABCD1234);
return m_name.c_str();
return m_local_name.c_str();
} // getName
// ------------------------------------------------------------------------

View File

@ -178,7 +178,6 @@
#include "network/server_network_manager.hpp"
#include "network/protocol_manager.hpp"
#include "network/protocols/server_lobby_room_protocol.hpp"
#include "online/current_user.hpp"
#include "online/profile_manager.hpp"
#include "online/request_manager.hpp"
#include "online/servers_manager.hpp"
@ -966,7 +965,7 @@ int handleCmdLine()
{
irr::core::stringw s;
Online::XMLRequest* request =
PlayerManager::getCurrentUser()->requestSignIn(login, password, false, false);
PlayerManager::requestSignIn(login, password, false, false);
request->executeNow();
if (request->isSuccess())

View File

@ -23,7 +23,6 @@
#include "network/network_manager.hpp"
#include "network/network_world.hpp"
#include "network/protocols/start_game_protocol.hpp"
#include "online/current_user.hpp"
#include "online/online_profile.hpp"
#include "states_screens/network_kart_selection.hpp"
#include "states_screens/state_manager.hpp"

View File

@ -25,7 +25,6 @@
#include "network/protocols/hide_public_address.hpp"
#include "network/protocols/request_connection.hpp"
#include "network/protocols/ping_protocol.hpp"
#include "online/current_user.hpp"
#include "utils/time.hpp"
#include "utils/log.hpp"

View File

@ -27,7 +27,6 @@
#include "network/protocols/ping_protocol.hpp"
#include "network/protocols/quick_join_protocol.hpp"
#include "network/protocols/client_lobby_room_protocol.hpp"
#include "online/current_user.hpp"
#include "utils/time.hpp"
#include "utils/log.hpp"

View File

@ -19,11 +19,10 @@
#include "network/protocols/get_peer_address.hpp"
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "network/protocol_manager.hpp"
#include "network/network_manager.hpp"
#include "online/request_manager.hpp"
#include "online/current_user.hpp"
#include "config/user_config.hpp"
#include "utils/log.hpp"
GetPeerAddress::GetPeerAddress(uint32_t peer_id, CallbackObject* callback_object) : Protocol(callback_object, PROTOCOL_SILENT)

View File

@ -22,7 +22,6 @@
#include "config/user_config.hpp"
#include "network/protocol_manager.hpp"
#include "online/request_manager.hpp"
#include "online/current_user.hpp"
#include "utils/log.hpp"
HidePublicAddress::HidePublicAddress() : Protocol(NULL, PROTOCOL_SILENT)

View File

@ -21,7 +21,6 @@
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "network/network_manager.hpp"
#include "online/current_user.hpp"
#include "online/request_manager.hpp"
#include "utils/log.hpp"

View File

@ -22,7 +22,6 @@
#include "config/user_config.hpp"
#include "network/protocol_manager.hpp"
#include "online/servers_manager.hpp"
#include "online/current_user.hpp"
using namespace Online;

View File

@ -2,7 +2,6 @@
#define HEADER_REQUEST_CONNECTION_HPP
#include "network/protocol.hpp"
#include "online/current_user.hpp"
#include "online/xml_request.hpp"
class RequestConnection : public Protocol

View File

@ -28,7 +28,6 @@
#include "network/protocols/start_server.hpp"
#include "network/protocols/start_game_protocol.hpp"
#include "network/server_network_manager.hpp"
#include "online/current_user.hpp"
#include "online/online_profile.hpp"
#include "online/request_manager.hpp"
#include "utils/log.hpp"

View File

@ -22,7 +22,6 @@
#include "config/user_config.hpp"
#include "network/network_manager.hpp"
#include "online/request_manager.hpp"
#include "online/current_user.hpp"
#include "utils/log.hpp"
ShowPublicAddress::ShowPublicAddress() : Protocol(NULL, PROTOCOL_SILENT)

View File

@ -10,7 +10,6 @@
#include "network/game_setup.hpp"
#include "network/network_world.hpp"
#include "network/protocols/synchronization_protocol.hpp"
#include "online/current_user.hpp"
#include "online/online_profile.hpp"
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
@ -19,8 +18,8 @@
#include "utils/log.hpp"
#include "utils/time.hpp"
StartGameProtocol::StartGameProtocol(GameSetup* game_setup) :
Protocol(NULL, PROTOCOL_START_GAME)
StartGameProtocol::StartGameProtocol(GameSetup* game_setup)
: Protocol(NULL, PROTOCOL_START_GAME)
{
m_game_setup = game_setup;
std::vector<NetworkPlayerProfile*> players = m_game_setup->getPlayers();

View File

@ -21,7 +21,6 @@
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "network/network_manager.hpp"
#include "online/current_user.hpp"
#include "online/request_manager.hpp"
StartServer::StartServer() : Protocol(NULL, PROTOCOL_SILENT)

View File

@ -21,7 +21,6 @@
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "network/network_manager.hpp"
#include "online/current_user.hpp"
#include "online/request_manager.hpp"
StopServer::StopServer() : Protocol(NULL, PROTOCOL_SILENT)

View File

@ -388,18 +388,6 @@ namespace Online
}
}
// ------------------------------------------------------------------------
/** \return the username if signed in. */
core::stringw CurrentUser::getUserName() const
{
if((m_state == US_SIGNED_IN ) || (m_state == US_GUEST))
{
assert(m_profile != NULL);
return m_profile->getUserName();
}
return _("Currently not signed in");
} // getUserName
// ------------------------------------------------------------------------
/** \return the online id, or 0 if the user is not signed in.
*/

View File

@ -119,26 +119,23 @@ namespace Online
/** Returns a pointer to the profile associated with the current
* user. */
OnlineProfile* getProfile() const { return m_profile; }
public:
CurrentUser();
void requestSavedSession();
SignInRequest * requestSignIn( const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session,
bool request_now = true);
void requestSignOut();
void requestFriendRequest(const uint32_t friend_id) const;
void onSTKQuit() const;
void requestPoll() const;
irr::core::stringw getUserName() const;
// ----------------------------------------------------------------
// ----------------------------------------------------------------
/** Returns the session token of the signed in user. */
const std::string& getToken() const { return m_token; }
void requestPoll() const;
void requestSavedSession();
void onSTKQuit() const;
void requestSignOut();
SignInRequest *requestSignIn(const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session,
bool request_now = true);
public:
CurrentUser();
// ----------------------------------------------------------------
// ----------------------------------------------------------------
}; // class CurrentUser

View File

@ -19,7 +19,6 @@
#include "online/profile_manager.hpp"
#include "online/current_user.hpp"
#include "online/online_profile.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"

View File

@ -21,7 +21,6 @@
#include "online/request_manager.hpp"
#include "config/player_manager.hpp"
#include "online/current_user.hpp"
#include "states_screens/state_manager.hpp"
#include <iostream>
@ -132,7 +131,7 @@ namespace Online
// In case that login id was not saved (or first start of stk),
// current player would not be defined at this stage.
if(PlayerManager::getCurrentPlayer())
PlayerManager::getCurrentUser()->requestSavedSession();
PlayerManager::resumeSavedSession();
} // startNetworkThread
// ------------------------------------------------------------------------
@ -150,7 +149,7 @@ namespace Online
// a download, which mean we can get the mutex and ask the service
// thread here to cancel properly.
//cancelAllDownloads(); FIXME if used this way it also cancels the client-quit action
PlayerManager::getCurrentUser()->onSTKQuit();
PlayerManager::onSTKQuit();
addRequest(new Request(true, HTTP_MAX_PRIORITY, Request::RT_QUIT));
} // stopNetworkThread
@ -295,7 +294,7 @@ namespace Online
if(m_time_since_poll > interval)
{
m_time_since_poll = 0;
PlayerManager::getCurrentUser()->requestPoll();
PlayerManager::requestOnlinePoll();
}
} // update

View File

@ -58,7 +58,7 @@ void CreateServerScreen::loadedFromFile()
m_name_widget = getWidget<TextBoxWidget>("name");
assert(m_name_widget != NULL);
m_name_widget->setText(PlayerManager::getCurrentUser()->getUserName() + _("'s server"));
m_name_widget->setText(PlayerManager::getCurrentOnlineUserName() + _("'s server"));
m_max_players_widget = getWidget<SpinnerWidget>("max_players");
assert(m_max_players_widget != NULL);
m_max_players_widget->setValue(8);

View File

@ -20,7 +20,6 @@
#include "guiengine/screen.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
#include "online/xml_request.hpp"

View File

@ -20,10 +20,11 @@
#include "audio/sfx_manager.hpp"
#include "config/player_manager.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets.hpp"
#include "online/messages.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/messages.hpp"
#include <IGUIEnvironment.h>
#include <irrString.h>

View File

@ -19,13 +19,16 @@
#ifndef HEADER_CHANGE_PASSWORD_DIALOG_HPP
#define HEADER_CHANGE_PASSWORD_DIALOG_HPP
#include "online/current_user.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include <irrString.h>
namespace GUIEngine
{
class IconButtonWidget;
class LabelWidget;
}
/**
* \brief Dialog that allows a user to sign in
* \ingroup states_screens

View File

@ -35,7 +35,7 @@ using namespace Online;
// -----------------------------------------------------------------------------
NotificationDialog::NotificationDialog(Type type, const core::stringw info)
NotificationDialog::NotificationDialog(Type type, const core::stringw &info)
: ModalDialog(0.8f,0.5f)
{
m_info = info;

View File

@ -19,13 +19,12 @@
#ifndef HEADER_NOTIFICATION_DIALOG_HPP
#define HEADER_NOTIFICATION_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
#include "utils/types.hpp"
#include <irrString.h>
/**
* \brief Dialog that allows a user to sign in
@ -53,7 +52,7 @@ private:
GUIEngine::IconButtonWidget * m_cancel_widget;
public:
NotificationDialog(Type type, const core::stringw info);
NotificationDialog(Type type, const core::stringw &info);
~NotificationDialog();
virtual void beforeAddingWidgets();

View File

@ -20,10 +20,10 @@
#include "audio/sfx_manager.hpp"
#include "config/player_manager.hpp"
#include "guiengine/engine.hpp"
#include "online/messages.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/messages.hpp"
#include <IGUIEnvironment.h>

View File

@ -19,11 +19,14 @@
#ifndef HEADER_RECOVERY_DIALOG_HPP
#define HEADER_RECOVERY_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
namespace Online
{
class XMLRequest;
}
/**
* \brief Dialog that allows a user to recover his account

View File

@ -17,16 +17,16 @@
#include "states_screens/dialogs/registration_dialog.hpp"
#include <IGUIEnvironment.h>
#include "audio/sfx_manager.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/register_screen.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/messages.hpp"
#include <IGUIEnvironment.h>
using namespace GUIEngine;
using namespace irr;

View File

@ -19,11 +19,8 @@
#ifndef HEADER_REGISTRATION_DIALOG_HPP
#define HEADER_REGISTRATION_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
/**
* \brief Dialog that allows a user to register
* \ingroup states_screens

View File

@ -21,7 +21,6 @@
#include "guiengine/engine.hpp"
#include "network/protocol_manager.hpp"
#include "network/protocols/connect_to_server.hpp"
#include "online/current_user.hpp"
#include "online/messages.hpp"
#include "online/servers_manager.hpp"
#include "states_screens/dialogs/registration_dialog.hpp"

View File

@ -19,17 +19,15 @@
#ifndef HEADER_SERVER_INFO_DIALOG_HPP
#define HEADER_SERVER_INFO_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "network/protocols/request_connection.hpp"
#include "online/current_user.hpp"
#include "online/server.hpp"
#include "utils/types.hpp"
#include <irrString.h>
/**
* \brief Dialog that allows a user to sign in

View File

@ -21,12 +21,15 @@
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
#include "online/profile_manager.hpp"
#include "utils/types.hpp"
#include <irrString.h>
namespace Online
{
class OnlineProfile;
}
/**
* \brief Dialog that allows a user to sign in
* \ingroup states_screens

View File

@ -18,18 +18,16 @@
#include "states_screens/dialogs/vote_dialog.hpp"
#include "addons/addons_manager.hpp"
#include "config/player_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "config/player_manager.hpp"
#include "guiengine/engine.hpp"
#include "online/messages.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/current_user.hpp"
#include "online/messages.hpp"
#include <IGUIEnvironment.h>
using namespace GUIEngine;
using namespace irr;
using namespace irr::gui;

View File

@ -19,12 +19,16 @@
#ifndef HEADER_VOTE_DIALOG_HPP
#define HEADER_VOTE_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
#include <irrString.h>
namespace Online
{
class XMLRequest;
}
/**
* \brief Dialog that allows a user to sign in
* \ingroup states_screens

View File

@ -24,7 +24,6 @@
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "online/current_user.hpp"
#include "online/messages.hpp"
#include "states_screens/guest_login_screen.hpp"
#include "states_screens/online_screen.hpp"
@ -99,8 +98,7 @@ void LoginScreen::login()
m_options_widget->setDeactivated();
info_widget->setDefaultColor();
bool remember = getWidget<CheckBoxWidget>("remember")->getState();
PlayerManager::getCurrentUser()->requestSignIn(username, password,
remember );
PlayerManager::requestSignIn(username, password, remember);
}
} // login

View File

@ -10,7 +10,6 @@
#include "network/protocol_manager.hpp"
#include "network/protocols/client_lobby_room_protocol.hpp"
#include "network/network_manager.hpp"
#include "online/current_user.hpp"
#include "states_screens/state_manager.hpp"
static const char RANDOM_KART_ID[] = "randomkart";

View File

@ -138,7 +138,7 @@ void OnlineScreen::init()
setInitialFocus();
DemoWorld::resetIdleTime();
core::stringw m = _("Signed in as: %s.",
PlayerManager::getCurrentUser()->getUserName());
PlayerManager::getCurrentOnlineUserName());
m_online_status_widget->setText(m, false);
} // init
@ -226,7 +226,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
if (selection == m_sign_out_widget->m_properties[PROP_ID])
{
PlayerManager::getCurrentUser()->requestSignOut();
PlayerManager::requestSignOut();
StateManager::get()->popMenu();
}
else if (selection == m_profile_widget->m_properties[PROP_ID])

View File

@ -20,8 +20,8 @@
#include "audio/sfx_manager.hpp"
#include "config/player_manager.hpp"
#include "guiengine/modaldialog.hpp"
#include "online/current_user.hpp"
#include "online/messages.hpp"
#include "online/profile_manager.hpp"
#include "states_screens/dialogs/user_info_dialog.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/state_manager.hpp"

View File

@ -21,8 +21,8 @@
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "online/current_user.hpp"
#include "online/messages.hpp"
#include "online/xml_request.hpp"
#include "states_screens/dialogs/registration_dialog.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/guest_login_screen.hpp"

View File

@ -22,7 +22,6 @@
#include "config/user_config.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "online/current_user.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/state_manager.hpp"
@ -124,7 +123,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
// a login (if an online login was saved). If the current player was
// saved, this request will be started much earlier in the startup
// sequence from the RequestManager.
player->getCurrentUser()->requestSavedSession();
PlayerManager::resumeSavedSession();
}
} // eventCallback