[TSA] Psychiccyberfreak wrote:I think a group of us should get together and write a really kick ass stats parser with a subversion repo or something..
I'm down for this. A few weeks ago I was having a look at the server log parser that look likes the one you based your script off of... and after commenting the crap out of / redesigning the front end, I decided a mysql solution would be better.
I talked to my buddy about this and he said he knew a great way, using a fifo file to be a liaison between the server and the database. Long story short, it's been over 2 weeks since he last worked on it and it'd be great if we could get some community solution.
Here is a (I believe to be working) class file he wrote to parse the stats... however, I think he was having trouble with actually inserting the data to the database.
- Code: Select all
class NexuizStats {
function processMatch($data) {
$match = array();
foreach ($data as $score_line) {
$info = explode(":",trim($score_line,":"));
switch ($info[0]) {
case "scores":
$match['match']['map'] = $info[1];
$match['match']['length'] = $info[2];
break;
case "player":
$match['players'][] = self::playerStats($info);
break;
default:
break;
}
}
foreach ($match['players'] as $p) {
$positions_arr[$p['frags']] = $p['name'];
}
krsort($positions_arr);
$match['game']['first_place'] = array_shift($positions_arr);
$match['game']['second_place'] = array_shift($positions_arr);
$match['game']['third_place'] = array_shift($positions_arr);
return $match;
}
function playerStats($info) {
$player=array();
$player['name'] = $info[5];
$player['team'] = self::translateTeam($info[4]);
$player['frags'] = $info[1];
$player['deaths'] = $info[2];
$player['playtime'] = $info[3];
return $player;
}
function translateTeam($team_id) {
$teams = array(5 => "Red", 14 => "Blue");
if (!isset($teams[$team_id])) {
return FALSE;
}
return $teams[$team_id];
}
function addMatch($match) {
$db = new DB();
$SQL = "INSERT INTO matches(mid, map, gametime) VALUES ('', '" . mysql_escape_string($match['map']) . "','" . mysql_escape_string($match['length']) . "')";
$mid = $db->insert($SQL);
echo $mid;
return $mid;
}
function addPlayers($players) {
$db = new DB("nn_stats");
foreach ($players as $p) {
if (self::findPlayer($p['name'])) {
self::updatePlayer($p['name']);
} else {
$SQL = "INSERT INTO players(uid, player_name, playtime, matches, total_frags, total_deaths) VALUES ('','" . mysql_escape_string($p['name'])
. "','" . mysql_escape_string($p['playtime'])
. "','1','" . mysql_escape_string($p['frags'])
. "','" . mysql_escape_string($p['deaths'])
. "')";
$uid = $db->insert($SQL);
self::updateLastGame($uid, $p);
}
}
}
function updateLastGame($uid, $p) {
return false;
}
function findPlayer($pid) {
return FALSE;
}
function updatePlayer($pid) {
return TRUE;
}
// END nexstats-functions
I would love to ask him where he's at in the code but he's being a bit of a dolt right now, so I figured I'd share this with the group.
Here's a basic function I wrote to color the names, it doesn't close the tags and therefore doesn't validate but I didn't really care to putting much thought into parsing it properly as it probably requires exploding by some crazy regex.
- Code: Select all
// Converts ^0 to Black etc.
// cheap hack
function colorsToCss($string) {
$nexuiz = array('^0','^1','^2','^3','^4','^5','^6','^7','^8','^9');
$css = array(
'<span style="color:#000;">',
'<span style="color:#f00;">',
'<span style="color:#0f0;">',
'<span style="color:#ff0;">',
'<span style="color:#00f;">',
'<span style="color:#3ff;">',
'<span style="color:#f0f;">',
'<span style="color:#fff;">',
'<span style="color:#bbb;">',
'<span style="color:#777;">'
);
return str_replace($nexuiz, $css, $string);
}
Lastly, here's the code I use on www.nexuizninjaz.com, which looked good until some jackass with a long name broke the floats

And here's the map images if you need/want them.