snapshot_poker_uiux_cleanup_2
This commit is contained in:
@@ -818,6 +818,22 @@ function createMongoPokerStore(
|
||||
);
|
||||
},
|
||||
|
||||
async deleteGame(
|
||||
gameId
|
||||
) {
|
||||
const result =
|
||||
await collection.deleteOne({
|
||||
gameId,
|
||||
gameType:
|
||||
POKER_GAME_TYPE,
|
||||
recordType:
|
||||
"game"
|
||||
});
|
||||
|
||||
return result.deletedCount ===
|
||||
1;
|
||||
},
|
||||
|
||||
async listActiveGames() {
|
||||
const documents =
|
||||
await collection
|
||||
@@ -1114,6 +1130,22 @@ function createDefaultPokerEconomy() {
|
||||
userId,
|
||||
operationId
|
||||
);
|
||||
},
|
||||
|
||||
async clearOperation(
|
||||
userId,
|
||||
operationId
|
||||
) {
|
||||
const {
|
||||
clearCookieOperation
|
||||
} = require(
|
||||
"./cookieEconomy"
|
||||
);
|
||||
|
||||
return clearCookieOperation(
|
||||
userId,
|
||||
operationId
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1139,6 +1171,43 @@ function createPokerService({
|
||||
lobbyTimeout =
|
||||
POKER_LOBBY_TIMEOUT
|
||||
} = {}) {
|
||||
async function clearOperationQuietly(
|
||||
userId,
|
||||
operationId
|
||||
) {
|
||||
try {
|
||||
await economy.clearOperation(
|
||||
userId,
|
||||
operationId
|
||||
);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(
|
||||
`[Poker] Failed to clear completed Cookie operation ${operationId} for ${userId}:`,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteGameQuietly(
|
||||
gameId
|
||||
) {
|
||||
try {
|
||||
await store.deleteGame(
|
||||
gameId
|
||||
);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(
|
||||
`[Poker] Failed to delete settled table ${gameId}:`,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function readGame(
|
||||
gameId
|
||||
) {
|
||||
@@ -1234,6 +1303,22 @@ function createPokerService({
|
||||
gameId,
|
||||
sessionId
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
buyInOperationId(
|
||||
gameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
buyInRefundOperationId(
|
||||
gameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1362,6 +1447,14 @@ function createPokerService({
|
||||
sessionId,
|
||||
now()
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
ownerId,
|
||||
buyInOperationId(
|
||||
gameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
@@ -1519,6 +1612,14 @@ function createPokerService({
|
||||
sessionId,
|
||||
now()
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
buyInOperationId(
|
||||
gameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
@@ -2317,6 +2418,23 @@ function createPokerService({
|
||||
player.sessionId
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
cashOutOperationId(
|
||||
gameId,
|
||||
player.sessionId
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
nextGame.state ===
|
||||
"CLOSED"
|
||||
) {
|
||||
await deleteGameQuietly(
|
||||
gameId
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
amount,
|
||||
game:
|
||||
@@ -2403,6 +2521,23 @@ function createPokerService({
|
||||
closed
|
||||
)
|
||||
) {
|
||||
for (
|
||||
const player
|
||||
of current.data.players
|
||||
) {
|
||||
await clearOperationQuietly(
|
||||
player.userId,
|
||||
cashOutOperationId(
|
||||
gameId,
|
||||
player.sessionId
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
await deleteGameQuietly(
|
||||
gameId
|
||||
);
|
||||
|
||||
return closed;
|
||||
}
|
||||
}
|
||||
@@ -2413,6 +2548,88 @@ function createPokerService({
|
||||
);
|
||||
}
|
||||
|
||||
async function cancelTable({
|
||||
gameId,
|
||||
userId
|
||||
}) {
|
||||
const game =
|
||||
await readGame(
|
||||
gameId
|
||||
);
|
||||
|
||||
if (
|
||||
String(game.data.ownerId) !==
|
||||
String(userId)
|
||||
) {
|
||||
throw new PokerTableError(
|
||||
"NOT_TABLE_OWNER",
|
||||
"Only the Poker table owner can cancel this table."
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
isHandActive(
|
||||
game
|
||||
)
|
||||
) {
|
||||
throw new PokerTableError(
|
||||
"CANCEL_HAND_ACTIVE",
|
||||
"Finish the current hand before cancelling the table."
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
game.state ===
|
||||
"CLOSING"
|
||||
) {
|
||||
return finishClosingTable(
|
||||
gameId
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!POKER_OPEN_STATES.includes(
|
||||
game.state
|
||||
)
|
||||
) {
|
||||
throw new PokerTableError(
|
||||
"TABLE_NOT_CANCELLABLE",
|
||||
"This Poker table cannot be cancelled in its current state."
|
||||
);
|
||||
}
|
||||
|
||||
const closing =
|
||||
clone(game);
|
||||
|
||||
closing.state =
|
||||
"CLOSING";
|
||||
|
||||
closing.version =
|
||||
game.version + 1;
|
||||
|
||||
closing.updatedAt =
|
||||
now();
|
||||
|
||||
const committed =
|
||||
await store.updateGameVersion(
|
||||
gameId,
|
||||
game.version,
|
||||
closing
|
||||
);
|
||||
|
||||
if (!committed) {
|
||||
throw new PokerTableError(
|
||||
"STATE_CONFLICT",
|
||||
"Poker table changed while cancellation was starting."
|
||||
);
|
||||
}
|
||||
|
||||
return finishClosingTable(
|
||||
gameId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
async function expireLobby(
|
||||
gameId
|
||||
) {
|
||||
@@ -2569,6 +2786,28 @@ function createPokerService({
|
||||
player.sessionId
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
player.userId,
|
||||
cashOutOperationId(
|
||||
game.gameId,
|
||||
player.sessionId
|
||||
)
|
||||
);
|
||||
|
||||
const remainingGame =
|
||||
await store.getGame(
|
||||
game.gameId
|
||||
);
|
||||
|
||||
if (
|
||||
remainingGame?.state ===
|
||||
"CLOSED"
|
||||
) {
|
||||
await deleteGameQuietly(
|
||||
game.gameId
|
||||
);
|
||||
}
|
||||
|
||||
results.push({
|
||||
gameId:
|
||||
game.gameId,
|
||||
@@ -2651,6 +2890,14 @@ function createPokerService({
|
||||
now()
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
buyInOperationId(
|
||||
tableGameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
|
||||
results.push({
|
||||
userId,
|
||||
gameId:
|
||||
@@ -2692,6 +2939,22 @@ function createPokerService({
|
||||
sessionId
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
buyInOperationId(
|
||||
tableGameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
|
||||
await clearOperationQuietly(
|
||||
userId,
|
||||
buyInRefundOperationId(
|
||||
tableGameId,
|
||||
sessionId
|
||||
)
|
||||
);
|
||||
|
||||
results.push({
|
||||
userId,
|
||||
gameId:
|
||||
@@ -2750,6 +3013,7 @@ function createPokerService({
|
||||
processTurnTimeout,
|
||||
processExpiredTurns,
|
||||
cashOut,
|
||||
cancelTable,
|
||||
finishClosingTable,
|
||||
expireLobby,
|
||||
processExpiredLobbies,
|
||||
|
||||
Reference in New Issue
Block a user