[GSoC Uni_] Enhanced online_screen. Let 'Sign In' and 'Register' connect to the server. Renaming GUI file. Added debug code to connector.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@12991 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-06-27 01:38:16 +00:00
parent 83ff1cbe79
commit 075b3aa3c7
6 changed files with 74 additions and 62 deletions

View File

@ -1,11 +1,12 @@
<stkgui> <stkgui>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
<div x="0" y="0" width="100%" height="100%" layout="vertical-row" > <div x="0" y="0" width="100%" height="100%" layout="vertical-row" >
<icon id="logo" align="center" proportion="5" width="100%" icon="gui/logo.png"/> <icon id="logo" align="center" proportion="5" width="100%" icon="gui/logo.png"/>
<buttonbar id="menu_toprow" proportion="3" width="75%" align="center"> <buttonbar id="menu_toprow" proportion="3" width="75%" align="center">
<icon-button id="login" width="128" height="128" <icon-button id="signin" width="128" height="128"
icon="gui/menu_race.png" focus_icon="gui/menu_race_focus.png" icon="gui/menu_race.png" focus_icon="gui/menu_race_focus.png"
I18N="Online menu button" text="Sign in"/> I18N="Online menu button" text="Sign in"/>
</buttonbar> </buttonbar>
@ -14,16 +15,13 @@
<bottombar width="100%" height="10%" layout="horizontal-row"> <bottombar width="100%" height="10%" layout="horizontal-row">
<spacer width="10" height="10" /> <spacer proportion="3" height="10" />
<label proportion="3" height="100%" id="info_addons" <buttonbar id="menu_bottomrow" x="0" y="0" width="20%" height="100%" align="center">
I18N="In the main screen" <icon-button id="signin" width="64" height="64" icon="gui/main_options.png" extend_label="50"
text="" I18N="Main menu button" text="Log In" label_location="hover"/>
align="center" text_align="left" /> <icon-button id="signout" width="64" height="64" icon="gui/main_quit.png" extend_label="50"
I18N="Main menu button" text="Log Out" label_location="hover"/>
<spacer width="10" height="10" />
<buttonbar id="menu_bottomrow" x="0" y="0" width="30%" height="100%" align="center">
</buttonbar> </buttonbar>
</bottombar> </bottombar>

View File

@ -58,56 +58,60 @@ bool CurrentOnlineUser::signUp( const irr::core::stringw &username,
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 &msg){ 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");
connector->setParameter("action",std::string("register")); connector->setParameter("action",std::string("register"));
connector->setParameter("user",username); connector->setParameter("username",username);
connector->setParameter("password",password); connector->setParameter("password",password);
const XMLNode * result = connector->getXMLFromPage(); const XMLNode * result = connector->getXMLFromPage();
std::string rec_success; std::string rec_success;
bool success = false;
if(result->get("success", &rec_success)) if(result->get("success", &rec_success))
{ {
if(rec_success == "yes") success = (rec_success == "yes");
{ assert(result->get("info", &info));
msg = "Registered!";
return true;
}
else
{
msg = "Registering went wrong!";
}
} }
else else
{ {
msg = "Registering went wrong!2"; info = _("Server error");
} }
return false; return success;
} }
// ============================================================================ // ============================================================================
bool CurrentOnlineUser::signIn(const irr::core::stringw &username, const irr::core::stringw &password, irr::core::stringw &info) 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");
connector->setParameter("action",std::string("connect")); connector->setParameter("action",std::string("connect"));
connector->setParameter("user",username); connector->setParameter("username",username);
connector->setParameter("password",password); connector->setParameter("password",password);
info = "Temporary error so that testers do not have to connect to the server.";
return false; //FIXME
const XMLNode * result = connector->getXMLFromPage(); const XMLNode * result = connector->getXMLFromPage();
std::string rec_success = ""; std::string rec_success = "";
if(result->get("success", &rec_success) && rec_success =="yes") if(result->get("success", &rec_success))
{ {
assert(result->get("token", &m_token)); if (rec_success =="yes")
assert(result->get("username", &m_name)); {
assert(result->get("userid", &m_id)); assert(result->get("token", &m_token));
m_is_signed_in = true; assert(result->get("username", &m_name));
assert(result->get("userid", &m_id));
m_is_signed_in = true;
}
result->get("info", &info);
} }
result->get("info", &info); else
{
info = _("Server error");
}
return m_is_signed_in; return m_is_signed_in;
} }
// ============================================================================ // ============================================================================
@ -120,15 +124,17 @@ bool CurrentOnlineUser::signOut(){
const XMLNode * result = connector->getXMLFromPage(); const XMLNode * result = connector->getXMLFromPage();
std::string rec_success = ""; std::string rec_success = "";
if(result->get("success", &rec_success) && rec_success =="yes") if(result->get("success", &rec_success))
{ {
m_token = ""; if (rec_success =="yes")
m_name = ""; {
m_id = 0; m_token = "";
m_is_signed_in = false; m_name = "";
m_id = 0;
m_is_signed_in = false;
}
} }
//result->get("info", &info); return !m_is_signed_in;
return m_is_signed_in;
} }
// ============================================================================ // ============================================================================

