]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
This commit is dedicated to Boo ;-pppppp
[user/henk/code/inspircd.git] / include / inspircd.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 #ifndef __INSPIRCD_H__
18 #define __INSPIRCD_H__
19
20 #include <time.h>
21 #include <string>
22 #include <sstream>
23 #include "inspircd_config.h"
24 #include "users.h"
25 #include "channels.h"
26 #include "socket.h"
27 #include "mode.h"
28
29 #include "socketengine.h"
30 #include "command_parse.h"
31
32 /** Returned by some functions to indicate failure,
33  * and the exit code of the program if it terminates.
34  */
35 #define ERROR -1
36
37 /** Crucial defines
38  */
39 #define ETIREDGERBILS EAGAIN
40
41 /** Debug levels for use with InspIRCd::Log()
42  */
43 enum DebugLevel
44 {
45         DEBUG           =       10,
46         VERBOSE         =       20,
47         DEFAULT         =       30,
48         SPARSE          =       40,
49         NONE            =       50,
50 };
51
52 /**
53  * This define is used in place of strcmp when we 
54  * want to check if a char* string contains only one
55  * letter. Pretty fast, its just two compares and an
56  * addition.
57  */
58 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
59
60 /** Delete a pointer, and NULL its value
61  */
62 #define DELETE(x) {if (x) { delete x; x = NULL; }}
63
64 /** Template function to convert any input type to std::string
65  */
66 template<typename T> inline std::string ConvToStr(const T &in)
67 {
68         std::stringstream tmp;
69         if (!(tmp << in)) return std::string();
70         return tmp.str();
71 }
72
73 /** This class contains various STATS counters
74  * It is used by the InspIRCd class, which internally
75  * has an instance of it.
76  */
77 class serverstats : public classbase
78 {
79   public:
80         /** Number of accepted connections
81          */
82         unsigned long statsAccept;
83         /** Number of failed accepts
84          */
85         unsigned long statsRefused;
86         /** Number of unknown commands seen
87          */
88         unsigned long statsUnknown;
89         /** Number of nickname collisions handled
90          */
91         unsigned long statsCollisions;
92         /** Number of DNS queries sent out
93          */
94         unsigned long statsDns;
95         /** Number of good DNS replies received
96          * NOTE: This may not tally to the number sent out,
97          * due to timeouts and other latency issues.
98          */
99         unsigned long statsDnsGood;
100         /** Number of bad (negative) DNS replies received
101          * NOTE: This may not tally to the number sent out,
102          * due to timeouts and other latency issues.
103          */
104         unsigned long statsDnsBad;
105         /** Number of inbound connections seen
106          */
107         unsigned long statsConnects;
108         /** Total bytes of data transmitted
109          */
110         double statsSent;
111         /** Total bytes of data received
112          */
113         double statsRecv;
114         /** Number of bound listening ports
115          */
116         unsigned long BoundPortCount;
117
118         /** The constructor initializes all the counts to zero
119          */
120         serverstats()
121                 : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
122                 statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0.0), statsRecv(0.0),
123                 BoundPortCount(0)
124         {
125         }
126 };
127
128 class XLineManager;
129
130 /** The main singleton class of the irc server.
131  * This class contains instances of all the other classes
132  * in this software, with the exception of the base class,
133  * classbase. Amongst other things, it contains a ModeParser,
134  * a DNS object, a CommandParser object, and a list of active
135  * Module objects, and facilities for Module objects to
136  * interact with the core system it implements. You should
137  * NEVER attempt to instantiate a class of type InspIRCd
138  * yourself. If you do, this is equivalent to spawning a second
139  * IRC server, and could have catastrophic consequences for the
140  * program in terms of ram usage (basically, you could create
141  * an obese forkbomb built from recursively spawning irc servers!)
142  */
143 class InspIRCd : public classbase
144 {
145  private:
146         /** Holds a string describing the last module error to occur
147          */
148         char MODERR[MAXBUF];
149
150         /** This is an internal flag used by the mainloop
151          */
152         bool expire_run;
153
154         /** List of server names we've seen.
155          */
156         servernamelist servernames;
157  
158         /** Remove a ModuleFactory pointer
159          * @param j Index number of the ModuleFactory to remove
160          */
161         void EraseFactory(int j);
162
163         /** Remove a Module pointer
164          * @param j Index number of the Module to remove
165          */
166         void EraseModule(int j);
167
168         /** Build the ISUPPORT string by triggering all modules On005Numeric events
169          */
170         void BuildISupport();
171
172         /** Move a given module to a specific slot in the list
173          * @param modulename The module name to relocate
174          * @param slot The slot to move the module into
175          */
176         void MoveTo(std::string modulename,int slot);
177
178         /** Display the startup banner
179          */
180         void Start();
181
182         /** Set up the signal handlers
183          * @param SEGVHandler create a handler for segfaults (deprecated)
184          */
185         void SetSignals(bool SEGVHandler);
186
187         /** Daemonize the ircd and close standard input/output streams
188          * @return True if the program daemonized succesfully
189          */
190         bool DaemonSeed();
191
192         /** Build the upper/lowercase comparison table
193          */
194         void MakeLowerMap();
195
196         /** Moves the given module to the last slot in the list
197          * @param modulename The module name to relocate
198          */
199         void MoveToLast(std::string modulename);
200
201         /** Moves the given module to the first slot in the list
202          * @param modulename The module name to relocate
203          */
204         void MoveToFirst(std::string modulename);
205
206         /** Moves one module to be placed after another in the list
207          * @param modulename The module name to relocate
208          * @param after The module name to place the module after
209          */
210         void MoveAfter(std::string modulename, std::string after);
211
212         /** Moves one module to be placed before another in the list
213          * @param modulename The module name to relocate
214          * @param after The module name to place the module before
215          */
216         void MoveBefore(std::string modulename, std::string before);
217
218         /** Process a user whos socket has been flagged as active
219          * @param cu The user to process
220          * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
221          */
222         void ProcessUser(userrec* cu);
223
224         /** Iterate the list of InspSocket objects, removing ones which have timed out
225          * @param TIME the current time
226          */
227         void DoSocketTimeouts(time_t TIME);
228
229         /** Perform background user events such as PING checks
230          * @param TIME the current time
231          */
232         void DoBackgroundUserStuff(time_t TIME);
233
234         /** Returns true when all modules have done pre-registration checks on a user
235          * @param user The user to verify
236          * @return True if all modules have finished checking this user
237          */
238         bool AllModulesReportReady(userrec* user);
239
240         /** Total number of modules loaded into the ircd, minus one
241          */
242         int ModCount;
243
244         /** Logfile pathname specified on the commandline, or empty string
245          */
246         char LogFileName[MAXBUF];
247
248         /** The feature names published by various modules
249          */
250         featurelist Features;
251
252         /** The current time, updated in the mainloop
253          */
254         time_t TIME;
255
256         /** The time that was recorded last time around the mainloop
257          */
258         time_t OLDTIME;
259
260         /** A 64k buffer used to read client lines into
261          */
262         char ReadBuffer[65535];
263
264         /** Number of seconds in a minute
265          */
266         const long duration_m;
267
268         /** Number of seconds in an hour
269          */
270         const long duration_h;
271
272         /** Number of seconds in a day
273          */
274         const long duration_d;
275
276         /** Number of seconds in a week
277          */
278         const long duration_w;
279
280         /** Number of seconds in a year
281          */
282         const long duration_y;
283
284         /** Used when connecting clients
285          */
286         insp_sockaddr client, server;
287
288         /** Used when connecting clients
289          */
290         socklen_t length;
291
292         /** Used to count iterations around the mainloop
293          */
294         int iterations;
295
296  public:
297         /** Time this ircd was booted
298          */
299         time_t startup_time;
300
301         /** Mode handler, handles mode setting and removal
302          */
303         ModeParser* Modes;
304
305         /** Command parser, handles client to server commands
306          */
307         CommandParser* Parser;
308
309         /** Socket engine, handles socket activity events
310          */
311         SocketEngine* SE;
312
313         /** Stats class, holds miscellaneous stats counters
314          */
315         serverstats* stats;
316
317         /**  Server Config class, holds configuration file data
318          */
319         ServerConfig* Config;
320
321         /** Module sockets list, holds the active set of InspSocket classes
322          */
323         std::vector<InspSocket*> module_sockets;
324
325         /** Socket reference table, provides fast lookup of fd to InspSocket*
326          */
327         InspSocket* socket_ref[MAX_DESCRIPTORS];
328
329         /** user reference table, provides fast lookup of fd to userrec*
330          */
331         userrec* fd_ref_table[MAX_DESCRIPTORS];
332
333         /** Client list, a hash_map containing all clients, local and remote
334          */
335         user_hash clientlist;
336
337         /** Channel list, a hash_map containing all channels
338          */
339         chan_hash chanlist;
340
341         /** Local client list, a vector containing only local clients
342          */
343         std::vector<userrec*> local_users;
344
345         /** Oper list, a vector containing all local and remote opered users
346          */
347         std::vector<userrec*> all_opers;
348
349         /** Whowas container, contains a map of vectors of users tracked by WHOWAS
350          */
351         irc::whowas::whowas_users whowas;
352
353         /** DNS class, provides resolver facilities to the core and modules
354          */
355         DNS* Res;
356
357         /** Timer manager class, triggers InspTimer timer events
358          */
359         TimerManager* Timers;
360
361         /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
362          */
363         XLineManager* XLines;
364
365         /** A list of Module* module classes
366          * Note that this list is always exactly 255 in size.
367          * The actual number of loaded modules is available from GetModuleCount()
368          */
369         ModuleList modules;
370
371         /** A list of ModuleFactory* module factories
372          * Note that this list is always exactly 255 in size.
373          * The actual number of loaded modules is available from GetModuleCount()
374          */
375         FactoryList factory;
376
377         /** Get the current time
378          * Because this only calls time() once every time around the mainloop,
379          * it is much faster than calling time() directly.
380          * @return The current time as an epoch value (time_t)
381          */
382         time_t Time();
383
384         /** Get the total number of currently loaded modules
385          * @return The number of loaded modules
386          */
387         int GetModuleCount();
388
389         /** Find a module by name, and return a Module* to it.
390          * This is preferred over iterating the module lists yourself.
391          * @param name The module name to look up
392          * @return A pointer to the module, or NULL if the module cannot be found
393          */
394         Module* FindModule(const std::string &name);
395
396         /** Bind all ports specified in the configuration file.
397          * @param bail True if the function should bail back to the shell on failure
398          * @return The number of ports actually bound without error
399          */
400         int BindPorts(bool bail);
401
402         /** Returns true if this server has the given port bound to the given address
403          * @param port The port number
404          * @param addr The address
405          * @return True if we have a port listening on this address
406          */
407         bool HasPort(int port, char* addr);
408
409         /** Binds a socket on an already open file descriptor
410          * @param sockfd A valid file descriptor of an open socket
411          * @param client A sockaddr to use as temporary storage
412          * @param server A sockaddr to use as temporary storage
413          * @param port The port number to bind to
414          * @param addr The address to bind to (IP only)
415          * @return True if the port was bound successfully
416          */
417         bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
418
419         /** Adds a server name to the list of servers we've seen
420          * @param The servername to add
421          */
422         void AddServerName(const std::string &servername);
423
424         /** Finds a cached char* pointer of a server name,
425          * This is used to optimize userrec by storing only the pointer to the name
426          * @param The servername to find
427          * @return A pointer to this name, gauranteed to never become invalid
428          */
429         const char* FindServerNamePtr(const std::string &servername);
430
431         /** Returns true if we've seen the given server name before
432          * @param The servername to find
433          * @return True if we've seen this server name before
434          */
435         bool FindServerName(const std::string &servername);
436
437         /** Gets the GECOS (description) field of the given server.
438          * If the servername is not that of the local server, the name
439          * is passed to handling modules which will attempt to determine
440          * the GECOS that bleongs to the given servername.
441          * @param servername The servername to find the description of
442          * @return The description of this server, or of the local server
443          */
444         std::string GetServerDescription(const char* servername);
445
446         /** Write text to all opers connected to this server
447          * @param text The text format string
448          * @param ... Format args
449          */
450         void WriteOpers(const char* text, ...);
451
452         /** Write text to all opers connected to this server
453          * @param text The text to send
454          */
455         void WriteOpers(const std::string &text);
456         
457         /** Find a nickname in the nick hash
458          * @param nick The nickname to find
459          * @return A pointer to the user, or NULL if the user does not exist
460          */
461         userrec* FindNick(const std::string &nick);
462
463         /** Find a nickname in the nick hash
464          * @param nick The nickname to find
465          * @return A pointer to the user, or NULL if the user does not exist
466          */
467         userrec* FindNick(const char* nick);
468
469         /** Find a channel in the channels hash
470          * @param chan The channel to find
471          * @return A pointer to the channel, or NULL if the channel does not exist
472          */
473         chanrec* FindChan(const std::string &chan);
474
475         /** Find a channel in the channels hash
476          * @param chan The channel to find
477          * @return A pointer to the channel, or NULL if the channel does not exist
478          */
479         chanrec* FindChan(const char* chan);
480
481         /** Called by the constructor to load all modules from the config file.
482          */
483         void LoadAllModules();
484
485         /** Check for a 'die' tag in the config file, and abort if found
486          * @return Depending on the configuration, this function may never return
487          */
488         void CheckDie();
489
490         /** Check we aren't running as root, and exit if we are
491          * @return Depending on the configuration, this function may never return
492          */
493         void CheckRoot();
494
495         /** Determine the right path for, and open, the logfile
496          * @param argv The argv passed to main() initially, used to calculate program path
497          * @param argc The argc passed to main() initially, used to calculate program path
498          */
499         void OpenLog(char** argv, int argc);
500
501         /** Convert a user to a pseudoclient, disconnecting the real user
502          * @param user The user to convert
503          * @param message The quit message to display when exiting the user
504          * @return True if the operation succeeded
505          */
506         bool UserToPseudo(userrec* user, const std::string &message);
507
508         /** Convert a pseudoclient to a real user, discarding the pseudoclient
509          * @param alive A live client
510          * @param zombie A pseudoclient
511          * @param message The message to display when quitting the pseudoclient
512          * @return True if the operation succeeded
513          */
514         bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
515
516         /** Send a server notice to all local users
517          * @param text The text format string to send
518          * @param ... The format arguments
519          */
520         void ServerNoticeAll(char* text, ...);
521
522         /** Send a server message (PRIVMSG) to all local users
523          * @param text The text format string to send
524          * @param ... The format arguments
525          */
526         void ServerPrivmsgAll(char* text, ...);
527
528         /** Send text to all users with a specific set of modes
529          * @param modes The modes to check against, without a +, e.g. 'og'
530          * @param flags one of WM_OR or WM_AND. If you specify WM_OR, any one of the 
531          * mode characters in the first parameter causes receipt of the message, and
532          * if you specify WM_OR, all the modes must be present.
533          * @param text The text format string to send
534          * @param ... The format arguments
535          */
536         void WriteMode(const char* modes, int flags, const char* text, ...);
537
538         /** Return true if a channel name is valid
539          * @param chname A channel name to verify
540          * @return True if the name is valid
541          */
542         bool IsChannel(const char *chname);
543
544         /** Rehash the local server
545          * @param status This value is unused, and required for signal handler functions
546          */
547         static void Rehash(int status);
548
549         /** Causes the server to exit immediately
550          * @param The exit code to give to the operating system
551          */
552         static void Exit(int status);
553
554         /** Return a count of users, unknown and known connections
555          * @return The number of users
556          */
557         int UserCount();
558
559         /** Return a count of fully registered connections only
560          * @return The number of registered users
561          */
562         int RegisteredUserCount();
563
564         /** Return a count of invisible (umode +i) users only
565          * @return The number of invisible users
566          */
567         int InvisibleUserCount();
568
569         /** Return a count of opered (umode +o) users only
570          * @return The number of opers
571          */
572         int OperCount();
573
574         /** Return a count of unregistered (before NICK/USER) users only
575          * @return The number of unregistered (unknown) connections
576          */
577         int UnregisteredUserCount();
578
579         /** Return a count of channels on the network
580          * @return The number of channels
581          */
582         long ChannelCount();
583
584         /** Return a count of local users on this server only
585          * @return The number of local users
586          */
587         long LocalUserCount();
588
589         /** Send an error notice to all local users, opered and unopered
590          * @param s The error string to send
591          */
592         void SendError(const char *s);
593
594         /** For use with Module::Prioritize().
595          * When the return value of this function is returned from
596          * Module::Prioritize(), this specifies that the module wishes
597          * to be ordered exactly BEFORE 'modulename'. For more information
598          * please see Module::Prioritize().
599          * @param modulename The module your module wants to be before in the call list
600          * @returns a priority ID which the core uses to relocate the module in the list
601          */
602         long PriorityBefore(const std::string &modulename);
603
604         /** For use with Module::Prioritize().
605          * When the return value of this function is returned from
606          * Module::Prioritize(), this specifies that the module wishes
607          * to be ordered exactly AFTER 'modulename'. For more information please
608          * see Module::Prioritize().
609          * @param modulename The module your module wants to be after in the call list
610          * @returns a priority ID which the core uses to relocate the module in the list
611          */
612         long PriorityAfter(const std::string &modulename);
613
614         /** Publish a 'feature'.
615          * There are two ways for a module to find another module it depends on.
616          * Either by name, using InspIRCd::FindModule, or by feature, using this
617          * function. A feature is an arbitary string which identifies something this
618          * module can do. For example, if your module provides SSL support, but other
619          * modules provide SSL support too, all the modules supporting SSL should
620          * publish an identical 'SSL' feature. This way, any module requiring use
621          * of SSL functions can just look up the 'SSL' feature using FindFeature,
622          * then use the module pointer they are given.
623          * @param FeatureName The case sensitive feature name to make available
624          * @param Mod a pointer to your module class
625          * @returns True on success, false if the feature is already published by
626          * another module.
627          */
628         bool PublishFeature(const std::string &FeatureName, Module* Mod);
629
630         /** Unpublish a 'feature'.
631          * When your module exits, it must call this method for every feature it
632          * is providing so that the feature table is cleaned up.
633          * @param FeatureName the feature to remove
634          */
635         bool UnpublishFeature(const std::string &FeatureName);
636
637         /** Find a 'feature'.
638          * There are two ways for a module to find another module it depends on.
639          * Either by name, using InspIRCd::FindModule, or by feature, using the
640          * InspIRCd::PublishFeature method. A feature is an arbitary string which
641          * identifies something this module can do. For example, if your module
642          * provides SSL support, but other modules provide SSL support too, all
643          * the modules supporting SSL should publish an identical 'SSL' feature.
644          * To find a module capable of providing the feature you want, simply
645          * call this method with the feature name you are looking for.
646          * @param FeatureName The feature name you wish to obtain the module for
647          * @returns A pointer to a valid module class on success, NULL on failure.
648          */
649         Module* FindFeature(const std::string &FeatureName);
650
651         /** Given a pointer to a Module, return its filename
652          * @param m The module pointer to identify
653          * @return The module name or an empty string
654          */
655         const std::string& GetModuleName(Module* m);
656
657         /** Return true if a nickname is valid
658          * @param n A nickname to verify
659          * @return True if the nick is valid
660          */
661         bool IsNick(const char* n);
662
663         /** Return true if an ident is valid
664          * @param An ident to verify
665          * @return True if the ident is valid
666          */
667         bool IsIdent(const char* n);
668
669         /** Find a username by their file descriptor.
670          * It is preferred to use this over directly accessing the fd_ref_table array.
671          * @param socket The file descriptor of a user
672          * @return A pointer to the user if the user exists locally on this descriptor
673          */
674         userrec* FindDescriptor(int socket);
675
676         /** Add a new mode to this server's mode parser
677          * @param mh The modehandler to add
678          * @param modechar The mode character this modehandler handles
679          * @return True if the mode handler was added
680          */
681         bool AddMode(ModeHandler* mh, const unsigned char modechar);
682
683         /** Add a new mode watcher to this server's mode parser
684          * @param mw The modewatcher to add
685          * @return True if the modewatcher was added
686          */
687         bool AddModeWatcher(ModeWatcher* mw);
688
689         /** Delete a mode watcher from this server's mode parser
690          * @param mw The modewatcher to delete
691          * @return True if the modewatcher was deleted
692          */
693         bool DelModeWatcher(ModeWatcher* mw);
694
695         /** Add a dns Resolver class to this server's active set
696          * @param r The resolver to add
697          * @return True if the resolver was added
698          */
699         bool AddResolver(Resolver* r);
700
701         /** Add a command to this server's command parser
702          * @param f A command_t command handler object to add
703          * @throw ModuleException Will throw ModuleExcption if the command already exists
704          */
705         void AddCommand(command_t *f);
706
707         /** Send a modechange.
708          * The parameters provided are identical to that sent to the
709          * handler for class cmd_mode.
710          * @param parameters The mode parameters
711          * @param pcnt The number of items you have given in the first parameter
712          * @param user The user to send error messages to
713          */
714         void SendMode(const char **parameters, int pcnt, userrec *user);
715
716         /** Match two strings using pattern matching.
717          * This operates identically to the global function match(),
718          * except for that it takes std::string arguments rather than
719          * const char* ones.
720          * @param sliteral The literal string to match against
721          * @param spattern The pattern to match against. CIDR and globs are supported.
722          */
723         bool MatchText(const std::string &sliteral, const std::string &spattern);
724
725         /** Call the handler for a given command.
726          * @param commandname The command whos handler you wish to call
727          * @param parameters The mode parameters
728          * @param pcnt The number of items you have given in the first parameter
729          * @param user The user to execute the command as
730          * @return True if the command handler was called successfully
731          */
732         bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
733
734         /** Return true if the command is a module-implemented command and the given parameters are valid for it
735          * @param parameters The mode parameters
736          * @param pcnt The number of items you have given in the first parameter
737          * @param user The user to test-execute the command as
738          * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
739          */
740         bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
741
742         /** Add a gline and apply it
743          * @param duration How long the line should last
744          * @param source Who set the line
745          * @param reason The reason for the line
746          * @param hostmask The hostmask to set the line against
747          */
748         void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
749
750         /** Add a qline and apply it
751          * @param duration How long the line should last
752          * @param source Who set the line
753          * @param reason The reason for the line
754          * @param nickname The nickmask to set the line against
755          */
756         void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
757
758         /** Add a zline and apply it
759          * @param duration How long the line should last
760          * @param source Who set the line
761          * @param reason The reason for the line
762          * @param ipaddr The ip-mask to set the line against
763          */
764         void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
765
766         /** Add a kline and apply it
767          * @param duration How long the line should last
768          * @param source Who set the line
769          * @param reason The reason for the line
770          * @param hostmask The hostmask to set the line against
771          */
772         void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
773
774         /** Add an eline
775          * @param duration How long the line should last
776          * @param source Who set the line
777          * @param reason The reason for the line
778          * @param hostmask The hostmask to set the line against
779          */
780         void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
781
782         /** Delete a gline
783          * @param hostmask The gline to delete
784          * @return True if the item was removed
785          */
786         bool DelGLine(const std::string &hostmask);
787
788         /** Delete a qline
789          * @param nickname The qline to delete
790          * @return True if the item was removed
791          */
792         bool DelQLine(const std::string &nickname);
793
794         /** Delete a zline
795          * @param ipaddr The zline to delete
796          * @return True if the item was removed
797          */
798         bool DelZLine(const std::string &ipaddr);
799
800         /** Delete a kline
801          * @param hostmask The kline to delete
802          * @return True if the item was removed
803          */
804         bool DelKLine(const std::string &hostmask);
805
806         /** Delete an eline
807          * @param hostmask The kline to delete
808          * @return True if the item was removed
809          */
810         bool DelELine(const std::string &hostmask);
811
812         /** Return true if the given parameter is a valid nick!user\@host mask
813          * @param mask A nick!user\@host masak to match against 
814          * @return True i the mask is valid
815          */
816         bool IsValidMask(const std::string &mask);
817
818         /** Add an InspSocket class to the active set
819          * @param sock A socket to add to the active set
820          */
821         void AddSocket(InspSocket* sock);
822
823         /** Remove an InspSocket class from the active set at next time around the loop
824          * @param sock A socket to remove from the active set
825          */
826         void RemoveSocket(InspSocket* sock);
827
828         /** Delete a socket immediately without waiting for the next iteration of the mainloop
829          * @param sock A socket to delete from the active set
830          */
831         void DelSocket(InspSocket* sock);
832
833         /** Rehash the local server
834          */
835         void RehashServer();
836
837         /** Return the channel whos index number matches that provided
838          * @param The index number of the channel to fetch
839          * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
840          */
841         chanrec* GetChannelIndex(long index);
842
843         /** Dump text to a user target, splitting it appropriately to fit
844          * @param User the user to dump the text to
845          * @param LinePrefix text to prefix each complete line with
846          * @param TextStream the text to send to the user
847          */
848         void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
849
850         /** Check if the given nickmask matches too many users, send errors to the given user
851          * @param nick A nickmask to match against
852          * @param user A user to send error text to
853          * @return True if the nick matches too many users
854          */
855         bool NickMatchesEveryone(const std::string &nick, userrec* user);
856
857         /** Check if the given IP mask matches too many users, send errors to the given user
858          * @param ip An ipmask to match against
859          * @param user A user to send error text to
860          * @return True if the ip matches too many users
861          */
862         bool IPMatchesEveryone(const std::string &ip, userrec* user);
863
864         /** Check if the given hostmask matches too many users, send errors to the given user
865          * @param mask A hostmask to match against
866          * @param user A user to send error text to
867          * @return True if the host matches too many users
868          */
869         bool HostMatchesEveryone(const std::string &mask, userrec* user);
870
871         /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
872          * @param str A string containing a time in the form 1y2w3d4h6m5s
873          * (one year, two weeks, three days, four hours, six minutes and five seconds)
874          * @return The total number of seconds
875          */
876         long Duration(const char* str);
877
878         /** Attempt to compare an oper password to a string from the config file.
879          * This will be passed to handling modules which will compare the data
880          * against possible hashed equivalents in the input string.
881          * @param data The data from the config file
882          * @param input The data input by the oper
883          * @return 0 if the strings match, 1 or -1 if they do not
884          */
885         int OperPassCompare(const char* data,const char* input);
886
887         /** Check if a given server is a uline.
888          * An empty string returns true, this is by design.
889          * @param server The server to check for uline status
890          * @return True if the server is a uline OR the string is empty
891          */
892         bool ULine(const char* server);
893
894         /** Returns the subversion revision ID of this ircd
895          * @return The revision ID or an empty string
896          */
897         std::string GetRevision();
898
899         /** Returns the full version string of this ircd
900          * @return The version string
901          */
902         std::string GetVersionString();
903
904         /** Attempt to write the process id to a given file
905          * @param filename The PID file to attempt to write to
906          * @return This function may bail if the file cannot be written
907          */
908         void WritePID(const std::string &filename);
909
910         /** Returns text describing the last module error
911          * @return The last error message to occur
912          */
913         char* ModuleError();
914
915         /** Load a given module file
916          * @param filename The file to load
917          * @return True if the module was found and loaded
918          */
919         bool LoadModule(const char* filename);
920
921         /** Unload a given module file
922          * @param filename The file to unload
923          * @return True if the module was unloaded
924          */
925         bool UnloadModule(const char* filename);
926
927         /** This constructor initialises all the subsystems and reads the config file.
928          * @param argc The argument count passed to main()
929          * @param argv The argument list passed to main()
930          * @throw <anything> If anything is thrown from here and makes it to
931          * you, you should probably just give up and go home. Yes, really.
932          * It's that bad. Higher level classes should catch any non-fatal exceptions.
933          */
934         InspIRCd(int argc, char** argv);
935
936         /** Do one iteration of the mainloop
937          * @param process_module_sockets True if module sockets are to be processed
938          * this time around the event loop. The is the default.
939          */
940         void DoOneIteration(bool process_module_sockets = true);
941
942         /** Output a log message to the ircd.log file
943          * The text will only be output if the current loglevel
944          * is less than or equal to the level you provide
945          * @param level A log level from the DebugLevel enum
946          * @param text Format string of to write to the log
947          * @param ... Format arguments of text to write to the log
948          */
949         void Log(int level, const char* text, ...);
950
951         /** Output a log message to the ircd.log file
952          * The text will only be output if the current loglevel
953          * is less than or equal to the level you provide
954          * @param level A log level from the DebugLevel enum
955          * @param text Text to write to the log
956          */
957         void Log(int level, const std::string &text);
958
959         /** Begin execution of the server.
960          * NOTE: this function NEVER returns. Internally,
961          * after performing some initialisation routines,
962          * it will repeatedly call DoOneIteration in a loop.
963          * @return The return value for this function is undefined.
964          */
965         int Run();
966 };
967
968 #endif
969