reload() public static method

public static reload ( )
Example #1
0
 public function reload()
 {
     $this->logger->info("Saving levels...");
     foreach ($this->levels as $level) {
         $level->save();
     }
     $this->pluginManager->disablePlugins();
     $this->pluginManager->clearPlugins();
     $this->commandMap->clearCommands();
     $this->logger->info("Reloading properties...");
     $this->properties->reload();
     $this->maxPlayers = $this->getConfigInt("max-players", 20);
     if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) {
         $this->setConfigInt("difficulty", 3);
     }
     $this->banByIP->load();
     $this->banByName->load();
     $this->reloadWhitelist();
     $this->operators->reload();
     $this->memoryManager->doObjectCleanup();
     foreach ($this->getIPBans()->getEntries() as $entry) {
         $this->getNetwork()->blockAddress($entry->getName(), -1);
     }
     $this->pluginManager->registerInterface(PharPluginLoader::class);
     $this->pluginManager->registerInterface(ScriptPluginLoader::class);
     $this->pluginManager->loadPlugins($this->pluginPath);
     $this->enablePlugins(PluginLoadOrder::STARTUP);
     $this->enablePlugins(PluginLoadOrder::POSTWORLD);
     TimingsHandler::reload();
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return true;
     }
     $mode = strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(true);
         TimingsHandler::reload();
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.enable"));
         return true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(false);
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.disable"));
         return true;
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsDisabled"));
         return true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.reset"));
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = microtime(true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         if (!file_exists($timingFolder)) {
             mkdir($timingFolder, 0777);
         }
         $timings = $timingFolder . "timings.txt";
         while (file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? fopen("php://temp", "r+b") : fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         fwrite($fileTimings, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
         if ($paste) {
             fseek($fileTimings, 0);
             $data = ["syntax" => "text", "poster" => $sender->getServer()->getName(), "content" => stream_get_contents($fileTimings)];
             $ch = curl_init("http://paste.ubuntu.com/");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             curl_setopt($ch, CURLOPT_AUTOREFERER, false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
             curl_setopt($ch, CURLOPT_HEADER, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $data = curl_exec($ch);
             curl_close($ch);
             if (preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
                 $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError"));
                 return true;
             }
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsUpload", ["http://paste.ubuntu.com/" . $matches[1] . "/"]));
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead", ["http://timings.aikar.co/?url=" . $matches[1]]));
             fclose($fileTimings);
         } else {
             fclose($fileTimings);
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsWrite", [$timings]));
         }
     }
     return true;
 }
Example #3
0
 public function reload()
 {
     $this->logger->info("Saving levels...");
     foreach ($this->levels as $level) {
         $level->save();
     }
     $this->pluginManager->disablePlugins();
     $this->pluginManager->clearPlugins();
     $this->commandMap->clearCommands();
     $this->logger->info("Reloading properties...");
     $this->properties->reload();
     $this->maxPlayers = $this->getConfigInt("max-players", 20);
     if (($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", "256M")))) !== false) {
         $value = ["M" => 1, "G" => 1024];
         $real = (int) substr($memory, 0, -1) * $value[substr($memory, -1)];
         if ($real < 256) {
             $this->logger->warning($this->getName() . " may not work right with less than 256MB of RAM", true, true, 0);
         }
         @ini_set("memory_limit", $memory);
     } else {
         $this->setConfigString("memory-limit", "256M");
     }
     if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) {
         $this->setConfigInt("difficulty", 3);
     }
     $this->banByIP->load();
     $this->banByName->load();
     $this->reloadWhitelist();
     $this->operators->reload();
     foreach ($this->getIPBans()->getEntries() as $entry) {
         $this->blockAddress($entry->getName(), -1);
     }
     $this->pluginManager->registerInterface(PharPluginLoader::class);
     $this->pluginManager->loadPlugins($this->pluginPath);
     $this->enablePlugins(PluginLoadOrder::STARTUP);
     $this->enablePlugins(PluginLoadOrder::POSTWORLD);
     TimingsHandler::reload();
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) !== 1) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return \true;
     }
     $mode = \strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(\true);
         TimingsHandler::reload();
         $sender->sendMessage("Enabled Timings & Reset");
         return \true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(\false);
         $sender->sendMessage("Disabled Timings");
         return \true;
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage("Please enable timings by typing /timings on");
         return \true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage("Timings reset");
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = \microtime(\true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         if (!\file_exists($timingFolder)) {
             \mkdir($timingFolder, 0777);
         }
         $timings = $timingFolder . "timings.txt";
         while (\file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? \fopen("php://temp", "r+b") : \fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         \fwrite($fileTimings, "Sample time " . \round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . \PHP_EOL);
         if ($paste) {
             \fseek($fileTimings, 0);
             $data = ["syntax" => "text", "poster" => $sender->getServer()->getName(), "content" => \stream_get_contents($fileTimings)];
             $ch = curl_init("http://paste.ubuntu.com/");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, \false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             curl_setopt($ch, CURLOPT_AUTOREFERER, \false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, \false);
             curl_setopt($ch, CURLOPT_HEADER, \true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, \true);
             $data = curl_exec($ch);
             curl_close($ch);
             if (\preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
                 $sender->sendMessage("An error happened while pasting the report");
                 return \true;
             }
             $sender->sendMessage("Timings uploaded to http://paste.ubuntu.com/" . $matches[1] . "/");
             $sender->sendMessage("You can read the results at http://timings.aikar.co/?url=" . $matches[1]);
             \fclose($fileTimings);
         } else {
             \fclose($fileTimings);
             $sender->sendMessage("Timings written to " . $timings);
         }
     }
     return \true;
 }
Example #5
0
 public function onEnable()
 {
     //		$this->ircSender = new IRCSender;
     //		$this->ircSender->start();
     //		$this->getLogger()->addAttachment($att = new IRCLoggerAttachment($this->ircSender));
     echo "Enabling auto save...";
     $this->getServer()->setAutoSave(true);
     $this->resetLine();
     echo "Preloading resources...";
     $this->words = json_decode(stream_get_contents($stream = $this->getResource("words.json")), true);
     $this->timestamp = (int) stream_get_contents($stream = $this->getResource("timestamp.LEGIONPE"));
     fclose($stream);
     $this->resetLine();
     echo "Establishing MySQL connection...";
     $this->mysqli = new MysqlConnection($this);
     $this->resetLine();
     echo "Initializing chat channels...";
     $this->chanMgr = new ChannelManager($this);
     $this->hubChannel = $this->chanMgr->joinChannel($this, "Global", Channel::CLASS_MODULAR, false);
     $this->mandatoryChannel = $this->chanMgr->joinChannel($this, "Mandatory", Channel::CLASS_INFRASTRUCTURAL, true);
     $this->supportChannel = $this->chanMgr->joinChannel($this, "Support", Channel::CLASS_CUSTOM, true);
     $this->staffChannel = $this->chanMgr->joinChannel($this, "Staff", Channel::CLASS_CUSTOM);
     $this->resetLine(true);
     echo "Initializing teams...";
     $this->teamMgr = new TeamManager($this);
     $this->resetLine();
     echo "Registering sessions handler and commands...";
     $this->getServer()->getPluginManager()->registerEvents($this->sessions = new SessionInterface($this), $this);
     $this->registerCommands();
     if (!HAVE_THEY_FIXED_ARMOR) {
         $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new CallbackPluginTask($this, function () {
             foreach ($this->getServer()->getOnlinePlayers() as $p) {
                 if ($p->isOnline()) {
                     $p->getInventory()->sendArmorContents($p->getLevel()->getPlayers());
                 }
             }
         }), 20, 20);
     }
     $this->resetLine();
     echo "Initializing statistics...";
     $this->stats = new Statistics([self::TITLE_LEGIONPE_JOINS, self::TITLE_KITPVP_JOINS, self::TITLE_PARKOUR_JOINS, self::TITLE_INFECTED_JOINS, self::TITLE_LEGIONPE_NEW_JOINS, self::TITLE_KITPVP_NEW_JOINS, self::TITLE_PARKOUR_NEW_JOINS, self::TITLE_INFECTED_NEW_JOINS], $this);
     $this->initModules();
     $this->resetLine(true);
     $msg = $this->getDescription()->getFullName() . " has been enabled at " . Utils::getIP() . ":{$this->getServer()->getPort()}. ";
     $msg .= "The process ID is " . getmypid() . ". ";
     $dateTime = (new \DateTime())->setTimestamp($this->timestamp);
     $msg .= "The plugin was built on " . $dateTime->format("jS F, Y \\a\\t H:i:s (T, \\G\\M\\T P). ");
     $msg .= "Easter mode is " . (IT_IS_EASTER ? "" : "not ") . "enabled.";
     $msg .= "Timings is now being enabled.";
     if (!IS_TEST) {
         Utils::getURL(self::IRC_WEBHOOK . urlencode($msg), 2);
     }
     $this->localize = yaml_parse_file($this->getDataFolder() . "localize.yml");
     if (!IS_TEST) {
         $sid = $this->localize["server-id"];
         $ip = $this->localize["ip"];
         $port = $this->localize["port"];
         $this->getMySQLi()->query("INSERT INTO active_servers(sid,address,port,pid)VALUES({$sid},%s,{$port},%s)ON DUPLICATE KEY UPDATE last_up=NOW(),pid=%s", MysqlConnection::RAW, $ip, (string) getmypid(), (string) getmypid());
         $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new CallbackPluginTask($this, function () use($sid, $port, $ip) {
             $total = count($this->getServer()->getOnlinePlayers());
             $kitpvp = $this->getGame(Session::SESSION_GAME_KITPVP)->countPlayers();
             $parkour = $this->getGame(Session::SESSION_GAME_PARKOUR)->countPlayers();
             $spleef = $this->getGame(Session::SESSION_GAME_SPLEEF)->countPlayers();
             $this->getMySQLi()->query("UPDATE active_servers SET last_up=NOW(),cnt={$total},kitpvp={$kitpvp},parkour={$parkour},spleef={$spleef} WHERE sid={$sid}", MysqlConnection::RAW, $ip);
         }), 50, 50);
     }
     $this->getLogger()->info($msg);
     $this->getServer()->getPluginManager()->setUseTimings(true);
     TimingsHandler::reload();
 }
