From d2d50c849bd180b125e8ca7e2660af51060e06aa Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 9 Aug 2015 13:29:31 -0700 Subject: [PATCH] Started support for IRC LINKS command --- commands.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/commands.go b/commands.go index 7f35784..e1c24e5 100644 --- a/commands.go +++ b/commands.go @@ -2,6 +2,7 @@ package irc import ( "fmt" + "regexp" "strconv" "strings" "time" @@ -948,3 +949,26 @@ func VersionHandler(message *irc.Message, client *Client) { m := irc.Message{Prefix: client.Server.Prefix, Command: irc.RPL_VERSION, Params: []string{client.Nickname, p}} client.Encode(&m) } + +// LinksHandler is a specialized CommandHandler to respond to channel IRC LINKS commands from a client +// Implemented according to RFC 1459 Section 4.3.3 and RFC 2812 Section 3.4.5 +func LinksHandler(message *irc.Message, client *Client) { + if len(message.Params) == 2 { + m := irc.Message{Prefix: client.Server.Prefix, Command: irc.ERR_NOSUCHSERVER, Params: []string{client.Nickname, message.Params[0]}, Trailing: "No such server"} + client.Encode(&m) + return + } + + mask := "*" + if len(message.Params) != 0 { + mask = message.Params[0] + } + regMask := strings.Replace(mask, "*", ".*", -1) + ok, err := regexp.MatchString(regMask, client.Server.Config.Name) + if ok && err == nil { + m := irc.Message{Prefix: client.Server.Prefix, Command: irc.RPL_LINKS, Params: []string{client.Nickname, mask, client.Server.Config.Name}, Trailing: "0"} + client.Encode(&m) + } + m := irc.Message{Prefix: client.Server.Prefix, Command: irc.RPL_ENDOFLINKS, Params: []string{client.Nickname, mask}, Trailing: "End of LINKS list"} + client.Encode(&m) +}