#define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
+// 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,
+// and any modules after are ignored.
+
+// *********************************************************************************************
+
+#define FOREACH_RESULT(x) { MOD_RESULT = 0; \
+ for (int i = 0; i <= MODCOUNT; i++) { \
+ int res = modules[i]->x ; \
+ if (res) { \
+ MOD_RESULT = res; \
+ break; \
+ } \
+ } \
+ }
+
+// *********************************************************************************************
+
extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams);
extern void server_mode(char **parameters, int pcnt, userrec *user);
* digital signatures and anything else you may want to add. This should be regarded as a pre-processor
* and will be called before ANY other operations within the ircd core program.
*/
- virtual void Module::OnPacketTransmit(char *p);
+ virtual void OnPacketTransmit(char *p);
/** Called after a packet is received from another irc server.
* The packet is represented as a char*, as it should be regarded as a buffer, and not a string.
* and will be called immediately after the packet is received but before any other operations with the
* core of the ircd.
*/
- virtual void Module::OnPacketReceive(char *p);
+ virtual void OnPacketReceive(char *p);
/** Called on rehash.
* This method is called prior to a /REHASH or when a SIGHUP is received from the operating
* parameters for the mode as strings. If mode_on is false, the mode is being removed, and parameters
* may contain the parameters for the mode, dependent on wether they were defined when a mode handler
* was set up with Server::AddExtendedMode
- * If the mode is not a channel mode, chanrec* chan is null, and should not be read from or written to.
+ * If the mode is a channel mode, target is a chanrec*, and if it is a user mode, target is a userrec*.
+ * You must cast this value yourself to make use of it.
*/
- virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list ¶ms);
+ virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms);
-
+ /** 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
+ * 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.
+ *
+ * IMPORTANT NOTE!
+ *
+ * If the user joins a NEW channel which does not exist yet, OnUserPreJoin will be called BEFORE the channel
+ * record is created. This will cause chanrec* chan to be NULL. There is very little you can do in form of
+ * 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.
+ */
+ virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
+
+
+ /** Called whenever a user opers locally.
+ * The userrec will contain the oper mode 'o' as this function is called after any modifications
+ * are made to the user's structure by the core.
+ */
+ virtual void OnOper(userrec* user);
+
+ /** Called whenever a user types /INFO.
+ * The userrec will contain the information of the user who typed the command. Modules may use this
+ * method to output their own credits in /INFO (which is the ircd's version of an about box).
+ * 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
+ */
+ virtual void OnInfo(userrec* user);
+
+ /** Called whenever a /WHOIS is performed on a local user.
+ * The source parameter contains the details of the user who issued the WHOIS command, and
+ * the dest parameter contains the information of the user they are whoising.
+ */
+ virtual void Module::OnWhois(userrec* source, userrec* dest);
+
+ /** 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,
+ * notices etc. This is useful for modules which may want to filter or redirect messages.
+ * 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.
+ */
+ 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
+ * 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 or redirect messages.
+ * 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.
+ */
+ virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::String text);
};
* This allows modules to add extra mode letters, e.g. +x for hostcloak.
* the "type" parameter is either MT_CHANNEL, MT_CLIENT, or MT_SERVER, to
* indicate wether the mode is a channel mode, a client mode, or a server mode.
- * default_on is true if the mode is to be applied to default connections.
+ * requires_oper is used with MT_CLIENT type modes only to indicate the mode can only
+ * be set or unset by an oper. If this is used for MT_CHANNEL type modes it is ignored.
* params_when_on is the number of modes to expect when the mode is turned on
- * (for type MT_CHANNEL only), e.g. with mode +b, this would have a value of 1.
+ * (for type MT_CHANNEL only), e.g. with mode +k, this would have a value of 1.
* the params_when_off value has a similar value to params_when_on, except it indicates
* the number of parameters to expect when the mode is disabled. Modes which act in a similar
* way to channel mode +l (e.g. require a parameter to enable, but not to disable) should
* a mode can have at most one parameter, attempting to use more parameters will have undefined
* effects.
*/
- virtual bool AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off);
+ virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
/** Adds a command to the command table.
* This allows modules to add extra commands into the command table. You must place a function within your
*
* For example:
*
- * char modes[3][MAXBUF];
+ * char *modes[3];
+ *
* modes[0] = ChannelName;
+ *
* modes[1] = "+o";
+ *
* modes[2] = user->nick;
+ *
* Srv->SendMode(modes,3,user);
*
* The modes will originate from the server where the command was issued, however responses (e.g. numerics)
*/
virtual void SendMode(char **parameters, int pcnt, userrec *user);
+
+ /** Sends to all users matching a mode mask
+ * You must specify one or more usermodes as the first parameter. These can be RFC specified modes such as +i,
+ * or module provided modes, including ones provided by your own module.
+ * In the second parameter you must place a flag value which indicates wether the modes you have given will be
+ * logically ANDed or OR'ed. You may use one of either WM_AND or WM_OR.
+ * for example, if you were to use:
+ *
+ * Serv->SendToModeMask("xi", WM_OR, "m00");
+ *
+ * Then the text 'm00' will be sent to all users with EITHER mode x or i. Conversely if you used WM_AND, the
+ * user must have both modes set to receive the message.
+ */
+ virtual void SendToModeMask(std::string modes, int flags, std::string text);
+
+ /** Forces a user to join a channel.
+ * This is similar to svsjoin and can be used to implement redirection, etc.
+ * On success, the return value is a valid pointer to a chanrec* of the channel the user was joined to.
+ * On failure, the result is NULL.
+ */
+ virtual chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key);
+
+ /** Forces a user to part a channel.
+ * This is similar to svspart and can be used to implement redirection, etc.
+ * Although the return value of this function is a pointer to a channel record, the returned data is
+ * undefined and should not be read or written to. This behaviour may be changed in a future version.
+ */
+ virtual chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason);
+
+ /** Forces a user nickchange.
+ * This command works similarly to SVSNICK, and can be used to implement Q-lines etc.
+ * If you specify an invalid nickname, the nick change will be dropped and the target user will receive
+ * the error numeric for it.
+ */
+ virtual void ChangeUserNick(userrec* user, std::string nickname);
+
+ /** Forces a user to quit with the specified reason.
+ * To the user, it will appear as if they typed /QUIT themselves, except for the fact that this function
+ * may bypass the quit prefix specified in the config file.
+ *
+ * WARNING!
+ *
+ * Once you call this function, userrec* user will immediately become INVALID. You MUST NOT write to, or
+ * read from this pointer after calling the QuitUser method UNDER ANY CIRCUMSTANCES! The best course of
+ * action after calling this method is to immediately bail from your handler.
+ */
+ virtual void QuitUser(userrec* user, std::string reason);
};
/** Allows reading of values from configuration files