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