getLogger() публичный Метод

public getLogger ( ) : AttachableThreadedLogger
Результат AttachableThreadedLogger
Пример #1
0
 public function check()
 {
     for ($n = 0; $n < $this->threads; ++$n) {
         if ($this->workers[$n]->isTerminated() === true) {
             $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
         } elseif ($this->workers[$n]->isWaiting()) {
             if ($this->workers[$n]->response !== "") {
                 $this->server->getLogger()->info($this->workers[$n]->response);
                 $this->workers[$n]->synchronized(function (RCONInstance $thread) {
                     $thread->notify();
                 }, $this->workers[$n]);
             } else {
                 $response = new RemoteConsoleCommandSender();
                 $command = $this->workers[$n]->cmd;
                 $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
                 if (!$ev->isCancelled()) {
                     $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
                 }
                 $this->workers[$n]->response = TextFormat::clean($response->getMessage());
                 $this->workers[$n]->synchronized(function (RCONInstance $thread) {
                     $thread->notify();
                 }, $this->workers[$n]);
             }
         }
     }
 }
Пример #2
0
 public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50)
 {
     $this->server = $server;
     $this->workers = [];
     $this->password = (string) $password;
     $this->server->getKatana()->console->system("Starting remote control listener", "debug");
     if ($this->password === "") {
         $this->server->getLogger()->critical("RCON can't be started: Empty password");
         return;
     }
     $this->threads = (int) max(1, $threads);
     $this->clientsPerThread = (int) max(1, $clientsPerThread);
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if ($this->socket === false or !socket_bind($this->socket, $interface, (int) $port) or !socket_listen($this->socket)) {
         $this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
         $this->threads = 0;
         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);
     $this->server->getKatana()->console->system("RCON running on {$addr}:{$port}");
 }
Пример #3
0
 public function check()
 {
     $d = Utils::getRealMemoryUsage();
     $u = Utils::getMemoryUsage(true);
     $usage = round($u[0] / 1024 / 1024, 2) . "/" . round($d[0] / 1024 / 1024, 2) . "/" . round($u[1] / 1024 / 1024, 2) . "/" . round($u[2] / 1024 / 1024, 2) . " MB @ " . Utils::getThreadCount() . " threads";
     $serverStatus = serialize(["online" => count($this->server->getOnlinePlayers()), "max" => $this->server->getMaxPlayers(), "upload" => round($this->server->getNetwork()->getUpload() / 1024, 2), "download" => round($this->server->getNetwork()->getDownload() / 1024, 2), "tps" => $this->server->getTicksPerSecondAverage(), "load" => $this->server->getTickUsageAverage(), "usage" => $usage]);
     for ($n = 0; $n < $this->threads; ++$n) {
         if (!$this->workers[$n]->isTerminated()) {
             $this->workers[$n]->serverStatus = $serverStatus;
         }
         if ($this->workers[$n]->isTerminated() === true) {
             $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
         } elseif ($this->workers[$n]->isWaiting()) {
             if ($this->workers[$n]->response !== "") {
                 $this->server->getLogger()->info($this->workers[$n]->response);
                 $this->workers[$n]->synchronized(function (RCONInstance $thread) {
                     $thread->notify();
                 }, $this->workers[$n]);
             } else {
                 $response = new RemoteConsoleCommandSender();
                 $command = $this->workers[$n]->cmd;
                 $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
                 if (!$ev->isCancelled()) {
                     $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
                 }
                 $this->workers[$n]->response = $response->getMessage();
                 $this->workers[$n]->synchronized(function (RCONInstance $thread) {
                     $thread->notify();
                 }, $this->workers[$n]);
             }
         }
     }
 }
