]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allow changing of command string and parameter vector within OnPreCommand, allowing...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 6 Jun 2008 15:22:07 +0000 (15:22 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 6 Jun 2008 15:22:07 +0000 (15:22 +0000)
Add basic skeleton module for it

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9840 e03df62e-2008-0410-955e-edbf42e46eb7

18 files changed:
include/modules.h
src/modules.cpp
src/modules/extra/m_sqllog.cpp
src/modules/extra/m_sqloper.cpp
src/modules/extra/m_ssl_oper_cert.cpp
src/modules/m_abbreviation.cpp [new file with mode: 0644]
src/modules/m_alias.cpp
src/modules/m_antibear.cpp
src/modules/m_antibottler.cpp
src/modules/m_blockamsg.cpp
src/modules/m_conn_waitpong.cpp
src/modules/m_namesx.cpp
src/modules/m_operlog.cpp
src/modules/m_safelist.cpp
src/modules/m_securelist.cpp
src/modules/m_shun.cpp
src/modules/m_spanningtree/precommand.cpp
src/modules/m_uhnames.cpp

index 585bd98d9a89e8800bcd1ca45a31343f13704d06..7ae620752abb1edebaf566f162bbd56386a8facb 100644 (file)
@@ -1034,10 +1034,11 @@ class CoreExport Module : public Extensible
         * @param pcnt The nuimber of parameters passed to the command
         * @param user the user issuing the command
         * @param validated True if the command has passed all checks, e.g. it is recognised, has enough parameters, the user has permission to execute it, etc.
+        * You should only change the parameter list and command string if validated == false (e.g. before the command lookup occurs).
         * @param original_line The entire original line as passed to the parser from the user
         * @return 1 to block the command, 0 to allow
         */
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, bool validated, const std::string &original_line);
+       virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User *user, bool validated, const std::string &original_line);
 
        /** Called after any command has been executed.
         * This event occurs for all registered commands, wether they are registered in the core,
index 5cfbd6f9398ffcb72a02bece83751291a77426e7..a45ec21eca64ff7007b79827f9a1725ea07cb6db 100644 (file)
@@ -132,7 +132,7 @@ int         Module::OnKill(User*, User*, const std::string&) { return 0; }
 void           Module::OnLoadModule(Module*, const std::string&) { }
 void           Module::OnUnloadModule(Module*, const std::string&) { }
 void           Module::OnBackgroundTimer(time_t) { }
-int            Module::OnPreCommand(const std::string&, const std::vector<std::string>&, User *, bool, const std::string&) { return 0; }
+int            Module::OnPreCommand(std::string&, std::vector<std::string>&, User *, bool, const std::string&) { return 0; }
 void           Module::OnPostCommand(const std::string&, const std::vector<std::string>&, User *, CmdResult, const std::string&) { }
 bool           Module::OnCheckReady(User*) { return true; }
 int            Module::OnUserRegister(User*) { return 0; }
index 16746f69001b66ccfeb5bee47ccdb858f480b6f2..fb49f828c98592f346f9b79f17851f5ff46290fb 100644 (file)
@@ -276,7 +276,7 @@ class ModuleSQLLog : public Module
                return 0;
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                if ((command == "GLINE" || command == "KLINE" || command == "ELINE" || command == "ZLINE") && validated)
                {
index f3c32b14047af9057ffb1011eed245272053099c..b848345580747db17d92d6824caf2e3a68af9b5a 100644 (file)
@@ -111,7 +111,7 @@ public:
                hashtype = assign(Conf.ReadValue("sqloper", "hash", 0));
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                if ((validated) && (command == "OPER"))
                {
index c99dfa2e20a0331a211d093d461fc0460f49edf8..ed4ba9c003d48a365f0266064c420d8a8c55c9b3 100644 (file)
@@ -112,7 +112,7 @@ class ModuleOperSSLCert : public Module
                return false;
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                irc::string cmd = command.c_str();
                
diff --git a/src/modules/m_abbreviation.cpp b/src/modules/m_abbreviation.cpp
new file mode 100644 (file)
index 0000000..fd6309e
--- /dev/null
@@ -0,0 +1,50 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include "wildcard.h"
+
+/* $ModDesc: Provides the ability to abbreviate commands. */
+
+class ModuleAbbreviation : public Module
+{
+
+ public:
+       
+       ModuleAbbreviation(InspIRCd* Me)
+               : Module(Me)
+       {
+               Me->Modules->Attach(I_OnPreCommand, this);
+               /* Must do this first */
+               Me->Modules->SetPriority(this, I_OnPreCommand, PRIO_FIRST);
+       }
+
+       virtual Version GetVersion()
+       {
+               return Version(1,2,0,0,VF_VENDOR,API_VERSION);
+       }
+
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       {
+               /* Command is already validated, has a length of 0, or last character is not a . */
+               if (validated || command.empty() || *command.rbegin() != '.')
+                       return 0;
+
+               /* Whack the . off the end */
+               command.erase(command.end() - 1);
+
+               ServerInstance->Logs->Log("m_abbreviation", DEBUG, "Abbreviated command: %s", command.c_str());
+       }
+};
+
+MODULE_INIT(ModuleAbbreviation)
index 1eb78023e388480369a841143a960a93be719de1..762ba6e29fd4665794a186e3fe7ddb93ea88f12e 100644 (file)
@@ -124,7 +124,7 @@ class ModuleAlias : public Module
                }
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                User *u = NULL;
 
