aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Core/Stats.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2017-08-22 11:00:13 +0200
committerDarkelarious <darkelarious@333networks.com>2017-08-22 11:00:13 +0200
commitc06322da38b4cb76b2036af1a5448083adb8ff20 (patch)
tree189c9f0fec3325be927f763aba23cf18aa68cfe4 /lib/MasterServer/Core/Stats.pm
parente0d727670cbeda0db0812c5c9efc503d75f8d0a4 (diff)
downloadMasterServer-Perl-c06322da38b4cb76b2036af1a5448083adb8ff20.tar.gz
MasterServer-Perl-c06322da38b4cb76b2036af1a5448083adb8ff20.zip
new server checking mechanism, complete recode of major functionsv2.4.0
Diffstat (limited to 'lib/MasterServer/Core/Stats.pm')
-rwxr-xr-xlib/MasterServer/Core/Stats.pm48
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;