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();
193 /** A list of failed port bindings, used for informational purposes on startup */
194 typedef std::vector<std::pair<std::string, long> > FailedPortList;
198 /** The main class of the irc server.
199 * This class contains instances of all the other classes
200 * in this software, with the exception of the base class,
201 * classbase. Amongst other things, it contains a ModeParser,
202 * a DNS object, a CommandParser object, and a list of active
203 * Module objects, and facilities for Module objects to
204 * interact with the core system it implements. You should
205 * NEVER attempt to instantiate a class of type InspIRCd
206 * yourself. If you do, this is equivalent to spawning a second
207 * IRC server, and could have catastrophic consequences for the
208 * program in terms of ram usage (basically, you could create
209 * an obese forkbomb built from recursively spawning irc servers!)
211 class InspIRCd : public classbase
214 /** Holds a string describing the last module error to occur
218 /** Remove a ModuleFactory pointer
219 * @param j Index number of the ModuleFactory to remove
221 void EraseFactory(int j);
223 /** Remove a Module pointer
224 * @param j Index number of the Module to remove
226 void EraseModule(int j);
228 /** Build the ISUPPORT string by triggering all modules On005Numeric events
230 void BuildISupport();
232 /** Move a given module to a specific slot in the list
233 * @param modulename The module name to relocate
234 * @param slot The slot to move the module into
236 void MoveTo(std::string modulename,int slot);
238 /** Display the startup banner
242 /** Set up the signal handlers
246 /** Daemonize the ircd and close standard input/output streams
247 * @return True if the program daemonized succesfully
251 /** Moves the given module to the last slot in the list
252 * @param modulename The module name to relocate
254 void MoveToLast(std::string modulename);
256 /** Moves the given module to the first slot in the list
257 * @param modulename The module name to relocate
259 void MoveToFirst(std::string modulename);
261 /** Moves one module to be placed after another in the list
262 * @param modulename The module name to relocate
263 * @param after The module name to place the module after
265 void MoveAfter(std::string modulename, std::string after);
267 /** Moves one module to be placed before another in the list
268 * @param modulename The module name to relocate
269 * @param after The module name to place the module before
271 void MoveBefore(std::string modulename, std::string before);
273 /** Iterate the list of InspSocket objects, removing ones which have timed out
274 * @param TIME the current time
276 void DoSocketTimeouts(time_t TIME);
278 /** Perform background user events such as PING checks
279 * @param TIME the current time
281 void DoBackgroundUserStuff(time_t TIME);
283 /** Returns true when all modules have done pre-registration checks on a user
284 * @param user The user to verify
285 * @return True if all modules have finished checking this user
287 bool AllModulesReportReady(userrec* user);
289 /** Total number of modules loaded into the ircd, minus one
293 /** Logfile pathname specified on the commandline, or empty string
295 char LogFileName[MAXBUF];
297 /** The feature names published by various modules
299 featurelist Features;
301 /** The current time, updated in the mainloop
305 /** The time that was recorded last time around the mainloop
309 /** A 64k buffer used to read client lines into
311 char ReadBuffer[65535];
313 /** Number of seconds in a minute
315 const long duration_m;
317 /** Number of seconds in an hour
319 const long duration_h;
321 /** Number of seconds in a day
323 const long duration_d;
325 /** Number of seconds in a week
327 const long duration_w;
329 /** Number of seconds in a year
331 const long duration_y;
333 /** Used when connecting clients
335 insp_sockaddr client, server;
337 /** Used when connecting clients
341 /** Nonblocking file writer
345 /** Time offset in seconds
346 * This offset is added to all calls to Time(). Use SetTimeDelta() to update
351 /** List of server names we've seen.
353 servernamelist servernames;
355 /** Time this ircd was booted
359 /** Mode handler, handles mode setting and removal
363 /** Command parser, handles client to server commands
365 CommandParser* Parser;
367 /** Socket engine, handles socket activity events
371 /** Stats class, holds miscellaneous stats counters
375 /** Server Config class, holds configuration file data
377 ServerConfig* Config;
379 /** Snomask manager - handles routing of snomask messages
384 /** Client list, a hash_map containing all clients, local and remote
386 user_hash clientlist;
388 /** Channel list, a hash_map containing all channels
392 /** Local client list, a vector containing only local clients
394 std::vector<userrec*> local_users;
396 /** Oper list, a vector containing all local and remote opered users
398 std::vector<userrec*> all_opers;
400 /** Whowas container, contains a map of vectors of users tracked by WHOWAS
402 irc::whowas::whowas_users whowas;
404 /** Whowas container, contains a map of time_t to users tracked by WHOWAS
406 irc::whowas::whowas_users_fifo whowas_fifo;
408 /** DNS class, provides resolver facilities to the core and modules
412 /** Timer manager class, triggers InspTimer timer events
414 TimerManager* Timers;
416 /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
418 XLineManager* XLines;
420 /** A list of Module* module classes
421 * Note that this list is always exactly 255 in size.
422 * The actual number of loaded modules is available from GetModuleCount()
426 /** A list of ModuleFactory* module factories
427 * Note that this list is always exactly 255 in size.
428 * The actual number of loaded modules is available from GetModuleCount()
432 /** The time we next call our ping timeout and reg timeout checks
436 /** Get the current time
437 * Because this only calls time() once every time around the mainloop,
438 * it is much faster than calling time() directly.
439 * @param delta True to use the delta as an offset, false otherwise
440 * @return The current time as an epoch value (time_t)
442 time_t Time(bool delta = false);
444 /** Set the time offset in seconds
445 * This offset is added to Time() to offset the system time by the specified
447 * @param delta The number of seconds to offset
448 * @return The old time delta
450 int SetTimeDelta(int delta);
452 /** Get the time offset in seconds
453 * @return The current time delta (in seconds)
457 /** Process a user whos socket has been flagged as active
458 * @param cu The user to process
459 * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
461 void ProcessUser(userrec* cu);
463 /** Get the total number of currently loaded modules
464 * @return The number of loaded modules
466 int GetModuleCount();
468 /** Find a module by name, and return a Module* to it.
469 * This is preferred over iterating the module lists yourself.
470 * @param name The module name to look up
471 * @return A pointer to the module, or NULL if the module cannot be found
473 Module* FindModule(const std::string &name);
475 /** Bind all ports specified in the configuration file.
476 * @param bail True if the function should bail back to the shell on failure
477 * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
478 * @return The number of ports actually bound without error
480 int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
482 /** Returns true if this server has the given port bound to the given address
483 * @param port The port number
484 * @param addr The address
485 * @return True if we have a port listening on this address
487 bool HasPort(int port, char* addr);
489 /** Binds a socket on an already open file descriptor
490 * @param sockfd A valid file descriptor of an open socket
491 * @param client A sockaddr to use as temporary storage
492 * @param server A sockaddr to use as temporary storage
493 * @param port The port number to bind to
494 * @param addr The address to bind to (IP only)
495 * @return True if the port was bound successfully
497 bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
499 /** Adds a server name to the list of servers we've seen
500 * @param The servername to add
502 void AddServerName(const std::string &servername);
504 /** Finds a cached char* pointer of a server name,
505 * This is used to optimize userrec by storing only the pointer to the name
506 * @param The servername to find
507 * @return A pointer to this name, gauranteed to never become invalid
509 const char* FindServerNamePtr(const std::string &servername);
511 /** Returns true if we've seen the given server name before
512 * @param The servername to find
513 * @return True if we've seen this server name before
515 bool FindServerName(const std::string &servername);
517 /** Gets the GECOS (description) field of the given server.
518 * If the servername is not that of the local server, the name
519 * is passed to handling modules which will attempt to determine
520 * the GECOS that bleongs to the given servername.
521 * @param servername The servername to find the description of
522 * @return The description of this server, or of the local server
524 std::string GetServerDescription(const char* servername);
526 /** Write text to all opers connected to this server
527 * @param text The text format string
528 * @param ... Format args
530 void WriteOpers(const char* text, ...);
532 /** Write text to all opers connected to this server
533 * @param text The text to send
535 void WriteOpers(const std::string &text);
537 /** Find a nickname in the nick hash
538 * @param nick The nickname to find
539 * @return A pointer to the user, or NULL if the user does not exist
541 userrec* FindNick(const std::string &nick);
543 /** Find a nickname in the nick hash
544 * @param nick The nickname to find
545 * @return A pointer to the user, or NULL if the user does not exist
547 userrec* FindNick(const char* nick);
549 /** Find a channel in the channels hash
550 * @param chan The channel to find
551 * @return A pointer to the channel, or NULL if the channel does not exist
553 chanrec* FindChan(const std::string &chan);
555 /** Find a channel in the channels hash
556 * @param chan The channel to find
557 * @return A pointer to the channel, or NULL if the channel does not exist
559 chanrec* FindChan(const char* chan);
561 /** Called by the constructor to load all modules from the config file.
563 void LoadAllModules();
565 /** Check for a 'die' tag in the config file, and abort if found
566 * @return Depending on the configuration, this function may never return
570 /** Check we aren't running as root, and exit if we are
571 * @return Depending on the configuration, this function may never return
575 /** Determine the right path for, and open, the logfile
576 * @param argv The argv passed to main() initially, used to calculate program path
577 * @param argc The argc passed to main() initially, used to calculate program path
579 void OpenLog(char** argv, int argc);
581 /** Convert a user to a pseudoclient, disconnecting the real user
582 * @param user The user to convert
583 * @param message The quit message to display when exiting the user
584 * @return True if the operation succeeded
586 bool UserToPseudo(userrec* user, const std::string &message);
588 /** Convert a pseudoclient to a real user, discarding the pseudoclient
589 * @param alive A live client
590 * @param zombie A pseudoclient
591 * @param message The message to display when quitting the pseudoclient
592 * @return True if the operation succeeded
594 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
596 /** Send a server notice to all local users
597 * @param text The text format string to send
598 * @param ... The format arguments
600 void ServerNoticeAll(char* text, ...);
602 /** Send a server message (PRIVMSG) to all local users
603 * @param text The text format string to send
604 * @param ... The format arguments
606 void ServerPrivmsgAll(char* text, ...);
608 /** Send text to all users with a specific set of modes
609 * @param modes The modes to check against, without a +, e.g. 'og'
610 * @param flags one of WM_OR or WM_AND. If you specify WM_OR, any one of the
611 * mode characters in the first parameter causes receipt of the message, and
612 * if you specify WM_OR, all the modes must be present.
613 * @param text The text format string to send
614 * @param ... The format arguments
616 void WriteMode(const char* modes, int flags, const char* text, ...);
618 /** Return true if a channel name is valid
619 * @param chname A channel name to verify
620 * @return True if the name is valid
622 bool IsChannel(const char *chname);
624 /** Rehash the local server
625 * @param status This value is unused, and required for signal handler functions
627 static void Rehash(int status);
629 /** Causes the server to exit immediately
630 * @param The exit code to give to the operating system
632 static void Exit(int status);
634 /** Return a count of users, unknown and known connections
635 * @return The number of users
639 /** Return a count of fully registered connections only
640 * @return The number of registered users
642 int RegisteredUserCount();
644 /** Return a count of invisible (umode +i) users only
645 * @return The number of invisible users
647 int InvisibleUserCount();
649 /** Return a count of opered (umode +o) users only
650 * @return The number of opers
654 /** Return a count of unregistered (before NICK/USER) users only
655 * @return The number of unregistered (unknown) connections
657 int UnregisteredUserCount();
659 /** Return a count of channels on the network
660 * @return The number of channels
664 /** Return a count of local users on this server only
665 * @return The number of local users
667 long LocalUserCount();
669 /** Send an error notice to all local users, opered and unopered
670 * @param s The error string to send
672 void SendError(const char *s);
674 /** For use with Module::Prioritize().
675 * When the return value of this function is returned from
676 * Module::Prioritize(), this specifies that the module wishes
677 * to be ordered exactly BEFORE 'modulename'. For more information
678 * please see Module::Prioritize().
679 * @param modulename The module your module wants to be before in the call list
680 * @returns a priority ID which the core uses to relocate the module in the list
682 long PriorityBefore(const std::string &modulename);
684 /** For use with Module::Prioritize().
685 * When the return value of this function is returned from
686 * Module::Prioritize(), this specifies that the module wishes
687 * to be ordered exactly AFTER 'modulename'. For more information please
688 * see Module::Prioritize().
689 * @param modulename The module your module wants to be after in the call list
690 * @returns a priority ID which the core uses to relocate the module in the list
692 long PriorityAfter(const std::string &modulename);
694 /** Publish a 'feature'.
695 * There are two ways for a module to find another module it depends on.
696 * Either by name, using InspIRCd::FindModule, or by feature, using this
697 * function. A feature is an arbitary string which identifies something this
698 * module can do. For example, if your module provides SSL support, but other
699 * modules provide SSL support too, all the modules supporting SSL should
700 * publish an identical 'SSL' feature. This way, any module requiring use
701 * of SSL functions can just look up the 'SSL' feature using FindFeature,
702 * then use the module pointer they are given.
703 * @param FeatureName The case sensitive feature name to make available
704 * @param Mod a pointer to your module class
705 * @returns True on success, false if the feature is already published by
708 bool PublishFeature(const std::string &FeatureName, Module* Mod);
710 /** Unpublish a 'feature'.
711 * When your module exits, it must call this method for every feature it
712 * is providing so that the feature table is cleaned up.
713 * @param FeatureName the feature to remove
715 bool UnpublishFeature(const std::string &FeatureName);
717 /** Find a 'feature'.
718 * There are two ways for a module to find another module it depends on.
719 * Either by name, using InspIRCd::FindModule, or by feature, using the
720 * InspIRCd::PublishFeature method. A feature is an arbitary string which
721 * identifies something this module can do. For example, if your module
722 * provides SSL support, but other modules provide SSL support too, all
723 * the modules supporting SSL should publish an identical 'SSL' feature.
724 * To find a module capable of providing the feature you want, simply
725 * call this method with the feature name you are looking for.
726 * @param FeatureName The feature name you wish to obtain the module for
727 * @returns A pointer to a valid module class on success, NULL on failure.
729 Module* FindFeature(const std::string &FeatureName);
731 /** Given a pointer to a Module, return its filename
732 * @param m The module pointer to identify
733 * @return The module name or an empty string
735 const std::string& GetModuleName(Module* m);
737 /** Return true if a nickname is valid
738 * @param n A nickname to verify
739 * @return True if the nick is valid
741 bool IsNick(const char* n);
743 /** Return true if an ident is valid
744 * @param An ident to verify
745 * @return True if the ident is valid
747 bool IsIdent(const char* n);
749 /** Find a username by their file descriptor.
750 * It is preferred to use this over directly accessing the fd_ref_table array.
751 * @param socket The file descriptor of a user
752 * @return A pointer to the user if the user exists locally on this descriptor
754 userrec* FindDescriptor(int socket);
756 /** Add a new mode to this server's mode parser
757 * @param mh The modehandler to add
758 * @param modechar The mode character this modehandler handles
759 * @return True if the mode handler was added
761 bool AddMode(ModeHandler* mh, const unsigned char modechar);
763 /** Add a new mode watcher to this server's mode parser
764 * @param mw The modewatcher to add
765 * @return True if the modewatcher was added
767 bool AddModeWatcher(ModeWatcher* mw);
769 /** Delete a mode watcher from this server's mode parser
770 * @param mw The modewatcher to delete
771 * @return True if the modewatcher was deleted
773 bool DelModeWatcher(ModeWatcher* mw);
775 /** Add a dns Resolver class to this server's active set
776 * @param r The resolver to add
777 * @return True if the resolver was added
779 bool AddResolver(Resolver* r);
781 /** Add a command to this server's command parser
782 * @param f A command_t command handler object to add
783 * @throw ModuleException Will throw ModuleExcption if the command already exists
785 void AddCommand(command_t *f);
787 /** Send a modechange.
788 * The parameters provided are identical to that sent to the
789 * handler for class cmd_mode.
790 * @param parameters The mode parameters
791 * @param pcnt The number of items you have given in the first parameter
792 * @param user The user to send error messages to
794 void SendMode(const char **parameters, int pcnt, userrec *user);
796 /** Match two strings using pattern matching.
797 * This operates identically to the global function match(),
798 * except for that it takes std::string arguments rather than
800 * @param sliteral The literal string to match against
801 * @param spattern The pattern to match against. CIDR and globs are supported.
803 bool MatchText(const std::string &sliteral, const std::string &spattern);
805 /** Call the handler for a given command.
806 * @param commandname The command whos handler you wish to call
807 * @param parameters The mode parameters
808 * @param pcnt The number of items you have given in the first parameter
809 * @param user The user to execute the command as
810 * @return True if the command handler was called successfully
812 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
814 /** Return true if the command is a module-implemented command and the given parameters are valid for it
815 * @param parameters The mode parameters
816 * @param pcnt The number of items you have given in the first parameter
817 * @param user The user to test-execute the command as
818 * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
820 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
822 /** Add a gline and apply it
823 * @param duration How long the line should last
824 * @param source Who set the line
825 * @param reason The reason for the line
826 * @param hostmask The hostmask to set the line against
828 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
830 /** Add a qline and apply it
831 * @param duration How long the line should last
832 * @param source Who set the line
833 * @param reason The reason for the line
834 * @param nickname The nickmask to set the line against
836 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
838 /** Add a zline and apply it
839 * @param duration How long the line should last
840 * @param source Who set the line
841 * @param reason The reason for the line
842 * @param ipaddr The ip-mask to set the line against
844 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
846 /** Add a kline and apply it
847 * @param duration How long the line should last
848 * @param source Who set the line
849 * @param reason The reason for the line
850 * @param hostmask The hostmask to set the line against
852 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
855 * @param duration How long the line should last
856 * @param source Who set the line
857 * @param reason The reason for the line
858 * @param hostmask The hostmask to set the line against
860 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
863 * @param hostmask The gline to delete
864 * @return True if the item was removed
866 bool DelGLine(const std::string &hostmask);
869 * @param nickname The qline to delete
870 * @return True if the item was removed
872 bool DelQLine(const std::string &nickname);
875 * @param ipaddr The zline to delete
876 * @return True if the item was removed
878 bool DelZLine(const std::string &ipaddr);
881 * @param hostmask The kline to delete
882 * @return True if the item was removed
884 bool DelKLine(const std::string &hostmask);
887 * @param hostmask The kline to delete
888 * @return True if the item was removed
890 bool DelELine(const std::string &hostmask);
892 /** Return true if the given parameter is a valid nick!user\@host mask
893 * @param mask A nick!user\@host masak to match against
894 * @return True i the mask is valid
896 bool IsValidMask(const std::string &mask);
898 /** Rehash the local server
902 /** Return the channel whos index number matches that provided
903 * @param The index number of the channel to fetch
904 * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
906 chanrec* GetChannelIndex(long index);
908 /** Dump text to a user target, splitting it appropriately to fit
909 * @param User the user to dump the text to
910 * @param LinePrefix text to prefix each complete line with
911 * @param TextStream the text to send to the user
913 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
915 /** Check if the given nickmask matches too many users, send errors to the given user
916 * @param nick A nickmask to match against
917 * @param user A user to send error text to
918 * @return True if the nick matches too many users
920 bool NickMatchesEveryone(const std::string &nick, userrec* user);
922 /** Check if the given IP mask matches too many users, send errors to the given user
923 * @param ip An ipmask to match against
924 * @param user A user to send error text to
925 * @return True if the ip matches too many users
927 bool IPMatchesEveryone(const std::string &ip, userrec* user);
929 /** Check if the given hostmask matches too many users, send errors to the given user
930 * @param mask A hostmask to match against
931 * @param user A user to send error text to
932 * @return True if the host matches too many users
934 bool HostMatchesEveryone(const std::string &mask, userrec* user);
936 /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
937 * @param str A string containing a time in the form 1y2w3d4h6m5s
938 * (one year, two weeks, three days, four hours, six minutes and five seconds)
939 * @return The total number of seconds
941 long Duration(const char* str);
943 /** Attempt to compare an oper password to a string from the config file.
944 * This will be passed to handling modules which will compare the data
945 * against possible hashed equivalents in the input string.
946 * @param data The data from the config file
947 * @param input The data input by the oper
948 * @return 0 if the strings match, 1 or -1 if they do not
950 int OperPassCompare(const char* data,const char* input);
952 /** Check if a given server is a uline.
953 * An empty string returns true, this is by design.
954 * @param server The server to check for uline status
955 * @return True if the server is a uline OR the string is empty
957 bool ULine(const char* server);
959 /** Returns the subversion revision ID of this ircd
960 * @return The revision ID or an empty string
962 std::string GetRevision();
964 /** Returns the full version string of this ircd
965 * @return The version string
967 std::string GetVersionString();
969 /** Attempt to write the process id to a given file
970 * @param filename The PID file to attempt to write to
971 * @return This function may bail if the file cannot be written
973 void WritePID(const std::string &filename);
975 /** Returns text describing the last module error
976 * @return The last error message to occur
980 /** Load a given module file
981 * @param filename The file to load
982 * @return True if the module was found and loaded
984 bool LoadModule(const char* filename);
986 /** Unload a given module file
987 * @param filename The file to unload
988 * @return True if the module was unloaded
990 bool UnloadModule(const char* filename);
992 /** This constructor initialises all the subsystems and reads the config file.
993 * @param argc The argument count passed to main()
994 * @param argv The argument list passed to main()
995 * @throw <anything> If anything is thrown from here and makes it to
996 * you, you should probably just give up and go home. Yes, really.
997 * It's that bad. Higher level classes should catch any non-fatal exceptions.
999 InspIRCd(int argc, char** argv);
1001 /** Do one iteration of the mainloop
1002 * @param process_module_sockets True if module sockets are to be processed
1003 * this time around the event loop. The is the default.
1005 void DoOneIteration(bool process_module_sockets = true);
1007 /** Output a log message to the ircd.log file
1008 * The text will only be output if the current loglevel
1009 * is less than or equal to the level you provide
1010 * @param level A log level from the DebugLevel enum
1011 * @param text Format string of to write to the log
1012 * @param ... Format arguments of text to write to the log
1014 void Log(int level, const char* text, ...);
1016 /** Output a log message to the ircd.log file
1017 * The text will only be output if the current loglevel
1018 * is less than or equal to the level you provide
1019 * @param level A log level from the DebugLevel enum
1020 * @param text Text to write to the log
1022 void Log(int level, const std::string &text);
1024 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text);
1026 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...);
1028 /** Begin execution of the server.
1029 * NOTE: this function NEVER returns. Internally,
1030 * after performing some initialisation routines,
1031 * it will repeatedly call DoOneIteration in a loop.
1032 * @return The return value for this function is undefined.