]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/modules.h
Added VF_ module flags as discussed with Craig
[user/henk/code/inspircd.git] / include / modules.h
index 60d951623989357ed595a169cba34aa1ea30646f..9b2118472b15307c689a8d0e7c66da6a6905c4eb 100644 (file)
@@ -1,8 +1,18 @@
-/*
-
-
-
-*/
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *                       E-mail:
+ *                <brain@chatspike.net>
+ *               <Craig@chatspike.net>
+ *     
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
 
 
 #ifndef __PLUGIN_H
 #define AC_INVITE 7            // a user is being invited
 #define AC_GENERAL_MODE 8      // a user channel mode is being changed
 
+// used to define a set of behavior bits for a module
+
+#define VF_STATIC              1       // module is static, cannot be /unloadmodule'd
+#define VF_VENDOR              2       // module is a vendor module (came in the original tarball, not 3rd party)
+#define VF_SERVICEPROVIDER     4       // module provides a service to other modules (can be a dependency)
+#define VF_COMMON              8       // module needs to be common on all servers in a mesh to link
+
 #include "dynamic.h"
 #include "base.h"
 #include "ctables.h"
@@ -70,12 +87,12 @@ typedef std::deque<userrec*> chanuserlist;
 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
                        for (int i = 0; i <= MODCOUNT; i++) { \
                        int res = modules[i]->x ; \
-                       if (res) { \
+                       if (res != 0) { \
                                MOD_RESULT = res; \
                                break; \
                        } \
                } \
-   } 
+       
    
 // *********************************************************************************************
 
@@ -201,9 +218,10 @@ class Module : public classbase
        virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
        
        /** Called whenever a user is about to join a channel, before any processing is done.
-        * Returning any nonzero value from this function stops the process immediately, causing no
+        * Returning a value of 1 from this function stops the process immediately, causing no
         * output to be sent to the user by the core. If you do this you must produce your own numerics,
-        * notices etc. This is useful for modules which may want to mimic +b, +k, +l etc.
+        * notices etc. This is useful for modules which may want to mimic +b, +k, +l etc. Returning -1 from
+        * this function forces the join to be allowed, bypassing restrictions such as banlists, invite, keys etc.
         *
         * IMPORTANT NOTE!
         *
@@ -227,7 +245,7 @@ class Module : public classbase
         * It is purposefully not possible to modify any info that has already been output, or halt the list.
         * You must write a 371 numeric to the user, containing your info in the following format:
         *
-        * <nick> :information here
+        * &lt;nick&gt; :information here
         */
        virtual void OnInfo(userrec* user);
        
@@ -237,6 +255,13 @@ class Module : public classbase
         */
        virtual void OnWhois(userrec* source, userrec* dest);
        
+       /** Called whenever a user is about to invite another user into a channel, before any processing is done.
+        * Returning 1 from this function stops the process immediately, causing no
+        * output to be sent to the user by the core. If you do this you must produce your own numerics,
+        * notices etc. This is useful for modules which may want to filter invites to channels.
+        */
+       virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
+       
        /** Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done.
         * Returning any nonzero value from this function stops the process immediately, causing no
         * output to be sent to the user by the core. If you do this you must produce your own numerics,
@@ -245,7 +270,7 @@ class Module : public classbase
         * you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details
         * of where the message is destined to be sent.
         */
-       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text);
+       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
 
        /** Called whenever a user is about to NOTICE A user or a channel, before any processing is done.
         * Returning any nonzero value from this function stops the process immediately, causing no
@@ -254,8 +279,11 @@ class Module : public classbase
         * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user,
         * you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details
         * of where the message is destined to be sent.
+        * You may alter the message text as you wish before relinquishing control to the next module
+        * in the chain, and if no other modules block the text this altered form of the text will be sent out
+        * to the user and possibly to other servers.
         */
