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
31 Redirect(Server* s) : ModeHandler('L', 1, 0, false, MODETYPE_CHANNEL, false), Srv(s) { }
33 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
39 if (!IsValidChannelName(parameter.c_str()))
41 WriteServ(source->fd,"403 %s %s :Invalid channel name",source->nick, parameter.c_str());
43 return MODEACTION_DENY;
46 c = Srv->FindChannel(parameter);
49 /* Fix by brain: Dont let a channel be linked to *itself* either */
50 if ((c == channel) || (c->IsModeSet('L')))
52 WriteServ(source->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",source->nick,parameter.c_str());
54 return MODEACTION_DENY;
58 channel->SetMode('L', true);
59 channel->SetModeParam('L', parameter.c_str(), true);
60 return MODEACTION_ALLOW;
64 if (channel->IsModeSet('L'))
66 channel->SetMode('L', false);
67 return MODEACTION_ALLOW;
71 return MODEACTION_DENY;
76 class ModuleRedirect : public Module
83 ModuleRedirect(Server* Me)
87 re = new Redirect(Me);
88 Srv->AddMode(re, 'L');
91 void Implements(char* List)
93 List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
96 virtual void On005Numeric(std::string &output)
98 InsertMode(output, "L", 3);
101 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
105 if (chan->IsModeSet('L'))
107 if (Srv->CountUsers(chan) >= chan->limit)
109 std::string channel = chan->GetModeParameter('L');
110 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());
111 Srv->JoinUserToChannel(user,channel.c_str(),"");
119 virtual ~ModuleRedirect()
124 virtual Version GetVersion()
126 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
131 class ModuleRedirectFactory : public ModuleFactory
134 ModuleRedirectFactory()
138 ~ModuleRedirectFactory()
142 virtual Module * CreateModule(Server* Me)
144 return new ModuleRedirect(Me);
150 extern "C" void * init_module( void )
152 return new ModuleRedirectFactory;