1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #ifndef __INSPIRCD_H__
18 #define __INSPIRCD_H__
23 #include "inspircd_config.h"
28 #include "socketengine.h"
29 #include "command_parse.h"
32 /** Returned by some functions to indicate failure,
33 * and the exit code of the program if it terminates.
39 #define ETIREDGERBILS EAGAIN
41 /** Debug levels for use with InspIRCd::Log()
53 * This define is used in place of strcmp when we
54 * want to check if a char* string contains only one
55 * letter. Pretty fast, its just two compares and an
58 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
60 /** Delete a pointer, and NULL its value
62 template<typename T> inline void DELETE(T* x)
68 /** Template function to convert any input type to std::string
70 template<typename T> inline std::string ConvToStr(const T &in)
72 std::stringstream tmp;
73 if (!(tmp << in)) return std::string();
77 /** This class contains various STATS counters
78 * It is used by the InspIRCd class, which internally
79 * has an instance of it.
81 class serverstats : public classbase
84 /** Number of accepted connections
86 unsigned long statsAccept;
87 /** Number of failed accepts
89 unsigned long statsRefused;
90 /** Number of unknown commands seen
92 unsigned long statsUnknown;
93 /** Number of nickname collisions handled
95 unsigned long statsCollisions;
96 /** Number of DNS queries sent out
98 unsigned long statsDns;
99 /** Number of good DNS replies received
100 * NOTE: This may not tally to the number sent out,
101 * due to timeouts and other latency issues.
103 unsigned long statsDnsGood;
104 /** Number of bad (negative) DNS replies received
105 * NOTE: This may not tally to the number sent out,
106 * due to timeouts and other latency issues.
108 unsigned long statsDnsBad;
109 /** Number of inbound connections seen
111 unsigned long statsConnects;
112 /** Total bytes of data transmitted
115 /** Total bytes of data received
118 /** Number of bound listening ports
120 unsigned long BoundPortCount;
122 /** The constructor initializes all the counts to zero
125 : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
126 statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0.0), statsRecv(0.0),
134 /** This class implements a nonblocking log-writer.
135 * Most people writing an ircd give little thought to their disk
136 * i/o. On a congested system, disk writes can block for long
137 * periods of time (e.g. if the system is busy and/or swapping
138 * a lot). If we just use a blocking fprintf() call, this could
139 * block for undesirable amounts of time (half of a second through
140 * to whole seconds). We DO NOT want this, so we make our logfile
141 * nonblocking and hook it into the SocketEngine.
142 * NB: If the operating system does not support nonblocking file
143 * I/O (linux seems to, as does freebsd) this will default to
144 * blocking behaviour.
146 class FileLogger : public EventHandler
149 /** The creator/owner of this object
151 InspIRCd* ServerInstance;
152 /** The log file (fd is inside this somewhere,
153 * we get it out with fileno())
156 /** Buffer of pending log lines to be written
159 /** Number of write operations that have occured
163 /** The constructor takes an already opened logfile.
165 FileLogger(InspIRCd* Instance, FILE* logfile);
166 /** This returns false, logfiles are writeable.
168 virtual bool Readable();
169 /** Handle pending write events.
170 * This will flush any waiting data to disk.
171 * If any data remains after the fprintf call,
172 * another write event is scheduled to write
173 * the rest of the data when possible.
175 virtual void HandleEvent(EventType et, int errornum = 0);
176 /** Write one or more preformatted log lines.
177 * If the data cannot be written immediately,
178 * this class will insert itself into the
179 * SocketEngine, and register a write event,
180 * and when the write event occurs it will
181 * attempt again to write the data.
183 void WriteLogLine(const std::string &line);
184 /** Close the log file and cancel any events.
186 virtual void Close();
187 /** Close the log file and cancel any events.
188 * (indirectly call Close()
190 virtual ~FileLogger();
195 /** The main class of the irc server.
196 * This class contains instances of all the other classes
197 * in this software, with the exception of the base class,
198 * classbase. Amongst other things, it contains a ModeParser,
199 * a DNS object, a CommandParser object, and a list of active
200 * Module objects, and facilities for Module objects to
201 * interact with the core system it implements. You should
202 * NEVER attempt to instantiate a class of type InspIRCd
203 * yourself. If you do, this is equivalent to spawning a second
204 * IRC server, and could have catastrophic consequences for the
205 * program in terms of ram usage (basically, you could create
206 * an obese forkbomb built from recursively spawning irc servers!)
208 class InspIRCd : public classbase
211 /** Holds a string describing the last module error to occur
215 /** Remove a ModuleFactory pointer
216 * @param j Index number of the ModuleFactory to remove
218 void EraseFactory(int j);
220 /** Remove a Module pointer
221 * @param j Index number of the Module to remove
223 void EraseModule(int j);
225 /** Build the ISUPPORT string by triggering all modules On005Numeric events
227 void BuildISupport();
229 /** Move a given module to a specific slot in the list
230 * @param modulename The module name to relocate
231 * @param slot The slot to move the module into
233 void MoveTo(std::string modulename,int slot);
235 /** Display the startup banner
239 /** Set up the signal handlers
243 /** Daemonize the ircd and close standard input/output streams
244 * @return True if the program daemonized succesfully
248 /** Moves the given module to the last slot in the list
249 * @param modulename The module name to relocate
251 void MoveToLast(std::string modulename);
253 /** Moves the given module to the first slot in the list
254 * @param modulename The module name to relocate
256 void MoveToFirst(std::string modulename);
258 /** Moves one module to be placed after another in the list
259 * @param modulename The module name to relocate
260 * @param after The module name to place the module after
262 void MoveAfter(std::string modulename, std::string after);
264 /** Moves one module to be placed before another in the list
265 * @param modulename The module name to relocate
266 * @param after The module name to place the module before
268 void MoveBefore(std::string modulename, std::string before);
270 /** Iterate the list of InspSocket objects, removing ones which have timed out
271 * @param TIME the current time
273 void DoSocketTimeouts(time_t TIME);
275 /** Perform background user events such as PING checks
276 * @param TIME the current time
278 void DoBackgroundUserStuff(time_t TIME);
280 /** Returns true when all modules have done pre-registration checks on a user
281 * @param user The user to verify
282 * @return True if all modules have finished checking this user
284 bool AllModulesReportReady(userrec* user);
286 /** Total number of modules loaded into the ircd, minus one
290 /** Logfile pathname specified on the commandline, or empty string
292 char LogFileName[MAXBUF];
294 /** The feature names published by various modules
296 featurelist Features;
298 /** The current time, updated in the mainloop
302 /** The time that was recorded last time around the mainloop
306 /** A 64k buffer used to read client lines into
308 char ReadBuffer[65535];
310 /** Number of seconds in a minute
312 const long duration_m;
314 /** Number of seconds in an hour
316 const long duration_h;
318 /** Number of seconds in a day
320 const long duration_d;
322 /** Number of seconds in a week
324 const long duration_w;
326 /** Number of seconds in a year
328 const long duration_y;
330 /** Used when connecting clients
332 insp_sockaddr client, server;
334 /** Used when connecting clients
338 /** Nonblocking file writer
342 /** Time offset in seconds
343 * This offset is added to all calls to Time(). Use SetTimeDelta() to update
348 /** List of server names we've seen.
350 servernamelist servernames;
352 /** Time this ircd was booted
356 /** Mode handler, handles mode setting and removal
360 /** Command parser, handles client to server commands
362 CommandParser* Parser;
364 /** Socket engine, handles socket activity events
368 /** Stats class, holds miscellaneous stats counters
372 /** Server Config class, holds configuration file data
374 ServerConfig* Config;
376 /** Snomask manager - handles routing of snomask messages
381 /** Client list, a hash_map containing all clients, local and remote
383 user_hash clientlist;
385 /** Channel list, a hash_map containing all channels
389 /** Local client list, a vector containing only local clients
391 std::vector<userrec*> local_users;
393 /** Oper list, a vector containing all local and remote opered users
395 std::vector<userrec*> all_opers;
397 /** Whowas container, contains a map of vectors of users tracked by WHOWAS
399 irc::whowas::whowas_users whowas;
401 /** DNS class, provides resolver facilities to the core and modules
405 /** Timer manager class, triggers InspTimer timer events
407 TimerManager* Timers;
409 /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
411 XLineManager* XLines;
413 /** A list of Module* module classes
414 * Note that this list is always exactly 255 in size.
415 * The actual number of loaded modules is available from GetModuleCount()
419 /** A list of ModuleFactory* module factories
420 * Note that this list is always exactly 255 in size.
421 * The actual number of loaded modules is available from GetModuleCount()
425 /** The time we next call our ping timeout and reg timeout checks
429 /** Get the current time
430 * Because this only calls time() once every time around the mainloop,
431 * it is much faster than calling time() directly.
432 * @param delta True to use the delta as an offset, false otherwise
433 * @return The current time as an epoch value (time_t)
435 time_t Time(bool delta = false);
437 /** Set the time offset in seconds
438 * This offset is added to Time() to offset the system time by the specified
440 * @param delta The number of seconds to offset
441 * @return The old time delta
443 int SetTimeDelta(int delta);
445 /** Process a user whos socket has been flagged as active
446 * @param cu The user to process
447 * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
449 void ProcessUser(userrec* cu);
451 /** Get the total number of currently loaded modules
452 * @return The number of loaded modules
454 int GetModuleCount();
456 /** Find a module by name, and return a Module* to it.
457 * This is preferred over iterating the module lists yourself.
458 * @param name The module name to look up
459 * @return A pointer to the module, or NULL if the module cannot be found
461 Module* FindModule(const std::string &name);
463 /** Bind all ports specified in the configuration file.
464 * @param bail True if the function should bail back to the shell on failure
465 * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
466 * @return The number of ports actually bound without error
468 int BindPorts(bool bail, int &found_ports);
470 /** Returns true if this server has the given port bound to the given address
471 * @param port The port number
472 * @param addr The address
473 * @return True if we have a port listening on this address
475 bool HasPort(int port, char* addr);
477 /** Binds a socket on an already open file descriptor
478 * @param sockfd A valid file descriptor of an open socket
479 * @param client A sockaddr to use as temporary storage
480 * @param server A sockaddr to use as temporary storage
481 * @param port The port number to bind to
482 * @param addr The address to bind to (IP only)
483 * @return True if the port was bound successfully
485 bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
487 /** Adds a server name to the list of servers we've seen
488 * @param The servername to add
490 void AddServerName(const std::string &servername);
492 /** Finds a cached char* pointer of a server name,
493 * This is used to optimize userrec by storing only the pointer to the name
494 * @param The servername to find
495 * @return A pointer to this name, gauranteed to never become invalid
497 const char* FindServerNamePtr(const std::string &servername);
499 /** Returns true if we've seen the given server name before
500 * @param The servername to find
501 * @return True if we've seen this server name before
503 bool FindServerName(const std::string &servername);
505 /** Gets the GECOS (description) field of the given server.
506 * If the servername is not that of the local server, the name
507 * is passed to handling modules which will attempt to determine
508 * the GECOS that bleongs to the given servername.
509 * @param servername The servername to find the description of
510 * @return The description of this server, or of the local server
512 std::string GetServerDescription(const char* servername);
514 /** Write text to all opers connected to this server
515 * @param text The text format string
516 * @param ... Format args
518 void WriteOpers(const char* text, ...);
520 /** Write text to all opers connected to this server
521 * @param text The text to send
523 void WriteOpers(const std::string &text);
525 /** Find a nickname in the nick hash
526 * @param nick The nickname to find
527 * @return A pointer to the user, or NULL if the user does not exist
529 userrec* FindNick(const std::string &nick);
531 /** Find a nickname in the nick hash
532 * @param nick The nickname to find
533 * @return A pointer to the user, or NULL if the user does not exist
535 userrec* FindNick(const char* nick);
537 /** Find a channel in the channels hash
538 * @param chan The channel to find
539 * @return A pointer to the channel, or NULL if the channel does not exist
541 chanrec* FindChan(const std::string &chan);
543 /** Find a channel in the channels hash
544 * @param chan The channel to find
545 * @return A pointer to the channel, or NULL if the channel does not exist
547 chanrec* FindChan(const char* chan);
549 /** Called by the constructor to load all modules from the config file.
551 void LoadAllModules();
553 /** Check for a 'die' tag in the config file, and abort if found
554 * @return Depending on the configuration, this function may never return
558 /** Check we aren't running as root, and exit if we are
559 * @return Depending on the configuration, this function may never return
563 /** Determine the right path for, and open, the logfile
564 * @param argv The argv passed to main() initially, used to calculate program path
565 * @param argc The argc passed to main() initially, used to calculate program path
567 void OpenLog(char** argv, int argc);
569 /** Convert a user to a pseudoclient, disconnecting the real user
570 * @param user The user to convert
571 * @param message The quit message to display when exiting the user
572 * @return True if the operation succeeded
574 bool UserToPseudo(userrec* user, const std::string &message);
576 /** Convert a pseudoclient to a real user, discarding the pseudoclient
577 * @param alive A live client
578 * @param zombie A pseudoclient
579 * @param message The message to display when quitting the pseudoclient
580 * @return True if the operation succeeded
582 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
584 /** Send a server notice to all local users
585 * @param text The text format string to send
586 * @param ... The format arguments
588 void ServerNoticeAll(char* text, ...);
590 /** Send a server message (PRIVMSG) to all local users
591 * @param text The text format string to send
592 * @param ... The format arguments
594 void ServerPrivmsgAll(char* text, ...);
596 /** Send text to all users with a specific set of modes
597 * @param modes The modes to check against, without a +, e.g. 'og'
598 * @param flags one of WM_OR or WM_AND. If you specify WM_OR, any one of the
599 * mode characters in the first parameter causes receipt of the message, and
600 * if you specify WM_OR, all the modes must be present.
601 * @param text The text format string to send
602 * @param ... The format arguments
604 void WriteMode(const char* modes, int flags, const char* text, ...);
606 /** Return true if a channel name is valid
607 * @param chname A channel name to verify
608 * @return True if the name is valid
610 bool IsChannel(const char *chname);
612 /** Rehash the local server
613 * @param status This value is unused, and required for signal handler functions
615 static void Rehash(int status);
617 /** Causes the server to exit immediately
618 * @param The exit code to give to the operating system
620 static void Exit(int status);
622 /** Return a count of users, unknown and known connections
623 * @return The number of users
627 /** Return a count of fully registered connections only
628 * @return The number of registered users
630 int RegisteredUserCount();
632 /** Return a count of invisible (umode +i) users only
633 * @return The number of invisible users
635 int InvisibleUserCount();
637 /** Return a count of opered (umode +o) users only
638 * @return The number of opers
642 /** Return a count of unregistered (before NICK/USER) users only
643 * @return The number of unregistered (unknown) connections
645 int UnregisteredUserCount();
647 /** Return a count of channels on the network
648 * @return The number of channels
652 /** Return a count of local users on this server only
653 * @return The number of local users
655 long LocalUserCount();
657 /** Send an error notice to all local users, opered and unopered
658 * @param s The error string to send
660 void SendError(const char *s);
662 /** For use with Module::Prioritize().
663 * When the return value of this function is returned from
664 * Module::Prioritize(), this specifies that the module wishes
665 * to be ordered exactly BEFORE 'modulename'. For more information
666 * please see Module::Prioritize().
667 * @param modulename The module your module wants to be before in the call list
668 * @returns a priority ID which the core uses to relocate the module in the list
670 long PriorityBefore(const std::string &modulename);
672 /** For use with Module::Prioritize().
673 * When the return value of this function is returned from
674 * Module::Prioritize(), this specifies that the module wishes
675 * to be ordered exactly AFTER 'modulename'. For more information please
676 * see Module::Prioritize().
677 * @param modulename The module your module wants to be after in the call list
678 * @returns a priority ID which the core uses to relocate the module in the list
680 long PriorityAfter(const std::string &modulename);
682 /** Publish a 'feature'.
683 * There are two ways for a module to find another module it depends on.
684 * Either by name, using InspIRCd::FindModule, or by feature, using this
685 * function. A feature is an arbitary string which identifies something this
686 * module can do. For example, if your module provides SSL support, but other
687 * modules provide SSL support too, all the modules supporting SSL should
688 * publish an identical 'SSL' feature. This way, any module requiring use
689 * of SSL functions can just look up the 'SSL' feature using FindFeature,
690 * then use the module pointer they are given.
691 * @param FeatureName The case sensitive feature name to make available
692 * @param Mod a pointer to your module class
693 * @returns True on success, false if the feature is already published by
696 bool PublishFeature(const std::string &FeatureName, Module* Mod);
698 /** Unpublish a 'feature'.
699 * When your module exits, it must call this method for every feature it
700 * is providing so that the feature table is cleaned up.
701 * @param FeatureName the feature to remove
703 bool UnpublishFeature(const std::string &FeatureName);
705 /** Find a 'feature'.
706 * There are two ways for a module to find another module it depends on.
707 * Either by name, using InspIRCd::FindModule, or by feature, using the
708 * InspIRCd::PublishFeature method. A feature is an arbitary string which
709 * identifies something this module can do. For example, if your module
710 * provides SSL support, but other modules provide SSL support too, all
711 * the modules supporting SSL should publish an identical 'SSL' feature.
712 * To find a module capable of providing the feature you want, simply
713 * call this method with the feature name you are looking for.
714 * @param FeatureName The feature name you wish to obtain the module for
715 * @returns A pointer to a valid module class on success, NULL on failure.
717 Module* FindFeature(const std::string &FeatureName);
719 /** Given a pointer to a Module, return its filename
720 * @param m The module pointer to identify
721 * @return The module name or an empty string
723 const std::string& GetModuleName(Module* m);
725 /** Return true if a nickname is valid
726 * @param n A nickname to verify
727 * @return True if the nick is valid
729 bool IsNick(const char* n);
731 /** Return true if an ident is valid
732 * @param An ident to verify
733 * @return True if the ident is valid
735 bool IsIdent(const char* n);
737 /** Find a username by their file descriptor.
738 * It is preferred to use this over directly accessing the fd_ref_table array.
739 * @param socket The file descriptor of a user
740 * @return A pointer to the user if the user exists locally on this descriptor
742 userrec* FindDescriptor(int socket);
744 /** Add a new mode to this server's mode parser
745 * @param mh The modehandler to add
746 * @param modechar The mode character this modehandler handles
747 * @return True if the mode handler was added
749 bool AddMode(ModeHandler* mh, const unsigned char modechar);
751 /** Add a new mode watcher to this server's mode parser
752 * @param mw The modewatcher to add
753 * @return True if the modewatcher was added
755 bool AddModeWatcher(ModeWatcher* mw);
757 /** Delete a mode watcher from this server's mode parser
758 * @param mw The modewatcher to delete
759 * @return True if the modewatcher was deleted
761 bool DelModeWatcher(ModeWatcher* mw);
763 /** Add a dns Resolver class to this server's active set
764 * @param r The resolver to add
765 * @return True if the resolver was added
767 bool AddResolver(Resolver* r);
769 /** Add a command to this server's command parser
770 * @param f A command_t command handler object to add
771 * @throw ModuleException Will throw ModuleExcption if the command already exists
773 void AddCommand(command_t *f);
775 /** Send a modechange.
776 * The parameters provided are identical to that sent to the
777 * handler for class cmd_mode.
778 * @param parameters The mode parameters
779 * @param pcnt The number of items you have given in the first parameter
780 * @param user The user to send error messages to
782 void SendMode(const char **parameters, int pcnt, userrec *user);
784 /** Match two strings using pattern matching.
785 * This operates identically to the global function match(),
786 * except for that it takes std::string arguments rather than
788 * @param sliteral The literal string to match against
789 * @param spattern The pattern to match against. CIDR and globs are supported.
791 bool MatchText(const std::string &sliteral, const std::string &spattern);
793 /** Call the handler for a given command.
794 * @param commandname The command whos handler you wish to call
795 * @param parameters The mode parameters
796 * @param pcnt The number of items you have given in the first parameter
797 * @param user The user to execute the command as
798 * @return True if the command handler was called successfully
800 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
802 /** Return true if the command is a module-implemented command and the given parameters are valid for it
803 * @param parameters The mode parameters
804 * @param pcnt The number of items you have given in the first parameter
805 * @param user The user to test-execute the command as
806 * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
808 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
810 /** Add a gline and apply it
811 * @param duration How long the line should last
812 * @param source Who set the line
813 * @param reason The reason for the line
814 * @param hostmask The hostmask to set the line against
816 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
818 /** Add a qline and apply it
819 * @param duration How long the line should last
820 * @param source Who set the line
821 * @param reason The reason for the line
822 * @param nickname The nickmask to set the line against
824 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
826 /** Add a zline and apply it
827 * @param duration How long the line should last
828 * @param source Who set the line
829 * @param reason The reason for the line
830 * @param ipaddr The ip-mask to set the line against
832 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
834 /** Add a kline and apply it
835 * @param duration How long the line should last
836 * @param source Who set the line
837 * @param reason The reason for the line
838 * @param hostmask The hostmask to set the line against
840 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
843 * @param duration How long the line should last
844 * @param source Who set the line
845 * @param reason The reason for the line
846 * @param hostmask The hostmask to set the line against
848 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
851 * @param hostmask The gline to delete
852 * @return True if the item was removed
854 bool DelGLine(const std::string &hostmask);
857 * @param nickname The qline to delete
858 * @return True if the item was removed
860 bool DelQLine(const std::string &nickname);
863 * @param ipaddr The zline to delete
864 * @return True if the item was removed
866 bool DelZLine(const std::string &ipaddr);
869 * @param hostmask The kline to delete
870 * @return True if the item was removed
872 bool DelKLine(const std::string &hostmask);
875 * @param hostmask The kline to delete
876 * @return True if the item was removed
878 bool DelELine(const std::string &hostmask);
880 /** Return true if the given parameter is a valid nick!user\@host mask
881 * @param mask A nick!user\@host masak to match against
882 * @return True i the mask is valid
884 bool IsValidMask(const std::string &mask);
886 /** Rehash the local server
890 /** Return the channel whos index number matches that provided
891 * @param The index number of the channel to fetch
892 * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
894 chanrec* GetChannelIndex(long index);
896 /** Dump text to a user target, splitting it appropriately to fit
897 * @param User the user to dump the text to
898 * @param LinePrefix text to prefix each complete line with
899 * @param TextStream the text to send to the user
901 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
903 /** Check if the given nickmask matches too many users, send errors to the given user
904 * @param nick A nickmask to match against
905 * @param user A user to send error text to
906 * @return True if the nick matches too many users
908 bool NickMatchesEveryone(const std::string &nick, userrec* user);
910 /** Check if the given IP mask matches too many users, send errors to the given user
911 * @param ip An ipmask to match against
912 * @param user A user to send error text to
913 * @return True if the ip matches too many users
915 bool IPMatchesEveryone(const std::string &ip, userrec* user);
917 /** Check if the given hostmask matches too many users, send errors to the given user
918 * @param mask A hostmask to match against
919 * @param user A user to send error text to
920 * @return True if the host matches too many users
922 bool HostMatchesEveryone(const std::string &mask, userrec* user);
924 /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
925 * @param str A string containing a time in the form 1y2w3d4h6m5s
926 * (one year, two weeks, three days, four hours, six minutes and five seconds)
927 * @return The total number of seconds
929 long Duration(const char* str);
931 /** Attempt to compare an oper password to a string from the config file.
932 * This will be passed to handling modules which will compare the data
933 * against possible hashed equivalents in the input string.
934 * @param data The data from the config file
935 * @param input The data input by the oper
936 * @return 0 if the strings match, 1 or -1 if they do not
938 int OperPassCompare(const char* data,const char* input);
940 /** Check if a given server is a uline.
941 * An empty string returns true, this is by design.
942 * @param server The server to check for uline status
943 * @return True if the server is a uline OR the string is empty
945 bool ULine(const char* server);
947 /** Returns the subversion revision ID of this ircd
948 * @return The revision ID or an empty string
950 std::string GetRevision();
952 /** Returns the full version string of this ircd
953 * @return The version string
955 std::string GetVersionString();
957 /** Attempt to write the process id to a given file
958 * @param filename The PID file to attempt to write to
959 * @return This function may bail if the file cannot be written
961 void WritePID(const std::string &filename);
963 /** Returns text describing the last module error
964 * @return The last error message to occur
968 /** Load a given module file
969 * @param filename The file to load
970 * @return True if the module was found and loaded
972 bool LoadModule(const char* filename);
974 /** Unload a given module file
975 * @param filename The file to unload
976 * @return True if the module was unloaded
978 bool UnloadModule(const char* filename);
980 /** This constructor initialises all the subsystems and reads the config file.
981 * @param argc The argument count passed to main()
982 * @param argv The argument list passed to main()
983 * @throw <anything> If anything is thrown from here and makes it to
984 * you, you should probably just give up and go home. Yes, really.
985 * It's that bad. Higher level classes should catch any non-fatal exceptions.
987 InspIRCd(int argc, char** argv);
989 /** Do one iteration of the mainloop
990 * @param process_module_sockets True if module sockets are to be processed
991 * this time around the event loop. The is the default.
993 void DoOneIteration(bool process_module_sockets = true);
995 /** Output a log message to the ircd.log file
996 * The text will only be output if the current loglevel
997 * is less than or equal to the level you provide
998 * @param level A log level from the DebugLevel enum
999 * @param text Format string of to write to the log
1000 * @param ... Format arguments of text to write to the log
1002 void Log(int level, const char* text, ...);
1004 /** Output a log message to the ircd.log file
1005 * The text will only be output if the current loglevel
1006 * is less than or equal to the level you provide
1007 * @param level A log level from the DebugLevel enum
1008 * @param text Text to write to the log
1010 void Log(int level, const std::string &text);
1012 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text);
1014 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...);
1016 /** Begin execution of the server.
1017 * NOTE: this function NEVER returns. Internally,
1018 * after performing some initialisation routines,
1019 * it will repeatedly call DoOneIteration in a loop.
1020 * @return The return value for this function is undefined.