Temporary commit so that I can easily revert if shit goes down. And it will go down. Thread callbacks madness!

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13290 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-19 21:20:32 +00:00
parent ae6bc57b95
commit ad198a6e70
30 changed files with 420 additions and 220 deletions

View File

@ -56,7 +56,7 @@
<icon-button id="as_guest" width="64" height="64" icon="gui/main_about.png" <icon-button id="as_guest" width="64" height="64" icon="gui/main_about.png"
I18N="Login dialog" text="As guest" label_location="bottom"/> I18N="Login dialog" text="As guest" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png" <icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Login dialog" text="Cancel" label_location="bottom"/> I18N="Login dialog" text="Close" label_location="bottom"/>
</buttonbar> </buttonbar>

View File

@ -148,6 +148,7 @@ src/network/race_state.cpp
src/online/current_user.cpp src/online/current_user.cpp
src/online/http_connector.cpp src/online/http_connector.cpp
src/online/http_manager.cpp src/online/http_manager.cpp
src/online/messages.cpp
src/online/request.cpp src/online/request.cpp
src/online/server.cpp src/online/server.cpp
src/online/servers_manager.cpp src/online/servers_manager.cpp
@ -418,7 +419,9 @@ src/network/remote_kart_info.hpp
src/network/world_loaded_message.hpp src/network/world_loaded_message.hpp
src/online/current_user.hpp src/online/current_user.hpp
src/online/http_connector.hpp src/online/http_connector.hpp
src/online/http_listener.hpp
src/online/http_manager.hpp src/online/http_manager.hpp
src/online/messages.hpp
src/online/request.hpp src/online/request.hpp
src/online/server.hpp src/online/server.hpp
src/online/servers_manager.hpp src/online/servers_manager.hpp

View File

