Actually perform name changes & world transfers on startup

No changes were being committed
This commit is contained in:
P0nk
2021-04-11 13:05:12 +02:00
parent ed100613f3
commit 858fcd2a3a

View File

@@ -1575,8 +1575,10 @@ public class Server {
PreparedStatement ps = con.prepareStatement("SELECT * FROM namechanges WHERE completionTime IS NULL"); PreparedStatement ps = con.prepareStatement("SELECT * FROM namechanges WHERE completionTime IS NULL");
ResultSet rs = ps.executeQuery()) { ResultSet rs = ps.executeQuery()) {
List<Pair<String, String>> changedNames = new LinkedList<>(); //logging only List<Pair<String, String>> changedNames = new LinkedList<>(); //logging only
while (rs.next()) {
con.setAutoCommit(false); con.setAutoCommit(false);
try {
while (rs.next()) {
int nameChangeId = rs.getInt("id"); int nameChangeId = rs.getInt("id");
int characterId = rs.getInt("characterId"); int characterId = rs.getInt("characterId");
String oldName = rs.getString("old"); String oldName = rs.getString("old");
@@ -1585,8 +1587,11 @@ public class Server {
if (!success) { if (!success) {
con.rollback(); //discard changes con.rollback(); //discard changes
} else { } else {
con.commit();
changedNames.add(new Pair<>(oldName, newName)); changedNames.add(new Pair<>(oldName, newName));
} }
}
} finally {
con.setAutoCommit(true); con.setAutoCommit(true);
} }
//log //log
@@ -1625,8 +1630,10 @@ public class Server {
} }
rs.beforeFirst(); rs.beforeFirst();
List<Pair<Integer, Pair<Integer, Integer>>> worldTransfers = new LinkedList<>(); //logging only <charid, <oldWorld, newWorld>> List<Pair<Integer, Pair<Integer, Integer>>> worldTransfers = new LinkedList<>(); //logging only <charid, <oldWorld, newWorld>>
while (rs.next()) {
con.setAutoCommit(false); con.setAutoCommit(false);
try {
while (rs.next()) {
int nameChangeId = rs.getInt("id"); int nameChangeId = rs.getInt("id");
if (removedTransfers.contains(nameChangeId)) { if (removedTransfers.contains(nameChangeId)) {
continue; continue;
@@ -1638,10 +1645,14 @@ public class Server {
if (!success) { if (!success) {
con.rollback(); con.rollback();
} else { } else {
con.commit();
worldTransfers.add(new Pair<>(characterId, new Pair<>(oldWorld, newWorld))); worldTransfers.add(new Pair<>(characterId, new Pair<>(oldWorld, newWorld)));
} }
}
} finally {
con.setAutoCommit(true); con.setAutoCommit(true);
} }
//log //log
for (Pair<Integer, Pair<Integer, Integer>> worldTransferPair : worldTransfers) { for (Pair<Integer, Pair<Integer, Integer>> worldTransferPair : worldTransfers) {
int charId = worldTransferPair.getLeft(); int charId = worldTransferPair.getLeft();