]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/modules.h
Add more features to modestacker so that we can stack +, -, and parameterless modes
[user/henk/code/inspircd.git] / include / modules.h
index 90c06361f24ff4223a1d311809220570d0d23e89..df9497fd2db64b1b49a52f99bda2477de2ce2aa3 100644 (file)
@@ -64,14 +64,18 @@ enum TargetTypeFlags {
 #include <string>
 #include <deque>
 #include <sstream>
-#include <typeinfo>
 #include "timer.h"
 #include "mode.h"
 #include "dns.h"
 
+/** If you change the module API, change this value
+ */
+#define API_VERSION 11001
+
 class ServerConfig;
 
-// Forward-delacare module for ModuleMessage etc
+/* Forward-delacare module for ModuleMessage etc
+ */
 class Module;
 
 /** Low level definition of a FileReader classes file cache area
@@ -97,7 +101,7 @@ typedef std::map<std::string,Module*> featurelist;
                } \
                catch (ModuleException& modexcept) \
                { \
-                       log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \
+                       ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \
                } \
        } \
   }
@@ -111,7 +115,7 @@ typedef std::map<std::string,Module*> featurelist;
                } \
                catch (ModuleException& modexcept) \
                { \
-                       log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \
+                       z->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \
                } \
        } \
 }
@@ -134,7 +138,7 @@ typedef std::map<std::string,Module*> featurelist;
                                } \
                                catch (ModuleException& modexcept) \
                                { \
-                                       log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+                                       ServerInstance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
                                } \
                        } \
                } \
@@ -155,7 +159,7 @@ typedef std::map<std::string,Module*> featurelist;
                                } \
                                catch (ModuleException& modexcept) \
                                { \
-                                       log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+                                       z->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
                                } \
                        } \
                } \
@@ -166,9 +170,9 @@ typedef std::map<std::string,Module*> featurelist;
 
 // useful macros
 
-#define IS_LOCAL(x) ((x->fd > -1) && (x->fd <= MAX_DESCRIPTORS))
-#define IS_REMOTE(x) (x->fd < 0)
-#define IS_MODULE_CREATED(x) (x->fd == FD_MAGIC_NUMBER)
+#define IS_LOCAL(x) ((x->GetFd() > -1) && (x->GetFd() <= MAX_DESCRIPTORS))
+#define IS_REMOTE(x) (x->GetFd() < 0)
+#define IS_MODULE_CREATED(x) (x->GetFd() == FD_MAGIC_NUMBER)
 
 /** Holds a module's Version information
  *  The four members (set by the constructor only) indicate details as to the version number
@@ -177,20 +181,17 @@ typedef std::map<std::string,Module*> featurelist;
 class Version : public classbase
 {
  public:
-        const int Major, Minor, Revision, Build, Flags;
-        Version(int major, int minor, int revision, int build, int flags);
+        const int Major, Minor, Revision, Build, Flags, API;
+        Version(int major, int minor, int revision, int build, int flags, int api_ver);
 };
 
 /** The ModuleMessage class is the base class of Request and Event
  * This class is used to represent a basic data structure which is passed
  * between modules for safe inter-module communications.
  */
-class ModuleMessage : public classbase
+class ModuleMessage : public Extensible
 {
  public:
-       /** This class is pure virtual and must be inherited.
-        */
-       virtual char* Send() = 0;
        virtual ~ModuleMessage() {};
 };
 
@@ -294,7 +295,7 @@ class Event : public ModuleMessage
         * The return result of an Event::Send() will always be NULL as
         * no replies are expected.
         */
-       char* Send();
+       char* Send(InspIRCd* ServerInstance);
 };
 
 /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
