Skip to content

Instantly share code, notes, and snippets.

@demogar
Created August 19, 2010 19:46
Show Gist options
  • Save demogar/538726 to your computer and use it in GitHub Desktop.
Save demogar/538726 to your computer and use it in GitHub Desktop.
<?php
// (...)
public function get_stats() {
# Open file
$log = fopen($this->config->item('archivos_path') . $this->file, 'r');
$players = array();
# If file exists, read it
if ($log) {
# Mientras se pueda leer, set el buffer
while (! feof($log)) {
$buffer = fgets($log);
# Date, game, version
if (preg_match('/^L ([^ -]+).*game "([^"]+)".*version "([^"]+)"/', $buffer, $part)) {
$this->server->date = $part[1];
$this->server->game = $part[2];
$this->server->version = $part[3];
}
# Delete L x/x/x - x:x:x: from the log
$buffer = preg_replace('/^L.*: /', '', $buffer);
# Frag
if (preg_match('/^"([^"]+)" ([^"\(]+) "([^"]+)" [^"\(]+ "([^"]+)"(.*)$/', $buffer, $part)) {
# Variables
$s_killer = $part[1];
$s_action = $part[2];
$s_victim = $part[3];
$s_weapon = $part[4];
# Killer info
preg_match('/^(.+)<([^<>]*)><([^<>]*)><([^<>]*)>/', $part[1], $killer_info);
$killer_id = $killer_info[3];
# Victim info
preg_match('/^(.+)<([^<>]*)><([^<>]*)><([^<>]*)>/', $part[3], $victim_info);
$victim_id = $victim_info[3];
# Add stat to the killer
@$data['players'][$killer_id]['frags']++;
@$data['players'][$killer_id]['frags_by_gun'][$s_weapon]++;
@$data['players'][$killer_id]['points'] += $this->points($s_weapon);
# Add stat to the victim
@$data['players'][$victim_id]['deaths']++;
@$data['players'][$victim_id]['deaths_by_gun'][$s_weapon]++;
}
}
fclose($log);
}
return $data;
}
// (...)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment