public function onRun()
 {
     list($host, $port, $auth) = $this->server;
     $ret = Rcon::connect($host, $port, $auth);
     if (!is_array($ret)) {
         $this->close($ret);
         return;
     }
     list($this->sock, $id) = $ret;
     $ret = Rcon::cmd($this->cmd, $this->sock, $id);
     $this->close($ret);
 }
Beispiel #2
0
 public function onCommand(CommandSender $c, Command $cmd, $label, array $args)
 {
     if (count($args) == 0) {
         return false;
     }
     if ($cmd->getName() != "rcon") {
         return false;
     }
     if (count($args) < 2) {
         return false;
     }
     $id = array_shift($args);
     $lst = $this->owner->getModule("ServerList");
     $grp = [];
     if ($id == "--all") {
         foreach ($lst->getIds() as $i) {
             if ($lst->getServerAttr($i, "rcon-pw") !== null) {
                 $grp[$i] = $i;
             }
         }
     } else {
         foreach (explode(",", $id) as $i) {
             if ($lst->getServer($i) === null) {
                 $c->sendMessage(mc::_("%1% does not exist", $i));
                 continue;
             }
             if ($lst->getServerAttr($i, "rcon-pw") === null) {
                 $c->sendMessage(mc::_("No rcon-pw specified for %1%", $i));
                 continue;
             }
             $grp[$i] = $i;
         }
         if (count($grp) == 0) {
             return false;
         }
     }
     $cmd = implode(" ", $args);
     if ($c instanceof RemoteConsoleCommandSender) {
         // This is an Rcon connection itself... we run in the foreground
         foreach ($grp as $id) {
             $host = $lst->getServerAttr($id, "rcon-host");
             $port = $lst->getServerAttr($id, "rcon-port");
             $auth = $lst->getServerAttr($id, "rcon-pw");
             $ret = Rcon::connect($host, $port, $auth);
             if (!is_array($ret)) {
                 $c->sendMessage($ret);
                 continue;
             }
             list($sock, $id) = $ret;
             $ret = Rcon::cmd($cmd, $sock, $id);
             if (is_array($ret)) {
                 $c->sendMessage($ret[0]);
             } else {
                 $c->sendMessage($ret);
             }
             fclose($sock);
         }
         return true;
     }
     foreach ($grp as $id) {
         $host = $lst->getServerAttr($id, "rcon-host");
         $port = $lst->getServerAttr($id, "rcon-port");
         $auth = $lst->getServerAttr($id, "rcon-pw");
         $this->owner->getServer()->getScheduler()->scheduleAsyncTask(new RconTask($this->owner, "rconDone", [$host, $port, $auth], $cmd, [$c instanceof Player ? $c->getName() : null]));
     }
     return true;
 }