From 6f688a4644d6e5c33f86b693fd54747871a76772 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 8 May 2020 05:44:40 -0400 Subject: [PATCH] fix #994 --- irc/client.go | 7 +------ irc/commands.go | 6 ++++++ irc/handlers.go | 6 ++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/irc/client.go b/irc/client.go index 5007c0dd..a290adf4 100644 --- a/irc/client.go +++ b/irc/client.go @@ -661,12 +661,7 @@ func (client *Client) run(session *Session) { cmd, exists := Commands[msg.Command] if !exists { - if len(msg.Command) > 0 { - session.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.Nick(), msg.Command, client.t("Unknown command")) - } else { - session.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.Nick(), "lastcmd", client.t("No command given")) - } - continue + cmd = unknownCommand } isExiting := cmd.Run(client.server, client, session, msg) diff --git a/irc/commands.go b/irc/commands.go index 5cd48ea0..1ad9f484 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -73,6 +73,12 @@ func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ir return exiting } +// fake handler for unknown commands (see #994: this ensures the response tags are correct) +var unknownCommand = Command{ + handler: unknownCommandHandler, + usablePreReg: true, +} + // Commands holds all commands executable by a client connected to us. var Commands map[string]Command diff --git a/irc/handlers.go b/irc/handlers.go index 8f1e6ad7..bdf228fe 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2760,3 +2760,9 @@ func zncHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo zncModuleHandler(client, msg.Params[0], msg.Params[1:], rb) return false } + +// fake handler for unknown commands +func unknownCommandHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { + rb.Add(nil, server.name, ERR_UNKNOWNCOMMAND, client.Nick(), utils.SafeErrorParam(msg.Command), client.t("Unknown command")) + return false +}