From 35bb90145524d99f2325cfdf3ebcc54764aedbdb Mon Sep 17 00:00:00 2001 From: reverse Date: Wed, 19 Aug 2026 00:43:03 +0000 Subject: [PATCH] =?UTF-8?q?whoisport:=20report=20the=20port=20the=20user?= =?UTF-8?q?=20actually=20connected=20to=20(User.port,=20set=20at=20accept)?= =?UTF-8?q?=20instead=20of=20conf("bind")/conf("bind=5Ftls")=20=E2=80=94?= =?UTF-8?q?=20those=20are=20Vec-valued=20so=20conf()=20returned=20only=20t?= =?UTF-8?q?he=20LAST=20configured=20listener,=20giving=20every=20user=20th?= =?UTF-8?q?e=20same=20wrong=20port=20on=20a=20multi-listener=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/whoisport.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/modules/whoisport.rs b/src/modules/whoisport.rs index ea30d68..5c5b5bb 100644 --- a/src/modules/whoisport.rs +++ b/src/modules/whoisport.rs @@ -1,20 +1,15 @@ -//! Shows an IRC operator, in WHOIS, the listener port the target connected to. -//! Derives the port from the `bind` / `bind_tls` listeners. +//! Shows an IRC operator, in WHOIS, the listener port the target connected to — +//! read straight from the user's own connection (set at accept time), so it's +//! correct even when the server has several `bind` / `bind_tls` listeners. use crate::server::Server; use crate::Uid; -fn port_of(addr: &str) -> u16 { - addr.rsplit(':') - .next() - .and_then(|p| p.parse().ok()) - .unwrap_or(0) -} - /// The `is using port N` WHOIS line for opers, or `None` if the port is unknown. pub fn line(s: &Server, target: Uid) -> Option { - let secure = s.users.get(&target).map(|u| u.secure).unwrap_or(false); - let bind = if secure { "bind_tls" } else { "bind" }; - let port = s.conf(bind).map(port_of).unwrap_or(0); - (port != 0).then(|| format!("is using port {port}")) + s.users + .get(&target) + .map(|u| u.port) + .filter(|&p| p != 0) + .map(|p| format!("is using port {p}")) }