Форум: Форум PHPФорум ApacheФорум Регулярные ВыраженияФорум MySQLHTML+CSS+JavaScriptФорум FlashРазное
Новые темы: 0000000
MySQL на примерах. Авторы: Кузнецов М.В., Симдянов И.В. C++. Мастер-класс в задачах и примерах. Авторы: Кузнецов М.В., Симдянов И.В. PHP 5. На примерах. Авторы: Кузнецов М.В., Симдянов И.В., Голышев С.В. PHP Puzzles. Авторы: Кузнецов М.В., Симдянов И.В. MySQL 5. В подлиннике. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ

Форум PHP

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум (новые сообщения вниз) Структурный форум

тема: Тестирование сервера

Сообщения:  [1-10] 

 
 автор: t3ma   (15.04.2007 в 08:25)   письмо автору
 
   для: madmo3r   (14.04.2007 в 12:22)
 

Для этого нужно обмениваться пакетами с сервером counter-strike.

Нпример:

fputs($socket, "данные")

   
 
 автор: madmo3r   (14.04.2007 в 12:22)   письмо автору
 
   для: maDMo3r   (11.04.2007 в 14:25)
 

АП!.. что никто не может помочь ? =)

   
 
 автор: maDMo3r   (11.04.2007 в 14:25)   письмо автору
 
   для: Trianon   (10.04.2007 в 18:23)
 

Спасибо Понял.. :)) Помогите сделать тогда правильно :D

   
 
 автор: Trianon   (10.04.2007 в 18:23)   письмо автору
 
   для: maDMo3r   (10.04.2007 в 16:25)
 

udp - протокол без ответа Так называемый "выстрелил и забыл" .
Главное отправить. А попал ли, а если попал, то в кого, уже совершенно неважно.

   
 
 автор: maDMo3r   (10.04.2007 в 16:54)   письмо автору
 
   для: Unkind   (10.04.2007 в 16:44)
 

Исправил.. но не проконало :)

   
 
 автор: Unkind   (10.04.2007 в 16:44)   письмо автору
 
   для: maDMo3r   (10.04.2007 в 16:25)
 

Замените строку
if ($socket === false)
на
if ($socket == false)

fsockopen возвращает integer, а не boolean.

   
 
 автор: maDMo3r   (10.04.2007 в 16:25)   письмо автору
 
   для: maDMo3r   (10.04.2007 в 16:05)
 


<?php
function test_server($host, $port, $queryport)
    {
        $socket = fsockopen('udp://'. $host, $port, $errno, $errstr, 3);
            if ($socket === false)
               {
                echo "Error: $errno - $errstr<br>\n";
            }
        else
        {
            echo "Online";
        }
            fclose($socket);
    }
   test_server("194.50.85.251","27015","27015");
?>

Почему-то всегда онлайн :))) Если даже написать другой ип.. будет Online =\

   
 
 автор: maDMo3r   (10.04.2007 в 16:05)   письмо автору
 
   для: t3ma   (10.04.2007 в 15:54)
 

Многовато :)) Но спасибо.. попробую разобраться.. ;)

   
 
 автор: t3ma   (10.04.2007 в 15:54)   письмо автору
 
   для: madmo3r   (10.04.2007 в 15:50)
 

пожалуйста...


<? 
/*****************************************************************************************************************************/ 
class cs_stat{ 
    var $maxlen = 2048; 
    var $q_info   = "\xFF\xFF\xFF\xFF\x64\x65\x74\x61\x69\x6C\x73"; 
    var $q_rules  = "\xFF\xFF\xFF\xFF\x72\x75\x6C\x65\x73"; 
    var $q_player = "\xFF\xFF\xFF\xFF\x70\x6C\x61\x79\x65\x72\x73"; 
    var $s_info   = false; 
    var $response = false; 

    function microtime_float() 
    { 
        list($usec, $sec) = explode(" ", microtime()); 
  
        return ((float)$usec + (float)$sec); 
    } 

    function get_info($socket) 
    { 
    socket_set_timeout($socket, 3); 
         
    $time_begin = $this->microtime_float(); 
     
    fwrite($socket, $this->q_info); 
    $this->s_info['info'] = fread($socket, $this->maxlen); 

    $time_end  = $this->microtime_float(); 
        $this->response = $time_end - $time_begin; 
    $this->response = ($this->response * 1000); 
    $this->response = (int)$this->response; 
    } 

    function get_rules($socket) 
    { 
        socket_set_timeout($socket, 3); 
    fwrite($socket, $this->q_rules); 
    $this->s_info['rules'] = fread($socket, $this->maxlen); 
    } 

    function get_players($socket) 
    { 
    socket_set_timeout($socket, 3); 
    fwrite ($socket, $this->q_player); 
    $this->s_info['player'] = fread($socket, $this->maxlen); 
    } 

