Remember session (without GUI) and starting to integrate online-multiplayer and addons networking code. (Limited to config file for now.)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13202 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-13 15:59:27 +00:00
parent 200127102d
commit 3463a01e85
3 changed files with 88 additions and 15 deletions

View File

@ -603,16 +603,48 @@ namespace UserConfigParams
PARAM_DEFAULT( WStringUserConfigParam(L"", "default_player",
"Which player to use by default (if empty, will prompt)") );
// ---- Online multiplayer related
// ---- Internet related
PARAM_PREFIX IntUserConfigParam m_internet_status
PARAM_DEFAULT( IntUserConfigParam(0, "enable_internet",
"Status of internet: 0 user "
"wasn't asked, 1: allowed, 2: "
"not allowed") );
// ---- Online gameplay related
PARAM_PREFIX GroupUserConfigParam m_online_group
PARAM_DEFAULT( GroupUserConfigParam("OnlinePlay",
"Everything related to online play.") );
PARAM_PREFIX StringUserConfigParam m_server_multiplayer
PARAM_DEFAULT( StringUserConfigParam("http://api.stkaddons.net/",
"server_multiplayer",
"The server used for online multiplayer."));
PARAM_DEFAULT( StringUserConfigParam( "http://api.stkaddons.net/",
"server_multiplayer",
&m_online_group,
"The server used for online multiplayer."));
PARAM_PREFIX BoolUserConfigParam m_saved_session
PARAM_DEFAULT( BoolUserConfigParam( false,
"saved_session",
&m_online_group,
"Is there a saved session?") );
PARAM_PREFIX IntUserConfigParam m_saved_user
PARAM_DEFAULT( IntUserConfigParam( 0,
"saved_user",
&m_online_group,
"User ID of the saved session.") );
PARAM_PREFIX StringUserConfigParam m_saved_token
PARAM_DEFAULT( StringUserConfigParam( "",
"saved_token",
&m_online_group,
"Token of the saved session.") );
// ---- Addon server related entries
PARAM_PREFIX GroupUserConfigParam m_addon_group
PARAM_DEFAULT( GroupUserConfigParam("AddonAndNews",
PARAM_DEFAULT( GroupUserConfigParam("AddonAndNews",
"Addon and news related settings") );
PARAM_PREFIX StringUserConfigParam m_server_addons
@ -643,13 +675,6 @@ namespace UserConfigParams
"Don't show important message "
"with this or a lower id again") );
PARAM_PREFIX IntUserConfigParam m_internet_status
PARAM_DEFAULT( IntUserConfigParam(0, "enable_internet",
&m_addon_group,
"Status of internet: 0 user "
"wasn't asked, 1: allowed, 2: "
"not allowed") );
PARAM_PREFIX TimeUserConfigParam m_addons_last_updated
PARAM_DEFAULT( TimeUserConfigParam(0, "addon_last_updated",
&m_addon_group,

View File

@ -25,6 +25,7 @@
#include "online/http_connector.hpp"
#include "config/user_config.hpp"
#include "utils/translation.hpp"
#include "utils/log.hpp"
static CurrentOnlineUser* user_singleton = NULL;
@ -42,8 +43,6 @@ void CurrentOnlineUser::deallocate()
} // deallocate
// ============================================================================
CurrentOnlineUser::CurrentOnlineUser(){
m_is_signed_in = false;
m_is_guest = false;
@ -53,6 +52,42 @@ CurrentOnlineUser::CurrentOnlineUser(){
m_token = "";
}
// ============================================================================
bool CurrentOnlineUser::trySavedSession()
{
assert(m_is_signed_in == false);
if(UserConfigParams::m_saved_session)
{
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action",std::string("validate"));
connector->setParameter("userid", UserConfigParams::m_saved_user);
connector->setParameter("token", UserConfigParams::m_saved_token);
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);
m_is_signed_in = true;
m_is_guest = false;
}
result->get("info", &info);
Log::info("trySavedSession","%s",info);
}
else
{
Log::error("trySavedSession","%s",
_("Unable to connect to the server. Check your internet connection or try again later."));
}
}
return m_is_signed_in;
}
// ============================================================================
// Register
bool CurrentOnlineUser::signUp( const irr::core::stringw &username,
@ -89,6 +124,7 @@ bool CurrentOnlineUser::signUp( const irr::core::stringw &username,
bool CurrentOnlineUser::signIn( const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session,
irr::core::stringw &info)
{
assert(m_is_signed_in == false);
@ -108,6 +144,12 @@ bool CurrentOnlineUser::signIn( const irr::core::stringw &username,
assert(token_fetched && username_fetched && userid_fetched);
m_is_signed_in = true;
m_is_guest = false;
if(save_session)
{
UserConfigParams::m_saved_user = m_id;
UserConfigParams::m_saved_token = m_token;
UserConfigParams::m_saved_session = true;
}
}
result->get("info", &info);
}
@ -125,7 +167,7 @@ bool CurrentOnlineUser::createServer( const irr::core::stringw &name,
int max_players,
irr::core::stringw &info)
{
assert(m_is_signed_in && !m_is_guest && !m_is_server_host);
assert(m_is_signed_in && !m_is_guest);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action", std::string("create_server"));
connector->setParameter("token", m_token);
@ -172,6 +214,9 @@ bool CurrentOnlineUser::signOut(irr::core::stringw &info){
m_id = 0;
m_is_signed_in = false;
m_is_guest = false;
UserConfigParams::m_saved_user = 0;
UserConfigParams::m_saved_token = "";
UserConfigParams::m_saved_session = false;
}
result->get("info", &info);
}

View File

@ -47,9 +47,12 @@ class CurrentOnlineUser : public OnlineUser
// singleton
static CurrentOnlineUser* get();
static void deallocate();
bool trySavedSession();
// Login
bool signIn( const irr::core::stringw &username,
const irr::core::stringw &password,
bool save_session,
irr::core::stringw &info);
// Register
bool signUp( const irr::core::stringw &username,