diff --git a/client.go b/client.go index 95ab181..fb9b030 100644 --- a/client.go +++ b/client.go @@ -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: diff --git a/rosella.go b/rosella.go index afb7d6b..30dc42f 100644 --- a/rosella.go +++ b/rosella.go @@ -108,6 +108,7 @@ const ( rplList rplOper rplChannelModeIs + rplKick errMoreArgs errNoNick errInvalidNick diff --git a/server.go b/server.go index 8d2d605..c437349 100644 --- a/server.go +++ b/server.go @@ -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)