/** * Unregister a player * * @param Player|OfflinePlayer $player * * @return int|boolean true on SUCCESS or false if the player is not registered, otherwise the current error */ public function unregisterPlayer($player) { if ($player instanceof Player || $player instanceof OfflinePlayer) { if ($this->isPlayerRegistered($player->getName())) { $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthUnregisterEvent($player)); if ($event->isCancelled()) { return ServerAuth::CANCELLED; } if ($this->getDataProvider()) { //Check MySQL connection if ($this->getDatabase() && $this->getDatabase()->ping()) { $query = "DELETE FROM " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata WHERE user='******'"; if ($this->getDatabase()->query($query)) { //Restore default messages ServerAuth::getAPI()->enableLoginMessages(true); ServerAuth::getAPI()->enableRegisterMessages(true); return ServerAuth::SUCCESS; } else { return ServerAuth::ERR_GENERIC; } } else { return ServerAuth::ERR_GENERIC; } } else { @unlink($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml")); //Restore default messages ServerAuth::getAPI()->enableLoginMessages(true); ServerAuth::getAPI()->enableRegisterMessages(true); return ServerAuth::SUCCESS; } } else { return ServerAuth::ERR_USER_NOT_REGISTERED; } } else { return -1; } }
/** * Change player password * * @param Player|OfflinePlayer $player * @param string $new_password * * @return int|boolean true on SUCCESS or false if the player is not registered, otherwise the current error */ public function changePlayerPassword($player, $new_password) { if ($player instanceof Player || $player instanceof OfflinePlayer) { $cfg = $this->getConfig()->getAll(); if ($this->isPlayerRegistered($player->getName())) { if (strlen($new_password) < $cfg["minPasswordLength"]) { return ServerAuth::ERR_PASSWORD_TOO_SHORT; } elseif (strlen($new_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\ServerAuthPasswordChangeEvent($player, $new_password)); if ($event->isCancelled()) { return ServerAuth::CANCELLED; } if ($this->getDataProvider()) { //Check MySQL connection if ($this->getDatabase() && $this->getDatabase()->ping()) { $stmt = $this->getDatabase()->prepare("UPDATE " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata SET password=? WHERE user=?"); $stmt_password = hash($this->getPasswordHash(), $new_password); $stmt_player = strtolower($player->getName()); $stmt->bind_param("ss", $stmt_password, $stmt_player); if ($stmt->execute()) { $stmt->close(); return ServerAuth::SUCCESS; } else { $stmt->close(); return ServerAuth::ERR_GENERIC; } } else { return ServerAuth::ERR_GENERIC; } } else { $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML); $data->set("password", hash($this->getPasswordHash(), $new_password)); $data->save(); return ServerAuth::SUCCESS; } } } else { return $this->isPlayerRegistered($player->getName()); } } else { return ServerAuth::ERR_USER_NOT_REGISTERED; } }