aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Sadie Powell2020-06-21 04:25:45 +0100
committerGravatar Sadie Powell2021-05-08 15:31:50 +0100
commit0c750c060839f9018ca129bd7456184792ea0dc0 (patch)
tree43aa8d0a593afa292e2922d2481b2349e0dc8dfd /include
parentMerge branch 'insp3' into master. (diff)
Move channel logic from InspIRCd to the new ChannelManager class.
Diffstat (limited to 'include')
-rw-r--r--include/channelmanager.h51
-rw-r--r--include/inspircd.h27
-rw-r--r--include/typedefs.h1
3 files changed, 54 insertions, 25 deletions
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 <sadie@witchery.services>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+typedef std::unordered_map<std::string, Channel*, irc::insensitive, irc::StrHashComp> 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<bool(const std::string&)> 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<bool(const std::string&)> 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<std::string, User*, irc::insensitive, irc::StrHashComp> user_hash;
-typedef std::unordered_map<std::string, Channel*, irc::insensitive, irc::StrHashComp> chan_hash;
/** List of channels to consider when building the neighbor list of a user
*/