Removed m_save_session, some code cleanup.
This commit is contained in:
parent
1472e69c66
commit
498c6b46db
@ -121,7 +121,7 @@ public:
|
||||
/** 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;
|
||||
const std::string &php_script = "") const = 0;
|
||||
virtual uint32_t getOnlineId() const = 0;
|
||||
virtual PlayerProfile::OnlineState getOnlineState() const = 0;
|
||||
virtual Online::OnlineProfile* getProfile() const = 0;
|
||||
|
@ -52,8 +52,8 @@ namespace Online
|
||||
* \param action If not empty, the action to be set.
|
||||
*/
|
||||
void OnlinePlayerProfile::setUserDetails(HTTPRequest *request,
|
||||
const std::string &action,
|
||||
const std::string &php_script)
|
||||
const std::string &action,
|
||||
const std::string &php_script) const
|
||||
{
|
||||
if (php_script.size()>0)
|
||||
request->setServerURL(php_script);
|
||||
@ -74,7 +74,6 @@ namespace Online
|
||||
{
|
||||
m_online_state = OS_SIGNED_OUT;
|
||||
m_token = "";
|
||||
m_save_session = false;
|
||||
m_profile = NULL;
|
||||
} // OnlinePlayerProfile
|
||||
|
||||
@ -84,7 +83,6 @@ namespace Online
|
||||
{
|
||||
m_online_state = OS_SIGNED_OUT;
|
||||
m_token = "";
|
||||
m_save_session = false;
|
||||
m_profile = NULL;
|
||||
|
||||
} // OnlinePlayerProfile
|
||||
@ -97,10 +95,11 @@ namespace Online
|
||||
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", getSavedUserId());
|
||||
request->addParameter("token", getSavedToken() );
|
||||
setUserDetails(request, "saved-session");
|
||||
// The userid must be taken from the saved data,
|
||||
// setUserDetails takes it from current data.
|
||||
request->addParameter("userid", getSavedUserId());
|
||||
request->addParameter("token", getSavedToken() );
|
||||
request->queue();
|
||||
m_online_state = OS_SIGNING_IN;
|
||||
}
|
||||
@ -110,23 +109,20 @@ namespace Online
|
||||
/** 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.
|
||||
*/
|
||||
OnlinePlayerProfile::SignInRequest*
|
||||
OnlinePlayerProfile::requestSignIn(const core::stringw &username,
|
||||
const core::stringw &password)
|
||||
const core::stringw &password)
|
||||
{
|
||||
assert(m_online_state == OS_SIGNED_OUT);
|
||||
m_save_session = UserConfigParams::m_remember_user;
|
||||
SignInRequest * request = new SignInRequest(false);
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action","connect");
|
||||
request->addParameter("username",username);
|
||||
request->addParameter("password",password);
|
||||
request->addParameter("save-session", m_save_session);
|
||||
// We can't use setUserDetail here, since there is no token yet
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action","connect");
|
||||
request->addParameter("username",username);
|
||||
request->addParameter("password",password);
|
||||
request->addParameter("save-session",
|
||||
UserConfigParams::m_remember_user);
|
||||
request->queue();
|
||||
m_online_state = OS_SIGNING_IN;
|
||||
return request;
|
||||
@ -166,11 +162,11 @@ namespace Online
|
||||
int username_fetched = input->get("username", &username);
|
||||
uint32_t userid(0);
|
||||
int userid_fetched = input->get("userid", &userid);
|
||||
PlayerManager::getCurrentPlayer()->setLastOnlineName(username);
|
||||
setLastOnlineName(username);
|
||||
m_profile = new OnlineProfile(userid, username, true);
|
||||
assert(token_fetched && username_fetched && userid_fetched);
|
||||
m_online_state = OS_SIGNED_IN;
|
||||
if(doSaveSession())
|
||||
if(UserConfigParams::m_remember_user)
|
||||
{
|
||||
saveSession(getOnlineId(), getToken() );
|
||||
}
|
||||
@ -272,10 +268,7 @@ namespace Online
|
||||
{
|
||||
assert(m_online_state == OS_SIGNED_IN);
|
||||
OnlinePlayerProfile::PollRequest * request = new OnlinePlayerProfile::PollRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "poll");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("userid", getOnlineId());
|
||||
setUserDetails(request, "poll");
|
||||
request->queue();
|
||||
} // requestPoll()
|
||||
|
||||
|
@ -67,36 +67,18 @@ namespace Online
|
||||
|
||||
private:
|
||||
std::string m_token;
|
||||
bool m_save_session;
|
||||
OnlineProfile *m_profile;
|
||||
|
||||
/** The state of the player (logged in, logging in, ...) */
|
||||
PlayerProfile::OnlineState m_online_state;
|
||||
|
||||
bool doSaveSession() const { return m_save_session; }
|
||||
|
||||
|
||||
virtual void signIn(bool success, const XMLNode * input);
|
||||
virtual void signOut(bool success, const XMLNode * input,
|
||||
const irr::core::stringw &info);
|
||||
|
||||
// For now declare functions that will become part of PlayerManager
|
||||
// or Playerprofile to be private, and give only PlayerManager
|
||||
// access to them. FIXME
|
||||
|
||||
// FIXME: This apparently does not compile on linux :(
|
||||
// So for now (while this is needed) I'll only add this on
|
||||
// windows only (where it works).
|
||||
#ifdef WIN32
|
||||
friend class PlayerManager;
|
||||
public:
|
||||
#else
|
||||
public:
|
||||
#endif
|
||||
virtual uint32_t getOnlineId() const;
|
||||
virtual void setUserDetails(Online::HTTPRequest *request,
|
||||
const std::string &action,
|
||||
const std::string &php_script = "");
|
||||
const std::string &php_script = "") const;
|
||||
|
||||
virtual void requestPoll() const;
|
||||
// ----------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user