diff options
Diffstat (limited to 'internal/game/casino.go')
| -rw-r--r-- | internal/game/casino.go | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go index 58e1e69..23b6c51 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -147,6 +147,26 @@ func (w casinoWallet) ResolveStake(stakeID string) { } } +// ResolveStakesByIDs consumes the listed pending stakes in one durable save. +// A losing split/doubled hand used to call ResolveStake once per handle, each +// with its own full character save; batching removes that repeated fsync and +// the crash window between saves. +func (w casinoWallet) ResolveStakesByIDs(stakeIDs ...string) { + if len(stakeIDs) == 0 { + return + } + removed := takePendingWagers(w.p, stakeIDs) + if len(removed) == 0 { + return + } + if err := w.g.AccountStore.SaveCharacter(w.p); err != nil { + // The durable file still lists the stakes, so restore them in memory to + // keep the two records consistent for a later retry/recovery. + w.p.PendingWagers = append(w.p.PendingWagers, removed...) + fmt.Fprintf(os.Stderr, "casino resolve stakes: save for %s: %v (ledger restored in memory)\n", w.p.Name, err) + } +} + // RefundOutstanding returns every pending stake to the player — chips in // kind, credits as credits — and clears the ledger in one save. It is used // by graceful shutdown/eviction and by a pre-deal disconnect. On a failed @@ -272,6 +292,15 @@ func (g *Game) casinoMachine(roomID int, gameName string) (*casino.Machine, bool if casino.ValidateRoomConfigs(room.CasinoTables, room.CasinoMachines) != nil { return nil, false } + // An explicit machine id is the most specific address, so match it first: + // the shipped room's machine `huff_puff_01` must be reachable by name even + // though it also declares a variant. + for _, cfg := range room.CasinoMachines { + if strings.EqualFold(cfg.ID, gameName) { + machine := g.Casino.EnsureMachine(roomID, cfg) + return machine, machine != nil + } + } // Prefer an exact variant match first: a room may host several variants of // one game, where a bare game name is ambiguous. for _, cfg := range room.CasinoMachines { @@ -295,16 +324,6 @@ func (g *Game) casinoMachine(roomID int, gameName string) (*casino.Machine, bool return machine, machine != nil } } - // Migrate older room definitions that declared slots under casino_tables; - // slots are still always instantiated as one-player machines. - if strings.EqualFold(gameName, "slots") { - for _, cfg := range room.CasinoTables { - if strings.EqualFold(string(cfg.Game), "slots") { - machine := g.Casino.EnsureMachine(roomID, casino.LegacySlotMachine(cfg)) - return machine, machine != nil - } - } - } return nil, false } |
