You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 15:36:17 +00:00
fix(trading): prevent duplicate active trades
Guard RoomTradeManager.startTrade while holding the activeTrades lock so concurrent trade starts cannot register the same participant in multiple active trades before room status updates settle. Add a contract test covering the lock-scoped participant guard and keep the existing trade safety tests green.
This commit is contained in:
@@ -19,8 +19,13 @@ public class RoomTradeManager {
|
||||
* Starts a trade between two users.
|
||||
*/
|
||||
public void startTrade(Habbo userOne, Habbo userTwo) {
|
||||
RoomTrade trade = new RoomTrade(userOne, userTwo, this.room);
|
||||
RoomTrade trade;
|
||||
synchronized (this.activeTrades) {
|
||||
if (this.hasActiveTrade(userOne) || this.hasActiveTrade(userTwo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
trade = new RoomTrade(userOne, userTwo, this.room);
|
||||
this.activeTrades.add(trade);
|
||||
}
|
||||
|
||||
@@ -58,4 +63,16 @@ public class RoomTradeManager {
|
||||
public THashSet<RoomTrade> getActiveTrades() {
|
||||
return this.activeTrades;
|
||||
}
|
||||
|
||||
private boolean hasActiveTrade(Habbo user) {
|
||||
for (RoomTrade trade : this.activeTrades) {
|
||||
for (RoomTradeUser habbo : trade.getRoomTradeUsers()) {
|
||||
if (habbo.getHabbo() == user) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user