| |
|
|
| | Помогите разобраться в скрипте..
Как сделать, чтобы он показывал количество игроков (имена игроков, количество убийств/смертей)
Скрипт состоит из двух файлов. (cs_stat.php, cs1.php ), скрипт работает!
Листинг файла cs1.php:
<?
require_once("cs_stat.php");
//Counter Strike - Classic
$cscs= new cs_stat;
$cscs->getstream("999.99.999.999","27015","27015"); // ip сервера и порт...
$cscsx=$cscs->getrules("./");
?>
<? echo $cscsx[nowplayers]." / ".$cscsx[maxplayers]; ?>
// Написав эту строку, скрипт показывает количество игроков играющих на сервере в данный момент / максимальное количество игроков
|
Листинг файла cs_stat.php:
<?
/*****************************************************************************************************************************/
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;
}
}
/*****************************************************************************************************************************/
?>
|
| |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 14:24)
| | | Кажется, за вывод списка игроков тут отвечает "getplayers()".
<?php
require_once("cs_stat.php");
$cscs= new cs_stat;
$cscs->getstream("999.99.999.999", "27015", "27015");
$cscsx = $cscs->getrules("./");
echo($cscsx['nowplayers']." / ".$cscsx['maxplayers'] . "<br />\n");
echo($cscs->getplayers());
?>
|
| |
| |
|
|
| |
|
|
| |
для: Unkind
(07.04.2007 в 14:53)
| | | Спасибо! Но вот как отделить каждого игрока ? Т.е. что бы они не в одну строчку шли а один игрок на одну строку.
как получилось смотрите на картинку приклепленную, а надо сделать так:
Пример:
Name1 Убийст: 15 Смертей: 56
Name2 Убийст: 14 Смертей: 12 | |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 15:15)
| | | Попробуйте так ...
<?php
require_once("cs_stat.php");
$cscs= new cs_stat;
$cscs->getstream("999.99.999.999", "27015", "27015");
$cscsx = $cscs->getrules("./");
echo "<pre>";
echo($cscsx['nowplayers']." / ".$cscsx['maxplayers'] . "<br />\n");
echo($cscs->getplayers());
echo "</pre>";
?>
|
| |
| |
|
|
| |
|
|
| |
для: ddhvvn
(07.04.2007 в 15:18)
| | | Спасибо вам большое !!!! Теперь каждый игрок на одной строчке! | |
| |
|
|
| |
|
|
| |
для: ddhvvn
(07.04.2007 в 15:18)
| | | И еще вопрос! Как мне сделать чтобы игроки помещались в таблицу ????
Пример: смотрите рисунок
пожалуйста помогите! я неочень шарю в php. | |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 16:42)
| | | Для этого нужно модифицировать функцию getplayers(), точнее код вывода данных о игроках... | |
| |
|
|
| |
|
|
| |
для: ddhvvn
(07.04.2007 в 17:59)
| | | Помогите мне, пожалуйста, это сделать, а то я незнаю с какой стороны к ней подходить!
В долгу неостанусь! | |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 19:04)
| | | Если никто Вам не подскажет, то я отвечу попозже... | |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 19:04)
| | | Попробуйте заменить
<?php
$players[$nowplayers] = $frags . " " . $time . " " . "\"$nick\"";
?>
|
на
<?php
$players[$nowplayers] = '<tr><td>' . $nowplayers . '</td><td>"' . $nick . '"</td><td>' . $frags . '</td><td>' . $time . '</td></tr>';
?>
|
| |
| |
|
|
| |
|
|
| |
для: Unkind
(07.04.2007 в 19:53)
| | | неа...неполучается | |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 19:59)
| | | неа...неполучается
Да, все верно. Не получится. :)
Тогда
замените на
return "<table>" . $srv_player . "</table>";
|
| |
| |
|
|
| |
|
|
| |
для: Unkind
(07.04.2007 в 19:53)
| | | Замените так, как сказано в пред посте и плюс вместо того, куска, который я Вам давал использовать такой:
<?php
require_once("cs_stat.php");
$cscs= new cs_stat;
$cscs->getstream("999.99.999.999", "27015", "27015");
$cscsx = $cscs->getrules("./");
echo "<table>";
echo($cscsx['nowplayers']." / ".$cscsx['maxplayers'] . "<br />\n");
echo($cscs->getplayers());
echo "</table>";
?>
|
| |
| |
|
|
| |
|
|
| |
для: ddhvvn
(07.04.2007 в 20:07)
| | | Все нормально ! Спасибо большое тем кто мне помог!! ddhvvn скажите ваше icq | |
| |
|
|
| |
|
|
| |
для: t3ma
(07.04.2007 в 20:17)
| | | >Все нормально ! Спасибо большое тем кто мне помог!! ddhvvn скажите ваше icq
Только осталось наложить стили :))
Мой: двести1100два1 :)) | |
| |
|
|