Rework Converter + Add CrazyLogin flat converter
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
public interface Converter {
|
||||
|
||||
void convert() throws Exception;
|
||||
public interface Converter extends Runnable {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
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.settings.Settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class CrazyLoginConverter implements Converter {
|
||||
|
||||
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 getInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private static String fileName;
|
||||
private static File source;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fileName = Settings.crazyloginFileName;
|
||||
try {
|
||||
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!");
|
||||
return;
|
||||
}
|
||||
source.createNewFile();
|
||||
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;
|
||||
String player = args[0];
|
||||
String psw = args[1];
|
||||
try {
|
||||
if (player != null && psw != null) {
|
||||
PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis());
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
users.close();
|
||||
ConsoleLogger.info("CrazyLogin database has been imported correctly");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,8 +48,9 @@ public class FlatToSql implements Converter {
|
||||
columnLogged = Settings.getMySQLColumnLogged;
|
||||
columnID = Settings.getMySQLColumnId;
|
||||
}
|
||||
|
||||
public void convert() throws IOException {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
@@ -58,7 +59,7 @@ public class FlatToSql implements Converter {
|
||||
BufferedWriter sql = null;
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
sql = new BufferedWriter(new FileWriter(output));
|
||||
String createDB = " CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
String createDB = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ columnID + " INTEGER AUTO_INCREMENT,"
|
||||
+ columnName + " VARCHAR(255) NOT NULL UNIQUE,"
|
||||
+ columnPassword + " VARCHAR(255) NOT NULL,"
|
||||
|
||||
@@ -41,8 +41,9 @@ public class FlatToSqlite implements Converter {
|
||||
private static String database;
|
||||
private static String columnID;
|
||||
private static Connection con;
|
||||
|
||||
public void convert() throws Exception {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
database = Settings.getMySQLDatabase;
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
|
||||
@@ -45,7 +45,8 @@ public class RakamakConverter implements Converter {
|
||||
private static File source;
|
||||
private static File ipfiles;
|
||||
|
||||
public void convert() throws Exception {
|
||||
@Override
|
||||
public void run() {
|
||||
HashAlgorithm hash = Settings.getPasswordHash;
|
||||
useIP = Settings.rakamakUseIp;
|
||||
fileName = Settings.rakamakUsers;
|
||||
@@ -98,10 +99,13 @@ public class RakamakConverter implements Converter {
|
||||
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");
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
sender.sendMessage("Error IOException");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class RoyalAuthConverter extends Thread implements Converter {
|
||||
public class RoyalAuthConverter implements Converter {
|
||||
|
||||
public AuthMe plugin;
|
||||
private DataSource data;
|
||||
@@ -17,14 +17,10 @@ public class RoyalAuthConverter extends Thread implements Converter {
|
||||
public RoyalAuthConverter(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.data = plugin.database;
|
||||
this.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert() throws Exception {
|
||||
public void run() {
|
||||
for (OfflinePlayer o : plugin.getServer().getOfflinePlayers()) {
|
||||
try {
|
||||
String name = o.getName().toLowerCase();
|
||||
@@ -41,7 +37,6 @@ public class RoyalAuthConverter extends Thread implements Converter {
|
||||
ConsoleLogger.showError("Error while trying to import "+ o.getName() + " RoyalAuth datas");
|
||||
}
|
||||
}
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class newxAuthToFlat extends Thread {
|
||||
public class newxAuthToFlat {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
@@ -30,12 +30,6 @@ public class newxAuthToFlat extends Thread {
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
convert();
|
||||
if (isAlive())
|
||||
interrupt();
|
||||
}
|
||||
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class oldxAuthToFlat extends Thread {
|
||||
public class oldxAuthToFlat {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
@@ -35,12 +35,6 @@ public class oldxAuthToFlat extends Thread {
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
convert();
|
||||
if (isAlive())
|
||||
interrupt();
|
||||
}
|
||||
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
|
||||
@@ -16,18 +16,20 @@ public class xAuthConverter implements Converter {
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert() throws Exception {
|
||||
public void run() {
|
||||
try {
|
||||
Class.forName("com.cypherx.xauth.xAuth");
|
||||
oldxAuthToFlat converter = new oldxAuthToFlat(plugin, database, sender);
|
||||
converter.run();
|
||||
converter.convert();
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
Class.forName("de.luricos.bukkit.xAuth.xAuth");
|
||||
newxAuthToFlat converter = new newxAuthToFlat(plugin, database, sender);
|
||||
converter.run();
|
||||
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