summaryrefslogtreecommitdiff
path: root/util/master/master.cgi
diff options
context:
space:
mode:
authorproller <proller@github.com>2013-10-18 01:32:49 +0400
committerproller <proller@github.com>2013-10-18 01:32:49 +0400
commita924409bd1c57fb96e67a1c6cea0b7331d11cb73 (patch)
treeb7d5f5d602127a0971ffe50f4911b3614361843f /util/master/master.cgi
parente232f7311f62e600189f1397fdd29a65ae186b1f (diff)
downloadminetest-a924409bd1c57fb96e67a1c6cea0b7331d11cb73.tar.gz
minetest-a924409bd1c57fb96e67a1c6cea0b7331d11cb73.tar.bz2
minetest-a924409bd1c57fb96e67a1c6cea0b7331d11cb73.zip
Masterserver update
Diffstat (limited to 'util/master/master.cgi')
-rwxr-xr-xutil/master/master.cgi21
1 files changed, 18 insertions, 3 deletions
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};
}