blob: 4f23723a1ddbe2674b1877177031da83008db412 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package MasterServer::Core::Stats;
use strict;
use warnings;
use AnyEvent::IO;
use Exporter 'import';
our @EXPORT = qw| update_stats |;
################################################################################
# Update statistics on servers and update the games table with those values
################################################################################
sub update_stats {
my $self = shift;
# find all gamenames with 1 server or more
my $in_slist = $self->get_gamenames();
my $in_glist = $self->get_listedstats();
# list of unique gamenames
my %games; $games{$_->[0]} = 1 for (@{$in_slist}, @{$in_glist});
# update stats per gamename
for my $gamename (sort keys %games) {
# get statistics per game
my $num = $self->get_gamestats($gamename)->[0];
# update in db
my $u = $self->write_stat(
gamename => $gamename,
num_uplink => $num->{num_uplink} || 0,
num_total => $num->{num_total} || 0,
);
# log stats too
if ( int($u) > 0) {
# log the statistics
$self->log("update", "updated stats ($num->{num_uplink}/$num->{num_total}) for $gamename");
} else {
# report unable to update stats
$self->log("error", "can not update stats for $gamename");
}
}
# notify
$self->log("stat", "updated all game statistics");
}
1;
|