Ejemplo n.º 1
0
 /**
  * @param string $str
  *
  * @return BanEntry
  */
 public static function fromString($str)
 {
     if (strlen($str) < 2) {
         return null;
     } else {
         $str = explode("|", trim($str));
         $entry = new BanEntry(trim(array_shift($str)));
         if (count($str) > 0) {
             $datetime = \DateTime::createFromFormat(self::$format, array_shift($str));
             if (!$datetime instanceof \DateTime) {
                 MainLogger::getLogger()->alert("Error parsing date for BanEntry for player \"" . $entry->getName() . "\", the format may be invalid!");
                 return $entry;
             }
             $entry->setCreated($datetime);
             if (count($str) > 0) {
                 $entry->setSource(trim(array_shift($str)));
                 if (count($str) > 0) {
                     $expire = trim(array_shift($str));
                     if (strtolower($expire) !== "forever" and strlen($expire) > 0) {
                         $entry->setExpires(\DateTime::createFromFormat(self::$format, $expire));
                     }
                     if (count($str) > 0) {
                         $entry->setReason(trim(array_shift($str)));
                     }
                 }
             }
         }
         return $entry;
     }
 }
Ejemplo n.º 2
0
 public function load()
 {
     $this->list = [];
     $fp = @\fopen($this->file, "r");
     if (\is_resource($fp)) {
         while (($line = \fgets($fp)) !== \false) {
             if ($line[0] !== "#") {
                 $entry = BanEntry::fromString($line);
                 if ($entry instanceof BanEntry) {
                     $this->list[$entry->getName()] = $entry;
                 }
             }
         }
         \fclose($fp);
     } else {
         MainLogger::getLogger()->error("Could not load ban list");
     }
 }