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 /* $ModDesc: Implements config tags which allow changing characters allowed in channel names */
24 static std::bitset<256> allowedmap;
26 class NewIsChannelHandler : public HandlerBase2<bool, const char*, size_t>
29 NewIsChannelHandler() { }
30 virtual ~NewIsChannelHandler() { }
31 virtual bool Call(const char*, size_t);
34 bool NewIsChannelHandler::Call(const char* c, size_t max)
36 /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */
37 if (!c || *c++ != '#')
42 unsigned int i = *c++ & 0xFF;
46 // a name of exactly max length will have max = 1 here; the null does not trigger --max
50 class ModuleChannelNames : public Module
53 NewIsChannelHandler myhandler;
54 caller2<bool, const char*, size_t> rememberer;
58 ModuleChannelNames() : rememberer(ServerInstance->IsChannel), badchan(false)
64 ServerInstance->IsChannel = &myhandler;
65 Implementation eventlist[] = { I_OnRehash, I_OnUserKick };
66 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
73 std::vector<Channel*> chanvec;
74 for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
76 if (!ServerInstance->IsChannel(i->second->name.c_str(), MAXBUF))
77 chanvec.push_back(i->second);
79 std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
80 while (c2 != chanvec.rend())
83 if (c->IsModeSet('P') && c->GetUserCounter())
85 std::vector<std::string> modes;
86 modes.push_back(c->name);
87 modes.push_back("-P");
89 ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
91 const UserMembList* users = c->GetUsers();
92 for(UserMembCIter j = users->begin(); j != users->end(); )
94 if (IS_LOCAL(j->first))
96 // KickUser invalidates the iterator
97 UserMembCIter it = j++;
98 c->KickUser(ServerInstance->FakeClient, it->first, "Channel name no longer valid");
107 virtual void OnRehash(User* user)
109 ConfigTag* tag = ServerInstance->Config->ConfValue("channames");
110 std::string denyToken = tag->getString("denyrange");
111 std::string allowToken = tag->getString("allowrange");
113 if (!denyToken.compare(0, 2, "0-"))
115 if (!allowToken.compare(0, 2, "0-"))
120 irc::portparser denyrange(denyToken, false);
122 while (0 != (denyno = denyrange.GetToken()))
123 allowedmap[denyno & 0xFF] = false;
125 irc::portparser allowrange(allowToken, false);
127 while (0 != (allowno = allowrange.GetToken()))
128 allowedmap[allowno & 0xFF] = true;
130 allowedmap[0x07] = false; // BEL
131 allowedmap[0x20] = false; // ' '
132 allowedmap[0x2C] = false; // ','
137 virtual void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except_list)
141 const UserMembList* users = memb->chan->GetUsers();
142 for(UserMembCIter i = users->begin(); i != users->end(); i++)
143 if (i->first != memb->user)
144 except_list.insert(i->first);
148 virtual ~ModuleChannelNames()
150 ServerInstance->IsChannel = rememberer;
154 virtual Version GetVersion()
156 return Version("Implements config tags which allow changing characters allowed in channel names", VF_VENDOR);
160 MODULE_INIT(ModuleChannelNames)