X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules.h;h=56bf2d18f57b25b01882cb1a63280c1f5c5582f8;hb=7907a1f1cc78ca532547c824cd221060b57f4fff;hp=5939ba0bbae07cf8059c1a8b97b4b88795af47ad;hpb=cdaf7ac3781a0ea1bfbfac85c4a428ddea7725f9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index 5939ba0bb..56bf2d18f 100644 --- a/include/modules.h +++ b/include/modules.h @@ -60,7 +60,8 @@ enum WriteModeFlags { enum TargetTypeFlags { TYPE_USER = 1, TYPE_CHANNEL, - TYPE_SERVER + TYPE_SERVER, + TYPE_OTHER }; #include "dynamic.h" @@ -92,7 +93,14 @@ typedef std::deque 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 +114,17 @@ typedef std::deque 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,12 +283,48 @@ 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() + */ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }; +/** Implementation-specific flags which may be set in Module::Implements() + */ 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, @@ -285,7 +336,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, @@ -299,6 +350,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); @@ -313,8 +365,39 @@ class Module : public classbase */ virtual Version GetVersion(); + /** The Implements function specifies which methods a module should receive events for. + * The char* parameter passed to this function contains a set of true or false values + * (1 or 0) which indicate wether each function is implemented. You must use the Iimplementation + * enum (documented elsewhere on this page) to mark functions as active. For example, to + * receive events for OnUserJoin(): + * + * Implements[I_OnUserJoin] = 1; + * + * @param The implement list + */ virtual void Implements(char* Implements); + /** Used to set the 'priority' of a module (e.g. when it is called in relation to other modules. + * Some modules prefer to be called before other modules, due to their design. For example, a + * module which is expected to operate on complete information would expect to be placed last, so + * that any other modules which wish to adjust that information would execute before it, to be sure + * its information is correct. You can change your module's priority by returning one of: + * + * PRIORITY_FIRST - To place your module first in the list + * + * PRIORITY_LAST - To place your module last in the list + * + * PRIORITY_DONTCARE - To leave your module as it is (this is the default value, if you do not implement this function) + * + * The result of Server::PriorityBefore() - To move your module before another named module + * + * The result of Server::PriorityLast() - To move your module after another named module + * + * For a good working example of this method call, please see src/modules/m_spanningtree.cpp + * and src/modules/m_hostchange.so which make use of it. It is highly recommended that unless + * your module has a real need to reorder its priority, it should not implement this function, + * as many modules changing their priorities can make the system redundant. + */ virtual Priority Prioritize(); /** Called when a user connects. @@ -427,7 +510,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); @@ -448,6 +531,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 @@ -500,9 +592,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 @@ -518,9 +611,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 @@ -541,8 +635,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* @@ -551,8 +646,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* @@ -632,6 +728,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 @@ -1139,6 +1246,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); }; @@ -1154,10 +1265,12 @@ class Server : public classbase * Creates a Server object. */ Server(); + /** Default destructor. * 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. @@ -1167,7 +1280,8 @@ class Server : public classbase /** For use with Module::Prioritize(). * When the return value of this function is returned from * Module::Prioritize(), this specifies that the module wishes - * to be ordered exactly BEFORE 'modulename'. + * to be ordered exactly BEFORE 'modulename'. For more information + * please see Module::Prioritize(). * @param modulename The module your module wants to be before in the call list * @returns a priority ID which the core uses to relocate the module in the list */ @@ -1176,7 +1290,8 @@ class Server : public classbase /** For use with Module::Prioritize(). * When the return value of this function is returned from * Module::Prioritize(), this specifies that the module wishes - * to be ordered exactly AFTER 'modulename'. + * to be ordered exactly AFTER 'modulename'. For more information please + * see Module::Prioritize(). * @param modulename The module your module wants to be after in the call list * @returns a priority ID which the core uses to relocate the module in the list */ @@ -1186,33 +1301,40 @@ class Server : public classbase * 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. */ virtual void Log(int level, std::string s); + /** Sends a line of text down a TCP/IP socket. * This method writes a line of text to an established socket, cutting it to 510 characters * plus a carriage return and linefeed if required. */ virtual void Send(int Socket, std::string s); + /** Sends text from the server to a socket. * This method writes a line of text to an established socket, with the servername prepended * as used by numerics (see RFC 1459) */ virtual void SendServ(int Socket, std::string s); + /** Writes text to a channel, but from a server, including all. * This can be used to send server notices to a group of users. */ virtual void SendChannelServerNotice(std::string ServName, chanrec* Channel, std::string text); + /** Sends text from a user to a socket. * This method writes a line of text to an established socket, with the given user's nick/ident * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459) */ virtual void SendFrom(int Socket, userrec* User, std::string s); + /** Sends text from a user to another user. * This method writes a line of text to a user, with a user's nick/ident * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459) @@ -1228,6 +1350,7 @@ class Server : public classbase * Which is useful for numerics and server notices to single users, etc. */ virtual void SendTo(userrec* Source, userrec* Dest, std::string s); + /** Sends text from a user to a channel (mulicast). * This method writes a line of text to a channel, with the given user's nick/ident * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the @@ -1235,11 +1358,13 @@ class Server : public classbase * it originated, as seen in MODE (see RFC 1459). */ virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender); + /** Returns true if two users share a common channel. * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon * method. */ virtual bool CommonChannels(userrec* u1, userrec* u2); + /** Sends text from a user to one or more channels (mulicast). * This method writes a line of text to all users which share a common channel with a given * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc @@ -1248,6 +1373,7 @@ class Server : public classbase * is only sent to the other recipients, as seen in QUIT. */ virtual void SendCommon(userrec* User, std::string text,bool IncludeSender); + /** Sends a WALLOPS message. * This method writes a WALLOPS message to all users with the +w flag, originating from the * specified user. @@ -1258,46 +1384,61 @@ class Server : public classbase * Nicks for unregistered connections will return false. */ virtual bool IsNick(std::string nick); + /** Returns a count of the number of users on a channel. * This will NEVER be 0, as if the chanrec exists, it will have at least one user in the channel. */ 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. */ virtual userrec* FindNick(std::string nick); + /** Attempts to look up a nick using the file descriptor associated with that nick. * This function will return NULL if the file descriptor is not associated with a valid user. */ virtual userrec* FindDescriptor(int socket); + /** Attempts to look up a channel and return a pointer to it. * This function will return NULL if the channel does not exist. */ virtual chanrec* FindChannel(std::string channel); + /** Attempts to look up a user's privilages on a channel. * This function will return a string containing either @, %, +, or an empty string, * representing the user's privilages upon the channel you specify. */ virtual std::string ChanMode(userrec* User, chanrec* Chan); + /** Checks if a user is on a channel. * This function will return true or false to indicate if user 'User' is on channel 'Chan'. */ virtual bool IsOnChannel(userrec* User, chanrec* Chan); + /** Returns the server name of the server where the module is loaded. */ virtual std::string GetServerName(); + /** Returns the network name, global to all linked servers. */ virtual std::string GetNetworkName(); + /** Returns the server description string of the local server */ virtual std::string GetServerDescription(); + /** Returns the information of the server as returned by the /ADMIN command. * See the Admin class for further information of the return value. The members * Admin::Nick, Admin::Email and Admin::Name contain the information for the * server where the module is loaded. */ virtual Admin GetAdmin(); + /** Adds an extended mode letter which is parsed by a module. * 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 @@ -1430,6 +1571,13 @@ class Server : public classbase */ virtual void QuitUser(userrec* user, std::string reason); + /** Makes a user kick another user, with the specified reason. + * If source is NULL, the server will peform the kick. + * @param The person or server (if NULL) performing the KICK + * @param target The person being kicked + * @param chan The channel to kick from + * @param reason The kick reason + */ virtual void KickUser(userrec* source, userrec* target, chanrec* chan, std::string reason); /** Matches text against a glob pattern. @@ -1451,6 +1599,11 @@ class Server : public classbase */ virtual void 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 + * if the command is implemented by a module (not the core). This has a few specific uses, usually + * within network protocols (see src/modules/m_spanningtree.cpp) + */ virtual bool IsValidModuleCommand(std::string commandname, int pcnt, userrec* user); /** Change displayed hostname of a user. @@ -1470,10 +1623,7 @@ class Server : public classbase /** Returns true if the servername you give is ulined. * ULined servers have extra privilages. They are allowed to change nicknames on remote servers, * change modes of clients which are on remote servers and set modes of channels where there are - * no channel operators for that channel on the ulined server, amongst other things. Ulined server - * data is also broadcast across the mesh at all times as opposed to selectively messaged in the - * case of normal servers, as many ulined server types (such as services) do not support meshed - * links and must operate in this manner. + * no channel operators for that channel on the ulined server, amongst other things. */ virtual bool IsUlined(std::string server); @@ -1492,7 +1642,7 @@ class Server : public classbase /** This user takes one user, and switches their file descriptor with another user, so that one user * "becomes" the other. The user in 'alive' is booted off the server with the given message. The user - * referred to by 'zombie' should have previously been locked with Server::ZombifyUser, otherwise + * referred to by 'zombie' should have previously been locked with Server::UserToPseudo, otherwise * stale sockets and file descriptor leaks can occur. After this call, the pointer to alive will be * invalid, and the pointer to zombie will be equivalent in effect to the old pointer to alive. */ @@ -1543,15 +1693,15 @@ class Server : public classbase */ virtual void AddELine(long duration, std::string source, std::string reason, std::string hostmask); - /** Deletes a G-Line from all servers on the mesh + /** Deletes a G-Line from all servers */ virtual bool DelGLine(std::string hostmask); - /** Deletes a Q-Line from all servers on the mesh + /** Deletes a Q-Line from all servers */ virtual bool DelQLine(std::string nickname); - /** Deletes a Z-Line from all servers on the mesh + /** Deletes a Z-Line from all servers */ virtual bool DelZLine(std::string ipaddr); @@ -1593,6 +1743,10 @@ class Server : public classbase virtual void DelSocket(InspSocket* sock); virtual void RehashServer(); + + virtual long GetChannelCount(); + + virtual chanrec* GetChannelIndex(long index); };