From b2055595e1a6ebe5e6e4bd27bc921c06d27a54a2 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Thu, 6 Mar 2014 12:14:21 -0800 Subject: [PATCH] WHOWAS command --- irc/commands.go | 24 ++++++++++++++++++++++++ irc/constants.go | 1 + irc/reply.go | 15 +++++++++++++++ irc/server.go | 9 +++++++++ 4 files changed, 49 insertions(+) diff --git a/irc/commands.go b/irc/commands.go index 0fa347aa..a0963687 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -54,6 +54,7 @@ var ( VERSION: NewVersionCommand, WHO: NewWhoCommand, WHOIS: NewWhoisCommand, + WHOWAS: NewWhoWasCommand, } ) @@ -968,3 +969,26 @@ func NewKillCommand(args []string) (editableCommand, error) { comment: args[1], }, nil } + +type WhoWasCommand struct { + BaseCommand + nicknames []string + count int64 + target string +} + +func NewWhoWasCommand(args []string) (editableCommand, error) { + if len(args) < 1 { + return nil, NotEnoughArgsError + } + cmd := &WhoWasCommand{ + nicknames: strings.Split(args[0], ","), + } + if len(args) > 1 { + cmd.count, _ = strconv.ParseInt(args[1], 10, 64) + } + if len(args) > 2 { + cmd.target = args[2] + } + return cmd, nil +} diff --git a/irc/constants.go b/irc/constants.go index 6b4a89ec..bab17e6b 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -61,6 +61,7 @@ const ( VERSION StringCode = "VERSION" WHO StringCode = "WHO" WHOIS StringCode = "WHOIS" + WHOWAS StringCode = "WHOWAS" // numeric codes RPL_WELCOME NumericCode = 1 diff --git a/irc/reply.go b/irc/reply.go index 27b39fa8..a32a5765 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -394,6 +394,16 @@ func (target *Client) RplTime() { "%s :%s", target.server.name, time.Now().Format(time.RFC1123)) } +func (target *Client) RplWhoWasUser(nickname, username, hostname, realname string) { + target.NumericReply(RPL_WHOWASUSER, + "%s %s %s * :%s", nickname, username, hostname, realname) +} + +func (target *Client) RplEndOfWhoWas(nickname string) { + target.NumericReply(RPL_ENDOFWHOWAS, + "%s :End of WHOWAS", nickname) +} + // // errors (also numeric) // @@ -512,3 +522,8 @@ func (target *Client) ErrChannelIsFull(channel *Channel) { target.NumericReply(ERR_CHANNELISFULL, "%s :Cannot join channel (+l)", channel) } + +func (target *Client) ErrWasNoSuchNick(nickname string) { + target.NumericReply(ERR_WASNOSUCHNICK, + "%s :There was no such nickname", nickname) +} diff --git a/irc/server.go b/irc/server.go index fa186b0d..d31b0eac 100644 --- a/irc/server.go +++ b/irc/server.go @@ -844,6 +844,15 @@ func (msg *KillCommand) HandleServer(server *Server) { target.Quit(quitMsg) } +func (msg *WhoWasCommand) HandleServer(server *Server) { + client := msg.Client() + for _, nickname := range msg.nicknames { + // TODO implement nick history + client.ErrWasNoSuchNick(nickname) + client.RplEndOfWhoWas(nickname) + } +} + // // keeping track of clients //