Skip to content

Commit 382357d

Browse files
committedOct 18, 2013
Masterserver totals fix
1 parent a924409 commit 382357d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
 

‎util/master/list.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ function human_time(t, abs) {
4848
function success(r) {
4949
if (!r || !r.list) return;
5050
var h = '';
51-
if (!master.no_total && r.total)
52-
h += '<div class="mts_total">Now players: ' + r.total.clients + ' servers: ' + r.total.servers + '</div>';
53-
if (!master.no_total_max && r.total_max)
54-
h += '<div class="mts_total_max">Max players: ' + r.total_max.clients + ' servers: ' + r.total_max.servers + '</div>';
51+
if (!master.no_total && r.total && r.total_max)
52+
h += '<div class="mts_total">Players: ' + r.total.clients + ('/' + r.total_max.clients) + ' servers: ' + r.total.servers + ('/' + r.total_max.servers) + '</div>';
5553
h += '<table class="mts_table">';
5654
if (r.list.length) {
5755
h += '<tr class="mts_head">';

‎util/master/master.cgi

+10-5
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ sub request (;$) {
229229
return if !$param->{ping};
230230
}
231231
my $list = read_json($config{list_full}) || {};
232-
printlog "readed[$config{list_full}] list size=", scalar @{$list->{list}};
232+
printlog "readed[$config{list_full}] list size=", scalar @{$list->{list}} if $config{debug};
233233
my $listk = {map { $_->{key} => $_ } @{$list->{list}}};
234234
my $old = $listk->{$param->{key}};
235235
$param->{time} = $old->{time} if $param->{off};
@@ -250,13 +250,12 @@ sub request (;$) {
250250
delete $param->{action};
251251
$listk->{$param->{key}} = $param;
252252
#printlog 'write', Dumper $param if $config{debug};
253-
$list->{list} = [grep { $_->{time} > time - $config{time_purge} } values %$listk];
254-
file_rewrite($config{list_full}, JSON->new->encode($list));
255-
printlog "writed[$config{list_full}] list size=", scalar @{$list->{list}} if $config{debug};
253+
my $list_full = [grep { $_->{time} > time - $config{time_purge} } values %$listk];
254+
256255
$list->{list} = [
257256
sort { $b->{clients} <=> $a->{clients} || $a->{start} <=> $b->{start} }
258257
grep { $_->{time} > time - $config{time_alive} and !$_->{off} and (!$config{ping} or !$config{pingable} or $_->{ping}) }
259-
@{$list->{list}}
258+
@{$list_full}
260259
];
261260
$list->{total} = {clients => 0, servers => 0};
262261
for (@{$list->{list}}) {
@@ -265,8 +264,14 @@ sub request (;$) {
265264
}
266265
$list->{total_max}{clients} = $list->{total}{clients} if $list->{total_max}{clients} < $list->{total}{clients};
267266
$list->{total_max}{servers} = $list->{total}{servers} if $list->{total_max}{servers} < $list->{total}{servers};
267+
268268
file_rewrite($config{list_pub}, JSON->new->encode($list));
269269
printlog "writed[$config{list_pub}] list size=", scalar @{$list->{list}} if $config{debug};
270+
271+
$list->{list} = $list_full;
272+
file_rewrite($config{list_full}, JSON->new->encode($list));
273+
printlog "writed[$config{list_full}] list size=", scalar @{$list->{list}} if $config{debug};
274+
270275
}
271276
};
272277
return [200, ["Content-type", "application/json"], [JSON->new->encode({})]], $after;

0 commit comments

Comments
 (0)
Please sign in to comment.