aboutsummaryrefslogtreecommitdiff
path: root/internal/game/session_registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/session_registry.go')
-rw-r--r--internal/game/session_registry.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/game/session_registry.go b/internal/game/session_registry.go
index c4f5d67..cf4e8df 100644
--- a/internal/game/session_registry.go
+++ b/internal/game/session_registry.go
@@ -23,3 +23,17 @@ func (g *Game) detachSession(name string) {
g.queue.ClearPlayer(name)
}
}
+
+// sessionRegistered reports whether sess is still the live session for name.
+// Tick subscribers that can outlive a disconnect/re-login must consult this
+// before acting on a session that is no longer in the world (a detached
+// combat or logout subscriber would otherwise keep saving a ghost).
+func (g *Game) sessionRegistered(sess *net.Session, name string) bool {
+ if sess == nil || sess.Player == nil {
+ return false
+ }
+ g.charsMu.Lock()
+ current := g.loggedInChars[name]
+ g.charsMu.Unlock()
+ return current == sess
+}