diff options
| author | historia <[not public]> | 2026-07-31 17:44:10 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-31 17:44:10 -0400 |
| commit | f51424c90dbce7191a31b6e675818c985f0f4539 (patch) | |
| tree | a7845a2e09bd6e83d2d034f5e702a4940f38126a /internal/net/server.go | |
| parent | 58758d41488a777d2bc0e787be655363bdd9eb60 (diff) | |
| download | thehouseoficarus-f51424c90dbce7191a31b6e675818c985f0f4539.tar.gz | |
feat: casino framework and basic slot machine
Diffstat (limited to 'internal/net/server.go')
| -rw-r--r-- | internal/net/server.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/internal/net/server.go b/internal/net/server.go index 9da90ea..da1c01b 100644 --- a/internal/net/server.go +++ b/internal/net/server.go @@ -100,10 +100,11 @@ type Server struct { } type Hub struct { - mu sync.Mutex - sessions map[*Session]bool - rooms map[int]map[*Session]bool - onRemove func(*Session) + mu sync.Mutex + sessions map[*Session]bool + rooms map[int]map[*Session]bool + onRemove func(*Session) + onDisconnect func(*Session) } func NewHub() *Hub { @@ -119,6 +120,12 @@ func (h *Hub) OnRemove(cb func(*Session)) { h.onRemove = cb } +func (h *Hub) OnDisconnect(cb func(*Session)) { + h.mu.Lock() + defer h.mu.Unlock() + h.onDisconnect = cb +} + func (h *Hub) Add(s *Session) { h.mu.Lock() defer h.mu.Unlock() @@ -128,13 +135,18 @@ func (h *Hub) Add(s *Session) { func (h *Hub) Remove(s *Session) { h.mu.Lock() - defer h.mu.Unlock() if s.Player != nil && s.State == StateGame && !s.Disconnecting { s.Disconnecting = true s.DisconnectTicks = 10 + onDisconnect := h.onDisconnect + h.mu.Unlock() + if onDisconnect != nil { + onDisconnect(s) + } return } h.hardRemoveLocked(s) + h.mu.Unlock() } func (h *Hub) HardRemove(s *Session) { |
