Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 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; } } ?>
비교하기