Made a response queue for the http manager. Adapted everything to use it. Enhanced registration process. Loading messages use the global timer.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13302 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx
2013-07-21 00:47:48 +00:00
parent eafcbc7103
commit e84159f0c9
17 changed files with 290 additions and 241 deletions

View File

@@ -17,6 +17,11 @@
</div>
<spacer height="20" width="50">
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text=""/>
<spacer height="20" width="50">
<div id="options" width="fit" proportion="1" align="center" layout="horizontal-row">
<button id="previous" height="fit" align="center" width="fit" I18N="In the registration dialog" text="Previous"/>

View File

@@ -76,43 +76,30 @@ namespace Online{
}
// ============================================================================
// Register
bool CurrentUser::signUp( const irr::core::stringw &username,
const irr::core::stringw &password,
const irr::core::stringw &password_ver,
const irr::core::stringw &email,
bool terms,
irr::core::stringw &info)
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 == SIGNED_OUT || m_state == GUEST);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action",std::string("register"));
connector->setParameter("username",username);
connector->setParameter("password",password);
const XMLNode * result = connector->getXMLFromPage();
std::string rec_success;
bool success = false;
if(result->get("success", &rec_success))
{
success = (rec_success == "yes");
assert(result->get("info", &info));
}
else
{
info = _("Unable to connect to the server. Check your internet connection or try again later.");
}
return success;
XMLRequest * request = new XMLRequest(Request::RT_SIGN_UP);
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);
HTTPManager::get()->addRequest(request);
return request;
}
// ============================================================================
CurrentUser::SignInRequest * CurrentUser::requestSavedSession()
SignInRequest * CurrentUser::requestSavedSession()
{
CurrentUser::SignInRequest * request = NULL;
SignInRequest * request = NULL;
if(m_state != SIGNED_IN && UserConfigParams::m_saved_session)
{
request = new CurrentUser::SignInRequest();
request = new 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);
@@ -123,13 +110,13 @@ namespace Online{
return request;
}
CurrentUser::SignInRequest * CurrentUser::requestSignIn( const irr::core::stringw &username,
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;
CurrentUser::SignInRequest * request = new CurrentUser::SignInRequest();
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);
@@ -160,7 +147,7 @@ namespace Online{
m_state = SIGNED_OUT;
}
void CurrentUser::SignInRequest::callback()
void SignInRequest::callback()
{
CurrentUser::acquire()->signIn(this);
CurrentUser::release();
@@ -168,7 +155,7 @@ namespace Online{
// ============================================================================
CurrentUser::ServerCreationRequest * CurrentUser::requestServerCreation(const irr::core::stringw &name, int max_players)
ServerCreationRequest * CurrentUser::requestServerCreation(const irr::core::stringw &name, int max_players)
{
assert(m_state == SIGNED_IN);
ServerCreationRequest * request = new ServerCreationRequest();
@@ -182,16 +169,15 @@ namespace Online{
return request;
}
void CurrentUser::ServerCreationRequest::callback()
void ServerCreationRequest::callback()
{
//FIXME To be filled in
//FIXME
}
// ============================================================================
CurrentUser::SignOutRequest * CurrentUser::requestSignOut(){
SignOutRequest * CurrentUser::requestSignOut(){
assert(m_state == SIGNED_IN || m_state == GUEST);
CurrentUser::SignOutRequest * request = new CurrentUser::SignOutRequest();
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);
@@ -216,7 +202,7 @@ namespace Online{
UserConfigParams::m_saved_session = false;
}
void CurrentUser::SignOutRequest::callback()
void SignOutRequest::callback()
{
CurrentUser::acquire()->signOut(this);
CurrentUser::release();
@@ -224,9 +210,9 @@ namespace Online{
// ============================================================================
CurrentUser::ServerJoinRequest * CurrentUser::requestServerJoin(uint32_t server_id){
ServerJoinRequest * CurrentUser::requestServerJoin(uint32_t server_id){
assert(m_state == SIGNED_IN || m_state == GUEST);
CurrentUser::ServerJoinRequest * request = new CurrentUser::ServerJoinRequest();
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);
@@ -235,9 +221,9 @@ namespace Online{
return request;
}
void CurrentUser::ServerJoinRequest::callback()
void ServerJoinRequest::callback()
{
//FIXME To be filled in
//FIXME
}
// ============================================================================

View File

@@ -28,6 +28,33 @@
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) {}
};
// ============================================================================
/**
@@ -46,26 +73,6 @@ namespace Online{
SIGNING_OUT
};
class SignInRequest : public XMLRequest
{
virtual void callback ();
};
class SignOutRequest : public XMLRequest
{
virtual void callback ();
};
class ServerCreationRequest : public XMLRequest
{
virtual void callback ();
};
class ServerJoinRequest : public XMLRequest
{
virtual void callback ();
};
private:
std::string m_token;
bool m_save_session;
@@ -73,11 +80,6 @@ namespace Online{
CurrentUser();
void signIn (const SignInRequest * input);
void signOut (const SignOutRequest * input);
void createServer (const ServerCreationRequest * input);
public:
static CurrentUser* get(); //FIXME To be removed
@@ -96,21 +98,22 @@ namespace Online{
// Register
bool signUp( const irr::core::stringw &username,
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,
irr::core::stringw &info);
bool terms);
void signIn (const SignInRequest * input);
void signOut (const SignOutRequest * input);
void createServer (const ServerCreationRequest * input);
/** 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; }
UserState getUserState() { return m_state; }
bool isSignedIn() const { return m_state == SIGNED_IN; }
bool isGuest() const { return m_state == GUEST; }
bool isSigningIn() const { return m_state == SIGNING_IN; }
UserState getUserState() { return m_state; }
}; // class CurrentUser

View File

@@ -146,7 +146,7 @@ namespace Online{
* sorted by priority.
* \param request The pointer to the new request to insert.
*/
void HTTPManager::addRequest(Online::Request *request)
void HTTPManager::addRequest(Request *request)
{
assert(request->isAllowedToAdd());
m_request_queue.lock();
@@ -156,6 +156,36 @@ namespace Online{
m_request_queue.unlock();
} // insertRequest
// ----------------------------------------------------------------------------
/**
* \param request The pointer to the finished request to insert.
*/
void HTTPManager::addResponse(Request *request)
{
m_response_queue.lock();
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
@@ -170,7 +200,7 @@ namespace Online{
me->m_current_request = NULL;
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() || 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
@@ -185,12 +215,15 @@ namespace Online{
me->m_request_queue.getData().pop();
me->m_request_queue.unlock();
me->m_current_request->execute();
if(me->m_current_request->manageMemory())
{
delete me->m_current_request;
me->m_current_request = NULL;
}
else
{
me->addResponse(me->m_current_request);
}
me->m_request_queue.lock();
} // while

View File

@@ -44,6 +44,8 @@ namespace Online{
{
protected:
/** Ment for networking threads */
/** The current requested being worked on. */
Online::Request * m_current_request;
@@ -56,7 +58,7 @@ namespace Online{
/** Thread id of the thread running in this object. */
Synchronised<pthread_t *> m_thread_id;
/** The list of pointes to all requests. */
/** The list of pointers to all requests that still need to be handled. */
Synchronised< std::priority_queue <
Online::Request*,
std::vector<Online::Request*>,
@@ -64,6 +66,11 @@ namespace Online{
>
> 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();
@@ -84,6 +91,9 @@ namespace Online{
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(); };

View File

@@ -18,27 +18,28 @@
#include "online/messages.hpp"
#include "utils/translation.hpp"
#include "utils/time.hpp"
namespace Online
{
namespace Messages
{
irr::core::stringw loadingDots(float timer, bool spaces, float interval, int max_dots)
irr::core::stringw loadingDots(bool spaces, float interval, int max_dots)
{
int nr_dots = int(floor(timer * (1 / interval))) % (max_dots+1);
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(float timer)
irr::core::stringw signingIn()
{
return irr::core::stringw(_("Signing in")) + loadingDots(timer);
return irr::core::stringw(_("Signing in")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw signingOut(float timer)
irr::core::stringw signingOut()
{
return irr::core::stringw(_("Signing out")) + loadingDots(timer);
return irr::core::stringw(_("Signing out")) + loadingDots();
}
// ------------------------------------------------------------------------
@@ -47,14 +48,14 @@ namespace Online
return irr::core::stringw(_("Signed in as : ")) + name + ".";
}
irr::core::stringw joiningServer(float timer)
irr::core::stringw joiningServer()
{
return irr::core::stringw(_("Joining server")) + loadingDots(timer);
return irr::core::stringw(_("Joining server")) + loadingDots();
}
irr::core::stringw creatingServer(float timer)
irr::core::stringw creatingServer()
{
return irr::core::stringw(_("Creating server")) + loadingDots(timer);
return irr::core::stringw(_("Creating server")) + loadingDots();
}
} // namespace messages
} // namespace Online

View File

@@ -26,11 +26,11 @@ 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 joiningServer (float timer);
irr::core::stringw creatingServer (float timer);
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 joiningServer ();
irr::core::stringw creatingServer ();
irr::core::stringw signedInAs (const irr::core::stringw & name);
} // namespace Messages
}// namespace Online

View File

@@ -28,7 +28,8 @@ namespace Online{
// =========================================================================================
Request::Request(int priority, bool manage_memory)
Request::Request(RequestType type, int priority, bool manage_memory)
:m_type(type)
{
m_priority = priority;
m_manage_memory = manage_memory;
@@ -55,20 +56,19 @@ namespace Online{
// =========================================================================================
QuitRequest::QuitRequest()
: Request(9999,true)
: Request(RT_QUIT,9999,true)
{
}
// =========================================================================================
HTTPRequest::HTTPRequest(const std::string & url)
: Request(1,false)
HTTPRequest::HTTPRequest(RequestType type, const std::string & url)
: Request(type, 1,false)
{
m_url = url;
m_parameters = new Parameters;
m_progress.setAtomic(0);
m_added = false;
}
HTTPRequest::~HTTPRequest()
@@ -200,8 +200,8 @@ namespace Online{
// =========================================================================================
XMLRequest::XMLRequest(const std::string & url)
: HTTPRequest(url)
XMLRequest::XMLRequest(RequestType type, const std::string & url)
: HTTPRequest(type, url)
{
m_info = "";
m_success = false;

View File

@@ -32,6 +32,18 @@ namespace Online{
*/
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
};
protected:
/** The priority of this request. The higher the value the more
important this request is. */
@@ -39,6 +51,8 @@ namespace Online{
/** 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
@@ -46,7 +60,7 @@ namespace Online{
* be freed by the calling function. */
bool m_manage_memory;
Synchronised<bool> m_done;
Synchronised<bool> m_done;
virtual void beforeOperation() {}
virtual void operation() = 0;
@@ -54,31 +68,33 @@ namespace Online{
public:
Request(int priority, bool manage_memory=true);
Request(RequestType type, int priority, bool manage_memory=true);
virtual ~Request();
void execute();
// ------------------------------------------------------------------------
/** 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 = true; }
// ------------------------------------------------------------------------
/** Returns if this request is to be canceled. */
bool isCancelled() const { return m_cancel; }
bool isCancelled() const { return m_cancel; }
// ------------------------------------------------------------------------
/** Specifies if the memory should be managed by network_http. */
void setManageMemory(bool m) { m_manage_memory = m; }
/** 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 manageMemory() const { return m_manage_memory; }
bool isDone(){return m_done.getAtomic();}
bool isDone() const { return m_done.getAtomic(); }
virtual bool isAllowedToAdd() {return true;}
RequestType getType() const { return m_type; }
virtual bool isAllowedToAdd() { return true; }
/** This class is used by the priority queue to sort requests by priority.
*/
@@ -120,7 +136,6 @@ namespace Online{
* (everything ok) at the end. */
Synchronised<float> m_progress;
std::string m_url;
bool m_added;
virtual void afterOperation();
std::string downloadPage();
@@ -138,22 +153,18 @@ namespace Online{
virtual void callback() {}
public :
HTTPRequest(const std::string & url = "");
HTTPRequest(RequestType type, const std::string & url = "");
virtual ~HTTPRequest();
void setParameter(const std::string & name, const std::string &value){
if(!m_added)
(*m_parameters)[name] = value;
(*m_parameters)[name] = value;
};
void setParameter(const std::string & name, const irr::core::stringw &value){
if(!m_added)
(*m_parameters)[name] = irr::core::stringc(value.c_str()).c_str();
(*m_parameters)[name] = irr::core::stringc(value.c_str()).c_str();
}
template <typename T>
void setParameter(const std::string & name, const T& value){
if(!m_added)
(*m_parameters)[name] = StringUtils::toString(value);
(*m_parameters)[name] = StringUtils::toString(value);
}
/** Returns the current progress. */
@@ -180,7 +191,7 @@ namespace Online{
virtual void afterOperation() OVERRIDE;
public :
XMLRequest(const std::string & url = "");
XMLRequest(RequestType type, const std::string & url = "");
virtual XMLNode * getResult() const { return m_result; }
const irr::core::stringw & getInfo() const { return m_info; }

View File

@@ -32,6 +32,7 @@
using namespace GUIEngine;
using namespace irr;
using namespace irr::gui;
using namespace Online;
// -----------------------------------------------------------------------------
@@ -40,8 +41,7 @@ LoginDialog::LoginDialog(const Message message_type) :
{
m_self_destroy = false;
m_open_registration_dialog = false;
m_load_timer = 0;
m_sign_in_request = NULL;
m_signing_in = false;
loadFromFile("online/login_dialog.stkgui");
m_message_widget = getWidget<LabelWidget>("message");
@@ -96,7 +96,6 @@ LoginDialog::LoginDialog(const Message message_type) :
LoginDialog::~LoginDialog()
{
delete m_sign_in_request;
}
@@ -115,8 +114,9 @@ void LoginDialog::login()
else
{
m_options_widget->setDeactivated();
m_sign_in_request = Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState());
Online::CurrentUser::acquire()->requestSignIn(username,password, m_remember_widget->getState());
Online::CurrentUser::release();
m_signing_in = true;
}
}
@@ -163,30 +163,22 @@ void LoginDialog::onEnterPressedInternal()
void LoginDialog::onUpdate(float dt)
{
if(m_sign_in_request != NULL)
XMLRequest * sign_in_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_IN);
if(sign_in_request != NULL)
{
if(m_sign_in_request->isDone())
if(sign_in_request->isSuccess())
{
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);
}
m_options_widget->setActivated();
delete m_sign_in_request;
m_sign_in_request = NULL;
m_self_destroy = true;
}
else
{
m_load_timer += dt;
m_info_widget->setDefaultColor();
m_info_widget->setText(Online::Messages::signingIn(m_load_timer), false);
sfx_manager->quickSound( "anvil" );
m_info_widget->setErrorColor();
m_info_widget->setText(sign_in_request->getInfo(), 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);
@@ -197,6 +189,12 @@ void LoginDialog::onUpdate(float dt)
ModalDialog::dismiss();
if (m_open_registration_dialog)
new RegistrationDialog();
return;
}
if (m_signing_in)
{
m_info_widget->setDefaultColor();
m_info_widget->setText(Online::Messages::signingIn(), false);
}
}

View File

@@ -37,9 +37,7 @@ private:
bool m_self_destroy;
bool m_open_registration_dialog;
float m_load_timer;
Online::CurrentUser::SignInRequest * m_sign_in_request;
bool m_signing_in;
GUIEngine::LabelWidget * m_message_widget;
GUIEngine::TextBoxWidget * m_username_widget;
GUIEngine::TextBoxWidget * m_password_widget;

View File

@@ -25,18 +25,19 @@
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/current_user.hpp"
using namespace GUIEngine;
using namespace irr;
using namespace irr::gui;
using namespace Online;
// -----------------------------------------------------------------------------
RegistrationDialog::RegistrationDialog(const Phase phase) :
ModalDialog(0.8f,0.9f)
{
m_sign_up_request = NULL;
m_self_destroy = false;
m_show_registration_info = false;
m_show_registration_terms = false;
@@ -93,10 +94,10 @@ void RegistrationDialog::showRegistrationInfo(){
assert(textBox != NULL);
textBox->setText(m_email_confirm);
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_info_widget->setErrorColor();
m_info_widget->setText(m_registration_error, false);
LabelWidget* label = getWidget<LabelWidget>("info");
assert(label != NULL);
label->setErrorColor();
label->setText(m_registration_error, false);
ButtonWidget * button = getWidget<ButtonWidget>("next");
assert(button != NULL);
@@ -143,36 +144,38 @@ bool RegistrationDialog::processInfoEvent(const std::string& eventSource){
m_password_confirm = getWidget<TextBoxWidget>("password_confirm")->getText().trim();
m_email = getWidget<TextBoxWidget>("email")->getText().trim();
m_email_confirm = getWidget<TextBoxWidget>("email_confirm")->getText().trim();
LabelWidget * info_widget = getWidget<LabelWidget>("info");
//FIXME More validation of registration information
if (m_password != m_password_confirm)
{
getWidget<LabelWidget>("info")->setText(_("Passwords don't match!"), false);
info_widget->setText(_("Passwords don't match!"), false);
sfx_manager->quickSound( "anvil" );
}
else if (m_email != m_email_confirm)
{
getWidget<LabelWidget>("info")->setText(_("Emails don't match!"), false);
info_widget->setText(_("Emails don't match!"), false);
sfx_manager->quickSound( "anvil" );
}
else if (m_username.size() < 5 || m_username.size() > 30)
else if (m_username.size() < 4 || m_username.size() > 30)
{
getWidget<LabelWidget>("info")->setText(_("Username has to be between 5 and 30 characters long!"), false);
info_widget->setText(_("Username has to be between 5 and 30 characters long!"), false);
sfx_manager->quickSound( "anvil" );
}
else if (m_password.size() < 8 || m_password.size() > 30)
{
getWidget<LabelWidget>("info")->setText(_("Password has to be between 5 and 30 characters long!"), false);
info_widget->setText(_("Password has to be between 5 and 30 characters long!"), false);
sfx_manager->quickSound( "anvil" );
}
else if (m_email.size() < 5 || m_email.size() > 50)
else if (m_email.size() < 4 || m_email.size() > 50)
{
getWidget<LabelWidget>("info")->setText(_("Email has to be between 5 and 50 characters long!"), false);
sfx_manager->quickSound( "anvil" );
info_widget->setText(_("Email has to be between 5 and 50 characters long!"), false);
}
else
{
m_show_registration_terms = true;
return true;
}
sfx_manager->quickSound( "anvil" );
return true;
}
}
@@ -188,15 +191,7 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
{
assert(getWidget<CheckBoxWidget>("accepted")->getState());
m_agreement = true;
if(Online::CurrentUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, m_registration_error))
{
m_show_registration_activation = true;
m_registration_error = "";
}
else
{
m_show_registration_info = true;
}
m_sign_up_request = CurrentUser::acquire()->requestSignUp(m_username, m_password, m_password_confirm, m_email, m_agreement);
return true;
}
else if (eventSource == "accepted")
@@ -279,15 +274,38 @@ void RegistrationDialog::onEnterPressedInternal()
void RegistrationDialog::onUpdate(float dt)
{
/*
if(m_sign_up_request != NULL)
{
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_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);
}
}*/
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
{
ModalDialog::dismiss();
}
if (m_show_registration_info)
else if (m_show_registration_info)
showRegistrationInfo();
if (m_show_registration_terms)
else if (m_show_registration_terms)
showRegistrationTerms();
if (m_show_registration_activation)
else if (m_show_registration_activation)
showRegistrationActivation();
}

View File

@@ -23,6 +23,7 @@
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
/**
* \brief Dialog that allows a user to register
* \ingroup states_screens
@@ -48,14 +49,14 @@ public:
private:
GUIEngine::LabelWidget * m_info_widget;
Phase m_phase;
bool m_self_destroy;
bool m_show_registration_info;
bool m_show_registration_terms;
bool m_show_registration_activation;
Online::XMLRequest * m_sign_up_request;
//Saved user input :
irr::core::stringw m_username;
irr::core::stringw m_password;
@@ -65,6 +66,7 @@ private:
irr::core::stringw m_registration_error;
bool m_agreement;
void showRegistrationInfo();
void showRegistrationTerms();
void showRegistrationActivation();

View File

@@ -46,8 +46,7 @@ ServerInfoDialog::ServerInfoDialog(Server * server) :
m_server = server;
m_self_destroy = false;
m_enter_lobby = false;
m_server_join_request = NULL;
m_load_timer = 0;
m_joining_server = false;
loadFromFile("online/server_info_dialog.stkgui");
@@ -70,13 +69,13 @@ ServerInfoDialog::ServerInfoDialog(Server * server) :
// -----------------------------------------------------------------------------
ServerInfoDialog::~ServerInfoDialog()
{
delete m_server_join_request;
}
// -----------------------------------------------------------------------------
void ServerInfoDialog::requestJoin()
{
m_server_join_request = Online::CurrentUser::acquire()->requestServerJoin(m_server->getServerId());
Online::CurrentUser::acquire()->requestServerJoin(m_server->getServerId());
Online::CurrentUser::release();
m_joining_server = true;
}
// -----------------------------------------------------------------------------
@@ -116,33 +115,23 @@ void ServerInfoDialog::onEnterPressedInternal()
void ServerInfoDialog::onUpdate(float dt)
{
if(m_server_join_request != NULL)
XMLRequest * request = HTTPManager::get()->getXMLResponse(Request::RT_SERVER_JOIN);
if(request != NULL)
{
if(m_server_join_request->isDone())
if(request->isSuccess())
{
if(m_server_join_request->isSuccess())
{
ServersManager::get()->setJoinedServer(m_server);
m_enter_lobby = 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;
m_self_destroy = true;
}
else
{
m_load_timer += dt;
m_info_widget->setDefaultColor();
m_info_widget->setText(Online::Messages::joiningServer(m_load_timer), false);
sfx_manager->quickSound( "anvil" );
m_info_widget->setErrorColor();
m_info_widget->setText(request->getInfo(), false);
}
delete request;
m_joining_server = false;
}
//If we want to open the registration dialog, we need to close this one first
m_enter_lobby && (m_self_destroy = true);
@@ -152,5 +141,12 @@ void ServerInfoDialog::onUpdate(float dt)
ModalDialog::dismiss();
if (m_enter_lobby)
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
return;
}
if (m_joining_server)
{
m_info_widget->setDefaultColor();
m_info_widget->setText(Online::Messages::joiningServer(), false);
}
}

View File

@@ -40,11 +40,11 @@ private:
bool m_self_destroy;
bool m_enter_lobby;
bool m_joining_server;
float m_load_timer;
Online::Server * m_server;
Online::CurrentUser::ServerJoinRequest * m_server_join_request;
GUIEngine::LabelWidget * m_name_widget;
GUIEngine::LabelWidget * m_info_widget;

View File

@@ -52,9 +52,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
{
m_recorded_state = CurrentUser::SIGNED_OUT;
CurrentUser::SignInRequest * request = CurrentUser::acquire()->requestSavedSession();
if(request != NULL)
m_requests.push_back(request);
CurrentUser::acquire()->requestSavedSession();
CurrentUser::release();
} // OnlineScreen
@@ -62,7 +60,6 @@ OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
OnlineScreen::~OnlineScreen()
{
m_requests.clearAndDeleteAll();
}
// ----------------------------------------------------------------------------
@@ -145,7 +142,6 @@ void OnlineScreen::init()
Screen::init();
setInitialFocus();
DemoWorld::resetIdleTime();
m_load_timer = 0.0f;
m_online_status_widget->setText(Messages::signedInAs(CurrentUser::acquire()->getUserName()), false);
CurrentUser::release();
@@ -158,46 +154,42 @@ void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
GUIEngine::reshowCurrentScreen();
if (m_recorded_state == CurrentUser::SIGNING_IN)
{
m_load_timer += delta;
m_online_status_widget->setText(Messages::signingIn(m_load_timer), false);
m_online_status_widget->setText(Messages::signingIn(), false);
}
else if (m_recorded_state == CurrentUser::SIGNING_OUT)
{
m_load_timer += delta;
m_online_status_widget->setText(Messages::signingOut(m_load_timer), false);
m_online_status_widget->setText(Messages::signingOut(), false);
}
for(int i = m_requests.size()-1; i>=0; --i)
XMLRequest * sign_in_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_IN);
if(sign_in_request != NULL)
{
if(m_requests[i].isDone())
if(sign_in_request->isSuccess())
{
if( dynamic_cast<CurrentUser::SignInRequest*>(m_requests.get(i)))
{
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)))
{
if(m_requests[i].isSuccess())
{
new MessageDialog(_("Signed out successfully."));
}
else
{
sfx_manager->quickSound( "anvil" );
new MessageDialog(m_requests[i].getInfo());
}
}
m_requests.erase(i);
new MessageDialog(_("Signed in."));
}
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;
}
} // onUpdate
@@ -221,7 +213,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
}
else if (selection == "sign_out")
{
m_requests.push_back(CurrentUser::acquire()->requestSignOut());
CurrentUser::acquire()->requestSignOut();
CurrentUser::release();
}
else if (selection == "register")

View File

@@ -53,10 +53,6 @@ private:
Online::CurrentUser::UserState m_recorded_state;
float m_load_timer;
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. */