@Override
 public synchronized List<String> getAllAuthsByEmail(String email) {
   List<String> result = new ArrayList<>();
   for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
     PlayerAuth p = stringPlayerAuthEntry.getValue();
     if (p.getEmail().equals(email)) result.add(p.getNickname());
   }
   return result;
 }
 @Override
 public synchronized boolean updateEmail(final PlayerAuth auth) {
   if (!cache.containsKey(auth.getNickname())) {
     return false;
   }
   PlayerAuth cachedAuth = cache.get(auth.getNickname());
   final String oldEmail = cachedAuth.getEmail();
   cachedAuth.setEmail(auth.getEmail());
   exec.execute(
       new Runnable() {
         @Override
         public void run() {
           if (!source.updateEmail(auth)) {
             if (cache.containsKey(auth.getNickname())) {
               cache.get(auth.getNickname()).setEmail(oldEmail);
             }
           }
         }
       });
   return true;
 }
 /**
  * Method set.
  *
  * @param auth PlayerAuth
  */
 public void set(PlayerAuth auth) {
   this.setEmail(auth.getEmail());
   this.setPassword(auth.getPassword());
   this.setIp(auth.getIp());
   this.setLastLogin(auth.getLastLogin());
   this.setNickname(auth.getNickname());
   this.setQuitLocX(auth.getQuitLocX());
   this.setQuitLocY(auth.getQuitLocY());
   this.setQuitLocZ(auth.getQuitLocZ());
   this.setWorld(auth.getWorld());
   this.setRealName(auth.getRealName());
 }
Esempio n. 4
0
 @Override
 public boolean updateEmail(PlayerAuth auth) {
   if (!isAuthAvailable(auth.getNickname())) {
     return false;
   }
   PlayerAuth newAuth = null;
   BufferedReader br = null;
   try {
     br = new BufferedReader(new FileReader(source));
     String line = "";
     while ((line = br.readLine()) != null) {
       String[] args = line.split(":");
       if (args[0].equals(auth.getNickname())) {
         newAuth =
             new PlayerAuth(
                 args[0],
                 args[1],
                 args[2],
                 Long.parseLong(args[3]),
                 Double.parseDouble(args[4]),
                 Double.parseDouble(args[5]),
                 Double.parseDouble(args[6]),
                 args[7],
                 auth.getEmail(),
                 args[0]);
         break;
       }
     }
   } catch (FileNotFoundException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return false;
   } catch (IOException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return false;
   } finally {
     if (br != null) {
       try {
         br.close();
       } catch (IOException ex) {
       }
     }
   }
   if (newAuth != null) {
     removeAuth(auth.getNickname());
     saveAuth(newAuth);
   }
   return true;
 }
Esempio n. 5
0
 @Override
 public synchronized boolean saveAuth(PlayerAuth auth) {
   if (isAuthAvailable(auth.getNickname())) {
     return false;
   }
   BufferedWriter bw = null;
   try {
     bw = new BufferedWriter(new FileWriter(source, true));
     bw.write(
         auth.getNickname()
             + ":"
             + auth.getHash()
             + ":"
             + auth.getIp()
             + ":"
             + auth.getLastLogin()
             + ":"
             + auth.getQuitLocX()
             + ":"
             + auth.getQuitLocY()
             + ":"
             + auth.getQuitLocZ()
             + ":"
             + auth.getWorld()
             + ":"
             + auth.getEmail()
             + "\n");
   } catch (IOException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return false;
   } finally {
     if (bw != null) {
       try {
         bw.close();
       } catch (IOException ex) {
       }
     }
   }
   return true;
 }
  /**
   * 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;
  }