aboutsummaryrefslogtreecommitdiff
path: root/include/channelmanager.h
blob: 48d395770d6ea8f4eb75aaa8494b0d461656210b (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * 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 final
{
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) const;

	/** Retrieves a map containing all channels keyed by the channel name. */
	ChannelMap& GetChans() { return channels; }
	const ChannelMap& GetChans() const { return channels; }

	/** 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;
};