diff --git a/server.go b/server.go index 0cf3a03..ce5a7b4 100644 --- a/server.go +++ b/server.go @@ -89,10 +89,13 @@ func (s *Server) handleCommand(client *Client, command string, args []string) { switch command { case "PING": client.reply(rplPong) + case "INFO": client.reply(rplInfo, APP_DESCRIPTION) + case "VERSION": client.reply(rplVersion, VERSION) + case "NICK": client.reply(rplKill, "Can't change nicks on this server", "") client.disconnect() @@ -338,42 +341,8 @@ func (s *Server) handleCommand(client *Client, command string, args []string) { return } - if len(args) < 2 { - client.reply(errMoreArgs) - return - } - - channelKey := strings.ToLower(args[0]) - targetKey := strings.ToLower(args[1]) - - channel, channelExists := s.channelMap[channelKey] - if !channelExists { - client.reply(errNoSuchNick, args[0]) - return - } - - target, targetExists := channel.clientMap[targetKey] - if !targetExists { - client.reply(errNoSuchNick, args[1]) - return - } - - clientMode := channel.modeMap[client.key] - if !clientMode.operator && !client.operator { - client.reply(errNoPriv) - return - } - - reason := strings.Join(args[2:], " ") - - //It worked - for _, client := range channel.clientMap { - client.reply(rplKick, client.nick, channel.name, target.nick, reason) - } - - delete(channel.clientMap, targetKey) - delete(channel.modeMap, targetKey) - delete(target.channelMap, channelKey) + client.reply(errNoPriv) + return case "MODE": if client.registered == false { @@ -401,86 +370,9 @@ func (s *Server) handleCommand(client *Client, command string, args []string) { return } - if cm, ok := channel.modeMap[client.key]; !ok || !cm.operator { - //Not a channel operator. - - //If they're not an irc operator either, they'll fail - if !client.operator { - client.reply(errNoPriv) - return - } - } - - hasClient := false - var oldClientMode, newClientMode *ClientMode - var targetClient *Client - if len(args) >= 3 { - clientKey := strings.ToLower(args[2]) - oldClientMode, hasClient = channel.modeMap[clientKey] - if hasClient { - targetClient = channel.clientMap[clientKey] - newClientMode = new(ClientMode) - *newClientMode = *oldClientMode - } - } - - mod := strings.ToLower(args[1]) - if strings.HasPrefix(mod, "+") { - for _, char := range mod { - switch char { - case 's': - mode.secret = true - case 't': - mode.topicLocked = true - case 'm': - mode.moderated = true - case 'n': - mode.noExternal = true - case 'o': - if hasClient { - newClientMode.operator = true - } - case 'v': - if hasClient { - newClientMode.voice = true - } - } - } - } else if strings.HasPrefix(mod, "-") { - for _, char := range mod { - switch char { - case 's': - mode.secret = false - case 't': - mode.topicLocked = false - case 'm': - mode.moderated = false - case 'n': - mode.noExternal = false - case 'o': - if hasClient { - newClientMode.operator = false - } - case 'v': - if hasClient { - newClientMode.voice = false - } - } - } - } - - if hasClient { - *oldClientMode = *newClientMode - } - channel.mode = mode - - for _, client := range channel.clientMap { - if hasClient { - client.reply(rplChannelModeIs, channel.name, args[1], targetClient.nick) - } else { - client.reply(rplChannelModeIs, channel.name, args[1], "") - } - } + // Setting modes is disallowed + client.reply(errNoPriv) + return default: client.reply(errUnknownCommand, command)