diff --git a/irc/commands.go b/irc/commands.go index e75dd164..6fad2f32 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -48,6 +48,7 @@ var ( QUIT: NewQuitCommand, TOPIC: NewTopicCommand, USER: NewUserCommand, + VERSION: NewVersionCommand, WHO: NewWhoCommand, WHOIS: NewWhoisCommand, } @@ -900,3 +901,16 @@ func NewDebugCommand(args []string) (editableCommand, error) { subCommand: strings.ToUpper(args[0]), }, nil } + +type VersionCommand struct { + BaseCommand + target string +} + +func NewVersionCommand(args []string) (editableCommand, error) { + cmd := &VersionCommand{} + if len(args) > 0 { + cmd.target = args[0] + } + return cmd, nil +} diff --git a/irc/constants.go b/irc/constants.go index 8fd4e7e6..e00e6e74 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -23,9 +23,9 @@ var ( ) const ( - VERSION = "1.0.0" - CRLF = "\r\n" - MAX_REPLY_LEN = 512 - len(CRLF) + SERVER_VERSION = "1.0.0" + CRLF = "\r\n" + MAX_REPLY_LEN = 512 - len(CRLF) LOGIN_TIMEOUT = time.Minute / 2 // how long the client has to login IDLE_TIMEOUT = time.Minute // how long before a client is considered idle @@ -56,6 +56,7 @@ const ( QUIT StringCode = "QUIT" TOPIC StringCode = "TOPIC" USER StringCode = "USER" + VERSION StringCode = "VERSION" WHO StringCode = "WHO" WHOIS StringCode = "WHOIS" diff --git a/irc/reply.go b/irc/reply.go index 01168e2f..bd53ec25 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -146,7 +146,7 @@ func (target *Client) RplWelcome() { func (target *Client) RplYourHost() { target.NumericReply(RPL_YOURHOST, - ":Your host is %s, running version %s", target.server.name, VERSION) + ":Your host is %s, running version %s", target.server.name, SERVER_VERSION) } func (target *Client) RplCreated() { @@ -156,7 +156,7 @@ func (target *Client) RplCreated() { func (target *Client) RplMyInfo() { target.NumericReply(RPL_MYINFO, - "%s %s aiOorsw abeIikmntpqrsl", target.server.name, VERSION) + "%s %s aiOorsw abeIikmntpqrsl", target.server.name, SERVER_VERSION) } func (target *Client) RplUModeIs(client *Client) { @@ -364,6 +364,11 @@ func (target *Client) RplWhoisChannels(client *Client) { "%s :%s", client.Nick()) } +func (target *Client) RplVersion() { + target.NumericReply(RPL_VERSION, + "ergonomadic-%s %s", SERVER_VERSION, target.server.name) +} + // // errors (also numeric) // diff --git a/irc/server.go b/irc/server.go index d09161e3..f15780fb 100644 --- a/irc/server.go +++ b/irc/server.go @@ -762,3 +762,13 @@ func (msg *DebugCommand) HandleServer(server *Server) { server.Reply(client, "written to ergonomadic-heap.prof") } } + +func (msg *VersionCommand) HandleServer(server *Server) { + client := msg.Client() + if (msg.target != "") && (msg.target != server.name) { + client.ErrNoSuchServer(msg.target) + return + } + + client.RplVersion() +}