]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_services.cpp
Fixed bug number 34, same nick can exist multiple times on a silence list
[user/henk/code/inspircd.git] / src / modules / m_services.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 #include <string>
22
23
24 /* $ModDesc: Povides support for services +r user/chan modes and more */
25
26 class ModuleServices : public Module
27 {
28         Server *Srv; 
29  public:
30         ModuleServices()
31         {
32                 Srv = new Server;
33
34                 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
35                 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
36                 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
37                 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
38                 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
39         }
40
41         virtual void On005Numeric(std::string &output)
42         {
43                 std::stringstream line(output);
44                 std::string temp1, temp2;
45                 while (!line.eof())
46                 {
47                         line >> temp1;
48                         if (temp1.substr(0,10) == "CHANMODES=")
49                         {
50                                 // append the chanmode to the end
51                                 temp1 = temp1.substr(10,temp1.length());
52                                 temp1 = "CHANMODES=" + temp1 + "rRM";
53                         }
54                         temp2 = temp2 + temp1 + " ";
55                 }
56                 output = temp2.substr(0,temp2.length()-1);
57         }
58         
59         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
60         {
61                 
62                 if (modechar == 'r')
63                 {
64                         if (type == MT_CHANNEL)
65                         {
66                                 // only a u-lined server may add or remove the +r mode.
67                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
68                                 {
69                                         return 1;
70                                 }
71                                 else
72                                 {
73                                         Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
74                                 }
75                         }
76                         else
77                         {
78                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
79                                 {
80                                         return 1;
81                                 }
82                                 else
83                                 {
84                                         Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r user mode");
85                                 }
86                         }
87                 }
88                 else if (modechar == 'R')
89                 {
90                         if (type == MT_CHANNEL)
91                         {
92                                 return 1;
93                         }
94                 }
95                 else if (modechar == 'M')
96                 {
97                         if (type == MT_CHANNEL)
98                         {
99                                 return 1;
100                         }
101                 }
102
103                 return 0;
104         }
105
106         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
107         {
108                 if (target_type == TYPE_CHANNEL)
109                 {
110                         chanrec* c = (chanrec*)dest;
111                         if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
112                         {
113                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
114                                 {
115                                         // user is ulined, can speak regardless
116                                         return 0;
117                                 }
118                                 // user messaging a +M channel and is not registered
119                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
120                                 return 1;
121                         }
122                 }
123                 if (target_type == TYPE_USER)
124                 {
125                         userrec* u = (userrec*)dest;
126                         if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
127                         {
128                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
129                                 {
130                                         // user is ulined, can speak regardless
131                                         return 0;
132                                 }
133                                 // user messaging a +R user and is not registered
134                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
135                                 return 1;
136                         }
137                 }
138                 return 0;
139         }
140         
141         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
142         {
143                 if (target_type == TYPE_CHANNEL)
144                 {
145                         chanrec* c = (chanrec*)dest;
146                         if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
147                         {
148                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
149                                 {
150                                         // user is ulined, can speak regardless
151                                         return 0;
152                                 }
153                                 // user noticing a +M channel and is not registered
154                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
155                                 return 1;
156                         }
157                 }
158                 if (target_type == TYPE_USER)
159                 {
160                         userrec* u = (userrec*)dest;
161                         if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
162                         {
163                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
164                                 {
165                                         // user is ulined, can speak regardless
166                                         return 0;
167                                 }
168                                 // user noticing a +R user and is not registered
169                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
170                                 return 1;
171                         }
172                 }
173                 return 0;
174         }
175         
176         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
177         {
178                 if (chan)
179                 {
180                         if (chan->IsCustomModeSet('R'))
181                         {
182                                 if (!strchr(user->modes,'r'))
183                                 {
184                                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
185                                         {
186                                                 // user is ulined, won't be stopped from joining
187                                                 return 0;
188                                         }
189                                         // joining a +R channel and not identified
190                                         Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
191                                         return 1;
192                                 }
193                         }
194                 }
195                 return 0;
196         }
197
198         virtual ~ModuleServices()
199         {
200                 delete Srv;
201         }
202         
203         virtual Version GetVersion()
204         {
205                 return Version(1,0,0,0);
206         }
207         
208         virtual void OnUserConnect(userrec* user)
209         {
210         }
211
212 };
213
214
215 class ModuleServicesFactory : public ModuleFactory
216 {
217  public:
218         ModuleServicesFactory()
219         {
220         }
221         
222         ~ModuleServicesFactory()
223         {
224         }
225         
226         virtual Module * CreateModule()
227         {
228                 return new ModuleServices;
229         }
230         
231 };
232
233
234 extern "C" void * init_module( void )
235 {
236         return new ModuleServicesFactory;
237 }
238