Added /invisible command

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-19 14:35:11 +01:00
parent a833d92d76
commit 0f4ce5a539
4 changed files with 40 additions and 2 deletions

View File

@ -45,6 +45,26 @@ class ConsoleAPI{
public function defaultCommands($cmd, $params){ public function defaultCommands($cmd, $params){
switch($cmd){ switch($cmd){
case "invisible":
$p = strtolower(array_shift($params));
switch($p){
case "on":
case "true":
case "1":
console("[INFO] Server is invisible");
$this->server->api->setProperty("invisible", true);
break;
case "off":
case "false":
case "0":
console("[INFO] Server is visible");
$this->server->api->setProperty("invisible", false);
break;
default:
console("[INFO] Usage: /invisible <on | off>");
break;
}
break;
case "status": case "status":
case "lag": case "lag":
$info = $this->server->debugInfo(); $info = $this->server->debugInfo();
@ -184,6 +204,7 @@ class ConsoleAPI{
console("[INFO] /status: Show server TPS and memory usage"); console("[INFO] /status: Show server TPS and memory usage");
console("[INFO] /gamemode: Changes default gamemode"); console("[INFO] /gamemode: Changes default gamemode");
console("[INFO] /difficulty: Changes difficulty"); console("[INFO] /difficulty: Changes difficulty");
console("[INFO] /invisible: Manages server visibility");
console("[INFO] /say: Broadcasts mesages"); console("[INFO] /say: Broadcasts mesages");
console("[INFO] /save-all: Saves pending changes"); console("[INFO] /save-all: Saves pending changes");
console("[INFO] /whitelist: Manages whitelisting"); console("[INFO] /whitelist: Manages whitelisting");

View File

@ -217,9 +217,13 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
}else{ }else{
$this->config["memory-limit"] = "256M"; $this->config["memory-limit"] = "256M";
} }
if(!isset($this->config["invisible"])){
$this->config["invisible"] = false;
}
if(is_object($this->server)){ if(is_object($this->server)){
$this->server->setType($this->config["server-type"]); $this->server->setType($this->config["server-type"]);
$this->server->timePerSecond = $this->config["time-per-second"]; $this->server->timePerSecond = $this->config["time-per-second"];
$this->server->invisible = $this->config["invisible"];
$this->server->maxClients = $this->config["max-players"]; $this->server->maxClients = $this->config["max-players"];
$this->server->description = $this->config["description"]; $this->server->description = $this->config["description"];
$this->server->motd = $this->config["motd"]; $this->server->motd = $this->config["motd"];
@ -238,6 +242,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
$config = $this->config; $config = $this->config;
$config["white-list"] = $config["white-list"] === true ? "true":"false"; $config["white-list"] = $config["white-list"] === true ? "true":"false";
$config["invisible"] = $config["invisible"] === true ? "true":"false";
$prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n"; $prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n";
foreach($config as $n => $v){ foreach($config as $n => $v){
if($n == "spawn"){ if($n == "spawn"){
@ -304,6 +309,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$v = array("x" => floatval($v[0]), "y" => floatval($v[1]), "z" => floatval($v[2])); $v = array("x" => floatval($v[0]), "y" => floatval($v[1]), "z" => floatval($v[2]));
break; break;
case "white-list": case "white-list":
case "invisible":
$v = trim($v) == "true" ? true:false; $v = trim($v) == "true" ? true:false;
break; break;
} }

View File

@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
require_once("classes/Session.class.php"); require_once("classes/Session.class.php");
class PocketMinecraftServer extends stdClass{ class PocketMinecraftServer extends stdClass{
var $tickMeasure, $preparedSQL, $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $mapName, $map, $level, $tileEntities; var $invisible, $tickMeasure, $preparedSQL, $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $mapName, $map, $level, $tileEntities;
private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick; private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick;
function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){ function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){
$this->port = (int) $port; //19132 - 19135 $this->port = (int) $port; //19132 - 19135
@ -47,6 +47,7 @@ class PocketMinecraftServer extends stdClass{
$this->events = array(); $this->events = array();
$this->handlers = array(); $this->handlers = array();
$this->map = false; $this->map = false;
$this->invisible = false;
$this->level = false; $this->level = false;
$this->difficulty = 1; $this->difficulty = 1;
$this->tileEntities = array(); $this->tileEntities = array();
@ -312,6 +313,15 @@ class PocketMinecraftServer extends stdClass{
}else{ }else{
switch($packet["pid"]){ switch($packet["pid"]){
case 0x02: case 0x02:
if($this->invisible === true){
$this->send(0x1c, array(
$data[0],
$this->serverID,
MAGIC,
$this->serverType,
), false, $packet["ip"], $packet["port"]);
break;
}
if(in_array($packet["ip"], $this->bannedIPs)){ if(in_array($packet["ip"], $this->bannedIPs)){
$this->send(0x1c, array( $this->send(0x1c, array(
$data[0], $data[0],
@ -406,7 +416,7 @@ class PocketMinecraftServer extends stdClass{
public function process(){ public function process(){
while($this->stop === false){ while($this->stop === false){
$packet = $this->interface->readPacket(); $packet = @$this->interface->readPacket();
if($packet !== false){ if($packet !== false){
$this->packetHandler($packet); $this->packetHandler($packet);
}else{ }else{

View File

@ -2,6 +2,7 @@
server-name=PHP Server server-name=PHP Server
description= This is a Work in Progress custom server. description= This is a Work in Progress custom server.
motd=Welcome to PHP Server motd=Welcome to PHP Server
invisible=false
port=19132 port=19132
protocol=CURRENT protocol=CURRENT
memory-limit=256M memory-limit=256M