Added auto login importers

This commit is contained in:
games647
2016-08-25 17:45:09 +02:00
parent 88fdeff3f1
commit ad60397851
14 changed files with 370 additions and 51 deletions

View File

@ -1,5 +1,8 @@
######1.8
* Added autoIn importer
* Added BFA importer
* Added ElDziAuth importer
* Fix third-party not premium player detection
* Fix ProtocolSupport BungeeCord
* Fix duplicate logins for BungeeAuth users

View File

@ -4,6 +4,7 @@ import com.avaje.ebeaninternal.api.ClassUtil;
import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.ProtocolLibrary;
import com.github.games647.fastlogin.bukkit.commands.CrackedCommand;
import com.github.games647.fastlogin.bukkit.commands.ImportCommand;
import com.github.games647.fastlogin.bukkit.commands.PremiumCommand;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import com.github.games647.fastlogin.bukkit.listener.BukkitJoinListener;
@ -125,6 +126,7 @@ public class FastLoginBukkit extends JavaPlugin {
//register commands using a unique name
getCommand("premium").setExecutor(new PremiumCommand(this));
getCommand("cracked").setExecutor(new CrackedCommand(this));
getCommand("import-auth").setExecutor(new ImportCommand(this));
}
@Override

View File

@ -0,0 +1,85 @@
package com.github.games647.fastlogin.bukkit.commands;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.importer.ImportPlugin;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class ImportCommand implements CommandExecutor {
protected final FastLoginBukkit plugin;
public ImportCommand(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 2) {
sender.sendMessage(ChatColor.DARK_RED + "You need to specify the import plugin and database type");
return true;
}
ImportPlugin importPlugin;
switch (args[0].toLowerCase()) {
case "autoin":
importPlugin = ImportPlugin.AUTO_IN;
break;
case "bpa":
importPlugin = ImportPlugin.BPA;
break;
case "eldzi":
importPlugin = ImportPlugin.ELDZI;
break;
default:
sender.sendMessage(ChatColor.DARK_RED + "Unknown auto login plugin");
return true;
}
boolean sqlite;
switch (args[1].toLowerCase()) {
case "sqlite":
sqlite = true;
break;
case "mysql":
sqlite = false;
break;
default:
sender.sendMessage(ChatColor.DARK_RED + "Unknown storage type to import from. Either SQLite or MySQL");
return true;
}
String host = "";
String database = "";
String username = "";
String password = "";
if (!sqlite) {
if (args.length <= 5) {
sender.sendMessage(ChatColor.DARK_RED + "If importing from MySQL, you need to specify host database "
+ "and username passowrd too");
return true;
}
host = args[2];
database = args[3];
username = args[4];
password = args[5];
}
FastLoginCore core = plugin.getCore();
AuthStorage storage = core.getStorage();
boolean success = core.importDatabase(importPlugin, true, storage, host, database, username, password);
if (success) {
sender.sendMessage(ChatColor.DARK_GREEN + "Successful imported the data");
} else {
sender.sendMessage(ChatColor.DARK_RED + "Failed to import the data. Check out the logs");
}
return true;
}
}

View File

@ -40,6 +40,11 @@ commands:
usage: /<command> [player]
permission: ${project.artifactId}.command.unpremium
import-auth:
description: 'Imports the auth data from another auto login'
usage: /<command> [player]
permission: ${project.artifactId}.command.import
permissions:
${project.artifactId}.command.premium:
description: 'Label themselves as premium'
@ -54,7 +59,7 @@ permissions:
description: 'Label themselves as cracked'
default: true
${project.artifactId}.command..cracked.other:
${project.artifactId}.command.cracked.other:
description: 'Label others as cracked'
children:
${project.artifactId}.command.cracked: true

View File

@ -77,6 +77,9 @@ public class FastLoginBungee extends Plugin {
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this));
//bungee only commands
getProxy().getPluginManager().registerCommand(this, new ImportCommand(this));
//this is required to listen to messages from the server
getProxy().registerChannel(getDescription().getName());