Example #6
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return true;
     }
     $mode = strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(true);
         TimingsHandler::reload();
         $sender->sendMessage("Enabled Timings & Reset");
         return true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(false);
         $sender->sendMessage("Disabled Timings");
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage("Please enable timings by typing /timings on");
         return true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage("Timings reset");
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = microtime(true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         @mkdir($timingFolder, 0777);
         $timings = $timingFolder . "timings.txt";
         while (file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? fopen("php://temp", "r+b") : fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         fwrite($fileTimings, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
         if ($paste) {
             fseek($fileTimings, 0);
             $data = ["public" => false, "description" => $sender->getServer()->getName() . " Timings", "files" => ["timings.txt" => ["content" => stream_get_contents($fileTimings)]]];
             $ch = curl_init("https://api.github.com/gists");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES));
             curl_setopt($ch, CURLOPT_AUTOREFERER, true);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json", "User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $ret = curl_exec($ch);
             $data = json_decode($ret);
             curl_close($ch);
             if ($data === false or $data === null or !isset($data->html_url)) {
                 $sender->sendMessage("An error happened while pasting the report");
                 return true;
             }
             $timings = $data->html_url;
         }
         fclose($fileTimings);
         $sender->sendMessage("Timings written to " . $timings);
         $sender->sendMessage("Paste contents of file into form at http://aikar.co/timings.php to read results.");
     }
     return true;
 }
 public function onEnable()
 {
     $this->langs = new LanguageManager($this);
     ThetaCommand::registerAll($this, $this->getServer()->getCommandMap());
     $this->getServer()->getNetwork()->registerPacket(OldLoginPacket::NETWORK_ID, OldLoginPacket::class);
     $class = $this->getBasicListenerClass();
     $this->getServer()->getPluginManager()->registerEvents($this->listener = new $class($this), $this);
     $class = $this->getSessionListenerClass();
     $this->getServer()->getPluginManager()->registerEvents($this->sesList = new $class($this), $this);
     $this->db = Credentials::getMysql();
     new InitDbQuery($this);
     $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new SyncStatusTask($this), 40, 20);
     $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new SessionTickTask($this), 1, 10);
     $this->getServer()->getScheduler()->scheduleRepeatingTask($this->syncChatTask = new FireSyncChatQueryTask($this), 5);
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new DbPingQuery($this), 1200);
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new RestartServerTask($this), 6000);
     $this->restartTime = $this->getServer()->getTick() + 72000;
     $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new RandomBroadcastTask($this), 2400, 2400);
     $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this, function () {
         $plugin = $this->getServer()->getPluginManager()->getPlugin("FastTransfer");
         if ($plugin instanceof Plugin and $plugin->isEnabled()) {
             $this->getServer()->getPluginManager()->disablePlugin($plugin);
         }
     }), 2);
     // $RESEND_ADD_PLAYER = $this->getResendAddPlayerFreq();
     // if($RESEND_ADD_PLAYER > 0){
     //	  $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new ResendPlayersTask($this), $RESEND_ADD_PLAYER, $RESEND_ADD_PLAYER);
     // }
     /** @noinspection PhpUsageOfSilenceOperatorInspection */
     @touch($this->getDataFolder() . "privmsg.log");
     $this->pmLog = fopen($this->getDataFolder() . "privmsg.log", "at");
     $this->faceSeeks = json_decode($this->getResourceContents("head.json"));
     $this->badWords = json_decode($this->getResourceContents("words.json"));
     $this->approvedDomains = json_decode($this->getResourceContents("approvedDomains.json"));
     $buildInfo = json_decode($this->getResourceContents("build.json"));
     $compileTime = $buildInfo->time;
     $buildNumber = $buildInfo->buildNumber;
     $buildAuthor = $buildInfo->buildAuthor;
     Utils::getURL(Credentials::IRC_WEBHOOK_STATUS . urlencode("[Status] [" . Settings::$CLASSES_NAMES[Settings::$LOCALIZE_CLASS] . "] Server at " . Settings::$LOCALIZE_IP . ":" . Settings::$LOCALIZE_PORT . " started."), 3);
     $this->getServer()->getPluginManager()->setUseTimings(true);
     TimingsHandler::reload();
     $this->getLogger()->alert("Enabled " . $this->getDescription()->getFullName() . " Build {$buildNumber} compiled at " . date("d/m/Y H:i:s (P)", $compileTime) . " (" . MUtils::time_secsToString(time() - $compileTime) . " ago) by {$buildAuthor}. MyPID is " . \getmypid() . ".");
 }