    function getstream($host, $port, $queryport) 
    {    
        $socket = fsockopen('udp://'. $host, $port, $errno, $errstr, 3); 
     
    if ($socket === false) 
    { 
            echo "Error: $errno - $errstr<br>\n"; 
        } 
    else 
    { 
        $this->get_info($socket); 
        $this->get_players($socket); 
        } 
        fclose($socket); 
     
    if ($this->s_info['info']) 
    { 
        return true; 
    } 
    else 
    { 
        return false; 
    } 
    } 

    function getvalue_byte($def) 
    { 
        $tmp = $this->s_info[$def][0]; 
    $this->s_info[$def] = substr($this->s_info[$def], 1); 

    return ord($tmp); 
    } 
     
    function getvalue_string($def) 
    { 
        $tmp = ''; 
    $index = 0; 
     
    while (ord($this->s_info[$def][$index]) != 0) 
    { 
        $tmp .= $this->s_info[$def][$index]; 
        $index++; 
    } 
    $this->s_info[$def] = substr($this->s_info[$def], $index+1); 

    return $tmp; 
    } 
     
    function getvalue_sint($def) 
    { 
    $tmp = substr($this->s_info[$def], 0, 2); 
    $this->s_info[$def] = substr($this->s_info[$def], 2); 
    $array = @unpack('Sshort', $tmp); 
  
        return $array['short'];                 
    } 

    function getvalue_lint($def) 
    { 
        $tmp = substr($this->s_info[$def], 0, 4); 
    $this->s_info[$def] = substr($this->s_info[$def], 4); 
    $array = @unpack('Lint', $tmp); 
     
    return $array['int']; 
    } 

    function getvalue_float($def) 
    {  
    $tmp = substr($this->s_info[$def], 0, 4); 
    $this->s_info[$def] = substr($this->s_info[$def], 4); 
    $array = @unpack('ffloat', $tmp); 

    return $array['float']; 
    } 
         
    function getrules($phgdir) 
    { 
        $srv_rules['sets'] = false; 
    $srv_rules['response'] = $this->response . ' ms'; 
    $sets['pass'] = '<img src="' . $phgdir . 'privileges/pass.gif" alt="pw">'; 
        $def = 'info'; 
    $servertype = $this->s_info['info'][4]; 
    $this->s_info['info'] = substr($this->s_info['info'], 5); 
    if ($servertype == 'm') 
    { 
        $srv_rules['gameip']      = $this->getvalue_string($def); 
        $srv_rules['index']     = $this->getvalue_byte($def); 
        $srv_rules['hostname']    = $this->getvalue_string($def); 
        $srv_rules['mapname']     = $this->getvalue_string($def); 
        $srv_rules['gamedir']     = $this->getvalue_string($def); 
        $srv_rules['gametype']    = $this->getvalue_string($def); 
        $srv_rules['nowplayers']  = $this->getvalue_byte($def); 
        $srv_rules['maxplayers']  = $this->getvalue_byte($def); 
            $srv_rules['netver']      = $this->getvalue_byte($def); 
        $srv_rules['dedicated']   = $this->getvalue_byte($def); 
        $srv_rules['os']          = $this->getvalue_byte($def); 
        $srv_rules['password']    = $this->getvalue_byte($def); 
        $srv_rules['is_mod']      = $this->getvalue_byte($def); 
            $srv_rules['url_info']    = $this->getvalue_string($def); 
            $srv_rules['url_down']    = $this->getvalue_string($def); 
        $srv_rules['unused']      = $this->getvalue_string($def); 
        $srv_rules['mod_version'] = $this->getvalue_lint($def); 
        $srv_rules['mod_size']    = $this->getvalue_lint($def); 
            $srv_rules['sv_only']     = $this->getvalue_byte($def); 
        $srv_rules['cus_cl']      = $this->getvalue_byte($def); 
            $srv_rules['secure']      = $this->getvalue_byte($def); 
            $srv_rules['bots']        = $this->getvalue_byte($def); 
        $srv_rules['map_path'] = 'maps/hl'; 
        } 
    if ($servertype == 'I') 
    { 
        $srv_rules['netver']     = $this->getvalue_byte($def); 
        $srv_rules['index']     = $this->getvalue_byte($def); 
        $srv_rules['hostname']   = $this->getvalue_string($def); 
        $srv_rules['mapname']    = $this->getvalue_string($def); 
        $srv_rules['gamedir']    = $this->getvalue_string($def); 
        $srv_rules['gametype']   = $this->getvalue_string($def); 
        $srv_rules['app_id']     = $this->getvalue_sint($def); 
        $srv_rules['nowplayers'] = $this->getvalue_byte($def); 
        $srv_rules['maxplayers'] = $this->getvalue_byte($def); 
        $srv_rules['bots']       = $this->getvalue_byte($def); 
        $srv_rules['dedicated']  = $this->getvalue_byte($def); 
        $srv_rules['os']         = $this->getvalue_byte($def); 
        $srv_rules['password']   = $this->getvalue_byte($def); 
        $srv_rules['secure']     = $this->getvalue_byte($def); 
        $srv_rules['version']    = $this->getvalue_string($def); 
        $srv_rules['map_path'] = 'maps/hl2'; 
    } 
    $srv_rules['map_default'] = 'default.jpg'; 
    $srv_rules['gamename'] = $srv_rules['gametype'] . '<br>'; 
    if ($srv_rules['password'] == 1) 
        { 
        $srv_rules['sets'] = $sets['pass']; 
        } 
     
    if ($srv_rules['sets'] === false) 
    { 
        $srv_rules['sets'] = '-'; 
    } 

        $srv_rules['htmlinfo'] = 
        '<tr><td align="left">Mapname:</td><td align="left">' 
        . $srv_rules['mapname'] 
        . '</td></tr>' ."\n" 
        . '<tr><td align="left">Players:</td><td align="left">' 
        . $srv_rules['nowplayers'] . ' / ' . $srv_rules['maxplayers'] 
        . '</td></tr>' . "\n" 
        . '<tr><td align="left">Response:</td><td align="left">' 
        . $srv_rules['response'] 
        . '</td></tr>' . "\n" 
        . '<tr><td align="left">Privileges:</td><td align="left">' 
        . $srv_rules['sets'] 
        . '</td></tr>' . "\n"; 

        $srv_rules['htmldetail'] = 
        '<tr valign="top"><td align="left">Gamename:</td><td align="left">' 
        . $srv_rules['gamename'] 
        . '</td></tr>' . "\n" 
        . '<tr valign="top"><td align="left">Gamedir:</td><td align="left">' 
        . $srv_rules['gamedir'] 
        . '</td></tr>' . "\n" 
        . '<tr valign="top"><td align="left">Mapname:</td><td align="left">' 
        . $srv_rules['mapname'] 
        . '</td></tr>' . "\n" 
        . '<tr valign="top"><td align="left">Players:</td><td align="left">' 
        . $srv_rules['nowplayers'] . ' / ' . $srv_rules['maxplayers'] 
        . '</td></tr>' . "\n" 
        . '<tr valign="top"><td align="left">Response:</td><td align="left">' 
        . $srv_rules['response'] 
        . '</td></tr>' . "\n" 
        . '<tr valign="top"><td align="left">Privileges:</td><td align="left">' 
        . $srv_rules['sets'] 
        . '</td></tr>' . "\n"; 
    return $srv_rules; 
    } 
     
