Esempio n. 1
0
 /**
  * Deauthenticate a player
  * 
  * @param Player $player
  * 
  * @return int|boolean true on SUCCESS, otherwise the current error
  */
 public function deauthenticatePlayer(Player $player)
 {
     if ($this->isPlayerRegistered($player->getName())) {
         if ($this->isPlayerAuthenticated($player)) {
             $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthDeauthenticateEvent($player));
             if ($event->isCancelled()) {
                 return ServerAuth::CANCELLED;
             }
             if ($this->getDataProvider()) {
                 //Check MySQL connection
                 if ($this->getDatabase() && $this->getDatabase()->ping()) {
                     $query = "UPDATE " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata SET ip='" . $player->getAddress() . "' WHERE user='******'";
                     //Restore default messages
                     ServerAuth::getAPI()->enableLoginMessages(true);
                     ServerAuth::getAPI()->enableRegisterMessages(true);
                     unset($this->auth_users[strtolower($player->getName())]);
                     if ($this->getDatabase()->query($query)) {
                         return ServerAuth::SUCCESS;
                     } else {
                         return ServerAuth::ERR_GENERIC;
                     }
                 } else {
                     return ServerAuth::ERR_GENERIC;
                 }
             } else {
                 $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                 $data->set("ip", $player->getAddress());
                 $data->save();
                 //Restore default messages
                 ServerAuth::getAPI()->enableLoginMessages(true);
                 ServerAuth::getAPI()->enableRegisterMessages(true);
                 unset($this->auth_users[strtolower($player->getName())]);
                 return ServerAuth::SUCCESS;
             }
         } else {
             return ServerAuth::ERR_USER_NOT_AUTHENTICATED;
         }
     } else {
         return $this->isPlayerRegistered($player->getName());
     }
 }
Esempio n. 2
0
 /**
  * Deauthenticate a player
  * 
  * @param Player $player
  * 
  * @return int|boolean true on SUCCESS, otherwise the current error
  */
 public function deauthenticatePlayer(Player $player)
 {
     if ($this->isPlayerAuthenticated($player)) {
         //Reset cancelled message
         $this->canc_message = $this->chlang["operation-cancelled"];
         $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthDeauthenticateEvent($player));
         if ($event->isCancelled()) {
             return ServerAuth::CANCELLED;
         }
         //Restore default messages
         ServerAuth::getAPI()->enableLoginMessages(true);
         ServerAuth::getAPI()->enableRegisterMessages(true);
         unset($this->auth_users[strtolower($player->getName())]);
         return ServerAuth::SUCCESS;
     } else {
         return ServerAuth::ERR_USER_NOT_AUTHENTICATED;
     }
 }