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