[GSoC Uni_] Several improvements. No point in having a decent commit message, if it's for me only ;)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@12967 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-06-24 19:20:16 +00:00
parent fe47e50341
commit 7e36035228
13 changed files with 174 additions and 114 deletions

View File

@ -1,41 +1,37 @@
<stkgui> <stkgui>
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" > <div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
<header id="title" width="96%" proportion="2" text_align="center" word_wrap="true"
I18N="In the login dialog' dialog" text="Sign in"/>
<label id="title" width="100%" height="fit" text_align="center" word_wrap="true" <spacer proportion="2">
I18N="In the login dialog' dialog" text="Sign in" proportion="1" />
<spacer height="25" width="10" /> <div width="95%" proportion="3" layout="horizontal-row" >
<label proportion="1" text_align="center" I18N="In the login form" text="Username"/>
<div width="95%" height="fit" layout="horizontal-row" > <textbox proportion="2" id="username" I18N="In the login dialog"/>
<label proportion="1" text_align="center" I18N="In the login form" text="Username"/>
<div proportion="2" height="fit" layout="horizontal-row" >
<textbox id="username" width="100%" I18N="In the login dialog" align="center"/>
</div> </div>
</div>
<spacer height="20" width="20" /> <spacer proportion="1">
<div width="95%" height="fit" layout="horizontal-row" > <div width="95%" proportion="3" layout="horizontal-row" >
<label proportion="1" text_align="center" I18N="In the login form" text="Password"/> <label proportion="1" text_align="center" I18N="In the login form" text="Password"/>
<div proportion="2" height="fit" layout="horizontal-row" > <textbox proportion="2" id="password" I18N="In the login dialog"/>
<textbox id="password" width="100%" I18N="In the login dialog" align="center"/>
</div> </div>
<label id="info" proportion="1" width="96%" text_align="center" word_wrap="true"
I18N="In the login dialog' dialog" text=""/>
<spacer proportion="1">
<div id="options" width="fit" proportion="3" align="center" layout="horizontal-row">
<button id="signin" height="100%" proportion="4" I18N="In the login dialog" text="Sign In"/>
<spacer proportion="1" height="100%">
<button id="cancel" height="100%" proportion="4" I18N="In the login dialog" text="Cancel"/>
</div>
</div> </div>
<spacer height="20" width="20" />
<label id="errormsg" width="100%" height="fit" text_align="center" word_wrap="true"
I18N="In the login dialog' dialog" text="" proportion="1" />
<spacer height="20" width="20" />
<button id="signin" height="fit" I18N="In the login dialog" text="Sign In" align="center"/>
<button id="cancel" height="fit" I18N="In the login dialog" text="Cancel" align="center"/>
<spacer height="15" width="20" />
</div>
</stkgui> </stkgui>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 67 KiB

View File

@ -19,15 +19,6 @@
#ifndef HEADER_XML_NODE_HPP #ifndef HEADER_XML_NODE_HPP
#define HEADER_XML_NODE_HPP #define HEADER_XML_NODE_HPP
#ifdef _MSC_VER
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
# include <stdint.h>
#endif
#include <string> #include <string>
#include <map> #include <map>
#include <vector> #include <vector>
@ -43,6 +34,7 @@ using namespace irr;
#include "utils/leak_check.hpp" #include "utils/leak_check.hpp"
#include "utils/no_copy.hpp" #include "utils/no_copy.hpp"
#include "utils/time.hpp" #include "utils/time.hpp"
#include "utils/types.hpp"
class InterpolationArray; class InterpolationArray;
class Vec3; class Vec3;

View File

