From 01b28fa85db0f5d95892785dedbe71b444fd9969 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 23 Aug 2023 19:50:37 +0200 Subject: [PATCH] Use * instead of nick in some numeric replies This argument is supposed to be the destination client, but is useless. Simplify our functions by sending * instead. --- downstream.go | 22 +++++++++++----------- upstream.go | 2 +- xirc/genmsg.go | 22 +++++++++++----------- xirc/whox.go | 6 +++--- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/downstream.go b/downstream.go index 93b8117..fbb92a8 100644 --- a/downstream.go +++ b/downstream.go @@ -1507,7 +1507,7 @@ func (dc *downstreamConn) welcome(ctx context.Context, user *user) error { Command: irc.RPL_MYINFO, Params: []string{dc.nick, dc.srv.Config().Hostname, "soju", "aiwroO", "OovaimnqpsrtklbeI"}, }) - for _, msg := range xirc.GenerateIsupport(dc.srv.prefix(), dc.nick, isupport) { + for _, msg := range xirc.GenerateIsupport(dc.srv.prefix(), isupport) { dc.SendMessage(ctx, msg) } if uc := dc.upstream(); uc != nil { @@ -1531,7 +1531,7 @@ func (dc *downstreamConn) welcome(ctx context.Context, user *user) error { dc.updateCasemapping() if motd := dc.user.srv.Config().MOTD; motd != "" && dc.network == nil { - for _, msg := range xirc.GenerateMOTD(dc.srv.prefix(), dc.nick, motd) { + for _, msg := range xirc.GenerateMOTD(dc.srv.prefix(), motd) { dc.SendMessage(ctx, msg) } } else { @@ -2154,7 +2154,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. dc.SendMessage(ctx, &irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_ENDOFWHO, - Params: []string{dc.nick, "*", "End of /WHO list"}, + Params: []string{"*", "*", "End of /WHO list"}, }) return nil } @@ -2189,11 +2189,11 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. Account: dc.user.Username, Realname: dc.realname, } - dc.SendMessage(ctx, xirc.GenerateWHOXReply(dc.srv.prefix(), dc.nick, fields, &info)) + dc.SendMessage(ctx, xirc.GenerateWHOXReply(dc.srv.prefix(), fields, &info)) dc.SendMessage(ctx, &irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_ENDOFWHO, - Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, + Params: []string{"*", endOfWhoToken, "End of /WHO list"}, }) return nil } @@ -2216,11 +2216,11 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. Account: serviceNick, Realname: serviceRealname, } - dc.SendMessage(ctx, xirc.GenerateWHOXReply(dc.srv.prefix(), dc.nick, fields, &info)) + dc.SendMessage(ctx, xirc.GenerateWHOXReply(dc.srv.prefix(), fields, &info)) dc.SendMessage(ctx, &irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_ENDOFWHO, - Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, + Params: []string{"*", endOfWhoToken, "End of /WHO list"}, }) return nil } @@ -2228,7 +2228,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. dc.SendMessage(ctx, &irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_ENDOFWHO, - Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, + Params: []string{"*", endOfWhoToken, "End of /WHO list"}, }) return nil } @@ -2254,12 +2254,12 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. if uc.isChannel(mask) { info.Channel = mask } - dc.SendMessage(ctx, xirc.GenerateWHOXReply(dc.srv.prefix(), dc.nick, fields, &info)) + dc.SendMessage(ctx, xirc.GenerateWHOXReply(dc.srv.prefix(), fields, &info)) } dc.SendMessage(ctx, &irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_ENDOFWHO, - Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, + Params: []string{"*", endOfWhoToken, "End of /WHO list"}, }) return nil } @@ -3469,7 +3469,7 @@ func sendNames(ctx context.Context, dc *downstreamConn, ch *upstreamChannel) { members = append(members, s) }) - msgs := xirc.GenerateNamesReply(dc.srv.prefix(), dc.nick, ch.Name, ch.Status, members) + msgs := xirc.GenerateNamesReply(dc.srv.prefix(), ch.Name, ch.Status, members) for _, msg := range msgs { dc.SendMessage(ctx, msg) } diff --git a/upstream.go b/upstream.go index 75912c1..6b3a5b5 100644 --- a/upstream.go +++ b/upstream.go @@ -992,7 +992,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err uc.updateMonitor() uc.forEachDownstream(func(dc *downstreamConn) { - msgs := xirc.GenerateIsupport(dc.srv.prefix(), dc.nick, downstreamIsupport) + msgs := xirc.GenerateIsupport(dc.srv.prefix(), downstreamIsupport) for _, msg := range msgs { dc.SendMessage(ctx, msg) } diff --git a/xirc/genmsg.go b/xirc/genmsg.go index 5db1c7b..c8a42d8 100644 --- a/xirc/genmsg.go +++ b/xirc/genmsg.go @@ -82,7 +82,7 @@ func (js *joinSorter) Swap(i, j int) { js.keys[i], js.keys[j] = js.keys[j], js.keys[i] } -func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.Message { +func GenerateIsupport(prefix *irc.Prefix, tokens []string) []*irc.Message { maxTokens := maxMessageParams - 2 // 2 reserved params: nick + text // TODO: take into account maxMessageLength as well @@ -105,7 +105,7 @@ func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.M msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_ISUPPORT, - Params: append(append([]string{nick}, encodedTokens...), "are supported"), + Params: append(append([]string{"*"}, encodedTokens...), "are supported"), }) } @@ -114,26 +114,26 @@ func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.M var isupportEncoder = strings.NewReplacer(" ", "\\x20", "\\", "\\x5C") -func GenerateMOTD(prefix *irc.Prefix, nick string, motd string) []*irc.Message { +func GenerateMOTD(prefix *irc.Prefix, motd string) []*irc.Message { var msgs []*irc.Message msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_MOTDSTART, - Params: []string{nick, fmt.Sprintf("- Message of the Day -")}, + Params: []string{"*", fmt.Sprintf("- Message of the Day -")}, }) for _, l := range strings.Split(motd, "\n") { msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_MOTD, - Params: []string{nick, l}, + Params: []string{"*", l}, }) } msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_ENDOFMOTD, - Params: []string{nick, "End of /MOTD command."}, + Params: []string{"*", "End of /MOTD command."}, }) return msgs @@ -169,11 +169,11 @@ func GenerateMonitor(subcmd string, targets []string) []*irc.Message { return msgs } -func GenerateNamesReply(prefix *irc.Prefix, nick string, channel string, status ChannelStatus, members []string) []*irc.Message { +func GenerateNamesReply(prefix *irc.Prefix, channel string, status ChannelStatus, members []string) []*irc.Message { emptyNameReply := irc.Message{ Prefix: prefix, Command: irc.RPL_NAMREPLY, - Params: []string{nick, string(status), channel, ""}, + Params: []string{"*", string(status), channel, ""}, } maxLength := maxMessageLength - len(emptyNameReply.String()) @@ -186,7 +186,7 @@ func GenerateNamesReply(prefix *irc.Prefix, nick string, channel string, status msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_NAMREPLY, - Params: []string{nick, string(status), channel, buf.String()}, + Params: []string{"*", string(status), channel, buf.String()}, }) buf.Reset() } @@ -201,14 +201,14 @@ func GenerateNamesReply(prefix *irc.Prefix, nick string, channel string, status msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_NAMREPLY, - Params: []string{nick, string(status), channel, buf.String()}, + Params: []string{"*", string(status), channel, buf.String()}, }) } msgs = append(msgs, &irc.Message{ Prefix: prefix, Command: irc.RPL_ENDOFNAMES, - Params: []string{nick, channel, "End of /NAMES list"}, + Params: []string{"*", channel, "End of /NAMES list"}, }) return msgs } diff --git a/xirc/whox.go b/xirc/whox.go index a9eb1e8..a0f81ea 100644 --- a/xirc/whox.go +++ b/xirc/whox.go @@ -93,7 +93,7 @@ func (info *WHOXInfo) set(k byte, v string) { } } -func GenerateWHOXReply(prefix *irc.Prefix, nick, fields string, info *WHOXInfo) *irc.Message { +func GenerateWHOXReply(prefix *irc.Prefix, fields string, info *WHOXInfo) *irc.Message { if fields == "" { hostname := info.Hostname if strings.HasPrefix(info.Hostname, ":") { @@ -111,7 +111,7 @@ func GenerateWHOXReply(prefix *irc.Prefix, nick, fields string, info *WHOXInfo) return &irc.Message{ Prefix: prefix, Command: irc.RPL_WHOREPLY, - Params: []string{nick, channel, info.Username, hostname, info.Server, info.Nickname, info.Flags, "0 " + info.Realname}, + Params: []string{"*", channel, info.Username, hostname, info.Server, info.Nickname, info.Flags, "0 " + info.Realname}, } } @@ -131,7 +131,7 @@ func GenerateWHOXReply(prefix *irc.Prefix, nick, fields string, info *WHOXInfo) return &irc.Message{ Prefix: prefix, Command: RPL_WHOSPCRPL, - Params: append([]string{nick}, values...), + Params: append([]string{"*"}, values...), } }