diff options
| author | historia <[not public]> | 2026-09-16 02:56:56 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-16 02:56:56 -0400 |
| commit | f2d44f10f52d3fe68fdb19b518a330f7af9e1ed2 (patch) | |
| tree | 9db54e8d4fd2f9bd30c651700f7cf246eef1b017 /internal/game/casino.go | |
| parent | ad60843fbf577eda80105e3916822d663aaefcb3 (diff) | |
| download | thehouseoficarus-f2d44f10f52d3fe68fdb19b518a330f7af9e1ed2.tar.gz | |
fix: disconnect race, rename ownership, reserved pickup, economy recovery retry/refund semantics
Diffstat (limited to 'internal/game/casino.go')
| -rw-r--r-- | internal/game/casino.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go index bc1e690..0441903 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -77,6 +77,14 @@ func (w casinoWallet) Wager(amount int) (casino.Wager, error) { // if the save fails, the record stays open and startup recovery re-pays it // (the player is owed the settlement). func (w casinoWallet) PayCredits(amount int) error { + return w.payCreditsFlagged(amount, false) +} + +// payCreditsFlagged journals and applies a credit payout; a settlement +// payout (refund=false) proves the round resolved during recovery, while a +// refund payout (refund=true) marks a stake RETURNED at shutdown/eviction +// (its chip part returns in chips, not through this credit payout). +func (w casinoWallet) payCreditsFlagged(amount int, refund bool) error { if amount <= 0 { return nil } @@ -88,7 +96,7 @@ func (w casinoWallet) PayCredits(amount int) error { // With the cap blocking, the balance is unchanged and the open record // keeps the owed amount durable; startup recovery re-applies it once // the balance has room below the cap. - rec, err := w.g.Economy.start("payout", w.p, 0, amount, + rec, err := w.g.Economy.startKind("payout", refund, w.p, 0, amount, creditsBefore, creditsAfter, chipsBefore, chipsBefore) if err != nil { return casino.ErrWalletPersistence @@ -111,7 +119,7 @@ func (w casinoWallet) PayCredits(amount int) error { // round resolved (won, lost, pushed, or forfeited), so startup recovery // must no longer refund it. func (w casinoWallet) ResolveStakes() { - w.g.Economy.ResolveStakes(w.p.Name) + w.g.Economy.ResolveStakes(economyKey(w.p)) } // RefundOutstanding returns every outstanding stake to the player: chips @@ -119,7 +127,7 @@ func (w casinoWallet) ResolveStakes() { // are resolved only once the return is durable; on failure the chip return // is rolled back out of memory and the open records drive recovery instead. func (w casinoWallet) RefundOutstanding() (chips, credits int, err error) { - for _, rec := range w.g.Economy.openStakes(w.p.Name) { + for _, rec := range w.g.Economy.openStakes(economyKey(w.p)) { chips += rec.Chips credits += rec.Credit } @@ -138,7 +146,7 @@ func (w casinoWallet) RefundOutstanding() (chips, credits int, err error) { } } if credits > 0 { - if err := w.PayCredits(credits); err != nil { + if err := w.payCreditsFlagged(credits, true); err != nil { if chips > 0 { // Roll the chip return back out of memory: the durable // refund will re-apply both amounts from the open records. |
