forked from Mirrorlandia_minetest/minetest
Send long announce as POST, show OS in useragent
Add lag reporting to masterserver (average dtime) StyledWriter -> FastWriter in masterserver announce
This commit is contained in:
parent
3e728e722a
commit
c62bab010f
@ -37,8 +37,6 @@ Json::Value fetchJsonValue(const std::string url,
|
|||||||
HTTPFetchRequest fetchrequest;
|
HTTPFetchRequest fetchrequest;
|
||||||
HTTPFetchResult fetchresult;
|
HTTPFetchResult fetchresult;
|
||||||
fetchrequest.url = url;
|
fetchrequest.url = url;
|
||||||
fetchrequest.useragent = std::string("Minetest ")+minetest_version_hash;
|
|
||||||
fetchrequest.timeout = g_settings->getS32("curl_timeout");
|
|
||||||
fetchrequest.caller = HTTPFETCH_SYNC;
|
fetchrequest.caller = HTTPFETCH_SYNC;
|
||||||
|
|
||||||
struct curl_slist* runptr = chunk;
|
struct curl_slist* runptr = chunk;
|
||||||
|
@ -518,8 +518,6 @@ bool GUIEngine::downloadFile(std::string url,std::string target) {
|
|||||||
HTTPFetchRequest fetchrequest;
|
HTTPFetchRequest fetchrequest;
|
||||||
HTTPFetchResult fetchresult;
|
HTTPFetchResult fetchresult;
|
||||||
fetchrequest.url = url;
|
fetchrequest.url = url;
|
||||||
fetchrequest.useragent = std::string("Minetest ")+minetest_version_hash;
|
|
||||||
fetchrequest.timeout = g_settings->getS32("curl_timeout");
|
|
||||||
fetchrequest.caller = HTTPFETCH_SYNC;
|
fetchrequest.caller = HTTPFETCH_SYNC;
|
||||||
httpfetch_sync(fetchrequest,fetchresult);
|
httpfetch_sync(fetchrequest,fetchresult);
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#endif
|
||||||
#include "jthread/jevent.h"
|
#include "jthread/jevent.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
@ -32,10 +35,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util/container.h"
|
#include "util/container.h"
|
||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
|
#include "version.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
JMutex g_httpfetch_mutex;
|
JMutex g_httpfetch_mutex;
|
||||||
std::map<unsigned long, std::list<HTTPFetchResult> > g_httpfetch_results;
|
std::map<unsigned long, std::list<HTTPFetchResult> > g_httpfetch_results;
|
||||||
|
|
||||||
|
HTTPFetchRequest::HTTPFetchRequest()
|
||||||
|
{
|
||||||
|
url = "";
|
||||||
|
caller = HTTPFETCH_DISCARD;
|
||||||
|
request_id = 0;
|
||||||
|
timeout = g_settings->getS32("curl_timeout");
|
||||||
|
connect_timeout = timeout * 5;
|
||||||
|
|
||||||
|
useragent = std::string("Minetest ") + minetest_version_hash;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
useragent += "Windows";
|
||||||
|
#else
|
||||||
|
struct utsname osinfo;
|
||||||
|
uname(&osinfo);
|
||||||
|
useragent += std::string(" (") + osinfo.sysname + "; " + osinfo.release + "; " + osinfo.machine + ")";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void httpfetch_deliver_result(const HTTPFetchResult &fetchresult)
|
static void httpfetch_deliver_result(const HTTPFetchResult &fetchresult)
|
||||||
{
|
{
|
||||||
unsigned long caller = fetchresult.caller;
|
unsigned long caller = fetchresult.caller;
|
||||||
|
@ -58,14 +58,7 @@ struct HTTPFetchRequest
|
|||||||
//useragent to use
|
//useragent to use
|
||||||
std::string useragent;
|
std::string useragent;
|
||||||
|
|
||||||
HTTPFetchRequest()
|
HTTPFetchRequest();
|
||||||
{
|
|
||||||
url = "";
|
|
||||||
caller = HTTPFETCH_DISCARD;
|
|
||||||
request_id = 0;
|
|
||||||
timeout = 0;
|
|
||||||
connect_timeout = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HTTPFetchResult
|
struct HTTPFetchResult
|
||||||
|
@ -675,6 +675,7 @@ Server::Server(
|
|||||||
m_savemap_timer = 0.0;
|
m_savemap_timer = 0.0;
|
||||||
|
|
||||||
m_step_dtime = 0.0;
|
m_step_dtime = 0.0;
|
||||||
|
m_lag = g_settings->getFloat("dedicated_server_step");
|
||||||
|
|
||||||
if(path_world == "")
|
if(path_world == "")
|
||||||
throw ServerError("Supplied empty world path");
|
throw ServerError("Supplied empty world path");
|
||||||
@ -1260,13 +1261,14 @@ void Server::AsyncRunStep()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
m_lag += (m_lag > dtime ? -1 : 1) * dtime/100;
|
||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
// send masterserver announce
|
// send masterserver announce
|
||||||
{
|
{
|
||||||
float &counter = m_masterserver_timer;
|
float &counter = m_masterserver_timer;
|
||||||
if(!isSingleplayer() && (!counter || counter >= 300.0) && g_settings->getBool("server_announce") == true)
|
if(!isSingleplayer() && (!counter || counter >= 300.0) && g_settings->getBool("server_announce") == true)
|
||||||
{
|
{
|
||||||
ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_names, m_uptime.get(), m_env->getGameTime(), m_gamespec.id, m_mods);
|
ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_names, m_uptime.get(), m_env->getGameTime(), m_lag, m_gamespec.id, m_mods);
|
||||||
counter = 0.01;
|
counter = 0.01;
|
||||||
}
|
}
|
||||||
counter += dtime;
|
counter += dtime;
|
||||||
|
@ -701,6 +701,8 @@ private:
|
|||||||
float m_step_dtime;
|
float m_step_dtime;
|
||||||
JMutex m_step_dtime_mutex;
|
JMutex m_step_dtime_mutex;
|
||||||
|
|
||||||
|
float m_lag;
|
||||||
|
|
||||||
// The server mainly operates in this thread
|
// The server mainly operates in this thread
|
||||||
ServerThread *m_thread;
|
ServerThread *m_thread;
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ std::string serializeJson(std::vector<ServerListSpec> serverlist)
|
|||||||
|
|
||||||
|
|
||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
void sendAnnounce(std::string action, const std::vector<std::string> & clients_names, double uptime, u32 game_time, std::string gameid, std::vector<ModSpec> mods) {
|
void sendAnnounce(std::string action, const std::vector<std::string> & clients_names, double uptime, u32 game_time, float lag, std::string gameid, std::vector<ModSpec> mods) {
|
||||||
Json::Value server;
|
Json::Value server;
|
||||||
if (action.size())
|
if (action.size())
|
||||||
server["action"] = action;
|
server["action"] = action;
|
||||||
@ -226,16 +226,19 @@ void sendAnnounce(std::string action, const std::vector<std::string> & clients_n
|
|||||||
server["mods"].append(m->name);
|
server["mods"].append(m->name);
|
||||||
}
|
}
|
||||||
actionstream << "announcing to " << g_settings->get("serverlist_url") << std::endl;
|
actionstream << "announcing to " << g_settings->get("serverlist_url") << std::endl;
|
||||||
|
} else {
|
||||||
|
if (lag)
|
||||||
|
server["step"] = lag;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::StyledWriter writer;
|
Json::FastWriter writer;
|
||||||
HTTPFetchRequest fetchrequest;
|
HTTPFetchRequest fetchrequest;
|
||||||
fetchrequest.url = g_settings->get("serverlist_url")
|
fetchrequest.url = g_settings->get("serverlist_url") + std::string("/announce");
|
||||||
+ std::string("/announce?json=")
|
std::string query = std::string("json=") + urlencode(writer.write(server));
|
||||||
+ urlencode(writer.write(server));
|
if (query.size() < 1000)
|
||||||
fetchrequest.useragent = std::string("Minetest ")+minetest_version_hash;
|
fetchrequest.url += "?" + query;
|
||||||
fetchrequest.caller = HTTPFETCH_DISCARD;
|
else
|
||||||
fetchrequest.timeout = g_settings->getS32("curl_timeout");
|
fetchrequest.post_fields = query;
|
||||||
httpfetch_async(fetchrequest);
|
httpfetch_async(fetchrequest);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,7 +41,7 @@ namespace ServerList
|
|||||||
std::string serializeJson(std::vector<ServerListSpec>);
|
std::string serializeJson(std::vector<ServerListSpec>);
|
||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
void sendAnnounce(std::string action = "", const std::vector<std::string> & clients_names = std::vector<std::string>(),
|
void sendAnnounce(std::string action = "", const std::vector<std::string> & clients_names = std::vector<std::string>(),
|
||||||
double uptime = 0, u32 game_time = 0,std::string gameid = "",
|
double uptime = 0, u32 game_time = 0, float lag = 0, std::string gameid = "",
|
||||||
std::vector<ModSpec> mods = std::vector<ModSpec>());
|
std::vector<ModSpec> mods = std::vector<ModSpec>());
|
||||||
#endif
|
#endif
|
||||||
} //ServerList namespace
|
} //ServerList namespace
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
{{? !master.no_description}}<th>Description</th>{{?}}
|
{{? !master.no_description}}<th>Description</th>{{?}}
|
||||||
{{? !master.no_flags}}<th>Flags</th>{{?}}
|
{{? !master.no_flags}}<th>Flags</th>{{?}}
|
||||||
{{? !master.no_uptime}}<th>Uptime, Age</th>{{?}}
|
{{? !master.no_uptime}}<th>Uptime, Age</th>{{?}}
|
||||||
{{? !master.no_ping}}<th>Ping</th>{{?}}
|
{{? !master.no_ping}}<th>Ping, Lag</th>{{?}}
|
||||||
</tr>
|
</tr>
|
||||||
{{~it.list :server:index}}
|
{{~it.list :server:index}}
|
||||||
{{ if (master.limit && index + 1 > master.limit) break;}}
|
{{ if (master.limit && index + 1 > master.limit) break;}}
|
||||||
@ -64,7 +64,7 @@
|
|||||||
</td>{{?}}
|
</td>{{?}}
|
||||||
{{? !master.no_ping}}
|
{{? !master.no_ping}}
|
||||||
<td class="ping">
|
<td class="ping">
|
||||||
{{=Math.floor(server.ping * 1000)}}
|
{{=Math.floor(server.ping * 1000)}}{{? server.lag}}, {{= Math.floor(server.lag * 1000)}}{{?}}
|
||||||
</td>{{?}}
|
</td>{{?}}
|
||||||
</tr>
|
</tr>
|
||||||
{{~}}
|
{{~}}
|
||||||
|
Loading…
Reference in New Issue
Block a user