@@ -344,9 +345,9 @@ enum Implementation {       I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse
                        I_OnCleanup, I_OnUserPostNick, I_OnAccessCheck, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule, I_OnUnloadModule,
                        I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnUserRrgister, I_OnRawMode, I_OnCheckInvite,
                        I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, I_OnLocalTopicChange,
-                       I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnGlobalConnect, I_OnAddBan, I_OnDelBan,
+                       I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan,
                        I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
-                       I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway };
+                       I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList, I_OnPostCommand, I_OnPostJoin };
 
 /** Base class for all InspIRCd modules
  *  This class is the base class for InspIRCd modules. All modules must inherit from this class,
@@ -448,6 +449,14 @@ class Module : public Extensible
         */
        virtual void OnUserJoin(userrec* user, chanrec* channel);
 
+       /** Called after a user joins a channel
+        * Identical to OnUserJoin, but called immediately afterwards, when any linking module has
+        * seen the join.
+        * @param user The user who is joining
+        * @param channel The channel being joined
+        */
+       virtual void OnPostJoin(userrec* user, chanrec* channel);
+
        /** Called when a user parts a channel.
         * The details of the leaving user are available to you in the parameter userrec *user,
         * and the details of the channel they have left is available in the variable chanrec *channel
@@ -492,10 +501,13 @@ class Module : public Extensible
         * processing on the actual channel record at this point, however the channel NAME will still be passed in
         * char* cname, so that you could for example implement a channel blacklist or whitelist, etc.
         * @param user The user joining the channel
-        * @param cname The channel name being joined
+        * @param chan If the  channel is a new channel, this will be NULL, otherwise it will be a pointer to the channel being joined
+        * @param cname The channel name being joined. For new channels this is valid where chan is not.
+        * @param privs A string containing the users privilages when joining the channel. For new channels this will contain "@".
+        * You may alter this string to alter the user's modes on the channel.
         * @return 1 To prevent the join, 0 to allow it.
         */
-       virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
+       virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs);
        
        /** Called whenever a user is about to be kicked.
         * Returning a value of 1 from this function stops the process immediately, causing no
@@ -989,8 +1001,8 @@ class Module : public Extensible
 
        /** Called whenever any command is about to be executed.
         * This event occurs for all registered commands, wether they are registered in the core,
-        * or another module, but it will not occur for invalid commands (e.g. ones which do not
-        * exist within the command table). By returning 1 from this method you may prevent the
+        * or another module, and for invalid commands. Invalid commands may only be sent to this
+        * function when the value of validated is false. By returning 1 from this method you may prevent the
         * command being executed. If you do this, no output is created by the core, and it is
         * down to your module to produce any output neccessary.
         * Note that unless you return 1, you should not destroy any structures (e.g. by using
@@ -1001,9 +1013,24 @@ class 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.
+        * @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 char** parameters, int pcnt, userrec *user, bool validated);
+       virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *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,
+        * or another module, but it will not occur for invalid commands (e.g. ones which do not
+        * exist within the command table). The result code returned by the command handler is
+        * provided.
+        * @param command The command being executed
+        * @param parameters An array of array of characters containing the parameters for the command
+        * @param pcnt The nuimber of parameters passed to the command
+        * @param user the user issuing the command
+        * @param result The return code given by the command handler, one of CMD_SUCCESS or CMD_FAILURE
+        * @param original_line The entire original line as passed to the parser from the user
+        */
+       virtual void OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line);
 
        /** Called to check if a user who is connecting can now be allowed to register
         * If any modules return false for this function, the user is held in the waiting
@@ -1086,7 +1113,9 @@ class Module : public Extensible
         * This method is triggered for all /STATS use, including stats symbols handled by the core.
         * @param symbol the symbol provided to /STATS
         * @param user the user issuing the /STATS command
-        * @param results A string_list to append results into
+        * @param results A string_list to append results into. You should put all your results
+        * into this string_list, rather than displaying them directly, so that your handler will
+        * work when remote STATS queries are received.
         * @return 1 to block the /STATS from being processed by the core, 0 to allow it
         */
        virtual int OnStats(char symbol, userrec* user, string_list &results);
@@ -1160,12 +1189,13 @@ class Module : public Extensible
         */
        virtual void OnGlobalOper(userrec* user);
 
