aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Util/KFStatsWatcher.pm
blob: d78fbf94c557d2ee87e7dc29c8ce66a13cad05a9 (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
package MasterServer::Util::KFStatsWatcher;

use strict;
use warnings;
use AnyEvent::IO;
use Exporter 'import';
our @EXPORT = qw| read_kfstats |;

################################################################################
## Read Killing Floor Statistics from the file.
################################################################################
sub read_kfstats {
  my $self = shift;

  # open file and read content
  return aio_load($self->{kfstats_file}, 
    sub {
      my $f = shift;
      my $block = "";
              
      # read player stats
      for my $l (split /^/, $f) {
        # add data to "player" block
        $block .= $l;
        
        # if block contains last item GamesLost, process block
        if ($l =~ m/^(GamesLost=)/i){
          my @s = split "\n", $block;

          # process items
          my %h;
          for my $m (@s) {
            if ($m =~ m/(KFPlayerStats\])$/i) {
              $h{UTkey} = substr $m, 1, index($m, " ")-1;}
            if ($m =~ m/=/) {
              $h{substr $m, 0, index($m, "=")} = substr $m, index($m, "=")+1;}
          }
          $self->write_kfstats(\%h);
          $block = "";
        }
      }
      $self->log("kfstat", "Updated Killing Floor player stats.");
    }
  );
}

1;