diff --git a/pom.xml b/pom.xml index 4c2035541..c2719d4dc 100644 --- a/pom.xml +++ b/pom.xml @@ -28,12 +28,12 @@ - 2.8b1 + 2.9 org.bukkit bukkit - 1.6.2-R0.1-SNAPSHOT + 1.6.2-R0.1 net.milkbowl.vault diff --git a/src/main/java/uk/org/whoami/authme/AuthMe.java b/src/main/java/uk/org/whoami/authme/AuthMe.java index ebda851c3..7fbcb1323 100644 --- a/src/main/java/uk/org/whoami/authme/AuthMe.java +++ b/src/main/java/uk/org/whoami/authme/AuthMe.java @@ -65,6 +65,9 @@ import uk.org.whoami.authme.plugin.manager.EssSpawn; import uk.org.whoami.authme.settings.Messages; import uk.org.whoami.authme.settings.PlayersLogs; import uk.org.whoami.authme.settings.Settings; +import uk.org.whoami.authme.threads.FlatFileThread; +import uk.org.whoami.authme.threads.MySQLThread; +import uk.org.whoami.authme.threads.SQLiteThread; import me.muizers.Notifications.Notifications; import net.citizensnpcs.Citizens; @@ -108,6 +111,7 @@ public class AuthMe extends JavaPlugin { public List premium = new ArrayList(); public MultiverseCore mv = null; public Location essentialsSpawn; + public Thread databaseThread = null; @Override public void onEnable() { @@ -169,6 +173,13 @@ public class AuthMe extends JavaPlugin { */ switch (Settings.getDataSource) { case FILE: + if (Settings.useMultiThreading) { + FlatFileThread fileThread = new FlatFileThread(); + fileThread.run(); + database = fileThread; + databaseThread = fileThread; + break; + } try { database = new FileDataSource(); } catch (IOException ex) { @@ -183,6 +194,13 @@ public class AuthMe extends JavaPlugin { } break; case MYSQL: + if (Settings.useMultiThreading) { + MySQLThread sqlThread = new MySQLThread(); + sqlThread.run(); + database = sqlThread; + databaseThread = sqlThread; + break; + } try { database = new MySQLDataSource(); } catch (ClassNotFoundException ex) { @@ -215,6 +233,13 @@ public class AuthMe extends JavaPlugin { } break; case SQLITE: + if (Settings.useMultiThreading) { + SQLiteThread sqliteThread = new SQLiteThread(); + sqliteThread.run(); + database = sqliteThread; + databaseThread = sqliteThread; + break; + } try { database = new SqliteDataSource(); } catch (ClassNotFoundException ex) { @@ -285,7 +310,7 @@ public class AuthMe extends JavaPlugin { this.getCommand("changepassword").setExecutor(new ChangePasswordCommand(database, this)); this.getCommand("logout").setExecutor(new LogoutCommand(this,database)); this.getCommand("unregister").setExecutor(new UnregisterCommand(this, database)); - this.getCommand("passpartu").setExecutor(new PasspartuCommand(database, this)); + this.getCommand("passpartu").setExecutor(new PasspartuCommand(this)); this.getCommand("email").setExecutor(new EmailCommand(this, database)); this.getCommand("captcha").setExecutor(new CaptchaCommand(this)); @@ -428,6 +453,10 @@ public class AuthMe extends JavaPlugin { if (database != null) { database.close(); } + + if (databaseThread != null) { + databaseThread.interrupt(); + } if(Settings.isBackupActivated && Settings.isBackupOnStop) { Boolean Backup = new PerformBackup(this).DoBackup(); diff --git a/src/main/java/uk/org/whoami/authme/Utils.java b/src/main/java/uk/org/whoami/authme/Utils.java index 500c92178..b1ea1d71a 100644 --- a/src/main/java/uk/org/whoami/authme/Utils.java +++ b/src/main/java/uk/org/whoami/authme/Utils.java @@ -1,7 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package uk.org.whoami.authme; import java.io.File; diff --git a/src/main/java/uk/org/whoami/authme/api/API.java b/src/main/java/uk/org/whoami/authme/api/API.java index 0521882e6..babd08481 100644 --- a/src/main/java/uk/org/whoami/authme/api/API.java +++ b/src/main/java/uk/org/whoami/authme/api/API.java @@ -1,6 +1,7 @@ package uk.org.whoami.authme.api; import java.lang.reflect.Array; +import java.security.NoSuchAlgorithmException; import java.util.List; import org.bukkit.Bukkit; @@ -15,17 +16,18 @@ import uk.org.whoami.authme.cache.auth.PlayerAuth; import uk.org.whoami.authme.cache.auth.PlayerCache; import uk.org.whoami.authme.datasource.DataSource; import uk.org.whoami.authme.datasource.DataSource.DataSourceType; +import uk.org.whoami.authme.security.PasswordSecurity; import uk.org.whoami.authme.security.PasswordSecurity.HashAlgorithm; import uk.org.whoami.authme.settings.Settings; public class API { - public AuthMe instance; - public DataSource database; + public static AuthMe instance; + public static DataSource database; public API(AuthMe instance, DataSource database) { - this.instance = instance; - this.database = database; + API.instance = instance; + API.database = database; } /** * Hook into AuthMe @@ -173,15 +175,6 @@ public class API { } catch (NullPointerException npe) { } } - - public void saveAuth(final PlayerAuth auth) { - instance.getServer().getScheduler().runTask(instance, new Runnable() { - @Override - public void run() { - database.saveAuth(auth); - } - }); - } /** * @@ -189,10 +182,26 @@ public class API { * @return true if player is registered */ public static boolean isRegistered(String playerName) { - PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName); + String player = playerName.toLowerCase(); + PlayerAuth auth = database.getAuth(player); if (auth != null) return true; return false; } + + /** + * @param String playerName, String passwordToCheck + * @return true if the password is correct , false else + */ + public static boolean checkPassword(String playerName, String passwordToCheck) { + if (!isRegistered(playerName)) return false; + String player = playerName.toLowerCase(); + PlayerAuth auth = database.getAuth(player); + try { + return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), player); + } catch (NoSuchAlgorithmException e) { + return false; + } + } } diff --git a/src/main/java/uk/org/whoami/authme/commands/EmailCommand.java b/src/main/java/uk/org/whoami/authme/commands/EmailCommand.java index 3fbaa52a8..c312b8422 100644 --- a/src/main/java/uk/org/whoami/authme/commands/EmailCommand.java +++ b/src/main/java/uk/org/whoami/authme/commands/EmailCommand.java @@ -97,7 +97,7 @@ public class EmailCommand implements CommandExecutor { if (!data.isAuthAvailable(name)) { player.sendMessage(m._("login_msg")); } else { - player.sendMessage(m._("reg_msg")); + player.sendMessage(m._("reg_email_msg")); } } } else if(args[0].equalsIgnoreCase("change") && args.length == 3 ) { @@ -129,7 +129,7 @@ public class EmailCommand implements CommandExecutor { if (!data.isAuthAvailable(name)) { player.sendMessage(m._("login_msg")); } else { - player.sendMessage(m._("reg_msg")); + player.sendMessage(m._("reg_email_msg")); } } } @@ -189,7 +189,7 @@ public class EmailCommand implements CommandExecutor { sender.sendMessage(m._("error")); } } else { - player.sendMessage(m._("reg_msg")); + player.sendMessage(m._("reg_email_msg")); } } return true; diff --git a/src/main/java/uk/org/whoami/authme/commands/LoginCommand.java b/src/main/java/uk/org/whoami/authme/commands/LoginCommand.java index bf536d717..6fb714ea6 100644 --- a/src/main/java/uk/org/whoami/authme/commands/LoginCommand.java +++ b/src/main/java/uk/org/whoami/authme/commands/LoginCommand.java @@ -23,8 +23,6 @@ import org.bukkit.entity.Player; import uk.org.whoami.authme.AuthMe; import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.threads.LoginThread; public class LoginCommand implements CommandExecutor { @@ -52,12 +50,7 @@ public class LoginCommand implements CommandExecutor { player.sendMessage(m._("no_perm")); return true; } - if (Settings.useMultiThreading) { - plugin.management.performLogin(player, args[0], false); - } else { - Thread mThread = new LoginThread(plugin.database, plugin, player, args[0]); - mThread.run(); - } + plugin.management.performLogin(player, args[0], false); return true; } } diff --git a/src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java b/src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java index fc90e23a2..0ba331514 100644 --- a/src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java +++ b/src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java @@ -12,10 +12,7 @@ import org.bukkit.entity.Player; import uk.org.whoami.authme.AuthMe; import uk.org.whoami.authme.Utils; import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.threads.LoginThread; /** * @@ -23,12 +20,10 @@ import uk.org.whoami.authme.threads.LoginThread; */ public class PasspartuCommand implements CommandExecutor { private Utils utils = new Utils(); - private DataSource database; public AuthMe plugin; private Messages m; - public PasspartuCommand(DataSource database, AuthMe plugin) { - this.database = database; + public PasspartuCommand(AuthMe plugin) { this.plugin = plugin; } @@ -47,12 +42,7 @@ public class PasspartuCommand implements CommandExecutor { if ((sender instanceof Player) && args.length == 1) { if(utils.readToken(args[0])) { //bypass login! - if (Settings.useMultiThreading) { - Thread bypass = new LoginThread(database, false, plugin, (Player) sender, "dontneed"); - bypass.run(); - } else { - plugin.management.performLogin((Player) sender, "dontneed", true); - } + plugin.management.performLogin((Player) sender, "dontneed", true); return true; } sender.sendMessage("Time is expired or Token is Wrong!"); diff --git a/src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java b/src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java index a87477cde..c084f471c 100644 --- a/src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java +++ b/src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java @@ -48,7 +48,6 @@ import uk.org.whoami.authme.settings.Settings; import uk.org.whoami.authme.settings.Spawn; import uk.org.whoami.authme.task.MessageTask; import uk.org.whoami.authme.task.TimeoutTask; -import uk.org.whoami.authme.threads.RegisterThread; public class RegisterCommand implements CommandExecutor { @@ -87,217 +86,128 @@ public class RegisterCommand implements CommandExecutor { final String ip = ipA; - if (Settings.useMultiThreading) { - Thread register = new RegisterThread(plugin, database, player, ip, args); - register.run(); - return true; - } else { - if (PlayerCache.getInstance().isAuthenticated(name)) { - player.sendMessage(m._("logged_in")); - return true; - } + if (PlayerCache.getInstance().isAuthenticated(name)) { + player.sendMessage(m._("logged_in")); + return true; + } - if (!Settings.isRegistrationEnabled) { - player.sendMessage(m._("reg_disabled")); - return true; - } + if (!Settings.isRegistrationEnabled) { + player.sendMessage(m._("reg_disabled")); + return true; + } - if (database.isAuthAvailable(player.getName().toLowerCase())) { - player.sendMessage(m._("user_regged")); - if (pllog.getStringList("players").contains(player.getName())) { - pllog.getStringList("players").remove(player.getName()); - } - return true; + if (database.isAuthAvailable(player.getName().toLowerCase())) { + player.sendMessage(m._("user_regged")); + if (pllog.getStringList("players").contains(player.getName())) { + pllog.getStringList("players").remove(player.getName()); } + return true; + } - if(Settings.getmaxRegPerIp > 0 ){ - if(!plugin.authmePermissible(sender, "authme.allow2accounts") && database.getAllAuthsByIp(ipA).size() >= Settings.getmaxRegPerIp) { - player.sendMessage(m._("max_reg")); + if(Settings.getmaxRegPerIp > 0 ){ + if(!plugin.authmePermissible(sender, "authme.allow2accounts") && database.getAllAuthsByIp(ipA).size() >= Settings.getmaxRegPerIp) { + player.sendMessage(m._("max_reg")); + return true; + } + } + + if(Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { + if(args.length < 1 || !args[0].contains("@")) { + player.sendMessage(m._("reg_email_msg")); + return true; + } + if(Settings.doubleEmailCheck) { + if(args.length < 2) { + player.sendMessage(m._("reg_email_msg")); return true; - } - } - - if(Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { - if(!args[0].contains("@")) { - player.sendMessage(m._("usage_reg")); + } + if(!args[0].equals(args[1])) { + player.sendMessage(m._("reg_email_msg")); return true; - } - if(Settings.doubleEmailCheck) { - if(args.length < 2) { - player.sendMessage(m._("usage_reg")); - return true; - } - if(!args[0].equals(args[1])) { - player.sendMessage(m._("usage_reg")); - return true; - } - } - final String email = args[0]; - if(Settings.getmaxRegPerEmail > 0) { - if (!plugin.authmePermissible(sender, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { - player.sendMessage(m._("max_reg")); - return true; - } - } - RandomString rand = new RandomString(Settings.getRecoveryPassLength); - final String thePass = rand.nextString(); - if (!thePass.isEmpty()) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - if (PasswordSecurity.userSalt.containsKey(name)) { - try { - final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name); - final PlayerAuth fAuth = new PlayerAuth(name, hashnew, PasswordSecurity.userSalt.get(name), ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email); - database.saveAuth(fAuth); - database.updateEmail(fAuth); - database.updateSession(fAuth); - plugin.mail.main(fAuth, thePass); - } catch (NoSuchAlgorithmException e) { - ConsoleLogger.showError(e.getMessage()); - } - } else { - try { - final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name); - final PlayerAuth fAuth = new PlayerAuth(name, hashnew, ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email); - database.saveAuth(fAuth); - database.updateEmail(fAuth); - database.updateSession(fAuth); - plugin.mail.main(fAuth, thePass); - } catch (NoSuchAlgorithmException e) { - ConsoleLogger.showError(e.getMessage()); - } - } - } - }); - - if(!Settings.getRegisteredGroup.isEmpty()){ - Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED); - } - player.sendMessage(m._("vb_nonActiv")); - String msg = m._("login_msg"); - int time = Settings.getRegistrationTimeout * 20; - int msgInterval = Settings.getWarnMessageInterval; - if (time != 0) { - Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getTimeoutTaskId()); - BukkitTask id = Bukkit.getScheduler().runTaskLater(plugin, new TimeoutTask(plugin, name), time); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id.getTaskId()); - } - - Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId()); - BukkitTask nwMsg = Bukkit.getScheduler().runTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); - LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nwMsg.getTaskId()); - - LimboCache.getInstance().deleteLimboPlayer(name); - if (Settings.isTeleportToSpawnEnabled) { - World world = player.getWorld(); - Location loca = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - loca = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - loca = Spawn.getInstance().getLocation(); - RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); - plugin.getServer().getPluginManager().callEvent(tpEvent); - if(!tpEvent.isCancelled()) { - if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { - tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); - } - player.teleport(tpEvent.getTo()); - } - } - this.isFirstTimeJoin = true; - player.saveData(); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); - if(plugin.notifications != null) { - plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!")); - } - return true; - } - } - - if (args.length == 0 || (Settings.getEnablePasswordVerifier && args.length < 2) ) { - player.sendMessage(m._("usage_reg")); - return true; - } - - if(args[0].length() < Settings.getPasswordMinLen || args[0].length() > Settings.passwordMaxLength) { - player.sendMessage(m._("pass_len")); - return true; - } - try { - String hash; - if(Settings.getEnablePasswordVerifier) { - if (args[0].equals(args[1])) { - hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name); - } else { - player.sendMessage(m._("password_error")); - return true; - } - } else - hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name); - if (Settings.getMySQLColumnSalt.isEmpty()) - { - auth = new PlayerAuth(name, hash, ip, new Date().getTime()); - } else { - auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), ip, new Date().getTime()); - } - if (!database.saveAuth(auth)) { - player.sendMessage(m._("error")); - return true; - } - PlayerCache.getInstance().addPlayer(auth); - LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); - if (limbo != null) { - player.setGameMode(GameMode.getByValue(limbo.getGameMode())); - if (Settings.isTeleportToSpawnEnabled) { - World world = player.getWorld(); - Location loca = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - - } catch (ClassCastException cce) { - - } catch (NoClassDefFoundError ncdfe) { - - } - } - if (plugin.essentialsSpawn != null) { - loca = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - loca = Spawn.getInstance().getLocation(); - RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); - plugin.getServer().getPluginManager().callEvent(tpEvent); - if(!tpEvent.isCancelled()) { - if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { - tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); - } - player.teleport(tpEvent.getTo()); - } - } - sender.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); - sender.getServer().getScheduler().cancelTask(limbo.getMessageTaskId()); - LimboCache.getInstance().deleteLimboPlayer(name); - } + } + } + final String email = args[0]; + if(Settings.getmaxRegPerEmail > 0) { + if (!plugin.authmePermissible(sender, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { + player.sendMessage(m._("max_reg")); + return true; + } + } + RandomString rand = new RandomString(Settings.getRecoveryPassLength); + final String thePass = rand.nextString(); + if (!thePass.isEmpty()) { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + if (PasswordSecurity.userSalt.containsKey(name)) { + try { + final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name); + final PlayerAuth fAuth = new PlayerAuth(name, hashnew, PasswordSecurity.userSalt.get(name), ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email); + database.saveAuth(fAuth); + database.updateEmail(fAuth); + database.updateSession(fAuth); + plugin.mail.main(fAuth, thePass); + } catch (NoSuchAlgorithmException e) { + ConsoleLogger.showError(e.getMessage()); + } + } else { + try { + final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name); + final PlayerAuth fAuth = new PlayerAuth(name, hashnew, ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email); + database.saveAuth(fAuth); + database.updateEmail(fAuth); + database.updateSession(fAuth); + plugin.mail.main(fAuth, thePass); + } catch (NoSuchAlgorithmException e) { + ConsoleLogger.showError(e.getMessage()); + } + } + } + }); if(!Settings.getRegisteredGroup.isEmpty()){ Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED); } - player.sendMessage(m._("registered")); - if (!Settings.getmailAccount.isEmpty()) - player.sendMessage(m._("add_email")); + player.sendMessage(m._("vb_nonActiv")); + String msg = m._("login_msg"); + int time = Settings.getRegistrationTimeout * 20; + int msgInterval = Settings.getWarnMessageInterval; + if (time != 0) { + Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getTimeoutTaskId()); + BukkitTask id = Bukkit.getScheduler().runTaskLater(plugin, new TimeoutTask(plugin, name), time); + LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id.getTaskId()); + } + + Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId()); + BukkitTask nwMsg = Bukkit.getScheduler().runTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); + LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nwMsg.getTaskId()); + + LimboCache.getInstance().deleteLimboPlayer(name); + if (Settings.isTeleportToSpawnEnabled) { + World world = player.getWorld(); + Location loca = world.getSpawnLocation(); + if (plugin.mv != null) { + try { + loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); + } catch (NullPointerException npe) { + } catch (ClassCastException cce) { + } catch (NoClassDefFoundError ncdfe) { + } + } + if (plugin.essentialsSpawn != null) { + loca = plugin.essentialsSpawn; + } + if (Spawn.getInstance().getLocation() != null) + loca = Spawn.getInstance().getLocation(); + RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if(!tpEvent.isCancelled()) { + if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { + tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); + } + player.teleport(tpEvent.getTo()); + } + } this.isFirstTimeJoin = true; player.saveData(); if (!Settings.noConsoleSpam) @@ -305,11 +215,94 @@ public class RegisterCommand implements CommandExecutor { if(plugin.notifications != null) { plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!")); } - } catch (NoSuchAlgorithmException ex) { - ConsoleLogger.showError(ex.getMessage()); - sender.sendMessage(m._("error")); + return true; } } + + if (args.length == 0 || (Settings.getEnablePasswordVerifier && args.length < 2) ) { + player.sendMessage(m._("usage_reg")); + return true; + } + + if(args[0].length() < Settings.getPasswordMinLen || args[0].length() > Settings.passwordMaxLength) { + player.sendMessage(m._("pass_len")); + return true; + } + try { + String hash; + if(Settings.getEnablePasswordVerifier) { + if (args[0].equals(args[1])) { + hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name); + } else { + player.sendMessage(m._("password_error")); + return true; + } + } else + hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name); + if (Settings.getMySQLColumnSalt.isEmpty()) + { + auth = new PlayerAuth(name, hash, ip, new Date().getTime()); + } else { + auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), ip, new Date().getTime()); + } + if (!database.saveAuth(auth)) { + player.sendMessage(m._("error")); + return true; + } + PlayerCache.getInstance().addPlayer(auth); + LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); + if (limbo != null) { + player.setGameMode(GameMode.getByValue(limbo.getGameMode())); + if (Settings.isTeleportToSpawnEnabled) { + World world = player.getWorld(); + Location loca = world.getSpawnLocation(); + if (plugin.mv != null) { + try { + loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); + } catch (NullPointerException npe) { + + } catch (ClassCastException cce) { + + } catch (NoClassDefFoundError ncdfe) { + + } + } + if (plugin.essentialsSpawn != null) { + loca = plugin.essentialsSpawn; + } + if (Spawn.getInstance().getLocation() != null) + loca = Spawn.getInstance().getLocation(); + RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if(!tpEvent.isCancelled()) { + if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { + tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); + } + player.teleport(tpEvent.getTo()); + } + } + sender.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); + sender.getServer().getScheduler().cancelTask(limbo.getMessageTaskId()); + LimboCache.getInstance().deleteLimboPlayer(name); + } + + if(!Settings.getRegisteredGroup.isEmpty()){ + Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED); + } + player.sendMessage(m._("registered")); + if (!Settings.getmailAccount.isEmpty()) + player.sendMessage(m._("add_email")); + this.isFirstTimeJoin = true; + player.saveData(); + if (!Settings.noConsoleSpam) + ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); + if(plugin.notifications != null) { + plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!")); + } + } catch (NoSuchAlgorithmException ex) { + ConsoleLogger.showError(ex.getMessage()); + sender.sendMessage(m._("error")); + } return true; } } diff --git a/src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java b/src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java index 7d3fb5ea2..d0ed6d089 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java +++ b/src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java @@ -1,4 +1,4 @@ -// Copyright 2007-2011 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland +// Copyright 2007-2013 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland // www.source-code.biz, www.inventec.ch/chdh // // This module is multi-licensed and may be used under the terms @@ -37,7 +37,7 @@ public class MiniConnectionPoolManager { private ConnectionPoolDataSource dataSource; private int maxConnections; -private long timeoutMs = 70 * 1000L; +private long timeoutMs = 100 * 1000L; private PrintWriter logWriter; private Semaphore semaphore; private LinkedList recycledConnections; @@ -66,7 +66,7 @@ public static class TimeoutException extends RuntimeException { * the maximum number of connections. */ public MiniConnectionPoolManager (ConnectionPoolDataSource dataSource, int maxConnections) { - this(dataSource, maxConnections, 70); } + this(dataSource, maxConnections, 100); } /** * Constructs a MiniConnectionPoolManager object. diff --git a/src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java b/src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java index cd82d1123..c109b421e 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java +++ b/src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java @@ -88,7 +88,7 @@ public class MySQLDataSource implements DataSource { dataSource.setPort(Integer.parseInt(port)); dataSource.setUser(username); dataSource.setPassword(password); - conPool = new MiniConnectionPoolManager(dataSource, 10); + conPool = new MiniConnectionPoolManager(dataSource, 20); ConsoleLogger.info("Connection pool ready"); } diff --git a/src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java b/src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java index 0d81f3205..0f7aa99bb 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java +++ b/src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java @@ -21,10 +21,6 @@ import uk.org.whoami.authme.settings.Settings; @SuppressWarnings("unused") public class SqliteDataSource implements DataSource { - private String host; - private String port; - private String username; - private String password; private String database; private String tableName; private String columnName; @@ -33,7 +29,6 @@ public class SqliteDataSource implements DataSource { private String columnLastLogin; private String columnSalt; private String columnGroup; - private int nonActivatedGroup; private String lastlocX; private String lastlocY; private String lastlocZ; @@ -43,11 +38,7 @@ public class SqliteDataSource implements DataSource { private Connection con; public SqliteDataSource() throws ClassNotFoundException, SQLException { - this.host = Settings.getMySQLHost; - this.port = Settings.getMySQLPort; - this.username = Settings.getMySQLUsername; - this.password = Settings.getMySQLPassword; - this.database = Settings.getMySQLDatabase; + this.database = Settings.getMySQLDatabase; this.tableName = Settings.getMySQLTablename; this.columnName = Settings.getMySQLColumnName; this.columnPassword = Settings.getMySQLColumnPassword; @@ -59,7 +50,6 @@ public class SqliteDataSource implements DataSource { this.lastlocY = Settings.getMySQLlastlocY; this.lastlocZ = Settings.getMySQLlastlocZ; this.lastlocWorld = Settings.getMySQLlastlocWorld; - this.nonActivatedGroup = Settings.getNonActivatedGroup; this.columnEmail = Settings.getMySQLColumnEmail; this.columnID = Settings.getMySQLColumnId; diff --git a/src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java b/src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java index ca319d582..5215b698a 100644 --- a/src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java +++ b/src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java @@ -21,9 +21,7 @@ import org.getspout.spoutapi.player.SpoutPlayer; import uk.org.whoami.authme.AuthMe; import uk.org.whoami.authme.gui.Clickable; import uk.org.whoami.authme.gui.CustomButton; -import uk.org.whoami.authme.settings.Settings; import uk.org.whoami.authme.settings.SpoutCfg; -import uk.org.whoami.authme.threads.LoginThread; public class LoginScreen extends GenericPopup implements Clickable{ @@ -121,12 +119,7 @@ public class LoginScreen extends GenericPopup implements Clickable{ if (event.isCancelled() || event == null || event.getPlayer() == null) return; if (b.equals(loginBtn)) { - if (Settings.useMultiThreading) { - Thread mT = new LoginThread(plugin.database, plugin, player, passBox.getText()); - mT.run(); - } else { - plugin.management.performLogin(player, passBox.getText(), false); - } + plugin.management.performLogin(player, passBox.getText(), false); }else if(b.equals(exitBtn)) { event.getPlayer().kickPlayer(exitMsg); diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java b/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java index ff8833623..bcf30427e 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java @@ -28,6 +28,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -162,7 +163,11 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) { return; } - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } else { Bukkit.getScheduler().runTask(plugin, new Runnable() @@ -173,7 +178,11 @@ public class AuthMePlayerListener implements Listener { player.sendMessage(m._("login_msg")); } else { if (Settings.isForcedRegistrationEnabled) { - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } }}); @@ -211,7 +220,11 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) { return; } - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } else { Bukkit.getScheduler().runTask(plugin, new Runnable() @@ -222,7 +235,11 @@ public class AuthMePlayerListener implements Listener { player.sendMessage(m._("login_msg")); } else { if (Settings.isForcedRegistrationEnabled) { - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } }}); @@ -261,7 +278,11 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) { return; } - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } else { Bukkit.getScheduler().runTask(plugin, new Runnable() @@ -272,7 +293,11 @@ public class AuthMePlayerListener implements Listener { player.sendMessage(m._("login_msg")); } else { if (Settings.isForcedRegistrationEnabled) { - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } }}); @@ -310,7 +335,11 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) { return; } - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } else { Bukkit.getScheduler().runTask(plugin, new Runnable() @@ -321,7 +350,11 @@ public class AuthMePlayerListener implements Listener { player.sendMessage(m._("login_msg")); } else { if (Settings.isForcedRegistrationEnabled) { - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } }}); @@ -359,7 +392,11 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) { return; } - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } else { Bukkit.getScheduler().runTask(plugin, new Runnable() @@ -370,7 +407,11 @@ public class AuthMePlayerListener implements Listener { player.sendMessage(m._("login_msg")); } else { if (Settings.isForcedRegistrationEnabled) { - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } }}); @@ -408,7 +449,11 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) { return; } - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } else { Bukkit.getScheduler().runTask(plugin, new Runnable() @@ -419,7 +464,11 @@ public class AuthMePlayerListener implements Listener { player.sendMessage(m._("login_msg")); } else { if (Settings.isForcedRegistrationEnabled) { - player.sendMessage(m._("reg_msg")); + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } } } }}); @@ -576,22 +625,27 @@ public class AuthMePlayerListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerLowestJoin(PlayerJoinEvent event) { - if (event.getPlayer() == null) return; - Player player = event.getPlayer(); + if (event.getPlayer() == null) return; + final Player player = event.getPlayer(); if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } if (Settings.bungee) { - ByteArrayOutputStream b = new ByteArrayOutputStream(); + final ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try { out.writeUTF("IP"); } catch (IOException e) { } - player.sendPluginMessage(this.plugin, "BungeeCord", b.toByteArray()); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray()); + } + }); } } @@ -705,8 +759,6 @@ public class AuthMePlayerListener implements Listener { } catch (NullPointerException ex) { } } - if(player.isOp()) - player.setOp(false); if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); @@ -717,7 +769,12 @@ public class AuthMePlayerListener implements Listener { player.teleport(tpEvent.getTo()); } } - String msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_msg"); + String msg = ""; + if(Settings.emailRegistration) { + msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_email_msg"); + } else { + msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_msg"); + } int time = Settings.getRegistrationTimeout * 20; int msgInterval = Settings.getWarnMessageInterval; if (time != 0) { @@ -728,16 +785,27 @@ public class AuthMePlayerListener implements Listener { } if(!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); + if(player.isOp()) + player.setOp(false); BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId()); if (Settings.isForceSurvivalModeEnabled) - sched.runTask(plugin, new Runnable() { + sched.scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { e.getPlayer().setGameMode(GameMode.SURVIVAL); } }); + placePlayerSafely(player, spawnLoc); } + private void placePlayerSafely(Player player, Location spawnLoc) { + Block b = player.getLocation().getBlock(); + if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) { + player.sendMessage(m._("unsafe_spawn")); + player.teleport(spawnLoc); + } + } + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { if (event.getPlayer() == null) { diff --git a/src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java b/src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java index 365eb5fa6..ae3bea3b3 100644 --- a/src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java +++ b/src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java @@ -1,5 +1,9 @@ package uk.org.whoami.authme.plugin.manager; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; + import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; @@ -17,8 +21,14 @@ public class BungeeCordMessage implements PluginMessageListener { @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { - ConsoleLogger.info("PluginMessage send to " + player.getName() + " , the message was : " + message.toString()); - plugin.realIp.put(player.getName().toLowerCase(), message.toString()); + try { + final DataInputStream in = new DataInputStream(new ByteArrayInputStream(message)); + if (in.readUTF().equals("IP")) { //We need only the IP channel + ConsoleLogger.info("PluginMessage send to " + player.getName() + " , the message was : " + message.toString()); + plugin.realIp.put(player.getName().toLowerCase(), in.readUTF()); //Put the IP (only the ip not the port) in the hashmap + } + } catch (IOException ex) { + } } } \ No newline at end of file diff --git a/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java b/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java index 08478fe63..bf48e5e12 100644 --- a/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java +++ b/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java @@ -58,6 +58,14 @@ public class PasswordSecurity { byte[] digest = sha256.digest(); return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); } + + private static String getSHA512(String message) throws NoSuchAlgorithmException { + MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); + sha512.reset(); + sha512.update(message.getBytes()); + byte[] digest = sha512.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } public static String getWhirlpool(String message) { Whirlpool w = new Whirlpool(); @@ -93,9 +101,8 @@ public class PasswordSecurity { private static String getBCrypt(String message, String salt) throws NoSuchAlgorithmException { return BCrypt.hashpw(message, salt); } - + private static String getWBB3(String message, String salt) throws NoSuchAlgorithmException { - return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(message))))); } @@ -215,6 +222,8 @@ public class PasswordSecurity { userSalt.put(name, saltwbb); } return getWBB3(password, saltwbb); + case SHA512: + return getSHA512(password); default: throw new NoSuchAlgorithmException("Unknown hash algorithm"); } @@ -262,17 +271,20 @@ public class PasswordSecurity { String saltj = hash.split(":")[1]; return hash.equals(getMD5(password + saltj) + ":" + saltj); } + if(Settings.getPasswordHash == HashAlgorithm.SHA512) { + return hash.equals(getSHA512(password)); + } // PlainText Password - if(hash.length() < 32 ) { + if(Settings.getPasswordHash == HashAlgorithm.PLAINTEXT) { return hash.equals(password); } - if (hash.length() == 32) { + if (Settings.getPasswordHash == HashAlgorithm.MD5) { return hash.equals(getMD5(password)); } - if (hash.length() == 40) { + if (Settings.getPasswordHash == HashAlgorithm.SHA1) { return hash.equals(getSHA1(password)); } - if (hash.length() == 140) { + if (Settings.getPasswordHash == HashAlgorithm.XAUTH) { int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); String salt = hash.substring(saltPos, saltPos + 12); return hash.equals(getXAuth(password, salt)); @@ -327,7 +339,7 @@ public class PasswordSecurity { public enum HashAlgorithm { MD5, SHA1, SHA256, WHIRLPOOL, XAUTH, MD5VB, PHPBB, PLAINTEXT, MYBB, IPB3, PHPFUSION, SMF, XFSHA1, - XFSHA256, SALTED2MD5, JOOMLA, BCRYPT, WBB3 + XFSHA256, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512 } } diff --git a/src/main/java/uk/org/whoami/authme/settings/Messages.java b/src/main/java/uk/org/whoami/authme/settings/Messages.java index db47a950b..cd4e106cd 100644 --- a/src/main/java/uk/org/whoami/authme/settings/Messages.java +++ b/src/main/java/uk/org/whoami/authme/settings/Messages.java @@ -42,6 +42,7 @@ public class Messages extends CustomConfiguration { this.set("valid_session", "&cSession login"); this.set("login_msg", "&cPlease login with \"/login password\""); this.set("reg_msg", "&cPlease register with \"/register password ConfirmPassword\""); + this.set("reg_email_msg", "&cPlease register with \"/register \""); this.set("timeout", "&fLogin Timeout"); this.set("wrong_pwd", "&cWrong password"); this.set("logout", "&cSuccessful logout"); diff --git a/src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java b/src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java index 7b6197c60..55a0d4b38 100644 --- a/src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java +++ b/src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java @@ -30,7 +30,7 @@ public class SpoutCfg extends CustomConfiguration{ add("Sample text"); add("Change this at spout.yml"); add("--- AuthMe Reloaded by ---"); - add("d4rkwarriors and Xephi59"); + add("Xephi59"); }}); } diff --git a/src/main/java/uk/org/whoami/authme/threads/FlatFileThread.java b/src/main/java/uk/org/whoami/authme/threads/FlatFileThread.java new file mode 100644 index 000000000..a4bf3509c --- /dev/null +++ b/src/main/java/uk/org/whoami/authme/threads/FlatFileThread.java @@ -0,0 +1,500 @@ +package uk.org.whoami.authme.threads; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import uk.org.whoami.authme.AuthMe; +import uk.org.whoami.authme.ConsoleLogger; +import uk.org.whoami.authme.cache.auth.PlayerAuth; +import uk.org.whoami.authme.datasource.DataSource; +import uk.org.whoami.authme.settings.Settings; + +public class FlatFileThread extends Thread implements DataSource { + + /* file layout: + * + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:COORDS + * + * Old but compatible: + * PLAYERNAME:HASHSUM:IP + * PLAYERNAME:HASHSUM + * + */ + private File source; + + public void run() { + source = new File(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()); + return; + } + } + + @Override + public synchronized boolean isAuthAvailable(String user) { + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args.length > 1 && args[0].equals(user)) { + return true; + } + } + } 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) { + } + } + } + return false; + } + + @Override + public synchronized boolean saveAuth(PlayerAuth auth) { + if (isAuthAvailable(auth.getNickname())) { + return false; + } + BufferedWriter bw = null; + try { + if( auth.getQuitLocY() == 0 ) { + bw = new BufferedWriter(new FileWriter(source, true)); + bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + "\n"); + } else { + 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() + "\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 updatePassword(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], auth.getHash(), args[2], Long.parseLong(args[3])); + 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) { + } + } + } + removeAuth(auth.getNickname()); + saveAuth(newAuth); + return true; + } + + @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].equals(auth.getNickname())) { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin()); + 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) { + } + } + } + removeAuth(auth.getNickname()); + saveAuth(newAuth); + return true; + } + + @Override + public boolean updateQuitLoc(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]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld()); + 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) { + } + } + } + removeAuth(auth.getNickname()); + saveAuth(newAuth); + return true; + } + + @Override + public int getIps(String ip) { + BufferedReader br = null; + int countIp = 0; + 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(ip)) { + countIp++; + } + } + return countIp; + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return 0; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return 0; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + } + + @Override + public int purgeDatabase(long until) { + BufferedReader br = null; + BufferedWriter bw = null; + ArrayList lines = new ArrayList(); + int cleared = 0; + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args.length == 4) { + if (Long.parseLong(args[3]) >= until) { + lines.add(line); + continue; + } + } + cleared++; + } + bw = new BufferedWriter(new FileWriter(source)); + for (String l : lines) { + bw.write(l + "\n"); + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return cleared; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return cleared; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + if (bw != null) { + try { + bw.close(); + } catch (IOException ex) { + } + } + } + return cleared; + } + + @Override + public synchronized boolean removeAuth(String user) { + if (!isAuthAvailable(user)) { + return false; + } + BufferedReader br = null; + BufferedWriter bw = null; + ArrayList lines = new ArrayList(); + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args.length > 1 && !args[0].equals(user)) { + lines.add(line); + } + } + bw = new BufferedWriter(new FileWriter(source)); + for (String l : lines) { + bw.write(l + "\n"); + } + } 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 (bw != null) { + try { + bw.close(); + } catch (IOException ex) { + } + } + } + return true; + } + + @Override + public synchronized PlayerAuth getAuth(String user) { + 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(user)) { + switch (args.length) { + case 2: + return new PlayerAuth(args[0], args[1], "198.18.0.1", 0); + case 3: + return new PlayerAuth(args[0], args[1], args[2], 0); + case 4: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3])); + case 7: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), "unavailableworld"); + case 8: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), args[7]); + } + } + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + return null; + } + + @Override + public synchronized void close() { + } + + @Override + public void reload() { + } + + @Override + public boolean updateEmail(PlayerAuth auth) { + return false; + } + + @Override + public boolean updateSalt(PlayerAuth auth) { + return false; + } + + @Override + public List getAllAuthsByName(PlayerAuth auth) { + BufferedReader br = null; + List 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) { + } + } + } + } + + @Override + public List getAllAuthsByIp(String ip) { + BufferedReader br = null; + List 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(ip)) { + 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) { + } + } + } + } + + @Override + public List getAllAuthsByEmail(String email) { + return new ArrayList(); + } + + @Override + public void purgeBanned(List banned) { + BufferedReader br = null; + BufferedWriter bw = null; + ArrayList lines = new ArrayList(); + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + try { + if (banned.contains(args[0])) { + lines.add(line); + } + } catch (NullPointerException npe) {} + catch (ArrayIndexOutOfBoundsException aioobe) {} + } + bw = new BufferedWriter(new FileWriter(source)); + for (String l : lines) { + bw.write(l + "\n"); + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + if (bw != null) { + try { + bw.close(); + } catch (IOException ex) { + } + } + } + return; + } + +} diff --git a/src/main/java/uk/org/whoami/authme/threads/LoginThread.java b/src/main/java/uk/org/whoami/authme/threads/LoginThread.java deleted file mode 100644 index f702151fc..000000000 --- a/src/main/java/uk/org/whoami/authme/threads/LoginThread.java +++ /dev/null @@ -1,639 +0,0 @@ -package uk.org.whoami.authme.threads; - -import java.security.NoSuchAlgorithmException; -import java.util.Date; -import java.util.List; - -import me.muizers.Notifications.Notification; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; - -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.api.API; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.AuthMeTeleportEvent; -import uk.org.whoami.authme.events.LoginEvent; -import uk.org.whoami.authme.events.RestoreInventoryEvent; -import uk.org.whoami.authme.events.SpawnTeleportEvent; -import uk.org.whoami.authme.listener.AuthMePlayerListener; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.RandomString; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; - -public class LoginThread extends Thread { - - private Messages m = Messages.getInstance(); - private PlayersLogs pllog = PlayersLogs.getInstance(); - private Utils utils = Utils.getInstance(); - private FileCache playerCache = new FileCache(); - private DataSource database; - public AuthMe plugin; - private boolean passpartu = false; - public RandomString rdm = new RandomString(Settings.captchaLength); - public PluginManager pm; - private Player player; - private String password; - - public LoginThread(DataSource database, AuthMe plugin, Player player, - String password) { - this.database = database; - this.plugin = plugin; - this.pm = plugin.getServer().getPluginManager(); - this.player = player; - this.password = password; - } - - public LoginThread(DataSource database, boolean passpartu, AuthMe plugin, - Player player, String password) { - this.database = database; - this.passpartu = passpartu; - this.plugin = plugin; - this.pm = plugin.getServer().getPluginManager(); - this.player = player; - this.password = password; - } - - public void run() { - final String name = player.getName().toLowerCase(); - String ip = player.getAddress().getAddress().getHostAddress(); - if (Settings.bungee) { - if (plugin.realIp.containsKey(name)) - ip = plugin.realIp.get(name); - } - World world = player.getWorld(); - Location spawnLoc = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - spawnLoc = plugin.mv.getMVWorldManager().getMVWorld(world) - .getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - spawnLoc = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - spawnLoc = Spawn.getInstance().getLocation(); - if (PlayerCache.getInstance().isAuthenticated(name)) { - player.sendMessage(m._("logged_in")); - this.interrupt(); - return; - } - if (!database.isAuthAvailable(player.getName().toLowerCase())) { - player.sendMessage(m._("user_unknown")); - this.interrupt(); - return; - } - PlayerAuth pAuth = database.getAuth(name); - if (pAuth == null) { - player.sendMessage(m._("user_unknown")); - this.interrupt(); - return; - } - if (!Settings.getMySQLColumnGroup.isEmpty() - && pAuth.getGroupId() == Settings.getNonActivatedGroup) { - player.sendMessage(m._("vb_nonActiv")); - this.interrupt(); - return; - } - String hash = pAuth.getHash(); - String email = pAuth.getEmail(); - try { - if (!passpartu) { - if (Settings.useCaptcha) { - if (!plugin.captcha.containsKey(name)) { - plugin.captcha.put(name, 1); - } else { - int i = plugin.captcha.get(name) + 1; - plugin.captcha.remove(name); - plugin.captcha.put(name, i); - } - if (plugin.captcha.containsKey(name) - && plugin.captcha.get(name) > Settings.maxLoginTry) { - player.sendMessage(m._("need_captcha")); - plugin.cap.put(name, rdm.nextString()); - player.sendMessage("Type : /captcha " - + plugin.cap.get(name)); - this.interrupt(); - return; - } else if (plugin.captcha.containsKey(name) - && plugin.captcha.get(name) > Settings.maxLoginTry) { - try { - plugin.captcha.remove(name); - plugin.cap.remove(name); - } catch (NullPointerException npe) { - } - } - } - if (PasswordSecurity.comparePasswordWithHash(password, hash, - name)) { - PlayerAuth auth = new PlayerAuth(name, hash, ip, - new Date().getTime(), email); - database.updateSession(auth); - PlayerCache.getInstance().addPlayer(auth); - final LimboPlayer limbo = LimboCache.getInstance() - .getLimboPlayer(name); - PlayerAuth getAuth = database.getAuth(name); - if (limbo != null) { - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.setOp(limbo.getOperator()); - } - }); - - utils.addNormal(player, limbo.getGroup()); - - if ((Settings.isTeleportToSpawnEnabled) - && (!Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds - .contains(player.getWorld().getName()))) { - if ((Settings.isSaveQuitLocationEnabled) - && (getAuth.getQuitLocY() != 0)) { - utils.packCoords(getAuth.getQuitLocX(), - getAuth.getQuitLocY(), - getAuth.getQuitLocZ(), - getAuth.getWorld(), player); - } else { - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo.getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } - } else if (Settings.isForceSpawnLocOnJoinEnabled - && Settings.getForcedWorlds.contains(player - .getWorld().getName())) { - final Location spawnL = spawnLoc; - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( - player, player - .getLocation(), - spawnL, true); - pm.callEvent(tpEvent); - if (!tpEvent.isCancelled()) { - Location fLoc = tpEvent.getTo(); - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } else if ((Settings.isSaveQuitLocationEnabled) - && (getAuth.getQuitLocY() != 0)) { - utils.packCoords(getAuth.getQuitLocX(), - getAuth.getQuitLocY(), - getAuth.getQuitLocZ(), getAuth.getWorld(), - player); - } else { - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo.getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } - - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode.getByValue(limbo - .getGameMode())); - } - }); - - if (Settings.protectInventoryBeforeLogInEnabled - && player.hasPlayedBefore()) { - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - RestoreInventoryEvent event = new RestoreInventoryEvent( - player, limbo - .getInventory(), - limbo.getArmour()); - Bukkit.getServer() - .getPluginManager() - .callEvent(event); - if (!event.isCancelled()) { - API.setPlayerInventory(player, - limbo.getInventory(), - limbo.getArmour()); - } - } - }); - } - - player.getServer().getScheduler() - .cancelTask(limbo.getTimeoutTaskId()); - player.getServer().getScheduler() - .cancelTask(limbo.getMessageTaskId()); - LimboCache.getInstance().deleteLimboPlayer(name); - if (playerCache.doesCacheExist(name)) { - playerCache.removeCache(name); - } - } - - /* - * Little Work Around under Registration Group Switching for - * admins that add Registration thru a web Scripts. - */ - if (Settings.isPermissionCheckEnabled - && AuthMe.permission.playerInGroup(player, - Settings.unRegisteredGroup) - && !Settings.unRegisteredGroup.isEmpty()) { - AuthMe.permission.playerRemoveGroup(player.getWorld(), - player.getName(), Settings.unRegisteredGroup); - AuthMe.permission.playerAddGroup(player.getWorld(), - player.getName(), Settings.getRegisteredGroup); - } - - try { - if (!PlayersLogs.players.contains(player.getName())) - PlayersLogs.players.add(player.getName()); - pllog.save(); - } catch (NullPointerException ex) { - } - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - Bukkit.getServer().getPluginManager() - .callEvent(new LoginEvent(player, true)); - } - }); - if (Settings.useCaptcha) { - if (plugin.captcha.containsKey(name)) { - plugin.captcha.remove(name); - } - if (plugin.cap.containsKey(name)) { - plugin.cap.containsKey(name); - } - } - player.sendMessage(m._("login")); - displayOtherAccounts(auth); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " logged in!"); - if (plugin.notifications != null) { - plugin.notifications - .showNotification(new Notification("[AuthMe] " - + player.getName() + " logged in!")); - } - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.saveData(); - } - }); - this.interrupt(); - return; - } else { - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() - + " used the wrong password"); - if (Settings.isKickOnWrongPasswordEnabled) { - try { - final int gm = AuthMePlayerListener.gameMode - .get(name); - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode - .getByValue(gm)); - } - }); - } catch (NullPointerException npe) { - } - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.kickPlayer(m._("wrong_pwd")); - } - }); - } else { - player.sendMessage(m._("wrong_pwd")); - this.interrupt(); - return; - } - } - } else { - // need for bypass password check if passpartu command is - // enabled - PlayerAuth auth = new PlayerAuth(name, hash, ip, - new Date().getTime(), email); - database.updateSession(auth); - PlayerCache.getInstance().addPlayer(auth); - final LimboPlayer limbo = LimboCache.getInstance() - .getLimboPlayer(name); - if (limbo != null) { - - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.setOp(limbo.getOperator()); - } - }); - - utils.addNormal(player, limbo.getGroup()); - - if ((Settings.isTeleportToSpawnEnabled) - && (!Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds - .contains(player.getWorld().getName()))) { - if ((Settings.isSaveQuitLocationEnabled) - && (database.getAuth(name).getQuitLocY() != 0)) { - String worldname = database.getAuth(name) - .getWorld(); - World theWorld; - if (worldname.equals("unavailableworld")) { - theWorld = player.getWorld(); - } else { - theWorld = Bukkit.getWorld(worldname); - } - if (theWorld == null) - theWorld = player.getWorld(); - final Location quitLoc = new Location( - theWorld, - database.getAuth(name).getQuitLocX() + 0.5D, - database.getAuth(name).getQuitLocY() + 0.5D, - database.getAuth(name).getQuitLocZ() + 0.5D); - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, quitLoc); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } else { - Bukkit.getScheduler().runTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo.getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } - } else if (Settings.isForceSpawnLocOnJoinEnabled - && Settings.getForcedWorlds.contains(player - .getWorld().getName())) { - final Location spawnL = spawnLoc; - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( - player, player.getLocation(), spawnL, - true); - pm.callEvent(tpEvent); - if (!tpEvent.isCancelled()) { - Location fLoc = tpEvent.getTo(); - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } else if ((Settings.isSaveQuitLocationEnabled) - && (database.getAuth(name).getQuitLocY() != 0)) { - String worldname = database.getAuth(name).getWorld(); - World theWorld; - if (worldname.equals("unavailableworld")) { - theWorld = player.getWorld(); - } else { - theWorld = Bukkit.getWorld(worldname); - } - if (theWorld == null) - theWorld = player.getWorld(); - final Location quitLoc = new Location(theWorld, - database.getAuth(name).getQuitLocX() + 0.5D, - database.getAuth(name).getQuitLocY() + 0.5D, - database.getAuth(name).getQuitLocZ() + 0.5D); - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, quitLoc); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } else { - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo.getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk().isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } - - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode.getByValue(limbo - .getGameMode())); - } - }); - - if (Settings.protectInventoryBeforeLogInEnabled - && player.hasPlayedBefore()) { - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - RestoreInventoryEvent event = new RestoreInventoryEvent( - player, limbo.getInventory(), limbo - .getArmour()); - Bukkit.getServer().getPluginManager() - .callEvent(event); - if (!event.isCancelled()) { - API.setPlayerInventory(player, - limbo.getInventory(), - limbo.getArmour()); - } - } - }); - } - - player.getServer().getScheduler() - .cancelTask(limbo.getTimeoutTaskId()); - player.getServer().getScheduler() - .cancelTask(limbo.getMessageTaskId()); - LimboCache.getInstance().deleteLimboPlayer(name); - if (playerCache.doesCacheExist(name)) { - playerCache.removeCache(name); - } - } - - /* - * Little Work Around under Registration Group Switching for - * admins that add Registration thru a web Scripts. - */ - if (Settings.isPermissionCheckEnabled - && AuthMe.permission.playerInGroup(player, - Settings.unRegisteredGroup) - && !Settings.unRegisteredGroup.isEmpty()) { - AuthMe.permission.playerRemoveGroup(player.getWorld(), - player.getName(), Settings.unRegisteredGroup); - AuthMe.permission.playerAddGroup(player.getWorld(), - player.getName(), Settings.getRegisteredGroup); - } - - try { - if (!PlayersLogs.players.contains(player.getName())) - PlayersLogs.players.add(player.getName()); - pllog.save(); - } catch (NullPointerException ex) { - } - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - Bukkit.getServer().getPluginManager() - .callEvent(new LoginEvent(player, true)); - } - }); - if (Settings.useCaptcha) { - if (plugin.captcha.containsKey(name)) { - plugin.captcha.remove(name); - } - if (plugin.cap.containsKey(name)) { - plugin.cap.containsKey(name); - } - } - player.sendMessage(m._("login")); - displayOtherAccounts(auth); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " logged in!"); - if (plugin.notifications != null) { - plugin.notifications.showNotification(new Notification( - "[AuthMe] " + player.getName() + " logged in!")); - } - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - player.saveData(); - } - }); - this.interrupt(); - } - } catch (NoSuchAlgorithmException ex) { - ConsoleLogger.showError(ex.getMessage()); - player.sendMessage(m._("error")); - this.interrupt(); - return; - } - this.interrupt(); - return; - } - - private void displayOtherAccounts(PlayerAuth auth) { - if (!Settings.displayOtherAccounts) { - return; - } - if (auth == null) { - return; - } - if (this.database.getAllAuthsByName(auth).isEmpty() - || this.database.getAllAuthsByName(auth) == null) { - return; - } - if (this.database.getAllAuthsByName(auth).size() == 1) { - return; - } - List accountList = this.database.getAllAuthsByName(auth); - String message = "[AuthMe] "; - int i = 0; - for (String account : accountList) { - i++; - message = message + account; - if (i != accountList.size()) { - message = message + ", "; - } else { - message = message + "."; - } - - } - for (Player player : AuthMe.getInstance().getServer() - .getOnlinePlayers()) { - if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) { - player.sendMessage("[AuthMe] The player " + auth.getNickname() - + " has " + String.valueOf(accountList.size()) - + " accounts"); - player.sendMessage(message); - } - } - } - -} diff --git a/src/main/java/uk/org/whoami/authme/threads/MySQLThread.java b/src/main/java/uk/org/whoami/authme/threads/MySQLThread.java new file mode 100644 index 000000000..524eed949 --- /dev/null +++ b/src/main/java/uk/org/whoami/authme/threads/MySQLThread.java @@ -0,0 +1,620 @@ +package uk.org.whoami.authme.threads; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import uk.org.whoami.authme.AuthMe; +import uk.org.whoami.authme.ConsoleLogger; +import uk.org.whoami.authme.cache.auth.PlayerAuth; +import uk.org.whoami.authme.datasource.DataSource; +import uk.org.whoami.authme.datasource.MiniConnectionPoolManager; +import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; +import uk.org.whoami.authme.settings.Settings; + +import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; + +public class MySQLThread extends Thread implements DataSource { + + private String host; + private String port; + private String username; + private String password; + private String database; + private String tableName; + private String columnName; + private String columnPassword; + private String columnIp; + private String columnLastLogin; + private String columnSalt; + private String columnGroup; + private String lastlocX; + private String lastlocY; + private String lastlocZ; + private String lastlocWorld; + private String columnEmail; + private String columnID; + private List columnOthers; + private MiniConnectionPoolManager conPool; + + public void run() { + this.host = Settings.getMySQLHost; + this.port = Settings.getMySQLPort; + this.username = Settings.getMySQLUsername; + this.password = Settings.getMySQLPassword; + this.database = Settings.getMySQLDatabase; + this.tableName = Settings.getMySQLTablename; + this.columnName = Settings.getMySQLColumnName; + this.columnPassword = Settings.getMySQLColumnPassword; + this.columnIp = Settings.getMySQLColumnIp; + this.columnLastLogin = Settings.getMySQLColumnLastLogin; + this.lastlocX = Settings.getMySQLlastlocX; + this.lastlocY = Settings.getMySQLlastlocY; + this.lastlocZ = Settings.getMySQLlastlocZ; + this.lastlocWorld = Settings.getMySQLlastlocWorld; + this.columnSalt = Settings.getMySQLColumnSalt; + this.columnGroup = Settings.getMySQLColumnGroup; + this.columnEmail = Settings.getMySQLColumnEmail; + this.columnOthers = Settings.getMySQLOtherUsernameColumn; + this.columnID = Settings.getMySQLColumnId; + + try { + this.connect(); + this.setup(); + } catch (ClassNotFoundException e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + return; + } catch (SQLException e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + return; + } catch (TimeoutException e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + return; + } + } + + private synchronized void connect() throws ClassNotFoundException, SQLException, TimeoutException { + Class.forName("com.mysql.jdbc.Driver"); + ConsoleLogger.info("MySQL driver loaded"); + MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource(); + dataSource.setDatabaseName(database); + dataSource.setServerName(host); + dataSource.setPort(Integer.parseInt(port)); + dataSource.setUser(username); + dataSource.setPassword(password); + conPool = new MiniConnectionPoolManager(dataSource, 10); + ConsoleLogger.info("Connection pool ready"); + } + + private synchronized void setup() throws SQLException { + Connection con = null; + Statement st = null; + ResultSet rs = null; + try { + con = conPool.getValidConnection(); + st = con.createStatement(); + st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + + columnID + " INTEGER AUTO_INCREMENT," + + columnName + " VARCHAR(255) NOT NULL UNIQUE," + + columnPassword + " VARCHAR(255) NOT NULL," + + columnIp + " VARCHAR(40) NOT NULL," + + columnLastLogin + " BIGINT," + + lastlocX + " smallint(6) DEFAULT '0'," + + lastlocY + " smallint(6) DEFAULT '0'," + + lastlocZ + " smallint(6) DEFAULT '0'," + + lastlocWorld + " VARCHAR(255) DEFAULT 'world'," + + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); + rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + + columnPassword + " VARCHAR(255) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnIp); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + + columnIp + " VARCHAR(40) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + + columnLastLogin + " BIGINT;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " smallint(6) NOT NULL DEFAULT '0' AFTER " + + columnLastLogin +" , ADD " + lastlocY + " smallint(6) NOT NULL DEFAULT '0' AFTER " + lastlocX + " , ADD " + lastlocZ + " smallint(6) NOT NULL DEFAULT '0' AFTER " + lastlocY + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + lastlocZ +";"); + } + } finally { + close(rs); + close(st); + close(con); + } + } + + @Override + public synchronized boolean isAuthAvailable(String user) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnName + "=?;"); + + pst.setString(1, user); + rs = pst.executeQuery(); + return rs.next(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + close(con); + } + } + + @Override + public synchronized PlayerAuth getAuth(String user) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnName + "=?;"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) { + if (rs.getString(columnIp).isEmpty() ) { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "198.18.0.1", rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld),rs.getString(columnEmail)); + } else { + if(!columnSalt.isEmpty()){ + if(!columnGroup.isEmpty()) + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword),rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); + else return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword),rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld),rs.getString(columnEmail)); + } else { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); + } + } + } else { + return null; + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } finally { + close(rs); + close(pst); + close(con); + } + } + + @Override + public synchronized boolean saveAuth(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + try { + con = conPool.getValidConnection(); + if ((columnSalt.isEmpty() || columnSalt == null) && (auth.getSalt().isEmpty() || auth.getSalt() == null)) { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + ") VALUES (?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.executeUpdate(); + } else { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + ") VALUES (?,?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.setString(5, auth.getSalt()); + pst.executeUpdate(); + } + if (!columnOthers.isEmpty()) { + for(String column : columnOthers) { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + "." + column + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + @Override + public synchronized boolean updatePassword(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getHash()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + @Override + public boolean updateSession(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getIp()); + pst.setLong(2, auth.getLastLogin()); + pst.setString(3, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + @Override + public int purgeDatabase(long until) { + Connection con = null; + PreparedStatement pst = null; + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " getAllAuthsByName(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList(); + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnIp + "=?;"); + pst.setString(1, auth.getIp()); + rs = pst.executeQuery(); + while(rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } finally { + close(rs); + close(pst); + close(con); + } + } + + @Override + public List getAllAuthsByIp(String ip) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList(); + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnIp + "=?;"); + pst.setString(1, ip); + rs = pst.executeQuery(); + while(rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } finally { + close(rs); + close(pst); + close(con); + } + } + + @Override + public List getAllAuthsByEmail(String email) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List countEmail = new ArrayList(); + try { + con = conPool.getValidConnection(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnEmail + "=?;"); + pst.setString(1, email); + rs = pst.executeQuery(); + while(rs.next()) { + countEmail.add(rs.getString(columnName)); + } + return countEmail; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } finally { + close(rs); + close(pst); + close(con); + } + } + + @Override + public void purgeBanned(List banned) { + Connection con = null; + PreparedStatement pst = null; + try { + for (String name : banned) { + con = conPool.getValidConnection(); + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, name); + pst.executeUpdate(); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + close(con); + } + } +} diff --git a/src/main/java/uk/org/whoami/authme/threads/RegisterThread.java b/src/main/java/uk/org/whoami/authme/threads/RegisterThread.java deleted file mode 100644 index 3c23fae0d..000000000 --- a/src/main/java/uk/org/whoami/authme/threads/RegisterThread.java +++ /dev/null @@ -1,305 +0,0 @@ -package uk.org.whoami.authme.threads; - -import java.security.NoSuchAlgorithmException; -import java.util.Date; - -import me.muizers.Notifications.Notification; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; - -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.RegisterTeleportEvent; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.RandomString; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; -import uk.org.whoami.authme.task.MessageTask; -import uk.org.whoami.authme.task.TimeoutTask; - -public class RegisterThread extends Thread { - - private Messages m = Messages.getInstance(); - private PlayersLogs pllog = PlayersLogs.getInstance(); - private DataSource database; - private boolean isFirstTimeJoin; - private PlayerAuth auth; - private AuthMe plugin; - private Player player; - private String[] args; - private String ip; - - public RegisterThread(AuthMe plugin, DataSource database, Player player, String ip, String[] args) { - this.database = database; - this.setFirstTimeJoin(false); - this.plugin = plugin; - this.player = player; - this.args = args.clone(); - this.ip = ip; - } - public void run() { - final String name = player.getName().toLowerCase(); - if (PlayerCache.getInstance().isAuthenticated(name)) { - player.sendMessage(m._("logged_in")); - this.interrupt(); - return; - } - - if (!Settings.isRegistrationEnabled) { - player.sendMessage(m._("reg_disabled")); - this.interrupt(); - return; - } - - if (database.isAuthAvailable(player.getName().toLowerCase())) { - player.sendMessage(m._("user_regged")); - if (pllog.getStringList("players").contains(player.getName())) { - pllog.getStringList("players").remove(player.getName()); - } - this.interrupt(); - return; - } - - if(Settings.getmaxRegPerIp > 0 ){ - if(!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(ip).size() >= Settings.getmaxRegPerIp) { - player.sendMessage(m._("max_reg")); - this.interrupt(); - return; - } - } - - if(Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { - if(!args[0].contains("@")) { - player.sendMessage(m._("usage_reg")); - this.interrupt(); - return; - } - if(Settings.doubleEmailCheck) { - if(args.length < 2) { - player.sendMessage(m._("usage_reg")); - this.interrupt(); - return; - } - if(!args[0].equals(args[1])) { - player.sendMessage(m._("usage_reg")); - this.interrupt(); - return; - } - } - final String email = args[0]; - if(Settings.getmaxRegPerEmail > 0) { - if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { - player.sendMessage(m._("max_reg")); - this.interrupt(); - return; - } - } - RandomString rand = new RandomString(Settings.getRecoveryPassLength); - final String thePass = rand.nextString(); - if (!thePass.isEmpty()) { - if (PasswordSecurity.userSalt.containsKey(name)) { - try { - final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name); - final PlayerAuth fAuth = new PlayerAuth(name, hashnew, PasswordSecurity.userSalt.get(name), ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getWorld().getName(), email); - database.saveAuth(fAuth); - database.updateEmail(fAuth); - database.updateSession(fAuth); - plugin.mail.main(fAuth, thePass); - } catch (NoSuchAlgorithmException e) { - ConsoleLogger.showError(e.getMessage()); - } - } else { - try { - final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name); - final PlayerAuth fAuth = new PlayerAuth(name, hashnew, ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getWorld().getName(), email); - database.saveAuth(fAuth); - database.updateEmail(fAuth); - database.updateSession(fAuth); - plugin.mail.main(fAuth, thePass); - } catch (NoSuchAlgorithmException e) { - ConsoleLogger.showError(e.getMessage()); - } - } - if(!Settings.getRegisteredGroup.isEmpty()){ - Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED); - } - player.sendMessage(m._("vb_nonActiv")); - String msg = m._("login_msg"); - int time = Settings.getRegistrationTimeout * 20; - int msgInterval = Settings.getWarnMessageInterval; - if (time != 0) { - Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getTimeoutTaskId()); - BukkitTask id = Bukkit.getScheduler().runTaskLater(plugin, new TimeoutTask(plugin, name), time); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id.getTaskId()); - } - - Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId()); - BukkitTask nwMsg = Bukkit.getScheduler().runTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); - LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nwMsg.getTaskId()); - - LimboCache.getInstance().deleteLimboPlayer(name); - if (Settings.isTeleportToSpawnEnabled) { - World world = player.getWorld(); - Location loca = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - loca = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - loca = Spawn.getInstance().getLocation(); - final Location locaT = loca; - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, locaT); - plugin.getServer().getPluginManager().callEvent(tpEvent); - if(!tpEvent.isCancelled()) { - if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { - tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); - } - player.teleport(tpEvent.getTo()); - } - } - }); - } - this.setFirstTimeJoin(true); - player.saveData(); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); - if(plugin.notifications != null) { - plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!")); - } - this.interrupt(); - return; - } - } - - if (args.length == 0 || (Settings.getEnablePasswordVerifier && args.length < 2) ) { - player.sendMessage(m._("usage_reg")); - this.interrupt(); - return; - } - - if(args[0].length() < Settings.getPasswordMinLen || args[0].length() > Settings.passwordMaxLength) { - player.sendMessage(m._("pass_len")); - this.interrupt(); - return; - } - try { - String hash; - if(Settings.getEnablePasswordVerifier) { - if (args[0].equals(args[1])) { - hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name); - } else { - player.sendMessage(m._("password_error")); - this.interrupt(); - return; - } - } else - hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name); - if (Settings.getMySQLColumnSalt.isEmpty()) - { - auth = new PlayerAuth(name, hash, ip, new Date().getTime()); - } else { - auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), ip, new Date().getTime()); - } - if (!database.saveAuth(auth)) { - player.sendMessage(m._("error")); - this.interrupt(); - return; - } - PlayerCache.getInstance().addPlayer(auth); - final LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); - if (limbo != null) { - Bukkit.getScheduler().runTask(plugin, new Runnable(){ - @Override - public void run() { - player.setGameMode(GameMode.getByValue(limbo.getGameMode())); - } - }); - if (Settings.isTeleportToSpawnEnabled) { - World world = player.getWorld(); - Location loca = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - - } catch (ClassCastException cce) { - - } catch (NoClassDefFoundError ncdfe) { - - } - } - if (plugin.essentialsSpawn != null) { - loca = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - loca = Spawn.getInstance().getLocation(); - final Location locaT = loca; - Bukkit.getScheduler().runTask(plugin, new Runnable(){ - @Override - public void run() { - RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, locaT); - plugin.getServer().getPluginManager().callEvent(tpEvent); - if(!tpEvent.isCancelled()) { - if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { - tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); - } - player.teleport(tpEvent.getTo()); - } - } - }); - } - player.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); - player.getServer().getScheduler().cancelTask(limbo.getMessageTaskId()); - LimboCache.getInstance().deleteLimboPlayer(name); - } - - if(!Settings.getRegisteredGroup.isEmpty()){ - Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED); - } - player.sendMessage(m._("registered")); - if (!Settings.getmailAccount.isEmpty()) - player.sendMessage(m._("add_email")); - this.setFirstTimeJoin(true); - player.saveData(); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); - if(plugin.notifications != null) { - plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!")); - } - this.interrupt(); - } catch (NoSuchAlgorithmException ex) { - ConsoleLogger.showError(ex.getMessage()); - player.sendMessage(m._("error")); - this.interrupt(); - } - } - public void setFirstTimeJoin(boolean isFirstTimeJoin) { - this.isFirstTimeJoin = isFirstTimeJoin; - } - public boolean isFirstTimeJoin() { - return isFirstTimeJoin; - } -} diff --git a/src/main/java/uk/org/whoami/authme/threads/SQLiteThread.java b/src/main/java/uk/org/whoami/authme/threads/SQLiteThread.java new file mode 100644 index 000000000..48f11e6a0 --- /dev/null +++ b/src/main/java/uk/org/whoami/authme/threads/SQLiteThread.java @@ -0,0 +1,499 @@ +package uk.org.whoami.authme.threads; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import uk.org.whoami.authme.AuthMe; +import uk.org.whoami.authme.ConsoleLogger; +import uk.org.whoami.authme.cache.auth.PlayerAuth; +import uk.org.whoami.authme.datasource.DataSource; +import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; +import uk.org.whoami.authme.settings.Settings; + +public class SQLiteThread extends Thread implements DataSource { + + private String database; + private String tableName; + private String columnName; + private String columnPassword; + private String columnIp; + private String columnLastLogin; + private String columnSalt; + private String columnGroup; + private String lastlocX; + private String lastlocY; + private String lastlocZ; + private String lastlocWorld; + private String columnEmail; + private String columnID; + private Connection con; + + public void run() { + this.database = Settings.getMySQLDatabase; + this.tableName = Settings.getMySQLTablename; + this.columnName = Settings.getMySQLColumnName; + this.columnPassword = Settings.getMySQLColumnPassword; + this.columnIp = Settings.getMySQLColumnIp; + this.columnLastLogin = Settings.getMySQLColumnLastLogin; + this.columnSalt = Settings.getMySQLColumnSalt; + this.columnGroup = Settings.getMySQLColumnGroup; + this.lastlocX = Settings.getMySQLlastlocX; + this.lastlocY = Settings.getMySQLlastlocY; + this.lastlocZ = Settings.getMySQLlastlocZ; + this.lastlocWorld = Settings.getMySQLlastlocWorld; + this.columnEmail = Settings.getMySQLColumnEmail; + this.columnID = Settings.getMySQLColumnId; + + try { + this.connect(); + this.setup(); + } catch (ClassNotFoundException e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + return; + } catch (SQLException e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + return; + } + } + + private synchronized void connect() throws ClassNotFoundException, SQLException { + Class.forName("org.sqlite.JDBC"); + ConsoleLogger.info("SQLite driver loaded"); + this.con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/"+database+".db"); + + } + + private synchronized void setup() throws SQLException { + Statement st = null; + ResultSet rs = null; + try { + st = con.createStatement(); + st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + + columnID + " INTEGER AUTO_INCREMENT," + + columnName + " VARCHAR(255) NOT NULL UNIQUE," + + columnPassword + " VARCHAR(255) NOT NULL," + + columnIp + " VARCHAR(40) NOT NULL," + + columnLastLogin + " BIGINT," + + lastlocX + " smallint(6) DEFAULT '0'," + + lastlocY + " smallint(6) DEFAULT '0'," + + lastlocZ + " smallint(6) DEFAULT '0'," + + lastlocWorld + " VARCHAR(255) DEFAULT 'world'," + + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); + rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + + columnPassword + " VARCHAR(255) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnIp); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + + columnIp + " VARCHAR(40) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + + columnLastLogin + " BIGINT;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " smallint(6) NOT NULL DEFAULT '0'; " + + "ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " smallint(6) NOT NULL DEFAULT '0'; " + + "ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " smallint(6) NOT NULL DEFAULT '0';"); + } + rs.close(); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); + } + } finally { + close(rs); + close(st); + } + ConsoleLogger.info("SQLite Setup finished"); + } + + @Override + public synchronized boolean isAuthAvailable(String user) { + PreparedStatement pst = null; + ResultSet rs = null; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?"); + pst.setString(1, user); + rs = pst.executeQuery(); + return rs.next(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + } + } + + @Override + public synchronized PlayerAuth getAuth(String user) { + PreparedStatement pst = null; + ResultSet rs = null; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnName + "=?;"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) { + if (rs.getString(columnIp).isEmpty() ) { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "198.18.0.1", rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld) , rs.getString(columnEmail)); + } else { + if(!columnSalt.isEmpty()){ + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword),rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld) , rs.getString(columnEmail)); + } else { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getInt(lastlocX), rs.getInt(lastlocY), rs.getInt(lastlocZ), rs.getString(lastlocWorld) , rs.getString(columnEmail)); + } + } + } else { + return null; + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } finally { + close(rs); + close(pst); + } + } + + @Override + public synchronized boolean saveAuth(PlayerAuth auth) { + PreparedStatement pst = null; + try { + if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + ") VALUES (?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.executeUpdate(); + } else { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + ") VALUES (?,?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.setString(5, auth.getSalt()); + pst.executeUpdate(); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + @Override + public synchronized boolean updatePassword(PlayerAuth auth) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getHash()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + @Override + public boolean updateSession(PlayerAuth auth) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getIp()); + pst.setLong(2, auth.getLastLogin()); + pst.setString(3, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + @Override + public int purgeDatabase(long until) { + PreparedStatement pst = null; + try { + + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " getAllAuthsByName(PlayerAuth auth) { + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnIp + "=?;"); + pst.setString(1, auth.getIp()); + rs = pst.executeQuery(); + while(rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (NullPointerException npe) { + return new ArrayList(); + } finally { + close(rs); + close(pst); + } + } + + @Override + public List getAllAuthsByIp(String ip) { + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnIp + "=?;"); + pst.setString(1, ip); + rs = pst.executeQuery(); + while(rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (NullPointerException npe) { + return new ArrayList(); + } finally { + close(rs); + close(pst); + } + } + + @Override + public List getAllAuthsByEmail(String email) { + PreparedStatement pst = null; + ResultSet rs = null; + List countEmail = new ArrayList(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + + columnEmail + "=?;"); + pst.setString(1, email); + rs = pst.executeQuery(); + while(rs.next()) { + countEmail.add(rs.getString(columnName)); + } + return countEmail; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } catch (NullPointerException npe) { + return new ArrayList(); + } finally { + close(rs); + close(pst); + } + } + + @Override + public void purgeBanned(List banned) { + PreparedStatement pst = null; + try { + for (String name : banned) { + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, name); + pst.executeUpdate(); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + } + } + +} diff --git a/src/main/resources/messages_br.yml b/src/main/resources/messages_br.yml index e9eb200a1..b6ab82f78 100644 --- a/src/main/resources/messages_br.yml +++ b/src/main/resources/messages_br.yml @@ -15,6 +15,7 @@ no_perm: '&cSem permissao!' error: '&fOcorreu um erro de sistema, por favor reporte ao ADM.' login_msg: '&cPara entrar digite: "/login password"' reg_msg: '&cPara registrar um nick digite: "/register senha senha"' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cPara desregistrar digite: /unregister senha' pwd_changed: '&cSenha modificada!' user_unknown: '&cNome de usuario nao existe. Verifique.' diff --git a/src/main/resources/messages_cz.yml b/src/main/resources/messages_cz.yml index d03dd7e54..39ed815fc 100644 --- a/src/main/resources/messages_cz.yml +++ b/src/main/resources/messages_cz.yml @@ -13,6 +13,7 @@ no_perm: '&cNemas opravneni.' error: '&cVyskytla se chyba kontaktujte admina ...' login_msg: '&cProsim prihlaste se "/login vaseheslo".' reg_msg: '&cProsim zaregistrujte se "/register heslo heslo".' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cPouziti: "/unregister vaseheslo".' pwd_changed: '&cHeslo zmeneno!' user_unknown: '&cUzivatelske jmeno neni registrovano.' diff --git a/src/main/resources/messages_de.yml b/src/main/resources/messages_de.yml index fad921825..7dad66149 100644 --- a/src/main/resources/messages_de.yml +++ b/src/main/resources/messages_de.yml @@ -16,6 +16,7 @@ no_perm: '&cKeine Rechte' error: '&fEin Fehler ist aufgetreten. Bitte kontaktiere einen Admin' login_msg: '&cBitte logge dich ein mit "/login "' reg_msg: '&cBitte registriere dich mit "/register "' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cBenutze: /unregister ' pwd_changed: '&cPasswort geändert!' user_unknown: '&cBenutzername nicht registriert' diff --git a/src/main/resources/messages_en.yml b/src/main/resources/messages_en.yml index 273ed5d5c..8b88fdaf9 100644 --- a/src/main/resources/messages_en.yml +++ b/src/main/resources/messages_en.yml @@ -16,6 +16,7 @@ no_perm: '&cNo Permission' error: '&fAn error ocurred; Please contact the admin' login_msg: '&cPlease login with "/login password"' reg_msg: '&cPlease register with "/register password ConfirmPassword"' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cUsage: /unregister password' pwd_changed: '&cPassword changed!' user_unknown: '&cUsername not registered' diff --git a/src/main/resources/messages_es.yml b/src/main/resources/messages_es.yml index 72f29bc06..a25517e62 100644 --- a/src/main/resources/messages_es.yml +++ b/src/main/resources/messages_es.yml @@ -17,6 +17,7 @@ no_perm: '&cNo tienes permiso' error: '&fHa ocurrido un error. Por favor contacta al administrador.' login_msg: '&cInicia sesión con "/login contraseña"' reg_msg: '&cPor favor, regístrate con "/register Contraseña ConfirmarContraseña"' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cUso: /unregister contraseña' pwd_changed: '&c¡Contraseña cambiada!' user_unknown: '&cUsuario no registrado' diff --git a/src/main/resources/messages_fi.yml b/src/main/resources/messages_fi.yml index 316701991..3158619db 100644 --- a/src/main/resources/messages_fi.yml +++ b/src/main/resources/messages_fi.yml @@ -16,6 +16,7 @@ no_perm: '&cEi oikeuksia' error: '&fVirhe: Ota yhteys operaattoriin!' login_msg: '&cKirjaudu palvelimmelle "/login salasana"' reg_msg: '&cRekisteröidy palvelimellemme "/register salasana salasana"' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cKäyttö: /unregister password' pwd_changed: '&cSalasana vaihdettu!!' user_unknown: '&cSalasanat eivät täsmää' diff --git a/src/main/resources/messages_fr.yml b/src/main/resources/messages_fr.yml index 3ebb7b8c4..6b3df9762 100644 --- a/src/main/resources/messages_fr.yml +++ b/src/main/resources/messages_fr.yml @@ -16,7 +16,8 @@ max_reg: '&fLimite d''enregistrement atteinte pour ce compte' no_perm: '&cVous n''avez pas la permission' error: '&fUne erreur est apparue, veuillez contacter un administrateur' login_msg: '&cPour vous connecter, utilisez: /login motdepasse' -reg_msg: '&cPour vous inscrire, utilisez /register motdepasse confirmermotdepasse' +reg_msg: '&cPour vous inscrire, utilisez "/register motdepasse confirmermotdepasse"' +reg_email_msg: '&cPour vous inscrire, utilisez "/register "' usage_unreg: '&cPour supprimer ce compte, utilisez: /unregister password' pwd_changed: '&cMotdePasse changé avec succès!' user_unknown: '&c Ce compte n''est pas enregistré' diff --git a/src/main/resources/messages_hu.yml b/src/main/resources/messages_hu.yml index 6639f0d1e..c7cc93b75 100644 --- a/src/main/resources/messages_hu.yml +++ b/src/main/resources/messages_hu.yml @@ -23,6 +23,7 @@ login: '&aSikeresen Bel wrong_pwd: '&4Hibs jelsz' user_unknown: '&cJtkosnv nem regisztrlt' reg_msg: '&cKrlek Regisztrlj: "/register jelsz jelszjra"' +reg_email_msg: '&cPlease register with "/register "' unsafe_spawn: A kilpsi helyzeted nem biztonsgos, teleportls a kezd Spawnra. max_reg: Csak egy karakterrel Registrlhatsz!!! password_error: A jelsz nem illik ssze diff --git a/src/main/resources/messages_it.yml b/src/main/resources/messages_it.yml index 050adf1ae..d07efa604 100644 --- a/src/main/resources/messages_it.yml +++ b/src/main/resources/messages_it.yml @@ -16,6 +16,7 @@ no_perm: '&cNessun Permesso' error: "Errore; Perfavore, contatta l'admin" login_msg: '&cPerfavore, loggati con "/login password"' reg_msg: '&cPerfavore, registrati con "/register password confermaPassword"' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&cUtilizzo: /unregister password' pwd_changed: '&cPassword cambiata!' user_unknown: '&cUtente non registrato' diff --git a/src/main/resources/messages_lt.yml b/src/main/resources/messages_lt.yml index 6e6d482c4..e1e407149 100644 --- a/src/main/resources/messages_lt.yml +++ b/src/main/resources/messages_lt.yml @@ -16,6 +16,7 @@ no_perm: '&cNera leidimo' error: '&cAtsirado klaida, praneskite adminstratoriui.' login_msg: '&ePrasome prisijungti: /login slaptazodis' reg_msg: '&ePrasome prisiregistruoti: /register slaptazodis pakartotiSlaptazodi' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&ePanaikinti registracija: /unregister slaptazodis" pwd_changed: '&aSlaptazodis pakeistas' user_unknown: '&cVartotojas neprisiregistraves' diff --git a/src/main/resources/messages_pl.yml b/src/main/resources/messages_pl.yml index dc2c946b0..5b0fd967e 100644 --- a/src/main/resources/messages_pl.yml +++ b/src/main/resources/messages_pl.yml @@ -10,6 +10,7 @@ reg_only: '&fTylko zarejestrowani uzytkownicy maja do tego dostep!' valid_session: '&cSesja logowania' login_msg: '&2Prosze sie zalogowac przy uzyciu &6/login ' reg_msg: '&2Prosze sie zarejestrowac przy uzyciu &6/register ' +reg_email_msg: '&cPlease register with "/register "' timeout: '&fUplynal limit czasu zalogowania' wrong_pwd: '&cNiepoprawne haslo' logout: '&cPomyslnie wylogowany' diff --git a/src/main/resources/messages_ru.yml b/src/main/resources/messages_ru.yml index a77d96b1d..22088bbfd 100644 --- a/src/main/resources/messages_ru.yml +++ b/src/main/resources/messages_ru.yml @@ -19,6 +19,7 @@ error: '&cЧто-то пошло не так... &5Свяжись с админи login_msg: '&eВойди в игру - &d/l ПАРОЛЬ &eили &d/login ПАРОЛЬ' reg_msg: '&eЗарегистрируйся - &d/reg ПАРОЛЬ ПОВТОР_ПАРОЛЯ &eили &d/register ПАРОЛЬ ПОВТОР_ПАРОЛЯ' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&eСинтаксис: &d/unregister ПАРОЛЬ' pwd_changed: '&aПароль изменён' user_unknown: '&cТакой игрок не зарегистрирован' diff --git a/src/main/resources/messages_sk.yml b/src/main/resources/messages_sk.yml index e3e3e36f0..03ccb6592 100644 --- a/src/main/resources/messages_sk.yml +++ b/src/main/resources/messages_sk.yml @@ -14,6 +14,7 @@ reg_only: '&fVstup iba pre registrovanych! Navstiv http://www.cs-gaming.eu pre r valid_session: '&cZapamätané prihlásenie' login_msg: '&cPrihlás sa príkazom "/login heslo"' reg_msg: '&cZaregistruj sa príkazom "/register heslo zopakujHeslo"' +reg_email_msg: '&cPlease register with "/register "' timeout: '&fVyprsal cas na prihlásenie' wrong_pwd: '&cZadal si zlé heslo' logout: '&cBol si úspesne odhláseny' diff --git a/src/main/resources/messages_zhcn.yml b/src/main/resources/messages_zhcn.yml index 24d0845a8..57c389fe8 100644 --- a/src/main/resources/messages_zhcn.yml +++ b/src/main/resources/messages_zhcn.yml @@ -12,6 +12,7 @@ vb_nonActiv: '&f你的帐号还未激活,请查看你的邮箱!' user_regged: '&c此用户已经在此服务器注册过' usage_reg: '&c正确用法:“/register <密码> <再输入一次以确定密码>”' max_reg: '&f你不允许再为你的IP在服务器注册更多用户了!' +reg_email_msg: '&cPlease register with "/register "' no_perm: '&c没有权限' error: '&f发现错误,请联系管理员' login_msg: '&c请输入“/login <密码>”以登录' diff --git a/src/main/resources/messages_zhtw.yml b/src/main/resources/messages_zhtw.yml index 6b8c71b39..9be696211 100644 --- a/src/main/resources/messages_zhtw.yml +++ b/src/main/resources/messages_zhtw.yml @@ -16,6 +16,7 @@ no_perm: '&c你並沒有這個權限 。' error: '&f發生錯誤 , 請與管理員聯絡 。' login_msg: '&c請使用這個指令來登入 : 《 /login <密碼> 》' reg_msg: '&c請使用這個的指令來註冊 : 《 /register <密碼> <重覆密碼> 》' +reg_email_msg: '&cPlease register with "/register "' usage_unreg: '&c用法 : 《 /unregister <密碼> 》' pwd_changed: '&c你成功的更換了你的密碼 !' user_unknown: '&c此用戶名沒有已登記資料 。' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bc0e3e41b..a7972f343 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,9 @@ name: AuthMe -author: darkwarriors,Xephi +author: Xephi59 website: http://www.multiplayer-italia.com/ description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player. main: uk.org.whoami.authme.AuthMe -version: 2.8 +version: 2.9 softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag, Essentials, EssentialsSpawn] commands: register: diff --git a/src/main/resources/spout.yml b/src/main/resources/spout.yml index 16b5f6ad3..b86851531 100644 --- a/src/main/resources/spout.yml +++ b/src/main/resources/spout.yml @@ -9,4 +9,4 @@ LoginScreen: - Sample text - Change this at spout.yml - '--- AuthMe Reloaded by ---' - - d4rkwarriors and Xephi59 \ No newline at end of file + - Xephi59 \ No newline at end of file