View File

@ -53,7 +53,7 @@ class CurrentOnlineUser : public OnlineUser
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 &msg); irr::core::stringw &info);
// Logout - Best to be followed by CurrentOnlineUser::deallocate // Logout - Best to be followed by CurrentOnlineUser::deallocate
bool signOut(); bool signOut();
/** Returns the username if signed in. */ /** Returns the username if signed in. */

View File

@ -28,11 +28,11 @@ HTTPConnector::HTTPConnector(const std::string &url){
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init(); curl = curl_easy_init();
if(!curl) if(!curl)
printf("Error while loading cURL library.\n"); Log::error("online/http_functions", "Error while loading cURL library.");
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
if (url.substr(0, 5)!="http:") if (url.substr(0, 5)!="http:")
{ {
printf("Invalid URL"); Log::error("online/http_functions", "Invalid URL.");
} }
} }
@ -74,19 +74,15 @@ std::string HTTPConnector::getPage()
postString.append(escaped); postString.append(escaped);
curl_free(escaped); curl_free(escaped);
} }
printf("Sending: %s\n", postString.c_str());
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str()); curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str());
std::string readBuffer; std::string readBuffer;
curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer); curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer);
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", curl_easy_strerror(res));
//FIXME Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); else
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); Log::info("online/http_functions", "Received : %s", readBuffer.c_str());
}else{
printf("Retrieved: %s\n", readBuffer.c_str());
}
m_parameters.clear(); m_parameters.clear();
return readBuffer; return readBuffer;
} }

View File

@ -184,7 +184,15 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
{ {
assert(getWidget<CheckBoxWidget>("accepted")->getState()); assert(getWidget<CheckBoxWidget>("accepted")->getState());
m_agreement = true; m_agreement = true;
m_show_registration_activation = true; irr::core::stringw info;
if(CurrentOnlineUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, info))
{
m_show_registration_activation = true;
}
else
{
Log::error("Registration dialog", "Info : %s", irr::core::stringc(info.c_str()).c_str());
}
return true; return true;
} }
else if (eventSource == "accepted") else if (eventSource == "accepted")

View File

@ -46,7 +46,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
OnlineScreen::OnlineScreen() : Screen("online/online.stkgui") OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
{ {
} // OnlineScreen } // OnlineScreen
@ -95,22 +95,26 @@ void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void OnlineScreen::eventCallback(Widget* widget, const std::string& name, void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const int playerID)
const int playerID)
{ {
// most interesting stuff is in the ribbons, so start there if (name == "back")
{
StateManager::get()->escapePressed();
}
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget); RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return; // what's that event?? if (ribbon == NULL) return; // what's that event??
std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
// ---- A ribbon icon was clicked if (selection == "signin")
std::string selection =
ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == "login")
{ {
new LoginDialog(0.6f, 0.6f, _("Not yet an account? Press register beneath!")); new LoginDialog(0.6f, 0.6f, _("Not yet an account? Press register beneath!"));
} }
else if (selection == "signout")
{
new LoginDialog(0.6f, 0.6f, _("Not yet an account? Press register beneath!"));
}
} // eventCallback } // eventCallback
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------