Implemented the /KICK command

This commit is contained in:
Harry Jeffery 2013-08-29 21:10:28 +01:00
parent ee1564e65f
commit d8f874caef
3 changed files with 46 additions and 0 deletions

View File

@ -169,6 +169,8 @@ func (c *Client) reply(code replyCode, args ...string) {
c.outputChan <- fmt.Sprintf(":%s 381 %s :You are now an operator", c.server.name, c.nick)
case rplChannelModeIs:
c.outputChan <- fmt.Sprintf(":%s 324 %s %s %s %s", c.server.name, c.nick, args[0], args[1], args[2])
case rplKick:
c.outputChan <- fmt.Sprintf(":%s KICK %s %s %s", args[0], args[1], args[2], args[3])
case errMoreArgs:
c.outputChan <- fmt.Sprintf(":%s 461 %s :Not enough params", c.server.name, c.nick)
case errNoNick:

View File

@ -108,6 +108,7 @@ const (
rplList
rplOper
rplChannelModeIs
rplKick
errMoreArgs
errNoNick
errInvalidNick

View File

@ -326,6 +326,49 @@ func (s *Server) handleEvent(e Event) {
e.client.reply(errNoSuchNick, nick)
}
case command == "KICK":
if e.client.registered == false {
e.client.reply(errNotReg)
return
}
if len(args) < 2 {
e.client.reply(errMoreArgs)
return
}
channelKey := strings.ToLower(args[0])
targetKey := strings.ToLower(args[1])
channel, channelExists := s.channelMap[channelKey]
if !channelExists {
e.client.reply(errNoSuchNick, args[0])
return
}
target, targetExists := channel.clientMap[targetKey]
if !targetExists {
e.client.reply(errNoSuchNick, args[1])
return
}
clientMode := channel.modeMap[e.client.key]
if !clientMode.operator {
e.client.reply(errNoPriv)
return
}
reason := strings.Join(args[2:], " ")
//It worked
for _, client := range channel.clientMap {
client.reply(rplKick, e.client.nick, channel.name, target.nick, reason)
}
delete(channel.clientMap, targetKey)
delete(channel.modeMap, targetKey)
delete(target.channelMap, channelKey)
case command == "MODE":
if e.client.registered == false {
e.client.reply(errNotReg)