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); }
public AsyncRegister( Player player, String password, String email, AuthMe plugin, DataSource data) { this.m = plugin.getMessages(); this.player = player; this.password = password; this.name = player.getName().toLowerCase(); this.email = email; this.plugin = plugin; this.database = data; this.ip = plugin.getIP(player); }
/** * 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?"); } }
private boolean needFirstspawn() { if (player.hasPlayedBefore()) return false; if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null) return false; FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent( player, player.getLocation(), Spawn.getInstance().getFirstSpawn()); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) { final Location fLoc = tpEvent.getTo(); Bukkit.getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { player.teleport(fLoc); } }); } } return true; }
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); }
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(); } }
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)); }
private boolean preRegisterCheck() throws Exception { String passLow = password.toLowerCase(); if (PlayerCache.getInstance().isAuthenticated(name)) { m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return false; } else if (!Settings.isRegistrationEnabled) { m.send(player, MessageKey.REGISTRATION_DISABLED); return false; } else if (passLow.contains("delete") || passLow.contains("where") || passLow.contains("insert") || passLow.contains("modify") || passLow.contains("from") || passLow.contains("select") || passLow.contains(";") || passLow.contains("null") || !passLow.matches(Settings.getPassRegex)) { m.send(player, MessageKey.PASSWORD_MATCH_ERROR); return false; } else if (passLow.equalsIgnoreCase(player.getName())) { m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR); return false; } else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) { m.send(player, MessageKey.INVALID_PASSWORD_LENGTH); return false; } else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) { m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR); return false; } else if (database.isAuthAvailable(name)) { m.send(player, MessageKey.NAME_ALREADY_REGISTERED); return false; } else if (Settings.getmaxRegPerIp > 0 && !plugin .getPermissionsManager() .hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS) && !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost") && database.getAllAuthsByIp(ip).size() >= Settings.getmaxRegPerIp) { m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return false; } return true; }
@Override public boolean onCommand(CommandSender sender, Command cmnd, String label, final String[] args) { if (!(sender instanceof Player)) { return true; } final Player player = (Player) sender; if (args.length == 0) { m._(player, "usage_log"); return true; } if (!plugin.authmePermissible(player, "authme." + label.toLowerCase())) { m._(player, "no_perm"); return true; } plugin.management.performLogin(player, args[0], false); return true; }
public CacheDataSource(final AuthMe pl, DataSource src) { this.source = src; this.exec = Executors.newCachedThreadPool(); pl.setCanConnect(false); /* * We need to load all players in cache ... It will took more time to * load the server, but it will be much easier to check for an * isAuthAvailable ! */ exec.execute( new Runnable() { @Override public void run() { for (PlayerAuth auth : source.getAllAuths()) { cache.put(auth.getNickname().toLowerCase(), auth); } pl.setCanConnect(true); } }); }
public Management(DataSource database, AuthMe plugin) { this.database = database; this.plugin = plugin; this.pm = plugin.getServer().getPluginManager(); }
/** * 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); }
/** * 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)); }