summaryrefslogtreecommitdiff
path: root/src/serverlist.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-06-23 18:30:21 +0200
committerkwolekr <kwolekr@minetest.net>2013-07-02 19:58:20 -0400
commit967121a34bbc60e6b46c7ec470b151f668ef1fef (patch)
treee5cc5ec845d3c286bcb0e203e3a5f146950bfaf1 /src/serverlist.cpp
parentfe4ce03d529f70346b2e2c4872223ebdcd37fffa (diff)
downloadminetest-967121a34bbc60e6b46c7ec470b151f668ef1fef.tar.gz
minetest-967121a34bbc60e6b46c7ec470b151f668ef1fef.tar.bz2
minetest-967121a34bbc60e6b46c7ec470b151f668ef1fef.zip
Replace C++ mainmenu by formspec powered one
Diffstat (limited to 'src/serverlist.cpp')
-rw-r--r--src/serverlist.cpp60
1 files changed, 12 insertions, 48 deletions
diff --git a/src/serverlist.cpp b/src/serverlist.cpp
index ea5a616c2..6a68e0eac 100644
--- a/src/serverlist.cpp
+++ b/src/serverlist.cpp
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h"
#include "log.h"
#include "json/json.h"
+#include "convert_json.h"
#if USE_CURL
#include <curl/curl.h>
#endif
@@ -68,35 +69,22 @@ std::vector<ServerListSpec> getLocal()
#if USE_CURL
-
-static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
-{
- ((std::string*)userp)->append((char*)contents, size * nmemb);
- return size * nmemb;
-}
-
-
std::vector<ServerListSpec> getOnline()
{
- std::string liststring;
- CURL *curl;
+ Json::Value root = fetchJsonValue((g_settings->get("serverlist_url")+"/list").c_str(),0);
- 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")+"/list").c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ServerList::WriteCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &liststring);
+ std::vector<ServerListSpec> serverlist;
- res = curl_easy_perform(curl);
- if (res != CURLE_OK)
- errorstream<<"Serverlist at url "<<g_settings->get("serverlist_url")<<" not found (internet connection?)"<<std::endl;
- curl_easy_cleanup(curl);
+ if (root.isArray()) {
+ for (unsigned int i = 0; i < root.size(); i++)
+ {
+ if (root[i].isObject()) {
+ serverlist.push_back(root[i]);
+ }
+ }
}
- return ServerList::deSerializeJson(liststring);
+
+ return serverlist;
}
#endif
@@ -189,30 +177,6 @@ std::string serialize(std::vector<ServerListSpec> serverlist)
return liststring;
}
-std::vector<ServerListSpec> deSerializeJson(std::string liststring)
-{
- std::vector<ServerListSpec> serverlist;
- Json::Value root;
- Json::Reader reader;
- std::istringstream stream(liststring);
- if (!liststring.size()) {
- return serverlist;
- }
- if (!reader.parse( stream, root ) )
- {
- errorstream << "Failed to parse server list " << reader.getFormattedErrorMessages();
- return serverlist;
- }
- if (root["list"].isArray())
- for (unsigned int i = 0; i < root["list"].size(); i++)
- {
- if (root["list"][i].isObject()) {
- serverlist.push_back(root["list"][i]);
- }
- }
- return serverlist;
-}
-
std::string serializeJson(std::vector<ServerListSpec> serverlist)
{
Json::Value root;