From 747263fc2dc02969c1c710f6b7a9b3c5a3020cfd Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 4 Apr 2022 09:28:04 +0200 Subject: [PATCH] Simplify and improve WHOIS forwarding Group together most WHOIS replies. While at it, add a few missing replies. --- irc.go | 11 +++++++++-- upstream.go | 55 ++++------------------------------------------------- 2 files changed, 13 insertions(+), 53 deletions(-) diff --git a/irc.go b/irc.go index c17526f..4eaa9ef 100644 --- a/irc.go +++ b/irc.go @@ -15,13 +15,20 @@ const ( rpl_statsping = "246" rpl_localusers = "265" rpl_globalusers = "266" + rpl_whoiscertfp = "276" + rpl_whoisregnick = "307" + rpl_whoisspecial = "320" rpl_creationtime = "329" - rpl_topicwhotime = "333" - rpl_whospcrpl = "354" rpl_whoisaccount = "330" + rpl_topicwhotime = "333" + rpl_whoisactually = "338" + rpl_whospcrpl = "354" + rpl_whoishost = "378" + rpl_whoismodes = "379" rpl_visiblehost = "396" err_unknownerror = "400" err_invalidcapcmd = "410" + rpl_whoissecure = "671" // https://ircv3.net/specs/extensions/bot-mode rpl_whoisbot = "335" diff --git a/upstream.go b/upstream.go index 56d604e..320e79b 100644 --- a/upstream.go +++ b/upstream.go @@ -1428,63 +1428,16 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err Command: irc.RPL_ENDOFWHO, Params: []string{dc.nick, mask, "End of /WHO list"}, }) - case irc.RPL_WHOISUSER: - var nick, username, host, realname string - if err := parseMessageParams(msg, nil, &nick, &username, &host, nil, &realname); err != nil { - return err - } - - uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalEntity(uc.network, nick) - dc.SendMessage(&irc.Message{ - Prefix: dc.srv.prefix(), - Command: irc.RPL_WHOISUSER, - Params: []string{dc.nick, nick, username, host, "*", realname}, - }) - }) - case irc.RPL_WHOISSERVER: - var nick, server, serverInfo string - if err := parseMessageParams(msg, nil, &nick, &server, &serverInfo); err != nil { - return err - } - - uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalEntity(uc.network, nick) - dc.SendMessage(&irc.Message{ - Prefix: dc.srv.prefix(), - Command: irc.RPL_WHOISSERVER, - Params: []string{dc.nick, nick, server, serverInfo}, - }) - }) - case irc.RPL_WHOISOPERATOR: + case rpl_whoiscertfp, rpl_whoisregnick, irc.RPL_WHOISUSER, irc.RPL_WHOISSERVER, irc.RPL_WHOISOPERATOR, irc.RPL_WHOISIDLE, rpl_whoisspecial, rpl_whoisaccount, rpl_whoisactually, rpl_whoishost, rpl_whoismodes, rpl_whoissecure: var nick string if err := parseMessageParams(msg, nil, &nick); err != nil { return err } uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalEntity(uc.network, nick) - dc.SendMessage(&irc.Message{ - Prefix: dc.srv.prefix(), - Command: irc.RPL_WHOISOPERATOR, - Params: []string{dc.nick, nick, "is an IRC operator"}, - }) - }) - case irc.RPL_WHOISIDLE: - var nick string - if err := parseMessageParams(msg, nil, &nick, nil); err != nil { - return err - } - - uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalEntity(uc.network, nick) - params := []string{dc.nick, nick} - params = append(params, msg.Params[2:]...) - dc.SendMessage(&irc.Message{ - Prefix: dc.srv.prefix(), - Command: irc.RPL_WHOISIDLE, - Params: params, - }) + msg := msg.Copy() + msg.Params[1] = dc.marshalEntity(uc.network, nick) + dc.SendMessage(msg) }) case irc.RPL_WHOISCHANNELS: var nick, channelList string