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:
simoleo89
2026-06-14 19:25:16 +02:00
parent c25cb2a9b6
commit 478c4c70b8
2 changed files with 48 additions and 1 deletions
@@ -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;
}
}