Rework Converter + Add CrazyLogin flat converter

This commit is contained in:
Xephi 2014-06-14 01:53:46 +02:00
parent b403374c2a
commit 1d83b398f0
13 changed files with 126 additions and 38 deletions

View File

@ -33,6 +33,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.converter.Converter;
import fr.xephi.authme.converter.CrazyLoginConverter;
import fr.xephi.authme.converter.FlatToSql;
import fr.xephi.authme.converter.FlatToSqlite;
import fr.xephi.authme.converter.RakamakConverter;
@ -302,25 +303,33 @@ public class AdminCommand implements CommandExecutor {
} else if (args[0].equalsIgnoreCase("convertflattosql")) {
FlatToSql converter = new FlatToSql();
try {
converter.convert();
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
} catch (Exception e) {
sender.sendMessage("[AuthMe] Error while converting to authme.sql");
}
} else if (args[0].equalsIgnoreCase("flattosqlite")) {
FlatToSqlite converter = new FlatToSqlite(sender);
try {
converter.convert();
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
} catch (Exception e) {
}
return true;
} else if (args[0].equalsIgnoreCase("xauthimport")) {
Converter converter = new xAuthConverter(plugin, database, sender);
try {
converter.convert();
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
} catch (Exception e) {
sender.sendMessage("Error while importing xAuth data, check your logs");
}
return true;
} else if (args[0].equalsIgnoreCase("crazyloginimport")) {
Converter converter = new CrazyLoginConverter(plugin, database, sender);
try {
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
} catch (Exception e) {
sender.sendMessage("Error while importing CrazyLogin datas, check your logs");
}
return true;
} else if (args[0].equalsIgnoreCase("getemail")) {
if (args.length != 2) {
sender.sendMessage("Usage: /authme getemail playername");
@ -356,7 +365,7 @@ public class AdminCommand implements CommandExecutor {
} else if (args[0].equalsIgnoreCase("convertfromrakamak")) {
Converter converter = new RakamakConverter(plugin, database, sender);
try {
converter.convert();
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
} catch (Exception e) {
sender.sendMessage("Error while importing Rakamak data, check your logs");
}

View File

@ -1,6 +1,4 @@
package fr.xephi.authme.converter;
public interface Converter {
void convert() throws Exception;
public interface Converter extends Runnable {
}

View File

@ -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());
}
}
}

View File

@ -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,"

View File

@ -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;

View File

@ -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");
}
}
}

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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!");
}
}
}

View File

@ -69,7 +69,7 @@ public final class Settings extends YamlConfiguration {
getcUnrestrictedName, getRegisteredGroup, messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ,
rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName,
getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld,
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority;
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName;
public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength,
getMinNickLength, getPasswordMinLen, getMovementRadius, getmaxRegPerIp, getNonActivatedGroup,
@ -245,6 +245,7 @@ public void loadConfigOptions() {
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
delayJoinMessage = configFile.getBoolean("settings.delayJoinMessage", false);
noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false);
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
// Load the welcome message
getWelcomeMessage(plugin);
@ -405,6 +406,7 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) {
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
delayJoinMessage = configFile.getBoolean("settings.delayJoinMessage", false);
noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false);
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
// Reload the welcome message
getWelcomeMessage(AuthMe.getInstance());
@ -517,6 +519,10 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) {
}
if(contains("Converter.Rakamak.newPasswordHash"))
set("Converter.Rakamak.newPasswordHash", null);
if(!contains("Converter.CrazyLogin.fileName")) {
set("Converter.CrazyLogin.fileName", "accounts.db");
changes = true;
}
if (changes) {
plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me");

View File

@ -329,6 +329,9 @@ Converter:
useIP: false
# IP file name for rakamak
ipFileName: UsersIp.rak
CrazyLogin:
# CrazyLogin database file
fileName: accounts.db
Email:
# Email SMTP server host
mailSMTP: smtp.gmail.com

View File

@ -168,4 +168,7 @@ permissions:
default: op
authme.admin.getip:
description: Get IP from a player ( fake and real )
default: op
authme.admin.crazyloginimport:
description: Import CrazyLogin database into AuthMe database
default: op