]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
Move forward declarations to typedefs.h
[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 #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 "configreader.h"
83 #include "inspstring.h"
84 #include "protocol.h"
85 #include "threadengine.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         timeval 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_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
243 /** The background thread for config reading, so that reading from executable includes
244  * does not block.
245  */
246 class CoreExport ConfigReaderThread : public Thread
247 {
248         ServerConfig* Config;
249         volatile bool done;
250  public:
251         const std::string TheUserUID;
252         ConfigReaderThread(const std::string &useruid)
253                 : Config(new ServerConfig), done(false), TheUserUID(useruid)
254         {
255         }
256
257         virtual ~ConfigReaderThread()
258         {
259                 delete Config;
260         }
261
262         void Run();
263         /** Run in the main thread to apply the configuration */
264         void Finish();
265         bool IsDone() { return done; }
266 };
267
268 /** The main class of the irc server.
269  * This class contains instances of all the other classes in this software.
270  * Amongst other things, it contains a ModeParser, a DNS object, a CommandParser
271  * object, and a list of active Module objects, and facilities for Module
272  * objects to interact with the core system it implements.
273  */
274 class CoreExport InspIRCd
275 {
276  private:
277         /** Holds the current UID. Used to generate the next one.
278          */
279         char current_uid[UUID_LENGTH];
280
281         /** Set up the signal handlers
282          */
283         void SetSignals();
284
285         /** Daemonize the ircd and close standard input/output streams
286          * @return True if the program daemonized succesfully
287          */
288         bool DaemonSeed();
289
290         /** Iterate the list of BufferedSocket objects, removing ones which have timed out
291          * @param TIME the current time
292          */
293         void DoSocketTimeouts(time_t TIME);
294
295         /** Increments the current UID by one.
296          */
297         void IncrementUID(int pos);
298
299         /** Perform background user events such as PING checks
300          */
301         void DoBackgroundUserStuff();
302
303         /** Returns true when all modules have done pre-registration checks on a user
304          * @param user The user to verify
305          * @return True if all modules have finished checking this user
306          */
307         bool AllModulesReportReady(LocalUser* user);
308
309         /** The current time, updated in the mainloop
310          */
311         time_t TIME;
312
313         /** The time that was recorded last time around the mainloop
314          */
315         time_t OLDTIME;
316
317         /** A 64k buffer used to read socket data into
318          * NOTE: update ValidateNetBufferSize if you change this
319          */
320         char ReadBuffer[65535];
321
322 #ifdef WIN32
323         IPC* WindowsIPC;
324 #endif
325
326  public:
327
328         /** Global cull list, will be processed on next iteration
329          */
330         CullList GlobalCulls;
331         /** Actions that must happen outside of the current call stack */
332         ActionList AtomicActions;
333
334         /**** Functors ****/
335
336         IsNickHandler HandleIsNick;
337         IsIdentHandler HandleIsIdent;
338         FloodQuitUserHandler HandleFloodQuitUser;
339         IsChannelHandler HandleIsChannel;
340         IsSIDHandler HandleIsSID;
341         RehashHandler HandleRehash;
342
343         /** 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
344          * Reason for it:
345          * kludge alert!
346          * SendMode expects a User* to send the numeric replies
347          * back to, so we create it a fake user that isnt in the user
348          * hash and set its descriptor to FD_MAGIC_NUMBER so the data
349          * falls into the abyss :p
350          */
351         FakeUser* FakeClient;
352
353         /** Returns the next available UID for this server.
354          */
355         std::string GetUID();
356
357         /** Find a user in the UUID hash
358          * @param nick The nickname to find
359          * @return A pointer to the user, or NULL if the user does not exist
360          */
361         User* FindUUID(const std::string &);
362
363         /** Find a user in the UUID hash
364          * @param nick The nickname to find
365          * @return A pointer to the user, or NULL if the user does not exist
366          */
367         User* FindUUID(const char *);
368
369         /** Build the ISUPPORT string by triggering all modules On005Numeric events
370          */
371         void BuildISupport();
372
373         /** Time this ircd was booted
374          */
375         time_t startup_time;
376
377         /** Config file pathname specified on the commandline or via ./configure
378          */
379         std::string ConfigFileName;
380
381         ExtensionManager Extensions;
382
383         /** Mode handler, handles mode setting and removal
384          */
385         ModeParser* Modes;
386
387         /** Command parser, handles client to server commands
388          */
389         CommandParser* Parser;
390
391         /** Socket engine, handles socket activity events
392          */
393         SocketEngine* SE;
394
395         /** Thread engine, Handles threading where required
396          */
397         ThreadEngine* Threads;
398
399         /** The thread/class used to read config files in REHASH and on startup
400          */
401         ConfigReaderThread* ConfigThread;
402
403         /** LogManager handles logging.
404          */
405         LogManager *Logs;
406
407         /** ModuleManager contains everything related to loading/unloading
408          * modules.
409          */
410         ModuleManager* Modules;
411
412         /** BanCacheManager is used to speed up checking of restrictions on connection
413          * to the IRCd.
414          */
415         BanCacheManager *BanCache;
416
417         /** Stats class, holds miscellaneous stats counters
418          */
419         serverstats* stats;
420
421         /**  Server Config class, holds configuration file data
422          */
423         ServerConfig* Config;
424
425         /** Snomask manager - handles routing of snomask messages
426          * to opers.
427          */
428         SnomaskManager* SNO;
429
430         /** DNS class, provides resolver facilities to the core and modules
431          */
432         DNS* Res;
433
434         /** Timer manager class, triggers Timer timer events
435          */
436         TimerManager* Timers;
437
438         /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
439          */
440         XLineManager* XLines;
441
442         /** User manager. Various methods and data associated with users.
443          */
444         UserManager *Users;
445
446         /** Channel list, a hash_map containing all channels XXX move to channel manager class
447          */
448         chan_hash* chanlist;
449
450         /** List of the open ports
451          */
452         std::vector<ListenSocket*> ports;
453
454         /** Set to the current signal recieved
455          */
456         int s_signal;
457
458         /** Protocol interface, overridden by server protocol modules
459          */
460         ProtocolInterface* PI;
461
462         /** Holds extensible for user nickforced
463          */
464         LocalIntExt NICKForced;
465
466         /** Holds extensible for user operquit
467          */
468         LocalStringExt OperQuit;
469
470         /** Get the current time
471          * Because this only calls time() once every time around the mainloop,
472          * it is much faster than calling time() directly.
473          * @return The current time as an epoch value (time_t)
474          */
475         time_t Time();
476
477         /** Bind all ports specified in the configuration file.
478          * @return The number of ports bound without error
479          */
480         int BindPorts(FailedPortList &failed_ports);
481
482         /** Binds a socket on an already open file descriptor
483          * @param sockfd A valid file descriptor of an open socket
484          * @param port The port number to bind to
485          * @param addr The address to bind to (IP only)
486          * @return True if the port was bound successfully
487          */
488         bool BindSocket(int sockfd, int port, const char* addr, bool dolisten = true);
489
490         /** Gets the GECOS (description) field of the given server.
491          * If the servername is not that of the local server, the name
492          * is passed to handling modules which will attempt to determine
493          * the GECOS that bleongs to the given servername.
494          * @param servername The servername to find the description of
495          * @return The description of this server, or of the local server
496          */
497         std::string GetServerDescription(const std::string& servername);
498
499         /** Find a user in the nick hash.
500          * If the user cant be found in the nick hash check the uuid hash
501          * @param nick The nickname to find
502          * @return A pointer to the user, or NULL if the user does not exist
503          */
504         User* FindNick(const std::string &nick);
505
506         /** Find a user in the nick hash.
507          * If the user cant be found in the nick hash check the uuid hash
508          * @param nick The nickname to find
509          * @return A pointer to the user, or NULL if the user does not exist
510          */
511         User* FindNick(const char* nick);
512
513         /** Find a user in the nick hash ONLY
514          */
515         User* FindNickOnly(const char* nick);
516
517         /** Find a user in the nick hash ONLY
518          */
519         User* FindNickOnly(const std::string &nick);
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 std::string &chan);
526
527         /** Find a channel in the channels hash
528          * @param chan The channel to find
529          * @return A pointer to the channel, or NULL if the channel does not exist
530          */
531         Channel* FindChan(const char* chan);
532
533         /** Check we aren't running as root, and exit if we are
534          * @return Depending on the configuration, this function may never return
535          */
536         void CheckRoot();
537
538         /** Determine the right path for, and open, the logfile
539          * @param argv The argv passed to main() initially, used to calculate program path
540          * @param argc The argc passed to main() initially, used to calculate program path
541          * @return True if the log could be opened, false if otherwise
542          */
543         bool OpenLog(char** argv, int argc);
544
545         /** Return true if a channel name is valid
546          * @param chname A channel name to verify
547          * @return True if the name is valid
548          */
549         caller2<bool, const char*, size_t> IsChannel;
550
551         /** Return true if str looks like a server ID
552          * @param string to check against
553          */
554         caller1<bool, const std::string&> IsSID;
555
556         /** Rehash the local server
557          */
558         caller1<void, const std::string&> Rehash;
559
560         /** Handles incoming signals after being set
561          * @param signal the signal recieved
562          */
563         void SignalHandler(int signal);
564
565         /** Sets the signal recieved
566          * @param signal the signal recieved
567          */
568         static void SetSignal(int signal);
569
570         /** Causes the server to exit after unloading modules and
571          * closing all open file descriptors.
572          *
573          * @param The exit code to give to the operating system
574          * (See the ExitStatus enum for valid values)
575          */
576         void Exit(int status);
577
578         /** Causes the server to exit immediately with exit code 0.
579          * The status code is required for signal handlers, and ignored.
580          */
581         static void QuickExit(int status);
582
583         /** Return a count of channels on the network
584          * @return The number of channels
585          */
586         long ChannelCount();
587
588         /** Send an error notice to all local users, opered and unopered
589          * @param s The error string to send
590          */
591         void SendError(const std::string &s);
592
593         /** Return true if a nickname is valid
594          * @param n A nickname to verify
595          * @return True if the nick is valid
596          */
597         caller2<bool, const char*, size_t> IsNick;
598
599         /** Return true if an ident is valid
600          * @param An ident to verify
601          * @return True if the ident is valid
602          */
603         caller1<bool, const char*> IsIdent;
604
605         /** Add a dns Resolver class to this server's active set
606          * @param r The resolver to add
607          * @param cached If this value is true, then the cache will
608          * be searched for the DNS result, immediately. If the value is
609          * false, then a request will be sent to the nameserver, and the
610          * result will not be immediately available. You should usually
611          * use the boolean value which you passed to the Resolver
612          * constructor, which Resolver will set appropriately depending
613          * on if cached results are available and haven't expired. It is
614          * however safe to force this value to false, forcing a remote DNS
615          * lookup, but not an update of the cache.
616          * @return True if the operation completed successfully. Note that
617          * if this method returns true, you should not attempt to access
618          * the resolver class you pass it after this call, as depending upon
619          * the request given, the object may be deleted!
620          */
621         bool AddResolver(Resolver* r, bool cached);
622
623         /** Add a command to this server's command parser
624          * @param f A Command command handler object to add
625          * @throw ModuleException Will throw ModuleExcption if the command already exists
626          */
627         void AddCommand(Command *f);
628
629         /** Send a modechange.
630          * The parameters provided are identical to that sent to the
631          * handler for class cmd_mode.
632          * @param parameters The mode parameters
633          * @param user The user to send error messages to
634          */
635         void SendMode(const std::vector<std::string>& parameters, User *user);
636
637         /** Match two strings using pattern matching, optionally, with a map
638          * to check case against (may be NULL). If map is null, match will be case insensitive.
639          * @param str The literal string to match against
640          * @param mask The glob pattern to match against.
641          */
642         static bool Match(const std::string &str, const std::string &mask, unsigned const char *map = NULL);
643         static bool Match(const  char *str, const char *mask, unsigned const char *map = NULL);
644
645         /** Match two strings using pattern matching, optionally, with a map
646          * to check case against (may be NULL). If map is null, match will be case insensitive.
647          * Supports CIDR patterns as well as globs.
648          * @param str The literal string to match against
649          * @param mask The glob or CIDR pattern to match against.
650          */
651         static bool MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map = NULL);
652         static bool MatchCIDR(const  char *str, const char *mask, unsigned const char *map = NULL);
653
654         /** Call the handler for a given command.
655          * @param commandname The command whos handler you wish to call
656          * @param parameters The mode parameters
657          * @param pcnt The number of items you have given in the first parameter
658          * @param user The user to execute the command as
659          * @return True if the command handler was called successfully
660          */
661         CmdResult CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user);
662
663         /** Return true if the command is a module-implemented command and the given parameters are valid for it
664          * @param parameters The mode parameters
665          * @param pcnt The number of items you have given in the first parameter
666          * @param user The user to test-execute the command as
667          * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
668          */
669         bool IsValidModuleCommand(const std::string &commandname, int pcnt, User* user);
670
671         /** Return true if the given parameter is a valid nick!user\@host mask
672          * @param mask A nick!user\@host masak to match against
673          * @return True i the mask is valid
674          */
675         bool IsValidMask(const std::string &mask);
676
677         /** Rehash the local server
678          */
679         void RehashServer();
680
681         /** Check if the given nickmask matches too many users, send errors to the given user
682          * @param nick A nickmask to match against
683          * @param user A user to send error text to
684          * @return True if the nick matches too many users
685          */
686         bool NickMatchesEveryone(const std::string &nick, User* user);
687
688         /** Check if the given IP mask matches too many users, send errors to the given user
689          * @param ip An ipmask to match against
690          * @param user A user to send error text to
691          * @return True if the ip matches too many users
692          */
693         bool IPMatchesEveryone(const std::string &ip, User* user);
694
695         /** Check if the given hostmask matches too many users, send errors to the given user
696          * @param mask A hostmask to match against
697          * @param user A user to send error text to
698          * @return True if the host matches too many users
699          */
700         bool HostMatchesEveryone(const std::string &mask, User* user);
701
702         /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
703          * @param str A string containing a time in the form 1y2w3d4h6m5s
704          * (one year, two weeks, three days, four hours, six minutes and five seconds)
705          * @return The total number of seconds
706          */
707         long Duration(const std::string &str);
708
709         /** Attempt to compare a password to a string from the config file.
710          * This will be passed to handling modules which will compare the data
711          * against possible hashed equivalents in the input string.
712          * @param ex The object (user, server, whatever) causing the comparison.
713          * @param data The data from the config file
714          * @param input The data input by the oper
715          * @param hashtype The hash from the config file
716          * @return 0 if the strings match, 1 or -1 if they do not
717          */
718         int PassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype);
719
720         /** Check if a given server is a uline.
721          * An empty string returns true, this is by design.
722          * @param server The server to check for uline status
723          * @return True if the server is a uline OR the string is empty
724          */
725         bool ULine(const std::string& server);
726
727         /** Returns true if the uline is 'silent' (doesnt generate
728          * remote connect notices etc).
729          */
730         bool SilentULine(const std::string& server);
731
732         /** Returns the full version string of this ircd
733          * @return The version string
734          */
735         std::string GetVersionString();
736
737         /** Attempt to write the process id to a given file
738          * @param filename The PID file to attempt to write to
739          * @return This function may bail if the file cannot be written
740          */
741         void WritePID(const std::string &filename);
742
743         /** This constructor initialises all the subsystems and reads the config file.
744          * @param argc The argument count passed to main()
745          * @param argv The argument list passed to main()
746          * @throw <anything> If anything is thrown from here and makes it to
747          * you, you should probably just give up and go home. Yes, really.
748          * It's that bad. Higher level classes should catch any non-fatal exceptions.
749          */
750         InspIRCd(int argc, char** argv);
751
752         /** Send a line of WHOIS data to a user.
753          * @param user user to send the line to
754          * @param dest user being WHOISed
755          * @param numeric Numeric to send
756          * @param text Text of the numeric
757          */
758         void SendWhoisLine(User* user, User* dest, int numeric, const std::string &text);
759
760         /** Send a line of WHOIS data to a user.
761          * @param user user to send the line to
762          * @param dest user being WHOISed
763          * @param numeric Numeric to send
764          * @param format Format string for the numeric
765          * @param ... Parameters for the format string
766          */
767         void SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...) CUSTOM_PRINTF(5, 6);
768
769         /** Handle /STATS
770          */
771         void DoStats(char statschar, User* user, string_list &results);
772
773         /** Handle /WHOIS
774          */
775         void DoWhois(User* user, User* dest,unsigned long signon, unsigned long idle, const char* nick);
776
777         /** Quit a user for excess flood, and if they are not
778          * fully registered yet, temporarily zline their IP.
779          * @param current user to quit
780          */
781         caller1<void, User*> FloodQuitUser;
782
783         /** Restart the server.
784          * This function will not return. If an error occurs,
785          * it will throw an instance of CoreException.
786          * @param reason The restart reason to show to all clients
787          * @throw CoreException An instance of CoreException indicating the error from execv().
788          */
789         void Restart(const std::string &reason);
790
791         /** Prepare the ircd for restart or shutdown.
792          * This function unloads all modules which can be unloaded,
793          * closes all open sockets, and closes the logfile.
794          */
795         void Cleanup();
796
797         /** This copies the user and channel hash_maps into new hash maps.
798          * This frees memory used by the hash_map allocator (which it neglects
799          * to free, most of the time, using tons of ram)
800          */
801         void RehashUsersAndChans();
802
803         /** Resets the cached max bans value on all channels.
804          * Called by rehash.
805          */
806         void ResetMaxBans();
807
808         /** Return a time_t as a human-readable string.
809          */
810         std::string TimeString(time_t curtime);
811
812         /** Begin execution of the server.
813          * NOTE: this function NEVER returns. Internally,
814          * it will repeatedly loop.
815          * @return The return value for this function is undefined.
816          */
817         int Run();
818
819         /** Adds an extban char to the 005 token.
820          */
821         void AddExtBanChar(char c);
822
823         char* GetReadBuffer()
824         {
825                 return this->ReadBuffer;
826         }
827 };
828
829 ENTRYPOINT;
830
831 template<class Cmd>
832 class CommandModule : public Module
833 {
834         Cmd cmd;
835  public:
836         CommandModule() : cmd(this)
837         {
838                 ServerInstance->AddCommand(&cmd);
839         }
840
841         Version GetVersion()
842         {
843                 return Version(cmd.command, VF_VENDOR|VF_CORE);
844         }
845 };
846
847 #endif