]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_redirect.cpp
Decide that it wasn't quite appropriate :(
[user/henk/code/inspircd.git] / src / modules / m_redirect.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "helperfuncs.h"
24
25 /* $ModDesc: Provides channel mode +L (limit redirection) */
26
27
28 class ModuleRedirect : public Module
29 {
30         Server *Srv;
31         
32  public:
33  
34         ModuleRedirect(Server* Me)
35                 : Module::Module(Me)
36         {
37                 Srv = Me;
38                 Srv->AddExtendedMode('L',MT_CHANNEL,false,1,0);
39         }
40         
41         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
42         {
43                 if ((modechar == 'L') && (type == MT_CHANNEL))
44                 {
45                         if (mode_on)
46                         {
47                                 std::string ChanToJoin = params[0];
48                                 chanrec *c;
49
50                                 if (!IsValidChannelName(ChanToJoin.c_str()))
51                                 {
52                                         WriteServ(user->fd,"403 %s %s :Invalid channel name",user->nick, ChanToJoin.c_str());
53                                         return 0;
54                                 }
55
56                                 c = Srv->FindChannel(ChanToJoin);
57                                 if (c)
58                                 {
59                                         /* Fix by brain: Dont let a channel be linked to *itself* either */
60                                         if ((c == target) || (c->IsCustomModeSet('L')))
61                                         {
62                                                 WriteServ(user->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",user->nick,params[0].c_str());
63                                                 return 0;
64                                         }
65                                 }
66                         }
67                         return 1;
68                 }
69                 return 0;
70         }
71
72         void Implements(char* List)
73         {
74                 List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnExtendedMode] = 1;
75         }
76
77         virtual void On005Numeric(std::string &output)
78         {
79                 InsertMode(output, "L", 3);
80         }
81         
82         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
83         {
84                 if (chan)
85                 {
86                         if (chan->IsCustomModeSet('L'))
87                         {
88                                 if (Srv->CountUsers(chan) >= chan->limit)
89                                 {
90                                         std::string channel = chan->GetModeParameter('L');
91                                         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());
92                                         Srv->JoinUserToChannel(user,channel.c_str(),"");
93                                         return 1;
94                                 }
95                         }
96                 }
97                 return 0;
98         }
99
100         virtual ~ModuleRedirect()
101         {
102         }
103         
104         virtual Version GetVersion()
105         {
106                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
107         }
108 };
109
110
111 class ModuleRedirectFactory : public ModuleFactory
112 {
113  public:
114         ModuleRedirectFactory()
115         {
116         }
117         
118         ~ModuleRedirectFactory()
119         {
120         }
121         
122         virtual Module * CreateModule(Server* Me)
123         {
124                 return new ModuleRedirect(Me);
125         }
126         
127 };
128
129
130 extern "C" void * init_module( void )
131 {
132         return new ModuleRedirectFactory;
133 }
134