2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 static std::bitset<256> allowedmap;
24 class NewIsChannelHandler
27 static bool Call(const std::string&);
30 bool NewIsChannelHandler::Call(const std::string& channame)
32 if (channame.empty() || channame.length() > ServerInstance->Config->Limits.ChanMax || channame[0] != '#')
35 for (std::string::const_iterator c = channame.begin(); c != channame.end(); ++c)
37 unsigned int i = *c & 0xFF;
45 class ModuleChannelNames : public Module
47 TR1NS::function<bool(const std::string&)> rememberer;
49 ChanModeReference permchannelmode;
53 : rememberer(ServerInstance->IsChannel)
55 , permchannelmode(this, "permanent")
59 void init() CXX11_OVERRIDE
61 ServerInstance->IsChannel = NewIsChannelHandler::Call;
66 Modes::ChangeList removepermchan;
69 const chan_hash& chans = ServerInstance->GetChans();
70 for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); )
72 Channel* c = i->second;
73 // Move iterator before we begin kicking
75 if (ServerInstance->IsChannel(c->name))
76 continue; // The name of this channel is still valid
78 if (c->IsModeSet(permchannelmode) && c->GetUserCounter())
80 removepermchan.clear();
81 removepermchan.push_remove(*permchannelmode);
82 ServerInstance->Modes->Process(ServerInstance->FakeClient, c, NULL, removepermchan);
85 Channel::MemberMap& users = c->userlist;
86 for (Channel::MemberMap::iterator j = users.begin(); j != users.end(); )
88 if (IS_LOCAL(j->first))
90 // KickUser invalidates the iterator
91 Channel::MemberMap::iterator it = j++;
92 c->KickUser(ServerInstance->FakeClient, it, "Channel name no longer valid");
101 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
103 ConfigTag* tag = ServerInstance->Config->ConfValue("channames");
104 std::string denyToken = tag->getString("denyrange");
105 std::string allowToken = tag->getString("allowrange");
107 if (!denyToken.compare(0, 2, "0-"))
109 if (!allowToken.compare(0, 2, "0-"))
114 irc::portparser denyrange(denyToken, false);
116 while (0 != (denyno = denyrange.GetToken()))
117 allowedmap[denyno & 0xFF] = false;
119 irc::portparser allowrange(allowToken, false);
121 while (0 != (allowno = allowrange.GetToken()))
122 allowedmap[allowno & 0xFF] = true;
124 allowedmap[0x07] = false; // BEL
125 allowedmap[0x20] = false; // ' '
126 allowedmap[0x2C] = false; // ','
131 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except_list) CXX11_OVERRIDE
135 const Channel::MemberMap& users = memb->chan->GetUsers();
136 for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
137 if (i->first != memb->user)
138 except_list.insert(i->first);
142 CullResult cull() CXX11_OVERRIDE
144 ServerInstance->IsChannel = rememberer;
146 return Module::cull();
149 Version GetVersion() CXX11_OVERRIDE
151 return Version("Implements config tags which allow changing characters allowed in channel names", VF_VENDOR);
155 MODULE_INIT(ModuleChannelNames)