mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 19:04:00 +02:00
- Added libcurl to mega-glest for mu;ti-purpose / multi-platform http and ftp requests
(for linux requires the following new dependency: sudo apt-get install libcurl4-dev)
This commit is contained in:
@@ -20,7 +20,7 @@ for i in $(LIB_STREFLOP_DIRS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Library strefloplib : $(LIB_STREFLOP_SOURCES) ;
|
Library strefloplib : $(LIB_STREFLOP_SOURCES) ;
|
||||||
ExternalLibs strefloplib : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG ;
|
ExternalLibs strefloplib : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG CURL ;
|
||||||
IncludeDir strefloplib : $(LIB_STREFLOP_INCLUDE_DIRS) ;
|
IncludeDir strefloplib : $(LIB_STREFLOP_INCLUDE_DIRS) ;
|
||||||
|
|
||||||
#### Library ####
|
#### Library ####
|
||||||
@@ -50,7 +50,7 @@ for i in $(LIB_DIRS) {
|
|||||||
|
|
||||||
Library glestlib : $(LIB_SOURCES) ;
|
Library glestlib : $(LIB_SOURCES) ;
|
||||||
LinkWith glestlib : strefloplib ;
|
LinkWith glestlib : strefloplib ;
|
||||||
ExternalLibs glestlib : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG ;
|
ExternalLibs glestlib : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG CURL ;
|
||||||
IncludeDir glestlib : $(LIB_INCLUDE_DIRS) ;
|
IncludeDir glestlib : $(LIB_INCLUDE_DIRS) ;
|
||||||
|
|
||||||
#### Game ####
|
#### Game ####
|
||||||
@@ -79,7 +79,7 @@ for i in $(GLEST_DIRS) {
|
|||||||
|
|
||||||
Application glest.bin : $(GLEST_SOURCES) ;
|
Application glest.bin : $(GLEST_SOURCES) ;
|
||||||
LinkWith glest.bin : glestlib strefloplib ;
|
LinkWith glest.bin : glestlib strefloplib ;
|
||||||
ExternalLibs glest.bin : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG ;
|
ExternalLibs glest.bin : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG CURL ;
|
||||||
IncludeDir glest.bin : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_DIRS) ;
|
IncludeDir glest.bin : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_DIRS) ;
|
||||||
|
|
||||||
#### Editor ####
|
#### Editor ####
|
||||||
@@ -93,7 +93,7 @@ if $(WX_AVAILABLE) = "yes" {
|
|||||||
|
|
||||||
Application glest_editor : $(GLEST_MAP_SOURCES) ;
|
Application glest_editor : $(GLEST_MAP_SOURCES) ;
|
||||||
LinkWith glest_editor : glestlib strefloplib ;
|
LinkWith glest_editor : glestlib strefloplib ;
|
||||||
ExternalLibs glest_editor : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL WX ;
|
ExternalLibs glest_editor : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL WX CURL ;
|
||||||
IncludeDir glest_editor : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_MAP_DIRS) ;
|
IncludeDir glest_editor : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_MAP_DIRS) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ if $(WX_AVAILABLE) = "yes" {
|
|||||||
|
|
||||||
Application glest_g3dviewer : $(GLEST_VIEWER_SOURCES) ;
|
Application glest_g3dviewer : $(GLEST_VIEWER_SOURCES) ;
|
||||||
LinkWith glest_g3dviewer : glestlib strefloplib ;
|
LinkWith glest_g3dviewer : glestlib strefloplib ;
|
||||||
ExternalLibs glest_g3dviewer : SDL GL GLU WX ;
|
ExternalLibs glest_g3dviewer : SDL GL GLU WX CURL ;
|
||||||
IncludeDir glest_g3dviewer : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_VIEWER_DIRS) ;
|
IncludeDir glest_g3dviewer : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_VIEWER_DIRS) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +122,6 @@ if $(WX_AVAILABLE) = "yes" {
|
|||||||
|
|
||||||
Application glest_configurator : $(GLEST_CONFIG_SOURCES) ;
|
Application glest_configurator : $(GLEST_CONFIG_SOURCES) ;
|
||||||
LinkWith glest_configurator : glestlib strefloplib ;
|
LinkWith glest_configurator : glestlib strefloplib ;
|
||||||
ExternalLibs glest_configurator : SDL GL GLU XERCES WX ;
|
ExternalLibs glest_configurator : SDL GL GLU XERCES WX CURL ;
|
||||||
IncludeDir glest_configurator : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_CONFIG_DIRS) ;
|
IncludeDir glest_configurator : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_CONFIG_DIRS) ;
|
||||||
|
|
||||||
|
@@ -130,6 +130,14 @@ NP_FINDLIB([PNG], [LibPng], [LibPNG],
|
|||||||
[AC_MSG_ERROR([Please intall libpng])],
|
[AC_MSG_ERROR([Please intall libpng])],
|
||||||
[], [])
|
[], [])
|
||||||
|
|
||||||
|
NP_FINDLIB([CURL], [LibCurl], [LibCurl],
|
||||||
|
NP_LANG_PROGRAM([#include <curl/curl.h>],
|
||||||
|
[curl_easy_init();]),
|
||||||
|
[], [-lcurl],
|
||||||
|
[],
|
||||||
|
[AC_MSG_ERROR([Please intall libcurl])],
|
||||||
|
[], [])
|
||||||
|
|
||||||
CHECK_LUA([], [AC_MSG_ERROR([Please install lua 5.1])])
|
CHECK_LUA([], [AC_MSG_ERROR([Please install lua 5.1])])
|
||||||
|
|
||||||
AX_CHECK_GL
|
AX_CHECK_GL
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "simple_threads.h"
|
#include "simple_threads.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "auto_test.h"
|
#include "auto_test.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "masterserver_info.h"
|
#include "masterserver_info.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
@@ -224,6 +225,41 @@ void MenuStateMasterserver::update(){
|
|||||||
void MenuStateMasterserver::updateServerInfo() {
|
void MenuStateMasterserver::updateServerInfo() {
|
||||||
//MasterServerInfos masterServerInfos;
|
//MasterServerInfos masterServerInfos;
|
||||||
clearServerLines();
|
clearServerLines();
|
||||||
|
|
||||||
|
std::string serverInfo = SystemFlags::getHTTP("http://soft-haus.com/glest/cgi-bin/mega-glest-master-query.php");
|
||||||
|
|
||||||
|
std::vector<std::string> serverList;
|
||||||
|
Tokenize(serverInfo,serverList,"\n");
|
||||||
|
for(int i=0; i < serverList.size(); i++) {
|
||||||
|
string &server = serverList[i];
|
||||||
|
std::vector<std::string> serverEntities;
|
||||||
|
Tokenize(server,serverEntities,"|");
|
||||||
|
|
||||||
|
const int MIN_FIELDS_EXPECTED = 11;
|
||||||
|
if(serverEntities.size() >= MIN_FIELDS_EXPECTED) {
|
||||||
|
MasterServerInfo *masterServerInfo=new MasterServerInfo();
|
||||||
|
|
||||||
|
//general info:
|
||||||
|
masterServerInfo->setGlestVersion(serverEntities[0]);
|
||||||
|
masterServerInfo->setPlatform(serverEntities[1]);
|
||||||
|
masterServerInfo->setBinaryCompileDate(serverEntities[2]);
|
||||||
|
|
||||||
|
//game info:
|
||||||
|
masterServerInfo->setServerTitle(serverEntities[3]);
|
||||||
|
masterServerInfo->setIpAddress(serverEntities[4]);
|
||||||
|
|
||||||
|
//game setup info:
|
||||||
|
masterServerInfo->setTech(serverEntities[5]);
|
||||||
|
masterServerInfo->setMap(serverEntities[6]);
|
||||||
|
masterServerInfo->setTileset(serverEntities[7]);
|
||||||
|
masterServerInfo->setActiveSlots(strToInt(serverEntities[8]));
|
||||||
|
masterServerInfo->setNetworkSlots(strToInt(serverEntities[9]));
|
||||||
|
masterServerInfo->setConnectedClients(strToInt(serverEntities[10]));
|
||||||
|
|
||||||
|
serverLines.push_back(new ServerLine( masterServerInfo, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
for(int i=0; i<10;i++){
|
for(int i=0; i<10;i++){
|
||||||
MasterServerInfo *masterServerInfo=new MasterServerInfo();
|
MasterServerInfo *masterServerInfo=new MasterServerInfo();
|
||||||
|
|
||||||
@@ -248,6 +284,7 @@ void MenuStateMasterserver::updateServerInfo(){
|
|||||||
|
|
||||||
serverLines.push_back(new ServerLine( masterServerInfo, i));
|
serverLines.push_back(new ServerLine( masterServerInfo, i));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//masterServerInfos.push_back(masterServerInfo);
|
//masterServerInfos.push_back(masterServerInfo);
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace Shared::Platform;
|
using namespace Shared::Platform;
|
||||||
@@ -28,6 +29,11 @@ class SystemFlags
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
struct httpMemoryStruct {
|
||||||
|
char *memory;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
enum DebugType {
|
enum DebugType {
|
||||||
debugSystem,
|
debugSystem,
|
||||||
debugNetwork,
|
debugNetwork,
|
||||||
@@ -100,11 +106,15 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static CURL *curl_handle;
|
||||||
|
|
||||||
SystemFlags();
|
SystemFlags();
|
||||||
~SystemFlags();
|
~SystemFlags();
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; }
|
static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; }
|
||||||
|
static size_t httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);
|
||||||
|
static std::string getHTTP(std::string URL);
|
||||||
|
|
||||||
// Let the macro call into this when require.. NEVER call it automatically.
|
// Let the macro call into this when require.. NEVER call it automatically.
|
||||||
static void handleDebug(DebugType type, const char *fmt, ...);
|
static void handleDebug(DebugType type, const char *fmt, ...);
|
||||||
|
@@ -37,7 +37,63 @@ using namespace Shared::PlatformCommon;
|
|||||||
|
|
||||||
namespace Shared{ namespace Util{
|
namespace Shared{ namespace Util{
|
||||||
|
|
||||||
|
// Init statics
|
||||||
std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType> SystemFlags::debugLogFileList;
|
std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType> SystemFlags::debugLogFileList;
|
||||||
|
int SystemFlags::lockFile = -1;
|
||||||
|
string SystemFlags::lockfilename = "";
|
||||||
|
CURL *SystemFlags::curl_handle = NULL;
|
||||||
|
//
|
||||||
|
|
||||||
|
static void *myrealloc(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
/* There might be a realloc() out there that doesn't like reallocing
|
||||||
|
NULL pointers, so we take care of it here */
|
||||||
|
if(ptr)
|
||||||
|
return realloc(ptr, size);
|
||||||
|
else
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SystemFlags::httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||||
|
{
|
||||||
|
size_t realsize = size * nmemb;
|
||||||
|
struct httpMemoryStruct *mem = (struct httpMemoryStruct *)data;
|
||||||
|
|
||||||
|
mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
|
||||||
|
if (mem->memory) {
|
||||||
|
memcpy(&(mem->memory[mem->size]), ptr, realsize);
|
||||||
|
mem->size += realsize;
|
||||||
|
mem->memory[mem->size] = 0;
|
||||||
|
}
|
||||||
|
return realsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SystemFlags::getHTTP(std::string URL) {
|
||||||
|
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_URL, URL.c_str());
|
||||||
|
|
||||||
|
/* send all data to this function */
|
||||||
|
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_WRITEFUNCTION, SystemFlags::httpWriteMemoryCallback);
|
||||||
|
|
||||||
|
struct SystemFlags::httpMemoryStruct chunk;
|
||||||
|
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
|
||||||
|
chunk.size = 0; /* no data at this point */
|
||||||
|
|
||||||
|
/* we pass our 'chunk' struct to the callback function */
|
||||||
|
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
|
||||||
|
|
||||||
|
/* some servers don't like requests that are made without a user-agent
|
||||||
|
field, so we provide one */
|
||||||
|
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_USERAGENT, "mega-glest-agent/1.0");
|
||||||
|
|
||||||
|
/* get contents from the URL */
|
||||||
|
curl_easy_perform(SystemFlags::curl_handle);
|
||||||
|
std::string serverResponse = chunk.memory;
|
||||||
|
if(chunk.memory) {
|
||||||
|
free(chunk.memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverResponse;
|
||||||
|
}
|
||||||
|
|
||||||
void SystemFlags::init() {
|
void SystemFlags::init() {
|
||||||
if(SystemFlags::debugLogFileList.size() == 0) {
|
if(SystemFlags::debugLogFileList.size() == 0) {
|
||||||
@@ -46,10 +102,12 @@ void SystemFlags::init() {
|
|||||||
SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
|
SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
|
||||||
SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
|
SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int SystemFlags::lockFile = -1;
|
if(curl_handle == NULL) {
|
||||||
string SystemFlags::lockfilename = "";
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
curl_handle = curl_easy_init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline bool acquire_file_lock(int hnd)
|
inline bool acquire_file_lock(int hnd)
|
||||||
{
|
{
|
||||||
@@ -71,6 +129,12 @@ SystemFlags::SystemFlags() {
|
|||||||
}
|
}
|
||||||
SystemFlags::~SystemFlags() {
|
SystemFlags::~SystemFlags() {
|
||||||
SystemFlags::Close();
|
SystemFlags::Close();
|
||||||
|
|
||||||
|
if(curl_handle != NULL) {
|
||||||
|
curl_easy_cleanup(curl_handle);
|
||||||
|
curl_handle = NULL;
|
||||||
|
curl_global_cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemFlags::Close() {
|
void SystemFlags::Close() {
|
||||||
|
Reference in New Issue
Block a user