2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
|
|
|
|
* Copyright (C) 2012-2016, 2018 Attila Molnar <attilamolnar@hush.com>
|
2024-06-07 10:37:56 +01:00
|
|
|
* Copyright (C) 2012-2013, 2017-2023 Sadie Powell <sadie@witchery.services>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
|
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
|
|
|
* Copyright (C) 2007-2009 Dennis Friis <peavey@inspircd.org>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2007 Oliver Lupton <om@inspircd.org>
|
2022-12-30 11:31:28 +00:00
|
|
|
* Copyright (C) 2005-2008 Craig Edwards <brain@inspircd.org>
|
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
|
|
|
|
2018-04-14 16:11:57 +01:00
|
|
|
#include <cfloat>
|
2008-07-01 18:04:35 +00:00
|
|
|
#include <climits>
|
2013-05-07 03:55:29 +01:00
|
|
|
#include <csignal>
|
|
|
|
#include <cstdarg>
|
2018-07-31 03:02:16 +01:00
|
|
|
#include <cstdint>
|
2013-05-07 03:55:29 +01:00
|
|
|
#include <cstring>
|
2008-07-20 08:53:56 +00:00
|
|
|
|
2013-05-07 03:55:29 +01:00
|
|
|
#include <algorithm>
|
2018-07-31 03:02:16 +01:00
|
|
|
#include <array>
|
2019-07-16 15:11:21 +01:00
|
|
|
#include <atomic>
|
2013-05-07 03:55:29 +01:00
|
|
|
#include <bitset>
|
2008-07-19 20:34:14 +00:00
|
|
|
#include <deque>
|
2018-07-31 03:02:16 +01:00
|
|
|
#include <functional>
|
2020-10-31 16:55:18 +00:00
|
|
|
#include <memory>
|
2008-07-19 20:34:14 +00:00
|
|
|
#include <map>
|
2021-06-07 07:43:03 +01:00
|
|
|
#include <optional>
|
2008-10-18 16:52:46 +00:00
|
|
|
#include <set>
|
2013-05-07 03:55:29 +01:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2021-04-08 18:38:39 +01:00
|
|
|
#include <string_view>
|
2018-07-31 03:02:16 +01:00
|
|
|
#include <unordered_map>
|
2013-05-07 03:55:29 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2022-04-30 17:43:47 +01:00
|
|
|
#ifndef _WIN32
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2021-03-02 03:05:42 +00:00
|
|
|
#include "utility/aligned_storage.h"
|
2021-03-02 02:44:41 +00:00
|
|
|
#include "utility/iterator_range.h"
|
|
|
|
|
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"
|
2009-10-24 20:03:53 +00:00
|
|
|
#include "typedefs.h"
|
2018-07-26 21:23:45 +01:00
|
|
|
#include "convto.h"
|
2014-03-24 16:33:09 +01:00
|
|
|
#include "stdalgo.h"
|
2022-01-07 17:12:42 +00:00
|
|
|
#include "exception.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
|
|
|
|
2013-05-07 03:55:29 +01:00
|
|
|
#include "config.h"
|
2013-06-18 18:19:28 +02:00
|
|
|
#include "dynref.h"
|
2021-03-02 05:39:12 +00:00
|
|
|
#include "cull.h"
|
2009-09-13 20:30:25 +00:00
|
|
|
#include "extensible.h"
|
2018-07-26 19:43:54 +01:00
|
|
|
#include "ctables.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"
|
2023-09-03 18:40:03 +01:00
|
|
|
#include "token_list.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"
|
2020-06-21 04:25:45 +01:00
|
|
|
#include "channelmanager.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 "command_parse.h"
|
2007-07-16 17:30:04 +00:00
|
|
|
#include "mode.h"
|
|
|
|
#include "socketengine.h"
|
|
|
|
#include "snomasks.h"
|
2017-12-11 19:42:52 +00:00
|
|
|
#include "message.h"
|
2008-02-03 23:20:20 +00:00
|
|
|
#include "modules.h"
|
2022-06-26 17:02:47 +01:00
|
|
|
#include "moduledefs.h"
|
2018-08-13 20:17:46 +01:00
|
|
|
#include "clientprotocol.h"
|
2019-05-15 16:22:24 +01:00
|
|
|
#include "thread.h"
|
2008-02-03 23:20:20 +00:00
|
|
|
#include "configreader.h"
|
2008-04-04 12:30:38 +00:00
|
|
|
#include "protocol.h"
|
2014-06-13 15:23:39 +02:00
|
|
|
#include "bancache.h"
|
2022-01-18 03:10:47 +00:00
|
|
|
#include "logging.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.
|
|
|
|
*/
|
2023-07-13 10:08:10 +01:00
|
|
|
class ServerStats final
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Number of accepted connections
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Accept = 0;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Number of failed accepts
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Refused = 0;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Number of unknown commands seen
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Unknown = 0;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Number of nickname collisions handled
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Collisions = 0;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Number of inbound connections seen
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Connects = 0;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Total bytes of data transmitted
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Sent = 0;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Total bytes of data received
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned long Recv = 0;
|
|
|
|
|
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;
|
2020-02-06 11:25:42 +00:00
|
|
|
|
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
|
|
|
/** Time QP sample was read
|
|
|
|
*/
|
|
|
|
LARGE_INTEGER LastSampled;
|
2020-02-06 11:25:42 +00:00
|
|
|
|
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
|
|
|
/** QP frequency
|
|
|
|
*/
|
|
|
|
LARGE_INTEGER QPFrequency;
|
|
|
|
#else
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Cpu usage at last sample
|
|
|
|
*/
|
|
|
|
timeval LastCPU;
|
2020-10-31 16:55:18 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** 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 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
|
|
|
*/
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport InspIRCd final
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The last signal that was received from the operating system. */
|
|
|
|
static sig_atomic_t lastsignal;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** A 64k buffer used to read socket data into. */
|
|
|
|
char readbuffer[65535];
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The client protocol events provided by the core. */
|
2018-08-13 20:17:46 +01:00
|
|
|
ClientProtocol::RFCEvents rfcevents;
|
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The current time, updated once per main loop iteration. */
|
|
|
|
struct timespec ts;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Prepares the server for restart or shutdown. */
|
|
|
|
void Cleanup();
|
2013-04-14 18:20:02 +02:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Handles an stored signal in the main loop.
|
|
|
|
* @param signal The signal received from the operating system.
|
2007-07-25 16:58:56 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
void HandleSignal(sig_atomic_t signal);
|
|
|
|
|
|
|
|
/** Attempt to write the process id to a file. */
|
|
|
|
void WritePID();
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Actions that must happen outside of the current call stack. */
|
2009-10-14 22:12:55 +00:00
|
|
|
ActionList AtomicActions;
|
2007-07-25 16:58:56 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Caches server bans to speeds up checking of restrictions on connect. */
|
|
|
|
BanCacheManager BanCache;
|
2007-08-28 13:23:47 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Manager for state relating to channels. */
|
|
|
|
ChannelManager Channels;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Default implementation of the protocol interface which does nothing. */
|
|
|
|
ProtocolInterface DefaultProtocolInterface;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/* Manager for the extension system. */
|
2009-10-14 18:39:38 +00:00
|
|
|
ExtensionManager Extensions;
|
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Objects that should be culled outside of the current call stack. */
|
|
|
|
CullList GlobalCulls;
|
|
|
|
|
|
|
|
/** Manager for the logging system. */
|
|
|
|
Log::Manager Logs;
|
|
|
|
|
|
|
|
/* Manager for the mode handlers. */
|
2014-06-24 12:10:59 +02:00
|
|
|
ModeParser Modes;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Manager for the module loading system. */
|
|
|
|
ModuleManager Modules;
|
|
|
|
|
|
|
|
/** Manager for the command handlers. */
|
2014-06-13 15:45:55 +02:00
|
|
|
CommandParser Parser;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Manages sending snomasks to server operators. */
|
|
|
|
SnomaskManager SNO;
|
2008-02-24 14:09:02 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Holds miscellaneous stats counters. */
|
|
|
|
ServerStats Stats;
|
2008-06-12 21:00:48 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Manages scheduling and triggering of timer events. */
|
|
|
|
TimerManager Timers;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/* Generator for unique user identifiers. */
|
|
|
|
UIDGenerator UIDGen;
|
2007-11-04 13:23:15 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Manager for state relating to users. */
|
|
|
|
UserManager Users;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The server configuration. */
|
2020-02-06 11:25:42 +00:00
|
|
|
ServerConfig* Config = nullptr;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/* If non-nullptr then the thread that is reading the server configuration on rehash. */
|
|
|
|
ConfigReaderThread* ConfigThread = nullptr;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** A fake user that represents the local server. */
|
|
|
|
FakeUser* FakeClient = nullptr;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The protocol interface used for interacting with remote servers by the linking module. */
|
|
|
|
ProtocolInterface* PI = &DefaultProtocolInterface;
|
|
|
|
|
|
|
|
/** Manager for X-lines. */
|
2020-02-06 11:25:42 +00:00
|
|
|
XLineManager* XLines = nullptr;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The current server configuration file from --config or configure. */
|
|
|
|
std::string ConfigFileName = INSPIRCD_CONFIG_PATH "/inspircd.conf";
|
2008-01-13 03:37:25 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Fills a buffer with random bytes. */
|
|
|
|
std::function<void(char*, size_t)> GenRandom = &DefaultGenRandom;
|
2008-02-02 20:55:16 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Determines whether a nickname is valid. */
|
|
|
|
std::function<bool(const std::string_view&)> IsNick = &DefaultIsNick;
|
|
|
|
|
|
|
|
/** Determines whether a username is valid. */
|
|
|
|
std::function<bool(const std::string_view&)> IsUser = &DefaultIsUser;
|
|
|
|
|
|
|
|
/** List of the open listeners. */
|
2009-10-21 23:46:33 +00:00
|
|
|
std::vector<ListenSocket*> ports;
|
2009-07-01 22:55:39 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** The time at which the server was started. */
|
|
|
|
time_t startup_time;
|
2007-07-25 19:46:25 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Initialises a new server instance and stores it in ServerInstance
|
|
|
|
* @param argc The argument count from main().
|
|
|
|
* @param argv The argument list from main().
|
2008-04-04 12:30:38 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
InspIRCd(int argc, char** argv);
|
2008-04-04 12:30:38 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Binds to a specific port from a config tag.
|
|
|
|
* @param tag the tag that contains bind information.
|
|
|
|
* @param sa The endpoint to listen on.
|
|
|
|
* @param oldports Previously listening ports that may be on the same endpoint.
|
|
|
|
* @param protocol The protocol to bind with or 0 to determine from the endpoint.
|
|
|
|
* @return True if the port was bound successfully; otherwise, false.
|
2014-06-13 15:59:37 +02:00
|
|
|
*/
|
2024-08-27 13:27:17 +01:00
|
|
|
bool BindPort(const std::shared_ptr<ConfigTag>& tag, const irc::sockets::sockaddrs& sa, std::vector<ListenSocket*>& oldports, sa_family_t protocol);
|
2014-06-13 15:59:37 +02:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Binds all ports specified in the configuration file.
|
|
|
|
* @return The number of ports bound without error.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
size_t BindPorts(FailedPortList& failed_ports);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Compares a password to a hashed password.
|
|
|
|
* @param password The hashed password.
|
|
|
|
* @param passwordhash If non-empty then the algorithm the password is hashed with.
|
|
|
|
* @param value The value to check to see if the password is valid.
|
|
|
|
* @return True if the password is correct, otherwise, false.
|
2010-02-09 02:22:27 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool CheckPassword(const std::string& password, const std::string& passwordhash, const std::string& value);
|
|
|
|
|
|
|
|
/** Generates a random integer.
|
|
|
|
* @param max The maximum value for the integer.
|
|
|
|
* @return A random integer between 0 and \p max.
|
2010-02-09 02:22:27 +00:00
|
|
|
*/
|
2022-09-03 22:52:53 +01:00
|
|
|
unsigned long GenRandomInt(unsigned long max) const;
|
2010-02-09 02:22:27 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Generates a random string.
|
|
|
|
* @param length The length in bytes.
|
|
|
|
* @param printable Whether to only return printable characters.
|
|
|
|
* @return A random string of \p length bytes.
|
|
|
|
*/
|
|
|
|
std::string GenRandomStr(size_t length, bool printable = true) const;
|
|
|
|
|
|
|
|
/** Retrieves a 64k buffer used to read socket data into. */
|
|
|
|
inline auto* GetReadBuffer() { return readbuffer; }
|
|
|
|
|
|
|
|
/** Retrieves the client protocol events provided by the core. */
|
|
|
|
inline auto& GetRFCEvents() { return rfcevents; }
|
2017-11-25 12:50:11 +00:00
|
|
|
|
|
|
|
/** Fills the output buffer with the specified number of random characters.
|
|
|
|
* This is the default function for InspIRCd::GenRandom.
|
|
|
|
* @param output The output buffer to store random characters in.
|
|
|
|
* @param max The maximum number of random characters to put in the buffer.
|
|
|
|
*/
|
|
|
|
static void DefaultGenRandom(char* output, size_t max);
|
2010-02-09 02:22:27 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Determines whether a nickname is valid according to the RFC 1459 rules.
|
|
|
|
* This is the default function for InspIRCd::IsNick.
|
|
|
|
* @param nick The nickname to validate.
|
|
|
|
* @return True if the nickname is valid according to RFC 1459 rules; otherwise, false.
|
2018-07-13 10:28:28 +01:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool DefaultIsNick(const std::string_view& nick);
|
|
|
|
|
|
|
|
/** Determines whether a username is valid according to the RFC 1459 rules.
|
|
|
|
* This is the default function for InspIRCd::IsUser.
|
|
|
|
* @param user The username to validate.
|
|
|
|
* @return True if the username is valid according to RFC 1459 rules; otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool DefaultIsUser(const std::string_view& user);
|
2018-07-13 10:28:28 +01:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Causes the server to exit after unloading modules and closing all open file descriptors.
|
|
|
|
* @param status The exit code to give to the operating system.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
[[noreturn]]
|
|
|
|
void Exit(int status);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Determines whether a fully qualified hostname is valid according to RFC 5891 rules.
|
2018-06-29 11:28:19 +01:00
|
|
|
* @param host The hostname to validate.
|
|
|
|
* @return True if the hostname is valid; otherwise, false.
|
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
inline static auto IsFQDN(const std::string& host) { return IsHost(host, false); }
|
2023-01-13 07:17:32 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Determines whether a hostname is valid according to RFC 5891 rules.
|
2023-01-13 07:17:32 +00:00
|
|
|
* @param host The hostname to validate.
|
2024-08-27 12:40:55 +01:00
|
|
|
* @param allowsimple Whether to allow simple hostnames (e.g. localhost).
|
2023-01-13 07:17:32 +00:00
|
|
|
* @return True if the hostname is valid; otherwise, false.
|
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool IsHost(const std::string& host, bool allowsimple);
|
2018-06-29 11:28:19 +01:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Determines whether the specified string is a server identifier.
|
|
|
|
* @param sid The string to check.
|
|
|
|
* @return True if the specified string is a server identifier; otherwise, false.
|
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
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Determines whether the specified string is a valid nick!user\@host mask.
|
|
|
|
* @param mask The string to check.
|
|
|
|
* @return True if the specified string is a valid nick!user\@host mask; otherwise, false.
|
2007-07-25 19:46:25 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool IsValidMask(const std::string& mask);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Matches two strings using glob pattern matching, optionally with a case map to use instead
|
|
|
|
* of the server case map.
|
|
|
|
* @param str The literal string to match against
|
|
|
|
* @param pattern The glob pattern to match against.
|
|
|
|
* @param map The character map to use when matching.
|
|
|
|
* @return True if the string matches the mask; otherwise, false.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool Match(const std::string& str, const std::string& pattern, const unsigned char* map = nullptr);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Matches two strings using glob pattern matching, optionally with a case map to use instead
|
|
|
|
* of the server case map.
|
|
|
|
* @param str The literal string to match against
|
|
|
|
* @param pattern The glob pattern to match against.
|
|
|
|
* @param map The character map to use when matching.
|
|
|
|
* @return True if the string matches the pattern; otherwise, false.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool Match(const char* str, const char* pattern, const unsigned char* map = nullptr);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Matches two strings using glob pattern and CIDR range matching, optionally with a case map
|
|
|
|
* to use instead of the server case map.
|
2008-08-21 20:56:16 +00:00
|
|
|
* @param str The literal string to match against
|
2024-08-27 12:40:55 +01:00
|
|
|
* @param pattern The glob pattern to match against.
|
2012-07-05 21:00:35 +01:00
|
|
|
* @param map The character map to use when matching.
|
2024-08-27 12:40:55 +01:00
|
|
|
* @return True if the string matches the pattern; otherwise, false.
|
2008-08-21 20:56:16 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool MatchCIDR(const std::string& str, const std::string& pattern, const unsigned char* map = nullptr);
|
2008-08-21 20:56:16 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Matches two strings using glob pattern and CIDR range matching, optionally with a case map
|
|
|
|
* to use instead of the server case map.
|
2008-08-21 20:56:16 +00:00
|
|
|
* @param str The literal string to match against
|
2024-08-27 12:40:55 +01:00
|
|
|
* @param pattern The glob pattern to match against.
|
2012-07-05 21:00:35 +01:00
|
|
|
* @param map The character map to use when matching.
|
2024-08-27 12:40:55 +01:00
|
|
|
* @return True if the string matches the pattern; otherwise, false.
|
2008-08-21 20:56:16 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool MatchCIDR(const char* str, const char* pattern, const unsigned char* map = nullptr);
|
2013-05-06 11:49:50 +01:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Matches a hostname and address against a space delimited list of hostmasks.
|
2013-05-06 11:49:50 +01:00
|
|
|
* @param masks The space delimited masks to match against.
|
|
|
|
* @param hostname The hostname to try and match.
|
2024-08-27 12:40:55 +01:00
|
|
|
* @param address The IP address or UNIX socket path to try and match.
|
|
|
|
* @return True if a mask matches the hostname or address; otherwise, false.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& address);
|
2012-10-29 18:33:07 +01:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Reloads the server configuration.
|
|
|
|
* @param uuid If non-empty then the uuid of the user who started the rehash.
|
2012-09-12 16:27:59 +01:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
void Rehash(const std::string& uuid = "");
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Starts the execution of the server main loop. */
|
|
|
|
[[noreturn]]
|
|
|
|
void Run();
|
2012-10-29 17:19:21 +01:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Replaces color escapes in the specified lines with IRC colors.
|
|
|
|
* @param lines A vector of lines to replace color escapes in.
|
2023-02-28 14:30:35 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static void ProcessColors(std::vector<std::string>& lines);
|
2023-02-28 14:30:35 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Stores an incoming signal when received from the operating system.
|
|
|
|
* @param signal The signal received from the operating system.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static void SetSignal(int signal);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/* Removes IRC colors from the specified string.
|
|
|
|
* @param str The string to strip colors from.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static void StripColor(std::string& str);
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Retrieves the time, updated once per main loop iteration, as the number of seconds since
|
|
|
|
* the UNIX epoch. This is faster than calling time functions manually.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
inline auto Time() const { return ts.tv_sec; }
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Retrieves the time, updated once per main loop iteration, as the number of fractional
|
|
|
|
* seconds since the UNIX epoch. This is faster than calling time functions manually.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
inline auto Time_ns() const { return ts.tv_nsec; }
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Compares 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 str1 The first string to compare.
|
|
|
|
* @param str2 The second string to compare.
|
|
|
|
* @return True if the strings are equivalent; otherwise, false.
|
2014-06-28 18:25:05 +02:00
|
|
|
*/
|
2024-08-27 12:40:55 +01:00
|
|
|
static bool TimingSafeCompare(const std::string& str1, const std::string& str2);
|
2007-07-23 23:10:16 +00:00
|
|
|
|
2024-08-27 12:40:55 +01:00
|
|
|
/** Updates the current cached time. Don't call this unless you have reason to do so. */
|
|
|
|
void UpdateTime();
|
2007-07-16 17:30:04 +00:00
|
|
|
};
|
|
|
|
|
2022-12-27 14:12:10 +00:00
|
|
|
inline void Cullable::Deleter::operator()(Cullable* item)
|
2014-03-24 16:44:04 +01:00
|
|
|
{
|
|
|
|
if (item)
|
|
|
|
ServerInstance->GlobalCulls.AddItem(item);
|
|
|
|
}
|
2015-04-28 15:16:22 +02:00
|
|
|
|
2022-12-08 10:19:47 +00:00
|
|
|
inline void Channel::Write(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg, char status, const CUList& except_list) const
|
2018-08-13 20:17:46 +01:00
|
|
|
{
|
|
|
|
ClientProtocol::Event event(protoevprov, msg);
|
|
|
|
Write(event, status, except_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void LocalUser::Send(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg)
|
|
|
|
{
|
|
|
|
ClientProtocol::Event event(protoevprov, msg);
|
|
|
|
Send(event);
|
|
|
|
}
|