1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #ifndef __INSPIRCD_H__
15 #define __INSPIRCD_H__
20 #include "inspircd_config.h"
25 #include "socketengine.h"
26 #include "command_parse.h"
29 /** Returned by some functions to indicate failure.
35 #define ETIREDGERBILS EAGAIN
37 /** Debug levels for use with InspIRCd::Log()
49 * This define is used in place of strcmp when we
50 * want to check if a char* string contains only one
51 * letter. Pretty fast, its just two compares and an
54 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
56 /** Delete a pointer, and NULL its value
58 template<typename T> inline void DELETE(T* x)
64 /** Template function to convert any input type to std::string
66 template<typename T> inline std::string ConvToStr(const T &in)
68 std::stringstream tmp;
69 if (!(tmp << in)) return std::string();
73 template<typename T> inline long ConvToInt(const T &in)
75 std::stringstream tmp;
76 if (!(tmp << in)) return 0;
77 return atoi(tmp.str().c_str());
80 /** This class contains various STATS counters
81 * It is used by the InspIRCd class, which internally
82 * has an instance of it.
84 class serverstats : public classbase
87 /** Number of accepted connections
89 unsigned long statsAccept;
90 /** Number of failed accepts
92 unsigned long statsRefused;
93 /** Number of unknown commands seen
95 unsigned long statsUnknown;
96 /** Number of nickname collisions handled
98 unsigned long statsCollisions;
99 /** Number of DNS queries sent out
101 unsigned long statsDns;
102 /** Number of good DNS replies received
103 * NOTE: This may not tally to the number sent out,
104 * due to timeouts and other latency issues.
106 unsigned long statsDnsGood;
107 /** Number of bad (negative) DNS replies received
108 * NOTE: This may not tally to the number sent out,
109 * due to timeouts and other latency issues.
111 unsigned long statsDnsBad;
112 /** Number of inbound connections seen
114 unsigned long statsConnects;
115 /** Total bytes of data transmitted
118 /** Total bytes of data received
121 /** Number of bound listening ports
123 unsigned long BoundPortCount;
125 /** Cpu usage at last sample
129 /** Time last sample was read
133 /** The constructor initializes all the counts to zero
136 : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
137 statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0.0), statsRecv(0.0),
145 /** This class implements a nonblocking log-writer.
146 * Most people writing an ircd give little thought to their disk
147 * i/o. On a congested system, disk writes can block for long
148 * periods of time (e.g. if the system is busy and/or swapping
149 * a lot). If we just use a blocking fprintf() call, this could
150 * block for undesirable amounts of time (half of a second through
151 * to whole seconds). We DO NOT want this, so we make our logfile
152 * nonblocking and hook it into the SocketEngine.
153 * NB: If the operating system does not support nonblocking file
154 * I/O (linux seems to, as does freebsd) this will default to
155 * blocking behaviour.
157 class FileLogger : public EventHandler
160 /** The creator/owner of this object
162 InspIRCd* ServerInstance;
163 /** The log file (fd is inside this somewhere,
164 * we get it out with fileno())
167 /** Buffer of pending log lines to be written
170 /** Number of write operations that have occured
174 /** The constructor takes an already opened logfile.
176 FileLogger(InspIRCd* Instance, FILE* logfile);
177 /** This returns false, logfiles are writeable.
179 virtual bool Readable();
180 /** Handle pending write events.
181 * This will flush any waiting data to disk.
182 * If any data remains after the fprintf call,
183 * another write event is scheduled to write
184 * the rest of the data when possible.
186 virtual void HandleEvent(EventType et, int errornum = 0);
187 /** Write one or more preformatted log lines.
188 * If the data cannot be written immediately,
189 * this class will insert itself into the
190 * SocketEngine, and register a write event,
191 * and when the write event occurs it will
192 * attempt again to write the data.
194 void WriteLogLine(const std::string &line);
195 /** Close the log file and cancel any events.
197 virtual void Close();
198 /** Close the log file and cancel any events.
199 * (indirectly call Close()
201 virtual ~FileLogger();
204 /** A list of failed port bindings, used for informational purposes on startup */
205 typedef std::vector<std::pair<std::string, long> > FailedPortList;
207 /** A list of ip addresses cross referenced against clone counts */
208 typedef std::map<irc::string, unsigned int> clonemap;
212 /** The main class of the irc server.
213 * This class contains instances of all the other classes
214 * in this software, with the exception of the base class,
215 * classbase. Amongst other things, it contains a ModeParser,
216 * a DNS object, a CommandParser object, and a list of active
217 * Module objects, and facilities for Module objects to
218 * interact with the core system it implements. You should
219 * NEVER attempt to instantiate a class of type InspIRCd
220 * yourself. If you do, this is equivalent to spawning a second
221 * IRC server, and could have catastrophic consequences for the
222 * program in terms of ram usage (basically, you could create
223 * an obese forkbomb built from recursively spawning irc servers!)
225 class InspIRCd : public classbase
228 /** Holds a string describing the last module error to occur
232 /** Remove a ModuleFactory pointer
233 * @param j Index number of the ModuleFactory to remove
235 void EraseFactory(int j);
237 /** Remove a Module pointer
238 * @param j Index number of the Module to remove
240 void EraseModule(int j);
242 /** Build the ISUPPORT string by triggering all modules On005Numeric events
244 void BuildISupport();
246 /** Move a given module to a specific slot in the list
247 * @param modulename The module name to relocate
248 * @param slot The slot to move the module into
250 void MoveTo(std::string modulename,int slot);
252 /** Display the startup banner
256 /** Set up the signal handlers
260 /** Daemonize the ircd and close standard input/output streams
261 * @return True if the program daemonized succesfully
265 /** Moves the given module to the last slot in the list
266 * @param modulename The module name to relocate
268 void MoveToLast(std::string modulename);
270 /** Moves the given module to the first slot in the list
271 * @param modulename The module name to relocate
273 void MoveToFirst(std::string modulename);
275 /** Moves one module to be placed after another in the list
276 * @param modulename The module name to relocate
277 * @param after The module name to place the module after
279 void MoveAfter(std::string modulename, std::string after);
281 /** Moves one module to be placed before another in the list
282 * @param modulename The module name to relocate
283 * @param after The module name to place the module before
285 void MoveBefore(std::string modulename, std::string before);
287 /** Iterate the list of InspSocket objects, removing ones which have timed out
288 * @param TIME the current time
290 void DoSocketTimeouts(time_t TIME);
292 /** Perform background user events such as PING checks
293 * @param TIME the current time
295 void DoBackgroundUserStuff(time_t TIME);
297 /** Returns true when all modules have done pre-registration checks on a user
298 * @param user The user to verify
299 * @return True if all modules have finished checking this user
301 bool AllModulesReportReady(userrec* user);
303 /** Total number of modules loaded into the ircd, minus one
307 /** Logfile pathname specified on the commandline, or empty string
309 char LogFileName[MAXBUF];
311 /** The feature names published by various modules
313 featurelist Features;
315 /** The interface names published by various modules
317 interfacelist Interfaces;
319 /** The current time, updated in the mainloop
323 /** The time that was recorded last time around the mainloop
327 /** A 64k buffer used to read client lines into
329 char ReadBuffer[65535];
331 /** Number of seconds in a minute
333 const long duration_m;
335 /** Number of seconds in an hour
337 const long duration_h;
339 /** Number of seconds in a day
341 const long duration_d;
343 /** Number of seconds in a week
345 const long duration_w;
347 /** Number of seconds in a year
349 const long duration_y;
351 /** Used when connecting clients
353 insp_sockaddr client, server;
355 /** Used when connecting clients
359 /** Nonblocking file writer
363 /** Time offset in seconds
364 * This offset is added to all calls to Time(). Use SetTimeDelta() to update
369 /** List of server names we've seen.
371 servernamelist servernames;
373 /** Time this ircd was booted
377 /** Mode handler, handles mode setting and removal
381 /** Command parser, handles client to server commands
383 CommandParser* Parser;
385 /** Socket engine, handles socket activity events
389 /** Stats class, holds miscellaneous stats counters
393 /** Server Config class, holds configuration file data
395 ServerConfig* Config;
397 /** Snomask manager - handles routing of snomask messages
402 /** Client list, a hash_map containing all clients, local and remote
404 user_hash* clientlist;
406 /** Channel list, a hash_map containing all channels
410 /** Local client list, a vector containing only local clients
412 std::vector<userrec*> local_users;
414 /** Oper list, a vector containing all local and remote opered users
416 std::vector<userrec*> all_opers;
418 clonemap local_clones;
420 clonemap global_clones;
422 /** Whowas container, contains a map of vectors of users tracked by WHOWAS
424 irc::whowas::whowas_users whowas;
426 /** Whowas container, contains a map of time_t to users tracked by WHOWAS
428 irc::whowas::whowas_users_fifo whowas_fifo;
430 /** DNS class, provides resolver facilities to the core and modules
434 /** Timer manager class, triggers InspTimer timer events
436 TimerManager* Timers;
438 /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
440 XLineManager* XLines;
442 /** A list of Module* module classes
443 * Note that this list is always exactly 255 in size.
444 * The actual number of loaded modules is available from GetModuleCount()
448 /** A list of ModuleFactory* module factories
449 * Note that this list is always exactly 255 in size.
450 * The actual number of loaded modules is available from GetModuleCount()
454 /** The time we next call our ping timeout and reg timeout checks
458 /** Get the current time
459 * Because this only calls time() once every time around the mainloop,
460 * it is much faster than calling time() directly.
461 * @param delta True to use the delta as an offset, false otherwise
462 * @return The current time as an epoch value (time_t)
464 time_t Time(bool delta = false);
466 /** Set the time offset in seconds
467 * This offset is added to Time() to offset the system time by the specified
469 * @param delta The number of seconds to offset
470 * @return The old time delta
472 int SetTimeDelta(int delta);
474 void AddLocalClone(userrec* user);
476 void AddGlobalClone(userrec* user);
478 /** Get the time offset in seconds
479 * @return The current time delta (in seconds)
483 /** Process a user whos socket has been flagged as active
484 * @param cu The user to process
485 * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
487 void ProcessUser(userrec* cu);
489 /** Get the total number of currently loaded modules
490 * @return The number of loaded modules
492 int GetModuleCount();
494 /** Find a module by name, and return a Module* to it.
495 * This is preferred over iterating the module lists yourself.
496 * @param name The module name to look up
497 * @return A pointer to the module, or NULL if the module cannot be found
499 Module* FindModule(const std::string &name);
501 /** Bind all ports specified in the configuration file.
502 * @param bail True if the function should bail back to the shell on failure
503 * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
504 * @return The number of ports actually bound without error
506 int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
508 /** Returns true if this server has the given port bound to the given address
509 * @param port The port number
510 * @param addr The address
511 * @return True if we have a port listening on this address
513 bool HasPort(int port, char* addr);
515 /** Binds a socket on an already open file descriptor
516 * @param sockfd A valid file descriptor of an open socket
517 * @param client A sockaddr to use as temporary storage
518 * @param server A sockaddr to use as temporary storage
519 * @param port The port number to bind to
520 * @param addr The address to bind to (IP only)
521 * @return True if the port was bound successfully
523 bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
525 /** Adds a server name to the list of servers we've seen
526 * @param The servername to add
528 void AddServerName(const std::string &servername);
530 /** Finds a cached char* pointer of a server name,
531 * This is used to optimize userrec by storing only the pointer to the name
532 * @param The servername to find
533 * @return A pointer to this name, gauranteed to never become invalid
535 const char* FindServerNamePtr(const std::string &servername);
537 /** Returns true if we've seen the given server name before
538 * @param The servername to find
539 * @return True if we've seen this server name before
541 bool FindServerName(const std::string &servername);
543 /** Gets the GECOS (description) field of the given server.
544 * If the servername is not that of the local server, the name
545 * is passed to handling modules which will attempt to determine
546 * the GECOS that bleongs to the given servername.
547 * @param servername The servername to find the description of
548 * @return The description of this server, or of the local server
550 std::string GetServerDescription(const char* servername);
552 /** Write text to all opers connected to this server
553 * @param text The text format string
554 * @param ... Format args
556 void WriteOpers(const char* text, ...);
558 /** Write text to all opers connected to this server
559 * @param text The text to send
561 void WriteOpers(const std::string &text);
563 /** Find a nickname in the nick hash
564 * @param nick The nickname to find
565 * @return A pointer to the user, or NULL if the user does not exist
567 userrec* FindNick(const std::string &nick);
569 /** Find a nickname in the nick hash
570 * @param nick The nickname to find
571 * @return A pointer to the user, or NULL if the user does not exist
573 userrec* FindNick(const char* nick);
575 /** Find a channel in the channels hash
576 * @param chan The channel to find
577 * @return A pointer to the channel, or NULL if the channel does not exist
579 chanrec* FindChan(const std::string &chan);
581 /** Find a channel in the channels hash
582 * @param chan The channel to find
583 * @return A pointer to the channel, or NULL if the channel does not exist
585 chanrec* FindChan(const char* chan);
587 /** Called by the constructor to load all modules from the config file.
589 void LoadAllModules();
591 /** Check for a 'die' tag in the config file, and abort if found
592 * @return Depending on the configuration, this function may never return
596 /** Check we aren't running as root, and exit if we are
597 * @return Depending on the configuration, this function may never return
601 /** Determine the right path for, and open, the logfile
602 * @param argv The argv passed to main() initially, used to calculate program path
603 * @param argc The argc passed to main() initially, used to calculate program path
605 void OpenLog(char** argv, int argc);
609 /** Convert a user to a pseudoclient, disconnecting the real user
610 * @param user The user to convert
611 * @param message The quit message to display when exiting the user
612 * @return True if the operation succeeded
614 bool UserToPseudo(userrec* user, const std::string &message);
616 /** Convert a pseudoclient to a real user, discarding the pseudoclient
617 * @param alive A live client
618 * @param zombie A pseudoclient
619 * @param message The message to display when quitting the pseudoclient
620 * @return True if the operation succeeded
622 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
624 /** Send a server notice to all local users
625 * @param text The text format string to send
626 * @param ... The format arguments
628 void ServerNoticeAll(char* text, ...);
630 /** Send a server message (PRIVMSG) to all local users
631 * @param text The text format string to send
632 * @param ... The format arguments
634 void ServerPrivmsgAll(char* text, ...);
636 /** Send text to all users with a specific set of modes
637 * @param modes The modes to check against, without a +, e.g. 'og'
638 * @param flags one of WM_OR or WM_AND. If you specify WM_OR, any one of the
639 * mode characters in the first parameter causes receipt of the message, and
640 * if you specify WM_OR, all the modes must be present.
641 * @param text The text format string to send
642 * @param ... The format arguments
644 void WriteMode(const char* modes, int flags, const char* text, ...);
646 /** Return true if a channel name is valid
647 * @param chname A channel name to verify
648 * @return True if the name is valid
650 bool IsChannel(const char *chname);
652 /** Rehash the local server
653 * @param status This value is unused, and required for signal handler functions
655 static void Rehash(int status);
657 /** Causes the server to exit immediately
658 * @param The exit code to give to the operating system
659 * (See the ExitStatus enum for valid values)
661 static void Exit(int status);
663 /** Return a count of users, unknown and known connections
664 * @return The number of users
668 /** Return a count of fully registered connections only
669 * @return The number of registered users
671 int RegisteredUserCount();
673 /** Return a count of invisible (umode +i) users only
674 * @return The number of invisible users
676 int InvisibleUserCount();
678 /** Return a count of opered (umode +o) users only
679 * @return The number of opers
683 /** Return a count of unregistered (before NICK/USER) users only
684 * @return The number of unregistered (unknown) connections
686 int UnregisteredUserCount();
688 /** Return a count of channels on the network
689 * @return The number of channels
693 /** Return a count of local users on this server only
694 * @return The number of local users
696 long LocalUserCount();
698 /** Send an error notice to all local users, opered and unopered
699 * @param s The error string to send
701 void SendError(const std::string &s);
703 /** For use with Module::Prioritize().
704 * When the return value of this function is returned from
705 * Module::Prioritize(), this specifies that the module wishes
706 * to be ordered exactly BEFORE 'modulename'. For more information
707 * please see Module::Prioritize().
708 * @param modulename The module your module wants to be before in the call list
709 * @returns a priority ID which the core uses to relocate the module in the list
711 long PriorityBefore(const std::string &modulename);
713 /** For use with Module::Prioritize().
714 * When the return value of this function is returned from
715 * Module::Prioritize(), this specifies that the module wishes
716 * to be ordered exactly AFTER 'modulename'. For more information please
717 * see Module::Prioritize().
718 * @param modulename The module your module wants to be after in the call list
719 * @returns a priority ID which the core uses to relocate the module in the list
721 long PriorityAfter(const std::string &modulename);
723 /** Publish a 'feature'.
724 * There are two ways for a module to find another module it depends on.
725 * Either by name, using InspIRCd::FindModule, or by feature, using this
726 * function. A feature is an arbitary string which identifies something this
727 * module can do. For example, if your module provides SSL support, but other
728 * modules provide SSL support too, all the modules supporting SSL should
729 * publish an identical 'SSL' feature. This way, any module requiring use
730 * of SSL functions can just look up the 'SSL' feature using FindFeature,
731 * then use the module pointer they are given.
732 * @param FeatureName The case sensitive feature name to make available
733 * @param Mod a pointer to your module class
734 * @returns True on success, false if the feature is already published by
737 bool PublishFeature(const std::string &FeatureName, Module* Mod);
739 /** Publish a module to an 'interface'.
740 * Modules which implement the same interface (the same way of communicating
741 * with other modules) can publish themselves to an interface, using this
742 * method. When they do so, they become part of a list of related or
743 * compatible modules, and a third module may then query for that list
744 * and know that all modules within that list offer the same API.
745 * A prime example of this is the hashing modules, which all accept the
746 * same types of Request class. Consider this to be similar to PublishFeature,
747 * except for that multiple modules may publish the same 'feature'.
748 * @param InterfaceName The case sensitive interface name to make available
749 * @param Mod a pointer to your module class
750 * @returns True on success, false on failure (there are currently no failure
753 bool PublishInterface(const std::string &InterfaceName, Module* Mod);
755 /** Return a pair saying how many other modules are currently using the
756 * interfaces provided by module m.
757 * @param m The module to count usage for
758 * @return A pair, where the first value is the number of uses of the interface,
759 * and the second value is the interface name being used.
761 std::pair<int,std::string> GetInterfaceInstanceCount(Module* m);
763 /** Mark your module as using an interface.
764 * If you mark your module as using an interface, then that interface
765 * module may not unload until your module has unloaded first.
766 * This can be used to prevent crashes by ensuring code you depend on
767 * is always in memory while your module is active.
768 * @param InterfaceName The interface to use
770 void UseInterface(const std::string &InterfaceName);
772 /** Mark your module as finished with an interface.
773 * If you used UseInterface() above, you should use this method when
774 * your module is finished with the interface (usually in its destructor)
775 * to allow the modules which implement the given interface to be unloaded.
776 * @param InterfaceName The interface you are finished with using.
778 void DoneWithInterface(const std::string &InterfaceName);
780 /** Unpublish a 'feature'.
781 * When your module exits, it must call this method for every feature it
782 * is providing so that the feature table is cleaned up.
783 * @param FeatureName the feature to remove
785 bool UnpublishFeature(const std::string &FeatureName);
787 /** Unpublish your module from an interface
788 * When your module exits, it must call this method for every interface
789 * it is part of so that the interfaces table is cleaned up. Only when
790 * the last item is deleted from an interface does the interface get
792 * @param InterfaceName the interface to be removed from
793 * @param Mod The module to remove from the interface list
795 bool UnpublishInterface(const std::string &InterfaceName, Module* Mod);
797 /** Find a 'feature'.
798 * There are two ways for a module to find another module it depends on.
799 * Either by name, using InspIRCd::FindModule, or by feature, using the
800 * InspIRCd::PublishFeature method. A feature is an arbitary string which
801 * identifies something this module can do. For example, if your module
802 * provides SSL support, but other modules provide SSL support too, all
803 * the modules supporting SSL should publish an identical 'SSL' feature.
804 * To find a module capable of providing the feature you want, simply
805 * call this method with the feature name you are looking for.
806 * @param FeatureName The feature name you wish to obtain the module for
807 * @returns A pointer to a valid module class on success, NULL on failure.
809 Module* FindFeature(const std::string &FeatureName);
811 /** Find an 'interface'.
812 * An interface is a list of modules which all implement the same API.
813 * @param InterfaceName The Interface you wish to obtain the module
815 * @return A pointer to a deque of Module*, or NULL if the interface
818 modulelist* FindInterface(const std::string &InterfaceName);
820 /** Given a pointer to a Module, return its filename
821 * @param m The module pointer to identify
822 * @return The module name or an empty string
824 const std::string& GetModuleName(Module* m);
826 /** Return true if a nickname is valid
827 * @param n A nickname to verify
828 * @return True if the nick is valid
830 bool IsNick(const char* n);
832 /** Return true if an ident is valid
833 * @param An ident to verify
834 * @return True if the ident is valid
836 bool IsIdent(const char* n);
838 /** Find a username by their file descriptor.
839 * It is preferred to use this over directly accessing the fd_ref_table array.
840 * @param socket The file descriptor of a user
841 * @return A pointer to the user if the user exists locally on this descriptor
843 userrec* FindDescriptor(int socket);
845 /** Add a new mode to this server's mode parser
846 * @param mh The modehandler to add
847 * @param modechar The mode character this modehandler handles
848 * @return True if the mode handler was added
850 bool AddMode(ModeHandler* mh, const unsigned char modechar);
852 /** Add a new mode watcher to this server's mode parser
853 * @param mw The modewatcher to add
854 * @return True if the modewatcher was added
856 bool AddModeWatcher(ModeWatcher* mw);
858 /** Delete a mode watcher from this server's mode parser
859 * @param mw The modewatcher to delete
860 * @return True if the modewatcher was deleted
862 bool DelModeWatcher(ModeWatcher* mw);
864 /** Add a dns Resolver class to this server's active set
865 * @param r The resolver to add
866 * @return True if the resolver was added
868 bool AddResolver(Resolver* r);
870 /** Add a command to this server's command parser
871 * @param f A command_t command handler object to add
872 * @throw ModuleException Will throw ModuleExcption if the command already exists
874 void AddCommand(command_t *f);
876 /** Send a modechange.
877 * The parameters provided are identical to that sent to the
878 * handler for class cmd_mode.
879 * @param parameters The mode parameters
880 * @param pcnt The number of items you have given in the first parameter
881 * @param user The user to send error messages to
883 void SendMode(const char **parameters, int pcnt, userrec *user);
885 /** Match two strings using pattern matching.
886 * This operates identically to the global function match(),
887 * except for that it takes std::string arguments rather than
889 * @param sliteral The literal string to match against
890 * @param spattern The pattern to match against. CIDR and globs are supported.
892 bool MatchText(const std::string &sliteral, const std::string &spattern);
894 /** Call the handler for a given command.
895 * @param commandname The command whos handler you wish to call
896 * @param parameters The mode parameters
897 * @param pcnt The number of items you have given in the first parameter
898 * @param user The user to execute the command as
899 * @return True if the command handler was called successfully
901 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
903 /** Return true if the command is a module-implemented command and the given parameters are valid for it
904 * @param parameters The mode parameters
905 * @param pcnt The number of items you have given in the first parameter
906 * @param user The user to test-execute the command as
907 * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
909 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
911 /** Add a gline and apply it
912 * @param duration How long the line should last
913 * @param source Who set the line
914 * @param reason The reason for the line
915 * @param hostmask The hostmask to set the line against
917 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
919 /** Add a qline and apply it
920 * @param duration How long the line should last
921 * @param source Who set the line
922 * @param reason The reason for the line
923 * @param nickname The nickmask to set the line against
925 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
927 /** Add a zline and apply it
928 * @param duration How long the line should last
929 * @param source Who set the line
930 * @param reason The reason for the line
931 * @param ipaddr The ip-mask to set the line against
933 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
935 /** Add a kline and apply it
936 * @param duration How long the line should last
937 * @param source Who set the line
938 * @param reason The reason for the line
939 * @param hostmask The hostmask to set the line against
941 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
944 * @param duration How long the line should last
945 * @param source Who set the line
946 * @param reason The reason for the line
947 * @param hostmask The hostmask to set the line against
949 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
952 * @param hostmask The gline to delete
953 * @return True if the item was removed
955 bool DelGLine(const std::string &hostmask);
958 * @param nickname The qline to delete
959 * @return True if the item was removed
961 bool DelQLine(const std::string &nickname);
964 * @param ipaddr The zline to delete
965 * @return True if the item was removed
967 bool DelZLine(const std::string &ipaddr);
970 * @param hostmask The kline to delete
971 * @return True if the item was removed
973 bool DelKLine(const std::string &hostmask);
976 * @param hostmask The kline to delete
977 * @return True if the item was removed
979 bool DelELine(const std::string &hostmask);
981 /** Return true if the given parameter is a valid nick!user\@host mask
982 * @param mask A nick!user\@host masak to match against
983 * @return True i the mask is valid
985 bool IsValidMask(const std::string &mask);
987 /** Rehash the local server
991 /** Return the channel whos index number matches that provided
992 * @param The index number of the channel to fetch
993 * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
995 chanrec* GetChannelIndex(long index);
997 /** Dump text to a user target, splitting it appropriately to fit
998 * @param User the user to dump the text to
999 * @param LinePrefix text to prefix each complete line with
1000 * @param TextStream the text to send to the user
1002 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
1004 /** Check if the given nickmask matches too many users, send errors to the given user
1005 * @param nick A nickmask to match against
1006 * @param user A user to send error text to
1007 * @return True if the nick matches too many users
1009 bool NickMatchesEveryone(const std::string &nick, userrec* user);
1011 /** Check if the given IP mask matches too many users, send errors to the given user
1012 * @param ip An ipmask to match against
1013 * @param user A user to send error text to
1014 * @return True if the ip matches too many users
1016 bool IPMatchesEveryone(const std::string &ip, userrec* user);
1018 /** Check if the given hostmask matches too many users, send errors to the given user
1019 * @param mask A hostmask to match against
1020 * @param user A user to send error text to
1021 * @return True if the host matches too many users
1023 bool HostMatchesEveryone(const std::string &mask, userrec* user);
1025 /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
1026 * @param str A string containing a time in the form 1y2w3d4h6m5s
1027 * (one year, two weeks, three days, four hours, six minutes and five seconds)
1028 * @return The total number of seconds
1030 long Duration(const char* str);
1032 /** Attempt to compare an oper password to a string from the config file.
1033 * This will be passed to handling modules which will compare the data
1034 * against possible hashed equivalents in the input string.
1035 * @param data The data from the config file
1036 * @param input The data input by the oper
1037 * @param tagnum the tag number of the oper's tag in the config file
1038 * @return 0 if the strings match, 1 or -1 if they do not
1040 int OperPassCompare(const char* data,const char* input, int tagnum);
1042 /** Check if a given server is a uline.
1043 * An empty string returns true, this is by design.
1044 * @param server The server to check for uline status
1045 * @return True if the server is a uline OR the string is empty
1047 bool ULine(const char* server);
1049 /** Returns the subversion revision ID of this ircd
1050 * @return The revision ID or an empty string
1052 std::string GetRevision();
1054 /** Returns the full version string of this ircd
1055 * @return The version string
1057 std::string GetVersionString();
1059 /** Attempt to write the process id to a given file
1060 * @param filename The PID file to attempt to write to
1061 * @return This function may bail if the file cannot be written
1063 void WritePID(const std::string &filename);
1065 /** Returns text describing the last module error
1066 * @return The last error message to occur
1068 char* ModuleError();
1070 /** Load a given module file
1071 * @param filename The file to load
1072 * @return True if the module was found and loaded
1074 bool LoadModule(const char* filename);
1076 /** Unload a given module file
1077 * @param filename The file to unload
1078 * @return True if the module was unloaded
1080 bool UnloadModule(const char* filename);
1082 /** This constructor initialises all the subsystems and reads the config file.
1083 * @param argc The argument count passed to main()
1084 * @param argv The argument list passed to main()
1085 * @throw <anything> If anything is thrown from here and makes it to
1086 * you, you should probably just give up and go home. Yes, really.
1087 * It's that bad. Higher level classes should catch any non-fatal exceptions.
1089 InspIRCd(int argc, char** argv);
1091 /** Do one iteration of the mainloop
1092 * @param process_module_sockets True if module sockets are to be processed
1093 * this time around the event loop. The is the default.
1095 void DoOneIteration(bool process_module_sockets = true);
1097 /** Output a log message to the ircd.log file
1098 * The text will only be output if the current loglevel
1099 * is less than or equal to the level you provide
1100 * @param level A log level from the DebugLevel enum
1101 * @param text Format string of to write to the log
1102 * @param ... Format arguments of text to write to the log
1104 void Log(int level, const char* text, ...);
1106 /** Output a log message to the ircd.log file
1107 * The text will only be output if the current loglevel
1108 * is less than or equal to the level you provide
1109 * @param level A log level from the DebugLevel enum
1110 * @param text Text to write to the log
1112 void Log(int level, const std::string &text);
1114 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text);
1116 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...);
1118 /** Restart the server.
1119 * This function will not return. If an error occurs,
1120 * it will throw an instance of CoreException.
1121 * @param reason The restart reason to show to all clients
1122 * @throw CoreException An instance of CoreException indicating the error from execv().
1124 void Restart(const std::string &reason);
1126 /** Prepare the ircd for restart or shutdown.
1127 * This function unloads all modules which can be unloaded,
1128 * closes all open sockets, and closes the logfile.
1132 /** This copies the user and channel hash_maps into new hash maps.
1133 * This frees memory used by the hash_map allocator (which it neglects
1134 * to free, most of the time, using tons of ram)
1136 void RehashUsersAndChans();
1138 /** Begin execution of the server.
1139 * NOTE: this function NEVER returns. Internally,
1140 * after performing some initialisation routines,
1141 * it will repeatedly call DoOneIteration in a loop.
1142 * @return The return value for this function is undefined.