コード例 #1
0
 /**
  * Method run.
  *
  * @see java.lang.Runnable#run()
  */
 @Override
 public void run() {
   String fileName = Settings.crazyloginFileName;
   try {
     File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
     if (!source.exists()) {
       sender.sendMessage(
           "Error while trying to import datas, please put " + fileName + " in AuthMe folder!");
       return;
     }
     String line;
     BufferedReader users = new BufferedReader(new FileReader(source));
     while ((line = users.readLine()) != null) {
       if (line.contains("|")) {
         String[] args = line.split("\\|");
         if (args.length < 2) continue;
         if (args[0].equalsIgnoreCase("name")) continue;
         String playerName = args[0].toLowerCase();
         String psw = args[1];
         if (psw != null) {
           PlayerAuth auth =
               new PlayerAuth(
                   playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName);
           database.saveAuth(auth);
         }
       }
     }
     users.close();
     ConsoleLogger.info("CrazyLogin database has been imported correctly");
   } catch (IOException ex) {
     ConsoleLogger.showError(ex.getMessage());
     ConsoleLogger.showError("Can't open the crazylogin database file! Does it exist?");
   }
 }
コード例 #2
0
ファイル: FlatFile.java プロジェクト: Jaryn-R/AuthMeReloaded
 public FlatFile() {
   source = Settings.AUTH_FILE;
   try {
     source.createNewFile();
   } catch (IOException e) {
     ConsoleLogger.showError(e.getMessage());
     if (Settings.isStopEnabled) {
       ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN...");
       AuthMe.getInstance().getServer().shutdown();
     }
     if (!Settings.isStopEnabled) {
       AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
     }
     e.printStackTrace();
   }
 }
コード例 #3
0
  /**
   * Execute the command.
   *
   * @param sender The command sender.
   * @param commandReference The command reference.
   * @param commandArguments The command arguments.
   * @return True if the command was executed successfully, false otherwise.
   */
  @Override
  public boolean executeCommand(
      CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
    // AuthMe plugin instance
    final AuthMe plugin = AuthMe.getInstance();

    // Messages instance
    final Messages m = Messages.getInstance();

    // Get the parameter values
    String playerMail = commandArguments.get(0);

    // Make sure the current command executor is a player
    if (!(sender instanceof Player)) {
      return true;
    }

    // Get the player instance and name
    final Player player = (Player) sender;
    final String playerName = player.getName();

    // Command logic
    if (plugin.mail == null) {
      m.send(player, "error");
      return true;
    }
    if (plugin.database.isAuthAvailable(playerName)) {
      if (PlayerCache.getInstance().isAuthenticated(playerName)) {
        m.send(player, "logged_in");
        return true;
      }
      try {
        RandomString rand = new RandomString(Settings.getRecoveryPassLength);
        String thePass = rand.nextString();
        String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, playerName);
        PlayerAuth auth;
        if (PlayerCache.getInstance().isAuthenticated(playerName)) {
          auth = PlayerCache.getInstance().getAuth(playerName);
        } else if (plugin.database.isAuthAvailable(playerName)) {
          auth = plugin.database.getAuth(playerName);
        } else {
          m.send(player, "unknown_user");
          return true;
        }
        if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) {
          m.send(player, "error");
          return true;
        }

        if (!playerMail.equalsIgnoreCase(auth.getEmail())
            || playerMail.equalsIgnoreCase("*****@*****.**")
            || auth.getEmail().equalsIgnoreCase("*****@*****.**")) {
          m.send(player, "email_invalid");
          return true;
        }
        auth.setHash(hashNew);
        plugin.database.updatePassword(auth);
        plugin.mail.main(auth, thePass);
        m.send(player, "email_send");
      } catch (NoSuchAlgorithmException | NoClassDefFoundError ex) {
        ex.printStackTrace();
        ConsoleLogger.showError(ex.getMessage());
        m.send(sender, "error");
      }
    } else {
      m.send(player, "reg_email_msg");
    }

    return true;
  }
コード例 #4
0
ファイル: Messages.java プロジェクト: GODofART/AuthMeReloaded
    /**
     * Loads a file from the plugin jar and sets as default
     *
     * @param filename The filename to open
     */
    public final void loadDefaults(File file) {
        InputStream stream = AuthMe.getInstance().getResource(file.getName());
        if(stream == null) return;

        setDefaults(YamlConfiguration.loadConfiguration(stream));
    }