#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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user