]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_redirect.cpp
Added support for +L (services doesnt support this yet)
[user/henk/code/inspircd.git] / src / modules / m_redirect.cpp
1 #include <stdio.h>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6
7 /* $ModDesc: Provides channel mode +L (limit redirection) */
8
9
10 class ModuleRedirect : public Module
11 {
12         Server *Srv;
13         
14  public:
15  
16         ModuleRedirect()
17         {
18                 Srv = new Server;
19                 Srv->AddExtendedMode('L',MT_CHANNEL,false,1,0);
20         }
21         
22         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
23         {
24                 if ((modechar == 'L') && (type == MT_CHANNEL))
25                 {
26                         if (mode_on)
27                         {
28                                 std::string ChanToJoin = params[0];
29                                 chanrec* c = Srv->FindChannel(ChanToJoin);
30                                 if (c)
31                                 {
32                                         if (c->IsCustomModeSet('L'))
33                                         {
34                                                 WriteServ(user->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",user->nick,params[0].c_str());
35                                                 return 0;
36                                         }
37                                 }
38                         }
39                         return 1;
40                 }
41         }
42         
43         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
44         {
45                 if (chan)
46                 {
47                         if (chan->IsCustomModeSet('L'))
48                         {
49                                 if (chan->limit >= Srv->CountUsers(chan))
50                                 {
51                                         std::string channel = chan->GetModeParameter('L');
52                                         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());
53                                         Srv->JoinUserToChannel(user,channel.c_str(),"");
54                                         return 1;
55                                 }
56                         }
57                 }
58         }
59
60         virtual ~ModuleRedirect()
61         {
62                 delete Srv;
63         }
64         
65         virtual Version GetVersion()
66         {
67                 return Version(1,0,0,0);
68         }
69         
70         virtual void OnUserConnect(userrec* user)
71         {
72         }
73
74 };
75
76
77 class ModuleRedirectFactory : public ModuleFactory
78 {
79  public:
80         ModuleRedirectFactory()
81         {
82         }
83         
84         ~ModuleRedirectFactory()
85         {
86         }
87         
88         virtual Module * CreateModule()
89         {
90                 return new ModuleRedirect;
91         }
92         
93 };
94
95
96 extern "C" void * init_module( void )
97 {
98         return new ModuleRedirectFactory;
99 }
100