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