[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:
parent
83ff1cbe79
commit
075b3aa3c7
@ -1,11 +1,12 @@
|
||||
<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" >
|
||||
|
||||
<icon id="logo" align="center" proportion="5" width="100%" icon="gui/logo.png"/>
|
||||
|
||||
<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"
|
||||
I18N="Online menu button" text="Sign in"/>
|
||||
</buttonbar>
|
||||
@ -14,16 +15,13 @@
|
||||
|
||||
<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"
|
||||
I18N="In the main screen"
|
||||
text=""
|
||||
align="center" text_align="left" />
|
||||
|
||||
<spacer width="10" height="10" />
|
||||
|
||||
<buttonbar id="menu_bottomrow" x="0" y="0" width="30%" height="100%" align="center">
|
||||
<buttonbar id="menu_bottomrow" x="0" y="0" width="20%" height="100%" align="center">
|
||||
<icon-button id="signin" width="64" height="64" icon="gui/main_options.png" extend_label="50"
|
||||
I18N="Main menu button" text="Log In" label_location="hover"/>
|
||||
<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"/>
|
||||
</buttonbar>
|
||||
|
||||
</bottombar>
|
@ -58,56 +58,60 @@ bool CurrentOnlineUser::signUp( const irr::core::stringw &username,
|
||||
const irr::core::stringw &password_ver,
|
||||
const irr::core::stringw &email,
|
||||
bool terms,
|
||||
irr::core::stringw &msg){
|
||||
irr::core::stringw &info)
|
||||
{
|
||||
assert(m_is_signed_in == false);
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
connector->setParameter("action",std::string("register"));
|
||||
connector->setParameter("user",username);
|
||||
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))
|
||||
{
|
||||
if(rec_success == "yes")
|
||||
{
|
||||
msg = "Registered!";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "Registering went wrong!";
|
||||
}
|
||||
success = (rec_success == "yes");
|
||||
assert(result->get("info", &info));
|
||||
}
|
||||
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);
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
connector->setParameter("action",std::string("connect"));
|
||||
connector->setParameter("user",username);
|
||||
connector->setParameter("username",username);
|
||||
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();
|
||||
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));
|
||||
assert(result->get("username", &m_name));
|
||||
assert(result->get("userid", &m_id));
|
||||
m_is_signed_in = true;
|
||||
if (rec_success =="yes")
|
||||
{
|
||||
assert(result->get("token", &m_token));
|
||||
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;
|
||||
}
|
||||
// ============================================================================
|
||||
@ -120,15 +124,17 @@ bool CurrentOnlineUser::signOut(){
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
std::string rec_success = "";
|
||||
if(result->get("success", &rec_success) && rec_success =="yes")
|
||||
if(result->get("success", &rec_success))
|
||||
{
|
||||
m_token = "";
|
||||
m_name = "";
|
||||
m_id = 0;
|
||||
m_is_signed_in = false;
|
||||
if (rec_success =="yes")
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -53,7 +53,7 @@ class CurrentOnlineUser : public OnlineUser
|
||||
const irr::core::stringw &password_ver,
|
||||
const irr::core::stringw &email,
|
||||
bool terms,
|
||||
irr::core::stringw &msg);
|
||||
irr::core::stringw &info);
|
||||
// Logout - Best to be followed by CurrentOnlineUser::deallocate
|
||||
bool signOut();
|
||||
/** Returns the username if signed in. */
|
||||
|
@ -28,11 +28,11 @@ HTTPConnector::HTTPConnector(const std::string &url){
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
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());
|
||||
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);
|
||||
curl_free(escaped);
|
||||
}
|
||||
printf("Sending: %s\n", postString.c_str());
|
||||
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str());
|
||||
std::string readBuffer;
|
||||
curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer);
|
||||
res = curl_easy_perform(this->curl);
|
||||
if(res != CURLE_OK)
|
||||
{
|
||||
//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));
|
||||
}else{
|
||||
printf("Retrieved: %s\n", readBuffer.c_str());
|
||||
}
|
||||
Log::error("online/http_functions", "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||
else
|
||||
Log::info("online/http_functions", "Received : %s", readBuffer.c_str());
|
||||
m_parameters.clear();
|
||||
return readBuffer;
|
||||
}
|
||||
|
@ -184,7 +184,15 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
|
||||
{
|
||||
assert(getWidget<CheckBoxWidget>("accepted")->getState());
|
||||
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;
|
||||
}
|
||||
else if (eventSource == "accepted")
|
||||
|
@ -46,7 +46,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
OnlineScreen::OnlineScreen() : Screen("online/online.stkgui")
|
||||
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
|
||||
{
|
||||
} // OnlineScreen
|
||||
|
||||
@ -95,22 +95,26 @@ void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
void OnlineScreen::eventCallback(Widget* widget, const std::string& name, 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);
|
||||
|
||||
if (ribbon == NULL) return; // what's that event??
|
||||
std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
// ---- A ribbon icon was clicked
|
||||
std::string selection =
|
||||
ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
if (selection == "login")
|
||||
if (selection == "signin")
|
||||
{
|
||||
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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user