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