snapshot_poker_phase4_hotfix
This commit is contained in:
+28
-1
@@ -153,6 +153,32 @@ async function recoverPoker(
|
|||||||
const result =
|
const result =
|
||||||
await service.recover();
|
await service.recover();
|
||||||
|
|
||||||
|
const activeTables =
|
||||||
|
await service.listActiveTables();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rehydrate every still-active public Poker table after
|
||||||
|
* restart, even when no recovery action was necessary.
|
||||||
|
* Mongo remains authoritative; the Discord embed is only
|
||||||
|
* a projection of the current stored game state.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (const game of activeTables) {
|
||||||
|
try {
|
||||||
|
await refreshPokerTableMessage(
|
||||||
|
client,
|
||||||
|
game
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(
|
||||||
|
`[Poker] Failed to refresh active table ${game.gameId}:`,
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (
|
for (
|
||||||
const turn
|
const turn
|
||||||
of result.turns ?? []
|
of result.turns ?? []
|
||||||
@@ -212,7 +238,8 @@ async function recoverPoker(
|
|||||||
`${result.cashouts.length} cash-out(s), ` +
|
`${result.cashouts.length} cash-out(s), ` +
|
||||||
`${result.closingTables.length} closing table(s), ` +
|
`${result.closingTables.length} closing table(s), ` +
|
||||||
`${result.turns.length} expired turn(s), ` +
|
`${result.turns.length} expired turn(s), ` +
|
||||||
`${result.lobbies.length} expired lobby/lobbies.`
|
`${result.lobbies.length} expired lobby/lobbies, ` +
|
||||||
|
`${activeTables.length} active table(s) refreshed.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+73
-4
@@ -36,7 +36,7 @@ const POKER_DEFAULT_BIG_BLIND =
|
|||||||
200;
|
200;
|
||||||
|
|
||||||
const POKER_DEFAULT_BUY_IN =
|
const POKER_DEFAULT_BUY_IN =
|
||||||
5000;
|
1000;
|
||||||
|
|
||||||
const POKER_TURN_TIMEOUT =
|
const POKER_TURN_TIMEOUT =
|
||||||
30;
|
30;
|
||||||
@@ -652,6 +652,22 @@ function getSpecialGameCollection() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripMongoId(
|
||||||
|
document
|
||||||
|
) {
|
||||||
|
if (!document) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
_id,
|
||||||
|
...rest
|
||||||
|
} = document;
|
||||||
|
|
||||||
|
return rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function createMongoPokerStore(
|
function createMongoPokerStore(
|
||||||
collection =
|
collection =
|
||||||
getSpecialGameCollection()
|
getSpecialGameCollection()
|
||||||
@@ -660,13 +676,18 @@ function createMongoPokerStore(
|
|||||||
async getGame(
|
async getGame(
|
||||||
gameId
|
gameId
|
||||||
) {
|
) {
|
||||||
return collection.findOne({
|
const document =
|
||||||
|
await collection.findOne({
|
||||||
gameId,
|
gameId,
|
||||||
gameType:
|
gameType:
|
||||||
POKER_GAME_TYPE,
|
POKER_GAME_TYPE,
|
||||||
recordType:
|
recordType:
|
||||||
"game"
|
"game"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return stripMongoId(
|
||||||
|
document
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
async insertGame(
|
async insertGame(
|
||||||
@@ -687,6 +708,14 @@ function createMongoPokerStore(
|
|||||||
const replacement =
|
const replacement =
|
||||||
clone(nextGame);
|
clone(nextGame);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MongoDB owns _id. Domain game objects must never
|
||||||
|
* replace it, especially after structuredClone()
|
||||||
|
* has converted a BSON ObjectId into a plain object.
|
||||||
|
*/
|
||||||
|
|
||||||
|
delete replacement._id;
|
||||||
|
|
||||||
const result =
|
const result =
|
||||||
await collection.replaceOne(
|
await collection.replaceOne(
|
||||||
{
|
{
|
||||||
@@ -709,7 +738,8 @@ function createMongoPokerStore(
|
|||||||
guildId,
|
guildId,
|
||||||
userId
|
userId
|
||||||
) {
|
) {
|
||||||
return collection.findOne({
|
const document =
|
||||||
|
await collection.findOne({
|
||||||
gameType:
|
gameType:
|
||||||
POKER_GAME_TYPE,
|
POKER_GAME_TYPE,
|
||||||
recordType:
|
recordType:
|
||||||
@@ -727,6 +757,10 @@ function createMongoPokerStore(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return stripMongoId(
|
||||||
|
document
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
async listJoinableGames(
|
async listJoinableGames(
|
||||||
@@ -751,7 +785,8 @@ function createMongoPokerStore(
|
|||||||
channelId;
|
channelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection
|
const documents =
|
||||||
|
await collection
|
||||||
.find(filter)
|
.find(filter)
|
||||||
.sort({
|
.sort({
|
||||||
updatedAt: -1
|
updatedAt: -1
|
||||||
@@ -766,6 +801,34 @@ function createMongoPokerStore(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
|
return documents.map(
|
||||||
|
stripMongoId
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
async listActiveGames() {
|
||||||
|
const documents =
|
||||||
|
await collection
|
||||||
|
.find({
|
||||||
|
gameType:
|
||||||
|
POKER_GAME_TYPE,
|
||||||
|
recordType:
|
||||||
|
"game",
|
||||||
|
state: {
|
||||||
|
$nin: [
|
||||||
|
"CLOSED"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort({
|
||||||
|
updatedAt: -1
|
||||||
|
})
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
return documents.map(
|
||||||
|
stripMongoId
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
async claimMembership({
|
async claimMembership({
|
||||||
@@ -2624,6 +2687,11 @@ function createPokerService({
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function listActiveTables() {
|
||||||
|
return store.listActiveGames();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function recover() {
|
async function recover() {
|
||||||
const [
|
const [
|
||||||
memberships,
|
memberships,
|
||||||
@@ -2670,6 +2738,7 @@ function createPokerService({
|
|||||||
recoverClosingTables,
|
recoverClosingTables,
|
||||||
recoverPendingMemberships,
|
recoverPendingMemberships,
|
||||||
recover,
|
recover,
|
||||||
|
listActiveTables,
|
||||||
|
|
||||||
publicTableState,
|
publicTableState,
|
||||||
sanitizeGameForCaller
|
sanitizeGameForCaller
|
||||||
|
|||||||
Reference in New Issue
Block a user