@ -27,27 +27,48 @@
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
namespace online{ namespace Online{
static CurrentUser* user_singleton = NULL; static Synchronised<CurrentUser*> user_singleton(NULL);
CurrentUser* CurrentUser::get() CurrentUser* CurrentUser::get()
{ {
if (user_singleton == NULL) CurrentUser* user = user_singleton.getData();
user_singleton = new CurrentUser(); if (user == NULL)
return user_singleton; user = new CurrentUser();
return user;
} // get } // get
CurrentUser* CurrentUser::acquire()
{
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;
}
void CurrentUser::release()
{
user_singleton.unlock();
}
void CurrentUser::deallocate() void CurrentUser::deallocate()
{ {
delete user_singleton; user_singleton.lock();
user_singleton = NULL; CurrentUser* user = user_singleton.getData();
delete user;
user = NULL;
user_singleton.unlock();
} // deallocate } // deallocate
// ============================================================================ // ============================================================================
CurrentUser::CurrentUser(){ CurrentUser::CurrentUser(){
m_is_signed_in = false; m_state = SIGNED_OUT;
m_is_guest = false;
m_is_server_host = false;
m_id = 0; m_id = 0;
m_name = ""; m_name = "";
m_token = ""; m_token = "";
@ -57,7 +78,8 @@ namespace online{
// ============================================================================ // ============================================================================
bool CurrentUser::trySavedSession() bool CurrentUser::trySavedSession()
{ {
if (m_is_signed_in) return true; if (m_state == SIGNED_IN) return true;
bool success = false;
if(UserConfigParams::m_saved_session) if(UserConfigParams::m_saved_session)
{ {
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
@ -76,11 +98,10 @@ namespace online{
int userid_fetched = result->get("userid", &m_id); int userid_fetched = result->get("userid", &m_id);
assert(token_fetched && username_fetched && userid_fetched); assert(token_fetched && username_fetched && userid_fetched);
UserConfigParams::m_saved_token = m_token; UserConfigParams::m_saved_token = m_token;
m_is_signed_in = true; m_state = SIGNED_IN;
m_is_guest = false; success = true;
} }
result->get("info", &info); result->get("info", &info);
Log::info("trySavedSession","%s",info.c_str());
} }
else else
{ {
@ -88,19 +109,19 @@ namespace online{
_("Unable to connect to the server. Check your internet connection or try again later.")); _("Unable to connect to the server. Check your internet connection or try again later."));
} }
} }
return m_is_signed_in; return success;
} }
// ============================================================================ // ============================================================================
// Register // Register
bool CurrentUser::signUp( const irr::core::stringw &username, bool CurrentUser::signUp( const irr::core::stringw &username,
const irr::core::stringw &password, const irr::core::stringw &password,
const irr::core::stringw &password_ver, const irr::core::stringw &password_ver,
const irr::core::stringw &email, const irr::core::stringw &email,
bool terms, bool terms,
irr::core::stringw &info) irr::core::stringw &info)
{ {
assert(m_is_signed_in == false); assert(m_state == SIGNED_OUT || m_state == GUEST);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action",std::string("register")); connector->setParameter("action",std::string("register"));
connector->setParameter("username",username); connector->setParameter("username",username);
@ -117,7 +138,7 @@ namespace online{
} }
else else
{ {
info = _("Unable to connect to the server. Check your internet connection or try again later."); info = _("Unable to connect to the server. Check your internet connection or try again later.");
} }
return success; return success;
} }
@ -125,34 +146,40 @@ namespace online{
// ============================================================================ // ============================================================================
XMLRequest * CurrentUser::signInRequest( const irr::core::stringw &username, void CurrentUser::requestSignIn( const irr::core::stringw &username,
const irr::core::stringw &password, const irr::core::stringw &password,
bool save_session) bool save_session)
{ {
assert(m_is_signed_in == false); assert(m_state == SIGNED_OUT);
m_save_session = save_session; m_save_session = save_session;
XMLRequest * request = new XMLRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); XMLRequest * request = new XMLRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
request->setListener(this, CurrentUser::SIGN_IN_REQUEST);
request->setParameter("action",std::string("connect")); request->setParameter("action",std::string("connect"));
request->setParameter("username",username); request->setParameter("username",username);
request->setParameter("password",password); request->setParameter("password",password);
if(!HTTPManager::get()->addRequest(request)) if(!HTTPManager::get()->addRequest(request))
{
assert(false); assert(false);
return request; }
m_state = SIGNING_IN;
} }
bool CurrentUser::signIn(const XMLNode * input, irr::core::stringw &info) bool CurrentUser::signIn(XMLRequest * input)
{ {
std::string rec_success = ""; const XMLNode * xml = input->getResult();
if(input->get("success", &rec_success)) bool success = false;
irr::core::stringw info;
std::string rec_success;
if(xml->get("success", &rec_success))
{ {
if (rec_success =="yes") if (rec_success =="yes")
{ {
int token_fetched = input->get("token", &m_token); int token_fetched = xml->get("token", &m_token);
int username_fetched = input->get("username", &m_name); int username_fetched = xml->get("username", &m_name);
int userid_fetched = input->get("userid", &m_id); int userid_fetched = xml->get("userid", &m_id);
assert(token_fetched && username_fetched && userid_fetched); assert(token_fetched && username_fetched && userid_fetched);
m_is_signed_in = true; m_state = SIGNED_IN;
m_is_guest = false; success = true;
if(m_save_session) if(m_save_session)
{ {
UserConfigParams::m_saved_user = m_id; UserConfigParams::m_saved_user = m_id;
@ -160,58 +187,64 @@ namespace online{
UserConfigParams::m_saved_session = true; UserConfigParams::m_saved_session = true;
} }
} }
input->get("info", &info); xml->get("info", &info);
} }
else else
{ {
info = _("Unable to connect to the server. Check your internet connection or try again later."); info = _("Unable to connect to the server. Check your internet connection or try again later.");
} }
input->setInfo(info);
return m_is_signed_in; if(!success) m_state = SIGNED_OUT;
return success;
} }
// ============================================================================ // ============================================================================
bool CurrentUser::createServer( const irr::core::stringw &name, XMLRequest * CurrentUser::createServerRequest ( const irr::core::stringw &name, int max_players)
int max_players,
irr::core::stringw &info)
{ {
assert(m_is_signed_in && !m_is_guest); assert(m_state == SIGNED_IN);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); XMLRequest * request = new XMLRequest((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action", std::string("create_server")); request->setParameter("action", std::string("create_server"));
connector->setParameter("token", m_token); request->setParameter("token", m_token);
connector->setParameter("userid", m_id); request->setParameter("userid", m_id);
connector->setParameter("name", name); request->setParameter("name", name);
connector->setParameter("max_players", max_players); request->setParameter("max_players", max_players);
const XMLNode * result = connector->getXMLFromPage(); if(!HTTPManager::get()->addRequest(request))
assert(false);
return request;
}
bool CurrentUser::createServer( const XMLNode * input , irr::core::stringw &info)
{
bool success = false;
std::string rec_success = ""; std::string rec_success = "";
if(result->get("success", &rec_success)) if(input->get("success", &rec_success))
{ {
if (rec_success =="yes") if (rec_success =="yes")
{ {
// FIXME // FIXME
m_is_server_host = true; success = true;
} }
result->get("info", &info); input->get("info", &info);
} }
else else
{ {
info = _("Unable to connect to the server. Check your internet connection or try again later."); info = _("Unable to connect to the server. Check your internet connection or try again later.");
} }
return m_is_server_host; return success;
} }
// ============================================================================ // ============================================================================
bool CurrentUser::signOut(irr::core::stringw &info){ bool CurrentUser::signOut(irr::core::stringw &info){
assert(m_is_signed_in == true); assert(m_state == SIGNED_IN || m_state == GUEST);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action",std::string("disconnect")); connector->setParameter("action",std::string("disconnect"));
connector->setParameter("token",m_token); connector->setParameter("token",m_token);
connector->setParameter("userid",m_id); connector->setParameter("userid",m_id);
bool success = false;
const XMLNode * result = connector->getXMLFromPage(); const XMLNode * result = connector->getXMLFromPage();
std::string rec_success = ""; std::string rec_success = "";
if(result->get("success", &rec_success)) if(result->get("success", &rec_success))
@ -221,11 +254,11 @@ namespace online{
m_token = ""; m_token = "";
m_name = ""; m_name = "";
m_id = 0; m_id = 0;
m_is_signed_in = false; m_state = SIGNED_OUT;
m_is_guest = false;
UserConfigParams::m_saved_user = 0; UserConfigParams::m_saved_user = 0;
UserConfigParams::m_saved_token = ""; UserConfigParams::m_saved_token = "";
UserConfigParams::m_saved_session = false; UserConfigParams::m_saved_session = false;
success = true;
} }
result->get("info", &info); result->get("info", &info);
} }
@ -233,13 +266,13 @@ namespace online{
{ {
info = _("Unable to connect to the server. Check your internet connection or try again later."); info = _("Unable to connect to the server. Check your internet connection or try again later.");
} }
return !m_is_signed_in; return success;
} }
// ============================================================================ // ============================================================================
bool CurrentUser::requestJoin(uint32_t server_id, irr::core::stringw &info){ bool CurrentUser::requestJoin(uint32_t server_id, irr::core::stringw &info){
assert(m_is_signed_in == true); assert(m_state == SIGNED_IN || m_state == GUEST);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php"); HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
connector->setParameter("action",std::string("request-connection")); connector->setParameter("action",std::string("request-connection"));
connector->setParameter("token", m_token); connector->setParameter("token", m_token);
@ -271,9 +304,27 @@ namespace online{
irr::core::stringw CurrentUser::getUserName() const irr::core::stringw CurrentUser::getUserName() const
{ {
if(m_is_signed_in) if((m_state == SIGNED_IN ) || (m_state == GUEST))
return m_name; return m_name;
else else
return _("Currently not signed in"); return _("Currently not signed in");
} }
} // namespace online
// ============================================================================
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

View File

@ -27,35 +27,52 @@
#include "http_manager.hpp" #include "http_manager.hpp"
namespace online{ namespace Online{
// ============================================================================ // ============================================================================
/** /**
* \brief Class that represents an online registered user * \brief Class that represents an online registered user
* \ingroup online * \ingroup online
*/ */
class CurrentUser : public User class CurrentUser : public User, HTTPListener
{ {
public:
protected: enum UserState
{
SIGNED_OUT,
SIGNED_IN,
GUEST,
SIGNING_IN,
SIGNING_OUT
};
private:
enum RequestType{
SIGN_IN_REQUEST
};
std::map<int, std::pair<bool, irr::core::stringw> > m_http_results;
std::string m_token; std::string m_token;
bool m_is_signed_in;
bool m_is_guest;
bool m_save_session; bool m_save_session;
UserState m_state;
CurrentUser(); CurrentUser();
bool signIn(XMLRequest * input);
public: public:
// singleton // singleton
static CurrentUser* get(); static CurrentUser* get();
static void deallocate(); static void deallocate();
static CurrentUser* acquire();
static void release();
bool trySavedSession(); bool trySavedSession();
// Login // Login
XMLRequest * signInRequest( const irr::core::stringw &username, void requestSignIn( const irr::core::stringw &username,
const irr::core::stringw &password, const irr::core::stringw &password,
bool save_session); bool save_session);
bool signIn( const XMLNode * input, irr::core::stringw &info);
// Register // Register
bool signUp( const irr::core::stringw &username, bool signUp( const irr::core::stringw &username,
@ -67,20 +84,25 @@ namespace online{
// Logout - Best to be followed by CurrentOnlineUser::deallocate // Logout - Best to be followed by CurrentOnlineUser::deallocate
bool signOut( irr::core::stringw &info); bool signOut( irr::core::stringw &info);
bool createServer( const irr::core::stringw &name, XMLRequest * createServerRequest( const irr::core::stringw &name,
int max_players, int max_players);
irr::core::stringw &info);
bool createServer ( const XMLNode * input, irr::core::stringw &info);
bool requestJoin( uint32_t server_id, bool requestJoin( uint32_t server_id,
irr::core::stringw &info); irr::core::stringw &info);
/** Returns the username if signed in. */ /** Returns the username if signed in. */
irr::core::stringw getUserName() const; irr::core::stringw getUserName() const;
bool isSignedIn(){ return m_is_signed_in; } bool isSignedIn() const { return m_state == SIGNED_IN; }
bool isGuest(){ return m_is_guest; } 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 }; // class CurrentUser
} // namespace online
} // namespace Online
#endif #endif

View File

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

View File

@ -39,7 +39,7 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
namespace online{ namespace Online{
static HTTPManager * http_singleton = NULL; static HTTPManager * http_singleton = NULL;
@ -119,7 +119,7 @@ namespace online{
// thread here to cancel properly. // thread here to cancel properly.
cancelAllDownloads(); cancelAllDownloads();
online::QuitRequest * request = new online::QuitRequest(); QuitRequest * request = new QuitRequest();
addRequest(request); addRequest(request);
} // stopNetworkThread } // stopNetworkThread
@ -140,7 +140,7 @@ namespace online{
* sorted by priority. * sorted by priority.
* \param request The pointer to the new request to insert. * \param request The pointer to the new request to insert.
*/ */
bool HTTPManager::addRequest(online::Request *request) bool HTTPManager::addRequest(Online::Request *request)
{ {
if (request->isAllowedToAdd()) if (request->isAllowedToAdd())
{ {
@ -174,7 +174,7 @@ namespace online{
me->m_current_request = NULL; me->m_current_request = NULL;
me->m_request_queue.lock(); me->m_request_queue.lock();
while( me->m_request_queue.getData().empty() || !dynamic_cast<online::QuitRequest*>(me->m_request_queue.getData().top()) ) while( me->m_request_queue.getData().empty() || !dynamic_cast<Online::QuitRequest*>(me->m_request_queue.getData().top()) )
{ {
bool empty = me->m_request_queue.getData().empty(); bool empty = me->m_request_queue.getData().empty();
// Wait in cond_wait for a request to arrive. The 'while' is necessary // Wait in cond_wait for a request to arrive. The 'while' is necessary
@ -201,7 +201,7 @@ namespace online{
// At this stage we have the lock for m_request_queue // At this stage we have the lock for m_request_queue
while(!me->m_request_queue.getData().empty()) while(!me->m_request_queue.getData().empty())
{ {
online::Request * request = me->m_request_queue.getData().top(); Online::Request * request = me->m_request_queue.getData().top();
me->m_request_queue.getData().pop(); me->m_request_queue.getData().pop();
// Manage memory can be ignored here, all requests // Manage memory can be ignored here, all requests
// need to be freed. // need to be freed.
@ -212,7 +212,7 @@ namespace online{
pthread_exit(NULL); pthread_exit(NULL);
return 0; return 0;
} // mainLoop } // mainLoop
} // namespace online } // namespace Online

View File

@ -1,6 +1,6 @@
// //
// SuperTuxKart - a fun racing game with go-kart // SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 SuperTuxKart-Team // Copyright (C) 2013 Glenn De Jonghe
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License // modify it under the terms of the GNU General Public License
@ -34,7 +34,7 @@
#include "utils/synchronised.hpp" #include "utils/synchronised.hpp"
#include "online/request.hpp" #include "online/request.hpp"
namespace online{ namespace Online{
/** /**
* \brief Class to connect with a server over HTTP * \brief Class to connect with a server over HTTP
@ -45,7 +45,7 @@ namespace online{
protected: protected:
/** The current requested being worked on. */ /** 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. */ /** A conditional variable to wake up the main loop. */
pthread_cond_t m_cond_request; pthread_cond_t m_cond_request;
@ -58,9 +58,9 @@ namespace online{
/** The list of pointes to all requests. */ /** The list of pointes to all requests. */
Synchronised< std::priority_queue < Synchronised< std::priority_queue <
online::Request*, Online::Request*,
std::vector<online::Request*>, std::vector<Online::Request*>,
online::Request::Compare Online::Request::Compare
> >
> m_request_queue; > m_request_queue;
@ -79,16 +79,16 @@ namespace online{
static void deallocate(); static void deallocate();
//Execute //Execute
std::string getPage(online::Request * request); std::string getPage(Online::Request * request);
XMLNode * getXMLFromPage(online::Request * request); XMLNode * getXMLFromPage(Online::Request * request);
bool addRequest(online::Request *request); bool addRequest(Online::Request *request);
void cancelAllDownloads(); void cancelAllDownloads();
bool getAbort(){ return m_abort.getAtomic(); }; bool getAbort(){ return m_abort.getAtomic(); };
}; //class HTTPManager }; //class HTTPManager
} // namespace online } // namespace Online
#endif // HTTP_MANAGER_HPP #endif // HTTP_MANAGER_HPP

53
src/online/messages.cpp Normal file
View File

@ -0,0 +1,53 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "online/messages.hpp"
#include "utils/translation.hpp"
namespace Online
{
namespace Messages
{
irr::core::stringw loadingDots(float timer, bool spaces, float interval, int max_dots)
{
int nr_dots = int(floor(timer * (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(float timer)
{
return irr::core::stringw(_("Signing in")) + loadingDots(timer);
}
// ------------------------------------------------------------------------
irr::core::stringw signingOut(float timer)
{
return irr::core::stringw(_("Signing out")) + loadingDots(timer);
}
// ------------------------------------------------------------------------
irr::core::stringw signedInAs(const irr::core::stringw & name)
{
return irr::core::stringw(_("Signed in as : ")) + name + ".";
}
} // namespace messages
} // namespace Online
/* EOF */

37
src/online/messages.hpp Normal file
View File

@ -0,0 +1,37 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_ONLINE_MESSAGES_HPP
#define HEADER_ONLINE_MESSAGES_HPP
#include <string>
#include <irrString.h>
namespace Online
{
namespace Messages
{
irr::core::stringw loadingDots(float timer, bool spaces = true, float interval = 0.5f, int max_dots = 3);
irr::core::stringw signingIn (float timer);
irr::core::stringw signingOut (float timer);
irr::core::stringw signedInAs (const irr::core::stringw & name);
} // namespace Messages
}// namespace Online
#endif
/* EOF */

View File

@ -21,7 +21,7 @@
#include <online/http_manager.hpp> #include <online/http_manager.hpp>
namespace online{ namespace Online{
class HTTPManager; class HTTPManager;
@ -32,7 +32,6 @@ namespace online{
m_priority = priority; m_priority = priority;
m_manage_memory = manage_memory; m_manage_memory = manage_memory;
m_cancel = false; m_cancel = false;
m_done = false;
} // Request } // Request
Request::~Request() Request::~Request()
@ -63,14 +62,29 @@ namespace online{
m_parameters = new Parameters; m_parameters = new Parameters;
m_progress.setAtomic(0); m_progress.setAtomic(0);
m_added = false; m_added = false;
m_done.setAtomic(false);
m_listener.setAtomic(NULL);
m_listener_target = 0;
} }
HTTPRequest::~HTTPRequest() HTTPRequest::~HTTPRequest()
{ {
delete m_parameters; 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(){ bool HTTPRequest::isAllowedToAdd()
{
if (m_url.size() > 5 && ( m_url.substr(0, 5) != "http:")) if (m_url.size() > 5 && ( m_url.substr(0, 5) != "http:"))
{ {
Log::info("HTTPRequest::isAllowedToAdd", "Invalid URL."); Log::info("HTTPRequest::isAllowedToAdd", "Invalid URL.");
@ -79,6 +93,14 @@ namespace online{
return true; return true;
} }
void HTTPRequest::afterOperation()
{
if (m_listener != NULL)
{
m_listener->onHTTPCallback(this);
}
}
std::string HTTPRequest::downloadPage() std::string HTTPRequest::downloadPage()
{ {
CURL * curl_session; CURL * curl_session;
@ -198,4 +220,4 @@ namespace online{
{ {
m_result = file_manager->createXMLTreeFromString(downloadPage()); m_result = file_manager->createXMLTreeFromString(downloadPage());
} }
} // namespace online } // namespace Online

View File

@ -19,13 +19,13 @@
#include <string> #include <string>
#include "utils/leak_check.hpp"
#include "utils/synchronised.hpp"
#include "utils/cpp2011.h" #include "utils/cpp2011.h"
#include "io/file_manager.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
#include "utils/synchronised.hpp"
#include "io/file_manager.hpp"
#include "online/http_listener.hpp"
namespace online{ namespace Online{
/** /**
* Stores a request for the http connector. They will be sorted by priorities. * Stores a request for the http connector. They will be sorted by priorities.
@ -40,7 +40,6 @@ namespace online{
/** Cancel this request if it is active. */ /** Cancel this request if it is active. */
bool m_cancel; bool m_cancel;
bool m_done;
/** True if the memory for this Request should be managed by /** True if the memory for this Request should be managed by
* http connector (i.e. this object is freed once the request * http connector (i.e. this object is freed once the request
@ -50,10 +49,9 @@ namespace online{
virtual void beforeOperation() {} virtual void beforeOperation() {}
virtual void operation() = 0; virtual void operation() = 0;
virtual void afterOperation() { m_done = true;} virtual void afterOperation() {}
public: public:
LEAK_CHECK()
Request(int priority, bool manage_memory=true); Request(int priority, bool manage_memory=true);
virtual ~Request(); virtual ~Request();
@ -77,8 +75,6 @@ namespace online{
* by network_http (i.e. freed once the request is handled). */ * by network_http (i.e. freed once the request is handled). */
bool manageMemory() const { return m_manage_memory; } bool manageMemory() const { return m_manage_memory; }
bool isDone() const { return m_done; }
virtual bool isAllowedToAdd() {return true;} virtual bool isAllowedToAdd() {return true;}
/** This class is used by the priority queue to sort requests by priority. /** This class is used by the priority queue to sort requests by priority.
@ -119,10 +115,18 @@ namespace online{
/** The progress indicator. 0 till it is started and the first /** The progress indicator. 0 till it is started and the first
* packet is downloaded. At the end eithe -1 (error) or 1 * packet is downloaded. At the end eithe -1 (error) or 1
* (everything ok) at the end. */ * (everything ok) at the end. */
Synchronised<float> m_progress; Synchronised<float> m_progress;
std::string m_url; Synchronised<bool> m_done;
bool m_added; std::string m_url;
bool m_added;
Synchronised<HTTPListener *> m_listener;
int m_listener_target;
/**
* info to show on screen if necessary
*/
irr::core::stringw m_info;
virtual void afterOperation();
std::string downloadPage(); std::string downloadPage();
static int progressDownload(void *clientp, static int progressDownload(void *clientp,
@ -152,7 +156,7 @@ namespace online{
template <typename T> template <typename T>
void setParameter(const std::string & name, const T& value){ void setParameter(const std::string & name, const T& value){
if(!m_added) if(!m_added)
( *m_parameters)[name] = StringUtils::toString(value); (*m_parameters)[name] = StringUtils::toString(value);
} }
/** Returns the current progress. */ /** Returns the current progress. */
@ -160,10 +164,16 @@ namespace online{
/** Sets the current progress. */ /** Sets the current progress. */
void setProgress(float f) { m_progress.setAtomic(f); } void setProgress(float f) { m_progress.setAtomic(f); }
void setInfo(const irr::core::stringw & info) {m_info = info;}
const irr::core::stringw & getInfo() {return m_info;}
const std::string &getURL() const {return m_url;} const std::string &getURL() const {return m_url;}
virtual bool isAllowedToAdd() OVERRIDE; virtual bool isAllowedToAdd() OVERRIDE;
virtual void setListener(Synchronised<HTTPListener *> listener, int target = 0);
int getListenerTarget(){ return m_listener_target; }
}; };
class XMLRequest : public HTTPRequest class XMLRequest : public HTTPRequest
@ -174,9 +184,9 @@ namespace online{
public : public :
XMLRequest(const std::string &url); XMLRequest(const std::string &url);
XMLNode * getResult(){ return m_result; } virtual XMLNode * getResult() OVERRIDE { return m_result; }
}; };
} //namespace online } //namespace Online
#endif #endif

View File

@ -24,7 +24,7 @@
#include "utils/constants.hpp" #include "utils/constants.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
namespace online{ namespace Online{
Server::SortOrder Server::m_sort_order=Server::SO_NAME; //FIXME change to some other default Server::SortOrder Server::m_sort_order=Server::SO_NAME; //FIXME change to some other default
Server::Server(const XMLNode & xml) Server::Server(const XMLNode & xml)
@ -71,4 +71,4 @@ namespace online{
return false; return false;
} // filterByWords } // filterByWords
} // namespace online } // namespace Online

View File

@ -31,7 +31,7 @@
class XMLNode; class XMLNode;
namespace online{ namespace Online{
/** /**
* \ingroup online * \ingroup online
*/ */
@ -130,6 +130,6 @@ namespace online{
} // operator> } // operator>
}; // Server }; // Server
} // namespace online } // namespace Online
#endif #endif

View File

@ -26,7 +26,7 @@
#include "config/user_config.hpp" #include "config/user_config.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
namespace online{ namespace Online{
static ServersManager* user_singleton = NULL; static ServersManager* user_singleton = NULL;
@ -79,4 +79,4 @@ namespace online{
return m_servers->get(0); return m_servers->get(0);
return NULL; return NULL;
} }
} // namespace online } // namespace Online

View File

@ -23,7 +23,7 @@
#include "online/server.hpp" #include "online/server.hpp"
namespace online { namespace Online {
/** /**
* \brief * \brief
@ -54,7 +54,7 @@ namespace online {
}; // class ServersManager }; // class ServersManager
} // namespace online } // namespace Online
#endif #endif

View File

@ -22,10 +22,10 @@
#include <sstream> #include <sstream>
#include <stdlib.h> #include <stdlib.h>
namespace online{ namespace Online{
// ============================================================================ // ============================================================================
User::User(const irr::core::stringw &username) User::User(const irr::core::stringw &username)
{ {
m_name = username; m_name = username;
} // OnlineUser }
} // namespace online } // namespace Online

View File

@ -21,8 +21,9 @@
#include <irrString.h> #include <irrString.h>
#include "utils/types.hpp" #include "utils/types.hpp"
#include "utils/synchronised.hpp"
namespace online{ namespace Online{
/** /**
* \brief Class that represents an online registered user * \brief Class that represents an online registered user
@ -33,10 +34,8 @@ namespace online{
private: private:
protected: protected:
irr::core::stringw m_name;
bool m_is_server_host; uint32_t m_id;
irr::core::stringw m_name;
uint32_t m_id;
User(){} User(){}
public: public:
@ -49,7 +48,7 @@ namespace online{
}; // class User }; // class User
} // namespace online } // namespace Online
#endif #endif
/*EOF*/ /*EOF*/

View File

@ -39,8 +39,6 @@ LoginDialog::LoginDialog(const Message message_type) :
{ {
m_self_destroy = false; m_self_destroy = false;
m_open_registration_dialog = false; m_open_registration_dialog = false;
m_load_timer = 0.0f;
m_signin_request = NULL;
loadFromFile("online/login_dialog.stkgui"); loadFromFile("online/login_dialog.stkgui");
m_info_widget = getWidget<LabelWidget>("info"); m_info_widget = getWidget<LabelWidget>("info");
@ -95,7 +93,6 @@ LoginDialog::LoginDialog(const Message message_type) :
LoginDialog::~LoginDialog() LoginDialog::~LoginDialog()
{ {
delete m_signin_request;
} }
@ -105,7 +102,9 @@ void LoginDialog::login()
{ {
const stringw username = m_username_widget->getText().trim(); const stringw username = m_username_widget->getText().trim();
const stringw password = m_password_widget->getText().trim(); const stringw password = m_password_widget->getText().trim();
m_signin_request = online::CurrentUser::get()->signInRequest(username,password, m_remember_widget->getState()); Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState());
Online::CurrentUser::release();
m_self_destroy = true;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -117,8 +116,6 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER); const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_cancel_widget->m_properties[PROP_ID]) if (selection == m_cancel_widget->m_properties[PROP_ID])
{ {
if(m_signin_request != NULL)
m_signin_request->cancel();
m_self_destroy = true; m_self_destroy = true;
return GUIEngine::EVENT_BLOCK; return GUIEngine::EVENT_BLOCK;
} }
@ -152,31 +149,6 @@ void LoginDialog::onEnterPressedInternal()
void LoginDialog::onUpdate(float dt) void LoginDialog::onUpdate(float dt)
{ {
if(m_signin_request != NULL)
{
if(m_signin_request->isDone())
{
stringw info = "";
if(online::CurrentUser::get()->signIn(m_signin_request->getResult(), info))
{
m_self_destroy = true;
}
else
{
// error message
sfx_manager->quickSound( "anvil" );
m_message_widget->setColor(irr::video::SColor(255, 255, 0, 0));
m_message_widget->setText(info, false);
}
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 //If we want to open the registration dialog, we need to close this one first
m_open_registration_dialog && (m_self_destroy = true); m_open_registration_dialog && (m_self_destroy = true);

View File

@ -37,7 +37,6 @@ private:
bool m_self_destroy; bool m_self_destroy;
bool m_open_registration_dialog; bool m_open_registration_dialog;
online::XMLRequest * m_signin_request;
GUIEngine::LabelWidget * m_info_widget; GUIEngine::LabelWidget * m_info_widget;
GUIEngine::TextBoxWidget * m_username_widget; GUIEngine::TextBoxWidget * m_username_widget;
@ -54,8 +53,6 @@ private:
void login(); void login();
float m_load_timer;
public: public:
enum Message enum Message

View File

@ -192,7 +192,7 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
{ {
assert(getWidget<CheckBoxWidget>("accepted")->getState()); assert(getWidget<CheckBoxWidget>("accepted")->getState());
m_agreement = true; m_agreement = true;
if(online::CurrentUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, m_registration_error)) if(Online::CurrentUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, m_registration_error))
{ {
m_show_registration_activation = true; m_show_registration_activation = true;
m_registration_error = ""; m_registration_error = "";

View File

@ -34,7 +34,7 @@
using namespace GUIEngine; using namespace GUIEngine;
using namespace irr; using namespace irr;
using namespace irr::gui; using namespace irr::gui;
using namespace online; using namespace Online;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -72,7 +72,7 @@ void ServerInfoDialog::requestJoin()
{ {
//FIXME totally not correct. Receiving an answer, not kept in mind. //FIXME totally not correct. Receiving an answer, not kept in mind.
irr::core::stringw info; irr::core::stringw info;
if (online::CurrentUser::get()->requestJoin( m_server->getServerId(), info)) if (Online::CurrentUser::get()->requestJoin( m_server->getServerId(), info))
{ {
ServersManager::get()->setJoinedServer(m_server); ServersManager::get()->setJoinedServer(m_server);
m_enter_lobby = true; m_enter_lobby = true;

View File

@ -40,7 +40,7 @@ private:
bool m_self_destroy; bool m_self_destroy;
bool m_enter_lobby; bool m_enter_lobby;
online::Server * m_server; Online::Server * m_server;
GUIEngine::LabelWidget * m_name_widget; GUIEngine::LabelWidget * m_name_widget;
GUIEngine::LabelWidget * m_info_widget; GUIEngine::LabelWidget * m_info_widget;
@ -52,7 +52,7 @@ private:
void requestJoin(); void requestJoin();
public: public:
ServerInfoDialog(online::Server * server); ServerInfoDialog(Online::Server * server);
~ServerInfoDialog(); ~ServerInfoDialog();
void onEnterPressedInternal(); void onEnterPressedInternal();

View File

@ -37,7 +37,7 @@
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "online/servers_manager.hpp" #include "online/servers_manager.hpp"
using namespace online; using namespace Online;
using namespace GUIEngine; using namespace GUIEngine;
DEFINE_SCREEN_SINGLETON( NetworkingLobby ); DEFINE_SCREEN_SINGLETON( NetworkingLobby );

View File

@ -36,7 +36,7 @@ class NetworkingLobby : public GUIEngine::Screen,
private: private:
friend class GUIEngine::ScreenSingleton<NetworkingLobby>; friend class GUIEngine::ScreenSingleton<NetworkingLobby>;
online::Server * m_server; Online::Server * m_server;
NetworkingLobby(); NetworkingLobby();

View File

@ -36,6 +36,7 @@
using namespace GUIEngine; using namespace GUIEngine;
using namespace Online;
DEFINE_SCREEN_SINGLETON( NetworkingLobbySettings ); DEFINE_SCREEN_SINGLETON( NetworkingLobbySettings );
@ -70,7 +71,7 @@ void NetworkingLobbySettings::loadedFromFile()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool NetworkingLobbySettings::hasLostConnection() bool NetworkingLobbySettings::hasLostConnection()
{ {
return !online::CurrentUser::get()->isSignedIn(); return !CurrentUser::get()->isSignedIn();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -100,7 +101,7 @@ void NetworkingLobbySettings::createServer()
const stringw name = m_name_widget->getText().trim(); const stringw name = m_name_widget->getText().trim();
int max_players = m_max_players_widget->getValue(); int max_players = m_max_players_widget->getValue();
stringw info = ""; stringw info = "";
if(online::CurrentUser::get()->createServer(name, max_players, info)) /*if(online::CurrentUser::get()->createServer(name, max_players, info))
{ {
StateManager::get()->escapePressed(); StateManager::get()->escapePressed();
StateManager::get()->pushScreen(NetworkingLobby::getInstance()); StateManager::get()->pushScreen(NetworkingLobby::getInstance());
@ -110,7 +111,7 @@ void NetworkingLobbySettings::createServer()
sfx_manager->quickSound( "anvil" ); sfx_manager->quickSound( "anvil" );
m_info_widget->setColor(irr::video::SColor(255, 255, 0, 0)); m_info_widget->setColor(irr::video::SColor(255, 255, 0, 0));
m_info_widget->setText(info, false); m_info_widget->setText(info, false);
} }*/
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -37,14 +37,13 @@
#include "states_screens/networking_lobby_settings.hpp" #include "states_screens/networking_lobby_settings.hpp"
#include "states_screens/server_selection.hpp" #include "states_screens/server_selection.hpp"
#include "modes/demo_world.hpp" #include "modes/demo_world.hpp"
#include "utils/translation.hpp"
#include "online/current_user.hpp"
#include "online/servers_manager.hpp" #include "online/servers_manager.hpp"
#include "online/messages.hpp"
using namespace GUIEngine; using namespace GUIEngine;
using namespace online; using namespace Online;
DEFINE_SCREEN_SINGLETON( OnlineScreen ); DEFINE_SCREEN_SINGLETON( OnlineScreen );
@ -52,8 +51,9 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui") OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
{ {
m_recorded_state = Not; m_recorded_state = CurrentUser::SIGNED_OUT;
online::CurrentUser::get()->trySavedSession(); CurrentUser::acquire()->trySavedSession();
CurrentUser::release();
} // OnlineScreen } // OnlineScreen
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -87,16 +87,9 @@ void OnlineScreen::loadedFromFile()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool OnlineScreen::hasStateChanged() bool OnlineScreen::hasStateChanged()
{ {
State previous_state = m_recorded_state; CurrentUser::UserState previous_state = m_recorded_state;
if(online::CurrentUser::get()->isSignedIn()) m_recorded_state = CurrentUser::acquire()->getUserState();
{ CurrentUser::release();
if(online::CurrentUser::get()->isGuest())
m_recorded_state = Guest;
else
m_recorded_state = Registered;
}
else
m_recorded_state = Not;
if (previous_state != m_recorded_state) if (previous_state != m_recorded_state)
return true; return true;
return false; return false;
@ -109,19 +102,24 @@ void OnlineScreen::beforeAddingWidget()
m_bottom_menu_widget->setVisible(true); m_bottom_menu_widget->setVisible(true);
m_top_menu_widget->setVisible(true); m_top_menu_widget->setVisible(true);
hasStateChanged(); hasStateChanged();
if (m_recorded_state == Registered) if (m_recorded_state == CurrentUser::SIGNED_IN)
{ {
m_register_widget->setVisible(false); m_register_widget->setVisible(false);
m_sign_in_widget->setVisible(false); m_sign_in_widget->setVisible(false);
} }
else if (m_recorded_state == Not) else if (m_recorded_state == CurrentUser::SIGNED_OUT || CurrentUser::SIGNING_IN || CurrentUser::SIGNING_OUT)
{ {
m_quick_play_widget->setDeactivated(); m_quick_play_widget->setDeactivated();
m_find_server_widget->setDeactivated(); m_find_server_widget->setDeactivated();
m_create_server_widget->setDeactivated(); m_create_server_widget->setDeactivated();
m_sign_out_widget->setVisible(false); m_sign_out_widget->setVisible(false);
if(CurrentUser::SIGNING_IN || CurrentUser::SIGNING_OUT)
{
m_register_widget->setDeactivated();
m_sign_in_widget->setDeactivated();
}
} }
else if (m_recorded_state == Guest) else if (m_recorded_state == CurrentUser::GUEST)
{ {
m_find_server_widget->setDeactivated(); m_find_server_widget->setDeactivated();
m_create_server_widget->setDeactivated(); m_create_server_widget->setDeactivated();
@ -138,12 +136,20 @@ void OnlineScreen::init()
Screen::init(); Screen::init();
setInitialFocus(); setInitialFocus();
DemoWorld::resetIdleTime(); DemoWorld::resetIdleTime();
m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + online::CurrentUser::get()->getUserName() + ".", false); m_load_timer = 0.0f;
m_online_status_widget->setText(Messages::signedInAs(CurrentUser::acquire()->getUserName()), false);
CurrentUser::release();
} // init } // init
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver) void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{ {
if (m_recorded_state == CurrentUser::SIGNING_IN)
{
m_load_timer += delta;
m_online_status_widget->setText(Messages::signingIn(m_load_timer), false);
}
if (hasStateChanged()) if (hasStateChanged())
GUIEngine::reshowCurrentScreen(); GUIEngine::reshowCurrentScreen();
} // onUpdate } // onUpdate
@ -169,7 +175,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
else if (selection == "sign_out") else if (selection == "sign_out")
{ {
irr::core::stringw info; irr::core::stringw info;
if (online::CurrentUser::get()->signOut(info)) if (Online::CurrentUser::get()->signOut(info))
{ {
new MessageDialog(_("Signed out successfully.")); new MessageDialog(_("Signed out successfully."));
//GUIEngine::reshowCurrentScreen(); //GUIEngine::reshowCurrentScreen();
@ -194,7 +200,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
//FIXME temporary and the request join + join sequence should be placed in one method somewhere //FIXME temporary and the request join + join sequence should be placed in one method somewhere
Server * server = ServersManager::get()->getQuickPlay(); Server * server = ServersManager::get()->getQuickPlay();
irr::core::stringw info; irr::core::stringw info;
if (online::CurrentUser::get()->requestJoin( server->getServerId(), info)) if (Online::CurrentUser::get()->requestJoin( server->getServerId(), info))
{ {
ServersManager::get()->setJoinedServer(server); ServersManager::get()->setJoinedServer(server);
StateManager::get()->pushScreen(NetworkingLobby::getInstance()); StateManager::get()->pushScreen(NetworkingLobby::getInstance());
@ -233,17 +239,18 @@ void OnlineScreen::onDisabledItemClicked(const std::string& item)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void OnlineScreen::setInitialFocus() void OnlineScreen::setInitialFocus()
{ {
if(m_recorded_state == Not) if(m_recorded_state == CurrentUser::SIGNED_IN)
m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
else
m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
else
m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
} // setInitialFocus } // setInitialFocus
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void OnlineScreen::onDialogClose() void OnlineScreen::onDialogClose()
{ {
if (hasStateChanged()) /*if (hasStateChanged())
GUIEngine::reshowCurrentScreen(); GUIEngine::reshowCurrentScreen();
else else*/
setInitialFocus(); setInitialFocus();
} // onDialogClose() } // onDialogClose()

View File

@ -22,6 +22,7 @@
#include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp" #include "guiengine/widgets/icon_button_widget.hpp"
#include "online/current_user.hpp"
namespace GUIEngine { class Widget; class ListWidget; } namespace GUIEngine { class Widget; class ListWidget; }
@ -49,14 +50,9 @@ private:
GUIEngine::IconButtonWidget * m_register_widget; GUIEngine::IconButtonWidget * m_register_widget;
GUIEngine::IconButtonWidget * m_sign_out_widget; GUIEngine::IconButtonWidget * m_sign_out_widget;
enum State Online::CurrentUser::UserState m_recorded_state;
{
Not = 1,
Guest = 2,
Registered = 4
};
State m_recorded_state; float m_load_timer;
/** \brief Checks if the recorded state differs from the actual state and sets it. */ /** \brief Checks if the recorded state differs from the actual state and sets it. */
bool hasStateChanged(); bool hasStateChanged();

View File

@ -29,7 +29,7 @@
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
#include "online/servers_manager.hpp" #include "online/servers_manager.hpp"
using namespace online; using namespace Online;
DEFINE_SCREEN_SINGLETON( ServerSelection ); DEFINE_SCREEN_SINGLETON( ServerSelection );

View File

@ -709,14 +709,6 @@ namespace StringUtils
printf("Invalid version string '%s'.\n", s.c_str()); printf("Invalid version string '%s'.\n", s.c_str());
return version; return version;
} // versionToInt } // 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 } // namespace StringUtils

View File

@ -413,9 +413,6 @@ namespace StringUtils
/** Compute a simple hash of a string */ /** Compute a simple hash of a string */
unsigned int simpleHash(const char* input); 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 } // namespace StringUtils
#endif #endif