@Override public void updateName(String oldone, String newone) { PlayerAuth auth = this.getAuth(oldone); auth.setName(newone); this.saveAuth(auth); this.removeAuth(oldone); }
public void process() { preLogout(); if (!canLogout) return; final Player p = player; BukkitScheduler sched = p.getServer().getScheduler(); PlayerAuth auth = PlayerCache.getInstance().getAuth(name); database.updateSession(auth); auth.setQuitLocX(p.getLocation().getX()); auth.setQuitLocY(p.getLocation().getY()); auth.setQuitLocZ(p.getLocation().getZ()); auth.setWorld(p.getWorld().getName()); database.updateQuitLoc(auth); PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { Utils.teleportToSpawn(p); } }); if (LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().addLimboPlayer(player); Utils.setGroup(player, GroupType.NOTLOGGEDIN); sched.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin)); }
@Override public boolean equals(Object obj) { if (!(obj instanceof PlayerAuth)) { return false; } PlayerAuth other = (PlayerAuth) obj; return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname); }
@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; }
/** * 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()); }
@Override public int purgeDatabase(long until) { int cleared = source.purgeDatabase(until); if (cleared > 0) { for (PlayerAuth auth : cache.values()) { if (auth.getLastLogin() < until) { cache.remove(auth.getNickname()); } } } return cleared; }
@Override public List<String> autoPurgeDatabase(long until) { List<String> cleared = source.autoPurgeDatabase(until); if (cleared.size() > 0) { for (PlayerAuth auth : cache.values()) { if (auth.getLastLogin() < until) { cache.remove(auth.getNickname()); } } } return cleared; }
public void process() { preLogout(); if (!canLogout) return; final Player p = player; BukkitScheduler sched = p.getServer().getScheduler(); PlayerAuth auth = PlayerCache.getInstance().getAuth(name); database.updateSession(auth); auth.setQuitLocX(p.getLocation().getX()); auth.setQuitLocY(p.getLocation().getY()); auth.setQuitLocZ(p.getLocation().getZ()); auth.setWorld(p.getWorld().getName()); database.updateQuitLoc(auth); PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { Location spawnLoc = plugin.getSpawnLocation(p); final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(p, spawnLoc); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (tpEvent.getTo() != null) p.teleport(tpEvent.getTo()); } } }); } if (LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().addLimboPlayer(player); utils.setGroup(player, GroupType.NOTLOGGEDIN); if (Settings.protectInventoryBeforeLogInEnabled) { player.getInventory().clear(); // create cache file for handling lost of inventories on unlogged in // status DataFileCache playerData = new DataFileCache( LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour()); playerBackup.createCache(player, playerData); } sched.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin)); }
@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; }
private void emailRegister() throws Exception { if (Settings.getmaxRegPerEmail > 0 && !plugin .getPermissionsManager() .hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS) && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; } final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); final String salt = PasswordSecurity.userSalt.get(name); PlayerAuth auth = PlayerAuth.builder() .name(name) .realName(player.getName()) .hash(hashNew) .ip(ip) .locWorld(player.getLocation().getWorld().getName()) .locX(player.getLocation().getX()) .locY(player.getLocation().getY()) .locZ(player.getLocation().getZ()) .email(email) .salt(salt != null ? salt : "") .build(); if (!database.saveAuth(auth)) { m.send(player, MessageKey.ERROR); return; } database.updateEmail(auth); database.updateSession(auth); plugin.mail.main(auth, password); ProcessSyncEmailRegister sync = new ProcessSyncEmailRegister(player, plugin); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, sync); }
@Override public List<String> getAllAuthsByName(PlayerAuth auth) { BufferedReader br = null; List<String> countIp = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args.length > 3 && args[2].equals(auth.getIp())) { countIp.add(args[0]); } } return countIp; } catch (FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } catch (IOException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { if (br != null) { try { br.close(); } catch (IOException ex) { } } } }
private void passwordRegister() throws Exception { final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); final String salt = PasswordSecurity.userSalt.get(name); PlayerAuth auth = PlayerAuth.builder() .name(name) .realName(player.getName()) .hash(hashNew) .ip(ip) .locWorld(player.getLocation().getWorld().getName()) .locX(player.getLocation().getX()) .locY(player.getLocation().getY()) .locZ(player.getLocation().getZ()) .salt(salt != null ? salt : "") .build(); if (!database.saveAuth(auth)) { m.send(player, MessageKey.ERROR); return; } if (!Settings.forceRegLogin) { PlayerCache.getInstance().addPlayer(auth); database.setLogged(name); } plugin.otherAccounts.addPlayer(player.getUniqueId()); ProcessSyncronousPasswordRegister sync = new ProcessSyncronousPasswordRegister(player, plugin); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, sync); }
@Override public boolean updateEmail(final PlayerAuth auth) { boolean result = source.updateEmail(auth); if (result) { cachedAuths.refresh(auth.getNickname()); } return result; }
@Override public boolean saveAuth(PlayerAuth auth) { boolean result = source.saveAuth(auth); if (result) { cachedAuths.refresh(auth.getNickname()); } return result; }
@Override public synchronized boolean updatePassword(final PlayerAuth auth) { if (!cache.containsKey(auth.getNickname())) { return false; } final String oldHash = cache.get(auth.getNickname()).getHash(); cache.get(auth.getNickname()).setHash(auth.getHash()); exec.execute( new Runnable() { @Override public void run() { if (!source.updatePassword(auth)) { if (cache.containsKey(auth.getNickname())) { cache.get(auth.getNickname()).setHash(oldHash); } } } }); return true; }
@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; }
@Override public synchronized boolean saveAuth(final PlayerAuth auth) { cache.put(auth.getNickname(), auth); exec.execute( new Runnable() { @Override public void run() { if (!source.saveAuth(auth)) { cache.remove(auth.getNickname()); } } }); return true; }
@Override public synchronized boolean updateSalt(final PlayerAuth auth) { if (!cache.containsKey(auth.getNickname())) { return false; } PlayerAuth cachedAuth = cache.get(auth.getNickname()); final String oldSalt = cachedAuth.getSalt(); cachedAuth.setSalt(auth.getSalt()); exec.execute( new Runnable() { @Override public void run() { if (!source.updateSalt(auth)) { if (cache.containsKey(auth.getNickname())) { cache.get(auth.getNickname()).setSalt(oldSalt); } } } }); return true; }
@Override public boolean updateSession(final PlayerAuth auth) { if (!cache.containsKey(auth.getNickname())) { return false; } PlayerAuth cachedAuth = cache.get(auth.getNickname()); final String oldIp = cachedAuth.getIp(); final long oldLastLogin = cachedAuth.getLastLogin(); final String oldRealName = cachedAuth.getRealName(); cachedAuth.setIp(auth.getIp()); cachedAuth.setLastLogin(auth.getLastLogin()); cachedAuth.setRealName(auth.getRealName()); exec.execute( new Runnable() { @Override public void run() { if (!source.updateSession(auth)) { if (cache.containsKey(auth.getNickname())) { PlayerAuth cachedAuth = cache.get(auth.getNickname()); cachedAuth.setIp(oldIp); cachedAuth.setLastLogin(oldLastLogin); cachedAuth.setRealName(oldRealName); } } } }); return true; }
public void addPlayer(PlayerAuth auth) { cache.put(auth.getNickname().toLowerCase(), auth); }
public void updatePlayer(PlayerAuth auth) { cache.remove(auth.getNickname().toLowerCase()); cache.put(auth.getNickname().toLowerCase(), auth); }
@Override public boolean updateQuitLoc(final PlayerAuth auth) { if (!cache.containsKey(auth.getNickname())) { return false; } final PlayerAuth cachedAuth = cache.get(auth.getNickname()); final double oldX = cachedAuth.getQuitLocX(); final double oldY = cachedAuth.getQuitLocY(); final double oldZ = cachedAuth.getQuitLocZ(); final String oldWorld = cachedAuth.getWorld(); cachedAuth.setQuitLocX(auth.getQuitLocX()); cachedAuth.setQuitLocY(auth.getQuitLocY()); cachedAuth.setQuitLocZ(auth.getQuitLocZ()); cachedAuth.setWorld(auth.getWorld()); exec.execute( new Runnable() { @Override public void run() { if (!source.updateQuitLoc(auth)) { if (cache.containsKey(auth.getNickname())) { PlayerAuth cachedAuth = cache.get(auth.getNickname()); cachedAuth.setQuitLocX(oldX); cachedAuth.setQuitLocY(oldY); cachedAuth.setQuitLocZ(oldZ); cachedAuth.setWorld(oldWorld); } } } }); 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; }
public void process() { if (AuthMePlayerListener.gameMode.containsKey(name)) AuthMePlayerListener.gameMode.remove(name); AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode()); BukkitScheduler sched = plugin.getServer().getScheduler(); if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { return; } if (plugin.ess != null && Settings.disableSocialSpy) { plugin.ess.getUser(player).setSocialSpyEnabled(false); } if (!plugin.canConnect()) { final GameMode gM = AuthMePlayerListener.gameMode.get(name); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true); player.setGameMode(gM); player.kickPlayer("Server is loading, please wait before joining!"); } }); return; } final String ip = plugin.getIP(player); if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) { final GameMode gM = AuthMePlayerListener.gameMode.get(name); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true); player.setGameMode(gM); player.kickPlayer("You are not the Owner of this account, please try another name!"); if (Settings.banUnsafeIp) plugin.getServer().banIP(ip); } }); return; } if (Settings.getMaxJoinPerIp > 0 && !plugin.authmePermissible(player, "authme.allow2accounts") && !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost")) { if (plugin.hasJoinedIp(player.getName(), ip)) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { player.kickPlayer("A player with the same IP is already in game!"); } }); return; } } final Location spawnLoc = plugin.getSpawnLocation(player); final boolean isAuthAvailable = database.isAuthAvailable(name); if (isAuthAvailable) { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true); Utils.forceGM(player); } }); } if (!Settings.noTeleport) if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (player.isOnline() && tpEvent.getTo() != null) { if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo()); } } } }); } placePlayerSafely(player, spawnLoc); LimboCache.getInstance().updateLimboPlayer(player); // protect inventory if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { ProtectInventoryEvent ev = new ProtectInventoryEvent(player); plugin.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { plugin.inventoryProtector.sendInventoryPacket(player); if (!Settings.noConsoleSpam) ConsoleLogger.info( "ProtectInventoryEvent has been cancelled for " + player.getName() + " ..."); } } } else { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true); Utils.forceGM(player); } }); } if (!Settings.unRegisteredGroup.isEmpty()) { Utils.setGroup(player, Utils.GroupType.UNREGISTERED); } if (!Settings.isForcedRegistrationEnabled) { return; } if (!Settings.noTeleport) if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (player.isOnline() && tpEvent.getTo() != null) { if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo()); } } } }); } } String[] msg; if (Settings.emailRegistration) { msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_email_msg"); } else { msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_msg"); } int time = Settings.getRegistrationTimeout * 20; int msgInterval = Settings.getWarnMessageInterval; if (time != 0) { BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time); if (!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } if (!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); if (isAuthAvailable) { Utils.setGroup(player, GroupType.NOTLOGGEDIN); } else { Utils.setGroup(player, GroupType.UNREGISTERED); } sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { if (player.isOp()) player.setOp(false); if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(true); player.setFlying(true); } player.setNoDamageTicks(Settings.getRegistrationTimeout * 20); if (Settings.useEssentialsMotd) player.performCommand("motd"); if (Settings.applyBlindEffect) player.addPotionEffect( new PotionEffect( PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { player.setWalkSpeed(0.0f); player.setFlySpeed(0.0f); } } }); if (Settings.isSessionsEnabled && isAuthAvailable && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) { if (plugin.sessions.containsKey(name)) plugin.sessions.get(name).cancel(); plugin.sessions.remove(name); PlayerAuth auth = database.getAuth(name); if (auth != null && auth.getIp().equals(ip)) { m.send(player, "valid_session"); PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); plugin.management.performLogin(player, "dontneed", true); } else if (Settings.sessionExpireOnIpChange) { PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); m.send(player, "invalid_session"); } return; } BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); }
@Override public boolean updateSession(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].equalsIgnoreCase(auth.getNickname())) { switch (args.length) { case 4: { newAuth = new PlayerAuth( args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "*****@*****.**", args[0]); break; } case 7: { newAuth = new PlayerAuth( args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "*****@*****.**", args[0]); break; } case 8: { newAuth = new PlayerAuth( args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "*****@*****.**", args[0]); break; } case 9: { newAuth = new PlayerAuth( args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); break; } default: { newAuth = new PlayerAuth( args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "*****@*****.**", args[0]); break; } } 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; }