diff options
| author | historia <[not public]> | 2026-09-15 14:18:14 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-15 14:18:14 -0400 |
| commit | 396c3facb8287b9a34076cae8f3d7b300d366d99 (patch) | |
| tree | 941f280d051fac474fa68ca08318a8d16adc8d0f /internal/casino/manager.go | |
| parent | b3568f03e4103dd46db2ccc680fbab0a6454d604 (diff) | |
| download | thehouseoficarus-396c3facb8287b9a34076cae8f3d7b300d366d99.tar.gz | |
fix: atomic saves, casino RNG/config isolation, tick lifecycle
Diffstat (limited to 'internal/casino/manager.go')
| -rw-r--r-- | internal/casino/manager.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/internal/casino/manager.go b/internal/casino/manager.go index a9bab92..38b754f 100644 --- a/internal/casino/manager.go +++ b/internal/casino/manager.go @@ -26,7 +26,11 @@ func tableKey(roomID int, tableID string) string { return fmt.Sprintf("%d:%s", roomID, tableID) } +// EnsureMachine returns nil for an invalid or unsupported configuration. func (m *Manager) EnsureMachine(roomID int, cfg MachineConfig) *Machine { + if cfg.Validate() != nil { + return nil + } cfg = cfg.Normalize() key := tableKey(roomID, cfg.ID) m.mu.Lock() @@ -34,14 +38,18 @@ func (m *Manager) EnsureMachine(roomID int, cfg MachineConfig) *Machine { if machine := m.machines[key]; machine != nil { return machine } - machine := newMachine(roomID, cfg, m.rng) + // Only the manager consumes its RNG, under m.mu. Each game owns an + // independent stream protected by that game's lock. + machine := newMachine(roomID, cfg, rand.New(rand.NewSource(m.rng.Int63()))) m.machines[key] = machine return machine } -// EnsureTable returns the table for cfg, or nil when cfg.Game has no -// multiplayer table implementation. +// EnsureTable returns nil for an invalid or unsupported configuration. func (m *Manager) EnsureTable(roomID int, cfg TableConfig) *Table { + if cfg.Validate() != nil { + return nil + } cfg = cfg.Normalize() key := tableKey(roomID, cfg.ID) m.mu.Lock() @@ -49,7 +57,7 @@ func (m *Manager) EnsureTable(roomID int, cfg TableConfig) *Table { if table := m.tables[key]; table != nil { return table } - table := newTable(roomID, cfg, m.rng) + table := newTable(roomID, cfg, rand.New(rand.NewSource(m.rng.Int63()))) if table == nil { return nil } @@ -122,7 +130,11 @@ func (m *Manager) withMachine(roomID int, machineID string, fn func(*Machine) [] } func (m *Manager) JoinMachine(roomID int, cfg MachineConfig, name string) []Event { - return m.EnsureMachine(roomID, cfg).join(name) + machine := m.EnsureMachine(roomID, cfg) + if machine == nil { + return []Event{{RoomID: roomID, TableID: cfg.ID, Type: EventResult, PrivateTo: name, Message: "That game is not available here."}} + } + return machine.join(name) } func (m *Manager) SetMachineBet(roomID int, machineID, name string, amount int, wallet Wallet) []Event { |
