]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/modules.h
Tidying, strlen, strcasecmp where not needed.
[user/henk/code/inspircd.git] / include / modules.h
index b9bf136bb5eb0bd72a41c5c7b74d29fd80674df0..4dff5d48a566c218e040ba5af7bea536a50f2e37 100644 (file)
@@ -60,7 +60,8 @@ enum WriteModeFlags {
 enum TargetTypeFlags {
        TYPE_USER = 1,
        TYPE_CHANNEL,
-       TYPE_SERVER
+       TYPE_SERVER,
+       TYPE_OTHER
 };
 
 #include "dynamic.h"
@@ -71,6 +72,7 @@ enum TargetTypeFlags {
 #include <deque>
 #include <sstream>
 #include <typeinfo>
+#include "timer.h"
 
 class Server;
 class ServerConfig;
@@ -92,7 +94,14 @@ typedef std::deque<userrec*> chanuserlist;
 #define FOREACH_MOD(y,x) if (Config->global_implementation[y] > 0) { \
        for (int _i = 0; _i <= MODCOUNT; _i++) { \
        if (Config->implement_lists[_i][y]) \
-               modules[_i]->x ; \
+               try \
+               { \
+                       modules[_i]->x ; \
+               } \
+               catch (ModuleException& modexcept) \
+               { \
+                       log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+               } \
        } \
   }
 
@@ -106,10 +115,17 @@ typedef std::deque<userrec*> chanuserlist;
                        MOD_RESULT = 0; \
                        for (int _i = 0; _i <= MODCOUNT; _i++) { \
                        if (Config->implement_lists[_i][y]) {\
-                               int res = modules[_i]->x ; \
-                               if (res != 0) { \
-                                       MOD_RESULT = res; \
-                                       break; \
+                               try \
+                               { \
+                                       int res = modules[_i]->x ; \
+                                       if (res != 0) { \
+                                               MOD_RESULT = res; \
+                                               break; \
+                                       } \
+                               } \
+                               catch (ModuleException& modexcept) \
+                               { \
+                                       log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
                                } \
                        } \
                } \
@@ -268,7 +284,40 @@ class ExtMode : public classbase
         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) { };
+        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), list(false) { };
+};
+
+
+/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
+ * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or
+ * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not
+ * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
+ * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
+ */
+class ModuleException
+{
+ private:
+       /** Holds the error message to be displayed
+        */
+       std::string err;
+ public:
+       /** Default constructor, just uses the error mesage 'Module threw an exception'.
+        */
+       ModuleException() : err("Module threw an exception") {}
+       /** This constructor can be used to specify an error message before throwing.
+        */
+       ModuleException(std::string message) : err(message) {}
+       /** This destructor solves world hunger, cancels the world debt, and causes the world to end.
+        * Actually no, it does nothing. Never mind.
+        */
+       virtual ~ModuleException() {};
+       /** Returns the reason for the exception.
+        * The module should probably put something informative here as the user will see this upon failure.
+        */
+       virtual char *GetReason()
+       {
+               return (char*)err.c_str();
+       }
 };
 
 /** Priority types which can be returned from Module::Prioritize()
@@ -288,7 +337,7 @@ enum Implementation {       I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse
                        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, I_OnChannelDelete };
+                       I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway };
 
 /** Base class for all InspIRCd modules
  *  This class is the base class for InspIRCd modules. All modules must inherit from this class,
@@ -302,6 +351,7 @@ class Module : public classbase
        /** Default constructor
         * Creates a module class.
         * @param Me An instance of the Server class which can be saved for future use
+        * \exception ModuleException Throwing this class, or any class derived from ModuleException, causes loading of the module to abort.
         */
        Module(Server* Me);
 
@@ -461,7 +511,7 @@ class Module : public classbase
         * @param user The user being kicked
         * @param chan The channel the user is being kicked from
         * @param reason The kick reason
-        * @return 1 to prevent the kick, 0 to allow it
+        * @return 1 to prevent the kick, 0 to continue normally, -1 to explicitly allow the kick regardless of normal operation
          */
        virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
 
@@ -482,6 +532,15 @@ class Module : public classbase
         * @param opertype The opers type name
         */
        virtual void OnOper(userrec* user, std::string opertype);