View File

@ -0,0 +1,85 @@
package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.importer.ImportPlugin;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
public class ImportCommand extends Command {
private final FastLoginBungee plugin;
public ImportCommand(FastLoginBungee plugin) {
super("import-db");
this.plugin = plugin;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (args.length < 2) {
sender.sendMessage(ChatColor.DARK_RED + "You need to specify the import plugin and database type");
return;
}
ImportPlugin importPlugin;
switch (args[0].toLowerCase()) {
case "autoin":
importPlugin = ImportPlugin.AUTO_IN;
break;
case "bpa":
importPlugin = ImportPlugin.BPA;
break;
case "eldzi":
importPlugin = ImportPlugin.ELDZI;
break;
default:
sender.sendMessage(ChatColor.DARK_RED + "Unknown auto login plugin");
return;
}
boolean sqlite;
switch (args[1].toLowerCase()) {
case "sqlite":
sqlite = true;
break;
case "mysql":
sqlite = false;
break;
default:
sender.sendMessage(ChatColor.DARK_RED + "Unknown storage type to import from. Either SQLite or MySQL");
return;
}
String host = "";
String database = "";
String username = "";
String password = "";
if (!sqlite) {
if (args.length <= 5) {
sender.sendMessage(ChatColor.DARK_RED + "If importing from MySQL, you need to specify host database "
+ "and username passowrd too");
return;
}
host = args[2];
database = args[3];
username = args[4];
password = args[5];
}
FastLoginCore core = plugin.getCore();
AuthStorage storage = core.getStorage();
boolean success = core.importDatabase(importPlugin, true, storage, host, database, username, password);
if (success) {
sender.sendMessage(ChatColor.DARK_GREEN + "Successful imported the data");
} else {
sender.sendMessage(ChatColor.DARK_RED + "Failed to import the data. Check out the logs");
}
return;
}
}

View File

