You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 07:26:18 +00:00
fix(marketplace): only pay out claimed offers after detach
MarketPlace.getCredits previously removed sold offers from memory and granted credits before knowing whether marketplace_items.user_id had been detached in the database. If that update failed, the same sold offer could be loaded as claimable again later. Make removeUser report success, keep the offer claimable on failure, and only grant credits after the database detach succeeds.
This commit is contained in:
@@ -398,11 +398,12 @@ public class MarketPlace {
|
||||
synchronized (client.getHabbo().getInventory()) {
|
||||
for (MarketPlaceOffer offer : offers) {
|
||||
if (offer.getState().equals(MarketPlaceState.SOLD)) {
|
||||
client.getHabbo().getInventory().removeMarketplaceOffer(offer);
|
||||
credits += offer.getPrice();
|
||||
removeUser(offer);
|
||||
offer.needsUpdate(true);
|
||||
Emulator.getThreading().run(offer);
|
||||
if (removeUser(offer)) {
|
||||
client.getHabbo().getInventory().removeMarketplaceOffer(offer);
|
||||
credits += offer.getPrice();
|
||||
offer.needsUpdate(true);
|
||||
Emulator.getThreading().run(offer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -416,13 +417,14 @@ public class MarketPlace {
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeUser(MarketPlaceOffer offer) {
|
||||
private static boolean removeUser(MarketPlaceOffer offer) {
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE marketplace_items SET user_id = ? WHERE id = ?")) {
|
||||
statement.setInt(1, -1);
|
||||
statement.setInt(2, offer.getOfferId());
|
||||
statement.execute();
|
||||
return statement.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Caught SQL exception", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user