diff options
Diffstat (limited to 'lib/MasterServer/Core/Stats.pm')
| -rwxr-xr-x | lib/MasterServer/Core/Stats.pm | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/MasterServer/Core/Stats.pm b/lib/MasterServer/Core/Stats.pm index 8e9eb95..4f23723 100755 --- a/lib/MasterServer/Core/Stats.pm +++ b/lib/MasterServer/Core/Stats.pm @@ -4,7 +4,6 @@ use strict; use warnings; use AnyEvent::IO; use Exporter 'import'; - our @EXPORT = qw| update_stats |; ################################################################################ @@ -13,25 +12,38 @@ our @EXPORT = qw| update_stats |; sub update_stats { my $self = shift; - # get all gamenames where there is one or more servers online and update the - # stats per gamename. - my $games = $self->get_gamelist_stats(); - - # iterate through available stats - for my $e (@{$games}) { + # 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]; - # extract gamename, number of direct uplinks and total servers - my %opt = (); - $opt{gamename} = $e->[0]; - $opt{num_uplink} = $e->[1]; - $opt{num_total} = $e->[2]; - - # write to DB - $self->write_stat(%opt); + # 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"); + } } - - # done - $self->log("stat", "Updated all game statistics."); + + # notify + $self->log("stat", "updated all game statistics"); } 1; |