-       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text);
+       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
        
        /** Called before any nickchange, local or remote. This can be used to implement Q-lines etc.
         * Please note that although you can see remote nickchanges through this function, you should
@@ -266,6 +294,15 @@ class Module : public classbase
         */
        virtual int OnUserPreNick(userrec* user, std::string newnick);
        
+       /** Called after any nickchange, local or remote. This can be used to track users after nickchanges
+        * have been applied. Please note that although you can see remote nickchanges through this function, you should
+         * NOT make any changes to the userrec if the user is a remote user as this may cause a desnyc.
+         * check user->server before taking any action (including returning nonzero from the method).
+        * Because this method is called after the nickchange is taken place, no return values are possible
+        * to indicate forbidding of the nick change. Use OnUserPreNick for this.
+         */
+       virtual void OnUserPostNick(userrec* user, std::string oldnick);
+
        /** Called before an action which requires a channel privilage check.
         * This function is called before many functions which check a users status on a channel, for example
         * before opping a user, deopping a user, kicking a user, etc.
@@ -287,8 +324,8 @@ class Module : public classbase
         * AC_GENERAL_MODE type, as it may inadvertently override the behaviour of other modules. When the access_type
         * is AC_GENERAL_MODE, the destination of the mode will be NULL (as it has not yet been determined).
         */
-
        virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
+
        /** Called during a netburst to sync user data.
         * This is called during the netburst on a per-user basis. You should use this call to up any special
         * user-related things which are implemented by your module, e.g. sending listmodes. You may return
@@ -302,6 +339,34 @@ class Module : public classbase
         * multiple commands in the string_list.
         */
        virtual string_list OnChannelSync(chanrec* chan);
+
+       /** Called when a 005 numeric is about to be output.
+        * The module should modify the 005 numeric if needed to indicate its features.
+        */
+       virtual void On005Numeric(std::string &output);
+
+       /** Called when a client is disconnected by KILL.
+        * If a client is killed by a server, e.g. a nickname collision or protocol error,
+        * source is NULL.
+        * Return 1 from this function to prevent the kill, and 0 from this function to allow
+        * it as normal. If you prevent the kill no output will be sent to the client, it is
+        * down to your module to generate this information.
+        * NOTE: It is NOT advisable to stop kills which originate from servers. If you do
+        * so youre risking race conditions, desyncs and worse!
+        */
+       virtual int OnKill(userrec* source, userrec* dest, std::string reason);
+
+       /** Called whenever a module is loaded.
+        * mod will contain a pointer to the module, and string will contain its name,
+        * for example m_widgets.so. This function is primary for dependency checking,
+        * your module may decide to enable some extra features if it sees that you have
+        * for example loaded "m_killwidgets.so" with "m_makewidgets.so". It is highly
+        * recommended that modules do *NOT* bail if they cannot satisfy dependencies,
+        * but instead operate under reduced functionality, unless the dependency is
+        * absolutely neccessary (e.g. a module that extends the features of another
+        * module).
+        */
+       virtual void OnLoadModule(Module* mod,std::string name);
 };
 
 
@@ -623,6 +688,7 @@ class ConfigReader : public classbase
         * (such as comments) stripped from it.
         */
        std::stringstream *cache;
+       std::stringstream *errorlog;
        /** Used to store errors
         */
        bool readerror;
@@ -679,6 +745,13 @@ class ConfigReader : public classbase
         * file does not exist or could not be opened.
         */
        bool Verify();
+       /** Dumps the list of errors in a config file to an output location. If bail is true,
+        * then the program will abort. If bail is false and user points to a valid user
+        * record, the error report will be spooled to the given user by means of NOTICE.
+        * if bool is false AND user is false, the error report will be spooled to all opers
+        * by means of a NOTICE to all opers.
+        */
+       void DumpErrors(bool bail,userrec* user);
 
        /** Returns the number of items within a tag.
         * For example if the tag was &lt;test tag="blah" data="foo"&gt; then this