@ -42,6 +42,10 @@ public class AuthStorage {
this.dataSource = new HikariDataSource(databaseConfig);
}
public HikariDataSource getDataSource() {
return dataSource;
}
public void createTables() throws SQLException {
Connection con = null;
Statement createStmt = null;

View File

@ -1,6 +1,13 @@
package com.github.games647.fastlogin.core;
import com.github.games647.fastlogin.core.importer.AutoInImporter;
import com.github.games647.fastlogin.core.importer.ImportPlugin;
import com.github.games647.fastlogin.core.importer.Importer;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -59,6 +66,46 @@ public abstract class FastLoginCore {
}
}
public boolean importDatabase(ImportPlugin plugin, boolean sqlite, AuthStorage storage, String host, String database
, String username, String pass) {
if (sqlite && (plugin == ImportPlugin.BPA || plugin == ImportPlugin.ELDZI)) {
throw new IllegalArgumentException("These plugins doesn't support flat file databases");
}
Importer importer;
try {
importer = plugin.getImporter().newInstance();
} catch (Exception ex) {
getLogger().log(Level.SEVERE, "Couldn't not setup importer class", ex);
return false;
}
try {
if (sqlite && plugin == ImportPlugin.AUTO_IN) {
//load sqlite driver
Class.forName("org.sqlite.JDBC");
String jdbcUrl = "jdbc:sqlite:" + AutoInImporter.getSQLitePath();
Connection con = DriverManager.getConnection(jdbcUrl);
importer.importData(con, storage.getDataSource(), storage);
return true;
} else {
Class.forName("com.mysql.jdbc.Driver");
String jdbcUrl = "jdbc:mysql://" + host + "/" + database;
Connection con = DriverManager.getConnection(jdbcUrl, username, pass);
importer.importData(con, storage.getDataSource(), storage);
return true;
}
} catch (ClassNotFoundException ex) {
getLogger().log(Level.SEVERE, "Cannot find SQL driver. Do you removed it?", ex);
} catch (SQLException ex) {
getLogger().log(Level.SEVERE, "Couldn't import data. Aborting...", ex);
}
return false;
}
public void close() {
if (storage != null) {
storage.close();

View File

@ -1,51 +1,73 @@
package com.github.games647.fastlogin.core.importer;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.PlayerProfile;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import javax.sql.DataSource;
public class AutoInImporter extends Importer {
private static final String PLUGIN_NAME = "AutoIn";
private static final String SQLITE_FILE = "plugins/" + PLUGIN_NAME + "/AutoIn_PlayerOptions.db";
private static final String USER_TABLE = "nicknames";
private static final String UUID_TABLE = "uuids";
private static final String SESSION_TABLE = "sessions";
public static String getSQLitePath() {
return SQLITE_FILE;
}
@Override
public int importData(DataSource source, DataSource target, String targetTable) throws SQLException {
Connection con = null;
public int importData(Connection source, DataSource target, AuthStorage storage) throws SQLException {
Statement stmt = null;
ResultSet resultSet = null;
try {
con = source.getConnection();
stmt = con.createStatement();
int importedRows = stmt.executeUpdate("INSERT INTO " + targetTable + " (Name, Premium, LastIp, UUID) SELECT"
+ " name AS Name,"
/* Enable premium authentication only for those who want to be auto logged in, so
they have their cracked protection disabled */
+ " !protection AND premium AS Premium,"
+ " '' AS LastIp,"
/* Remove the dashes - returns null if puuid is null too */
+ " REPLACE(puuid, '-', '') AS UUID"
+ " FROM " + USER_TABLE
/* Get the premium uuid */
stmt = source.createStatement();
resultSet = stmt.executeQuery("SELECT name, protection, premium, puuid FROM " + USER_TABLE
+ " LEFT JOIN " + " ("
/* Prevent duplicates */
+ "SELECT * FROM " + UUID_TABLE + " GROUP BY nickname_id"
+ ") uuids"
+ " ON " + USER_TABLE + ".id = uuids.nickname_id");
int rows = 0;
while (resultSet.next()) {
String name = resultSet.getString(1);
boolean protection = resultSet.getBoolean(2);
/* Enable premium authentication only for those who want to be auto logged in,
so they have their cracked protection disabled */
boolean premium = !protection && resultSet.getBoolean(3);
String puuid = resultSet.getString(4);
/* FastLogin will also make lookups on the uuid column for name changes
the old 1.6.2 version won't check if those user have premium enabled
so it could happen that a premium could steal the account if we don't do this
It seems the uuid is saved on autoin too if the player is cracked */
stmt.executeUpdate("UPDATE `premium` SET `UUID`=NULL WHERE PREMIUM=0");
return importedRows;
PlayerProfile profile;
if (premium) {
profile = new PlayerProfile(UUID.fromString(puuid), name, premium, "");
} else {
profile = new PlayerProfile(null, name, premium, "");
}
storage.save(profile);
rows++;
}
return rows;
} finally {
closeQuietly(stmt);
closeQuietly(con);
closeQuietly(resultSet);
}
}
}

View File

@ -1,8 +1,13 @@
package com.github.games647.fastlogin.core.importer;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.PlayerProfile;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import javax.sql.DataSource;
@ -11,23 +16,35 @@ public class BPAImporter extends Importer {
private static final String DEFAULT_TABLE_NAME = "users";
@Override
public int importData(DataSource source, DataSource target, String targetTable) throws SQLException {
Connection con = null;
public int importData(Connection source, DataSource target, AuthStorage storage) throws SQLException {
Statement stmt = null;
ResultSet resultSet = null;
try {
con = source.getConnection();
stmt = con.createStatement();
int importedRows = stmt.executeUpdate("INSERT INTO " + targetTable + " SELECT"
+ " nick AS Name,"
+ " NULL AS UUID,"
+ " checked AS Premium,"
+ " lastIP AS LastIp,"
+ " FROM_UNIXTIME(lastJoined * 0.001) AS LastLogin"
+ " FROM " + DEFAULT_TABLE_NAME);
return importedRows;
stmt = source.createStatement();
resultSet = stmt.executeQuery("SELECT "
+ "nick, "
+ "checked, "
+ "lastIP, "
+ "FROM_UNIXTIME(lastJoined * 0.001) AS LastLogin "
+ "FROM " + DEFAULT_TABLE_NAME);
int rows = 0;
while (resultSet.next()) {
String name = resultSet.getString(1);
boolean premium = resultSet.getBoolean(2);
String lastIP = resultSet.getString(3);
Timestamp lastLogin = resultSet.getTimestamp(4);
//uuid doesn't exist here
PlayerProfile profile = new PlayerProfile(null, name, premium, lastIP);
storage.save(profile);
rows++;
}
return rows;
} finally {
closeQuietly(stmt);
closeQuietly(con);
closeQuietly(resultSet);
}
}
}

View File

@ -1,8 +1,14 @@
package com.github.games647.fastlogin.core.importer;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.PlayerProfile;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.UUID;
import javax.sql.DataSource;
@ -11,23 +17,42 @@ public class ElDziAuthImporter extends Importer {
private static final String TABLE_NAME = "accounts";
@Override
public int importData(DataSource source, DataSource target, String targetTable) throws SQLException {
Connection con = null;
public int importData(Connection source, DataSource target, AuthStorage storage) throws SQLException {
Statement stmt = null;
ResultSet resultSet = null;
try {
con = source.getConnection();
stmt = con.createStatement();
int importedRows = stmt.executeUpdate("INSERT INTO " + targetTable + " SELECT"
+ " nick AS Name,"
+ " uuid AS UUID,"
+ " premium AS Premium,"
+ " lastIp AS LastIp,"
+ " FROM_UNIXTIME(lastPlayed * 0.001) AS LastLogin"
+ " FROM " + TABLE_NAME);
return importedRows;
stmt = source.createStatement();
resultSet = stmt.executeQuery("SELECT "
+ "nick, "
+ "premium, "
+ "lastIP, "
+ "FROM_UNIXTIME(lastPlayed * 0.001) AS LastLogin "
+ "FROM " + TABLE_NAME);
int rows = 0;
while (resultSet.next()) {
String name = resultSet.getString(1);
boolean premium = resultSet.getBoolean(2);
String lastIP = resultSet.getString(3);
Timestamp lastLogin = resultSet.getTimestamp(4);
String uuid = resultSet.getString(5);
PlayerProfile profile;
if (premium) {
profile = new PlayerProfile(UUID.fromString(uuid), name, premium, lastIP);
} else {
profile = new PlayerProfile(null, name, premium, "");
}
storage.save(profile);
rows++;
}
return rows;
} finally {
closeQuietly(stmt);
closeQuietly(con);
closeQuietly(resultSet);
}
}
}

View File

@ -0,0 +1,20 @@
package com.github.games647.fastlogin.core.importer;
public enum ImportPlugin {
AUTO_IN(AutoInImporter.class),
BPA(BPAImporter.class),
ELDZI(ElDziAuthImporter.class);
private final Class<? extends Importer> importerClass;
ImportPlugin(Class<? extends Importer> importer) {
this.importerClass = importer;
}
public Class<? extends Importer> getImporter() {
return importerClass;
}
}

View File

@ -1,12 +1,13 @@
package com.github.games647.fastlogin.core.importer;
import com.github.games647.fastlogin.core.AuthStorage;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
public abstract class Importer {
public abstract int importData(DataSource source, DataSource target, String targetTable) throws SQLException;
public abstract int importData(Connection source, DataSource target, AuthStorage storage) throws SQLException;
protected void closeQuietly(AutoCloseable closeable) {
if (closeable != null) {

View File

@ -60,7 +60,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<configuration>
<outputDirectory>${outputDir}</outputDirectory>
</configuration>