+
+       /** Called after a user opers locally.
+        * This is identical to Module::OnOper(), except it is called after OnOper so that other modules
+        * can be gauranteed to already have processed the oper-up, for example m_spanningtree has sent
+        * out the OPERTYPE, etc.
+        * @param user The user who is opering up
+        * @param opertype The opers type name
+        */
+       virtual void OnPostOper(userrec* user, std::string opertype);
        
        /** Called whenever a user types /INFO.
         * The userrec will contain the information of the user who typed the command. Modules may use this
@@ -534,9 +593,10 @@ class Module : public classbase
         * @param dest The target of the message (chanrec* or userrec*)
         * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
         * @param text Changeable text being sent by the user
+        * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
         * @return 1 to deny the NOTICE, 0 to allow it
         */
-       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,char status);
 
        /** 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
@@ -552,9 +612,10 @@ class Module : public classbase
         * @param dest The target of the message (chanrec* or userrec*)
         * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
         * @param text Changeable text being sent by the user
+        * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
         * @return 1 to deny the NOTICE, 0 to allow it
         */
-       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,char status);
        
        /** 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
@@ -575,8 +636,9 @@ class Module : public classbase
         * @param dest The target of the message
         * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
         * @param text the text being sent by the user
+        * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
         */
-       virtual void OnUserMessage(userrec* user, void* dest, int target_type, std::string text);
+       virtual void OnUserMessage(userrec* user, void* dest, int target_type, std::string text, char status);
 
         /** Called after any NOTICE sent from a user.
         * The dest variable contains a userrec* if target_type is TYPE_USER and a chanrec*
@@ -585,8 +647,9 @@ class Module : public classbase
         * @param dest The target of the message
         * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
         * @param text the text being sent by the user
+        * @param status The status being used, e.g. NOTICE @#chan has status== '@', 0 to send to everyone.
         */
-       virtual void OnUserNotice(userrec* user, void* dest, int target_type, std::string text);
+       virtual void OnUserNotice(userrec* user, void* dest, int target_type, std::string text, char status);
 
        /** Called after every MODE command sent from a user
         * The dest variable contains a userrec* if target_type is TYPE_USER and a chanrec*
@@ -666,6 +729,17 @@ class Module : public classbase
         */
        virtual void OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, std::string extname);
 
+       /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
+        * Whenever the linking module wants to send out data, but doesnt know what the data
+        * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
+        * this method is called. You should use the ProtoSendMetaData function after you've
+        * correctly decided how the data should be represented, to send the metadata on its way if
+        * if it belongs to your module.
+        * @param proto A pointer to the module handling network protocol
+        * @param opaque An opaque pointer set by the protocol module, should not be modified!
+        */
+       virtual void OnSyncOtherMetaData(Module* proto, void* opaque);
+
        /** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module.
         * Please see src/modules/m_swhois.cpp for a working example of how to use this method call.
         * @param target_type The type of item to decode data for, TYPE_USER or TYPE_CHANNEL
@@ -1173,6 +1247,10 @@ class Module : public classbase
         * @return nonzero if the event was handled, in which case readresult must be valid on exit
         */
        virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
+
+       virtual void OnSetAway(userrec* user);
+
+       virtual void OnCancelAway(userrec* user);
 };
 
 
@@ -1313,6 +1391,10 @@ class Server : public classbase
         */
        virtual int CountUsers(chanrec* c);
 
+       /** Adds an InspTimer which will trigger at a future time
+        */
+       virtual void AddTimer(InspTimer* T);
+
        /** Attempts to look up a nick and return a pointer to it.
         * This function will return NULL if the nick does not exist.
         */
@@ -1515,8 +1597,9 @@ class Server : public classbase
         * in the array. If you do not pass enough parameters to meet the minimum needed by the handler, the
         * functiom will silently ignore it. The final parameter is the user executing the command handler,
         * used for privilage checks, etc.
+        * @return True if the command exists
         */
-       virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
+       virtual bool CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
 
        /** This function returns true if the commandname exists, pcnt is equal to or greater than the number
         * of paramters the command requires, the user specified is allowed to execute the command, AND
@@ -1662,6 +1745,10 @@ class Server : public classbase
        virtual void DelSocket(InspSocket* sock);
 
        virtual void RehashServer();
+
+       virtual long GetChannelCount();
+
+       virtual chanrec* GetChannelIndex(long index);
 };