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