1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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;
57 * We used to do some checking for circular +L here, but there is no real need for this any more especially as we
58 * now catch +L looping in PreJoin. Remove it, since O(n) logic makes me sad, and we catch it anyway. :) -- w00t
60 channel->SetModeParam('L', parameter);
61 return MODEACTION_ALLOW;
65 if (channel->IsModeSet('L'))
67 channel->SetModeParam('L', "");
68 return MODEACTION_ALLOW;
72 return MODEACTION_DENY;
77 class ModuleRedirect : public Module
88 if (!ServerInstance->Modes->AddMode(&re))
89 throw ModuleException("Could not add new modes!");
90 Implementation eventlist[] = { I_OnUserPreJoin };
91 ServerInstance->Modules->Attach(eventlist, this, 1);
95 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
99 if (chan->IsModeSet('L') && chan->IsModeSet('l'))
101 if (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str()))
103 std::string channel = chan->GetModeParameter('L');
105 /* sometimes broken ulines can make circular or chained +L, avoid this */
106 Channel* destchan = NULL;
107 destchan = ServerInstance->FindChan(channel);
108 if (destchan && destchan->IsModeSet('L'))
110 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);
114 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());
115 Channel::JoinUser(user, channel.c_str(), false, "", false, ServerInstance->Time());
120 return MOD_RES_PASSTHRU;
123 virtual ~ModuleRedirect()
127 virtual Version GetVersion()
129 return Version("Provides channel mode +L (limit redirection)", VF_COMMON | VF_VENDOR);
133 MODULE_INIT(ModuleRedirect)