diff options
Diffstat (limited to 'internal/game/casino.go')
| -rw-r--r-- | internal/game/casino.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go index 8ba9097..3f06b41 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -2,6 +2,7 @@ package game import ( "fmt" + "os" "strconv" "strings" "unicode/utf8" @@ -56,7 +57,11 @@ func (w casinoWallet) Wager(amount int) (casino.Wager, error) { // Revert the in-memory mutation: the play must not proceed on a // stake that could not be made durable. if chips > 0 { - w.g.giveChips(w.p, chips) + if !w.g.giveChips(w.p, chips) { + // Cannot happen (the debit just freed or reduced the chips + // stack), but surface it instead of silently losing chips. + fmt.Fprintf(os.Stderr, "casino wager revert: no inventory room for %d chips\n", chips) + } } w.p.Credits += credits w.g.Economy.void(rec) @@ -118,7 +123,14 @@ func (w casinoWallet) RefundOutstanding() (chips, credits int, err error) { return 0, 0, nil } if chips > 0 { - w.g.giveChips(w.p, chips) + if !w.g.giveChips(w.p, chips) { + // No inventory room for the chip return: nothing was refunded. + // The stakes stay open so recovery (or a later attempt once the + // player has inventory space) can complete the refund; callers + // report the stake as recorded rather than refunded, never as + // silently dropped. + return 0, 0, casino.ErrWalletPersistence + } } if credits > 0 { if err := w.PayCredits(credits); err != nil { |
