示例#1
0
 public function forceShutdown()
 {
     if ($this->hasStopped) {
         return;
     }
     try {
         $this->hasStopped = true;
         $this->shutdown();
         if ($this->rcon instanceof RCON) {
             $this->rcon->stop();
         }
         if ($this->getProperty("settings.upnp-forwarding", false) === true) {
             $this->logger->info("[UPnP] Removing port forward...");
             UPnP::RemovePortForward($this->getPort());
         }
         $this->pluginManager->disablePlugins();
         foreach ($this->players as $player) {
             $player->close(TextFormat::YELLOW . $player->getName() . " has left the game", $this->getProperty("settings.shutdown-message", "Server closed"));
         }
         foreach ($this->getLevels() as $level) {
             $this->unloadLevel($level, true);
         }
         if ($this->generationManager instanceof GenerationRequestManager) {
             $this->generationManager->shutdown();
         }
         HandlerList::unregisterAll();
         $this->scheduler->cancelAllTasks();
         $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
         $this->properties->save();
         $this->console->kill();
         foreach ($this->network->getInterfaces() as $interface) {
             $interface->shutdown();
             $this->network->unregisterInterface($interface);
         }
     } catch (\Exception $e) {
         $this->logger->emergency("Crashed while crashing, killing process");
         @kill(getmypid());
     }
 }
示例#2
0
 public function forceShutdown()
 {
     if ($this->hasStopped) {
         return;
     }
     try {
         if (!$this->isRunning()) {
             $this->sendUsage(SendUsageTask::TYPE_CLOSE);
         }
         $this->hasStopped = true;
         $this->shutdown();
         if ($this->rcon instanceof RCON) {
             $this->rcon->stop();
         }
         if ($this->getProperty("network.upnp-forwarding", false) === true) {
             $this->logger->info("[UPnP] Removing port forward...");
             UPnP::RemovePortForward($this->getPort());
         }
         $this->getLogger()->debug("Disabling all plugins");
         $this->pluginManager->disablePlugins();
         foreach ($this->players as $player) {
             $player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed"));
         }
         $this->getLogger()->debug("Unloading all levels");
         foreach ($this->getLevels() as $level) {
             $this->unloadLevel($level, true);
         }
         $this->getLogger()->debug("Removing event handlers");
         HandlerList::unregisterAll();
         $this->getLogger()->debug("Stopping all tasks");
         $this->scheduler->cancelAllTasks();
         $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
         $this->getLogger()->debug("Saving properties");
         $this->properties->save();
         $this->getLogger()->debug("Closing console");
         $this->console->kill();
         $this->getLogger()->debug("Stopping network interfaces");
         foreach ($this->network->getInterfaces() as $interface) {
             $interface->shutdown();
             $this->network->unregisterInterface($interface);
         }
         $this->memoryManager->doObjectCleanup();
         gc_collect_cycles();
     } catch (\Exception $e) {
         $this->logger->emergency("Crashed while crashing, killing process");
         @kill(getmypid());
     }
 }
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin->isEnabled()) {
         try {
             $plugin->getPluginLoader()->disablePlugin($plugin);
         } catch (\Exception $e) {
             $logger = Server::getInstance()->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->logException($e);
             }
         }
         $this->server->getScheduler()->cancelTasks($plugin);
         HandlerList::unregisterAll($plugin);
         foreach ($plugin->getDescription()->getPermissions() as $perm) {
             $this->removePermission($perm);
         }
     }
 }
示例#4
0
 public function forceShutdown()
 {
     if ($this->hasStopped) {
         return;
     }
     try {
         $this->hasStopped = true;
         $this->shutdown();
         if ($this->rcon instanceof RCON) {
             $this->rcon->stop();
         }
         if ($this->getProperty("network.upnp-forwarding", false) === true) {
             $this->katana->console->system("[UPnP] Removing port forward...");
             UPnP::RemovePortForward($this->getPort());
         }
         $this->katana->console->system(Terminal::$COLOR_GRAY . "Disabling all plugins");
         $this->pluginManager->disablePlugins();
         foreach ($this->players as $player) {
             $player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed"));
         }
         $this->katana->console->system(Terminal::$COLOR_GRAY . "Unloading all levels");
         foreach ($this->getLevels() as $level) {
             $this->unloadLevel($level, true);
         }
         $this->katana->console->system("Removing event handlers");
         HandlerList::unregisterAll();
         $this->katana->console->system("Saving properties");
         $this->properties->save();
         $this->katana->console->system("Closing console");
         $this->console->kill();
         $this->katana->console->system("Stopping network interfaces");
         foreach ($this->network->getInterfaces() as $interface) {
             $interface->shutdown();
             $this->network->unregisterInterface($interface);
         }
         $this->memoryManager->doObjectCleanup();
         gc_collect_cycles();
     } catch (\Exception $e) {
         $this->logger->emergency("Crashed while crashing, killing process");
         @kill(getmypid());
     }
 }
