]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_redirect.cpp
Changed to use __single_client_alloc, faster on most systems in a single thread
[user/henk/code/inspircd.git] / src / modules / m_redirect.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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()
35         {
36                 Srv = new Server;
37                 Srv->AddExtendedMode('L',MT_CHANNEL,false,1,0);
38         }
39         
40         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
41         {
42                 if ((modechar == 'L') && (type == MT_CHANNEL))
43                 {
44                         if (mode_on)
45                         {
46                                 std::string ChanToJoin = params[0];
47                                 chanrec* c = Srv->FindChannel(ChanToJoin);
48                                 if (c)
49                                 {
50                                         if (c->IsCustomModeSet('L'))
51                                         {
52                                                 WriteServ(user->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",user->nick,params[0].c_str());
53                                                 return 0;
54                                         }
55                                 }
56                         }
57                         return 1;
58                 }
59                 return 0;
60         }
61
62         virtual void On005Numeric(std::string &output)
63         {
64                 std::stringstream line(output);
65                 std::string temp1, temp2;
66                 while (!line.eof())
67                 {
68                         line >> temp1;
69                         if (temp1.substr(0,10) == "CHANMODES=")
70                         {
71                                 // By doing this we're *assuming* no other module has fucked up the CHANMODES=
72                                 // section of the 005 numeric. If they have, we're going DOWN in a blaze of glory,
73                                 // with a honking great EXCEPTION :)
74                                 temp1.insert(temp1.find(",")+1,"L");
75                         }
76                         temp2 = temp2 + temp1 + " ";
77                 }
78                 if (temp2.length())
79                         output = temp2.substr(0,temp2.length()-1);
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                 delete Srv;
103         }
104         
105         virtual Version GetVersion()
106         {
107                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
108         }
109         
110         virtual void OnUserConnect(userrec* user)
111         {
112         }
113
114 };
115
116
117 class ModuleRedirectFactory : public ModuleFactory
118 {
119  public:
120         ModuleRedirectFactory()
121         {
122         }
123         
124         ~ModuleRedirectFactory()
125         {
126         }
127         
128         virtual Module * CreateModule()
129         {
130                 return new ModuleRedirect;
131         }
132         
133 };
134
135
136 extern "C" void * init_module( void )
137 {
138         return new ModuleRedirectFactory;
139 }
140