2012-04-19 20:58:29 +02:00
/*
* InspIRCd - - Internet Relay Chat Daemon
2007-07-16 17:30:04 +00:00
*
2012-04-19 20:58:29 +02:00
* Copyright ( C ) 2009 Daniel De Graaf < danieldg @ inspircd . org >
* Copyright ( C ) 2007 - 2008 Robin Burchell < robin + git @ viroteck . net >
* Copyright ( C ) 2008 Pippijn van Steenhoven < pip88nl @ gmail . com >
* Copyright ( C ) 2003 - 2008 Craig Edwards < craigedwards @ brainbox . cc >
* Copyright ( C ) 2006 - 2007 Oliver Lupton < oliverlupton @ gmail . com >
* Copyright ( C ) 2007 Dennis Friis < peavey @ inspircd . org >
* Copyright ( C ) 2003 randomdan < ? ? ? @ ? ? ? >
2007-07-16 17:30:04 +00:00
*
2012-04-19 20:58:29 +02:00
* This file is part of InspIRCd . InspIRCd is free software : you can
* redistribute it and / or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation , version 2.
2007-07-16 17:30:04 +00:00
*
2012-04-19 20:58:29 +02:00
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE . See the GNU General Public License for more
* details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-07-16 17:30:04 +00:00
*/
2012-04-19 20:58:29 +02:00
2013-04-02 20:12:15 +01:00
# pragma once
2007-07-16 17:30:04 +00:00
2008-07-01 18:04:35 +00:00
# include <climits>
2013-05-07 03:55:29 +01:00
# include <cmath>
# include <csignal>
# include <cstdarg>
2009-03-25 05:08:58 +00:00
# include <cstdio>
2013-05-07 03:55:29 +01:00
# include <cstring>
# include <ctime>
2016-02-25 15:02:01 +01:00
# include <stdint.h>
2008-07-20 08:53:56 +00:00
2013-05-07 03:55:29 +01:00
# include <algorithm>
# include <bitset>
2008-07-19 20:34:14 +00:00
# include <deque>
2013-05-07 03:55:29 +01:00
# include <list>
2008-07-19 20:34:14 +00:00
# include <map>
2008-10-18 16:52:46 +00:00
# include <set>
2013-05-07 03:55:29 +01:00
# include <sstream>
# include <string>
# include <vector>
2014-01-24 12:58:01 +01:00
# include "intrusive_list.h"
2014-12-15 17:36:20 +01:00
# include "flat_map.h"
2013-05-07 03:55:29 +01:00
# include "compat.h"
2014-09-27 18:24:44 +02:00
# include "aligned_storage.h"
2009-10-24 20:03:53 +00:00
# include "typedefs.h"
2014-03-24 16:33:09 +01:00
# include "stdalgo.h"
2008-07-19 20:34:14 +00:00
2009-10-11 15:23:33 +00:00
CoreExport extern InspIRCd * ServerInstance ;
2009-09-13 20:32:27 +00:00
2014-06-24 12:08:20 +02:00
/** Base class for manager classes that are still accessed using -> but are no longer pointers
*/
template < typename T >
struct fakederef
{
T * operator - > ( )
{
return static_cast < T * > ( this ) ;
}
} ;
2013-05-07 03:55:29 +01:00
# include "config.h"
2016-02-25 15:15:00 +01:00
# include "convto.h"
2013-06-18 18:19:28 +02:00
# include "dynref.h"
2013-05-07 03:55:29 +01:00
# include "consolecolors.h"
2009-10-14 22:12:55 +00:00
# include "caller.h"
# include "cull_list.h"
2009-09-13 20:30:25 +00:00
# include "extensible.h"
2013-10-05 04:55:11 +01:00
# include "fileutils.h"
2008-07-13 19:01:17 +00:00
# include "numerics.h"
2016-02-25 15:25:02 +01:00
# include "numeric.h"
2007-08-26 23:07:06 +00:00
# include "uid.h"
2014-01-05 15:04:01 +01:00
# include "server.h"
2007-07-16 17:30:04 +00:00
# include "users.h"
# include "channels.h"
2008-02-03 23:20:20 +00:00
# include "timer.h"
2008-02-02 20:55:16 +00:00
# include "hashcomp.h"
2008-02-09 11:35:27 +00:00
# include "logger.h"
2008-02-02 20:55:16 +00:00
# include "usermanager.h"
2007-07-16 17:30:04 +00:00
# include "socket.h"
2008-02-03 23:20:20 +00:00
# include "ctables.h"
# include "command_parse.h"
2007-07-16 17:30:04 +00:00
# include "mode.h"
# include "socketengine.h"
# include "snomasks.h"
2007-07-25 11:53:07 +00:00
# include "filelogger.h"
2008-02-03 23:20:20 +00:00
# include "modules.h"
2009-10-25 15:21:45 +00:00
# include "threadengine.h"
2008-02-03 23:20:20 +00:00
# include "configreader.h"
# include "inspstring.h"
2008-04-04 12:30:38 +00:00
# include "protocol.h"
2014-06-13 15:23:39 +02:00
# include "bancache.h"
2014-07-14 16:39:09 +02:00
# include "isupportmanager.h"
2008-07-12 21:49:45 +00:00
2007-07-16 17:30:04 +00:00
/** This class contains various STATS counters
* It is used by the InspIRCd class , which internally
* has an instance of it .
*/
2009-10-18 16:18:44 +00:00
class serverstats
2007-07-16 17:30:04 +00:00
{
public :
/** Number of accepted connections
*/
2014-06-13 15:03:56 +02:00
unsigned long Accept ;
2007-07-16 17:30:04 +00:00
/** Number of failed accepts
*/
2014-06-13 15:03:56 +02:00
unsigned long Refused ;
2007-07-16 17:30:04 +00:00
/** Number of unknown commands seen
*/
2014-06-13 15:03:56 +02:00
unsigned long Unknown ;
2007-07-16 17:30:04 +00:00
/** Number of nickname collisions handled
*/
2014-06-13 15:03:56 +02:00
unsigned long Collisions ;
2007-07-16 17:30:04 +00:00
/** Number of DNS queries sent out
*/
2014-06-13 15:03:56 +02:00
unsigned long Dns ;
2007-07-16 17:30:04 +00:00
/** Number of good DNS replies received
* NOTE : This may not tally to the number sent out ,
* due to timeouts and other latency issues .
*/
2014-06-13 15:03:56 +02:00
unsigned long DnsGood ;
2007-07-16 17:30:04 +00:00
/** Number of bad (negative) DNS replies received
* NOTE : This may not tally to the number sent out ,
* due to timeouts and other latency issues .
*/
2014-06-13 15:03:56 +02:00
unsigned long DnsBad ;
2007-07-16 17:30:04 +00:00
/** Number of inbound connections seen
*/
2014-06-13 15:03:56 +02:00
unsigned long Connects ;
2007-07-16 17:30:04 +00:00
/** Total bytes of data transmitted
*/
2014-06-13 15:03:56 +02:00
unsigned long Sent ;
2007-07-16 17:30:04 +00:00
/** Total bytes of data received
*/
2014-06-13 15:03:56 +02:00
unsigned long Recv ;
Windows: In-depth cleanup (see details)
-Fix x64 builds for Windows. Now all configurations compile.
-Remove the non-working rebase stuff.
-Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now.
-Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2
-Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need.
-Enable optimizations for release builds.
-De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure
-Add the VC++ specific bad files in .gitignore
-Disable PID writing on Windows. This is only making sense for *nix builds.
-Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working)
-Removed certain unused functions and variables
-Remove stdint defines from the windows wrapper
-Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds.
-Re-evaluated the warnings list, commented it.
-Moved inspircd_config/_version to include/ to match *nix
-Removed the creation of inspircd_se_config, as it isn't used at all.
-Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out)
-Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly.
-Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down)
-Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded.
-Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways)
-Removed the unused ClearConsole()
-Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate.
-Made inet_aton an inline function for increased performance
-C4800, performance warning about bool forcing, resolved at all occurrences.
-C4701, uninitialized variable 'cached', resolved at all occurrences.
-dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance.
-Removed the wrong CRT debug flags. This drains a lot of performance.
-Removed the clock_gettime/gettimeofday wrappers
-Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function.
-Added a block of C4355 for < VS2012
-Update project files for c870714
2012-10-12 22:31:38 +02:00
# ifdef _WIN32
/** Cpu usage at last sample
*/
FILETIME LastCPU ;
/** Time QP sample was read
*/
LARGE_INTEGER LastSampled ;
/** QP frequency
*/
LARGE_INTEGER QPFrequency ;
# else
2007-07-16 17:30:04 +00:00
/** Cpu usage at last sample
*/
timeval LastCPU ;
/** Time last sample was read
*/
2010-01-18 19:36:41 +00:00
timespec LastSampled ;
Windows: In-depth cleanup (see details)
-Fix x64 builds for Windows. Now all configurations compile.
-Remove the non-working rebase stuff.
-Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now.
-Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2
-Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need.
-Enable optimizations for release builds.
-De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure
-Add the VC++ specific bad files in .gitignore
-Disable PID writing on Windows. This is only making sense for *nix builds.
-Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working)
-Removed certain unused functions and variables
-Remove stdint defines from the windows wrapper
-Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds.
-Re-evaluated the warnings list, commented it.
-Moved inspircd_config/_version to include/ to match *nix
-Removed the creation of inspircd_se_config, as it isn't used at all.
-Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out)
-Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly.
-Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down)
-Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded.
-Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways)
-Removed the unused ClearConsole()
-Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate.
-Made inet_aton an inline function for increased performance
-C4800, performance warning about bool forcing, resolved at all occurrences.
-C4701, uninitialized variable 'cached', resolved at all occurrences.
-dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance.
-Removed the wrong CRT debug flags. This drains a lot of performance.
-Removed the clock_gettime/gettimeofday wrappers
-Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function.
-Added a block of C4355 for < VS2012
-Update project files for c870714
2012-10-12 22:31:38 +02:00
# endif
2007-07-16 17:30:04 +00:00
/** The constructor initializes all the counts to zero
*/
serverstats ( )
2014-06-13 15:03:56 +02:00
: Accept ( 0 ) , Refused ( 0 ) , Unknown ( 0 ) , Collisions ( 0 ) , Dns ( 0 ) ,
DnsGood ( 0 ) , DnsBad ( 0 ) , Connects ( 0 ) , Sent ( 0 ) , Recv ( 0 )
2007-07-16 17:30:04 +00:00
{
}
} ;
2013-05-18 18:55:01 +01:00
DEFINE_HANDLER1 ( IsNickHandler , bool , const std : : string & ) ;
2010-02-09 02:22:27 +00:00
DEFINE_HANDLER2 ( GenRandomHandler , void , char * , size_t ) ;
2013-04-01 16:20:35 +02:00
DEFINE_HANDLER1 ( IsIdentHandler , bool , const std : : string & ) ;
2013-05-18 18:55:01 +01:00
DEFINE_HANDLER1 ( IsChannelHandler , bool , const std : : string & ) ;
2007-07-25 16:58:56 +00:00
2007-07-16 17:30:04 +00:00
/** The main class of the irc server.
2009-10-18 16:18:44 +00:00
* This class contains instances of all the other classes in this software .
* Amongst other things , it contains a ModeParser , a DNS object , a CommandParser
* object , and a list of active Module objects , and facilities for Module
* objects to interact with the core system it implements .
2007-07-16 17:30:04 +00:00
*/
2009-10-18 16:18:44 +00:00
class CoreExport InspIRCd
2007-07-16 17:30:04 +00:00
{
private :
/** Set up the signal handlers
*/
void SetSignals ( ) ;
/** Daemonize the ircd and close standard input/output streams
* @ return True if the program daemonized succesfully
*/
bool DaemonSeed ( ) ;
/** The current time, updated in the mainloop
*/
2010-01-18 19:36:41 +00:00
struct timespec TIME ;
2007-07-16 17:30:04 +00:00
2008-07-20 09:15:01 +00:00
/** A 64k buffer used to read socket data into
* NOTE : update ValidateNetBufferSize if you change this
2007-07-16 17:30:04 +00:00
*/
char ReadBuffer [ 65535 ] ;
2013-06-18 21:20:30 +02:00
/** Check we aren't running as root, and exit if we are
* with exit code EXIT_STATUS_ROOT .
*/
void CheckRoot ( ) ;
2007-07-16 17:30:04 +00:00
public :
2013-04-14 18:20:02 +02:00
UIDGenerator UIDGen ;
2007-07-25 16:58:56 +00:00
/** Global cull list, will be processed on next iteration
*/
CullList GlobalCulls ;
2009-10-14 22:12:55 +00:00
/** Actions that must happen outside of the current call stack */
ActionList AtomicActions ;
2007-07-25 16:58:56 +00:00
/**** Functors ****/
2007-07-25 17:21:30 +00:00
IsNickHandler HandleIsNick ;
IsIdentHandler HandleIsIdent ;
2008-04-13 03:28:56 +00:00
IsChannelHandler HandleIsChannel ;
2010-02-09 02:22:27 +00:00
GenRandomHandler HandleGenRandom ;
2007-07-25 16:58:56 +00:00
2007-08-28 13:23:47 +00:00
/** Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1
2007-08-28 13:50:04 +00:00
* Reason for it :
* kludge alert !
2007-10-15 20:59:05 +00:00
* SendMode expects a User * to send the numeric replies
2007-08-28 13:50:04 +00:00
* back to , so we create it a fake user that isnt in the user
* hash and set its descriptor to FD_MAGIC_NUMBER so the data
* falls into the abyss : p
2007-08-28 13:23:47 +00:00
*/
2009-05-13 05:27:39 +00:00
FakeUser * FakeClient ;
2007-08-28 13:23:47 +00:00
2007-08-27 01:01:20 +00:00
/** Find a user in the UUID hash
2012-07-05 21:00:35 +01:00
* @ param uid The UUID to find
2007-08-27 01:01:20 +00:00
* @ return A pointer to the user , or NULL if the user does not exist
*/
2012-07-05 21:00:35 +01:00
User * FindUUID ( const std : : string & uid ) ;
2007-08-27 01:01:20 +00:00
2007-07-16 17:30:04 +00:00
/** Time this ircd was booted
*/
time_t startup_time ;
/** Config file pathname specified on the commandline or via ./configure
*/
2009-09-24 01:44:29 +00:00
std : : string ConfigFileName ;
2007-07-16 17:30:04 +00:00
2009-10-14 18:39:38 +00:00
ExtensionManager Extensions ;
2007-07-16 17:30:04 +00:00
/** Mode handler, handles mode setting and removal
*/
2014-06-24 12:10:59 +02:00
ModeParser Modes ;
2007-07-16 17:30:04 +00:00
/** Command parser, handles client to server commands
*/
2014-06-13 15:45:55 +02:00
CommandParser Parser ;
2007-07-16 17:30:04 +00:00
2008-02-24 14:09:02 +00:00
/** Thread engine, Handles threading where required
*/
2014-06-13 15:09:20 +02:00
ThreadEngine Threads ;
2008-02-24 14:09:02 +00:00
/** The thread/class used to read config files in REHASH and on startup
*/
ConfigReaderThread * ConfigThread ;
2008-02-09 11:43:25 +00:00
/** LogManager handles logging.
*/
2014-06-24 12:15:03 +02:00
LogManager Logs ;
2008-06-12 21:00:48 +00:00
2007-08-28 23:32:41 +00:00
/** ModuleManager contains everything related to loading/unloading
* modules .
*/
2014-06-24 12:16:57 +02:00
ModuleManager Modules ;
2007-07-16 17:30:04 +00:00
2007-11-04 13:23:15 +00:00
/** BanCacheManager is used to speed up checking of restrictions on connection
* to the IRCd .
*/
2014-06-13 15:27:40 +02:00
BanCacheManager BanCache ;
2007-11-04 13:23:15 +00:00
2007-07-16 17:30:04 +00:00
/** Stats class, holds miscellaneous stats counters
*/
2014-06-13 15:03:56 +02:00
serverstats stats ;
2007-07-16 17:30:04 +00:00
/** Server Config class, holds configuration file data
*/
ServerConfig * Config ;
/** Snomask manager - handles routing of snomask messages
* to opers .
*/
2014-06-24 12:20:02 +02:00
SnomaskManager SNO ;
2007-07-16 17:30:04 +00:00
2007-10-15 21:03:30 +00:00
/** Timer manager class, triggers Timer timer events
2007-07-16 17:30:04 +00:00
*/
2014-03-15 15:38:09 +01:00
TimerManager Timers ;
2007-07-16 17:30:04 +00:00
/** X-Line manager. Handles G/K/Q/E line setting, removal and matching
*/
XLineManager * XLines ;
2008-01-13 03:37:25 +00:00
/** User manager. Various methods and data associated with users.
*/
2014-06-24 12:21:31 +02:00
UserManager Users ;
2008-01-13 03:37:25 +00:00
2008-02-02 20:55:16 +00:00
/** Channel list, a hash_map containing all channels XXX move to channel manager class
*/
2014-03-14 12:59:19 +01:00
chan_hash chanlist ;
2008-02-02 20:55:16 +00:00
2009-07-01 22:55:39 +00:00
/** List of the open ports
*/
2009-10-21 23:46:33 +00:00
std : : vector < ListenSocket * > ports ;
2009-07-01 22:55:39 +00:00
2007-07-25 19:46:25 +00:00
/** Set to the current signal recieved
*/
2013-05-07 03:55:29 +01:00
static sig_atomic_t s_signal ;
2007-07-25 19:46:25 +00:00
2008-04-04 12:30:38 +00:00
/** Protocol interface, overridden by server protocol modules
*/
ProtocolInterface * PI ;
2014-06-13 15:59:37 +02:00
/** Default implementation of the ProtocolInterface, does nothing
*/
ProtocolInterface DefaultProtocolInterface ;
2013-04-07 22:23:25 +01:00
/** Manages the generation and transmission of ISUPPORT. */
ISupportManager ISupport ;
2007-07-16 17:30:04 +00:00
/** Get the current time
* Because this only calls time ( ) once every time around the mainloop ,
* it is much faster than calling time ( ) directly .
* @ return The current time as an epoch value ( time_t )
*/
2010-01-18 19:36:41 +00:00
inline time_t Time ( ) { return TIME . tv_sec ; }
/** The fractional time at the start of this mainloop iteration (nanoseconds) */
inline long Time_ns ( ) { return TIME . tv_nsec ; }
/** Update the current time. Don't call this unless you have reason to do so. */
void UpdateTime ( ) ;
2007-07-16 17:30:04 +00:00
2010-02-09 02:22:27 +00:00
/** Generate a random string with the given length
* @ param length The length in bytes
* @ param printable if false , the string will use characters 0 - 255 ; otherwise ,
* it will be limited to 0x30 - 0x7E ( ' 0 ' - ' ~ ' , nonspace printable characters )
*/
2017-11-17 00:02:03 +00:00
std : : string GenRandomStr ( unsigned int length , bool printable = true ) ;
2010-02-09 02:22:27 +00:00
/** Generate a random integer.
* This is generally more secure than rand ( )
*/
unsigned long GenRandomInt ( unsigned long max ) ;
/** Fill a buffer with random bits */
caller2 < void , char * , size_t > GenRandom ;
2007-07-16 17:30:04 +00:00
/** Bind all ports specified in the configuration file.
2009-07-01 22:55:46 +00:00
* @ return The number of ports bound without error
2007-07-16 17:30:04 +00:00
*/
2009-07-01 22:55:46 +00:00
int BindPorts ( FailedPortList & failed_ports ) ;
2007-07-16 17:30:04 +00:00
2007-08-27 13:54:15 +00:00
/** Find a user in the nick hash.
* If the user cant be found in the nick hash check the uuid hash
2007-07-16 17:30:04 +00:00
* @ param nick The nickname to find
* @ return A pointer to the user , or NULL if the user does not exist
*/
2007-10-15 20:59:05 +00:00
User * FindNick ( const std : : string & nick ) ;
2007-07-16 17:30:04 +00:00
2007-08-27 13:54:15 +00:00
/** Find a user in the nick hash ONLY
*/
2007-10-15 20:59:05 +00:00
User * FindNickOnly ( const std : : string & nick ) ;
2007-08-27 13:54:15 +00:00
2007-07-16 17:30:04 +00:00
/** Find a channel in the channels hash
* @ param chan The channel to find
* @ return A pointer to the channel , or NULL if the channel does not exist
*/
2007-10-15 20:59:05 +00:00
Channel * FindChan ( const std : : string & chan ) ;
2007-07-16 17:30:04 +00:00
2014-03-14 12:56:20 +01:00
/** Get a hash map containing all channels, keyed by their name
* @ return A hash map mapping channel names to Channel pointers
*/
2014-03-14 12:59:19 +01:00
chan_hash & GetChans ( ) { return chanlist ; }
2014-03-14 12:56:20 +01:00
2007-07-16 17:30:04 +00:00
/** Return true if a channel name is valid
* @ param chname A channel name to verify
* @ return True if the name is valid
*/
2013-05-18 18:55:01 +01:00
caller1 < bool , const std : : string & > IsChannel ;
2007-07-16 17:30:04 +00:00
2008-01-16 21:36:07 +00:00
/** Return true if str looks like a server ID
2013-06-21 03:52:56 +01:00
* @ param sid string to check against
2008-01-16 21:36:07 +00:00
*/
2013-04-01 16:15:19 +02:00
static bool IsSID ( const std : : string & sid ) ;
2008-01-16 21:36:07 +00:00
2007-07-25 19:46:25 +00:00
/** Handles incoming signals after being set
* @ param signal the signal recieved
*/
void SignalHandler ( int signal ) ;
2008-06-12 21:00:48 +00:00
/** Sets the signal recieved
2007-07-25 19:46:25 +00:00
* @ param signal the signal recieved
*/
static void SetSignal ( int signal ) ;
2007-07-16 17:30:04 +00:00
/** Causes the server to exit after unloading modules and
* closing all open file descriptors .
*
2012-07-05 21:00:35 +01:00
* @ param status The exit code to give to the operating system
2007-07-16 17:30:04 +00:00
* ( See the ExitStatus enum for valid values )
*/
2007-07-25 20:23:18 +00:00
void Exit ( int status ) ;
2007-07-16 17:30:04 +00:00
/** Causes the server to exit immediately with exit code 0.
* The status code is required for signal handlers , and ignored .
*/
2013-06-18 21:20:30 +02:00
static void QuickExit ( int status ) ;
2013-05-12 10:54:07 -07:00
2013-06-21 03:52:56 +01:00
/** Formats the input string with the specified arguments.
* @ param formatString The string to format
* @ param . . . A variable number of format arguments .
2013-05-12 10:54:07 -07:00
* @ return The formatted string
*/
2013-05-18 11:31:25 -07:00
static const char * Format ( const char * formatString , . . . ) CUSTOM_PRINTF ( 1 , 2 ) ;
2013-05-20 14:20:08 -04:00
static const char * Format ( va_list & vaList , const char * formatString ) CUSTOM_PRINTF ( 2 , 0 ) ;
2013-05-12 10:54:07 -07:00
2007-07-16 17:30:04 +00:00
/** Return true if a nickname is valid
* @ param n A nickname to verify
* @ return True if the nick is valid
*/
2013-05-18 18:55:01 +01:00
caller1 < bool , const std : : string & > IsNick ;
2007-07-16 17:30:04 +00:00
/** Return true if an ident is valid
* @ param An ident to verify
* @ return True if the ident is valid
*/
2013-04-01 16:20:35 +02:00
caller1 < bool , const std : : string & > IsIdent ;
2007-07-16 17:30:04 +00:00
2008-08-21 20:56:16 +00:00
/** Match two strings using pattern matching, optionally, with a map
2008-08-22 16:14:36 +00:00
* to check case against ( may be NULL ) . If map is null , match will be case insensitive .
2008-08-21 20:56:16 +00:00
* @ param str The literal string to match against
* @ param mask The glob pattern to match against .
2012-07-05 21:00:35 +01:00
* @ param map The character map to use when matching .
2008-08-21 20:56:16 +00:00
*/
2013-08-07 14:37:30 +01:00
static bool Match ( const std : : string & str , const std : : string & mask , unsigned const char * map = NULL ) ;
static bool Match ( const char * str , const char * mask , unsigned const char * map = NULL ) ;
2008-08-21 20:56:16 +00:00
/** Match two strings using pattern matching, optionally, with a map
2008-08-22 16:14:36 +00:00
* to check case against ( may be NULL ) . If map is null , match will be case insensitive .
* Supports CIDR patterns as well as globs .
2008-08-21 20:56:16 +00:00
* @ param str The literal string to match against
* @ param mask The glob or CIDR pattern to match against .
2012-07-05 21:00:35 +01:00
* @ param map The character map to use when matching .
2008-08-21 20:56:16 +00:00
*/
2013-08-07 14:37:30 +01:00
static bool MatchCIDR ( const std : : string & str , const std : : string & mask , unsigned const char * map = NULL ) ;
static bool MatchCIDR ( const char * str , const char * mask , unsigned const char * map = NULL ) ;
2013-05-06 11:49:50 +01:00
/** Matches a hostname and IP against a space delimited list of hostmasks.
* @ param masks The space delimited masks to match against .
* @ param hostname The hostname to try and match .
* @ param ipaddr The IP address to try and match .
*/
static bool MatchMask ( const std : : string & masks , const std : : string & hostname , const std : : string & ipaddr ) ;
2007-07-16 17:30:04 +00:00
/** Return true if the given parameter is a valid nick!user\@host mask
* @ param mask A nick ! user \ @ host masak to match against
* @ return True i the mask is valid
*/
2013-12-15 05:34:00 +00:00
static bool IsValidMask ( const std : : string & mask ) ;
2012-10-29 18:33:07 +01:00
2015-12-08 16:32:50 +01:00
/** Strips all color and control codes except 001 from the given string
2012-10-29 18:33:07 +01:00
* @ param sentence The string to strip from
2012-09-12 16:27:59 +01:00
*/
static void StripColor ( std : : string & sentence ) ;
2007-07-16 17:30:04 +00:00
2012-10-29 17:19:21 +01:00
/** Parses color codes from string values to actual color codes
* @ param input The data to process
*/
static void ProcessColors ( file_cache & input ) ;
2007-07-16 17:30:04 +00:00
/** Rehash the local server
2013-09-08 17:21:01 +02:00
* @ param uuid The uuid of the user who started the rehash , can be empty
2007-07-16 17:30:04 +00:00
*/
2013-09-08 17:21:01 +02:00
void Rehash ( const std : : string & uuid = " " ) ;
2007-07-16 17:30:04 +00:00
/** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
* @ param str A string containing a time in the form 1 y2w3d4h6m5s
* ( one year , two weeks , three days , four hours , six minutes and five seconds )
* @ return The total number of seconds
*/
2013-04-03 15:54:28 +02:00
static unsigned long Duration ( const std : : string & str ) ;
2007-07-16 17:30:04 +00:00
2008-01-27 00:12:11 +00:00
/** Attempt to compare a password to a string from the config file.
2007-07-16 17:30:04 +00:00
* This will be passed to handling modules which will compare the data
* against possible hashed equivalents in the input string .
2008-01-27 00:12:11 +00:00
* @ param ex The object ( user , server , whatever ) causing the comparison .
2007-07-16 17:30:04 +00:00
* @ param data The data from the config file
* @ param input The data input by the oper
2008-01-27 00:12:11 +00:00
* @ param hashtype The hash from the config file
2014-01-18 04:53:52 +00:00
* @ return True if the strings match , false if they do not
2007-07-16 17:30:04 +00:00
*/
2014-01-18 04:53:52 +00:00
bool PassCompare ( Extensible * ex , const std : : string & data , const std : : string & input , const std : : string & hashtype ) ;
2007-07-16 17:30:04 +00:00
/** Returns the full version string of this ircd
* @ return The version string
*/
2013-05-06 11:49:50 +01:00
std : : string GetVersionString ( bool getFullVersion = false ) ;
2007-07-16 17:30:04 +00:00
/** Attempt to write the process id to a given file
* @ param filename The PID file to attempt to write to
2016-06-17 12:04:12 +02:00
* @ param exitonfail If true and the PID fail cannot be written log to stdout and exit , otherwise only log on failure
2007-07-16 17:30:04 +00:00
* @ return This function may bail if the file cannot be written
*/
2016-06-17 12:04:12 +02:00
void WritePID ( const std : : string & filename , bool exitonfail = true ) ;
2007-07-16 17:30:04 +00:00
/** This constructor initialises all the subsystems and reads the config file.
* @ param argc The argument count passed to main ( )
* @ param argv The argument list passed to main ( )
* @ throw < anything > If anything is thrown from here and makes it to
* you , you should probably just give up and go home . Yes , really .
* It ' s that bad . Higher level classes should catch any non - fatal exceptions .
*/
InspIRCd ( int argc , char * * argv ) ;
/** Prepare the ircd for restart or shutdown.
* This function unloads all modules which can be unloaded ,
* closes all open sockets , and closes the logfile .
*/
void Cleanup ( ) ;
/** Return a time_t as a human-readable string.
2014-05-02 16:39:40 +01:00
* @ param format The format to retrieve the date / time in . See ` man 3 strftime `
* for more information . If NULL , " %a %b %d %T %Y " is assumed .
2017-08-25 13:03:53 +01:00
* @ param curtime The timestamp to convert to a human - readable string .
2014-06-13 00:09:34 +01:00
* @ param utc True to convert the time to string as - is , false to convert it to local time first .
2014-05-02 16:39:40 +01:00
* @ return A string representing the given date / time .
2007-07-16 17:30:04 +00:00
*/
2014-06-13 00:09:34 +01:00
static std : : string TimeString ( time_t curtime , const char * format = NULL , bool utc = false ) ;
2007-07-16 17:30:04 +00:00
2014-06-28 18:25:05 +02:00
/** Compare two strings in a timing-safe way. If the lengths of the strings differ, the function
* returns false immediately ( leaking information about the length ) , otherwise it compares each
* character and only returns after all characters have been compared .
* @ param one First string
* @ param two Second string
* @ return True if the strings match , false if they don ' t
*/
static bool TimingSafeCompare ( const std : : string & one , const std : : string & two ) ;
2007-07-16 17:30:04 +00:00
/** Begin execution of the server.
* NOTE : this function NEVER returns . Internally ,
2007-09-23 19:19:14 +00:00
* it will repeatedly loop .
2007-07-16 17:30:04 +00:00
*/
2013-06-18 21:20:30 +02:00
void Run ( ) ;
2007-07-23 23:10:16 +00:00
2007-07-26 16:36:37 +00:00
char * GetReadBuffer ( )
{
return this - > ReadBuffer ;
}
2007-07-16 17:30:04 +00:00
} ;
2008-08-21 11:01:51 +00:00
ENTRYPOINT ;
2009-09-03 02:30:12 +00:00
template < class Cmd >
class CommandModule : public Module
{
Cmd cmd ;
public :
2009-09-26 14:13:13 +00:00
CommandModule ( ) : cmd ( this )
2009-09-03 02:30:12 +00:00
{
2010-01-19 15:16:41 +00:00
}
2017-11-21 13:05:17 +00:00
Version GetVersion ( ) CXX11_OVERRIDE
2009-09-03 02:30:12 +00:00
{
2009-11-15 18:26:53 +00:00
return Version ( cmd . name , VF_VENDOR | VF_CORE ) ;
2009-09-03 02:30:12 +00:00
}
} ;
2014-03-24 16:44:04 +01:00
inline void stdalgo : : culldeleter : : operator ( ) ( classbase * item )
{
if ( item )
ServerInstance - > GlobalCulls . AddItem ( item ) ;
}
2015-04-28 15:16:22 +02:00
2015-12-30 13:20:21 +01:00
# include "numericbuilder.h"
2015-04-28 15:16:22 +02:00
# include "modules/whois.h"
2016-02-25 17:02:03 +01:00
# include "modules/stats.h"