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(InspIRCd* Instance) : ModeHandler(Instance, 'L', 1, 0, false, MODETYPE_CHANNEL, false) { }
25 ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
27 if (channel->IsModeSet('L'))
28 return std::make_pair(true, channel->GetModeParameter('L'));
30 return std::make_pair(false, parameter);
33 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool server)
39 if (!ServerInstance->IsChannel(parameter.c_str(), ServerInstance->Config->Limits.ChanMax))
41 source->WriteNumeric(403, "%s %s :Invalid channel name", source->nick.c_str(), parameter.c_str());
43 return MODEACTION_DENY;
47 if (IS_LOCAL(source) && !IS_OPER(source) && !server)
49 Channel* c = ServerInstance->FindChan(parameter);
52 source->WriteNumeric(690, "%s :Target channel %s must exist to be set as a redirect.",source->nick.c_str(),parameter.c_str());
54 return MODEACTION_DENY;
56 else if (c->GetStatus(source) < STATUS_OP)
58 source->WriteNumeric(690, "%s :You must be opped on %s to set it as a redirect.",source->nick.c_str(),parameter.c_str());
60 return MODEACTION_DENY;
65 * We used to do some checking for circular +L here, but there is no real need for this any more especially as we
66 * now catch +L looping in PreJoin. Remove it, since O(n) logic makes me sad, and we catch it anyway. :) -- w00t
68 channel->SetModeParam('L', parameter);
69 return MODEACTION_ALLOW;
73 if (channel->IsModeSet('L'))
75 channel->SetModeParam('L', "");
76 return MODEACTION_ALLOW;
80 return MODEACTION_DENY;
85 class ModuleRedirect : public Module
92 ModuleRedirect(InspIRCd* Me)
96 re = new Redirect(ServerInstance);
97 if (!ServerInstance->Modes->AddMode(re))
98 throw ModuleException("Could not add new modes!");
99 Implementation eventlist[] = { I_OnUserPreJoin };
100 ServerInstance->Modules->Attach(eventlist, this, 1);
104 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
108 if (chan->IsModeSet('L') && chan->modes[CM_LIMIT])
110 if (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str()))
112 std::string channel = chan->GetModeParameter('L');
114 /* sometimes broken ulines can make circular or chained +L, avoid this */
115 Channel* destchan = NULL;
116 destchan = ServerInstance->FindChan(channel);
117 if (destchan && destchan->IsModeSet('L'))
119 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);
123 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());
124 Channel::JoinUser(ServerInstance, user, channel.c_str(), false, "", false, ServerInstance->Time());
132 virtual ~ModuleRedirect()
134 ServerInstance->Modes->DelMode(re);
138 virtual Version GetVersion()
140 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
144 MODULE_INIT(ModuleRedirect)