コード例 #1
1
 /**
  * When the player join
  * @param PlayerJoinEvent $event
  */
 public function onPlayerJoin(PlayerJoinEvent $event)
 {
     $player = $event->getPlayer();
     // If the user exist
     if (User::exist($player->getName())) {
         $user = User::get($player->getName());
         // Get the login timeout from the config
         $minutes = Config::get("config.loginProtection.loginTimeout");
         // If is not an integer, set default value and write an error in the logs
         if (!is_int($minutes)) {
             $minutes = 5;
             Config::getLogger()->error("The LoginProtection loginTimeout is not and integer and will be the default time (5 minutes)");
         }
         // Add $minutes to the last_disconnection time
         $maxTime = date('Y-m-d H:i:s', strtotime($user->last_disconnection . ' + ' . $minutes . ' minute'));
         $now = date('Y-m-d H:i:s');
         // If he is logged and the maxTime is < than the actual time, then logout him.
         if ($user->isLogged() && $maxTime < $now) {
             $user->logout();
         }
     }
     // If he is disconnected, tell him to log in
     if (isset($user) && !$user->isLogged()) {
         $player->sendMessage(TextFormat::GOLD . "Welcome, you need to login before playing");
     } else {
         if (isset($user) && $user->isLogged()) {
             $player->sendMessage(TextFormat::GREEN . "Welcome back {$user->username}");
         }
     }
 }
コード例 #2
0
ファイル: BACommand.php プロジェクト: Vavaballz/BallzAuth
 public function execute(CommandSender $sender, $command, array $args)
 {
     if (count($args) > 0) {
         if ($args[0] == "reload" && ($sender->isOp() || $sender->hasPermission("ballzauth.ba.reload"))) {
             if (isset($args[1])) {
                 if ($args[1] == "users") {
                     User::load();
                     $sender->sendMessage(TextFormat::GREEN . "The users where reloaded");
                     return true;
                 } elseif ($args[1] == "config") {
                     Config::load();
                     $sender->sendMessage(TextFormat::GREEN . "The config where reloaded");
                     return true;
                 }
             }
             $sender->sendMessage(TextFormat::GOLD . "Usage : /ba reload [config/users]");
             return true;
         } elseif ($args[0] == "help" && count($args) < 2) {
             $sender->sendMessage(TextFormat::GOLD . "------ Help ------");
             $sender->sendMessage(TextFormat::GOLD . "/ba reload : " . TextFormat::GRAY . "Reload the users or the config");
             return true;
         }
     }
     $sender->sendMessage(TextFormat::GREEN . "------" . TextFormat::GOLD . " BallzAuth " . TextFormat::GREEN . "------");
     $sender->sendMessage(TextFormat::GREEN . "  Created by Vavaballz");
     $sender->sendMessage(TextFormat::GREEN . "-----------------------");
     $sender->sendMessage(TextFormat::GOLD . "Type /ba help for command help");
     return true;
 }
コード例 #3
0
ファイル: BallzAuth.php プロジェクト: Vavaballz/BallzAuth
 /**
  * Loading the plugin
  * @return type
  */
 public function onLoad()
 {
     self::$logger = $this->getLogger();
     self::$logger->info("Loading ...");
     // Initialize the Config
     Config::init($this->getDataFolder(), self::$logger);
     // Registering the commands
     $this->getServer()->getCommandMap()->register("register", new RegisterCommand("register"));
     $this->getServer()->getCommandMap()->register("login", new LoginCommand("login"));
     $this->getServer()->getCommandMap()->register("ba", new BACommand("ba"));
     // Loading the users
     self::$logger->info("Loading users ...");
     if (!is_null(User::getAll())) {
         self::$logger->info("Users loaded !");
     } else {
         self::$logger->error("Users not loaded !");
     }
     self::$logger->info("Loaded !");
 }
コード例 #4
0
ファイル: Utils.php プロジェクト: Vavaballz/BallzAuth
 /**
  * To write the JSON Errors
  * (if any) into the logs
  * @return bool
  */
 public static function getJsonErrors()
 {
     switch (json_last_error()) {
         case JSON_ERROR_DEPTH:
             $error = 'Maximum stack depth exceeded';
             break;
         case JSON_ERROR_STATE_MISMATCH:
             $error = 'Underflow or the modes mismatch';
             break;
         case JSON_ERROR_CTRL_CHAR:
             $error = 'Unexpected control character found';
             break;
         case JSON_ERROR_SYNTAX:
             $error = 'Syntax error, malformed JSON';
             break;
         case JSON_ERROR_UTF8:
             $error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
             break;
     }
     if (isset($error)) {
         Config::getLogger()->error(TextFormat::DARK_RED . $error);
     }
     return isset($error) ? true : false;
 }
コード例 #5
0
ファイル: User.php プロジェクト: Vavaballz/BallzAuth
 /**
  * Save the users into the file
  * @return bool
  */
 public static function save()
 {
     file_put_contents(Config::getDataFolder() . "users.json", json_encode(self::$users, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     if (!Utils::getJsonErrors()) {
         Config::getLogger()->info("Users saved !");
     } else {
         Config::getLogger()->error("An error occured while saving users !");
     }
     return Utils::getJsonErrors();
 }
コード例 #6
0
ファイル: SaveUsers.php プロジェクト: Vavaballz/BallzAuth
 /**
  * Save the users on run
  * @param $currentTick
  */
 public function onRun($currentTick)
 {
     Config::getLogger()->info("Saving of all users ...");
     User::save();
 }