]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_redirect.cpp
Fixed strcpy vs. strlcpy problem
[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                 output = temp2.substr(0,temp2.length()-1);
76         }
77         
78         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
79         {
80                 if (chan)
81                 {
82                         if (chan->IsCustomModeSet('L'))
83                         {
84                                 if (chan->limit >= Srv->CountUsers(chan))
85                                 {
86                                         std::string channel = chan->GetModeParameter('L');
87                                         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());
88                                         Srv->JoinUserToChannel(user,channel.c_str(),"");
89                                         return 1;
90                                 }
91                         }
92                 }
93         }
94
95         virtual ~ModuleRedirect()
96         {
97                 delete Srv;
98         }
99         
100         virtual Version GetVersion()
101         {
102                 return Version(1,0,0,0);
103         }
104         
105         virtual void OnUserConnect(userrec* user)
106         {
107         }
108
109 };
110
111
112 class ModuleRedirectFactory : public ModuleFactory
113 {
114  public:
115         ModuleRedirectFactory()
116         {
117         }
118         
119         ~ModuleRedirectFactory()
120         {
121         }
122         
123         virtual Module * CreateModule()
124         {
125                 return new ModuleRedirect;
126         }
127         
128 };
129
130
131 extern "C" void * init_module( void )
132 {
133         return new ModuleRedirectFactory;
134 }
135