I have a script that parses a log file for a game (used for replays). It contains most of the actions in the game such as movements, kills, deaths, etc.
I've been using this script for a while but now I'm working on a stats site using Codeigniter and I'm getting a lot of error notices and I'm not sure why.
The exact error is Message: Undefined offset: 3
The lines it's referring to are the lines in the team case that have $message[3] in them.
Here's the script:
$f = fopen($full_path,"r");
while ($line = fgets($f))
{
$line = str_replace("ööööö", " ",trim($line)); // these characters are found in win replay files
$line = str_replace("ššššš", " ", $line); // these characters are found in mac replay files
$message = explode(" ",$line);
$lasttimestamp = $message[sizeof($message)-1];
if ($message[0]=="PLAYERSENT" || $message[0]=="TCPSENT")
{
array_shift($message);
$swapfield = $message[0];
$message[0] = $message[1];
$message[1] = $swapfield;
}
switch ($message[0])
{
case "team": // team (player id) (team)
$name = $names[$message[1]];
if ($message[2]>-1) $players[$name]['Played'] = true;
$players[$name]['Sessions'][] = array("Team"=>$players[$name]['Team'],"TimeSpent"=>($message[3]-$players[$name]['LastTimeStamp']));
if ($players[$name]['Team']>-1) $players[$name]['TotalTime'] += $message[3]-$players[$name]['LastTimeStamp'];
$players[$name]['Team'] = $message[2];
$players[$name]['LastTimeStamp'] = $message[3];
break;
default:
}
}
fclose($f);
The case matches lines that look like this:
team 4 -1ööööö57167168
As seen in the script, the ööööö
characters are replaced with a space, so it should become team 4 -1 57167168
, so $message[3] should be showing me the timestamp 57167168
I can't figure out why it's giving me the notices for this, any ideas how can fix this?