diff options
Diffstat (limited to 'internal/game/cmd_quit.go')
| -rw-r--r-- | internal/game/cmd_quit.go | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/internal/game/cmd_quit.go b/internal/game/cmd_quit.go index 24519f8..85e3510 100644 --- a/internal/game/cmd_quit.go +++ b/internal/game/cmd_quit.go @@ -1,11 +1,17 @@ package game import ( + "strings" + "thehouseoficarus/internal/engine" "thehouseoficarus/internal/net" ) func (g *Game) executeQuit(sess *net.Session, args []string, rawInput string) { + if len(args) > 0 && strings.EqualFold(args[0], "now") { + g.doQuitNow(sess) + return + } g.doQuit(sess) } @@ -22,11 +28,39 @@ func (g *Game) doQuit(sess *net.Session) { // Depart casino games the way "stop" does: a table with a wager committed // to the round in flight refuses and the quit is aborted, so deliberate // exits never forfeit a stake or reveal cards mid-hand. Forfeit-on-leave - // stays reserved for genuine disconnects (hub.OnDisconnect). + // stays reserved for genuine disconnects and "quit now". if !g.leaveCasinoGames(sess, p) { + sess.WriteLine(g.colorize(sess, "warning", "Type \"quit now\" to log out anyway — your bet will be forfeited.")) + return + } + + g.beginQuitCountdown(sess) +} + +// doQuitNow force-quits past a table's mid-round refusal. The logout +// countdown starts immediately, but the seat and wager are only forfeited +// on the countdown's final tick, immediately before the disconnect — until +// then any active or free command (or "stop") cancels the countdown and +// leaves the wager intact. +func (g *Game) doQuitNow(sess *net.Session) { + p := sess.Player + if g.Combat.Get(p.Name) != nil { + sess.WriteLine("You can't rest during combat!") return } + if g.inCasinoGame(p.Name) { + sess.WriteLine(g.colorize(sess, "warning", "WARNING: Logging out mid-game will forfeit your bet! Type \"stop\" to cancel.")) + } + g.beginQuitCountdown(sess) +} +// beginQuitCountdown runs the shared logout sequence: stop any current +// action, then count ten ticks down to the final tick that severs the +// session. Casino participation (a "quit now" mid-game) is resolved on +// that final tick via MarkDisconnected, so the countdown stays cancellable +// the whole way down. +func (g *Game) beginQuitCountdown(sess *net.Session) { + p := sess.Player g.cancelAction(p) g.cancelRest(p.Name) @@ -44,6 +78,9 @@ func (g *Game) doQuit(sess *net.Session) { case 0: g.cancelRest(p.Name) g.restoreGodPlayer(p) + // Forfeit any committed casino wager and free the seat only + // now — immediately before the disconnect. Settling games only + // pay seated bettors, so this forfeits a mid-round stake. g.emitCasinoEvents(g.Casino.MarkDisconnected(p.Name)) g.AccountStore.SaveCharacter(p) g.charsMu.Lock() |
