Code Refactor - Whitespace Refactor
This commit is contained in:
@@ -14,65 +14,69 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class CrazyLoginConverter implements Converter {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public CrazyLoginConverter (AuthMe instance, DataSource database, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
public CrazyLoginConverter(AuthMe instance, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public CrazyLoginConverter getInstance() {
|
||||
return this;
|
||||
}
|
||||
public CrazyLoginConverter getInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private static String fileName;
|
||||
private static File source;
|
||||
private static String fileName;
|
||||
private static File source;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fileName = Settings.crazyloginFileName;
|
||||
@Override
|
||||
public void run() {
|
||||
fileName = Settings.crazyloginFileName;
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
|
||||
source = new File(AuthMe.getInstance().getDataFolder()
|
||||
+ File.separator + fileName);
|
||||
if (!source.exists()) {
|
||||
sender.sendMessage("Error while trying to import datas, please put " + fileName + " in AuthMe folder!");
|
||||
sender.sendMessage("Error while trying to import datas, please put "
|
||||
+ fileName + " in AuthMe folder!");
|
||||
return;
|
||||
}
|
||||
source.createNewFile();
|
||||
BufferedReader users = null;
|
||||
String line;
|
||||
BufferedReader users = null;
|
||||
String line;
|
||||
users = new BufferedReader(new FileReader(source));
|
||||
while ((line = users.readLine()) != null) {
|
||||
if (line.contains("|")) {
|
||||
String[] args = line.split("\\|");
|
||||
if (args.length < 2)
|
||||
continue;
|
||||
if (args[0].equalsIgnoreCase("name"))
|
||||
continue;
|
||||
if (line.contains("|")) {
|
||||
String[] args = line.split("\\|");
|
||||
if (args.length < 2) continue;
|
||||
if (args[0].equalsIgnoreCase("name")) continue;
|
||||
String player = args[0].toLowerCase();
|
||||
String psw = args[1];
|
||||
try {
|
||||
if (player != null && psw != null) {
|
||||
PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis());
|
||||
PlayerAuth auth = new PlayerAuth(player, psw,
|
||||
"127.0.0.1", System.currentTimeMillis());
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
users.close();
|
||||
ConsoleLogger.info("CrazyLogin database has been imported correctly");
|
||||
ConsoleLogger
|
||||
.info("CrazyLogin database has been imported correctly");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,11 +12,10 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class FlatToSql implements Converter {
|
||||
|
||||
private static String tableName;
|
||||
@@ -31,73 +30,103 @@ public class FlatToSql implements Converter {
|
||||
private static String columnEmail;
|
||||
private static String columnLogged;
|
||||
private static String columnID;
|
||||
private static File source;
|
||||
private static File output;
|
||||
private static File source;
|
||||
private static File output;
|
||||
|
||||
public FlatToSql() {
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
columnPassword = Settings.getMySQLColumnPassword;
|
||||
columnIp = Settings.getMySQLColumnIp;
|
||||
columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||
lastlocX = Settings.getMySQLlastlocX;
|
||||
lastlocY = Settings.getMySQLlastlocY;
|
||||
lastlocZ = Settings.getMySQLlastlocZ;
|
||||
lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||
columnEmail = Settings.getMySQLColumnEmail;
|
||||
columnLogged = Settings.getMySQLColumnLogged;
|
||||
columnID = Settings.getMySQLColumnId;
|
||||
}
|
||||
public FlatToSql() {
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
columnPassword = Settings.getMySQLColumnPassword;
|
||||
columnIp = Settings.getMySQLColumnIp;
|
||||
columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||
lastlocX = Settings.getMySQLlastlocX;
|
||||
lastlocY = Settings.getMySQLlastlocY;
|
||||
lastlocZ = Settings.getMySQLlastlocZ;
|
||||
lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||
columnEmail = Settings.getMySQLColumnEmail;
|
||||
columnLogged = Settings.getMySQLColumnLogged;
|
||||
columnID = Settings.getMySQLColumnId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source = new File(AuthMe.getInstance().getDataFolder()
|
||||
+ File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
output = new File(AuthMe.getInstance().getDataFolder() + File.separator + "authme.sql");
|
||||
BufferedReader br = null;
|
||||
BufferedWriter sql = null;
|
||||
output = new File(AuthMe.getInstance().getDataFolder()
|
||||
+ File.separator + "authme.sql");
|
||||
BufferedReader br = null;
|
||||
BufferedWriter sql = null;
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
sql = new BufferedWriter(new FileWriter(output));
|
||||
String createDB = "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 DEFAULT '127.0.0.1',"
|
||||
+ columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "',"
|
||||
+ lastlocX + " DOUBLE NOT NULL DEFAULT '0.0',"
|
||||
+ lastlocY + " DOUBLE NOT NULL DEFAULT '0.0',"
|
||||
+ lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0',"
|
||||
+ lastlocWorld + " VARCHAR(255) DEFAULT 'world',"
|
||||
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com',"
|
||||
+ columnLogged + " SMALLINT NOT NULL DEFAULT '0',"
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));";
|
||||
+ columnID + " INTEGER AUTO_INCREMENT," + columnName
|
||||
+ " VARCHAR(255) NOT NULL UNIQUE," + columnPassword
|
||||
+ " VARCHAR(255) NOT NULL," + columnIp
|
||||
+ " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1',"
|
||||
+ columnLastLogin + " BIGINT NOT NULL DEFAULT '"
|
||||
+ System.currentTimeMillis() + "'," + lastlocX
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld
|
||||
+ " VARCHAR(255) DEFAULT 'world'," + columnEmail
|
||||
+ " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged
|
||||
+ " SMALLINT NOT NULL DEFAULT '0',"
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID
|
||||
+ "));";
|
||||
sql.write(createDB);
|
||||
String line;
|
||||
String newline;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sql.newLine();
|
||||
sql.newLine();
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0.0, 0.0, 0.0, 'world', 'your@email.com', 0);";
|
||||
else if (args.length == 7)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com', 0);";
|
||||
else if (args.length == 8)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com', 0);";
|
||||
else if (args.length == 9)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', '" + args[8] + "', 0);";
|
||||
else
|
||||
newline = "";
|
||||
if (newline != "")
|
||||
sql.write(newline);
|
||||
if (args.length == 4) newline = "INSERT INTO " + tableName
|
||||
+ "(" + columnName + "," + columnPassword + ","
|
||||
+ columnIp + "," + columnLastLogin + "," + lastlocX
|
||||
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
|
||||
+ "," + columnEmail + "," + columnLogged
|
||||
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
|
||||
+ args[2] + "', " + args[3]
|
||||
+ ", 0.0, 0.0, 0.0, 'world', 'your@email.com', 0);";
|
||||
else if (args.length == 7) newline = "INSERT INTO " + tableName
|
||||
+ "(" + columnName + "," + columnPassword + ","
|
||||
+ columnIp + "," + columnLastLogin + "," + lastlocX
|
||||
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
|
||||
+ "," + columnEmail + "," + columnLogged
|
||||
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
|
||||
+ args[2] + "', " + args[3] + ", " + args[4] + ", "
|
||||
+ args[5] + ", " + args[6]
|
||||
+ ", 'world', 'your@email.com', 0);";
|
||||
else if (args.length == 8) newline = "INSERT INTO " + tableName
|
||||
+ "(" + columnName + "," + columnPassword + ","
|
||||
+ columnIp + "," + columnLastLogin + "," + lastlocX
|
||||
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
|
||||
+ "," + columnEmail + "," + columnLogged
|
||||
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
|
||||
+ args[2] + "', " + args[3] + ", " + args[4] + ", "
|
||||
+ args[5] + ", " + args[6] + ", '" + args[7]
|
||||
+ "', 'your@email.com', 0);";
|
||||
else if (args.length == 9) newline = "INSERT INTO " + tableName
|
||||
+ "(" + columnName + "," + columnPassword + ","
|
||||
+ columnIp + "," + columnLastLogin + "," + lastlocX
|
||||
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
|
||||
+ "," + columnEmail + "," + columnLogged
|
||||
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
|
||||
+ args[2] + "', " + args[3] + ", " + args[4] + ", "
|
||||
+ args[5] + ", " + args[6] + ", '" + args[7] + "', '"
|
||||
+ args[8] + "', 0);";
|
||||
else newline = "";
|
||||
if (newline != "") sql.write(newline);
|
||||
}
|
||||
sql.close();
|
||||
br.close();
|
||||
ConsoleLogger.info("The FlatFile has been converted to authme.sql file");
|
||||
ConsoleLogger
|
||||
.info("The FlatFile has been converted to authme.sql file");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,8 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
public class FlatToSqlite implements Converter {
|
||||
|
||||
|
||||
public CommandSender sender;
|
||||
|
||||
public FlatToSqlite(CommandSender sender) {
|
||||
@@ -37,13 +36,13 @@ public class FlatToSqlite implements Converter {
|
||||
private static String lastlocZ;
|
||||
private static String lastlocWorld;
|
||||
private static String columnEmail;
|
||||
private static File source;
|
||||
private static String database;
|
||||
private static String columnID;
|
||||
private static Connection con;
|
||||
private static File source;
|
||||
private static String database;
|
||||
private static String columnID;
|
||||
private static Connection con;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
database = Settings.getMySQLDatabase;
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
@@ -56,60 +55,77 @@ public class FlatToSqlite implements Converter {
|
||||
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;
|
||||
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 !");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
BufferedReader br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
int i = 1;
|
||||
String newline;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0, 0, 0, 'world', 'your@email.com');";
|
||||
else if (args.length == 7)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com');";
|
||||
else if (args.length == 8)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com');";
|
||||
else if (args.length == 9)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', '" + args[8] + "');";
|
||||
else
|
||||
newline = "";
|
||||
if (newline != "")
|
||||
saveAuth(newline);
|
||||
i = i + 1;
|
||||
}
|
||||
br.close();
|
||||
ConsoleLogger.info("The FlatFile has been converted to " + database + ".db file");
|
||||
close();
|
||||
sender.sendMessage("The FlatFile has been converted to " + database + ".db file");
|
||||
return;
|
||||
} catch (FileNotFoundException ex) {
|
||||
connect();
|
||||
setup();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger
|
||||
.showError("Problem while trying to convert to sqlite !");
|
||||
sender.sendMessage("Problem while trying to convert to sqlite !");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder()
|
||||
+ File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
BufferedReader br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
int i = 1;
|
||||
String newline;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4) newline = "INSERT INTO " + tableName
|
||||
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
|
||||
+ "', '" + args[2] + "', " + args[3]
|
||||
+ ", 0, 0, 0, 'world', 'your@email.com');";
|
||||
else if (args.length == 7) newline = "INSERT INTO " + tableName
|
||||
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
|
||||
+ "', '" + args[2] + "', " + args[3] + ", " + args[4]
|
||||
+ ", " + args[5] + ", " + args[6]
|
||||
+ ", 'world', 'your@email.com');";
|
||||
else if (args.length == 8) newline = "INSERT INTO " + tableName
|
||||
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
|
||||
+ "', '" + args[2] + "', " + args[3] + ", " + args[4]
|
||||
+ ", " + args[5] + ", " + args[6] + ", '" + args[7]
|
||||
+ "', 'your@email.com');";
|
||||
else if (args.length == 9) newline = "INSERT INTO " + tableName
|
||||
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
|
||||
+ "', '" + args[2] + "', " + args[3] + ", " + args[4]
|
||||
+ ", " + args[5] + ", " + args[6] + ", '" + args[7]
|
||||
+ "', '" + args[8] + "');";
|
||||
else newline = "";
|
||||
if (newline != "") saveAuth(newline);
|
||||
i = i + 1;
|
||||
}
|
||||
br.close();
|
||||
ConsoleLogger.info("The FlatFile has been converted to " + database
|
||||
+ ".db file");
|
||||
close();
|
||||
sender.sendMessage("The FlatFile has been converted to " + database
|
||||
+ ".db file");
|
||||
return;
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
sender.sendMessage("Errors appears while trying to convert to SQLite");
|
||||
return;
|
||||
}
|
||||
|
||||
private synchronized static void connect() throws ClassNotFoundException, SQLException {
|
||||
}
|
||||
|
||||
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");
|
||||
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/"
|
||||
+ database + ".db");
|
||||
}
|
||||
|
||||
private synchronized static void setup() throws SQLException {
|
||||
@@ -118,18 +134,19 @@ public class FlatToSqlite implements Converter {
|
||||
try {
|
||||
st = con.createStatement();
|
||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ columnID + " INTEGER AUTO_INCREMENT,"
|
||||
+ columnName + " VARCHAR(255) NOT NULL UNIQUE,"
|
||||
+ columnPassword + " VARCHAR(255) NOT NULL,"
|
||||
+ columnIp + " VARCHAR(40) NOT NULL,"
|
||||
+ columnLastLogin + " BIGINT,"
|
||||
+ lastlocX + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocY + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocZ + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocWorld + " VARCHAR(255) DEFAULT 'world',"
|
||||
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com',"
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||
+ columnID + " INTEGER AUTO_INCREMENT," + columnName
|
||||
+ " VARCHAR(255) NOT NULL UNIQUE," + columnPassword
|
||||
+ " VARCHAR(255) NOT NULL," + columnIp
|
||||
+ " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT,"
|
||||
+ lastlocX + " smallint(6) DEFAULT '0'," + lastlocY
|
||||
+ " smallint(6) DEFAULT '0'," + lastlocZ
|
||||
+ " smallint(6) DEFAULT '0'," + lastlocWorld
|
||||
+ " VARCHAR(255) DEFAULT 'world'," + columnEmail
|
||||
+ " VARCHAR(255) DEFAULT 'your@email.com',"
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID
|
||||
+ "));");
|
||||
rs = con.getMetaData().getColumns(null, null, tableName,
|
||||
columnPassword);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ columnPassword + " VARCHAR(255) NOT NULL;");
|
||||
@@ -141,7 +158,8 @@ public class FlatToSqlite implements Converter {
|
||||
+ columnIp + " VARCHAR(40) NOT NULL;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
|
||||
rs = con.getMetaData().getColumns(null, null, tableName,
|
||||
columnLastLogin);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ columnLastLogin + " BIGINT;");
|
||||
@@ -149,19 +167,29 @@ 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 + " smallint(6) NOT NULL DEFAULT '0'; "
|
||||
+ "ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ lastlocY + " smallint(6) NOT NULL DEFAULT '0'; "
|
||||
+ "ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ lastlocZ + " smallint(6) NOT NULL DEFAULT '0';");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld);
|
||||
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' AFTER "
|
||||
+ lastlocZ + ";");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail);
|
||||
rs = con.getMetaData().getColumns(null, null, tableName,
|
||||
columnEmail);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';");
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ columnEmail
|
||||
+ " VARCHAR(255) DEFAULT 'your@email.com';");
|
||||
}
|
||||
} finally {
|
||||
close(rs);
|
||||
@@ -169,21 +197,21 @@ public class FlatToSqlite implements Converter {
|
||||
}
|
||||
ConsoleLogger.info("SQLite Setup finished");
|
||||
}
|
||||
|
||||
|
||||
private static synchronized boolean saveAuth(String s) {
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
pst = con.prepareStatement(s);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return true;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
pst = con.prepareStatement(s);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static void close(Statement st) {
|
||||
if (st != null) {
|
||||
try {
|
||||
@@ -203,7 +231,7 @@ public class FlatToSqlite implements Converter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized static void close() {
|
||||
try {
|
||||
con.close();
|
||||
|
||||
@@ -20,86 +20,91 @@ import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class RakamakConverter implements Converter {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public RakamakConverter (AuthMe instance, DataSource database, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
public RakamakConverter(AuthMe instance, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public RakamakConverter getInstance() {
|
||||
return this;
|
||||
}
|
||||
public RakamakConverter getInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private static Boolean useIP;
|
||||
private static String fileName;
|
||||
private static String ipFileName;
|
||||
private static File source;
|
||||
private static File ipfiles;
|
||||
private static Boolean useIP;
|
||||
private static String fileName;
|
||||
private static String ipFileName;
|
||||
private static File source;
|
||||
private static File ipfiles;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
HashAlgorithm hash = Settings.getPasswordHash;
|
||||
useIP = Settings.rakamakUseIp;
|
||||
fileName = Settings.rakamakUsers;
|
||||
ipFileName = Settings.rakamakUsersIp;
|
||||
HashMap<String, String> playerIP = new HashMap<String, String>();
|
||||
HashMap<String, String> playerPSW = new HashMap<String, String>();
|
||||
@Override
|
||||
public void run() {
|
||||
HashAlgorithm hash = Settings.getPasswordHash;
|
||||
useIP = Settings.rakamakUseIp;
|
||||
fileName = Settings.rakamakUsers;
|
||||
ipFileName = Settings.rakamakUsersIp;
|
||||
HashMap<String, String> playerIP = new HashMap<String, String>();
|
||||
HashMap<String, String> playerPSW = new HashMap<String, String>();
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
|
||||
ipfiles = new File(AuthMe.getInstance().getDataFolder() + File.separator + ipFileName);
|
||||
source = new File(AuthMe.getInstance().getDataFolder()
|
||||
+ File.separator + fileName);
|
||||
ipfiles = new File(AuthMe.getInstance().getDataFolder()
|
||||
+ File.separator + ipFileName);
|
||||
source.createNewFile();
|
||||
ipfiles.createNewFile();
|
||||
BufferedReader users = null;
|
||||
BufferedReader ipFile = null;
|
||||
BufferedReader users = null;
|
||||
BufferedReader ipFile = null;
|
||||
ipFile = new BufferedReader(new FileReader(ipfiles));
|
||||
String line;
|
||||
String line;
|
||||
if (useIP) {
|
||||
String tempLine;
|
||||
while ((tempLine = ipFile.readLine()) != null) {
|
||||
if (tempLine.contains("=")) {
|
||||
String[] args = tempLine.split("=");
|
||||
playerIP.put(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
String tempLine;
|
||||
while ((tempLine = ipFile.readLine()) != null) {
|
||||
if (tempLine.contains("=")) {
|
||||
String[] args = tempLine.split("=");
|
||||
playerIP.put(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
ipFile.close();
|
||||
users = new BufferedReader(new FileReader(source));
|
||||
while ((line = users.readLine()) != null) {
|
||||
if (line.contains("=")) {
|
||||
String[] arguments = line.split("=");
|
||||
try {
|
||||
playerPSW.put(arguments[0],PasswordSecurity.getHash(hash, arguments[1], arguments[0]));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
}
|
||||
}
|
||||
if (line.contains("=")) {
|
||||
String[] arguments = line.split("=");
|
||||
try {
|
||||
playerPSW.put(arguments[0], PasswordSecurity.getHash(
|
||||
hash, arguments[1], arguments[0]));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
users.close();
|
||||
for (Entry<String, String> m : playerPSW.entrySet()) {
|
||||
String player = m.getKey();
|
||||
String psw = playerPSW.get(player);
|
||||
String ip;
|
||||
if (useIP) {
|
||||
ip = playerIP.get(player);
|
||||
} else {
|
||||
ip = "127.0.0.1";
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis());
|
||||
if (PasswordSecurity.userSalt.containsKey(player))
|
||||
auth.setSalt(PasswordSecurity.userSalt.get(player));
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
ConsoleLogger.info("Rakamak database has been imported correctly");
|
||||
sender.sendMessage("Rakamak database has been imported correctly");
|
||||
for (Entry<String, String> m : playerPSW.entrySet()) {
|
||||
String player = m.getKey();
|
||||
String psw = playerPSW.get(player);
|
||||
String ip;
|
||||
if (useIP) {
|
||||
ip = playerIP.get(player);
|
||||
} else {
|
||||
ip = "127.0.0.1";
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(player, psw, ip,
|
||||
System.currentTimeMillis());
|
||||
if (PasswordSecurity.userSalt.containsKey(player)) auth
|
||||
.setSalt(PasswordSecurity.userSalt.get(player));
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
ConsoleLogger.info("Rakamak database has been imported correctly");
|
||||
sender.sendMessage("Rakamak database has been imported correctly");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
sender.sendMessage("Error file not found");
|
||||
@@ -107,5 +112,5 @@ public class RakamakConverter implements Converter {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
sender.sendMessage("Error IOException");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class RoyalAuthConverter implements Converter {
|
||||
|
||||
public AuthMe plugin;
|
||||
private DataSource data;
|
||||
|
||||
public RoyalAuthConverter(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.data = plugin.database;
|
||||
}
|
||||
|
||||
public AuthMe plugin;
|
||||
private DataSource data;
|
||||
|
||||
public RoyalAuthConverter(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.data = plugin.database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -25,16 +25,19 @@ public class RoyalAuthConverter implements Converter {
|
||||
try {
|
||||
String name = o.getName().toLowerCase();
|
||||
String separator = File.separator;
|
||||
File file = new File("." + separator + "plugins" + separator + "RoyalAuth" + separator + "userdata" + separator + name + ".yml");
|
||||
if (data.isAuthAvailable(name))
|
||||
continue;
|
||||
if (!file.exists())
|
||||
continue;
|
||||
File file = new File("." + separator + "plugins" + separator
|
||||
+ "RoyalAuth" + separator + "userdata" + separator
|
||||
+ name + ".yml");
|
||||
if (data.isAuthAvailable(name)) continue;
|
||||
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", o.getName());
|
||||
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.showError("Error while trying to import "+ o.getName() + " RoyalAuth datas");
|
||||
ConsoleLogger.showError("Error while trying to import "
|
||||
+ o.getName() + " RoyalAuth datas");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,17 @@ import fr.xephi.authme.settings.CustomConfiguration;
|
||||
|
||||
public class RoyalAuthYamlReader extends CustomConfiguration {
|
||||
|
||||
public RoyalAuthYamlReader(File file) {
|
||||
super(file);
|
||||
public RoyalAuthYamlReader(File file) {
|
||||
super(file);
|
||||
load();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastLogin() {
|
||||
return getLong("timestamps.quit");
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return getString("login.password");
|
||||
}
|
||||
public long getLastLogin() {
|
||||
return getLong("timestamps.quit");
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return getString("login.password");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,59 +21,63 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class newxAuthToFlat {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public newxAuthToFlat(AuthMe instance, DataSource database, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
public newxAuthToFlat(AuthMe instance, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||
return false;
|
||||
}
|
||||
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
|
||||
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
|
||||
}
|
||||
List<Integer> players = getXAuthPlayers();
|
||||
if (players == null || players.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Starting import...");
|
||||
try {
|
||||
for (int id : players) {
|
||||
String pl = getIdPlayer(id);
|
||||
String psw = getPassword(id);
|
||||
if (psw != null && !psw.isEmpty() && pl != null) {
|
||||
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0, "your@email.com", API.getPlayerRealName(pl));
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Successfull convert from xAuth database");
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||
return false;
|
||||
}
|
||||
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
|
||||
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
|
||||
}
|
||||
List<Integer> players = getXAuthPlayers();
|
||||
if (players == null || players.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Starting import...");
|
||||
try {
|
||||
for (int id : players) {
|
||||
String pl = getIdPlayer(id);
|
||||
String psw = getPassword(id);
|
||||
if (psw != null && !psw.isEmpty() && pl != null) {
|
||||
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0,
|
||||
"your@email.com", API.getPlayerRealName(pl));
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Successfull convert from xAuth database");
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdPlayer(int id) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
public String getIdPlayer(int id) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController()
|
||||
.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
String sql = String.format(
|
||||
"SELECT `playername` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController()
|
||||
.getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next())
|
||||
return null;
|
||||
if (!rs.next()) return null;
|
||||
realPass = rs.getString("playername").toLowerCase();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Failed to retrieve name for account: " + id, e);
|
||||
@@ -81,20 +85,21 @@ public class newxAuthToFlat {
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
|
||||
public List<Integer> getXAuthPlayers() {
|
||||
List<Integer> xP = new ArrayList<Integer>();
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
public List<Integer> getXAuthPlayers() {
|
||||
List<Integer> xP = new ArrayList<Integer>();
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController()
|
||||
.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT * FROM `%s`",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin()
|
||||
.getDatabaseController().getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
while (rs.next()) {
|
||||
xP.add(rs.getInt("id"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@@ -103,29 +108,32 @@ public class newxAuthToFlat {
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return xP;
|
||||
}
|
||||
return xP;
|
||||
}
|
||||
|
||||
public String getPassword(int accountId) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
public String getPassword(int accountId) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController()
|
||||
.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
String sql = String.format(
|
||||
"SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController()
|
||||
.getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, accountId);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next())
|
||||
return null;
|
||||
if (!rs.next()) return null;
|
||||
realPass = rs.getString("password");
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Failed to retrieve password hash for account: " + accountId, e);
|
||||
xAuthLog.severe("Failed to retrieve password hash for account: "
|
||||
+ accountId, e);
|
||||
return null;
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,66 +19,69 @@ import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class oldxAuthToFlat {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public oldxAuthToFlat(AuthMe instance, DataSource database, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
public oldxAuthToFlat(AuthMe instance, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||
return false;
|
||||
}
|
||||
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
|
||||
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
|
||||
}
|
||||
List<Integer> players = getXAuthPlayers();
|
||||
if (players == null || players.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Starting import...");
|
||||
try {
|
||||
for (int id : players) {
|
||||
String pl = getIdPlayer(id);
|
||||
String psw = getPassword(id);
|
||||
if (psw != null && !psw.isEmpty() && pl != null) {
|
||||
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0, "your@email.com", API.getPlayerRealName(pl));
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Successfull convert from xAuth database");
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||
return false;
|
||||
}
|
||||
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
|
||||
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
|
||||
}
|
||||
List<Integer> players = getXAuthPlayers();
|
||||
if (players == null || players.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Starting import...");
|
||||
try {
|
||||
for (int id : players) {
|
||||
String pl = getIdPlayer(id);
|
||||
String psw = getPassword(id);
|
||||
if (psw != null && !psw.isEmpty() && pl != null) {
|
||||
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0,
|
||||
"your@email.com", API.getPlayerRealName(pl));
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Successfull convert from xAuth database");
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdPlayer(int id) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
public String getIdPlayer(int id) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController()
|
||||
.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
String sql = String.format(
|
||||
"SELECT `playername` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController()
|
||||
.getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next())
|
||||
return null;
|
||||
if (!rs.next()) return null;
|
||||
realPass = rs.getString("playername").toLowerCase();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Failed to retrieve name for account: " + id, e);
|
||||
@@ -86,20 +89,21 @@ public class oldxAuthToFlat {
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
|
||||
public List<Integer> getXAuthPlayers() {
|
||||
List<Integer> xP = new ArrayList<Integer>();
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
public List<Integer> getXAuthPlayers() {
|
||||
List<Integer> xP = new ArrayList<Integer>();
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController()
|
||||
.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT * FROM `%s`",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin()
|
||||
.getDatabaseController().getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
while (rs.next()) {
|
||||
xP.add(rs.getInt("id"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@@ -108,29 +112,32 @@ public class oldxAuthToFlat {
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return xP;
|
||||
}
|
||||
return xP;
|
||||
}
|
||||
|
||||
public String getPassword(int accountId) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
public String getPassword(int accountId) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController()
|
||||
.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
String sql = String.format(
|
||||
"SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController()
|
||||
.getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, accountId);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next())
|
||||
return null;
|
||||
if (!rs.next()) return null;
|
||||
realPass = rs.getString("password");
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Failed to retrieve password hash for account: " + accountId, e);
|
||||
xAuthLog.severe("Failed to retrieve password hash for account: "
|
||||
+ accountId, e);
|
||||
return null;
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ public class vAuthConverter implements Converter {
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public vAuthConverter(AuthMe plugin, DataSource database, CommandSender sender) {
|
||||
public vAuthConverter(AuthMe plugin, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
|
||||
@@ -15,23 +15,25 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class vAuthFileReader {
|
||||
|
||||
|
||||
public AuthMe plugin;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public vAuthFileReader(AuthMe plugin, DataSource database, CommandSender sender) {
|
||||
public vAuthFileReader(AuthMe plugin, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
|
||||
public void convert() throws IOException {
|
||||
final File file = new File(plugin.getDataFolder().getParent() + "/vAuth/passwords.yml");
|
||||
final File file = new File(plugin.getDataFolder().getParent()
|
||||
+ "/vAuth/passwords.yml");
|
||||
Scanner scanner = null;
|
||||
try {
|
||||
scanner = new Scanner(file);
|
||||
while(scanner.hasNextLine()) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
String name = line.split(": ")[0];
|
||||
String password = line.split(": ")[1];
|
||||
@@ -39,29 +41,34 @@ public class vAuthFileReader {
|
||||
if (isUUIDinstance(password)) {
|
||||
String pname = null;
|
||||
try {
|
||||
pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
|
||||
pname = Bukkit.getOfflinePlayer(UUID.fromString(name))
|
||||
.getName();
|
||||
} catch (Exception e) {
|
||||
pname = getName(UUID.fromString(name));
|
||||
} catch (NoSuchMethodError e) {
|
||||
pname = getName(UUID.fromString(name));
|
||||
}
|
||||
if (pname == null) continue;
|
||||
auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", pname);
|
||||
auth = new PlayerAuth(pname.toLowerCase(), password,
|
||||
"127.0.0.1", System.currentTimeMillis(),
|
||||
"your@email.com", pname);
|
||||
} else {
|
||||
auth = new PlayerAuth(name, password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", API.getPlayerRealName(name));
|
||||
auth = new PlayerAuth(name, password, "127.0.0.1",
|
||||
System.currentTimeMillis(), "your@email.com",
|
||||
API.getPlayerRealName(name));
|
||||
}
|
||||
if (auth != null) database.saveAuth(auth);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean isUUIDinstance(String s) {
|
||||
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-")) return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private String getName(UUID uuid) {
|
||||
try {
|
||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
||||
|
||||
@@ -10,8 +10,9 @@ public class xAuthConverter implements Converter {
|
||||
public AuthMe plugin;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public xAuthConverter(AuthMe plugin, DataSource database, CommandSender sender) {
|
||||
|
||||
public xAuthConverter(AuthMe plugin, DataSource database,
|
||||
CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
@@ -21,12 +22,14 @@ public class xAuthConverter implements Converter {
|
||||
public void run() {
|
||||
try {
|
||||
Class.forName("com.cypherx.xauth.xAuth");
|
||||
oldxAuthToFlat converter = new oldxAuthToFlat(plugin, database, sender);
|
||||
oldxAuthToFlat converter = new oldxAuthToFlat(plugin, database,
|
||||
sender);
|
||||
converter.convert();
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
Class.forName("de.luricos.bukkit.xAuth.xAuth");
|
||||
newxAuthToFlat converter = new newxAuthToFlat(plugin, database, sender);
|
||||
newxAuthToFlat converter = new newxAuthToFlat(plugin, database,
|
||||
sender);
|
||||
converter.convert();
|
||||
} catch (ClassNotFoundException ce) {
|
||||
sender.sendMessage("xAuth has not been found, please put xAuth.jar in your plugin folder and restart!");
|
||||
|
||||
Reference in New Issue
Block a user