From 03bfe80ee2704ca68e659553c3f654b9cd192900 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Tue, 21 Jul 2015 01:13:27 +0200 Subject: [PATCH 1/6] Set SQLite as default database and convert actual flat to sqlite --- src/main/java/fr/xephi/authme/AuthMe.java | 11 ++++-- .../authme/commands/ConverterCommand.java | 5 --- .../xephi/authme/converter/FlatToSqlite.java | 23 ++++++------ .../authme/converter/ForceFlatToSqlite.java | 35 +++++++++++++++++++ .../authme/listener/AuthMePlayerListener.java | 5 +-- .../fr/xephi/authme/settings/Settings.java | 5 +++ 6 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 5bbcac601..f9434a76f 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -51,6 +51,8 @@ import fr.xephi.authme.commands.LogoutCommand; import fr.xephi.authme.commands.PasspartuCommand; import fr.xephi.authme.commands.RegisterCommand; import fr.xephi.authme.commands.UnregisterCommand; +import fr.xephi.authme.converter.Converter; +import fr.xephi.authme.converter.ForceFlatToSqlite; import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DatabaseCalls; @@ -766,8 +768,6 @@ public class AuthMe extends JavaPlugin { switch (Settings.getDataSource) { case FILE: database = new FlatFile(); - final int a = database.getAccountsRegistered(); - ConsoleLogger.showError("YOU'RE USING THE FILE BACKEND WITH " + a + "+ ACCOUNTS, YOU SHOULD NEVER USE THIS, PLEASE UPGRADE TO SQLITE!!!"); break; case MYSQL: database = new MySQL(); @@ -785,5 +785,12 @@ public class AuthMe extends JavaPlugin { } database = new DatabaseCalls(database); + + if (Settings.getDataSource == DataSource.DataSourceType.FILE) { + Converter converter = new ForceFlatToSqlite(database, this); + Bukkit.getScheduler().runTaskAsynchronously(this, converter); + ConsoleLogger.showError("FlatFile backend as been detected and is now deprecated, next time server startup, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performances !"); + ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart"); + } } } diff --git a/src/main/java/fr/xephi/authme/commands/ConverterCommand.java b/src/main/java/fr/xephi/authme/commands/ConverterCommand.java index 3da052a04..56deecdf3 100644 --- a/src/main/java/fr/xephi/authme/commands/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/ConverterCommand.java @@ -4,7 +4,6 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import fr.xephi.authme.AuthMe; import fr.xephi.authme.converter.Converter; @@ -30,10 +29,6 @@ public class ConverterCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmnd, String label, final String[] args) { - if (!(sender instanceof Player)) { - return true; - } - if (!plugin.authmePermissible(sender, "authme.admin.converter")) { m.send(sender, "no_perm"); return true; diff --git a/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java index 1a662bec7..cbcb283a1 100644 --- a/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java @@ -39,6 +39,8 @@ public class FlatToSqlite implements Converter { private static File source; private static String database; private static String columnID; + private static String columnSalt; + private static String columnGroup; private static Connection con; @Override @@ -49,23 +51,20 @@ public class FlatToSqlite implements Converter { columnPassword = Settings.getMySQLColumnPassword; columnIp = Settings.getMySQLColumnIp; columnLastLogin = Settings.getMySQLColumnLastLogin; + columnSalt = Settings.getMySQLColumnSalt; + columnGroup = Settings.getMySQLColumnGroup; lastlocX = Settings.getMySQLlastlocX; lastlocY = Settings.getMySQLlastlocY; lastlocZ = Settings.getMySQLlastlocZ; lastlocWorld = Settings.getMySQLlastlocWorld; columnEmail = Settings.getMySQLColumnEmail; columnID = Settings.getMySQLColumnId; - ConsoleLogger.info("Converting FlatFile to SQLite ..."); - if (new File(AuthMe.getInstance().getDataFolder() + File.separator + database + ".db").exists()) { - sender.sendMessage("The Database " + database + ".db can't be created cause the file already exist"); - return; - } + try { connect(); setup(); } catch (Exception e) { - ConsoleLogger.showError("Problem while trying to convert to sqlite !"); - sender.sendMessage("Problem while trying to convert to sqlite !"); + sender.sendMessage("Some error appears while trying to setup and connect to sqlite database... Aborting"); return; } try { @@ -107,7 +106,6 @@ public class FlatToSqlite implements Converter { private synchronized static void connect() throws ClassNotFoundException, SQLException { Class.forName("org.sqlite.JDBC"); - ConsoleLogger.info("SQLite driver loaded"); con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db"); } @@ -116,7 +114,7 @@ public class FlatToSqlite implements Converter { 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 + "));"); + 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 + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + 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;"); @@ -134,12 +132,14 @@ public class FlatToSqlite implements Converter { 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';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); } 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 + ";"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';"); } rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); @@ -150,7 +150,6 @@ public class FlatToSqlite implements Converter { close(rs); close(st); } - ConsoleLogger.info("SQLite Setup finished"); } private static synchronized boolean saveAuth(String s) { diff --git a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java new file mode 100644 index 000000000..007f95415 --- /dev/null +++ b/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java @@ -0,0 +1,35 @@ +package fr.xephi.authme.converter; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.SQLite; + +public class ForceFlatToSqlite implements Converter { + + private DataSource data; + private AuthMe plugin; + + public ForceFlatToSqlite(DataSource data, AuthMe plugin) { + this.data = data; + this.plugin = plugin; + } + + @Override + public void run() { + DataSource sqlite = null; + try { + sqlite = new SQLite(); + for (PlayerAuth auth : data.getAllAuths()) + sqlite.saveAuth(auth); + plugin.getSettings().setValue("DataSource.backend", "sqlite"); + ConsoleLogger.info("Database successfully converted to sqlite !"); + } catch (Exception e) { + ConsoleLogger.showError("An error appears while trying to convert flatfile ..."); + } finally { + if (sqlite != null) + sqlite.close(); + } + } +} diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index b0aaf5ed1..6b42f2e29 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -5,6 +5,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -407,7 +408,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (player.isBanned()) + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) return; if (Settings.enablePasspartu && !Settings.countriesBlacklist.isEmpty()) { @@ -460,7 +461,7 @@ public class AuthMePlayerListener implements Listener { String regex = Settings.getNickRegex; if (name.length() > max || name.length() < min) { - event.setKickMessage(m.send("name_len")[0]); + event.setKickMessage(Arrays.toString(m.send("name_len"))); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index abd5e45f0..fe1f34eae 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -602,6 +602,11 @@ public final class Settings extends YamlConfiguration { return; } + public void setValue(String key, Object value) { + this.set(key, value); + this.save(); + } + private static HashAlgorithm getPasswordHash() { String key = "settings.security.passwordHash"; try { From 8b48e936fbf165028034e2a25174d83e05ebd734 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Tue, 21 Jul 2015 01:17:24 +0200 Subject: [PATCH 2/6] Use our own thread --- src/main/java/fr/xephi/authme/AuthMe.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index f9434a76f..1c2d964bd 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -788,7 +788,8 @@ public class AuthMe extends JavaPlugin { if (Settings.getDataSource == DataSource.DataSourceType.FILE) { Converter converter = new ForceFlatToSqlite(database, this); - Bukkit.getScheduler().runTaskAsynchronously(this, converter); + Thread t = new Thread(converter); + t.start(); ConsoleLogger.showError("FlatFile backend as been detected and is now deprecated, next time server startup, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performances !"); ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart"); } From f0eed86155008d71fea00befde7f625044a15e55 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Tue, 21 Jul 2015 17:32:53 +0200 Subject: [PATCH 3/6] Deprecated this method, V2 of verygames already include this --- src/main/java/fr/xephi/authme/AuthMe.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 1c2d964bd..e9ef82b98 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -744,6 +744,7 @@ public class AuthMe extends JavaPlugin { * @param Player * player */ + @Deprecated public String getVeryGamesIP(Player player) { String realIP = player.getAddress().getAddress().getHostAddress(); String sUrl = vgUrl; @@ -788,8 +789,11 @@ public class AuthMe extends JavaPlugin { if (Settings.getDataSource == DataSource.DataSourceType.FILE) { Converter converter = new ForceFlatToSqlite(database, this); - Thread t = new Thread(converter); - t.start(); + try { + Thread t = new Thread(converter); + t.start(); + } catch (Exception e) { + } ConsoleLogger.showError("FlatFile backend as been detected and is now deprecated, next time server startup, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performances !"); ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart"); } From 82ed191a999b06af81095fb794df81f4d97173b7 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Tue, 21 Jul 2015 18:39:45 +0200 Subject: [PATCH 4/6] Re-set this, some problem with Class not added correctly --- pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4027120f4..9fcaa4c69 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,7 @@ com.maxmind.geoip:* javax.mail:* + com.sun.mail:* com.comphenix.attribute:* org.mcstats.*:* @@ -188,8 +189,8 @@ - javax.mail - javax.mail-api + com.sun.mail + javax.mail 1.5.4 From ef5a2462bcb621ccbfbb62baa25953652f9c0e46 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Wed, 22 Jul 2015 02:03:10 +0200 Subject: [PATCH 5/6] English syntax --- src/main/java/fr/xephi/authme/AuthMe.java | 2 +- src/main/java/fr/xephi/authme/converter/FlatToSqlite.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index e9ef82b98..d8a550bef 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -794,7 +794,7 @@ public class AuthMe extends JavaPlugin { t.start(); } catch (Exception e) { } - ConsoleLogger.showError("FlatFile backend as been detected and is now deprecated, next time server startup, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performances !"); + ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, next time server starts up, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performance !"); ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart"); } } diff --git a/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java index cbcb283a1..057b16f6b 100644 --- a/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java @@ -64,7 +64,7 @@ public class FlatToSqlite implements Converter { connect(); setup(); } catch (Exception e) { - sender.sendMessage("Some error appears while trying to setup and connect to sqlite database... Aborting"); + sender.sendMessage("Some error appeared while trying to setup and connect to sqlite database... Aborting"); return; } try { From 4ecfffd8cf483b83f2d6ec8ecf0edb0e13d52985 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Wed, 22 Jul 2015 02:04:43 +0200 Subject: [PATCH 6/6] English Syntax #2 --- src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java index 007f95415..44034a49c 100644 --- a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java @@ -26,7 +26,7 @@ public class ForceFlatToSqlite implements Converter { plugin.getSettings().setValue("DataSource.backend", "sqlite"); ConsoleLogger.info("Database successfully converted to sqlite !"); } catch (Exception e) { - ConsoleLogger.showError("An error appears while trying to convert flatfile ..."); + ConsoleLogger.showError("An error appeared while trying to convert flatfile to sqlite ..."); } finally { if (sqlite != null) sqlite.close();