我试图创建自己的服务器查询,但我有一些问题..
我正在使用A2S_INFO请求。
问题在于我没有得到我想要的所有信息,比如当前的玩家数量,机器人的数量......
这是我从查询中得到的:
array (size=10)
0 => string 'ÿÿÿÿI[USA]Arena 1v1|1on1|Aim|Store|' (length=36)
1 => string 'am_dust_v6' (length=10)
2 => string 'csgo' (length=4)
3 => string 'Counter-Strike: Global Offensive' (length=32)
4 => string 'Ú' (length=4)
5 => string 'dl' (length=2)
6 => string '1.35.0.9' (length=9)
7 => string '¡‡i1v,1vs1,admin,aim,arena,awp,awp dm,community,comp,competitive,deagle,deathmatch,dm,drops,free,free admin,jail,multi,pistols,rpg,secure' (length=137)
8 => string 'Ú' (length=2)
9 => string '�����' (length=5)

这是我的实际代码
$ip = "107.172.18.227";
$port = "27015";
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
$result = socket_connect($socket, $ip, $port);
if($result < 0)
echo "connect() failed.\nReason: ($result) \n";
$data = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00";
socket_write($socket, $data, strlen($data));
$out = socket_read($socket, 4096);
$serverInfo = explode("\x00", $out, 10);
var_dump($serverInfo);
&#13;
我做错了什么?
谢谢!
答案 0 :(得分:2)
我没有得到任何帮助,但我找到了解决方案,所以我将分享它
$ip = "188.93.237.11";
$port = "1344";
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
$result = socket_connect($socket, $ip, $port);
if($result < 0)
echo "connect() failed.\nReason: ($result) \n";
$data = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00";
socket_write($socket, $data, strlen($data));
$out = socket_read($socket, 4096);
$queryData = explode("\x00", substr($out, 6), 5);
$server['name'] = $queryData[0];
$server['map'] = $queryData[1];
$server['game'] = $queryData[2];
$server['description'] = $queryData[3];
$packet = $queryData[4];
$app_id = array_pop(unpack("S", substr($packet, 0, 2)));
$server['players'] = ord(substr($packet, 2, 1));
$server['playersmax'] = ord(substr($packet, 3, 1));
$server['bots'] = ord(substr($packet, 4, 1));
$server['dedicated'] = substr($packet, 5, 1);
$server['os'] = substr($packet, 6, 1);
$server['password'] = ord(substr($packet, 7, 1));
$server['vac'] = ord(substr($packet, 8, 1));
var_dump($server);
&#13;
谢谢!