1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides channel mode +L (limit redirection) */
18 /** Handle channel mode +L
20 class Redirect : public ModeHandler
23 Redirect(Module* Creator) : ModeHandler(Creator, "redirect", 'L', PARAM_SETONLY, MODETYPE_CHANNEL) { }
25 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
31 if (!ServerInstance->IsChannel(parameter.c_str(), ServerInstance->Config->Limits.ChanMax))
33 source->WriteNumeric(403, "%s %s :Invalid channel name", source->nick.c_str(), parameter.c_str());
35 return MODEACTION_DENY;
39 if (IS_LOCAL(source) && !IS_OPER(source))
41 Channel* c = ServerInstance->FindChan(parameter);
44 source->WriteNumeric(690, "%s :Target channel %s must exist to be set as a redirect.",source->nick.c_str(),parameter.c_str());
46 return MODEACTION_DENY;
48 else if (c->GetPrefixValue(source) < OP_VALUE)
50 source->WriteNumeric(690, "%s :You must be opped on %s to set it as a redirect.",source->nick.c_str(),parameter.c_str());
52 return MODEACTION_DENY;
56 if (channel->GetModeParameter('L') == parameter)
57 return MODEACTION_DENY;
59 * We used to do some checking for circular +L here, but there is no real need for this any more especially as we
60 * now catch +L looping in PreJoin. Remove it, since O(n) logic makes me sad, and we catch it anyway. :) -- w00t
62 channel->SetModeParam('L', parameter);
63 return MODEACTION_ALLOW;
67 if (channel->IsModeSet('L'))
69 channel->SetModeParam('L', "");
70 return MODEACTION_ALLOW;
74 return MODEACTION_DENY;
79 class ModuleRedirect : public Module
90 if (!ServerInstance->Modes->AddMode(&re))
91 throw ModuleException("Could not add new modes!");
92 Implementation eventlist[] = { I_OnUserPreJoin };
93 ServerInstance->Modules->Attach(eventlist, this, 1);
97 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
101 if (chan->IsModeSet('L') && chan->IsModeSet('l'))
103 if (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str()))
105 std::string channel = chan->GetModeParameter('L');
107 /* sometimes broken ulines can make circular or chained +L, avoid this */
108 Channel* destchan = NULL;
109 destchan = ServerInstance->FindChan(channel);
110 if (destchan && destchan->IsModeSet('L'))
112 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);
116 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());
117 Channel::JoinUser(user, channel.c_str(), false, "", false, ServerInstance->Time());
122 return MOD_RES_PASSTHRU;
125 virtual ~ModuleRedirect()
129 virtual Version GetVersion()
131 return Version("Provides channel mode +L (limit redirection)", VF_VENDOR);
135 MODULE_INIT(ModuleRedirect)