1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 /* $ModDesc: Provides channel mode +L (limit redirection) */
26 /** Handle channel mode +L
28 class Redirect : public ModeHandler
31 Redirect(InspIRCd* Instance) : ModeHandler(Instance, 'L', 1, 0, false, MODETYPE_CHANNEL, false) { }
33 ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
35 if (channel->IsModeSet('L'))
36 return std::make_pair(true, channel->GetModeParameter('L'));
38 return std::make_pair(false, parameter);
41 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
43 /* When TS is equal, the alphabetically later one wins */
44 return (their_param < our_param);
47 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
53 if (!ServerInstance->IsChannel(parameter.c_str()))
55 source->WriteServ("403 %s %s :Invalid channel name",source->nick, parameter.c_str());
57 return MODEACTION_DENY;
60 c = ServerInstance->FindChan(parameter);
63 /* Fix by brain: Dont let a channel be linked to *itself* either */
66 if ((c == channel) || (c->IsModeSet('L')))
68 source->WriteServ("690 %s :Circular or chained +L to %s not allowed (Channel already has +L). Pack of wild dogs has been unleashed.",source->nick,parameter.c_str());
70 return MODEACTION_DENY;
74 for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
76 if ((i->second != channel) && (i->second->IsModeSet('L')) && (irc::string(i->second->GetModeParameter('L').c_str()) == irc::string(channel->name)))
78 source->WriteServ("690 %s :Circular or chained +L to %s not allowed (Already forwarded here from %s). Angry monkeys dispatched.",source->nick,parameter.c_str(),i->second->name);
79 return MODEACTION_DENY;
86 channel->SetMode('L', true);
87 channel->SetModeParam('L', parameter.c_str(), true);
88 return MODEACTION_ALLOW;
92 if (channel->IsModeSet('L'))
94 channel->SetMode('L', false);
95 return MODEACTION_ALLOW;
99 return MODEACTION_DENY;
104 class ModuleRedirect : public Module
111 ModuleRedirect(InspIRCd* Me)
115 re = new Redirect(ServerInstance);
116 ServerInstance->AddMode(re, 'L');
119 void Implements(char* List)
121 List[I_OnUserPreJoin] = 1;
124 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
128 if (chan->IsModeSet('L') && chan->limit)
130 if (chan->GetUserCounter() >= chan->limit)
132 std::string channel = chan->GetModeParameter('L');
133 user->WriteServ("470 %s :%s has become full, so you are automatically being transferred to the linked channel %s",user->nick,cname,channel.c_str());
134 chanrec::JoinUser(ServerInstance, user, channel.c_str(), false);
142 virtual ~ModuleRedirect()
144 ServerInstance->Modes->DelMode(re);
148 virtual Version GetVersion()
150 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
155 class ModuleRedirectFactory : public ModuleFactory
158 ModuleRedirectFactory()
162 ~ModuleRedirectFactory()
166 virtual Module * CreateModule(InspIRCd* Me)
168 return new ModuleRedirect(Me);
174 extern "C" void * init_module( void )
176 return new ModuleRedirectFactory;