From 0c750c060839f9018ca129bd7456184792ea0dc0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 21 Jun 2020 04:25:45 +0100 Subject: Move channel logic from InspIRCd to the new ChannelManager class. --- include/channelmanager.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ include/inspircd.h | 27 +++---------------------- include/typedefs.h | 1 - 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 include/channelmanager.h (limited to 'include') diff --git a/include/channelmanager.h b/include/channelmanager.h new file mode 100644 index 000000000..f149fbc09 --- /dev/null +++ b/include/channelmanager.h @@ -0,0 +1,51 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2020 Sadie Powell + * + * 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. + * + * 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 . + */ + + +#pragma once + +typedef std::unordered_map ChannelMap; + +/** Manages state relating to channels. */ +class CoreExport ChannelManager +{ + private: + /** A map of channel names to the channel object. */ + ChannelMap channels; + + public: + /** Determines whether an channel name is valid. */ + std::function IsChannel = DefaultIsChannel; + + /** Determines whether a channel name is valid according to the RFC 1459 rules. + * This is the default function for InspIRCd::IsChannel. + * @param channel The channel name to validate. + * @return True if the channel name is valid according to RFC 1459 rules; otherwise, false. + */ + static bool DefaultIsChannel(const std::string& channel); + + /** Finds a channel by name. + * @param channel The name of the channel to look up. + * @return If the channel was found then a pointer to a Channel object; otherwise, nullptr. + */ + Channel* Find(const std::string& channel); + + /** Retrieves a map containing all channels keyed by the channel name. */ + ChannelMap& GetChans() { return channels; } + const ChannelMap& GetChans() const { return channels; } +}; diff --git a/include/inspircd.h b/include/inspircd.h index b2a2d8973..b42e95ac9 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -88,6 +88,7 @@ CoreExport extern InspIRCd* ServerInstance; #include "timer.h" #include "hashcomp.h" #include "logger.h" +#include "channelmanager.h" #include "usermanager.h" #include "socket.h" #include "command_parse.h" @@ -280,9 +281,8 @@ class CoreExport InspIRCd */ UserManager Users; - /** Channel list, a hash_map containing all channels XXX move to channel manager class - */ - chan_hash chanlist; + /** Manager for state relating to channels. */ + ChannelManager Channels; /** List of the open ports */ @@ -344,27 +344,6 @@ class CoreExport InspIRCd */ size_t BindPorts(FailedPortList &failed_ports); - /** 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 - */ - Channel* FindChan(const std::string &chan); - - /** Get a hash map containing all channels, keyed by their name - * @return A hash map mapping channel names to Channel pointers - */ - chan_hash& GetChans() { return chanlist; } - - /** Determines whether an channel name is valid. */ - std::function IsChannel; - - /** Determines whether a channel name is valid according to the RFC 1459 rules. - * This is the default function for InspIRCd::IsChannel. - * @param channel The channel name to validate. - * @return True if the channel name is valid according to RFC 1459 rules; otherwise, false. - */ - static bool DefaultIsChannel(const std::string& channel); - /** Determines whether a hostname is valid according to RFC 5891 rules. * @param host The hostname to validate. * @return True if the hostname is valid; otherwise, false. diff --git a/include/typedefs.h b/include/typedefs.h index 7907ea035..1685cef7d 100644 --- a/include/typedefs.h +++ b/include/typedefs.h @@ -85,7 +85,6 @@ namespace ClientProtocol #include "base.h" typedef std::unordered_map user_hash; -typedef std::unordered_map chan_hash; /** List of channels to consider when building the neighbor list of a user */ -- cgit v1.3.1-10-gc9f91