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 class Redirect : public ModeHandler
30 Redirect() : ModeHandler('L', 1, 0, false, MODETYPE_CHANNEL, false) { }
32 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
38 if (!IsValidChannelName(parameter.c_str()))
40 WriteServ(user->fd,"403 %s %s :Invalid channel name",user->nick, parameter.c_str());
42 return MODEACTION_DENY;
45 c = Srv->FindChannel(parameter);
48 /* Fix by brain: Dont let a channel be linked to *itself* either */
49 if ((c == target) || (c->IsModeSet('L')))
51 WriteServ(user->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",user->nick,parameter.c_str());
53 return MODEACTION_DENY;
57 c->SetMode('L', true);
58 c->SetModeParam('L', parameter);
59 return MODEACTION_ALLOW;
64 class ModuleRedirect : public Module
70 ModuleRedirect(Server* Me)
74 Srv->AddExtendedMode('L',MT_CHANNEL,false,1,0);
77 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
79 if ((modechar == 'L') && (type == MT_CHANNEL))
83 std::string ChanToJoin = params[0];
86 if (!IsValidChannelName(ChanToJoin.c_str()))
88 WriteServ(user->fd,"403 %s %s :Invalid channel name",user->nick, ChanToJoin.c_str());
92 c = Srv->FindChannel(ChanToJoin);
95 /* Fix by brain: Dont let a channel be linked to *itself* either */
96 if ((c == target) || (c->IsModeSet('L')))
98 WriteServ(user->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",user->nick,params[0].c_str());
108 void Implements(char* List)
110 List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnExtendedMode] = 1;
113 virtual void On005Numeric(std::string &output)
115 InsertMode(output, "L", 3);
118 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
122 if (chan->IsModeSet('L'))
124 if (Srv->CountUsers(chan) >= chan->limit)
126 std::string channel = chan->GetModeParameter('L');
127 WriteServ(user->fd,"470 %s :%s has become full, so you are automatically being transferred to the linked channel %s",user->nick,cname,channel.c_str());
128 Srv->JoinUserToChannel(user,channel.c_str(),"");
136 virtual ~ModuleRedirect()
140 virtual Version GetVersion()
142 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
147 class ModuleRedirectFactory : public ModuleFactory
150 ModuleRedirectFactory()
154 ~ModuleRedirectFactory()
158 virtual Module * CreateModule(Server* Me)
160 return new ModuleRedirect(Me);
166 extern "C" void * init_module( void )
168 return new ModuleRedirectFactory;