Мониторинг одного сервера, Помогите доработать функцию |
Здравствуйте, гость Вход | Регистрация
Наши новости:
|
|
|
Мониторинг одного сервера, Помогите доработать функцию |
rafic
|
8.2.2013, 0:34
Сообщение
|
|
|
Приветствую тебя, дорогой друг!
Недавно захотелось мне вывести статистику моего сервера на сайт и начал я искать скрипт мониторинга. В интернете, да и на этом форуме в соседней теме, куча мощных скриптов мониторинга. Но мне они не к чему, так как у меня всего лишь один сервер. Решил писать сам, тем более что я веб-разработчик. Нашел я заветную страничку и погуглив я даже нашел уже готовые функции. Завернув их в класс я получил довольно функциональный инструмент для организации мониторинга. НО, запустить функцию A2S_RULES - получение настроек сервера, у меня так и не вышло. Кто может сказать почему и что нужно сделать чтобы она заработала? Сейчас она не выводит ничего=( Скрытый текст Код <? class CS_Server { private function cutchar(&$string){ $char = substr($string, 0, 1); $string = substr($string, 1); return $char; } private function cutbyte(&$string){ $byte = ord(substr($string, 0, 1)); $string = substr($string, 1); return $byte; } private function cutstring(&$string){ $str = substr($string, 0, StrPos($string, chr(0))); $string = substr($string, StrPos($string, chr(0))+1); return $str; } private function cutshort(&$string){ $short = substr($string, 0, 2); list(,$short) = @unpack("S", $short); $string = substr($string, 2); return $short; } private function cutlong(&$string){ $long = substr($string, 0, 4); list(,$long) = @unpack("l", $long); $string = substr($string, 4); return $long; } private function pastelong($long){ return pack("l", $long); } private function cutfloat(&$string){ $float = substr($string, 0, 4); list(,$float) = @unpack("f", $float); $string = substr($string, 4); return $float; } private function request($request,$host,$port){ $request = "\xFF\xFF\xFF\xFF".$request."\x00"; $fp = @fsockopen('udp://'.$host, $port); if (!$fp) return false; @fwrite($fp, $request); socket_set_timeout($fp,1); $string=fread($fp,1); $socket_status=socket_get_status($fp); $socket_status=$socket_status["unread_bytes"]; if ($socket_status == 0){ @fclose($fp); return false; } $string.=fread($fp,$socket_status); @fclose($fp); return $string; } public function A2A_PING($host, $port) { $st = $this->request("\x69",$host,$port); if (!$st) return false; $st = substr($st, 4); if (substr($st, 0, 1) != "\x6A") return false; else return true; } public function A2S_INFO($host, $port) { $st = $this->request("\x54Source Engine Query",$host,$port); if (!$st) return false; $st = substr($st, 4); if (substr($st, 0, 1) == "\x49") { $result['Type'] = $this->cutchar($st); // Char: 'I' (0x49) - For Source $result['Version'] = $this->cutbyte($st); // Byte: Network version $result['Server Name'] = $this->cutstring($st); // String: The server's name, eg: "Recoil NZ CS Server #1" $result['Map'] = $this->cutstring($st); // String: The current map being played, eg: "de_dust" $result['Game Directory'] = $this->cutstring($st); // String: The name of the folder containing the game files, eg: "cstrike" $result['Game Description'] = $this->cutstring($st); // String: A friendly string name for the game type, eg: "Counter Strike: Source" $result['AppID'] = $this->cutshort($st); // Short: Steam Application ID $result['Number of players'] = $this->cutbyte($st); // Byte: The number of players currently on the server $result['Maximum players'] = $this->cutbyte($st); // Byte: Maximum allowed players for the server $result['Number of bots'] = $this->cutbyte($st); // Byte: Number of bot players currently on the server $result['Dedicated'] = $this->cutchar($st); // Char: 'l' for listen, 'd' for dedicated, 'p' for SourceTV $result['OS'] = $this->cutchar($st); // Char: Host operating system. 'l' for Linux, 'w' for Windows $result['Password'] = $this->cutbyte($st); // Byte: If set to 0x01, a password is required to join this server $result['Secure'] = $this->cutbyte($st); // Byte: if set to 0x01, this server is VAC secured $result['Game Version'] = $this->cutstring($st); // String: The version of the game, eg: "1.0.0.14" } elseif (substr($st, 0, 1) == "\x6D") { $result['Type'] = $this->cutchar($st); // Char: 'm' (0x6D) - For GoldSrc $result['Game IP'] = $this->cutstring($st); // String: Game Server IP address and port $result['Server Name'] = $this->cutstring($st); // String: The server's name, eg: "Recoil NZ CS Server #1" $result['Map'] = $this->cutstring($st); // String: The current map being played, eg: "de_dust" $result['Game Directory'] = $this->cutstring($st); // String: The name of the folder containing the game files, eg: "cstrike" $result['Game Description'] = $this->cutstring($st); // String: A friendly string name for the game type, eg: "Counter Strike: Source" $result['Number of players'] = $this->cutbyte($st); // Byte: The number of players currently on the server $result['Maximum players'] = $this->cutbyte($st); // Byte: Maximum allowed players for the server $result['Version'] = $this->cutbyte($st); // Byte: Network version $result['Dedicated'] = $this->cutchar($st); // Char: 'l' for listen, 'd' for dedicated, 'p' for SourceTV $result['OS'] = $this->cutchar($st); // Char: Host operating system. 'l' for Linux, 'w' for Windows $result['Password'] = $this->cutbyte($st); // Byte: If set to 0x01, a password is required to join this server $result['IsMod'] = $this->cutbyte($st); // Byte: If set to 0x01, this byte is followed by ModInfo $result['Secure'] = $this->cutbyte($st); // Byte: if set to 0x01, this server is VAC secured $result['Number of bots'] = $this->cutbyte($st); // Byte: Number of bot players currently on the server if ($result['IsMod'] == 1) { $result['URLInfo'] = $this->cutstring($st); // String: URL containing information about this mod $result['URLDL'] = $this->cutstring($st); // String: URL to download this mod $result['Nul'] = $this->cutbyte($st); // Byte: 0x00 $result['ModVersion'] = $this->cutlong($st); // Long: Version of the installed mod $result['ModSize'] = $this->cutlong($st); // Long: The download size of this mod $result['SvOnly'] = $this->cutbyte($st); // Byte: If 1 this is a server side only mod $result['ClDLL'] = $this->cutbyte($st); // Byte: If 1 this mod has a custom client dll } } else return false; return $result; } public function A2S_SERVERQUERY_GETCHALLENGE($host, $port){ $st = $this->request("\x57",$host,$port); if (!$st) return false; $st = substr($st, 4); if (substr($st, 0, 1) != "\x41") return false; else return $this->cutlong(substr($st, 1)); } public function A2S_RULES($host, $port) { $challenge = $this->A2S_SERVERQUERY_GETCHALLENGE($host, $port); $st = $this->request("\x56". $this->pastelong($challenge),$host,$port); if (!$st) return false; $st=substr($st, 4); if (substr($st, 0, 1) == "\x41") { $orolbi = substr($st, 1); $challenge = $this->cutlong($orolbi); $st = $this->request("\x56". $this->pastelong($challenge),$host,$port); if (!$st) return false; $st = substr($st, 4); } if (substr($st, 0, 1) != "\x45") return false; $result['Type'] = $this->cutchar($st); // Char: Should be equal to 'E' $result['Num Rules'] = $this->cutshort($st); // Short: The number of rules reported in response for ($i = 1; $i <= $result['Num Rules']; $i++) { $result['Rule Name'][$i] = $this->cutstring($st); // String: The name of the rule $result['Rule Value'][$i] = $this->cutstring($st); // String: The rule's value } return $result; } public function A2S_PLAYER($host, $port) { $challenge = $this->A2S_SERVERQUERY_GETCHALLENGE($host, $port); $st = $this->request("\x55". $this->pastelong($challenge),$host,$port); if (!$st) return false; $st = substr($st, 4); if (substr($st, 0, 1) == "\x41") { $orolbi = substr($st, 1); $challenge = $this->cutlong($orolbi); $st = $this->request("\x55". $this->pastelong($challenge),$host,$port); if (!$st) return false; $st = substr($st, 4); } if (substr($st, 0, 1) != "\x44") return false; $result['Type'] = $this->cutchar($st); // Char: Should be equal to 'D' $result['Num Players'] = $this->cutbyte($st); // Byte: The number of players reported in response for ($i = 1; $i <= $result['Num Players']; $i++) { $result['Index'][$i] = $this->cutbyte($st); // Byte: The index into [0.. Num Players] for this entry $result['Player Name'][$i] = $this->cutstring($st); // String: Player's name $result['Kills'][$i] = $this->cutlong($st); // Long: Number of kills this player has $result['Time connected'][$i] = $this->cutfloat($st); // Float: The time in seconds this player has been connected } return $result; } } $cs_server = new CS_Server; echo "<br/><br/>"; print_r($cs_server->A2S_INFO("0.0.0.0",27015)); echo "<br/><br/>"; print_r($cs_server->A2S_RULES("0.0.0.0",27015)); echo "<br/><br/>"; print_r($cs_server->A2S_PLAYER("0.0.0.0",27015)); echo "<br/><br/>"; print_r($cs_server->A2A_PING("0.0.0.0",27015)); ?> Конкретно, проблема заключается в том, что функция возвращает false, а не результат. И происходит это вот на этом условии Код if (substr($st, 0, 1) != "\x45") return false; Я не совсем разобрался что оно проверяет, поэтому не могу решить поставленную задачу.
Отредактировал: rafic, - 8.2.2013, 7:23
|
|
|
|
jtiq
|
8.2.2013, 8:56
Сообщение
|
![]() ![]() |
rafic, не парься
|
Поблагодарили 1 раз
|
|
![]() ![]() |