From 1409a1f7b56457e59b1779315a63e9fd6627736f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 17 Jan 2013 16:10:25 +0100 Subject: [PATCH 1/5] Added /kick command --- src/API/BanAPI.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index e9832889..d8bffbb4 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -41,11 +41,28 @@ class BanAPI{ $this->banned = new Config(FILE_PATH."banned.txt", CONFIG_LIST); $this->server->api->console->register("banip", "Manages IP Banning", array($this, "commandHandler")); $this->server->api->console->register("ban", "Manages Bannning", array($this, "commandHandler")); + $this->server->api->console->register("kick", "Kicks a player", array($this, "commandHandler")); $this->server->api->console->register("whitelist", "Manages White-listing", array($this, "commandHandler")); } public function commandHandler($cmd, $params){ switch($cmd){ + case "kick": + if(!isset($params[0])){ + console("[INFO] Usage: /kick [reason]"); + }else{ + $name = array_shift($params); + $player = $this->api->player->get($name); + if($player === false){ + console("[ERROR] Player \"".$name."\" does not exist"); + }else{ + $reason = implode(" ", $params); + $reason = $reason == "" ? "No reason":$reason; + $player->close("You have been kicked: ".$reason); + console("[INFO] Player \"".$player->username."\" has been kicked: $reason"); + } + } + break; case "whitelist": $p = strtolower(array_shift($params)); switch($p){ From ed61111acaa8c4a480b58f19338b7244ef77fd1b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 17 Jan 2013 16:10:41 +0100 Subject: [PATCH 2/5] Added a way to call custom commands in ConsoleAPI --- src/API/ConsoleAPI.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index ed65cfce..e6cae7ba 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -150,7 +150,11 @@ class ConsoleAPI{ } public function alias($alias, $cmd){ + if(!isset($this->cmds[$cmd])){ + return false; + } $this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd]; + return true; } public function register($cmd, $help, $callback){ @@ -161,21 +165,25 @@ class ConsoleAPI{ $this->cmds[$cmd] = $callback; $this->help[$cmd] = $help; } + + public function run($line = ""){ + if($line != ""){ + $params = explode(" ", $line); + $cmd = strtolower(array_shift($params)); + console("[INFO] Issued server command: /$cmd ".implode(" ", $params)); + if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ + call_user_func($this->cmds[$cmd], $cmd, $params); + }elseif($this->server->api->dhandle("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){ + $this->defaultCommands($cmd, $params); + } + } + } public function handle($time){ if($this->loop->line !== false){ $line = trim($this->loop->line); $this->loop->line = false; - if($line !== ""){ - $params = explode(" ", $line); - $cmd = strtolower(array_shift($params)); - console("[INFO] Issued server command: /$cmd ".implode(" ", $params)); - if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ - call_user_func($this->cmds[$cmd], $cmd, $params); - }elseif($this->server->api->dhandle("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){ - $this->defaultCommands($cmd, $params); - } - } + $this->run($line); }else{ $this->loop->notify(); } From a5229cc34eb9ddb20f9abf8d25a3f8ca604b9c1a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 17 Jan 2013 16:37:53 +0100 Subject: [PATCH 3/5] Fixed a typo ;) --- src/API/BanAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index d8bffbb4..bf3fa6dc 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -52,7 +52,7 @@ class BanAPI{ console("[INFO] Usage: /kick [reason]"); }else{ $name = array_shift($params); - $player = $this->api->player->get($name); + $player = $this->server->api->player->get($name); if($player === false){ console("[ERROR] Player \"".$name."\" does not exist"); }else{ From a24da0e5adf1b2f1cd60a924cecc3345346038af Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 17 Jan 2013 19:02:50 +0100 Subject: [PATCH 4/5] Removed unused commands --- src/API/ConsoleAPI.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index e6cae7ba..0ab3fcd5 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -87,11 +87,6 @@ class ConsoleAPI{ console("[INFO] Stopping the server..."); $this->server->close(); break; - /*case "restart": - console("[INFO] Restarting the server..."); - $this->server->api->restart = true; - $this->server->close(); - break;*/ case "gamemode": $s = trim(array_shift($params)); if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){ @@ -122,12 +117,6 @@ class ConsoleAPI{ case "save-all": $this->server->save(); break; - case "block": - foreach($this->server->clients as $client){ - $b = $this->server->map->getBlock(round($client->entity->position["x"] - 0.5), round($client->entity->position["y"] - 1), round($client->entity->position["z"] - 0.5)); - console("[INFO] EID ".$client->eid." is over block ".$b[0].":".$b[1]); - } - break; case "help": case "?": console("[INFO] /help: Show available commands"); From 1d9e1fde79f08cd1165589c115284b1ad5fca696 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 17 Jan 2013 23:23:45 +0100 Subject: [PATCH 5/5] Fixed Description --- src/classes/PocketMinecraftServer.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/classes/PocketMinecraftServer.php b/src/classes/PocketMinecraftServer.php index bf7e4486..82371865 100644 --- a/src/classes/PocketMinecraftServer.php +++ b/src/classes/PocketMinecraftServer.php @@ -421,9 +421,7 @@ class PocketMinecraftServer{ $this->custom["times_".$CID] = 0; } $ln = 15; - if(strlen($this->description) === 0){ - $this->description = ""; - } + $this->description .= " "; $txt = substr($this->description, $this->custom["times_".$CID], $ln); $txt .= substr($this->description, 0, $ln - strlen($txt)); $this->send(0x1c, array(