]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules.h
Fixed paths and makefile locations
[user/henk/code/inspircd.git] / include / modules.h
1 /*
2
3 $Log$
4 Revision 1.1  2003/01/23 19:45:58  brain
5 Initial revision
6
7 Revision 1.12  2003/01/22 20:59:10  brain
8 Added FileReader class documentation
9
10 Revision 1.11  2003/01/22 20:49:16  brain
11 Added FileReader file-caching class
12 Changed m_randquote to use FileReader class
13
14 Revision 1.10  2003/01/22 00:57:27  brain
15 Changes to documentation
16
17 Revision 1.9  2003/01/22 00:44:26  brain
18 Added documentation comments
19
20 Revision 1.8  2003/01/21 20:31:24  brain
21 Modified to add documentation
22 Added ConfigReader class for modules
23
24 Revision 1.7  2003/01/15 22:47:44  brain
25 Changed user and channel structs to classes (finally)
26
27 Revision 1.6  2003/01/13 22:30:50  brain
28 Added Admin class (holds /admin info for modules)
29 Added methods to Server class
30
31
32 */
33
34
35 #ifndef __PLUGIN_H
36 #define __PLUGIN_H
37
38 #include "dynamic.h"
39 #include <string>
40 #include <deque>
41
42 /** Low level definition of a FileReader classes file cache area
43  */
44 typedef deque<string> file_cache;
45
46
47 // This #define allows us to call a method in all
48 // loaded modules in a readable simple way, e.g.:
49 // 'FOREACH_MOD OnConnect(user);'
50
51 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
52
53 // class Version holds the version information of a Module, returned
54 // by Module::GetVersion (thanks RD)
55
56 /** Holds a module's Version information
57  *  The four members (set by the constructor only) indicate details as to the version number
58  *  of a module. A class of type Version is returned by the GetVersion method of the Module class.
59  */
60 class Version
61 {
62  public:
63          const int Major, Minor, Revision, Build;
64          Version(int major, int minor, int revision, int build);
65 };
66
67
68 /** Holds /ADMIN data
69  *  This class contains the admin details of the local server. It is constructed by class Server,
70  *  and has three read-only values, Name, Email and Nick that contain the specified values for the
71  *  server where the module is running.
72  */
73 class Admin
74 {
75  public:
76          const string Name, Email, Nick;
77          Admin(string name,string email,string nick);
78 };
79
80 /** Base class for all InspIRCd modules
81  *  This class is the base class for InspIRCd modules. All modules must inherit from this class,
82  *  its methods will be called when irc server events occur. class inherited from module must be
83  *  instantiated by the ModuleFactory class (see relevent section) for the plugin to be initialised.
84  */
85 class Module
86 {
87  public:
88         /** Default constructor
89          * creates a module class
90          */
91         Module();
92         /** Default destructor
93          * destroys a module class
94          */
95         virtual ~Module();
96         /** Returns the version number of a Module.
97          * The method should return a Version object with its version information assigned via
98          * Version::Version
99          */
100         virtual Version GetVersion();
101         /** Called when a user connects.
102          * The details of the connecting user are available to you in the parameter userrec *user
103          */
104         virtual void OnUserConnect(userrec* user);
105         /** Called when a user quits.
106          * The details of the exiting user are available to you in the parameter userrec *user
107          */
108         virtual void OnUserQuit(userrec* user);
109         /** Called when a user joins a channel.
110          * The details of the joining user are available to you in the parameter userrec *user,
111          * and the details of the channel they have joined is available in the variable chanrec *channel
112          */
113         virtual void OnUserJoin(userrec* user, chanrec* channel);
114         /** Called when a user parts a channel.
115          * The details of the leaving user are available to you in the parameter userrec *user,
116          * and the details of the channel they have left is available in the variable chanrec *channel
117          */
118         virtual void OnUserPart(userrec* user, chanrec* channel);
119 };
120
121
122 /** Allows server output and query functions
123  * This class contains methods which allow a module to query the state of the irc server, and produce
124  * output to users and other servers. All modules should instantiate at least one copy of this class,
125  * and use its member functions to perform their tasks.
126  */
127 class Server
128 {
129  public:
130         /** Default constructor.
131          * Creates a Server object.
132          */
133         Server();
134         /** Default destructor.
135          * Destroys a Server object.
136          */
137         virtual ~Server();
138
139         /** Sends text to all opers.
140          * This method sends a server notice to all opers with the usermode +s.
141          */
142         virtual void SendOpers(string s);
143         /** Sends a debug string.
144          * This method writes a line of text to the debug log. If debugging is disabled
145          * in the configuration, this command has no effect.
146          */
147         virtual void Debug(string s);
148         /** Sends a line of text down a TCP/IP socket.
149          * This method writes a line of text to an established socket, cutting it to 510 characters
150          * plus a carriage return and linefeed if required.
151          */
152         virtual void Send(int Socket, string s);
153         /** Sends text from the server to a socket.
154          * This method writes a line of text to an established socket, with the servername prepended
155          * as used by numerics (see RFC 1459)
156          */
157         virtual void SendServ(int Socket, string s);
158         /** Sends text from a user to a socket.
159          * This method writes a line of text to an established socket, with the given user's nick/ident
160          * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459)
161          */
162         virtual void SendFrom(int Socket, userrec* User, string s);
163         /** Sends text from a user to another user.
164          * This method writes a line of text to a user, with a user's nick/ident
165          * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459)
166          */
167         virtual void SendTo(userrec* Source, userrec* Dest, string s);
168         /** Sends text from a user to a channel (mulicast).
169          * This method writes a line of text to a channel, with the given user's nick/ident
170          * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the
171          * IncludeSender flag is set, then the text is also sent back to the user from which
172          * it originated, as seen in MODE (see RFC 1459).
173          */
174         virtual void SendChannel(userrec* User, chanrec* Channel, string s,bool IncludeSender);
175         /** Returns true if two users share a common channel.
176          * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
177          * method.
178          */
179         virtual bool CommonChannels(userrec* u1, userrec* u2);
180         /** Sends text from a user to one or more channels (mulicast).
181          * This method writes a line of text to all users which share a common channel with a given     
182          * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc
183          * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent
184          * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it
185          * is only sent to the other recipients, as seen in QUIT.
186          */
187         virtual void SendCommon(userrec* User, string text,bool IncludeSender);
188         /** Sends a WALLOPS message.
189          * This method writes a WALLOPS message to all users with the +w flag, originating from the
190          * specified user.
191          */
192         virtual void SendWallops(userrec* User, string text);
193
194         /** Returns true if a nick is valid.
195          * Nicks for unregistered connections will return false.
196          */
197         virtual bool IsNick(string nick);
198         /** Attempts to look up a nick and return a pointer to it.
199          * This function will return NULL if the nick does not exist.
200          */
201         virtual userrec* FindNick(string nick);
202         /** Attempts to look up a channel and return a pointer to it.
203          * This function will return NULL if the channel does not exist.
204          */
205         virtual chanrec* FindChannel(string channel);
206         /** Attempts to look up a user's privilages on a channel.
207          * This function will return a string containing either @, %, +, or an empty string,
208          * representing the user's privilages upon the channel you specify.
209          */
210         virtual string ChanMode(userrec* User, chanrec* Chan);
211         /** Returns the server name of the server where the module is loaded.
212          */
213         virtual string GetServerName();
214         /** Returns the network name, global to all linked servers.
215          */
216         virtual string GetNetworkName();
217         /** Returns the information of the server as returned by the /ADMIN command.
218          * See the Admin class for further information of the return value. The members
219          * Admin::Nick, Admin::Email and Admin::Name contain the information for the
220          * server where the module is loaded.
221          */
222         virtual Admin GetAdmin();
223          
224 };
225
226 /** Allows reading of values from configuration files
227  * This class allows a module to read from either the main configuration file (inspircd.conf) or from
228  * a module-specified configuration file. It may either be instantiated with one parameter or none.
229  * Constructing the class using one parameter allows you to specify a path to your own configuration
230  * file, otherwise, inspircd.conf is read.
231  */
232 class ConfigReader
233 {
234   protected:
235         /** The filename of the configuration file, as set by the constructor.
236          */
237         string fname;
238   public:
239         /** Default constructor.
240          * This constructor initialises the ConfigReader class to read the inspircd.conf file
241          * as specified when running ./configure.
242          */
243         ConfigReader();                 // default constructor reads ircd.conf
244         /** Overloaded constructor.
245          * This constructor initialises the ConfigReader class to read a user-specified config file
246          */
247         ConfigReader(string filename);  // read a module-specific config
248         /** Default destructor.
249          * This method destroys the ConfigReader class.
250          */
251         ~ConfigReader();
252         /** Retrieves a value from the config file.
253          * This method retrieves a value from the config file. Where multiple copies of the tag
254          * exist in the config file, index indicates which of the values to retrieve.
255          */
256         string ReadValue(string tag, string name, int index);
257         /** Counts the number of times a given tag appears in the config file.
258          * This method counts the number of times a tag appears in a config file, for use where
259          * there are several tags of the same kind, e.g. with opers and connect types. It can be
260          * used with the index value of ConfigReader::ReadValue to loop through all copies of a
261          * multiple instance tag.
262          */
263         int Enumerate(string tag);
264         /** Returns true if a config file is valid.
265          * This method is unimplemented and will always return true.
266          */
267         bool Verify();
268 };
269
270
271
272 /** Caches a text file into memory and can be used to retrieve lines from it.
273  * This class contains methods for read-only manipulation of a text file in memory.
274  * Either use the constructor type with one parameter to load a file into memory
275  * at construction, or use the LoadFile method to load a file.
276  */
277 class FileReader
278 {
279  file_cache fc;
280  public:
281          /** Default constructor.
282           * This method does not load any file into memory, you must use the LoadFile method
283           * after constructing the class this way.
284           */
285          FileReader();
286          /** Secondary constructor.
287           * This method initialises the class with a file loaded into it ready for GetLine and
288           * and other methods to be called. If the file could not be loaded, FileReader::FileSize
289           * returns 0.
290           */
291          FileReader(string filename);
292          /** Default destructor.
293           * This deletes the memory allocated to the file.
294           */
295          ~FileReader();
296          /** Used to load a file.
297           * This method loads a file into the class ready for GetLine and
298           * and other methods to be called. If the file could not be loaded, FileReader::FileSize
299           * returns 0.
300           */
301          void LoadFile(string filename);
302          /** Retrieve one line from the file.
303           * This method retrieves one line from the text file. If an empty non-NULL string is returned,
304           * the index was out of bounds, or the line had no data on it.
305           */
306          string GetLine(int x);
307          /** Returns the size of the file in lines.
308           * This method returns the number of lines in the read file. If it is 0, no lines have been
309           * read into memory, either because the file is empty or it does not exist, or cannot be
310           * opened due to permission problems.
311           */
312          int FileSize();
313 };
314
315
316 /** Instantiates classes inherited from Module
317  * This class creates a class inherited from type Module, using new. This is to allow for modules
318  * to create many different variants of Module, dependent on architecture, configuration, etc.
319  * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
320  * modules.
321  */
322 class ModuleFactory
323 {
324  public:
325         ModuleFactory() { }
326         virtual ~ModuleFactory() { }
327         /** Creates a new module.
328          * Your inherited class of ModuleFactory must return a pointer to your Module class
329          * using this method.
330          */
331         virtual Module * CreateModule() = 0;
332 };
333
334 #endif