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