1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-22 23:58:48 -05:00

Masterserver: report gameid, uptime, cosmetic fixes on server web page

This commit is contained in:
proller 2013-03-30 02:03:24 +04:00
parent df49b93877
commit 16c11eb4a3
5 changed files with 29 additions and 21 deletions

View File

@ -1243,7 +1243,7 @@ void Server::AsyncRunStep()
float &counter = m_masterserver_timer; float &counter = m_masterserver_timer;
if((!counter || counter >= 300.0) && g_settings->getBool("server_announce") == true) if((!counter || counter >= 300.0) && g_settings->getBool("server_announce") == true)
{ {
ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_number); ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_number, m_uptime.get(), m_gamespec.id);
counter = 0.01; counter = 0.01;
} }
counter += dtime; counter += dtime;

View File

@ -232,7 +232,7 @@ static size_t ServerAnnounceCallback(void *contents, size_t size, size_t nmemb,
//((std::string*)userp)->append((char*)contents, size * nmemb); //((std::string*)userp)->append((char*)contents, size * nmemb);
//return size * nmemb; //return size * nmemb;
} }
void sendAnnounce(std::string action, u16 clients) { void sendAnnounce(std::string action, u16 clients, double uptime, std::string gameid) {
Json::Value server; Json::Value server;
if (action.size()) if (action.size())
server["action"] = action; server["action"] = action;
@ -250,6 +250,9 @@ void sendAnnounce(std::string action, u16 clients) {
server["pvp"] = g_settings->getBool("enable_pvp"); server["pvp"] = g_settings->getBool("enable_pvp");
server["clients"] = clients; server["clients"] = clients;
server["clients_max"] = g_settings->get("max_users"); server["clients_max"] = g_settings->get("max_users");
if (uptime >=1) server["uptime"] = (int)uptime;
if (gameid!="") server["gameid"] = gameid;
} }
if(server["action"] == "start") if(server["action"] == "start")
actionstream << "announcing to " << g_settings->get("serverlist_url") << std::endl; actionstream << "announcing to " << g_settings->get("serverlist_url") << std::endl;

View File

@ -39,7 +39,7 @@ namespace ServerList
std::vector<ServerListSpec> deSerializeJson(std::string liststring); std::vector<ServerListSpec> deSerializeJson(std::string liststring);
std::string serializeJson(std::vector<ServerListSpec>); std::string serializeJson(std::vector<ServerListSpec>);
#if USE_CURL #if USE_CURL
void sendAnnounce(std::string action = "", u16 clients = 0); void sendAnnounce(std::string action = "", u16 clients = 0, double uptime = 0, std::string gameid = "");
#endif #endif
} //ServerList namespace } //ServerList namespace

View File

