26 /** Low level definition of a FileReader classes file cache area
28 typedef std::deque<std::string> file_cache;
29 typedef file_cache string_list;
31 // This #define allows us to call a method in all
32 // loaded modules in a readable simple way, e.g.:
33 // 'FOREACH_MOD OnConnect(user);'
35 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
37 // class Version holds the version information of a Module, returned
38 // by Module::GetVersion (thanks RD)
40 /** Holds a module's Version information
41 * The four members (set by the constructor only) indicate details as to the version number
42 * of a module. A class of type Version is returned by the GetVersion method of the Module class.
44 class Version : public classbase
47 const int Major, Minor, Revision, Build;
48 Version(int major, int minor, int revision, int build);
52 * This class contains the admin details of the local server. It is constructed by class Server,
53 * and has three read-only values, Name, Email and Nick that contain the specified values for the
54 * server where the module is running.
56 class Admin : public classbase
59 const std::string Name, Email, Nick;
60 Admin(std::string name, std::string email, std::string nick);
63 /** Base class for all InspIRCd modules
64 * This class is the base class for InspIRCd modules. All modules must inherit from this class,
65 * its methods will be called when irc server events occur. class inherited from module must be
66 * instantiated by the ModuleFactory class (see relevent section) for the plugin to be initialised.
68 class Module : public classbase
72 /** Default constructor
73 * creates a module class
77 /** Default destructor
78 * destroys a module class
82 /** Returns the version number of a Module.
83 * The method should return a Version object with its version information assigned via
86 virtual Version GetVersion();
88 /** Called when a user connects.
89 * The details of the connecting user are available to you in the parameter userrec *user
91 virtual void OnUserConnect(userrec* user);
93 /** Called when a user quits.
94 * The details of the exiting user are available to you in the parameter userrec *user
96 virtual void OnUserQuit(userrec* user);
98 /** Called when a user joins a channel.
99 * The details of the joining user are available to you in the parameter userrec *user,
100 * and the details of the channel they have joined is available in the variable chanrec *channel
102 virtual void OnUserJoin(userrec* user, chanrec* channel);
104 /** Called when a user parts a channel.
105 * The details of the leaving user are available to you in the parameter userrec *user,
106 * and the details of the channel they have left is available in the variable chanrec *channel
108 virtual void OnUserPart(userrec* user, chanrec* channel);
110 /** Called before a packet is transmitted across the irc network between two irc servers.
111 * The packet is represented as a char*, as it should be regarded as a buffer, and not a string.
112 * This allows you to easily represent it in the correct ways to implement encryption, compression,
113 * digital signatures and anything else you may want to add. This should be regarded as a pre-processor
114 * and will be called before ANY other operations within the ircd core program.
116 virtual void Module::OnPacketTransmit(char *p);
118 /** Called after a packet is received from another irc server.
119 * The packet is represented as a char*, as it should be regarded as a buffer, and not a string.
120 * This allows you to easily represent it in the correct ways to implement encryption, compression,
121 * digital signatures and anything else you may want to add. This should be regarded as a pre-processor
122 * and will be called immediately after the packet is received but before any other operations with the
125 virtual void Module::OnPacketReceive(char *p);
127 /** Called on rehash.
128 * This method is called prior to a /REHASH or when a SIGHUP is received from the operating
129 * system. You should use it to reload any files so that your module keeps in step with the
130 * rest of the application.
132 virtual void OnRehash();
134 /** Called when a raw command is transmitted or received.
135 * This method is the lowest level of handler available to a module. It will be called with raw
136 * data which is passing through a connected socket. If you wish, you may munge this data by changing
137 * the string parameter "raw". If you do this, after your function exits it will immediately be
138 * cut down to 510 characters plus a carriage return and linefeed.
140 virtual void OnServerRaw(std::string &raw, bool inbound);
142 /** Called whenever an extended mode is to be processed.
143 * The type parameter is MT_SERVER, MT_CLIENT or MT_CHANNEL, dependent on where the mode is being
144 * changed. mode_on is set when the mode is being set, in which case params contains a list of
145 * parameters for the mode as strings. If mode_on is false, the mode is being removed, and parameters
146 * may contain the parameters for the mode, dependent on wether they were defined when a mode handler
147 * was set up with Server::AddExtendedMode
148 * If the mode is not a channel mode, chanrec* chan is null, and should not be read from or written to.
150 virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list ¶ms);
155 /** Allows server output and query functions
156 * This class contains methods which allow a module to query the state of the irc server, and produce
157 * output to users and other servers. All modules should instantiate at least one copy of this class,
158 * and use its member functions to perform their tasks.
160 class Server : public classbase
163 /** Default constructor.
164 * Creates a Server object.
167 /** Default destructor.
168 * Destroys a Server object.
172 /** Sends text to all opers.
173 * This method sends a server notice to all opers with the usermode +s.
175 virtual void SendOpers(std::string s);
176 /** Writes a log string.
177 * This method writes a line of text to the log. If the level given is lower than the
178 * level given in the configuration, this command has no effect.
180 virtual void Log(int level, std::string s);
181 /** Sends a line of text down a TCP/IP socket.
182 * This method writes a line of text to an established socket, cutting it to 510 characters
183 * plus a carriage return and linefeed if required.
185 virtual void Send(int Socket, std::string s);
186 /** Sends text from the server to a socket.
187 * This method writes a line of text to an established socket, with the servername prepended
188 * as used by numerics (see RFC 1459)
190 virtual void SendServ(int Socket, std::string s);
191 /** Sends text from a user to a socket.
192 * This method writes a line of text to an established socket, with the given user's nick/ident
193 * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459)
195 virtual void SendFrom(int Socket, userrec* User, std::string s);
196 /** Sends text from a user to another user.
197 * This method writes a line of text to a user, with a user's nick/ident
198 * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459)
200 virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
201 /** Sends text from a user to a channel (mulicast).
202 * This method writes a line of text to a channel, with the given user's nick/ident
203 * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the
204 * IncludeSender flag is set, then the text is also sent back to the user from which
205 * it originated, as seen in MODE (see RFC 1459).
207 virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
208 /** Returns true if two users share a common channel.
209 * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
212 virtual bool CommonChannels(userrec* u1, userrec* u2);
213 /** Sends text from a user to one or more channels (mulicast).
214 * This method writes a line of text to all users which share a common channel with a given
215 * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc
216 * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent
217 * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it
218 * is only sent to the other recipients, as seen in QUIT.
220 virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
221 /** Sends a WALLOPS message.
222 * This method writes a WALLOPS message to all users with the +w flag, originating from the
225 virtual void SendWallops(userrec* User, std::string text);
227 /** Returns true if a nick is valid.
228 * Nicks for unregistered connections will return false.
230 virtual bool IsNick(std::string nick);
231 /** Attempts to look up a nick and return a pointer to it.
232 * This function will return NULL if the nick does not exist.
234 virtual userrec* FindNick(std::string nick);
235 /** Attempts to look up a channel and return a pointer to it.
236 * This function will return NULL if the channel does not exist.
238 virtual chanrec* FindChannel(std::string channel);
239 /** Attempts to look up a user's privilages on a channel.
240 * This function will return a string containing either @, %, +, or an empty string,
241 * representing the user's privilages upon the channel you specify.
243 virtual std::string ChanMode(userrec* User, chanrec* Chan);
244 /** Returns the server name of the server where the module is loaded.
246 virtual std::string GetServerName();
247 /** Returns the network name, global to all linked servers.
249 virtual std::string GetNetworkName();
250 /** Returns the information of the server as returned by the /ADMIN command.
251 * See the Admin class for further information of the return value. The members
252 * Admin::Nick, Admin::Email and Admin::Name contain the information for the
253 * server where the module is loaded.
255 virtual Admin GetAdmin();
256 /** Adds an extended mode letter which is parsed by a module
257 * This allows modules to add extra mode letters, e.g. +x for hostcloak.
258 * the "type" parameter is either MT_CHANNEL, MT_CLIENT, or MT_SERVER, to
259 * indicate wether the mode is a channel mode, a client mode, or a server mode.
260 * default_on is true if the mode is to be applied to default connections.
261 * params_when_on is the number of modes to expect when the mode is turned on
262 * (for type MT_CHANNEL only), e.g. with mode +b, this would have a value of 1.
263 * the params_when_off value has a similar value to params_when_on, except it indicates
264 * the number of parameters to expect when the mode is disabled. Modes which act in a similar
265 * way to channel mode +l (e.g. require a parameter to enable, but not to disable) should
266 * use this parameter. The function returns false if the mode is unavailable, and will not
267 * attempt to allocate another character, as this will confuse users. This also means that
268 * as only one module can claim a specific mode character, the core does not need to keep track
269 * of which modules own which modes, which speeds up operation of the server. In this version,
270 * a mode can have at most one parameter, attempting to use more parameters will have undefined
273 virtual bool AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off);
277 /** Allows reading of values from configuration files
278 * This class allows a module to read from either the main configuration file (inspircd.conf) or from
279 * a module-specified configuration file. It may either be instantiated with one parameter or none.
280 * Constructing the class using one parameter allows you to specify a path to your own configuration
281 * file, otherwise, inspircd.conf is read.
283 class ConfigReader : public classbase
286 /** The filename of the configuration file, as set by the constructor.
290 /** Default constructor.
291 * This constructor initialises the ConfigReader class to read the inspircd.conf file
292 * as specified when running ./configure.
294 ConfigReader(); // default constructor reads ircd.conf
295 /** Overloaded constructor.
296 * This constructor initialises the ConfigReader class to read a user-specified config file
298 ConfigReader(std::string filename); // read a module-specific config
299 /** Default destructor.
300 * This method destroys the ConfigReader class.
303 /** Retrieves a value from the config file.
304 * This method retrieves a value from the config file. Where multiple copies of the tag
305 * exist in the config file, index indicates which of the values to retrieve.
307 std::string ReadValue(std::string tag, std::string name, int index);
308 /** Counts the number of times a given tag appears in the config file.
309 * This method counts the number of times a tag appears in a config file, for use where
310 * there are several tags of the same kind, e.g. with opers and connect types. It can be
311 * used with the index value of ConfigReader::ReadValue to loop through all copies of a
312 * multiple instance tag.
314 int Enumerate(std::string tag);
315 /** Returns true if a config file is valid.
316 * This method is unimplemented and will always return true.
323 /** Caches a text file into memory and can be used to retrieve lines from it.
324 * This class contains methods for read-only manipulation of a text file in memory.
325 * Either use the constructor type with one parameter to load a file into memory
326 * at construction, or use the LoadFile method to load a file.
328 class FileReader : public classbase
332 /** Default constructor.
333 * This method does not load any file into memory, you must use the LoadFile method
334 * after constructing the class this way.
337 /** Secondary constructor.
338 * This method initialises the class with a file loaded into it ready for GetLine and
339 * and other methods to be called. If the file could not be loaded, FileReader::FileSize
342 FileReader(std::string filename);
343 /** Default destructor.
344 * This deletes the memory allocated to the file.
347 /** Used to load a file.
348 * This method loads a file into the class ready for GetLine and
349 * and other methods to be called. If the file could not be loaded, FileReader::FileSize
352 void LoadFile(std::string filename);
353 /** Retrieve one line from the file.
354 * This method retrieves one line from the text file. If an empty non-NULL string is returned,
355 * the index was out of bounds, or the line had no data on it.
357 std::string GetLine(int x);
358 /** Returns the size of the file in lines.
359 * This method returns the number of lines in the read file. If it is 0, no lines have been
360 * read into memory, either because the file is empty or it does not exist, or cannot be
361 * opened due to permission problems.
367 /** Instantiates classes inherited from Module
368 * This class creates a class inherited from type Module, using new. This is to allow for modules
369 * to create many different variants of Module, dependent on architecture, configuration, etc.
370 * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
373 class ModuleFactory : public classbase
377 virtual ~ModuleFactory() { }
378 /** Creates a new module.
379 * Your inherited class of ModuleFactory must return a pointer to your Module class
382 virtual Module * CreateModule() = 0;
386 typedef DLLFactory<ModuleFactory> ircd_module;