2013-04-11 18:18:34 +02:00
|
|
|
var master_root, output_to;
|
|
|
|
|
2013-02-21 23:00:44 +01:00
|
|
|
function e(s) {
|
|
|
|
if (typeof s === "undefined") s = '';
|
|
|
|
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); //mc"
|
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
|
|
|
|
function human_time(t, abs) {
|
2013-02-21 23:00:44 +01:00
|
|
|
var n = 's';
|
|
|
|
if (!t || t < 0) t = 0;
|
|
|
|
var f = 0;
|
2013-03-29 23:03:24 +01:00
|
|
|
var s = parseInt(abs ? (t || 0) : (new Date().getTime() / 1000 - (t || 0)));
|
2013-02-21 23:00:44 +01:00
|
|
|
if (!s || s <= 0) s = 0;
|
|
|
|
if (s == 0) return 'now';
|
|
|
|
if (s >= 60) {
|
|
|
|
s /= 60;
|
|
|
|
n = 'm';
|
|
|
|
if (s >= 60) {
|
|
|
|
s /= 60;
|
|
|
|
n = 'h';
|
|
|
|
f = 1;
|
|
|
|
if (s >= 24) {
|
|
|
|
s /= 24;
|
|
|
|
n = 'd';
|
|
|
|
f = 1;
|
|
|
|
if (s >= 30) {
|
|
|
|
s /= 30;
|
|
|
|
n = 'M';
|
|
|
|
f = 1;
|
|
|
|
if (s >= 12) {
|
|
|
|
s /= 12;
|
|
|
|
n = 'y';
|
|
|
|
f = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ((f ? parseFloat(s).toFixed(1) : parseInt(s)) + n);
|
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
|
2013-02-21 23:00:44 +01:00
|
|
|
function success(r) {
|
|
|
|
if (!r || !r.list) return;
|
2013-08-03 01:02:59 +02:00
|
|
|
var h = '<table class="mts_table"><tr class="mts_head"><th>ip[:port]</th><th>clients/max</th><th>version gameid mapgen</th><th>name</th><th>description</th><th>flags</th><th>uptime</th><th>ping</th></tr>';
|
2013-02-21 23:00:44 +01:00
|
|
|
for (var i = 0; i < r.list.length; ++i) {
|
|
|
|
var s = r.list[i];
|
|
|
|
if (!s) continue;
|
2013-07-04 17:39:26 +02:00
|
|
|
if (/:/.test(s.address)) s.address = '[' + s.address + ']';
|
2013-03-29 23:03:24 +01:00
|
|
|
h += '<tr class="mts_row">';
|
|
|
|
h += '<td class="mts_address">' + e(s.address) + (s.port != 30000 ? (':' + e(s.port)) : '') + '</td>';
|
2013-08-07 09:20:36 +02:00
|
|
|
h += '<td class="mts_clients">' + e(s.clients) + (s.clients_max ? '/' + e(s.clients_max) : '') + (s.clients_top ? ', ' + e(s.clients_top) : '') + '</td>';
|
2013-08-03 01:02:59 +02:00
|
|
|
var mods = 0;
|
2013-07-04 17:39:26 +02:00
|
|
|
if (s.mods && jQuery.isArray(s.mods)) {
|
2013-07-13 02:10:16 +02:00
|
|
|
mods = s.mods.length;
|
2013-07-12 22:37:28 +02:00
|
|
|
}
|
2013-08-04 21:45:03 +02:00
|
|
|
h += '<td class="mts_version' + (mods ? ' mts_ismods' : '') + '">' + e(s.version) + ' ' + e(s.gameid) + ' ' + e(s.mapgen);
|
2013-07-12 22:37:28 +02:00
|
|
|
if (mods) {
|
2013-08-03 01:02:59 +02:00
|
|
|
h += '<div class="mts_mods">Mods ('+mods+'):<br/>';
|
2013-07-04 17:39:26 +02:00
|
|
|
for (m in s.mods) {
|
|
|
|
h += s.mods[m] + '<br/>';
|
|
|
|
}
|
|
|
|
h += '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
h += '</td>';
|
|
|
|
|
2013-03-29 23:03:24 +01:00
|
|
|
h += '<td class="mts_url">';
|
2013-02-21 23:00:44 +01:00
|
|
|
if (s.url) h += '<a href="' + e(s.url) + '">';
|
|
|
|
h += e(s.name || s.url);
|
|
|
|
if (s.url) h += '</a>';
|
|
|
|
h += '</td>';
|
2013-03-29 23:03:24 +01:00
|
|
|
h += '<td class="mts_description">' + e(s.description) + '</td>';
|
2013-08-03 01:02:59 +02:00
|
|
|
h += '<td class="mts_flags">' +
|
|
|
|
(s.password ? 'Pwd ' : '') +
|
|
|
|
(s.creative ? 'Cre ' : '') +
|
|
|
|
(s.damage ? 'Dmg ' : '') +
|
|
|
|
(s.pvp ? 'Pvp ' : '') +
|
|
|
|
(s.dedicated ? 'Ded ' : '') +
|
|
|
|
(s.rollback ? 'Rol ' : '') +
|
|
|
|
(s.liquid_finite ? 'Liq ' : '') +
|
|
|
|
'</td>';
|
2013-02-21 23:00:44 +01:00
|
|
|
if (!s.start || s.start < 0) s.start = 0;
|
2013-03-29 23:36:06 +01:00
|
|
|
h += '<td class="mts_time">' + (s.uptime ? human_time(s.uptime, 1) : s.start ? human_time(s.start) : '') + '</td>';
|
2013-03-29 23:03:24 +01:00
|
|
|
h += '<td class="mts_ping">' + (s.ping ? parseFloat(s.ping).toFixed(3) * 1000 : '') + '</td>';
|
2013-02-21 23:00:44 +01:00
|
|
|
h += '</tr>';
|
|
|
|
}
|
|
|
|
h += '</table>'
|
2013-04-11 18:18:34 +02:00
|
|
|
jQuery(output_to || '#servers_table').html(h);
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
|
2013-02-21 23:00:44 +01:00
|
|
|
function get() {
|
2013-03-29 23:03:24 +01:00
|
|
|
jQuery.getJSON((master_root || '') + 'list', success);
|
2013-02-21 23:00:44 +01:00
|
|
|
setTimeout(get, 60000);
|
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
get();
|