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