Last active
August 29, 2015 14:23
-
-
Save bologer/92e3642f848ddb85fedf to your computer and use it in GitHub Desktop.
Rcon для получения данных о сервере
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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