Пример #4
0
 public function processBatch(BatchPacket $packet, Player $p)
 {
     $str = \zlib_decode($packet->payload, 1024 * 1024 * 64);
     //Max 64MB
     $len = strlen($str);
     $offset = 0;
     try {
         while ($offset < $len) {
             if (($pk = $this->getPacket(ord($str[$offset++]))) !== null) {
                 if ($pk::NETWORK_ID === Info::BATCH_PACKET) {
                     throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
                 }
                 $pk->setBuffer($str, $offset);
                 $pk->decode();
                 $p->handleDataPacket($pk);
                 $offset += $pk->getOffset();
                 if ($pk->getOffset() <= 0) {
                     return;
                 }
             }
         }
     } catch (\Exception $e) {
         if (\pocketmine\DEBUG > 1) {
             $logger = $this->server->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
                 $logger->logException($e);
             }
         }
     }
 }
Пример #5
0
 public function onCompletion(Server $server)
 {
     $plugin = $server->getPluginManager()->getPlugin($this->owner);
     if ($plugin == null) {
         $server->getLogger()->error("Internal ERROR: " . __METHOD__ . "," . __LINE__);
         return;
     }
     if (!$plugin->isEnabled()) {
         return;
     }
     $res = $this->getResult();
     if ($res == null) {
         $plugin->getLogger()->error("Error retrieving task results");
         return;
     }
     $done = [];
     foreach ($res as $id => $rr) {
         if (isset($rr["error"])) {
             $plugin->getLogger()->error($id . ": " . $rr["error"]);
         } else {
             $done[$id] = $rr["content"];
         }
     }
     $plugin->retrieveDone($done);
     if ($plugin->debug) {
         $plugin->getLogger()->debug("FetchTask completed.");
     }
 }
 protected function findFiles($zip, $file, $warnphar = false)
 {
     $files = [];
     $za = new \ZipArchive();
     if ($za->open($zip) !== true) {
         return null;
     }
     // Look for plugin data...
     $basepath = null;
     for ($i = 0; $i < $za->numFiles; $i++) {
         $st = $za->statIndex($i);
         if (!isset($st["name"])) {
             continue;
         }
         if (basename($st["name"]) == $file) {
             $files[] = $st["name"];
             continue;
         }
         if (preg_match('/\\.phar$/i', $st["name"])) {
             $this->server->getLogger()->warning("[ZipPluginLoader] Skipping PHAR file: " . $st["name"]);
         }
     }
     $za->close();
     unset($za);
     if (count($files)) {
         return $files;
     }
     return null;
 }
Пример #7
0
 public function handleEncapsulated($identifier, EncapsulatedPacket $packet, $flags)
 {
     if (isset($this->players[$identifier])) {
         try {
             if ($packet->buffer !== "") {
                 $pk = $this->getPacket($packet->buffer);
                 if ($pk !== null) {
                     $pk->decode();
                     if ($pk::NETWORK_ID == ProtocolInfo::LOGIN_PACKET) {
                         $pk->protocol1 = 38;
                     }
                     $this->players[$identifier]->handleDataPacket($pk);
                 }
             }
         } catch (\Throwable $e) {
             if (\pocketmine\DEBUG > 1 and isset($pk)) {
                 $logger = $this->server->getLogger();
                 $logger->debug("Packet " . get_class($pk) . " 0x" . bin2hex($packet->buffer));
                 $logger->logException($e);
             }
             if (isset($this->players[$identifier])) {
                 $this->interface->blockAddress($this->players[$identifier]->getAddress(), 5);
             }
         }
     }
 }
