summaryrefslogtreecommitdiff
path: root/src/serverlist.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2013-08-29 05:58:13 +0200
committerKahrl <kahrl@gmx.net>2013-12-13 18:05:39 +0100
commitb03135548bbd9bcb73d14b067b96ec913404dd5f (patch)
tree7638bb8a6372ab540e0e4783b79b9242005a9948 /src/serverlist.cpp
parent0a903e69fbd9b19d8d8da0593f31dec5807af566 (diff)
downloadminetest-b03135548bbd9bcb73d14b067b96ec913404dd5f.tar.gz
minetest-b03135548bbd9bcb73d14b067b96ec913404dd5f.tar.bz2
minetest-b03135548bbd9bcb73d14b067b96ec913404dd5f.zip
Use httpfetch_async in serverlist announce code
Diffstat (limited to 'src/serverlist.cpp')
-rw-r--r--src/serverlist.cpp36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/serverlist.cpp b/src/serverlist.cpp
index 7376bce99..204427f88 100644
--- a/src/serverlist.cpp
+++ b/src/serverlist.cpp
@@ -30,9 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "json/json.h"
#include "convert_json.h"
-#if USE_CURL
-#include <curl/curl.h>
-#endif
+#include "httpfetch.h"
+#include "util/string.h"
namespace ServerList
{
@@ -189,11 +188,6 @@ std::string serializeJson(std::vector<ServerListSpec> serverlist)
#if USE_CURL
-static size_t ServerAnnounceCallback(void *contents, size_t size, size_t nmemb, void *userp)
-{
- //((std::string*)userp)->append((char*)contents, size * nmemb);
- return size * nmemb;
-}
void sendAnnounce(std::string action, const std::vector<std::string> & clients_names, double uptime, u32 game_time, std::string gameid, std::vector<ModSpec> mods) {
Json::Value server;
if (action.size())
@@ -235,24 +229,14 @@ void sendAnnounce(std::string action, const std::vector<std::string> & clients_n
}
Json::StyledWriter writer;
- CURL *curl;
- curl = curl_easy_init();
- if (curl)
- {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_URL, (g_settings->get("serverlist_url")+std::string("/announce?json=")+curl_easy_escape(curl, writer.write( server ).c_str(), 0)).c_str());
- curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ServerList::ServerAnnounceCallback);
- //curl_easy_setopt(curl, CURLOPT_WRITEDATA, &liststring);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1);
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1);
- res = curl_easy_perform(curl);
- if (res != CURLE_OK)
- errorstream<<"Serverlist at url "<<g_settings->get("serverlist_url")<<" error ("<<curl_easy_strerror(res)<<")"<<std::endl;
- curl_easy_cleanup(curl);
- }
-
+ HTTPFetchRequest fetchrequest;
+ fetchrequest.url = g_settings->get("serverlist_url")
+ + std::string("/announce?json=")
+ + urlencode(writer.write(server));
+ fetchrequest.useragent = std::string("Minetest ")+minetest_version_hash;
+ fetchrequest.caller = HTTPFETCH_DISCARD;
+ fetchrequest.timeout = g_settings->getS32("curl_timeout");
+ httpfetch_async(fetchrequest);
}
#endif