Masterserver totals fix
authorproller <proller@github.com>
Fri, 18 Oct 2013 17:56:34 +0000 (21:56 +0400)
committerproller <proller@github.com>
Fri, 18 Oct 2013 19:57:22 +0000 (23:57 +0400)
util/master/list.js
util/master/master.cgi

index b5974619a56b25a48074101e6fb9d3ef3b07158e..4e2104bc88a8f2567e12e030d99aa910a1a993cb 100644 (file)
@@ -48,10 +48,8 @@ function human_time(t, abs) {
 function success(r) {
     if (!r || !r.list) return;
     var h = '';
-    if (!master.no_total && r.total)
-        h += '<div class="mts_total">Now players: ' + r.total.clients + ' servers: ' + r.total.servers + '</div>';
-    if (!master.no_total_max && r.total_max)
-        h += '<div class="mts_total_max">Max players: ' + r.total_max.clients + ' servers: ' + r.total_max.servers + '</div>';
+    if (!master.no_total && r.total && r.total_max)
+        h += '<div class="mts_total">Players: ' + r.total.clients + ('/' + r.total_max.clients) + ' servers: ' + r.total.servers + ('/' + r.total_max.servers) + '</div>';
     h += '<table class="mts_table">';
     if (r.list.length) {
         h += '<tr class="mts_head">';
index a916827fea874d41ceef71552f81ef77ca1efa08..6dbf83fca03b127a398f41ccab21f0d3e76a8b54 100755 (executable)
@@ -229,7 +229,7 @@ sub request (;$) {
                 return if !$param->{ping};
             }
             my $list = read_json($config{list_full}) || {};
-            printlog "readed[$config{list_full}] list size=", scalar @{$list->{list}};
+            printlog "readed[$config{list_full}] list size=", scalar @{$list->{list}} if $config{debug};
             my $listk = {map { $_->{key} => $_ } @{$list->{list}}};
             my $old = $listk->{$param->{key}};
             $param->{time} = $old->{time} if $param->{off};
@@ -250,13 +250,12 @@ sub request (;$) {
             delete $param->{action};
             $listk->{$param->{key}} = $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};
+            my $list_full = [grep { $_->{time} > time - $config{time_purge} } values %$listk];
+
             $list->{list} = [
                 sort { $b->{clients} <=> $a->{clients} || $a->{start} <=> $b->{start} }
                   grep { $_->{time} > time - $config{time_alive} and !$_->{off} and (!$config{ping} or !$config{pingable} or $_->{ping}) }
-                  @{$list->{list}}
+                  @{$list_full}
             ];
             $list->{total} = {clients => 0, servers => 0};
             for (@{$list->{list}}) {
@@ -265,8 +264,14 @@ sub request (;$) {
             }
             $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};
+
+            $list->{list} = $list_full;
+            file_rewrite($config{list_full}, JSON->new->encode($list));
+            printlog "writed[$config{list_full}] list size=", scalar @{$list->{list}} if $config{debug};
+
         }
     };
     return [200, ["Content-type", "application/json"], [JSON->new->encode({})]], $after;