示例#5
0
 private function rmCmd(CommandSender $c, $n)
 {
     // Removing defined command...
     if ($this->listeners[$n]["command"] === null) {
         $c->sendMessage(mc::_("No command defined for %1%", $this->listeners[$n]["event"]));
         return true;
     }
     $this->listeners[$n]["command"] = null;
     HandlerList::unregisterAll($this->listeners[$n]["listener"]);
     $c->sendMessage(mc::_("Command removed for %1%", $this->listeners[$n]["event"]));
     return true;
 }
 public function onCommand(CommandSender $c, Command $cc, $label, array $args)
 {
     if (count($args) == 1) {
         switch (strtolower($args[0])) {
             case "on":
                 if ($this->listener !== null) {
                     $c->sendMessage(mc::_("Trace already on"));
                     return true;
                 }
                 $this->tracers = [];
                 $this->listener = new TraceListener($this->owner, [$this, "trace"]);
                 $this->owner->getServer()->getPluginManager()->registerEvents($this->listener, $this->owner);
                 $this->timerTask = new PluginCallbackTask($this->owner, [$this, "expireEvents"], []);
                 $h = $this->owner->getServer()->getScheduler()->scheduleRepeatingTask($this->timerTask, $this->timer_ticks);
                 $this->timerTask->setHandler($h);
                 $this->owner->getServer()->broadcastMessage(mc::_("Tracing has been started"));
                 return true;
             case "off":
                 if ($this->timerTask !== null) {
                     $this->owner->getServer()->getScheduler()->cancelTask($this->timerTask->getTaskId());
                     $this->timerTask = null;
                 }
                 if ($this->listener === null) {
                     $c->sendMessage(mc::_("Trace already off"));
                     return true;
                 }
                 HandlerList::unregisterAll($this->listener);
                 unset($this->listener);
                 $this->listener = null;
                 $this->tracers = null;
                 $this->owner->getServer()->broadcastMessage(mc::_("Tracing has been stopped"));
                 return true;
         }
     }
     if ($this->listener === null) {
         $c->sendMessage(mc::_("Tracing is off"));
         return true;
     }
     if (count($args) >= 1 && strtolower($args[0]) == "events") {
         if (count($args) == 1) {
             $lst = $this->listener->getList();
             $c->sendMessage(mc::_("Types: %1%", implode(", ", $lst["types"])));
             $c->sendMessage(mc::_("Classes: %1%", implode(", ", $lst["classes"])));
             return true;
         }
         array_shift($args);
         foreach ($args as $p) {
             $t = $this->listener->checkEvent($p);
             if ($t == null) {
                 $c->sendMessage(mc::_("Unknown event: %1%", $p));
                 return true;
             }
             $c->sendMessage(mc::_("Events: %1%", implode(", ", $t)));
         }
     }
     if ($c instanceof Player) {
         $n = strtolower($c->getName());
     } else {
         $n = "";
     }
     if (count($args) == 0) {
         $c->sendMessage(mc::_("Tracing is on"));
         $lst = [];
         //print_r($this->tracers);//##DEBUG
         foreach (array_keys($this->tracers) as $type) {
             if (isset($this->tracers[$type]["listeners"][$n])) {
                 $lst[] = $type;
             }
         }
         if (count($lst) == 0) {
             return true;
         }
         $c->sendMessage(mc::n(mc::_("Tracing one event: %1%", $lst[0]), mc::_("Tracing %1% events: %2%", count($lst), implode(", ", $lst)), count($lst)));
         return true;
     }
     list($i, $j) = [0, 0];
     foreach ($args as $k) {
         if ($k[0] == "-") {
             // Removing trace
             $k = substr($k, 1);
             $types = $this->listener->checkEvent($k);
             if ($types == null) {
                 $c->sendMessage(mc::_("Unknown event %1%", $k));
                 continue;
             }
             $j += count($types);
             foreach ($types as $l) {
                 $this->rmTrace($l, $n);
             }
         } else {
             // Adding traces
             $types = $this->listener->checkEvent($k);
             if ($types == null) {
                 $c->sendMessage(mc::_("Unknown event %1%", $k));
                 continue;
             }
             $i += count($types);
             foreach ($types as $l) {
                 if (!isset($this->tracers[$l])) {
                     $this->tracers[$l] = ["listeners" => []];
                 }
                 $this->tracers[$l]["listeners"][$n] = $n;
             }
         }
     }
     if ($i) {
         $c->sendMessage(mc::n(mc::_("Adding one event trace"), mc::_("Adding %1% event traces", $i), $i));
     }
     if ($j) {
         $c->sendMessage(mc::n(mc::_("Removing one event trace"), mc::_("Removing %1% event traces", $j), $j));
     }
     return true;
 }
示例#7
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin->isEnabled()) {
         $plugin->getPluginLoader()->disablePlugin($plugin);
         $this->server->getScheduler()->cancelTasks($plugin);
         HandlerList::unregisterAll($plugin);
         foreach ($plugin->getDescription()->getPermissions() as $perm) {
             $this->removePermission($perm);
         }
     }
 }