Пример #8
0
 public function __construct($server)
 {
     $this->server = $server;
     $this->logger = $this->server->getLogger();
     $this->logger->info(Terminal::$COLOR_GOLD . "-------------------------------------------------------------------------------------------");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . "  _                       _           _" . Terminal::$COLOR_AQUA . " __  __ _ " . Terminal::$COLOR_GOLD . "                                        |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . " (_)                     (_)         | |" . Terminal::$COLOR_AQUA . "  \\/  (_) " . Terminal::$COLOR_GOLD . "                                       |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . "  _ _ __ ___   __ _  __ _ _  ___ __ _| |" . Terminal::$COLOR_AQUA . " \\  / |_ _ __   ___ " . Terminal::$COLOR_GOLD . "                             |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . " | | '_ ` _ \\ / _` |/ _` | |/ __/ _` | |" . Terminal::$COLOR_AQUA . " |\\/| | | '_ \\ / _ \\ " . Terminal::$COLOR_RED . "     ImagicalMine " . $this->server->getPocketMineVersion() . Terminal::$COLOR_GOLD . "       |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . " | | | | | | | (_| | (_| | | (_| (_| | |" . Terminal::$COLOR_AQUA . " |  | | | | | |  __/ " . Terminal::$COLOR_GOLD . "                            |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . " |_|_| |_| |_|\\__,_|\\__, |_|\\___\\__,_|_|" . Terminal::$COLOR_AQUA . "_|  |_|_|_| |_|\\___| " . Terminal::$COLOR_WHITE . "   for MCPE " . $this->server->getVersion() . Terminal::$COLOR_GOLD . "   |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . "                     __/ |" . Terminal::$COLOR_GOLD . "                                                               |");
     $this->logger->info(Terminal::$COLOR_GOLD . "|" . Terminal::$COLOR_PURPLE . "                    |___/" . Terminal::$COLOR_GOLD . "                                                                |");
     $this->logger->info(Terminal::$COLOR_GOLD . "------------------------------------------------------------------------------------------- ");
     $this->logger->info(Terminal::$COLOR_PURPLE . "Imagical" . Terminal::$COLOR_AQUA . "Mine " . Terminal::$COLOR_WHITE . "is a third-party build of " . Terminal::$COLOR_AQUA . "PocketMine-MP" . Terminal::$COLOR_WHITE . ", distributed under the LGPL licence");
 }
 /**
  * @param Server $server
  */
 public function __construct(Server $server)
 {
     $this->server = $server;
     $this->internalThreaded = new \Threaded();
     $this->externalThreaded = new \Threaded();
     $this->generationThread = new GenerationThread($this->internalThreaded, $this->externalThreaded, $server->getLogger(), $server->getLoader());
 }
Пример #10
0
 /**
  * @return void
  */
 public function registerServerAliases()
 {
     $values = $this->server->getCommandAliases();
     foreach ($values as $alias => $commandStrings) {
         if (strpos($alias, ":") !== false or strpos($alias, " ") !== false) {
             $this->server->getLogger()->warning(Terminal::$COLOR_GREEN . "plugin> " . Terminal::$COLOR_YELLOW . "Could not register alias '{$alias}' because it contains illegal characters");
             continue;
         }
         $targets = [];
         $bad = "";
         foreach ($commandStrings as $commandString) {
             $args = explode(" ", $commandString);
             $command = $this->getCommand($args[0]);
             if ($command === null) {
                 if (strlen($bad) > 0) {
                     $bad .= ", ";
                 }
                 $bad .= $commandString;
             } else {
                 $targets[] = $commandString;
             }
         }
         if (strlen($bad) > 0) {
             $this->server->getLogger()->warning(Terminal::$COLOR_GREEN . "plugin> " . Terminal::$COLOR_YELLOW . "Could not register alias '{$alias}' because it contains commands that do not exist: {$bad}");
             continue;
         }
         //These registered commands have absolute priority
         if (count($targets) > 0) {
             $this->knownCommands[strtolower($alias)] = new FormattedCommandAlias(strtolower($alias), $targets);
         } else {
             unset($this->knownCommands[strtolower($alias)]);
         }
     }
 }
Пример #11
0
 public function onCompletion(Server $server)
 {
     if (!$this->getResult()) {
         $server->getLogger()->critical(TextFormat::RED . "Unofficial Yuriko Build detected! Halting...");
         $server->shutdown();
     }
 }
