Remove the uuid index for name change conflicts

This commit is contained in:
games647
2016-07-12 12:23:32 +02:00
parent 9334296beb
commit f27bad02d3

View File

@@ -57,7 +57,6 @@ public class Storage {
+ "Premium BOOLEAN NOT NULL, " + "Premium BOOLEAN NOT NULL, "
+ "LastIp VARCHAR(255) NOT NULL, " + "LastIp VARCHAR(255) NOT NULL, "
+ "LastLogin TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " + "LastLogin TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "
+ "UNIQUE (UUID), "
//the premium shouldn't steal the cracked account by changing the name //the premium shouldn't steal the cracked account by changing the name
+ "UNIQUE (Name) " + "UNIQUE (Name) "
+ ")"; + ")";
@@ -67,6 +66,19 @@ public class Storage {
} }
createStmt.executeUpdate(createDataStmt); createStmt.executeUpdate(createDataStmt);
//drop the old unique index
try {
createStmt.executeUpdate("ALTER TABLE premium DROP INDEX UUID");
} catch (SQLException sqlEx) {
core.getLogger().log(Level.FINE, "Error dropping unique uuid index", sqlEx);
}
try {
createStmt.executeUpdate("CREATE INDEX uuid_idx on premium (UUID)");
} catch (SQLException sqlEx) {
core.getLogger().log(Level.FINE, "Error creating uuid index", sqlEx);
}
} finally { } finally {
closeQuietly(con); closeQuietly(con);
closeQuietly(createStmt); closeQuietly(createStmt);
@@ -155,6 +167,8 @@ public class Storage {
con = dataSource.getConnection(); con = dataSource.getConnection();
UUID uuid = playerProfile.getUuid(); UUID uuid = playerProfile.getUuid();
if (playerProfile.getUserId() == -1) {
if (uuid != null) { if (uuid != null) {
//User was authenticated with a premium authentication, so it's possible that the player is premium //User was authenticated with a premium authentication, so it's possible that the player is premium
updateStmt = con.prepareStatement("UPDATE " + PREMIUM_TABLE updateStmt = con.prepareStatement("UPDATE " + PREMIUM_TABLE
@@ -173,7 +187,6 @@ public class Storage {
} }
} }
if (playerProfile.getUserId() == -1) {
saveStmt = con.prepareStatement("INSERT INTO " + PREMIUM_TABLE saveStmt = con.prepareStatement("INSERT INTO " + PREMIUM_TABLE
+ " (UUID, Name, Premium, LastIp) VALUES (?, ?, ?, ?) ", Statement.RETURN_GENERATED_KEYS); + " (UUID, Name, Premium, LastIp) VALUES (?, ?, ?, ?) ", Statement.RETURN_GENERATED_KEYS);