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]);
}
}
}
}
/** * Tries to execute a server tick */ private function tick() { $tickTime = microtime(true); if ($tickTime - $this->nextTick < -0.025) { //Allow half a tick of diff return false; } Timings::$serverTickTimer->startTiming(); ++$this->tickCounter; $this->checkConsole(); Timings::$connectionTimer->startTiming(); $this->network->processInterfaces(); if ($this->rcon !== null) { $this->rcon->check(); } Timings::$connectionTimer->stopTiming(); Timings::$schedulerTimer->startTiming(); $this->scheduler->mainThreadHeartbeat($this->tickCounter); Timings::$schedulerTimer->stopTiming(); $this->checkTickUpdates($this->tickCounter, $tickTime); foreach ($this->players as $player) { $player->checkNetwork(); } if (($this->tickCounter & 0b1111) === 0) { $this->titleTick(); $this->maxTick = 20; $this->maxUse = 0; if (($this->tickCounter & 0b111111111) === 0) { try { $this->getPluginManager()->callEvent($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5)); if ($this->queryHandler !== null) { $this->queryHandler->regenerateInfo(); } } catch (\Exception $e) { if ($this->logger instanceof MainLogger) { $this->logger->logException($e); } } } $this->getNetwork()->updateName(); } if ($this->autoSave and ++$this->autoSaveTicker >= $this->autoSaveTicks) { $this->autoSaveTicker = 0; $this->doAutoSave(); } if ($this->sendUsageTicker > 0 and --$this->sendUsageTicker === 0) { $this->sendUsageTicker = 6000; $this->sendUsage(SendUsageTask::TYPE_STATUS); } if ($this->tickCounter % 100 === 0) { foreach ($this->levels as $level) { $level->clearCache(); } if ($this->getTicksPerSecondAverage() < 12) { $this->logger->warning($this->getLanguage()->translateString("pocketmine.server.tickOverload")); } } if ($this->dispatchSignals and $this->tickCounter % 5 === 0) { pcntl_signal_dispatch(); } $this->getMemoryManager()->check(); Timings::$serverTickTimer->stopTiming(); $now = microtime(true); $tick = min(20, 1 / max(0.001, $now - $tickTime)); $use = min(1, ($now - $tickTime) / 0.05); TimingsHandler::tick($tick <= $this->profilingTickRate); if ($this->maxTick > $tick) { $this->maxTick = $tick; } if ($this->maxUse < $use) { $this->maxUse = $use; } array_shift($this->tickAverage); $this->tickAverage[] = $tick; array_shift($this->useAverage); $this->useAverage[] = $use; if ($this->nextTick - $tickTime < -1) { $this->nextTick = $tickTime; } else { $this->nextTick += 0.05; } return true; }