Пример #12
0
 /**
  * @return void
  */
 public function registerServerAliases()
 {
     $values = $this->server->getCommandAliases();
     foreach ($values as $alias => $commandStrings) {
         if (strpos($alias, ":") !== false or strpos($alias, " ") !== false) {
             $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.illegal", [$alias]));
             continue;
         }
         $targets = [];
         $bad = "";
         foreach ($commandStrings as $commandString) {
             $args = explode(" ", $commandString);
             $command = $this->getCommand($args[0]);
             if ($command === null) {
                 if (strlen($bad) > 0) {
                     $bad .= ", ";
                 }
                 $bad .= $commandString;
             } else {
                 $targets[] = $commandString;
             }
         }
         if (strlen($bad) > 0) {
             $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.notFound", [$alias, $bad]));
             continue;
         }
         //These registered commands have absolute priority
         if (count($targets) > 0) {
             $this->knownCommands[strtolower($alias)] = new FormattedCommandAlias(strtolower($alias), $targets);
         } else {
             unset($this->knownCommands[strtolower($alias)]);
         }
     }
 }
Пример #13
0
 public function handleEncapsulated($identifier, EncapsulatedPacket $packet, $flags)
 {
     if (isset($this->players[$identifier])) {
         try {
             if ($packet->buffer !== "") {
                 $pk = $this->getPacket($packet->buffer);
                 if ($pk !== null) {
                     $pk->decode();
                     $this->players[$identifier]->handleDataPacket($pk);
                 }
             }
         } catch (\Exception $e) {
             if (\pocketmine\DEBUG > 1 and isset($pk)) {
                 $logger = $this->server->getLogger();
                 if ($logger instanceof MainLogger) {
                     $logger->debug("Packet " . get_class($pk) . " 0x" . bin2hex($packet->buffer));
                     $logger->logException($e);
                 }
             }
             if (isset($this->players[$identifier])) {
                 $this->interface->blockAddress($this->players[$identifier]->getAddress(), 5);
             }
         }
     }
 }
Пример #14
0
 /**
  * @return void
  */
 public function registerServerAliases()
 {
     $values = $this->server->getCommandAliases();
     foreach ($values as $alias => $commandStrings) {
         if (\strpos($alias, ":") !== \false or \strpos($alias, " ") !== \false) {
             $this->server->getLogger()->warning("Could not register alias " . $alias . " because it contains illegal characters");
             continue;
         }
         $targets = [];
         $bad = "";
         foreach ($commandStrings as $commandString) {
             $args = \explode(" ", $commandString);
             $command = $this->getCommand($args[0]);
             if ($command === \null) {
                 if (\strlen($bad) > 0) {
                     $bad .= ", ";
                 }
                 $bad .= $commandString;
             } else {
                 $targets[] = $commandString;
             }
         }
         if (\strlen($bad) > 0) {
             $this->server->getLogger()->warning("Could not register alias " . $alias . " because it contains commands that do not exist: " . $bad);
             continue;
         }
         //These registered commands have absolute priority
         if (\count($targets) > 0) {
             $this->knownCommands[\strtolower($alias)] = new FormattedCommandAlias(\strtolower($alias), $targets);
         } else {
             unset($this->knownCommands[\strtolower($alias)]);
         }
     }
 }
Пример #15
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin instanceof PluginBase and $plugin->isEnabled()) {
         $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.disable", [$plugin->getDescription()->getFullName()]));
         $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
         $plugin->setEnabled(false);
     }
 }
Пример #16
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin instanceof PluginBase and $plugin->isEnabled()) {
         $this->server->getLogger()->info("Disabling " . $plugin->getDescription()->getFullName());
         $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
         $plugin->setEnabled(\false);
     }
 }
