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 * ---------------------------------------------------
23 #include "helperfuncs.h"
26 /* $ModDesc: Provides channel mode +L (limit redirection) */
28 extern InspIRCd* ServerInstance;
30 class Redirect : public ModeHandler
34 Redirect(Server* s) : ModeHandler('L', 1, 0, false, MODETYPE_CHANNEL, false), Srv(s) { }
36 ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
38 if (channel->IsModeSet('L'))
39 return std::make_pair(true, channel->GetModeParameter('L'));
41 return std::make_pair(false, parameter);
44 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
46 /* When TS is equal, the alphabetically later one wins */
47 return (their_param < our_param);
50 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
56 if (!IsValidChannelName(parameter.c_str()))
58 source->WriteServ("403 %s %s :Invalid channel name",source->nick, parameter.c_str());
60 return MODEACTION_DENY;
63 c = ServerInstance->FindChan(parameter);
66 /* Fix by brain: Dont let a channel be linked to *itself* either */
69 if ((c == channel) || (c->IsModeSet('L')))
71 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());
73 return MODEACTION_DENY;
77 for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
79 if ((i->second != channel) && (i->second->IsModeSet('L')) && (irc::string(i->second->GetModeParameter('L').c_str()) == irc::string(channel->name)))
81 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);
82 return MODEACTION_DENY;
89 channel->SetMode('L', true);
90 channel->SetModeParam('L', parameter.c_str(), true);
91 return MODEACTION_ALLOW;
95 if (channel->IsModeSet('L'))
97 channel->SetMode('L', false);
98 return MODEACTION_ALLOW;
102 return MODEACTION_DENY;
107 class ModuleRedirect : public Module
114 ModuleRedirect(Server* Me)
118 re = new Redirect(Me);
119 Srv->AddMode(re, 'L');
122 void Implements(char* List)
124 List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
127 virtual void On005Numeric(std::string &output)
129 InsertMode(output, "L", 3);
132 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
136 if (chan->IsModeSet('L'))
138 if (chan->GetUserCounter() >= chan->limit)
140 std::string channel = chan->GetModeParameter('L');
141 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());
142 chanrec::JoinUser(ServerInstance, user, channel.c_str(), false);
150 virtual ~ModuleRedirect()
155 virtual Version GetVersion()
157 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
162 class ModuleRedirectFactory : public ModuleFactory
165 ModuleRedirectFactory()
169 ~ModuleRedirectFactory()
173 virtual Module * CreateModule(Server* Me)
175 return new ModuleRedirect(Me);
181 extern "C" void * init_module( void )
183 return new ModuleRedirectFactory;