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,18 +1575,23 @@ 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);
int nameChangeId = rs.getInt("id"); try {
int characterId = rs.getInt("characterId"); while (rs.next()) {
String oldName = rs.getString("old"); int nameChangeId = rs.getInt("id");
String newName = rs.getString("new"); int characterId = rs.getInt("characterId");
boolean success = MapleCharacter.doNameChange(con, characterId, oldName, newName, nameChangeId); String oldName = rs.getString("old");
if (!success) { String newName = rs.getString("new");
con.rollback(); //discard changes boolean success = MapleCharacter.doNameChange(con, characterId, oldName, newName, nameChangeId);
} else { if (!success) {
changedNames.add(new Pair<>(oldName, newName)); con.rollback(); //discard changes
} else {
con.commit();
changedNames.add(new Pair<>(oldName, newName));
}
} }
} finally {
con.setAutoCommit(true); con.setAutoCommit(true);
} }
//log //log
@@ -1625,23 +1630,29 @@ 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);
int nameChangeId = rs.getInt("id"); try {
if (removedTransfers.contains(nameChangeId)) { while (rs.next()) {
continue; int nameChangeId = rs.getInt("id");
} if (removedTransfers.contains(nameChangeId)) {
int characterId = rs.getInt("characterId"); continue;
int oldWorld = rs.getInt("from"); }
int newWorld = rs.getInt("to"); int characterId = rs.getInt("characterId");
boolean success = MapleCharacter.doWorldTransfer(con, characterId, oldWorld, newWorld, nameChangeId); int oldWorld = rs.getInt("from");
if (!success) { int newWorld = rs.getInt("to");
con.rollback(); boolean success = MapleCharacter.doWorldTransfer(con, characterId, oldWorld, newWorld, nameChangeId);
} else { if (!success) {
worldTransfers.add(new Pair<>(characterId, new Pair<>(oldWorld, newWorld))); con.rollback();
} else {
con.commit();
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();