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