]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/modules.h
Converted to new Implements system
[user/henk/code/inspircd.git] / include / modules.h
index 315739c2259793a1b582aaa5659da7ed49415a3e..264354db91d77d51f486d37803a2413d7924ccf8 100644 (file)
 #include <string>
 #include <deque>
 #include <sstream>
+#include <typeinfo>
 
 class Server;
+class ServerConfig;
 
 /** Low level definition of a FileReader classes file cache area
  */
@@ -78,7 +80,10 @@ typedef std::deque<userrec*> chanuserlist;
 // loaded modules in a readable simple way, e.g.:
 // 'FOREACH_MOD OnConnect(user);'
 
-#define FOREACH_MOD for (int _i = 0; _i <= MODCOUNT; _i++) modules[_i]->
+#define FOREACH_MOD(y,x) for (int _i = 0; _i <= MODCOUNT; _i++) { \
+       if (Config->implement_lists[_i][y]) \
+               modules[_i]->x ; \
+       }
 
 // This define is similar to the one above but returns a result in MOD_RESULT.
 // The first module to return a nonzero result is the value to be accepted,
@@ -86,12 +91,14 @@ typedef std::deque<userrec*> chanuserlist;
 
 // *********************************************************************************************
 
-#define FOREACH_RESULT(x) { MOD_RESULT = 0; \
+#define FOREACH_RESULT(y,x) { MOD_RESULT = 0; \
                        for (int _i = 0; _i <= MODCOUNT; _i++) { \
-                       int res = modules[_i]->x ; \
-                       if (res != 0) { \
-                               MOD_RESULT = res; \
-                               break; \
+                       if (Config->implement_lists[_i][y]) {\
+                               int res = modules[_i]->x ; \
+                               if (res != 0) { \
+                                       MOD_RESULT = res; \
+                                       break; \
+                               } \
                        } \
                } \
        } 
@@ -100,8 +107,25 @@ typedef std::deque<userrec*> chanuserlist;
 
 #define FD_MAGIC_NUMBER -42
 
-extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
-extern void server_mode(char **parameters, int pcnt, userrec *user);
+// useful macros
+
+#define IS_LOCAL(x) (x->fd > -1)
+#define IS_REMOTE(x) (x->fd < 0)
+#define IS_MODULE_CREATED(x) (x->fd == FD_MAGIC_NUMBER)
+
+// flags for use with WriteMode
+
+#define WM_AND 1
+#define WM_OR 2
+
+// flags for use with OnUserPreMessage and OnUserPreNotice
+
+#define TYPE_USER 1
+#define TYPE_CHANNEL 2
+#define TYPE_SERVER 3
+
+/*extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
+extern void server_mode(char **parameters, int pcnt, userrec *user);*/
 
 // class Version holds the version information of a Module, returned
 // by Module::GetVersion (thanks RD)
@@ -230,6 +254,34 @@ class Event : public ModuleMessage
         char* Send();
 };
 
+/** Holds an extended mode's details.
+ * Used internally by modules.cpp
+ */
+class ExtMode : public classbase
+{
+ public:
+        char modechar;
+        int type;
+        bool needsoper;
+        int params_when_on;
+        int params_when_off;
+        bool list;
+        ExtMode(char mc, int ty, bool oper, int p_on, int p_off) : modechar(mc), type(ty), needsoper(oper), params_when_on(p_on), params_when_off(p_off) { };
+};
+
+
+enum Implementation {  I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash, I_OnServerRaw, 
+                       I_OnExtendedMode, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois, I_OnUserPreInvite,
+                       I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreNick, I_OnUserMessage, I_OnUserNotice, I_OnMode,
+                       I_OnGetServerDescription, I_OnSyncUser, I_OnSyncChannel, I_OnSyncChannelMetaData, I_OnSyncUserMetaData,
+                       I_OnDecodeMetaData, I_ProtoSendMode, I_ProtoSendMetaData, I_OnWallops, I_OnChangeHost, I_OnChangeName, I_OnAddGLine,
+                       I_OnAddZLine, I_OnAddQLine, I_OnAddKLine, I_OnAddELine, I_OnDelGLine, I_OnDelZLine, I_OnDelKLine, I_OnDelELine, I_OnDelQLine,
+                       I_OnCleanup, I_OnUserPostNick, I_OnAccessCheck, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule, I_OnUnloadModule,
+                       I_OnBackgroundTimer, I_OnSendList, 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_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
+                       I_OnOperCompare };
 
 /** Base class for all InspIRCd modules
  *  This class is the base class for InspIRCd modules. All modules must inherit from this class,
@@ -257,6 +309,8 @@ class Module : public classbase
         */
        virtual Version GetVersion();
 
+       virtual void Implements(char* Implements);
+
        /** Called when a user connects.
         * The details of the connecting user are available to you in the parameter userrec *user
         * @param user The user who is connecting
@@ -844,9 +898,10 @@ class Module : public classbase
         * @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 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.
         * @return 1 to block the command, 0 to allow
         */
-       virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user);
+       virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated);
 
        /** 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
@@ -1089,11 +1144,18 @@ class Server : public classbase
         * Destroys a Server object.
         */
        virtual ~Server();
-
+       /** Obtains a pointer to the server's ServerConfig object.
+        * The ServerConfig object contains most of the configuration data
+        * of the IRC server, as read from the config file by the core.
+        */
+       ServerConfig* GetConfig();
        /** Sends text to all opers.
         * This method sends a server notice to all opers with the usermode +s.
         */
        virtual void SendOpers(std::string s);
+       /** Returns the version string of this server
+        */
+       std::string GetVersion();
        /** Writes a log string.
         * This method writes a line of text to the log. If the level given is lower than the
         * level given in the configuration, this command has no effect.
@@ -1263,7 +1325,7 @@ class Server : public classbase
         * extension) e.g. "m_blarp.so". If you place the wrong identifier here, you can cause crashes if your module
         * is unloaded.
         */
-       virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
+       virtual void AddCommand(command_t *f);
         
        /** Sends a servermode.
         * you must format the parameters array with the target, modes and parameters for those modes.
@@ -1666,4 +1728,11 @@ class ModuleFactory : public classbase
 
 typedef DLLFactory<ModuleFactory> ircd_module;
 
+bool ModeDefined(char c, int i);
+bool ModeDefinedOper(char c, int i);
+int ModeDefinedOn(char c, int i);
+int ModeDefinedOff(char c, int i);
+void ModeMakeList(char modechar);
+bool ModeIsListMode(char modechar, int type);
+
 #endif