"; $curcolor = $nextcolor; $buf .= sprintf("", $color[$curcolor]); } // $buf .= htmlspecialchars($text[$x]); $buf .= $text[$x]; } if ($curcolor != -1) { $buf .= ""; } return $buf; } function getValue($cvar) { for ($i = 0; $i <= count($GLOBALS['settings']); $i++) { if (strtolower($GLOBALS['settings'][$i]['cvar']) == strtolower($cvar)) { return $GLOBALS['settings'][$i]['value']; break; } } } function getMap($bsp) { for ($i = 0; $i < count($GLOBALS['mapinfo']); $i++) { if ($GLOBALS['mapinfo'][$i]['bsp'] == $bsp) { return $GLOBALS['mapinfo'][$i]['name']; break; } } } function getServers($master,$proto) { if (isset($master) && isset($proto)) { if (!($fp = fsockopen('udp://'.$master, 27950, $errno, $errstr))) return "socket error"; stream_set_timeout($fp, 3); fwrite($fp, "\xFF\xFF\xFF\xFFgetservers $proto full empty\x0A"); $response = ""; while ( $buffer = fread($fp,1000) ) { $response .= $buffer; } fclose($fp); $serverlist = str_replace("\x5CEOT\x00\x00\x00","",$response); $serverlist = str_replace("\x5CEOT","",$serverlist); $serverlist = str_replace("\xFF\xFF\xFF\xFFgetserversResponse","",$serverlist); for( $listecnt=0 ; ($listecnt * 7) < strlen($serverlist) ; $listecnt++ ) { $server = substr($serverlist,($listecnt * 7),7); $eintrag[] = ord(substr($server,1)) . '.' . ord(substr($server,2)) . '.' . ord(substr($server,3)) . '.' . ord(substr($server,4)) . ':' . ((ord(substr($server,5)) * 256) + ord(substr($server,6))); } /* // Begin Test $ServerList = array(); for($i=0;$i $eintrag[$i] ) , $ServerInfo); } else { $ServerList[] = $ServerInfo; } } // End Test */ if (isset($eintrag)) { return $eintrag; } else { return false; } } else { return false; } } function getInfo($server) { $server = explode(":",$server); $ip = $server[0]; $port = $server[1]; if ($ip == "86.59.121.243") { $ip = "192.168.61.1"; } if (!($fp = fsockopen('udp://'.$ip, $port, $errno, $errstr))) return "socket error"; stream_set_timeout($fp, 3); fwrite($fp, "\xFF\xFF\xFF\xFFgetinfo\x0A"); if (!($inforesponse = fread($fp, 4096))) { return "no infoResponse"; } fclose($fp); if (substr($inforesponse,0,16) != "\xff\xff\xff\xffinfoResponse") { return "getInfo failed"; } $info = explode("\x5C",str_replace("\xFF\xFF\xFF\xFFinfoResponse\x0A\x5C","",$inforesponse)); for ($i = 0; $i*2 < count($info); $i++) { $serverinfo[$info[$i*2]] = $info[($i*2)+1]; } if (isset($serverinfo['hostname'])) { $serverinfo['hostname'] = substr($serverinfo['hostname'],0,50); } else { $serverinfo['hostname'] = ""; } if (! isset($serverinfo['gamename'])) { $serverinfo['gamename'] = "wolfmp"; } if (! isset($serverinfo['game'])) { if ($serverinfo['gamename'] == "et") { $serverinfo['game'] = "etmain"; } if ($serverinfo['gamename'] == "wolfmp") { $serverinfo['game'] = "main"; } } return $serverinfo; } function getStatus($server) { if (! isset($server)) { return "no server given"; } $serveraddr = explode(":",$server); $ip = $serveraddr[0]; $port = $serveraddr[1]; if ($ip == "86.59.121.243") { $ip = "192.168.61.1"; } if (!($fp = fsockopen('udp://'.$ip, $port, $errno, $errstr, 3))) return "socket error"; stream_set_timeout($fp, 3); # challenge? fwrite($fp, "\xff\xff\xff\xffgetstatus\x0A"); # getstatus reply should always come as a single (possibly fragmented) datagram if (!($statusresponse = fread($fp, 4096))) { return "no statusResponse"; } fclose($fp); $status = explode("\n", $statusresponse); if ($status[0] != "\xff\xff\xff\xffstatusResponse") { return "getStatus failed"; } # build an array of all the serverinfo keys $info = explode("\x5C", $status[1]); array_shift($info); for ($i = 0; $i*2 < count($info); $i++) { $serverstatus[$info[$i*2]] = $info[($i*2)+1]; } $serverstatus = array_merge( getInfo($server) , $serverstatus ); # build an array of all the players # start by shifting off the response header and the serverinfo array_shift($status); array_shift($status); # and then looping through what is left while (list($idx, $str) = each($status)) { 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($serverstatus, $idx); if ($team == "5") { if ($ping == 999) { $team = "0"; } else { $team = "3"; } } if ($team == "-1") { $team = "empty"; } if ($team == "0") { $team = "connect"; } if ($team == "1") { $team = "axis"; } if ($team == "2") { $team = "allied"; } if ($team == "3") { $team = "spec"; } $playerlist[$idx]['slot'] = $slot; $playerlist[$idx]['side'] = $team; $playerlist[$idx]['score'] = $score; $playerlist[$idx]['ping'] = $ping; $playerlist[$idx]['name'] = $name; } return array('status' => $serverstatus, 'players' => $playerlist); } function correlateplayerinfo($info, $num) { if (isset($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++; } } elseif ( isset($info['Players_Allies']) || isset($info['Players_Axis']) ) { $slotsred = explode(" ", $info['Players_Axis']); $slotsblue = explode(" ", $info['Players_Allies']); if (in_array($num, $slotsred)) { return array($num, "1"); } elseif (in_array($num, $slotsblue)) { return array($num, "2"); } else { return array($num, "5"); } } return array($num, "-1"); } ?> Server-Info