"#000000", 1 => "#ff0000", 2 => "#00ff00", 3 => "#ffff00", 4 => "#0000ff", 5 => "#00ffff", 6 => "#ff00ff", 7 => "#ffffff", 8 => "#ff7f00", 9 => "#7f7f7f", 10 => "#bfbfbf", 11 => "#bfbfbf", 12 => "#007f00", 13 => "#7f7f00", 14 => "#00007f", 15 => "#7f0000", 16 => "#7f3f00", 17 => "#ff9919", 18 => "#007f7f", 19 => "#7f007f", 20 => "#007fff", 21 => "#7f00ff", 22 => "#3399cc", 23 => "#ccffcc", 24 => "#006633", 25 => "#ff0033", 26 => "#b21919", 27 => "#993300", 28 => "#cc9933", 29 => "#999933", 30 => "#ffffbf", 31 => "#ffff7f" ); function getstatus($server, $port = 27960) { if (!($fd = @fsockopen("udp://$server", $port, $errno, $errstr, 3))) return FALSE; stream_set_timeout($fd, 3, 0); # challenge? fwrite($fd, "\xff\xff\xff\xffgetstatus " . rand()); # getstatus reply should always come as a single (possibly # fragmented) datagram if (!($buf = @fread($fd, 4096))) { echo("failed"); return FALSE; } $parts = explode("\n", $buf); if ($parts[0] != "\xff\xff\xff\xffstatusResponse") { echo("bad response"); return FALSE; } # build an array of all the serverinfo keys $infostring = explode("\\", $parts[1]); array_shift($infostring); $side = 0; while (list($idx, $str) = each($infostring)) { if ($side == 0) $key = $str; else $info[$key] = $str; $side ^= 1; } # build an array of all the players # start by shifting off the response header and the serverinfo array_shift($parts); array_shift($parts); # and then looping through what's left while (list($idx, $str) = each($parts)) { if ($str == "") break; $playerparts = explode("\"", $str); $playerinfo = $playerparts[0]; $name = $playerparts[1]; $scoreping = explode(" ", $playerinfo); $score = $scoreping[0]; $ping = $scoreping[1]; # try to get slot and team info list($slot, $team) = correlateplayerinfo($info, $idx); $playerlist[$idx]['slot'] = $slot; $playerlist[$idx]['team'] = $team; $playerlist[$idx]['score'] = $score; $playerlist[$idx]['ping'] = $ping; $playerlist[$idx]['name'] = $name; } return array(info => $info, players => $playerlist); } function correlateplayerinfo($info, $num) { if ($info['P'] != '') { $infonum = 0; for ($x = 0; $x < strlen($info['P']); $x++) { $cur = $info['P'][$x]; if ($cur == '-') continue; if ($infonum == $num) return array($x, $cur); $infonum++; } } else if ($info['Players_Allies'] != '' || $info['Players_Axis'] != '') { # This method of listing players isn't accurate. If a # spectator or connecting client is in a slot where players # who are actually on a team follow, it'll be impossible to # match things up properly. As such, I can't be arsed to # actually support this right now. } return array(-1, -1); } function colorize($text) { global $osp_colors; $curcolor = -1; $nextcolor = 7; for ($x = 0; $x < strlen($text); $x++) { if ($text[$x] == '^' && $text[$x + 1] != '^') { $nextcolor = (ord($text[$x + 1]) + 16) & 31; $x++; continue; } if ($curcolor != $nextcolor) { if ($curcolor != -1) $buf .= ""; $curcolor = $nextcolor; $buf .= sprintf("", $osp_colors[$curcolor]); } $buf .= htmlspecialchars($text[$x]); } if ($curcolor != -1) $buf .= ""; return $buf; } function teamname($num) { switch ($num) { case 0: return "Connecting"; case 1: return "Axis"; case 2: return "Allies"; default: return "Spectators"; } } function sort_by_score_desc($a, $b) { if ($a['score'] == $b['score']) return 0; return ($a['score'] > $b['score']) ? -1 : 1; } function sort_by_team($a, $b) { if ($a['team'] == $b['team']) return 0; return ($a['team'] > $b['team']) ? 1 : -1; } ?> blah! \n", colorize($status['info']['sv_hostname'])); printf("Map: %s
\n", colorize($status['info']['mapname'])); echo "\n"; echo "\n"; if ($status['players']) { if ($_GET['sort'] == 'team') uasort($status['players'], sort_by_team); else if ($_GET['sort'] != 'id') uasort($status['players'], sort_by_score_desc); while (list($idx, $curplayer) = each($status['players'])) { # echo "Player $idx: " . htmlentities(serialize($curplayer)) . "
\n"; printf(" \n", $curplayer['slot'], colorize($curplayer['name']), teamname($curplayer['team']), $curplayer['score'], $curplayer['ping']); } } ?>
#nameteamscoreping
%d%s%s%d%d