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.
33 /** Support for librodent -
34 * see http://www.chatspike.net/index.php?z=64
36 #define ETIREDHAMSTERS EAGAIN
38 /** Debug levels for use with InspIRCd::Log()
50 * This define is used in place of strcmp when we
51 * want to check if a char* string contains only one
52 * letter. Pretty fast, its just two compares and an
55 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
57 /** Delete a pointer, and NULL its value
59 template<typename T> inline void DELETE(T* x)
65 /** Template function to convert any input type to std::string
67 template<typename T> inline std::string ConvToStr(const T &in)
69 std::stringstream tmp;
70 if (!(tmp << in)) return std::string();
74 template<typename T> inline long ConvToInt(const T &in)
76 std::stringstream tmp;
77 if (!(tmp << in)) return 0;
78 return atoi(tmp.str().c_str());
81 /** Template function to convert integer to char, storing result in *res and
82 * also returning the pointer to res. Based on Stuart Lowe's C/C++ Pages.
84 template<typename T, typename V, typename R> inline char* itoa(const T &in, V *res, R base)
86 if (base < 2 || base > 16) { *res = 0; return res; }
90 *out = "0123456789abcdef"[ std::abs( quotient % base ) ];
94 if ( in < 0 && base == 10) *out++ = '-';
95 std::reverse( res, out );
100 /** This class contains various STATS counters
101 * It is used by the InspIRCd class, which internally
102 * has an instance of it.
104 class serverstats : public classbase
107 /** Number of accepted connections
109 unsigned long statsAccept;
110 /** Number of failed accepts
112 unsigned long statsRefused;
113 /** Number of unknown commands seen
115 unsigned long statsUnknown;
116 /** Number of nickname collisions handled
118 unsigned long statsCollisions;
119 /** Number of DNS queries sent out
121 unsigned long statsDns;
122 /** Number of good DNS replies received
123 * NOTE: This may not tally to the number sent out,
124 * due to timeouts and other latency issues.
126 unsigned long statsDnsGood;
127 /** Number of bad (negative) DNS replies received
128 * NOTE: This may not tally to the number sent out,
129 * due to timeouts and other latency issues.
131 unsigned long statsDnsBad;
132 /** Number of inbound connections seen
134 unsigned long statsConnects;
135 /** Total bytes of data transmitted
138 /** Total bytes of data received
141 /** Number of bound listening ports
143 unsigned long BoundPortCount;
145 /** Cpu usage at last sample
149 /** Time last sample was read
153 /** The constructor initializes all the counts to zero
156 : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
157 statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0.0), statsRecv(0.0),
165 /** This class implements a nonblocking log-writer.
166 * Most people writing an ircd give little thought to their disk
167 * i/o. On a congested system, disk writes can block for long
168 * periods of time (e.g. if the system is busy and/or swapping
169 * a lot). If we just use a blocking fprintf() call, this could
170 * block for undesirable amounts of time (half of a second through
171 * to whole seconds). We DO NOT want this, so we make our logfile
172 * nonblocking and hook it into the SocketEngine.
173 * NB: If the operating system does not support nonblocking file
174 * I/O (linux seems to, as does freebsd) this will default to
175 * blocking behaviour.
177 class FileLogger : public EventHandler
180 /** The creator/owner of this object
182 InspIRCd* ServerInstance;
183 /** The log file (fd is inside this somewhere,
184 * we get it out with fileno())
187 /** Buffer of pending log lines to be written
190 /** Number of write operations that have occured
194 /** The constructor takes an already opened logfile.
196 FileLogger(InspIRCd* Instance, FILE* logfile);
197 /** This returns false, logfiles are writeable.
199 virtual bool Readable();
200 /** Handle pending write events.
201 * This will flush any waiting data to disk.
202 * If any data remains after the fprintf call,
203 * another write event is scheduled to write
204 * the rest of the data when possible.
206 virtual void HandleEvent(EventType et, int errornum = 0);
207 /** Write one or more preformatted log lines.
208 * If the data cannot be written immediately,
209 * this class will insert itself into the
210 * SocketEngine, and register a write event,
211 * and when the write event occurs it will
212 * attempt again to write the data.
214 void WriteLogLine(const std::string &line);
215 /** Close the log file and cancel any events.
217 virtual void Close();
218 /** Close the log file and cancel any events.
219 * (indirectly call Close()
221 virtual ~FileLogger();
224 /** A list of failed port bindings, used for informational purposes on startup */
225 typedef std::vector<std::pair<std::string, long> > FailedPortList;
227 /** A list of ip addresses cross referenced against clone counts */
228 typedef std::map<irc::string, unsigned int> clonemap;
232 /** The main class of the irc server.
233 * This class contains instances of all the other classes
234 * in this software, with the exception of the base class,
235 * classbase. Amongst other things, it contains a ModeParser,
236 * a DNS object, a CommandParser object, and a list of active
237 * Module objects, and facilities for Module objects to
238 * interact with the core system it implements. You should
239 * NEVER attempt to instantiate a class of type InspIRCd
240 * yourself. If you do, this is equivalent to spawning a second
241 * IRC server, and could have catastrophic consequences for the
242 * program in terms of ram usage (basically, you could create
243 * an obese forkbomb built from recursively spawning irc servers!)
245 class InspIRCd : public classbase
248 /** Holds a string describing the last module error to occur
252 /** Remove a ModuleFactory pointer
253 * @param j Index number of the ModuleFactory to remove
255 void EraseFactory(int j);
257 /** Remove a Module pointer
258 * @param j Index number of the Module to remove
260 void EraseModule(int j);
262 /** Build the ISUPPORT string by triggering all modules On005Numeric events
264 void BuildISupport();
266 /** Move a given module to a specific slot in the list
267 * @param modulename The module name to relocate
268 * @param slot The slot to move the module into
270 void MoveTo(std::string modulename,int slot);
272 /** Display the startup banner
276 /** Set up the signal handlers
280 /** Daemonize the ircd and close standard input/output streams
281 * @return True if the program daemonized succesfully
285 /** Moves the given module to the last slot in the list
286 * @param modulename The module name to relocate
288 void MoveToLast(std::string modulename);
290 /** Moves the given module to the first slot in the list
291 * @param modulename The module name to relocate
293 void MoveToFirst(std::string modulename);
295 /** Moves one module to be placed after another in the list
296 * @param modulename The module name to relocate
297 * @param after The module name to place the module after
299 void MoveAfter(std::string modulename, std::string after);
301 /** Moves one module to be placed before another in the list
302 * @param modulename The module name to relocate
303 * @param after The module name to place the module before
305 void MoveBefore(std::string modulename, std::string before);
307 /** Iterate the list of InspSocket objects, removing ones which have timed out
308 * @param TIME the current time
310 void DoSocketTimeouts(time_t TIME);
312 /** Perform background user events such as PING checks
313 * @param TIME the current time
315 void DoBackgroundUserStuff(time_t TIME);
317 /** Returns true when all modules have done pre-registration checks on a user
318 * @param user The user to verify
319 * @return True if all modules have finished checking this user
321 bool AllModulesReportReady(userrec* user);
323 /** Total number of modules loaded into the ircd, minus one
327 /** Logfile pathname specified on the commandline, or empty string
329 char LogFileName[MAXBUF];
331 /** The feature names published by various modules
333 featurelist Features;
335 /** The interface names published by various modules
337 interfacelist Interfaces;
339 /** The current time, updated in the mainloop
343 /** The time that was recorded last time around the mainloop
347 /** A 64k buffer used to read client lines into
349 char ReadBuffer[65535];
351 /** Number of seconds in a minute
353 const long duration_m;
355 /** Number of seconds in an hour
357 const long duration_h;
359 /** Number of seconds in a day
361 const long duration_d;
363 /** Number of seconds in a week
365 const long duration_w;
367 /** Number of seconds in a year
369 const long duration_y;
371 /** Used when connecting clients
373 insp_sockaddr client, server;
375 /** Used when connecting clients
379 /** Nonblocking file writer
383 /** Time offset in seconds
384 * This offset is added to all calls to Time(). Use SetTimeDelta() to update
390 /** Number of unregistered users online right now.
391 * (Unregistered means before USER/NICK/dns)
393 int unregistered_count;
395 /** List of server names we've seen.
397 servernamelist servernames;
399 /** Time this ircd was booted
403 /** Mode handler, handles mode setting and removal
407 /** Command parser, handles client to server commands
409 CommandParser* Parser;
411 /** Socket engine, handles socket activity events
415 /** Stats class, holds miscellaneous stats counters
419 /** Server Config class, holds configuration file data
421 ServerConfig* Config;
423 /** Snomask manager - handles routing of snomask messages
428 /** Client list, a hash_map containing all clients, local and remote
430 user_hash* clientlist;
432 /** Channel list, a hash_map containing all channels
436 /** Local client list, a vector containing only local clients
438 std::vector<userrec*> local_users;
440 /** Oper list, a vector containing all local and remote opered users
442 std::vector<userrec*> all_opers;
444 clonemap local_clones;
446 clonemap global_clones;
448 /** DNS class, provides resolver facilities to the core and modules
452 /** Timer manager class, triggers InspTimer timer events
454 TimerManager* Timers;
456 /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
458 XLineManager* XLines;
460 /** A list of Module* module classes
461 * Note that this list is always exactly 255 in size.
462 * The actual number of loaded modules is available from GetModuleCount()
466 /** A list of ModuleFactory* module factories
467 * Note that this list is always exactly 255 in size.
468 * The actual number of loaded modules is available from GetModuleCount()
472 /** The time we next call our ping timeout and reg timeout checks
476 /** Get the current time
477 * Because this only calls time() once every time around the mainloop,
478 * it is much faster than calling time() directly.
479 * @param delta True to use the delta as an offset, false otherwise
480 * @return The current time as an epoch value (time_t)
482 time_t Time(bool delta = false);
484 /** Set the time offset in seconds
485 * This offset is added to Time() to offset the system time by the specified
487 * @param delta The number of seconds to offset
488 * @return The old time delta
490 int SetTimeDelta(int delta);
492 void AddLocalClone(userrec* user);
494 void AddGlobalClone(userrec* user);
496 /** Number of users with a certain mode set on them
498 int ModeCount(const char mode);
500 /** Get the time offset in seconds
501 * @return The current time delta (in seconds)
505 /** Process a user whos socket has been flagged as active
506 * @param cu The user to process
507 * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
509 void ProcessUser(userrec* cu);
511 /** Get the total number of currently loaded modules
512 * @return The number of loaded modules
514 int GetModuleCount();
516 /** Find a module by name, and return a Module* to it.
517 * This is preferred over iterating the module lists yourself.
518 * @param name The module name to look up
519 * @return A pointer to the module, or NULL if the module cannot be found
521 Module* FindModule(const std::string &name);
523 /** Bind all ports specified in the configuration file.
524 * @param bail True if the function should bail back to the shell on failure
525 * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
526 * @return The number of ports actually bound without error
528 int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
530 /** Returns true if this server has the given port bound to the given address
531 * @param port The port number
532 * @param addr The address
533 * @return True if we have a port listening on this address
535 bool HasPort(int port, char* addr);
537 /** Binds a socket on an already open file descriptor
538 * @param sockfd A valid file descriptor of an open socket
539 * @param client A sockaddr to use as temporary storage
540 * @param server A sockaddr to use as temporary storage
541 * @param port The port number to bind to
542 * @param addr The address to bind to (IP only)
543 * @return True if the port was bound successfully
545 bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
547 /** Adds a server name to the list of servers we've seen
548 * @param The servername to add
550 void AddServerName(const std::string &servername);
552 /** Finds a cached char* pointer of a server name,
553 * This is used to optimize userrec by storing only the pointer to the name
554 * @param The servername to find
555 * @return A pointer to this name, gauranteed to never become invalid
557 const char* FindServerNamePtr(const std::string &servername);
559 /** Returns true if we've seen the given server name before
560 * @param The servername to find
561 * @return True if we've seen this server name before
563 bool FindServerName(const std::string &servername);
565 /** Gets the GECOS (description) field of the given server.
566 * If the servername is not that of the local server, the name
567 * is passed to handling modules which will attempt to determine
568 * the GECOS that bleongs to the given servername.
569 * @param servername The servername to find the description of
570 * @return The description of this server, or of the local server
572 std::string GetServerDescription(const char* servername);
574 /** Write text to all opers connected to this server
575 * @param text The text format string
576 * @param ... Format args
578 void WriteOpers(const char* text, ...);
580 /** Write text to all opers connected to this server
581 * @param text The text to send
583 void WriteOpers(const std::string &text);
585 /** Find a nickname in the nick hash
586 * @param nick The nickname to find
587 * @return A pointer to the user, or NULL if the user does not exist
589 userrec* FindNick(const std::string &nick);
591 /** Find a nickname in the nick hash
592 * @param nick The nickname to find
593 * @return A pointer to the user, or NULL if the user does not exist
595 userrec* FindNick(const char* nick);
597 /** Find a channel in the channels hash
598 * @param chan The channel to find
599 * @return A pointer to the channel, or NULL if the channel does not exist
601 chanrec* FindChan(const std::string &chan);
603 /** Find a channel in the channels hash
604 * @param chan The channel to find
605 * @return A pointer to the channel, or NULL if the channel does not exist
607 chanrec* FindChan(const char* chan);
609 /** Called by the constructor to load all modules from the config file.
611 void LoadAllModules();
613 /** Check for a 'die' tag in the config file, and abort if found
614 * @return Depending on the configuration, this function may never return
618 /** Check we aren't running as root, and exit if we are
619 * @return Depending on the configuration, this function may never return
623 /** Determine the right path for, and open, the logfile
624 * @param argv The argv passed to main() initially, used to calculate program path
625 * @param argc The argc passed to main() initially, used to calculate program path
627 void OpenLog(char** argv, int argc);
631 /** Convert a user to a pseudoclient, disconnecting the real user
632 * @param user The user to convert
633 * @param message The quit message to display when exiting the user
634 * @return True if the operation succeeded
636 bool UserToPseudo(userrec* user, const std::string &message);
638 /** Convert a pseudoclient to a real user, discarding the pseudoclient
639 * @param alive A live client
640 * @param zombie A pseudoclient
641 * @param message The message to display when quitting the pseudoclient
642 * @return True if the operation succeeded
644 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
646 /** Send a server notice to all local users
647 * @param text The text format string to send
648 * @param ... The format arguments
650 void ServerNoticeAll(char* text, ...);
652 /** Send a server message (PRIVMSG) to all local users
653 * @param text The text format string to send
654 * @param ... The format arguments
656 void ServerPrivmsgAll(char* text, ...);
658 /** Send text to all users with a specific set of modes
659 * @param modes The modes to check against, without a +, e.g. 'og'
660 * @param flags one of WM_OR or WM_AND. If you specify WM_OR, any one of the
661 * mode characters in the first parameter causes receipt of the message, and
662 * if you specify WM_OR, all the modes must be present.
663 * @param text The text format string to send
664 * @param ... The format arguments
666 void WriteMode(const char* modes, int flags, const char* text, ...);
668 /** Return true if a channel name is valid
669 * @param chname A channel name to verify
670 * @return True if the name is valid
672 bool IsChannel(const char *chname);
674 /** Rehash the local server
675 * @param status This value is unused, and required for signal handler functions
677 static void Rehash(int status);
679 /** Causes the server to exit immediately
680 * @param The exit code to give to the operating system
681 * (See the ExitStatus enum for valid values)
683 static void Exit(int status);
685 /** Return a count of users, unknown and known connections
686 * @return The number of users
690 /** Return a count of fully registered connections only
691 * @return The number of registered users
693 int RegisteredUserCount();
695 /** Return a count of invisible (umode +i) users only
696 * @return The number of invisible users
698 int InvisibleUserCount();
700 /** Return a count of opered (umode +o) users only
701 * @return The number of opers
705 /** Return a count of unregistered (before NICK/USER) users only
706 * @return The number of unregistered (unknown) connections
708 int UnregisteredUserCount();
710 /** Return a count of channels on the network
711 * @return The number of channels
715 /** Return a count of local users on this server only
716 * @return The number of local users
718 long LocalUserCount();
720 /** Send an error notice to all local users, opered and unopered
721 * @param s The error string to send
723 void SendError(const std::string &s);
725 /** For use with Module::Prioritize().
726 * When the return value of this function is returned from
727 * Module::Prioritize(), this specifies that the module wishes
728 * to be ordered exactly BEFORE 'modulename'. For more information
729 * please see Module::Prioritize().
730 * @param modulename The module your module wants to be before in the call list
731 * @returns a priority ID which the core uses to relocate the module in the list
733 long PriorityBefore(const std::string &modulename);
735 /** For use with Module::Prioritize().
736 * When the return value of this function is returned from
737 * Module::Prioritize(), this specifies that the module wishes
738 * to be ordered exactly AFTER 'modulename'. For more information please
739 * see Module::Prioritize().
740 * @param modulename The module your module wants to be after in the call list
741 * @returns a priority ID which the core uses to relocate the module in the list
743 long PriorityAfter(const std::string &modulename);
745 /** Publish a 'feature'.
746 * There are two ways for a module to find another module it depends on.
747 * Either by name, using InspIRCd::FindModule, or by feature, using this
748 * function. A feature is an arbitary string which identifies something this
749 * module can do. For example, if your module provides SSL support, but other
750 * modules provide SSL support too, all the modules supporting SSL should
751 * publish an identical 'SSL' feature. This way, any module requiring use
752 * of SSL functions can just look up the 'SSL' feature using FindFeature,
753 * then use the module pointer they are given.
754 * @param FeatureName The case sensitive feature name to make available
755 * @param Mod a pointer to your module class
756 * @returns True on success, false if the feature is already published by
759 bool PublishFeature(const std::string &FeatureName, Module* Mod);
761 /** Publish a module to an 'interface'.
762 * Modules which implement the same interface (the same way of communicating
763 * with other modules) can publish themselves to an interface, using this
764 * method. When they do so, they become part of a list of related or
765 * compatible modules, and a third module may then query for that list
766 * and know that all modules within that list offer the same API.
767 * A prime example of this is the hashing modules, which all accept the
768 * same types of Request class. Consider this to be similar to PublishFeature,
769 * except for that multiple modules may publish the same 'feature'.
770 * @param InterfaceName The case sensitive interface name to make available
771 * @param Mod a pointer to your module class
772 * @returns True on success, false on failure (there are currently no failure
775 bool PublishInterface(const std::string &InterfaceName, Module* Mod);
777 /** Return a pair saying how many other modules are currently using the
778 * interfaces provided by module m.
779 * @param m The module to count usage for
780 * @return A pair, where the first value is the number of uses of the interface,
781 * and the second value is the interface name being used.
783 std::pair<int,std::string> GetInterfaceInstanceCount(Module* m);
785 /** Mark your module as using an interface.
786 * If you mark your module as using an interface, then that interface
787 * module may not unload until your module has unloaded first.
788 * This can be used to prevent crashes by ensuring code you depend on
789 * is always in memory while your module is active.
790 * @param InterfaceName The interface to use
792 void UseInterface(const std::string &InterfaceName);
794 /** Mark your module as finished with an interface.
795 * If you used UseInterface() above, you should use this method when
796 * your module is finished with the interface (usually in its destructor)
797 * to allow the modules which implement the given interface to be unloaded.
798 * @param InterfaceName The interface you are finished with using.
800 void DoneWithInterface(const std::string &InterfaceName);
802 /** Unpublish a 'feature'.
803 * When your module exits, it must call this method for every feature it
804 * is providing so that the feature table is cleaned up.
805 * @param FeatureName the feature to remove
807 bool UnpublishFeature(const std::string &FeatureName);
809 /** Unpublish your module from an interface
810 * When your module exits, it must call this method for every interface
811 * it is part of so that the interfaces table is cleaned up. Only when
812 * the last item is deleted from an interface does the interface get
814 * @param InterfaceName the interface to be removed from
815 * @param Mod The module to remove from the interface list
817 bool UnpublishInterface(const std::string &InterfaceName, Module* Mod);
819 /** Find a 'feature'.
820 * There are two ways for a module to find another module it depends on.
821 * Either by name, using InspIRCd::FindModule, or by feature, using the
822 * InspIRCd::PublishFeature method. A feature is an arbitary string which
823 * identifies something this module can do. For example, if your module
824 * provides SSL support, but other modules provide SSL support too, all
825 * the modules supporting SSL should publish an identical 'SSL' feature.
826 * To find a module capable of providing the feature you want, simply
827 * call this method with the feature name you are looking for.
828 * @param FeatureName The feature name you wish to obtain the module for
829 * @returns A pointer to a valid module class on success, NULL on failure.
831 Module* FindFeature(const std::string &FeatureName);
833 /** Find an 'interface'.
834 * An interface is a list of modules which all implement the same API.
835 * @param InterfaceName The Interface you wish to obtain the module
837 * @return A pointer to a deque of Module*, or NULL if the interface
840 modulelist* FindInterface(const std::string &InterfaceName);
842 /** Given a pointer to a Module, return its filename
843 * @param m The module pointer to identify
844 * @return The module name or an empty string
846 const std::string& GetModuleName(Module* m);
848 /** Return true if a nickname is valid
849 * @param n A nickname to verify
850 * @return True if the nick is valid
852 bool IsNick(const char* n);
854 /** Return true if an ident is valid
855 * @param An ident to verify
856 * @return True if the ident is valid
858 bool IsIdent(const char* n);
860 /** Find a username by their file descriptor.
861 * It is preferred to use this over directly accessing the fd_ref_table array.
862 * @param socket The file descriptor of a user
863 * @return A pointer to the user if the user exists locally on this descriptor
865 userrec* FindDescriptor(int socket);
867 /** Add a new mode to this server's mode parser
868 * @param mh The modehandler to add
869 * @param modechar The mode character this modehandler handles
870 * @return True if the mode handler was added
872 bool AddMode(ModeHandler* mh, const unsigned char modechar);
874 /** Add a new mode watcher to this server's mode parser
875 * @param mw The modewatcher to add
876 * @return True if the modewatcher was added
878 bool AddModeWatcher(ModeWatcher* mw);
880 /** Delete a mode watcher from this server's mode parser
881 * @param mw The modewatcher to delete
882 * @return True if the modewatcher was deleted
884 bool DelModeWatcher(ModeWatcher* mw);
886 /** Add a dns Resolver class to this server's active set
887 * @param r The resolver to add
888 * @return True if the resolver was added
890 bool AddResolver(Resolver* r);
892 /** Add a command to this server's command parser
893 * @param f A command_t command handler object to add
894 * @throw ModuleException Will throw ModuleExcption if the command already exists
896 void AddCommand(command_t *f);
898 /** Send a modechange.
899 * The parameters provided are identical to that sent to the
900 * handler for class cmd_mode.
901 * @param parameters The mode parameters
902 * @param pcnt The number of items you have given in the first parameter
903 * @param user The user to send error messages to
905 void SendMode(const char **parameters, int pcnt, userrec *user);
907 /** Match two strings using pattern matching.
908 * This operates identically to the global function match(),
909 * except for that it takes std::string arguments rather than
911 * @param sliteral The literal string to match against
912 * @param spattern The pattern to match against. CIDR and globs are supported.
914 bool MatchText(const std::string &sliteral, const std::string &spattern);
916 /** Call the handler for a given command.
917 * @param commandname The command whos handler you wish to call
918 * @param parameters The mode parameters
919 * @param pcnt The number of items you have given in the first parameter
920 * @param user The user to execute the command as
921 * @return True if the command handler was called successfully
923 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
925 /** Return true if the command is a module-implemented command and the given parameters are valid for it
926 * @param parameters The mode parameters
927 * @param pcnt The number of items you have given in the first parameter
928 * @param user The user to test-execute the command as
929 * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
931 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
933 /** Add a gline and apply it
934 * @param duration How long the line should last
935 * @param source Who set the line
936 * @param reason The reason for the line
937 * @param hostmask The hostmask to set the line against
939 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
941 /** Add a qline and apply it
942 * @param duration How long the line should last
943 * @param source Who set the line
944 * @param reason The reason for the line
945 * @param nickname The nickmask to set the line against
947 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
949 /** Add a zline and apply it
950 * @param duration How long the line should last
951 * @param source Who set the line
952 * @param reason The reason for the line
953 * @param ipaddr The ip-mask to set the line against
955 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
957 /** Add a kline and apply it
958 * @param duration How long the line should last
959 * @param source Who set the line
960 * @param reason The reason for the line
961 * @param hostmask The hostmask to set the line against
963 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
966 * @param duration How long the line should last
967 * @param source Who set the line
968 * @param reason The reason for the line
969 * @param hostmask The hostmask to set the line against
971 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
974 * @param hostmask The gline to delete
975 * @return True if the item was removed
977 bool DelGLine(const std::string &hostmask);
980 * @param nickname The qline to delete
981 * @return True if the item was removed
983 bool DelQLine(const std::string &nickname);
986 * @param ipaddr The zline to delete
987 * @return True if the item was removed
989 bool DelZLine(const std::string &ipaddr);
992 * @param hostmask The kline to delete
993 * @return True if the item was removed
995 bool DelKLine(const std::string &hostmask);
998 * @param hostmask The kline to delete
999 * @return True if the item was removed
1001 bool DelELine(const std::string &hostmask);
1003 /** Return true if the given parameter is a valid nick!user\@host mask
1004 * @param mask A nick!user\@host masak to match against
1005 * @return True i the mask is valid
1007 bool IsValidMask(const std::string &mask);
1009 /** Rehash the local server
1011 void RehashServer();
1013 /** Return the channel whos index number matches that provided
1014 * @param The index number of the channel to fetch
1015 * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
1017 chanrec* GetChannelIndex(long index);
1019 /** Dump text to a user target, splitting it appropriately to fit
1020 * @param User the user to dump the text to
1021 * @param LinePrefix text to prefix each complete line with
1022 * @param TextStream the text to send to the user
1024 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
1026 /** Check if the given nickmask matches too many users, send errors to the given user
1027 * @param nick A nickmask to match against
1028 * @param user A user to send error text to
1029 * @return True if the nick matches too many users
1031 bool NickMatchesEveryone(const std::string &nick, userrec* user);
1033 /** Check if the given IP mask matches too many users, send errors to the given user
1034 * @param ip An ipmask to match against
1035 * @param user A user to send error text to
1036 * @return True if the ip matches too many users
1038 bool IPMatchesEveryone(const std::string &ip, userrec* user);
1040 /** Check if the given hostmask matches too many users, send errors to the given user
1041 * @param mask A hostmask to match against
1042 * @param user A user to send error text to
1043 * @return True if the host matches too many users
1045 bool HostMatchesEveryone(const std::string &mask, userrec* user);
1047 /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
1048 * @param str A string containing a time in the form 1y2w3d4h6m5s
1049 * (one year, two weeks, three days, four hours, six minutes and five seconds)
1050 * @return The total number of seconds
1052 long Duration(const char* str);
1054 /** Attempt to compare an oper password to a string from the config file.
1055 * This will be passed to handling modules which will compare the data
1056 * against possible hashed equivalents in the input string.
1057 * @param data The data from the config file
1058 * @param input The data input by the oper
1059 * @param tagnum the tag number of the oper's tag in the config file
1060 * @return 0 if the strings match, 1 or -1 if they do not
1062 int OperPassCompare(const char* data,const char* input, int tagnum);
1064 /** Check if a given server is a uline.
1065 * An empty string returns true, this is by design.
1066 * @param server The server to check for uline status
1067 * @return True if the server is a uline OR the string is empty
1069 bool ULine(const char* server);
1071 /** Returns the subversion revision ID of this ircd
1072 * @return The revision ID or an empty string
1074 std::string GetRevision();
1076 /** Returns the full version string of this ircd
1077 * @return The version string
1079 std::string GetVersionString();
1081 /** Attempt to write the process id to a given file
1082 * @param filename The PID file to attempt to write to
1083 * @return This function may bail if the file cannot be written
1085 void WritePID(const std::string &filename);
1087 /** Returns text describing the last module error
1088 * @return The last error message to occur
1090 char* ModuleError();
1092 /** Load a given module file
1093 * @param filename The file to load
1094 * @return True if the module was found and loaded
1096 bool LoadModule(const char* filename);
1098 /** Unload a given module file
1099 * @param filename The file to unload
1100 * @return True if the module was unloaded
1102 bool UnloadModule(const char* filename);
1104 /** This constructor initialises all the subsystems and reads the config file.
1105 * @param argc The argument count passed to main()
1106 * @param argv The argument list passed to main()
1107 * @throw <anything> If anything is thrown from here and makes it to
1108 * you, you should probably just give up and go home. Yes, really.
1109 * It's that bad. Higher level classes should catch any non-fatal exceptions.
1111 InspIRCd(int argc, char** argv);
1113 /** Do one iteration of the mainloop
1114 * @param process_module_sockets True if module sockets are to be processed
1115 * this time around the event loop. The is the default.
1117 void DoOneIteration(bool process_module_sockets = true);
1119 /** Output a log message to the ircd.log file
1120 * The text will only be output if the current loglevel
1121 * is less than or equal to the level you provide
1122 * @param level A log level from the DebugLevel enum
1123 * @param text Format string of to write to the log
1124 * @param ... Format arguments of text to write to the log
1126 void Log(int level, const char* text, ...);
1128 /** Output a log message to the ircd.log file
1129 * The text will only be output if the current loglevel
1130 * is less than or equal to the level you provide
1131 * @param level A log level from the DebugLevel enum
1132 * @param text Text to write to the log
1134 void Log(int level, const std::string &text);
1136 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text);
1138 void SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...);
1140 /** Restart the server.
1141 * This function will not return. If an error occurs,
1142 * it will throw an instance of CoreException.
1143 * @param reason The restart reason to show to all clients
1144 * @throw CoreException An instance of CoreException indicating the error from execv().
1146 void Restart(const std::string &reason);
1148 /** Prepare the ircd for restart or shutdown.
1149 * This function unloads all modules which can be unloaded,
1150 * closes all open sockets, and closes the logfile.
1154 /** This copies the user and channel hash_maps into new hash maps.
1155 * This frees memory used by the hash_map allocator (which it neglects
1156 * to free, most of the time, using tons of ram)
1158 void RehashUsersAndChans();
1160 /** Begin execution of the server.
1161 * NOTE: this function NEVER returns. Internally,
1162 * after performing some initialisation routines,
1163 * it will repeatedly call DoOneIteration in a loop.
1164 * @return The return value for this function is undefined.