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) c.outputChan <- fmt.Sprintf(":%s 381 %s :You are now an operator", c.server.name, c.nick)
case rplChannelModeIs: case rplChannelModeIs:
c.outputChan <- fmt.Sprintf(":%s 324 %s %s %s %s", c.server.name, c.nick, args[0], args[1], args[2]) 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: case errMoreArgs:
c.outputChan <- fmt.Sprintf(":%s 461 %s :Not enough params", c.server.name, c.nick) c.outputChan <- fmt.Sprintf(":%s 461 %s :Not enough params", c.server.name, c.nick)
case errNoNick: case errNoNick:

View File

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

View File

@ -326,6 +326,49 @@ func (s *Server) handleEvent(e Event) {
e.client.reply(errNoSuchNick, nick) 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": case command == "MODE":
if e.client.registered == false { if e.client.registered == false {
e.client.reply(errNotReg) e.client.reply(errNotReg)