Refactor so that PlayerProfile provides a proper interface plus
function/states for local use, and CurrentUser implements the missing functions.
This commit is contained in:
parent
447ca89c0a
commit
056aa5ed6f
@ -56,14 +56,14 @@ void PlayerManager::setUserDetails(Online::HTTPRequest *request,
|
||||
const std::string &action,
|
||||
const std::string &php_name)
|
||||
{
|
||||
get()->getCurrentUser()->setUserDetails(request, action, php_name);
|
||||
get()->getCurrentPlayer()->setUserDetails(request, action, php_name);
|
||||
} // setUserDetails
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns whether a user is signed in or not. */
|
||||
bool PlayerManager::isCurrentLoggedIn()
|
||||
{
|
||||
return getCurrentUser()->isRegisteredUser();
|
||||
return getCurrentPlayer()->isLoggedIn();
|
||||
} // isCurrentLoggedIn
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -72,24 +72,25 @@ bool PlayerManager::isCurrentLoggedIn()
|
||||
*/
|
||||
unsigned int PlayerManager::getCurrentOnlineId()
|
||||
{
|
||||
return getCurrentUser()->getID();
|
||||
return getCurrentPlayer()->getOnlineId();
|
||||
} // getCurrentOnlineId
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the online state of the current player. It can be logged out,
|
||||
* logging in, logged in, logging out, logged out, or guest.
|
||||
*/
|
||||
PlayerManager::OnlineState PlayerManager::getCurrentOnlineState()
|
||||
PlayerProfile::OnlineState PlayerManager::getCurrentOnlineState()
|
||||
{
|
||||
return (OnlineState)getCurrentUser()->getUserState();
|
||||
return getCurrentPlayer()->getOnlineState();
|
||||
} // getCurrentOnlineState
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the online name of this player.
|
||||
*/
|
||||
const irr::core::stringw& PlayerManager::getCurrentOnlineUserName()
|
||||
{
|
||||
if (getCurrentOnlineState() == OS_SIGNED_IN ||
|
||||
getCurrentOnlineState() == OS_GUEST )
|
||||
if (getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN ||
|
||||
getCurrentOnlineState() == PlayerProfile::OS_GUEST )
|
||||
return getCurrentOnlineProfile()->getUserName();
|
||||
|
||||
static core::stringw not_signed_in = _("Currently not signed in");
|
||||
@ -102,7 +103,7 @@ const irr::core::stringw& PlayerManager::getCurrentOnlineUserName()
|
||||
*/
|
||||
void PlayerManager::requestOnlinePoll()
|
||||
{
|
||||
getCurrentUser()->requestPoll();
|
||||
getCurrentPlayer()->requestPoll();
|
||||
} // requestOnlinePoll
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -110,7 +111,7 @@ void PlayerManager::requestOnlinePoll()
|
||||
*/
|
||||
void PlayerManager::resumeSavedSession()
|
||||
{
|
||||
getCurrentUser()->requestSavedSession();
|
||||
getCurrentPlayer()->requestSavedSession();
|
||||
} // resumeSavedSession
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -119,7 +120,7 @@ void PlayerManager::resumeSavedSession()
|
||||
*/
|
||||
void PlayerManager::onSTKQuit()
|
||||
{
|
||||
getCurrentUser()->onSTKQuit();
|
||||
getCurrentPlayer()->onSTKQuit();
|
||||
} // onSTKQuit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -137,8 +138,8 @@ Online::XMLRequest *PlayerManager::requestSignIn(const irr::core::stringw &usern
|
||||
bool save_session,
|
||||
bool request_now)
|
||||
{
|
||||
return getCurrentUser()->requestSignIn(username, password, save_session,
|
||||
request_now);
|
||||
return getCurrentPlayer()->requestSignIn(username, password, save_session,
|
||||
request_now);
|
||||
} // requestSignIn
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -146,7 +147,7 @@ Online::XMLRequest *PlayerManager::requestSignIn(const irr::core::stringw &usern
|
||||
*/
|
||||
void PlayerManager::requestSignOut()
|
||||
{
|
||||
getCurrentUser()->requestSignOut();
|
||||
getCurrentPlayer()->requestSignOut();
|
||||
} // requestSignOut
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -155,7 +156,7 @@ void PlayerManager::requestSignOut()
|
||||
*/
|
||||
Online::OnlineProfile* PlayerManager::getCurrentOnlineProfile()
|
||||
{
|
||||
return getCurrentUser()->getProfile();
|
||||
return getCurrentPlayer()->getProfile();
|
||||
} // getCurrentOnlineProfile
|
||||
|
||||
// ============================================================================
|
||||
@ -200,7 +201,7 @@ void PlayerManager::load()
|
||||
for(unsigned int i=0; i<m_player_data->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode *player_xml = m_player_data->getNode(i);
|
||||
PlayerProfile *player = new PlayerProfile(player_xml);
|
||||
PlayerProfile *player = new Online::CurrentUser(player_xml);
|
||||
m_all_players.push_back(player);
|
||||
if(player->isDefault())
|
||||
m_current_player = player;
|
||||
@ -271,7 +272,7 @@ void PlayerManager::save()
|
||||
*/
|
||||
void PlayerManager::addNewPlayer(const core::stringw& name)
|
||||
{
|
||||
m_all_players.push_back( new PlayerProfile(name) );
|
||||
m_all_players.push_back( new Online::CurrentUser(name) );
|
||||
} // addNewPlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -343,10 +344,10 @@ void PlayerManager::addDefaultPlayer()
|
||||
// Set the name as the default name, but don't mark it as 'default'
|
||||
// yet, since not having a default player forces the player selection
|
||||
// screen to be shown.
|
||||
m_all_players.push_back(new PlayerProfile(username.c_str()) );
|
||||
m_all_players.push_back(new Online::CurrentUser(username.c_str()) );
|
||||
|
||||
// add default guest player
|
||||
m_all_players.push_back(new PlayerProfile(_LTR("Guest"), /*guest*/true));
|
||||
m_all_players.push_back(new Online::CurrentUser(_LTR("Guest"), /*guest*/true));
|
||||
} // addDefaultPlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -103,17 +103,7 @@ public:
|
||||
static bool isCurrentLoggedIn();
|
||||
static Online::OnlineProfile* getCurrentOnlineProfile();
|
||||
|
||||
/** The online state a player can be in. */
|
||||
enum OnlineState
|
||||
{
|
||||
OS_SIGNED_OUT = 0,
|
||||
OS_SIGNED_IN,
|
||||
OS_GUEST,
|
||||
OS_SIGNING_IN,
|
||||
OS_SIGNING_OUT
|
||||
};
|
||||
|
||||
static OnlineState getCurrentOnlineState();
|
||||
static PlayerProfile::OnlineState getCurrentOnlineState();
|
||||
static const irr::core::stringw& getCurrentOnlineUserName();
|
||||
static void requestOnlinePoll();
|
||||
static void resumeSavedSession();
|
||||
@ -130,11 +120,6 @@ public:
|
||||
{
|
||||
return get()->m_current_player;
|
||||
} // getCurrentPlayer
|
||||
// ------------------------------------------------------------------------
|
||||
static Online::CurrentUser* getCurrentUser()
|
||||
{
|
||||
return get()->m_current_player->getCurrentUser();
|
||||
} // getCurrentUser
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
PlayerProfile *getPlayer(const irr::core::stringw &name);
|
||||
|
@ -43,7 +43,6 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
|
||||
m_is_guest_account = is_guest;
|
||||
m_use_frequency = is_guest ? -1 : 0;
|
||||
m_unique_id = PlayerManager::get()->getUniqueId();
|
||||
m_current_user = new Online::CurrentUser();
|
||||
m_is_default = false;
|
||||
m_is_default = false;
|
||||
m_saved_session = false;
|
||||
@ -74,7 +73,6 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
|
||||
m_saved_user_id = 0;
|
||||
m_story_mode_status = NULL;
|
||||
m_achievements_status = NULL;
|
||||
m_current_user = new Online::CurrentUser();
|
||||
|
||||
node->get("name", &m_local_name );
|
||||
node->get("guest", &m_is_guest_account);
|
||||
@ -96,7 +94,6 @@ PlayerProfile::~PlayerProfile()
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xDEADBEEF;
|
||||
#endif
|
||||
delete m_current_user;
|
||||
} // ~PlayerProfile
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define HEADER_PLAYER_PROFILE_HPP
|
||||
|
||||
#include "challenges/story_mode_status.hpp"
|
||||
#include "utils/leak_check.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
@ -29,7 +30,13 @@ using namespace irr;
|
||||
#include <string>
|
||||
|
||||
class AchievementsStatus;
|
||||
namespace Online { class CurrentUser; }
|
||||
namespace Online
|
||||
{
|
||||
class CurrentUser;
|
||||
class HTTPRequest;
|
||||
class OnlineProfile;
|
||||
class XMLRequest;
|
||||
}
|
||||
class UTFWriter;
|
||||
|
||||
/** Class for managing player profiles (name, usage frequency,
|
||||
@ -41,9 +48,20 @@ class UTFWriter;
|
||||
*/
|
||||
class PlayerProfile : public NoCopy
|
||||
{
|
||||
private:
|
||||
public:
|
||||
/** The online state a player can be in. */
|
||||
enum OnlineState
|
||||
{
|
||||
OS_SIGNED_OUT = 0,
|
||||
OS_SIGNED_IN,
|
||||
OS_GUEST,
|
||||
OS_SIGNING_IN,
|
||||
OS_SIGNING_OUT
|
||||
};
|
||||
|
||||
Online::CurrentUser *m_current_user;
|
||||
|
||||
private:
|
||||
LEAK_CHECK()
|
||||
|
||||
/** The name of the player (wide string, so it can be in native
|
||||
* language). */
|
||||
@ -83,7 +101,7 @@ public:
|
||||
|
||||
PlayerProfile(const core::stringw &name, bool is_guest = false);
|
||||
PlayerProfile(const XMLNode *node);
|
||||
~PlayerProfile();
|
||||
virtual ~PlayerProfile();
|
||||
void save(UTFWriter &out);
|
||||
void loadRemainingData(const XMLNode *node);
|
||||
void initRemainingData();
|
||||
@ -94,8 +112,24 @@ public:
|
||||
void saveSession(int user_id, const std::string &token);
|
||||
void clearSession();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
Online::CurrentUser* getCurrentUser() { return m_current_user; }
|
||||
/** Abstract virtual classes, to be implemented by the OnlinePlayer. */
|
||||
virtual void setUserDetails(Online::HTTPRequest *request,
|
||||
const std::string &action,
|
||||
const std::string &php_script = "") = 0;
|
||||
virtual uint32_t getOnlineId() const = 0;
|
||||
virtual PlayerProfile::OnlineState getOnlineState() const = 0;
|
||||
virtual Online::OnlineProfile* getProfile() const = 0;
|
||||
virtual void requestPoll() const = 0;
|
||||
virtual void requestSavedSession() = 0;
|
||||
virtual void onSTKQuit() const = 0;
|
||||
virtual Online::XMLRequest* requestSignIn(const irr::core::stringw &username,
|
||||
const irr::core::stringw &password,
|
||||
bool save_session,
|
||||
bool request_now = true) = 0;
|
||||
virtual void signIn(bool success, const XMLNode * input) = 0;
|
||||
virtual void signOut(bool success, const XMLNode * input) = 0;
|
||||
virtual void requestSignOut() = 0;
|
||||
virtual bool isLoggedIn() const { return false; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the name of this player. */
|
||||
void setName(const core::stringw& name)
|
||||
|
@ -62,37 +62,47 @@ namespace Online
|
||||
|
||||
if (m_profile)
|
||||
request->addParameter("userid", m_profile->getID());
|
||||
if(m_state == US_SIGNED_IN)
|
||||
if(m_online_state == OS_SIGNED_IN)
|
||||
request->addParameter("token", m_token);
|
||||
if (action.size() > 0)
|
||||
request->addParameter("action", action);
|
||||
} // setUserDetails
|
||||
|
||||
// ========================================================================
|
||||
CurrentUser::CurrentUser()
|
||||
CurrentUser::CurrentUser(const XMLNode *player)
|
||||
: PlayerProfile(player)
|
||||
{
|
||||
m_state = US_SIGNED_OUT;
|
||||
m_online_state = OS_SIGNED_OUT;
|
||||
m_token = "";
|
||||
m_save_session = false;
|
||||
m_profile = NULL;
|
||||
} // CurrentUser
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
CurrentUser::CurrentUser(const core::stringw &name, bool is_guest)
|
||||
: PlayerProfile(name, is_guest)
|
||||
{
|
||||
m_online_state = OS_SIGNED_OUT;
|
||||
m_token = "";
|
||||
m_save_session = false;
|
||||
m_profile = NULL;
|
||||
|
||||
} // CurrentUser
|
||||
// ------------------------------------------------------------------------
|
||||
/** Request a login using the saved credentials of the user.
|
||||
*/
|
||||
void CurrentUser::requestSavedSession()
|
||||
{
|
||||
SignInRequest * request = NULL;
|
||||
const PlayerProfile *cp = PlayerManager::getCurrentPlayer();
|
||||
if (m_state == US_SIGNED_OUT && cp->hasSavedSession() )
|
||||
if (m_online_state == OS_SIGNED_OUT && hasSavedSession() )
|
||||
{
|
||||
request = new SignInRequest(true);
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action","saved-session");
|
||||
request->addParameter("userid", cp->getSavedUserId());
|
||||
request->addParameter("token", cp->getSavedToken());
|
||||
request->addParameter("action", "saved-session" );
|
||||
request->addParameter("userid", getSavedUserId());
|
||||
request->addParameter("token", getSavedToken() );
|
||||
request->queue();
|
||||
m_state = US_SIGNING_IN;
|
||||
m_online_state = OS_SIGNING_IN;
|
||||
}
|
||||
} // requestSavedSession
|
||||
|
||||
@ -110,7 +120,7 @@ namespace Online
|
||||
const core::stringw &password,
|
||||
bool save_session, bool request_now)
|
||||
{
|
||||
assert(m_state == US_SIGNED_OUT);
|
||||
assert(m_online_state == OS_SIGNED_OUT);
|
||||
m_save_session = save_session;
|
||||
SignInRequest * request = new SignInRequest(false);
|
||||
request->setServerURL("client-user.php");
|
||||
@ -121,7 +131,7 @@ namespace Online
|
||||
if (request_now)
|
||||
{
|
||||
request->queue();
|
||||
m_state = US_SIGNING_IN;
|
||||
m_online_state = OS_SIGNING_IN;
|
||||
}
|
||||
return request;
|
||||
} // requestSignIn
|
||||
@ -131,7 +141,7 @@ namespace Online
|
||||
*/
|
||||
void CurrentUser::SignInRequest::callback()
|
||||
{
|
||||
PlayerManager::getCurrentUser()->signIn(isSuccess(), getXMLData());
|
||||
PlayerManager::getCurrentPlayer()->signIn(isSuccess(), getXMLData());
|
||||
GUIEngine::Screen *screen = GUIEngine::getCurrentScreen();
|
||||
LoginScreen *login = dynamic_cast<LoginScreen*>(screen);
|
||||
if(login)
|
||||
@ -162,11 +172,10 @@ namespace Online
|
||||
int userid_fetched = input->get("userid", &userid);
|
||||
m_profile = new OnlineProfile(userid, username, true);
|
||||
assert(token_fetched && username_fetched && userid_fetched);
|
||||
m_state = US_SIGNED_IN;
|
||||
if(saveSession())
|
||||
m_online_state = OS_SIGNED_IN;
|
||||
if(doSaveSession())
|
||||
{
|
||||
PlayerManager::getCurrentPlayer()->saveSession(getID(),
|
||||
getToken() );
|
||||
saveSession(getOnlineId(), getToken() );
|
||||
}
|
||||
ProfileManager::get()->addPersistent(m_profile);
|
||||
std::string achieved_string("");
|
||||
@ -180,27 +189,27 @@ namespace Online
|
||||
} // if success
|
||||
else
|
||||
{
|
||||
m_state = US_SIGNED_OUT;
|
||||
m_online_state = OS_SIGNED_OUT;
|
||||
}
|
||||
} // signIn
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void CurrentUser::requestSignOut()
|
||||
{
|
||||
assert(m_state == US_SIGNED_IN || m_state == US_GUEST);
|
||||
assert(m_online_state == OS_SIGNED_IN || m_online_state == OS_GUEST);
|
||||
SignOutRequest * request = new SignOutRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action","disconnect");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("userid", getID());
|
||||
request->addParameter("userid", getOnlineId());
|
||||
request->queue();
|
||||
m_state = US_SIGNING_OUT;
|
||||
m_online_state = OS_SIGNING_OUT;
|
||||
} // requestSignOut
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void CurrentUser::SignOutRequest::callback()
|
||||
{
|
||||
PlayerManager::getCurrentUser()->signOut(isSuccess(), getXMLData());
|
||||
PlayerManager::getCurrentPlayer()->signOut(isSuccess(), getXMLData());
|
||||
} // SignOutRequest::callback
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -215,7 +224,7 @@ namespace Online
|
||||
m_token = "";
|
||||
ProfileManager::get()->clearPersistent();
|
||||
m_profile = NULL;
|
||||
m_state = US_SIGNED_OUT;
|
||||
m_online_state = OS_SIGNED_OUT;
|
||||
PlayerManager::getCurrentPlayer()->clearSession();
|
||||
} // signOut
|
||||
|
||||
@ -225,12 +234,12 @@ namespace Online
|
||||
*/
|
||||
void CurrentUser::requestPoll() const
|
||||
{
|
||||
assert(m_state == US_SIGNED_IN);
|
||||
assert(m_online_state == OS_SIGNED_IN);
|
||||
CurrentUser::PollRequest * request = new CurrentUser::PollRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "poll");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("userid", getID());
|
||||
request->addParameter("userid", getOnlineId());
|
||||
request->queue();
|
||||
} // requestPoll()
|
||||
|
||||
@ -242,9 +251,9 @@ namespace Online
|
||||
{
|
||||
if(isSuccess())
|
||||
{
|
||||
if (!PlayerManager::getCurrentUser()->isRegisteredUser())
|
||||
if (!PlayerManager::getCurrentPlayer()->isLoggedIn())
|
||||
return;
|
||||
if (PlayerManager::getCurrentUser()->getProfile()->hasFetchedFriends())
|
||||
if (PlayerManager::getCurrentPlayer()->getProfile()->hasFetchedFriends())
|
||||
{
|
||||
std::string online_friends_string("");
|
||||
if(getXMLData()->get("online", &online_friends_string) == 1)
|
||||
@ -253,7 +262,7 @@ namespace Online
|
||||
StringUtils::splitToUInt(online_friends_string, ' ');
|
||||
bool went_offline = false;
|
||||
std::vector<uint32_t> friends =
|
||||
PlayerManager::getCurrentUser()->getProfile()->getFriends();
|
||||
PlayerManager::getCurrentPlayer()->getProfile()->getFriends();
|
||||
std::vector<core::stringw> to_notify;
|
||||
for(unsigned int i = 0; i < friends.size(); ++i)
|
||||
{
|
||||
@ -329,7 +338,7 @@ namespace Online
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerManager::getCurrentUser()->getProfile()->fetchFriends();
|
||||
PlayerManager::getCurrentPlayer()->getProfile()->fetchFriends();
|
||||
}
|
||||
|
||||
int friend_request_count = 0;
|
||||
@ -376,14 +385,14 @@ namespace Online
|
||||
*/
|
||||
void CurrentUser::onSTKQuit() const
|
||||
{
|
||||
if(isRegisteredUser())
|
||||
if(isLoggedIn())
|
||||
{
|
||||
HTTPRequest * request =
|
||||
new HTTPRequest(true, RequestManager::HTTP_MAX_PRIORITY);
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "client-quit");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("userid", getID());
|
||||
request->addParameter("userid", getOnlineId());
|
||||
request->queue();
|
||||
}
|
||||
}
|
||||
@ -391,14 +400,14 @@ namespace Online
|
||||
// ------------------------------------------------------------------------
|
||||
/** \return the online id, or 0 if the user is not signed in.
|
||||
*/
|
||||
uint32_t CurrentUser::getID() const
|
||||
uint32_t CurrentUser::getOnlineId() const
|
||||
{
|
||||
if((m_state == US_SIGNED_IN ))
|
||||
if((m_online_state == OS_SIGNED_IN ))
|
||||
{
|
||||
assert(m_profile != NULL);
|
||||
return m_profile->getID();
|
||||
}
|
||||
return 0;
|
||||
} // getID
|
||||
} // getOnlineId
|
||||
|
||||
} // namespace Online
|
||||
|
@ -19,12 +19,12 @@
|
||||
#ifndef HEADER_CURRENT_ONLINE_USER_HPP
|
||||
#define HEADER_CURRENT_ONLINE_USER_HPP
|
||||
|
||||
#include "config/player_profile.hpp"
|
||||
#include "online/http_request.hpp"
|
||||
#include "online/online_profile.hpp"
|
||||
#include "online/request_manager.hpp"
|
||||
#include "online/server.hpp"
|
||||
#include "online/xml_request.hpp"
|
||||
#include "utils/leak_check.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
@ -46,10 +46,8 @@ namespace Online
|
||||
* \brief Class that represents an online registered user
|
||||
* \ingroup online
|
||||
*/
|
||||
class CurrentUser
|
||||
class CurrentUser : public PlayerProfile
|
||||
{
|
||||
private:
|
||||
LEAK_CHECK()
|
||||
public:
|
||||
// ----------------------------------------------------------------
|
||||
class SignInRequest : public XMLRequest
|
||||
@ -80,11 +78,14 @@ namespace Online
|
||||
bool m_save_session;
|
||||
OnlineProfile *m_profile;
|
||||
|
||||
bool saveSession() const { return m_save_session; }
|
||||
/** The state of the player (logged in, logging in, ...) */
|
||||
PlayerProfile::OnlineState m_online_state;
|
||||
|
||||
bool doSaveSession() const { return m_save_session; }
|
||||
|
||||
|
||||
void signIn (bool success, const XMLNode * input);
|
||||
void signOut (bool success, const XMLNode * input);
|
||||
virtual void signIn(bool success, const XMLNode * input);
|
||||
virtual 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
|
||||
@ -95,26 +96,31 @@ namespace Online
|
||||
// windows only (where it works).
|
||||
#ifdef WIN32
|
||||
friend class PlayerManager;
|
||||
private:
|
||||
public:
|
||||
#else
|
||||
public:
|
||||
#endif
|
||||
uint32_t getID() const;
|
||||
void setUserDetails(HTTPRequest *request,
|
||||
const std::string &action,
|
||||
const std::string &php_script = "");
|
||||
bool isRegisteredUser() const { return m_state == US_SIGNED_IN; }
|
||||
/** Returns the user state. */
|
||||
enum UserState
|
||||
virtual uint32_t getOnlineId() const;
|
||||
virtual void setUserDetails(Online::HTTPRequest *request,
|
||||
const std::string &action,
|
||||
const std::string &php_script = "");
|
||||
|
||||
virtual void requestPoll() const;
|
||||
virtual void onSTKQuit() const;
|
||||
// ----------------------------------------------------------------
|
||||
/** Returns if this user is logged in. */
|
||||
virtual bool isLoggedIn() const
|
||||
{
|
||||
US_SIGNED_OUT = 0,
|
||||
US_SIGNED_IN,
|
||||
US_GUEST,
|
||||
US_SIGNING_IN,
|
||||
US_SIGNING_OUT
|
||||
};
|
||||
UserState m_state;
|
||||
const UserState getUserState() const { return m_state; }
|
||||
return m_online_state == PlayerProfile::OS_SIGNED_IN;
|
||||
} // isLoggedIn
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
/** The online state of the player (i.e. logged out, logging in,
|
||||
* logged in, ...). */
|
||||
PlayerProfile::OnlineState getOnlineState() const
|
||||
{
|
||||
return m_online_state;
|
||||
} // getOnlineState
|
||||
// ----------------------------------------------------------------
|
||||
/** Returns a pointer to the profile associated with the current
|
||||
* user. */
|
||||
@ -122,20 +128,17 @@ namespace Online
|
||||
// ----------------------------------------------------------------
|
||||
/** 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);
|
||||
virtual void requestSavedSession();
|
||||
virtual void requestSignOut();
|
||||
virtual SignInRequest *requestSignIn(const irr::core::stringw &username,
|
||||
const irr::core::stringw &password,
|
||||
bool save_session,
|
||||
bool request_now = true);
|
||||
|
||||
public:
|
||||
CurrentUser();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
CurrentUser(const XMLNode *player);
|
||||
CurrentUser(const core::stringw &name, bool is_guest = false);
|
||||
virtual ~CurrentUser() {};
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
}; // class CurrentUser
|
||||
|
@ -146,13 +146,13 @@ void MainMenuScreen::init()
|
||||
void MainMenuScreen::onUpdate(float delta)
|
||||
|
||||
{
|
||||
if(PlayerManager::getCurrentOnlineState() == PlayerManager::OS_GUEST ||
|
||||
PlayerManager::getCurrentOnlineState() == PlayerManager::OS_SIGNED_IN)
|
||||
if(PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_GUEST ||
|
||||
PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN)
|
||||
{
|
||||
m_online->setActivated();
|
||||
m_online->setLabel( _("Online"));
|
||||
}
|
||||
else if (PlayerManager::getCurrentOnlineState() == PlayerManager::OS_SIGNED_OUT)
|
||||
else if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_OUT)
|
||||
{
|
||||
m_online->setActivated();
|
||||
m_online->setLabel( _("Login" ));
|
||||
|
@ -56,7 +56,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
|
||||
|
||||
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
|
||||
{
|
||||
m_recorded_state = PlayerManager::OS_SIGNED_OUT;
|
||||
m_recorded_state = PlayerProfile::OS_SIGNED_OUT;
|
||||
} // OnlineScreen
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -98,7 +98,7 @@ void OnlineScreen::loadedFromFile()
|
||||
*/
|
||||
bool OnlineScreen::hasStateChanged()
|
||||
{
|
||||
PlayerManager::OnlineState previous_state = m_recorded_state;
|
||||
PlayerProfile::OnlineState previous_state = m_recorded_state;
|
||||
m_recorded_state = PlayerManager::getCurrentOnlineState();
|
||||
if (previous_state != m_recorded_state)
|
||||
return true;
|
||||
@ -112,9 +112,9 @@ void OnlineScreen::beforeAddingWidget()
|
||||
m_bottom_menu_widget->setVisible(true);
|
||||
m_top_menu_widget->setVisible(true);
|
||||
hasStateChanged();
|
||||
if (m_recorded_state == PlayerManager::OS_SIGNED_OUT ||
|
||||
m_recorded_state == PlayerManager::OS_SIGNING_IN ||
|
||||
m_recorded_state == PlayerManager::OS_SIGNING_OUT)
|
||||
if (m_recorded_state == PlayerProfile::OS_SIGNED_OUT ||
|
||||
m_recorded_state == PlayerProfile::OS_SIGNING_IN ||
|
||||
m_recorded_state == PlayerProfile::OS_SIGNING_OUT)
|
||||
{
|
||||
m_quick_play_widget->setDeactivated();
|
||||
m_find_server_widget->setDeactivated();
|
||||
@ -122,7 +122,7 @@ void OnlineScreen::beforeAddingWidget()
|
||||
m_sign_out_widget->setVisible(false);
|
||||
m_profile_widget->setVisible(false);
|
||||
}
|
||||
else if (m_recorded_state == PlayerManager::OS_GUEST)
|
||||
else if (m_recorded_state == PlayerProfile::OS_GUEST)
|
||||
{
|
||||
m_find_server_widget->setDeactivated();
|
||||
m_create_server_widget->setDeactivated();
|
||||
@ -151,11 +151,11 @@ void OnlineScreen::onUpdate(float delta)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_recorded_state == PlayerManager::OS_SIGNING_IN)
|
||||
if (m_recorded_state == PlayerProfile::OS_SIGNING_IN)
|
||||
{
|
||||
m_online_status_widget->setText(Messages::signingIn(), false);
|
||||
}
|
||||
else if (m_recorded_state == PlayerManager::OS_SIGNING_OUT)
|
||||
else if (m_recorded_state == PlayerProfile::OS_SIGNING_OUT)
|
||||
{
|
||||
m_online_status_widget->setText(Messages::signingOut(), false);
|
||||
}
|
||||
@ -259,7 +259,7 @@ void OnlineScreen::tearDown()
|
||||
*/
|
||||
void OnlineScreen::setInitialFocus()
|
||||
{
|
||||
if (m_recorded_state == PlayerManager::OS_SIGNED_IN)
|
||||
if (m_recorded_state == PlayerProfile::OS_SIGNED_IN)
|
||||
m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
else
|
||||
m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
@ -54,7 +54,7 @@ private:
|
||||
GUIEngine::IconButtonWidget * m_profile_widget;
|
||||
GUIEngine::IconButtonWidget * m_sign_out_widget;
|
||||
|
||||
PlayerManager::OnlineState m_recorded_state;
|
||||
PlayerProfile::OnlineState m_recorded_state;
|
||||
|
||||
bool hasStateChanged();
|
||||
void setInitialFocus();
|
||||
|
Loading…
x
Reference in New Issue
Block a user