From bba70d0a2903ab1fff5a2e89cff97cb1f6c7f82a Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Thu, 25 Jun 2026 07:44:23 -0700 Subject: 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. --- hotline/presence.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 hotline/presence.go (limited to 'hotline/presence.go') 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) +} -- cgit