diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index 947df69a2..2c2f4d326 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -57,21 +57,27 @@ public class AdminCommand implements CommandExecutor { public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) { if (args.length == 0) { - sender.sendMessage("Usage: /authme reload - Reload the config"); + sender.sendMessage("Usage:"); + sender.sendMessage("/authme reload - Reload the config"); + sender.sendMessage("/authme version - Get AuthMe version info"); sender.sendMessage("/authme register - Register a player"); - sender.sendMessage("/authme changepassword - Change player password"); sender.sendMessage("/authme unregister - Unregister a player"); - sender.sendMessage("/authme purge - Purge Database"); - sender.sendMessage("/authme version - Get AuthMe version infos"); - sender.sendMessage("/authme lastlogin - Display Date about the Player's LastLogin"); + sender.sendMessage("/authme changepassword - Change a player's password"); + sender.sendMessage("/authme chgemail - Change a player's email"); + sender.sendMessage("/authme getemail - Get a player's email"); + sender.sendMessage("/authme getip - Display a player's IP if he's online"); + sender.sendMessage("/authme lastlogin - Display the date of a player's last login"); sender.sendMessage("/authme accounts - Display all player's accounts"); - sender.sendMessage("/authme setSpawn - Set AuthMe spawn to your current pos"); - sender.sendMessage("/authme spawn - Teleport you to the AuthMe SpawnPoint"); - sender.sendMessage("/authme chgemail - Change player email"); - sender.sendMessage("/authme getemail - Get player email"); - sender.sendMessage("/authme purgelastpos - Purge last position for a player"); - sender.sendMessage("/authme switchantibot on/off - Enable/Disable antibot method"); - sender.sendMessage("/authme forcelogin "); + sender.sendMessage("/authme purge - Purge database"); + sender.sendMessage("/authme purgebannedplayers - Purge database from banned players"); + sender.sendMessage("/authme purgelastpos - Purge last position infos for a player"); + sender.sendMessage("/authme setspawn - Set player's spawn to your current position"); + sender.sendMessage("/authme setfirstspawn - Set player's first spawn to your current position"); + sender.sendMessage("/authme spawn - Teleport yourself to the spawn point"); + sender.sendMessage("/authme firstspawn - Teleport yourself to the first spawn point"); + sender.sendMessage("/authme switchantibot on/off - Enable/Disable AntiBot feature"); + sender.sendMessage("/authme forcelogin - Enforce the login of a connected player"); + sender.sendMessage("/authme passpartutoken - Generate a timed token to login with every player's account (CONSOLE ONLY)"); return true; } @@ -80,15 +86,15 @@ public class AdminCommand implements CommandExecutor { return true; } - if ((sender instanceof ConsoleCommandSender) && args[0].equalsIgnoreCase("passpartuToken")) { + if ((sender instanceof ConsoleCommandSender) && args[0].equalsIgnoreCase("passpartutoken")) { if (args.length > 1) { - System.out.println("[AuthMe] command usage: /authme passpartuToken"); + System.out.println("[AuthMe] command usage: /authme passpartutoken"); return true; } if (Utils.getInstance().obtainToken()) { - System.out.println("[AuthMe] You have 30s for insert this token ingame with /passpartu [token]"); + System.out.println("[AuthMe] You have 30s to insert this token ingame with /passpartu "); } else { - System.out.println("[AuthMe] Security error on passpartu token, redo it. "); + System.out.println("[AuthMe] Security error on passpartu token, please redo the command."); } return true; } @@ -100,7 +106,11 @@ public class AdminCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("purge")) { if (args.length != 2) { - sender.sendMessage("Usage: /authme purge "); + sender.sendMessage("Usage: /authme purge "); + return true; + } + if (Integer.parseInt(args[1]) < 30) { + sender.sendMessage("You can only purge data older than 30 days") return true; } try { @@ -117,9 +127,10 @@ public class AdminCommand implements CommandExecutor { plugin.dataManager.purgeLimitedCreative(purged); if (Settings.purgeAntiXray) plugin.dataManager.purgeAntiXray(purged); + sender.sendMessage("[AuthMe] Database has been purged correctly"); return true; } catch (NumberFormatException e) { - sender.sendMessage("Usage: /authme purge "); + sender.sendMessage("Usage: /authme purge "); return true; } } else if (args[0].equalsIgnoreCase("reload")) { @@ -161,24 +172,23 @@ public class AdminCommand implements CommandExecutor { return true; } try { - if (database.getAuth(args[1].toLowerCase()) != null) { - PlayerAuth player = database.getAuth(args[1].toLowerCase()); - long lastLogin = player.getLastLogin(); - Date d = new Date(lastLogin); - final long diff = System.currentTimeMillis() - lastLogin; - final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs."; - String lastIP = player.getIp(); - sender.sendMessage("[AuthMe] " + args[1] + " lastlogin : " + d.toString()); - sender.sendMessage("[AuthMe] The player : " + player.getNickname() + " is unlogged since " + msg); - sender.sendMessage("[AuthMe] LastPlayer IP : " + lastIP); - } else { - m.send(sender, "unknown_user"); - return true; - } + PlayerAuth auth = database.getAuth(args[1].toLowerCase()); } catch (NullPointerException e) { m.send(sender, "unknown_user"); return true; } + if (auth == null) { + m.send(sender, "user_unknown"); + return true; + } + long lastLogin = auth.getLastLogin(); + Date d = new Date(lastLogin); + final long diff = System.currentTimeMillis() - lastLogin; + final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs."; + String lastIP = auth.getIp(); + sender.sendMessage("[AuthMe] " + args[1] + " lastlogin : " + d.toString()); + sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " is unlogged since " + msg); + sender.sendMessage("[AuthMe] Last Player's IP: " + lastIP); } else if (args[0].equalsIgnoreCase("accounts")) { if (args.length != 2) { sender.sendMessage("Usage: /authme accounts "); @@ -186,83 +196,77 @@ public class AdminCommand implements CommandExecutor { return true; } if (!args[1].contains(".")) { - final CommandSender fSender = sender; - final String[] arguments = args; Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlayerAuth pAuth = null; + PlayerAuth auth = null; String message = "[AuthMe] "; try { - pAuth = database.getAuth(arguments[1].toLowerCase()); + auth = database.getAuth(args[1].toLowerCase()); } catch (NullPointerException npe) { - fSender.sendMessage("[AuthMe] This player is unknown"); - return; + m.send(sender, "unknown_user"); + return true; } - if (pAuth != null) { - List accountList = database.getAllAuthsByName(pAuth); - if (accountList.isEmpty() || accountList == null) { - fSender.sendMessage("[AuthMe] This player is unknown"); - return; - } - if (accountList.size() == 1) { - fSender.sendMessage("[AuthMe] " + arguments[1] + " is a single account player"); - return; - } - int i = 0; - for (String account : accountList) { - i++; - message = message + account; - if (i != accountList.size()) { - message = message + ", "; - } else { - message = message + "."; - } - } - fSender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts"); - fSender.sendMessage(message); - } else { - fSender.sendMessage("[AuthMe] This player is unknown"); - return; + if (auth == null) { + m.send(sender, "unknown_user"); + return true; } + List accountList = database.getAllAuthsByName(auth); + if (accountList.isEmpty() || accountList == null) { + m.send(sender, "user_unknown"); + return true; + } + if (accountList.size() == 1) { + sender.sendMessage("[AuthMe] " + args[1] + " is a single account player"); + return true; + } + int i = 0; + for (String account : accountList) { + i++; + message = message + account; + if (i != accountList.size()) { + message = message + ", "; + } else { + message = message + "."; + } + } + sender.sendMessage("[AuthMe] " + args[1] + " has " + String.valueOf(accountList.size()) + " accounts"); + sender.sendMessage(message); } }); return true; } else { - final CommandSender fSender = sender; - final String[] arguments = args; Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { String message = "[AuthMe] "; - if (arguments[1] != null) { - List accountList = database.getAllAuthsByIp(arguments[1]); - if (accountList.isEmpty() || accountList == null) { - fSender.sendMessage("[AuthMe] Please put a valid IP"); - return; - } - if (accountList.size() == 1) { - fSender.sendMessage("[AuthMe] " + arguments[1] + " is a single account player"); - return; - } - int i = 0; - for (String account : accountList) { - i++; - message = message + account; - if (i != accountList.size()) { - message = message + ", "; - } else { - message = message + "."; - } - } - fSender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts"); - fSender.sendMessage(message); - } else { - fSender.sendMessage("[AuthMe] Please put a valid IP"); + if (args[1] == null) { + sender.sendMessage("[AuthMe] Please put a valid IP"); return; } + List accountList = database.getAllAuthsByIp(args[1]); + if (accountList.isEmpty() || accountList == null) { + sender.sendMessage("[AuthMe] This IP does not exist in the database"); + return true; + } + if (accountList.size() == 1) { + sender.sendMessage("[AuthMe] " + args[1] + " is a single account player"); + return true; + } + int i = 0; + for (String account : accountList) { + i++; + message = message + account; + if (i != accountList.size()) { + message = message + ", "; + } else { + message = message + "."; + } + } + sender.sendMessage("[AuthMe] " + args[1] + " has " + String.valueOf(accountList.size()) + " accounts"); + sender.sendMessage(message); } }); return true; @@ -270,9 +274,28 @@ public class AdminCommand implements CommandExecutor { } else if (args[0].equalsIgnoreCase("register") || args[0].equalsIgnoreCase("reg")) { if (args.length != 3) { - sender.sendMessage("Usage: /authme register playername password"); + sender.sendMessage("Usage: /authme register "); return true; } + String lowpass = args[2].toLowerCase(); + if (lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null") || !lowpass.matches(Settings.getPassRegex)) { + m.send(player, "password_error"); + return true; + } + if (lowpass.equalsIgnoreCase(args[1])) { + m.send(player, "password_error_nick"); + return true; + } + if (lowpass.length() < Settings.getPasswordMinLen || lowpass.length() > Settings.passwordMaxLength) { + m.send(player, "pass_len"); + return true; + } + if (!Settings.unsafePasswords.isEmpty()) { + if (Settings.unsafePasswords.contains(lowpass)) { + m.send(player, "password_error_unsafe"); + return true; + } + } try { String name = args[1].toLowerCase(); if (database.isAuthAvailable(name)) { @@ -280,7 +303,7 @@ public class AdminCommand implements CommandExecutor { return true; } String hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[2], name); - PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0L, "your@email.com"); + PlayerAuth auth = new PlayerAuth(name, hash, "198.168.0.1", 0L, "your@email.com"); if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) auth.setSalt(PasswordSecurity.userSalt.get(name)); else auth.setSalt(""); @@ -297,42 +320,49 @@ public class AdminCommand implements CommandExecutor { return true; } else if (args[0].equalsIgnoreCase("getemail")) { if (args.length != 2) { - sender.sendMessage("Usage: /authme getemail playername"); + sender.sendMessage("Usage: /authme getemail "); return true; } String playername = args[1].toLowerCase(); - PlayerAuth getAuth = database.getAuth(playername); - if (getAuth == null) { + PlayerAuth auth = database.getAuth(playername); + if (auth == null) { m.send(sender, "unknown_user"); return true; } - sender.sendMessage("[AuthMe] " + args[1] + " email : " + getAuth.getEmail()); + sender.sendMessage("[AuthMe] " + args[1] + "'s email: " + getAuth.getEmail()); return true; } else if (args[0].equalsIgnoreCase("chgemail")) { if (args.length != 3) { - sender.sendMessage("Usage: /authme chgemail playername email"); + sender.sendMessage("Usage: /authme chgemail "); + return true; + } + if (!Settings.isEmailCorrect(args[2])) { + m.send(player, "email_invalid"); return true; } String playername = args[1].toLowerCase(); - PlayerAuth getAuth = database.getAuth(playername); - if (getAuth == null) { + PlayerAuth auth = database.getAuth(playername); + if (auth == null) { m.send(sender, "unknown_user"); return true; } - getAuth.setEmail(args[2]); - if (!database.updateEmail(getAuth)) { + auth.setEmail(args[2]); + if (!database.updateEmail(auth)) { m.send(sender, "error"); return true; } if (PlayerCache.getInstance().getAuth(playername) != null) - PlayerCache.getInstance().updatePlayer(getAuth); + PlayerCache.getInstance().updatePlayer(auth); + m.send(sender, "email_changed"); return true; } else if (args[0].equalsIgnoreCase("setspawn")) { try { if (sender instanceof Player) { - if (Spawn.getInstance().setSpawn(((Player) sender).getLocation())) - sender.sendMessage("[AuthMe] Correctly define new spawn"); - else sender.sendMessage("[AuthMe] SetSpawn fail , please retry"); + if (Spawn.getInstance().setSpawn(((Player) sender).getLocation())) { + sender.sendMessage("[AuthMe] Correctly defined new spawn point"); + } else { + sender.sendMessage("[AuthMe] SetSpawn has failed, please retry"); + } } else { sender.sendMessage("[AuthMe] Please use that command in game"); } @@ -344,8 +374,8 @@ public class AdminCommand implements CommandExecutor { try { if (sender instanceof Player) { if (Spawn.getInstance().setFirstSpawn(((Player) sender).getLocation())) - sender.sendMessage("[AuthMe] Correctly define new first spawn"); - else sender.sendMessage("[AuthMe] SetFirstSpawn fail , please retry"); + sender.sendMessage("[AuthMe] Correctly defined new first spawn point"); + else sender.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry"); } else { sender.sendMessage("[AuthMe] Please use that command in game"); } @@ -367,13 +397,14 @@ public class AdminCommand implements CommandExecutor { plugin.dataManager.purgeLimitedCreative(bannedPlayers); if (Settings.purgeAntiXray) plugin.dataManager.purgeAntiXray(bannedPlayers); + sender.sendMessage("[AuthMe] Database has been purged correctly"); return true; } else if (args[0].equalsIgnoreCase("spawn")) { try { if (sender instanceof Player) { if (Spawn.getInstance().getSpawn() != null) ((Player) sender).teleport(Spawn.getInstance().getSpawn()); - else sender.sendMessage("[AuthMe] Spawn fail , please try to define the spawn"); + else sender.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn"); } else { sender.sendMessage("[AuthMe] Please use that command in game"); } @@ -386,7 +417,7 @@ public class AdminCommand implements CommandExecutor { if (sender instanceof Player) { if (Spawn.getInstance().getFirstSpawn() != null) ((Player) sender).teleport(Spawn.getInstance().getFirstSpawn()); - else sender.sendMessage("[AuthMe] Spawn fail , please try to define the first spawn"); + else sender.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn"); } else { sender.sendMessage("[AuthMe] Please use that command in game"); } @@ -394,12 +425,30 @@ public class AdminCommand implements CommandExecutor { ConsoleLogger.showError(ex.getMessage()); } return true; - } else - if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) { + } else if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) { if (args.length != 3) { - sender.sendMessage("Usage: /authme changepassword playername newpassword"); + sender.sendMessage("Usage: /authme changepassword "); return true; } + String lowpass = args[2].toLowerCase(); + if (lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null") || !lowpass.matches(Settings.getPassRegex)) { + m.send(player, "password_error"); + return true; + } + if (lowpass.equalsIgnoreCase(args[1])) { + m.send(player, "password_error_nick"); + return true; + } + if (lowpass.length() < Settings.getPasswordMinLen || lowpass.length() > Settings.passwordMaxLength) { + m.send(player, "pass_len"); + return true; + } + if (!Settings.unsafePasswords.isEmpty()) { + if (Settings.unsafePasswords.contains(lowpass)) { + m.send(player, "password_error_unsafe"); + return true; + } + } try { String name = args[1].toLowerCase(); String hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[2], name); @@ -431,7 +480,7 @@ public class AdminCommand implements CommandExecutor { return true; } else if (args[0].equalsIgnoreCase("unregister") || args[0].equalsIgnoreCase("unreg") || args[0].equalsIgnoreCase("del")) { if (args.length != 2) { - sender.sendMessage("Usage: /authme unregister playername"); + sender.sendMessage("Usage: /authme unregister "); return true; } String name = args[1].toLowerCase(); @@ -477,24 +526,24 @@ public class AdminCommand implements CommandExecutor { m.send(sender, "unregistered"); ConsoleLogger.info(args[1] + " unregistered"); return true; - } else if (args[0].equalsIgnoreCase("purgelastpos")) { + } else if (args[0].equalsIgnoreCase("purgelastpos") || args[0].equalsIgnoreCase("resetposition")) { if (args.length != 2) { - sender.sendMessage("Usage: /authme purgelastpos playername"); + sender.sendMessage("Usage: /authme purgelastpos "); return true; } try { String name = args[1].toLowerCase(); PlayerAuth auth = database.getAuth(name); if (auth == null) { - sender.sendMessage("The player " + name + " is not registered "); + m.send(sender, "unknown_user"); return true; } - auth.setQuitLocX(0); - auth.setQuitLocY(0); - auth.setQuitLocZ(0); + auth.setQuitLocX(0D); + auth.setQuitLocY(0D); + auth.setQuitLocZ(0D); auth.setWorld("world"); database.updateQuitLoc(auth); - sender.sendMessage(name + " 's last pos location is now reset"); + sender.sendMessage(name + "'s last position location is now reset"); } catch (Exception e) { ConsoleLogger.showError("An error occured while trying to reset location or player do not exist, please see below: "); ConsoleLogger.showError(e.getMessage()); @@ -504,7 +553,7 @@ public class AdminCommand implements CommandExecutor { return true; } else if (args[0].equalsIgnoreCase("switchantibot")) { if (args.length != 2) { - sender.sendMessage("Usage : /authme switchantibot on/off"); + sender.sendMessage("Usage: /authme switchantibot on/off"); return true; } if (args[1].equalsIgnoreCase("on")) { @@ -517,49 +566,31 @@ public class AdminCommand implements CommandExecutor { sender.sendMessage("[AuthMe] AntiBotMod disabled"); return true; } - sender.sendMessage("Usage : /authme switchantibot on/off"); + sender.sendMessage("Usage: /authme switchantibot on/off"); return true; } else if (args[0].equalsIgnoreCase("getip")) { if (args.length < 2) { - sender.sendMessage("Usage : /authme getip onlinePlayerName"); + sender.sendMessage("Usage: /authme getip "); return true; } - if (Bukkit.getPlayer(args[1]) != null) { - Player player = Bukkit.getPlayer(args[1]); - sender.sendMessage(player.getName() + " actual ip is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort()); - sender.sendMessage(player.getName() + " real ip is : " + plugin.getIP(player)); - return true; - } else { + Player player = Bukkit.getPlayer(args[1]); + if (player == null) { sender.sendMessage("This player is not actually online"); - sender.sendMessage("Usage : /authme getip onlinePlayerName"); + sender.sendMessage("Usage: /authme getip "); return true; } - } else if (args[0].equalsIgnoreCase("resetposition")) { - if (args.length < 2) { - sender.sendMessage("Usage : /authme resetPosition "); + sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort()); + sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player)); return true; - } - PlayerAuth auth = database.getAuth(args[1]); - if (auth == null) { - m.send(sender, "unknown_user"); - return true; - } - auth.setQuitLocX(0D); - auth.setQuitLocY(0D); - auth.setQuitLocZ(0D); - auth.setWorld("world"); - database.updateQuitLoc(auth); - sender.sendMessage("[AuthMe] Successfully reset position for " + auth.getNickname()); - return true; } else if (args[0].equalsIgnoreCase("forcelogin")) { if (args.length < 2) { - sender.sendMessage("Usage : /authme forcelogin "); + sender.sendMessage("Usage: /authme forcelogin "); return true; } try { Player player = Bukkit.getPlayer(args[1]); if (player == null || !player.isOnline()) { - sender.sendMessage("Online player only !"); + sender.sendMessage("Player needs to be online!"); return true; } if (!plugin.authmePermissible(player, "authme.canbeforced")) { @@ -567,7 +598,7 @@ public class AdminCommand implements CommandExecutor { return true; } plugin.management.performLogin(player, "dontneed", true); - sender.sendMessage("Force Login performed !"); + sender.sendMessage("Force Login performed!"); } catch (Exception e) { sender.sendMessage("An error occured while trying to get that player!"); }