2020-06-21 04:25:45 +01:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
|
|
|
*
|
2024-06-07 10:37:56 +01:00
|
|
|
* Copyright (C) 2020-2022 Sadie Powell <sadie@witchery.services>
|
2020-06-21 04:25:45 +01: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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2022-10-07 20:03:05 +01:00
|
|
|
/** A mapping of channel names to their Channel object. */
|
2020-06-21 04:25:45 +01:00
|
|
|
typedef std::unordered_map<std::string, Channel*, irc::insensitive, irc::StrHashComp> ChannelMap;
|
|
|
|
|
|
|
|
/** Manages state relating to channels. */
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport ChannelManager final
|
2020-06-21 04:25:45 +01:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2020-06-21 04:25:45 +01:00
|
|
|
/** A map of channel names to the channel object. */
|
|
|
|
ChannelMap channels;
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2020-06-21 04:25:45 +01:00
|
|
|
/** Determines whether an channel name is valid. */
|
2022-11-21 13:14:19 +00:00
|
|
|
std::function<bool(const std::string_view&)> IsChannel = DefaultIsChannel;
|
2020-06-21 04:25:45 +01:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
2022-11-21 13:14:19 +00:00
|
|
|
static bool DefaultIsChannel(const std::string_view& channel);
|
2020-06-21 04:25:45 +01:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
2021-05-08 15:59:32 +01:00
|
|
|
Channel* Find(const std::string& channel) const;
|
2020-06-21 04:25:45 +01:00
|
|
|
|
|
|
|
/** Retrieves a map containing all channels keyed by the channel name. */
|
|
|
|
ChannelMap& GetChans() { return channels; }
|
|
|
|
const ChannelMap& GetChans() const { return channels; }
|
2021-05-08 16:31:38 +01:00
|
|
|
|
|
|
|
/** Determines whether the specified character is a valid channel prefix.
|
|
|
|
* @param prefix The channel name prefix to validate.
|
|
|
|
* @return True if the character is a channel prefix; otherwise, false.
|
|
|
|
*/
|
|
|
|
bool IsPrefix(unsigned char prefix) const;
|
2020-06-21 04:25:45 +01:00
|
|
|
};
|