mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 11:27:07 +00:00
Added RCON
This commit is contained in:
parent
379b70eca7
commit
11356b68ba
@ -60,6 +60,7 @@ use pocketmine\network\query\QueryHandler;
|
||||
use pocketmine\network\query\QueryPacket;
|
||||
use pocketmine\network\raknet\Info as RakNetInfo;
|
||||
use pocketmine\network\raknet\Packet as RakNetPacket;
|
||||
use pocketmine\network\rcon\RCON;
|
||||
use pocketmine\network\ThreadedHandler;
|
||||
use pocketmine\network\upnp\UPnP;
|
||||
use pocketmine\permission\BanList;
|
||||
@ -1360,10 +1361,17 @@ class Server{
|
||||
* Starts the PocketMine-MP server and starts processing ticks and packets
|
||||
*/
|
||||
public function start(){
|
||||
|
||||
if($this->getConfigBoolean("enable-rcon", false) === true){
|
||||
$this->rcon = new RCON($this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50));
|
||||
}
|
||||
|
||||
if($this->getConfigBoolean("enable-query", true) === true){
|
||||
$this->queryHandler = new QueryHandler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($this->getConfigBoolean("upnp-forwarding", false) == true){
|
||||
console("[INFO] [UPnP] Trying to port forward...");
|
||||
UPnP::PortForward($this->getPort());
|
||||
|
@ -22,6 +22,22 @@
|
||||
namespace pocketmine\command;
|
||||
|
||||
|
||||
interface RemoteConsoleCommandSender extends CommandSender{
|
||||
class RemoteConsoleCommandSender extends ConsoleCommandSender{
|
||||
|
||||
/** @var string */
|
||||
private $messages = "";
|
||||
|
||||
public function sendMessage($message){
|
||||
$this->messages .= trim($message, "\r\n")."\n";
|
||||
}
|
||||
|
||||
public function getMessage(){
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Rcon";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -53,8 +53,8 @@ class PluginsCommand extends VanillaCommand{
|
||||
if(strlen($list) > 0){
|
||||
$list .= TextFormat::WHITE . ", ";
|
||||
}
|
||||
$list .= $plugin->isEnabled() ? TextFormat::DARK_GREEN : TextFormat::RED;
|
||||
$list .= $plugin->getDescription()->getName();
|
||||
$list .= $plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED;
|
||||
$list .= $plugin->getDescription()->getFullName();
|
||||
}
|
||||
|
||||
return "(" . count($plugins) . "): $list";
|
||||
|
@ -25,11 +25,20 @@
|
||||
*/
|
||||
namespace pocketmine\network\rcon;
|
||||
|
||||
use pocketmine\command\RemoteConsoleCommandSender;
|
||||
use pocketmine\scheduler\CallbackTask;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
|
||||
class RCON{
|
||||
private $socket, $password, $workers, $threads, $clientsPerThread;
|
||||
private $socket;
|
||||
private $password;
|
||||
/** @var RCONInstance[] */
|
||||
private $workers;
|
||||
private $threads;
|
||||
private $clientsPerThread;
|
||||
private $rconSender;
|
||||
|
||||
public function __construct($password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
|
||||
$this->workers = array();
|
||||
@ -49,18 +58,18 @@ class RCON{
|
||||
return;
|
||||
}
|
||||
@socket_set_block($this->socket);
|
||||
|
||||
for($n = 0; $n < $this->threads; ++$n){
|
||||
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
|
||||
}
|
||||
@socket_getsockname($this->socket, $addr, $port);
|
||||
console("[INFO] RCON running on $addr:$port");
|
||||
Server::getInstance()->schedule(2, array($this, "check"), array(), true);
|
||||
Server::getInstance()->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "check")), 3);
|
||||
}
|
||||
|
||||
public function stop(){
|
||||
for($n = 0; $n < $this->threads; ++$n){
|
||||
$this->workers[$n]->close();
|
||||
$this->workers[$n]->join();
|
||||
usleep(50000);
|
||||
$this->workers[$n]->kill();
|
||||
}
|
||||
@ -77,7 +86,8 @@ class RCON{
|
||||
console($this->workers[$n]->response);
|
||||
$this->workers[$n]->notify();
|
||||
}else{
|
||||
$this->workers[$n]->response = Server::getInstance()->api->console->run($this->workers[$n]->cmd, "rcon");
|
||||
Server::getInstance()->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
|
||||
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
|
||||
$this->workers[$n]->notify();
|
||||
}
|
||||
}
|
||||
|
@ -222,28 +222,28 @@ class TextFormat{
|
||||
|
||||
//Colors
|
||||
case TextFormat::BLACK:
|
||||
$newString .= "\x1b[30m";
|
||||
$newString .= "\x1b[30;0m";
|
||||
break;
|
||||
case TextFormat::DARK_BLUE:
|
||||
$newString .= "\x1b[34m";
|
||||
$newString .= "\x1b[34;0m";
|
||||
break;
|
||||
case TextFormat::DARK_GREEN:
|
||||
$newString .= "\x1b[32m";
|
||||
$newString .= "\x1b[32;0m";
|
||||
break;
|
||||
case TextFormat::DARK_AQUA:
|
||||
$newString .= "\x1b[36m";
|
||||
$newString .= "\x1b[36;0m";
|
||||
break;
|
||||
case TextFormat::DARK_RED:
|
||||
$newString .= "\x1b[31m";
|
||||
$newString .= "\x1b[31;0m";
|
||||
break;
|
||||
case TextFormat::DARK_PURPLE:
|
||||
$newString .= "\x1b[35m";
|
||||
$newString .= "\x1b[35;0m";
|
||||
break;
|
||||
case TextFormat::GOLD:
|
||||
$newString .= "\x1b[33m";
|
||||
$newString .= "\x1b[33;0m";
|
||||
break;
|
||||
case TextFormat::GRAY:
|
||||
$newString .= "\x1b[37m";
|
||||
$newString .= "\x1b[37;0m";
|
||||
break;
|
||||
case TextFormat::DARK_GRAY:
|
||||
$newString .= "\x1b[30;1m";
|
||||
|
Loading…
x
Reference in New Issue
Block a user