From 3463a01e8561063f9db81e0b0f7925723d986a64 Mon Sep 17 00:00:00 2001 From: unitraxx Date: Sat, 13 Jul 2013 15:59:27 +0000 Subject: [PATCH] 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 --- src/config/user_config.hpp | 49 +++++++++++++++++++++------- src/online/current_online_user.cpp | 51 ++++++++++++++++++++++++++++-- src/online/current_online_user.hpp | 3 ++ 3 files changed, 88 insertions(+), 15 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 597061976..548c938be 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -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, diff --git a/src/online/current_online_user.cpp b/src/online/current_online_user.cpp index e85322e5a..e11578f31 100644 --- a/src/online/current_online_user.cpp +++ b/src/online/current_online_user.cpp @@ -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); } diff --git a/src/online/current_online_user.hpp b/src/online/current_online_user.hpp index 3b0c81ea2..27c4df1c0 100644 --- a/src/online/current_online_user.hpp +++ b/src/online/current_online_user.hpp @@ -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,