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 ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
35 if (channel->IsModeSet('L'))
36 return std::make_pair(true, channel->GetModeParameter('L'));
38 return std::make_pair(false, parameter);
41 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
43 /* When TS is equal, the alphabetically later one wins */
44 return (their_param < our_param);
47 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
53 if (!IsValidChannelName(parameter.c_str()))
55 WriteServ(source->fd,"403 %s %s :Invalid channel name",source->nick, parameter.c_str());
57 return MODEACTION_DENY;
60 c = Srv->FindChannel(parameter);
63 /* Fix by brain: Dont let a channel be linked to *itself* either */
64 if ((c == channel) || (c->IsModeSet('L')))
66 WriteServ(source->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",source->nick,parameter.c_str());
68 return MODEACTION_DENY;
72 channel->SetMode('L', true);
73 channel->SetModeParam('L', parameter.c_str(), true);
74 return MODEACTION_ALLOW;
78 if (channel->IsModeSet('L'))
80 channel->SetMode('L', false);
81 return MODEACTION_ALLOW;
85 return MODEACTION_DENY;
90 class ModuleRedirect : public Module
97 ModuleRedirect(Server* Me)
101 re = new Redirect(Me);
102 Srv->AddMode(re, 'L');
105 void Implements(char* List)
107 List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
110 virtual void On005Numeric(std::string &output)
112 InsertMode(output, "L", 3);
115 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
119 if (chan->IsModeSet('L'))
121 if (Srv->CountUsers(chan) >= chan->limit)
123 std::string channel = chan->GetModeParameter('L');
124 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());
125 Srv->JoinUserToChannel(user,channel.c_str(),"");
133 virtual ~ModuleRedirect()
138 virtual Version GetVersion()
140 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
145 class ModuleRedirectFactory : public ModuleFactory
148 ModuleRedirectFactory()
152 ~ModuleRedirectFactory()
156 virtual Module * CreateModule(Server* Me)
158 return new ModuleRedirect(Me);
164 extern "C" void * init_module( void )
166 return new ModuleRedirectFactory;