1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel)
35 /* When TS is equal, the alphabetically later one wins */
36 return (their_param < our_param);
39 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
45 if (IS_LOCAL(source) && !ServerInstance->IsChannel(parameter.c_str(), ServerInstance->Config->Limits.ChanMax))
47 source->WriteNumeric(403, "%s %s :Invalid channel name", source->nick.c_str(), parameter.c_str());
49 return MODEACTION_DENY;
52 c = ServerInstance->FindChan(parameter);
53 if (!c && !IS_OPER(source))
55 source->WriteNumeric(690, "%s :Target channel %s must exist to be set as a redirect.",source->nick.c_str(),parameter.c_str());
57 return MODEACTION_DENY;
60 if (c && c->GetStatus(source) < STATUS_OP && !IS_OPER(source))
62 source->WriteNumeric(690, "%s :You must be opped on %s to set it as a redirect.",source->nick.c_str(),parameter.c_str());
64 return MODEACTION_DENY;
68 * We used to do some checking for circular +L here, but there is no real need for this any more especially as we
69 * now catch +L looping in PreJoin. Remove it, since O(n) logic makes me sad, and we catch it anyway. :) -- w00t
71 channel->SetMode('L', true);
72 channel->SetModeParam('L', parameter.c_str(), true);
73 return MODEACTION_ALLOW;
77 if (channel->IsModeSet('L'))
79 channel->SetMode('L', false);
80 return MODEACTION_ALLOW;
84 return MODEACTION_DENY;
89 class ModuleRedirect : public Module
96 ModuleRedirect(InspIRCd* Me)
100 re = new Redirect(ServerInstance);
101 if (!ServerInstance->Modes->AddMode(re))
102 throw ModuleException("Could not add new modes!");
103 Implementation eventlist[] = { I_OnUserPreJoin };
104 ServerInstance->Modules->Attach(eventlist, this, 1);
108 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
112 if (chan->IsModeSet('L') && chan->modes[CM_LIMIT])
114 if (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str()))
116 std::string channel = chan->GetModeParameter('L');
118 /* sometimes broken ulines can make circular or chained +L, avoid this */
119 Channel* destchan = NULL;
120 destchan = ServerInstance->FindChan(channel);
121 if (destchan && destchan->IsModeSet('L'))
123 user->WriteNumeric(470, "%s :You may not join %s. A redirect is set, but you may not be redirected as it is a circular loop.", user->nick.c_str(), cname);
127 user->WriteNumeric(470, "%s :You may not join %s, so you are automatically being transferred to the redirect channel %s", user->nick.c_str(), cname, channel.c_str());
128 Channel::JoinUser(ServerInstance, user, channel.c_str(), false, "", false, ServerInstance->Time());
136 virtual ~ModuleRedirect()
138 ServerInstance->Modes->DelMode(re);
142 virtual Version GetVersion()
144 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
148 MODULE_INIT(ModuleRedirect)