From 7b2ab6642bb0c046dd5afe744bca09df9d101947 Mon Sep 17 00:00:00 2001 From: "." <.@.> Date: Sat, 27 Aug 2016 14:07:02 +1200 Subject: [PATCH] WHOIS support (needs testing) --HG-- branch : nmdc-ircfrontend --- TODO.txt | 2 -- server.go | 36 ++++++++++++++++++++++++++++++++++++ typedefs.go | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/TODO.txt b/TODO.txt index 77476d5..c5f8e5d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -15,8 +15,6 @@ WISHLIST - automatic markdown bold/italic formatting -- support WHOIS - - support USERIP/KILL/KICK for ops - use CTCP chat to support irc-special characters in chat messages (colon, newline) diff --git a/server.go b/server.go index e3383a0..26f51a8 100644 --- a/server.go +++ b/server.go @@ -657,6 +657,35 @@ func (s *Server) handleJoinedCommand(command string, args []string) { return + case "WHOIS": + if len(args) < 1 { + s.reply(errMoreArgs) + return + } + + // WHOIS [target] nick[,nick2[,nick...]] + nicklist := args[0] // Assume WHOIS ${nick} only, + if len(args) >= 2 { + nicklist = args[1] // It was WHOIS ${target} ${nick} instead + } + + for _, targetnick := range strings.Split(nicklist, ",") { + // tell the client something about it + // The protocol does ostensibly support wildcard WHOIS, but we don't (yet) + s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error { + for nick, nickinfo := range *u { + if nick == targetnick { + s.reply(rplWhoisUser, nick, nickinfo.Description+" <"+nickinfo.ClientVersion+">") + if nickinfo.IsOperator { + s.reply(rplWhoisOperator, nick) + } + } + } + return nil + }) + s.reply(rplEndOfWhois) + } + default: s.reply(errUnknownCommand, command) } @@ -815,6 +844,13 @@ func (s *Server) reply(code replyCode, args ...string) { case rplPong: s.writeClient(fmt.Sprintf(":%s PONG %s %s", s.name, s.clientNick(), args[0])) + case rplWhoisUser: + s.writeClient(fmt.Sprintf(":%s 311 %s %s %s * :%s", s.name, args[0], args[0], args[0], args[1])) // caller should supply nick,description + case rplWhoisOperator: + s.writeClient(fmt.Sprintf(":%s 313 %s :is an IRC operator", s.name, args[0])) + case rplEndOfWhois: + s.writeClient(fmt.Sprintf(":%s 318 :End of WHOIS list", s.name)) + case errMoreArgs: s.writeClient(fmt.Sprintf(":%s 461 %s :Not enough params", s.name, s.clientNick())) case errNoNick: diff --git a/typedefs.go b/typedefs.go index ad12382..c7c2c3c 100644 --- a/typedefs.go +++ b/typedefs.go @@ -56,6 +56,9 @@ const ( rplMOTD rplEndOfMOTD rplPong + rplWhoisUser + rplWhoisOperator + rplEndOfWhois errMoreArgs errNoNick errInvalidNick