3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

fix analogous invalid parameters for ERR_NOSUCHNICK

This commit is contained in:
Shivaram Lingamneni 2019-12-05 06:52:07 -05:00
parent aa8579b6e8
commit 0880f20f4b
4 changed files with 28 additions and 35 deletions

View File

@ -1048,10 +1048,9 @@ func (channel *Channel) SendSplitMessage(command string, minPrefixMode modes.Mod
} }
func (channel *Channel) applyModeToMember(client *Client, mode modes.Mode, op modes.ModeOp, nick string, rb *ResponseBuffer) (result *modes.ModeChange) { func (channel *Channel) applyModeToMember(client *Client, mode modes.Mode, op modes.ModeOp, nick string, rb *ResponseBuffer) (result *modes.ModeChange) {
casefoldedName, err := CasefoldName(nick) target := channel.server.clients.Get(nick)
target := channel.server.clients.Get(casefoldedName) if target == nil {
if err != nil || target == nil { rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.Nick(), utils.SafeErrorParam(nick), client.t("No such nick"))
rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.Nick(), nick, client.t("No such nick"))
return nil return nil
} }

View File

@ -1228,10 +1228,9 @@ func inviteHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
nickname := msg.Params[0] nickname := msg.Params[0]
channelName := msg.Params[1] channelName := msg.Params[1]
casefoldedNickname, err := CasefoldName(nickname) target := server.clients.Get(nickname)
target := server.clients.Get(casefoldedNickname) if target == nil {
if err != nil || target == nil { rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), utils.SafeErrorParam(nickname), client.t("No such nick"))
rb.Add(nil, server.name, ERR_NOSUCHNICK, client.nick, nickname, client.t("No such nick"))
return false return false
} }
@ -1313,7 +1312,7 @@ func sajoinHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
} else { } else {
target = server.clients.Get(msg.Params[0]) target = server.clients.Get(msg.Params[0])
if target == nil { if target == nil {
rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), msg.Params[0], "No such nick") rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), utils.SafeErrorParam(msg.Params[0]), "No such nick")
return false return false
} }
channelString = msg.Params[1] channelString = msg.Params[1]
@ -1385,10 +1384,9 @@ func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
comment = msg.Params[1] comment = msg.Params[1]
} }
casefoldedNickname, err := CasefoldName(nickname) target := server.clients.Get(nickname)
target := server.clients.Get(casefoldedNickname) if target == nil {
if err != nil || target == nil { rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.nick, utils.SafeErrorParam(nickname), client.t("No such nick"))
rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.nick, nickname, client.t("No such nick"))
return false return false
} }
@ -2564,25 +2562,23 @@ func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
// USERHOST <nickname>{ <nickname>} // USERHOST <nickname>{ <nickname>}
func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
returnedNicks := make(map[string]bool) returnedClients := make(ClientSet)
for i, nickname := range msg.Params { for i, nickname := range msg.Params {
if i >= 10 { if i >= 10 {
break break
} }
casefoldedNickname, err := CasefoldName(nickname) target := server.clients.Get(nickname)
target := server.clients.Get(casefoldedNickname) if target == nil {
if err != nil || target == nil { rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.nick, utils.SafeErrorParam(nickname), client.t("No such nick"))
rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.nick, nickname, client.t("No such nick"))
return false
}
if returnedNicks[casefoldedNickname] {
continue continue
} }
// to prevent returning multiple results for a single nick // to prevent returning multiple results for a single nick
returnedNicks[casefoldedNickname] = true if returnedClients.Has(target) {
continue
}
returnedClients.Add(target)
var isOper, isAway string var isOper, isAway string
@ -2730,11 +2726,6 @@ func whoisHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
masksString = msg.Params[0] masksString = msg.Params[0]
} }
if len(strings.TrimSpace(masksString)) < 1 {
rb.Add(nil, server.name, ERR_UNKNOWNERROR, client.nick, msg.Command, client.t("No masks given"))
return false
}
handleService := func(nick string) bool { handleService := func(nick string) bool {
cfnick, _ := CasefoldName(nick) cfnick, _ := CasefoldName(nick)
service, ok := OragonoServices[cfnick] service, ok := OragonoServices[cfnick]
@ -2754,7 +2745,7 @@ func whoisHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
for _, mask := range strings.Split(masksString, ",") { for _, mask := range strings.Split(masksString, ",") {
matches := server.clients.FindAll(mask) matches := server.clients.FindAll(mask)
if len(matches) == 0 && !handleService(mask) { if len(matches) == 0 && !handleService(mask) {
rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.nick, mask, client.t("No such nick")) rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.Nick(), utils.SafeErrorParam(mask), client.t("No such nick"))
continue continue
} }
for mclient := range matches { for mclient := range matches {
@ -2768,11 +2759,11 @@ func whoisHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Res
if mclient != nil { if mclient != nil {
client.getWhoisOf(mclient, rb) client.getWhoisOf(mclient, rb)
} else if !handleService(nick) { } else if !handleService(nick) {
rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.nick, masksString, client.t("No such nick")) rb.Add(nil, client.server.name, ERR_NOSUCHNICK, client.Nick(), utils.SafeErrorParam(masksString), client.t("No such nick"))
} }
// fall through, ENDOFWHOIS is always sent // fall through, ENDOFWHOIS is always sent
} }
rb.Add(nil, server.name, RPL_ENDOFWHOIS, client.nick, masksString, client.t("End of /WHOIS list")) rb.Add(nil, server.name, RPL_ENDOFWHOIS, client.nick, utils.SafeErrorParam(masksString), client.t("End of /WHOIS list"))
return false return false
} }

