getLastPlayed() public method

public getLastPlayed ( )
Ejemplo n.º 1
0
 /**
  * Register a player to ServerAuth
  * 
  * @param Player $player
  * @param string $password
  * 
  * @return int|boolean true on SUCCESS, otherwise the current error
  */
 public function registerPlayer(Player $player, $password)
 {
     $cfg = $this->getConfig()->getAll();
     if ($this->isPlayerRegistered($player->getName())) {
         return ServerAuth::ERR_USER_ALREADY_REGISTERED;
     } else {
         if (strlen($password) <= $cfg["minPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_SHORT;
         } elseif (strlen($password) >= $cfg["maxPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_LONG;
         } else {
             $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthRegisterEvent($player, $password));
             if ($event->isCancelled()) {
                 return ServerAuth::CANCELLED;
             }
             if ($this->getDataProvider()) {
                 //Check MySQL connection
                 if ($this->getDatabase() && $this->getDatabase()->ping()) {
                     if ($cfg["register"]["enable-max-ip"]) {
                         if (\mysqli_num_rows($this->getDatabase()->query("SELECT user, password, ip, firstlogin, lastlogin FROM " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata WHERE ip='" . $player->getAddress() . "'")) + 1 <= $cfg["register"]["max-ip"]) {
                             $query = "INSERT INTO " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata (user, password, ip, firstlogin, lastlogin) VALUES ('" . $player->getName() . "', '" . hash($this->getPasswordHash(), $password) . "', '" . $player->getAddress() . "', '" . $player->getFirstPlayed() . "', '" . $player->getLastPlayed() . "')";
                             if ($this->getDatabase()->query($query)) {
                                 return ServerAuth::SUCCESS;
                             } else {
                                 return ServerAuth::ERR_GENERIC;
                             }
                         } else {
                             return ServerAuth::ERR_MAX_IP_REACHED;
                         }
                     } else {
                         $query = "INSERT INTO " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata (user, password, ip, firstlogin, lastlogin) VALUES ('" . $player->getName() . "', '" . hash($this->getPasswordHash(), $password) . "', '" . $player->getAddress() . "', '" . $player->getFirstPlayed() . "', '" . $player->getLastPlayed() . "')";
                         if ($this->getDatabase()->query($query)) {
                             return ServerAuth::SUCCESS;
                         } else {
                             return ServerAuth::ERR_GENERIC;
                         }
                     }
                 } else {
                     return ServerAuth::ERR_GENERIC;
                 }
             } else {
                 if ($cfg["register"]["enable-max-ip"]) {
                     if ($this->grep($this->getDataFolder() . "users/", $player->getAddress()) + 1 <= $cfg["register"]["max-ip"]) {
                         $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                         $data->set("password", hash($this->getPasswordHash(), $password));
                         $data->set("ip", $player->getAddress());
                         $data->set("firstlogin", $player->getFirstPlayed());
                         $data->set("lastlogin", $player->getLastPlayed());
                         $data->save();
                         return ServerAuth::SUCCESS;
                     } else {
                         return ServerAuth::ERR_MAX_IP_REACHED;
                     }
                 } else {
                     $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                     $data->set("password", hash($this->getPasswordHash(), $password));
                     $data->set("ip", $player->getAddress());
                     $data->set("firstlogin", $player->getFirstPlayed());
                     $data->set("lastlogin", $player->getLastPlayed());
                     $data->save();
                     return ServerAuth::SUCCESS;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Register a player to ServerAuth
  * 
  * @param Player $player
  * @param string $password
  * 
  * @return int|boolean true on SUCCESS, otherwise the current error
  */
 public function registerPlayer(Player $player, $password)
 {
     $cfg = $this->getConfig()->getAll();
     if ($this->isPlayerRegistered($player->getName())) {
         return ServerAuth::ERR_USER_ALREADY_REGISTERED;
     } else {
         if (strlen($password) <= $cfg["minPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_SHORT;
         } elseif (strlen($password) >= $cfg["maxPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_LONG;
         } else {
             //Reset cancelled message
             $this->canc_message = $this->chlang["operation-cancelled"];
             $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthRegisterEvent($player, $password));
             if ($event->isCancelled()) {
                 return ServerAuth::CANCELLED;
             }
             if ($this->getDataProvider()) {
                 //Check MySQL connection
                 if ($this->getDatabase() && $this->getDatabase()->ping()) {
                     if ($cfg["register"]["enable-max-ip"]) {
                         $stmt = $this->getDatabase()->prepare("SELECT user, password, ip, firstlogin, lastlogin FROM " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata WHERE ip=?");
                         $stmt_address = $player->getAddress();
                         $stmt->bind_param("s", $stmt_address);
                         $stmt->execute();
                         $stmt->store_result();
                         if ($stmt->num_rows + 1 <= $cfg["register"]["max-ip"]) {
                             $stmt = $this->getDatabase()->prepare("INSERT INTO " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata (user, password, ip, firstlogin, lastlogin) VALUES (?, ?, ?, ?, ?)");
                             $stmt_player = $player->getName();
                             $stmt_password = hash($this->getPasswordHash(), $password);
                             $stmt_address = $player->getAddress();
                             $stmt_firstlogin = $player->getFirstPlayed();
                             $stmt_lastlogin = $player->getLastPlayed();
                             $stmt->bind_param("sssss", $stmt_player, $stmt_password, $stmt_address, $stmt_firstlogin, $stmt_lastlogin);
                             if ($stmt->execute()) {
                                 //Set User in cached array
                                 if (!isset($this->cached_registered_users[strtolower($player->getName())])) {
                                     $this->cached_registered_users[strtolower($player->getName())] = "";
                                 }
                                 $stmt->close();
                                 return ServerAuth::SUCCESS;
                             } else {
                                 $stmt->close();
                                 return ServerAuth::ERR_GENERIC;
                             }
                         } else {
                             return ServerAuth::ERR_MAX_IP_REACHED;
                         }
                     } else {
                         $stmt = $this->getDatabase()->prepare("INSERT INTO " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata (user, password, ip, firstlogin, lastlogin) VALUES (?, ?, ?, ?, ?)");
                         $stmt_player = $player->getName();
                         $stmt_password = hash($this->getPasswordHash(), $password);
                         $stmt_address = $player->getAddress();
                         $stmt_firstlogin = $player->getFirstPlayed();
                         $stmt_lastlogin = $player->getLastPlayed();
                         $stmt->bind_param("sssss", $stmt_player, $stmt_password, $stmt_address, $stmt_firstlogin, $stmt_lastlogin);
                         if ($stmt->execute()) {
                             //Set User in cached array
                             if (!isset($this->cached_registered_users[strtolower($player->getName())])) {
                                 $this->cached_registered_users[strtolower($player->getName())] = "";
                             }
                             $stmt->close();
                             return ServerAuth::SUCCESS;
                         } else {
                             $stmt->close();
                             return ServerAuth::ERR_GENERIC;
                         }
                     }
                 } else {
                     return ServerAuth::ERR_GENERIC;
                 }
             } else {
                 if ($cfg["register"]["enable-max-ip"]) {
                     if ($this->grep($this->getDataFolder() . "users/", $player->getAddress()) + 1 <= $cfg["register"]["max-ip"]) {
                         $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                         $data->set("password", hash($this->getPasswordHash(), $password));
                         $data->set("ip", $player->getAddress());
                         $data->set("firstlogin", $player->getFirstPlayed());
                         $data->set("lastlogin", $player->getLastPlayed());
                         $data->save();
                         //Set User in cached array
                         if (!isset($this->cached_registered_users[strtolower($player->getName())])) {
                             $this->cached_registered_users[strtolower($player->getName())] = "";
                         }
                         return ServerAuth::SUCCESS;
                     } else {
                         return ServerAuth::ERR_MAX_IP_REACHED;
                     }
                 } else {
                     $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                     $data->set("password", hash($this->getPasswordHash(), $password));
                     $data->set("ip", $player->getAddress());
                     $data->set("firstlogin", $player->getFirstPlayed());
                     $data->set("lastlogin", $player->getLastPlayed());
                     $data->save();
                     //Set User in cached array
                     if (!isset($this->cached_registered_users[strtolower($player->getName())])) {
                         $this->cached_registered_users[strtolower($player->getName())] = "";
                     }
                     return ServerAuth::SUCCESS;
                 }
             }
         }
     }
 }