    function getplayers() 
    { 
        $players = array(); 
    $def = 'player'; 
    $thead = "<tr><th>Rank</th><th>Name</th><th>Frags</th><th colspan=2>Time</th></tr>"; 
    $this->s_info[$def] = substr($this->s_info[$def], 5); 
    $nowplayers = $this->getvalue_byte($def); 
    while ($nowplayers != 0) 
    { 
        $index = $this->getvalue_byte($def); 
        $nick  = $this->getvalue_string($def); 
        $frags = $this->getvalue_lint($def); 
        $time  = $this->getvalue_float($def); 
         
        $minutes = floor($time / 60); 
        $h       = floor($minutes / 60); 
        $seconds = floor($time - ($minutes * 60)); 
        $minutes = $minutes - ($h * 60); 
         
        $time = sprintf("%02s:%02s:%02s", $h, $minutes, $seconds); 

        // scan connecting players 
        if ($time == '00:00:00') 
        { 
            $nick =  'new connection'; 
        $frags = '-'; 
        } 
         
            $players[$nowplayers] = $frags . " " . $time . " " . "\"$nick\""; 
        $nowplayers--; 
    } 
     
    // check the connected players and sort the ranking 
    if ($players) 
    { 
        sort($players, SORT_NUMERIC); 
    } 
    else 
    { 
        $thead .= "<tr align=center><td>--</td><td>--</td><td>--</td><td colspan=2>--</td></tr>\n"; 
    } 

    // store the html table line to the info array 
    $srv_player = $thead; 

    // check how many players scanned 
    $clients = count($players); 
    $clients = $clients - 1; 
         
    // manage the player data in the following code 
    $index = 1; 
     
    while ($clients != -1) 
    { 
        list ($cache[$index], $player[$index]) = split ('\"', $players[$clients]); 
        list ($points[$index], $ping[$index]) =  split(' ', $cache[$index]); 

        // strip html code from player name 
        $player[$index] = htmlentities($player[$index]); 

            $tdata = "<tr align=center><td>$index.</td><td>$player[$index]</td><td>$points[$index]</td><td colspan=2>$ping[$index]</td></tr>\n"; 
     
        $srv_player = $srv_player . $tdata; 
        $clients--; 
        $index++; 
    } 
          
    return $srv_player; 
    } 
} 
/*****************************************************************************************************************************/ 
?>

   
 
 автор: madmo3r   (10.04.2007 в 15:50)   письмо автору
 
 

Помогите плиз :) Нужен скрипт который бы тестировал сервер.. включен он или нет..
Для примера вот такой "194.50.85.251:27015"(Counter Strike).. Спасибо :)

   

Сообщения:  [1-10] 

Форум разработан IT-студией SoftTime