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"
25 /* $ModDesc: Provides channel mode +L (limit redirection) */
27 extern chan_hash chanlist;
29 class Redirect : public ModeHandler
33 Redirect(Server* s) : ModeHandler('L', 1, 0, false, MODETYPE_CHANNEL, false), Srv(s) { }
35 ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
37 if (channel->IsModeSet('L'))
38 return std::make_pair(true, channel->GetModeParameter('L'));
40 return std::make_pair(false, parameter);
43 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
45 /* When TS is equal, the alphabetically later one wins */
46 return (their_param < our_param);
49 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
55 if (!IsValidChannelName(parameter.c_str()))
57 source->WriteServ("403 %s %s :Invalid channel name",source->nick, parameter.c_str());
59 return MODEACTION_DENY;
62 c = Srv->FindChannel(parameter);
65 /* Fix by brain: Dont let a channel be linked to *itself* either */
68 if ((c == channel) || (c->IsModeSet('L')))
70 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());
72 return MODEACTION_DENY;
76 for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
78 if ((i->second != channel) && (i->second->IsModeSet('L')) && (irc::string(i->second->GetModeParameter('L').c_str()) == irc::string(channel->name)))
80 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);
81 return MODEACTION_DENY;
88 channel->SetMode('L', true);
89 channel->SetModeParam('L', parameter.c_str(), true);
90 return MODEACTION_ALLOW;
94 if (channel->IsModeSet('L'))
96 channel->SetMode('L', false);
97 return MODEACTION_ALLOW;
101 return MODEACTION_DENY;
106 class ModuleRedirect : public Module
113 ModuleRedirect(Server* Me)
117 re = new Redirect(Me);
118 Srv->AddMode(re, 'L');
121 void Implements(char* List)
123 List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
126 virtual void On005Numeric(std::string &output)
128 InsertMode(output, "L", 3);
131 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
135 if (chan->IsModeSet('L'))
137 if (Srv->CountUsers(chan) >= chan->limit)
139 std::string channel = chan->GetModeParameter('L');
140 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());
141 chanrec::JoinUser(user, channel.c_str(), false);
149 virtual ~ModuleRedirect()
154 virtual Version GetVersion()
156 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
161 class ModuleRedirectFactory : public ModuleFactory
164 ModuleRedirectFactory()
168 ~ModuleRedirectFactory()
172 virtual Module * CreateModule(Server* Me)
174 return new ModuleRedirect(Me);
180 extern "C" void * init_module( void )
182 return new ModuleRedirectFactory;