mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 19:46:42 +00:00
Stage 2 of IP -> UUID migration: changing the admin list to use UUIDs
This commit is contained in:
@ -84,7 +84,7 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.createStatement().execute("CREATE TABLE `admins` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `ptero_id` VARCHAR);");
|
||||
connection.createStatement().execute("CREATE TABLE `admins` (`uuid` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `ptero_id` VARCHAR);");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@ -135,8 +135,8 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] data = {key, admin.getName()};
|
||||
PreparedStatement statement = connection.prepareStatement(MessageFormat.format("UPDATE admins SET {0}=? WHERE username=''{1}''", data));
|
||||
Object[] data = {key, admin.getUuid()};
|
||||
PreparedStatement statement = connection.prepareStatement(MessageFormat.format("UPDATE admins SET {0}=? WHERE uuid=''{1}''", data));
|
||||
statement = setUnknownType(statement, 1, value);
|
||||
statement.executeUpdate();
|
||||
|
||||
@ -164,21 +164,6 @@ public class SQLite extends FreedomService
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAdminName(String oldName, String newName)
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement(MessageFormat.format("UPDATE admins SET username=? WHERE username=''{0}''", oldName));
|
||||
statement = setUnknownType(statement, 1, newName);
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to update admin name: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public PreparedStatement setUnknownType(PreparedStatement statement, int index, Object value) throws SQLException
|
||||
{
|
||||
if (value == null)
|
||||
@ -235,7 +220,7 @@ public class SQLite extends FreedomService
|
||||
try
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO admins VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
statement.setString(1, admin.getName());
|
||||
statement.setString(1, admin.getUuid().toString());
|
||||
statement.setString(2, FUtil.listToString(admin.getIps()));
|
||||
statement.setString(3, admin.getRank().toString());
|
||||
statement.setBoolean(4, admin.isActive());
|
||||
@ -282,11 +267,11 @@ public class SQLite extends FreedomService
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet getAdminByName(String name)
|
||||
public ResultSet getAdminByUuid(UUID uuid)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultSet resultSet = connection.createStatement().executeQuery(MessageFormat.format("SELECT * FROM admins WHERE username=''{0}''", name));
|
||||
ResultSet resultSet = connection.createStatement().executeQuery(MessageFormat.format("SELECT * FROM admins WHERE uuid=''{0}''", uuid.toString()));
|
||||
if (resultSet.next())
|
||||
{
|
||||
return resultSet;
|
||||
|
Reference in New Issue
Block a user