From e9f299fca8885dd3d6dea5059029a3a846fd7cc2 Mon Sep 17 00:00:00 2001 From: games647 Date: Sat, 3 Oct 2015 18:22:13 +0200 Subject: [PATCH] Fix PlayerAuth constructor calls --- src/main/java/fr/xephi/authme/api/API.java | 366 ++-- src/main/java/fr/xephi/authme/api/NewAPI.java | 306 ++-- .../xephi/authme/commands/AdminCommand.java | 2 +- .../xephi/authme/commands/EmailCommand.java | 5 +- .../authme/converter/CrazyLoginConverter.java | 4 +- .../authme/converter/RakamakConverter.java | 12 +- .../authme/converter/RoyalAuthConverter.java | 2 +- .../authme/converter/vAuthFileReader.java | 4 +- .../xephi/authme/converter/xAuthToFlat.java | 2 +- .../fr/xephi/authme/datasource/FlatFile.java | 1501 ++++++++--------- .../xephi/authme/plugin/manager/EssSpawn.java | 4 +- .../authme/security/crypts/PHPFUSION.java | 6 +- .../fr/xephi/authme/security/crypts/XF.java | 2 +- .../authme/security/pbkdf2/MacBasedPRF.java | 10 +- .../xephi/authme/settings/OtherAccounts.java | 9 +- .../java/fr/xephi/authme/settings/Spawn.java | 8 +- 16 files changed, 1115 insertions(+), 1128 deletions(-) diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 11eba8613..79eaeaffe 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -1,183 +1,183 @@ -package fr.xephi.authme.api; - -import java.security.NoSuchAlgorithmException; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.Utils; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.settings.Settings; - -public class API { - - public static final String newline = System.getProperty("line.separator"); - public static AuthMe instance; - - @Deprecated - public API(AuthMe instance) { - API.instance = instance; - } - - /** - * Hook into AuthMe - * - * @return AuthMe instance - */ - @Deprecated - public static AuthMe hookAuthMe() { - if (instance != null) - return instance; - Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe"); - if (plugin == null || !(plugin instanceof AuthMe)) { - return null; - } - instance = (AuthMe) plugin; - return instance; - } - - @Deprecated - public AuthMe getPlugin() { - return instance; - } - - /** - * - * @param player - * @return true if player is authenticate - */ - @Deprecated - public static boolean isAuthenticated(Player player) { - return PlayerCache.getInstance().isAuthenticated(player.getName()); - } - - /** - * - * @param player - * @return true if player is a npc - */ - @Deprecated - public boolean isaNPC(Player player) { - return Utils.isNPC(player); - } - - /** - * - * @param player - * @return true if player is a npc - */ - @Deprecated - public boolean isNPC(Player player) { - return Utils.isNPC(player); - } - - /** - * - * @param player - * @return true if the player is unrestricted - */ - @Deprecated - public static boolean isUnrestricted(Player player) { - return Utils.isUnrestricted(player); - } - - @Deprecated - public static Location getLastLocation(Player player) { - try { - PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); - - if (auth != null) { - Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); - return loc; - } else { - return null; - } - - } catch (NullPointerException ex) { - return null; - } - } - - @Deprecated - public static void setPlayerInventory(Player player, ItemStack[] content, - ItemStack[] armor) { - try { - player.getInventory().setContents(content); - player.getInventory().setArmorContents(armor); - } catch (NullPointerException npe) { - } - } - - /** - * - * @param playerName - * @return true if player is registered - */ - @Deprecated - public static boolean isRegistered(String playerName) { - String player = playerName.toLowerCase(); - return instance.database.isAuthAvailable(player); - } - - /** - * @param String - * playerName, String passwordToCheck - * @return true if the password is correct , false else - */ - @Deprecated - public static boolean checkPassword(String playerName, - String passwordToCheck) { - if (!isRegistered(playerName)) - return false; - String player = playerName.toLowerCase(); - PlayerAuth auth = instance.database.getAuth(player); - try { - return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName); - } catch (NoSuchAlgorithmException e) { - return false; - } - } - - /** - * Register a player - * - * @param String - * playerName, String password - * @return true if the player is register correctly - */ - @Deprecated - public static boolean registerPlayer(String playerName, String password) { - try { - String name = playerName.toLowerCase(); - String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); - if (isRegistered(name)) { - return false; - } - PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com"); - if (!instance.database.saveAuth(auth)) { - return false; - } - return true; - } catch (NoSuchAlgorithmException ex) { - return false; - } - } - - /** - * Force a player to login - * - * @param Player - * player - */ - @Deprecated - public static void forceLogin(Player player) { - instance.management.performLogin(player, "dontneed", true); - } - -} +package fr.xephi.authme.api; + +import java.security.NoSuchAlgorithmException; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Settings; + +public class API { + + public static final String newline = System.getProperty("line.separator"); + public static AuthMe instance; + + @Deprecated + public API(AuthMe instance) { + API.instance = instance; + } + + /** + * Hook into AuthMe + * + * @return AuthMe instance + */ + @Deprecated + public static AuthMe hookAuthMe() { + if (instance != null) + return instance; + Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe"); + if (plugin == null || !(plugin instanceof AuthMe)) { + return null; + } + instance = (AuthMe) plugin; + return instance; + } + + @Deprecated + public AuthMe getPlugin() { + return instance; + } + + /** + * + * @param player + * @return true if player is authenticate + */ + @Deprecated + public static boolean isAuthenticated(Player player) { + return PlayerCache.getInstance().isAuthenticated(player.getName()); + } + + /** + * + * @param player + * @return true if player is a npc + */ + @Deprecated + public boolean isaNPC(Player player) { + return Utils.isNPC(player); + } + + /** + * + * @param player + * @return true if player is a npc + */ + @Deprecated + public boolean isNPC(Player player) { + return Utils.isNPC(player); + } + + /** + * + * @param player + * @return true if the player is unrestricted + */ + @Deprecated + public static boolean isUnrestricted(Player player) { + return Utils.isUnrestricted(player); + } + + @Deprecated + public static Location getLastLocation(Player player) { + try { + PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); + + if (auth != null) { + Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); + return loc; + } else { + return null; + } + + } catch (NullPointerException ex) { + return null; + } + } + + @Deprecated + public static void setPlayerInventory(Player player, ItemStack[] content, + ItemStack[] armor) { + try { + player.getInventory().setContents(content); + player.getInventory().setArmorContents(armor); + } catch (NullPointerException npe) { + } + } + + /** + * + * @param playerName + * @return true if player is registered + */ + @Deprecated + public static boolean isRegistered(String playerName) { + String player = playerName.toLowerCase(); + return instance.database.isAuthAvailable(player); + } + + /** + * @param String + * playerName, String passwordToCheck + * @return true if the password is correct , false else + */ + @Deprecated + public static boolean checkPassword(String playerName, + String passwordToCheck) { + if (!isRegistered(playerName)) + return false; + String player = playerName.toLowerCase(); + PlayerAuth auth = instance.database.getAuth(player); + try { + return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName); + } catch (NoSuchAlgorithmException e) { + return false; + } + } + + /** + * Register a player + * + * @param String + * playerName, String password + * @return true if the player is register correctly + */ + @Deprecated + public static boolean registerPlayer(String playerName, String password) { + try { + String name = playerName.toLowerCase(); + String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); + if (isRegistered(name)) { + return false; + } + PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName); + if (!instance.database.saveAuth(auth)) { + return false; + } + return true; + } catch (NoSuchAlgorithmException ex) { + return false; + } + } + + /** + * Force a player to login + * + * @param Player + * player + */ + @Deprecated + public static void forceLogin(Player player) { + instance.management.performLogin(player, "dontneed", true); + } + +} diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index ab7d7cb47..4a6eb301b 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -1,153 +1,153 @@ -package fr.xephi.authme.api; - -import java.security.NoSuchAlgorithmException; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.Utils; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.settings.Settings; - -public class NewAPI { - - public static final String newline = System.getProperty("line.separator"); - public static NewAPI singleton; - public AuthMe plugin; - - public NewAPI(AuthMe plugin) { - this.plugin = plugin; - } - - public NewAPI(Server serv) { - this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe"); - } - - /** - * Hook into AuthMe - * - * @return AuthMe plugin - */ - public static NewAPI getInstance() { - if (singleton != null) - return singleton; - Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe"); - if (p == null || !(p instanceof AuthMe)) { - return null; - } - AuthMe authme = (AuthMe) p; - singleton = (new NewAPI(authme)); - return singleton; - } - - public AuthMe getPlugin() { - return plugin; - } - - /** - * - * @param player - * @return true if player is authenticate - */ - public boolean isAuthenticated(Player player) { - return PlayerCache.getInstance().isAuthenticated(player.getName()); - } - - /** - * - * @param player - * @return true if player is a npc - */ - public boolean isNPC(Player player) { - return Utils.isNPC(player); - } - - /** - * - * @param player - * @return true if the player is unrestricted - */ - public boolean isUnrestricted(Player player) { - return Utils.isUnrestricted(player); - } - - public Location getLastLocation(Player player) { - try { - PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); - - if (auth != null) { - return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); - } else { - return null; - } - - } catch (NullPointerException ex) { - return null; - } - } - - /** - * - * @param playerName - * @return true if player is registered - */ - public boolean isRegistered(String playerName) { - String player = playerName.toLowerCase(); - return plugin.database.isAuthAvailable(player); - } - - /** - * @param String - * playerName, String passwordToCheck - * @return true if the password is correct , false else - */ - public boolean checkPassword(String playerName, String passwordToCheck) { - if (!isRegistered(playerName)) - return false; - String player = playerName.toLowerCase(); - PlayerAuth auth = plugin.database.getAuth(player); - try { - return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName); - } catch (NoSuchAlgorithmException e) { - return false; - } - } - - /** - * Register a player - * - * @param String - * playerName, String password - * @return true if the player is register correctly - */ - public boolean registerPlayer(String playerName, String password) { - try { - String name = playerName.toLowerCase(); - String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); - if (isRegistered(name)) { - return false; - } - PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com"); - return plugin.database.saveAuth(auth); - } catch (NoSuchAlgorithmException ex) { - return false; - } - } - - /** - * Force a player to login - * - * @param Player - * player - */ - public void forceLogin(Player player) { - plugin.management.performLogin(player, "dontneed", true); - } - -} +package fr.xephi.authme.api; + +import java.security.NoSuchAlgorithmException; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Settings; + +public class NewAPI { + + public static final String newline = System.getProperty("line.separator"); + public static NewAPI singleton; + public AuthMe plugin; + + public NewAPI(AuthMe plugin) { + this.plugin = plugin; + } + + public NewAPI(Server serv) { + this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe"); + } + + /** + * Hook into AuthMe + * + * @return AuthMe plugin + */ + public static NewAPI getInstance() { + if (singleton != null) + return singleton; + Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe"); + if (p == null || !(p instanceof AuthMe)) { + return null; + } + AuthMe authme = (AuthMe) p; + singleton = (new NewAPI(authme)); + return singleton; + } + + public AuthMe getPlugin() { + return plugin; + } + + /** + * + * @param player + * @return true if player is authenticate + */ + public boolean isAuthenticated(Player player) { + return PlayerCache.getInstance().isAuthenticated(player.getName()); + } + + /** + * + * @param player + * @return true if player is a npc + */ + public boolean isNPC(Player player) { + return Utils.isNPC(player); + } + + /** + * + * @param player + * @return true if the player is unrestricted + */ + public boolean isUnrestricted(Player player) { + return Utils.isUnrestricted(player); + } + + public Location getLastLocation(Player player) { + try { + PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); + + if (auth != null) { + return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); + } else { + return null; + } + + } catch (NullPointerException ex) { + return null; + } + } + + /** + * + * @param playerName + * @return true if player is registered + */ + public boolean isRegistered(String playerName) { + String player = playerName.toLowerCase(); + return plugin.database.isAuthAvailable(player); + } + + /** + * @param String + * playerName, String passwordToCheck + * @return true if the password is correct , false else + */ + public boolean checkPassword(String playerName, String passwordToCheck) { + if (!isRegistered(playerName)) + return false; + String player = playerName.toLowerCase(); + PlayerAuth auth = plugin.database.getAuth(player); + try { + return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName); + } catch (NoSuchAlgorithmException e) { + return false; + } + } + + /** + * Register a player + * + * @param String + * playerName, String password + * @return true if the player is register correctly + */ + public boolean registerPlayer(String playerName, String password) { + try { + String name = playerName.toLowerCase(); + String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); + if (isRegistered(name)) { + return false; + } + PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com", playerName); + return plugin.database.saveAuth(auth); + } catch (NoSuchAlgorithmException ex) { + return false; + } + } + + /** + * Force a player to login + * + * @param Player + * player + */ + public void forceLogin(Player player) { + plugin.management.performLogin(player, "dontneed", true); + } + +} diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index eab60353f..573d956fe 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -260,7 +260,7 @@ public class AdminCommand implements CommandExecutor { return; } String hash = PasswordSecurity.getHash(Settings.getPasswordHash, lowpass, name); - PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0L, "your@email.com"); + PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0L, "your@email.com", name); if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) auth.setSalt(PasswordSecurity.userSalt.get(name)); else auth.setSalt(""); diff --git a/src/main/java/fr/xephi/authme/commands/EmailCommand.java b/src/main/java/fr/xephi/authme/commands/EmailCommand.java index b81627ed4..241d543db 100644 --- a/src/main/java/fr/xephi/authme/commands/EmailCommand.java +++ b/src/main/java/fr/xephi/authme/commands/EmailCommand.java @@ -173,12 +173,9 @@ public class EmailCommand implements CommandExecutor { plugin.database.updatePassword(auth); plugin.mail.main(auth, thePass); m.send(player, "email_send"); - } catch (NoSuchAlgorithmException ex) { + } catch (NoSuchAlgorithmException | NoClassDefFoundError ex) { ConsoleLogger.showError(ex.getMessage()); m.send(sender, "error"); - } catch (NoClassDefFoundError ncdfe) { - ConsoleLogger.showError(ncdfe.getMessage()); - m.send(sender, "error"); } } else { m.send(player, "reg_email_msg"); diff --git a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java b/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java index 7ba5742af..c598f518d 100644 --- a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java +++ b/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java @@ -49,10 +49,10 @@ public class CrazyLoginConverter implements Converter { continue; if (args[0].equalsIgnoreCase("name")) continue; - String player = args[0].toLowerCase(); + String playerName = args[0].toLowerCase(); String psw = args[1]; if (psw != null) { - PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis(), player); + PlayerAuth auth = new PlayerAuth(playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName); database.saveAuth(auth); } } diff --git a/src/main/java/fr/xephi/authme/converter/RakamakConverter.java b/src/main/java/fr/xephi/authme/converter/RakamakConverter.java index 3f8cc0c0c..b2ddf704d 100644 --- a/src/main/java/fr/xephi/authme/converter/RakamakConverter.java +++ b/src/main/java/fr/xephi/authme/converter/RakamakConverter.java @@ -74,17 +74,17 @@ public class RakamakConverter implements Converter { } users.close(); for (Entry m : playerPSW.entrySet()) { - String player = m.getKey(); - String psw = playerPSW.get(player); + String playerName = m.getKey(); + String psw = playerPSW.get(playerName); String ip; if (useIP) { - ip = playerIP.get(player); + ip = playerIP.get(playerName); } else { ip = "127.0.0.1"; } - PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis(), player); - if (PasswordSecurity.userSalt.containsKey(player)) - auth.setSalt(PasswordSecurity.userSalt.get(player)); + PlayerAuth auth = new PlayerAuth(playerName, psw, ip, System.currentTimeMillis(), playerName); + if (PasswordSecurity.userSalt.containsKey(playerName)) + auth.setSalt(PasswordSecurity.userSalt.get(playerName)); database.saveAuth(auth); } ConsoleLogger.info("Rakamak database has been imported correctly"); diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java index 78a32aee9..4af9f1bde 100644 --- a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java +++ b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java @@ -30,7 +30,7 @@ public class RoyalAuthConverter implements Converter { if (!file.exists()) continue; RoyalAuthYamlReader ra = new RoyalAuthYamlReader(file); - PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com"); + PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName()); data.saveAuth(auth); } catch (Exception e) { ConsoleLogger.writeStackTrace(e); diff --git a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java index 0fb2c73e2..4a193e150 100644 --- a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java +++ b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java @@ -44,9 +44,9 @@ public class vAuthFileReader { } if (pname == null) continue; - auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com"); + auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", pname); } else { - auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com"); + auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name); } database.saveAuth(auth); } diff --git a/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java b/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java index 0c6d62fd0..d9823562e 100644 --- a/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java +++ b/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java @@ -47,7 +47,7 @@ public class xAuthToFlat { String pl = getIdPlayer(id); String psw = getPassword(id); if (psw != null && !psw.isEmpty() && pl != null) { - PlayerAuth auth = new PlayerAuth(pl, psw, "192.168.0.1", 0, "your@email.com"); + PlayerAuth auth = new PlayerAuth(pl, psw, "192.168.0.1", 0, "your@email.com", pl); database.saveAuth(auth); } } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 22fee78cd..0f3872b40 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -1,751 +1,750 @@ -package fr.xephi.authme.datasource; - -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.settings.Settings; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -public class FlatFile implements DataSource { - - /* - * file layout: - * - * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY:LASTPOSZ: - * LASTPOSWORLD:EMAIL - * - * Old but compatible: - * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY - * :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS - * PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM - */ - private File source; - - public FlatFile() { - source = Settings.AUTH_FILE; - try { - source.createNewFile(); - } catch (IOException e) { - ConsoleLogger.showError(e.getMessage()); - if (Settings.isStopEnabled) { - ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN..."); - AuthMe.getInstance().getServer().shutdown(); - } - if (!Settings.isStopEnabled) { - AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); - } - e.printStackTrace(); - } - } - - @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].equalsIgnoreCase(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 { - bw = new BufferedWriter(new FileWriter(source, true)); - bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n"); - } catch (IOException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - if (bw != null) { - try { - bw.close(); - } catch (IOException ex) { - } - } - } - return true; - } - - @Override - public synchronized boolean 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())) { - switch (args.length) { - case 4: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com", args[0]); - break; - } - case 7: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]); - break; - } - case 8: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); - break; - } - case 9: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); - break; - } - default: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com", args[0]); - break; - } - } - break; - } - } - } catch (FileNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } catch (IOException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { - } - } - } - if (newAuth != null) { - removeAuth(auth.getNickname()); - saveAuth(newAuth); - } - return true; - } - - @Override - public boolean updateSession(PlayerAuth auth) { - if (!isAuthAvailable(auth.getNickname())) { - return false; - } - PlayerAuth newAuth = null; - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(source)); - String line; - while ((line = br.readLine()) != null) { - String[] args = line.split(":"); - if (args[0].equalsIgnoreCase(auth.getNickname())) { - switch (args.length) { - case 4: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]); - break; - } - case 7: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]); - break; - } - case 8: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); - break; - } - case 9: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); - break; - } - default: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]); - break; - } - } - break; - } - } - } catch (FileNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } catch (IOException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { - } - } - } - if (newAuth != null) { - removeAuth(auth.getNickname()); - saveAuth(newAuth); - } - return true; - } - - @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].equalsIgnoreCase(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]); - break; - } - } - } catch (FileNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } catch (IOException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { - } - } - } - if (newAuth != null) { - removeAuth(auth.getNickname()); - saveAuth(newAuth); - } - return true; - } - - @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 List autoPurgeDatabase(long until) { - BufferedReader br = null; - BufferedWriter bw = null; - ArrayList lines = new ArrayList(); - List cleared = new ArrayList(); - 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.add(args[0]); - } - 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].equalsIgnoreCase(user)) { - switch (args.length) { - case 2: - return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]); - case 3: - return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0]); - case 4: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]); - case 7: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]); - case 8: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); - case 9: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); - } - } - } - } 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) { - if (!isAuthAvailable(auth.getNickname())) { - return false; - } - PlayerAuth newAuth = null; - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(source)); - String line = ""; - while ((line = br.readLine()) != null) { - String[] args = line.split(":"); - if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail(), args[0]); - break; - } - } - } catch (FileNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } catch (IOException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { - } - } - } - if (newAuth != null) { - removeAuth(auth.getNickname()); - saveAuth(newAuth); - } - return true; - } - - @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) { - BufferedReader br = null; - List countEmail = new ArrayList(); - try { - br = new BufferedReader(new FileReader(source)); - String line; - while ((line = br.readLine()) != null) { - String[] args = line.split(":"); - if (args.length > 8 && args[8].equals(email)) { - countEmail.add(args[0]); - } - } - return countEmail; - } 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 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; - } - - @Override - public DataSourceType getType() { - return DataSourceType.FILE; - } - - @Override - public boolean isLogged(String user) { - return PlayerCache.getInstance().isAuthenticated(user); - } - - @Override - public void setLogged(String user) { - } - - @Override - public void setUnlogged(String user) { - } - - @Override - public void purgeLogged() { - } - - @Override - public int getAccountsRegistered() { - BufferedReader br = null; - int result = 0; - try { - br = new BufferedReader(new FileReader(source)); - while ((br.readLine()) != null) { - result++; - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return result; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { - } - } - } - return result; - } - - @Override - public void updateName(String oldone, String newone) { - PlayerAuth auth = this.getAuth(oldone); - auth.setName(newone); - this.saveAuth(auth); - this.removeAuth(oldone); - } - - @Override - public List getAllAuths() { - BufferedReader br = null; - List auths = new ArrayList(); - try { - br = new BufferedReader(new FileReader(source)); - String line; - while ((line = br.readLine()) != null) { - String[] args = line.split(":"); - switch (args.length) { - case 2: - auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0])); - break; - case 3: - auths.add(new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0])); - break; - case 4: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0])); - break; - case 7: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0])); - break; - case 8: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0])); - break; - case 9: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0])); - break; - } - } - } catch (FileNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - return auths; - } catch (IOException ex) { - ConsoleLogger.showError(ex.getMessage()); - return auths; - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { - } - } - } - return auths; - } - - @Override - public List getLoggedPlayers() { - return new ArrayList(); - } -} +package fr.xephi.authme.datasource; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.settings.Settings; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class FlatFile implements DataSource { + + /* + * file layout: + * + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY:LASTPOSZ: + * LASTPOSWORLD:EMAIL + * + * Old but compatible: + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY + * :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS + * PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM + */ + private File source; + + public FlatFile() { + source = Settings.AUTH_FILE; + try { + source.createNewFile(); + } catch (IOException e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) { + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + } + e.printStackTrace(); + } + } + + @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].equalsIgnoreCase(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 { + bw = new BufferedWriter(new FileWriter(source, true)); + bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n"); + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + if (bw != null) { + try { + bw.close(); + } catch (IOException ex) { + } + } + } + return true; + } + + @Override + public synchronized boolean 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())) { + switch (args.length) { + case 4: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com", args[0]); + break; + } + case 7: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]); + break; + } + case 8: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); + break; + } + case 9: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); + break; + } + default: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com", args[0]); + break; + } + } + break; + } + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + if (newAuth != null) { + removeAuth(auth.getNickname()); + saveAuth(newAuth); + } + return true; + } + + @Override + public boolean updateSession(PlayerAuth auth) { + if (!isAuthAvailable(auth.getNickname())) { + return false; + } + PlayerAuth newAuth = null; + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args[0].equalsIgnoreCase(auth.getNickname())) { + switch (args.length) { + case 4: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]); + break; + } + case 7: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]); + break; + } + case 8: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); + break; + } + case 9: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); + break; + } + default: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]); + break; + } + } + break; + } + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + if (newAuth != null) { + removeAuth(auth.getNickname()); + saveAuth(newAuth); + } + return true; + } + + @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].equalsIgnoreCase(auth.getNickname())) { + newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]); + break; + } + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + if (newAuth != null) { + removeAuth(auth.getNickname()); + saveAuth(newAuth); + } + return true; + } + + @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 List autoPurgeDatabase(long until) { + BufferedReader br = null; + BufferedWriter bw = null; + ArrayList lines = new ArrayList<>(); + List cleared = new ArrayList<>(); + 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.add(args[0]); + } + 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].equalsIgnoreCase(user)) { + switch (args.length) { + case 2: + return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]); + case 3: + return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0]); + case 4: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]); + case 7: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]); + case 8: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); + case 9: + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); + } + } + } + } 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) { + if (!isAuthAvailable(auth.getNickname())) { + return false; + } + PlayerAuth newAuth = null; + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(source)); + String line = ""; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args[0].equals(auth.getNickname())) { + newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail(), args[0]); + break; + } + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + if (newAuth != null) { + removeAuth(auth.getNickname()); + saveAuth(newAuth); + } + return true; + } + + @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) { + BufferedReader br = null; + List countEmail = new ArrayList<>(); + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args.length > 8 && args[8].equals(email)) { + countEmail.add(args[0]); + } + } + return countEmail; + } 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 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 | ArrayIndexOutOfBoundsException exc) { + } + } + 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; + } + + @Override + public DataSourceType getType() { + return DataSourceType.FILE; + } + + @Override + public boolean isLogged(String user) { + return PlayerCache.getInstance().isAuthenticated(user); + } + + @Override + public void setLogged(String user) { + } + + @Override + public void setUnlogged(String user) { + } + + @Override + public void purgeLogged() { + } + + @Override + public int getAccountsRegistered() { + BufferedReader br = null; + int result = 0; + try { + br = new BufferedReader(new FileReader(source)); + while ((br.readLine()) != null) { + result++; + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return result; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + return result; + } + + @Override + public void updateName(String oldone, String newone) { + PlayerAuth auth = this.getAuth(oldone); + auth.setName(newone); + this.saveAuth(auth); + this.removeAuth(oldone); + } + + @Override + public List getAllAuths() { + BufferedReader br = null; + List auths = new ArrayList<>(); + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + switch (args.length) { + case 2: + auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0])); + break; + case 3: + auths.add(new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0])); + break; + case 4: + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0])); + break; + case 7: + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0])); + break; + case 8: + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0])); + break; + case 9: + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0])); + break; + } + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + } + return auths; + } + + @Override + public List getLoggedPlayers() { + return new ArrayList<>(); + } +} diff --git a/src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java b/src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java index 673d74505..cd422b48c 100644 --- a/src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java @@ -32,9 +32,7 @@ public class EssSpawn extends CustomConfiguration { return null; Location location = new Location(Bukkit.getWorld(this.getString("spawns.default.world")), this.getDouble("spawns.default.x"), this.getDouble("spawns.default.y"), this.getDouble("spawns.default.z"), Float.parseFloat(this.getString("spawns.default.yaw")), Float.parseFloat(this.getString("spawns.default.pitch"))); return location; - } catch (NullPointerException npe) { - return null; - } catch (NumberFormatException nfe) { + } catch (NullPointerException | NumberFormatException npe) { return null; } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java index d9f500841..25d9897b6 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java @@ -33,10 +33,10 @@ public class PHPFUSION implements EncryptionMethod { hash.append(hex); } digest = hash.toString(); - } catch (UnsupportedEncodingException e) { - } catch (InvalidKeyException e) { - } catch (NoSuchAlgorithmException e) { + } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { + //ingore } + return digest; } diff --git a/src/main/java/fr/xephi/authme/security/crypts/XF.java b/src/main/java/fr/xephi/authme/security/crypts/XF.java index 54ba70357..b6ad9bde8 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/XF.java +++ b/src/main/java/fr/xephi/authme/security/crypts/XF.java @@ -44,7 +44,7 @@ public class XF implements EncryptionMethod { } public String regmatch(String pattern, String line) { - List allMatches = new ArrayList(); + List allMatches = new ArrayList<>(); Matcher m = Pattern.compile(pattern).matcher(line); while (m.find()) { allMatches.add(m.group(1)); diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java index 27f8bc0c6..b7d803826 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java @@ -9,7 +9,7 @@ import javax.crypto.spec.SecretKeySpec; /** * Default PRF implementation based on standard javax.crypt.Mac mechanisms. - * + * *
*

* A free Java implementation of Password Based Key Derivation Function 2 as @@ -37,7 +37,7 @@ import javax.crypto.spec.SecretKeySpec; * href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html" * >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. *

- * + * * @author Matthias Gärtner * @version 1.0 */ @@ -51,7 +51,7 @@ public class MacBasedPRF implements PRF { /** * Create Mac-based Pseudo Random Function. - * + * * @param macAlgorithm * Mac algorithm to use, i.e. HMacSHA1 or HMacMD5. */ @@ -70,9 +70,7 @@ public class MacBasedPRF implements PRF { try { mac = Mac.getInstance(macAlgorithm, provider); hLen = mac.getMacLength(); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } catch (NoSuchProviderException e) { + } catch (NoSuchAlgorithmException | NoSuchProviderException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java index 4da7b677c..697104d49 100644 --- a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java +++ b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java @@ -44,8 +44,8 @@ public class OtherAccounts extends CustomConfiguration { this.getStringList(uuid.toString()).add(player.getName()); save(); } - } catch (NoSuchMethodError e) { - } catch (Exception e) { + } catch (NoSuchMethodError | Exception e) { + //ingore } } @@ -58,10 +58,9 @@ public class OtherAccounts extends CustomConfiguration { this.getStringList(uuid.toString()).remove(player.getName()); save(); } - } catch (NoSuchMethodError e) { - } catch (Exception e) { + } catch (NoSuchMethodError | Exception e) { + //ignore } - } public List getAllPlayersByUUID(UUID uuid) { diff --git a/src/main/java/fr/xephi/authme/settings/Spawn.java b/src/main/java/fr/xephi/authme/settings/Spawn.java index 6827387af..81b0891e6 100644 --- a/src/main/java/fr/xephi/authme/settings/Spawn.java +++ b/src/main/java/fr/xephi/authme/settings/Spawn.java @@ -90,9 +90,7 @@ public class Spawn extends CustomConfiguration { return null; Location location = new Location(Bukkit.getWorld(this.getString("spawn.world")), this.getDouble("spawn.x"), this.getDouble("spawn.y"), this.getDouble("spawn.z"), Float.parseFloat(this.getString("spawn.yaw")), Float.parseFloat(this.getString("spawn.pitch"))); return location; - } catch (NullPointerException npe) { - return null; - } catch (NumberFormatException nfe) { + } catch (NullPointerException | NumberFormatException npe) { return null; } } @@ -103,9 +101,7 @@ public class Spawn extends CustomConfiguration { return null; Location location = new Location(Bukkit.getWorld(this.getString("firstspawn.world")), this.getDouble("firstspawn.x"), this.getDouble("firstspawn.y"), this.getDouble("firstspawn.z"), Float.parseFloat(this.getString("firstspawn.yaw")), Float.parseFloat(this.getString("firstspawn.pitch"))); return location; - } catch (NullPointerException npe) { - return null; - } catch (NumberFormatException nfe) { + } catch (NullPointerException | NumberFormatException npe) { return null; } }