aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Util
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2016-11-19 20:56:04 +0100
committerDarkelarious <darkelarious@333networks.com>2016-11-19 20:56:04 +0100
commitc3f8d65a4fb1f5674557ee67cf7f74369df86ad1 (patch)
tree92aab2a394bda28da0ed7c7c75e633fdf386fc71 /lib/MasterServer/Util
parent1de3da4b8027508a91144639455c934fd6ccb9b7 (diff)
downloadMasterServer-Perl-c3f8d65a4fb1f5674557ee67cf7f74369df86ad1.tar.gz
MasterServer-Perl-c3f8d65a4fb1f5674557ee67cf7f74369df86ad1.zip
Massive improvements on efficiency, robustness, security, reliability and more
Diffstat (limited to 'lib/MasterServer/Util')
-rwxr-xr-xlib/MasterServer/Util/KFStatsWatcher.pm59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/MasterServer/Util/KFStatsWatcher.pm b/lib/MasterServer/Util/KFStatsWatcher.pm
new file mode 100755
index 0000000..916446e
--- /dev/null
+++ b/lib/MasterServer/Util/KFStatsWatcher.pm
@@ -0,0 +1,59 @@
+
+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;
+
+ # process player data as blocks
+ my $block = "";
+
+ # read player stats
+ for my $l (split /^/, $f) {
+
+ # add data to block
+ $block .= $l;
+
+ # if block contains last item GamesLost, process block
+ if ($l =~ m/^(GamesLost=)/i){
+
+ # treat as array
+ 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; }
+ }
+
+ # store in db
+ $self->write_kfstats(\%h);
+
+ # clear block for next player
+ $block = "";
+ }
+ }
+
+ #notify
+ $self->log("kfstat", "Updated Killing Floor player stats.");
+ }
+ );
+}
+
+
+1;