Esempio n. 1
0
 $autoloader->register(true);
 set_time_limit(0);
 //Who set it to 30 seconds?!?!
 gc_enable();
 error_reporting(-1);
 ini_set("allow_url_fopen", 1);
 ini_set("display_errors", 1);
 ini_set("display_startup_errors", 1);
 ini_set("default_charset", "utf-8");
 ini_set("memory_limit", -1);
 define("BukkitPE\\START_TIME", microtime(true));
 $opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-profiler"]);
 define("BukkitPE\\DATA", isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR);
 define("BukkitPE\\PLUGIN_PATH", isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR);
 Terminal::init();
 define("BukkitPE\\ANSI", Terminal::hasFormattingCodes());
 if (!file_exists(\BukkitPE\DATA)) {
     mkdir(\BukkitPE\DATA, 0777, true);
 }
 //Logger has a dependency on timezone, so we'll set it to UTC until we can get the actual timezone.
 date_default_timezone_set("UTC");
 $logger = new MainLogger(\BukkitPE\DATA . "server.log", \BukkitPE\ANSI);
 if (!ini_get("date.timezone")) {
     if ($timezone = detect_system_timezone() and date_default_timezone_set($timezone)) {
         //Success! Timezone has already been set and validated in the if statement.
         //This here is just for redundancy just in case some program wants to read timezone data from the ini.
         ini_set("date.timezone", $timezone);
     } else {
         //If system timezone detection fails or timezone is an invalid value.
         if ($response = Utils::getURL("http://ip-api.com/json") and $ip_geolocation_data = json_decode($response, true) and $ip_geolocation_data['status'] != 'fail' and date_default_timezone_set($ip_geolocation_data['timezone'])) {
             //Again, for redundancy.
Esempio n. 2
0
 protected function send($message, $level, $prefix, $color)
 {
     $now = time();
     $thread = \Thread::getCurrentThread();
     if ($thread === null) {
         $threadName = "Server thread";
     } elseif ($thread instanceof Thread or $thread instanceof Worker) {
         $threadName = $thread->getThreadName() . " thread";
     } else {
         $threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
     }
     $message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s", $now) . "] " . TextFormat::RESET . $color . "[" . $prefix . "]:" . " " . $message . TextFormat::RESET);
     //$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s") . "] ". TextFormat::RESET . $color ."<".$prefix . ">" . " " . $message . TextFormat::RESET);
     $cleanMessage = TextFormat::clean($message);
     if (!Terminal::hasFormattingCodes()) {
         echo $cleanMessage . PHP_EOL;
     } else {
         echo $message . PHP_EOL;
     }
     if ($this->attachment instanceof \ThreadedLoggerAttachment) {
         $this->attachment->call($level, $message);
     }
     $this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
     if ($this->logStream->count() === 1) {
         $this->synchronized(function () {
             $this->notify();
         });
     }
 }