[uni GSoC] Connection with server OK. Remark : won't work if you don't have a locally set up server, change the adress in the config accordingly and have the code of my stkaddons branch running.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@12889 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
98274f59d5
commit
be11ce1cd0
@ -1,4 +1,4 @@
|
||||
# Generated by /home/gl3nn/repos/gsoc-stk-branch/update_file_list.sh. Do not edit this file manually.
|
||||
# Generated by ./update_file_list.sh. Do not edit this file manually.
|
||||
set(STK_SOURCES
|
||||
src/addons/addon.cpp
|
||||
src/addons/addons_manager.cpp
|
||||
@ -144,7 +144,7 @@ src/network/race_info_message.cpp
|
||||
src/network/race_result_message.cpp
|
||||
src/network/race_state.cpp
|
||||
src/online/current_online_user.cpp
|
||||
src/online/http_functions.cpp
|
||||
src/online/http_connector.cpp
|
||||
src/online/online_user.cpp
|
||||
src/physics/btKart.cpp
|
||||
src/physics/btKartRaycast.cpp
|
||||
@ -406,7 +406,7 @@ src/network/race_state.hpp
|
||||
src/network/remote_kart_info.hpp
|
||||
src/network/world_loaded_message.hpp
|
||||
src/online/current_online_user.hpp
|
||||
src/online/http_functions.hpp
|
||||
src/online/http_connector.hpp
|
||||
src/online/online_user.hpp
|
||||
src/physics/btKart.hpp
|
||||
src/physics/btKartRaycast.hpp
|
||||
|
@ -603,6 +603,13 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( WStringUserConfigParam(L"", "default_player",
|
||||
"Which player to use by default (if empty, will prompt)") );
|
||||
|
||||
// ---- Online multiplayer related
|
||||
|
||||
PARAM_PREFIX StringUserConfigParam m_server_multiplayer
|
||||
PARAM_DEFAULT( StringUserConfigParam("http://api.stkaddons.net/",
|
||||
"server_multiplayer",
|
||||
"The server used for online multiplayer."));
|
||||
|
||||
// ---- Addon server related entries
|
||||
PARAM_PREFIX GroupUserConfigParam m_addon_group
|
||||
PARAM_DEFAULT( GroupUserConfigParam("AddonAndNews",
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "online/http_connector.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
|
||||
static CurrentOnlineUser* user_singleton = NULL;
|
||||
|
||||
@ -47,11 +49,17 @@ CurrentOnlineUser::CurrentOnlineUser(){
|
||||
|
||||
// ============================================================================
|
||||
|
||||
bool CurrentOnlineUser::logIn(const std::string &username, const std::string &password)
|
||||
bool CurrentOnlineUser::signIn(const std::string &username, const std::string &password)
|
||||
{
|
||||
assert(m_is_signed_in == false);
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
HTTPConnector::Parameters parameters;
|
||||
parameters["action"] = "signin";
|
||||
parameters["user"] = username;
|
||||
std::string result = connector->getPage(parameters);
|
||||
printf("Result: %s\n", result.c_str());
|
||||
//Sign in
|
||||
if(/*succes*/true)
|
||||
if(/*succes*/false)
|
||||
{
|
||||
m_user = new OnlineUser(username);
|
||||
m_is_signed_in = true;
|
||||
|
@ -32,21 +32,21 @@
|
||||
*/
|
||||
class CurrentOnlineUser
|
||||
{
|
||||
private:
|
||||
private:
|
||||
|
||||
protected:
|
||||
std::string m_token;
|
||||
bool m_is_signed_in;
|
||||
OnlineUser * m_user;
|
||||
CurrentOnlineUser();
|
||||
protected:
|
||||
std::string m_token;
|
||||
bool m_is_signed_in;
|
||||
OnlineUser * m_user;
|
||||
CurrentOnlineUser();
|
||||
|
||||
public:
|
||||
// singleton
|
||||
static CurrentOnlineUser* get();
|
||||
static void deallocate();
|
||||
bool logIn(const std::string &username, const std::string &password);
|
||||
/** Returns the username if signed in. */
|
||||
std::string getUserName() const;
|
||||
public:
|
||||
// singleton
|
||||
static CurrentOnlineUser* get();
|
||||
static void deallocate();
|
||||
bool signIn(const std::string &username, const std::string &password);
|
||||
/** Returns the username if signed in. */
|
||||
std::string getUserName() const;
|
||||
|
||||
}; // class CurrentOnlineUser
|
||||
|
||||
|
@ -16,18 +16,35 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "http_functions.hpp"
|
||||
#include "http_connector.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <curl/curl.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include "io/file_manager.hpp"
|
||||
|
||||
namespace HTTP
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
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");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
if (url.substr(0, 5)!="http:")
|
||||
{
|
||||
printf("Invalid URL");
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
|
||||
HTTPConnector::~HTTPConnector(){
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
@ -35,36 +52,34 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if(!curl)
|
||||
printf("Error while loading cURL library.\n");
|
||||
}
|
||||
|
||||
XMLNode * getXMLFromPage(std::string url)
|
||||
XMLNode * HTTPConnector::getXMLFromPage(Parameters & post_parameters)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string getPage(std::string url)
|
||||
std::string HTTPConnector::getPage(Parameters & post_parameters)
|
||||
{
|
||||
Parameters::iterator iter;
|
||||
std::string postString;
|
||||
|
||||
for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter)
|
||||
{
|
||||
if(iter != post_parameters.begin())
|
||||
postString.append("&");
|
||||
postString.append(iter->first);
|
||||
postString.append("=");
|
||||
postString.append(iter->second);
|
||||
}
|
||||
printf("Poststring: %s\n", postString.c_str());
|
||||
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str());
|
||||
std::string readBuffer;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||
res = curl_easy_perform(curl);
|
||||
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)
|
||||
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));
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
}
|
@ -16,29 +16,32 @@
|
||||
// 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_FUNCTIONS_HPP
|
||||
#define HTTP_FUNCTIONS_HPP
|
||||
#ifndef HTTP_CONNECTOR_HPP
|
||||
#define HTTP_CONNECTOR_HPP
|
||||
|
||||
#include <string>
|
||||
#include "io/xml_node.hpp"
|
||||
#include <curl/curl.h>
|
||||
|
||||
/**
|
||||
* \brief HTTP functions to connect with the server
|
||||
* \brief Class to connect with a server over HTTP
|
||||
* \ingroup online
|
||||
*/
|
||||
|
||||
namespace HTTP
|
||||
class HTTPConnector
|
||||
{
|
||||
protected:
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
|
||||
std::string getPage(std::string url);
|
||||
XMLNode * getXMLFromPage(std::string url);
|
||||
public:
|
||||
typedef std::map <std::string, std::string> Parameters;
|
||||
HTTPConnector(const std::string &url);
|
||||
~HTTPConnector();
|
||||
std::string getPage(Parameters & post_parameters);
|
||||
XMLNode * getXMLFromPage(Parameters & post_parameters);
|
||||
}; //class HTTPConnector
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // HTTP_FUNCTIONS_HPP
|
||||
#endif // HTTP_CONNECTOR_HPP
|
||||
|
||||
/*EOF*/
|
@ -30,21 +30,21 @@
|
||||
*/
|
||||
class OnlineUser
|
||||
{
|
||||
private:
|
||||
private:
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
std::string m_username;
|
||||
std::string m_username;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
OnlineUser(const std::string &username);
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
OnlineUser(const std::string &username);
|
||||
|
||||
/** Returns the username. */
|
||||
std::string getUserName() const { return m_username; }
|
||||
/** Returns the username. */
|
||||
std::string getUserName() const { return m_username; }
|
||||
|
||||
}; // class OnlineUser
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "online/current_online_user.hpp"
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr;
|
||||
@ -94,16 +95,24 @@ void LoginDialog::onEnterPressedInternal()
|
||||
nonEmptyChars++;
|
||||
}
|
||||
}
|
||||
|
||||
std::string msg;
|
||||
if (size > 0 && nonEmptyChars > 0)
|
||||
{
|
||||
Log::info("Login Dialog","Username : %ls", username.c_str());
|
||||
m_self_destroy = true;
|
||||
if(CurrentOnlineUser::get()->signIn(core::stringc(username.c_str()).c_str(), ""))
|
||||
{
|
||||
m_self_destroy = true;
|
||||
}else{
|
||||
msg = "Signing in failed.";
|
||||
m_self_destroy = false;
|
||||
}
|
||||
|
||||
} // if valid name
|
||||
else
|
||||
msg = "Invalid username.";
|
||||
{
|
||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
||||
label->setText(_("Not a valid username"), false);
|
||||
label->setText(_(msg.c_str()), false);
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user