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.
This commit is contained in:
Simon Ser 2023-08-23 19:50:37 +02:00
parent 3650446156
commit 01b28fa85d
4 changed files with 26 additions and 26 deletions

View File

@ -1507,7 +1507,7 @@ func (dc *downstreamConn) welcome(ctx context.Context, user *user) error {
Command: irc.RPL_MYINFO, Command: irc.RPL_MYINFO,
Params: []string{dc.nick, dc.srv.Config().Hostname, "soju", "aiwroO", "OovaimnqpsrtklbeI"}, 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) dc.SendMessage(ctx, msg)
} }
if uc := dc.upstream(); uc != nil { if uc := dc.upstream(); uc != nil {
@ -1531,7 +1531,7 @@ func (dc *downstreamConn) welcome(ctx context.Context, user *user) error {
dc.updateCasemapping() dc.updateCasemapping()
if motd := dc.user.srv.Config().MOTD; motd != "" && dc.network == nil { 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) dc.SendMessage(ctx, msg)
} }
} else { } else {
@ -2154,7 +2154,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
dc.SendMessage(ctx, &irc.Message{ dc.SendMessage(ctx, &irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFWHO, Command: irc.RPL_ENDOFWHO,
Params: []string{dc.nick, "*", "End of /WHO list"}, Params: []string{"*", "*", "End of /WHO list"},
}) })
return nil return nil
} }
@ -2189,11 +2189,11 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
Account: dc.user.Username, Account: dc.user.Username,
Realname: dc.realname, 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{ dc.SendMessage(ctx, &irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFWHO, Command: irc.RPL_ENDOFWHO,
Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, Params: []string{"*", endOfWhoToken, "End of /WHO list"},
}) })
return nil return nil
} }
@ -2216,11 +2216,11 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
Account: serviceNick, Account: serviceNick,
Realname: serviceRealname, 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{ dc.SendMessage(ctx, &irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFWHO, Command: irc.RPL_ENDOFWHO,
Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, Params: []string{"*", endOfWhoToken, "End of /WHO list"},
}) })
return nil return nil
} }
@ -2228,7 +2228,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
dc.SendMessage(ctx, &irc.Message{ dc.SendMessage(ctx, &irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFWHO, Command: irc.RPL_ENDOFWHO,
Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, Params: []string{"*", endOfWhoToken, "End of /WHO list"},
}) })
return nil return nil
} }
@ -2254,12 +2254,12 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
if uc.isChannel(mask) { if uc.isChannel(mask) {
info.Channel = 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{ dc.SendMessage(ctx, &irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFWHO, Command: irc.RPL_ENDOFWHO,
Params: []string{dc.nick, endOfWhoToken, "End of /WHO list"}, Params: []string{"*", endOfWhoToken, "End of /WHO list"},
}) })
return nil return nil
} }
@ -3469,7 +3469,7 @@ func sendNames(ctx context.Context, dc *downstreamConn, ch *upstreamChannel) {
members = append(members, s) 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 { for _, msg := range msgs {
dc.SendMessage(ctx, msg) dc.SendMessage(ctx, msg)
} }

View File

@ -992,7 +992,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
uc.updateMonitor() uc.updateMonitor()
uc.forEachDownstream(func(dc *downstreamConn) { 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 { for _, msg := range msgs {
dc.SendMessage(ctx, msg) dc.SendMessage(ctx, msg)
} }

View File

@ -82,7 +82,7 @@ func (js *joinSorter) Swap(i, j int) {
js.keys[i], js.keys[j] = js.keys[j], js.keys[i] 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 maxTokens := maxMessageParams - 2 // 2 reserved params: nick + text
// TODO: take into account maxMessageLength as well // 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{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_ISUPPORT, 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") 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 var msgs []*irc.Message
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_MOTDSTART, 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") { for _, l := range strings.Split(motd, "\n") {
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_MOTD, Command: irc.RPL_MOTD,
Params: []string{nick, l}, Params: []string{"*", l},
}) })
} }
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_ENDOFMOTD, Command: irc.RPL_ENDOFMOTD,
Params: []string{nick, "End of /MOTD command."}, Params: []string{"*", "End of /MOTD command."},
}) })
return msgs return msgs
@ -169,11 +169,11 @@ func GenerateMonitor(subcmd string, targets []string) []*irc.Message {
return msgs 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{ emptyNameReply := irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_NAMREPLY, Command: irc.RPL_NAMREPLY,
Params: []string{nick, string(status), channel, ""}, Params: []string{"*", string(status), channel, ""},
} }
maxLength := maxMessageLength - len(emptyNameReply.String()) maxLength := maxMessageLength - len(emptyNameReply.String())
@ -186,7 +186,7 @@ func GenerateNamesReply(prefix *irc.Prefix, nick string, channel string, status
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_NAMREPLY, Command: irc.RPL_NAMREPLY,
Params: []string{nick, string(status), channel, buf.String()}, Params: []string{"*", string(status), channel, buf.String()},
}) })
buf.Reset() buf.Reset()
} }
@ -201,14 +201,14 @@ func GenerateNamesReply(prefix *irc.Prefix, nick string, channel string, status
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_NAMREPLY, Command: irc.RPL_NAMREPLY,
Params: []string{nick, string(status), channel, buf.String()}, Params: []string{"*", string(status), channel, buf.String()},
}) })
} }
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_ENDOFNAMES, Command: irc.RPL_ENDOFNAMES,
Params: []string{nick, channel, "End of /NAMES list"}, Params: []string{"*", channel, "End of /NAMES list"},
}) })
return msgs return msgs
} }

View File

@ -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 == "" { if fields == "" {
hostname := info.Hostname hostname := info.Hostname
if strings.HasPrefix(info.Hostname, ":") { if strings.HasPrefix(info.Hostname, ":") {
@ -111,7 +111,7 @@ func GenerateWHOXReply(prefix *irc.Prefix, nick, fields string, info *WHOXInfo)
return &irc.Message{ return &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_WHOREPLY, 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{ return &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: RPL_WHOSPCRPL, Command: RPL_WHOSPCRPL,
Params: append([]string{nick}, values...), Params: append([]string{"*"}, values...),
} }
} }