Beispiel #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]);
             }
         }
     }
 }
 /**
  * @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("BukkitPE.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("BukkitPE.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)]);
         }
     }
 }
 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 (\BukkitPE\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);
             }
         }
     }
 }
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin instanceof PluginBase and $plugin->isEnabled()) {
         $this->server->getLogger()->info($this->server->getLanguage()->translateString("BukkitPE.plugin.disable", [$plugin->getDescription()->getFullName()]));
         $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
         $plugin->setEnabled(false);
     }
 }
Beispiel #5
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();
 }
 /**
  * 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(\ReflectionMethod::IS_PUBLIC) 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("BukkitPE.plugin.deprecatedEvent", [$plugin->getName(), $class, get_class($listener) . "->" . $method->getName() . "()"]));
                 }
                 $this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled);
             }
         }
     }
 }
Beispiel #7
0
 public function unloadChunk($x, $z, $safe = true, $trySave = true)
 {
     if ($safe === true and $this->isChunkInUse($x, $z)) {
         return false;
     }
     if (!$this->isChunkLoaded($x, $z)) {
         return true;
     }
     $this->timings->doChunkUnload->startTiming();
     $index = Level::chunkHash($x, $z);
     $chunk = $this->getChunk($x, $z);
     if ($chunk !== null and $chunk->getProvider() !== null) {
         $this->server->getPluginManager()->callEvent($ev = new ChunkUnloadEvent($chunk));
         if ($ev->isCancelled()) {
             $this->timings->doChunkUnload->stopTiming();
             return false;
         }
     }
     try {
         if ($chunk !== null) {
             if ($trySave and $this->getAutoSave()) {
                 $entities = 0;
                 foreach ($chunk->getEntities() as $e) {
                     if ($e instanceof Player) {
                         continue;
                     }
                     ++$entities;
                 }
                 if ($chunk->hasChanged() or count($chunk->getTiles()) > 0 or $entities > 0) {
                     $this->provider->setChunk($x, $z, $chunk);
                     $this->provider->saveChunk($x, $z);
                 }
             }
             foreach ($this->getChunkLoaders($x, $z) as $loader) {
                 $loader->onChunkUnloaded($chunk);
             }
         }
         $this->provider->unloadChunk($x, $z, $safe);
     } catch (\Exception $e) {
         $logger = $this->server->getLogger();
         $logger->error($this->server->getLanguage()->translateString("BukkitPE.level.chunkUnloadError", [$e->getMessage()]));
         if ($logger instanceof MainLogger) {
             $logger->logException($e);
         }
     }
     unset($this->chunks[$index]);
     unset($this->chunkTickList[$index]);
     unset($this->chunkCache[$index]);
     $this->timings->doChunkUnload->stopTiming();
     return true;
 }
Beispiel #8
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) {
             $pkLen = Binary::readInt(substr($str, $offset, 4));
             $offset += 4;
             $buf = substr($str, $offset, $pkLen);
             $offset += $pkLen;
             if (($pk = $this->getPacket(ord($buf[0]))) !== null) {
                 if ($pk::NETWORK_ID === Info::BATCH_PACKET) {
                     throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
                 }
                 $pk->setBuffer($buf, 1);
                 $pk->decode();
                 $p->handleDataPacket($pk);
                 if ($pk->getOffset() <= 0) {
                     return;
                 }
             }
         }
     } catch (\Exception $e) {
         if (\BukkitPE\DEBUG > 1) {
             $logger = $this->server->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
                 $logger->logException($e);
             }
         }
     }
 }