@ -2,11 +2,12 @@ function e(s) {
if (typeof s === "undefined") s = ''; if (typeof s === "undefined") s = '';
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); //mc" return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); //mc"
} }
function human_time(t) {
function human_time(t, abs) {
var n = 's'; var n = 's';
if (!t || t < 0) t = 0; if (!t || t < 0) t = 0;
var f = 0; var f = 0;
var s = parseInt((new Date().getTime() / 1000 - (t || 0))); var s = parseInt(abs ? (t || 0) : (new Date().getTime() / 1000 - (t || 0)));
if (!s || s <= 0) s = 0; if (!s || s <= 0) s = 0;
if (s == 0) return 'now'; if (s == 0) return 'now';
if (s >= 60) { if (s >= 60) {
@ -35,38 +36,37 @@ function human_time(t) {
} }
return ((f ? parseFloat(s).toFixed(1) : parseInt(s)) + n); return ((f ? parseFloat(s).toFixed(1) : parseInt(s)) + n);
} }
function success(r) { function success(r) {
if (!r || !r.list) return; if (!r || !r.list) return;
var h = '<table><tr><th>ip:port</th><th>clients, max</th><th>version</th><th>name</th><th>desc</th><th>flags</th><th>updated/started</th><th>ping</th></tr>'; var h = '<table class="mts_table"><tr class="mts_head"><th>ip[:port]</th><th>clients/max</th><th>version gameid</th><th>name</th><th>desc</th><th>flags</th><th>uptime</th><th>ping</th></tr>';
for (var i = 0; i < r.list.length; ++i) { for (var i = 0; i < r.list.length; ++i) {
var s = r.list[i]; var s = r.list[i];
if (!s) continue; if (!s) continue;
h += '<tr>'; h += '<tr class="mts_row">';
h += '<td>' + e(s.address) + ':' + e(s.port) + '</td>'; h += '<td class="mts_address">' + e(s.address) + (s.port != 30000 ? (':' + e(s.port)) : '') + '</td>';
h += '<td>' + e(s.clients) + (s.clients_max ? '/' + e(s.clients_max) : '') + (s.clients_top ? ', ' + s.clients_top : '') + '</td>'; h += '<td class="mts_clients">' + e(s.clients) + (s.clients_max ? '/' + e(s.clients_max) : '') + (s.clients_top ? ', ' + s.clients_top : '') + '</td>';
h += '<td>' + e(s.version) + '</td>'; h += '<td class="mts_version">' + e(s.version) + ' ' + e(s.gameid) + '</td>';
h += '<td>'; h += '<td class="mts_url">';
if (s.url) h += '<a href="' + e(s.url) + '">'; if (s.url) h += '<a href="' + e(s.url) + '">';
h += e(s.name || s.url); h += e(s.name || s.url);
if (s.url) h += '</a>'; if (s.url) h += '</a>';
h += '</td>'; h += '</td>';
h += '<td>' + e(s.description) + '</td>'; h += '<td class="mts_description">' + e(s.description) + '</td>';
h += '<td>' + e(s.password ? 'Pwd ' : '') + (s.creative ? 'Cre ' : '') + (s.damage ? 'Dmg ' : '') + (s.pvp ? 'Pvp ' : '') + (s.dedicated ? 'Ded ' : '') + '</td>'; h += '<td class="mts_flags">' + e(s.password ? 'Pwd ' : '') + (s.creative ? 'Cre ' : '') + (s.damage ? 'Dmg ' : '') + (s.pvp ? 'Pvp ' : '') + (s.dedicated ? 'Ded ' : '') + '</td>';
if (!s.time || s.time < 0) s.time = 0; if (!s.time || s.time < 0) s.time = 0;
if (!s.start || s.start < 0) s.start = 0; if (!s.start || s.start < 0) s.start = 0;
h += '<td>' + human_time(s.time) + (s.start ? '/' + human_time(s.start) : '') + '</td>'; h += '<td class="mts_time">' + (s.uptime ? human_time(s.uptime, 1) : '') + '</td>';
h += '<td>' + (s.ping ? parseFloat(s.ping).toFixed(3)*1000 : '') + '</td>'; h += '<td class="mts_ping">' + (s.ping ? parseFloat(s.ping).toFixed(3) * 1000 : '') + '</td>';
h += '</tr>'; h += '</tr>';
} }
h += '</table>' h += '</table>'
jQuery('#table').html(h); jQuery('#table').html(h);
} }
var master_root;
function get() { function get() {
jQuery.ajax({ jQuery.getJSON((master_root || '') + 'list', success);
url: 'list',
dataType: 'json',
success: success
});
setTimeout(get, 60000); setTimeout(get, 60000);
} }
get(); get();

View File

@ -18,6 +18,7 @@ nginx:
location / { location / {
index index.html; index index.html;
add_header Access-Control-Allow-Origin *;
} }
location /announce { location /announce {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock; fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
@ -35,6 +36,10 @@ apache .htaccess:
Allow from all Allow from all
</FilesMatch> </FilesMatch>
Deny from all Deny from all
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</ifModule>
=cut =cut