Пример #17
0
 protected function showChannelSuggestionBeta()
 {
     $logger = $this->server->getLogger();
     $logger->info("----- PocketMine-MP Auto Updater -----");
     $logger->info("It appears you're running a Beta build, when you've specified that you prefer to run Stable builds.");
     $logger->info("If you would like to be kept informed about new Beta or Development builds, it is recommended that you change 'preferred-channel' in your pocketmine.yml to 'beta' or 'development'.");
     $logger->info("----- -------------------------- -----");
 }
Пример #18
0
 protected function showCuttingEdge()
 {
     $logger = $this->server->getLogger();
     $logger->warning("----- ClearSky Auto Updater -----");
     $logger->warning("It appears you're running a CuttingEdge build, it means you are using src or a custom build");
     $logger->warning("If you want to run a production server, please use a phar provided by our Jenkins server for better performance");
     $logger->warning("If you are running a custom build, please remember that the ClearSky Team won't support this version");
     $logger->warning("----- -------------------------- -----");
 }
Пример #19
0
 public function trigger($memory, $limit, $global = false, $triggerCount = 0)
 {
     $this->server->getLogger()->debug("[Memory Manager] " . ($global ? "Global " : "") . "Low memory triggered, limit " . round($limit / 1024 / 1024, 2) . "MB, using " . round($memory / 1024 / 1024, 2) . "MB");
     if ($this->cacheTrigger) {
         foreach ($this->server->getLevels() as $level) {
             $level->clearCache(true);
         }
     }
     if ($this->chunkTrigger and $this->chunkCollect) {
         foreach ($this->server->getLevels() as $level) {
             $level->doChunkGarbageCollection();
         }
     }
     $ev = new LowMemoryEvent($memory, $limit, $global, $triggerCount);
     $this->server->getPluginManager()->callEvent($ev);
     $cycles = 0;
     if ($this->garbageCollectionTrigger) {
         $cycles = $this->triggerGarbageCollector();
     }
     $this->server->getLogger()->debug("[Memory Manager] Freed " . round($ev->getMemoryFreed() / 1024 / 1024, 2) . "MB, {$cycles} cycles");
 }
Пример #20
0
 public function collectTasks()
 {
     Timings::$schedulerAsyncTimer->startTiming();
     for ($i = 0; $i < 2; $i++) {
         if (!$this->pool->collect(function (AsyncTask $task) {
             if ($task->isGarbage() and !$task->isRunning() and !$task->isCrashed()) {
                 if (!$task->hasCancelledRun()) {
                     $task->onCompletion($this->server);
                 }
                 $this->removeTask($task);
             } elseif ($task->isTerminated() or $task->isCrashed()) {
                 $this->server->getLogger()->critical("Could not execute asynchronous task " . (new \ReflectionClass($task))->getShortName() . ": Task crashed");
                 $this->removeTask($task);
             }
             return $task->isGarbage();
         })) {
             break;
         }
     }
     Timings::$schedulerAsyncTimer->stopTiming();
 }
 public function onCompletion(Server $server)
 {
     $plugin = $server->getPluginManager()->getPlugin($this->owner);
     if ($plugin == null) {
         $server->getLogger()->error("Internal ERROR: " . __METHOD__ . "," . __LINE__);
         return;
     }
     if (!$plugin->isEnabled()) {
         return;
     }
     $callback = [$plugin, $this->callable];
     $callback($this->getResult(), $this->args);
 }
Пример #22
0
 public function collectTasks()
 {
     foreach ($this->tasks as $task) {
         if ($task->isGarbage()) {
             $task->onCompletion($this->server);
             $this->removeTask($task);
         } elseif ($task->isTerminated()) {
             $info = $task->getTerminationInfo();
             $this->removeTask($task);
             $this->server->getLogger()->critical("Could not execute asynchronous task " . (new \ReflectionClass($task))->getShortName() . ": " . $info["message"]);
             $this->server->getLogger()->critical("On " . $info["scope"] . ", line " . $info["line"] . ", " . $info["function"] . "()");
         }
     }
 }
