1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <?php
# Source RCON by William Ruckman (http://ruckman.net)
define('PACKET_SIZE', '1400');
define('SERVERQUERY_INFO', "\xFF\xFF\xFF\xFFTSource Engine Query");
define ('REPLY_INFO', "\x49");
define('SERVERQUERY_GETCHALLENGE', "\xFF\xFF\xFF\xFF\x57");
define ('REPLY_GETCHALLENGE', "\x41");
define('SERVERDATA_AUTH', 3) ;
define ('SERVERDATA_EXECCOMMAND', 2) ;
class srcds_rcon
{
function getLong(&$string)
{
$data = substr($string, 0, 4);
$string = substr($string, 4);
$data = unpack('Vvalue', $data);
return $data['value'];
}
function rcon_command($ip, $port, $password)
{
$requestId = 1;
$s2 = '';
$socket = @fsockopen ('tcp://'.$ip, $port, $errno, $errstr, 30);
if (!$socket)
return 0;
$data = pack("VV", $requestId, SERVERDATA_AUTH).$password.chr(0).$s2.chr(0);
$data = pack("V",strlen($data)).$data;
fwrite ($socket, $data, strlen($data));
$requestId++ ;
$junk = fread ($socket, PACKET_SIZE);
$string = fread ($socket, PACKET_SIZE);
$size = $this->getLong($string);
$id = $this->getLong($string) ;
if ($id == -1)
{
return 0;
}
else
{
return 1; //Si bon rcon : alors on retourne 1, sinon 0
}
}
}
$ip = $_POST["ip"];
$port = $_POST["port"];
$password = $_POST["rcon"];
$srcds_rcon = new srcds_rcon();
$OUTPUT = $srcds_rcon->rcon_command($ip, $port, $password);
return $OUTPUT;
?> |
Partager