]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules.h
Changed to using LogLevels
[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         virtual void Module::OnPacketTransmit(char *p);
96         virtual void Module::OnPacketReceive(char *p);
97         virtual void OnRehash();
98
99 };
100
101
102 /** Allows server output and query functions
103  * This class contains methods which allow a module to query the state of the irc server, and produce
104  * output to users and other servers. All modules should instantiate at least one copy of this class,
105  * and use its member functions to perform their tasks.
106  */
107 class Server : public classbase
108 {
109  public:
110         /** Default constructor.
111          * Creates a Server object.
112          */
113         Server();
114         /** Default destructor.
115          * Destroys a Server object.
116          */
117         virtual ~Server();
118
119         /** Sends text to all opers.
120          * This method sends a server notice to all opers with the usermode +s.
121          */
122         virtual void SendOpers(string s);
123         /** Writes a log string.
124          * This method writes a line of text to the log. If the level given is lower than the
125          * level given in the configuration, this command has no effect.
126          */
127         virtual void Log(int level, string s);
128         /** Sends a line of text down a TCP/IP socket.
129          * This method writes a line of text to an established socket, cutting it to 510 characters
130          * plus a carriage return and linefeed if required.
131          */
132         virtual void Send(int Socket, string s);
133         /** Sends text from the server to a socket.
134          * This method writes a line of text to an established socket, with the servername prepended
135          * as used by numerics (see RFC 1459)
136          */
137         virtual void SendServ(int Socket, string s);
138         /** Sends text from a user to a socket.
139          * This method writes a line of text to an established socket, with the given user's nick/ident
140          * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459)
141          */
142         virtual void SendFrom(int Socket, userrec* User, string s);
143         /** Sends text from a user to another user.
144          * This method writes a line of text to a user, with a user's nick/ident
145          * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459)
146          */
147         virtual void SendTo(userrec* Source, userrec* Dest, string s);
148         /** Sends text from a user to a channel (mulicast).
149          * This method writes a line of text to a channel, with the given user's nick/ident
150          * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the
151          * IncludeSender flag is set, then the text is also sent back to the user from which
152          * it originated, as seen in MODE (see RFC 1459).
153          */
154         virtual void SendChannel(userrec* User, chanrec* Channel, string s,bool IncludeSender);
155         /** Returns true if two users share a common channel.
156          * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
157          * method.
158          */
159         virtual bool CommonChannels(userrec* u1, userrec* u2);
160         /** Sends text from a user to one or more channels (mulicast).
161          * This method writes a line of text to all users which share a common channel with a given     
162          * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc
163          * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent
164          * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it
165          * is only sent to the other recipients, as seen in QUIT.
166          */
167         virtual void SendCommon(userrec* User, string text,bool IncludeSender);
168         /** Sends a WALLOPS message.
169          * This method writes a WALLOPS message to all users with the +w flag, originating from the
170          * specified user.
171          */
172         virtual void SendWallops(userrec* User, string text);
173
174         /** Returns true if a nick is valid.
175          * Nicks for unregistered connections will return false.
176          */
177         virtual bool IsNick(string nick);
178         /** Attempts to look up a nick and return a pointer to it.
179          * This function will return NULL if the nick does not exist.
180          */
181         virtual userrec* FindNick(string nick);
182         /** Attempts to look up a channel and return a pointer to it.
183          * This function will return NULL if the channel does not exist.
184          */
185         virtual chanrec* FindChannel(string channel);
186         /** Attempts to look up a user's privilages on a channel.
187          * This function will return a string containing either @, %, +, or an empty string,
188          * representing the user's privilages upon the channel you specify.
189          */
190         virtual string ChanMode(userrec* User, chanrec* Chan);
191         /** Returns the server name of the server where the module is loaded.
192          */
193         virtual string GetServerName();
194         /** Returns the network name, global to all linked servers.
195          */
196         virtual string GetNetworkName();
197         /** Returns the information of the server as returned by the /ADMIN command.
198          * See the Admin class for further information of the return value. The members
199          * Admin::Nick, Admin::Email and Admin::Name contain the information for the
200          * server where the module is loaded.
201          */
202         virtual Admin GetAdmin();
203          
204 };
205
206 /** Allows reading of values from configuration files
207  * This class allows a module to read from either the main configuration file (inspircd.conf) or from
208  * a module-specified configuration file. It may either be instantiated with one parameter or none.
209  * Constructing the class using one parameter allows you to specify a path to your own configuration
210  * file, otherwise, inspircd.conf is read.
211  */
212 class ConfigReader : public classbase
213 {
214   protected:
215         /** The filename of the configuration file, as set by the constructor.
216          */
217         string fname;
218   public:
219         /** Default constructor.
220          * This constructor initialises the ConfigReader class to read the inspircd.conf file
221          * as specified when running ./configure.
222          */
223         ConfigReader();                 // default constructor reads ircd.conf
224         /** Overloaded constructor.
225          * This constructor initialises the ConfigReader class to read a user-specified config file
226          */
227         ConfigReader(string filename);  // read a module-specific config
228         /** Default destructor.
229          * This method destroys the ConfigReader class.
230          */
231         ~ConfigReader();
232         /** Retrieves a value from the config file.
233          * This method retrieves a value from the config file. Where multiple copies of the tag
234          * exist in the config file, index indicates which of the values to retrieve.
235          */
236         string ReadValue(string tag, string name, int index);
237         /** Counts the number of times a given tag appears in the config file.
238          * This method counts the number of times a tag appears in a config file, for use where
239          * there are several tags of the same kind, e.g. with opers and connect types. It can be
240          * used with the index value of ConfigReader::ReadValue to loop through all copies of a
241          * multiple instance tag.
242          */
243         int Enumerate(string tag);
244         /** Returns true if a config file is valid.
245          * This method is unimplemented and will always return true.
246          */
247         bool Verify();
248 };
249
250
251
252 /** Caches a text file into memory and can be used to retrieve lines from it.
253  * This class contains methods for read-only manipulation of a text file in memory.
254  * Either use the constructor type with one parameter to load a file into memory
255  * at construction, or use the LoadFile method to load a file.
256  */
257 class FileReader : public classbase
258 {
259  file_cache fc;
260  public:
261          /** Default constructor.
262           * This method does not load any file into memory, you must use the LoadFile method
263           * after constructing the class this way.
264           */
265          FileReader();
266          /** Secondary constructor.
267           * This method initialises the class with a file loaded into it ready for GetLine and
268           * and other methods to be called. If the file could not be loaded, FileReader::FileSize
269           * returns 0.
270           */
271          FileReader(string filename);
272          /** Default destructor.
273           * This deletes the memory allocated to the file.
274           */
275          ~FileReader();
276          /** Used to load a file.
277           * This method loads a file into the class ready for GetLine and
278           * and other methods to be called. If the file could not be loaded, FileReader::FileSize
279           * returns 0.
280           */
281          void LoadFile(string filename);
282          /** Retrieve one line from the file.
283           * This method retrieves one line from the text file. If an empty non-NULL string is returned,
284           * the index was out of bounds, or the line had no data on it.
285           */
286          string GetLine(int x);
287          /** Returns the size of the file in lines.
288           * This method returns the number of lines in the read file. If it is 0, no lines have been
289           * read into memory, either because the file is empty or it does not exist, or cannot be
290           * opened due to permission problems.
291           */
292          int FileSize();
293 };
294
295
296 /** Instantiates classes inherited from Module
297  * This class creates a class inherited from type Module, using new. This is to allow for modules
298  * to create many different variants of Module, dependent on architecture, configuration, etc.
299  * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
300  * modules.
301  */
302 class ModuleFactory : public classbase
303 {
304  public:
305         ModuleFactory() { }
306         virtual ~ModuleFactory() { }
307         /** Creates a new module.
308          * Your inherited class of ModuleFactory must return a pointer to your Module class
309          * using this method.
310          */
311         virtual Module * CreateModule() = 0;
312 };
313
314
315 typedef DLLFactory<ModuleFactory> ircd_module;
316
317 #endif