Пример #23
0
 public function collectTasks()
 {
     Timings::$schedulerAsyncTimer->startTiming();
     foreach ($this->tasks as $task) {
         if ($task->isFinished() and !$task->isRunning() and !$task->isCrashed()) {
             if (!$task->hasCancelledRun()) {
                 $task->onCompletion($this->server);
             }
             $this->removeTask($task);
         } elseif ($task->isTerminated() or $task->isCrashed()) {
             $this->server->getLogger()->critical("Could not execute asynchronous task " . (new \ReflectionClass($task))->getShortName() . ": Task crashed");
             $this->removeTask($task, true);
         }
     }
     Timings::$schedulerAsyncTimer->stopTiming();
 }
 public function __construct(Server $server, array $config)
 {
     self::$obj = $this;
     $this->server = $server;
     $this->serverIp = $config["server-ip"];
     $this->port = $config["server-port"];
     $this->isMainServer = $config["isMainServer"];
     $this->password = $config["password"];
     $this->description = $config["description"];
     $this->logger = $server->getLogger();
     $this->interface = new SynapseInterface($this, $this->serverIp, $this->port);
     $this->synLibInterface = new SynLibInterface($this, $this->interface);
     $this->lastUpdate = microtime(true);
     $this->lastRecvInfo = microtime(true);
     $this->connect();
 }
Пример #25
0
 public function collectTasks()
 {
     Timings::$schedulerAsyncTimer->startTiming();
     foreach ($this->tasks as $task) {
         if ($task->isGarbage() and !$task->isRunning()) {
             if (!$task->hasCancelledRun()) {
                 $task->onCompletion($this->server);
             }
             $this->removeTask($task);
         } elseif ($task->isTerminated()) {
             $info = $task->getTerminationInfo();
             $this->removeTask($task, true);
             $this->server->getLogger()->critical("Could not execute asynchronous task " . (new \ReflectionClass($task))->getShortName() . ": " . (isset($info["message"]) ? $info["message"] : "Unknown"));
             $this->server->getLogger()->critical("On " . $info["scope"] . ", line " . $info["line"] . ", " . $info["function"] . "()");
         }
     }
     Timings::$schedulerAsyncTimer->stopTiming();
 }
Пример #26
0
 /**
  * @param string        $event Class name that extends Event
  * @param Listener      $listener
  * @param int           $priority
  * @param EventExecutor $executor
  * @param Plugin        $plugin
  * @param bool          $ignoreCancelled
  *
  * @throws PluginException
  */
 public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false)
 {
     if (!is_subclass_of($event, Event::class)) {
         throw new PluginException($event . " is not an Event");
     }
     $class = new \ReflectionClass($event);
     if ($class->isAbstract()) {
         throw new PluginException($event . " is an abstract Event");
     }
     if ($class->getProperty("handlerList")->getDeclaringClass()->getName() !== $event) {
         $this->server->getLogger()->notice($event . " does not have a handler list");
     }
     if (!$plugin->isEnabled()) {
         throw new PluginException("Plugin attempted to register " . $event . " while not enabled");
     }
     $timings = new TimingsHandler("Plugin: " . $plugin->getDescription()->getFullName() . " Event: " . get_class($listener) . "::" . ($executor instanceof MethodEventExecutor ? $executor->getMethod() : "???") . "(" . (new \ReflectionClass($event))->getShortName() . ")", self::$pluginParentTimer);
     $this->getEventListeners($event)->register(new RegisteredListener($listener, $executor, $priority, $plugin, $ignoreCancelled, $timings));
 }
 /**
  * @param Server $server
  */
 public function onCompletion(Server $server)
 {
     //var_dump($this->result);
     $numPlayers = count($server->getOnlinePlayers());
     $maxPlayers = $server->getMaxPlayers();
     foreach ($this->result as $result) {
         if (is_array($result)) {
             $numPlayers += $result["info"]["numplayers"];
             $maxPlayers += $result["info"]["maxplayers"];
         } else {
             $server->getLogger()->critical($result);
         }
     }
     if (($plugin = $server->getPluginManager()->getPlugin("QueryFacade")) instanceof QueryFacade) {
         $plugin->getModifier()->setPlayerCount($numPlayers);
         $plugin->getModifier()->setMaxPlayerCount($maxPlayers);
     }
 }
 public function handleEncapsulated($identifier, EncapsulatedPacket $packet, $flags)
 {
     if (isset($this->players[$identifier])) {
         try {
             if ($packet->buffer !== "") {
                 $pk = $this->getPacket($packet->buffer);
                 if ($pk !== null) {
                     $pk->decode();
                     $this->players[$identifier]->handleDataPacket($pk);
                 }
             }
         } catch (\Throwable $e) {
             $logger = $this->server->getLogger();
             if (\pocketmine\DEBUG > 1 and isset($pk)) {
                 $logger->debug("Exception in packet " . get_class($pk) . " 0x" . bin2hex($packet->buffer));
             }
             $logger->logException($e);
         }
     }
 }
