<?php /* modificated by book777 */
class socketMON {
private $socket, $info;
public $online, $motd, $onlplayers, $maxplayers, $proc, $ip, $port, $error;
public function __construct($ip, $port = '25565') {
if($this->socket = @stream_socket_client('tcp://'.$ip.':'.$port, $errno, $errstr, 1)) {
$this->online = true;
fwrite($this->socket, "\xfe");
$handle = fread($this->socket, 256);
$handle = str_replace("\x00", '', $handle);
$handle = substr($handle, 2);
$this->info = explode("\xa7", $handle);
unset($handle);
fclose($this->socket);
if(sizeof($this->info) == 3) {
$this->motd = $this->info[0];
$this->onlplayers = $this->info[1];
$this->maxplayers = $this->info[2];
$this->proc=@ceil(($this->onlplayers/$this->maxplayers)*100);
$this->error = false;
} else if(sizeof($this->info) > 3) {
unset($temp);
for($i = 0; $i < sizeof($this->info) - 2; $i++) {
$temp .= ($i > 0 ? 'В§' : '').$this->info[$i];
}
$this->motd = $temp;
$this->onlplayers = (int)$this->info[sizeof($this->info) - 2];
$this->maxplayers = (int)$this->info[sizeof($this->info) - 1];
$this->error = 'Цветной motd';
$this->proc=@ceil(($this->onlplayers/$this->maxplayers)*100);
} else {
$this->failed();
$this->error = 'Странное ядро сервера';
}
} else {
$this->online = false;
$this->failed();
$this->error = 'Сервер недоступен';
}
}
private function failed() {
$this->motd = false;
$this->onlplayers = false;
$this->maxplayers = false;
}
}