Diff
checker
Texte
Texte
Images
Documents
Excel
Dossiers
Legal
Enterprise
Application de bureau
Prix
Se connecter
Télécharger Diffchecker Desktop
Comparer le texte
Trouver la différence entre deux fichiers texte
Outils
Historique
Éditeur live
Masquer les espaces
Cacher identiques
Sans retour à la ligne
Vue
Divisé
Unifié
Niveau de précision
Intelligent
Mot
Caractère
Styles de texte
Modifier l’apparence
Coloration syntaxique
Choisir la syntaxe
Ignorer
Transformer le texte
Aller au premier écart
Modifier l'entrée
Diffchecker Desktop
La façon la plus sécurisée d'utiliser Diffchecker. Obtenez l'application Diffchecker Desktop : vos diffs ne quittent jamais votre ordinateur !
Obtenir Desktop
Untitled diff
Créé
il y a 9 ans
Le diff n'expire jamais
Effacer
Exporter
Partager
Expliquer
1 suppression
Lignes
Total
Supprimé
Caractères
Total
Supprimé
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
488 lignes
Copier tout
492 ajouts
Lignes
Total
Ajouté
Caractères
Total
Ajouté
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
977 lignes
Copier tout
<?php
<?php
Copier
Copié
Copier
Copié
/*
/*
Copier
Copié
Copier
Copié
LiveStats Library
LiveStats Library
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
version: 2.0
version: 2.0
Copier
Copié
Copier
Copié
query engines: Goldsource, Source, SA:MP
query engines: Goldsource, Source, SA:MP
Copier
Copié
Copier
Copié
protocol: 47, 48
protocol: 47, 48
Copier
Copié
Copier
Copié
author: nr913
author: nr913
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
visit www.
freakz
.ro
visit www.
foxh
.ro
*/
*/
Copier
Copié
Copier
Copié
define('HL_PACKET', -1);
define('HL_PACKET', -1);
Copier
Copié
Copier
Copié
define('HL_PACKET_SPLITTED', -2);
define('HL_PACKET_SPLITTED', -2);
Copier
Copié
Copier
Copié
define('SAMP_PACKET', 1347240275);
define('SAMP_PACKET', 1347240275);
Copier
Copié
Copier
Copié
class Player {
class Player {
Copier
Copié
Copier
Copié
var $ID;
var $ID;
Copier
Copié
Copier
Copié
var $Name;
var $Name;
Copier
Copié
Copier
Copié
var $Score;
var $Score;
Copier
Copié
Copier
Copié
var $TimePlayed;
var $TimePlayed;
Copier
Copié
Copier
Copié
var $Ping;
var $Ping;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
class Server {
class Server {
Copier
Copié
Copier
Copié
var $Type = 0;
var $Type = 0;
Copier
Copié
Copier
Copié
var $ProtocolVersion;
var $ProtocolVersion;
Copier
Copié
Copier
Copié
var $Address;
var $Address;
Copier
Copié
Copier
Copié
var $Hostname;
var $Hostname;
Copier
Copié
Copier
Copié
var $Map;
var $Map;
Copier
Copié
Copier
Copié
var $Directory;
var $Directory;
Copier
Copié
Copier
Copié
var $Description;
var $Description;
Copier
Copié
Copier
Copié
var $AppID;
var $AppID;
Copier
Copié
Copier
Copié
var $MaxPlayers;
var $MaxPlayers;
Copier
Copié
Copier
Copié
var $PlayerCount;
var $PlayerCount;
Copier
Copié
Copier
Copié
var $BotCount;
var $BotCount;
Copier
Copié
Copier
Copié
var $Dedicated;
var $Dedicated;
Copier
Copié
Copier
Copié
var $OS;
var $OS;
Copier
Copié
Copier
Copié
var $PasswordProtected;
var $PasswordProtected;
Copier
Copié
Copier
Copié
var $Secured;
var $Secured;
Copier
Copié
Copier
Copié
var $GameMode;
var $GameMode;
Copier
Copié
Copier
Copié
var $WitnessCount;
var $WitnessCount;
Copier
Copié
Copier
Copié
var $WitnessTime;
var $WitnessTime;
Copier
Copié
Copier
Copié
var $GameVersion;
var $GameVersion;
Copier
Copié
Copier
Copié
var $Players = array();
var $Players = array();
Copier
Copié
Copier
Copié
var $Rules = array();
var $Rules = array();
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
class Time {
class Time {
Copier
Copié
Copier
Copié
var $Hours;
var $Hours;
Copier
Copié
Copier
Copié
var $Minutes;
var $Minutes;
Copier
Copié
Copier
Copié
var $Seconds;
var $Seconds;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function __construct($seconds) {
function __construct($seconds) {
Copier
Copié
Copier
Copié
$this->Hours = floor($seconds / 3600);
$this->Hours = floor($seconds / 3600);
Copier
Copié
Copier
Copié
$this->Minutes = floor($seconds / 60) % 60;
$this->Minutes = floor($seconds / 60) % 60;
Copier
Copié
Copier
Copié
$this->Seconds = floor($seconds) % 60;
$this->Seconds = floor($seconds) % 60;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function __toString() {
function __toString() {
Copier
Copié
Copier
Copié
$hours = ($this->Hours < 10 ? '0' . $this->Hours : $this->Hours);
$hours = ($this->Hours < 10 ? '0' . $this->Hours : $this->Hours);
Copier
Copié
Copier
Copié
$minutes = ($this->Minutes < 10 ? '0' . $this->Minutes : $this->Minutes);
$minutes = ($this->Minutes < 10 ? '0' . $this->Minutes : $this->Minutes);
Copier
Copié
Copier
Copié
$seconds = ($this->Seconds < 10 ? '0' . $this->Seconds : $this->Seconds);
$seconds = ($this->Seconds < 10 ? '0' . $this->Seconds : $this->Seconds);
Copier
Copié
Copier
Copié
return "$hours:$minutes:$seconds";
return "$hours:$minutes:$seconds";
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
class LSError extends Exception {
class LSError extends Exception {
Copier
Copié
Copier
Copié
var $ErrorMessage;
var $ErrorMessage;
Copier
Copié
Copier
Copié
var $ErrorCode;
var $ErrorCode;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function __construct($errcode, $errmsg) {
function __construct($errcode, $errmsg) {
Copier
Copié
Copier
Copié
$this->ErrorCode = $errcode;
$this->ErrorCode = $errcode;
Copier
Copié
Copier
Copié
$this->ErrorMessage = $errmsg;
$this->ErrorMessage = $errmsg;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
class Utils {
class Utils {
Copier
Copié
Copier
Copié
static function getTime() {
static function getTime() {
Copier
Copié
Copier
Copié
list($u, $s) = explode(' ', microtime());
list($u, $s) = explode(' ', microtime());
Copier
Copié
Copier
Copié
return ((float)$u + (float)$s);
return ((float)$u + (float)$s);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
static function getString($packet, &$offset, $length = -1) {
static function getString($packet, &$offset, $length = -1) {
Copier
Copié
Copier
Copié
$len = strlen($packet);
$len = strlen($packet);
Copier
Copié
Copier
Copié
$i = 0;
$i = 0;
Copier
Copié
Copier
Copié
if ($length == -1) {
if ($length == -1) {
Copier
Copié
Copier
Copié
while ($offset + $i < $len && $packet[$offset + $i] != "\x00")
while ($offset + $i < $len && $packet[$offset + $i] != "\x00")
Copier
Copié
Copier
Copié
$i++;
$i++;
Copier
Copié
Copier
Copié
$offset += $i + 1;
$offset += $i + 1;
Copier
Copié
Copier
Copié
return substr($packet, $offset - $i - 1, $i);
return substr($packet, $offset - $i - 1, $i);
Copier
Copié
Copier
Copié
} else {
} else {
Copier
Copié
Copier
Copié
$i = $length;
$i = $length;
Copier
Copié
Copier
Copié
if ($len - $offset < $length)
if ($len - $offset < $length)
Copier
Copié
Copier
Copié
$i = $len - $offset;
$i = $len - $offset;
Copier
Copié
Copier
Copié
$offset += $i;
$offset += $i;
Copier
Copié
Copier
Copié
return substr($packet, $offset - $i, $i);
return substr($packet, $offset - $i, $i);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
static function getByte($packet, &$offset) {
static function getByte($packet, &$offset) {
Copier
Copié
Copier
Copié
if ($offset >= strlen($packet))
if ($offset >= strlen($packet))
Copier
Copié
Copier
Copié
return 0;
return 0;
Copier
Copié
Copier
Copié
$char = unpack('cchar', $packet[$offset]);
$char = unpack('cchar', $packet[$offset]);
Copier
Copié
Copier
Copié
$offset++;
$offset++;
Copier
Copié
Copier
Copié
return $char['char'];
return $char['char'];
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
static function getShort($packet, &$offset) {
static function getShort($packet, &$offset) {
Copier
Copié
Copier
Copié
if ($offset + 2 >= strlen($packet))
if ($offset + 2 >= strlen($packet))
Copier
Copié
Copier
Copié
return 0;
return 0;
Copier
Copié
Copier
Copié
$short = unpack('sshort', substr($packet, $offset, 2));
$short = unpack('sshort', substr($packet, $offset, 2));
Copier
Copié
Copier
Copié
$offset += 2;
$offset += 2;
Copier
Copié
Copier
Copié
return $short['short'];
return $short['short'];
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
static function getInt($packet, &$offset) {
static function getInt($packet, &$offset) {
Copier
Copié
Copier
Copié
if ($offset + 4 >= strlen($packet))
if ($offset + 4 >= strlen($packet))
Copier
Copié
Copier
Copié
return 0;
return 0;
Copier
Copié
Copier
Copié
$int = unpack('iint', substr($packet, $offset, 4));
$int = unpack('iint', substr($packet, $offset, 4));
Copier
Copié
Copier
Copié
$offset += 4;
$offset += 4;
Copier
Copié
Copier
Copié
return $int['int'];
return $int['int'];
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
static function getFloat($packet, &$offset) {
static function getFloat($packet, &$offset) {
Copier
Copié
Copier
Copié
if ($offset + 4 >= strlen($packet))
if ($offset + 4 >= strlen($packet))
Copier
Copié
Copier
Copié
return ((float)0.0);
return ((float)0.0);
Copier
Copié
Copier
Copié
$float = unpack('ffloat', substr($packet, $offset, 4));
$float = unpack('ffloat', substr($packet, $offset, 4));
Copier
Copié
Copier
Copié
$offset += 4;
$offset += 4;
Copier
Copié
Copier
Copié
return ((float)$float['float']);
return ((float)$float['float']);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
class LiveStats {
class LiveStats {
Copier
Copié
Copier
Copié
var $IP;
var $IP;
Copier
Copié
Copier
Copié
var $Port;
var $Port;
Copier
Copié
Copier
Copié
var $Sock;
var $Sock;
Copier
Copié
Copier
Copié
var $Challenge = "\xFF\xFF\xFF\xFF";
var $Challenge = "\xFF\xFF\xFF\xFF";
Copier
Copié
Copier
Copié
var $HaveInfo = false;
var $HaveInfo = false;
Copier
Copié
Copier
Copié
var $HavePlayer = false;
var $HavePlayer = false;
Copier
Copié
Copier
Copié
var $HaveRules = false;
var $HaveRules = false;
Copier
Copié
Copier
Copié
var $ResendPlayer = false;
var $ResendPlayer = false;
Copier
Copié
Copier
Copié
var $ResendRules = false;
var $ResendRules = false;
Copier
Copié
Copier
Copié
var $SendQueue = array();
var $SendQueue = array();
Copier
Copié
Copier
Copié
var $MaxExecutionTime = 2;
var $MaxExecutionTime = 2;
Copier
Copié
Copier
Copié
var $SplittedPackets = array();
var $SplittedPackets = array();
Copier
Copié
Copier
Copié
var $SAMPHeader = "SAMP";
var $SAMPHeader = "SAMP";
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
var $Server;
var $Server;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
public function __construct($hostname, $port = 27015) {
public function __construct($hostname, $port = 27015) {
Copier
Copié
Copier
Copié
$this->IP = gethostbyname($hostname);
$this->IP = gethostbyname($hostname);
Copier
Copié
Copier
Copié
$this->Port = $port;
$this->Port = $port;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$errno = 0; $errstr = '';
$errno = 0; $errstr = '';
Copier
Copié
Copier
Copié
$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);
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
if ($this->Sock === false)
if ($this->Sock === false)
Copier
Copié
Copier
Copié
throw new LSError(1, "Could not connect to specified host [$errno]: $errstr.");
throw new LSError(1, "Could not connect to specified host [$errno]: $errstr.");
Copier
Copié
Copier
Copié
if (stream_set_blocking($this->Sock, false) == false)
if (stream_set_blocking($this->Sock, false) == false)
Copier
Copié
Copier
Copié
throw new LSError(2, "Could not set to non-blocking mode.");
throw new LSError(2, "Could not set to non-blocking mode.");
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
if (stream_set_timeout($this->Sock, 3) == false)
if (stream_set_timeout($this->Sock, 3) == false)
Copier
Copié
Copier
Copié
throw new LSError(3, "Could not set timeout to 10 seconds.");
throw new LSError(3, "Could not set timeout to 10 seconds.");
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$this->Server = new Server;
$this->Server = new Server;
Copier
Copié
Copier
Copié
$this->Server->Address = "{$this->IP}:{$this->Port}";
$this->Server->Address = "{$this->IP}:{$this->Port}";
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$ip = explode('.', $this->IP);
$ip = explode('.', $this->IP);
Copier
Copié
Copier
Copié
$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);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function onSplittedPacketReceived($packet) {
function onSplittedPacketReceived($packet) {
Copier
Copié
Copier
Copié
$offset = 4;
$offset = 4;
Copier
Copié
Copier
Copié
$ReqID = Utils::getInt($packet, $offset);
$ReqID = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
if (!isset($this->SplittedPackets[$ReqID])) {
if (!isset($this->SplittedPackets[$ReqID])) {
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID] = array(
$this->SplittedPackets[$ReqID] = array(
Copier
Copié
Copier
Copié
'Data' => array(),
'Data' => array(),
Copier
Copié
Copier
Copié
'Type' => -1,
'Type' => -1,
Copier
Copié
Copier
Copié
'Packets' => -1
'Packets' => -1
Copier
Copié
Copier
Copié
);
);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Data'][] = $packet;
$this->SplittedPackets[$ReqID]['Data'][] = $packet;
Copier
Copié
Copier
Copié
if (count($this->SplittedPackets[$ReqID]['Data']) == 2) {
if (count($this->SplittedPackets[$ReqID]['Data']) == 2) {
Copier
Copié
Copier
Copié
$offset = 8;
$offset = 8;
Copier
Copié
Copier
Copié
$FB1 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][0], $offset);
$FB1 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][0], $offset);
Copier
Copié
Copier
Copié
$offset = 8;
$offset = 8;
Copier
Copié
Copier
Copié
$FB2 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][1], $offset);
$FB2 = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][1], $offset);
Copier
Copié
Copier
Copié
if ($FB1 != $FB2) {
if ($FB1 != $FB2) {
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Type'] = 0;
$this->SplittedPackets[$ReqID]['Type'] = 0;
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Packets'] = ($FB1<<4)>>4;
$this->SplittedPackets[$ReqID]['Packets'] = ($FB1<<4)>>4;
Copier
Copié
Copier
Copié
} else {
} else {
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Type'] = 1;
$this->SplittedPackets[$ReqID]['Type'] = 1;
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Packets'] = $FB1;
$this->SplittedPackets[$ReqID]['Packets'] = $FB1;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
if (count($this->SplittedPackets[$ReqID]['Data']) == $this->SplittedPackets[$ReqID]['Packets']) {
if (count($this->SplittedPackets[$ReqID]['Data']) == $this->SplittedPackets[$ReqID]['Packets']) {
Copier
Copié
Copier
Copié
if ($this->SplittedPackets[$ReqID]['Type'] == 0) {
if ($this->SplittedPackets[$ReqID]['Type'] == 0) {
Copier
Copié
Copier
Copié
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
Copier
Copié
Copier
Copié
$offset = 8;
$offset = 8;
Copier
Copié
Copier
Copié
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset)>>4;
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset)>>4;
Copier
Copié
Copier
Copié
if ($i != $PckID) {
if ($i != $PckID) {
Copier
Copié
Copier
Copié
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
Copier
Copié
Copier
Copié
$i--;
$i--;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 13);
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 13);
Copier
Copié
Copier
Copié
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
Copier
Copié
Copier
Copié
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 9);
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 9);
Copier
Copié
Copier
Copié
} else {
} else {
Copier
Copié
Copier
Copié
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
for ($i = 0; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++) {
Copier
Copié
Copier
Copié
$offset = 9;
$offset = 9;
Copier
Copié
Copier
Copié
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset);
$PckID = Utils::getByte($this->SplittedPackets[$ReqID]['Data'][$i], $offset);
Copier
Copié
Copier
Copié
if ($i != $PckID) {
if ($i != $PckID) {
Copier
Copié
Copier
Copié
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
$aux = $this->SplittedPackets[$ReqID]['Data'][$PckID];
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
$this->SplittedPackets[$ReqID]['Data'][$PckID] = $this->SplittedPackets[$ReqID]['Data'][$i];
Copier
Copié
Copier
Copié
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
$this->SplittedPackets[$ReqID]['Data'][$i] = $aux;
Copier
Copié
Copier
Copié
$i--;
$i--;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 16);
$packet = "\xFF\xFF\xFF\xFF" . substr($this->SplittedPackets[$ReqID]['Data'][0], 16);
Copier
Copié
Copier
Copié
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
for ($i = 1; $i < $this->SplittedPackets[$ReqID]['Packets']; $i++)
Copier
Copié
Copier
Copié
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 12);
$packet .= substr($this->SplittedPackets[$ReqID]['Data'][$i], 12);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
unset($this->SplittedPackets[$ReqID]);
unset($this->SplittedPackets[$ReqID]);
Copier
Copié
Copier
Copié
$this->onPacketReceived($packet);
$this->onPacketReceived($packet);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function onPacketReceived($packet) {
function onPacketReceived($packet) {
Copier
Copié
Copier
Copié
$offset = 4;
$offset = 4;
Copier
Copié
Copier
Copié
switch (Utils::getByte($packet, $offset)) {
switch (Utils::getByte($packet, $offset)) {
Copier
Copié
Copier
Copié
case 0x41: // challenge
case 0x41: // challenge
Copier
Copié
Copier
Copié
$this->Challenge = substr($packet, 5);
$this->Challenge = substr($packet, 5);
Copier
Copié
Copier
Copié
if ($this->ResendPlayer) {
if ($this->ResendPlayer) {
Copier
Copié
Copier
Copié
$this->ResendPlayer = false;
$this->ResendPlayer = false;
Copier
Copié
Copier
Copié
$this->requestPlayer();
$this->requestPlayer();
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
if ($this->ResendRules) {
if ($this->ResendRules) {
Copier
Copié
Copier
Copié
$this->ResendRules = false;
$this->ResendRules = false;
Copier
Copié
Copier
Copié
$this->requestRules();
$this->requestRules();
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case 0x44: // player
case 0x44: // player
Copier
Copié
Copier
Copié
if ($this->HavePlayer)
if ($this->HavePlayer)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$offset = 5;
$offset = 5;
Copier
Copié
Copier
Copié
$numplayers = Utils::getByte($packet, $offset);
$numplayers = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
while ($numplayers) {
while ($numplayers) {
Copier
Copié
Copier
Copié
$Player = new Player;
$Player = new Player;
Copier
Copié
Copier
Copié
$Player->ID = Utils::getByte($packet, $offset);
$Player->ID = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$Player->Name = Utils::getString($packet, $offset);
$Player->Name = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$len = strlen($Player->Name);
$len = strlen($Player->Name);
Copier
Copié
Copier
Copié
$Player->Score = Utils::getInt($packet, $offset);
$Player->Score = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
$Player->TimePlayed = new Time(Utils::getFloat($packet, $offset));
$Player->TimePlayed = new Time(Utils::getFloat($packet, $offset));
Copier
Copié
Copier
Copié
$numplayers--;
$numplayers--;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
array_push($this->Server->Players, $Player);
array_push($this->Server->Players, $Player);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->HavePlayer = true;
$this->HavePlayer = true;
Copier
Copié
Copier
Copié
$this->ResendPlayer = false;
$this->ResendPlayer = false;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case 0x49: // info, source
case 0x49: // info, source
Copier
Copié
Copier
Copié
if ($this->HaveInfo)
if ($this->HaveInfo)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$offset = 5;
$offset = 5;
Copier
Copié
Copier
Copié
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Hostname = Utils::getString($packet, $offset);
$this->Server->Hostname = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Map = Utils::getString($packet, $offset);
$this->Server->Map = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Directory = Utils::getString($packet, $offset);
$this->Server->Directory = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Description = Utils::getString($packet, $offset);
$this->Server->Description = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->AppID = Utils::getShort($packet, $offset);
$this->Server->AppID = Utils::getShort($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->BotCount = Utils::getByte($packet, $offset);
$this->Server->BotCount = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
Copier
Copié
Copier
Copié
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
Copier
Copié
Copier
Copié
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
Copier
Copié
Copier
Copié
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
Copier
Copié
Copier
Copié
$TheShipAppIDs = array(2400, 2401, 2402, 2412, 2430, 2406, 2405, 2403);
$TheShipAppIDs = array(2400, 2401, 2402, 2412, 2430, 2406, 2405, 2403);
Copier
Copié
Copier
Copié
if (in_array($this->Server->AppID, $TheShipAppIDs)) {
if (in_array($this->Server->AppID, $TheShipAppIDs)) {
Copier
Copié
Copier
Copié
$gm = Utils::getByte($packet, $offset);
$gm = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$GameModes = array('Hunt', 'Elimination', 'Duel', 'Deathmatch', 'Team VIP', 'Team Elimination');
$GameModes = array('Hunt', 'Elimination', 'Duel', 'Deathmatch', 'Team VIP', 'Team Elimination');
Copier
Copié
Copier
Copié
$this->Server->GameMode = (isset($GameModes[$gm]) ? $GameModes[$gm] : 'Unknown');
$this->Server->GameMode = (isset($GameModes[$gm]) ? $GameModes[$gm] : 'Unknown');
Copier
Copié
Copier
Copié
$this->Server->WitnessCount = Utils::getByte($packet, $offset);
$this->Server->WitnessCount = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->WitnessTime = Utils::getByte($packet, $offset);
$this->Server->WitnessTime = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->Server->GameVersion = Utils::getString($packet, $offset);
$this->Server->GameVersion = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->HaveInfo = true;
$this->HaveInfo = true;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case 0x6D: // info, goldsource
case 0x6D: // info, goldsource
Copier
Copié
Copier
Copié
if ($this->HaveInfo)
if ($this->HaveInfo)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$offset = 5;
$offset = 5;
Copier
Copié
Copier
Copié
Utils::getString($packet, $offset);
Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Hostname = Utils::getString($packet, $offset);
$this->Server->Hostname = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Map = Utils::getString($packet, $offset);
$this->Server->Map = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Directory = Utils::getString($packet, $offset);
$this->Server->Directory = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Description = Utils::getString($packet, $offset);
$this->Server->Description = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
$this->Server->PlayerCount = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
$this->Server->MaxPlayers = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
$this->Server->ProtocolVersion = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
$this->Server->Dedicated = (Utils::getByte($packet, $offset) == ord('d') ? true : false);
Copier
Copié
Copier
Copié
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
$this->Server->OS = (Utils::getByte($packet, $offset) == 'l' ? 'Linux' : 'Windows');
Copier
Copié
Copier
Copié
$this->Server->AppID = ($this->Server->OS == 'Linux' ? 4 : 5);
$this->Server->AppID = ($this->Server->OS == 'Linux' ? 4 : 5);
Copier
Copié
Copier
Copié
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
Copier
Copié
Copier
Copié
$IsMod = Utils::getByte($packet, $offset);
$IsMod = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
if ($IsMod == 1) {
if ($IsMod == 1) {
Copier
Copié
Copier
Copié
Utils::getString($packet, $offset);
Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
Utils::getString($packet, $offset);
Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
Utils::getByte($packet, $offset);
Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
Utils::getInt($packet, $offset);
Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
Utils::getInt($packet, $offset);
Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
Utils::getByte($packet, $offset);
Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
Utils::getByte($packet, $offset);
Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->Secured = (Utils::getByte($packet, $offset) == 1 ? true : false);
Copier
Copié
Copier
Copié
$this->Server->BotCount = Utils::getByte($packet, $offset);
$this->Server->BotCount = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$this->HaveInfo = true;
$this->HaveInfo = true;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case 0x45: // rules
case 0x45: // rules
Copier
Copié
Copier
Copié
if ($this->HaveRules)
if ($this->HaveRules)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$offset = 5;
$offset = 5;
Copier
Copié
Copier
Copié
$rulesnum = Utils::getShort($packet, $offset);
$rulesnum = Utils::getShort($packet, $offset);
Copier
Copié
Copier
Copié
while ($rulesnum) {
while ($rulesnum) {
Copier
Copié
Copier
Copié
$Name = Utils::getString($packet, $offset);
$Name = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$Value = Utils::getString($packet, $offset);
$Value = Utils::getString($packet, $offset);
Copier
Copié
Copier
Copié
$rulesnum--;
$rulesnum--;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$this->Server->Rules[$Name] = $Value;
$this->Server->Rules[$Name] = $Value;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->HaveRules = true;
$this->HaveRules = true;
Copier
Copié
Copier
Copié
$this->ResendRules = false;
$this->ResendRules = false;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
default:
default:
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function onSampPacketReceived($packet) {
function onSampPacketReceived($packet) {
Copier
Copié
Copier
Copié
$offset = 10;
$offset = 10;
Copier
Copié
Copier
Copié
switch (Utils::getByte($packet, $offset)) {
switch (Utils::getByte($packet, $offset)) {
Copier
Copié
Copier
Copié
case 0x69: // info
case 0x69: // info
Copier
Copié
Copier
Copié
if ($this->HaveInfo)
if ($this->HaveInfo)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
$this->Server->PasswordProtected = (Utils::getByte($packet, $offset) == 1 ? true : false);
Copier
Copié
Copier
Copié
$this->Server->PlayerCount = Utils::getShort($packet, $offset);
$this->Server->PlayerCount = Utils::getShort($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->MaxPlayers = Utils::getShort($packet, $offset);
$this->Server->MaxPlayers = Utils::getShort($packet, $offset);
Copier
Copié
Copier
Copié
$len = Utils::getInt($packet, $offset);
$len = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Hostname = Utils::getString($packet, $offset, $len);
$this->Server->Hostname = Utils::getString($packet, $offset, $len);
Copier
Copié
Copier
Copié
$len = Utils::getInt($packet, $offset);
$len = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->GameMode = Utils::getString($packet, $offset, $len);
$this->Server->GameMode = Utils::getString($packet, $offset, $len);
Copier
Copié
Copier
Copié
$len = Utils::getInt($packet, $offset);
$len = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
$this->Server->Map = Utils::getString($packet, $offset, $len);
$this->Server->Map = Utils::getString($packet, $offset, $len);
Copier
Copié
Copier
Copié
$this->HaveInfo = true;
$this->HaveInfo = true;
Copier
Copié
Copier
Copié
if ($this->Server->PlayerCount >= 100)
if ($this->Server->PlayerCount >= 100)
Copier
Copié
Copier
Copié
$this->HavePlayer = true;
$this->HavePlayer = true;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case 0x72: // rules
case 0x72: // rules
Copier
Copié
Copier
Copié
if ($this->HaveRules)
if ($this->HaveRules)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$rulesnum = Utils::getShort($packet, $offset);
$rulesnum = Utils::getShort($packet, $offset);
Copier
Copié
Copier
Copié
while ($rulesnum) {
while ($rulesnum) {
Copier
Copié
Copier
Copié
$len = Utils::getByte($packet, $offset);
$len = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$Name = Utils::getString($packet, $offset, $len);
$Name = Utils::getString($packet, $offset, $len);
Copier
Copié
Copier
Copié
$len = Utils::getByte($packet, $offset);
$len = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$Value = Utils::getString($packet, $offset, $len);
$Value = Utils::getString($packet, $offset, $len);
Copier
Copié
Copier
Copié
$rulesnum--;
$rulesnum--;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$this->Server->Rules[$Name] = $Value;
$this->Server->Rules[$Name] = $Value;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->HaveRules = true;
$this->HaveRules = true;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case 0x64: // player
case 0x64: // player
Copier
Copié
Copier
Copié
if ($this->HavePlayer)
if ($this->HavePlayer)
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$numplayers = Utils::getShort($packet, $offset);
$numplayers = Utils::getShort($packet, $offset);
Copier
Copié
Copier
Copié
$lastID = 0;
$lastID = 0;
Copier
Copié
Copier
Copié
$plusID = 0;
$plusID = 0;
Copier
Copié
Copier
Copié
while ($numplayers) {
while ($numplayers) {
Copier
Copié
Copier
Copié
$Player = new Player;
$Player = new Player;
Copier
Copié
Copier
Copié
$Player->ID = Utils::getByte($packet, $offset) + $plusID;
$Player->ID = Utils::getByte($packet, $offset) + $plusID;
Copier
Copié
Copier
Copié
if ($Player->ID < $lastID) {
if ($Player->ID < $lastID) {
Copier
Copié
Copier
Copié
$Player->ID += 256;
$Player->ID += 256;
Copier
Copié
Copier
Copié
$plusID += 256;
$plusID += 256;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$lastID = $Player->ID;
$lastID = $Player->ID;
Copier
Copié
Copier
Copié
$len = Utils::getByte($packet, $offset);
$len = Utils::getByte($packet, $offset);
Copier
Copié
Copier
Copié
$Player->Name = Utils::getString($packet, $offset, $len);
$Player->Name = Utils::getString($packet, $offset, $len);
Copier
Copié
Copier
Copié
$len = strlen($Player->Name);
$len = strlen($Player->Name);
Copier
Copié
Copier
Copié
$Player->Score = Utils::getInt($packet, $offset);
$Player->Score = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
$Player->Ping = Utils::getInt($packet, $offset);
$Player->Ping = Utils::getInt($packet, $offset);
Copier
Copié
Copier
Copié
$numplayers--;
$numplayers--;
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
array_push($this->Server->Players, $Player);
array_push($this->Server->Players, $Player);
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
$this->HavePlayer = true;
$this->HavePlayer = true;
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
default:
default:
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function requestInfo() {
function requestInfo() {
Copier
Copié
Copier
Copié
array_push($this->SendQueue, "\xFF\xFF\xFF\xFFTSource Engine Query\x00");
array_push($this->SendQueue, "\xFF\xFF\xFF\xFFTSource Engine Query\x00");
Copier
Copié
Copier
Copié
array_push($this->SendQueue, $this->SAMPHeader . "i");
array_push($this->SendQueue, $this->SAMPHeader . "i");
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function requestPlayer() {
function requestPlayer() {
Copier
Copié
Copier
Copié
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x55" . $this->Challenge);
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x55" . $this->Challenge);
Copier
Copié
Copier
Copié
array_push($this->SendQueue, $this->SAMPHeader . "d");
array_push($this->SendQueue, $this->SAMPHeader . "d");
Copier
Copié
Copier
Copié
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
Copier
Copié
Copier
Copié
$this->ResendPlayer = true;
$this->ResendPlayer = true;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function requestRules() {
function requestRules() {
Copier
Copié
Copier
Copié
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x56" . $this->Challenge);
array_push($this->SendQueue, "\xFF\xFF\xFF\xFF\x56" . $this->Challenge);
Copier
Copié
Copier
Copié
array_push($this->SendQueue, $this->SAMPHeader . "r");
array_push($this->SendQueue, $this->SAMPHeader . "r");
Copier
Copié
Copier
Copié
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
if ($this->Challenge == "\xFF\xFF\xFF\xFF")
Copier
Copié
Copier
Copié
$this->ResendRules = true;
$this->ResendRules = true;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
function GetServer() {
function GetServer() {
Copier
Copié
Copier
Copié
$start = Utils::getTime();
$start = Utils::getTime();
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$this->requestInfo();
$this->requestInfo();
Copier
Copié
Copier
Copié
$this->requestPlayer();
$this->requestPlayer();
Copier
Copié
Copier
Copié
$this->requestRules();
$this->requestRules();
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
while (!($this->HaveRules && $this->HaveInfo && $this->HavePlayer)) {
while (!($this->HaveRules && $this->HaveInfo && $this->HavePlayer)) {
Copier
Copié
Copier
Copié
if (Utils::getTime() - $start >= $this->MaxExecutionTime) {
if (Utils::getTime() - $start >= $this->MaxExecutionTime) {
Copier
Copié
Copier
Copié
if ($this->HaveInfo && $this->HavePlayer) {
if ($this->HaveInfo && $this->HavePlayer) {
Copier
Copié
Copier
Copié
$this->HaveRules = true;
$this->HaveRules = true;
Copier
Copié
Copier
Copié
} else {
} else {
Copier
Copié
Copier
Copié
throw new LSError(4, "Timed out.");
throw new LSError(4, "Timed out.");
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
if (count($this->SendQueue) > 0) {
if (count($this->SendQueue) > 0) {
Copier
Copié
Copier
Copié
stream_socket_sendto($this->Sock, array_shift($this->SendQueue));
stream_socket_sendto($this->Sock, array_shift($this->SendQueue));
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$meta = stream_get_meta_data($this->Sock);
$meta = stream_get_meta_data($this->Sock);
Copier
Copié
Copier
Copié
if ($meta['timed_out'])
if ($meta['timed_out'])
Copier
Copié
Copier
Copié
throw new LSError(5, "Timed out.");
throw new LSError(5, "Timed out.");
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
usleep(50000);
usleep(50000);
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$packet = fread($this->Sock, 2048);
$packet = fread($this->Sock, 2048);
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
$meta = stream_get_meta_data($this->Sock);
$meta = stream_get_meta_data($this->Sock);
Copier
Copié
Copier
Copié
if ($meta['timed_out'])
if ($meta['timed_out'])
Copier
Copié
Copier
Copié
throw new LSError(6, "Timed out.");
throw new LSError(6, "Timed out.");
Copier
Copié
Copier
Copié
Copier
Copié
Copier
Copié
if (strlen($packet) > 0) {
if (strlen($packet) > 0) {
Copier
Copié
Copier
Copié
$offset = 0;
$offset = 0;
Copier
Copié
Copier
Copié
switch (Utils::getInt($packet, $offset)) {
switch (Utils::getInt($packet, $offset)) {
Copier
Copié
Copier
Copié
case HL_PACKET:
case HL_PACKET:
Copier
Copié
Copier
Copié
if (!in_array($this->Server->Type, array(0, 1)))
if (!in_array($this->Server->Type, array(0, 1)))
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$this->Server->Type = 1;
$this->Server->Type = 1;
Copier
Copié
Copier
Copié
$this->onPacketReceived($packet);
$this->onPacketReceived($packet);
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case HL_PACKET_SPLITTED:
case HL_PACKET_SPLITTED:
Copier
Copié
Copier
Copié
if (!in_array($this->Server->Type, array(0, 1)))
if (!in_array($this->Server->Type, array(0, 1)))
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$this->Server->Type = 1;
$this->Server->Type = 1;
Copier
Copié
Copier
Copié
$this->onSplittedPacketReceived($packet);
$this->onSplittedPacketReceived($packet);
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
case SAMP_PACKET:
case SAMP_PACKET:
Copier
Copié
Copier
Copié
if (!in_array($this->Server->Type, array(0, 2)))
if (!in_array($this->Server->Type, array(0, 2)))
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
$this->Server->Type = 2;
$this->Server->Type = 2;
Copier
Copié
Copier
Copié
$this->onSampPacketReceived($packet);
$this->onSampPacketReceived($packet);
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
default:
default:
Copier
Copié
Copier
Copié
break;
break;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
return $this->Server;
return $this->Server;
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
}
}
Copier
Copié
Copier
Copié
?>
?>
Différences enregistrées
Texte d'origine
Ouvrir un fichier
<?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; } } ?>
Texte modifié
Ouvrir un fichier
<?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; } } ?>
Trouver la différence