Skip to content

Instantly share code, notes, and snippets.

@bologer
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bologer/92e3642f848ddb85fedf to your computer and use it in GitHub Desktop.
Save bologer/92e3642f848ddb85fedf to your computer and use it in GitHub Desktop.
Rcon для получения данных о сервере
<?php
class Rcon
{
public $host, $port, $pass;
private $fp, $challenge_number;
public function __construct($host, $pass)
{
$_host = explode(":", $host);
$this->host = $_host[0];
$this->port = $_host[1];
$this->pass = $pass;
}
public function Connect()
{
$this->fp = fsockopen("udp://".$this->host, $this->port);
stream_set_timeout($this->fp, 1);
return $this->fp ? $this->GetChallengeNumber() : false;
}
public function Disconnect()
{
return fclose($this->fp) ? true : false;
}
public function Command($command)
{
return $this->RconCommand("\xff\xff\xff\xffrcon $this->challenge_number \"$this->pass\" $command");
}
private function GetChallengeNumber()
{
$this->challenge_number = trim($this->RconCommand("\xff\xff\xff\xffchallenge rcon"));
if(!empty($this->challenge_number))
{
$_challenge = explode(" ", $this->challenge_number);
$this->challenge_number = $_challenge["2"];
return $this->challenge_number;
} else
return false;
}
private function RconCommand($command)
{
fputs($this->fp, $command, strlen($command));
$buffer = fread($this->fp, 1);
if($buffer)
{
$status = socket_get_status($this->fp);
$buffer .= fread($this->fp, $status["unread_bytes"]);
}
return substr($buffer, 5);;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment