Automatically signing in, is now very smooth.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13292 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-19 22:41:54 +00:00
parent 54333c17b0
commit 8c9834a236
5 changed files with 55 additions and 88 deletions

View File

@ -75,43 +75,6 @@ namespace Online{
m_save_session = false;
}
// ============================================================================
bool CurrentUser::trySavedSession()
{
if (m_state == SIGNED_IN) return true;
bool success = false;
if(UserConfigParams::m_saved_session)
{
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action",std::string("saved-session"));
connector->setParameter("userid", UserConfigParams::m_saved_user);
connector->setParameter("token", UserConfigParams::m_saved_token.c_str());
const XMLNode * result = connector->getXMLFromPage();
std::string rec_success = "";
std::string info;
if(result->get("success", &rec_success))
{
if (rec_success =="yes")
{
int token_fetched = result->get("token", &m_token);
int username_fetched = result->get("username", &m_name);
int userid_fetched = result->get("userid", &m_id);
assert(token_fetched && username_fetched && userid_fetched);
UserConfigParams::m_saved_token = m_token;
m_state = SIGNED_IN;
success = true;
}
result->get("info", &info);
}
else
{
Log::error("trySavedSession","%s",
_("Unable to connect to the server. Check your internet connection or try again later."));
}
}
return success;
}
// ============================================================================
// Register
bool CurrentUser::signUp( const irr::core::stringw &username,
@ -143,12 +106,31 @@ namespace Online{
return success;
}
// ============================================================================
CurrentUser::SignInRequest * CurrentUser::requestSavedSession()
{
CurrentUser::SignInRequest * request = NULL;
if(m_state != SIGNED_IN && UserConfigParams::m_saved_session)
{
request = new CurrentUser::SignInRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
request->setParameter("action",std::string("saved-session"));
request->setParameter("userid", UserConfigParams::m_saved_user);
request->setParameter("token", UserConfigParams::m_saved_token.c_str());
if(!HTTPManager::get()->addRequest(request))
{
assert(false);
}
m_state = SIGNING_IN;
}
return request;
}
// ============================================================================
CurrentUser::SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session)
CurrentUser::SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session)
{
assert(m_state == SIGNED_OUT);
m_save_session = save_session;
@ -185,6 +167,7 @@ namespace Online{
UserConfigParams::m_saved_user = m_id;
UserConfigParams::m_saved_token = m_token;
UserConfigParams::m_saved_session = true;
m_save_session = false;
}
}
xml->get("info", &info);

View File

@ -72,8 +72,8 @@ namespace Online{
static CurrentUser* acquire();
static void release();
bool trySavedSession();
// Login
SignInRequest * requestSavedSession();
SignInRequest * requestSignIn( const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session);
@ -102,7 +102,6 @@ namespace Online{
bool isGuest() const { return m_state == GUEST; }
bool isSigningIn() const { return m_state == SIGNING_IN; }
UserState getUserState() {return m_state;}
void onHTTPCallback(HTTPRequest * finished_request);
}; // class CurrentUser

View File

@ -1,41 +0,0 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HTTP_LISTENER_HPP
#define HTTP_LISTENER_HPP
#include <string>
#include <curl/curl.h>
#include <irrString.h>
namespace Online{
class HTTPRequest;
class HTTPListener
{
public :
virtual ~HTTPListener() {}
virtual void onHTTPCallback(HTTPRequest * finished_request) {};
}; //class HTTPListener
} // namespace Online
#endif // HTTP_LISTENER_HPP
/*EOF*/

View File

@ -52,12 +52,19 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
{
m_recorded_state = CurrentUser::SIGNED_OUT;
CurrentUser::acquire()->trySavedSession();
m_sign_in_request = CurrentUser::acquire()->requestSavedSession();
CurrentUser::release();
} // OnlineScreen
// ----------------------------------------------------------------------------
OnlineScreen::~OnlineScreen()
{
delete m_sign_in_request;
}
// ----------------------------------------------------------------------------
void OnlineScreen::loadedFromFile()
{
//Box ? FIXME
@ -145,13 +152,30 @@ void OnlineScreen::init()
// ----------------------------------------------------------------------------
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
if (hasStateChanged())
GUIEngine::reshowCurrentScreen();
if (m_recorded_state == CurrentUser::SIGNING_IN)
{
m_load_timer += delta;
m_online_status_widget->setText(Messages::signingIn(m_load_timer), false);
}
if (hasStateChanged())
GUIEngine::reshowCurrentScreen();
if(m_sign_in_request != NULL)
{
if(m_sign_in_request->isDone())
{
if(m_sign_in_request->isSuccess())
{
new MessageDialog(_("Automatically signed in."));
}
else
{
sfx_manager->quickSound( "anvil" );
new MessageDialog(m_sign_in_request->getInfo());
}
delete m_sign_in_request;
m_sign_in_request = NULL;
}
}
} // onUpdate
// ----------------------------------------------------------------------------
@ -249,8 +273,8 @@ void OnlineScreen::setInitialFocus()
// ----------------------------------------------------------------------------
void OnlineScreen::onDialogClose()
{
/*if (hasStateChanged())
if (hasStateChanged())
GUIEngine::reshowCurrentScreen();
else*/
else
setInitialFocus();
} // onDialogClose()

View File

@ -37,6 +37,7 @@ private:
friend class GUIEngine::ScreenSingleton<OnlineScreen>;
OnlineScreen();
~OnlineScreen();
GUIEngine::RibbonWidget * m_top_menu_widget;
GUIEngine::IconButtonWidget * m_quick_play_widget;
@ -53,6 +54,7 @@ private:
Online::CurrentUser::UserState m_recorded_state;
float m_load_timer;
Online::CurrentUser::SignInRequest * m_sign_in_request;
/** \brief Checks if the recorded state differs from the actual state and sets it. */
bool hasStateChanged();