]> git.lizzy.rs Git - dragonfireclient.git/blob - util/master/list.js
new auto masterserver
[dragonfireclient.git] / util / master / list.js
1 function e(s) {
2     if (typeof s === "undefined") s = '';
3     return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); //mc"
4 }
5 function human_time(t) {
6     var n = 's';
7     if (!t || t < 0) t = 0;
8     var f = 0;
9     var s = parseInt((new Date().getTime() / 1000 - (t || 0)));
10     if (!s || s <= 0) s = 0;
11     if (s == 0) return 'now';
12     if (s >= 60) {
13         s /= 60;
14         n = 'm';
15         if (s >= 60) {
16             s /= 60;
17             n = 'h';
18             f = 1;
19             if (s >= 24) {
20                 s /= 24;
21                 n = 'd';
22                 f = 1;
23                 if (s >= 30) {
24                     s /= 30;
25                     n = 'M';
26                     f = 1;
27                     if (s >= 12) {
28                         s /= 12;
29                         n = 'y';
30                         f = 1;
31                     }
32                 }
33             }
34         }
35     }
36     return ((f ? parseFloat(s).toFixed(1) : parseInt(s)) + n);
37 }
38 function success(r) {
39     if (!r || !r.list) return;
40     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>';
41     for (var i = 0; i < r.list.length; ++i) {
42         var s = r.list[i];
43         if (!s) continue;
44         h += '<tr>';
45         h += '<td>' + e(s.address) + ':' + e(s.port) + '</td>';
46         h += '<td>' + e(s.clients) + (s.clients_max ? '/' + e(s.clients_max) : '') + (s.clients_top ? ', ' + s.clients_top : '') + '</td>';
47         h += '<td>' + e(s.version) + '</td>';
48         h += '<td>';
49         if (s.url) h += '<a href="' + e(s.url) + '">';
50         h += e(s.name || s.url);
51         if (s.url) h += '</a>';
52         h += '</td>';
53         h += '<td>' + e(s.description) + '</td>';
54         h += '<td>' + e(s.password ? 'Pwd ' : '') + (s.creative ? 'Cre ' : '') + (s.damage ? 'Dmg ' : '') + (s.pvp ? 'Pvp ' : '') + (s.dedicated ? 'Ded ' : '') + '</td>';
55         if (!s.time || s.time < 0) s.time = 0;
56         if (!s.start || s.start < 0) s.start = 0;
57         h += '<td>' + human_time(s.time) + (s.start ? '/' + human_time(s.start) : '') + '</td>';
58         h += '<td>' + (s.ping ? parseFloat(s.ping).toFixed(3)*1000 : '') + '</td>';
59         h += '</tr>';
60     }
61     h += '</table>'
62     jQuery('#table').html(h);
63 }
64 function get() {
65     jQuery.ajax({
66         url: 'list',
67         dataType: 'json',
68         success: success
69     });
70     setTimeout(get, 60000);
71 }
72 get();