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 : public HandlerBase1<bool, const std::string&>
27 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 NewIsChannelHandler myhandler;
48 caller1<bool, const std::string&> rememberer;
50 ChanModeReference permchannelmode;
54 : rememberer(ServerInstance->IsChannel)
56 , permchannelmode(this, "permanent")
60 void init() CXX11_OVERRIDE
62 ServerInstance->IsChannel = &myhandler;
68 std::vector<Channel*> chanvec;
69 const chan_hash& chans = ServerInstance->GetChans();
70 for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i)
72 if (!ServerInstance->IsChannel(i->second->name))
73 chanvec.push_back(i->second);
75 std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
76 while (c2 != chanvec.rend())
79 if (c->IsModeSet(permchannelmode) && c->GetUserCounter())
81 std::vector<std::string> modes;
82 modes.push_back(c->name);
83 modes.push_back(std::string("-") + permchannelmode->GetModeChar());
85 ServerInstance->Modes->Process(modes, ServerInstance->FakeClient);
87 const UserMembList* users = c->GetUsers();
88 for(UserMembCIter j = users->begin(); j != users->end(); )
90 if (IS_LOCAL(j->first))
92 // KickUser invalidates the iterator
93 UserMembCIter it = j++;
94 c->KickUser(ServerInstance->FakeClient, it->first, "Channel name no longer valid");
103 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
105 ConfigTag* tag = ServerInstance->Config->ConfValue("channames");
106 std::string denyToken = tag->getString("denyrange");
107 std::string allowToken = tag->getString("allowrange");
109 if (!denyToken.compare(0, 2, "0-"))
111 if (!allowToken.compare(0, 2, "0-"))
116 irc::portparser denyrange(denyToken, false);
118 while (0 != (denyno = denyrange.GetToken()))
119 allowedmap[denyno & 0xFF] = false;
121 irc::portparser allowrange(allowToken, false);
123 while (0 != (allowno = allowrange.GetToken()))
124 allowedmap[allowno & 0xFF] = true;
126 allowedmap[0x07] = false; // BEL
127 allowedmap[0x20] = false; // ' '
128 allowedmap[0x2C] = false; // ','
133 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except_list) CXX11_OVERRIDE
137 const UserMembList* users = memb->chan->GetUsers();
138 for(UserMembCIter i = users->begin(); i != users->end(); i++)
139 if (i->first != memb->user)
140 except_list.insert(i->first);
144 ~ModuleChannelNames()
146 ServerInstance->IsChannel = rememberer;
150 Version GetVersion() CXX11_OVERRIDE
152 return Version("Implements config tags which allow changing characters allowed in channel names", VF_VENDOR);
156 MODULE_INIT(ModuleChannelNames)