diff --git a/sources.cmake b/sources.cmake index c9f8454a7..db63c1dbb 100644 --- a/sources.cmake +++ b/sources.cmake @@ -1,4 +1,4 @@ -# Generated by /home/gl3nn/repos/gsoc-stk-branch/update_file_list.sh. Do not edit this file manually. +# Generated by ./update_file_list.sh. Do not edit this file manually. set(STK_SOURCES src/addons/addon.cpp src/addons/addons_manager.cpp @@ -145,11 +145,13 @@ src/network/network_manager.cpp src/network/race_info_message.cpp src/network/race_result_message.cpp src/network/race_state.cpp -src/online/current_online_user.cpp +src/online/current_user.cpp src/online/http_connector.cpp -src/online/online_user.cpp +src/online/http_manager.cpp +src/online/request.cpp src/online/server.cpp src/online/servers_manager.cpp +src/online/user.cpp src/physics/btKart.cpp src/physics/btKartRaycast.cpp src/physics/btUprightConstraint.cpp @@ -414,11 +416,13 @@ src/network/race_start_message.hpp src/network/race_state.hpp src/network/remote_kart_info.hpp src/network/world_loaded_message.hpp -src/online/current_online_user.hpp +src/online/current_user.hpp src/online/http_connector.hpp -src/online/online_user.hpp +src/online/http_manager.hpp +src/online/request.hpp src/online/server.hpp src/online/servers_manager.hpp +src/online/user.hpp src/physics/btKart.hpp src/physics/btKartRaycast.hpp src/physics/btUprightConstraint.hpp diff --git a/src/online/current_online_user.cpp b/src/online/current_online_user.cpp deleted file mode 100644 index f75eee02f..000000000 --- a/src/online/current_online_user.cpp +++ /dev/null @@ -1,270 +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. - - -#include "online/current_online_user.hpp" - -#include -#include -#include -#include "online/http_connector.hpp" -#include "config/user_config.hpp" -#include "utils/translation.hpp" -#include "utils/log.hpp" - -static CurrentOnlineUser* user_singleton = NULL; - -CurrentOnlineUser* CurrentOnlineUser::get() -{ - if (user_singleton == NULL) - user_singleton = new CurrentOnlineUser(); - return user_singleton; -} // get - -void CurrentOnlineUser::deallocate() -{ - delete user_singleton; - user_singleton = NULL; -} // deallocate - -// ============================================================================ -CurrentOnlineUser::CurrentOnlineUser(){ - m_is_signed_in = false; - m_is_guest = false; - m_is_server_host = false; - m_id = 0; - m_name = ""; - m_token = ""; -} - -// ============================================================================ -bool CurrentOnlineUser::trySavedSession() -{ - if (m_is_signed_in) return true; - 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_is_signed_in = true; - m_is_guest = false; - } - result->get("info", &info); - Log::info("trySavedSession","%s",info.c_str()); - } - 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, - const irr::core::stringw &password, - const irr::core::stringw &password_ver, - const irr::core::stringw &email, - bool terms, - irr::core::stringw &info) -{ - assert(m_is_signed_in == false); - HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); - connector->setParameter("action",std::string("register")); - connector->setParameter("username",username); - connector->setParameter("password",password); - - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success; - - bool success = false; - if(result->get("success", &rec_success)) - { - success = (rec_success == "yes"); - assert(result->get("info", &info)); - } - else - { - info = _("Unable to connect to the server. Check your internet connection or try again later."); - } - return success; -} - - -// ============================================================================ - -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); - HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); - connector->setParameter("action",std::string("connect")); - connector->setParameter("username",username); - connector->setParameter("password",password); - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success = ""; - 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; - if(save_session) - { - UserConfigParams::m_saved_user = m_id; - UserConfigParams::m_saved_token = m_token; - UserConfigParams::m_saved_session = true; - } - } - result->get("info", &info); - } - else - { - info = _("Unable to connect to the server. Check your internet connection or try again later."); - } - - return m_is_signed_in; -} - -// ============================================================================ - -bool CurrentOnlineUser::createServer( const irr::core::stringw &name, - int max_players, - irr::core::stringw &info) -{ - 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); - connector->setParameter("userid", m_id); - connector->setParameter("name", name); - connector->setParameter("max_players", max_players); - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success = ""; - if(result->get("success", &rec_success)) - { - if (rec_success =="yes") - { - // FIXME - m_is_server_host = true; - } - result->get("info", &info); - } - else - { - info = _("Unable to connect to the server. Check your internet connection or try again later."); - } - - return m_is_server_host; -} - - -// ============================================================================ -bool CurrentOnlineUser::signOut(irr::core::stringw &info){ - assert(m_is_signed_in == true); - HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); - connector->setParameter("action",std::string("disconnect")); - connector->setParameter("token",m_token); - connector->setParameter("userid",m_id); - - - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success = ""; - if(result->get("success", &rec_success)) - { - if (rec_success =="yes") - { - m_token = ""; - m_name = ""; - 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); - } - else - { - info = _("Unable to connect to the server. Check your internet connection or try again later."); - } - return !m_is_signed_in; -} - -// ============================================================================ - -bool CurrentOnlineUser::requestJoin(uint32_t server_id, irr::core::stringw &info){ - assert(m_is_signed_in == true); - HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php"); - connector->setParameter("action",std::string("request-connection")); - connector->setParameter("token", m_token); - connector->setParameter("id", m_id); - connector->setParameter("server_id", server_id); - bool success = false; - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success = ""; - if(result->get("success", &rec_success)) - { - if (rec_success =="yes") - { - success = true; - } - else - { - success = false; - } - result->get("info", &info); - } - else - { - info = _("Unable to connect to the server. Check your internet connection or try again later."); - } - return success; -} - -// ============================================================================ - -irr::core::stringw CurrentOnlineUser::getUserName() const -{ - if(m_is_signed_in) - return m_name; - else - return _("Currently not signed in"); -} diff --git a/src/online/current_online_user.hpp b/src/online/current_online_user.hpp deleted file mode 100644 index 27c4df1c0..000000000 --- a/src/online/current_online_user.hpp +++ /dev/null @@ -1,83 +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 HEADER_CURRENT_ONLINE_USER_HPP -#define HEADER_CURRENT_ONLINE_USER_HPP - -#include "online/online_user.hpp" -#include -#include -#include "utils/types.hpp" -#include "online/server.hpp" - - - -// ============================================================================ - -/** - * \brief Class that represents an online registered user - * \ingroup online - */ -class CurrentOnlineUser : public OnlineUser -{ - private: - - protected: - std::string m_token; - bool m_is_signed_in; - bool m_is_guest; - CurrentOnlineUser(); - - public: - // 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, - const irr::core::stringw &password, - const irr::core::stringw &password_ver, - const irr::core::stringw &email, - bool terms, - irr::core::stringw &info); - // Logout - Best to be followed by CurrentOnlineUser::deallocate - bool signOut( irr::core::stringw &info); - - bool createServer( const irr::core::stringw &name, - int max_players, - irr::core::stringw &info); - - bool requestJoin( uint32_t server_id, - irr::core::stringw &info); - - /** Returns the username if signed in. */ - irr::core::stringw getUserName() const; - bool isSignedIn(){ return m_is_signed_in; } - bool isGuest(){ return m_is_guest; } - -}; // class CurrentOnlineUser - -#endif - -/*EOF*/ diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp new file mode 100644 index 000000000..f6a3e7fdf --- /dev/null +++ b/src/online/current_user.cpp @@ -0,0 +1,279 @@ +// +// 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. + + +#include "online/current_user.hpp" + +#include +#include +#include +#include "online/http_connector.hpp" +#include "config/user_config.hpp" +#include "utils/translation.hpp" +#include "utils/log.hpp" + +namespace online{ + static CurrentUser* user_singleton = NULL; + + CurrentUser* CurrentUser::get() + { + if (user_singleton == NULL) + user_singleton = new CurrentUser(); + return user_singleton; + } // get + + void CurrentUser::deallocate() + { + delete user_singleton; + user_singleton = NULL; + } // deallocate + + // ============================================================================ + CurrentUser::CurrentUser(){ + m_is_signed_in = false; + m_is_guest = false; + m_is_server_host = false; + m_id = 0; + m_name = ""; + m_token = ""; + m_save_session = false; + } + + // ============================================================================ + bool CurrentUser::trySavedSession() + { + if (m_is_signed_in) return true; + 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_is_signed_in = true; + m_is_guest = false; + } + result->get("info", &info); + Log::info("trySavedSession","%s",info.c_str()); + } + 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 CurrentUser::signUp( const irr::core::stringw &username, + const irr::core::stringw &password, + const irr::core::stringw &password_ver, + const irr::core::stringw &email, + bool terms, + irr::core::stringw &info) + { + assert(m_is_signed_in == false); + HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + connector->setParameter("action",std::string("register")); + connector->setParameter("username",username); + connector->setParameter("password",password); + + const XMLNode * result = connector->getXMLFromPage(); + std::string rec_success; + + bool success = false; + if(result->get("success", &rec_success)) + { + success = (rec_success == "yes"); + assert(result->get("info", &info)); + } + else + { + info = _("Unable to connect to the server. Check your internet connection or try again later."); + } + return success; + } + + + // ============================================================================ + + XMLRequest * CurrentUser::signInRequest( const irr::core::stringw &username, + const irr::core::stringw &password, + bool save_session) + { + assert(m_is_signed_in == false); + m_save_session = save_session; + XMLRequest * request = new XMLRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action",std::string("connect")); + request->setParameter("username",username); + request->setParameter("password",password); + if(!HTTPManager::get()->addRequest(request)) + assert(false); + return request; + } + + bool CurrentUser::signIn(const XMLNode * input, irr::core::stringw &info) + { + std::string rec_success = ""; + if(input->get("success", &rec_success)) + { + if (rec_success =="yes") + { + int token_fetched = input->get("token", &m_token); + int username_fetched = input->get("username", &m_name); + int userid_fetched = input->get("userid", &m_id); + assert(token_fetched && username_fetched && userid_fetched); + m_is_signed_in = true; + m_is_guest = false; + if(m_save_session) + { + UserConfigParams::m_saved_user = m_id; + UserConfigParams::m_saved_token = m_token; + UserConfigParams::m_saved_session = true; + } + } + input->get("info", &info); + } + else + { + info = _("Unable to connect to the server. Check your internet connection or try again later."); + } + + return m_is_signed_in; + } + + // ============================================================================ + + bool CurrentUser::createServer( const irr::core::stringw &name, + int max_players, + irr::core::stringw &info) + { + 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); + connector->setParameter("userid", m_id); + connector->setParameter("name", name); + connector->setParameter("max_players", max_players); + const XMLNode * result = connector->getXMLFromPage(); + std::string rec_success = ""; + if(result->get("success", &rec_success)) + { + if (rec_success =="yes") + { + // FIXME + m_is_server_host = true; + } + result->get("info", &info); + } + else + { + info = _("Unable to connect to the server. Check your internet connection or try again later."); + } + + return m_is_server_host; + } + + + // ============================================================================ + bool CurrentUser::signOut(irr::core::stringw &info){ + assert(m_is_signed_in == true); + HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + connector->setParameter("action",std::string("disconnect")); + connector->setParameter("token",m_token); + connector->setParameter("userid",m_id); + + + const XMLNode * result = connector->getXMLFromPage(); + std::string rec_success = ""; + if(result->get("success", &rec_success)) + { + if (rec_success =="yes") + { + m_token = ""; + m_name = ""; + 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); + } + else + { + info = _("Unable to connect to the server. Check your internet connection or try again later."); + } + return !m_is_signed_in; + } + + // ============================================================================ + + bool CurrentUser::requestJoin(uint32_t server_id, irr::core::stringw &info){ + assert(m_is_signed_in == true); + HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php"); + connector->setParameter("action",std::string("request-connection")); + connector->setParameter("token", m_token); + connector->setParameter("id", m_id); + connector->setParameter("server_id", server_id); + bool success = false; + const XMLNode * result = connector->getXMLFromPage(); + std::string rec_success = ""; + if(result->get("success", &rec_success)) + { + if (rec_success =="yes") + { + success = true; + } + else + { + success = false; + } + result->get("info", &info); + } + else + { + info = _("Unable to connect to the server. Check your internet connection or try again later."); + } + return success; + } + + // ============================================================================ + + irr::core::stringw CurrentUser::getUserName() const + { + if(m_is_signed_in) + return m_name; + else + return _("Currently not signed in"); + } +} // namespace online diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp new file mode 100644 index 000000000..07bac1b3f --- /dev/null +++ b/src/online/current_user.hpp @@ -0,0 +1,87 @@ +// +// 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 HEADER_CURRENT_ONLINE_USER_HPP +#define HEADER_CURRENT_ONLINE_USER_HPP + +#include "online/user.hpp" +#include +#include +#include "utils/types.hpp" +#include "online/server.hpp" +#include "http_manager.hpp" + + +namespace online{ + // ============================================================================ + + /** + * \brief Class that represents an online registered user + * \ingroup online + */ + class CurrentUser : public User + { + + protected: + std::string m_token; + bool m_is_signed_in; + bool m_is_guest; + bool m_save_session; + CurrentUser(); + + public: + // singleton + static CurrentUser* get(); + static void deallocate(); + + bool trySavedSession(); + // Login + XMLRequest * signInRequest( const irr::core::stringw &username, + const irr::core::stringw &password, + bool save_session); + + bool signIn( const XMLNode * input, irr::core::stringw &info); + + // Register + bool signUp( const irr::core::stringw &username, + const irr::core::stringw &password, + const irr::core::stringw &password_ver, + const irr::core::stringw &email, + bool terms, + irr::core::stringw &info); + // Logout - Best to be followed by CurrentOnlineUser::deallocate + bool signOut( irr::core::stringw &info); + + bool createServer( const irr::core::stringw &name, + int max_players, + irr::core::stringw &info); + + bool requestJoin( uint32_t server_id, + irr::core::stringw &info); + + /** Returns the username if signed in. */ + irr::core::stringw getUserName() const; + bool isSignedIn(){ return m_is_signed_in; } + bool isGuest(){ return m_is_guest; } + + }; // class CurrentUser +} // namespace online + +#endif + +/*EOF*/ diff --git a/src/online/http_connector.cpp b/src/online/http_connector.cpp index 6637fa39e..832b2d5c9 100644 --- a/src/online/http_connector.cpp +++ b/src/online/http_connector.cpp @@ -1,6 +1,6 @@ // // SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013 SuperTuxKart-Team +// 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 diff --git a/src/online/http_connector.hpp b/src/online/http_connector.hpp index 0eecebb24..f221f7f06 100644 --- a/src/online/http_connector.hpp +++ b/src/online/http_connector.hpp @@ -1,6 +1,6 @@ // // SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013 SuperTuxKart-Team +// 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 diff --git a/src/online/http_manager.cpp b/src/online/http_manager.cpp new file mode 100644 index 000000000..6b2bc479a --- /dev/null +++ b/src/online/http_manager.cpp @@ -0,0 +1,219 @@ +// +// 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. + +#include "online/http_manager.hpp" + +#include +#include +#include +#include + +#if defined(WIN32) && !defined(__CYGWIN__) +# include +# define isnan _isnan +#else +# include +# include +#endif + +#if defined(WIN32) && !defined(__CYGWIN__) +// Use Sleep, which takes time in msecs. It must be defined after the +// includes, since otherwise irrlicht's sleep function is changed. +# define sleep(s) Sleep(1000*(s)) +#else +# include +#endif + +namespace online{ + + static HTTPManager * http_singleton = NULL; + + HTTPManager* HTTPManager::get() + { + if (http_singleton == NULL) + { + http_singleton = new HTTPManager(); + http_singleton->startNetworkThread(); + } + return http_singleton; + } // get + + void HTTPManager::deallocate() + { + delete http_singleton; + http_singleton = NULL; + } // deallocate + + + HTTPManager::HTTPManager(){ + curl_global_init(CURL_GLOBAL_DEFAULT); + pthread_cond_init(&m_cond_request, NULL); + } + + // ============================================================================ + HTTPManager::~HTTPManager(){ + curl_global_cleanup(); + } + + + // --------------------------------------------------------------------------- + /** Start the actual network thread. This can not be done as part of + * the constructor, since the assignment to the global network_http + * variable has not been assigned at that stage, and the thread might + * use network_http - a very subtle race condition. So the thread can + * only be started after the assignment (in main) has been done. + */ + void HTTPManager::startNetworkThread() + { + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + // Should be the default, but just in case: + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + //pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + + m_thread_id.setAtomic(new pthread_t()); + int error = pthread_create(m_thread_id.getData(), &attr, + &HTTPManager::mainLoop, this); + if(error) + { + m_thread_id.lock(); + delete m_thread_id.getData(); + m_thread_id.unlock(); + m_thread_id.setAtomic(0); + Log::error("HTTP Manager", "Could not create thread, error=%d.\n", errno); + } + pthread_attr_destroy(&attr); + } // startNetworkThread + + + + // --------------------------------------------------------------------------- + /** This function inserts a high priority request to quit into the request + * queue of the network thead, and also aborts any ongoing download. + * Separating this allows more time for the thread to finish cleanly, + * before it gets cancelled in the destructor. + */ + void HTTPManager::stopNetworkThread() + { + // If a download should be active (which means it was cancelled by the + // user, in which case it will still be ongoing in the background) + // we can't get the mutex, and would have to wait for a timeout, + // and we couldn't finish STK. This way we request an abort of + // a download, which mean we can get the mutex and ask the service + // thread here to cancel properly. + cancelAllDownloads(); + + online::QuitRequest * request = new online::QuitRequest(); + addRequest(request); + } // stopNetworkThread + + + // ---------------------------------------------------------------------------- + /** Signals to the progress function to request any ongoing download to be + * cancelled. This function can also be called if there is actually no + * download atm. The function progressDownload checks m_abort and will + * return a non-zero value which causes libcurl to abort. */ + void HTTPManager::cancelAllDownloads() + { + m_abort.setAtomic(true); + } // cancelAllDownloads + + + // ---------------------------------------------------------------------------- + /** Inserts a request into the queue of all requests. The request will be + * sorted by priority. + * \param request The pointer to the new request to insert. + */ + bool HTTPManager::addRequest(online::Request *request) + { + if (request->isAllowedToAdd()) + { + m_request_queue.lock(); + + m_request_queue.getData().push(request); + // Wake up the network http thread + pthread_cond_signal(&m_cond_request); + + m_request_queue.unlock(); + return true; + } + else + { + Log::info("HTTPManager::addrequest", "Did not add request."); + return false; + } + } // insertRequest + + // --------------------------------------------------------------------------- + /** The actual main loop, which is started as a separate thread from the + * constructor. After testing for a new server, fetching news, the list + * of packages to download, it will wait for commands to be issued. + * \param obj: A pointer to this object, passed on by pthread_create + */ + void *HTTPManager::mainLoop(void *obj) + { + HTTPManager *me = (HTTPManager*) obj; + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + me->m_current_request = NULL; + me->m_request_queue.lock(); + while( me->m_request_queue.getData().empty() || !dynamic_cast(me->m_request_queue.getData().top()) ) + { + bool empty = me->m_request_queue.getData().empty(); + // Wait in cond_wait for a request to arrive. The 'while' is necessary + // since "spurious wakeups from the pthread_cond_wait ... may occur" + // (pthread_cond_wait man page)! + while(empty) + { + pthread_cond_wait(&me->m_cond_request, me->m_request_queue.getMutex()); + empty = me->m_request_queue.getData().empty(); + } + me->m_current_request = me->m_request_queue.getData().top(); + me->m_request_queue.getData().pop(); + me->m_request_queue.unlock(); + me->m_current_request->execute(); + + if(me->m_current_request->manageMemory()) + { + delete me->m_current_request; + me->m_current_request = NULL; + } + me->m_request_queue.lock(); + } // while + + // At this stage we have the lock for m_request_queue + while(!me->m_request_queue.getData().empty()) + { + online::Request * request = me->m_request_queue.getData().top(); + me->m_request_queue.getData().pop(); + // Manage memory can be ignored here, all requests + // need to be freed. + delete request; + } + me->m_request_queue.unlock(); + + pthread_exit(NULL); + return 0; + } // mainLoop +} // namespace online + + + + diff --git a/src/online/http_manager.hpp b/src/online/http_manager.hpp new file mode 100644 index 000000000..35f6717a5 --- /dev/null +++ b/src/online/http_manager.hpp @@ -0,0 +1,95 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2013 SuperTuxKart-Team +// +// 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_MANAGER_HPP +#define HTTP_MANAGER_HPP + +#include +#include +#include +#include +#include + +#ifdef WIN32 +# include +#endif + +#include "io/xml_node.hpp" +#include "utils/string_utils.hpp" +#include "utils/synchronised.hpp" +#include "online/request.hpp" + +namespace online{ + + /** + * \brief Class to connect with a server over HTTP + * \ingroup online + */ + class HTTPManager + { + protected: + + /** The current requested being worked on. */ + online::Request *m_current_request; + + /** A conditional variable to wake up the main loop. */ + pthread_cond_t m_cond_request; + + /** Signal an abort in case that a download is still happening. */ + Synchronised m_abort; + + /** Thread id of the thread running in this object. */ + Synchronised m_thread_id; + + /** The list of pointes to all requests. */ + Synchronised< std::priority_queue < + online::Request*, + std::vector, + online::Request::Compare + > + > m_request_queue; + + static void *mainLoop(void *obj); + void startNetworkThread(); + void stopNetworkThread(); + + + HTTPManager(); //const std::string &url + ~HTTPManager(); + + public: + + // singleton + static HTTPManager* get(); + static void deallocate(); + + //Execute + std::string getPage(online::Request * request); + XMLNode * getXMLFromPage(online::Request * request); + + bool addRequest(online::Request *request); + void cancelAllDownloads(); + + bool getAbort(){ return m_abort.getAtomic(); }; + + }; //class HTTPManager +} // namespace online + +#endif // HTTP_MANAGER_HPP + +/*EOF*/ diff --git a/src/online/request.cpp b/src/online/request.cpp new file mode 100644 index 000000000..eaffa1469 --- /dev/null +++ b/src/online/request.cpp @@ -0,0 +1,201 @@ +// 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. + +#include "online/request.hpp" + +#include +#include +#include + + +namespace online{ + + class HTTPManager; + + // ========================================================================================= + + Request::Request(int priority, bool manage_memory) + { + m_priority = priority; + m_manage_memory = manage_memory; + m_cancel = false; + m_done = false; + } // Request + + Request::~Request() + { + } + + void Request::execute() + { + beforeOperation(); + operation(); + afterOperation(); + } + + // ========================================================================================= + + QuitRequest::QuitRequest() + : Request(9999,true) + { + } + + + // ========================================================================================= + + HTTPRequest::HTTPRequest(const std::string &url) + : Request(1,false) + { + m_url = url; + m_parameters = new Parameters; + m_progress.setAtomic(0); + m_added = false; + } + + HTTPRequest::~HTTPRequest() + { + delete m_parameters; + } + + bool HTTPRequest::isAllowedToAdd(){ + if (m_url.size() > 5 && ( m_url.substr(0, 5) != "http:")) + { + Log::info("HTTPRequest::isAllowedToAdd", "Invalid URL."); + return false; + } + return true; + } + + std::string HTTPRequest::downloadPage() + { + CURL * curl_session; + curl_session = curl_easy_init(); + if(!curl_session) + { + Log::error("online/http_functions", "Error while initialising libCurl session"); + return ""; + } + + curl_easy_setopt(curl_session, CURLOPT_URL, m_url.c_str()); + Parameters::iterator iter; + std::string postString = ""; + for (iter = m_parameters->begin(); iter != m_parameters->end(); ++iter) + { + if(iter != m_parameters->begin()) + postString.append("&"); + char * escaped = curl_easy_escape(curl_session , iter->first.c_str(), iter->first.size()); + postString.append(escaped); + curl_free(escaped); + postString.append("="); + escaped = curl_easy_escape(curl_session , iter->second.c_str(), iter->second.size()); + postString.append(escaped); + curl_free(escaped); + } + curl_easy_setopt(curl_session, CURLOPT_POSTFIELDS, postString.c_str()); + std::string readBuffer; + curl_easy_setopt(curl_session, CURLOPT_WRITEFUNCTION, &HTTPRequest::WriteCallback); + curl_easy_setopt(curl_session, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(curl_session, CURLOPT_PROGRESSDATA, this); + curl_easy_setopt(curl_session, CURLOPT_PROGRESSFUNCTION, &HTTPRequest::progressDownload); + curl_easy_setopt(curl_session, CURLOPT_FILE, &readBuffer); + // Timeout + // Reduce the connection phase timeout (it's 300 by default). + // Add a low speed limit to have a sort of timeout in the + // download phase. Being under 10 B/s during a certain time will + // probably only happen when no access to the net is available. + // The timeout is set to 20s, it should be enough to not produce + // false positive error. + curl_easy_setopt(curl_session, CURLOPT_CONNECTTIMEOUT, 20); + curl_easy_setopt(curl_session, CURLOPT_LOW_SPEED_LIMIT, 10); + curl_easy_setopt(curl_session, CURLOPT_LOW_SPEED_TIME, 20); + CURLcode res = curl_easy_perform(curl_session); + if(res == CURLE_OK) + { + Log::info("online/http_functions", "Received : %s", readBuffer.c_str()); + setProgress(1.0f); + } + else + { + Log::error("HTTPRequest::downloadPage", "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + setProgress(-1.0f); + } + curl_easy_cleanup(curl_session); + return readBuffer; + } + + + size_t HTTPRequest::WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) + { + ((std::string*)userp)->append((char*)contents, size * nmemb); + return size * nmemb; + } + + // ---------------------------------------------------------------------------- + /** Callback function from curl: inform about progress. + * \param clientp + * \param download_total Total size of data to download. + * \param download_now How much has been downloaded so far. + * \param upload_total Total amount of upload. + * \param upload_now How muc has been uploaded so far. + */ + int HTTPRequest::progressDownload(void *clientp, + double download_total, double download_now, + double upload_total, double upload_now) + { + HTTPRequest *request = (HTTPRequest *)clientp; + + HTTPManager* http_manager = HTTPManager::get(); + + // Check if we are asked to abort the download. If so, signal this + // back to libcurl by returning a non-zero status. + if(http_manager->getAbort() || request->isCancelled() ) + { + // Indicates to abort the current download, which means that this + // thread will go back to the mainloop and handle the next request. + return 1; + } + + float f; + if(download_now < download_total) + { + f = (float)download_now / (float)download_total; + // In case of floating point rouding errors make sure that + // 1.0 is only reached when downloadFileInternal is finished + if (f>=1.0f) f=0.99f; + } + else + { + // Don't set progress to 1.0f; this is done in loadFileInternal + // after checking curls return code! + f= download_total==0 ? 0 : 0.99f; + } + request->setProgress(f); + return 0; + } // progressDownload + + + + // ========================================================================================= + XMLRequest::XMLRequest(const std::string &url) + : HTTPRequest(url) + { + } + + void XMLRequest::operation() + { + m_result = file_manager->createXMLTreeFromString(downloadPage()); + } +} // namespace online diff --git a/src/online/request.hpp b/src/online/request.hpp new file mode 100644 index 000000000..3c6a41a40 --- /dev/null +++ b/src/online/request.hpp @@ -0,0 +1,182 @@ +// 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 HEADER_ONLINE_REQUEST_HPP +#define HEADER_ONLINE_REQUEST_HPP + +#include + +#include "utils/leak_check.hpp" +#include "utils/synchronised.hpp" +#include "utils/cpp2011.h" +#include "io/file_manager.hpp" +#include "utils/string_utils.hpp" + +namespace online{ + + /** + * Stores a request for the http connector. They will be sorted by priorities. + * \ingroup online + */ + class Request + { + protected: + /** The priority of this request. The higher the value the more + important this request is. */ + int m_priority; + /** Cancel this request if it is active. */ + bool m_cancel; + + bool m_done; + + /** True if the memory for this Request should be managed by + * http connector (i.e. this object is freed once the request + * is handled). Otherwise the memory is not freed, so it must + * be freed by the calling function. */ + bool m_manage_memory; + + virtual void beforeOperation() {} + virtual void operation() = 0; + virtual void afterOperation() { m_done = true;} + + public: + LEAK_CHECK() + + Request(int priority, bool manage_memory=true); + virtual ~Request(); + + void execute(); + + // ------------------------------------------------------------------------ + /** Returns the priority of this request. */ + int getPriority() const { return m_priority; } + // ------------------------------------------------------------------------ + /** Signals that this request should be canceled. */ + void cancel() { m_cancel = true; } + // ------------------------------------------------------------------------ + /** Returns if this request is to be canceled. */ + bool isCancelled() const { return m_cancel; } + // ------------------------------------------------------------------------ + /** Specifies if the memory should be managed by network_http. */ + void setManageMemory(bool m) { m_manage_memory = m; } + // ------------------------------------------------------------------------ + /** Returns if the memory for this object should be managed by + * by network_http (i.e. freed once the request is handled). */ + bool manageMemory() const { return m_manage_memory; } + + bool isDone() const { return m_done; } + + virtual bool isAllowedToAdd() {return true;} + + /** This class is used by the priority queue to sort requests by priority. + */ + class Compare + { + public: + /** Compares two requests, returns if the first request has a lower + * priority than the second one. */ + bool operator() (const Request *a, const Request *b) const + { return a->getPriority() < b->getPriority(); } + }; // Compare + }; // Request + + + // ======================================================================== + + + class QuitRequest : public Request + { + public : + QuitRequest(); + virtual void operation() OVERRIDE {} + }; + + + // ======================================================================== + + + class HTTPRequest : public Request + { + + protected : + + typedef std::map Parameters; + Parameters * m_parameters; + + /** The progress indicator. 0 till it is started and the first + * packet is downloaded. At the end eithe -1 (error) or 1 + * (everything ok) at the end. */ + Synchronised m_progress; + std::string m_url; + bool m_added; + + std::string downloadPage(); + + static int progressDownload(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); + + static size_t WriteCallback(void *contents, + size_t size, + size_t nmemb, + void *userp); + + public : + + HTTPRequest(const std::string &url); + virtual ~HTTPRequest(); + + void setParameter(const std::string & name, const std::string &value){ + if(!m_added) + (*m_parameters)[name] = value; + }; + void setParameter(const std::string & name, const irr::core::stringw &value){ + if(!m_added) + (*m_parameters)[name] = irr::core::stringc(value.c_str()).c_str(); + } + template + void setParameter(const std::string & name, const T& value){ + if(!m_added) + ( *m_parameters)[name] = StringUtils::toString(value); + } + + /** Returns the current progress. */ + float getProgress() const { return m_progress.getAtomic(); } + /** Sets the current progress. */ + void setProgress(float f) { m_progress.setAtomic(f); } + + const std::string &getURL() const {return m_url;} + + virtual bool isAllowedToAdd() OVERRIDE; + + }; + + class XMLRequest : public HTTPRequest + { + protected : + XMLNode * m_result; + virtual void operation() OVERRIDE; + + public : + XMLRequest(const std::string &url); + XMLNode * getResult(){ return m_result; } + }; +} //namespace online + +#endif + diff --git a/src/online/online_user.cpp b/src/online/user.cpp similarity index 77% rename from src/online/online_user.cpp rename to src/online/user.cpp index e3063a2bb..2e3d0d3ac 100644 --- a/src/online/online_user.cpp +++ b/src/online/user.cpp @@ -17,15 +17,15 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "online/online_user.hpp" +#include "online/user.hpp" #include #include - -// ============================================================================ -OnlineUser::OnlineUser(const irr::core::stringw &username) -{ - m_name = username; -} // OnlineUser - +namespace online{ + // ============================================================================ + User::User(const irr::core::stringw &username) + { + m_name = username; + } // OnlineUser +} // namespace online diff --git a/src/online/online_user.hpp b/src/online/user.hpp similarity index 62% rename from src/online/online_user.hpp rename to src/online/user.hpp index 6d67a12f6..e8e206b43 100644 --- a/src/online/online_user.hpp +++ b/src/online/user.hpp @@ -22,34 +22,34 @@ #include #include "utils/types.hpp" -// ============================================================================ +namespace online{ -/** - * \brief Class that represents an online registered user - * \ingroup online - */ -class OnlineUser -{ - private: + /** + * \brief Class that represents an online registered user + * \ingroup online + */ + class User + { + private: - protected: + protected: - bool m_is_server_host; - irr::core::stringw m_name; - uint32_t m_id; - OnlineUser(){} + bool m_is_server_host; + irr::core::stringw m_name; + uint32_t m_id; + User(){} - public: + public: - OnlineUser(const irr::core::stringw &username); + User(const irr::core::stringw &username); - irr::core::stringw getUserName() const { return m_name; } - uint32_t getUserID() const { return m_id; } + irr::core::stringw getUserName() const { return m_name; } + uint32_t getUserID() const { return m_id; } -}; // class OnlineUser - + }; // class User +} // namespace online #endif /*EOF*/ diff --git a/src/states_screens/dialogs/login_dialog.cpp b/src/states_screens/dialogs/login_dialog.cpp index c6cbe0ed8..01fa2ce09 100644 --- a/src/states_screens/dialogs/login_dialog.cpp +++ b/src/states_screens/dialogs/login_dialog.cpp @@ -25,7 +25,6 @@ #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" -#include "online/current_online_user.hpp" #include "states_screens/dialogs/registration_dialog.hpp" @@ -40,6 +39,7 @@ LoginDialog::LoginDialog(const Message message_type) : { m_self_destroy = false; m_open_registration_dialog = false; + m_signin_request = NULL; loadFromFile("online/login_dialog.stkgui"); m_info_widget = getWidget("info"); @@ -103,17 +103,7 @@ void LoginDialog::login() { const stringw username = m_username_widget->getText().trim(); const stringw password = m_password_widget->getText().trim(); - stringw info = ""; - if(CurrentOnlineUser::get()->signIn(username,password, m_remember_widget->getState(),info)) - { - m_self_destroy = true; - } - else - { - sfx_manager->quickSound( "anvil" ); - m_message_widget->setColor(irr::video::SColor(255, 255, 0, 0)); - m_message_widget->setText(info, false); - } + m_signin_request = online::CurrentUser::get()->signInRequest(username,password, m_remember_widget->getState()); } // ----------------------------------------------------------------------------- @@ -158,6 +148,26 @@ void LoginDialog::onEnterPressedInternal() void LoginDialog::onUpdate(float dt) { + if(m_signin_request != NULL) + { + // load screen + if(m_signin_request->isDone()) + { + stringw info = ""; + if(online::CurrentUser::get()->signIn(m_signin_request->getResult(), info)) + { + m_self_destroy = true; + } + else + { + // error message + sfx_manager->quickSound( "anvil" ); + m_message_widget->setColor(irr::video::SColor(255, 255, 0, 0)); + m_message_widget->setText(info, false); + } + } + } + //If we want to open the registration dialog, we need to close this one first m_open_registration_dialog && (m_self_destroy = true); @@ -169,6 +179,4 @@ void LoginDialog::onUpdate(float dt) new RegistrationDialog(); } - - } diff --git a/src/states_screens/dialogs/login_dialog.hpp b/src/states_screens/dialogs/login_dialog.hpp index 590289f8f..b3de375db 100644 --- a/src/states_screens/dialogs/login_dialog.hpp +++ b/src/states_screens/dialogs/login_dialog.hpp @@ -21,6 +21,8 @@ #include +#include "online/current_user.hpp" + #include "guiengine/modaldialog.hpp" #include "guiengine/widgets/text_box_widget.hpp" #include "guiengine/widgets/check_box_widget.hpp" @@ -39,6 +41,7 @@ private: bool m_self_destroy; bool m_open_registration_dialog; + online::XMLRequest * m_signin_request; GUIEngine::LabelWidget * m_info_widget; GUIEngine::TextBoxWidget * m_username_widget; diff --git a/src/states_screens/dialogs/registration_dialog.cpp b/src/states_screens/dialogs/registration_dialog.cpp index eb0329997..3af68e652 100644 --- a/src/states_screens/dialogs/registration_dialog.cpp +++ b/src/states_screens/dialogs/registration_dialog.cpp @@ -29,7 +29,7 @@ #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" -#include "online/current_online_user.hpp" +#include "online/current_user.hpp" using namespace GUIEngine; @@ -192,7 +192,7 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){ { assert(getWidget("accepted")->getState()); m_agreement = true; - if(CurrentOnlineUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, m_registration_error)) + if(online::CurrentUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, m_registration_error)) { m_show_registration_activation = true; m_registration_error = ""; diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp index 695dba9ef..495438b4a 100644 --- a/src/states_screens/dialogs/server_info_dialog.cpp +++ b/src/states_screens/dialogs/server_info_dialog.cpp @@ -25,7 +25,7 @@ #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" -#include "online/current_online_user.hpp" +#include "online/current_user.hpp" #include "online/servers_manager.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "states_screens/networking_lobby.hpp" @@ -71,7 +71,7 @@ void ServerInfoDialog::requestJoin() { //FIXME totally not correct. Receiving an answer, not kept in mind. irr::core::stringw info; - if (CurrentOnlineUser::get()->requestJoin( m_server->getServerId(), info)) + if (online::CurrentUser::get()->requestJoin( m_server->getServerId(), info)) { ServersManager::get()->setJoinedServer(m_server); m_enter_lobby = true; diff --git a/src/states_screens/networking_lobby.cpp b/src/states_screens/networking_lobby.cpp index 4b8d7da64..795d7bd7a 100644 --- a/src/states_screens/networking_lobby.cpp +++ b/src/states_screens/networking_lobby.cpp @@ -37,8 +37,6 @@ #include "utils/translation.hpp" #include "online/servers_manager.hpp" -#include "online/current_online_user.hpp" - using namespace GUIEngine; diff --git a/src/states_screens/networking_lobby_settings.cpp b/src/states_screens/networking_lobby_settings.cpp index 7cc6a423b..cd5f26832 100644 --- a/src/states_screens/networking_lobby_settings.cpp +++ b/src/states_screens/networking_lobby_settings.cpp @@ -32,7 +32,7 @@ #include "utils/translation.hpp" #include "states_screens/networking_lobby.hpp" -#include "online/current_online_user.hpp" +#include "online/current_user.hpp" using namespace GUIEngine; @@ -70,7 +70,7 @@ void NetworkingLobbySettings::loadedFromFile() // ---------------------------------------------------------------------------- bool NetworkingLobbySettings::hasLostConnection() { - return !CurrentOnlineUser::get()->isSignedIn(); + return !online::CurrentUser::get()->isSignedIn(); } // ---------------------------------------------------------------------------- @@ -100,7 +100,7 @@ void NetworkingLobbySettings::createServer() const stringw name = m_name_widget->getText().trim(); int max_players = m_max_players_widget->getValue(); stringw info = ""; - if(CurrentOnlineUser::get()->createServer(name, max_players, info)) + if(online::CurrentUser::get()->createServer(name, max_players, info)) { StateManager::get()->escapePressed(); StateManager::get()->pushScreen(NetworkingLobby::getInstance()); diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index 31d691c08..b7ebf37af 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -38,7 +38,7 @@ #include "states_screens/server_selection.hpp" #include "modes/demo_world.hpp" #include "utils/translation.hpp" -#include "online/current_online_user.hpp" +#include "online/current_user.hpp" #include "online/servers_manager.hpp" @@ -52,7 +52,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen ); OnlineScreen::OnlineScreen() : Screen("online/main.stkgui") { m_recorded_state = Not; - CurrentOnlineUser::get()->trySavedSession(); + online::CurrentUser::get()->trySavedSession(); } // OnlineScreen // ---------------------------------------------------------------------------- @@ -87,9 +87,9 @@ void OnlineScreen::loadedFromFile() bool OnlineScreen::hasStateChanged() { State previous_state = m_recorded_state; - if(CurrentOnlineUser::get()->isSignedIn()) + if(online::CurrentUser::get()->isSignedIn()) { - if(CurrentOnlineUser::get()->isGuest()) + if(online::CurrentUser::get()->isGuest()) m_recorded_state = Guest; else m_recorded_state = Registered; @@ -137,7 +137,7 @@ void OnlineScreen::init() Screen::init(); setInitialFocus(); DemoWorld::resetIdleTime(); - m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + CurrentOnlineUser::get()->getUserName() + ".", false); + m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + online::CurrentUser::get()->getUserName() + ".", false); } // init // ---------------------------------------------------------------------------- @@ -168,7 +168,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const else if (selection == "sign_out") { irr::core::stringw info; - if (CurrentOnlineUser::get()->signOut(info)) + if (online::CurrentUser::get()->signOut(info)) { new MessageDialog(_("Signed out successfully.")); //GUIEngine::reshowCurrentScreen(); @@ -193,7 +193,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const //FIXME temporary and the request join + join sequence should be placed in one method somewhere Server * server = ServersManager::get()->getQuickPlay(); irr::core::stringw info; - if (CurrentOnlineUser::get()->requestJoin( server->getServerId(), info)) + if (online::CurrentUser::get()->requestJoin( server->getServerId(), info)) { ServersManager::get()->setJoinedServer(server); StateManager::get()->pushScreen(NetworkingLobby::getInstance());