Diff
checker
文本
文本
圖像
文檔
Excel
文件夾
Legal
Enterprise
桌面版
定價
登入
下載 Diffchecker 桌面版
比較文本
尋找兩個文字檔案之間的差異
工具
歷史
即時編輯器
隱藏空白變更
摺疊未變更行
關閉換行
檢視
拆分
統一
比對精度
智能
單詞
字符
文字樣式
變更外觀
語法突出顯示
選擇語法
忽略
文字轉換
前往第一個差異
編輯輸入
Diffchecker Desktop
執行Diffchecker最安全的方式。取得Diffchecker桌面應用程式:您的差異永遠不會離開您的電腦!
取得桌面版
Untitled diff
建立於
9 年前
差異永不過期
清除
匯出
分享
解釋
1 刪除
行
總計
刪除
字符
總計
刪除
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
488 行
全部複製
492 新增
行
總計
新增
字符
總計
新增
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
977 行
全部複製
<?php
<?php
複製
已複製
複製
已複製
/*
/*
複製
已複製
複製
已複製
LiveStats Library
LiveStats Library
複製
已複製
複製
已複製
複製
已複製
複製
已複製
version: 2.0
version: 2.0
複製
已複製
複製
已複製
query engines: Goldsource, Source, SA:MP
query engines: Goldsource, Source, SA:MP
複製
已複製
複製
已複製
protocol: 47, 48
protocol: 47, 48
複製
已複製
複製
已複製
author: nr913
author: nr913
複製
已複製
複製
已複製
複製
已複製
複製
已複製
visit www.
freakz
.ro
visit www.
foxh
.ro
*/
*/
複製
已複製
複製
已複製
define('HL_PACKET', -1);
define('HL_PACKET', -1);
複製
已複製
複製
已複製
define('HL_PACKET_SPLITTED', -2);
define('HL_PACKET_SPLITTED', -2);
複製
已複製
複製
已複製
define('SAMP_PACKET', 1347240275);
define('SAMP_PACKET', 1347240275);
複製
已複製
複製
已複製
class Player {
class Player {
複製
已複製
複製
已複製
var $ID;
var $ID;
複製
已複製
複製
已複製
var $Name;
var $Name;
複製
已複製
複製
已複製
var $Score;
var $Score;
複製
已複製
複製
已複製
var $TimePlayed;
var $TimePlayed;
複製
已複製
複製
已複製
var $Ping;
var $Ping;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
class Server {
class Server {
複製
已複製
複製
已複製
var $Type = 0;
var $Type = 0;
複製
已複製
複製
已複製
var $ProtocolVersion;
var $ProtocolVersion;
複製
已複製
複製
已複製
var $Address;
var $Address;
複製
已複製
複製
已複製
var $Hostname;
var $Hostname;
複製
已複製
複製
已複製
var $Map;
var $Map;
複製
已複製
複製
已複製
var $Directory;
var $Directory;
複製
已複製
複製
已複製
var $Description;
var $Description;
複製
已複製
複製
已複製
var $AppID;
var $AppID;
複製
已複製
複製
已複製
var $MaxPlayers;
var $MaxPlayers;
複製
已複製
複製
已複製
var $PlayerCount;
var $PlayerCount;
複製
已複製
複製
已複製
var $BotCount;
var $BotCount;
複製
已複製
複製
已複製
var $Dedicated;
var $Dedicated;
複製
已複製
複製
已複製
var $OS;
var $OS;
複製
已複製
複製
已複製
var $PasswordProtected;
var $PasswordProtected;
複製
已複製
複製
已複製
var $Secured;
var $Secured;
複製
已複製
複製
已複製
var $GameMode;
var $GameMode;
複製
已複製
複製
已複製
var $WitnessCount;
var $WitnessCount;
複製
已複製
複製
已複製
var $WitnessTime;
var $WitnessTime;
複製
已複製
複製
已複製
var $GameVersion;
var $GameVersion;
複製
已複製
複製
已複製
var $Players = array();
var $Players = array();
複製
已複製
複製
已複製
var $Rules = array();
var $Rules = array();
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
class Time {
class Time {
複製
已複製
複製
已複製
var $Hours;
var $Hours;
複製
已複製
複製
已複製
var $Minutes;
var $Minutes;
複製
已複製
複製
已複製
var $Seconds;
var $Seconds;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function __construct($seconds) {
function __construct($seconds) {
複製
已複製
複製
已複製
$this->Hours = floor($seconds / 3600);
$this->Hours = floor($seconds / 3600);
複製
已複製
複製
已複製
$this->Minutes = floor($seconds / 60) % 60;
$this->Minutes = floor($seconds / 60) % 60;
複製
已複製
複製
已複製
$this->Seconds = floor($seconds) % 60;
$this->Seconds = floor($seconds) % 60;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function __toString() {
function __toString() {
複製
已複製
複製
已複製
$hours = ($this->Hours < 10 ? '0' . $this->Hours : $this->Hours);
$hours = ($this->Hours < 10 ? '0' . $this->Hours : $this->Hours);
複製
已複製
複製
已複製
$minutes = ($this->Minutes < 10 ? '0' . $this->Minutes : $this->Minutes);
$minutes = ($this->Minutes < 10 ? '0' . $this->Minutes : $this->Minutes);
複製
已複製
複製
已複製
$seconds = ($this->Seconds < 10 ? '0' . $this->Seconds : $this->Seconds);
$seconds = ($this->Seconds < 10 ? '0' . $this->Seconds : $this->Seconds);
複製
已複製
複製
已複製
return "$hours:$minutes:$seconds";
return "$hours:$minutes:$seconds";
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
class LSError extends Exception {
class LSError extends Exception {
複製
已複製
複製
已複製
var $ErrorMessage;
var $ErrorMessage;
複製
已複製
複製
已複製
var $ErrorCode;
var $ErrorCode;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function __construct($errcode, $errmsg) {
function __construct($errcode, $errmsg) {
複製
已複製
複製
已複製
$this->ErrorCode = $errcode;
$this->ErrorCode = $errcode;
複製
已複製
複製
已複製
$this->ErrorMessage = $errmsg;
$this->ErrorMessage = $errmsg;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
class Utils {
class Utils {
複製
已複製
複製
已複製
static function getTime() {
static function getTime() {
複製
已複製
複製
已複製
list($u, $s) = explode(' ', microtime());
list($u, $s) = explode(' ', microtime());
複製
已複製
複製
已複製
return ((float)$u + (float)$s);
return ((float)$u + (float)$s);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
static function getString($packet, &$offset, $length = -1) {
static function getString($packet, &$offset, $length = -1) {
複製
已複製
複製
已複製
$len = strlen($packet);
$len = strlen($packet);
複製
已複製
複製
已複製
$i = 0;
$i = 0;
複製
已複製
複製
已複製
if ($length == -1) {
if ($length == -1) {
複製
已複製
複製
已複製
while ($offset + $i < $len && $packet[$offset + $i] != "\x00")
while ($offset + $i < $len && $packet[$offset + $i] != "\x00")
複製
已複製
複製
已複製
$i++;
$i++;
複製
已複製
複製
已複製
$offset += $i + 1;
$offset += $i + 1;
複製
已複製
複製
已複製
return substr($packet, $offset - $i - 1, $i);
return substr($packet, $offset - $i - 1, $i);
複製
已複製
複製
已複製
} else {
} else {
複製
已複製
複製
已複製
$i = $length;
$i = $length;
複製
已複製
複製
已複製
if ($len - $offset < $length)
if ($len - $offset < $length)
複製
已複製
複製
已複製
$i = $len - $offset;
$i = $len - $offset;
複製
已複製
複製
已複製
$offset += $i;
$offset += $i;
複製
已複製
複製
已複製
return substr($packet, $offset - $i, $i);
return substr($packet, $offset - $i, $i);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
static function getByte($packet, &$offset) {
static function getByte($packet, &$offset) {
複製
已複製
複製
已複製
if ($offset >= strlen($packet))
if ($offset >= strlen($packet))
複製
已複製
複製
已複製
return 0;
return 0;
複製
已複製
複製
已複製
$char = unpack('cchar', $packet[$offset]);
$char = unpack('cchar', $packet[$offset]);
複製
已複製
複製
已複製
$offset++;
$offset++;
複製
已複製
複製
已複製
return $char['char'];
return $char['char'];
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
static function getShort($packet, &$offset) {
static function getShort($packet, &$offset) {
複製
已複製
複製
已複製
if ($offset + 2 >= strlen($packet))
if ($offset + 2 >= strlen($packet))
複製
已複製
複製
已複製
return 0;
return 0;
複製
已複製
複製
已複製
$short = unpack('sshort', substr($packet, $offset, 2));
$short = unpack('sshort', substr($packet, $offset, 2));
複製
已複製
複製
已複製
$offset += 2;
$offset += 2;
複製
已複製
複製
已複製
return $short['short'];
return $short['short'];
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
static function getInt($packet, &$offset) {
static function getInt($packet, &$offset) {
複製
已複製
複製
已複製
if ($offset + 4 >= strlen($packet))
if ($offset + 4 >= strlen($packet))
複製
已複製
複製
已複製
return 0;
return 0;
複製
已複製
複製
已複製
$int = unpack('iint', substr($packet, $offset, 4));
$int = unpack('iint', substr($packet, $offset, 4));
複製
已複製
複製
已複製
$offset += 4;
$offset += 4;
複製
已複製
複製
已複製
return $int['int'];
return $int['int'];
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
static function getFloat($packet, &$offset) {
static function getFloat($packet, &$offset) {
複製
已複製
複製
已複製
if ($offset + 4 >= strlen($packet))
if ($offset + 4 >= strlen($packet))
複製
已複製
複製
已複製
return ((float)0.0);
return ((float)0.0);
複製
已複製
複製
已複製
$float = unpack('ffloat', substr($packet, $offset, 4));
$float = unpack('ffloat', substr($packet, $offset, 4));
複製
已複製
複製
已複製
$offset += 4;
$offset += 4;
複製
已複製
複製
已複製
return ((float)$float['float']);
return ((float)$float['float']);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
class LiveStats {
class LiveStats {
複製
已複製
複製
已複製
var $IP;
var $IP;
複製
已複製
複製
已複製
var $Port;
var $Port;
複製
已複製
複製
已複製
var $Sock;
var $Sock;
複製
已複製
複製
已複製
var $Challenge = "\xFF\xFF\xFF\xFF";
var $Challenge = "\xFF\xFF\xFF\xFF";
複製
已複製
複製
已複製
var $HaveInfo = false;
var $HaveInfo = false;
複製
已複製
複製
已複製
var $HavePlayer = false;
var $HavePlayer = false;
複製
已複製
複製
已複製
var $HaveRules = false;
var $HaveRules = false;
複製
已複製
複製
已複製
var $ResendPlayer = false;
var $ResendPlayer = false;
複製
已複製
複製
已複製
var $ResendRules = false;
var $ResendRules = false;
複製
已複製
複製
已複製
var $SendQueue = array();
var $SendQueue = array();
複製
已複製
複製
已複製
var $MaxExecutionTime = 2;
var $MaxExecutionTime = 2;
複製
已複製
複製
已複製
var $SplittedPackets = array();
var $SplittedPackets = array();
複製
已複製
複製
已複製
var $SAMPHeader = "SAMP";
var $SAMPHeader = "SAMP";
複製
已複製
複製
已複製
複製
已複製
複製
已複製
var $Server;
var $Server;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
public function __construct($hostname, $port = 27015) {
public function __construct($hostname, $port = 27015) {
複製
已複製
複製
已複製
$this->IP = gethostbyname($hostname);
$this->IP = gethostbyname($hostname);
複製
已複製
複製
已複製
$this->Port = $port;
$this->Port = $port;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$errno = 0; $errstr = '';
$errno = 0; $errstr = '';
複製
已複製
複製
已複製
$this->Sock = @stream_socket_client("udp://{$this->IP}:{$this->Port}", $errno, $errstr, 5);
$this->Sock = @stream_socket_client("udp://{$this->IP}:{$this->Port}", $errno, $errstr, 5);
複製
已複製
複製
已複製
複製
已複製
複製
已複製
if ($this->Sock === false)
if ($this->Sock === false)
複製
已複製
複製
已複製
throw new LSError(1, "Could not connect to specified host [$errno]: $errstr.");
throw new LSError(1, "Could not connect to specified host [$errno]: $errstr.");
複製
已複製
複製
已複製
if (stream_set_blocking($this->Sock, false) == false)
if (stream_set_blocking($this->Sock, false) == false)
複製
已複製
複製
已複製
throw new LSError(2, "Could not set to non-blocking mode.");
throw new LSError(2, "Could not set to non-blocking mode.");
複製
已複製
複製
已複製
複製
已複製
複製
已複製
if (stream_set_timeout($this->Sock, 3) == false)
if (stream_set_timeout($this->Sock, 3) == false)
複製
已複製
複製
已複製
throw new LSError(3, "Could not set timeout to 10 seconds.");
throw new LSError(3, "Could not set timeout to 10 seconds.");
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$this->Server = new Server;
$this->Server = new Server;
複製
已複製
複製
已複製
$this->Server->Address = "{$this->IP}:{$this->Port}";
$this->Server->Address = "{$this->IP}:{$this->Port}";
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$ip = explode('.', $this->IP);
$ip = explode('.', $this->IP);
複製
已複製
複製
已複製
$this->SAMPHeader .= chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]) . chr($this->Port & 0xFF) . chr(($this->Port >> 8) & 0xFF);
$this->SAMPHeader .= chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]) . chr($this->Port & 0xFF) . chr(($this->Port >> 8) & 0xFF);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function onSplittedPacketReceived($packet) {
function onSplittedPacketReceived($packet) {
複製
已複製
複製
已複製
$offset = 4;
$offset = 4;
複製
已複製
複製
已複製
$ReqID = Utils::getInt($packet, $offset);
$ReqID = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
if (!isset($this->SplittedPackets[$ReqID])) {
if (!isset($this->SplittedPackets[$ReqID])) {
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID] = array(
$this->SplittedPackets[$ReqID] = array(
複製
已複製
複製
已複製
'Data' => array(),
'Data' => array(),
複製
已複製
複製
已複製
'Type' => -1,
'Type' => -1,
複製
已複製
複製
已複製
'Packets' => -1
'Packets' => -1
複製
已複製
複製
已複製
);
);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Data'][] = $packet;
$this->SplittedPackets[$ReqID]['Data'][] = $packet;
複製
已複製
複製
已複製
if (count($this->SplittedPackets[$ReqID]['Data']) == 2) {
if (count($this->SplittedPackets[$ReqID]['Data']) == 2) {
複製
已複製
複製
已複製
$offset = 8;
$offset = 8;
複製
已複製
複製
已複製
$FB1 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][0], $offset);
$FB1 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][0], $offset);
複製
已複製
複製
已複製
$offset = 8;
$offset = 8;
複製
已複製
複製
已複製
$FB2 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][1], $offset);
$FB2 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][1], $offset);
複製
已複製
複製
已複製
if ($FB1 != $FB2) {
if ($FB1 != $FB2) {
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Type'] = 0;
$this->SplittedPackets[$ReqID]['Type'] = 0;
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Packets'] = ($FB1<<4)>>4;
$this->SplittedPackets[$ReqID]['Packets'] = ($FB1<<4)>>4;
複製
已複製
複製
已複製
} else {
} else {
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Type'] = 1;
$this->SplittedPackets[$ReqID]['Type'] = 1;
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Packets'] = $FB1;
$this->SplittedPackets[$ReqID]['Packets'] = $FB1;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
if (count($this->SplittedPackets[$ReqID]['Data']) == $this->SplittedPackets[$ReqID]['Packets']) {
if (count($this->SplittedPackets[$ReqID]['Data']) == $this->SplittedPackets[$ReqID]['Packets']) {
複製
已複製
複製
已複製
if ($this->SplittedPackets[$ReqID]['Type'] == 0) {
if ($this->SplittedPackets[$ReqID]['Type'] == 0) {
複製
已複製
複製
已複製
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
複製
已複製
複製
已複製
$offset = 8;
$offset = 8;
複製
已複製
複製
已複製
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset)>>4;
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset)>>4;
複製
已複製
複製
已複製
if ($i != $PckID) {
if ($i != $PckID) {
複製
已複製
複製
已複製
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
複製
已複製
複製
已複製
$i--;
$i--;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 13);
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 13);
複製
已複製
複製
已複製
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
複製
已複製
複製
已複製
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 9);
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 9);
複製
已複製
複製
已複製
} else {
} else {
複製
已複製
複製
已複製
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
複製
已複製
複製
已複製
$offset = 9;
$offset = 9;
複製
已複製
複製
已複製
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset);
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset);
複製
已複製
複製
已複製
if ($i != $PckID) {
if ($i != $PckID) {
複製
已複製
複製
已複製
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
複製
已複製
複製
已複製
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
複製
已複製
複製
已複製
$i--;
$i--;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 16);
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 16);
複製
已複製
複製
已複製
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
複製
已複製
複製
已複製
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 12);
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 12);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
unset($this->SplittedPackets[$ReqID]);
unset($this->SplittedPackets[$ReqID]);
複製
已複製
複製
已複製
$this->onPacketReceived($packet);
$this->onPacketReceived($packet);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function onPacketReceived($packet) {
function onPacketReceived($packet) {
複製
已複製
複製
已複製
$offset = 4;
$offset = 4;
複製
已複製
複製
已複製
switch (Utils::getByte($packet, $offset)) {
switch (Utils::getByte($packet, $offset)) {
複製
已複製
複製
已複製
case 0x41: // challenge
case 0x41: // challenge
複製
已複製
複製
已複製
$this->Challenge = substr($packet, 5);
$this->Challenge = substr($packet, 5);
複製
已複製
複製
已複製
if ($this->ResendPlayer) {
if ($this->ResendPlayer) {
複製
已複製
複製
已複製
$this->ResendPlayer = false;
$this->ResendPlayer = false;
複製
已複製
複製
已複製
$this->requestPlayer();
$this->requestPlayer();
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
if ($this->ResendRules) {
if ($this->ResendRules) {
複製
已複製
複製
已複製
$this->ResendRules = false;
$this->ResendRules = false;
複製
已複製
複製
已複製
$this->requestRules();
$this->requestRules();
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case 0x44: // player
case 0x44: // player
複製
已複製
複製
已複製
if ($this->HavePlayer)
if ($this->HavePlayer)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$offset = 5;
$offset = 5;
複製
已複製
複製
已複製
$numplayers = Utils::getByte($packet, $offset);
$numplayers = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
while ($numplayers) {
while ($numplayers) {
複製
已複製
複製
已複製
$Player = new Player;
$Player = new Player;
複製
已複製
複製
已複製
$Player->ID = Utils::getByte($packet, $offset);
$Player->ID = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$Player->Name = Utils::getString($packet, $offset);
$Player->Name = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$len = strlen($Player->Name);
$len = strlen($Player->Name);
複製
已複製
複製
已複製
$Player->Score = Utils::getInt($packet, $offset);
$Player->Score = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
$Player->TimePlayed = new Time(Utils::getFloat($packet, $offset));
$Player->TimePlayed = new Time(Utils::getFloat($packet, $offset));
複製
已複製
複製
已複製
$numplayers--;
$numplayers--;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
array_push($this->Server->Players, $Player);
array_push($this->Server->Players, $Player);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->HavePlayer = true;
$this->HavePlayer = true;
複製
已複製
複製
已複製
$this->ResendPlayer = false;
$this->ResendPlayer = false;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case 0x49: // info, source
case 0x49: // info, source
複製
已複製
複製
已複製
if ($this->HaveInfo)
if ($this->HaveInfo)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$offset = 5;
$offset = 5;
複製
已複製
複製
已複製
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Hostname = Utils::getString($packet, $offset);
$this->Server->Hostname = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Map = Utils::getString($packet, $offset);
$this->Server->Map = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Directory = Utils::getString($packet, $offset);
$this->Server->Directory = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Description = Utils::getString($packet, $offset);
$this->Server->Description = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->AppID = Utils::getShort($packet, $offset);
$this->Server->AppID = Utils::getShort($packet, $offset);
複製
已複製
複製
已複製
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->BotCount = Utils::getByte($packet, $offset);
$this->Server->BotCount = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
複製
已複製
複製
已複製
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
複製
已複製
複製
已複製
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
複製
已複製
複製
已複製
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
複製
已複製
複製
已複製
$TheShipAppIDs = array(2400, 2401, 2402, 2412, 2430, 2406, 2405, 2403);
$TheShipAppIDs = array(2400, 2401, 2402, 2412, 2430, 2406, 2405, 2403);
複製
已複製
複製
已複製
if (in_array($this->Server->AppID, $TheShipAppIDs)) {
if (in_array($this->Server->AppID, $TheShipAppIDs)) {
複製
已複製
複製
已複製
$gm = Utils::getByte($packet, $offset);
$gm = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$GameModes = array('Hunt', 'Elimination', 'Duel', 'Deathmatch', 'Team VIP', 'Team Elimination');
$GameModes = array('Hunt', 'Elimination', 'Duel', 'Deathmatch', 'Team VIP', 'Team Elimination');
複製
已複製
複製
已複製
$this->Server->GameMode = (isset($GameModes[$gm]) ? $GameModes[$gm] : 'Unknown');
$this->Server->GameMode = (isset($GameModes[$gm]) ? $GameModes[$gm] : 'Unknown');
複製
已複製
複製
已複製
$this->Server->WitnessCount = Utils::getByte($packet, $offset);
$this->Server->WitnessCount = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->WitnessTime = Utils::getByte($packet, $offset);
$this->Server->WitnessTime = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->Server->GameVersion = Utils::getString($packet, $offset);
$this->Server->GameVersion = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->HaveInfo = true;
$this->HaveInfo = true;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case 0x6D: // info, goldsource
case 0x6D: // info, goldsource
複製
已複製
複製
已複製
if ($this->HaveInfo)
if ($this->HaveInfo)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$offset = 5;
$offset = 5;
複製
已複製
複製
已複製
Utils::getString($packet, $offset);
Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Hostname = Utils::getString($packet, $offset);
$this->Server->Hostname = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Map = Utils::getString($packet, $offset);
$this->Server->Map = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Directory = Utils::getString($packet, $offset);
$this->Server->Directory = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Description = Utils::getString($packet, $offset);
$this->Server->Description = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
複製
已複製
複製
已複製
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
複製
已複製
複製
已複製
$this->Server->AppID = ($this->Server->OS == 'Linux' ? 4 : 5);
$this->Server->AppID = ($this->Server->OS == 'Linux' ? 4 : 5);
複製
已複製
複製
已複製
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
複製
已複製
複製
已複製
$IsMod = Utils::getByte($packet, $offset);
$IsMod = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
if ($IsMod == 1) {
if ($IsMod == 1) {
複製
已複製
複製
已複製
Utils::getString($packet, $offset);
Utils::getString($packet, $offset);
複製
已複製
複製
已複製
Utils::getString($packet, $offset);
Utils::getString($packet, $offset);
複製
已複製
複製
已複製
Utils::getByte($packet, $offset);
Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
Utils::getInt($packet, $offset);
Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
Utils::getInt($packet, $offset);
Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
Utils::getByte($packet, $offset);
Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
Utils::getByte($packet, $offset);
Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
複製
已複製
複製
已複製
$this->Server->BotCount = Utils::getByte($packet, $offset);
$this->Server->BotCount = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$this->HaveInfo = true;
$this->HaveInfo = true;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case 0x45: // rules
case 0x45: // rules
複製
已複製
複製
已複製
if ($this->HaveRules)
if ($this->HaveRules)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$offset = 5;
$offset = 5;
複製
已複製
複製
已複製
$rulesnum = Utils::getShort($packet, $offset);
$rulesnum = Utils::getShort($packet, $offset);
複製
已複製
複製
已複製
while ($rulesnum) {
while ($rulesnum) {
複製
已複製
複製
已複製
$Name = Utils::getString($packet, $offset);
$Name = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$Value = Utils::getString($packet, $offset);
$Value = Utils::getString($packet, $offset);
複製
已複製
複製
已複製
$rulesnum--;
$rulesnum--;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$this->Server->Rules[$Name] = $Value;
$this->Server->Rules[$Name] = $Value;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->HaveRules = true;
$this->HaveRules = true;
複製
已複製
複製
已複製
$this->ResendRules = false;
$this->ResendRules = false;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
default:
default:
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function onSampPacketReceived($packet) {
function onSampPacketReceived($packet) {
複製
已複製
複製
已複製
$offset = 10;
$offset = 10;
複製
已複製
複製
已複製
switch (Utils::getByte($packet, $offset)) {
switch (Utils::getByte($packet, $offset)) {
複製
已複製
複製
已複製
case 0x69: // info
case 0x69: // info
複製
已複製
複製
已複製
if ($this->HaveInfo)
if ($this->HaveInfo)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
複製
已複製
複製
已複製
$this->Server->PlayerCount = Utils::getShort($packet, $offset);
$this->Server->PlayerCount = Utils::getShort($packet, $offset);
複製
已複製
複製
已複製
$this->Server->MaxPlayers = Utils::getShort($packet, $offset);
$this->Server->MaxPlayers = Utils::getShort($packet, $offset);
複製
已複製
複製
已複製
$len = Utils::getInt($packet, $offset);
$len = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Hostname = Utils::getString($packet, $offset, $len);
$this->Server->Hostname = Utils::getString($packet, $offset, $len);
複製
已複製
複製
已複製
$len = Utils::getInt($packet, $offset);
$len = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
$this->Server->GameMode = Utils::getString($packet, $offset, $len);
$this->Server->GameMode = Utils::getString($packet, $offset, $len);
複製
已複製
複製
已複製
$len = Utils::getInt($packet, $offset);
$len = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
$this->Server->Map = Utils::getString($packet, $offset, $len);
$this->Server->Map = Utils::getString($packet, $offset, $len);
複製
已複製
複製
已複製
$this->HaveInfo = true;
$this->HaveInfo = true;
複製
已複製
複製
已複製
if ($this->Server->PlayerCount >= 100)
if ($this->Server->PlayerCount >= 100)
複製
已複製
複製
已複製
$this->HavePlayer = true;
$this->HavePlayer = true;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case 0x72: // rules
case 0x72: // rules
複製
已複製
複製
已複製
if ($this->HaveRules)
if ($this->HaveRules)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$rulesnum = Utils::getShort($packet, $offset);
$rulesnum = Utils::getShort($packet, $offset);
複製
已複製
複製
已複製
while ($rulesnum) {
while ($rulesnum) {
複製
已複製
複製
已複製
$len = Utils::getByte($packet, $offset);
$len = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$Name = Utils::getString($packet, $offset, $len);
$Name = Utils::getString($packet, $offset, $len);
複製
已複製
複製
已複製
$len = Utils::getByte($packet, $offset);
$len = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$Value = Utils::getString($packet, $offset, $len);
$Value = Utils::getString($packet, $offset, $len);
複製
已複製
複製
已複製
$rulesnum--;
$rulesnum--;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$this->Server->Rules[$Name] = $Value;
$this->Server->Rules[$Name] = $Value;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->HaveRules = true;
$this->HaveRules = true;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case 0x64: // player
case 0x64: // player
複製
已複製
複製
已複製
if ($this->HavePlayer)
if ($this->HavePlayer)
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$numplayers = Utils::getShort($packet, $offset);
$numplayers = Utils::getShort($packet, $offset);
複製
已複製
複製
已複製
$lastID = 0;
$lastID = 0;
複製
已複製
複製
已複製
$plusID = 0;
$plusID = 0;
複製
已複製
複製
已複製
while ($numplayers) {
while ($numplayers) {
複製
已複製
複製
已複製
$Player = new Player;
$Player = new Player;
複製
已複製
複製
已複製
$Player->ID = Utils::getByte($packet, $offset) + $plusID;
$Player->ID = Utils::getByte($packet, $offset) + $plusID;
複製
已複製
複製
已複製
if ($Player->ID < $lastID) {
if ($Player->ID < $lastID) {
複製
已複製
複製
已複製
$Player->ID += 256;
$Player->ID += 256;
複製
已複製
複製
已複製
$plusID += 256;
$plusID += 256;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$lastID = $Player->ID;
$lastID = $Player->ID;
複製
已複製
複製
已複製
$len = Utils::getByte($packet, $offset);
$len = Utils::getByte($packet, $offset);
複製
已複製
複製
已複製
$Player->Name = Utils::getString($packet, $offset, $len);
$Player->Name = Utils::getString($packet, $offset, $len);
複製
已複製
複製
已複製
$len = strlen($Player->Name);
$len = strlen($Player->Name);
複製
已複製
複製
已複製
$Player->Score = Utils::getInt($packet, $offset);
$Player->Score = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
$Player->Ping = Utils::getInt($packet, $offset);
$Player->Ping = Utils::getInt($packet, $offset);
複製
已複製
複製
已複製
$numplayers--;
$numplayers--;
複製
已複製
複製
已複製
複製
已複製
複製
已複製
array_push($this->Server->Players, $Player);
array_push($this->Server->Players, $Player);
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
$this->HavePlayer = true;
$this->HavePlayer = true;
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
default:
default:
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function requestInfo() {
function requestInfo() {
複製
已複製
複製
已複製
array_push($this->SendQueue, "\xFF\xFF\xFF\xFFTSource Engine Query\x00");
array_push($this->SendQueue, "\xFF\xFF\xFF\xFFTSource Engine Query\x00");
複製
已複製
複製
已複製
array_push($this->SendQueue, $this->SAMPHeader . "i");
array_push($this->SendQueue, $this->SAMPHeader . "i");
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function requestPlayer() {
function requestPlayer() {
複製
已複製
複製
已複製
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x55" . $this->Challenge);
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x55" . $this->Challenge);
複製
已複製
複製
已複製
array_push($this->SendQueue, $this->SAMPHeader . "d");
array_push($this->SendQueue, $this->SAMPHeader . "d");
複製
已複製
複製
已複製
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
複製
已複製
複製
已複製
$this->ResendPlayer = true;
$this->ResendPlayer = true;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function requestRules() {
function requestRules() {
複製
已複製
複製
已複製
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x56" . $this->Challenge);
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x56" . $this->Challenge);
複製
已複製
複製
已複製
array_push($this->SendQueue, $this->SAMPHeader . "r");
array_push($this->SendQueue, $this->SAMPHeader . "r");
複製
已複製
複製
已複製
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
複製
已複製
複製
已複製
$this->ResendRules = true;
$this->ResendRules = true;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
function GetServer() {
function GetServer() {
複製
已複製
複製
已複製
$start = Utils::getTime();
$start = Utils::getTime();
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$this->requestInfo();
$this->requestInfo();
複製
已複製
複製
已複製
$this->requestPlayer();
$this->requestPlayer();
複製
已複製
複製
已複製
$this->requestRules();
$this->requestRules();
複製
已複製
複製
已複製
複製
已複製
複製
已複製
while (!($this->HaveRules && $this->HaveInfo && $this->HavePlayer)) {
while (!($this->HaveRules && $this->HaveInfo && $this->HavePlayer)) {
複製
已複製
複製
已複製
if (Utils::getTime() - $start >= $this->MaxExecutionTime) {
if (Utils::getTime() - $start >= $this->MaxExecutionTime) {
複製
已複製
複製
已複製
if ($this->HaveInfo && $this->HavePlayer) {
if ($this->HaveInfo && $this->HavePlayer) {
複製
已複製
複製
已複製
$this->HaveRules = true;
$this->HaveRules = true;
複製
已複製
複製
已複製
} else {
} else {
複製
已複製
複製
已複製
throw new LSError(4, "Timed out.");
throw new LSError(4, "Timed out.");
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
if (count($this->SendQueue) > 0) {
if (count($this->SendQueue) > 0) {
複製
已複製
複製
已複製
stream_socket_sendto($this->Sock, array_shift($this->SendQueue));
stream_socket_sendto($this->Sock, array_shift($this->SendQueue));
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$meta = stream_get_meta_data($this->Sock);
$meta = stream_get_meta_data($this->Sock);
複製
已複製
複製
已複製
if ($meta['timed_out'])
if ($meta['timed_out'])
複製
已複製
複製
已複製
throw new LSError(5, "Timed out.");
throw new LSError(5, "Timed out.");
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
複製
已複製
複製
已複製
usleep(50000);
usleep(50000);
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$packet = fread($this->Sock, 2048);
$packet = fread($this->Sock, 2048);
複製
已複製
複製
已複製
複製
已複製
複製
已複製
$meta = stream_get_meta_data($this->Sock);
$meta = stream_get_meta_data($this->Sock);
複製
已複製
複製
已複製
if ($meta['timed_out'])
if ($meta['timed_out'])
複製
已複製
複製
已複製
throw new LSError(6, "Timed out.");
throw new LSError(6, "Timed out.");
複製
已複製
複製
已複製
複製
已複製
複製
已複製
if (strlen($packet) > 0) {
if (strlen($packet) > 0) {
複製
已複製
複製
已複製
$offset = 0;
$offset = 0;
複製
已複製
複製
已複製
switch (Utils::getInt($packet, $offset)) {
switch (Utils::getInt($packet, $offset)) {
複製
已複製
複製
已複製
case HL_PACKET:
case HL_PACKET:
複製
已複製
複製
已複製
if (!in_array($this->Server->Type, array(0, 1)))
if (!in_array($this->Server->Type, array(0, 1)))
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$this->Server->Type = 1;
$this->Server->Type = 1;
複製
已複製
複製
已複製
$this->onPacketReceived($packet);
$this->onPacketReceived($packet);
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case HL_PACKET_SPLITTED:
case HL_PACKET_SPLITTED:
複製
已複製
複製
已複製
if (!in_array($this->Server->Type, array(0, 1)))
if (!in_array($this->Server->Type, array(0, 1)))
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$this->Server->Type = 1;
$this->Server->Type = 1;
複製
已複製
複製
已複製
$this->onSplittedPacketReceived($packet);
$this->onSplittedPacketReceived($packet);
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
case SAMP_PACKET:
case SAMP_PACKET:
複製
已複製
複製
已複製
if (!in_array($this->Server->Type, array(0, 2)))
if (!in_array($this->Server->Type, array(0, 2)))
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
$this->Server->Type = 2;
$this->Server->Type = 2;
複製
已複製
複製
已複製
$this->onSampPacketReceived($packet);
$this->onSampPacketReceived($packet);
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
default:
default:
複製
已複製
複製
已複製
break;
break;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
return $this->Server;
return $this->Server;
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
}
}
複製
已複製
複製
已複製
?>
?>
已保存差異
原始文本
開啟檔案
<?php /* LiveStats Library version: 2.0 query engines: Goldsource, Source, SA:MP protocol: 47, 48 author: nr913 visit www.freakz.ro */ define('HL_PACKET', -1); define('HL_PACKET_SPLITTED', -2); define('SAMP_PACKET', 1347240275); class Player { var $ID; var $Name; var $Score; var $TimePlayed; var $Ping; } class Server { var $Type = 0; var $ProtocolVersion; var $Address; var $Hostname; var $Map; var $Directory; var $Description; var $AppID; var $MaxPlayers; var $PlayerCount; var $BotCount; var $Dedicated; var $OS; var $PasswordProtected; var $Secured; var $GameMode; var $WitnessCount; var $WitnessTime; var $GameVersion; var $Players = array(); var $Rules = array(); } class Time { var $Hours; var $Minutes; var $Seconds; function __construct($seconds) { $this->Hours = floor($seconds / 3600); $this->Minutes = floor($seconds / 60) % 60; $this->Seconds = floor($seconds) % 60; } function __toString() { $hours = ($this->Hours < 10 ? '0' . $this->Hours : $this->Hours); $minutes = ($this->Minutes < 10 ? '0' . $this->Minutes : $this->Minutes); $seconds = ($this->Seconds < 10 ? '0' . $this->Seconds : $this->Seconds); return "$hours:$minutes:$seconds"; } } class LSError extends Exception { var $ErrorMessage; var $ErrorCode; function __construct($errcode, $errmsg) { $this->ErrorCode = $errcode; $this->ErrorMessage = $errmsg; } } class Utils { static function getTime() { list($u, $s) = explode(' ', microtime()); return ((float)$u + (float)$s); } static function getString($packet, &$offset, $length = -1) { $len = strlen($packet); $i = 0; if ($length == -1) { while ($offset + $i < $len && $packet[$offset + $i] != "\x00") $i++; $offset += $i + 1; return substr($packet, $offset - $i - 1, $i); } else { $i = $length; if ($len - $offset < $length) $i = $len - $offset; $offset += $i; return substr($packet, $offset - $i, $i); } } static function getByte($packet, &$offset) { if ($offset >= strlen($packet)) return 0; $char = unpack('cchar', $packet[$offset]); $offset++; return $char['char']; } static function getShort($packet, &$offset) { if ($offset + 2 >= strlen($packet)) return 0; $short = unpack('sshort', substr($packet, $offset, 2)); $offset += 2; return $short['short']; } static function getInt($packet, &$offset) { if ($offset + 4 >= strlen($packet)) return 0; $int = unpack('iint', substr($packet, $offset, 4)); $offset += 4; return $int['int']; } static function getFloat($packet, &$offset) { if ($offset + 4 >= strlen($packet)) return ((float)0.0); $float = unpack('ffloat', substr($packet, $offset, 4)); $offset += 4; return ((float)$float['float']); } } class LiveStats { var $IP; var $Port; var $Sock; var $Challenge = "\xFF\xFF\xFF\xFF"; var $HaveInfo = false; var $HavePlayer = false; var $HaveRules = false; var $ResendPlayer = false; var $ResendRules = false; var $SendQueue = array(); var $MaxExecutionTime = 2; var $SplittedPackets = array(); var $SAMPHeader = "SAMP"; var $Server; public function __construct($hostname, $port = 27015) { $this->IP = gethostbyname($hostname); $this->Port = $port; $errno = 0; $errstr = ''; $this->Sock = @stream_socket_client("udp://{$this->IP}:{$this->Port}", $errno, $errstr, 5); if ($this->Sock === false) throw new LSError(1, "Could not connect to specified host [$errno]: $errstr."); if (stream_set_blocking($this->Sock, false) == false) throw new LSError(2, "Could not set to non-blocking mode."); if (stream_set_timeout($this->Sock, 3) == false) throw new LSError(3, "Could not set timeout to 10 seconds."); $this->Server = new Server; $this->Server->Address = "{$this->IP}:{$this->Port}"; $ip = explode('.', $this->IP); $this->SAMPHeader .= chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]) . chr($this->Port & 0xFF) . chr(($this->Port >> 8) & 0xFF); } function onSplittedPacketReceived($packet) { $offset = 4; $ReqID = Utils::getInt($packet, $offset); if (!isset($this->SplittedPackets[$ReqID])) { $this->SplittedPackets[$ReqID] = array( 'Data' => array(), 'Type' => -1, 'Packets' => -1 ); } $this->SplittedPackets[$ReqID]['Data'][] = $packet; if (count($this->SplittedPackets[$ReqID]['Data']) == 2) { $offset = 8; $FB1 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][0], $offset); $offset = 8; $FB2 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][1], $offset); if ($FB1 != $FB2) { $this->SplittedPackets[$ReqID]['Type'] = 0; $this->SplittedPackets[$ReqID]['Packets'] = ($FB1<<4)>>4; } else { $this->SplittedPackets[$ReqID]['Type'] = 1; $this->SplittedPackets[$ReqID]['Packets'] = $FB1; } } if (count($this->SplittedPackets[$ReqID]['Data']) == $this->SplittedPackets[$ReqID]['Packets']) { if ($this->SplittedPackets[$ReqID]['Type'] == 0) { for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) { $offset = 8; $PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset)>>4; if ($i != $PckID) { $aux = $this->SplittedPackets[$ReqID]['Data'][$PckID]; $this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i]; $this->SplittedPackets[$ReqID]['Data'][$i] = $aux; $i--; } } $packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 13); for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) $packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 9); } else { for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) { $offset = 9; $PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset); if ($i != $PckID) { $aux = $this->SplittedPackets[$ReqID]['Data'][$PckID]; $this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i]; $this->SplittedPackets[$ReqID]['Data'][$i] = $aux; $i--; } } $packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 16); for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) $packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 12); } unset($this->SplittedPackets[$ReqID]); $this->onPacketReceived($packet); } } function onPacketReceived($packet) { $offset = 4; switch (Utils::getByte($packet, $offset)) { case 0x41: // challenge $this->Challenge = substr($packet, 5); if ($this->ResendPlayer) { $this->ResendPlayer = false; $this->requestPlayer(); } if ($this->ResendRules) { $this->ResendRules = false; $this->requestRules(); } break; case 0x44: // player if ($this->HavePlayer) break; $offset = 5; $numplayers = Utils::getByte($packet, $offset); while ($numplayers) { $Player = new Player; $Player->ID = Utils::getByte($packet, $offset); $Player->Name = Utils::getString($packet, $offset); $len = strlen($Player->Name); $Player->Score = Utils::getInt($packet, $offset); $Player->TimePlayed = new Time(Utils::getFloat($packet, $offset)); $numplayers--; array_push($this->Server->Players, $Player); } $this->HavePlayer = true; $this->ResendPlayer = false; break; case 0x49: // info, source if ($this->HaveInfo) break; $offset = 5; $this->Server->ProtocolVersion = Utils::getByte($packet, $offset); $this->Server->Hostname = Utils::getString($packet, $offset); $this->Server->Map = Utils::getString($packet, $offset); $this->Server->Directory = Utils::getString($packet, $offset); $this->Server->Description = Utils::getString($packet, $offset); $this->Server->AppID = Utils::getShort($packet, $offset); $this->Server->PlayerCount = Utils::getByte($packet, $offset); $this->Server->MaxPlayers = Utils::getByte($packet, $offset); $this->Server->BotCount = Utils::getByte($packet, $offset); $this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false); $this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows'); $this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false); $this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false); $TheShipAppIDs = array(2400, 2401, 2402, 2412, 2430, 2406, 2405, 2403); if (in_array($this->Server->AppID, $TheShipAppIDs)) { $gm = Utils::getByte($packet, $offset); $GameModes = array('Hunt', 'Elimination', 'Duel', 'Deathmatch', 'Team VIP', 'Team Elimination'); $this->Server->GameMode = (isset($GameModes[$gm]) ? $GameModes[$gm] : 'Unknown'); $this->Server->WitnessCount = Utils::getByte($packet, $offset); $this->Server->WitnessTime = Utils::getByte($packet, $offset); } $this->Server->GameVersion = Utils::getString($packet, $offset); $this->HaveInfo = true; break; case 0x6D: // info, goldsource if ($this->HaveInfo) break; $offset = 5; Utils::getString($packet, $offset); $this->Server->Hostname = Utils::getString($packet, $offset); $this->Server->Map = Utils::getString($packet, $offset); $this->Server->Directory = Utils::getString($packet, $offset); $this->Server->Description = Utils::getString($packet, $offset); $this->Server->PlayerCount = Utils::getByte($packet, $offset); $this->Server->MaxPlayers = Utils::getByte($packet, $offset); $this->Server->ProtocolVersion = Utils::getByte($packet, $offset); $this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false); $this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows'); $this->Server->AppID = ($this->Server->OS == 'Linux' ? 4 : 5); $this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false); $IsMod = Utils::getByte($packet, $offset); if ($IsMod == 1) { Utils::getString($packet, $offset); Utils::getString($packet, $offset); Utils::getByte($packet, $offset); Utils::getInt($packet, $offset); Utils::getInt($packet, $offset); Utils::getByte($packet, $offset); Utils::getByte($packet, $offset); } $this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false); $this->Server->BotCount = Utils::getByte($packet, $offset); $this->HaveInfo = true; break; case 0x45: // rules if ($this->HaveRules) break; $offset = 5; $rulesnum = Utils::getShort($packet, $offset); while ($rulesnum) { $Name = Utils::getString($packet, $offset); $Value = Utils::getString($packet, $offset); $rulesnum--; $this->Server->Rules[$Name] = $Value; } $this->HaveRules = true; $this->ResendRules = false; break; default: break; } } function onSampPacketReceived($packet) { $offset = 10; switch (Utils::getByte($packet, $offset)) { case 0x69: // info if ($this->HaveInfo) break; $this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false); $this->Server->PlayerCount = Utils::getShort($packet, $offset); $this->Server->MaxPlayers = Utils::getShort($packet, $offset); $len = Utils::getInt($packet, $offset); $this->Server->Hostname = Utils::getString($packet, $offset, $len); $len = Utils::getInt($packet, $offset); $this->Server->GameMode = Utils::getString($packet, $offset, $len); $len = Utils::getInt($packet, $offset); $this->Server->Map = Utils::getString($packet, $offset, $len); $this->HaveInfo = true; if ($this->Server->PlayerCount >= 100) $this->HavePlayer = true; break; case 0x72: // rules if ($this->HaveRules) break; $rulesnum = Utils::getShort($packet, $offset); while ($rulesnum) { $len = Utils::getByte($packet, $offset); $Name = Utils::getString($packet, $offset, $len); $len = Utils::getByte($packet, $offset); $Value = Utils::getString($packet, $offset, $len); $rulesnum--; $this->Server->Rules[$Name] = $Value; } $this->HaveRules = true; break; case 0x64: // player if ($this->HavePlayer) break; $numplayers = Utils::getShort($packet, $offset); $lastID = 0; $plusID = 0; while ($numplayers) { $Player = new Player; $Player->ID = Utils::getByte($packet, $offset) + $plusID; if ($Player->ID < $lastID) { $Player->ID += 256; $plusID += 256; } $lastID = $Player->ID; $len = Utils::getByte($packet, $offset); $Player->Name = Utils::getString($packet, $offset, $len); $len = strlen($Player->Name); $Player->Score = Utils::getInt($packet, $offset); $Player->Ping = Utils::getInt($packet, $offset); $numplayers--; array_push($this->Server->Players, $Player); } $this->HavePlayer = true; break; default: break; } } function requestInfo() { array_push($this->SendQueue, "\xFF\xFF\xFF\xFFTSource Engine Query\x00"); array_push($this->SendQueue, $this->SAMPHeader . "i"); } function requestPlayer() { array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x55" . $this->Challenge); array_push($this->SendQueue, $this->SAMPHeader . "d"); if ($this->Challenge == "\xFF\xFF\xFF\xFF") $this->ResendPlayer = true; } function requestRules() { array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x56" . $this->Challenge); array_push($this->SendQueue, $this->SAMPHeader . "r"); if ($this->Challenge == "\xFF\xFF\xFF\xFF") $this->ResendRules = true; } function GetServer() { $start = Utils::getTime(); $this->requestInfo(); $this->requestPlayer(); $this->requestRules(); while (!($this->HaveRules && $this->HaveInfo && $this->HavePlayer)) { if (Utils::getTime() - $start >= $this->MaxExecutionTime) { if ($this->HaveInfo && $this->HavePlayer) { $this->HaveRules = true; } else { throw new LSError(4, "Timed out."); } } if (count($this->SendQueue) > 0) { stream_socket_sendto($this->Sock, array_shift($this->SendQueue)); $meta = stream_get_meta_data($this->Sock); if ($meta['timed_out']) throw new LSError(5, "Timed out."); } usleep(50000); $packet = fread($this->Sock, 2048); $meta = stream_get_meta_data($this->Sock); if ($meta['timed_out']) throw new LSError(6, "Timed out."); if (strlen($packet) > 0) { $offset = 0; switch (Utils::getInt($packet, $offset)) { case HL_PACKET: if (!in_array($this->Server->Type, array(0, 1))) break; $this->Server->Type = 1; $this->onPacketReceived($packet); break; case HL_PACKET_SPLITTED: if (!in_array($this->Server->Type, array(0, 1))) break; $this->Server->Type = 1; $this->onSplittedPacketReceived($packet); break; case SAMP_PACKET: if (!in_array($this->Server->Type, array(0, 2))) break; $this->Server->Type = 2; $this->onSampPacketReceived($packet); break; default: break; } } } return $this->Server; } } ?>
更改後文本
開啟檔案
<?php /* LiveStats Library version: 2.0 query engines: Goldsource, Source, SA:MP protocol: 47, 48 author: nr913 visit www.foxh.ro */ define('HL_PACKET', -1); define('HL_PACKET_SPLITTED', -2); define('SAMP_PACKET', 1347240275); class Player { var $ID; var $Name; var $Score; var $TimePlayed; var $Ping; } class Server { var $Type = 0; var $ProtocolVersion; var $Address; var $Hostname; var $Map; var $Directory; var $Description; var $AppID; var $MaxPlayers; var $PlayerCount; var $BotCount; var $Dedicated; var $OS; var $PasswordProtected; var $Secured; var $GameMode; var $WitnessCount; var $WitnessTime; var $GameVersion; var $Players = array(); var $Rules = array(); } class Time { var $Hours; var $Minutes; var $Seconds; function __construct($seconds) { $this->Hours = floor($seconds / 3600); $this->Minutes = floor($seconds / 60) % 60; $this->Seconds = floor($seconds) % 60; } function __toString() { $hours = ($this->Hours < 10 ? '0' . $this->Hours : $this->Hours); $minutes = ($this->Minutes < 10 ? '0' . $this->Minutes : $this->Minutes); $seconds = ($this->Seconds < 10 ? '0' . $this->Seconds : $this->Seconds); return "$hours:$minutes:$seconds"; } } class LSError extends Exception { var $ErrorMessage; var $ErrorCode; function __construct($errcode, $errmsg) { $this->ErrorCode = $errcode; $this->ErrorMessage = $errmsg; } } class Utils { static function getTime() { list($u, $s) = explode(' ', microtime()); return ((float)$u + (float)$s); } static function getString($packet, &$offset, $length = -1) { $len = strlen($packet); $i = 0; if ($length == -1) { while ($offset + $i < $len && $packet[$offset + $i] != "\x00") $i++; $offset += $i + 1; return substr($packet, $offset - $i - 1, $i); } else { $i = $length; if ($len - $offset < $length) $i = $len - $offset; $offset += $i; return substr($packet, $offset - $i, $i); } } static function getByte($packet, &$offset) { if ($offset >= strlen($packet)) return 0; $char = unpack('cchar', $packet[$offset]); $offset++; return $char['char']; } static function getShort($packet, &$offset) { if ($offset + 2 >= strlen($packet)) return 0; $short = unpack('sshort', substr($packet, $offset, 2)); $offset += 2; return $short['short']; } static function getInt($packet, &$offset) { if ($offset + 4 >= strlen($packet)) return 0; $int = unpack('iint', substr($packet, $offset, 4)); $offset += 4; return $int['int']; } static function getFloat($packet, &$offset) { if ($offset + 4 >= strlen($packet)) return ((float)0.0); $float = unpack('ffloat', substr($packet, $offset, 4)); $offset += 4; return ((float)$float['float']); } } class LiveStats { var $IP; var $Port; var $Sock; var $Challenge = "\xFF\xFF\xFF\xFF"; var $HaveInfo = false; var $HavePlayer = false; var $HaveRules = false; var $ResendPlayer = false; var $ResendRules = false; var $SendQueue = array(); var $MaxExecutionTime = 2; var $SplittedPackets = array(); var $SAMPHeader = "SAMP"; var $Server; public function __construct($hostname, $port = 27015) { $this->IP = gethostbyname($hostname); $this->Port = $port; $errno = 0; $errstr = ''; $this->Sock = @stream_socket_client("udp://{$this->IP}:{$this->Port}", $errno, $errstr, 5); if ($this->Sock === false) throw new LSError(1, "Could not connect to specified host [$errno]: $errstr."); if (stream_set_blocking($this->Sock, false) == false) throw new LSError(2, "Could not set to non-blocking mode."); if (stream_set_timeout($this->Sock, 3) == false) throw new LSError(3, "Could not set timeout to 10 seconds."); $this->Server = new Server; $this->Server->Address = "{$this->IP}:{$this->Port}"; $ip = explode('.', $this->IP); $this->SAMPHeader .= chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]) . chr($this->Port & 0xFF) . chr(($this->Port >> 8) & 0xFF); } function onSplittedPacketReceived($packet) { $offset = 4; $ReqID = Utils::getInt($packet, $offset); if (!isset($this->SplittedPackets[$ReqID])) { $this->SplittedPackets[$ReqID] = array( 'Data' => array(), 'Type' => -1, 'Packets' => -1 ); } $this->SplittedPackets[$ReqID]['Data'][] = $packet; if (count($this->SplittedPackets[$ReqID]['Data']) == 2) { $offset = 8; $FB1 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][0], $offset); $offset = 8; $FB2 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][1], $offset); if ($FB1 != $FB2) { $this->SplittedPackets[$ReqID]['Type'] = 0; $this->SplittedPackets[$ReqID]['Packets'] = ($FB1<<4)>>4; } else { $this->SplittedPackets[$ReqID]['Type'] = 1; $this->SplittedPackets[$ReqID]['Packets'] = $FB1; } } if (count($this->SplittedPackets[$ReqID]['Data']) == $this->SplittedPackets[$ReqID]['Packets']) { if ($this->SplittedPackets[$ReqID]['Type'] == 0) { for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) { $offset = 8; $PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset)>>4; if ($i != $PckID) { $aux = $this->SplittedPackets[$ReqID]['Data'][$PckID]; $this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i]; $this->SplittedPackets[$ReqID]['Data'][$i] = $aux; $i--; } } $packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 13); for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) $packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 9); } else { for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) { $offset = 9; $PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset); if ($i != $PckID) { $aux = $this->SplittedPackets[$ReqID]['Data'][$PckID]; $this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i]; $this->SplittedPackets[$ReqID]['Data'][$i] = $aux; $i--; } } $packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 16); for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) $packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 12); } unset($this->SplittedPackets[$ReqID]); $this->onPacketReceived($packet); } } function onPacketReceived($packet) { $offset = 4; switch (Utils::getByte($packet, $offset)) { case 0x41: // challenge $this->Challenge = substr($packet, 5); if ($this->ResendPlayer) { $this->ResendPlayer = false; $this->requestPlayer(); } if ($this->ResendRules) { $this->ResendRules = false; $this->requestRules(); } break; case 0x44: // player if ($this->HavePlayer) break; $offset = 5; $numplayers = Utils::getByte($packet, $offset); while ($numplayers) { $Player = new Player; $Player->ID = Utils::getByte($packet, $offset); $Player->Name = Utils::getString($packet, $offset); $len = strlen($Player->Name); $Player->Score = Utils::getInt($packet, $offset); $Player->TimePlayed = new Time(Utils::getFloat($packet, $offset)); $numplayers--; array_push($this->Server->Players, $Player); } $this->HavePlayer = true; $this->ResendPlayer = false; break; case 0x49: // info, source if ($this->HaveInfo) break; $offset = 5; $this->Server->ProtocolVersion = Utils::getByte($packet, $offset); $this->Server->Hostname = Utils::getString($packet, $offset); $this->Server->Map = Utils::getString($packet, $offset); $this->Server->Directory = Utils::getString($packet, $offset); $this->Server->Description = Utils::getString($packet, $offset); $this->Server->AppID = Utils::getShort($packet, $offset); $this->Server->PlayerCount = Utils::getByte($packet, $offset); $this->Server->MaxPlayers = Utils::getByte($packet, $offset); $this->Server->BotCount = Utils::getByte($packet, $offset); $this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false); $this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows'); $this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false); $this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false); $TheShipAppIDs = array(2400, 2401, 2402, 2412, 2430, 2406, 2405, 2403); if (in_array($this->Server->AppID, $TheShipAppIDs)) { $gm = Utils::getByte($packet, $offset); $GameModes = array('Hunt', 'Elimination', 'Duel', 'Deathmatch', 'Team VIP', 'Team Elimination'); $this->Server->GameMode = (isset($GameModes[$gm]) ? $GameModes[$gm] : 'Unknown'); $this->Server->WitnessCount = Utils::getByte($packet, $offset); $this->Server->WitnessTime = Utils::getByte($packet, $offset); } $this->Server->GameVersion = Utils::getString($packet, $offset); $this->HaveInfo = true; break; case 0x6D: // info, goldsource if ($this->HaveInfo) break; $offset = 5; Utils::getString($packet, $offset); $this->Server->Hostname = Utils::getString($packet, $offset); $this->Server->Map = Utils::getString($packet, $offset); $this->Server->Directory = Utils::getString($packet, $offset); $this->Server->Description = Utils::getString($packet, $offset); $this->Server->PlayerCount = Utils::getByte($packet, $offset); $this->Server->MaxPlayers = Utils::getByte($packet, $offset); $this->Server->ProtocolVersion = Utils::getByte($packet, $offset); $this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false); $this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows'); $this->Server->AppID = ($this->Server->OS == 'Linux' ? 4 : 5); $this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false); $IsMod = Utils::getByte($packet, $offset); if ($IsMod == 1) { Utils::getString($packet, $offset); Utils::getString($packet, $offset); Utils::getByte($packet, $offset); Utils::getInt($packet, $offset); Utils::getInt($packet, $offset); Utils::getByte($packet, $offset); Utils::getByte($packet, $offset); } $this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false); $this->Server->BotCount = Utils::getByte($packet, $offset); $this->HaveInfo = true; break; case 0x45: // rules if ($this->HaveRules) break; $offset = 5; $rulesnum = Utils::getShort($packet, $offset); while ($rulesnum) { $Name = Utils::getString($packet, $offset); $Value = Utils::getString($packet, $offset); $rulesnum--; $this->Server->Rules[$Name] = $Value; } $this->HaveRules = true; $this->ResendRules = false; break; default: break; } } function onSampPacketReceived($packet) { $offset = 10; switch (Utils::getByte($packet, $offset)) { case 0x69: // info if ($this->HaveInfo) break; $this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false); $this->Server->PlayerCount = Utils::getShort($packet, $offset); $this->Server->MaxPlayers = Utils::getShort($packet, $offset); $len = Utils::getInt($packet, $offset); $this->Server->Hostname = Utils::getString($packet, $offset, $len); $len = Utils::getInt($packet, $offset); $this->Server->GameMode = Utils::getString($packet, $offset, $len); $len = Utils::getInt($packet, $offset); $this->Server->Map = Utils::getString($packet, $offset, $len); $this->HaveInfo = true; if ($this->Server->PlayerCount >= 100) $this->HavePlayer = true; break; case 0x72: // rules if ($this->HaveRules) break; $rulesnum = Utils::getShort($packet, $offset); while ($rulesnum) { $len = Utils::getByte($packet, $offset); $Name = Utils::getString($packet, $offset, $len); $len = Utils::getByte($packet, $offset); $Value = Utils::getString($packet, $offset, $len); $rulesnum--; $this->Server->Rules[$Name] = $Value; } $this->HaveRules = true; break; case 0x64: // player if ($this->HavePlayer) break; $numplayers = Utils::getShort($packet, $offset); $lastID = 0; $plusID = 0; while ($numplayers) { $Player = new Player; $Player->ID = Utils::getByte($packet, $offset) + $plusID; if ($Player->ID < $lastID) { $Player->ID += 256; $plusID += 256; } $lastID = $Player->ID; $len = Utils::getByte($packet, $offset); $Player->Name = Utils::getString($packet, $offset, $len); $len = strlen($Player->Name); $Player->Score = Utils::getInt($packet, $offset); $Player->Ping = Utils::getInt($packet, $offset); $numplayers--; array_push($this->Server->Players, $Player); } $this->HavePlayer = true; break; default: break; } } function requestInfo() { array_push($this->SendQueue, "\xFF\xFF\xFF\xFFTSource Engine Query\x00"); array_push($this->SendQueue, $this->SAMPHeader . "i"); } function requestPlayer() { array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x55" . $this->Challenge); array_push($this->SendQueue, $this->SAMPHeader . "d"); if ($this->Challenge == "\xFF\xFF\xFF\xFF") $this->ResendPlayer = true; } function requestRules() { array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x56" . $this->Challenge); array_push($this->SendQueue, $this->SAMPHeader . "r"); if ($this->Challenge == "\xFF\xFF\xFF\xFF") $this->ResendRules = true; } function GetServer() { $start = Utils::getTime(); $this->requestInfo(); $this->requestPlayer(); $this->requestRules(); while (!($this->HaveRules && $this->HaveInfo && $this->HavePlayer)) { if (Utils::getTime() - $start >= $this->MaxExecutionTime) { if ($this->HaveInfo && $this->HavePlayer) { $this->HaveRules = true; } else { throw new LSError(4, "Timed out."); } } if (count($this->SendQueue) > 0) { stream_socket_sendto($this->Sock, array_shift($this->SendQueue)); $meta = stream_get_meta_data($this->Sock); if ($meta['timed_out']) throw new LSError(5, "Timed out."); } usleep(50000); $packet = fread($this->Sock, 2048); $meta = stream_get_meta_data($this->Sock); if ($meta['timed_out']) throw new LSError(6, "Timed out."); if (strlen($packet) > 0) { $offset = 0; switch (Utils::getInt($packet, $offset)) { case HL_PACKET: if (!in_array($this->Server->Type, array(0, 1))) break; $this->Server->Type = 1; $this->onPacketReceived($packet); break; case HL_PACKET_SPLITTED: if (!in_array($this->Server->Type, array(0, 1))) break; $this->Server->Type = 1; $this->onSplittedPacketReceived($packet); break; case SAMP_PACKET: if (!in_array($this->Server->Type, array(0, 2))) break; $this->Server->Type = 2; $this->onSampPacketReceived($packet); break; default: break; } } } return $this->Server; } } ?>
尋找差異