From 1fe73aaa9edaf24a2b6fbcbb70415cf2fb213592 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Tue, 25 Feb 2014 09:10:16 -0800 Subject: [PATCH] kill command --- irc/commands.go | 17 +++++++++++++++++ irc/constants.go | 1 + irc/reply.go | 5 +++++ irc/server.go | 22 ++++++++++++++++++++-- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/irc/commands.go b/irc/commands.go index 5c2b9765..2b45a128 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -33,6 +33,7 @@ var ( ISON: NewIsOnCommand, JOIN: NewJoinCommand, KICK: NewKickCommand, + KILL: NewKillCommand, LIST: NewListCommand, MODE: NewModeCommand, MOTD: NewMOTDCommand, @@ -946,3 +947,19 @@ func NewTimeCommand(args []string) (editableCommand, error) { } return cmd, nil } + +type KillCommand struct { + BaseCommand + nickname string + comment string +} + +func NewKillCommand(args []string) (editableCommand, error) { + if len(args) < 2 { + return nil, NotEnoughArgsError + } + return &KillCommand{ + nickname: args[0], + comment: args[1], + }, nil +} diff --git a/irc/constants.go b/irc/constants.go index 55aa44fd..d5248347 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -40,6 +40,7 @@ const ( ISON StringCode = "ISON" JOIN StringCode = "JOIN" KICK StringCode = "KICK" + KILL StringCode = "KILL" LIST StringCode = "LIST" MODE StringCode = "MODE" MOTD StringCode = "MOTD" diff --git a/irc/reply.go b/irc/reply.go index ca9f497f..50034214 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -137,6 +137,11 @@ func RplKick(channel *Channel, client *Client, target *Client, comment string) s channel, target.Nick(), comment) } +func RplKill(client *Client, target *Client, comment string) string { + return NewStringReply(client, KICK, + "%s :%s", target.Nick(), comment) +} + // numeric replies func (target *Client) RplWelcome() { diff --git a/irc/server.go b/irc/server.go index acac8ed6..889bea8f 100644 --- a/irc/server.go +++ b/irc/server.go @@ -793,9 +793,27 @@ func (msg *InviteCommand) HandleServer(server *Server) { } func (msg *TimeCommand) HandleServer(server *Server) { + client := msg.Client() if (msg.target != "") && (msg.target != server.name) { - msg.Client().ErrNoSuchServer(msg.target) + client.ErrNoSuchServer(msg.target) return } - msg.Client().RplTime() + client.RplTime() +} + +func (msg *KillCommand) HandleServer(server *Server) { + client := msg.Client() + if !client.flags[Operator] { + client.ErrNoPrivileges() + return + } + + target := server.clients.Get(msg.nickname) + if target == nil { + client.ErrNoSuchNick(msg.nickname) + return + } + + quitMsg := fmt.Sprintf("KILLed by %s: %s", client.Nick(), msg.comment) + target.Quit(quitMsg) }