]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_redirect.cpp
Added m_blockcolor, implements unreal-style mode +c for color blocking
[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                 return 0;
42         }
43         
44         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
45         {
46                 if (chan)
47                 {
48                         if (chan->IsCustomModeSet('L'))
49                         {
50                                 if (chan->limit >= Srv->CountUsers(chan))
51                                 {
52                                         std::string channel = chan->GetModeParameter('L');
53                                         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());
54                                         Srv->JoinUserToChannel(user,channel.c_str(),"");
55                                         return 1;
56                                 }
57                         }
58                 }
59         }
60
61         virtual ~ModuleRedirect()
62         {
63                 delete Srv;
64         }
65         
66         virtual Version GetVersion()
67         {
68                 return Version(1,0,0,0);
69         }
70         
71         virtual void OnUserConnect(userrec* user)
72         {
73         }
74
75 };
76
77
78 class ModuleRedirectFactory : public ModuleFactory
79 {
80  public:
81         ModuleRedirectFactory()
82         {
83         }
84         
85         ~ModuleRedirectFactory()
86         {
87         }
88         
89         virtual Module * CreateModule()
90         {
91                 return new ModuleRedirect;
92         }
93         
94 };
95
96
97 extern "C" void * init_module( void )
98 {
99         return new ModuleRedirectFactory;
100 }
101