From effdee5716b46e61df34af53fe60792027b37633 Mon Sep 17 00:00:00 2001 From: madbad Date: Sun, 12 Apr 2020 15:09:35 +0000 Subject: [PATCH] webserver: fix/workaround for ticket 1048. * enable the actual reading of the webserver config file previously hardoced * update the config file with an actual usable url * change the place where we do the reading of the config file git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6913 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 30dbb76b794899c5af9cdb9c40bdbd72b785ca6e Former-commit-id: 3c7563159a05a4f503de38ff70ec7e490d0ea2d6 --- src/libs/tgfclient/webserver.cpp | 71 +++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/src/libs/tgfclient/webserver.cpp b/src/libs/tgfclient/webserver.cpp index 346d9ce85..696f3bf04 100644 --- a/src/libs/tgfclient/webserver.cpp +++ b/src/libs/tgfclient/webserver.cpp @@ -387,6 +387,11 @@ WebServer::WebServer() this->multi_handle = curl_multi_init(); this->handle_count = 0; + //todo:even if this was the appropriate place to do this, it is not working as intended + //i guess some of the Gf function are not available to be call that early in the game initialization process + //so we get a segfault. + // moved this call to the start of the functions 'addAsyncRequest' and 'sendGenericRequest' + //initialize the configuration //this->readConfiguration(); } @@ -562,6 +567,9 @@ int WebServer::updateAsyncStatus() int WebServer::addAsyncRequest(std::string const data) { GfLogInfo("WebServer: Performing ASYNC request:\n%s\n", data.c_str()); + + //read the webserver configuration + this->readConfiguration(); CURL* curl = NULL; struct curl_httppost *formpost=NULL; @@ -622,6 +630,10 @@ int WebServer::addOrderedAsyncRequest(std::string data) int WebServer::sendGenericRequest (std::string data, std::string& serverReply) { + //read the webserver configuration + this->readConfiguration(); + + CURL *curl; CURLcode res; @@ -697,26 +709,17 @@ int WebServer::sendGenericRequest (std::string data, std::string& serverReply) void WebServer::readConfiguration () { + void *configHandle; + char configFileUrl[256]; - GfLogInfo("WebServer prefFile is in: %s%s\n", GfLocalDir(), "config/webserver.xml"); + //get the preferencies file location + sprintf(configFileUrl, "%s%s", GfLocalDir(), "config/webserver.xml"); - - void *configHandle; - char configFileUrl[256]; + //read the preferencies file + configHandle = GfParmReadFile(configFileUrl, GFPARM_RMODE_REREAD); - //get the preferencies file location - sprintf(configFileUrl, "%s%s", GfLocalDir(), "config/webserver.xml"); - - //read the preferencies file - configHandle = GfParmReadFile(configFileUrl, GFPARM_RMODE_REREAD); - - //get webServer url from the config - this->url = GfParmGetStr(configHandle, "WebServer Settings", "url","val"); - - - //this->url ="http://www.madbad.altervista.org/speed-dreams/webserver.php"; - //this->url ="http://masterserver.speed-dreams.fr/webserver.php"; -// this->url ="http://localhost/speed-dreams/webserver.php"; + //get webServer url from the config + this->url = GfParmGetStr(configHandle, "WebServer Settings", "url","val"); GfLogInfo("WebServer - webserver url is: %s\n", this->url); } @@ -749,13 +752,38 @@ int WebServer::sendLogin (int userId) { std::string serverReply; - //initialize the configuration - this->readConfiguration(); - //read username and password and save it in as webserver properties this->readUserConfig(userId); this->sendLogin(this->username, this->password); +/* + std::string username="username"; + std::string password="password"; + //if the user has not setup the webserver login info abort the login + if(username==this->username && password==this->password){ + GfLogInfo("WebServer: Send of login info aborted (the user is not correctly setup in this client).\n"); + return 1; + } + + //prepare the string to send + std::string dataToSend (""); + dataToSend.append( "" + "" + "{{request_id}}" + "" + "" + "{{username}}" + "{{password}}" + "" + "" + ""); + + //replace the {{tags}} with the respecting values + replaceAll(dataToSend, "{{username}}", this->username); + replaceAll(dataToSend, "{{password}}", this->password); + + this->addOrderedAsyncRequest(dataToSend); +*/ return 0; } @@ -763,9 +791,6 @@ int WebServer::sendLogin (const char* username, const char* password) { std::string serverReply; - //initialize the configuration - this->readConfiguration(); - //prepare the string to send std::string dataToSend (""); dataToSend.append( ""