aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/manager.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/manager.go')
-rw-r--r--internal/casino/manager.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/internal/casino/manager.go b/internal/casino/manager.go
index 78e26b0..4798217 100644
--- a/internal/casino/manager.go
+++ b/internal/casino/manager.go
@@ -3,6 +3,7 @@ package casino
import (
"fmt"
"math/rand"
+ "reflect"
"sort"
"strings"
"sync"
@@ -41,7 +42,10 @@ func (m *Manager) EnsureMachine(roomID int, cfg MachineConfig) *Machine {
m.mu.Lock()
defer m.mu.Unlock()
if machine := m.machines[key]; machine != nil {
- if machine.Config == cfg {
+ // DeepEqual (not ==) so the *bool rule fields compare by value;
+ // == would treat every freshly parsed config as different and
+ // discard an idle machine on every room load.
+ if reflect.DeepEqual(machine.Config, cfg) {
return machine
}
if machine.idle() {
@@ -74,7 +78,7 @@ func (m *Manager) EnsureTable(roomID int, cfg TableConfig) *Table {
m.mu.Lock()
defer m.mu.Unlock()
if table := m.tables[key]; table != nil {
- if table.Config == cfg {
+ if reflect.DeepEqual(table.Config, cfg) {
return table
}
if table.idle() {
@@ -308,6 +312,10 @@ func (m *Manager) RefundAll() []Event {
// (oldID -> newID): both the manager's map keys and each game's RoomID.
// Game state (wagers, rounds) is preserved — the games continue in the
// renamed room. Uses delete-all-then-set-all so a swap cannot clobber.
+//
+// Callers MUST run on the owner goroutine: each game's RoomID is mutated
+// without taking that game's own lock, which is safe only because Tick and
+// every command are owner-serialized too.
func (m *Manager) RekeyRooms(idMap map[int]int) {
if len(idMap) == 0 {
return