]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_redirect.cpp
Added preliminary m_sqllog.cpp
[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 #include <stdio.h>
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21
22 /* $ModDesc: Provides channel mode +L (limit redirection) */
23
24
25 class ModuleRedirect : public Module
26 {
27         Server *Srv;
28         
29  public:
30  
31         ModuleRedirect()
32         {
33                 Srv = new Server;
34                 Srv->AddExtendedMode('L',MT_CHANNEL,false,1,0);
35         }
36         
37         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
38         {
39                 if ((modechar == 'L') && (type == MT_CHANNEL))
40                 {
41                         if (mode_on)
42                         {
43                                 std::string ChanToJoin = params[0];
44                                 chanrec* c = Srv->FindChannel(ChanToJoin);
45                                 if (c)
46                                 {
47                                         if (c->IsCustomModeSet('L'))
48                                         {
49                                                 WriteServ(user->fd,"690 %s :Circular redirection, mode +L to %s not allowed.",user->nick,params[0].c_str());
50                                                 return 0;
51                                         }
52                                 }
53                         }
54                         return 1;
55                 }
56                 return 0;
57         }
58
59         virtual void On005Numeric(std::string &output)
60         {
61                 std::stringstream line(output);
62                 std::string temp1, temp2;
63                 while (!line.eof())
64                 {
65                         line >> temp1;
66                         if (temp1.substr(0,10) == "CHANMODES=")
67                         {
68                                 // By doing this we're *assuming* no other module has fucked up the CHANMODES=
69                                 // section of the 005 numeric. If they have, we're going DOWN in a blaze of glory,
70                                 // with a honking great EXCEPTION :)
71                                 temp1.insert(temp1.find(",")+1,"L");
72                         }
73                         temp2 = temp2 + temp1 + " ";
74                 }
75                 if (temp2.length())
76                         output = temp2.substr(0,temp2.length()-1);
77         }
78         
79         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
80         {
81                 if (chan)
82                 {
83                         if (chan->IsCustomModeSet('L'))
84                         {
85                                 if (Srv->CountUsers(chan) >= chan->limit)
86                                 {
87                                         std::string channel = chan->GetModeParameter('L');
88                                         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());
89                                         Srv->JoinUserToChannel(user,channel.c_str(),"");
90                                         return 1;
91                                 }
92                         }
93                 }
94                 return 0;
95         }
96
97         virtual ~ModuleRedirect()
98         {
99                 delete Srv;
100         }
101         
102         virtual Version GetVersion()
103         {
104                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
105         }
106         
107         virtual void OnUserConnect(userrec* user)
108         {
109         }
110
111 };
112
113
114 class ModuleRedirectFactory : public ModuleFactory
115 {
116  public:
117         ModuleRedirectFactory()
118         {
119         }
120         
121         ~ModuleRedirectFactory()
122         {
123         }
124         
125         virtual Module * CreateModule()
126         {
127                 return new ModuleRedirect;
128         }
129         
130 };
131
132
133 extern "C" void * init_module( void )
134 {
135         return new ModuleRedirectFactory;
136 }
137