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; } }
/** * @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; } } }
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"); } }
/** * @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); } }