#792 Add columns for registration IP and registration date
- Add columns for reg date and IP - Rename "ip" to "last IP"
This commit is contained in:
@@ -14,7 +14,7 @@ public final class Columns {
|
||||
public final String REAL_NAME;
|
||||
public final String PASSWORD;
|
||||
public final String SALT;
|
||||
public final String IP;
|
||||
public final String LAST_IP;
|
||||
public final String LAST_LOGIN;
|
||||
public final String GROUP;
|
||||
public final String LASTLOC_X;
|
||||
@@ -26,24 +26,28 @@ public final class Columns {
|
||||
public final String EMAIL;
|
||||
public final String ID;
|
||||
public final String IS_LOGGED;
|
||||
public final String REGISTRATION_DATE;
|
||||
public final String REGISTRATION_IP;
|
||||
|
||||
public Columns(Settings settings) {
|
||||
NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_NAME);
|
||||
REAL_NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_REALNAME);
|
||||
PASSWORD = settings.getProperty(DatabaseSettings.MYSQL_COL_PASSWORD);
|
||||
SALT = settings.getProperty(DatabaseSettings.MYSQL_COL_SALT);
|
||||
IP = settings.getProperty(DatabaseSettings.MYSQL_COL_IP);
|
||||
LAST_LOGIN = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOGIN);
|
||||
GROUP = settings.getProperty(DatabaseSettings.MYSQL_COL_GROUP);
|
||||
LASTLOC_X = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_X);
|
||||
LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y);
|
||||
LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z);
|
||||
LASTLOC_WORLD = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_WORLD);
|
||||
LASTLOC_YAW = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_YAW);
|
||||
LASTLOC_PITCH = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_PITCH);
|
||||
EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
|
||||
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
|
||||
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);
|
||||
NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_NAME);
|
||||
REAL_NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_REALNAME);
|
||||
PASSWORD = settings.getProperty(DatabaseSettings.MYSQL_COL_PASSWORD);
|
||||
SALT = settings.getProperty(DatabaseSettings.MYSQL_COL_SALT);
|
||||
LAST_IP = settings.getProperty(DatabaseSettings.MYSQL_COL_LAST_IP);
|
||||
LAST_LOGIN = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOGIN);
|
||||
GROUP = settings.getProperty(DatabaseSettings.MYSQL_COL_GROUP);
|
||||
LASTLOC_X = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_X);
|
||||
LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y);
|
||||
LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z);
|
||||
LASTLOC_WORLD = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_WORLD);
|
||||
LASTLOC_YAW = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_YAW);
|
||||
LASTLOC_PITCH = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_PITCH);
|
||||
EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
|
||||
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
|
||||
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);
|
||||
REGISTRATION_DATE = settings.getProperty(DatabaseSettings.MYSQL_COL_REGISTER_DATE);
|
||||
REGISTRATION_IP = settings.getProperty(DatabaseSettings.MYSQL_COL_REGISTER_IP);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class FlatFile implements DataSource {
|
||||
return false;
|
||||
}
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(source, true))) {
|
||||
bw.write(auth.getNickname() + ":" + auth.getPassword().getHash() + ":" + auth.getIp()
|
||||
bw.write(auth.getNickname() + ":" + auth.getPassword().getHash() + ":" + auth.getLastIp()
|
||||
+ ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY()
|
||||
+ ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n");
|
||||
} catch (IOException ex) {
|
||||
@@ -139,7 +139,7 @@ public class FlatFile implements DataSource {
|
||||
newAuth = buildAuthFromArray(args);
|
||||
if (newAuth != null) {
|
||||
newAuth.setLastLogin(auth.getLastLogin());
|
||||
newAuth.setIp(auth.getIp());
|
||||
newAuth.setLastIp(auth.getLastIp());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -393,7 +393,7 @@ public class FlatFile implements DataSource {
|
||||
PlayerAuth.Builder builder = PlayerAuth.builder()
|
||||
.name(args[0]).realName(args[0]).password(args[1], null);
|
||||
|
||||
if (args.length >= 3) builder.ip(args[2]);
|
||||
if (args.length >= 3) builder.lastIp(args[2]);
|
||||
if (args.length >= 4) builder.lastLogin(Long.parseLong(args[3]));
|
||||
if (args.length >= 7) {
|
||||
builder.locX(Double.parseDouble(args[4]))
|
||||
|
||||
@@ -189,9 +189,9 @@ public class MySQL implements DataSource {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IP)) {
|
||||
if (isColumnMissing(md, col.LAST_IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;");
|
||||
+ " ADD COLUMN " + col.LAST_IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
@@ -201,6 +201,16 @@ public class MySQL implements DataSource {
|
||||
migrateLastLoginColumn(con, md);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REGISTRATION_DATE)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.REGISTRATION_DATE + " BIGINT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REGISTRATION_IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.REGISTRATION_IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LAST_LOGIN + " , ADD "
|
||||
@@ -305,20 +315,19 @@ public class MySQL implements DataSource {
|
||||
public boolean saveAuth(PlayerAuth auth) {
|
||||
try (Connection con = getConnection()) {
|
||||
String sql;
|
||||
|
||||
boolean useSalt = !col.SALT.isEmpty() || !StringUtils.isEmpty(auth.getPassword().getSalt());
|
||||
sql = "INSERT INTO " + tableName + "("
|
||||
+ col.NAME + "," + col.PASSWORD + "," + col.IP + ","
|
||||
+ col.LAST_LOGIN + "," + col.REAL_NAME + "," + col.EMAIL
|
||||
+ col.NAME + "," + col.PASSWORD + "," + col.REAL_NAME
|
||||
+ "," + col.EMAIL + "," + col.REGISTRATION_DATE + "," + col.REGISTRATION_IP
|
||||
+ (useSalt ? "," + col.SALT : "")
|
||||
+ ") VALUES (?,?,?,?,?,?" + (useSalt ? ",?" : "") + ");";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, auth.getNickname());
|
||||
pst.setString(2, auth.getPassword().getHash());
|
||||
pst.setString(3, auth.getIp());
|
||||
pst.setLong(4, auth.getLastLogin());
|
||||
pst.setString(5, auth.getRealName());
|
||||
pst.setString(6, auth.getEmail());
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getEmail());
|
||||
pst.setObject(5, auth.getRegistrationDate());
|
||||
pst.setString(6, auth.getRegistrationIp());
|
||||
if (useSalt) {
|
||||
pst.setString(7, auth.getPassword().getSalt());
|
||||
}
|
||||
@@ -382,9 +391,9 @@ public class MySQL implements DataSource {
|
||||
@Override
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
String sql = "UPDATE " + tableName + " SET "
|
||||
+ col.IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
|
||||
+ col.LAST_IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, auth.getIp());
|
||||
pst.setString(1, auth.getLastIp());
|
||||
pst.setLong(2, auth.getLastLogin());
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getNickname());
|
||||
@@ -479,7 +488,7 @@ public class MySQL implements DataSource {
|
||||
@Override
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
List<String> result = new ArrayList<>();
|
||||
String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.IP + "=?;";
|
||||
String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_IP + "=?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, ip);
|
||||
try (ResultSet rs = pst.executeQuery()) {
|
||||
@@ -665,15 +674,17 @@ public class MySQL implements DataSource {
|
||||
.realName(row.getString(col.REAL_NAME))
|
||||
.password(row.getString(col.PASSWORD), salt)
|
||||
.lastLogin(row.getLong(col.LAST_LOGIN))
|
||||
.ip(row.getString(col.IP))
|
||||
.lastIp(row.getString(col.LAST_IP))
|
||||
.email(row.getString(col.EMAIL))
|
||||
.registrationDate(row.getLong(col.REGISTRATION_DATE))
|
||||
.registrationIp(row.getString(col.REGISTRATION_IP))
|
||||
.groupId(group)
|
||||
.locWorld(row.getString(col.LASTLOC_WORLD))
|
||||
.locX(row.getDouble(col.LASTLOC_X))
|
||||
.locY(row.getDouble(col.LASTLOC_Y))
|
||||
.locZ(row.getDouble(col.LASTLOC_Z))
|
||||
.locYaw(row.getFloat(col.LASTLOC_YAW))
|
||||
.locPitch(row.getFloat(col.LASTLOC_PITCH))
|
||||
.email(row.getString(col.EMAIL))
|
||||
.groupId(group)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -706,6 +717,7 @@ public class MySQL implements DataSource {
|
||||
* Performs conversion of lastlogin column from timestamp type to bigint.
|
||||
*
|
||||
* @param con connection to the database
|
||||
* @see <a href="https://github.com/AuthMe/AuthMeReloaded/issues/477">#477</a>
|
||||
*/
|
||||
private void migrateLastLoginColumnFromTimestamp(Connection con) throws SQLException {
|
||||
ConsoleLogger.info("Migrating lastlogin column from timestamp to bigint");
|
||||
@@ -721,7 +733,7 @@ public class MySQL implements DataSource {
|
||||
// Create lastlogin column
|
||||
sql = String.format("ALTER TABLE %s ADD COLUMN %s "
|
||||
+ "BIGINT NOT NULL DEFAULT 0 AFTER %s",
|
||||
tableName, col.LAST_LOGIN, col.IP);
|
||||
tableName, col.LAST_LOGIN, col.LAST_IP);
|
||||
con.prepareStatement(sql).execute();
|
||||
|
||||
// Set values of lastlogin based on lastlogin_old
|
||||
@@ -740,6 +752,8 @@ public class MySQL implements DataSource {
|
||||
* Performs conversion of lastlogin column from int to bigint.
|
||||
*
|
||||
* @param con connection to the database
|
||||
* @see <a href="https://github.com/AuthMe/AuthMeReloaded/issues/887">
|
||||
* #887: Migrate lastlogin column from int32 to bigint</a>
|
||||
*/
|
||||
private void migrateLastLoginColumnFromInt(Connection con) throws SQLException {
|
||||
// Change from int to bigint
|
||||
|
||||
@@ -94,9 +94,9 @@ public class SQLite implements DataSource {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IP)) {
|
||||
if (isColumnMissing(md, col.LAST_IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.IP + " VARCHAR(40) NOT NULL DEFAULT '';");
|
||||
+ " ADD COLUMN " + col.LAST_IP + " VARCHAR(40) NOT NULL DEFAULT '';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
@@ -104,6 +104,16 @@ public class SQLite implements DataSource {
|
||||
+ " ADD COLUMN " + col.LAST_LOGIN + " TIMESTAMP;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REGISTRATION_IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.REGISTRATION_IP + " VARCHAR(40);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REGISTRATION_DATE)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.REGISTRATION_DATE + " TIMESTAMP NOT NULL DEFAULT '0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_X
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
@@ -209,6 +219,7 @@ public class SQLite implements DataSource {
|
||||
|
||||
@Override
|
||||
public boolean saveAuth(PlayerAuth auth) {
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
HashedPassword password = auth.getPassword();
|
||||
if (col.SALT.isEmpty()) {
|
||||
@@ -216,33 +227,36 @@ public class SQLite implements DataSource {
|
||||
ConsoleLogger.warning("Warning! Detected hashed password with separate salt but the salt column "
|
||||
+ "is not set in the config!");
|
||||
}
|
||||
try (PreparedStatement pst = con.prepareStatement("INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD +
|
||||
"," + col.IP + "," + col.LAST_LOGIN + "," + col.REAL_NAME + "," + col.EMAIL +
|
||||
") VALUES (?,?,?,?,?,?);")) {
|
||||
pst.setString(1, auth.getNickname());
|
||||
pst.setString(2, password.getHash());
|
||||
pst.setString(3, auth.getIp());
|
||||
pst.setLong(4, auth.getLastLogin());
|
||||
pst.setString(5, auth.getRealName());
|
||||
pst.setString(6, auth.getEmail());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
|
||||
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD
|
||||
+ "," + col.REAL_NAME + "," + col.EMAIL
|
||||
+ "," + col.REGISTRATION_DATE + "," + col.REGISTRATION_IP
|
||||
+ ") VALUES (?,?,?,?,?,?);");
|
||||
pst.setString(1, auth.getNickname());
|
||||
pst.setString(2, password.getHash());
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getEmail());
|
||||
pst.setLong(5, auth.getRegistrationDate());
|
||||
pst.setString(6, auth.getRegistrationIp());
|
||||
pst.executeUpdate();
|
||||
} else {
|
||||
try (PreparedStatement pst = con.prepareStatement("INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD + ","
|
||||
+ col.IP + "," + col.LAST_LOGIN + "," + col.REAL_NAME + "," + col.EMAIL + "," + col.SALT
|
||||
+ ") VALUES (?,?,?,?,?,?,?);")) {
|
||||
pst.setString(1, auth.getNickname());
|
||||
pst.setString(2, password.getHash());
|
||||
pst.setString(3, auth.getIp());
|
||||
pst.setLong(4, auth.getLastLogin());
|
||||
pst.setString(5, auth.getRealName());
|
||||
pst.setString(6, auth.getEmail());
|
||||
pst.setString(7, password.getSalt());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD
|
||||
+ "," + col.REAL_NAME + "," + col.EMAIL
|
||||
+ "," + col.REGISTRATION_DATE + "," + col.REGISTRATION_IP + "," + col.SALT
|
||||
+ ") VALUES (?,?,?,?,?,?,?);");
|
||||
pst.setString(1, auth.getNickname());
|
||||
pst.setString(2, password.getHash());
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getEmail());
|
||||
pst.setLong(5, auth.getRegistrationDate());
|
||||
pst.setString(6, auth.getRegistrationIp());
|
||||
pst.setString(7, password.getSalt());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -277,9 +291,10 @@ public class SQLite implements DataSource {
|
||||
|
||||
@Override
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
String sql = "UPDATE " + tableName + " SET " + col.IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
|
||||
String sql = "UPDATE " + tableName + " SET " + col.LAST_IP + "=?, " + col.LAST_LOGIN + "=?, "
|
||||
+ col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)){
|
||||
pst.setString(1, auth.getIp());
|
||||
pst.setString(1, auth.getLastIp());
|
||||
pst.setLong(2, auth.getLastLogin());
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getNickname());
|
||||
@@ -388,7 +403,7 @@ public class SQLite implements DataSource {
|
||||
@Override
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
List<String> countIp = new ArrayList<>();
|
||||
String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.IP + "=?;";
|
||||
String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_IP + "=?;";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, ip);
|
||||
try (ResultSet rs = pst.executeQuery()) {
|
||||
@@ -554,27 +569,24 @@ public class SQLite implements DataSource {
|
||||
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
|
||||
String salt = !col.SALT.isEmpty() ? row.getString(col.SALT) : null;
|
||||
|
||||
PlayerAuth.Builder authBuilder = PlayerAuth.builder()
|
||||
return PlayerAuth.builder()
|
||||
.name(row.getString(col.NAME))
|
||||
.email(row.getString(col.EMAIL))
|
||||
.realName(row.getString(col.REAL_NAME))
|
||||
.password(row.getString(col.PASSWORD), salt)
|
||||
.lastLogin(row.getLong(col.LAST_LOGIN))
|
||||
.lastIp(row.getString(col.LAST_IP))
|
||||
.registrationDate(row.getLong(col.REGISTRATION_DATE))
|
||||
.registrationIp(row.getString(col.REGISTRATION_IP))
|
||||
.locX(row.getDouble(col.LASTLOC_X))
|
||||
.locY(row.getDouble(col.LASTLOC_Y))
|
||||
.locZ(row.getDouble(col.LASTLOC_Z))
|
||||
.locWorld(row.getString(col.LASTLOC_WORLD))
|
||||
.locYaw(row.getFloat(col.LASTLOC_YAW))
|
||||
.locPitch(row.getFloat(col.LASTLOC_PITCH));
|
||||
|
||||
String ip = row.getString(col.IP);
|
||||
if (!ip.isEmpty()) {
|
||||
authBuilder.ip(ip);
|
||||
}
|
||||
return authBuilder.build();
|
||||
.locPitch(row.getFloat(col.LASTLOC_PITCH))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private static void close(Statement st) {
|
||||
if (st != null) {
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
@@ -20,4 +21,18 @@ final class SqlDataSourceUtils {
|
||||
static void logSqlException(SQLException e) {
|
||||
ConsoleLogger.logException("Error during SQL operation:", e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of a column, or null when appropriate. This method is necessary because
|
||||
* JDBC's {@link ResultSet#getLong} returns {@code 0} if the entry in the database is {@code null}.
|
||||
*
|
||||
* @param rs the result set to read from
|
||||
* @param columnName the name of the column to retrieve
|
||||
* @return the value (which may be null)
|
||||
* @throws SQLException :)
|
||||
*/
|
||||
static Long getNullableLong(ResultSet rs, String columnName) throws SQLException {
|
||||
long longValue = rs.getLong(columnName);
|
||||
return rs.wasNull() ? null : longValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ public abstract class AbstractDataSourceConverter<S extends DataSource> implemen
|
||||
} else {
|
||||
adaptPlayerAuth(auth);
|
||||
destination.saveAuth(auth);
|
||||
destination.updateSession(auth);
|
||||
destination.updateQuitLoc(auth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -94,6 +95,7 @@ public class LoginSecurityConverter implements Converter {
|
||||
} else {
|
||||
PlayerAuth auth = buildAuthFromLoginSecurity(name, resultSet);
|
||||
dataSource.saveAuth(auth);
|
||||
dataSource.updateSession(auth);
|
||||
++successfulSaves;
|
||||
}
|
||||
}
|
||||
@@ -113,16 +115,17 @@ public class LoginSecurityConverter implements Converter {
|
||||
* @return the created player auth object
|
||||
*/
|
||||
private static PlayerAuth buildAuthFromLoginSecurity(String name, ResultSet resultSet) throws SQLException {
|
||||
// TODO #792: Last login should be null if not present
|
||||
long lastLoginMillis = Optional.ofNullable(resultSet.getTimestamp("last_login"))
|
||||
.map(Timestamp::getTime).orElse(System.currentTimeMillis());
|
||||
Long lastLoginMillis = Optional.ofNullable(resultSet.getTimestamp("last_login"))
|
||||
.map(Timestamp::getTime).orElse(null);
|
||||
long regDate = Optional.ofNullable(resultSet.getDate("registration_date"))
|
||||
.map(Date::getTime).orElse(System.currentTimeMillis());
|
||||
return PlayerAuth.builder()
|
||||
.name(name)
|
||||
.realName(name)
|
||||
.password(resultSet.getString("password"), null)
|
||||
.ip(resultSet.getString("ip_address"))
|
||||
.lastIp(resultSet.getString("ip_address"))
|
||||
.lastLogin(lastLoginMillis)
|
||||
// TODO #792: Register date
|
||||
.registrationDate(regDate)
|
||||
.locX(resultSet.getDouble("x"))
|
||||
.locY(resultSet.getDouble("y"))
|
||||
.locZ(resultSet.getDouble("z"))
|
||||
|
||||
@@ -80,11 +80,11 @@ public class RakamakConverter implements Converter {
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(playerName)
|
||||
.realName(playerName)
|
||||
.ip(ip)
|
||||
.lastIp(ip)
|
||||
.password(psw)
|
||||
.lastLogin(0)
|
||||
.build();
|
||||
database.saveAuth(auth);
|
||||
database.updateSession(auth);
|
||||
}
|
||||
Utils.logAndSendMessage(sender, "Rakamak database has been imported correctly");
|
||||
} catch (IOException ex) {
|
||||
|
||||
@@ -46,6 +46,7 @@ public class RoyalAuthConverter implements Converter {
|
||||
.build();
|
||||
|
||||
dataSource.saveAuth(auth);
|
||||
dataSource.updateSession(auth);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Error while trying to import " + player.getName() + " RoyalAuth data", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user