2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2004, 2006 Craig Edwards <craigedwards@brainbox.cc>
8 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /* $ModDesc: Provides channel mode +L (limit redirection) */
28 /** Handle channel mode +L
30 class Redirect : public ModeHandler
33 Redirect(Module* Creator) : ModeHandler(Creator, "redirect", 'L', PARAM_SETONLY, MODETYPE_CHANNEL) { }
35 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
41 if (!ServerInstance->IsChannel(parameter.c_str(), ServerInstance->Config->Limits.ChanMax))
43 source->WriteNumeric(403, "%s %s :Invalid channel name", source->nick.c_str(), parameter.c_str());
45 return MODEACTION_DENY;
49 if (IS_LOCAL(source) && !IS_OPER(source))
51 Channel* c = ServerInstance->FindChan(parameter);
54 source->WriteNumeric(690, "%s :Target channel %s must exist to be set as a redirect.",source->nick.c_str(),parameter.c_str());
56 return MODEACTION_DENY;
58 else if (c->GetPrefixValue(source) < OP_VALUE)
60 source->WriteNumeric(690, "%s :You must be opped on %s to set it as a redirect.",source->nick.c_str(),parameter.c_str());
62 return MODEACTION_DENY;
66 if (channel->GetModeParameter('L') == parameter)
67 return MODEACTION_DENY;
69 * We used to do some checking for circular +L here, but there is no real need for this any more especially as we
70 * now catch +L looping in PreJoin. Remove it, since O(n) logic makes me sad, and we catch it anyway. :) -- w00t
72 channel->SetModeParam('L', parameter);
73 return MODEACTION_ALLOW;
77 if (channel->IsModeSet('L'))
79 channel->SetModeParam('L', "");
80 return MODEACTION_ALLOW;
84 return MODEACTION_DENY;
89 class ModuleRedirect : public Module
100 if (!ServerInstance->Modes->AddMode(&re))
101 throw ModuleException("Could not add new modes!");
102 Implementation eventlist[] = { I_OnUserPreJoin };
103 ServerInstance->Modules->Attach(eventlist, this, 1);
107 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
111 if (chan->IsModeSet('L') && chan->IsModeSet('l'))
113 if (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str()))
115 std::string channel = chan->GetModeParameter('L');
117 /* sometimes broken ulines can make circular or chained +L, avoid this */
118 Channel* destchan = NULL;
119 destchan = ServerInstance->FindChan(channel);
120 if (destchan && destchan->IsModeSet('L'))
122 user->WriteNumeric(470, "%s %s * :You may not join this channel. A redirect is set, but you may not be redirected as it is a circular loop.", user->nick.c_str(), cname);
126 user->WriteNumeric(470, "%s %s %s :You may not join this channel, so you are automatically being transferred to the redirect channel.", user->nick.c_str(), cname, channel.c_str());
127 Channel::JoinUser(user, channel.c_str(), false, "", false, ServerInstance->Time());
132 return MOD_RES_PASSTHRU;
135 virtual ~ModuleRedirect()
139 virtual Version GetVersion()
141 return Version("Provides channel mode +L (limit redirection)", VF_VENDOR);
145 MODULE_INIT(ModuleRedirect)