@ -24,7 +24,7 @@
#include <assert.h> #include <assert.h>
#include "online/http_connector.hpp" #include "online/http_connector.hpp"
#include "config/user_config.hpp" #include "config/user_config.hpp"
#include "utils/string_utils.hpp" #include "utils/translation.hpp"
static CurrentOnlineUser* user_singleton = NULL; static CurrentOnlineUser* user_singleton = NULL;
@ -46,18 +46,26 @@ void CurrentOnlineUser::deallocate()
CurrentOnlineUser::CurrentOnlineUser(){ CurrentOnlineUser::CurrentOnlineUser(){
m_is_signed_in = false; m_is_signed_in = false;
m_id = 0;
m_name = "";
m_token = "";
} }
// ============================================================================ // ============================================================================
// Register // Register
bool CurrentOnlineUser::signUp(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg){ bool CurrentOnlineUser::signUp( const irr::core::stringw &username,
const irr::core::stringw &password,
const irr::core::stringw &password_ver,
const irr::core::stringw &email,
bool terms,
irr::core::stringw &msg){
assert(m_is_signed_in == false); assert(m_is_signed_in == false);
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");
HTTPConnector::Parameters parameters; connector->setParameter("action",std::string("register"));
parameters["action"] = "register"; connector->setParameter("user",username);
parameters["user"] = username; connector->setParameter("password",password);
parameters["password"] = password;
const XMLNode * result = connector->getXMLFromPage(parameters); 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))
{ {
@ -81,32 +89,45 @@ bool CurrentOnlineUser::signUp(const irr::core::stringw &username, const irr::co
// ============================================================================ // ============================================================================
bool CurrentOnlineUser::signIn(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg) bool CurrentOnlineUser::signIn(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &info)
{ {
assert(m_is_signed_in == false); assert(m_is_signed_in == false);
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");
HTTPConnector::Parameters parameters; connector->setParameter("action",std::string("connect"));
parameters["action"] = "connect"; connector->setParameter("user",username);
parameters["user"] = username; connector->setParameter("password",password);
parameters["password"] = password; info = "Temporary error so that testers do not have to connect to the server.";
const XMLNode * result = connector->getXMLFromPage(parameters); return false; //FIXME
return false; const XMLNode * result = connector->getXMLFromPage();
std::string rec_token; std::string rec_success = "";
irr::core::stringw rec_username; if(result->get("success", &rec_success) && rec_success =="yes")
std::string rec_userid;
if(result->get("token", &rec_token) && result->get("username", &rec_username) && result->get("userid", &rec_userid))
{ {
long userid; assert(result->get("token", &m_token));
StringUtils::fromString<long>(rec_userid, userid); assert(result->get("username", &m_name));
m_user = new OnlineUser(""); assert(result->get("userid", &m_id));
m_token = rec_token;
m_is_signed_in = true; m_is_signed_in = true;
} }
else result->get("info", &info);
return m_is_signed_in;
}
// ============================================================================
bool CurrentOnlineUser::signOut(){
assert(m_is_signed_in == true);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action",std::string("disconnect"));
connector->setParameter("token",m_token);
connector->setParameter("userid",m_id);
const XMLNode * result = connector->getXMLFromPage();
std::string rec_success = "";
if(result->get("success", &rec_success) && rec_success =="yes")
{ {
//I don't know if something should happen here yet m_token = "";
m_name = "";
m_id = 0;
m_is_signed_in = false;
} }
//result->get("info", &info);
return m_is_signed_in; return m_is_signed_in;
} }
@ -115,10 +136,9 @@ bool CurrentOnlineUser::signIn(const irr::core::stringw &username, const irr::co
irr::core::stringw CurrentOnlineUser::getUserName() const irr::core::stringw CurrentOnlineUser::getUserName() const
{ {
if(m_is_signed_in){ if(m_is_signed_in){
assert(m_user != NULL); return m_name;
return m_user->getUserName();
}else{ }else{
return "Guest"; return _("Not Signed In");
} }
} }

View File

@ -30,22 +30,32 @@
* \brief Class that represents an online registered user * \brief Class that represents an online registered user
* \ingroup online * \ingroup online
*/ */
class CurrentOnlineUser class CurrentOnlineUser : public OnlineUser
{ {
private: private:
protected: protected:
std::string m_token; std::string m_token;
bool m_is_signed_in; bool m_is_signed_in;
OnlineUser * m_user;
CurrentOnlineUser(); CurrentOnlineUser();
public: public:
// singleton // singleton
static CurrentOnlineUser* get(); static CurrentOnlineUser* get();
static void deallocate(); static void deallocate();
bool signIn(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg); // Login
bool signUp(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &msg); bool signIn( const irr::core::stringw &username,
const irr::core::stringw &password,
irr::core::stringw &info);
// Register
bool signUp( const irr::core::stringw &username,
const irr::core::stringw &password,
const irr::core::stringw &password_ver,
const irr::core::stringw &email,
bool terms,
irr::core::stringw &msg);
// Logout - Best to be followed by CurrentOnlineUser::deallocate
bool signOut();
/** 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(){ return m_is_signed_in; }

View File

@ -22,7 +22,6 @@
#include <stdio.h> #include <stdio.h>
#include <memory.h> #include <memory.h>
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "utils/string_utils.hpp"
HTTPConnector::HTTPConnector(const std::string &url){ HTTPConnector::HTTPConnector(const std::string &url){
@ -53,24 +52,25 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use
return size * nmemb; return size * nmemb;
} }
XMLNode * HTTPConnector::getXMLFromPage(Parameters & post_parameters) XMLNode * HTTPConnector::getXMLFromPage()
{ {
return file_manager->createXMLTreeFromString(getPage(post_parameters)); return file_manager->createXMLTreeFromString(getPage());
} }
std::string HTTPConnector::getPage(Parameters & post_parameters) std::string HTTPConnector::getPage()
{ {
Parameters::iterator iter; Parameters::iterator iter;
std::string postString = ""; std::string postString = "";
for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter) for (iter = m_parameters.begin(); iter != m_parameters.end(); ++iter)
{ {
if(iter != post_parameters.begin()) if(iter != m_parameters.begin())
postString.append("&"); 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("=");
core::stringc converted = core::stringc(iter->second.c_str()); escaped = curl_easy_escape(this->curl , iter->second.c_str(), iter->second.size());
char * escaped = curl_easy_escape(this->curl , converted.c_str(), converted.size());
postString.append(escaped); postString.append(escaped);
curl_free(escaped); curl_free(escaped);
} }
@ -82,12 +82,11 @@ std::string HTTPConnector::getPage(Parameters & post_parameters)
res = curl_easy_perform(this->curl); res = curl_easy_perform(this->curl);
if(res != CURLE_OK) if(res != CURLE_OK)
{ {
Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); //FIXME Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}else{ }else{
printf("Retrieved: %s\n", readBuffer.c_str()); printf("Retrieved: %s\n", readBuffer.c_str());
} }
m_parameters.clear();
return readBuffer; return readBuffer;
} }

View File

@ -23,7 +23,7 @@
#include "io/xml_node.hpp" #include "io/xml_node.hpp"
#include <curl/curl.h> #include <curl/curl.h>
#include <irrString.h> #include <irrString.h>
using namespace irr; #include "utils/string_utils.hpp"
/** /**
* \brief Class to connect with a server over HTTP * \brief Class to connect with a server over HTTP
@ -34,13 +34,33 @@ class HTTPConnector
protected: protected:
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
typedef std::map<std::string, std::string> Parameters;
Parameters m_parameters;
public: public:
typedef std::map<std::string, core::stringw> Parameters;
HTTPConnector(const std::string &url); HTTPConnector(const std::string &url);
~HTTPConnector(); ~HTTPConnector();
std::string getPage(Parameters & post_parameters);
XMLNode * getXMLFromPage(Parameters & post_parameters); //Execute
std::string getPage();
XMLNode * getXMLFromPage();
//Setting parameters to be send with the next request
void setParameter(const std::string & name, const std::string &value){
printf("template3");
m_parameters[name] = value;
};
void setParameter(const std::string & name, const irr::core::stringw &value){
printf("template2");
m_parameters[name] = irr::core::stringc(value.c_str()).c_str();
}
template <typename T>
void setParameter(const std::string & name, const T& value){
printf("template1");
m_parameters[name] = StringUtils::toString(value);
}
}; //class HTTPConnector }; //class HTTPConnector

View File

@ -26,6 +26,6 @@
// ============================================================================ // ============================================================================
OnlineUser::OnlineUser(const irr::core::stringw &username) OnlineUser::OnlineUser(const irr::core::stringw &username)
{ {
m_username = username; m_name = username;
} // OnlineUser } // OnlineUser

View File

@ -20,6 +20,7 @@
#define HEADER_ONLINE_USER_HPP #define HEADER_ONLINE_USER_HPP
#include <irrString.h> #include <irrString.h>
#include "utils/types.hpp"
// ============================================================================ // ============================================================================
@ -33,7 +34,9 @@ class OnlineUser
protected: protected:
irr::core::stringw m_username; irr::core::stringw m_name;
uint32_t m_id;
OnlineUser(){}
public: public:
@ -43,7 +46,9 @@ class OnlineUser
OnlineUser(const irr::core::stringw &username); OnlineUser(const irr::core::stringw &username);
/** Returns the username. */ /** Returns the username. */
irr::core::stringw getUserName() const { return m_username; } irr::core::stringw getUserName() const { return m_name; }
uint32_t getUserID() const { return m_id; }
}; // class OnlineUser }; // class OnlineUser

View File

@ -72,23 +72,19 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
else if(eventSource == "signin") else if(eventSource == "signin")
{ {
// ---- See if we can accept the input // ---- See if we can accept the input
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("username"); const stringw username = getWidget<TextBoxWidget>("username")->getText().trim();
const stringw username = textCtrl->getText().trim(); const stringw password = getWidget<TextBoxWidget>("password")->getText().trim();
textCtrl = getWidget<TextBoxWidget>("password"); stringw info = "";
const stringw password = textCtrl->getText().trim(); if(CurrentOnlineUser::get()->signIn(username,password,info))
stringw msg = "";
if(CurrentOnlineUser::get()->signUp(username,password,msg))
{ {
//m_self_destroy = true; m_self_destroy = true;
m_self_destroy = false;
} }
else else
{ {
sfx_manager->quickSound( "anvil" ); sfx_manager->quickSound( "anvil" );
m_self_destroy = false; m_self_destroy = false;
} }
getWidget<LabelWidget>("errormsg")->setText(msg, false); getWidget<LabelWidget>("info")->setText(info, false);
return GUIEngine::EVENT_BLOCK; return GUIEngine::EVENT_BLOCK;
} }
return GUIEngine::EVENT_LET; return GUIEngine::EVENT_LET;
@ -118,16 +114,7 @@ void LoginDialog::onUpdate(float dt)
// It's unsafe to delete from inside the event handler so we do it here // It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy) if (m_self_destroy)
{ {
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("username");
stringw playerName = textCtrl->getText().trim();
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window ); GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss(); ModalDialog::dismiss();
} }
} }

View File

@ -119,7 +119,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
if (selection == "login") if (selection == "login")
{ {
new LoginDialog(0.5f, 0.4f); new LoginDialog(0.8f, 0.7f);
} }
} // eventCallback } // eventCallback

31
src/utils/types.hpp Normal file
View File

@ -0,0 +1,31 @@
//
// 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_TYPES_HPP
#define HEADER_TYPES_HPP
#ifdef _MSC_VER
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
# include <stdint.h>
#endif
#endif