index 633b1e332795fc91dcb71b22ac4cc88ef7734272..925ec23149278eb1eae245bfb1329c33879242cd 100644 (file)
@@ -37,7 +37,7 @@ class ModuleAntiBear : public Module
                return Version(1,2,0,0,VF_VENDOR,API_VERSION);
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                if (command == "NOTICE" && !validated && parameters.size() > 1 && user->GetExt("antibear_timewait"))
                {
index bafd422da37475dd1856fb97ddd85674f8f7688f..37f5f953ec9c819aa3918dd5a0052370ddb701d1 100644 (file)
@@ -37,7 +37,7 @@ class ModuleAntiBottler : public Module
                return Version(1,2,0,1,VF_VENDOR,API_VERSION);
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                char data[MAXBUF];
                strlcpy(data,original_line.c_str(),MAXBUF);
index 500452fc4e27345eab78e058b1c89e5611c68df8..cf390f1653b733631bdf7fdfd64aa9863e957dc1 100644 (file)
@@ -84,7 +84,7 @@ class ModuleBlockAmsg : public Module
                        action = IBLOCK_KILLOPERS;
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                // Don't do anything with unregistered users, or remote ones.
                if(!user || (user->registered != REG_ALL) || !IS_LOCAL(user))
index 4fe71f1629dca01ec869717128ba6bc060853ffe..8d631b4f08b8400794fbc49ff47f6ce4ee857c21 100644 (file)
@@ -69,7 +69,7 @@ class ModuleWaitPong : public Module
                return 0;
        }
        
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User* user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User* user, bool validated, const std::string &original_line)
        {
                if (command == "PONG")
                {
index e9b109f5c114307d0207fe06cfdc1e335fdf2071..6ad15fa1d990c4fb7873a9f9c011d0e0acb914b1 100644 (file)
@@ -48,7 +48,7 @@ class ModuleNamesX : public Module
                output.append(" NAMESX");
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                irc::string c = command.c_str();
                /* We don't actually create a proper command handler class for PROTOCTL,
index e295d2183a5c176682a842ec3901cdb87f67d18a..9c82222c1eb1ba4a05ad69bb446741a3331aea98 100644 (file)
@@ -37,7 +37,7 @@ class ModuleOperLog : public Module
        }
  
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                /* If the command doesnt appear to be valid, we dont want to mess with it. */
                if (!validated)
index e6bb24442de3620b61ae21d4159b63cda19041cd..9bcc78806b62b222c87a0a61c57cfff09dc6eba3 100644 (file)
@@ -69,7 +69,7 @@ class ModuleSafeList : public Module
         * OnPreCommand()
         *   Intercept the LIST command.
         */ 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                /* If the command doesnt appear to be valid, we dont want to mess with it. */
                if (!validated)
index b86a35b7ffa91e1f071e4e98162e938681eccfcf..356a1a93e65ae9130d5dcca8dbc3f9dec4b14b1f 100644 (file)
@@ -54,7 +54,7 @@ class ModuleSecureList : public Module
         * OnPreCommand()
         *   Intercept the LIST command.
         */ 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                /* If the command doesnt appear to be valid, we dont want to mess with it. */
                if (!validated)
index be77f9d772beb69b65c46ebe8f24080cffc2c0d3..cd777340a4058a8d225a0761786472ece1d5f40a 100644 (file)
@@ -195,7 +195,7 @@ class ModuleShun : public Module
                }
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
        {
                if((command != "PONG") && (command != "PING"))
                {
index 2fdd9a5d5c70730652305e0eba6a6f0a6ed485c1..e27de1dbd5a9a7a47eb6120930c0eba3fb952ea3 100644 (file)
@@ -33,7 +33,7 @@
 
 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_spanningtree/rconnect.h m_spanningtree/rsquit.h */
 
-int ModuleSpanningTree::OnPreCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, bool validated, const std::string &original_line)
+int ModuleSpanningTree::OnPreCommand(std::string &command, std::vector<std::string>& parameters, User *user, bool validated, const std::string &original_line)
 {
        /* If the command doesnt appear to be valid, we dont want to mess with it. */
        if (!validated)
index 3733d1b351a16e7144b888e0ad4b73ea41752e23..e2144febcf3d4baf5f2d17f13e57dda14fd31471 100644 (file)
@@ -48,7 +48,7 @@ class ModuleUHNames : public Module
                output.append(" UHNAMES");
        }
 
-       virtual int OnPreCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
        {
                irc::string c = command.c_str();
                /* We don't actually create a proper command handler class for PROTOCTL,