diff options
Diffstat (limited to 'internal/net')
| -rw-r--r-- | internal/net/server.go | 4 | ||||
| -rw-r--r-- | internal/net/server_test.go | 15 |
2 files changed, 19 insertions, 0 deletions
diff --git a/internal/net/server.go b/internal/net/server.go index c715074..d983161 100644 --- a/internal/net/server.go +++ b/internal/net/server.go @@ -502,6 +502,10 @@ func (h *Hub) hardRemoveLocked(s *Session) func(*Session) { func (h *Hub) EnterRoom(s *Session, roomID int) { h.mu.Lock() defer h.mu.Unlock() + // A detailed table watch is scoped to the room it was set in: entering any + // room stops it, so leaving and returning does not silently resume it. + s.CasinoWatchRoom = 0 + s.CasinoWatchTable = "" h.leaveRoomLocked(s) if h.rooms[roomID] == nil { h.rooms[roomID] = make(map[*Session]bool) diff --git a/internal/net/server_test.go b/internal/net/server_test.go index da8084a..6a3b376 100644 --- a/internal/net/server_test.go +++ b/internal/net/server_test.go @@ -99,6 +99,21 @@ func (c *fakeNetConn) readDeadline() time.Time { return c.deadline } +// TestEnterRoomClearsCasinoWatch: detailed table watch is scoped to the room +// it was set in, so entering a room stops a stale watch instead of silently +// resuming it when the player returns. +func TestEnterRoomClearsCasinoWatch(t *testing.T) { + h := NewHub() + s := &Session{} + h.Add(s) + s.CasinoWatchRoom = 7 + s.CasinoWatchTable = "bj1" + h.EnterRoom(s, 9) + if s.CasinoWatchRoom != 0 || s.CasinoWatchTable != "" { + t.Fatalf("watch survived a room change: room=%d table=%q", s.CasinoWatchRoom, s.CasinoWatchTable) + } +} + // TestConnectionCapRefusalKeepsTheServerDrained: at maxConnections a new // connection is refused without holding a slot (the counter stays at the cap), // and the refused peer is told why. Once the admitted sessions end, the live |
