]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/numericbuilder.h
Add support for sending a standard reply with no command name.
[user/henk/code/inspircd.git] / include / numericbuilder.h
index 0d55093ca59c3db15d9f75b787f2872fa7dc918d..73bcc2c97f67ec28a7d0c187c3e8ae55f19adc99 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
  *   Copyright (C) 2015-2016 Attila Molnar <attilamolnar@hush.com>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
@@ -207,6 +208,29 @@ namespace Numerics
 /* Builder for the ERR_INVALIDMODEPARAM numeric. */
 class Numerics::InvalidModeParameter : public Numeric::Numeric
 {
+ private:
+       void push_message(ModeHandler* mode, const std::string& message)
+       {
+               if (!message.empty())
+               {
+                       // The caller has specified their own message.
+                       push(message);
+                       return;
+               }
+
+               const std::string& syntax = mode->GetSyntax();
+               if (!syntax.empty())
+               {
+                       // If the mode has a syntax hint we include it in the message.
+                       push(InspIRCd::Format("Invalid %s mode parameter. Syntax: %s.", mode->name.c_str(), syntax.c_str()));
+               }
+               else
+               {
+                       // Otherwise, send it without.
+                       push(InspIRCd::Format("Invalid %s mode parameter.", mode->name.c_str()));
+               }
+       }
+
  public:
        InvalidModeParameter(Channel* chan, ModeHandler* mode, const std::string& parameter, const std::string& message = "")
                : Numeric(ERR_INVALIDMODEPARAM)
@@ -214,7 +238,7 @@ class Numerics::InvalidModeParameter : public Numeric::Numeric
                push(chan->name);
                push(mode->GetModeChar());
                push(parameter);
-               push(message.empty() ? InspIRCd::Format("Invalid %s mode parameter", mode->name.c_str()) : message);
+               push_message(mode, message);
        }
 
        InvalidModeParameter(User* user, ModeHandler* mode, const std::string& parameter, const std::string& message = "")
@@ -223,7 +247,7 @@ class Numerics::InvalidModeParameter : public Numeric::Numeric
                push(user->registered & REG_NICK ? user->nick : "*");
                push(mode->GetModeChar());
                push(parameter);
-               push(message.empty() ? InspIRCd::Format("Invalid %s mode parameter", mode->name.c_str()) : message);
+               push_message(mode, message);
        }
 };
 
@@ -234,7 +258,7 @@ class Numerics::NoSuchChannel : public Numeric::Numeric
        NoSuchChannel(const std::string& chan)
                : Numeric(ERR_NOSUCHCHANNEL)
        {
-               push(chan);
+               push(chan.empty() ? "*" : chan);
                push("No such channel");
        }
 };
@@ -246,7 +270,7 @@ class Numerics::NoSuchNick : public Numeric::Numeric
        NoSuchNick(const std::string& nick)
                : Numeric(ERR_NOSUCHNICK)
        {
-               push(nick);
+               push(nick.empty() ? "*" : nick);
                push("No such nick");
        }
 };