View File

@ -49,7 +49,7 @@ func performNickChange(server *Server, client *Client, target *Client, session *
} else if err == errNicknameReserved { } else if err == errNicknameReserved {
rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, nickname, client.t("Nickname is reserved by a different account")) rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, nickname, client.t("Nickname is reserved by a different account"))
} else if err == errNicknameInvalid { } else if err == errNicknameInvalid {
rb.Add(nil, server.name, ERR_ERRONEUSNICKNAME, currentNick, nickname, client.t("Erroneous nickname")) rb.Add(nil, server.name, ERR_ERRONEUSNICKNAME, currentNick, utils.SafeErrorParam(nickname), client.t("Erroneous nickname"))
} else if err != nil { } else if err != nil {
rb.Add(nil, server.name, ERR_UNKNOWNERROR, currentNick, "NICK", fmt.Sprintf(client.t("Could not set or change nickname: %s"), err.Error())) rb.Add(nil, server.name, ERR_UNKNOWNERROR, currentNick, "NICK", fmt.Sprintf(client.t("Could not set or change nickname: %s"), err.Error()))
} }

View File

@ -7,12 +7,14 @@ package irc
import "github.com/oragono/oragono/irc/modes" import "github.com/oragono/oragono/irc/modes"
type empty struct{}
// ClientSet is a set of clients. // ClientSet is a set of clients.
type ClientSet map[*Client]bool type ClientSet map[*Client]empty
// Add adds the given client to this set. // Add adds the given client to this set.
func (clients ClientSet) Add(client *Client) { func (clients ClientSet) Add(client *Client) {
clients[client] = true clients[client] = empty{}
} }
// Remove removes the given client from this set. // Remove removes the given client from this set.
@ -22,7 +24,8 @@ func (clients ClientSet) Remove(client *Client) {
// Has returns true if the given client is in this set. // Has returns true if the given client is in this set.
func (clients ClientSet) Has(client *Client) bool { func (clients ClientSet) Has(client *Client) bool {
return clients[client] _, ok := clients[client]
return ok
} }
// MemberSet is a set of members with modes. // MemberSet is a set of members with modes.