tyty!
yup works for windows and linux!
tyty!
yup works for windows and linux!
fix for the parser:
<?php
class parser {
private $logfile = false;
private $parsedloglines = 0;
private $logpos = 0;
private $lastparsed = "0000000000";
public function __construct($logfile, &$success) {
if (!is_readable($logfile)) {
$success = false;
return;
}
$this->logfile = $logfile;
$this->logpos = filesize($this->logfile);
$succes = true;
}
public function getNewLines() {
$fp = fopen($this->logfile, "r");
fseek($fp, $this->logpos, SEEK_SET);
$newlines = array();
while (!feof($fp)) {
$get = fgets($fp);
if ($get === false) {
break;
}
$this->logpos += strlen($get);
$newlines[] = $get;
}
fclose($fp);
return $newlines;
}
public function parseLine($line) {
$pattern = '|^\s*(\d{10}) |';
if (preg_match($pattern, $line, $subpatterns) == 0) {
return false;
}
$lasttime = (int) $this->lastparsed;
$thistime = (int) $subpatterns[1];
if ($lasttime > $thistime) {
$restart = true;
}
else {
$restart = false;
}
$this->lastparsed = $subpatterns[1];
$this->parsedloglines ++;
$line = trim(str_replace($subpatterns[0], "", $line));
$action = $this->getAction($line);
return array(
"timestamp" => $this->lastparsed,
"line" => $line,
"action" => $action,
"parsed" => $this->parseParts($line, $action),
"serverrestart" => $restart,
);
}
private function getAction($line) {
$actions = array(
"damage" => "D;",
"vehicledamage" => "VD;",
"actordamage" => "AD;",
"kill" => "K;",
"join" => "J;",
"quit" => "Q;",
"say" => "say;",
"sayteam" => "sayteam;",
"weapon" => "Weapon;",
"nextmap" => "InitGame:",
"exitmap" => "ShutdownGame:",
"mapend" => "ExitLevel: executed"
);
foreach ($actions as $key => $value) {
if (strpos($line, $value) === 0) {
return $key;
}
}
return "unknown";
}
private function parseParts($line, $action) {
switch ($action) {
case "damage":
case "weapon":
case "kill":
case "join":
case "quit":
case "vehicledamage":
case "actordamage":
$parts = explode(";", $line);
array_shift($parts);
return $parts;
case "say":
case "sayteam";
$parts = explode(";", $line, 5);
array_shift($parts);
if ($parts[3]{0} == chr(21)) {
$parts[3] = substr($parts[3], 1);
}
return $parts;
case "mapend":
case "exitmap":
return false;
case "nextmap":
$explode = explode("\\", $line);
$parts = array();
for($i = 1; $i < count($explode); $i += 2) {
$parts[$explode[$i]] = $explode[$i + 1];
}
return $parts;
default:
return false;
}
}
public function getLastParsedTimeStamp() {
return $this->lastparsed;
}
}
Alles anzeigen
testing to make sure this works on windows...