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