Пример #29
0
 public function handleEncapsulated($identifier, EncapsulatedPacket $packet, $flags)
 {
     if (isset($this->players[$identifier])) {
         try {
             if ($packet->buffer !== "") {
                 $pk = $this->getPacket($packet->buffer);
                 if ($pk !== null) {
                     $pk->decode();
                     assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread!");
                     $this->players[$identifier]->handleDataPacket($pk);
                 }
             }
         } catch (\Throwable $e) {
             if (\pocketmine\DEBUG > 1 and isset($pk)) {
                 $logger = $this->server->getLogger();
                 $logger->debug("Packet " . get_class($pk) . " 0x" . bin2hex($packet->buffer));
                 $logger->logException($e);
             }
             if (isset($this->players[$identifier])) {
                 $this->interface->blockAddress($this->players[$identifier]->getAddress(), 5);
             }
         }
     }
 }
Пример #30
0
 /**
  * Registers all the events in the given Listener class
  *
  * @param Listener $listener
  * @param Plugin   $plugin
  *
  * @throws PluginException
  */
 public function registerEvents(Listener $listener, Plugin $plugin)
 {
     if (!$plugin->isEnabled()) {
         throw new PluginException("Plugin attempted to register " . get_class($listener) . " while not enabled");
     }
     $reflection = new \ReflectionClass(get_class($listener));
     foreach ($reflection->getMethods() as $method) {
         if (!$method->isStatic()) {
             $priority = EventPriority::NORMAL;
             $ignoreCancelled = false;
             if (preg_match("/^[\t ]*\\* @priority[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) {
                 $matches[1] = strtoupper($matches[1]);
                 if (defined(EventPriority::class . "::" . $matches[1])) {
                     $priority = constant(EventPriority::class . "::" . $matches[1]);
                 }
             }
             if (preg_match("/^[\t ]*\\* @ignoreCancelled[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) {
                 $matches[1] = strtolower($matches[1]);
                 if ($matches[1] === "false") {
                     $ignoreCancelled = false;
                 } elseif ($matches[1] === "true") {
                     $ignoreCancelled = true;
                 }
             }
             $parameters = $method->getParameters();
             if (count($parameters) === 1 and $parameters[0]->getClass() instanceof \ReflectionClass and is_subclass_of($parameters[0]->getClass()->getName(), Event::class)) {
                 $class = $parameters[0]->getClass()->getName();
                 $reflection = new \ReflectionClass($class);
                 if (strpos((string) $reflection->getDocComment(), "@deprecated") !== false and $this->server->getProperty("settings.deprecated-verbose", true)) {
                     $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.deprecatedEvent", [$plugin->getName(), $class, get_class($listener) . "->" . $method->getName() . "()"]));
                 }
                 $this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled);
             }
         }
     }
 }