-       /**  Called whenever a user connects, anywhere on the network.
+       /** Called after a user has fully connected and all modules have executed OnUserConnect
         * This event is informational only. You should not change any user information in this
         * event. To do so, use the OnUserConnect method to change the state of local users.
+        * This is called for both local and remote users.
         * @param user The user who is connecting
         */
-       virtual void OnGlobalConnect(userrec* user);
+       virtual void OnPostConnect(userrec* user);
 
        /** Called whenever a ban is added to a channel's list.
         * Return a non-zero value to 'eat' the mode change and prevent the ban from being added.
@@ -1240,6 +1270,13 @@ class Module : public Extensible
        /** Called when a user cancels their away state.
         */
        virtual void OnCancelAway(userrec* user);
+
+       /** Called whenever a NAMES list is requested.
+        * You can produce the nameslist yourself, overriding the current list,
+        * and if you do you must return 1. If you do not handle the names list,
+        * return 0.
+        */
+       virtual int OnUserList(userrec* user, chanrec* Ptr);
 };
 
 
@@ -1258,6 +1295,7 @@ class Module : public Extensible
 class ConfigReader : public classbase
 {
   protected:
+       InspIRCd* ServerInstance;
        /** The contents of the configuration file
         * This protected member should never be accessed by a module (and cannot be accessed unless the
         * core is changed). It will contain a pointer to the configuration file data with unneeded data
@@ -1276,11 +1314,11 @@ class ConfigReader : public classbase
         * This constructor initialises the ConfigReader class to read the inspircd.conf file
         * as specified when running ./configure.
         */
-       ConfigReader();                 // default constructor reads ircd.conf
+       ConfigReader(InspIRCd* Instance);
        /** Overloaded constructor.
         * This constructor initialises the ConfigReader class to read a user-specified config file
         */
-       ConfigReader(const std::string &filename);      // read a module-specific config
+       ConfigReader(InspIRCd* Instance, const std::string &filename);
        /** Default destructor.
         * This method destroys the ConfigReader class.
         */
@@ -1347,6 +1385,7 @@ class ConfigReader : public classbase
  */
 class FileReader : public classbase
 {
+       InspIRCd* ServerInstance;
        /** The file contents
         */
        file_cache fc;
@@ -1360,14 +1399,14 @@ class FileReader : public classbase
         * This method does not load any file into memory, you must use the LoadFile method
         * after constructing the class this way.
         */
-       FileReader();
+       FileReader(InspIRCd* Instance);
 
        /** Secondary constructor.
         * This method initialises the class with a file loaded into it ready for GetLine and
         * and other methods to be called. If the file could not be loaded, FileReader::FileSize
         * returns 0.
         */
-       FileReader(const std::string &filename);
+       FileReader(InspIRCd* Instance, const std::string &filename);
 
        /** Default destructor.
         * This deletes the memory allocated to the file.
@@ -1409,7 +1448,7 @@ class FileReader : public classbase
 };
 
 
-/** Instantiates classes inherited from Module
+/** Instantiates classes inherited from Module.
  * This class creates a class inherited from type Module, using new. This is to allow for modules
  * to create many different variants of Module, dependent on architecture, configuration, etc.
  * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
@@ -1418,7 +1457,11 @@ class FileReader : public classbase
 class ModuleFactory : public classbase
 {
  public:
+       /** The default constructor does nothing.
+        */
        ModuleFactory() { }
+       /** The default destructor does nothing
+        */
        virtual ~ModuleFactory() { }
        /** Creates a new module.
         * Your inherited class of ModuleFactory must return a pointer to your Module class
@@ -1427,9 +1470,16 @@ class ModuleFactory : public classbase
        virtual Module * CreateModule(InspIRCd* Me) = 0;
 };
 
-
+/** A DLLFactory (designed to load shared objects) containing a ModuleFactory.
+ */
 typedef DLLFactory<ModuleFactory> ircd_module;
+
+/** A list of loaded Modules
+ */
 typedef std::vector<Module*> ModuleList;
+
+/** A list of loaded ModuleFactories
+ */
 typedef std::vector<ircd_module*> FactoryList;
 
 #endif