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 class Redirect : public ModeHandler
29 Redirect(InspIRCd* Instance) : ModeHandler(Instance, 'L', 1, 0, false, MODETYPE_CHANNEL, false) { }
31 ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
33 if (channel->IsModeSet('L'))
34 return std::make_pair(true, channel->GetModeParameter('L'));
36 return std::make_pair(false, parameter);
39 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
41 /* When TS is equal, the alphabetically later one wins */
42 return (their_param < our_param);
45 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
51 if (!ServerInstance->IsChannel(parameter.c_str()))
53 source->WriteServ("403 %s %s :Invalid channel name",source->nick, parameter.c_str());
55 return MODEACTION_DENY;
58 c = ServerInstance->FindChan(parameter);
61 /* Fix by brain: Dont let a channel be linked to *itself* either */
64 if ((c == channel) || (c->IsModeSet('L')))
66 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());
68 return MODEACTION_DENY;
72 for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
74 if ((i->second != channel) && (i->second->IsModeSet('L')) && (irc::string(i->second->GetModeParameter('L').c_str()) == irc::string(channel->name)))
76 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);
77 return MODEACTION_DENY;
84 channel->SetMode('L', true);
85 channel->SetModeParam('L', parameter.c_str(), true);
86 return MODEACTION_ALLOW;
90 if (channel->IsModeSet('L'))
92 channel->SetMode('L', false);
93 return MODEACTION_ALLOW;
97 return MODEACTION_DENY;
102 class ModuleRedirect : public Module
109 ModuleRedirect(InspIRCd* Me)
113 re = new Redirect(ServerInstance);
114 ServerInstance->AddMode(re, 'L');
117 void Implements(char* List)
119 List[I_OnUserPreJoin] = 1;
122 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
126 if (chan->IsModeSet('L') && chan->limit)
128 if (chan->GetUserCounter() >= chan->limit)
130 std::string channel = chan->GetModeParameter('L');
131 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());
132 chanrec::JoinUser(ServerInstance, user, channel.c_str(), false);
140 virtual ~ModuleRedirect()
142 ServerInstance->Modes->DelMode(re);
146 virtual Version GetVersion()
148 return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR);
153 class ModuleRedirectFactory : public ModuleFactory
156 ModuleRedirectFactory()
160 ~ModuleRedirectFactory()
164 virtual Module * CreateModule(InspIRCd* Me)
166 return new ModuleRedirect(Me);
172 extern "C" void * init_module( void )
174 return new ModuleRedirectFactory;