Пример #1
0
 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.
             ini_set("date.timezone", $ip_geolocation_data['timezone']);
         } else {
             ini_set("date.timezone", "UTC");
             date_default_timezone_set("UTC");
             $logger->warning("Timezone could not be automatically determined. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file.");
         }
Пример #2
0
 public function readChunk($x, $z)
 {
     $index = self::getChunkOffset($x, $z);
     if ($index < 0 or $index >= 4096) {
         return null;
     }
     $this->lastUsed = time();
     if (!$this->isChunkGenerated($index)) {
         return null;
     }
     fseek($this->filePointer, $this->locationTable[$index][0] << 12);
     $length = Binary::readInt(fread($this->filePointer, 4));
     $compression = ord(fgetc($this->filePointer));
     if ($length <= 0 or $length > self::MAX_SECTOR_LENGTH) {
         //Not yet generated / corrupted
         if ($length >= self::MAX_SECTOR_LENGTH) {
             $this->locationTable[$index][0] = ++$this->lastSector;
             $this->locationTable[$index][1] = 1;
             MainLogger::getLogger()->error("Corrupted chunk header detected");
         }
         return null;
     }
     if ($length > $this->locationTable[$index][1] << 12) {
         //Invalid chunk, bigger than defined number of sectors
         MainLogger::getLogger()->error("Corrupted bigger chunk detected");
         $this->locationTable[$index][1] = $length >> 12;
         $this->writeLocationIndex($index);
     } elseif ($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP) {
         MainLogger::getLogger()->error("Invalid compression type");
         return null;
     }
     $chunk = $this->unserializeChunk(fread($this->filePointer, $length - 1));
     if ($chunk instanceof FullChunk) {
         return $chunk;
     } else {
         MainLogger::getLogger()->error("Corrupted chunk detected");
         return null;
     }
 }
Пример #3
0
 /**
  * @param $content
  */
 private function parseProperties($content)
 {
     if (preg_match_all('/([a-zA-Z0-9\\-_\\.]*)=([^\\r\\n]*)/u', $content, $matches) > 0) {
         //false or 0 matches
         foreach ($matches[1] as $i => $k) {
             $v = trim($matches[2][$i]);
             switch (strtolower($v)) {
                 case "on":
                 case "true":
                 case "yes":
                     $v = true;
                     break;
                 case "off":
                 case "false":
                 case "no":
                     $v = false;
                     break;
             }
             if (isset($this->config[$k])) {
                 MainLogger::getLogger()->debug("[Config] Repeated property " . $k . " on file " . $this->file);
             }
             $this->config[$k] = $v;
         }
     }
 }
Пример #4
0
 public function save($flag = true)
 {
     $this->removeExpired();
     $fp = @fopen($this->file, "w");
     if (is_resource($fp)) {
         if ($flag === true) {
             fwrite($fp, "# Updated " . strftime("%x %H:%M", time()) . " by " . Server::getInstance()->getName() . " " . Server::getInstance()->getBukkitPEVersion() . "\n");
             fwrite($fp, "# victim name | ban date | banned by | banned until | reason\n\n");
         }
         foreach ($this->list as $entry) {
             fwrite($fp, $entry->getString() . "\n");
         }
         fclose($fp);
     } else {
         MainLogger::getLogger()->error("Could not save ban list");
     }
 }
Пример #5
0
 /**
  * @param string $message
  */
 public function sendMessage($message)
 {
     if ($message instanceof TextContainer) {
         $message = $this->getServer()->getLanguage()->translate($message);
     } else {
         $message = $this->getServer()->getLanguage()->translateString($message);
     }
     foreach (explode("\n", trim($message)) as $line) {
         MainLogger::getLogger()->info($line);
     }
 }