aboutsummaryrefslogtreecommitdiff
path: root/hotline/presence.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2026-06-25 07:44:23 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2026-06-25 07:44:23 -0700
commitbba70d0a2903ab1fff5a2e89cff97cb1f6c7f82a (patch)
treecb8bd5cda76f287358bd7b73292ae024e756c824 /hotline/presence.go
parent4912c3a7c20d765692993f6caaa98a94f5ae28cb (diff)
Introduce PresenceTracker interface for online-user tracking
Replace the leaky *redis.Client field on Server with a PresenceTracker interface that receives connect/rename/disconnect lifecycle events. This removes Redis-specific set encoding from hotline/server.go and the session handlers, and drops the redis dependency from the hotline package. The Redis implementation moves to mobius.RedisPresenceTracker, which owns the legacy "login::ip"/"login:nickname:ip" set encoding so existing deployments keep working. The API server reads online users through a new OnlineLister interface and falls back to the in-memory ClientMgr when no presence tracker is configured. Startup clearing of stale online state now happens unconditionally when Redis is configured, not only when the API server is enabled.
Diffstat (limited to 'hotline/presence.go')
-rw-r--r--hotline/presence.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/hotline/presence.go b/hotline/presence.go
new file mode 100644
index 0000000..7e41357
--- /dev/null
+++ b/hotline/presence.go
@@ -0,0 +1,20 @@
+package hotline
+
+// PresenceTracker receives best-effort notifications about user session lifecycle
+// events so an external system (e.g. Redis) can maintain a list of online users.
+//
+// It is optional: when a Server has no PresenceTracker, online presence is derived
+// from the in-memory ClientManager instead. Implementations must be safe for
+// concurrent use by multiple goroutines.
+type PresenceTracker interface {
+ // UserConnected is called after a successful login, before the nickname is known.
+ UserConnected(login, ip string)
+
+ // UserRenamed is called when a user's nickname is set or changed. oldNickname is
+ // empty the first time a nickname is set (e.g. the 1.2.3 login flow or TranAgreed).
+ UserRenamed(login, oldNickname, newNickname, ip string)
+
+ // UserDisconnected is called when a user's session ends. nickname is empty if the
+ // user disconnected before setting one.
+ UserDisconnected(login, nickname, ip string)
+}