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