Exemplo n.º 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->getKatana()->console->system($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]);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin instanceof PluginBase and $plugin->isEnabled()) {
         $this->server->getKatana()->console->plugin("Disabling " . Terminal::$COLOR_WHITE . $plugin->getDescription()->getFullName());
         $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
         $plugin->setEnabled(false);
     }
 }
Exemplo n.º 3
0
        //Found Git information!
        define("pocketmine\\GIT_COMMIT", strtolower(trim(file_get_contents(\pocketmine\PATH . ".git/refs/heads/master"))));
    } else {
        //Unknown :(
        define("pocketmine\\GIT_COMMIT", str_repeat("00", 20));
    }
    @define("ENDIANNESS", pack("d", 1) === "?ð" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN);
    @define("INT32_MASK", is_int(4294967295.0) ? 4294967295.0 : -1);
    @ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false)));
    //Fix OPCache address errors
    if (!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])) {
        new Installer();
    }
    if (\Phar::running(true) === "") {
        $logger->warning("Non-packaged Katana installation detected, do not use on production.");
    }
    ThreadManager::init();
    $server = new Server($autoloader, $logger, \pocketmine\PATH, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);
    $server->getKatana()->console->system("Stopping other threads");
    foreach (ThreadManager::getInstance()->getAll() as $id => $thread) {
        $server->getKatana()->console->system("Stopping " . Terminal::$COLOR_WHITE . (new \ReflectionClass($thread))->getShortName() . Terminal::$COLOR_GRAY . " thread");
        $thread->quit();
    }
    $killer = new ServerKiller(8);
    $killer->start();
    $killer->detach();
    $logger->shutdown();
    $logger->join();
    echo Terminal::$FORMAT_RESET . "\n";
    exit(0);
}
Exemplo n.º 4
0
 public function chunkRequestCallback($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
 {
     $this->timings->syncChunkSendTimer->startTiming();
     $index = Level::chunkHash($x, $z);
     $this->saveChunkToDisk($x, $z, $payload, $ordering);
     if (isset($this->chunkSendTasks[$index])) {
         foreach ($this->chunkSendQueue[$index] as $player) {
             /** @var Player $player */
             if ($player->isConnected() and isset($player->usedChunks[$index])) {
                 $player->sendBatchedChunk($x, $z, $this->chunkCache[$x . ":" . $z]);
             }
         }
         unset($this->chunkSendQueue[$index]);
         unset($this->chunkSendTasks[$index]);
     }
     $this->timings->syncChunkSendTimer->stopTiming();
     if (!$this->server->getKatana()->getProperty("cache.save-to-ram", true)) {
         unset($this->chunkCache[$x . ":" . $z]);
     }
 }
Exemplo n.º 5
0
 public function saveChunkToDisk($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
 {
     // When the payload of the chunk has been calculated it, save it if possible to save future CPU cycles
     /** @var Player $player */
     if (file_exists("chunk_cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat")) {
         return $this->loadChunkFromDisk($x, $z);
     }
     $pk = new FullChunkDataPacket();
     $pk->chunkX = $x;
     $pk->chunkZ = $z;
     $pk->order = $ordering;
     $pk->data = $payload;
     $pk->encode();
     // all chunks are zlib_encoded, level is arbitrary but 6 is a good match between device CPU power needed
     // and bandwidth
     $data = zlib_encode(Binary::writeInt(strlen($pk->buffer)) . $pk->buffer, ZLIB_ENCODING_DEFLATE, 6);
     if (!$this->server->getKatana()->getProperty("caching.save-to-disk", true)) {
         return $data;
     }
     file_put_contents("chunk_cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat", $data);
     return $data;
 }