Start a class for the network; use sample functions is getting dirty.
Starting to implement the 'redirection' system (e.g. if we want to change the server git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5665 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
5efcf2fd90
commit
ad6785a2b2
@ -38,6 +38,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
|
|
||||||
|
#include "karts/kart_properties_manager.hpp"
|
||||||
|
|
||||||
using namespace irr; /* irrXML which is used to read (not write) xml file,
|
using namespace irr; /* irrXML which is used to read (not write) xml file,
|
||||||
is located in the namespace irr::io.*/
|
is located in the namespace irr::io.*/
|
||||||
using namespace io;
|
using namespace io;
|
||||||
@ -370,6 +372,8 @@ void Addons::SaveInstalled()
|
|||||||
}
|
}
|
||||||
xml_installed << "</addons>" << std::endl;
|
xml_installed << "</addons>" << std::endl;
|
||||||
xml_installed.close();
|
xml_installed.close();
|
||||||
|
kart_properties_manager->unloadAllKarts();
|
||||||
|
kart_properties_manager->loadAllKarts();
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void Addons::UnInstall()
|
void Addons::UnInstall()
|
||||||
|
@ -26,6 +26,67 @@
|
|||||||
|
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
|
|
||||||
|
NetworkHttp * network_http = 0;
|
||||||
|
NetworkHttp::NetworkHttp()
|
||||||
|
{
|
||||||
|
pthread_t thread;
|
||||||
|
pthread_create(&thread, NULL, &NetworkHttp::checkNewServer, this);
|
||||||
|
}
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void * NetworkHttp::checkNewServer(void * obj)
|
||||||
|
{
|
||||||
|
NetworkHttp * pthis = (NetworkHttp *)obj;
|
||||||
|
std::string newserver = pthis->downloadToStr("redirect");
|
||||||
|
std::cout << newserver << std::endl;
|
||||||
|
if(newserver != "")
|
||||||
|
{
|
||||||
|
std::cout << "new server !" << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "no new server :(" << std::endl;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
size_t NetworkHttp::writeStr(char ptr [], size_t size, size_t nb_char, std::string * stream)
|
||||||
|
{
|
||||||
|
static std::string str = std::string(ptr);
|
||||||
|
*stream = str;
|
||||||
|
//std::cout << *stream << std::endl;
|
||||||
|
return nb_char;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NetworkHttp::downloadToStr(std::string url)
|
||||||
|
{
|
||||||
|
for(int i =0; i < 10; i++) std::cout << "stream---------------------------------------" << std::endl;
|
||||||
|
CURL *session = curl_easy_init();
|
||||||
|
|
||||||
|
curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + url).c_str());
|
||||||
|
|
||||||
|
std::string * fout = new std::string("");
|
||||||
|
|
||||||
|
|
||||||
|
//from and out
|
||||||
|
curl_easy_setopt(session, CURLOPT_WRITEDATA, fout);
|
||||||
|
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, &NetworkHttp::writeStr);
|
||||||
|
|
||||||
|
int succes = curl_easy_perform(session);
|
||||||
|
|
||||||
|
//stop curl
|
||||||
|
curl_easy_cleanup(session);
|
||||||
|
|
||||||
|
if(succes == 0)
|
||||||
|
{
|
||||||
|
std::cout << "Download successfull" << std::endl;
|
||||||
|
return *fout;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Download failed... check your network connexion" << std::endl;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
bool download(std::string file, std::string save, int * progress_data)
|
bool download(std::string file, std::string save, int * progress_data)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,20 @@
|
|||||||
#ifndef HEADER_NETWORK_HPP
|
#ifndef HEADER_NETWORK_HPP
|
||||||
#define HEADER_NETWORK_HPP
|
#define HEADER_NETWORK_HPP
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <string>
|
||||||
|
class NetworkHttp
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
public:
|
||||||
|
NetworkHttp();
|
||||||
|
static void * checkNewServer(void * obj);
|
||||||
|
static size_t writeStr(char str [], size_t size, size_t nb_char, std::string * stream);
|
||||||
|
std::string downloadToStr(std::string url);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern NetworkHttp * network_http;
|
||||||
/* * Download a file. The file name isn't absolute, the server in the config will be added to file.
|
/* * Download a file. The file name isn't absolute, the server in the config will be added to file.
|
||||||
* progress_data is used to have the state of the download (in %)*/
|
* progress_data is used to have the state of the download (in %)*/
|
||||||
bool download(std::string file, std::string save = "", int * progress_data = 0);
|
bool download(std::string file, std::string save = "", int * progress_data = 0);
|
||||||
|
@ -69,6 +69,9 @@
|
|||||||
#include "tracks/track_manager.hpp"
|
#include "tracks/track_manager.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
|
|
||||||
|
#ifdef ADDONS_MANAGER
|
||||||
|
#include "addons/network.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
void cmdLineHelp (char* invocation)
|
void cmdLineHelp (char* invocation)
|
||||||
{
|
{
|
||||||
@ -530,6 +533,9 @@ void initRest()
|
|||||||
highscore_manager = new HighscoreManager ();
|
highscore_manager = new HighscoreManager ();
|
||||||
grand_prix_manager = new GrandPrixManager ();
|
grand_prix_manager = new GrandPrixManager ();
|
||||||
network_manager = new NetworkManager ();
|
network_manager = new NetworkManager ();
|
||||||
|
#ifdef ADDONS_MANAGER
|
||||||
|
network_http = new NetworkHttp ();
|
||||||
|
#endif
|
||||||
|
|
||||||
stk_config->load(file_manager->getConfigFile("stk_config.xml"));
|
stk_config->load(file_manager->getConfigFile("stk_config.xml"));
|
||||||
track_manager->loadTrackList();
|
track_manager->loadTrackList();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user