]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
- Tear out a useless load of XLine clutters that did nothing much except confuse...
[user/henk/code/inspircd.git] / include / inspircd.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __INSPIRCD_H__
15 #define __INSPIRCD_H__
16
17 #ifndef WIN32
18 #define DllExport 
19 #define CoreExport 
20 #define printf_c printf
21 #else
22 #include "inspircd_win32wrapper.h"
23 /** Windows defines these already */
24 #undef DELETE
25 #undef ERROR
26 #endif
27
28 #include <time.h>
29 #include <string>
30 #include <sstream>
31 #include <list>
32 #include "inspircd_config.h"
33 #include "uid.h"
34 #include "users.h"
35 #include "channels.h"
36 #include "socket.h"
37 #include "mode.h"
38 #include "socketengine.h"
39 #include "command_parse.h"
40 #include "snomasks.h"
41 #include "cull_list.h"
42 #include "filelogger.h"
43 #include "caller.h"
44
45 /**
46  * Used to define the maximum number of parameters a command may have.
47  */
48 #define MAXPARAMETERS 127
49
50 /** Returned by some functions to indicate failure.
51  */
52 #define ERROR -1
53
54 /** Support for librodent -
55  * see http://www.chatspike.net/index.php?z=64
56  */
57 #define ETIREDHAMSTERS EAGAIN
58
59 /** Delete a pointer, and NULL its value
60  */
61 template<typename T> inline void DELETE(T* x)
62 {
63         delete x;
64         x = NULL;
65 }
66
67 /** Template function to convert any input type to std::string
68  */
69 template<typename T> inline std::string ConvNumeric(const T &in)
70 {
71         if (in == 0) return "0";
72         char res[MAXBUF];
73         char* out = res;
74         T quotient = in;
75         while (quotient) {
76                 *out = "0123456789"[ std::abs( (long)quotient % 10 ) ];
77                 ++out;
78                 quotient /= 10;
79         }
80         if (in < 0)
81                 *out++ = '-';
82         *out = 0;
83         std::reverse(res,out);
84         return res;
85 }
86
87 /** Template function to convert any input type to std::string
88  */
89 inline std::string ConvToStr(const int in)
90 {
91         return ConvNumeric(in);
92 }
93
94 /** Template function to convert any input type to std::string
95  */
96 inline std::string ConvToStr(const long in)
97 {
98         return ConvNumeric(in);
99 }
100
101 /** Template function to convert any input type to std::string
102  */
103 inline std::string ConvToStr(const char* in)
104 {
105         return in;
106 }
107
108 /** Template function to convert any input type to std::string
109  */
110 inline std::string ConvToStr(const bool in)
111 {
112         return (in ? "1" : "0");
113 }
114
115 /** Template function to convert any input type to std::string
116  */
117 inline std::string ConvToStr(char in)
118 {
119         return std::string(in,1);
120 }
121
122 /** Template function to convert any input type to std::string
123  */
124 template <class T> inline std::string ConvToStr(const T &in)
125 {
126         std::stringstream tmp;
127         if (!(tmp << in)) return std::string();
128         return tmp.str();
129 }
130
131 /** Template function to convert any input type to any other type
132  * (usually an integer or numeric type)
133  */
134 template<typename T> inline long ConvToInt(const T &in)
135 {
136         std::stringstream tmp;
137         if (!(tmp << in)) return 0;
138         return atoi(tmp.str().c_str());
139 }
140
141 /** Template function to convert integer to char, storing result in *res and
142  * also returning the pointer to res. Based on Stuart Lowe's C/C++ Pages.
143  * @param T input value
144  * @param V result value
145  * @param R base to convert to
146  */
147 template<typename T, typename V, typename R> inline char* itoa(const T &in, V *res, R base)
148 {
149         if (base < 2 || base > 16) { *res = 0; return res; }
150         char* out = res;
151         int quotient = in;
152         while (quotient) {
153                 *out = "0123456789abcdef"[ std::abs( quotient % base ) ];
154                 ++out;
155                 quotient /= base;
156         }
157         if ( in < 0 && base == 10) *out++ = '-';
158         std::reverse( res, out );
159         *out = 0;
160         return res;
161 }
162
163 /** This class contains various STATS counters
164  * It is used by the InspIRCd class, which internally
165  * has an instance of it.
166  */
167 class serverstats : public classbase
168 {
169   public:
170         /** Number of accepted connections
171          */
172         unsigned long statsAccept;
173         /** Number of failed accepts
174          */
175         unsigned long statsRefused;
176         /** Number of unknown commands seen
177          */
178         unsigned long statsUnknown;
179         /** Number of nickname collisions handled
180          */
181         unsigned long statsCollisions;
182         /** Number of DNS queries sent out
183          */
184         unsigned long statsDns;
185         /** Number of good DNS replies received
186          * NOTE: This may not tally to the number sent out,
187          * due to timeouts and other latency issues.
188          */
189         unsigned long statsDnsGood;
190         /** Number of bad (negative) DNS replies received
191          * NOTE: This may not tally to the number sent out,
192          * due to timeouts and other latency issues.
193          */
194         unsigned long statsDnsBad;
195         /** Number of inbound connections seen
196          */
197         unsigned long statsConnects;
198         /** Total bytes of data transmitted
199          */
200         double statsSent;
201         /** Total bytes of data received
202          */
203         double statsRecv;
204         /** Cpu usage at last sample
205          */
206         timeval LastCPU;
207         /** Time last sample was read
208          */
209         timeval LastSampled;
210         /** The constructor initializes all the counts to zero
211          */
212         serverstats()
213                 : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
214                 statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0.0), statsRecv(0.0)
215         {
216         }
217 };
218
219 /** A list of failed port bindings, used for informational purposes on startup */
220 typedef std::vector<std::pair<std::string, long> > FailedPortList;
221
222 /** A list of ip addresses cross referenced against clone counts */
223 typedef std::map<irc::string, unsigned int> clonemap;
224
225 class InspIRCd;
226
227 DEFINE_HANDLER1(ProcessUserHandler, void, User*);
228 DEFINE_HANDLER1(IsNickHandler, bool, const char*);
229 DEFINE_HANDLER1(IsIdentHandler, bool, const char*);
230 DEFINE_HANDLER1(FindDescriptorHandler, User*, int);
231 DEFINE_HANDLER1(FloodQuitUserHandler, void, User*);
232
233 /* Forward declaration - required */
234 class XLineManager;
235
236 /** The main class of the irc server.
237  * This class contains instances of all the other classes
238  * in this software, with the exception of the base class,
239  * classbase. Amongst other things, it contains a ModeParser,
240  * a DNS object, a CommandParser object, and a list of active
241  * Module objects, and facilities for Module objects to
242  * interact with the core system it implements. You should
243  * NEVER attempt to instantiate a class of type InspIRCd
244  * yourself. If you do, this is equivalent to spawning a second
245  * IRC server, and could have catastrophic consequences for the
246  * program in terms of ram usage (basically, you could create
247  * an obese forkbomb built from recursively spawning irc servers!)
248  */
249 class CoreExport InspIRCd : public classbase
250 {
251  private:
252         /** Holds the current UID. Used to generate the next one.
253          */
254         char current_uid[UUID_LENGTH];
255
256         /** Set up the signal handlers
257          */
258         void SetSignals();
259
260         /** Daemonize the ircd and close standard input/output streams
261          * @return True if the program daemonized succesfully
262          */
263         bool DaemonSeed();
264
265         /** Iterate the list of BufferedSocket objects, removing ones which have timed out
266          * @param TIME the current time
267          */
268         void DoSocketTimeouts(time_t TIME);
269
270         /** Sets up UID subsystem
271          */
272         void InitialiseUID();
273
274         /** Perform background user events such as PING checks
275          */
276         void DoBackgroundUserStuff();
277
278         /** Returns true when all modules have done pre-registration checks on a user
279          * @param user The user to verify
280          * @return True if all modules have finished checking this user
281          */
282         bool AllModulesReportReady(User* user);
283
284         /** Logfile pathname specified on the commandline, or empty string
285          */
286         char LogFileName[MAXBUF];
287
288         /** The current time, updated in the mainloop
289          */
290         time_t TIME;
291
292         /** The time that was recorded last time around the mainloop
293          */
294         time_t OLDTIME;
295
296         /** A 64k buffer used to read client lines into
297          */
298         char ReadBuffer[65535];
299
300         /** Used when connecting clients
301          */
302         insp_sockaddr client, server;
303
304         /** Used when connecting clients
305          */
306         socklen_t length;
307
308         /** Nonblocking file writer
309          */
310         FileLogger* Logger;
311
312         /** Time offset in seconds
313          * This offset is added to all calls to Time(). Use SetTimeDelta() to update
314          */
315         int time_delta;
316
317 #ifdef WIN32
318         IPC* WindowsIPC;
319 #endif
320
321  public:
322
323         /** Global cull list, will be processed on next iteration
324          */
325         CullList GlobalCulls;
326
327         /**** Functors ****/
328
329         ProcessUserHandler HandleProcessUser;
330         IsNickHandler HandleIsNick;
331         IsIdentHandler HandleIsIdent;
332         FindDescriptorHandler HandleFindDescriptor;
333         FloodQuitUserHandler HandleFloodQuitUser;
334
335         /** BufferedSocket classes pending deletion after being closed.
336          * We don't delete these immediately as this may cause a segmentation fault.
337          */
338         std::map<BufferedSocket*,BufferedSocket*> SocketCull;
339
340         /** Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1
341          * Reason for it:
342          * kludge alert!
343          * SendMode expects a User* to send the numeric replies
344          * back to, so we create it a fake user that isnt in the user
345          * hash and set its descriptor to FD_MAGIC_NUMBER so the data
346          * falls into the abyss :p
347          */
348         User *FakeClient;
349
350         /** Returns the next available UID for this server.
351          */
352         std::string GetUID();
353
354         /** Find a user in the UUID hash
355          * @param nick The nickname to find
356          * @return A pointer to the user, or NULL if the user does not exist
357          */
358         User *FindUUID(const std::string &);
359
360         /** Find a user in the UUID hash
361          * @param nick The nickname to find
362          * @return A pointer to the user, or NULL if the user does not exist
363          */
364         User *FindUUID(const char *);
365
366         /** Build the ISUPPORT string by triggering all modules On005Numeric events
367          */
368         void BuildISupport();
369
370         /** Number of unregistered users online right now.
371          * (Unregistered means before USER/NICK/dns)
372          */
373         int unregistered_count;
374
375         /** List of server names we've seen.
376          */
377         servernamelist servernames;
378
379         /** Time this ircd was booted
380          */
381         time_t startup_time;
382
383         /** Config file pathname specified on the commandline or via ./configure
384          */
385         char ConfigFileName[MAXBUF];
386
387         /** Mode handler, handles mode setting and removal
388          */
389         ModeParser* Modes;
390
391         /** Command parser, handles client to server commands
392          */
393         CommandParser* Parser;
394
395         /** Socket engine, handles socket activity events
396          */
397         SocketEngine* SE;
398         
399         /** ModuleManager contains everything related to loading/unloading
400          * modules.
401          */
402         ModuleManager* Modules;
403
404         /** Stats class, holds miscellaneous stats counters
405          */
406         serverstats* stats;
407
408         /**  Server Config class, holds configuration file data
409          */
410         ServerConfig* Config;
411
412         /** Snomask manager - handles routing of snomask messages
413          * to opers.
414          */
415         SnomaskManager* SNO;
416
417         /** Client list, a hash_map containing all clients, local and remote
418          */
419         user_hash* clientlist;
420
421         /** Client list stored by UUID. Contains all clients, and is updated
422          * automatically by the constructor and destructor of User.
423          */
424         user_hash* uuidlist;
425
426         /** Channel list, a hash_map containing all channels
427          */
428         chan_hash* chanlist;
429
430         /** Local client list, a vector containing only local clients
431          */
432         std::vector<User*> local_users;
433
434         /** Oper list, a vector containing all local and remote opered users
435          */
436         std::list<User*> all_opers;
437
438         /** Map of local ip addresses for clone counting
439          */
440         clonemap local_clones;
441
442         /** Map of global ip addresses for clone counting
443          */
444         clonemap global_clones;
445
446         /** DNS class, provides resolver facilities to the core and modules
447          */
448         DNS* Res;
449
450         /** Timer manager class, triggers Timer timer events
451          */
452         TimerManager* Timers;
453
454         /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
455          */
456         XLineManager* XLines;
457
458         /** Set to the current signal recieved
459          */
460         int s_signal;
461
462         /** Get the current time
463          * Because this only calls time() once every time around the mainloop,
464          * it is much faster than calling time() directly.
465          * @param delta True to use the delta as an offset, false otherwise
466          * @return The current time as an epoch value (time_t)
467          */
468         time_t Time(bool delta = false);
469
470         /** Set the time offset in seconds
471          * This offset is added to Time() to offset the system time by the specified
472          * number of seconds.
473          * @param delta The number of seconds to offset
474          * @return The old time delta
475          */
476         int SetTimeDelta(int delta);
477
478         /** Add a user to the local clone map
479          * @param user The user to add
480          */
481         void AddLocalClone(User* user);
482
483         /** Add a user to the global clone map
484          * @param user The user to add
485          */
486         void AddGlobalClone(User* user);
487         
488         /** Number of users with a certain mode set on them
489          */
490         int ModeCount(const char mode);
491
492         /** Get the time offset in seconds
493          * @return The current time delta (in seconds)
494          */
495         int GetTimeDelta();
496
497         /** Process a user whos socket has been flagged as active
498          * @param cu The user to process
499          * @return There is no actual return value, however upon exit, the user 'cu' may have been
500          * marked for deletion in the global CullList.
501          */
502         caller1<void, User*> ProcessUser;
503
504         /** Bind all ports specified in the configuration file.
505          * @param bail True if the function should bail back to the shell on failure
506          * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
507          * @return The number of ports actually bound without error
508          */
509         int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
510
511         /** Binds a socket on an already open file descriptor
512          * @param sockfd A valid file descriptor of an open socket
513          * @param port The port number to bind to
514          * @param addr The address to bind to (IP only)
515          * @return True if the port was bound successfully
516          */
517         bool BindSocket(int sockfd, int port, char* addr, bool dolisten = true);
518
519         /** Adds a server name to the list of servers we've seen
520          * @param The servername to add
521          */
522         void AddServerName(const std::string &servername);
523
524         /** Finds a cached char* pointer of a server name,
525          * This is used to optimize User by storing only the pointer to the name
526          * @param The servername to find
527          * @return A pointer to this name, gauranteed to never become invalid
528          */
529         const char* FindServerNamePtr(const std::string &servername);
530
531         /** Returns true if we've seen the given server name before
532          * @param The servername to find
533          * @return True if we've seen this server name before
534          */
535         bool FindServerName(const std::string &servername);
536
537         /** Gets the GECOS (description) field of the given server.
538          * If the servername is not that of the local server, the name
539          * is passed to handling modules which will attempt to determine
540          * the GECOS that bleongs to the given servername.
541          * @param servername The servername to find the description of
542          * @return The description of this server, or of the local server
543          */
544         std::string GetServerDescription(const char* servername);
545
546         /** Write text to all opers connected to this server
547          * @param text The text format string
548          * @param ... Format args
549          */
550         void WriteOpers(const char* text, ...);
551
552         /** Write text to all opers connected to this server
553          * @param text The text to send
554          */
555         void WriteOpers(const std::string &text);
556
557         /** Find a user in the nick hash.
558          * If the user cant be found in the nick hash check the uuid hash
559          * @param nick The nickname to find
560          * @return A pointer to the user, or NULL if the user does not exist
561          */
562         User* FindNick(const std::string &nick);
563
564         /** Find a user in the nick hash.
565          * If the user cant be found in the nick hash check the uuid hash
566          * @param nick The nickname to find
567          * @return A pointer to the user, or NULL if the user does not exist
568          */
569         User* FindNick(const char* nick);
570
571         /** Find a user in the nick hash ONLY
572          */
573         User* FindNickOnly(const char* nick);
574
575         /** Find a user in the nick hash ONLY
576          */
577         User* FindNickOnly(const std::string &nick);
578
579         /** Find a channel in the channels hash
580          * @param chan The channel to find
581          * @return A pointer to the channel, or NULL if the channel does not exist
582          */
583         Channel* FindChan(const std::string &chan);
584
585         /** Find a channel in the channels hash
586          * @param chan The channel to find
587          * @return A pointer to the channel, or NULL if the channel does not exist
588          */
589         Channel* FindChan(const char* chan);
590
591         /** Check for a 'die' tag in the config file, and abort if found
592          * @return Depending on the configuration, this function may never return
593          */
594         void CheckDie();
595
596         /** Check we aren't running as root, and exit if we are
597          * @return Depending on the configuration, this function may never return
598          */
599         void CheckRoot();
600
601         /** Determine the right path for, and open, the logfile
602          * @param argv The argv passed to main() initially, used to calculate program path
603          * @param argc The argc passed to main() initially, used to calculate program path
604          * @return True if the log could be opened, false if otherwise
605          */
606         bool OpenLog(char** argv, int argc);
607
608         /** Close the currently open log file
609          */
610         void CloseLog();
611
612         /** Send a server notice to all local users
613          * @param text The text format string to send
614          * @param ... The format arguments
615          */
616         void ServerNoticeAll(char* text, ...);
617
618         /** Send a server message (PRIVMSG) to all local users
619          * @param text The text format string to send
620          * @param ... The format arguments
621          */
622         void ServerPrivmsgAll(char* text, ...);
623
624         /** Send text to all users with a specific set of modes
625          * @param modes The modes to check against, without a +, e.g. 'og'
626          * @param flags one of WM_OR or WM_AND. If you specify WM_OR, any one of the
627          * mode characters in the first parameter causes receipt of the message, and
628          * if you specify WM_OR, all the modes must be present.
629          * @param text The text format string to send
630          * @param ... The format arguments
631          */
632         void WriteMode(const char* modes, int flags, const char* text, ...);
633
634         /** Return true if a channel name is valid
635          * @param chname A channel name to verify
636          * @return True if the name is valid
637          */
638         bool IsChannel(const char *chname);
639
640         /** Rehash the local server
641          */
642         void Rehash();
643
644         /** Handles incoming signals after being set
645          * @param signal the signal recieved
646          */
647         void SignalHandler(int signal);
648
649         /** Sets the signal recieved    
650          * @param signal the signal recieved
651          */
652         static void SetSignal(int signal);
653
654         /** Causes the server to exit after unloading modules and
655          * closing all open file descriptors.
656          *
657          * @param The exit code to give to the operating system
658          * (See the ExitStatus enum for valid values)
659          */
660         void Exit(int status);
661
662         /** Causes the server to exit immediately with exit code 0.
663          * The status code is required for signal handlers, and ignored.
664          */
665         static void QuickExit(int status);
666
667         /** Return a count of users, unknown and known connections
668          * @return The number of users
669          */
670         int UserCount();
671
672         /** Return a count of fully registered connections only
673          * @return The number of registered users
674          */
675         int RegisteredUserCount();
676
677         /** Return a count of opered (umode +o) users only
678          * @return The number of opers
679          */
680         int OperCount();
681
682         /** Return a count of unregistered (before NICK/USER) users only
683          * @return The number of unregistered (unknown) connections
684          */
685         int UnregisteredUserCount();
686
687         /** Return a count of channels on the network
688          * @return The number of channels
689          */
690         long ChannelCount();
691
692         /** Return a count of local users on this server only
693          * @return The number of local users
694          */
695         long LocalUserCount();
696
697         /** Send an error notice to all local users, opered and unopered
698          * @param s The error string to send
699          */
700         void SendError(const std::string &s);
701
702         /** Return true if a nickname is valid
703          * @param n A nickname to verify
704          * @return True if the nick is valid
705          */
706         caller1<bool, const char*> IsNick;
707
708         /** Return true if an ident is valid
709          * @param An ident to verify
710          * @return True if the ident is valid
711          */
712         caller1<bool, const char*> IsIdent;
713
714         /** Find a username by their file descriptor.
715          * It is preferred to use this over directly accessing the fd_ref_table array.
716          * @param socket The file descriptor of a user
717          * @return A pointer to the user if the user exists locally on this descriptor
718          */
719         caller1<User*, int> FindDescriptor;
720
721         /** Add a new mode to this server's mode parser
722          * @param mh The modehandler to add
723          * @return True if the mode handler was added
724          */
725         bool AddMode(ModeHandler* mh);
726
727         /** Add a new mode watcher to this server's mode parser
728          * @param mw The modewatcher to add
729          * @return True if the modewatcher was added
730          */
731         bool AddModeWatcher(ModeWatcher* mw);
732
733         /** Delete a mode watcher from this server's mode parser
734          * @param mw The modewatcher to delete
735          * @return True if the modewatcher was deleted
736          */
737         bool DelModeWatcher(ModeWatcher* mw);
738
739         /** Add a dns Resolver class to this server's active set
740          * @param r The resolver to add
741          * @param cached If this value is true, then the cache will
742          * be searched for the DNS result, immediately. If the value is
743          * false, then a request will be sent to the nameserver, and the
744          * result will not be immediately available. You should usually
745          * use the boolean value which you passed to the Resolver
746          * constructor, which Resolver will set appropriately depending
747          * on if cached results are available and haven't expired. It is
748          * however safe to force this value to false, forcing a remote DNS
749          * lookup, but not an update of the cache.
750          * @return True if the operation completed successfully. Note that
751          * if this method returns true, you should not attempt to access
752          * the resolver class you pass it after this call, as depending upon
753          * the request given, the object may be deleted!
754          */
755         bool AddResolver(Resolver* r, bool cached);
756
757         /** Add a command to this server's command parser
758          * @param f A Command command handler object to add
759          * @throw ModuleException Will throw ModuleExcption if the command already exists
760          */
761         void AddCommand(Command *f);
762
763         /** Send a modechange.
764          * The parameters provided are identical to that sent to the
765          * handler for class cmd_mode.
766          * @param parameters The mode parameters
767          * @param pcnt The number of items you have given in the first parameter
768          * @param user The user to send error messages to
769          */
770         void SendMode(const char **parameters, int pcnt, User *user);
771
772         /** Match two strings using pattern matching.
773          * This operates identically to the global function match(),
774          * except for that it takes std::string arguments rather than
775          * const char* ones.
776          * @param sliteral The literal string to match against
777          * @param spattern The pattern to match against. CIDR and globs are supported.
778          */
779         bool MatchText(const std::string &sliteral, const std::string &spattern);
780
781         /** Call the handler for a given command.
782          * @param commandname The command whos handler you wish to call
783          * @param parameters The mode parameters
784          * @param pcnt The number of items you have given in the first parameter
785          * @param user The user to execute the command as
786          * @return True if the command handler was called successfully
787          */
788         CmdResult CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, User* user);
789
790         /** Return true if the command is a module-implemented command and the given parameters are valid for it
791          * @param parameters The mode parameters
792          * @param pcnt The number of items you have given in the first parameter
793          * @param user The user to test-execute the command as
794          * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
795          */
796         bool IsValidModuleCommand(const std::string &commandname, int pcnt, User* user);
797
798         /** Return true if the given parameter is a valid nick!user\@host mask
799          * @param mask A nick!user\@host masak to match against
800          * @return True i the mask is valid
801          */
802         bool IsValidMask(const std::string &mask);
803
804         /** Rehash the local server
805          */
806         void RehashServer();
807
808         /** Return the channel whos index number matches that provided
809          * @param The index number of the channel to fetch
810          * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
811          */
812         Channel* GetChannelIndex(long index);
813
814         /** Dump text to a user target, splitting it appropriately to fit
815          * @param User the user to dump the text to
816          * @param LinePrefix text to prefix each complete line with
817          * @param TextStream the text to send to the user
818          */
819         void DumpText(User* User, const std::string &LinePrefix, stringstream &TextStream);
820
821         /** Check if the given nickmask matches too many users, send errors to the given user
822          * @param nick A nickmask to match against
823          * @param user A user to send error text to
824          * @return True if the nick matches too many users
825          */
826         bool NickMatchesEveryone(const std::string &nick, User* user);
827
828         /** Check if the given IP mask matches too many users, send errors to the given user
829          * @param ip An ipmask to match against
830          * @param user A user to send error text to
831          * @return True if the ip matches too many users
832          */
833         bool IPMatchesEveryone(const std::string &ip, User* user);
834
835         /** Check if the given hostmask matches too many users, send errors to the given user
836          * @param mask A hostmask to match against
837          * @param user A user to send error text to
838          * @return True if the host matches too many users
839          */
840         bool HostMatchesEveryone(const std::string &mask, User* user);
841
842         /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
843          * @param str A string containing a time in the form 1y2w3d4h6m5s
844          * (one year, two weeks, three days, four hours, six minutes and five seconds)
845          * @return The total number of seconds
846          */
847         long Duration(const std::string &str);
848
849         /** Attempt to compare an oper password to a string from the config file.
850          * This will be passed to handling modules which will compare the data
851          * against possible hashed equivalents in the input string.
852          * @param data The data from the config file
853          * @param input The data input by the oper
854          * @param tagnum the tag number of the oper's tag in the config file
855          * @return 0 if the strings match, 1 or -1 if they do not
856          */
857         int OperPassCompare(const char* data,const char* input, int tagnum);
858
859         /** Check if a given server is a uline.
860          * An empty string returns true, this is by design.
861          * @param server The server to check for uline status
862          * @return True if the server is a uline OR the string is empty
863          */
864         bool ULine(const char* server);
865
866         /** Returns true if the uline is 'silent' (doesnt generate
867          * remote connect notices etc).
868          */
869         bool SilentULine(const char* server);
870
871         /** Returns the subversion revision ID of this ircd
872          * @return The revision ID or an empty string
873          */
874         std::string GetRevision();
875
876         /** Returns the full version string of this ircd
877          * @return The version string
878          */
879         std::string GetVersionString();
880
881         /** Attempt to write the process id to a given file
882          * @param filename The PID file to attempt to write to
883          * @return This function may bail if the file cannot be written
884          */
885         void WritePID(const std::string &filename);
886
887         /** This constructor initialises all the subsystems and reads the config file.
888          * @param argc The argument count passed to main()
889          * @param argv The argument list passed to main()
890          * @throw <anything> If anything is thrown from here and makes it to
891          * you, you should probably just give up and go home. Yes, really.
892          * It's that bad. Higher level classes should catch any non-fatal exceptions.
893          */
894         InspIRCd(int argc, char** argv);
895
896         /** Output a log message to the ircd.log file
897          * The text will only be output if the current loglevel
898          * is less than or equal to the level you provide
899          * @param level A log level from the DebugLevel enum
900          * @param text Format string of to write to the log
901          * @param ... Format arguments of text to write to the log
902          */
903         void Log(int level, const char* text, ...);
904
905         /** Output a log message to the ircd.log file
906          * The text will only be output if the current loglevel
907          * is less than or equal to the level you provide
908          * @param level A log level from the DebugLevel enum
909          * @param text Text to write to the log
910          */
911         void Log(int level, const std::string &text);
912
913         /** Send a line of WHOIS data to a user.
914          * @param user user to send the line to
915          * @param dest user being WHOISed
916          * @param numeric Numeric to send
917          * @param text Text of the numeric
918          */
919         void SendWhoisLine(User* user, User* dest, int numeric, const std::string &text);
920
921         /** Send a line of WHOIS data to a user.
922          * @param user user to send the line to
923          * @param dest user being WHOISed
924          * @param numeric Numeric to send
925          * @param format Format string for the numeric
926          * @param ... Parameters for the format string
927          */
928         void SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...);
929
930         /** Quit a user for excess flood, and if they are not
931          * fully registered yet, temporarily zline their IP.
932          * @param current user to quit
933          */
934         caller1<void, User*> FloodQuitUser;
935
936         /** Restart the server.
937          * This function will not return. If an error occurs,
938          * it will throw an instance of CoreException.
939          * @param reason The restart reason to show to all clients
940          * @throw CoreException An instance of CoreException indicating the error from execv().
941          */
942         void Restart(const std::string &reason);
943
944         /** Prepare the ircd for restart or shutdown.
945          * This function unloads all modules which can be unloaded,
946          * closes all open sockets, and closes the logfile.
947          */
948         void Cleanup();
949
950         /** This copies the user and channel hash_maps into new hash maps.
951          * This frees memory used by the hash_map allocator (which it neglects
952          * to free, most of the time, using tons of ram)
953          */
954         void RehashUsersAndChans();
955
956         /** Resets the cached max bans value on all channels.
957          * Called by rehash.
958          */
959         void ResetMaxBans();
960
961         /** Return a time_t as a human-readable string.
962          */
963         std::string TimeString(time_t curtime);
964
965         /** Begin execution of the server.
966          * NOTE: this function NEVER returns. Internally,
967          * it will repeatedly loop.
968          * @return The return value for this function is undefined.
969          */
970         int Run();
971
972         /** Force all BufferedSockets to be removed which are due to
973          * be culled.
974          */
975         void BufferedSocketCull();
976
977         char* GetReadBuffer()
978         {
979                 return this->ReadBuffer;
980         }
981 };
982
983 #endif