From: <uni...@us...> - 2013-06-21 02:12:42
|
Revision: 12910 http://sourceforge.net/p/supertuxkart/code/12910 Author: unitraxx Date: 2013-06-21 02:12:38 +0000 (Fri, 21 Jun 2013) Log Message: ----------- [GSoC Uni] XML parsing of the server reply. Username & Password back to std::string. Modified Paths: -------------- main/branches/uni/src/online/current_online_user.cpp main/branches/uni/src/online/current_online_user.hpp main/branches/uni/src/online/http_connector.cpp main/branches/uni/src/online/http_connector.hpp main/branches/uni/src/online/online_user.cpp main/branches/uni/src/online/online_user.hpp main/branches/uni/src/states_screens/dialogs/login_dialog.cpp Modified: main/branches/uni/src/online/current_online_user.cpp =================================================================== --- main/branches/uni/src/online/current_online_user.cpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/online/current_online_user.cpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -49,7 +49,7 @@ // ============================================================================ -bool CurrentOnlineUser::signIn(const stringw &username, const stringw &password) +bool CurrentOnlineUser::signIn(const std::string &username, const std::string &password) { assert(m_is_signed_in == false); HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); @@ -59,7 +59,6 @@ parameters["password"] = password; const XMLNode * result = connector->getXMLFromPage(parameters); std::string token; - //const XMLNode * connection = result->getNode("connection"); bool succes = result->get("token", &token); if(succes) { @@ -76,7 +75,7 @@ // ============================================================================ -core::stringw CurrentOnlineUser::getUserName() const +std::string CurrentOnlineUser::getUserName() const { if(m_is_signed_in){ assert(m_user != NULL); Modified: main/branches/uni/src/online/current_online_user.hpp =================================================================== --- main/branches/uni/src/online/current_online_user.hpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/online/current_online_user.hpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -21,8 +21,6 @@ #include "online/online_user.hpp" #include <string> -#include <irrString.h> -using namespace irr; // ============================================================================ @@ -45,9 +43,9 @@ // singleton static CurrentOnlineUser* get(); static void deallocate(); - bool signIn(const core::stringw &username, const core::stringw &password); + bool signIn(const std::string &username, const std::string &password); /** Returns the username if signed in. */ - core::stringw getUserName() const; + std::string getUserName() const; bool isSignedIn(){ return m_is_signed_in; } }; // class CurrentOnlineUser Modified: main/branches/uni/src/online/http_connector.cpp =================================================================== --- main/branches/uni/src/online/http_connector.cpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/online/http_connector.cpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -61,22 +61,26 @@ std::string HTTPConnector::getPage(Parameters & post_parameters) { Parameters::iterator iter; - core::stringw postString; + std::string postString; for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter) { if(iter != post_parameters.begin()) postString.append("&"); - postString.append(iter->first); + char * escaped = curl_easy_escape(this->curl , iter->first.c_str(), iter->first.size()); + postString.append(escaped); + curl_free(escaped); postString.append("="); - postString.append(iter->second); + escaped = curl_easy_escape(this->curl , iter->second.c_str(), iter->second.size()); + postString.append(escaped); + curl_free(escaped); } - core::stringc postString2 = postString.c_str(); - printf("Sending: %s\n", postString2.c_str()); - curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString2.c_str()); + printf("Sending: %s\n", postString.c_str()); + curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str()); std::string readBuffer; curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer); res = curl_easy_perform(this->curl); + if(res != CURLE_OK) { Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); @@ -84,7 +88,7 @@ }else{ printf("Retrieved: %s\n", readBuffer.c_str()); } - return readBuffer; + return readBuffer; } Modified: main/branches/uni/src/online/http_connector.hpp =================================================================== --- main/branches/uni/src/online/http_connector.hpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/online/http_connector.hpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -36,7 +36,7 @@ CURLcode res; public: - typedef std::map<core::stringw, core::stringw> Parameters; + typedef std::map<std::string, std::string> Parameters; HTTPConnector(const std::string &url); ~HTTPConnector(); std::string getPage(Parameters & post_parameters); Modified: main/branches/uni/src/online/online_user.cpp =================================================================== --- main/branches/uni/src/online/online_user.cpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/online/online_user.cpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -24,7 +24,7 @@ // ============================================================================ -OnlineUser::OnlineUser(const core::stringw &username) +OnlineUser::OnlineUser(const std::string &username) { m_username = username; } // OnlineUser Modified: main/branches/uni/src/online/online_user.hpp =================================================================== --- main/branches/uni/src/online/online_user.hpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/online/online_user.hpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -19,10 +19,8 @@ #ifndef HEADER_ONLINE_USER_HPP #define HEADER_ONLINE_USER_HPP -#include <irrString.h> -using namespace irr; +#include <string> - // ============================================================================ /** @@ -35,17 +33,17 @@ protected: - core::stringw m_username; + std::string m_username; public: /** * Constructor */ - OnlineUser(const core::stringw &username); + OnlineUser(const std::string &username); /** Returns the username. */ - core::stringw getUserName() const { return m_username; } + std::string getUserName() const { return m_username; } }; // class OnlineUser Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-06-21 00:26:19 UTC (rev 12909) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-06-21 02:12:38 UTC (rev 12910) @@ -85,8 +85,8 @@ sfx_manager->quickSound( "anvil" ); return GUIEngine::EVENT_BLOCK; } - - if(CurrentOnlineUser::get()->signIn(username, password)) + ; + if(CurrentOnlineUser::get()->signIn(core::stringc(username.c_str()).c_str(), core::stringc(password.c_str()).c_str())) { m_self_destroy = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-06-22 02:47:32
|
Revision: 12913 http://sourceforge.net/p/supertuxkart/code/12913 Author: unitraxx Date: 2013-06-22 02:47:28 +0000 (Sat, 22 Jun 2013) Log Message: ----------- [GSoC Uni_] Writing and fetching from database (registering) works. Lots of debug code to be cleaned up. Modified Paths: -------------- main/branches/uni/src/online/current_online_user.cpp main/branches/uni/src/online/current_online_user.hpp main/branches/uni/src/online/http_connector.cpp main/branches/uni/src/online/http_connector.hpp main/branches/uni/src/online/online_user.cpp main/branches/uni/src/online/online_user.hpp main/branches/uni/src/states_screens/dialogs/login_dialog.cpp Modified: main/branches/uni/src/online/current_online_user.cpp =================================================================== --- main/branches/uni/src/online/current_online_user.cpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/online/current_online_user.cpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -24,6 +24,7 @@ #include <assert.h> #include "online/http_connector.hpp" #include "config/user_config.hpp" +#include "utils/string_utils.hpp" static CurrentOnlineUser* user_singleton = NULL; @@ -48,8 +49,39 @@ } // ============================================================================ +// Register +bool CurrentOnlineUser::signUp(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg){ + assert(m_is_signed_in == false); + HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + HTTPConnector::Parameters parameters; + parameters["action"] = "register"; + parameters["user"] = username; + parameters["password"] = password; + const XMLNode * result = connector->getXMLFromPage(parameters); + std::string rec_success; + if(result->get("success", &rec_success)) + { + if(rec_success == "yes") + { + msg = "Registered!"; + return true; + } + else + { + msg = "Registering went wrong!"; + } + } + else + { + msg = "Registering went wrong!2"; + } + return false; +} -bool CurrentOnlineUser::signIn(const std::string &username, const std::string &password) + +// ============================================================================ + +bool CurrentOnlineUser::signIn(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg) { assert(m_is_signed_in == false); HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); @@ -58,12 +90,17 @@ parameters["user"] = username; parameters["password"] = password; const XMLNode * result = connector->getXMLFromPage(parameters); - std::string token; - bool succes = result->get("token", &token); - if(succes) + return false; + std::string rec_token; + irr::core::stringw rec_username; + std::string rec_userid; + + if(result->get("token", &rec_token) && result->get("username", &rec_username) && result->get("userid", &rec_userid)) { - m_user = new OnlineUser(username); - m_token = token; + long userid; + StringUtils::fromString<long>(rec_userid, userid); + m_user = new OnlineUser(""); + m_token = rec_token; m_is_signed_in = true; } else @@ -75,7 +112,7 @@ // ============================================================================ -std::string CurrentOnlineUser::getUserName() const +irr::core::stringw CurrentOnlineUser::getUserName() const { if(m_is_signed_in){ assert(m_user != NULL); Modified: main/branches/uni/src/online/current_online_user.hpp =================================================================== --- main/branches/uni/src/online/current_online_user.hpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/online/current_online_user.hpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -21,6 +21,7 @@ #include "online/online_user.hpp" #include <string> +#include <irrString.h> // ============================================================================ @@ -43,9 +44,10 @@ // singleton static CurrentOnlineUser* get(); static void deallocate(); - bool signIn(const std::string &username, const std::string &password); + bool signIn(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg); + bool signUp(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg); /** Returns the username if signed in. */ - std::string getUserName() const; + irr::core::stringw getUserName() const; bool isSignedIn(){ return m_is_signed_in; } }; // class CurrentOnlineUser Modified: main/branches/uni/src/online/http_connector.cpp =================================================================== --- main/branches/uni/src/online/http_connector.cpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/online/http_connector.cpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -60,17 +60,17 @@ std::string HTTPConnector::getPage(Parameters & post_parameters) { + Parameters::iterator iter; - std::string postString; + std::string postString = ""; for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter) { if(iter != post_parameters.begin()) postString.append("&"); - char * escaped = curl_easy_escape(this->curl , iter->first.c_str(), iter->first.size()); - postString.append(escaped); - curl_free(escaped); + postString.append(iter->first); postString.append("="); - escaped = curl_easy_escape(this->curl , iter->second.c_str(), iter->second.size()); + core::stringc converted = core::stringc(iter->second.c_str()); + char * escaped = curl_easy_escape(this->curl , converted.c_str(), converted.size()); postString.append(escaped); curl_free(escaped); } @@ -80,7 +80,6 @@ curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer); res = curl_easy_perform(this->curl); - if(res != CURLE_OK) { Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); Modified: main/branches/uni/src/online/http_connector.hpp =================================================================== --- main/branches/uni/src/online/http_connector.hpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/online/http_connector.hpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -36,7 +36,7 @@ CURLcode res; public: - typedef std::map<std::string, std::string> Parameters; + typedef std::map<std::string, core::stringw> Parameters; HTTPConnector(const std::string &url); ~HTTPConnector(); std::string getPage(Parameters & post_parameters); Modified: main/branches/uni/src/online/online_user.cpp =================================================================== --- main/branches/uni/src/online/online_user.cpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/online/online_user.cpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -24,7 +24,7 @@ // ============================================================================ -OnlineUser::OnlineUser(const std::string &username) +OnlineUser::OnlineUser(const irr::core::stringw &username) { m_username = username; } // OnlineUser Modified: main/branches/uni/src/online/online_user.hpp =================================================================== --- main/branches/uni/src/online/online_user.hpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/online/online_user.hpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -19,7 +19,7 @@ #ifndef HEADER_ONLINE_USER_HPP #define HEADER_ONLINE_USER_HPP -#include <string> +#include <irrString.h> // ============================================================================ @@ -33,17 +33,17 @@ protected: - std::string m_username; + irr::core::stringw m_username; public: /** * Constructor */ - OnlineUser(const std::string &username); + OnlineUser(const irr::core::stringw &username); /** Returns the username. */ - std::string getUserName() const { return m_username; } + irr::core::stringw getUserName() const { return m_username; } }; // class OnlineUser Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-06-21 08:20:12 UTC (rev 12912) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-06-22 02:47:28 UTC (rev 12913) @@ -59,6 +59,7 @@ { } + // ----------------------------------------------------------------------------- GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSource) @@ -73,29 +74,21 @@ // ---- See if we can accept the input TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("username"); const stringw username = textCtrl->getText().trim(); - if (!StringUtils::notEmpty(username)){ - getWidget<LabelWidget>("errormsg")->setText(_("Username was empty"), false); - sfx_manager->quickSound( "anvil" ); - return GUIEngine::EVENT_BLOCK; - } textCtrl = getWidget<TextBoxWidget>("password"); const stringw password = textCtrl->getText().trim(); - if (!StringUtils::notEmpty(password)){ - getWidget<LabelWidget>("errormsg")->setText(_("Password was empty"), false); - sfx_manager->quickSound( "anvil" ); - return GUIEngine::EVENT_BLOCK; - } - ; - if(CurrentOnlineUser::get()->signIn(core::stringc(username.c_str()).c_str(), core::stringc(password.c_str()).c_str())) + stringw msg = ""; + if(CurrentOnlineUser::get()->signUp(username,password,msg)) { - m_self_destroy = true; + //m_self_destroy = true; + m_self_destroy = false; } else { - getWidget<LabelWidget>("errormsg")->setText(_("Signing in went wrong."), false); + sfx_manager->quickSound( "anvil" ); m_self_destroy = false; } + getWidget<LabelWidget>("errormsg")->setText(msg, false); return GUIEngine::EVENT_BLOCK; } return GUIEngine::EVENT_LET; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-06-30 22:16:33
|
Revision: 13048 http://sourceforge.net/p/supertuxkart/code/13048 Author: unitraxx Date: 2013-06-30 22:16:29 +0000 (Sun, 30 Jun 2013) Log Message: ----------- [_GSoC Uni_] 'Screen' has now a callback 'onDialogClose' which gets called by 'ModalDialog' after being dismissed. (Also removed a debug line in RibbonWidget) Modified Paths: -------------- main/branches/uni/src/guiengine/modaldialog.cpp main/branches/uni/src/guiengine/screen.hpp main/branches/uni/src/guiengine/widgets/ribbon_widget.cpp main/branches/uni/src/states_screens/dialogs/login_dialog.cpp main/branches/uni/src/states_screens/dialogs/login_dialog.hpp main/branches/uni/src/states_screens/online_screen.cpp main/branches/uni/src/states_screens/online_screen.hpp Modified: main/branches/uni/src/guiengine/modaldialog.cpp =================================================================== --- main/branches/uni/src/guiengine/modaldialog.cpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/guiengine/modaldialog.cpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -187,6 +187,7 @@ { if(modalWindow != NULL) delete modalWindow; modalWindow = NULL; + GUIEngine::getCurrentScreen()->onDialogClose(); } // ---------------------------------------------------------------------------- Modified: main/branches/uni/src/guiengine/screen.hpp =================================================================== --- main/branches/uni/src/guiengine/screen.hpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/guiengine/screen.hpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -302,6 +302,10 @@ int axisDir, int value) {} + /** Callback that gets called when a dialog is closed. + * Can be used to set focus for instance. + */ + virtual void onDialogClose() {} }; } Modified: main/branches/uni/src/guiengine/widgets/ribbon_widget.cpp =================================================================== --- main/branches/uni/src/guiengine/widgets/ribbon_widget.cpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/guiengine/widgets/ribbon_widget.cpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -471,7 +471,6 @@ // ---------------------------------------------------------------------------- EventPropagation RibbonWidget::rightPressed(const int playerID) { - Log::info("RibbonWidget", "Right Pressed"); if (m_deactivated) return EVENT_LET; // empty ribbon, or only one item (can't move right) if (m_active_children.size() < 2) return EVENT_LET; Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -40,7 +40,6 @@ { m_self_destroy = false; m_open_registration_dialog = false; - m_reshow_current_screen = false; loadFromFile("online/login_dialog.stkgui"); m_info_widget = getWidget<LabelWidget>("info"); @@ -105,7 +104,6 @@ stringw info = ""; if(CurrentOnlineUser::get()->signIn(username,password,info)) { - m_reshow_current_screen = true; m_self_destroy = true; } else @@ -128,7 +126,7 @@ void LoginDialog::onEnterPressedInternal() { - //If enter was pressed while "cancel" nor "signup" was selected, then interpret as "signin" press. + //If enter was pressed while none of the other widgets are focused, then interpret as "signin" press. const int playerID = PLAYER_ID_GAME_MASTER; if (!GUIEngine::isFocusedForPlayer(m_recovery_widget, playerID) && !GUIEngine::isFocusedForPlayer(m_register_widget, playerID) && @@ -150,14 +148,6 @@ if (m_self_destroy) { ModalDialog::dismiss(); - if (m_reshow_current_screen) - /*Replaced to online state screen. Not 100% how I will handle this. - * Thee options : - * - Listener - * - Directly calling GUIEngine::reshowCurrentScreen(); (old option) - * - Underlying stateschreen is responsible for polling changed state (current option) - */ - true;//GUIEngine::reshowCurrentScreen(); if (m_open_registration_dialog) new RegistrationDialog(0.8f, 0.9f); Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -37,7 +37,6 @@ bool m_self_destroy; bool m_open_registration_dialog; - bool m_reshow_current_screen; GUIEngine::LabelWidget * m_info_widget; GUIEngine::TextBoxWidget * m_username_widget; Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -32,8 +32,8 @@ #include "main_loop.hpp" #include "states_screens/online_screen.hpp" #include "states_screens/state_manager.hpp" +#include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/dialogs/login_dialog.hpp" -#include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "modes/demo_world.hpp" #include "utils/translation.hpp" @@ -133,12 +133,8 @@ void OnlineScreen::init() { Screen::init(); - if(m_recorded_state == Not) - m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - else - m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - - DemoWorld::resetIdleTime(); + setInitialFocus(); + DemoWorld::resetIdleTime(); //FIXME : what's this? m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + CurrentOnlineUser::get()->getUserName() + ".", false); } // init @@ -205,7 +201,6 @@ } // tearDown // ---------------------------------------------------------------------------- - void OnlineScreen::onDisabledItemClicked(const std::string& item) { if (item == "find_server" || item =="create_server") @@ -217,3 +212,21 @@ new LoginDialog(LoginDialog::Signing_In_Required); } } // onDisabledItemClicked + +// ---------------------------------------------------------------------------- +void OnlineScreen::setInitialFocus() +{ + if(m_recorded_state == Not) + m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + else + m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); +} // setInitialFocus + +// ---------------------------------------------------------------------------- +void OnlineScreen::onDialogClose() +{ + if (hasStateChanged()) + GUIEngine::reshowCurrentScreen(); + else + setInitialFocus(); +} // onLoginDialogClose() Modified: main/branches/uni/src/states_screens/online_screen.hpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.hpp 2013-06-30 19:20:33 UTC (rev 13047) +++ main/branches/uni/src/states_screens/online_screen.hpp 2013-06-30 22:16:29 UTC (rev 13048) @@ -29,7 +29,8 @@ * \brief Handles the main menu * \ingroup states_screens */ -class OnlineScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<OnlineScreen> +class OnlineScreen : public GUIEngine::Screen, + public GUIEngine::ScreenSingleton<OnlineScreen> { private: friend class GUIEngine::ScreenSingleton<OnlineScreen>; @@ -59,6 +60,8 @@ /** \brief Checks if the recorded state differs from the actual state and sets it. */ bool hasStateChanged(); + /** \brief Sets which widget has to be focused. Depends on the user state. */ + void setInitialFocus(); public: @@ -82,6 +85,9 @@ /** \brief implement callback from parent class GUIEngine::Screen */ virtual void onDisabledItemClicked(const std::string& item) OVERRIDE; + + /** \brief Implements the callback when a dialog gets closed. */ + virtual void onDialogClose() OVERRIDE; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-13 15:59:30
|
Revision: 13202 http://sourceforge.net/p/supertuxkart/code/13202 Author: unitraxx Date: 2013-07-13 15:59:27 +0000 (Sat, 13 Jul 2013) Log Message: ----------- Remember session (without GUI) and starting to integrate online-multiplayer and addons networking code. (Limited to config file for now.) Modified Paths: -------------- main/branches/uni/src/config/user_config.hpp main/branches/uni/src/online/current_online_user.cpp main/branches/uni/src/online/current_online_user.hpp Modified: main/branches/uni/src/config/user_config.hpp =================================================================== --- main/branches/uni/src/config/user_config.hpp 2013-07-13 15:24:50 UTC (rev 13201) +++ main/branches/uni/src/config/user_config.hpp 2013-07-13 15:59:27 UTC (rev 13202) @@ -603,16 +603,48 @@ 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 @@ "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, Modified: main/branches/uni/src/online/current_online_user.cpp =================================================================== --- main/branches/uni/src/online/current_online_user.cpp 2013-07-13 15:24:50 UTC (rev 13201) +++ main/branches/uni/src/online/current_online_user.cpp 2013-07-13 15:59:27 UTC (rev 13202) @@ -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 @@ } // deallocate // ============================================================================ - - CurrentOnlineUser::CurrentOnlineUser(){ m_is_signed_in = false; m_is_guest = false; @@ -54,6 +53,42 @@ } // ============================================================================ +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, const irr::core::stringw &password, @@ -89,6 +124,7 @@ 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 @@ 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 @@ 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 @@ 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); } Modified: main/branches/uni/src/online/current_online_user.hpp =================================================================== --- main/branches/uni/src/online/current_online_user.hpp 2013-07-13 15:24:50 UTC (rev 13201) +++ main/branches/uni/src/online/current_online_user.hpp 2013-07-13 15:59:27 UTC (rev 13202) @@ -47,9 +47,12 @@ // 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, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-14 22:24:09
|
Revision: 13221 http://sourceforge.net/p/supertuxkart/code/13221 Author: unitraxx Date: 2013-07-14 22:24:06 +0000 (Sun, 14 Jul 2013) Log Message: ----------- Removed the old tab hack from scalable font. (Could someone check if done correctly?) and made it possible for table entries to have both left-aligned and centered content. Modified Paths: -------------- main/branches/uni/src/guiengine/scalable_font.cpp main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp main/branches/uni/src/guiengine/widgets/CGUISTKListBox.h main/branches/uni/src/guiengine/widgets/list_widget.cpp main/branches/uni/src/guiengine/widgets/list_widget.hpp main/branches/uni/src/states_screens/addons_screen.cpp main/branches/uni/src/states_screens/server_selection.cpp Modified: main/branches/uni/src/guiengine/scalable_font.cpp =================================================================== --- main/branches/uni/src/guiengine/scalable_font.cpp 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/guiengine/scalable_font.cpp 2013-07-14 22:24:06 UTC (rev 13221) @@ -500,15 +500,12 @@ core::position2d<s32> offset = position.UpperLeftCorner; core::dimension2d<s32> text_dimension; - // When we use the "tab" hack, disable right-alignment, it messes up everything - bool has_tab = (text.findFirst(L'\t') != -1); - - if ((m_rtl && !has_tab) || hcenter || vcenter || clip) + if (m_rtl || hcenter || vcenter || clip) { text_dimension = getDimension(text.c_str()); - if (hcenter) offset.X += (position.getWidth() - text_dimension.Width) / 2; - else if (m_rtl && !has_tab) offset.X += (position.getWidth() - text_dimension.Width); + if (hcenter) offset.X += (position.getWidth() - text_dimension.Width) / 2; + else if (m_rtl) offset.X += (position.getWidth() - text_dimension.Width); if (vcenter) offset.Y += (position.getHeight() - text_dimension.Height) / 2; if (clip) @@ -519,14 +516,6 @@ } } - if (m_rtl && has_tab) - { - const int where = text.findFirst(L'\t'); - core::stringw substr = text.subString(0, where-1); - text_dimension = getDimension(substr.c_str()) + getDimension(L"XX"); - offset.X += (int)(position.getWidth()*m_tab_stop-text_dimension.Width); - } - // ---- collect character locations const unsigned int text_size = text.size(); core::array<s32> indices(text_size); Modified: main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp =================================================================== --- main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp 2013-07-14 22:24:06 UTC (rev 13221) @@ -488,7 +488,7 @@ { total_proportion += Items[i].m_contents[x].m_proportion; } - int part_size = textRect.getWidth() / total_proportion; + int part_size = (int)(textRect.getWidth() / float(total_proportion)); for(int x = 0; x < Items[i].m_contents.size(); ++x) { @@ -532,7 +532,7 @@ textRect, hasItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) ? getItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_TEXT_HIGHLIGHT), - false, true, &clientClip); + Items[i].m_contents[x].m_center, true, &clientClip); } else { @@ -540,7 +540,7 @@ Items[i].m_contents[x].m_text.c_str(), textRect, hasItemOverrideColor(i, EGUI_LBC_TEXT) ? getItemOverrideColor(i, EGUI_LBC_TEXT) : getItemDefaultColor(EGUI_LBC_TEXT), - false, true, &clientClip); + Items[i].m_contents[x].m_center, true, &clientClip); } //Position back to inital pos textRect.UpperLeftCorner.X -= ItemsIconWidth+6; Modified: main/branches/uni/src/guiengine/widgets/CGUISTKListBox.h =================================================================== --- main/branches/uni/src/guiengine/widgets/CGUISTKListBox.h 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/guiengine/widgets/CGUISTKListBox.h 2013-07-14 22:24:06 UTC (rev 13221) @@ -32,12 +32,14 @@ irr::core::stringw m_text; int m_proportion; s32 m_icon; + bool m_center; - ListCell(irr::core::stringw text, s32 icon = -1, int proportion = 1) + ListCell(irr::core::stringw text, s32 icon = -1, int proportion = 1, bool center = false) { m_text = text; m_proportion = proportion; m_icon = icon; + m_center = center; } }; Modified: main/branches/uni/src/guiengine/widgets/list_widget.cpp =================================================================== --- main/branches/uni/src/guiengine/widgets/list_widget.cpp 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/guiengine/widgets/list_widget.cpp 2013-07-14 22:24:06 UTC (rev 13221) @@ -182,12 +182,13 @@ void ListWidget::addItem( const std::string& internal_name, const irr::core::stringw &name, - const int icon) + const int icon, + bool center) { // May only be called AFTER this widget has been add()ed assert(m_element != NULL); - ListCell cell(name, icon); + ListCell cell(name, icon, 1, center); ListItem newItem; newItem.m_internal_name = internal_name; newItem.m_contents.push_back(cell); Modified: main/branches/uni/src/guiengine/widgets/list_widget.hpp =================================================================== --- main/branches/uni/src/guiengine/widgets/list_widget.hpp 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/guiengine/widgets/list_widget.hpp 2013-07-14 22:24:06 UTC (rev 13221) @@ -122,7 +122,8 @@ */ void addItem( const std::string& internal_name, const irr::core::stringw &name, - const int icon=-1); + const int icon=-1, + bool center = false); void addItem( const std::string& internal_name, PtrVector<ListCell> * contents); Modified: main/branches/uni/src/states_screens/addons_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/addons_screen.cpp 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/states_screens/addons_screen.cpp 2013-07-14 22:24:06 UTC (rev 13221) @@ -104,7 +104,7 @@ getWidget<GUIEngine::ListWidget>("list_addons"); assert(w_list != NULL); w_list->clearColumns(); - w_list->addColumn( _("Add-on name"), 2 ); + w_list->addColumn( _("Add-on name"), 3 ); w_list->addColumn( _("Updated date"), 1 ); GUIEngine::SpinnerWidget* w_filter_date = @@ -358,8 +358,8 @@ } PtrVector<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>; - row->push_back(new GUIEngine::ListWidget::ListCell(s.c_str(),icon,2)); - row->push_back(new GUIEngine::ListWidget::ListCell(addon->getDateAsString().c_str(),-1,1)); + row->push_back(new GUIEngine::ListWidget::ListCell(s.c_str(), icon, 3, false)); + row->push_back(new GUIEngine::ListWidget::ListCell(addon->getDateAsString().c_str(), -1, 1, true)); w_list->addItem(addon->getId(), row); // Highlight if it's not approved in artists debug mode. Modified: main/branches/uni/src/states_screens/server_selection.cpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.cpp 2013-07-14 22:09:06 UTC (rev 13220) +++ main/branches/uni/src/states_screens/server_selection.cpp 2013-07-14 22:24:06 UTC (rev 13221) @@ -109,7 +109,7 @@ num_players.append(StringUtils::toWString(server->getMaxPlayers())); PtrVector<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>; row->push_back(new GUIEngine::ListWidget::ListCell(server->getName(),-1,3)); - row->push_back(new GUIEngine::ListWidget::ListCell(num_players,-1,1)); + row->push_back(new GUIEngine::ListWidget::ListCell(num_players,-1,1,true)); m_server_list_widget->addItem("server", row); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-15 00:25:58
|
Revision: 13224 http://sourceforge.net/p/supertuxkart/code/13224 Author: unitraxx Date: 2013-07-15 00:25:56 +0000 (Mon, 15 Jul 2013) Log Message: ----------- You need to sign in now, for the features where it's needed. Also made a temporary implementation for quick play. Modified Paths: -------------- main/branches/uni/src/online/servers_manager.cpp main/branches/uni/src/online/servers_manager.hpp main/branches/uni/src/states_screens/online_screen.cpp Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-14 22:54:45 UTC (rev 13223) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-15 00:25:56 UTC (rev 13224) @@ -69,3 +69,11 @@ } //FIXME error message } + +// ============================================================================ +Server * ServersManager::getQuickPlay() +{ + if(m_servers->size() > 0) + return m_servers->get(0); + return NULL; +} Modified: main/branches/uni/src/online/servers_manager.hpp =================================================================== --- main/branches/uni/src/online/servers_manager.hpp 2013-07-14 22:54:45 UTC (rev 13223) +++ main/branches/uni/src/online/servers_manager.hpp 2013-07-15 00:25:56 UTC (rev 13224) @@ -49,6 +49,8 @@ void sort(bool sort_desc) { m_servers->insertionSort(0, sort_desc); }; void setJoinedServer(Server * server){ m_joined_server = server;}; Server * getJoinedServer(){ return m_joined_server;}; + //Returns the best server to join + Server * getQuickPlay(); }; // class ServersManager #endif Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-14 22:54:45 UTC (rev 13223) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-15 00:25:56 UTC (rev 13224) @@ -22,8 +22,7 @@ #include <string> #include <iostream> -#include "challenges/game_slot.hpp" -#include "challenges/unlock_manager.hpp" +#include "audio/sfx_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/scalable_font.hpp" #include "input/device_manager.hpp" @@ -39,10 +38,11 @@ #include "states_screens/server_selection.hpp" #include "modes/demo_world.hpp" #include "utils/translation.hpp" - #include "online/current_online_user.hpp" +#include "online/servers_manager.hpp" + using namespace GUIEngine; DEFINE_SCREEN_SINGLETON( OnlineScreen ); @@ -136,7 +136,7 @@ { Screen::init(); setInitialFocus(); - DemoWorld::resetIdleTime(); //FIXME : what's this? + DemoWorld::resetIdleTime(); m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + CurrentOnlineUser::get()->getUserName() + ".", false); } // init @@ -186,12 +186,21 @@ } else if (selection == "create_server") { - //if (m_recorded_state == Registered) StateManager::get()->pushScreen(NetworkingLobbySettings::getInstance()); } else if (selection == "quick_play") { - //if (m_recorded_state == Registered || m_recorded_state == Guest) FIXME + //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)) + { + ServersManager::get()->setJoinedServer(server); + } + else + { + sfx_manager->quickSound( "anvil" ); + } StateManager::get()->pushScreen(NetworkingLobby::getInstance()); } @@ -208,18 +217,15 @@ { if (item == "find_server") { - StateManager::get()->pushScreen(ServerSelection::getInstance()); - // FIXME new LoginDialog(LoginDialog::Registration_Required); + new LoginDialog(LoginDialog::Registration_Required); } else if (item =="create_server") { - StateManager::get()->pushScreen(NetworkingLobbySettings::getInstance()); - // FIXME temporary; new LoginDialog(LoginDialog::Registration_Required); + new LoginDialog(LoginDialog::Registration_Required); } else if (item == "quick_play") { - StateManager::get()->pushScreen(NetworkingLobby::getInstance()); - // FIXME temporary; new LoginDialog(LoginDialog::Signing_In_Required); + new LoginDialog(LoginDialog::Signing_In_Required); } } // onDisabledItemClicked This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-15 00:37:07
|
Revision: 13226 http://sourceforge.net/p/supertuxkart/code/13226 Author: unitraxx Date: 2013-07-15 00:37:05 +0000 (Mon, 15 Jul 2013) Log Message: ----------- Removed the addons_screen references to the tab_stop method which were left behind Modified Paths: -------------- main/branches/uni/src/guiengine/scalable_font.cpp main/branches/uni/src/guiengine/scalable_font.hpp main/branches/uni/src/states_screens/addons_screen.cpp Modified: main/branches/uni/src/guiengine/scalable_font.cpp =================================================================== --- main/branches/uni/src/guiengine/scalable_font.cpp 2013-07-15 00:32:19 UTC (rev 13225) +++ main/branches/uni/src/guiengine/scalable_font.cpp 2013-07-15 00:37:05 UTC (rev 13226) @@ -32,7 +32,6 @@ m_fallback_kerning_width = 0; m_fallback_font_scale = 1.0f; m_scale = 1.0f; - m_tab_stop = 0.5f; m_is_hollow_copy = false; m_black_border = false; m_shadow = false; Modified: main/branches/uni/src/guiengine/scalable_font.hpp =================================================================== --- main/branches/uni/src/guiengine/scalable_font.hpp 2013-07-15 00:32:19 UTC (rev 13225) +++ main/branches/uni/src/guiengine/scalable_font.hpp 2013-07-15 00:37:05 UTC (rev 13226) @@ -61,9 +61,6 @@ bool m_is_hollow_copy; bool m_rtl; - /** Position in range [0..1] of the single tab stop we support */ - float m_tab_stop; - public: LEAK_CHECK() @@ -145,9 +142,6 @@ void updateRTL(); - /** \param pos position of the tab stop, in range [0..1] */ - void setTabStop(float pos) { m_tab_stop = pos; } - private: struct SFontArea Modified: main/branches/uni/src/states_screens/addons_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/addons_screen.cpp 2013-07-15 00:32:19 UTC (rev 13225) +++ main/branches/uni/src/states_screens/addons_screen.cpp 2013-07-15 00:37:05 UTC (rev 13226) @@ -140,8 +140,6 @@ getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated(); - GUIEngine::getFont()->setTabStop(0.66f); - if(UserConfigParams::logAddons()) std::cout << "[addons] Using directory <" + file_manager->getAddonsDir() << ">\n"; @@ -188,8 +186,6 @@ void AddonsScreen::tearDown() { - // return tab stop to the center when leaving this screen!! - GUIEngine::getFont()->setTabStop(0.5f); } // ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-15 01:20:08
|
Revision: 13228 http://sourceforge.net/p/supertuxkart/code/13228 Author: unitraxx Date: 2013-07-15 01:20:06 +0000 (Mon, 15 Jul 2013) Log Message: ----------- Fixed issue that requesting to join a server signed you out. Modified Paths: -------------- main/branches/uni/src/online/current_online_user.cpp main/branches/uni/src/states_screens/online_screen.cpp Modified: main/branches/uni/src/online/current_online_user.cpp =================================================================== --- main/branches/uni/src/online/current_online_user.cpp 2013-07-15 00:56:29 UTC (rev 13227) +++ main/branches/uni/src/online/current_online_user.cpp 2013-07-15 01:20:06 UTC (rev 13228) @@ -244,13 +244,12 @@ { if (rec_success =="yes") { - m_token = ""; - m_name = ""; - m_id = 0; - m_is_signed_in = false; - m_is_guest = false; success = true; } + else + { + success = false; + } result->get("info", &info); } else Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-15 00:56:29 UTC (rev 13227) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-15 01:20:06 UTC (rev 13228) @@ -196,12 +196,12 @@ if (CurrentOnlineUser::get()->requestJoin( server->getServerId(), info)) { ServersManager::get()->setJoinedServer(server); + StateManager::get()->pushScreen(NetworkingLobby::getInstance()); } else { sfx_manager->quickSound( "anvil" ); } - StateManager::get()->pushScreen(NetworkingLobby::getInstance()); } } // eventCallback This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-18 22:49:22
|
Revision: 13276 http://sourceforge.net/p/supertuxkart/code/13276 Author: unitraxx Date: 2013-07-18 22:49:19 +0000 (Thu, 18 Jul 2013) Log Message: ----------- Signin in now fully uses asynchronous http requesting. Implemented a nice "loading dots" gimmick for loading. Modified Paths: -------------- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp main/branches/uni/src/states_screens/dialogs/login_dialog.hpp main/branches/uni/src/utils/string_utils.cpp main/branches/uni/src/utils/string_utils.hpp Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-18 22:46:46 UTC (rev 13275) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-18 22:49:19 UTC (rev 13276) @@ -39,6 +39,7 @@ { m_self_destroy = false; m_open_registration_dialog = false; + m_load_timer = 0.0f; m_signin_request = NULL; loadFromFile("online/login_dialog.stkgui"); @@ -94,6 +95,7 @@ LoginDialog::~LoginDialog() { + delete m_signin_request; } @@ -115,6 +117,8 @@ const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER); if (selection == m_cancel_widget->m_properties[PROP_ID]) { + if(m_signin_request != NULL) + m_signin_request->cancel(); m_self_destroy = true; return GUIEngine::EVENT_BLOCK; } @@ -150,13 +154,12 @@ { 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; + m_self_destroy = true; } else { @@ -165,7 +168,14 @@ m_message_widget->setColor(irr::video::SColor(255, 255, 0, 0)); m_message_widget->setText(info, false); } + delete m_signin_request; + m_signin_request = NULL; } + else + { + m_load_timer += dt; + m_message_widget->setText(irr::core::stringw(_("Signing in")) + StringUtils::loadingDots(m_load_timer), false); + } } //If we want to open the registration dialog, we need to close this one first Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-18 22:46:46 UTC (rev 13275) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-18 22:49:19 UTC (rev 13276) @@ -24,11 +24,7 @@ #include "online/current_user.hpp" #include "guiengine/modaldialog.hpp" -#include "guiengine/widgets/text_box_widget.hpp" -#include "guiengine/widgets/check_box_widget.hpp" -#include "guiengine/widgets/icon_button_widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "guiengine/widgets/label_widget.hpp" +#include "guiengine/widgets.hpp" /** * \brief Dialog that allows a user to sign in @@ -58,6 +54,8 @@ void login(); + float m_load_timer; + public: enum Message Modified: main/branches/uni/src/utils/string_utils.cpp =================================================================== --- main/branches/uni/src/utils/string_utils.cpp 2013-07-18 22:46:46 UTC (rev 13275) +++ main/branches/uni/src/utils/string_utils.cpp 2013-07-18 22:49:19 UTC (rev 13276) @@ -709,6 +709,14 @@ printf("Invalid version string '%s'.\n", s.c_str()); return version; } // versionToInt + + // ------------------------------------------------------------------------ + + irr::core::stringw loadingDots(float time, bool spaces, float interval, int max_dots) + { + int nr_dots = int(floor(time * (1 / interval))) % (max_dots+1); + return irr::core::stringw((std::string(nr_dots,'.') + std::string(max_dots-nr_dots,' ')).c_str()); + } } // namespace StringUtils Modified: main/branches/uni/src/utils/string_utils.hpp =================================================================== --- main/branches/uni/src/utils/string_utils.hpp 2013-07-18 22:46:46 UTC (rev 13275) +++ main/branches/uni/src/utils/string_utils.hpp 2013-07-18 22:49:19 UTC (rev 13276) @@ -413,6 +413,9 @@ /** Compute a simple hash of a string */ unsigned int simpleHash(const char* input); + + + irr::core::stringw loadingDots(float time, bool spaces = true, float interval = 0.5f, int max_dots = 3); } // namespace StringUtils #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-18 23:02:20
|
Revision: 13279 http://sourceforge.net/p/supertuxkart/code/13279 Author: unitraxx Date: 2013-07-18 23:02:18 +0000 (Thu, 18 Jul 2013) Log Message: ----------- Added Server and ServersManager to the online namespace and edited everything that uses those. Modified Paths: -------------- main/branches/uni/src/online/server.cpp main/branches/uni/src/online/server.hpp main/branches/uni/src/online/servers_manager.cpp main/branches/uni/src/online/servers_manager.hpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp main/branches/uni/src/states_screens/networking_lobby.cpp main/branches/uni/src/states_screens/networking_lobby.hpp main/branches/uni/src/states_screens/online_screen.cpp main/branches/uni/src/states_screens/server_selection.cpp Modified: main/branches/uni/src/online/server.cpp =================================================================== --- main/branches/uni/src/online/server.cpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/online/server.cpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -24,49 +24,51 @@ #include "utils/constants.hpp" #include "utils/string_utils.hpp" -Server::SortOrder Server::m_sort_order=Server::SO_NAME; //FIXME change to some other default +namespace online{ + Server::SortOrder Server::m_sort_order=Server::SO_NAME; //FIXME change to some other default -Server::Server(const XMLNode & xml) -{ - assert(xml.getName() == "server"); - m_name = ""; - m_satisfaction_score = 0; - m_server_id = 0; - m_current_players = 0; - m_max_players = 0; + Server::Server(const XMLNode & xml) + { + assert(xml.getName() == "server"); + m_name = ""; + m_satisfaction_score = 0; + m_server_id = 0; + m_current_players = 0; + m_max_players = 0; - xml.get("name", &m_lower_case_name); - m_name = StringUtils::decodeFromHtmlEntities(m_lower_case_name); - m_lower_case_name = StringUtils::toLowerCase(m_lower_case_name); + xml.get("name", &m_lower_case_name); + m_name = StringUtils::decodeFromHtmlEntities(m_lower_case_name); + m_lower_case_name = StringUtils::toLowerCase(m_lower_case_name); - xml.get("id", &m_server_id); - xml.get("max_players", &m_max_players); - xml.get("current_players", &m_current_players); + xml.get("id", &m_server_id); + xml.get("max_players", &m_max_players); + xml.get("current_players", &m_current_players); -}; // Server(const XML&) + }; // Server(const XML&) -// ---------------------------------------------------------------------------- -/** - * \brief Filter the add-on with a list of words. - * \param words A list of words separated by ' '. - * \return true if the add-on contains one of the words, otherwise false. - */ -bool Server::filterByWords(const core::stringw words) const -{ - if (words == NULL || words.empty()) - return true; + // ---------------------------------------------------------------------------- + /** + * \brief Filter the add-on with a list of words. + * \param words A list of words separated by ' '. + * \return true if the add-on contains one of the words, otherwise false. + */ + bool Server::filterByWords(const core::stringw words) const + { + if (words == NULL || words.empty()) + return true; - std::vector<core::stringw> list = StringUtils::split(words, ' ', false); + std::vector<core::stringw> list = StringUtils::split(words, ' ', false); - for (unsigned int i = 0; i < list.size(); i++) - { - list[i].make_lower(); - - if ((core::stringw(m_name).make_lower()).find(list[i].c_str()) != -1) + for (unsigned int i = 0; i < list.size(); i++) { - return true; + list[i].make_lower(); + + if ((core::stringw(m_name).make_lower()).find(list[i].c_str()) != -1) + { + return true; + } } - } - - return false; -} // filterByWords + + return false; + } // filterByWords +} // namespace online Modified: main/branches/uni/src/online/server.hpp =================================================================== --- main/branches/uni/src/online/server.hpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/online/server.hpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -31,104 +31,105 @@ class XMLNode; -/** - * \ingroup online - */ -class Server -{ -public: +namespace online{ + /** + * \ingroup online + */ + class Server + { + public: - /** Set the sort order used in the comparison function. */ - enum SortOrder { SO_SCORE = 1, // Sorted on satisfaction score - SO_NAME = 2, // Sorted alphabetically by name - SO_PLAYERS = 4 - }; + /** Set the sort order used in the comparison function. */ + enum SortOrder { SO_SCORE = 1, // Sorted on satisfaction score + SO_NAME = 2, // Sorted alphabetically by name + SO_PLAYERS = 4 + }; -protected: - /** The name to be displayed. */ - irr::core::stringw m_name; - std::string m_lower_case_name; //Used for comparison + protected: + /** The name to be displayed. */ + irr::core::stringw m_name; + std::string m_lower_case_name; //Used for comparison - uint32_t m_server_id; + uint32_t m_server_id; - int m_max_players; + int m_max_players; - int m_current_players; + int m_current_players; - float m_satisfaction_score; + float m_satisfaction_score; - /** The sort order to be used in the comparison. */ - static SortOrder m_sort_order; + /** The sort order to be used in the comparison. */ + static SortOrder m_sort_order; - Server() {}; + Server() {}; -public: + public: + + /** Initialises the object from an XML node. */ + Server(const XMLNode & xml); + // ------------------------------------------------------------------------ + /** Sets the sort order used in the comparison function. It is static, so + * that each instance can access the sort order. */ + static void setSortOrder(SortOrder so) { m_sort_order = so; } + // ------------------------------------------------------------------------ + /** Returns the name of the server. */ + const irr::core::stringw& getName() const { return m_name; } + const std::string & getLowerCaseName() const { return m_lower_case_name; } + // ------------------------------------------------------------------------ + const float getScore() const { return m_satisfaction_score; } + // ------------------------------------------------------------------------ + /** Returns the ID of this server. */ + const uint32_t getServerId() const { return m_server_id; } + const int getMaxPlayers() const { return m_max_players; } + const int getCurrentPlayers() const { return m_current_players; } + // ------------------------------------------------------------------------ + bool filterByWords(const irr::core::stringw words) const; + // ------------------------------------------------------------------------ - /** Initialises the object from an XML node. */ - Server(const XMLNode & xml); - // ------------------------------------------------------------------------ - /** Sets the sort order used in the comparison function. It is static, so - * that each instance can access the sort order. */ - static void setSortOrder(SortOrder so) { m_sort_order = so; } - // ------------------------------------------------------------------------ - /** Returns the name of the server. */ - const irr::core::stringw& getName() const { return m_name; } - const std::string & getLowerCaseName() const { return m_lower_case_name; } - // ------------------------------------------------------------------------ - const float getScore() const { return m_satisfaction_score; } - // ------------------------------------------------------------------------ - /** Returns the ID of this server. */ - const uint32_t getServerId() const { return m_server_id; } - const int getMaxPlayers() const { return m_max_players; } - const int getCurrentPlayers() const { return m_current_players; } - // ------------------------------------------------------------------------ - bool filterByWords(const irr::core::stringw words) const; - // ------------------------------------------------------------------------ - - /** Compares two servers according to the sort order currently defined. - * \param a The addon to compare this addon to. - */ - bool operator<(const Server &server) const - { - switch(m_sort_order) + /** Compares two servers according to the sort order currently defined. + * \param a The addon to compare this addon to. + */ + bool operator<(const Server &server) const { - case SO_SCORE: - return m_satisfaction_score < server.getScore(); - break; - case SO_NAME: - // m_id is the lower case name - return m_name < server.getName(); - break; - case SO_PLAYERS: - return m_current_players < server.getCurrentPlayers(); - break; - } // switch - return true; - } // operator< + switch(m_sort_order) + { + case SO_SCORE: + return m_satisfaction_score < server.getScore(); + break; + case SO_NAME: + // m_id is the lower case name + return m_name < server.getName(); + break; + case SO_PLAYERS: + return m_current_players < server.getCurrentPlayers(); + break; + } // switch + return true; + } // operator< - // ------------------------------------------------------------------------ - /** Compares two addons according to the sort order currently defined. - * Comparison is done for sorting in descending order. - * \param a The addon to compare this addon to. - */ - bool operator>(const Server &server) const - { - switch(m_sort_order) + // ------------------------------------------------------------------------ + /** Compares two addons according to the sort order currently defined. + * Comparison is done for sorting in descending order. + * \param a The addon to compare this addon to. + */ + bool operator>(const Server &server) const { - case SO_SCORE: - return m_satisfaction_score > server.getScore(); - break; - case SO_NAME: - return m_lower_case_name > server.getLowerCaseName(); - break; - case SO_PLAYERS: - return m_current_players > server.getCurrentPlayers(); - break; - } // switch - return true; - } // operator> + switch(m_sort_order) + { + case SO_SCORE: + return m_satisfaction_score > server.getScore(); + break; + case SO_NAME: + return m_lower_case_name > server.getLowerCaseName(); + break; + case SO_PLAYERS: + return m_current_players > server.getCurrentPlayers(); + break; + } // switch + return true; + } // operator> -}; // Server + }; // Server +} // namespace online - #endif Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -26,54 +26,57 @@ #include "config/user_config.hpp" #include "utils/translation.hpp" -static ServersManager* user_singleton = NULL; +namespace online{ -ServersManager* ServersManager::get() -{ - if (user_singleton == NULL) - user_singleton = new ServersManager(); - return user_singleton; -} // get + static ServersManager* user_singleton = NULL; -void ServersManager::deallocate() -{ - delete user_singleton; - user_singleton = NULL; -} // deallocate + ServersManager* ServersManager::get() + { + if (user_singleton == NULL) + user_singleton = new ServersManager(); + return user_singleton; + } // get -// ============================================================================ -ServersManager::ServersManager(){ - m_servers = new PtrVector<Server>; - refresh(); -} + void ServersManager::deallocate() + { + delete user_singleton; + user_singleton = NULL; + } // deallocate -// ============================================================================ -void ServersManager::refresh() -{ - HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); - connector->setParameter("action",std::string("get_server_list")); + // ============================================================================ + ServersManager::ServersManager(){ + m_servers = new PtrVector<Server>; + refresh(); + } - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success = ""; - if(result->get("success", &rec_success)) + // ============================================================================ + void ServersManager::refresh() { - if (rec_success =="yes") + HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + connector->setParameter("action",std::string("get_server_list")); + + const XMLNode * result = connector->getXMLFromPage(); + std::string rec_success = ""; + if(result->get("success", &rec_success)) { - const XMLNode * servers_xml = result->getNode("servers"); - m_servers->clearAndDeleteAll(); - for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++) + if (rec_success =="yes") { - m_servers->push_back(new Server(*servers_xml->getNode(i))); + const XMLNode * servers_xml = result->getNode("servers"); + m_servers->clearAndDeleteAll(); + for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++) + { + m_servers->push_back(new Server(*servers_xml->getNode(i))); + } } } + //FIXME error message } - //FIXME error message -} -// ============================================================================ -Server * ServersManager::getQuickPlay() -{ - if(m_servers->size() > 0) - return m_servers->get(0); - return NULL; -} + // ============================================================================ + Server * ServersManager::getQuickPlay() + { + if(m_servers->size() > 0) + return m_servers->get(0); + return NULL; + } +} // namespace online Modified: main/branches/uni/src/online/servers_manager.hpp =================================================================== --- main/branches/uni/src/online/servers_manager.hpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/online/servers_manager.hpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -23,36 +23,40 @@ #include "online/server.hpp" -// ============================================================================ +namespace online { -/** - * \brief - * \ingroup online - */ -class ServersManager -{ - private: - ServersManager(); - PtrVector<Server> * m_servers; - bool m_not_fetched; - Server * m_joined_server; + /** + * \brief + * \ingroup online + */ + class ServersManager + { + private: + ServersManager(); + PtrVector<Server> * m_servers; + bool m_not_fetched; + Server * m_joined_server; - public: - // singleton - static ServersManager* get(); - static void deallocate(); + public: + // singleton + static ServersManager* get(); + static void deallocate(); - void refresh(); - PtrVector<Server> * getServers () const { return m_servers; }; - int getNumServers () const { return m_servers->size(); }; - Server * getServer (int index) const { return m_servers->get(index);}; - void sort(bool sort_desc) { m_servers->insertionSort(0, sort_desc); }; - void setJoinedServer(Server * server){ m_joined_server = server;}; - Server * getJoinedServer(){ return m_joined_server;}; - //Returns the best server to join - Server * getQuickPlay(); -}; // class ServersManager + void refresh(); + PtrVector<Server> * getServers () const { return m_servers; }; + int getNumServers () const { return m_servers->size(); }; + Server * getServer (int index) const { return m_servers->get(index);}; + void sort(bool sort_desc) { m_servers->insertionSort(0, sort_desc); }; + void setJoinedServer(Server * server){ m_joined_server = server;}; + Server * getJoinedServer(){ return m_joined_server;}; + //Returns the best server to join + Server * getQuickPlay(); + }; // class ServersManager + +} // namespace online + + #endif /*EOF*/ Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -34,6 +34,7 @@ using namespace GUIEngine; using namespace irr; using namespace irr::gui; +using namespace online; // ----------------------------------------------------------------------------- Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -26,6 +26,8 @@ #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/label_widget.hpp" #include "online/server.hpp" + + /** * \brief Dialog that allows a user to sign in * \ingroup states_screens @@ -38,7 +40,7 @@ bool m_self_destroy; bool m_enter_lobby; - Server * m_server; + online::Server * m_server; GUIEngine::LabelWidget * m_name_widget; GUIEngine::LabelWidget * m_info_widget; @@ -50,7 +52,7 @@ void requestJoin(); public: - ServerInfoDialog(Server * server); + ServerInfoDialog(online::Server * server); ~ServerInfoDialog(); void onEnterPressedInternal(); Modified: main/branches/uni/src/states_screens/networking_lobby.cpp =================================================================== --- main/branches/uni/src/states_screens/networking_lobby.cpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/states_screens/networking_lobby.cpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -37,7 +37,7 @@ #include "utils/translation.hpp" #include "online/servers_manager.hpp" - +using namespace online; using namespace GUIEngine; DEFINE_SCREEN_SINGLETON( NetworkingLobby ); Modified: main/branches/uni/src/states_screens/networking_lobby.hpp =================================================================== --- main/branches/uni/src/states_screens/networking_lobby.hpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/states_screens/networking_lobby.hpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -36,7 +36,7 @@ private: friend class GUIEngine::ScreenSingleton<NetworkingLobby>; - Server * m_server; + online::Server * m_server; NetworkingLobby(); Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -44,6 +44,7 @@ using namespace GUIEngine; +using namespace online; DEFINE_SCREEN_SINGLETON( OnlineScreen ); Modified: main/branches/uni/src/states_screens/server_selection.cpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.cpp 2013-07-18 22:58:40 UTC (rev 13278) +++ main/branches/uni/src/states_screens/server_selection.cpp 2013-07-18 23:02:18 UTC (rev 13279) @@ -29,6 +29,8 @@ #include "utils/string_utils.hpp" #include "online/servers_manager.hpp" +using namespace online; + DEFINE_SCREEN_SINGLETON( ServerSelection ); // ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-19 22:12:39
|
Revision: 13291 http://sourceforge.net/p/supertuxkart/code/13291 Author: unitraxx Date: 2013-07-19 22:12:36 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Fix. Asynchronous calls can now have callbacks. Thead-safeness improved. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/online/request.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/states_screens/dialogs/login_dialog.cpp main/branches/uni/src/states_screens/dialogs/login_dialog.hpp main/branches/uni/src/states_screens/online_screen.cpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/online/current_user.cpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -146,14 +146,13 @@ // ============================================================================ - void 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; - XMLRequest * request = new XMLRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); - request->setListener(this, CurrentUser::SIGN_IN_REQUEST); + CurrentUser::SignInRequest * request = new CurrentUser::SignInRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action",std::string("connect")); request->setParameter("username",username); request->setParameter("password",password); @@ -162,9 +161,10 @@ assert(false); } m_state = SIGNING_IN; + return request; } - bool CurrentUser::signIn(XMLRequest * input) + void CurrentUser::signIn(SignInRequest * input) { const XMLNode * xml = input->getResult(); bool success = false; @@ -194,10 +194,16 @@ info = _("Unable to connect to the server. Check your internet connection or try again later."); } input->setInfo(info); + input->setSuccess(success); if(!success) m_state = SIGNED_OUT; - return success; } + void CurrentUser::SignInRequest::callback() + { + CurrentUser::acquire()->signIn(this); + CurrentUser::release(); + } + // ============================================================================ XMLRequest * CurrentUser::createServerRequest ( const irr::core::stringw &name, int max_players) @@ -310,21 +316,4 @@ return _("Currently not signed in"); } - - // ============================================================================ - - - void CurrentUser::onHTTPCallback(HTTPRequest * finished_request) - { - XMLRequest * input = (XMLRequest *) finished_request; - - switch(finished_request->getListenerTarget()) - { - case CurrentUser::SIGN_IN_REQUEST: - signIn(input); - break; - default: - break; - } - } } // namespace Online Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/online/current_user.hpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -34,7 +34,7 @@ * \brief Class that represents an online registered user * \ingroup online */ - class CurrentUser : public User, HTTPListener + class CurrentUser : public User { public: @@ -47,17 +47,21 @@ SIGNING_OUT }; + class SignInRequest : public XMLRequest + { + protected : + virtual void callback (); + public : + SignInRequest(const std::string &url) : XMLRequest(url) {} + }; + private: - enum RequestType{ - SIGN_IN_REQUEST - }; - std::map<int, std::pair<bool, irr::core::stringw> > m_http_results; std::string m_token; bool m_save_session; UserState m_state; CurrentUser(); - bool signIn(XMLRequest * input); + void signIn(SignInRequest * input); public: @@ -70,9 +74,9 @@ bool trySavedSession(); // Login - void requestSignIn( const irr::core::stringw &username, - const irr::core::stringw &password, - bool save_session); + SignInRequest * requestSignIn( const irr::core::stringw &username, + const irr::core::stringw &password, + bool save_session); // Register bool signUp( const irr::core::stringw &username, Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/online/request.cpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -32,6 +32,7 @@ m_priority = priority; m_manage_memory = manage_memory; m_cancel = false; + m_done.setAtomic(false); } // Request Request::~Request() @@ -45,6 +46,11 @@ afterOperation(); } + void Request::afterOperation() + { + m_done.setAtomic(true); + } + // ========================================================================================= QuitRequest::QuitRequest() @@ -62,26 +68,14 @@ m_parameters = new Parameters; m_progress.setAtomic(0); m_added = false; - m_done.setAtomic(false); - m_listener.setAtomic(NULL); - m_listener_target = 0; + m_info = ""; + m_success = false; } HTTPRequest::~HTTPRequest() { delete m_parameters; - m_listener.lock(); - if (m_listener.getData() != NULL) - { - delete m_listener.getData(); - } - m_listener.unlock(); } - void HTTPRequest::setListener(Synchronised<HTTPListener *> listener, int target) - { - m_listener = listener; - m_listener_target = 0; - } bool HTTPRequest::isAllowedToAdd() { @@ -95,10 +89,8 @@ void HTTPRequest::afterOperation() { - if (m_listener != NULL) - { - m_listener->onHTTPCallback(this); - } + callback(); + Request::afterOperation(); } std::string HTTPRequest::downloadPage() Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/online/request.hpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -23,7 +23,6 @@ #include "utils/string_utils.hpp" #include "utils/synchronised.hpp" #include "io/file_manager.hpp" -#include "online/http_listener.hpp" namespace Online{ @@ -47,9 +46,11 @@ * be freed by the calling function. */ bool m_manage_memory; + Synchronised<bool> m_done; + virtual void beforeOperation() {} virtual void operation() = 0; - virtual void afterOperation() {} + virtual void afterOperation(); public: @@ -75,6 +76,8 @@ * by network_http (i.e. freed once the request is handled). */ bool manageMemory() const { return m_manage_memory; } + bool isDone(){return m_done.getAtomic();} + virtual bool isAllowedToAdd() {return true;} /** This class is used by the priority queue to sort requests by priority. @@ -116,11 +119,9 @@ * packet is downloaded. At the end eithe -1 (error) or 1 * (everything ok) at the end. */ Synchronised<float> m_progress; - Synchronised<bool> m_done; std::string m_url; bool m_added; - Synchronised<HTTPListener *> m_listener; - int m_listener_target; + bool m_success; /** * info to show on screen if necessary */ @@ -139,6 +140,7 @@ size_t size, size_t nmemb, void *userp); + virtual void callback() {} public : @@ -167,13 +169,13 @@ void setInfo(const irr::core::stringw & info) {m_info = info;} const irr::core::stringw & getInfo() {return m_info;} + void setSuccess(bool success = true){ m_success = success; } + bool isSuccess(){ return m_success; } + const std::string &getURL() const {return m_url;} virtual bool isAllowedToAdd() OVERRIDE; - virtual void setListener(Synchronised<HTTPListener *> listener, int target = 0); - int getListenerTarget(){ return m_listener_target; } - }; class XMLRequest : public HTTPRequest Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -26,6 +26,7 @@ #include "utils/translation.hpp" #include "utils/string_utils.hpp" #include "states_screens/dialogs/registration_dialog.hpp" +#include "online/messages.hpp" using namespace GUIEngine; @@ -39,6 +40,8 @@ { m_self_destroy = false; m_open_registration_dialog = false; + m_load_timer = 0; + m_sign_in_request = NULL; loadFromFile("online/login_dialog.stkgui"); m_info_widget = getWidget<LabelWidget>("info"); @@ -93,6 +96,7 @@ LoginDialog::~LoginDialog() { + delete m_sign_in_request; } @@ -102,9 +106,8 @@ { const stringw username = m_username_widget->getText().trim(); const stringw password = m_password_widget->getText().trim(); - Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState()); + m_sign_in_request = Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState()); Online::CurrentUser::release(); - m_self_destroy = true; } // ----------------------------------------------------------------------------- @@ -149,7 +152,29 @@ void LoginDialog::onUpdate(float dt) { - + if(m_sign_in_request != NULL) + { + if(m_sign_in_request->isDone()) + { + if(m_sign_in_request->isSuccess()) + { + m_self_destroy = true; + } + else + { + sfx_manager->quickSound( "anvil" ); + m_message_widget->setColor(irr::video::SColor(255, 255, 0, 0)); + m_message_widget->setText(m_sign_in_request->getInfo(), false); + } + delete m_sign_in_request; + m_sign_in_request = NULL; + } + else + { + m_load_timer += dt; + m_message_widget->setText(Online::Messages::signingIn(m_load_timer), false); + } + } //If we want to open the registration dialog, we need to close this one first m_open_registration_dialog && (m_self_destroy = true); Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -37,6 +37,8 @@ bool m_self_destroy; bool m_open_registration_dialog; + float m_load_timer; + Online::CurrentUser::SignInRequest * m_sign_in_request; GUIEngine::LabelWidget * m_info_widget; GUIEngine::TextBoxWidget * m_username_widget; Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-19 21:20:32 UTC (rev 13290) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-19 22:12:36 UTC (rev 13291) @@ -107,13 +107,13 @@ m_register_widget->setVisible(false); m_sign_in_widget->setVisible(false); } - else if (m_recorded_state == CurrentUser::SIGNED_OUT || CurrentUser::SIGNING_IN || CurrentUser::SIGNING_OUT) + else if (m_recorded_state == CurrentUser::SIGNED_OUT || m_recorded_state == CurrentUser::SIGNING_IN || m_recorded_state == CurrentUser::SIGNING_OUT) { m_quick_play_widget->setDeactivated(); m_find_server_widget->setDeactivated(); m_create_server_widget->setDeactivated(); m_sign_out_widget->setVisible(false); - if(CurrentUser::SIGNING_IN || CurrentUser::SIGNING_OUT) + if(m_recorded_state == CurrentUser::SIGNING_IN || m_recorded_state == CurrentUser::SIGNING_OUT) { m_register_widget->setDeactivated(); m_sign_in_widget->setDeactivated(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-19 22:41:58
|
Revision: 13292 http://sourceforge.net/p/supertuxkart/code/13292 Author: unitraxx Date: 2013-07-19 22:41:54 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Automatically signing in, is now very smooth. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/states_screens/online_screen.cpp main/branches/uni/src/states_screens/online_screen.hpp Removed Paths: ------------- main/branches/uni/src/online/http_listener.hpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-19 22:12:36 UTC (rev 13291) +++ main/branches/uni/src/online/current_user.cpp 2013-07-19 22:41:54 UTC (rev 13292) @@ -76,43 +76,6 @@ } // ============================================================================ - 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, const irr::core::stringw &password, @@ -143,12 +106,31 @@ 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 @@ 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); Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-19 22:12:36 UTC (rev 13291) +++ main/branches/uni/src/online/current_user.hpp 2013-07-19 22:41:54 UTC (rev 13292) @@ -72,8 +72,8 @@ 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 @@ 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 Deleted: main/branches/uni/src/online/http_listener.hpp =================================================================== --- main/branches/uni/src/online/http_listener.hpp 2013-07-19 22:12:36 UTC (rev 13291) +++ main/branches/uni/src/online/http_listener.hpp 2013-07-19 22:41:54 UTC (rev 13292) @@ -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*/ Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-19 22:12:36 UTC (rev 13291) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-19 22:41:54 UTC (rev 13292) @@ -52,12 +52,19 @@ 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::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::onDialogClose() { - /*if (hasStateChanged()) + if (hasStateChanged()) GUIEngine::reshowCurrentScreen(); - else*/ + else setInitialFocus(); } // onDialogClose() Modified: main/branches/uni/src/states_screens/online_screen.hpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.hpp 2013-07-19 22:12:36 UTC (rev 13291) +++ main/branches/uni/src/states_screens/online_screen.hpp 2013-07-19 22:41:54 UTC (rev 13292) @@ -37,6 +37,7 @@ friend class GUIEngine::ScreenSingleton<OnlineScreen>; OnlineScreen(); + ~OnlineScreen(); GUIEngine::RibbonWidget * m_top_menu_widget; GUIEngine::IconButtonWidget * m_quick_play_widget; @@ -53,6 +54,7 @@ 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(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-20 01:38:46
|
Revision: 13293 http://sourceforge.net/p/supertuxkart/code/13293 Author: unitraxx Date: 2013-07-20 01:38:44 +0000 (Sat, 20 Jul 2013) Log Message: ----------- Signing out is now also asynchronous. Made the extending of the requests easier. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/online/http_manager.cpp main/branches/uni/src/online/http_manager.hpp main/branches/uni/src/online/request.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/states_screens/online_screen.cpp main/branches/uni/src/states_screens/online_screen.hpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/online/current_user.cpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -112,14 +112,12 @@ 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 = new CurrentUser::SignInRequest(); + request->setURL((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); - } + HTTPManager::get()->addRequest(request); m_state = SIGNING_IN; } return request; @@ -134,14 +132,12 @@ { assert(m_state == SIGNED_OUT); m_save_session = save_session; - CurrentUser::SignInRequest * request = new CurrentUser::SignInRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + CurrentUser::SignInRequest * request = new CurrentUser::SignInRequest(); + request->setURL((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); - } + HTTPManager::get()->addRequest(request); m_state = SIGNING_IN; return request; } @@ -192,14 +188,14 @@ XMLRequest * CurrentUser::createServerRequest ( const irr::core::stringw &name, int max_players) { assert(m_state == SIGNED_IN); - XMLRequest * request = new XMLRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + XMLRequest * request = NULL;//new XMLRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action", std::string("create_server")); request->setParameter("token", m_token); request->setParameter("userid", m_id); request->setParameter("name", name); request->setParameter("max_players", max_players); - if(!HTTPManager::get()->addRequest(request)) - assert(false); + HTTPManager::get()->addRequest(request); return request; } @@ -226,38 +222,48 @@ // ============================================================================ - bool CurrentUser::signOut(irr::core::stringw &info){ + CurrentUser::SignOutRequest * CurrentUser::requestSignOut(){ assert(m_state == SIGNED_IN || m_state == GUEST); - 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); + CurrentUser::SignOutRequest * request = new CurrentUser::SignOutRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action",std::string("disconnect")); + request->setParameter("token",m_token); + request->setParameter("userid",m_id); + HTTPManager::get()->addRequest(request); + m_state = SIGNING_OUT; + return request; + } - bool success = false; - const XMLNode * result = connector->getXMLFromPage(); - std::string rec_success = ""; - if(result->get("success", &rec_success)) + void CurrentUser::signOut(SignOutRequest * input) + { + const XMLNode * xml = input->getResult(); + irr::core::stringw info; + std::string rec_success; + if(xml->get("success", &rec_success) && (rec_success =="yes")) { - if (rec_success =="yes") - { - m_token = ""; - m_name = ""; - m_id = 0; - m_state = SIGNED_OUT; - UserConfigParams::m_saved_user = 0; - UserConfigParams::m_saved_token = ""; - UserConfigParams::m_saved_session = false; - success = true; - } - result->get("info", &info); + xml->get("info", &info); } else { - info = _("Unable to connect to the server. Check your internet connection or try again later."); + Log::warn("CurrentUser::signOut", "%s", _("There were some connection issues while signing out. Report a bug if this caused issues.")); } - return success; + m_token = ""; + m_name = ""; + m_id = 0; + m_state = SIGNED_OUT; + UserConfigParams::m_saved_user = 0; + UserConfigParams::m_saved_token = ""; + UserConfigParams::m_saved_session = false; + input->setInfo(info); + input->setSuccess(true); } + void CurrentUser::SignOutRequest::callback() + { + CurrentUser::acquire()->signOut(this); + CurrentUser::release(); + } + // ============================================================================ bool CurrentUser::requestJoin(uint32_t server_id, irr::core::stringw &info){ Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/online/current_user.hpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -49,12 +49,14 @@ class SignInRequest : public XMLRequest { - protected : virtual void callback (); - public : - SignInRequest(const std::string &url) : XMLRequest(url) {} }; + class SignOutRequest : public XMLRequest + { + virtual void callback (); + }; + private: std::string m_token; bool m_save_session; @@ -62,6 +64,7 @@ CurrentUser(); void signIn(SignInRequest * input); + void signOut(SignOutRequest * input); public: @@ -78,6 +81,10 @@ const irr::core::stringw &password, bool save_session); + // Logout - Best to be followed by CurrentUser::deallocate + SignOutRequest * requestSignOut(); + + // Register bool signUp( const irr::core::stringw &username, const irr::core::stringw &password, @@ -85,9 +92,8 @@ 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); + XMLRequest * createServerRequest( const irr::core::stringw &name, int max_players); Modified: main/branches/uni/src/online/http_manager.cpp =================================================================== --- main/branches/uni/src/online/http_manager.cpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/online/http_manager.cpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -63,6 +63,7 @@ HTTPManager::HTTPManager(){ curl_global_init(CURL_GLOBAL_DEFAULT); pthread_cond_init(&m_cond_request, NULL); + m_abort.setAtomic(false); } // ============================================================================ @@ -140,24 +141,14 @@ * sorted by priority. * \param request The pointer to the new request to insert. */ - bool HTTPManager::addRequest(Online::Request *request) + void 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; - } + assert(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(); } // insertRequest // --------------------------------------------------------------------------- Modified: main/branches/uni/src/online/http_manager.hpp =================================================================== --- main/branches/uni/src/online/http_manager.hpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/online/http_manager.hpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -82,7 +82,7 @@ std::string getPage(Online::Request * request); XMLNode * getXMLFromPage(Online::Request * request); - bool addRequest(Online::Request *request); + void addRequest(Online::Request *request); void cancelAllDownloads(); bool getAbort(){ return m_abort.getAtomic(); }; Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/online/request.cpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -61,7 +61,7 @@ // ========================================================================================= - HTTPRequest::HTTPRequest(const std::string &url) + HTTPRequest::HTTPRequest(const std::string & url) : Request(1,false) { m_url = url; @@ -80,10 +80,7 @@ bool HTTPRequest::isAllowedToAdd() { if (m_url.size() > 5 && ( m_url.substr(0, 5) != "http:")) - { - Log::info("HTTPRequest::isAllowedToAdd", "Invalid URL."); return false; - } return true; } @@ -203,10 +200,6 @@ // ========================================================================================= - XMLRequest::XMLRequest(const std::string &url) - : HTTPRequest(url) - { - } void XMLRequest::operation() { Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/online/request.hpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -144,7 +144,7 @@ public : - HTTPRequest(const std::string &url); + HTTPRequest(const std::string & url = ""); virtual ~HTTPRequest(); void setParameter(const std::string & name, const std::string &value){ @@ -173,6 +173,7 @@ bool isSuccess(){ return m_success; } const std::string &getURL() const {return m_url;} + void setURL(const std::string & url) { m_url = url;} virtual bool isAllowedToAdd() OVERRIDE; @@ -185,7 +186,7 @@ virtual void operation() OVERRIDE; public : - XMLRequest(const std::string &url); + XMLRequest(const std::string & url = "") : HTTPRequest(url) {}; virtual XMLNode * getResult() OVERRIDE { return m_result; } }; } //namespace Online Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -52,7 +52,9 @@ OnlineScreen::OnlineScreen() : Screen("online/main.stkgui") { m_recorded_state = CurrentUser::SIGNED_OUT; - m_sign_in_request = CurrentUser::acquire()->requestSavedSession(); + CurrentUser::SignInRequest * request = CurrentUser::acquire()->requestSavedSession(); + if(request != NULL) + m_requests.push_back(request); CurrentUser::release(); } // OnlineScreen @@ -60,7 +62,7 @@ OnlineScreen::~OnlineScreen() { - delete m_sign_in_request; + m_requests.clearAndDeleteAll(); } // ---------------------------------------------------------------------------- @@ -159,23 +161,44 @@ m_load_timer += delta; m_online_status_widget->setText(Messages::signingIn(m_load_timer), false); } - if(m_sign_in_request != NULL) + else if (m_recorded_state == CurrentUser::SIGNING_OUT) { - if(m_sign_in_request->isDone()) + m_load_timer += delta; + m_online_status_widget->setText(Messages::signingOut(m_load_timer), false); + } + + for(int i = m_requests.size()-1; i>=0; --i) + { + if(m_requests[i].isDone()) { - if(m_sign_in_request->isSuccess()) + if( dynamic_cast<CurrentUser::SignInRequest*>(m_requests.get(i))) { - new MessageDialog(_("Automatically signed in.")); - } - else + if(m_requests[i].isSuccess()) + { + new MessageDialog(_("Automatically signed in.")); + } + else + { + sfx_manager->quickSound( "anvil" ); + new MessageDialog(m_requests[i].getInfo()); + } + }else if( dynamic_cast<CurrentUser::SignOutRequest*>(m_requests.get(i))) { - sfx_manager->quickSound( "anvil" ); - new MessageDialog(m_sign_in_request->getInfo()); + if(m_requests[i].isSuccess()) + { + new MessageDialog(_("Signed out successfully.")); + } + else + { + sfx_manager->quickSound( "anvil" ); + new MessageDialog(m_requests[i].getInfo()); + } } - delete m_sign_in_request; - m_sign_in_request = NULL; + + m_requests.erase(i); } } + } // onUpdate // ---------------------------------------------------------------------------- @@ -198,14 +221,8 @@ } else if (selection == "sign_out") { - irr::core::stringw info; - if (Online::CurrentUser::get()->signOut(info)) - { - new MessageDialog(_("Signed out successfully.")); - //GUIEngine::reshowCurrentScreen(); - } - else - new MessageDialog(info); + m_requests.push_back(CurrentUser::acquire()->requestSignOut()); + CurrentUser::release(); } else if (selection == "register") { @@ -238,10 +255,9 @@ } // eventCallback // ---------------------------------------------------------------------------- - void OnlineScreen::tearDown() { -} // tearDown +} // ---------------------------------------------------------------------------- void OnlineScreen::onDisabledItemClicked(const std::string& item) @@ -278,3 +294,4 @@ else setInitialFocus(); } // onDialogClose() + Modified: main/branches/uni/src/states_screens/online_screen.hpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.hpp 2013-07-19 22:41:54 UTC (rev 13292) +++ main/branches/uni/src/states_screens/online_screen.hpp 2013-07-20 01:38:44 UTC (rev 13293) @@ -54,8 +54,9 @@ Online::CurrentUser::UserState m_recorded_state; float m_load_timer; - Online::CurrentUser::SignInRequest * m_sign_in_request; + PtrVector<Online::XMLRequest> m_requests; + /** \brief Checks if the recorded state differs from the actual state and sets it. */ bool hasStateChanged(); /** \brief Sets which widget has to be focused. Depends on the user state. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-20 02:14:40
|
Revision: 13294 http://sourceforge.net/p/supertuxkart/code/13294 Author: unitraxx Date: 2013-07-20 02:14:36 +0000 (Sat, 20 Jul 2013) Log Message: ----------- Decent killing of the network singleton and thread. Modified Paths: -------------- main/branches/uni/src/main.cpp main/branches/uni/src/online/http_manager.cpp main/branches/uni/src/online/http_manager.hpp Modified: main/branches/uni/src/main.cpp =================================================================== --- main/branches/uni/src/main.cpp 2013-07-20 01:38:44 UTC (rev 13293) +++ main/branches/uni/src/main.cpp 2013-07-20 02:14:36 UTC (rev 13294) @@ -169,6 +169,7 @@ #include "modes/demo_world.hpp" #include "modes/profile_world.hpp" #include "network/network_manager.hpp" +#include "online/http_manager.hpp" #include "race/grand_prix_manager.hpp" #include "race/highscore_manager.hpp" #include "race/history.hpp" @@ -1211,6 +1212,8 @@ if(INetworkHttp::get()) INetworkHttp::get()->stopNetworkThread(); + if(Online::HTTPManager::isRunning()) + Online::HTTPManager::get()->stopNetworkThread(); //delete in reverse order of what they were created in. //see InitTuxkart() Referee::cleanup(); Modified: main/branches/uni/src/online/http_manager.cpp =================================================================== --- main/branches/uni/src/online/http_manager.cpp 2013-07-20 01:38:44 UTC (rev 13293) +++ main/branches/uni/src/online/http_manager.cpp 2013-07-20 02:14:36 UTC (rev 13294) @@ -59,7 +59,12 @@ http_singleton = NULL; } // deallocate + bool HTTPManager::isRunning() + { + return http_singleton != NULL; + } + HTTPManager::HTTPManager(){ curl_global_init(CURL_GLOBAL_DEFAULT); pthread_cond_init(&m_cond_request, NULL); Modified: main/branches/uni/src/online/http_manager.hpp =================================================================== --- main/branches/uni/src/online/http_manager.hpp 2013-07-20 01:38:44 UTC (rev 13293) +++ main/branches/uni/src/online/http_manager.hpp 2013-07-20 02:14:36 UTC (rev 13294) @@ -45,7 +45,7 @@ protected: /** The current requested being worked on. */ - Online::Request *m_current_request; + Online::Request * m_current_request; /** A conditional variable to wake up the main loop. */ pthread_cond_t m_cond_request; @@ -66,9 +66,7 @@ static void *mainLoop(void *obj); void startNetworkThread(); - void stopNetworkThread(); - HTTPManager(); //const std::string &url ~HTTPManager(); @@ -77,6 +75,7 @@ // singleton static HTTPManager* get(); static void deallocate(); + static bool isRunning(); //Execute std::string getPage(Online::Request * request); @@ -84,6 +83,7 @@ void addRequest(Online::Request *request); void cancelAllDownloads(); + void stopNetworkThread(); bool getAbort(){ return m_abort.getAtomic(); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-21 15:19:18
|
Revision: 13306 http://sourceforge.net/p/supertuxkart/code/13306 Author: unitraxx Date: 2013-07-21 15:19:15 +0000 (Sun, 21 Jul 2013) Log Message: ----------- Apparently the onEscapePressed callback for a dialog didn't operate as advertised. I fiex. Modified Paths: -------------- main/branches/uni/src/guiengine/modaldialog.hpp main/branches/uni/src/states_screens/state_manager.cpp Modified: main/branches/uni/src/guiengine/modaldialog.hpp =================================================================== --- main/branches/uni/src/guiengine/modaldialog.hpp 2013-07-21 14:03:36 UTC (rev 13305) +++ main/branches/uni/src/guiengine/modaldialog.hpp 2013-07-21 15:19:15 UTC (rev 13306) @@ -105,7 +105,7 @@ static bool isADialogActive(); /** Override to change what happens on escape pressed */ - virtual void escapePressed() { dismiss(); } + virtual bool onEscapePressed() { return true; } /** Override to be notified of updates */ virtual void onUpdate(float dt) { } Modified: main/branches/uni/src/states_screens/state_manager.cpp =================================================================== --- main/branches/uni/src/states_screens/state_manager.cpp 2013-07-21 14:03:36 UTC (rev 13305) +++ main/branches/uni/src/states_screens/state_manager.cpp 2013-07-21 15:19:15 UTC (rev 13306) @@ -167,7 +167,8 @@ // when another modal dialog is visible else if(ModalDialog::isADialogActive()) { - ModalDialog::getCurrent()->escapePressed(); + if(ModalDialog::getCurrent()->onEscapePressed()) + ModalDialog::getCurrent()->dismiss(); } // In-game else if(m_game_mode == GAME) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-21 15:21:51
|
Revision: 13307 http://sourceforge.net/p/supertuxkart/code/13307 Author: unitraxx Date: 2013-07-21 15:21:48 +0000 (Sun, 21 Jul 2013) Log Message: ----------- Another enhancement for my HTTPManager which needed a lot of changes. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/online/http_manager.cpp main/branches/uni/src/online/http_manager.hpp main/branches/uni/src/online/messages.cpp main/branches/uni/src/online/messages.hpp main/branches/uni/src/online/request.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/states_screens/dialogs/login_dialog.cpp main/branches/uni/src/states_screens/dialogs/login_dialog.hpp main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp main/branches/uni/src/states_screens/online_screen.cpp main/branches/uni/src/states_screens/online_screen.hpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/current_user.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -68,7 +68,7 @@ // ============================================================================ CurrentUser::CurrentUser(){ - m_state = SIGNED_OUT; + m_state = US_SIGNED_OUT; m_id = 0; m_name = ""; m_token = ""; @@ -82,8 +82,8 @@ const irr::core::stringw &email, bool terms) { - assert(m_state == SIGNED_OUT || m_state == GUEST); - XMLRequest * request = new XMLRequest(Request::RT_SIGN_UP); + assert(m_state == US_SIGNED_OUT || m_state == US_GUEST); + XMLRequest * request = new XMLRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action",std::string("register")); request->setParameter("username",username); @@ -94,10 +94,10 @@ } // ============================================================================ - SignInRequest * CurrentUser::requestSavedSession() + CurrentUser::SignInRequest * CurrentUser::requestSavedSession() { SignInRequest * request = NULL; - if(m_state != SIGNED_IN && UserConfigParams::m_saved_session) + if(m_state != US_SIGNED_IN && UserConfigParams::m_saved_session) { request = new SignInRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); @@ -105,16 +105,16 @@ request->setParameter("userid", UserConfigParams::m_saved_user); request->setParameter("token", UserConfigParams::m_saved_token.c_str()); HTTPManager::get()->addRequest(request); - m_state = SIGNING_IN; + m_state = US_SIGNING_IN; } return request; } - SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username, + CurrentUser::SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username, const irr::core::stringw &password, bool save_session) { - assert(m_state == SIGNED_OUT); + assert(m_state == US_SIGNED_OUT); m_save_session = save_session; SignInRequest * request = new SignInRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); @@ -122,7 +122,7 @@ request->setParameter("username",username); request->setParameter("password",password); HTTPManager::get()->addRequest(request); - m_state = SIGNING_IN; + m_state = US_SIGNING_IN; return request; } @@ -134,7 +134,7 @@ int username_fetched = input->getResult()->get("username", &m_name); int userid_fetched = input->getResult()->get("userid", &m_id); assert(token_fetched && username_fetched && userid_fetched); - m_state = SIGNED_IN; + m_state = US_SIGNED_IN; if(m_save_session) { UserConfigParams::m_saved_user = m_id; @@ -144,10 +144,10 @@ } } else - m_state = SIGNED_OUT; + m_state = US_SIGNED_OUT; } - void SignInRequest::callback() + void CurrentUser::SignInRequest::callback() { CurrentUser::acquire()->signIn(this); CurrentUser::release(); @@ -155,9 +155,9 @@ // ============================================================================ - ServerCreationRequest * CurrentUser::requestServerCreation(const irr::core::stringw &name, int max_players) + CurrentUser::ServerCreationRequest * CurrentUser::requestServerCreation(const irr::core::stringw &name, int max_players) { - assert(m_state == SIGNED_IN); + assert(m_state == US_SIGNED_IN); ServerCreationRequest * request = new ServerCreationRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action", std::string("create_server")); @@ -169,21 +169,21 @@ return request; } - void ServerCreationRequest::callback() + void CurrentUser::ServerCreationRequest::callback() { //FIXME } // ============================================================================ - SignOutRequest * CurrentUser::requestSignOut(){ - assert(m_state == SIGNED_IN || m_state == GUEST); + CurrentUser::SignOutRequest * CurrentUser::requestSignOut(){ + assert(m_state == US_SIGNED_IN || m_state == US_GUEST); SignOutRequest * request = new SignOutRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action",std::string("disconnect")); request->setParameter("token",m_token); request->setParameter("userid",m_id); HTTPManager::get()->addRequest(request); - m_state = SIGNING_OUT; + m_state = US_SIGNING_OUT; return request; } @@ -196,13 +196,13 @@ m_token = ""; m_name = ""; m_id = 0; - m_state = SIGNED_OUT; + m_state = US_SIGNED_OUT; UserConfigParams::m_saved_user = 0; UserConfigParams::m_saved_token = ""; UserConfigParams::m_saved_session = false; } - void SignOutRequest::callback() + void CurrentUser::SignOutRequest::callback() { CurrentUser::acquire()->signOut(this); CurrentUser::release(); @@ -210,8 +210,8 @@ // ============================================================================ - ServerJoinRequest * CurrentUser::requestServerJoin(uint32_t server_id){ - assert(m_state == SIGNED_IN || m_state == GUEST); + CurrentUser::ServerJoinRequest * CurrentUser::requestServerJoin(uint32_t server_id){ + assert(m_state == US_SIGNED_IN || m_state == US_GUEST); ServerJoinRequest * request = new ServerJoinRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php"); request->setParameter("action",std::string("request-connection")); @@ -221,7 +221,7 @@ return request; } - void ServerJoinRequest::callback() + void CurrentUser::ServerJoinRequest::callback() { //FIXME } @@ -230,7 +230,7 @@ irr::core::stringw CurrentUser::getUserName() const { - if((m_state == SIGNED_IN ) || (m_state == GUEST)) + if((m_state == US_SIGNED_IN ) || (m_state == US_GUEST)) return m_name; else return _("Currently not signed in"); Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/current_user.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -29,32 +29,6 @@ namespace Online{ - class SignInRequest : public XMLRequest - { - virtual void callback (); - public : - SignInRequest() : XMLRequest(RT_SIGN_IN) {} - }; - - class SignOutRequest : public XMLRequest - { - virtual void callback (); - public : - SignOutRequest() : XMLRequest(RT_SIGN_OUT) {} - }; - - class ServerCreationRequest : public XMLRequest { - virtual void callback (); - public : - ServerCreationRequest() : XMLRequest(RT_SERVER_JOIN) {} - }; - - class ServerJoinRequest : public XMLRequest { - virtual void callback (); - public : - ServerJoinRequest() : XMLRequest(RT_SERVER_JOIN) {} - }; - // ============================================================================ /** @@ -66,13 +40,49 @@ public: enum UserState { - SIGNED_OUT, - SIGNED_IN, - GUEST, - SIGNING_IN, - SIGNING_OUT + US_SIGNED_OUT, + US_SIGNED_IN, + US_GUEST, + US_SIGNING_IN, + US_SIGNING_OUT }; + enum RequestType + { + RT_SIGN_IN = 1, + RT_SIGN_OUT, + RT_SIGN_UP, + RT_SERVER_JOIN, + RT_SERVER_CREATION + }; + + class SignInRequest : public XMLRequest + { + virtual void callback (); + public: + SignInRequest() : XMLRequest(RT_SIGN_IN) {} + }; + + class SignOutRequest : public XMLRequest + { + virtual void callback (); + public: + SignOutRequest() : XMLRequest(RT_SIGN_OUT) {} + }; + + class ServerCreationRequest : public XMLRequest { + virtual void callback (); + public: + ServerCreationRequest() : XMLRequest(RT_SERVER_CREATION) {} + }; + + class ServerJoinRequest : public XMLRequest { + virtual void callback (); + public: + ServerJoinRequest() : XMLRequest(RT_SERVER_JOIN) {} + }; + + private: std::string m_token; bool m_save_session; @@ -110,9 +120,9 @@ /** Returns the username if signed in. */ irr::core::stringw getUserName() const; - bool isSignedIn() const { return m_state == SIGNED_IN; } - bool isGuest() const { return m_state == GUEST; } - bool isSigningIn() const { return m_state == SIGNING_IN; } + bool isSignedIn() const { return m_state == US_SIGNED_IN; } + bool isGuest() const { return m_state == US_GUEST; } + bool isSigningIn() const { return m_state == US_SIGNING_IN; } UserState getUserState() { return m_state; } }; // class CurrentUser Modified: main/branches/uni/src/online/http_manager.cpp =================================================================== --- main/branches/uni/src/online/http_manager.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/http_manager.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -74,11 +74,6 @@ // ============================================================================ HTTPManager::~HTTPManager(){ curl_global_cleanup(); - m_response_queue.lock(); - //FIXME should all be deleted - m_response_queue.getData().clear(); - m_response_queue.unlock(); - //FIXME empty and delete request queue? } @@ -129,9 +124,7 @@ // a download, which mean we can get the mutex and ask the service // thread here to cancel properly. cancelAllDownloads(); - - QuitRequest * request = new QuitRequest(); - addRequest(request); + addRequest(new Request(true, 9999, Request::RT_QUIT)); } // stopNetworkThread @@ -161,41 +154,6 @@ m_request_queue.unlock(); } // insertRequest - // ---------------------------------------------------------------------------- - /** - * \param request The pointer to the finished request to insert. - */ - void HTTPManager::addResponse(Request *request) - { - m_response_queue.lock(); - if (m_response_queue.getData().count(request->getType())) - { - delete m_response_queue.getData()[request->getType()]; - m_response_queue.getData().erase(request->getType()); - } - m_response_queue.getData()[request->getType()] = request; - m_response_queue.unlock(); - } // insertRequest - - Request * HTTPManager::getResponse(Request::RequestType type) - { - Request * response = NULL; - m_response_queue.lock(); - if (m_response_queue.getData().count(type)) - response = m_response_queue.getData()[type]; - m_response_queue.getData().erase(type); - m_response_queue.unlock(); - return response; - } - - XMLRequest * HTTPManager::getXMLResponse(Request::RequestType type) - { - Request * response = getResponse(type); - if(response != NULL) - return (XMLRequest *) response; - return NULL; - } - // --------------------------------------------------------------------------- /** The actual main loop, which is started as a separate thread from the * constructor. After testing for a new server, fetching news, the list @@ -210,7 +168,7 @@ me->m_current_request = NULL; me->m_request_queue.lock(); - while( me->m_request_queue.getData().empty() || me->m_request_queue.getData().top()->getType() != Request::RT_QUIT ) + while( me->m_request_queue.getData().empty() || me->m_request_queue.getData().top()->getType() != Request::RT_QUIT) { bool empty = me->m_request_queue.getData().empty(); // Wait in cond_wait for a request to arrive. The 'while' is necessary @@ -230,10 +188,6 @@ delete me->m_current_request; me->m_current_request = NULL; } - else - { - me->addResponse(me->m_current_request); - } me->m_request_queue.lock(); } // while Modified: main/branches/uni/src/online/http_manager.hpp =================================================================== --- main/branches/uni/src/online/http_manager.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/http_manager.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -66,11 +66,6 @@ > > m_request_queue; - /** The list of pointers to all requests that are already handled but didn't need to be deleted. */ - Synchronised< std::map < Online::Request::RequestType, Online::Request* > > m_response_queue; - - void addResponse(Online::Request*); - static void *mainLoop(void *obj); void startNetworkThread(); @@ -91,9 +86,6 @@ void addRequest(Online::Request *request); void cancelAllDownloads(); void stopNetworkThread(); - Request * getResponse(Online::Request::RequestType type); - /** Same as getResponse but with a cast to XMLRequest */ - XMLRequest * getXMLResponse(Online::Request::RequestType type); bool getAbort(){ return m_abort.getAtomic(); }; Modified: main/branches/uni/src/online/messages.cpp =================================================================== --- main/branches/uni/src/online/messages.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/messages.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -24,13 +24,6 @@ { namespace Messages { - irr::core::stringw loadingDots(bool spaces, float interval, int max_dots) - { - int nr_dots = int(floor(Time::getRealTime() * (1 / interval))) % (max_dots+1); - return irr::core::stringw((std::string(nr_dots,'.') + std::string(max_dots-nr_dots,' ')).c_str()); - } - // ------------------------------------------------------------------------ - irr::core::stringw signingIn() { return irr::core::stringw(_("Signing in")) + loadingDots(); @@ -42,21 +35,35 @@ return irr::core::stringw(_("Signing out")) + loadingDots(); } // ------------------------------------------------------------------------ + irr::core::stringw signingUp() + { + return irr::core::stringw(_("Validating registration info")) + loadingDots(); + } + // ------------------------------------------------------------------------ irr::core::stringw signedInAs(const irr::core::stringw & name) { return irr::core::stringw(_("Signed in as : ")) + name + "."; } + // ------------------------------------------------------------------------ irr::core::stringw joiningServer() { return irr::core::stringw(_("Joining server")) + loadingDots(); } + // ------------------------------------------------------------------------ irr::core::stringw creatingServer() { return irr::core::stringw(_("Creating server")) + loadingDots(); } + + // ------------------------------------------------------------------------ + irr::core::stringw loadingDots(bool spaces, float interval, int max_dots) + { + int nr_dots = int(floor(Time::getRealTime() * (1 / interval))) % (max_dots+1); + return irr::core::stringw((std::string(nr_dots,'.') + std::string(max_dots-nr_dots,' ')).c_str()); + } } // namespace messages } // namespace Online Modified: main/branches/uni/src/online/messages.hpp =================================================================== --- main/branches/uni/src/online/messages.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/messages.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -29,6 +29,7 @@ irr::core::stringw loadingDots (bool spaces = true, float interval = 0.5f, int max_dots = 3); irr::core::stringw signingIn (); irr::core::stringw signingOut (); + irr::core::stringw signingUp (); irr::core::stringw joiningServer (); irr::core::stringw creatingServer (); irr::core::stringw signedInAs (const irr::core::stringw & name); Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/request.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -28,8 +28,8 @@ // ========================================================================================= - Request::Request(RequestType type, int priority, bool manage_memory) - :m_type(type) + Request::Request(int type, bool manage_memory, int priority) + : m_type(type) { m_priority = priority; m_manage_memory = manage_memory; @@ -55,18 +55,12 @@ // ========================================================================================= - QuitRequest::QuitRequest() - : Request(RT_QUIT,9999,true) + HTTPRequest::HTTPRequest(int type, bool manage_memory, int priority) + : Request(priority, manage_memory, type) { - } - - - // ========================================================================================= - - HTTPRequest::HTTPRequest(RequestType type, const std::string & url) - : Request(type, 1,false) - { - m_url = url; + //Negative numbers are reserved for special requests ment for the HTTP Manager + assert(type >= 0); + m_url = ""; m_parameters = new Parameters; m_progress.setAtomic(0); } @@ -200,8 +194,8 @@ // ========================================================================================= - XMLRequest::XMLRequest(RequestType type, const std::string & url) - : HTTPRequest(type, url) + XMLRequest::XMLRequest(int type, bool manage_memory, int priority) + : HTTPRequest(priority, manage_memory, type) { m_info = ""; m_success = false; Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/online/request.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -32,18 +32,8 @@ */ class Request { - public: - /** List of different types of requests which are used as key in the response map - */ - enum RequestType { - RT_QUIT, - RT_SIGN_IN, - RT_SIGN_OUT, - RT_SIGN_UP, - RT_SERVER_CREATION, - RT_SERVER_JOIN - }; - + private: + const int m_type; protected: /** The priority of this request. The higher the value the more important this request is. */ @@ -51,9 +41,6 @@ /** Cancel this request if it is active. */ bool m_cancel; - const RequestType m_type; - - /** 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 @@ -63,12 +50,17 @@ Synchronised<bool> m_done; virtual void beforeOperation() {} - virtual void operation() = 0; + virtual void operation() {}; virtual void afterOperation(); public: + /** Negative numbers are reserved for requests that are special for the HTTP Manager*/ + enum RequestType + { + RT_QUIT = -1 + }; - Request(RequestType type, int priority, bool manage_memory=true); + Request(int type, bool manage_memory, int priority); virtual ~Request(); void execute(); @@ -83,19 +75,16 @@ /** Returns if this request is to be canceled. */ bool isCancelled() const { return m_cancel; } // ------------------------------------------------------------------------ - /** Specifies if the memory should be managed by http manager. */ - 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.getAtomic(); } - RequestType getType() const { return m_type; } - virtual bool isAllowedToAdd() { return true; } + int getType() const { return m_type; } + /** This class is used by the priority queue to sort requests by priority. */ class Compare @@ -112,17 +101,6 @@ // ======================================================================== - class QuitRequest : public Request - { - public : - QuitRequest(); - virtual void operation() OVERRIDE {} - }; - - - // ======================================================================== - - class HTTPRequest : public Request { @@ -153,7 +131,7 @@ virtual void callback() {} public : - HTTPRequest(RequestType type, const std::string & url = ""); + HTTPRequest(int type = 0, bool manage_memory = false, int priority = 1); virtual ~HTTPRequest(); void setParameter(const std::string & name, const std::string &value){ @@ -191,7 +169,7 @@ virtual void afterOperation() OVERRIDE; public : - XMLRequest(RequestType type, const std::string & url = ""); + XMLRequest(int type = 0, bool manage_memory = false, int priority = 1); virtual XMLNode * getResult() const { return m_result; } const irr::core::stringw & getInfo() const { return m_info; } Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -41,7 +41,7 @@ { m_self_destroy = false; m_open_registration_dialog = false; - m_signing_in = false; + m_sign_in_request = NULL; loadFromFile("online/login_dialog.stkgui"); m_message_widget = getWidget<LabelWidget>("message"); @@ -96,6 +96,7 @@ LoginDialog::~LoginDialog() { + delete m_sign_in_request; } @@ -114,9 +115,8 @@ else { m_options_widget->setDeactivated(); - Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState()); + m_sign_in_request = Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState()); Online::CurrentUser::release(); - m_signing_in = true; } } @@ -161,24 +161,36 @@ // ----------------------------------------------------------------------------- +bool LoginDialog::onEscapePressed() +{ + return false; +} + void LoginDialog::onUpdate(float dt) { - XMLRequest * sign_in_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_IN); - if(sign_in_request != NULL) + if(m_sign_in_request != NULL) { - if(sign_in_request->isSuccess()) + if(m_sign_in_request->isDone()) { - m_self_destroy = true; + if(m_sign_in_request->isSuccess()) + { + m_self_destroy = true; + } + else + { + sfx_manager->quickSound( "anvil" ); + m_info_widget->setErrorColor(); + m_info_widget->setText(m_sign_in_request->getInfo(), false); + } + delete m_sign_in_request; + m_sign_in_request = NULL; + m_options_widget->setActivated(); } else { - sfx_manager->quickSound( "anvil" ); - m_info_widget->setErrorColor(); - m_info_widget->setText(sign_in_request->getInfo(), false); + m_info_widget->setDefaultColor(); + m_info_widget->setText(Online::Messages::signingIn(), false); } - delete sign_in_request; - m_signing_in = false; - m_options_widget->setActivated(); } //If we want to open the registration dialog, we need to close this one first m_open_registration_dialog && (m_self_destroy = true); @@ -191,10 +203,4 @@ new RegistrationDialog(); return; } - - if (m_signing_in) - { - m_info_widget->setDefaultColor(); - m_info_widget->setText(Online::Messages::signingIn(), false); - } } Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -37,7 +37,7 @@ bool m_self_destroy; bool m_open_registration_dialog; - bool m_signing_in; + Online::CurrentUser::SignInRequest * m_sign_in_request; GUIEngine::LabelWidget * m_message_widget; GUIEngine::TextBoxWidget * m_username_widget; GUIEngine::TextBoxWidget * m_password_widget; @@ -69,8 +69,10 @@ ~LoginDialog(); void onEnterPressedInternal(); + GUIEngine::EventPropagation processEvent(const std::string& eventSource); + virtual bool onEscapePressed(); virtual void onUpdate(float dt); //virtual void onTextUpdated(); }; Modified: main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -25,6 +25,7 @@ #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" +#include "online/messages.hpp" using namespace GUIEngine; @@ -38,6 +39,7 @@ ModalDialog(0.8f,0.9f) { m_sign_up_request = NULL; + m_activation_request = NULL; m_self_destroy = false; m_show_registration_info = false; m_show_registration_terms = false; @@ -59,6 +61,8 @@ RegistrationDialog::~RegistrationDialog() { + delete m_sign_up_request; + delete m_activation_request; } // ----------------------------------------------------------------------------- @@ -190,8 +194,8 @@ if (eventSource == "next") { assert(getWidget<CheckBoxWidget>("accepted")->getState()); - m_agreement = true; - m_sign_up_request = CurrentUser::acquire()->requestSignUp(m_username, m_password, m_password_confirm, m_email, m_agreement); + m_sign_up_request = CurrentUser::acquire()->requestSignUp(m_username, m_password, m_password_confirm, m_email, true); + CurrentUser::release(); return true; } else if (eventSource == "accepted") @@ -274,31 +278,56 @@ void RegistrationDialog::onUpdate(float dt) { - /* - if(m_sign_up_request != NULL) + if (m_phase == Terms) { - if(m_sign_up_request->isDone()) + if(m_sign_up_request != NULL) { - if(m_sign_up_request->isSuccess()) + if(m_sign_up_request->isDone()) { + if(m_sign_up_request->isSuccess()) + { + m_show_registration_activation = true; + } + else + { + sfx_manager->quickSound( "anvil" ); + m_show_registration_info = true; + m_registration_error = m_sign_up_request->getInfo(); + } + delete m_sign_up_request; + m_sign_up_request = NULL; + //FIXME m_options_widget->setActivated(); + } + else + { + LabelWidget* label = getWidget<LabelWidget>("info"); + assert(label != NULL); + label->setDefaultColor(); + label->setText(Messages::signingUp(), false); + } + } + } + else if (m_phase == Activation) + { + /* + XMLRequest * sign_up_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_UP); + if(sign_up_request != NULL) + { + if(sign_up_request->isSuccess()) + { m_show_registration_activation = true; } else { sfx_manager->quickSound( "anvil" ); m_show_registration_info = true; + m_registration_error = sign_up_request->getInfo(); } - m_options_widget->setActivated(); - delete m_sign_in_request; - m_sign_in_request = NULL; - } - else - { - m_load_timer += dt; - m_info_widget->setDefaultColor(); - m_info_widget->setText(Online::Messages::signingIn(m_load_timer), false); - } - }*/ + delete sign_up_request; + m_signing_up = false; + //FIXME m_options_widget->setActivated(); + }*/ + } // It's unsafe to delete from inside the event handler so we do it here if (m_self_destroy) ModalDialog::dismiss(); Modified: main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -56,6 +56,7 @@ bool m_show_registration_activation; Online::XMLRequest * m_sign_up_request; + Online::XMLRequest * m_activation_request; //Saved user input : irr::core::stringw m_username; Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -46,7 +46,7 @@ m_server = server; m_self_destroy = false; m_enter_lobby = false; - m_joining_server = false; + m_server_join_request = NULL; loadFromFile("online/server_info_dialog.stkgui"); @@ -69,13 +69,13 @@ // ----------------------------------------------------------------------------- ServerInfoDialog::~ServerInfoDialog() { + delete m_server_join_request; } // ----------------------------------------------------------------------------- void ServerInfoDialog::requestJoin() { Online::CurrentUser::acquire()->requestServerJoin(m_server->getServerId()); Online::CurrentUser::release(); - m_joining_server = true; } // ----------------------------------------------------------------------------- @@ -115,21 +115,28 @@ void ServerInfoDialog::onUpdate(float dt) { - XMLRequest * request = HTTPManager::get()->getXMLResponse(Request::RT_SERVER_JOIN); - if(request != NULL) + if(m_server_join_request != NULL) { - if(request->isSuccess()) + if(m_server_join_request->isDone()) { - m_self_destroy = true; + if(m_server_join_request->isSuccess()) + { + m_self_destroy = true; + } + else + { + sfx_manager->quickSound( "anvil" ); + m_info_widget->setErrorColor(); + m_info_widget->setText(m_server_join_request->getInfo(), false); + } + delete m_server_join_request; + m_server_join_request = NULL; } else { - sfx_manager->quickSound( "anvil" ); - m_info_widget->setErrorColor(); - m_info_widget->setText(request->getInfo(), false); + m_info_widget->setDefaultColor(); + m_info_widget->setText(Online::Messages::joiningServer(), false); } - delete request; - m_joining_server = false; } //If we want to open the registration dialog, we need to close this one first @@ -143,10 +150,4 @@ StateManager::get()->pushScreen(NetworkingLobby::getInstance()); return; } - - if (m_joining_server) - { - m_info_widget->setDefaultColor(); - m_info_widget->setText(Online::Messages::joiningServer(), false); - } } Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -40,7 +40,7 @@ bool m_self_destroy; bool m_enter_lobby; - bool m_joining_server; + Online::CurrentUser::ServerJoinRequest * m_server_join_request; float m_load_timer; Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -51,8 +51,10 @@ OnlineScreen::OnlineScreen() : Screen("online/main.stkgui") { - m_recorded_state = CurrentUser::SIGNED_OUT; - CurrentUser::acquire()->requestSavedSession(); + m_recorded_state = CurrentUser::US_SIGNED_OUT; + CurrentUser::SignInRequest * request = CurrentUser::acquire()->requestSavedSession(); + if(request != NULL) + m_requests.push_back(request); CurrentUser::release(); } // OnlineScreen @@ -60,6 +62,7 @@ OnlineScreen::~OnlineScreen() { + m_requests.clearAndDeleteAll(); } // ---------------------------------------------------------------------------- @@ -108,24 +111,24 @@ m_bottom_menu_widget->setVisible(true); m_top_menu_widget->setVisible(true); hasStateChanged(); - if (m_recorded_state == CurrentUser::SIGNED_IN) + if (m_recorded_state == CurrentUser::US_SIGNED_IN) { m_register_widget->setVisible(false); m_sign_in_widget->setVisible(false); } - else if (m_recorded_state == CurrentUser::SIGNED_OUT || m_recorded_state == CurrentUser::SIGNING_IN || m_recorded_state == CurrentUser::SIGNING_OUT) + else if (m_recorded_state == CurrentUser::US_SIGNED_OUT || m_recorded_state == CurrentUser::US_SIGNING_IN || m_recorded_state == CurrentUser::US_SIGNING_OUT) { m_quick_play_widget->setDeactivated(); m_find_server_widget->setDeactivated(); m_create_server_widget->setDeactivated(); m_sign_out_widget->setVisible(false); - if(m_recorded_state == CurrentUser::SIGNING_IN || m_recorded_state == CurrentUser::SIGNING_OUT) + if(m_recorded_state == CurrentUser::US_SIGNING_IN || m_recorded_state == CurrentUser::US_SIGNING_OUT) { m_register_widget->setDeactivated(); m_sign_in_widget->setDeactivated(); } } - else if (m_recorded_state == CurrentUser::GUEST) + else if (m_recorded_state == CurrentUser::US_GUEST) { m_find_server_widget->setDeactivated(); m_create_server_widget->setDeactivated(); @@ -150,47 +153,39 @@ // ---------------------------------------------------------------------------- void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver) { - if (hasStateChanged()) - GUIEngine::reshowCurrentScreen(); - if (m_recorded_state == CurrentUser::SIGNING_IN) + if (m_recorded_state == CurrentUser::US_SIGNING_IN) { m_online_status_widget->setText(Messages::signingIn(), false); } - else if (m_recorded_state == CurrentUser::SIGNING_OUT) + else if (m_recorded_state == CurrentUser::US_SIGNING_OUT) { m_online_status_widget->setText(Messages::signingOut(), false); } - XMLRequest * sign_in_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_IN); - if(sign_in_request != NULL) + for(int i = m_requests.size()-1; i>=0; --i) { - if(sign_in_request->isSuccess()) + if(m_requests[i].isDone()) { - new MessageDialog(_("Signed in.")); + if(m_requests[i].getType() == CurrentUser::RT_SIGN_IN) + { + if(m_requests[i].isSuccess()) + { + new MessageDialog(_("Signed in.")); + } + else + { + sfx_manager->quickSound( "anvil" ); + new MessageDialog(m_requests[i].getInfo()); + } + }else if(m_requests[i].getType() == CurrentUser::RT_SIGN_OUT) + { + new MessageDialog(_("Signed out successfully.")); + } + m_requests.erase(i); } - else - { - sfx_manager->quickSound( "anvil" ); - new MessageDialog(sign_in_request->getInfo()); - } - delete sign_in_request; } - XMLRequest * sign_out_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_OUT); - if(sign_out_request != NULL) - { - if(sign_out_request->isSuccess()) - { - new MessageDialog(_("Signed out successfully.")); - } - else - { - sfx_manager->quickSound( "anvil" ); - new MessageDialog(sign_out_request->getInfo()); - } - delete sign_out_request; - } - - + if (hasStateChanged()) + GUIEngine::reshowCurrentScreen(); } // onUpdate // ---------------------------------------------------------------------------- @@ -272,7 +267,7 @@ // ---------------------------------------------------------------------------- void OnlineScreen::setInitialFocus() { - if(m_recorded_state == CurrentUser::SIGNED_IN) + if(m_recorded_state == CurrentUser::US_SIGNED_IN) m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); else m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); Modified: main/branches/uni/src/states_screens/online_screen.hpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.hpp 2013-07-21 15:19:15 UTC (rev 13306) +++ main/branches/uni/src/states_screens/online_screen.hpp 2013-07-21 15:21:48 UTC (rev 13307) @@ -23,6 +23,7 @@ #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/icon_button_widget.hpp" #include "online/current_user.hpp" +#include "utils/ptr_vector.hpp" namespace GUIEngine { class Widget; class ListWidget; } @@ -53,6 +54,8 @@ Online::CurrentUser::UserState m_recorded_state; + PtrVector<Online::XMLRequest> m_requests; + /** \brief Checks if the recorded state differs from the actual state and sets it. */ bool hasStateChanged(); /** \brief Sets which widget has to be focused. Depends on the user state. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-21 20:26:33
|
Revision: 13311 http://sourceforge.net/p/supertuxkart/code/13311 Author: unitraxx Date: 2013-07-21 20:26:27 +0000 (Sun, 21 Jul 2013) Log Message: ----------- Some documentation and thread-safeness. ___Remind me to ask some questions about mutex___! Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/request.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/states_screens/online_screen.cpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-21 17:41:02 UTC (rev 13310) +++ main/branches/uni/src/online/current_user.cpp 2013-07-21 20:26:27 UTC (rev 13311) @@ -88,10 +88,8 @@ CurrentUser::SignInRequest * CurrentUser::requestSavedSession() { SignInRequest * request = NULL; - Log::info("CurrentUser::requestSavedSession","1"); if(m_state != US_SIGNED_IN && UserConfigParams::m_saved_session) { - Log::info("CurrentUser::requestSavedSession","2"); request = new SignInRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action",std::string("saved-session")); Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-21 17:41:02 UTC (rev 13310) +++ main/branches/uni/src/online/request.cpp 2013-07-21 20:26:27 UTC (rev 13311) @@ -29,11 +29,9 @@ // ========================================================================================= Request::Request(int type, bool manage_memory, int priority) - : m_type(type) + : m_type(type), m_manage_memory(manage_memory), m_priority(priority) { - m_priority = priority; - m_manage_memory = manage_memory; - m_cancel = false; + m_cancel.setAtomic(false); m_done.setAtomic(false); } // Request Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-21 17:41:02 UTC (rev 13310) +++ main/branches/uni/src/online/request.hpp 2013-07-21 20:26:27 UTC (rev 13311) @@ -27,28 +27,33 @@ namespace Online{ /** - * Stores a request for the http connector. They will be sorted by priorities. + * Stores a request for the HTTP Manager. They will be sorted by priorities. * \ingroup online */ class Request { private: - const int m_type; - 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; - + /** Can be used as identifier for the user. + * Has 0 as default value. + * Only requests ment to control the HTTP Manager should use negative values, for all other uses positive values are obliged + * */ + const int m_type; /** 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; + const bool m_manage_memory; + /** The priority of this request. The higher the value the more + important this request is. */ + const int m_priority; - Synchronised<bool> m_done; + protected: + /** Cancel this request if it is active. */ + Synchronised<bool> m_cancel; + /** Set to though if the reply of the request is in and callbacks are executed */ + Synchronised<bool> m_done; + virtual void beforeOperation() {} virtual void operation() {}; virtual void afterOperation(); @@ -64,27 +69,27 @@ virtual ~Request(); void execute(); - + int getType() const { return m_type; } // ------------------------------------------------------------------------ + /** 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; } + // ------------------------------------------------------------------------ /** Returns the priority of this request. */ - int getPriority() const { return m_priority; } + int getPriority() const { return m_priority; } // ------------------------------------------------------------------------ /** Signals that this request should be canceled. */ - void cancel() { m_cancel = true; } + void cancel() { m_cancel.setAtomic(true); } // ------------------------------------------------------------------------ /** Returns if this request is to be canceled. */ - bool isCancelled() const { return m_cancel; } + bool isCancelled() const { return m_cancel.getAtomic(); } // ------------------------------------------------------------------------ - /** 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; } + /** Returns if this request is done. */ + bool isDone() const { return m_done.getAtomic(); } + // ------------------------------------------------------------------------ + /** Virtual method to check if a request has initialized all needed members to a valid value. */ + virtual bool isAllowedToAdd() const { return true; } - bool isDone() const { return m_done.getAtomic(); } - - virtual bool isAllowedToAdd() { return true; } - - int getType() const { return m_type; } - /** This class is used by the priority queue to sort requests by priority. */ class Compare @@ -93,7 +98,9 @@ /** 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(); } + { + return a->getPriority() < b->getPriority(); + } }; // Compare }; // Request @@ -106,30 +113,37 @@ protected : - typedef std::map<std::string, std::string> Parameters; - Parameters * m_parameters; + typedef std::map<std::string, std::string> Parameters; - /** The progress indicator. 0 till it is started and the first - * packet is downloaded. At the end eithe -1 (error) or 1 + + /** The progress indicator. 0 untill it is started and the first + * packet is downloaded. At the end either -1 (error) or 1 * (everything ok) at the end. */ - Synchronised<float> m_progress; - std::string m_url; + Synchronised<float> m_progress; + std::string m_url; + Parameters * m_parameters; - virtual void afterOperation(); - std::string downloadPage(); + virtual void afterOperation() OVERRIDE; + /** Executed when a request has finished. */ + virtual void callback() {} + /** + * Performs a POST request to the website with URL m_url using the parameters given in m_parameters. + * Returns the page as a string. + **/ + std::string downloadPage(); - static int progressDownload(void *clientp, - double dltotal, - double dlnow, - double ultotal, - double ulnow); + 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); - virtual void callback() {} + static size_t WriteCallback( void *contents, + size_t size, + size_t nmemb, + void *userp); + public : HTTPRequest(int type = 0, bool manage_memory = false, int priority = 1); virtual ~HTTPRequest(); Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-21 17:41:02 UTC (rev 13310) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-21 20:26:27 UTC (rev 13311) @@ -153,6 +153,8 @@ // ---------------------------------------------------------------------------- void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver) { + if (hasStateChanged()) + GUIEngine::reshowCurrentScreen(); if (m_recorded_state == CurrentUser::US_SIGNING_IN) { m_online_status_widget->setText(Messages::signingIn(), false); @@ -161,7 +163,6 @@ { m_online_status_widget->setText(Messages::signingOut(), false); } - for(int i = m_requests.size()-1; i>=0; --i) { if(m_requests[i].isDone()) @@ -184,8 +185,6 @@ m_requests.erase(i); } } - if (hasStateChanged()) - GUIEngine::reshowCurrentScreen(); } // onUpdate // ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-22 00:23:45
|
Revision: 13315 http://sourceforge.net/p/supertuxkart/code/13315 Author: unitraxx Date: 2013-07-22 00:23:42 +0000 (Mon, 22 Jul 2013) Log Message: ----------- small fixes to let server joining work. (temporary version though.) Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-22 00:22:30 UTC (rev 13314) +++ main/branches/uni/src/online/current_user.cpp 2013-07-22 00:23:42 UTC (rev 13315) @@ -25,6 +25,7 @@ #include "config/user_config.hpp" #include "utils/translation.hpp" #include "utils/log.hpp" +#include "online/servers_manager.hpp" namespace Online{ static Synchronised<CurrentUser*> user_singleton(NULL); @@ -209,6 +210,7 @@ request->setParameter("token", m_token); request->setParameter("id", m_id); request->setParameter("server_id", server_id); + HTTPManager::get()->addRequest(request); return request; } Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-22 00:22:30 UTC (rev 13314) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-22 00:23:42 UTC (rev 13315) @@ -64,7 +64,8 @@ m_cancel_widget = getWidget<IconButtonWidget>("cancel"); assert(m_cancel_widget != NULL); m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - requestJoin(); + if (join) + requestJoin(); } // ----------------------------------------------------------------------------- @@ -75,7 +76,7 @@ // ----------------------------------------------------------------------------- void ServerInfoDialog::requestJoin() { - Online::CurrentUser::acquire()->requestServerJoin(m_server->getServerId()); + m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server->getServerId()); Online::CurrentUser::release(); } @@ -122,6 +123,8 @@ { if(m_server_join_request->isSuccess()) { + ServersManager::acquire()->setJoinedServer(m_server); + ServersManager::release(); m_enter_lobby = true; } else @@ -148,7 +151,9 @@ { ModalDialog::dismiss(); if (m_enter_lobby) + { StateManager::get()->pushScreen(NetworkingLobby::getInstance()); + } return; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-23 01:37:52
|
Revision: 13323 http://sourceforge.net/p/supertuxkart/code/13323 Author: unitraxx Date: 2013-07-23 01:37:49 +0000 (Tue, 23 Jul 2013) Log Message: ----------- Fixed the bug in rejoining a lobby. Added a lot of mutex stuff, which wasn't actually related to the problem at all. Modified Paths: -------------- main/branches/uni/src/online/request.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/online/servers_manager.cpp main/branches/uni/src/online/servers_manager.hpp main/branches/uni/src/states_screens/networking_lobby.cpp main/branches/uni/src/states_screens/server_selection.cpp main/branches/uni/src/states_screens/server_selection.hpp Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/online/request.cpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -58,7 +58,7 @@ { //Negative numbers are reserved for special requests ment for the HTTP Manager assert(type >= 0); - m_url = ""; + m_url.setAtomic(""); m_parameters = new Parameters; m_progress.setAtomic(0); } @@ -70,9 +70,12 @@ bool HTTPRequest::isAllowedToAdd() { - if (m_url.size() > 5 && ( m_url.substr(0, 5) != "http:")) - return false; - return true; + bool ok = true; + m_url.lock(); + if (m_url.getData().size() > 5 && ( m_url.getData().substr(0, 5) != "http:")) + ok = false; + m_url.unlock(); + return ok; } void HTTPRequest::afterOperation() @@ -90,8 +93,7 @@ Log::error("online/http_functions", "Error while initialising libCurl session"); return ""; } - - curl_easy_setopt(curl_session, CURLOPT_URL, m_url.c_str()); + curl_easy_setopt(curl_session, CURLOPT_URL, m_url.getAtomic().c_str()); Parameters::iterator iter; std::string postString = ""; for (iter = m_parameters->begin(); iter != m_parameters->end(); ++iter) @@ -195,12 +197,17 @@ XMLRequest::XMLRequest(int type, bool manage_memory, int priority) : HTTPRequest(priority, manage_memory, type) { - m_info = ""; - m_success = false; + m_info.setAtomic(""); + m_success.setAtomic(false); m_result = NULL; } + XMLRequest::~XMLRequest() + { + delete m_result; + } + void XMLRequest::operation() { m_result = file_manager->createXMLTreeFromString(downloadPage()); @@ -220,8 +227,8 @@ } else info = _("Unable to connect to the server. Check your internet connection or try again later."); - m_info = info; - m_success = success; + m_info.setAtomic(info); + m_success.setAtomic(success); HTTPRequest::afterOperation(); } } // namespace Online Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/online/request.hpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -120,7 +120,7 @@ * packet is downloaded. At the end either -1 (error) or 1 * (everything ok) at the end. */ Synchronised<float> m_progress; - std::string m_url; + Synchronised<std::string> m_url; Parameters * m_parameters; virtual void afterOperation() OVERRIDE; @@ -164,9 +164,15 @@ /** Sets the current progress. */ void setProgress(float f) { m_progress.setAtomic(f); } - const std::string &getURL() const {return m_url;} - void setURL(const std::string & url) { m_url = url;} + const std::string getURL() { + m_url.lock(); + const std::string url = m_url.getData(); + m_url.unlock(); + return url; + } + void setURL(const std::string & url) { m_url.setAtomic(url);} + virtual bool isAllowedToAdd() OVERRIDE; }; @@ -175,20 +181,25 @@ { protected : - XMLNode * m_result; - irr::core::stringw m_info; - bool m_success; + XMLNode * m_result; + Synchronised<irr::core::stringw> m_info; + Synchronised<bool> m_success; virtual void operation() OVERRIDE; virtual void afterOperation() OVERRIDE; public : XMLRequest(int type = 0, bool manage_memory = false, int priority = 1); - virtual ~XMLRequest() {delete m_result;} + virtual ~XMLRequest(); virtual XMLNode * getResult() const { return m_result; } - const irr::core::stringw & getInfo() const { return m_info; } - bool isSuccess() const { return m_success; } + const irr::core::stringw getInfo() { + m_info.lock(); + const irr::core::stringw info = m_info.getData(); + m_info.unlock(); + return info; + } + bool isSuccess() const { return m_success.getAtomic(); } }; } //namespace Online Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -87,7 +87,7 @@ return request; } - void ServersManager::refresh(const RefreshRequest * input) + void ServersManager::refresh(RefreshRequest * input) { if (input->isSuccess()) { Modified: main/branches/uni/src/online/servers_manager.hpp =================================================================== --- main/branches/uni/src/online/servers_manager.hpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/online/servers_manager.hpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -54,7 +54,7 @@ Server * m_joined_server; irr::core::stringw m_info_message; float m_last_load_time; - void refresh(const RefreshRequest * input); + void refresh(RefreshRequest * input); public: // Singleton Modified: main/branches/uni/src/states_screens/networking_lobby.cpp =================================================================== --- main/branches/uni/src/states_screens/networking_lobby.cpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/states_screens/networking_lobby.cpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -46,8 +46,7 @@ NetworkingLobby::NetworkingLobby() : Screen("online/lobby.stkgui") { - m_server = ServersManager::acquire()->getJoinedServer(); - ServersManager::release(); + m_server = NULL; } // NetworkingLobby // ---------------------------------------------------------------------------- @@ -85,6 +84,8 @@ Screen::init(); setInitialFocus(); DemoWorld::resetIdleTime(); //FIXME : what's this? + m_server = ServersManager::acquire()->getJoinedServer(); + ServersManager::release(); m_server_name_widget->setText(m_server->getName(),false); } // init Modified: main/branches/uni/src/states_screens/server_selection.cpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.cpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/states_screens/server_selection.cpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -46,10 +46,16 @@ ServerSelection::~ServerSelection() { - delete m_refresh_request; } // ServerSelection +// ---------------------------------------------------------------------------- +void ServerSelection::tearDown() +{ + delete m_refresh_request; +} // tearDown + + // ---------------------------------------------------------------------------- void ServerSelection::refresh() Modified: main/branches/uni/src/states_screens/server_selection.hpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.hpp 2013-07-22 23:07:45 UTC (rev 13322) +++ main/branches/uni/src/states_screens/server_selection.hpp 2013-07-23 01:37:49 UTC (rev 13323) @@ -76,6 +76,8 @@ virtual void init() OVERRIDE; + virtual void tearDown() OVERRIDE; + /** \brief implement callback from parent class GUIEngine::Screen */ virtual void onUpdate(float dt, irr::video::IVideoDriver*) OVERRIDE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-23 16:34:42
|
Revision: 13326 http://sourceforge.net/p/supertuxkart/code/13326 Author: unitraxx Date: 2013-07-23 16:34:38 +0000 (Tue, 23 Jul 2013) Log Message: ----------- Replaced all non-related GUI code actions done after a reply to request callbacks. Servers manager now allows getting by ID and sort index. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/online/servers_manager.cpp main/branches/uni/src/online/servers_manager.hpp main/branches/uni/src/states_screens/create_server_screen.cpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp main/branches/uni/src/states_screens/server_selection.cpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/online/current_user.cpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -163,7 +163,13 @@ void CurrentUser::ServerCreationRequest::callback() { - //FIXME + if(isSuccess()) + { + Server * server = new Server(*getResult()->getNode("server")); + ServersManager::acquire()->addServer(server); + ServersManager::release(); + m_created_server_id.setAtomic(server->getServerId()); + } } // ============================================================================ @@ -216,6 +222,14 @@ void CurrentUser::ServerJoinRequest::callback() { + if(isSuccess()) + { + uint32_t server_id; + getResult()->get("serverid", &server_id); + ServersManager::acquire()->setJoinedServer(server_id); + ServersManager::release(); + } + //FIXME needs changes for actual valid joining } // ============================================================================ Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/online/current_user.hpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -72,8 +72,10 @@ class ServerCreationRequest : public XMLRequest { virtual void callback (); + Synchronised<uint32_t> m_created_server_id; public: ServerCreationRequest() : XMLRequest(RT_SERVER_CREATION) {} + uint32_t getCreatedServerID() {return m_created_server_id.getAtomic();} }; class ServerJoinRequest : public XMLRequest { Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -62,18 +62,24 @@ // ============================================================================ ServersManager::ServersManager(){ - m_servers = new PtrVector<Server>; m_info_message = ""; m_last_load_time = 0.0f; m_joined_server = NULL; } ServersManager::~ServersManager(){ - m_servers->clearAndDeleteAll(); + cleanUpServers(); delete m_joined_server; } // ============================================================================ + void ServersManager::cleanUpServers() + { + m_sorted_servers.clearAndDeleteAll(); + m_mapped_servers.clear(); + } + + // ============================================================================ ServersManager::RefreshRequest * ServersManager::refreshRequest() { RefreshRequest * request = NULL; @@ -92,10 +98,10 @@ if (input->isSuccess()) { const XMLNode * servers_xml = input->getResult()->getNode("servers"); - m_servers->clearAndDeleteAll(); + cleanUpServers(); for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++) { - m_servers->push_back(new Server(*servers_xml->getNode(i))); + addServer(new Server(*servers_xml->getNode(i))); } m_last_load_time = Time::getRealTime(); } @@ -112,8 +118,48 @@ // ============================================================================ Server * ServersManager::getQuickPlay() { - if(m_servers->size() > 0) - return m_servers->get(0); + if(m_sorted_servers.size() > 0) + return getServerBySort(0); return NULL; } + + // ============================================================================ + void ServersManager::setJoinedServer(uint32_t id) + { + delete m_joined_server; + //It's a copy! + m_joined_server = new Server(*getServerByID(id)); + } + + // ============================================================================ + void ServersManager::unsetJoinedServer() + { + delete m_joined_server; + m_joined_server = NULL; + } + + // ============================================================================ + void ServersManager::addServer(Server * server) + { + m_sorted_servers.push_back(server); + m_mapped_servers[server->getServerId()] = server; + } + + // ============================================================================ + int ServersManager::getNumServers () + { + return m_sorted_servers.size(); + } + + // ============================================================================ + Server * ServersManager::getServerBySort (int index) + { + return m_sorted_servers.get(index); + } + + // ============================================================================ + Server * ServersManager::getServerByID (uint32_t id) + { + return m_mapped_servers[id]; + } } // namespace Online Modified: main/branches/uni/src/online/servers_manager.hpp =================================================================== --- main/branches/uni/src/online/servers_manager.hpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/online/servers_manager.hpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -20,6 +20,7 @@ #define HEADER_SERVERS_MANAGER_HPP #include "utils/ptr_vector.hpp" +#include "utils/types.hpp" #include "online/server.hpp" #include "http_manager.hpp" @@ -49,12 +50,18 @@ private: ServersManager(); ~ServersManager(); - PtrVector<Server> * m_servers; + /** Sorted vector of servers */ + PtrVector<Server> m_sorted_servers; + /** Maps server id's to the same servers*/ + std::map<uint32_t, Server*> m_mapped_servers; + /** This is a pointer to a copy of the server, the moment it got joined */ + Server * m_joined_server; + bool m_not_fetched; - Server * m_joined_server; irr::core::stringw m_info_message; float m_last_load_time; void refresh(RefreshRequest * input); + void cleanUpServers(); public: // Singleton @@ -63,11 +70,13 @@ static void deallocate(); RefreshRequest * refreshRequest(); - PtrVector<Server> * getServers () const { return m_servers; } - int getNumServers () const { return m_servers->size(); } - Server * getServer (int index) const { return m_servers->get(index); } - void sort(bool sort_desc) { m_servers->insertionSort(0, sort_desc); } - void setJoinedServer(Server * server){ m_joined_server = server; } + void setJoinedServer(uint32_t server_id); + void unsetJoinedServer(); + void addServer(Server * server); + int getNumServers (); + Server * getServerByID (uint32_t server_id); + Server * getServerBySort (int index); + void sort(bool sort_desc) { m_sorted_servers.insertionSort(0, sort_desc); } Server * getJoinedServer() { return m_joined_server; } //Returns the best server to join Server * getQuickPlay(); Modified: main/branches/uni/src/states_screens/create_server_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/create_server_screen.cpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/states_screens/create_server_screen.cpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -97,8 +97,7 @@ if(m_server_creation_request->isSuccess()) { if (m_enter_server){ - Server * server = new Server(*m_server_creation_request->getResult()->getNode("server")); - new ServerInfoDialog(server,true); + new ServerInfoDialog(m_server_creation_request->getCreatedServerID(),true); } else { Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -40,10 +40,10 @@ // ----------------------------------------------------------------------------- -ServerInfoDialog::ServerInfoDialog(Server * server, bool join) : +ServerInfoDialog::ServerInfoDialog(uint32_t server_id, bool join) : ModalDialog(0.8f,0.8f) { - m_server = server; + m_server_id = server_id; m_self_destroy = false; m_enter_lobby = false; m_server_join_request = NULL; @@ -52,8 +52,9 @@ m_name_widget = getWidget<LabelWidget>("name"); assert(m_name_widget != NULL); + Server * server = ServersManager::acquire()->getServerByID(m_server_id); m_name_widget->setText(server->getName(),false); - + ServersManager::release(); m_info_widget = getWidget<LabelWidget>("info"); assert(m_info_widget != NULL); @@ -76,7 +77,7 @@ // ----------------------------------------------------------------------------- void ServerInfoDialog::requestJoin() { - m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server->getServerId()); + m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server_id); Online::CurrentUser::release(); } @@ -123,8 +124,6 @@ { if(m_server_join_request->isSuccess()) { - ServersManager::acquire()->setJoinedServer(m_server); - ServersManager::release(); m_enter_lobby = true; } else Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -27,6 +27,7 @@ #include "guiengine/widgets/label_widget.hpp" #include "online/server.hpp" #include "online/current_user.hpp" +#include "utils/types.hpp" /** @@ -44,7 +45,7 @@ float m_load_timer; - Online::Server * m_server; + uint32_t m_server_id; GUIEngine::LabelWidget * m_name_widget; GUIEngine::LabelWidget * m_info_widget; @@ -56,7 +57,7 @@ void requestJoin(); public: - ServerInfoDialog(Online::Server * server, bool join = false); + ServerInfoDialog(uint32_t server_id, bool join = false); ~ServerInfoDialog(); void onEnterPressedInternal(); Modified: main/branches/uni/src/states_screens/server_selection.cpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.cpp 2013-07-23 16:18:44 UTC (rev 13325) +++ main/branches/uni/src/states_screens/server_selection.cpp 2013-07-23 16:34:38 UTC (rev 13326) @@ -117,7 +117,7 @@ manager->sort(m_sort_desc); for(int i=0; i < manager->getNumServers(); i++) { - Server * server = manager->getServer(i); + Server * server = manager->getServerBySort(i); core::stringw num_players; num_players.append(StringUtils::toWString(server->getCurrentPlayers())); num_players.append("/"); @@ -162,8 +162,9 @@ else if (name == m_server_list_widget->m_properties[GUIEngine::PROP_ID]) { m_selected_index = m_server_list_widget->getSelectionID(); - new ServerInfoDialog(ServersManager::acquire()->getServer(m_selected_index)); + uint32_t server_id = ServersManager::acquire()->getServerBySort(m_selected_index)->getServerId(); ServersManager::release(); + new ServerInfoDialog(server_id); } } // eventCallback This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-23 23:54:57
|
Revision: 13334 http://sourceforge.net/p/supertuxkart/code/13334 Author: unitraxx Date: 2013-07-23 23:54:55 +0000 (Tue, 23 Jul 2013) Log Message: ----------- Client-side code related to previous commit Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-23 23:54:03 UTC (rev 13333) +++ main/branches/uni/src/online/current_user.cpp 2013-07-23 23:54:55 UTC (rev 13334) @@ -77,10 +77,12 @@ assert(m_state == US_SIGNED_OUT || m_state == US_GUEST); XMLRequest * request = new XMLRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); - request->setParameter("action",std::string("register")); - request->setParameter("username",username); - request->setParameter("password",password); - request->setParameter("password_confirm",password_confirm); + request->setParameter("action", std::string("register")); + request->setParameter("username", username); + request->setParameter("password", password); + request->setParameter("password_confirm", password_confirm); + request->setParameter("email", email); + request->setParameter("terms", std::string("on")); HTTPManager::get()->addRequest(request); return request; } Modified: main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp 2013-07-23 23:54:03 UTC (rev 13333) +++ main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp 2013-07-23 23:54:55 UTC (rev 13334) @@ -125,7 +125,6 @@ m_info_widget = getWidget<LabelWidget>("info"); assert(m_info_widget != NULL); - m_info_widget->setText(m_registration_error, false); m_options_widget = getWidget<RibbonWidget>("options"); assert(m_options_widget != NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-25 02:22:56
|
Revision: 13346 http://sourceforge.net/p/supertuxkart/code/13346 Author: unitraxx Date: 2013-07-25 02:22:53 +0000 (Thu, 25 Jul 2013) Log Message: ----------- acquire/release approach removed for ServersManager. Added MutexLocker to synchronised.hpp. CurrentUser will folow after sleepy times. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/online/servers_manager.cpp main/branches/uni/src/online/servers_manager.hpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp main/branches/uni/src/states_screens/networking_lobby.cpp main/branches/uni/src/states_screens/server_selection.cpp main/branches/uni/src/states_screens/server_selection.hpp main/branches/uni/src/utils/synchronised.hpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/online/current_user.cpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -168,8 +168,7 @@ if(isSuccess()) { Server * server = new Server(*getResult()->getNode("server")); - ServersManager::acquire()->addServer(server); - ServersManager::release(); + ServersManager::get()->addServer(server); m_created_server_id.setAtomic(server->getServerId()); } } @@ -228,8 +227,7 @@ { uint32_t server_id; getResult()->get("serverid", &server_id); - ServersManager::acquire()->setJoinedServer(server_id); - ServersManager::release(); + ServersManager::get()->setJoinedServer(server_id); } //FIXME needs changes for actual valid joining } Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/online/request.hpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -193,7 +193,7 @@ virtual ~XMLRequest(); virtual XMLNode * getResult() const { return m_result; } - const irr::core::stringw getInfo() { + const irr::core::stringw getInfo() const { m_info.lock(); const irr::core::stringw info = m_info.getData(); m_info.unlock(); Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -30,60 +30,51 @@ namespace Online{ - static Synchronised<ServersManager*> manager_singleton(NULL); + static ServersManager* manager_singleton(NULL); - ServersManager* ServersManager::acquire() + ServersManager* ServersManager::get() { - manager_singleton.lock(); - ServersManager * manager = manager_singleton.getData(); - if (manager == NULL) - { - manager_singleton.unlock(); - manager = new ServersManager(); - manager_singleton.setAtomic(manager); - manager_singleton.lock(); - } - return manager; + if (manager_singleton == NULL) + manager_singleton = new ServersManager(); + return manager_singleton; } - void ServersManager::release() - { - manager_singleton.unlock(); - } - void ServersManager::deallocate() { - manager_singleton.lock(); - ServersManager* manager = manager_singleton.getData(); - delete manager; - manager = NULL; - manager_singleton.unlock(); + delete manager_singleton; + manager_singleton = NULL; } // deallocate // ============================================================================ ServersManager::ServersManager(){ - m_info_message = ""; - m_last_load_time = 0.0f; - m_joined_server = NULL; + m_info_message.setAtomic(""); + m_last_load_time.setAtomic(0.0f); + m_joined_server.setAtomic(NULL); } ServersManager::~ServersManager(){ cleanUpServers(); - delete m_joined_server; + m_joined_server.lock(); + delete m_joined_server.getData(); + m_joined_server.unlock(); } // ============================================================================ void ServersManager::cleanUpServers() { - m_sorted_servers.clearAndDeleteAll(); - m_mapped_servers.clear(); + m_sorted_servers.lock(); + m_sorted_servers.getData().clearAndDeleteAll(); + m_sorted_servers.unlock(); + m_mapped_servers.lock(); + m_mapped_servers.getData().clear(); + m_mapped_servers.unlock(); } // ============================================================================ - ServersManager::RefreshRequest * ServersManager::refreshRequest() + const ServersManager::RefreshRequest * ServersManager::refreshRequest() const { RefreshRequest * request = NULL; - if(Time::getRealTime() - m_last_load_time > SERVER_REFRESH_INTERVAL) + if(Time::getRealTime() - m_last_load_time.getAtomic() > SERVER_REFRESH_INTERVAL) { request = new RefreshRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); @@ -103,63 +94,87 @@ { addServer(new Server(*servers_xml->getNode(i))); } - m_last_load_time = Time::getRealTime(); + m_last_load_time.setAtomic(Time::getRealTime()); } - m_info_message = input->getInfo(); + m_info_message.setAtomic(input->getInfo()); //FIXME error message } void ServersManager::RefreshRequest::callback() { - ServersManager::acquire()->refresh(this); - ServersManager::release(); + ServersManager::get()->refresh(this); } // ============================================================================ - Server * ServersManager::getQuickPlay() + const Server * ServersManager::getQuickPlay() const { - if(m_sorted_servers.size() > 0) + /*if(m_sorted_servers.size() > 0) return getServerBySort(0); - return NULL; + return NULL;*/ } // ============================================================================ void ServersManager::setJoinedServer(uint32_t id) { - delete m_joined_server; + m_joined_server.lock(); + delete m_joined_server.getData(); //It's a copy! - m_joined_server = new Server(*getServerByID(id)); + m_joined_server.getData() = new Server(*getServerByID(id)); + m_joined_server.unlock(); } // ============================================================================ void ServersManager::unsetJoinedServer() { - delete m_joined_server; - m_joined_server = NULL; + m_joined_server.lock(); + delete m_joined_server.getData(); + m_joined_server.getData() = NULL; + m_joined_server.unlock(); } // ============================================================================ void ServersManager::addServer(Server * server) { - m_sorted_servers.push_back(server); - m_mapped_servers[server->getServerId()] = server; + m_sorted_servers.lock(); + m_sorted_servers.getData().push_back(server); + m_sorted_servers.unlock(); + m_mapped_servers.lock(); + m_mapped_servers.getData()[server->getServerId()] = server; + m_mapped_servers.unlock(); } // ============================================================================ - int ServersManager::getNumServers () + int ServersManager::getNumServers () const { - return m_sorted_servers.size(); + MutexLocker locker(m_sorted_servers); + return m_sorted_servers.getData().size(); } // ============================================================================ - Server * ServersManager::getServerBySort (int index) + const Server * ServersManager::getServerBySort (int index) const { - return m_sorted_servers.get(index); + MutexLocker locker(m_sorted_servers); + return m_sorted_servers.getData().get(index); } // ============================================================================ - Server * ServersManager::getServerByID (uint32_t id) + const Server * ServersManager::getServerByID (uint32_t id) const { - return m_mapped_servers[id]; + MutexLocker locker(m_mapped_servers); + return m_mapped_servers.getData().at(id); } + + // ============================================================================ + Server * ServersManager::getJoinedServer() const + { + return m_joined_server.getAtomic(); + } + + // ============================================================================ + void ServersManager::sort(bool sort_desc){ + m_sorted_servers.lock(); + m_sorted_servers.getData().insertionSort(0, sort_desc); + m_sorted_servers.unlock(); + } + } // namespace Online Modified: main/branches/uni/src/online/servers_manager.hpp =================================================================== --- main/branches/uni/src/online/servers_manager.hpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/online/servers_manager.hpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -23,9 +23,11 @@ #include "utils/types.hpp" #include "online/server.hpp" #include "http_manager.hpp" +#include "utils/synchronised.hpp" + namespace Online { /** @@ -51,35 +53,33 @@ ServersManager(); ~ServersManager(); /** Sorted vector of servers */ - PtrVector<Server> m_sorted_servers; + Synchronised<PtrVector<Server> > m_sorted_servers; /** Maps server id's to the same servers*/ - std::map<uint32_t, Server*> m_mapped_servers; + Synchronised<std::map<uint32_t, Server*> > m_mapped_servers; /** This is a pointer to a copy of the server, the moment it got joined */ - Server * m_joined_server; + Synchronised<Server *> m_joined_server; - bool m_not_fetched; - irr::core::stringw m_info_message; - float m_last_load_time; - void refresh(RefreshRequest * input); - void cleanUpServers(); + Synchronised<irr::core::stringw> m_info_message; + Synchronised<float> m_last_load_time; + void refresh(RefreshRequest * input); + void cleanUpServers(); public: // Singleton - static ServersManager* acquire(); - static void release(); - static void deallocate(); + static ServersManager* get(); + static void deallocate(); - RefreshRequest * refreshRequest(); - void setJoinedServer(uint32_t server_id); - void unsetJoinedServer(); - void addServer(Server * server); - int getNumServers (); - Server * getServerByID (uint32_t server_id); - Server * getServerBySort (int index); - void sort(bool sort_desc) { m_sorted_servers.insertionSort(0, sort_desc); } - Server * getJoinedServer() { return m_joined_server; } + const RefreshRequest * refreshRequest() const; + void setJoinedServer(uint32_t server_id); + void unsetJoinedServer(); + void addServer(Server * server); + int getNumServers () const; + const Server * getServerByID (uint32_t server_id) const; + const Server * getServerBySort (int index) const; + void sort(bool sort_desc); + Server * getJoinedServer() const; //Returns the best server to join - Server * getQuickPlay(); + const Server * getQuickPlay() const; }; // class ServersManager Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -53,9 +53,8 @@ m_name_widget = getWidget<LabelWidget>("name"); assert(m_name_widget != NULL); - Server * server = ServersManager::acquire()->getServerByID(m_server_id); + const Server * server = ServersManager::get()->getServerByID(m_server_id); m_name_widget->setText(server->getName(),false); - ServersManager::release(); m_info_widget = getWidget<LabelWidget>("info"); assert(m_info_widget != NULL); if (m_from_server_creation) Modified: main/branches/uni/src/states_screens/networking_lobby.cpp =================================================================== --- main/branches/uni/src/states_screens/networking_lobby.cpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/states_screens/networking_lobby.cpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -84,8 +84,7 @@ Screen::init(); setInitialFocus(); DemoWorld::resetIdleTime(); //FIXME : what's this? - m_server = ServersManager::acquire()->getJoinedServer(); - ServersManager::release(); + m_server = ServersManager::get()->getJoinedServer(); m_server_name_widget->setText(m_server->getName(),false); } // init Modified: main/branches/uni/src/states_screens/server_selection.cpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.cpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/states_screens/server_selection.cpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -60,8 +60,7 @@ void ServerSelection::refresh() { - m_refresh_request = ServersManager::acquire()->refreshRequest(); - ServersManager::release(); + m_refresh_request = ServersManager::get()->refreshRequest(); m_fake_refresh = (m_refresh_request == NULL ? true : false); m_server_list_widget->clear(); m_server_list_widget->addItem("spacer", L""); @@ -113,11 +112,11 @@ void ServerSelection::loadList() { m_server_list_widget->clear(); - ServersManager * manager = ServersManager::acquire(); + ServersManager * manager = ServersManager::get(); manager->sort(m_sort_desc); for(int i=0; i < manager->getNumServers(); i++) { - Server * server = manager->getServerBySort(i); + const Server * server = manager->getServerBySort(i); core::stringw num_players; num_players.append(StringUtils::toWString(server->getCurrentPlayers())); num_players.append("/"); @@ -127,7 +126,6 @@ row->push_back(new GUIEngine::ListWidget::ListCell(num_players,-1,1,true)); m_server_list_widget->addItem("server", row); } - ServersManager::release(); } // loadList // ---------------------------------------------------------------------------- @@ -162,8 +160,7 @@ else if (name == m_server_list_widget->m_properties[GUIEngine::PROP_ID]) { m_selected_index = m_server_list_widget->getSelectionID(); - uint32_t server_id = ServersManager::acquire()->getServerBySort(m_selected_index)->getServerId(); - ServersManager::release(); + uint32_t server_id = ServersManager::get()->getServerBySort(m_selected_index)->getServerId(); new ServerInfoDialog(server_id); } Modified: main/branches/uni/src/states_screens/server_selection.hpp =================================================================== --- main/branches/uni/src/states_screens/server_selection.hpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/states_screens/server_selection.hpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -53,7 +53,7 @@ /** \brief To check (and set) if sort order is descending **/ bool m_sort_desc; - Online::ServersManager::RefreshRequest * m_refresh_request; + const Online::ServersManager::RefreshRequest * m_refresh_request; bool m_fake_refresh; void refresh(); Modified: main/branches/uni/src/utils/synchronised.hpp =================================================================== --- main/branches/uni/src/utils/synchronised.hpp 2013-07-25 01:40:52 UTC (rev 13345) +++ main/branches/uni/src/utils/synchronised.hpp 2013-07-25 02:22:53 UTC (rev 13346) @@ -21,11 +21,20 @@ #include <pthread.h> -template<typename TYPE> + +class ISynchronised +{ +public : + virtual ~ISynchronised() {} + virtual void lock() const = 0 ; + virtual void unlock() const = 0; +}; + /** A variable that is automatically synchronised using pthreads mutex. */ -class Synchronised +template<typename TYPE> +class Synchronised : public ISynchronised { private: /** The mutex to protect this variable with. */ @@ -97,11 +106,11 @@ /** Locks the mutex. Note that calls to get() or set() will fail, since * they will try to lock the mutex as well! */ - void lock() { pthread_mutex_lock(&m_mutex); } + void lock() const { pthread_mutex_lock(&m_mutex); } // ------------------------------------------------------------------------ /** Unlocks the mutex. */ - void unlock() {pthread_mutex_unlock(&m_mutex); } + void unlock() const {pthread_mutex_unlock(&m_mutex); } // ------------------------------------------------------------------------ /** Gives access to the mutex, which can then be used in other pthread * calls (e.g. pthread_cond_wait). @@ -114,4 +123,19 @@ }; +class MutexLocker +{ + const ISynchronised * m_synchronised; +public: + MutexLocker(const ISynchronised & synchronised){ + m_synchronised = &synchronised; + m_synchronised->lock(); + } + + ~MutexLocker(){ + m_synchronised->unlock(); + } +}; + + #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-07-25 14:01:23
|
Revision: 13351 http://sourceforge.net/p/supertuxkart/code/13351 Author: unitraxx Date: 2013-07-25 14:01:20 +0000 (Thu, 25 Jul 2013) Log Message: ----------- CurrentUser doesn't use acquire and releqse anymore. Mutexes added to the members. Modified Paths: -------------- main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/online/request.cpp main/branches/uni/src/online/request.hpp main/branches/uni/src/online/servers_manager.cpp main/branches/uni/src/online/servers_manager.hpp main/branches/uni/src/online/user.cpp main/branches/uni/src/online/user.hpp main/branches/uni/src/states_screens/create_server_screen.cpp main/branches/uni/src/states_screens/create_server_screen.hpp main/branches/uni/src/states_screens/dialogs/login_dialog.cpp main/branches/uni/src/states_screens/dialogs/login_dialog.hpp main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp main/branches/uni/src/states_screens/online_screen.cpp main/branches/uni/src/states_screens/online_screen.hpp main/branches/uni/src/utils/synchronised.hpp Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/current_user.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -27,54 +27,41 @@ #include "utils/log.hpp" #include "online/servers_manager.hpp" +using namespace Online; + namespace Online{ - static Synchronised<CurrentUser*> user_singleton(NULL); + static CurrentUser* current_user_singleton(NULL); - CurrentUser* CurrentUser::acquire() + CurrentUser* CurrentUser::get() { - user_singleton.lock(); - CurrentUser * user = user_singleton.getData(); - if (user == NULL) - { - user_singleton.unlock(); - user = new CurrentUser(); - user_singleton.setAtomic(user); - user_singleton.lock(); - } - return user; + if (current_user_singleton == NULL) + current_user_singleton = new CurrentUser(); + return current_user_singleton; } - void CurrentUser::release() - { - user_singleton.unlock(); - } - void CurrentUser::deallocate() { - user_singleton.lock(); - CurrentUser* user = user_singleton.getData(); - delete user; - user = NULL; - user_singleton.unlock(); + delete current_user_singleton; + current_user_singleton = NULL; } // deallocate // ============================================================================ - CurrentUser::CurrentUser(){ - m_state = US_SIGNED_OUT; - m_id = 0; - m_name = ""; - m_token = ""; - m_save_session = false; + CurrentUser::CurrentUser() + : User("",0) + { + setState(US_SIGNED_OUT); + setToken(""); + setSaveSession(false); } // ============================================================================ - XMLRequest * CurrentUser::requestSignUp( const irr::core::stringw &username, - const irr::core::stringw &password, - const irr::core::stringw &password_confirm, - const irr::core::stringw &email, - bool terms) + const XMLRequest * CurrentUser::requestSignUp( const irr::core::stringw &username, + const irr::core::stringw &password, + const irr::core::stringw &password_confirm, + const irr::core::stringw &email, + bool terms) { - assert(m_state == US_SIGNED_OUT || m_state == US_GUEST); + assert(getState() == US_SIGNED_OUT || getState() == US_GUEST); XMLRequest * request = new XMLRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action", std::string("register")); @@ -88,10 +75,10 @@ } // ============================================================================ - CurrentUser::SignInRequest * CurrentUser::requestSavedSession() + const CurrentUser::SignInRequest * CurrentUser::requestSavedSession() { SignInRequest * request = NULL; - if(m_state != US_SIGNED_IN && UserConfigParams::m_saved_session) + if(getState() != US_SIGNED_IN && UserConfigParams::m_saved_session) { request = new SignInRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); @@ -99,24 +86,24 @@ request->setParameter("userid", UserConfigParams::m_saved_user); request->setParameter("token", UserConfigParams::m_saved_token.c_str()); HTTPManager::get()->addRequest(request); - m_state = US_SIGNING_IN; + setState(US_SIGNING_IN); } return request; } - CurrentUser::SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username, - const irr::core::stringw &password, - bool save_session) + const CurrentUser::SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username, + const irr::core::stringw &password, + bool save_session) { - assert(m_state == US_SIGNED_OUT); - m_save_session = save_session; + assert(getState() == US_SIGNED_OUT); + setSaveSession(save_session); SignInRequest * request = new SignInRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action",std::string("connect")); request->setParameter("username",username); request->setParameter("password",password); HTTPManager::get()->addRequest(request); - m_state = US_SIGNING_IN; + setState(US_SIGNING_IN); return request; } @@ -124,39 +111,44 @@ { if (input->isSuccess()) { - int token_fetched = input->getResult()->get("token", &m_token); - int username_fetched = input->getResult()->get("username", &m_name); - int userid_fetched = input->getResult()->get("userid", &m_id); + std::string token(""); + int token_fetched = input->getResult()->get("token", &token); + setToken(token); + irr::core::stringw username(""); + int username_fetched = input->getResult()->get("username", &username); + setUserName(username); + uint32_t userid(0); + int userid_fetched = input->getResult()->get("userid", &userid); + setUserID(userid); assert(token_fetched && username_fetched && userid_fetched); - m_state = US_SIGNED_IN; - if(m_save_session) + setState(US_SIGNED_IN); + if(getSaveSession()) { - UserConfigParams::m_saved_user = m_id; - UserConfigParams::m_saved_token = m_token; + UserConfigParams::m_saved_user = getUserID(); + UserConfigParams::m_saved_token = getToken(); UserConfigParams::m_saved_session = true; - m_save_session = false; } } else - m_state = US_SIGNED_OUT; + setState(US_SIGNED_OUT); } void CurrentUser::SignInRequest::callback() { - CurrentUser::acquire()->signIn(this); - CurrentUser::release(); + CurrentUser::get()->signIn(this); } // ============================================================================ - CurrentUser::ServerCreationRequest * CurrentUser::requestServerCreation(const irr::core::stringw &name, int max_players) + const CurrentUser::ServerCreationRequest * CurrentUser::requestServerCreation( const irr::core::stringw &name, + int max_players) { - assert(m_state == US_SIGNED_IN); + assert(getState() == US_SIGNED_IN); ServerCreationRequest * request = new ServerCreationRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action", std::string("create_server")); - request->setParameter("token", m_token); - request->setParameter("userid", m_id); + request->setParameter("token", getToken()); + request->setParameter("userid", getUserID()); request->setParameter("name", name); request->setParameter("max_players", max_players); HTTPManager::get()->addRequest(request); @@ -174,15 +166,15 @@ } // ============================================================================ - CurrentUser::SignOutRequest * CurrentUser::requestSignOut(){ - assert(m_state == US_SIGNED_IN || m_state == US_GUEST); + const CurrentUser::SignOutRequest * CurrentUser::requestSignOut(){ + assert(getState() == US_SIGNED_IN || getState() == US_GUEST); SignOutRequest * request = new SignOutRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); request->setParameter("action",std::string("disconnect")); - request->setParameter("token",m_token); - request->setParameter("userid",m_id); + request->setParameter("token", getToken()); + request->setParameter("userid", getUserID()); HTTPManager::get()->addRequest(request); - m_state = US_SIGNING_OUT; + setState(US_SIGNING_OUT); return request; } @@ -192,10 +184,10 @@ { Log::warn("CurrentUser::signOut", "%s", _("There were some connection issues while signing out. Report a bug if this caused issues.")); } - m_token = ""; - m_name = ""; - m_id = 0; - m_state = US_SIGNED_OUT; + setToken(""); + setUserName(""); + setUserID(0); + setState(US_SIGNED_OUT); UserConfigParams::m_saved_user = 0; UserConfigParams::m_saved_token = ""; UserConfigParams::m_saved_session = false; @@ -203,19 +195,18 @@ void CurrentUser::SignOutRequest::callback() { - CurrentUser::acquire()->signOut(this); - CurrentUser::release(); + CurrentUser::get()->signOut(this); } // ============================================================================ - CurrentUser::ServerJoinRequest * CurrentUser::requestServerJoin(uint32_t server_id){ - assert(m_state == US_SIGNED_IN || m_state == US_GUEST); + const CurrentUser::ServerJoinRequest * CurrentUser::requestServerJoin(uint32_t server_id){ + assert(getState() == US_SIGNED_IN || getState() == US_GUEST); ServerJoinRequest * request = new ServerJoinRequest(); request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php"); request->setParameter("action",std::string("request-connection")); - request->setParameter("token", m_token); - request->setParameter("id", m_id); + request->setParameter("token", getToken()); + request->setParameter("id", getUserID()); request->setParameter("server_id", server_id); HTTPManager::get()->addRequest(request); return request; @@ -234,12 +225,11 @@ // ============================================================================ - irr::core::stringw CurrentUser::getUserName() const + const irr::core::stringw CurrentUser::getUserName() const { - if((m_state == US_SIGNED_IN ) || (m_state == US_GUEST)) - return m_name; + if((getState() == US_SIGNED_IN ) || (getState() == US_GUEST)) + return getUserName(); else return _("Currently not signed in"); } - } // namespace Online Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/current_user.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -25,6 +25,7 @@ #include "utils/types.hpp" #include "online/server.hpp" #include "http_manager.hpp" +#include "utils/synchronised.hpp" namespace Online{ @@ -75,7 +76,7 @@ Synchronised<uint32_t> m_created_server_id; public: ServerCreationRequest() : XMLRequest(RT_SERVER_CREATION) {} - uint32_t getCreatedServerID() {return m_created_server_id.getAtomic();} + const uint32_t getCreatedServerID() const {return m_created_server_id.getAtomic();} }; class ServerJoinRequest : public XMLRequest { @@ -86,10 +87,18 @@ private: - std::string m_token; - bool m_save_session; - UserState m_state; + Synchronised<std::string> m_token; + Synchronised<bool> m_save_session; + Synchronised<UserState> m_state; + UserState getState() const { return m_state.getAtomic(); } + bool getSaveSession() const { return m_save_session.getAtomic(); } + const std::string getToken() const { return m_token.getAtomic(); } + + void setState (UserState user_state) { m_state.setAtomic(user_state); } + void setSaveSession (bool save_session) { m_save_session.setAtomic(save_session); } + void setToken (const std::string & token) { m_token.setAtomic(token); } + CurrentUser(); void signIn (const SignInRequest * input); @@ -98,32 +107,28 @@ public: //Singleton - static CurrentUser* acquire(); - static void release(); - static void deallocate(); + static CurrentUser * get(); + static void deallocate(); - SignInRequest * requestSavedSession(); - SignInRequest * requestSignIn( const irr::core::stringw &username, - const irr::core::stringw &password, - bool save_session); - SignOutRequest * requestSignOut(); - ServerCreationRequest * requestServerCreation( const irr::core::stringw &name, int max_players); - ServerJoinRequest * requestServerJoin( uint32_t server_id); + const SignInRequest * requestSavedSession(); + const SignInRequest * requestSignIn( const irr::core::stringw &username, + const irr::core::stringw &password, + bool save_session); + const SignOutRequest * requestSignOut(); + const ServerCreationRequest * requestServerCreation( const irr::core::stringw &name, int max_players); + const ServerJoinRequest * requestServerJoin( uint32_t server_id); // Register - XMLRequest * requestSignUp( const irr::core::stringw &username, - const irr::core::stringw &password, - const irr::core::stringw &password_ver, - const irr::core::stringw &email, - bool terms); + const XMLRequest * requestSignUp( const irr::core::stringw &username, + const irr::core::stringw &password, + const irr::core::stringw &password_ver, + const irr::core::stringw &email, + bool terms); /** Returns the username if signed in. */ - irr::core::stringw getUserName() const; - bool isSignedIn() const { return m_state == US_SIGNED_IN; } - bool isGuest() const { return m_state == US_GUEST; } - bool isSigningIn() const { return m_state == US_SIGNING_IN; } - UserState getUserState() { return m_state; } + const irr::core::stringw getUserName() const; + const UserState getUserState() const { return m_state.getAtomic(); } }; // class CurrentUser Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/request.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -59,13 +59,15 @@ //Negative numbers are reserved for special requests ment for the HTTP Manager assert(type >= 0); m_url.setAtomic(""); - m_parameters = new Parameters; + MutexLocker(m_parameters); + m_parameters.getData() = new Parameters; m_progress.setAtomic(0); } HTTPRequest::~HTTPRequest() { - delete m_parameters; + MutexLocker(m_parameters); + delete m_parameters.getData(); } bool HTTPRequest::isAllowedToAdd() @@ -96,9 +98,10 @@ curl_easy_setopt(curl_session, CURLOPT_URL, m_url.getAtomic().c_str()); Parameters::iterator iter; std::string postString = ""; - for (iter = m_parameters->begin(); iter != m_parameters->end(); ++iter) + m_parameters.lock(); + for (iter = m_parameters.getData()->begin(); iter != m_parameters.getData()->end(); ++iter) { - if(iter != m_parameters->begin()) + if(iter != m_parameters.getData()->begin()) postString.append("&"); char * escaped = curl_easy_escape(curl_session , iter->first.c_str(), iter->first.size()); postString.append(escaped); @@ -108,6 +111,7 @@ postString.append(escaped); curl_free(escaped); } + m_parameters.unlock(); curl_easy_setopt(curl_session, CURLOPT_POSTFIELDS, postString.c_str()); std::string readBuffer; curl_easy_setopt(curl_session, CURLOPT_WRITEFUNCTION, &HTTPRequest::WriteCallback); @@ -199,18 +203,21 @@ { m_info.setAtomic(""); m_success.setAtomic(false); - m_result = NULL; + MutexLocker(m_result); + m_result.getData() = NULL; } XMLRequest::~XMLRequest() { - delete m_result; + MutexLocker(m_result); + delete m_result.getData(); } void XMLRequest::operation() { - m_result = file_manager->createXMLTreeFromString(downloadPage()); + MutexLocker(m_result); + m_result.getData() = file_manager->createXMLTreeFromString(downloadPage()); } void XMLRequest::afterOperation() @@ -227,8 +234,22 @@ } else info = _("Unable to connect to the server. Check your internet connection or try again later."); - m_info.setAtomic(info); + m_info.lock(); + m_info.getData() = info; + m_info.unlock(); m_success.setAtomic(success); HTTPRequest::afterOperation(); } + + const XMLNode * XMLRequest::getResult() const + { + MutexLocker(m_result); + return m_result.getData(); + } + + const irr::core::stringw & XMLRequest::getInfo() const + { + MutexLocker(m_info); + return m_info.getData(); + } } // namespace Online Modified: main/branches/uni/src/online/request.hpp =================================================================== --- main/branches/uni/src/online/request.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/request.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -121,7 +121,7 @@ * (everything ok) at the end. */ Synchronised<float> m_progress; Synchronised<std::string> m_url; - Parameters * m_parameters; + Synchronised<Parameters *> m_parameters; virtual void afterOperation() OVERRIDE; /** Executed when a request has finished. */ @@ -149,14 +149,17 @@ virtual ~HTTPRequest(); void setParameter(const std::string & name, const std::string &value){ - (*m_parameters)[name] = value; + MutexLocker(m_parameters); + (*m_parameters.getData())[name] = value; }; void setParameter(const std::string & name, const irr::core::stringw &value){ - (*m_parameters)[name] = irr::core::stringc(value.c_str()).c_str(); + MutexLocker(m_parameters); + (*m_parameters.getData())[name] = irr::core::stringc(value.c_str()).c_str(); } template <typename T> void setParameter(const std::string & name, const T& value){ - (*m_parameters)[name] = StringUtils::toString(value); + MutexLocker(m_parameters); + (*m_parameters.getData())[name] = StringUtils::toString(value); } /** Returns the current progress. */ @@ -179,9 +182,9 @@ class XMLRequest : public HTTPRequest { + private: + Synchronised<XMLNode *> m_result; protected : - - XMLNode * m_result; Synchronised<irr::core::stringw> m_info; Synchronised<bool> m_success; @@ -192,13 +195,8 @@ XMLRequest(int type = 0, bool manage_memory = false, int priority = 1); virtual ~XMLRequest(); - virtual XMLNode * getResult() const { return m_result; } - const irr::core::stringw getInfo() const { - m_info.lock(); - const irr::core::stringw info = m_info.getData(); - m_info.unlock(); - return info; - } + const XMLNode * getResult() const; + const irr::core::stringw & getInfo() const; bool isSuccess() const { return m_success.getAtomic(); } }; Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -47,16 +47,14 @@ // ============================================================================ ServersManager::ServersManager(){ - m_info_message.setAtomic(""); m_last_load_time.setAtomic(0.0f); m_joined_server.setAtomic(NULL); } ServersManager::~ServersManager(){ cleanUpServers(); - m_joined_server.lock(); + MutexLocker(m_joined_server); delete m_joined_server.getData(); - m_joined_server.unlock(); } // ============================================================================ @@ -96,7 +94,6 @@ } m_last_load_time.setAtomic(Time::getRealTime()); } - m_info_message.setAtomic(input->getInfo()); //FIXME error message } @@ -116,20 +113,18 @@ // ============================================================================ void ServersManager::setJoinedServer(uint32_t id) { - m_joined_server.lock(); + MutexLocker(m_joined_server); delete m_joined_server.getData(); //It's a copy! m_joined_server.getData() = new Server(*getServerByID(id)); - m_joined_server.unlock(); } // ============================================================================ void ServersManager::unsetJoinedServer() { - m_joined_server.lock(); + MutexLocker(m_joined_server); delete m_joined_server.getData(); m_joined_server.getData() = NULL; - m_joined_server.unlock(); } // ============================================================================ @@ -146,21 +141,21 @@ // ============================================================================ int ServersManager::getNumServers () const { - MutexLocker locker(m_sorted_servers); + MutexLocker(m_sorted_servers); return m_sorted_servers.getData().size(); } // ============================================================================ const Server * ServersManager::getServerBySort (int index) const { - MutexLocker locker(m_sorted_servers); + MutexLocker(m_sorted_servers); return m_sorted_servers.getData().get(index); } // ============================================================================ const Server * ServersManager::getServerByID (uint32_t id) const { - MutexLocker locker(m_mapped_servers); + MutexLocker(m_mapped_servers); return m_mapped_servers.getData().at(id); } @@ -172,9 +167,8 @@ // ============================================================================ void ServersManager::sort(bool sort_desc){ - m_sorted_servers.lock(); + MutexLocker(m_sorted_servers); m_sorted_servers.getData().insertionSort(0, sort_desc); - m_sorted_servers.unlock(); } } // namespace Online Modified: main/branches/uni/src/online/servers_manager.hpp =================================================================== --- main/branches/uni/src/online/servers_manager.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/servers_manager.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -59,7 +59,6 @@ /** This is a pointer to a copy of the server, the moment it got joined */ Synchronised<Server *> m_joined_server; - Synchronised<irr::core::stringw> m_info_message; Synchronised<float> m_last_load_time; void refresh(RefreshRequest * input); void cleanUpServers(); Modified: main/branches/uni/src/online/user.cpp =================================================================== --- main/branches/uni/src/online/user.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/user.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -22,10 +22,15 @@ #include <sstream> #include <stdlib.h> +using namespace Online; + namespace Online{ // ============================================================================ - User::User(const irr::core::stringw &username) + User::User ( const irr::core::stringw & username, + const uint32_t & userid + ) { - m_name = username; + setUserName(username); + setUserID(userid); } } // namespace Online Modified: main/branches/uni/src/online/user.hpp =================================================================== --- main/branches/uni/src/online/user.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/online/user.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -32,19 +32,22 @@ class User { private: + Synchronised<irr::core::stringw> m_name; + Synchronised<uint32_t> m_id; protected: - irr::core::stringw m_name; - uint32_t m_id; - User(){} + void setUserName (const irr::core::stringw & name) { m_name.setAtomic(name); } + void setUserID (const uint32_t & id) { m_id.setAtomic(id); } public: - User(const irr::core::stringw &username); + User( const irr::core::stringw & username, + const uint32_t & userid + ); - irr::core::stringw getUserName() const { return m_name; } - uint32_t getUserID() const { return m_id; } + const irr::core::stringw getUserName() const { return m_name.getAtomic(); } + const uint32_t getUserID() const { return m_id.getAtomic(); } }; // class User Modified: main/branches/uni/src/states_screens/create_server_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/create_server_screen.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/create_server_screen.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -56,8 +56,7 @@ m_name_widget = getWidget<TextBoxWidget>("name"); assert(m_name_widget != NULL); - m_name_widget->setText(CurrentUser::acquire()->getUserName() + _("'s server")); - CurrentUser::release(); + m_name_widget->setText(CurrentUser::get()->getUserName() + _("'s server")); m_max_players_widget = getWidget<SpinnerWidget>("max_players"); assert(m_max_players_widget != NULL); m_max_players_widget->setValue(8); @@ -137,8 +136,7 @@ else { //m_options_widget->setDeactivated(); - m_server_creation_request = Online::CurrentUser::acquire()->requestServerCreation(name, max_players); - Online::CurrentUser::release(); + m_server_creation_request = Online::CurrentUser::get()->requestServerCreation(name, max_players); return; } sfx_manager->quickSound("anvil"); Modified: main/branches/uni/src/states_screens/create_server_screen.hpp =================================================================== --- main/branches/uni/src/states_screens/create_server_screen.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/create_server_screen.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -46,7 +46,7 @@ GUIEngine::IconButtonWidget * m_create_widget; GUIEngine::IconButtonWidget * m_cancel_widget; - Online::CurrentUser::ServerCreationRequest * m_server_creation_request; + const Online::CurrentUser::ServerCreationRequest * m_server_creation_request; /** \brief Sets which widget has to be focused. Depends on the user state. */ void setInitialFocus(); Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -115,8 +115,7 @@ else { m_options_widget->setDeactivated(); - m_sign_in_request = Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState()); - Online::CurrentUser::release(); + m_sign_in_request = Online::CurrentUser::get()->requestSignIn(username,password, m_remember_widget->getState()); } } Modified: main/branches/uni/src/states_screens/dialogs/login_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/dialogs/login_dialog.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -37,7 +37,7 @@ bool m_self_destroy; bool m_open_registration_dialog; - Online::CurrentUser::SignInRequest * m_sign_in_request; + const Online::CurrentUser::SignInRequest * m_sign_in_request; GUIEngine::LabelWidget * m_message_widget; GUIEngine::TextBoxWidget * m_username_widget; GUIEngine::TextBoxWidget * m_password_widget; Modified: main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/dialogs/registration_dialog.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -214,8 +214,7 @@ m_options_widget->setDeactivated(); m_info_widget->setDefaultColor(); m_info_widget->setText(Messages::signingUp(), false); - m_sign_up_request = CurrentUser::acquire()->requestSignUp(m_username, m_password, m_password_confirm, m_email, true); - CurrentUser::release(); + m_sign_up_request = CurrentUser::get()->requestSignUp(m_username, m_password, m_password_confirm, m_email, true); return true; } else if (eventSource == m_accept_terms_widget->m_properties[PROP_ID]) Modified: main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/dialogs/registration_dialog.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -56,8 +56,8 @@ bool m_show_registration_terms; bool m_show_registration_activation; - Online::XMLRequest * m_sign_up_request; - Online::XMLRequest * m_activation_request; + const Online::XMLRequest * m_sign_up_request; + const Online::XMLRequest * m_activation_request; //Saved user input : irr::core::stringw m_username; Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -40,10 +40,9 @@ // ----------------------------------------------------------------------------- -ServerInfoDialog::ServerInfoDialog(uint32_t server_id, bool from_server_creation) : - ModalDialog(0.8f,0.8f) +ServerInfoDialog::ServerInfoDialog(const uint32_t server_id, bool from_server_creation) + : ModalDialog(0.8f,0.8f), m_server_id(server_id) { - m_server_id = server_id; m_self_destroy = false; m_enter_lobby = false; m_from_server_creation = from_server_creation; @@ -77,8 +76,7 @@ // ----------------------------------------------------------------------------- void ServerInfoDialog::requestJoin() { - m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server_id); - Online::CurrentUser::release(); + m_server_join_request = Online::CurrentUser::get()->requestServerJoin(m_server_id); } // ----------------------------------------------------------------------------- Modified: main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/dialogs/server_info_dialog.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -42,11 +42,11 @@ bool m_self_destroy; bool m_enter_lobby; bool m_from_server_creation; - Online::CurrentUser::ServerJoinRequest * m_server_join_request; + const Online::CurrentUser::ServerJoinRequest * m_server_join_request; float m_load_timer; - uint32_t m_server_id; + const uint32_t m_server_id; GUIEngine::LabelWidget * m_name_widget; GUIEngine::LabelWidget * m_info_widget; @@ -58,7 +58,7 @@ void requestJoin(); public: - ServerInfoDialog(uint32_t server_id, bool just_created = false); + ServerInfoDialog(const uint32_t server_id, bool just_created = false); ~ServerInfoDialog(); void onEnterPressedInternal(); Modified: main/branches/uni/src/states_screens/online_screen.cpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.cpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/online_screen.cpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -52,10 +52,9 @@ OnlineScreen::OnlineScreen() : Screen("online/main.stkgui") { m_recorded_state = CurrentUser::US_SIGNED_OUT; - CurrentUser::SignInRequest * request = CurrentUser::acquire()->requestSavedSession(); + const CurrentUser::SignInRequest * request = CurrentUser::get()->requestSavedSession(); if(request != NULL) m_requests.push_back(request); - CurrentUser::release(); } // OnlineScreen // ---------------------------------------------------------------------------- @@ -97,8 +96,7 @@ bool OnlineScreen::hasStateChanged() { CurrentUser::UserState previous_state = m_recorded_state; - m_recorded_state = CurrentUser::acquire()->getUserState(); - CurrentUser::release(); + m_recorded_state = CurrentUser::get()->getUserState(); if (previous_state != m_recorded_state) return true; return false; @@ -145,8 +143,7 @@ Screen::init(); setInitialFocus(); DemoWorld::resetIdleTime(); - m_online_status_widget->setText(Messages::signedInAs(CurrentUser::acquire()->getUserName()), false); - CurrentUser::release(); + m_online_status_widget->setText(Messages::signedInAs(CurrentUser::get()->getUserName()), false); } // init @@ -207,8 +204,7 @@ } else if (selection == "sign_out") { - CurrentUser::acquire()->requestSignOut(); - CurrentUser::release(); + CurrentUser::get()->requestSignOut(); } else if (selection == "register") { Modified: main/branches/uni/src/states_screens/online_screen.hpp =================================================================== --- main/branches/uni/src/states_screens/online_screen.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/states_screens/online_screen.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -54,7 +54,7 @@ Online::CurrentUser::UserState m_recorded_state; - PtrVector<Online::XMLRequest> m_requests; + PtrVector<const Online::XMLRequest> m_requests; /** \brief Checks if the recorded state differs from the actual state and sets it. */ bool hasStateChanged(); Modified: main/branches/uni/src/utils/synchronised.hpp =================================================================== --- main/branches/uni/src/utils/synchronised.hpp 2013-07-25 12:26:24 UTC (rev 13350) +++ main/branches/uni/src/utils/synchronised.hpp 2013-07-25 14:01:20 UTC (rev 13351) @@ -21,8 +21,6 @@ #include <pthread.h> - - class ISynchronised { public : @@ -122,17 +120,18 @@ void operator=(const Synchronised<TYPE>& v) {} }; +#define MutexLocker(x) MutexLockerHelper __dummy(x); -class MutexLocker +class MutexLockerHelper { const ISynchronised * m_synchronised; public: - MutexLocker(const ISynchronised & synchronised){ + MutexLockerHelper(const ISynchronised & synchronised){ m_synchronised = &synchronised; m_synchronised->lock(); } - ~MutexLocker(){ + ~MutexLockerHelper(){ m_synchronised->unlock(); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2013-07-28 05:22:06
|
Revision: 13370 http://sourceforge.net/p/supertuxkart/code/13370 Author: hikerstk Date: 2013-07-28 05:22:02 +0000 (Sun, 28 Jul 2013) Log Message: ----------- Fixed VS compilation errors and warnings. Modified Paths: -------------- main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp main/branches/uni/src/online/http_manager.hpp main/branches/uni/src/online/request.cpp main/branches/uni/src/online/servers_manager.cpp Modified: main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp =================================================================== --- main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp 2013-07-28 02:03:06 UTC (rev 13369) +++ main/branches/uni/src/guiengine/widgets/CGUISTKListBox.cpp 2013-07-28 05:22:02 UTC (rev 13370) @@ -115,7 +115,7 @@ else if ((u32)Selected > id) { Selected -= 1; - selectTime = Time::getTimeSinceEpoch(); + selectTime = (u32)Time::getTimeSinceEpoch(); } Items.erase(id); @@ -205,7 +205,7 @@ else Selected = id; - selectTime = Time::getTimeSinceEpoch(); + selectTime = (u32)Time::getTimeSinceEpoch(); recalculateScrollPos(); } @@ -397,7 +397,7 @@ void CGUISTKListBox::selectNew(s32 ypos, bool onlyHover) { - u32 now = Time::getTimeSinceEpoch(); + u32 now = (u32)Time::getTimeSinceEpoch(); s32 oldSelected = Selected; Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); @@ -486,13 +486,13 @@ if (Font) { int total_proportion = 0; - for(int x = 0; x < Items[i].m_contents.size(); ++x) + for(unsigned int x = 0; x < Items[i].m_contents.size(); ++x) { total_proportion += Items[i].m_contents[x].m_proportion; } int part_size = (int)(textRect.getWidth() / float(total_proportion)); - for(int x = 0; x < Items[i].m_contents.size(); ++x) + for(unsigned int x = 0; x < Items[i].m_contents.size(); ++x) { textRect.LowerRightCorner.X = textRect.UpperLeftCorner.X + (Items[i].m_contents[x].m_proportion * part_size); @@ -511,7 +511,7 @@ iconPos, &clientClip, hasItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) ? getItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_ICON_HIGHLIGHT), - selectTime, Time::getTimeSinceEpoch(), false, true); + selectTime, (u32)Time::getTimeSinceEpoch(), false, true); } else { @@ -520,7 +520,7 @@ iconPos, &clientClip, hasItemOverrideColor(i, EGUI_LBC_ICON) ? getItemOverrideColor(i, EGUI_LBC_ICON) : getItemDefaultColor(EGUI_LBC_ICON), - 0 , (i==Selected) ? Time::getTimeSinceEpoch() : 0, false, true); + 0 , (i==Selected) ? (u32)Time::getTimeSinceEpoch() : 0, false, true); } textRect.UpperLeftCorner.X += ItemsIconWidth; } Modified: main/branches/uni/src/online/http_manager.hpp =================================================================== --- main/branches/uni/src/online/http_manager.hpp 2013-07-28 02:03:06 UTC (rev 13369) +++ main/branches/uni/src/online/http_manager.hpp 2013-07-28 05:22:02 UTC (rev 13370) @@ -19,21 +19,23 @@ #ifndef HTTP_MANAGER_HPP #define HTTP_MANAGER_HPP -#include <string> -#include <curl/curl.h> +#include "io/xml_node.hpp" +#include "online/request.hpp" +#include "utils/string_utils.hpp" +#include "utils/synchronised.hpp" + #include <irrString.h> -#include <queue> -#include <pthread.h> +#include <string> #ifdef WIN32 # include <winsock2.h> #endif -#include "io/xml_node.hpp" -#include "utils/string_utils.hpp" -#include "utils/synchronised.hpp" -#include "online/request.hpp" +#include <curl/curl.h> +#include <queue> +#include <pthread.h> + namespace Online{ /** Modified: main/branches/uni/src/online/request.cpp =================================================================== --- main/branches/uni/src/online/request.cpp 2013-07-28 02:03:06 UTC (rev 13369) +++ main/branches/uni/src/online/request.cpp 2013-07-28 05:22:02 UTC (rev 13370) @@ -16,10 +16,15 @@ #include "online/request.hpp" +#include "online/http_manager.hpp" +#include "utils/translation.hpp" + +#ifdef WIN32 +# include <winsock2.h> +#endif + #include <curl/curl.h> #include <assert.h> -#include <online/http_manager.hpp> -#include <utils/translation.hpp> namespace Online{ Modified: main/branches/uni/src/online/servers_manager.cpp =================================================================== --- main/branches/uni/src/online/servers_manager.cpp 2013-07-28 02:03:06 UTC (rev 13369) +++ main/branches/uni/src/online/servers_manager.cpp 2013-07-28 05:22:02 UTC (rev 13370) @@ -92,7 +92,7 @@ { addServer(new Server(*servers_xml->getNode(i))); } - m_last_load_time.setAtomic(Time::getRealTime()); + m_last_load_time.setAtomic((float)Time::getRealTime()); } //FIXME error message } @@ -107,7 +107,8 @@ { /*if(m_sorted_servers.size() > 0) return getServerBySort(0); - return NULL;*/ + */ + return NULL; } // ============================================================================ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uni...@us...> - 2013-08-01 01:02:39
|
Revision: 13396 http://sourceforge.net/p/supertuxkart/code/13396 Author: unitraxx Date: 2013-08-01 01:02:35 +0000 (Thu, 01 Aug 2013) Log Message: ----------- Some advancements with the addon voting Modified Paths: -------------- main/branches/uni/src/guiengine/skin.cpp main/branches/uni/src/guiengine/widgets/rating_bar_widget.cpp main/branches/uni/src/guiengine/widgets/rating_bar_widget.hpp main/branches/uni/src/online/current_user.cpp main/branches/uni/src/online/current_user.hpp main/branches/uni/src/states_screens/dialogs/vote_dialog.cpp Modified: main/branches/uni/src/guiengine/skin.cpp =================================================================== --- main/branches/uni/src/guiengine/skin.cpp 2013-07-31 20:47:06 UTC (rev 13395) +++ main/branches/uni/src/guiengine/skin.cpp 2013-08-01 01:02:35 UTC (rev 13396) @@ -813,14 +813,16 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect, const bool pressed, const bool focused) { - static const int step_number = 3; // Harcoded number of step. + RatingBarWidget *ratingBar = (RatingBarWidget*)w; + + core::position2d<s32> mouse_position = irr_driver->getDevice()->getCursorControl()->getPosition(); + ratingBar->setStepValuesByMouse(mouse_position); const ITexture *texture = SkinConfig::m_render_params["rating::neutral"].getImage(); const int texture_w = texture->getSize().Width / 4; const int texture_h = texture->getSize().Height; const float aspect_ratio = 1.0f; - RatingBarWidget *ratingBar = (RatingBarWidget*)w; const int star_number = ratingBar->getStarNumber(); int star_h = rect.getHeight(); @@ -846,7 +848,7 @@ star_rect.LowerRightCorner.X = x_from + (i + 1) * star_w; star_rect.LowerRightCorner.Y = y_from + star_h; - int step = ratingBar->getStepOfStar(i, step_number); + int step = ratingBar->getStepsOfStar(i); const core::recti source_area(texture_w * step, 0, texture_w * (step + 1), texture_h); Modified: main/branches/uni/src/guiengine/widgets/rating_bar_widget.cpp =================================================================== --- main/branches/uni/src/guiengine/widgets/rating_bar_widget.cpp 2013-07-31 20:47:06 UTC (rev 13395) +++ main/branches/uni/src/guiengine/widgets/rating_bar_widget.cpp 2013-08-01 01:02:35 UTC (rev 13396) @@ -16,6 +16,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "guiengine/engine.hpp" +#include "guiengine/modaldialog.hpp" #include "guiengine/widgets/rating_bar_widget.hpp" #include "utils/string_utils.hpp" #include <string.h> @@ -23,6 +24,7 @@ #include <IGUIEnvironment.h> #include <IGUIElement.h> #include <IGUIButton.h> +#include <cmath> using namespace GUIEngine; using namespace irr::core; @@ -32,15 +34,17 @@ RatingBarWidget::RatingBarWidget() : Widget(WTYPE_RATINGBAR) { m_rating = 0; - m_star_number = 0; + m_stars = 3; + m_steps = 3; + for(int i = 0; i < m_stars; i++) + m_star_values.push_back(0); } // ----------------------------------------------------------------------------- void RatingBarWidget::add() { - rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h); + irr::core::rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h); m_element = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, getNewNoFocusID(), NULL, L""); - m_id = m_element->getID(); m_element->setTabStop(false); m_element->setTabGroup(false); @@ -50,43 +54,62 @@ /** Get the current step of the star * * \param index The index of the star. - * \param max_step The number of different steps that a star can display. Two - * step are obligatory: full and empty. * \return The current step of the star. */ -int RatingBarWidget::getStepOfStar(int index, int max_step) +int RatingBarWidget::getStepsOfStar(int index) { - assert(index >= 0 && index < m_star_number); // Index must be between 0 and m_star_number - 1. - assert(max_step >= 2); // The maximun number of step must be larger or equal to 2. + assert(index >= 0 && index < m_stars); // Index must be between 0 and m_star_number - 1. - if (m_rating < index) + return m_star_values[index]; +} // getStepOfStar + + + +void RatingBarWidget::setStepValues(float float_rating) +{ + int rating = round(float_rating); + float step_size = 1 / (float)(m_steps - 1); + + for (int star = 0; star < m_stars; star++) { - return 0; - } - else if (m_rating > index + 1) - { - return max_step - 1; - } - else - { - float step_size = 1 / (float)(max_step - 1); - - for (int i = 0; i < max_step; i++) + if (rating < star) + m_star_values[star] = 0; + else if (rating > star + 1) + m_star_values[star] = m_steps-1; + else { - if (m_rating > index + step_size * (i - 0.5) - && m_rating < index + step_size * (i + 0.5)) - return i; + for (int step = 0; step < m_steps; step++) + { + if (rating > star + step_size * (step - 0.5) && rating < star + step_size * (step + 0.5)) + { + m_star_values[star] = step; + break; + } + } } } - - return 0; - // TODO: Assert or throws a exception, what type? -} // getStepOfStar +} +// ----------------------------------------------------------------------------- -EventPropagation RatingBarWidget::mouseHovered(Widget* child, const int playerID) { - Log::info("RatingBarWidget::mouseHovered",""); - //m_rating++; - return EVENT_BLOCK; +void RatingBarWidget::setRating(float rating) +{ + m_rating = rating; + setStepValues(m_rating); } +// ----------------------------------------------------------------------------- + +void RatingBarWidget::setStepValuesByMouse(const core::position2d<s32> & mouse_position) +{ + if(m_element->getAbsolutePosition().isPointInside(mouse_position)) + { + + float value = (float)(mouse_position.X - m_element->getAbsolutePosition().UpperLeftCorner.X); + setStepValues( (float)( value / (float)m_w * (float)m_stars) ); + + } +} + + + Modified: main/branches/uni/src/guiengine/widgets/rating_bar_widget.hpp =================================================================== --- main/branches/uni/src/guiengine/widgets/rating_bar_widget.hpp 2013-07-31 20:47:06 UTC (rev 13395) +++ main/branches/uni/src/guiengine/widgets/rating_bar_widget.hpp 2013-08-01 01:02:35 UTC (rev 13396) @@ -1,5 +1,6 @@ // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2009 Marianne Gagnon +// 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 @@ -34,13 +35,13 @@ */ class RatingBarWidget : public Widget { - - float m_rating; - int m_star_number; - - protected: + private: + float m_rating; + int m_stars; + int m_steps; + std::vector<int> m_star_values; - virtual EventPropagation mouseHovered(Widget* child, const int playerID); + void setStepValues(float rating); public: @@ -54,18 +55,20 @@ void add(); /** Change the rating value of the widget. */ - void setRating(float rating) { m_rating = rating; }; + void setRating(float rating); /** Get the current value of the widget. */ float getRating() {return m_rating; }; /** Change the number of stars of the widget. */ - void setStarNumber(int star_number) { m_star_number = star_number; }; + void setStarNumber(int star_number) { m_stars = star_number; }; /** Get the current number of stars of the widget. */ - int getStarNumber() {return m_star_number; }; + int getStarNumber() {return m_stars; }; - int getStepOfStar(int index, int max_step); + int getStepsOfStar(int index); + + void setStepValuesByMouse(const core::position2d<s32> & mouse_position); }; } Modified: main/branches/uni/src/online/current_user.cpp =================================================================== --- main/branches/uni/src/online/current_user.cpp 2013-07-31 20:47:06 UTC (rev 13395) +++ main/branches/uni/src/online/current_user.cpp 2013-08-01 01:02:35 UTC (rev 13396) @@ -246,6 +246,36 @@ // ============================================================================ + const XMLRequest * CurrentUser::requestGetAddonVote( uint32_t addon_id) + { + assert(isRegisteredUser()); + XMLRequest * request = new XMLRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action", std::string("get-addon-vote")); + request->setParameter("token", getToken()); + request->setParameter("id", getUserID()); + request->setParameter("addon-id", addon_id); + HTTPManager::get()->addRequest(request); + return request; + } + + // ============================================================================ + + const XMLRequest * CurrentUser::requestSetAddonVote( uint32_t addon_id) + { + assert(isRegisteredUser()); + XMLRequest * request = new XMLRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action", std::string("set-addon-vote")); + request->setParameter("token", getToken()); + request->setParameter("id", getUserID()); + request->setParameter("addon-id", addon_id); + HTTPManager::get()->addRequest(request); + return request; + } + + // ============================================================================ + const irr::core::stringw CurrentUser::getUserName() const { if((getUserState() == US_SIGNED_IN ) || (getUserState() == US_GUEST)) Modified: main/branches/uni/src/online/current_user.hpp =================================================================== --- main/branches/uni/src/online/current_user.hpp 2013-07-31 20:47:06 UTC (rev 13395) +++ main/branches/uni/src/online/current_user.hpp 2013-08-01 01:02:35 UTC (rev 13396) @@ -129,6 +129,9 @@ const XMLRequest * requestRecovery(const irr::core::stringw &username, const irr::core::stringw &email); + const XMLRequest * requestGetAddonVote(uint32_t addon_id); + const XMLRequest * requestSetAddonVote(uint32_t addon_id); + /** Returns the username if signed in. */ const irr::core::stringw getUserName() const; const UserState getUserState() const { return m_state.getAtomic(); } Modified: main/branches/uni/src/states_screens/dialogs/vote_dialog.cpp =================================================================== --- main/branches/uni/src/states_screens/dialogs/vote_dialog.cpp 2013-07-31 20:47:06 UTC (rev 13395) +++ main/branches/uni/src/states_screens/dialogs/vote_dialog.cpp 2013-08-01 01:02:35 UTC (rev 13396) @@ -20,7 +20,6 @@ #include <IGUIEnvironment.h> #include "audio/sfx_manager.hpp" -//#include "config/player.hpp" #include "guiengine/engine.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" @@ -46,8 +45,6 @@ m_rating_widget = getWidget<RatingBarWidget>("rating"); assert(m_rating_widget != NULL); m_rating_widget->setRating(0); - m_rating_widget->setStarNumber(3); - m_options_widget = getWidget<RibbonWidget>("options"); assert(m_options_widget != NULL); m_submit_widget = getWidget<IconButtonWidget>("submit"); @@ -56,6 +53,7 @@ assert(m_cancel_widget != NULL); m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + } // ----------------------------------------------------------------------------- @@ -68,14 +66,15 @@ GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& eventSource) { + if (eventSource == m_rating_widget->m_properties[PROP_ID]) + { + m_self_destroy = true; + return GUIEngine::EVENT_BLOCK; + } + if (eventSource == m_options_widget->m_properties[PROP_ID]) { const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER); - if (selection == m_rating_widget->m_properties[PROP_ID]) - { - m_self_destroy = true; - return GUIEngine::EVENT_BLOCK; - } } return GUIEngine::EVENT_LET; } @@ -84,5 +83,6 @@ void VoteDialog::onUpdate(float dt) { - + if (m_self_destroy) + ModalDialog::dismiss(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |