diff --git a/core/src/main/java/com/github/games647/fastlogin/core/importer/AutoInImporter.java b/core/src/main/java/com/github/games647/fastlogin/core/importer/AutoInImporter.java new file mode 100644 index 00000000..58245630 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/importer/AutoInImporter.java @@ -0,0 +1,36 @@ +package com.github.games647.fastlogin.core.importer; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.sql.DataSource; + +public class AutoInImporter extends Importer { + + private static final String USER_TABLE = "nicknames"; + private static final String UUID_TABLE = "uuids"; + private static final String SESSION_TABLE = "sessions"; + + @Override + public int importData(DataSource source, DataSource target, String targetTable) throws SQLException { + Connection con = null; + Statement stmt = null; + try { + con = source.getConnection(); + stmt = con.createStatement(); + int importedRows = stmt.executeUpdate("INSERT INTO " + targetTable + " SELECT" + + " name AS Name," + + " enabledLogin AS Premium," + + " '' AS LastIp," + + " REPLACE(puuid, '-', '') AS UUID" + + " FROM " + USER_TABLE + + " JOIN " + UUID_TABLE + + " ON " + UUID_TABLE + ".id = " + UUID_TABLE + ".nickname_id"); + return importedRows; + } finally { + closeQuietly(stmt); + closeQuietly(con); + } + } +} diff --git a/core/src/main/java/com/github/games647/fastlogin/core/importer/BPAImporter.java b/core/src/main/java/com/github/games647/fastlogin/core/importer/BPAImporter.java new file mode 100644 index 00000000..9c11838b --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/importer/BPAImporter.java @@ -0,0 +1,33 @@ +package com.github.games647.fastlogin.core.importer; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.sql.DataSource; + +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; + Statement stmt = 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; + } finally { + closeQuietly(stmt); + closeQuietly(con); + } + } +} diff --git a/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java b/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java new file mode 100644 index 00000000..1d1de711 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java @@ -0,0 +1,32 @@ +package com.github.games647.fastlogin.core.importer; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import javax.sql.DataSource; + +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; + Statement stmt = 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; + } finally { + closeQuietly(stmt); + closeQuietly(con); + } + } +} diff --git a/core/src/main/java/com/github/games647/fastlogin/core/importer/Importer.java b/core/src/main/java/com/github/games647/fastlogin/core/importer/Importer.java new file mode 100644 index 00000000..60944125 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/importer/Importer.java @@ -0,0 +1,20 @@ +package com.github.games647.fastlogin.core.importer; + +import java.sql.SQLException; + +import javax.sql.DataSource; + +public abstract class Importer { + + public abstract int importData(DataSource source, DataSource target, String targetTable) throws SQLException; + + protected void closeQuietly(AutoCloseable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (Exception ignore) { + //ignore + } + } + } +}