]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules.h
Removed unused check for valid channel name - if it's invalid, it won't exist in...
[user/henk/code/inspircd.git] / include / modules.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17
18 #ifndef __MODULES_H
19 #define __MODULES_H
20
21 /** log levels
22  */
23 enum DebugLevels { DEBUG, VERBOSE, DEFAULT, SPARSE, NONE };
24
25 /** Used with OnExtendedMode() method of modules
26  */
27 enum ModeTargetType { MT_CHANNEL, MT_CLIENT, MT_SERVER };
28
29 /** Used with OnAccessCheck() method of modules
30  */
31 enum AccessControlType {
32         ACR_DEFAULT,            // Do default action (act as if the module isnt even loaded)
33         ACR_DENY,               // deny the action
34         ACR_ALLOW,              // allow the action
35         AC_KICK,                // a user is being kicked
36         AC_DEOP,                // a user is being deopped
37         AC_OP,                  // a user is being opped
38         AC_VOICE,               // a user is being voiced
39         AC_DEVOICE,             // a user is being devoiced
40         AC_HALFOP,              // a user is being halfopped
41         AC_DEHALFOP,            // a user is being dehalfopped
42         AC_INVITE,              // a user is being invited
43         AC_GENERAL_MODE         // a channel mode is being changed
44 };
45
46 /** Used to define a set of behavior bits for a module
47  */
48 enum ModuleFlags {
49         VF_STATIC = 1,          // module is static, cannot be /unloadmodule'd
50         VF_VENDOR = 2,          // module is a vendor module (came in the original tarball, not 3rd party)
51         VF_SERVICEPROVIDER = 4, // module provides a service to other modules (can be a dependency)
52         VF_COMMON = 8           // module needs to be common on all servers in a network to link
53 };
54
55 enum WriteModeFlags {
56         WM_AND = 1,
57         WM_OR = 2
58 };
59
60 enum TargetTypeFlags {
61         TYPE_USER = 1,
62         TYPE_CHANNEL,
63         TYPE_SERVER,
64         TYPE_OTHER
65 };
66
67 #include "dynamic.h"
68 #include "base.h"
69 #include "ctables.h"
70 #include "socket.h"
71 #include <string>
72 #include <deque>
73 #include <sstream>
74 #include <typeinfo>
75 #include "timer.h"
76
77 class Server;
78 class ServerConfig;
79
80 /** Low level definition of a FileReader classes file cache area
81  */
82 typedef std::deque<std::string> file_cache;
83 typedef file_cache string_list;
84
85 /** Holds a list of users in a channel
86  */
87 typedef std::deque<userrec*> chanuserlist;
88
89
90 /**
91  * This #define allows us to call a method in all
92  * loaded modules in a readable simple way, e.g.:
93  * 'FOREACH_MOD(I_OnXonnwxr,OnConnect(user));'
94  */
95 #define FOREACH_MOD(y,x) if (Config->global_implementation[y] > 0) { \
96         for (int _i = 0; _i <= MODCOUNT; _i++) { \
97         if (Config->implement_lists[_i][y]) \
98                 try \
99                 { \
100                         modules[_i]->x ; \
101                 } \
102                 catch (ModuleException& modexcept) \
103                 { \
104                         log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
105                 } \
106         } \
107   }
108
109 /**
110  *  This define is similar to the one above but returns a result in MOD_RESULT.
111  * The first module to return a nonzero result is the value to be accepted,
112  * and any modules after are ignored.
113  */
114 #define FOREACH_RESULT(y,x) { if (Config->global_implementation[y] > 0) { \
115                         MOD_RESULT = 0; \
116                         for (int _i = 0; _i <= MODCOUNT; _i++) { \
117                         if (Config->implement_lists[_i][y]) {\
118                                 try \
119                                 { \
120                                         int res = modules[_i]->x ; \
121                                         if (res != 0) { \
122                                                 MOD_RESULT = res; \
123                                                 break; \
124                                         } \
125                                 } \
126                                 catch (ModuleException& modexcept) \
127                                 { \
128                                         log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
129                                 } \
130                         } \
131                 } \
132         } \
133  }
134
135 #define FD_MAGIC_NUMBER -42
136
137 // useful macros
138
139 #define IS_LOCAL(x) (x->fd > -1)
140 #define IS_REMOTE(x) (x->fd < 0)
141 #define IS_MODULE_CREATED(x) (x->fd == FD_MAGIC_NUMBER)
142
143 /** Holds a module's Version information
144  *  The four members (set by the constructor only) indicate details as to the version number
145  *  of a module. A class of type Version is returned by the GetVersion method of the Module class.
146  */
147 class Version : public classbase
148 {
149  public:
150          const int Major, Minor, Revision, Build, Flags;
151          Version(int major, int minor, int revision, int build, int flags);
152 };
153
154 /** Holds /ADMIN data
155  *  This class contains the admin details of the local server. It is constructed by class Server,
156  *  and has three read-only values, Name, Email and Nick that contain the specified values for the
157  *  server where the module is running.
158  */
159 class Admin : public classbase
160 {
161  public:
162          const std::string Name, Email, Nick;
163          Admin(std::string name, std::string email, std::string nick);
164 };
165
166 // Forward-delacare module for ModuleMessage etc
167 class Module;
168
169 /** The ModuleMessage class is the base class of Request and Event
170  * This class is used to represent a basic data structure which is passed
171  * between modules for safe inter-module communications.
172  */
173 class ModuleMessage : public classbase
174 {
175  public:
176         /** This class is pure virtual and must be inherited.
177          */
178         virtual char* Send() = 0;
179         virtual ~ModuleMessage() {};
180 };
181
182 /** The Request class is a unicast message directed at a given module.
183  * When this class is properly instantiated it may be sent to a module
184  * using the Send() method, which will call the given module's OnRequest
185  * method with this class as its parameter.
186  */
187 class Request : public ModuleMessage
188 {
189  protected:
190         /** This member holds a pointer to arbitary data set by the emitter of the message
191          */
192         char* data;
193         /** This is a pointer to the sender of the message, which can be used to
194          * directly trigger events, or to create a reply.
195          */
196         Module* source;
197         /** The single destination of the Request
198          */
199         Module* dest;
200  public:
201         /** Create a new Request
202          */
203         Request(char* anydata, Module* src, Module* dst);
204         /** Fetch the Request data
205          */
206         char* GetData();
207         /** Fetch the request source
208          */
209         Module* GetSource();
210         /** Fetch the request destination (should be 'this' in the receiving module)
211          */
212         Module* GetDest();
213         /** Send the Request.
214          * Upon returning the result will be arbitary data returned by the module you
215          * sent the request to. It is up to your module to know what this data is and
216          * how to deal with it.
217          */
218         char* Send();
219 };
220
221
222 /** The Event class is a unicast message directed at all modules.
223  * When the class is properly instantiated it may be sent to all modules
224  * using the Send() method, which will trigger the OnEvent method in
225  * all modules passing the object as its parameter.
226  */
227 class Event : public ModuleMessage
228 {
229  protected:
230         /** This member holds a pointer to arbitary data set by the emitter of the message
231          */
232         char* data;
233         /** This is a pointer to the sender of the message, which can be used to
234          * directly trigger events, or to create a reply.
235          */
236         Module* source;
237         /** The event identifier.
238          * This is arbitary text which should be used to distinguish
239          * one type of event from another.
240          */
241         std::string id;
242  public:
243         /** Create a new Event
244          */
245         Event(char* anydata, Module* src, const std::string &eventid);
246         /** Get the Event data
247          */
248         char* GetData();
249         /** Get the event Source
250          */
251         Module* GetSource();
252         /** Get the event ID.
253          * Use this to determine the event type for safe casting of the data
254          */
255         std::string GetEventID();
256         /** Send the Event.
257          * The return result of an Event::Send() will always be NULL as
258          * no replies are expected.
259          */
260         char* Send();
261 };
262
263 /** Holds an extended mode's details.
264  * Used internally by modules.cpp
265  */
266 class ExtMode : public classbase
267 {
268  public:
269         char modechar;
270         int type;
271         bool needsoper;
272         int params_when_on;
273         int params_when_off;
274         bool list;
275         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) { };
276 };
277
278
279 /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
280  * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or
281  * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not
282  * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
283  * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
284  */
285 class ModuleException
286 {
287  private:
288         /** Holds the error message to be displayed
289          */
290         std::string err;
291  public:
292         /** Default constructor, just uses the error mesage 'Module threw an exception'.
293          */
294         ModuleException() : err("Module threw an exception") {}
295         /** This constructor can be used to specify an error message before throwing.
296          */
297         ModuleException(std::string message) : err(message) {}
298         /** This destructor solves world hunger, cancels the world debt, and causes the world to end.
299          * Actually no, it does nothing. Never mind.
300          */
301         virtual ~ModuleException() {};
302         /** Returns the reason for the exception.
303          * The module should probably put something informative here as the user will see this upon failure.
304          */
305         virtual const char* GetReason()
306         {
307                 return err.c_str();
308         }
309 };
310
311 /** Priority types which can be returned from Module::Prioritize()
312  */
313 enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
314
315 /** Implementation-specific flags which may be set in Module::Implements()
316  */
317 enum Implementation {   I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash, I_OnServerRaw, 
318                         I_OnExtendedMode, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois, I_OnUserPreInvite,
319                         I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreNick, I_OnUserMessage, I_OnUserNotice, I_OnMode,
320                         I_OnGetServerDescription, I_OnSyncUser, I_OnSyncChannel, I_OnSyncChannelMetaData, I_OnSyncUserMetaData,
321                         I_OnDecodeMetaData, I_ProtoSendMode, I_ProtoSendMetaData, I_OnWallops, I_OnChangeHost, I_OnChangeName, I_OnAddGLine,
322                         I_OnAddZLine, I_OnAddQLine, I_OnAddKLine, I_OnAddELine, I_OnDelGLine, I_OnDelZLine, I_OnDelKLine, I_OnDelELine, I_OnDelQLine,
323                         I_OnCleanup, I_OnUserPostNick, I_OnAccessCheck, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule, I_OnUnloadModule,
324                         I_OnBackgroundTimer, I_OnSendList, I_OnPreCommand, I_OnCheckReady, I_OnUserRrgister, I_OnRawMode, I_OnCheckInvite,
325                         I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, I_OnLocalTopicChange,
326                         I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnGlobalConnect, I_OnAddBan, I_OnDelBan,
327                         I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
328                         I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway };
329
330 /** Base class for all InspIRCd modules
331  *  This class is the base class for InspIRCd modules. All modules must inherit from this class,
332  *  its methods will be called when irc server events occur. class inherited from module must be
333  *  instantiated by the ModuleFactory class (see relevent section) for the module to be initialised.
334  */
335 class Module : public classbase
336 {
337  public:
338
339         /** Default constructor
340          * Creates a module class.
341          * @param Me An instance of the Server class which can be saved for future use
342          * \exception ModuleException Throwing this class, or any class derived from ModuleException, causes loading of the module to abort.
343          */
344         Module(Server* Me);
345
346         /** Default destructor
347          * destroys a module class
348          */
349         virtual ~Module();
350
351         /** Returns the version number of a Module.
352          * The method should return a Version object with its version information assigned via
353          * Version::Version
354          */
355         virtual Version GetVersion();
356
357         /** The Implements function specifies which methods a module should receive events for.
358          * The char* parameter passed to this function contains a set of true or false values
359          * (1 or 0) which indicate wether each function is implemented. You must use the Iimplementation
360          * enum (documented elsewhere on this page) to mark functions as active. For example, to
361          * receive events for OnUserJoin():
362          *
363          * Implements[I_OnUserJoin] = 1;
364          *
365          * @param The implement list
366          */
367         virtual void Implements(char* Implements);
368
369         /** Used to set the 'priority' of a module (e.g. when it is called in relation to other modules.
370          * Some modules prefer to be called before other modules, due to their design. For example, a
371          * module which is expected to operate on complete information would expect to be placed last, so
372          * that any other modules which wish to adjust that information would execute before it, to be sure
373          * its information is correct. You can change your module's priority by returning one of:
374          *
375          * PRIORITY_FIRST - To place your module first in the list
376          * 
377          * PRIORITY_LAST - To place your module last in the list
378          *
379          * PRIORITY_DONTCARE - To leave your module as it is (this is the default value, if you do not implement this function)
380          *
381          * The result of Server::PriorityBefore() - To move your module before another named module
382          *
383          * The result of Server::PriorityLast() - To move your module after another named module
384          *
385          * For a good working example of this method call, please see src/modules/m_spanningtree.cpp
386          * and src/modules/m_hostchange.so which make use of it. It is highly recommended that unless
387          * your module has a real need to reorder its priority, it should not implement this function,
388          * as many modules changing their priorities can make the system redundant.
389          */
390         virtual Priority Prioritize();
391
392         /** Called when a user connects.
393          * The details of the connecting user are available to you in the parameter userrec *user
394          * @param user The user who is connecting
395          */
396         virtual void OnUserConnect(userrec* user);
397
398         /** Called when a user quits.
399          * The details of the exiting user are available to you in the parameter userrec *user
400          * This event is only called when the user is fully registered when they quit. To catch
401          * raw disconnections, use the OnUserDisconnect method.
402          * @param user The user who is quitting
403          * @param message The user's quit message
404          */
405         virtual void OnUserQuit(userrec* user, const std::string &message);
406
407         /** Called whenever a user's socket is closed.
408          * The details of the exiting user are available to you in the parameter userrec *user
409          * This event is called for all users, registered or not, as a cleanup method for modules
410          * which might assign resources to user, such as dns lookups, objects and sockets.
411          * @param user The user who is disconnecting
412          */
413         virtual void OnUserDisconnect(userrec* user);
414
415         /** Called whenever a channel is deleted, either by QUIT, KICK or PART.
416          * @param chan The channel being deleted
417          */
418         virtual void OnChannelDelete(chanrec* chan);
419
420         /** Called when a user joins a channel.
421          * The details of the joining user are available to you in the parameter userrec *user,
422          * and the details of the channel they have joined is available in the variable chanrec *channel
423          * @param user The user who is joining
424          * @param channel The channel being joined
425          */
426         virtual void OnUserJoin(userrec* user, chanrec* channel);
427
428         /** Called when a user parts a channel.
429          * The details of the leaving user are available to you in the parameter userrec *user,
430          * and the details of the channel they have left is available in the variable chanrec *channel
431          * @param user The user who is parting
432          * @param channel The channel being parted
433          * @param partmessage The part message, or an empty string
434          */
435         virtual void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage);
436
437         /** Called on rehash.
438          * This method is called prior to a /REHASH or when a SIGHUP is received from the operating
439          * system. You should use it to reload any files so that your module keeps in step with the
440          * rest of the application. If a parameter is given, the core has done nothing. The module
441          * receiving the event can decide if this parameter has any relevence to it.
442          * @param parameter The (optional) parameter given to REHASH from the user.
443          */
444         virtual void OnRehash(const std::string &parameter);
445
446         /** Called when a raw command is transmitted or received.
447          * This method is the lowest level of handler available to a module. It will be called with raw
448          * data which is passing through a connected socket. If you wish, you may munge this data by changing
449          * the string parameter "raw". If you do this, after your function exits it will immediately be
450          * cut down to 510 characters plus a carriage return and linefeed. For INBOUND messages only (where
451          * inbound is set to true) the value of user will be the userrec of the connection sending the
452          * data. This is not possible for outbound data because the data may be being routed to multiple targets.
453          * @param raw The raw string in RFC1459 format
454          * @param inbound A flag to indicate wether the data is coming into the daemon or going out to the user
455          * @param user The user record sending the text, when inbound == true.
456          */
457         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
458
459         /** Called whenever an extended mode is to be processed.
460          * The type parameter is MT_SERVER, MT_CLIENT or MT_CHANNEL, dependent on where the mode is being
461          * changed. mode_on is set when the mode is being set, in which case params contains a list of
462          * parameters for the mode as strings. If mode_on is false, the mode is being removed, and parameters
463          * may contain the parameters for the mode, dependent on wether they were defined when a mode handler
464          * was set up with Server::AddExtendedMode
465          * If the mode is a channel mode, target is a chanrec*, and if it is a user mode, target is a userrec*.
466          * You must cast this value yourself to make use of it.
467          * @param user The user issuing the mode
468          * @param target The user or channel having the mode set on them
469          * @param modechar The mode character being set
470          * @param type The type of mode (user or channel) being set
471          * @param mode_on True if the mode is being set, false if it is being unset
472          * @param params A list of parameters for any channel mode (currently supports either 0 or 1 parameters)
473          */
474         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
475         
476         /** Called whenever a user is about to join a channel, before any processing is done.
477          * Returning a value of 1 from this function stops the process immediately, causing no
478          * output to be sent to the user by the core. If you do this you must produce your own numerics,
479          * notices etc. This is useful for modules which may want to mimic +b, +k, +l etc. Returning -1 from
480          * this function forces the join to be allowed, bypassing restrictions such as banlists, invite, keys etc.
481          *
482          * IMPORTANT NOTE!
483          *
484          * If the user joins a NEW channel which does not exist yet, OnUserPreJoin will be called BEFORE the channel
485          * record is created. This will cause chanrec* chan to be NULL. There is very little you can do in form of
486          * processing on the actual channel record at this point, however the channel NAME will still be passed in
487          * char* cname, so that you could for example implement a channel blacklist or whitelist, etc.
488          * @param user The user joining the channel
489          * @param cname The channel name being joined
490          * @return 1 To prevent the join, 0 to allow it.
491          */
492         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
493         
494         /** Called whenever a user is about to be kicked.
495          * Returning a value of 1 from this function stops the process immediately, causing no
496          * output to be sent to the user by the core. If you do this you must produce your own numerics,
497          * notices etc.
498          * @param source The user issuing the kick
499          * @param user The user being kicked
500          * @param chan The channel the user is being kicked from
501          * @param reason The kick reason
502          * @return 1 to prevent the kick, 0 to continue normally, -1 to explicitly allow the kick regardless of normal operation
503          */
504         virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason);
505
506         /** Called whenever a user is kicked.
507          * If this method is called, the kick is already underway and cannot be prevented, so
508          * to prevent a kick, please use Module::OnUserPreKick instead of this method.
509          * @param source The user issuing the kick
510          * @param user The user being kicked
511          * @param chan The channel the user is being kicked from
512          * @param reason The kick reason
513          */
514         virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason);
515
516         /** Called whenever a user opers locally.
517          * The userrec will contain the oper mode 'o' as this function is called after any modifications
518          * are made to the user's structure by the core.
519          * @param user The user who is opering up
520          * @param opertype The opers type name
521          */
522         virtual void OnOper(userrec* user, const std::string &opertype);
523
524         /** Called after a user opers locally.
525          * This is identical to Module::OnOper(), except it is called after OnOper so that other modules
526          * can be gauranteed to already have processed the oper-up, for example m_spanningtree has sent
527          * out the OPERTYPE, etc.
528          * @param user The user who is opering up
529          * @param opertype The opers type name
530          */
531         virtual void OnPostOper(userrec* user, const std::string &opertype);
532         
533         /** Called whenever a user types /INFO.
534          * The userrec will contain the information of the user who typed the command. Modules may use this
535          * method to output their own credits in /INFO (which is the ircd's version of an about box).
536          * It is purposefully not possible to modify any info that has already been output, or halt the list.
537          * You must write a 371 numeric to the user, containing your info in the following format:
538          *
539          * &lt;nick&gt; :information here
540          *
541          * @param user The user issuing /INFO
542          */
543         virtual void OnInfo(userrec* user);
544         
545         /** Called whenever a /WHOIS is performed on a local user.
546          * The source parameter contains the details of the user who issued the WHOIS command, and
547          * the dest parameter contains the information of the user they are whoising.
548          * @param source The user issuing the WHOIS command
549          * @param dest The user who is being WHOISed
550          */
551         virtual void OnWhois(userrec* source, userrec* dest);
552         
553         /** Called whenever a user is about to invite another user into a channel, before any processing is done.
554          * Returning 1 from this function stops the process immediately, causing no
555          * output to be sent to the user by the core. If you do this you must produce your own numerics,
556          * notices etc. This is useful for modules which may want to filter invites to channels.
557          * @param source The user who is issuing the INVITE
558          * @param dest The user being invited
559          * @param channel The channel the user is being invited to
560          * @return 1 to deny the invite, 0 to allow
561          */
562         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
563         
564         /** Called after a user has been successfully invited to a channel.
565          * You cannot prevent the invite from occuring using this function, to do that,
566          * use OnUserPreInvite instead.
567          * @param source The user who is issuing the INVITE
568          * @param dest The user being invited
569          * @param channel The channel the user is being invited to
570          */
571         virtual void OnUserInvite(userrec* source,userrec* dest,chanrec* channel);
572         
573         /** Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done.
574          * Returning any nonzero value from this function stops the process immediately, causing no
575          * output to be sent to the user by the core. If you do this you must produce your own numerics,
576          * notices etc. This is useful for modules which may want to filter or redirect messages.
577          * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user,
578          * you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details
579          * of where the message is destined to be sent.
580          * @param user The user sending the message
581          * @param dest The target of the message (chanrec* or userrec*)
582          * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
583          * @param text Changeable text being sent by the user
584          * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
585          * @return 1 to deny the NOTICE, 0 to allow it
586          */
587         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status);
588
589         /** Called whenever a user is about to NOTICE A user or a channel, before any processing is done.
590          * Returning any nonzero value from this function stops the process immediately, causing no
591          * output to be sent to the user by the core. If you do this you must produce your own numerics,
592          * notices etc. This is useful for modules which may want to filter or redirect messages.
593          * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user,
594          * you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details
595          * of where the message is destined to be sent.
596          * You may alter the message text as you wish before relinquishing control to the next module
597          * in the chain, and if no other modules block the text this altered form of the text will be sent out
598          * to the user and possibly to other servers.
599          * @param user The user sending the message
600          * @param dest The target of the message (chanrec* or userrec*)
601          * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
602          * @param text Changeable text being sent by the user
603          * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
604          * @return 1 to deny the NOTICE, 0 to allow it
605          */
606         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status);
607         
608         /** Called before any nickchange, local or remote. This can be used to implement Q-lines etc.
609          * Please note that although you can see remote nickchanges through this function, you should
610          * NOT make any changes to the userrec if the user is a remote user as this may cause a desnyc.
611          * check user->server before taking any action (including returning nonzero from the method).
612          * If your method returns nonzero, the nickchange is silently forbidden, and it is down to your
613          * module to generate some meaninful output.
614          * @param user The username changing their nick
615          * @param newnick Their new nickname
616          * @return 1 to deny the change, 0 to allow
617          */
618         virtual int OnUserPreNick(userrec* user, const std::string &newnick);
619
620         /** Called after any PRIVMSG sent from a user.
621          * The dest variable contains a userrec* if target_type is TYPE_USER and a chanrec*
622          * if target_type is TYPE_CHANNEL.
623          * @param user The user sending the message
624          * @param dest The target of the message
625          * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
626          * @param text the text being sent by the user
627          * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
628          */
629         virtual void OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status);
630
631         /** Called after any NOTICE sent from a user.
632          * The dest variable contains a userrec* if target_type is TYPE_USER and a chanrec*
633          * if target_type is TYPE_CHANNEL.
634          * @param user The user sending the message
635          * @param dest The target of the message
636          * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
637          * @param text the text being sent by the user
638          * @param status The status being used, e.g. NOTICE @#chan has status== '@', 0 to send to everyone.
639          */
640         virtual void OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status);
641
642         /** Called after every MODE command sent from a user
643          * The dest variable contains a userrec* if target_type is TYPE_USER and a chanrec*
644          * if target_type is TYPE_CHANNEL. The text variable contains the remainder of the
645          * mode string after the target, e.g. "+wsi" or "+ooo nick1 nick2 nick3".
646          * @param user The user sending the MODEs
647          * @param dest The target of the modes (userrec* or chanrec*)
648          * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
649          * @param text The actual modes and their parameters if any
650          */
651         virtual void OnMode(userrec* user, void* dest, int target_type, const std::string &text);
652
653         /** Allows modules to alter or create server descriptions
654          * Whenever a module requires a server description, for example for display in
655          * WHOIS, this function is called in all modules. You may change or define the
656          * description given in std::string &description. If you do, this description
657          * will be shown in the WHOIS fields.
658          * @param servername The servername being searched for
659          * @param description Alterable server description for this server
660          */
661         virtual void OnGetServerDescription(const std::string &servername,std::string &description);
662
663         /** Allows modules to synchronize data which relates to users during a netburst.
664          * When this function is called, it will be called from the module which implements
665          * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
666          * is given in Module* proto, so that you may call its methods such as ProtoSendMode
667          * (see below). This function will be called for every user visible on your side
668          * of the burst, allowing you to for example set modes, etc. Do not use this call to
669          * synchronize data which you have stored using class Extensible -- There is a specialist
670          * function OnSyncUserMetaData and OnSyncChannelMetaData for this!
671          * @param user The user being syncronized
672          * @param proto A pointer to the module handling network protocol
673          * @param opaque An opaque pointer set by the protocol module, should not be modified!
674          */
675         virtual void OnSyncUser(userrec* user, Module* proto, void* opaque);
676
677         /** Allows modules to synchronize data which relates to channels during a netburst.
678          * When this function is called, it will be called from the module which implements
679          * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
680          * is given in Module* proto, so that you may call its methods such as ProtoSendMode
681          * (see below). This function will be called for every user visible on your side
682          * of the burst, allowing you to for example set modes, etc. Do not use this call to
683          * synchronize data which you have stored using class Extensible -- There is a specialist
684          * function OnSyncUserMetaData and OnSyncChannelMetaData for this!
685          *
686          * For a good example of how to use this function, please see src/modules/m_chanprotect.cpp
687          *
688          * @param chan The channel being syncronized
689          * @param proto A pointer to the module handling network protocol
690          * @param opaque An opaque pointer set by the protocol module, should not be modified!
691          */
692         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque);
693
694         /* Allows modules to syncronize metadata related to channels over the network during a netburst.
695          * Whenever the linking module wants to send out data, but doesnt know what the data
696          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
697          * this method is called.You should use the ProtoSendMetaData function after you've
698          * correctly decided how the data should be represented, to send the metadata on its way if it belongs
699          * to your module. For a good example of how to use this method, see src/modules/m_swhois.cpp.
700          * @param chan The channel whos metadata is being syncronized
701          * @param proto A pointer to the module handling network protocol
702          * @param opaque An opaque pointer set by the protocol module, should not be modified!
703          * @param extname The extensions name which is being searched for
704          */
705         virtual void OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname);
706
707         /* Allows modules to syncronize metadata related to users over the network during a netburst.
708          * Whenever the linking module wants to send out data, but doesnt know what the data
709          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
710          * this method is called. You should use the ProtoSendMetaData function after you've
711          * correctly decided how the data should be represented, to send the metadata on its way if
712          * if it belongs to your module.
713          * @param user The user whos metadata is being syncronized
714          * @param proto A pointer to the module handling network protocol
715          * @param opaque An opaque pointer set by the protocol module, should not be modified!
716          * @param extname The extensions name which is being searched for
717          */
718         virtual void OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname);
719
720         /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
721          * Whenever the linking module wants to send out data, but doesnt know what the data
722          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
723          * this method is called. You should use the ProtoSendMetaData function after you've
724          * correctly decided how the data should be represented, to send the metadata on its way if
725          * if it belongs to your module.
726          * @param proto A pointer to the module handling network protocol
727          * @param opaque An opaque pointer set by the protocol module, should not be modified!
728          */
729         virtual void OnSyncOtherMetaData(Module* proto, void* opaque);
730
731         /** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module.
732          * Please see src/modules/m_swhois.cpp for a working example of how to use this method call.
733          * @param target_type The type of item to decode data for, TYPE_USER or TYPE_CHANNEL
734          * @param target The chanrec* or userrec* that data should be added to
735          * @param extname The extension name which is being sent
736          * @param extdata The extension data, encoded at the other end by an identical module through OnSyncChannelMetaData or OnSyncUserMetaData
737          */
738         virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata);
739
740         /** Implemented by modules which provide the ability to link servers.
741          * These modules will implement this method, which allows transparent sending of servermodes
742          * down the network link as a broadcast, without a module calling it having to know the format
743          * of the MODE command before the actual mode string.
744          *
745          * More documentation to follow soon. Please see src/modules/m_chanprotect.cpp for examples
746          * of how to use this function.
747          *
748          * @param opaque An opaque pointer set by the protocol module, should not be modified!
749          * @param target_type The type of item to decode data for, TYPE_USER or TYPE_CHANNEL
750          * @param target The chanrec* or userrec* that modes should be sent for
751          * @param modeline The modes and parameters to be sent
752          */
753         virtual void ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline);
754
755         /** Implemented by modules which provide the ability to link servers.
756          * These modules will implement this method, which allows metadata (extra data added to
757          * user and channel records using class Extensible, Extensible::Extend, etc) to be sent
758          * to other servers on a netburst and decoded at the other end by the same module on a
759          * different server.
760          *
761          * More documentation to follow soon. Please see src/modules/m_swhois.cpp for example of
762          * how to use this function.
763          * @param opaque An opaque pointer set by the protocol module, should not be modified!
764          * @param target_type The type of item to decode data for, TYPE_USER or TYPE_CHANNEL
765          * @param target The chanrec* or userrec* that metadata should be sent for
766          * @param extname The extension name to send metadata for
767          * @param extdata Encoded data for this extension name, which will be encoded at the oppsite end by an identical module using OnDecodeMetaData
768          */
769         virtual void ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata);
770         
771         /** Called after every WALLOPS command.
772          * @param user The user sending the WALLOPS
773          * @param text The content of the WALLOPS message
774          */
775         virtual void OnWallops(userrec* user, const std::string &text);
776
777         /** Called whenever a user's hostname is changed.
778          * This event triggers after the host has been set.
779          * @param user The user whos host is being changed
780          * @param newhost The new hostname being set
781          */
782         virtual void OnChangeHost(userrec* user, const std::string &newhost);
783
784         /** Called whenever a user's GECOS (realname) is changed.
785          * This event triggers after the name has been set.
786          * @param user The user who's GECOS is being changed
787          * @param gecos The new GECOS being set on the user
788          */
789         virtual void OnChangeName(userrec* user, const std::string &gecos);
790
791         /** Called whenever a gline is added by a local user.
792          * This method is triggered after the line is added.
793          * @param duration The duration of the line in seconds
794          * @param source The sender of the line
795          * @param reason The reason text to be displayed
796          * @param hostmask The hostmask to add
797          */
798         virtual void OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask);
799
800         /** Called whenever a zline is added by a local user.
801          * This method is triggered after the line is added.
802          * @param duration The duration of the line in seconds
803          * @param source The sender of the line
804          * @param reason The reason text to be displayed
805          * @param ipmask The hostmask to add
806          */
807         virtual void OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask);
808
809         /** Called whenever a kline is added by a local user.
810          * This method is triggered after the line is added.
811          * @param duration The duration of the line in seconds
812          * @param source The sender of the line
813          * @param reason The reason text to be displayed
814          * @param hostmask The hostmask to add
815          */
816         virtual void OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask);
817
818         /** Called whenever a qline is added by a local user.
819          * This method is triggered after the line is added.
820          * @param duration The duration of the line in seconds
821          * @param source The sender of the line
822          * @param reason The reason text to be displayed
823          * @param nickmask The hostmask to add
824          */
825         virtual void OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask);
826
827         /** Called whenever a eline is added by a local user.
828          * This method is triggered after the line is added.
829          * @param duration The duration of the line in seconds
830          * @param source The sender of the line
831          * @param reason The reason text to be displayed
832          * @param hostmask The hostmask to add
833          */
834         virtual void OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask);
835
836         /** Called whenever a gline is deleted.
837          * This method is triggered after the line is deleted.
838          * @param source The user removing the line
839          * @param hostmask The hostmask to delete
840          */
841         virtual void OnDelGLine(userrec* source, const std::string &hostmask);
842
843         /** Called whenever a zline is deleted.
844          * This method is triggered after the line is deleted.
845          * @param source The user removing the line
846          * @param hostmask The hostmask to delete
847          */
848         virtual void OnDelZLine(userrec* source, const std::string &ipmask);
849
850         /** Called whenever a kline is deleted.
851          * This method is triggered after the line is deleted.
852          * @param source The user removing the line
853          * @param hostmask The hostmask to delete
854          */
855         virtual void OnDelKLine(userrec* source, const std::string &hostmask);
856         
857         /** Called whenever a qline is deleted.
858          * This method is triggered after the line is deleted.
859          * @param source The user removing the line
860          * @param hostmask The hostmask to delete
861          */
862         virtual void OnDelQLine(userrec* source, const std::string &nickmask);
863
864         /** Called whenever a eline is deleted.
865          * This method is triggered after the line is deleted.
866          * @param source The user removing the line
867          * @param hostmask The hostmask to delete
868          */
869         virtual void OnDelELine(userrec* source, const std::string &hostmask);
870
871         /** Called before your module is unloaded to clean up Extensibles.
872          * This method is called once for every user and channel on the network,
873          * so that when your module unloads it may clear up any remaining data
874          * in the form of Extensibles added using Extensible::Extend().
875          * If the target_type variable is TYPE_USER, then void* item refers to
876          * a userrec*, otherwise it refers to a chanrec*.
877          * @param target_type The type of item being cleaned
878          * @param item A pointer to the item's class
879          */
880         virtual void OnCleanup(int target_type, void* item);
881
882         /** Called after any nickchange, local or remote. This can be used to track users after nickchanges
883          * have been applied. Please note that although you can see remote nickchanges through this function, you should
884          * NOT make any changes to the userrec if the user is a remote user as this may cause a desnyc.
885          * check user->server before taking any action (including returning nonzero from the method).
886          * Because this method is called after the nickchange is taken place, no return values are possible
887          * to indicate forbidding of the nick change. Use OnUserPreNick for this.
888          * @param user The user changing their nick
889          * @param oldnick The old nickname of the user before the nickchange
890          */
891         virtual void OnUserPostNick(userrec* user, const std::string &oldnick);
892
893         /** Called before an action which requires a channel privilage check.
894          * This function is called before many functions which check a users status on a channel, for example
895          * before opping a user, deopping a user, kicking a user, etc.
896          * There are several values for access_type which indicate for what reason access is being checked.
897          * These are:<br><br>
898          * AC_KICK (0) - A user is being kicked<br>
899          * AC_DEOP (1) - a user is being deopped<br>
900          * AC_OP (2) - a user is being opped<br>
901          * AC_VOICE (3) - a user is being voiced<br>
902          * AC_DEVOICE (4) - a user is being devoiced<br>
903          * AC_HALFOP (5) - a user is being halfopped<br>
904          * AC_DEHALFOP (6) - a user is being dehalfopped<br>
905          * AC_INVITE (7) - a user is being invited<br>
906          * AC_GENERAL_MODE (8) - a user channel mode is being changed<br><br>
907          * Upon returning from your function you must return either ACR_DEFAULT, to indicate the module wishes
908          * to do nothing, or ACR_DENY where approprate to deny the action, and ACR_ALLOW where appropriate to allow
909          * the action. Please note that in the case of some access checks (such as AC_GENERAL_MODE) access may be
910          * denied 'upstream' causing other checks such as AC_DEOP to not be reached. Be very careful with use of the
911          * AC_GENERAL_MODE type, as it may inadvertently override the behaviour of other modules. When the access_type
912          * is AC_GENERAL_MODE, the destination of the mode will be NULL (as it has not yet been determined).
913          * @param source The source of the access check
914          * @param dest The destination of the access check
915          * @param channel The channel which is being checked
916          * @param access_type See above
917          */
918         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
919
920         /** Called when a 005 numeric is about to be output.
921          * The module should modify the 005 numeric if needed to indicate its features.
922          * @param output The 005 string to be modified if neccessary.
923          */
924         virtual void On005Numeric(std::string &output);
925
926         /** Called when a client is disconnected by KILL.
927          * If a client is killed by a server, e.g. a nickname collision or protocol error,
928          * source is NULL.
929          * Return 1 from this function to prevent the kill, and 0 from this function to allow
930          * it as normal. If you prevent the kill no output will be sent to the client, it is
931          * down to your module to generate this information.
932          * NOTE: It is NOT advisable to stop kills which originate from servers or remote users.
933          * If you do so youre risking race conditions, desyncs and worse!
934          * @param source The user sending the KILL
935          * @param dest The user being killed
936          * @param reason The kill reason
937          * @return 1 to prevent the kill, 0 to allow
938          */
939         virtual int OnKill(userrec* source, userrec* dest, const std::string &reason);
940
941         /** Called when an oper wants to disconnect a remote user via KILL
942          * @param source The user sending the KILL
943          * @param dest The user being killed
944          * @param reason The kill reason
945          */
946         virtual void OnRemoteKill(userrec* source, userrec* dest, const std::string &reason);
947
948         /** Called whenever a module is loaded.
949          * mod will contain a pointer to the module, and string will contain its name,
950          * for example m_widgets.so. This function is primary for dependency checking,
951          * your module may decide to enable some extra features if it sees that you have
952          * for example loaded "m_killwidgets.so" with "m_makewidgets.so". It is highly
953          * recommended that modules do *NOT* bail if they cannot satisfy dependencies,
954          * but instead operate under reduced functionality, unless the dependency is
955          * absolutely neccessary (e.g. a module that extends the features of another
956          * module).
957          * @param mod A pointer to the new module
958          * @param name The new module's filename
959          */
960         virtual void OnLoadModule(Module* mod,const std::string &name);
961
962         /** Called whenever a module is unloaded.
963          * mod will contain a pointer to the module, and string will contain its name,
964          * for example m_widgets.so. This function is primary for dependency checking,
965          * your module may decide to enable some extra features if it sees that you have
966          * for example loaded "m_killwidgets.so" with "m_makewidgets.so". It is highly
967          * recommended that modules do *NOT* bail if they cannot satisfy dependencies,
968          * but instead operate under reduced functionality, unless the dependency is
969          * absolutely neccessary (e.g. a module that extends the features of another
970          * module).
971          * @param mod Pointer to the module being unloaded (still valid)
972          * @param name The filename of the module being unloaded
973          */
974         virtual void OnUnloadModule(Module* mod,const std::string &name);
975
976         /** Called once every five seconds for background processing.
977          * This timer can be used to control timed features. Its period is not accurate
978          * enough to be used as a clock, but it is gauranteed to be called at least once in
979          * any five second period, directly from the main loop of the server.
980          * @param curtime The current timer derived from time(2)
981          */
982         virtual void OnBackgroundTimer(time_t curtime);
983
984         /** Called whenever a list is needed for a listmode.
985          * For example, when a /MODE #channel +b (without any other parameters) is called,
986          * if a module was handling +b this function would be called. The function can then
987          * output any lists it wishes to. Please note that all modules will see all mode
988          * characters to provide the ability to extend each other, so please only output
989          * a list if the mode character given matches the one(s) you want to handle.
990          * @param user The user requesting the list
991          * @param channel The channel the list is for
992          * @param mode The listmode which a list is being requested on
993          */
994         virtual void OnSendList(userrec* user, chanrec* channel, char mode);
995
996         /** Called whenever any command is about to be executed.
997          * This event occurs for all registered commands, wether they are registered in the core,
998          * or another module, but it will not occur for invalid commands (e.g. ones which do not
999          * exist within the command table). By returning 1 from this method you may prevent the
1000          * command being executed. If you do this, no output is created by the core, and it is
1001          * down to your module to produce any output neccessary.
1002          * Note that unless you return 1, you should not destroy any structures (e.g. by using
1003          * Server::QuitUser) otherwise when the command's handler function executes after your
1004          * method returns, it will be passed an invalid pointer to the user object and crash!)
1005          * @param command The command being executed
1006          * @param parameters An array of array of characters containing the parameters for the command
1007          * @param pcnt The nuimber of parameters passed to the command
1008          * @param user the user issuing the command
1009          * @param validated True if the command has passed all checks, e.g. it is recognised, has enough parameters, the user has permission to execute it, etc.
1010          * @return 1 to block the command, 0 to allow
1011          */
1012         virtual int OnPreCommand(const std::string &command, char **parameters, int pcnt, userrec *user, bool validated);
1013
1014         /** Called to check if a user who is connecting can now be allowed to register
1015          * If any modules return false for this function, the user is held in the waiting
1016          * state until all modules return true. For example a module which implements ident
1017          * lookups will continue to return false for a user until their ident lookup is completed.
1018          * Note that the registration timeout for a user overrides these checks, if the registration
1019          * timeout is reached, the user is disconnected even if modules report that the user is
1020          * not ready to connect.
1021          * @param user The user to check
1022          * @return true to indicate readiness, false if otherwise
1023          */
1024         virtual bool OnCheckReady(userrec* user);
1025
1026         /** Called whenever a user is about to register their connection (e.g. before the user
1027          * is sent the MOTD etc). Modules can use this method if they are performing a function
1028          * which must be done before the actual connection is completed (e.g. ident lookups,
1029          * dnsbl lookups, etc).
1030          * Note that you should NOT delete the user record here by causing a disconnection!
1031          * Use OnUserConnect for that instead.
1032          * @param user The user registering
1033          */
1034         virtual void OnUserRegister(userrec* user);
1035
1036         /** Called whenever a mode character is processed.
1037          * Return 1 from this function to block the mode character from being processed entirely,
1038          * so that you may perform your own code instead. Note that this method allows you to override
1039          * modes defined by other modes, but this is NOT RECOMMENDED!
1040          * @param user The user who is sending the mode
1041          * @param chan The channel the mode is being sent to
1042          * @param mode The mode character being set
1043          * @param param The parameter for the mode or an empty string
1044          * @param adding true of the mode is being added, false if it is being removed
1045          * @param pcnt The parameter count for the mode (0 or 1)
1046          * @return 1 to deny the mode, 0 to allow
1047          */
1048         virtual int OnRawMode(userrec* user, chanrec* chan, char mode, const std::string &param, bool adding, int pcnt);
1049
1050         /** Called whenever a user joins a channel, to determine if invite checks should go ahead or not.
1051          * This method will always be called for each join, wether or not the channel is actually +i, and
1052          * determines the outcome of an if statement around the whole section of invite checking code.
1053          * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
1054          * @param user The user joining the channel
1055          * @param chan The channel being joined
1056          * @return 1 to explicitly allow the join, 0 to proceed as normal
1057          */
1058         virtual int OnCheckInvite(userrec* user, chanrec* chan);
1059
1060         /** Called whenever a user joins a channel, to determine if key checks should go ahead or not.
1061          * This method will always be called for each join, wether or not the channel is actually +k, and
1062          * determines the outcome of an if statement around the whole section of key checking code.
1063          * if the user specified no key, the keygiven string will be a valid but empty value.
1064          * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
1065          * @param user The user joining the channel
1066          * @param chan The channel being joined
1067          * @return 1 to explicitly allow the join, 0 to proceed as normal
1068          */
1069         virtual int OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven);
1070
1071         /** Called whenever a user joins a channel, to determine if channel limit checks should go ahead or not.
1072          * This method will always be called for each join, wether or not the channel is actually +l, and
1073          * determines the outcome of an if statement around the whole section of channel limit checking code.
1074          * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
1075          * @param user The user joining the channel
1076          * @param chan The channel being joined
1077          * @return 1 to explicitly allow the join, 0 to proceed as normal
1078          */
1079         virtual int OnCheckLimit(userrec* user, chanrec* chan);
1080
1081         /** Called whenever a user joins a channel, to determine if banlist checks should go ahead or not.
1082          * This method will always be called for each join, wether or not the user actually matches a channel ban, and
1083          * determines the outcome of an if statement around the whole section of ban checking code.
1084          * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
1085          * @param user The user joining the channel
1086          * @param chan The channel being joined
1087          * @return 1 to explicitly allow the join, 0 to proceed as normal
1088          */
1089         virtual int OnCheckBan(userrec* user, chanrec* chan);
1090
1091         /** Called on all /STATS commands
1092          * This method is triggered for all /STATS use, including stats symbols handled by the core.
1093          * @param symbol the symbol provided to /STATS
1094          * @user the user issuing the /STATS command
1095          * @return 1 to block the /STATS from being processed by the core, 0 to allow it
1096          */
1097         virtual int OnStats(char symbol, userrec* user);
1098
1099         /** Called whenever a change of a local users displayed host is attempted.
1100          * Return 1 to deny the host change, or 0 to allow it.
1101          * @param user The user whos host will be changed
1102          * @param newhost The new hostname
1103          * @return 1 to deny the host change, 0 to allow
1104          */
1105         virtual int OnChangeLocalUserHost(userrec* user, const std::string &newhost);
1106
1107         /** Called whenever a change of a local users GECOS (fullname field) is attempted.
1108          * return 1 to deny the name change, or 0 to allow it.
1109          * @param user The user whos GECOS will be changed
1110          * @param newhost The new GECOS
1111          * @return 1 to deny the GECOS change, 0 to allow
1112          */
1113         virtual int OnChangeLocalUserGECOS(userrec* user, const std::string &newhost); 
1114
1115         /** Called whenever a topic is changed by a local user.
1116          * Return 1 to deny the topic change, or 0 to allow it.
1117          * @param user The user changing the topic
1118          * @param chan The channels who's topic is being changed
1119          * @param topic The actual topic text
1120          * @param 1 to block the topic change, 0 to allow
1121          */
1122         virtual int OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic);
1123
1124         /** Called whenever a local topic has been changed.
1125          * To block topic changes you must use OnLocalTopicChange instead.
1126          * @param user The user changing the topic
1127          * @param chan The channels who's topic is being changed
1128          * @param topic The actual topic text
1129          */
1130         virtual void OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic);
1131
1132         /** Called whenever an Event class is sent to all module by another module.
1133          * Please see the documentation of Event::Send() for further information. The Event sent can
1134          * always be assumed to be non-NULL, you should *always* check the value of Event::GetEventID()
1135          * before doing anything to the event data, and you should *not* change the event data in any way!
1136          * @param event The Event class being received
1137          */
1138         virtual void OnEvent(Event* event);
1139
1140         /** Called whenever a Request class is sent to your module by another module.
1141          * Please see the documentation of Request::Send() for further information. The Request sent
1142          * can always be assumed to be non-NULL, you should not change the request object or its data.
1143          * Your method may return arbitary data in the char* result which the requesting module
1144          * may be able to use for pre-determined purposes (e.g. the results of an SQL query, etc).
1145          * @param request The Request class being received
1146          */
1147         virtual char* OnRequest(Request* request);
1148
1149         /** Called whenever an oper password is to be compared to what a user has input.
1150          * The password field (from the config file) is in 'password' and is to be compared against
1151          * 'input'. This method allows for encryption of oper passwords and much more besides.
1152          * You should return a nonzero value if you want to allow the comparison or zero if you wish
1153          * to do nothing.
1154          * @param password The oper's password
1155          * @param input The password entered
1156          * @return 1 to match the passwords, 0 to do nothing
1157          */
1158         virtual int OnOperCompare(const std::string &password, const std::string &input);
1159
1160         /** Called whenever a user is given usermode +o, anywhere on the network.
1161          * You cannot override this and prevent it from happening as it is already happened and
1162          * such a task must be performed by another server. You can however bounce modes by sending
1163          * servermodes out to reverse mode changes.
1164          * @param user The user who is opering
1165          */
1166         virtual void OnGlobalOper(userrec* user);
1167
1168         /**  Called whenever a user connects, anywhere on the network.
1169          * This event is informational only. You should not change any user information in this
1170          * event. To do so, use the OnUserConnect method to change the state of local users.
1171          * @param user The user who is connecting
1172          */
1173         virtual void OnGlobalConnect(userrec* user);
1174
1175         /** Called whenever a ban is added to a channel's list.
1176          * Return a non-zero value to 'eat' the mode change and prevent the ban from being added.
1177          * @param source The user adding the ban
1178          * @param channel The channel the ban is being added to
1179          * @param banmask The ban mask being added
1180          * @return 1 to block the ban, 0 to continue as normal
1181          */
1182         virtual int OnAddBan(userrec* source, chanrec* channel,const std::string &banmask);
1183
1184         /** Called whenever a ban is removed from a channel's list.
1185          * Return a non-zero value to 'eat' the mode change and prevent the ban from being removed.
1186          * @param source The user deleting the ban
1187          * @param channel The channel the ban is being deleted from
1188          * @param banmask The ban mask being deleted
1189          * @return 1 to block the unban, 0 to continue as normal
1190          */
1191         virtual int OnDelBan(userrec* source, chanrec* channel,const std::string &banmask);
1192
1193         /** Called immediately after any  connection is accepted. This is intended for raw socket
1194          * processing (e.g. modules which wrap the tcp connection within another library) and provides
1195          * no information relating to a user record as the connection has not been assigned yet.
1196          * There are no return values from this call as all modules get an opportunity if required to
1197          * process the connection.
1198          * @param fd The file descriptor returned from accept()
1199          * @param ip The IP address of the connecting user
1200          * @param localport The local port number the user connected to
1201          */
1202         virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport);
1203
1204         /** Called immediately before any write() operation on a user's socket in the core. Because
1205          * this event is a low level event no user information is associated with it. It is intended
1206          * for use by modules which may wrap connections within another API such as SSL for example.
1207          * return a non-zero result if you have handled the write operation, in which case the core
1208          * will not call write().
1209          * @param fd The file descriptor of the socket
1210          * @param buffer A char* buffer being written
1211          * @param Number of characters to write
1212          * @return Number of characters actually written or 0 if you didn't handle the operation
1213          */
1214         virtual int OnRawSocketWrite(int fd, char* buffer, int count);
1215
1216         /** Called immediately before any socket is closed. When this event is called, shutdown()
1217          * has not yet been called on the socket.
1218          * @param fd The file descriptor of the socket prior to close()
1219          */
1220         virtual void OnRawSocketClose(int fd);
1221
1222         /** Called immediately before any read() operation on a client socket in the core.
1223          * This occurs AFTER the select() or poll() so there is always data waiting to be read
1224          * when this event occurs.
1225          * Your event should return 1 if it has handled the reading itself, which prevents the core
1226          * just using read(). You should place any data read into buffer, up to but NOT GREATER THAN
1227          * the value of count. The value of readresult must be identical to an actual result that might
1228          * be returned from the read() system call, for example, number of bytes read upon success,
1229          * 0 upon EOF or closed socket, and -1 for error. If your function returns a nonzero value,
1230          * you MUST set readresult.
1231          * @param fd The file descriptor of the socket
1232          * @param buffer A char* buffer being read to
1233          * @param count The size of the buffer
1234          * @param readresult The amount of characters read, or 0
1235          * @return nonzero if the event was handled, in which case readresult must be valid on exit
1236          */
1237         virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
1238
1239         /** Called whenever a user sets away.
1240          * This method has no parameter for the away message, as it is available in the
1241          * user record as userrec::awaymsg.
1242          */
1243         virtual void OnSetAway(userrec* user);
1244
1245         /** Called when a user cancels their away state.
1246          */
1247         virtual void OnCancelAway(userrec* user);
1248 };
1249
1250
1251 /** Allows server output and query functions
1252  * This class contains methods which allow a module to query the state of the irc server, and produce
1253  * output to users and other servers. All modules should instantiate at least one copy of this class,
1254  * and use its member functions to perform their tasks.
1255  */
1256 class Server : public classbase
1257 {
1258  public:
1259         /** Default constructor.
1260          * Creates a Server object.
1261          */
1262         Server();
1263
1264         /** Default destructor.
1265          * Destroys a Server object.
1266          */
1267         virtual ~Server();
1268
1269         /** Obtains a pointer to the server's ServerConfig object.
1270          * The ServerConfig object contains most of the configuration data
1271          * of the IRC server, as read from the config file by the core.
1272          */
1273         ServerConfig* GetConfig();
1274
1275         /** For use with Module::Prioritize().
1276          * When the return value of this function is returned from
1277          * Module::Prioritize(), this specifies that the module wishes
1278          * to be ordered exactly BEFORE 'modulename'. For more information
1279          * please see Module::Prioritize().
1280          * @param modulename The module your module wants to be before in the call list
1281          * @returns a priority ID which the core uses to relocate the module in the list
1282          */
1283         long PriorityBefore(const std::string &modulename);
1284
1285         /** For use with Module::Prioritize().
1286          * When the return value of this function is returned from
1287          * Module::Prioritize(), this specifies that the module wishes
1288          * to be ordered exactly AFTER 'modulename'. For more information please
1289          * see Module::Prioritize().
1290          * @param modulename The module your module wants to be after in the call list
1291          * @returns a priority ID which the core uses to relocate the module in the list
1292          */
1293         long PriorityAfter(const std::string &modulename);
1294         
1295         /** Sends text to all opers.
1296          * This method sends a server notice to all opers with the usermode +s.
1297          */
1298         virtual void SendOpers(const std::string &s);
1299
1300         /** Returns the version string of this server
1301          */
1302         std::string GetVersion();
1303
1304         /** Writes a log string.
1305          * This method writes a line of text to the log. If the level given is lower than the
1306          * level given in the configuration, this command has no effect.
1307          */
1308         virtual void Log(int level, const std::string &s);
1309
1310         /** Sends a line of text down a TCP/IP socket.
1311          * This method writes a line of text to an established socket, cutting it to 510 characters
1312          * plus a carriage return and linefeed if required.
1313          */
1314         virtual void Send(int Socket, const std::string &s);
1315
1316         /** Sends text from the server to a socket.
1317          * This method writes a line of text to an established socket, with the servername prepended
1318          * as used by numerics (see RFC 1459)
1319          */
1320         virtual void SendServ(int Socket, const std::string &s);
1321
1322         /** Writes text to a channel, but from a server, including all.
1323          * This can be used to send server notices to a group of users.
1324          */
1325         virtual void SendChannelServerNotice(const std::string &ServName, chanrec* Channel, const std::string &text);
1326
1327         /** Sends text from a user to a socket.
1328          * This method writes a line of text to an established socket, with the given user's nick/ident
1329          * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459)
1330          */
1331         virtual void SendFrom(int Socket, userrec* User, const std::string &s);
1332
1333         /** Sends text from a user to another user.
1334          * This method writes a line of text to a user, with a user's nick/ident
1335          * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459)
1336          * If you specify NULL as the source, then the data will originate from the
1337          * local server, e.g. instead of:
1338          *
1339          * :user!ident@host TEXT
1340          *
1341          * The format will become:
1342          *
1343          * :localserver TEXT
1344          *
1345          * Which is useful for numerics and server notices to single users, etc.
1346          */
1347         virtual void SendTo(userrec* Source, userrec* Dest, const std::string &s);
1348
1349         /** Sends text from a user to a channel (mulicast).
1350          * This method writes a line of text to a channel, with the given user's nick/ident
1351          * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the
1352          * IncludeSender flag is set, then the text is also sent back to the user from which
1353          * it originated, as seen in MODE (see RFC 1459).
1354          */
1355         virtual void SendChannel(userrec* User, chanrec* Channel, const std::string &s, bool IncludeSender);
1356
1357         /** Returns true if two users share a common channel.
1358          * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
1359          * method.
1360          */
1361         virtual bool CommonChannels(userrec* u1, userrec* u2);
1362
1363         /** Sends text from a user to one or more channels (mulicast).
1364          * This method writes a line of text to all users which share a common channel with a given     
1365          * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc
1366          * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent
1367          * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it
1368          * is only sent to the other recipients, as seen in QUIT.
1369          */
1370         virtual void SendCommon(userrec* User, const std::string &text, bool IncludeSender);
1371
1372         /** Sends a WALLOPS message.
1373          * This method writes a WALLOPS message to all users with the +w flag, originating from the
1374          * specified user.
1375          */
1376         virtual void SendWallops(userrec* User, const std::string &text);
1377
1378         /** Returns true if a nick is valid.
1379          * Nicks for unregistered connections will return false.
1380          */
1381         virtual bool IsNick(const std::string &nick);
1382
1383         /** Returns a count of the number of users on a channel.
1384          * This will NEVER be 0, as if the chanrec exists, it will have at least one user in the channel.
1385          */
1386         virtual int CountUsers(chanrec* c);
1387
1388         /** Adds an InspTimer which will trigger at a future time
1389          */
1390         virtual void AddTimer(InspTimer* T);
1391
1392         /** Attempts to look up a nick and return a pointer to it.
1393          * This function will return NULL if the nick does not exist.
1394          */
1395         virtual userrec* FindNick(const std::string &nick);
1396
1397         /** Attempts to look up a nick using the file descriptor associated with that nick.
1398          * This function will return NULL if the file descriptor is not associated with a valid user.
1399          */
1400         virtual userrec* FindDescriptor(int socket);
1401
1402         /** Attempts to look up a channel and return a pointer to it.
1403          * This function will return NULL if the channel does not exist.
1404          */
1405         virtual chanrec* FindChannel(const std::string &channel);
1406
1407         /** Attempts to look up a user's privilages on a channel.
1408          * This function will return a string containing either @, %, +, or an empty string,
1409          * representing the user's privilages upon the channel you specify.
1410          */
1411         virtual std::string ChanMode(userrec* User, chanrec* Chan);
1412
1413         /** Returns the server name of the server where the module is loaded.
1414          */
1415         virtual std::string GetServerName();
1416
1417         /** Returns the network name, global to all linked servers.
1418          */
1419         virtual std::string GetNetworkName();
1420
1421         /** Returns the server description string of the local server
1422          */
1423         virtual std::string GetServerDescription();
1424
1425         /** Returns the information of the server as returned by the /ADMIN command.
1426          * See the Admin class for further information of the return value. The members
1427          * Admin::Nick, Admin::Email and Admin::Name contain the information for the
1428          * server where the module is loaded.
1429          */
1430         virtual Admin GetAdmin();
1431
1432         /** Adds an extended mode letter which is parsed by a module.
1433          * This allows modules to add extra mode letters, e.g. +x for hostcloak.
1434          * the "type" parameter is either MT_CHANNEL, MT_CLIENT, or MT_SERVER, to
1435          * indicate wether the mode is a channel mode, a client mode, or a server mode.
1436          * requires_oper is used with MT_CLIENT type modes only to indicate the mode can only
1437          * be set or unset by an oper. If this is used for MT_CHANNEL type modes it is ignored.
1438          * params_when_on is the number of modes to expect when the mode is turned on
1439          * (for type MT_CHANNEL only), e.g. with mode +k, this would have a value of 1.
1440          * the params_when_off value has a similar value to params_when_on, except it indicates
1441          * the number of parameters to expect when the mode is disabled. Modes which act in a similar
1442          * way to channel mode +l (e.g. require a parameter to enable, but not to disable) should
1443          * use this parameter. The function returns false if the mode is unavailable, and will not
1444          * attempt to allocate another character, as this will confuse users. This also means that
1445          * as only one module can claim a specific mode character, the core does not need to keep track
1446          * of which modules own which modes, which speeds up operation of the server. In this version,
1447          * a mode can have at most one parameter, attempting to use more parameters will have undefined
1448          * effects.
1449          */
1450         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
1451
1452         /** Adds an extended mode letter which is parsed by a module and handled in a list fashion.
1453          * This call is used to implement modes like +q and +a. The characteristics of these modes are
1454          * as follows:
1455          *
1456          * (1) They are ALWAYS on channels, not on users, therefore their type is MT_CHANNEL
1457          *
1458          * (2) They always take exactly one parameter when being added or removed
1459          *
1460          * (3) They can be set multiple times, usually on users in channels
1461          *
1462          * (4) The mode and its parameter are NOT stored in the channels modes structure
1463          *
1464          * It is down to the module handling the mode to maintain state and determine what 'items' (e.g. users,
1465          * or a banlist) have the mode set on them, and process the modes at the correct times, e.g. during access
1466          * checks on channels, etc. When the extended mode is triggered the OnExtendedMode method will be triggered
1467          * as above. Note that the target you are given will be a channel, if for example your mode is set 'on a user'
1468          * (in for example +a) you must use Server::Find to locate the user the mode is operating on.
1469          * Your mode handler may return 1 to handle the mode AND tell the core to display the mode change, e.g.
1470          * '+aaa one two three' in the case of the mode for 'two', or it may return -1 to 'eat' the mode change,
1471          * so the above example would become '+aa one three' after processing.
1472          */
1473         virtual bool AddExtendedListMode(char modechar);
1474
1475         /** Adds a command to the command table.
1476          * This allows modules to add extra commands into the command table. You must place a function within your
1477          * module which is is of type handlerfunc:
1478          * 
1479          * typedef void (handlerfunc) (char**, int, userrec*);
1480          * ...
1481          * void handle_kill(char **parameters, int pcnt, userrec *user)
1482          *
1483          * When the command is typed, the parameters will be placed into the parameters array (similar to argv) and
1484          * the parameter count will be placed into pcnt (similar to argv). There will never be any less parameters
1485          * than the 'minparams' value you specified when creating the command. The *user parameter is the class of
1486          * the user which caused the command to trigger, who will always have the flag you specified in 'flags' when
1487          * creating the initial command. For example to create an oper only command create the commands with flags='o'.
1488          * The source parameter is used for resource tracking, and should contain the name of your module (with file
1489          * extension) e.g. "m_blarp.so". If you place the wrong identifier here, you can cause crashes if your module
1490          * is unloaded.
1491          */
1492         virtual void AddCommand(command_t *f);
1493          
1494         /** Sends a servermode.
1495          * you must format the parameters array with the target, modes and parameters for those modes.
1496          *
1497          * For example:
1498          *
1499          * char *modes[3];
1500          *
1501          * modes[0] = ChannelName;
1502          *
1503          * modes[1] = "+o";
1504          *
1505          * modes[2] = user->nick;
1506          *
1507          * Srv->SendMode(modes,3,user);
1508          *
1509          * The modes will originate from the server where the command was issued, however responses (e.g. numerics)
1510          * will be sent to the user you provide as the third parameter.
1511          * You must be sure to get the number of parameters correct in the pcnt parameter otherwise you could leave
1512          * your server in an unstable state!
1513          */
1514
1515         virtual void SendMode(char **parameters, int pcnt, userrec *user);
1516         
1517         /** Sends to all users matching a mode mask
1518          * You must specify one or more usermodes as the first parameter. These can be RFC specified modes such as +i,
1519          * or module provided modes, including ones provided by your own module.
1520          * In the second parameter you must place a flag value which indicates wether the modes you have given will be
1521          * logically ANDed or OR'ed. You may use one of either WM_AND or WM_OR.
1522          * for example, if you were to use:
1523          *
1524          * Serv->SendToModeMask("xi", WM_OR, "m00");
1525          *
1526          * Then the text 'm00' will be sent to all users with EITHER mode x or i. Conversely if you used WM_AND, the
1527          * user must have both modes set to receive the message.
1528          */
1529         virtual void SendToModeMask(const std::string &modes, int flags, const std::string &text);
1530
1531         /** Forces a user to join a channel.
1532          * This is similar to svsjoin and can be used to implement redirection, etc.
1533          * On success, the return value is a valid pointer to a chanrec* of the channel the user was joined to.
1534          * On failure, the result is NULL.
1535          */
1536         virtual chanrec* JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key);
1537         
1538         /** Forces a user to part a channel.
1539          * This is similar to svspart and can be used to implement redirection, etc.
1540          * Although the return value of this function is a pointer to a channel record, the returned data is
1541          * undefined and should not be read or written to. This behaviour may be changed in a future version.
1542          */
1543         virtual chanrec* PartUserFromChannel(userrec* user, const std::string &cname, const std::string &reason);
1544         
1545         /** Forces a user nickchange.
1546          * This command works similarly to SVSNICK, and can be used to implement Q-lines etc.
1547          * If you specify an invalid nickname, the nick change will be dropped and the target user will receive
1548          * the error numeric for it.
1549          */
1550         virtual void ChangeUserNick(userrec* user, const std::string &nickname);
1551         
1552         /** Forces a user to quit with the specified reason.
1553          * To the user, it will appear as if they typed /QUIT themselves, except for the fact that this function
1554          * may bypass the quit prefix specified in the config file.
1555          *
1556          * WARNING!
1557          *
1558          * Once you call this function, userrec* user will immediately become INVALID. You MUST NOT write to, or
1559          * read from this pointer after calling the QuitUser method UNDER ANY CIRCUMSTANCES! The best course of
1560          * action after calling this method is to immediately bail from your handler.
1561          */
1562         virtual void QuitUser(userrec* user, const std::string &reason);
1563
1564         /** Makes a user kick another user, with the specified reason.
1565          * If source is NULL, the server will peform the kick.
1566          * @param The person or server (if NULL) performing the KICK
1567          * @param target The person being kicked
1568          * @param chan The channel to kick from
1569          * @param reason The kick reason
1570          */
1571         virtual void KickUser(userrec* source, userrec* target, chanrec* chan, const std::string &reason);
1572         
1573         /**  Matches text against a glob pattern.
1574          * Uses the ircd's internal matching function to match string against a globbing pattern, e.g. *!*@*.com
1575          * Returns true if the literal successfully matches the pattern, false if otherwise.
1576          */
1577         virtual bool MatchText(const std::string &sliteral, const std::string &spattern);
1578         
1579         /** Calls the handler for a command, either implemented by the core or by another module.
1580          * You can use this function to trigger other commands in the ircd, such as PRIVMSG, JOIN,
1581          * KICK etc, or even as a method of callback. By defining command names that are untypeable
1582          * for users on irc (e.g. those which contain a \r or \n) you may use them as callback identifiers.
1583          * The first parameter to this method is the name of the command handler you wish to call, e.g.
1584          * PRIVMSG. This will be a command handler previously registered by the core or wih AddCommand().
1585          * The second parameter is an array of parameters, and the third parameter is a count of parameters
1586          * in the array. If you do not pass enough parameters to meet the minimum needed by the handler, the
1587          * functiom will silently ignore it. The final parameter is the user executing the command handler,
1588          * used for privilage checks, etc.
1589          * @return True if the command exists
1590          */
1591         virtual bool CallCommandHandler(const std::string &commandname, char** parameters, int pcnt, userrec* user);
1592
1593         /** This function returns true if the commandname exists, pcnt is equal to or greater than the number
1594          * of paramters the command requires, the user specified is allowed to execute the command, AND
1595          * if the command is implemented by a module (not the core). This has a few specific uses, usually
1596          * within network protocols (see src/modules/m_spanningtree.cpp)
1597          */
1598         virtual bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
1599         
1600         /** Change displayed hostname of a user.
1601          * You should always call this method to change a user's host rather than writing directly to the
1602          * dhost member of userrec, as any change applied via this method will be propogated to any
1603          * linked servers.
1604          */     
1605         virtual void ChangeHost(userrec* user, const std::string &host);
1606         
1607         /** Change GECOS (fullname) of a user.
1608          * You should always call this method to change a user's GECOS rather than writing directly to the
1609          * fullname member of userrec, as any change applied via this method will be propogated to any
1610          * linked servers.
1611          */     
1612         virtual void ChangeGECOS(userrec* user, const std::string &gecos);
1613         
1614         /** Returns true if the servername you give is ulined.
1615          * ULined servers have extra privilages. They are allowed to change nicknames on remote servers,
1616          * change modes of clients which are on remote servers and set modes of channels where there are
1617          * no channel operators for that channel on the ulined server, amongst other things.
1618          */
1619         virtual bool IsUlined(const std::string &server);
1620         
1621         /** Fetches the userlist of a channel. This function must be here and not a member of userrec or
1622          * chanrec due to include constraints.
1623          */
1624         virtual chanuserlist GetUsers(chanrec* chan);
1625
1626         /** Remove a user's connection to the irc server, but leave their client in existence in the
1627          * user hash. When you call this function, the user's file descriptor will be replaced with the
1628          * value of FD_MAGIC_NUMBER and their old file descriptor will be closed. This idle client will
1629          * remain until it is restored with a valid file descriptor, or is removed from IRC by an operator
1630          * After this call, the pointer to user will be invalid.
1631          */
1632         virtual bool UserToPseudo(userrec* user, const std::string &message);
1633
1634         /** This user takes one user, and switches their file descriptor with another user, so that one user
1635          * "becomes" the other. The user in 'alive' is booted off the server with the given message. The user
1636          * referred to by 'zombie' should have previously been locked with Server::UserToPseudo, otherwise
1637          * stale sockets and file descriptor leaks can occur. After this call, the pointer to alive will be
1638          * invalid, and the pointer to zombie will be equivalent in effect to the old pointer to alive.
1639          */
1640         virtual bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
1641
1642         /** Adds a G-line
1643          * The G-line is propogated to all of the servers in the mesh and enforced as soon as it is added.
1644          * The duration must be in seconds, however you can use the Server::CalcDuration method to convert
1645          * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used
1646          * to indicate who or what sent the data, usually this is the nickname of a person, or a server
1647          * name.
1648          */
1649         virtual void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
1650
1651         /** Adds a Q-line
1652          * The Q-line is propogated to all of the servers in the mesh and enforced as soon as it is added.
1653          * The duration must be in seconds, however you can use the Server::CalcDuration method to convert
1654          * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used
1655          * to indicate who or what sent the data, usually this is the nickname of a person, or a server
1656          * name.
1657          */
1658         virtual void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
1659
1660         /** Adds a Z-line
1661          * The Z-line is propogated to all of the servers in the mesh and enforced as soon as it is added.
1662          * The duration must be in seconds, however you can use the Server::CalcDuration method to convert
1663          * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used
1664          * to indicate who or what sent the data, usually this is the nickname of a person, or a server
1665          * name.
1666          */
1667         virtual void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
1668
1669         /** Adds a K-line
1670          * The K-line is enforced as soon as it is added.
1671          * The duration must be in seconds, however you can use the Server::CalcDuration method to convert
1672          * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used
1673          * to indicate who or what sent the data, usually this is the nickname of a person, or a server
1674          * name.
1675          */
1676         virtual void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
1677
1678         /** Adds a E-line
1679          * The E-line is enforced as soon as it is added.
1680          * The duration must be in seconds, however you can use the Server::CalcDuration method to convert
1681          * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used
1682          * to indicate who or what sent the data, usually this is the nickname of a person, or a server
1683          * name.
1684          */
1685         virtual void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
1686
1687         /** Deletes a G-Line from all servers
1688          */
1689         virtual bool DelGLine(const std::string &hostmask);
1690
1691         /** Deletes a Q-Line from all servers
1692          */
1693         virtual bool DelQLine(const std::string &nickname);
1694
1695         /** Deletes a Z-Line from all servers
1696          */
1697         virtual bool DelZLine(const std::string &ipaddr);
1698
1699         /** Deletes a local K-Line
1700          */
1701         virtual bool DelKLine(const std::string &hostmask);
1702
1703         /** Deletes a local E-Line
1704          */
1705         virtual bool DelELine(const std::string &hostmask);
1706
1707         /** Calculates a duration
1708          * This method will take a string containing a formatted duration (e.g. "1w2d") and return its value
1709          * as a total number of seconds. This is the same function used internally by /GLINE etc to set
1710          * the ban times.
1711          */
1712         virtual long CalcDuration(const std::string &duration);
1713
1714         /** Returns true if a nick!ident@host string is correctly formatted, false if otherwise.
1715          */
1716         virtual bool IsValidMask(const std::string &mask);
1717
1718         /** This function finds a module by name.
1719          * You must provide the filename of the module. If the module cannot be found (is not loaded)
1720          * the function will return NULL.
1721          */
1722         virtual Module* FindModule(const std::string &name);
1723
1724         /** Adds a class derived from InspSocket to the server's socket engine.
1725          */
1726         virtual void AddSocket(InspSocket* sock);
1727
1728         /** Forcibly removes a class derived from InspSocket from the servers socket engine.
1729          */
1730         virtual void RemoveSocket(InspSocket* sock);
1731
1732         /** Deletes a class derived from InspSocket from the server's socket engine.
1733          */
1734         virtual void DelSocket(InspSocket* sock);
1735
1736         /** Causes the local server to rehash immediately.
1737          * WARNING: Do not call this method from within your rehash method, for
1738          * obvious reasons!
1739          */
1740         virtual void RehashServer();
1741
1742         /** This method returns the total number of channels on the network.
1743          */
1744         virtual long GetChannelCount();
1745
1746         /** This method returns a channel whos index is greater than or equal to 0 and less than the number returned by Server::GetChannelCount().
1747          * This is slower (by factors of dozens) than requesting a channel by name with Server::FindChannel(), however there are times when
1748          * you wish to safely iterate the channel list, saving your position, with large amounts of time in between, which is what this function
1749          * is useful for.
1750          */
1751         virtual chanrec* GetChannelIndex(long index);
1752
1753         /** Dumps text (in a stringstream) to a user. The stringstream should not contain linefeeds, as it will be split
1754          * automatically by the function into safe amounts. The line prefix given is prepended onto each line (e.g. a servername
1755          * and a numeric).
1756          */
1757         void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
1758 };
1759
1760
1761 #define CONF_NOT_A_NUMBER       0x000010
1762 #define CONF_NOT_UNSIGNED       0x000080
1763 #define CONF_VALUE_NOT_FOUND    0x000100
1764 #define CONF_FILE_NOT_FOUND     0x000200
1765
1766
1767 /** Allows reading of values from configuration files
1768  * This class allows a module to read from either the main configuration file (inspircd.conf) or from
1769  * a module-specified configuration file. It may either be instantiated with one parameter or none.
1770  * Constructing the class using one parameter allows you to specify a path to your own configuration
1771  * file, otherwise, inspircd.conf is read.
1772  */
1773 class ConfigReader : public classbase
1774 {
1775   protected:
1776         /** The contents of the configuration file
1777          * This protected member should never be accessed by a module (and cannot be accessed unless the
1778          * core is changed). It will contain a pointer to the configuration file data with unneeded data
1779          * (such as comments) stripped from it.
1780          */
1781         std::stringstream *cache;
1782         std::stringstream *errorlog;
1783         /** Used to store errors
1784          */
1785         bool readerror;
1786         long error;
1787         
1788   public:
1789         /** Default constructor.
1790          * This constructor initialises the ConfigReader class to read the inspircd.conf file
1791          * as specified when running ./configure.
1792          */
1793         ConfigReader();                 // default constructor reads ircd.conf
1794         /** Overloaded constructor.
1795          * This constructor initialises the ConfigReader class to read a user-specified config file
1796          */
1797         ConfigReader(const std::string &filename);      // read a module-specific config
1798         /** Default destructor.
1799          * This method destroys the ConfigReader class.
1800          */
1801         ~ConfigReader();
1802         /** Retrieves a value from the config file.
1803          * This method retrieves a value from the config file. Where multiple copies of the tag
1804          * exist in the config file, index indicates which of the values to retrieve.
1805          */
1806         std::string ReadValue(const std::string &tag, const std::string &name, int index);
1807         /** Retrieves a boolean value from the config file.
1808          * This method retrieves a boolean value from the config file. Where multiple copies of the tag
1809          * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes"
1810          * and "true" in the config file count as true to ReadFlag, and any other value counts as false.
1811          */
1812         bool ReadFlag(const std::string &tag, const std::string &name, int index);
1813         /** Retrieves an integer value from the config file.
1814          * This method retrieves an integer value from the config file. Where multiple copies of the tag
1815          * exist in the config file, index indicates which of the values to retrieve. Any invalid integer
1816          * values in the tag will cause the objects error value to be set, and any call to GetError() will
1817          * return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned.
1818          * If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError()
1819          * will return CONF_NOT_UNSIGNED
1820          */
1821         long ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned);
1822         /** Returns the last error to occur.
1823          * Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition.
1824          * A call to GetError() resets the error flag back to 0.
1825          */
1826         long GetError();
1827         /** Counts the number of times a given tag appears in the config file.
1828          * This method counts the number of times a tag appears in a config file, for use where
1829          * there are several tags of the same kind, e.g. with opers and connect types. It can be
1830          * used with the index value of ConfigReader::ReadValue to loop through all copies of a
1831          * multiple instance tag.
1832          */
1833         int Enumerate(const std::string &tag);
1834         /** Returns true if a config file is valid.
1835          * This method is partially implemented and will only return false if the config
1836          * file does not exist or could not be opened.
1837          */
1838         bool Verify();
1839         /** Dumps the list of errors in a config file to an output location. If bail is true,
1840          * then the program will abort. If bail is false and user points to a valid user
1841          * record, the error report will be spooled to the given user by means of NOTICE.
1842          * if bool is false AND user is false, the error report will be spooled to all opers
1843          * by means of a NOTICE to all opers.
1844          */
1845         void DumpErrors(bool bail,userrec* user);
1846
1847         /** Returns the number of items within a tag.
1848          * For example if the tag was &lt;test tag="blah" data="foo"&gt; then this
1849          * function would return 2. Spaces and newlines both qualify as valid seperators
1850          * between values.
1851          */
1852         int EnumerateValues(const std::string &tag, int index);
1853 };
1854
1855
1856
1857 /** Caches a text file into memory and can be used to retrieve lines from it.
1858  * This class contains methods for read-only manipulation of a text file in memory.
1859  * Either use the constructor type with one parameter to load a file into memory
1860  * at construction, or use the LoadFile method to load a file.
1861  */
1862 class FileReader : public classbase
1863 {
1864         /** The file contents
1865          */
1866         file_cache fc;
1867  public:
1868          /** Default constructor.
1869           * This method does not load any file into memory, you must use the LoadFile method
1870           * after constructing the class this way.
1871           */
1872          FileReader();
1873
1874          /** Secondary constructor.
1875           * This method initialises the class with a file loaded into it ready for GetLine and
1876           * and other methods to be called. If the file could not be loaded, FileReader::FileSize
1877           * returns 0.
1878           */
1879          FileReader(const std::string &filename);
1880
1881          /** Default destructor.
1882           * This deletes the memory allocated to the file.
1883           */
1884          ~FileReader();
1885
1886          /** Used to load a file.
1887           * This method loads a file into the class ready for GetLine and
1888           * and other methods to be called. If the file could not be loaded, FileReader::FileSize
1889           * returns 0.
1890           */
1891          void LoadFile(const std::string &filename);
1892
1893          /** Returns true if the file exists
1894           * This function will return false if the file could not be opened.
1895           */
1896          bool Exists();
1897          
1898          /** Retrieve one line from the file.
1899           * This method retrieves one line from the text file. If an empty non-NULL string is returned,
1900           * the index was out of bounds, or the line had no data on it.
1901           */
1902          std::string GetLine(int x);
1903
1904          /** Returns the size of the file in lines.
1905           * This method returns the number of lines in the read file. If it is 0, no lines have been
1906           * read into memory, either because the file is empty or it does not exist, or cannot be
1907           * opened due to permission problems.
1908           */
1909          int FileSize();
1910 };
1911
1912
1913 /** Instantiates classes inherited from Module
1914  * This class creates a class inherited from type Module, using new. This is to allow for modules
1915  * to create many different variants of Module, dependent on architecture, configuration, etc.
1916  * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
1917  * modules.
1918  */
1919 class ModuleFactory : public classbase
1920 {
1921  public:
1922         ModuleFactory() { }
1923         virtual ~ModuleFactory() { }
1924         /** Creates a new module.
1925          * Your inherited class of ModuleFactory must return a pointer to your Module class
1926          * using this method.
1927          */
1928         virtual Module * CreateModule(Server* Me) = 0;
1929 };
1930
1931
1932 typedef DLLFactory<ModuleFactory> ircd_module;
1933
1934 bool ModeDefined(char c, int i);
1935 bool ModeDefinedOper(char c, int i);
1936 int ModeDefinedOn(char c, int i);
1937 int ModeDefinedOff(char c, int i);
1938 void ModeMakeList(char modechar);
1939 bool ModeIsListMode(char modechar, int type);
1940
1941 #endif