From a924409bd1c57fb96e67a1c6cea0b7331d11cb73 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 18 Oct 2013 01:32:49 +0400 Subject: Masterserver update --- util/master/index.html | 1 + util/master/list.js | 111 +++++++++++++++++++++++++++++++++---------------- util/master/master.cgi | 21 ++++++++-- util/master/style.css | 6 +-- 4 files changed, 97 insertions(+), 42 deletions(-) (limited to 'util') diff --git a/util/master/index.html b/util/master/index.html index 328dd8934..ad908fca8 100644 --- a/util/master/index.html +++ b/util/master/index.html @@ -8,4 +8,5 @@
+ diff --git a/util/master/list.js b/util/master/list.js index a17458fb4..b5974619a 100644 --- a/util/master/list.js +++ b/util/master/list.js @@ -1,7 +1,13 @@ var master_root, output_to; +var master; +if (!master) master = { + root: master_root, + output: output_to +}; function e(s) { if (typeof s === "undefined") s = ''; + if (typeof s === "number") return s; return s.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); //mc" } @@ -41,55 +47,88 @@ function human_time(t, abs) { function success(r) { if (!r || !r.list) return; - var h = ''; + var h = ''; + if (!master.no_total && r.total) + h += '
Now players: ' + r.total.clients + ' servers: ' + r.total.servers + '
'; + if (!master.no_total_max && r.total_max) + h += '
Max players: ' + r.total_max.clients + ' servers: ' + r.total_max.servers + '
'; + h += '
ip[:port]clients/maxversion gameid mapgennamedescriptionflagsuptimeping
'; + if (r.list.length) { + h += ''; + if (!master.no_address) h += ''; + if (!master.no_clients) h += ''; + if (!master.no_version) h += ''; + if (!master.no_name) h += ''; + if (!master.no_description) h += ''; + if (!master.no_flags) h += ''; + if (!master.no_uptime) h += ''; + if (!master.no_ping) h += ''; + h += ''; + } + var count = 0; for (var i = 0; i < r.list.length; ++i) { + if (++count > master.limit && master.limit) break; var s = r.list[i]; if (!s) continue; + if (master.clients_min && s.clients < master.clients_min) continue; if (/:/.test(s.address)) s.address = '[' + s.address + ']'; h += ''; - h += ''; - h += ''; + if (!master.no_address) h += ''; + if (!master.no_clients) { + h += ''; + } var mods = 0; - if (s.mods && jQuery.isArray(s.mods)) { + if (s.mods && jQuery.isArray(s.mods)) mods = s.mods.length; - } - h += ''; + } + if (!master.no_name) { + h += ''; + } + if (!master.no_description) h += ''; + if (!master.no_flags) { + h += ''; } - - h += ''; - - h += ''; - h += ''; - h += ''; if (!s.start || s.start < 0) s.start = 0; - h += ''; - h += ''; + if (!master.no_uptime) h += ''; + if (!master.no_ping) h += ''; h += ''; } - h += '
ip[:port]players/maxversion gameid mapgennamedescriptionflagsuptime ageping
' + e(s.address) + (s.port != 30000 ? (':' + e(s.port)) : '') + '' + e(s.clients) + (s.clients_max ? '/' + e(s.clients_max) : '') + (s.clients_top ? ', ' + e(s.clients_top) : '') + '' + e(s.address) + (s.port != 30000 ? (':' + e(s.port)) : '') + ''; + if (!master.no_clients_list && s.clients && s.clients_list) { + h += '
Players (' + e(s.clients) + '):
'; + for (var ii in s.clients_list) + h += e(s.clients_list[ii]) + '
'; + h += '
'; + } + h += e(s.clients) + (s.clients_max ? '/' + e(s.clients_max) : '') + (s.clients_top ? ', ' + e(s.clients_top) : '') + '
' + e(s.version) + ' ' + e(s.gameid) + ' ' + e(s.mapgen); - if (mods) { - h += '
Mods ('+mods+'):
'; - for (m in s.mods) { - h += s.mods[m] + '
'; + if (!master.no_version) { + h += '
' + e(s.version) + ' ' + e(s.gameid) + ' ' + e(s.mapgen); + if (!master.no_mods && mods) { + h += '
Mods (' + mods + '):
'; + for (var ii in s.mods) + h += e(s.mods[ii]) + '
'; + h += '
'; } - h += ''; + h += '
'; + if (s.url) h += ''; + h += e(s.name || s.url); + if (s.url) h += ''; + h += '' + e(s.description) + '' + + (s.password ? 'Pwd ' : '') + + (s.creative ? 'Cre ' : '') + + (s.damage ? 'Dmg ' : '') + + (s.pvp ? 'Pvp ' : '') + + (s.dedicated ? 'Ded ' : '') + + (s.rollback ? 'Rol ' : '') + + (s.liquid_finite ? 'Liq ' : '') + + ''; - if (s.url) h += ''; - h += e(s.name || s.url); - if (s.url) h += ''; - h += '' + e(s.description) + '' + - (s.password ? 'Pwd ' : '') + - (s.creative ? 'Cre ' : '') + - (s.damage ? 'Dmg ' : '') + - (s.pvp ? 'Pvp ' : '') + - (s.dedicated ? 'Ded ' : '') + - (s.rollback ? 'Rol ' : '') + - (s.liquid_finite ? 'Liq ' : '') + - '' + (s.uptime ? human_time(s.uptime, 1) : s.start ? human_time(s.start) : '') + '' + (s.ping ? parseFloat(s.ping).toFixed(3) * 1000 : '') + '' + (s.uptime ? human_time(s.uptime, 1) : s.start ? human_time(s.start) : '') + (s.game_time ? ' ' + human_time(s.game_time, 1) : '') + '' + (s.ping ? parseFloat(s.ping).toFixed(3) * 1000 : '') + '
' - jQuery(output_to || '#servers_table').html(h); + h += ''; + if (master.clients_min || master.limit) + h += 'more...'; + jQuery(master.output || '#servers_table').html(h); } -function get() { - jQuery.getJSON((master_root || '') + 'list', success); - setTimeout(get, 60000); +function get(refresh) { + jQuery.getJSON((master.root || '') + 'list', success); + if (!refresh && !master.no_refresh) setTimeout(get, 60000); } get(); diff --git a/util/master/master.cgi b/util/master/master.cgi index bf627a989..a916827fe 100755 --- a/util/master/master.cgi +++ b/util/master/master.cgi @@ -3,7 +3,7 @@ =info install: cpan JSON JSON::XS - touch list_full list + touch list_full list log.log chmod a+rw list_full list log.log freebsd: @@ -48,6 +48,7 @@ use strict; no strict qw(refs); use warnings "NONFATAL" => "all"; no warnings qw(uninitialized); +no if $] >= 5.017011, warnings => 'experimental::smartmatch'; use utf8; use Socket; BEGIN { @@ -72,7 +73,7 @@ our %config = ( list_full => $root_path . 'list_full', list_pub => $root_path . 'list', log => $root_path . 'log.log', - time_purge => 86400 * 30, + time_purge => 86400 * 1, time_alive => 650, source_check => 1, ping_timeout => 3, @@ -190,11 +191,13 @@ sub request (;$) { $param->{$_} = $j->{$_} for keys %$j; delete $param->{json}; } + #printlog 'recv', Dumper $param; if (%$param) { s/^false$// for values %$param; $param->{ip} = $r->{REMOTE_ADDR}; $param->{ip} =~ s/^::ffff://; for (@{$config{blacklist}}) { + #printlog("blacklist", $param->{ip} ~~ $_) if $config{debug}; return if $param->{ip} ~~ $_; } $param->{address} ||= $param->{ip}; @@ -223,6 +226,7 @@ sub request (;$) { $param->{ping} = $duration if $pingret; printlog " PING t=$config{ping_timeout}, $param->{address}:$param->{port} = ( $pingret, $duration, $ip )" if $config{debug}; } + return if !$param->{ping}; } my $list = read_json($config{list_full}) || {}; printlog "readed[$config{list_full}] list size=", scalar @{$list->{list}}; @@ -232,6 +236,7 @@ sub request (;$) { $param->{time} ||= int time; $param->{start} = $param->{action} ~~ 'start' ? $param->{time} : $old->{start} || $param->{time}; delete $param->{start} if $param->{off}; + $param->{clients} ||= scalar @{$param->{clients_list}} if ref $param->{clients_list} eq 'ARRAY'; $param->{first} ||= $old->{first} || $old->{time} || $param->{time}; $param->{clients_top} = $old->{clients_top} if $old->{clients_top} > $param->{clients}; $param->{clients_top} ||= $param->{clients} || 0; @@ -239,9 +244,12 @@ sub request (;$) { for (qw(dedicated rollback liquid_finite mapgen mods)) { $param->{$_} ||= $old->{$_} if $old->{$_} and !($param->{action} ~~ 'start'); } + $param->{pop_n} = $old->{pop_n} + 1; + $param->{pop_c} = $old->{pop_c} + $param->{clients}; + $param->{pop_v} = $param->{pop_c} / $param->{pop_n}; delete $param->{action}; $listk->{$param->{key}} = $param; - #printlog Dumper $param; + #printlog 'write', Dumper $param if $config{debug}; $list->{list} = [grep { $_->{time} > time - $config{time_purge} } values %$listk]; file_rewrite($config{list_full}, JSON->new->encode($list)); printlog "writed[$config{list_full}] list size=", scalar @{$list->{list}} if $config{debug}; @@ -250,6 +258,13 @@ sub request (;$) { grep { $_->{time} > time - $config{time_alive} and !$_->{off} and (!$config{ping} or !$config{pingable} or $_->{ping}) } @{$list->{list}} ]; + $list->{total} = {clients => 0, servers => 0}; + for (@{$list->{list}}) { + $list->{total}{clients} += $_->{clients}; + ++$list->{total}{servers}; + } + $list->{total_max}{clients} = $list->{total}{clients} if $list->{total_max}{clients} < $list->{total}{clients}; + $list->{total_max}{servers} = $list->{total}{servers} if $list->{total_max}{servers} < $list->{total}{servers}; file_rewrite($config{list_pub}, JSON->new->encode($list)); printlog "writed[$config{list_pub}] list size=", scalar @{$list->{list}} if $config{debug}; } diff --git a/util/master/style.css b/util/master/style.css index c92c56f6e..cff041216 100644 --- a/util/master/style.css +++ b/util/master/style.css @@ -13,7 +13,7 @@ div#table table { width: 100%; } -.mts_mods { +.mts_mods, .mts_clients_list { visibility: hidden; border:gray solid 1px; position:absolute; @@ -22,11 +22,11 @@ div#table table { padding:.5em; } -.mts_version:hover .mts_mods { +.mts_version:hover .mts_mods, .mts_clients:hover .mts_clients_list { visibility: visible; } -.mts_version.mts_ismods { +.mts_version.mts_is_mods, .mts_clients.mts_is_clients { text-decoration:underline; text-decoration-style:dashed; } -- cgit v1.2.3