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