Added cash shop name changes and world transfers. (#495)
* Name changes * World transfers. Fix NPE. Applied Arnuh's suggestions. More logging.
This commit is contained in:
@@ -103,6 +103,7 @@ import server.life.MaplePlayerNPCFactory;
|
||||
import server.quest.MapleQuest;
|
||||
import tools.AutoJCE;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.FilePrinter;
|
||||
import tools.Pair;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
|
||||
@@ -881,7 +882,8 @@ public class Server {
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
applyAllNameChanges(); //name changes can be missed by INSTANT_NAME_CHANGE
|
||||
applyAllWorldTransfers();
|
||||
MaplePet.clearMissingPetsFromDb();
|
||||
MapleCashidGenerator.loadExistentCashIdsFromDb();
|
||||
|
||||
@@ -1554,6 +1556,82 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyAllNameChanges() {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM namechanges WHERE completionTime IS NULL")) {
|
||||
ResultSet rs = ps.executeQuery();
|
||||
List<Pair<String, String>> changedNames = new LinkedList<Pair<String, String>>(); //logging only
|
||||
while(rs.next()) {
|
||||
con.setAutoCommit(false);
|
||||
int nameChangeId = rs.getInt("id");
|
||||
int characterId = rs.getInt("characterId");
|
||||
String oldName = rs.getString("old");
|
||||
String newName = rs.getString("new");
|
||||
boolean success = MapleCharacter.doNameChange(con, characterId, oldName, newName, nameChangeId);
|
||||
if(!success) con.rollback(); //discard changes
|
||||
else changedNames.add(new Pair<String, String>(oldName, newName));
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
//log
|
||||
for(Pair<String, String> namePair : changedNames) {
|
||||
FilePrinter.print(FilePrinter.CHANGE_CHARACTER_NAME, "Name change applied : from \"" + namePair.getLeft() + "\" to \"" + namePair.getRight() + "\" at " + Calendar.getInstance().getTime().toString());
|
||||
}
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to retrieve list of pending name changes.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyAllWorldTransfers() {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM worldtransfers WHERE completionTime IS NULL")) {
|
||||
ResultSet rs = ps.executeQuery();
|
||||
List<Integer> removedTransfers = new LinkedList<Integer>();
|
||||
while(rs.next()) {
|
||||
int nameChangeId = rs.getInt("id");
|
||||
int characterId = rs.getInt("characterId");
|
||||
int oldWorld = rs.getInt("from");
|
||||
int newWorld = rs.getInt("to");
|
||||
String reason = MapleCharacter.checkWorldTransferEligibility(con, characterId, oldWorld, newWorld); //check if character is still eligible
|
||||
if(reason != null) {
|
||||
removedTransfers.add(nameChangeId);
|
||||
FilePrinter.print(FilePrinter.WORLD_TRANSFER, "World transfer cancelled : Character ID " + characterId + " at " + Calendar.getInstance().getTime().toString() + ", Reason : " + reason);
|
||||
try (PreparedStatement delPs = con.prepareStatement("DELETE FROM worldtransfers WHERE id = ?")) {
|
||||
delPs.setInt(1, nameChangeId);
|
||||
delPs.executeUpdate();
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to delete world transfer for character ID " + characterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
rs.beforeFirst();
|
||||
List<Pair<Integer, Pair<Integer, Integer>>> worldTransfers = new LinkedList<Pair<Integer, Pair<Integer, Integer>>>(); //logging only <charid, <oldWorld, newWorld>>
|
||||
while(rs.next()) {
|
||||
con.setAutoCommit(false);
|
||||
int nameChangeId = rs.getInt("id");
|
||||
if(removedTransfers.contains(nameChangeId)) continue;
|
||||
int characterId = rs.getInt("characterId");
|
||||
int oldWorld = rs.getInt("from");
|
||||
int newWorld = rs.getInt("to");
|
||||
boolean success = MapleCharacter.doWorldTransfer(con, characterId, oldWorld, newWorld, nameChangeId);
|
||||
if(!success) con.rollback();
|
||||
else worldTransfers.add(new Pair<Integer, Pair<Integer, Integer>>(characterId, new Pair<Integer, Integer>(oldWorld, newWorld)));
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
//log
|
||||
for(Pair<Integer, Pair<Integer, Integer>> worldTransferPair : worldTransfers) {
|
||||
int charId = worldTransferPair.getLeft();
|
||||
int oldWorld = worldTransferPair.getRight().getLeft();
|
||||
int newWorld = worldTransferPair.getRight().getRight();
|
||||
FilePrinter.print(FilePrinter.WORLD_TRANSFER, "World transfer applied : Character ID " + charId + " from World " + oldWorld + " to World " + newWorld + " at " + Calendar.getInstance().getTime().toString());
|
||||
}
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to retrieve list of pending world transfers.");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadAccountCharacters(MapleClient c) {
|
||||
Integer accId = c.getAccID();
|
||||
if (!isFirstAccountLogin(accId)) {
|
||||
|
||||
Reference in New Issue
Block a user