Handler for IRC ISON command provided

This commit is contained in:
Justin 2015-08-10 09:18:28 -07:00
parent 5083966f7e
commit 0f59c50d4b
1 changed files with 24 additions and 0 deletions

View File

@ -1047,3 +1047,27 @@ func SendInvite(inviter *Client, invitee *Client, channel *Channel) {
}
return
}
// IsonHandler is a specialized CommandHandler to respond to channel IRC ISON commands from a client
// Implemented according to RFC 1459 Section 5.8 and RFC 2812 Section 4.9
func IsonHandler(message *irc.Message, client *Client) {
if len(message.Params) == 0 && len(message.Trailing) == 0 {
m := irc.Message{Prefix: client.Server.Prefix, Command: irc.ERR_NEEDMOREPARAMS, Params: []string{client.Nickname}, Trailing: "Not enough parameters"}
client.Encode(&m)
return
}
nicks := message.Params
if len(nicks) == 0 {
nicks = strings.Split(message.Trailing, " ")
}
found := []string{}
for _, nick := range nicks {
_, ok := client.Server.GetClientByNick(nick)
if ok {
found = append(found, nick)
}
}
m := irc.Message{Prefix: client.Server.Prefix, Command: irc.RPL_ISON, Params: []string{client.Nickname}, Trailing: strings.Join(found, " ")}
client.Encode(&m)
}