]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_services.cpp
Added m_blockcolor, implements unreal-style mode +c for color blocking
[user/henk/code/inspircd.git] / src / modules / m_services.cpp
1 #include <stdio.h>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6 #include <string>
7
8
9 /* $ModDesc: Povides support for services +r user/chan modes and more */
10
11 class ModuleServices : public Module
12 {
13         Server *Srv; 
14  public:
15         ModuleServices()
16         {
17                 Srv = new Server;
18
19                 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
20                 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
21                 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
22                 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
23                 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
24         }
25         
26         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
27         {
28                 
29                 if (modechar == 'r')
30                 {
31                         if (type == MT_CHANNEL)
32                         {
33                                 // only a u-lined server may add or remove the +r mode.
34                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
35                                 {
36                                         return 1;
37                                 }
38                                 else
39                                 {
40                                         Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
41                                 }
42                         }
43                         else
44                         {
45                                 if (!strcmp(user->server,""))
46                                 {
47                                         return 1;
48                                 }
49                                 else
50                                 {
51                                         Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
52                                 }
53                         }
54                 }
55                 else if (modechar == 'R')
56                 {
57                         if (type == MT_CHANNEL)
58                         {
59                                 return 1;
60                         }
61                 }
62                 else if (modechar == 'M')
63                 {
64                         if (type == MT_CHANNEL)
65                         {
66                                 return 1;
67                         }
68                 }
69
70                 return 0;
71         }
72
73         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text)
74         {
75                 if (target_type == TYPE_CHANNEL)
76                 {
77                         chanrec* c = (chanrec*)dest;
78                         if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
79                         {
80                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
81                                 {
82                                         // user is ulined, can speak regardless
83                                         return 0;
84                                 }
85                                 // user messaging a +M channel and is not registered
86                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
87                                 return 1;
88                         }
89                 }
90                 if (target_type == TYPE_USER)
91                 {
92                         userrec* u = (userrec*)dest;
93                         if ((strchr(u->modes,'R')) && (!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 +R user and is not registered
101                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
102                                 return 1;
103                         }
104                 }
105                 return 0;
106         }
107         
108         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text)
109         {
110                 if (target_type == TYPE_CHANNEL)
111                 {
112                         chanrec* c = (chanrec*)dest;
113                         if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
114                         {
115                                 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
116                                 {
117                                         // user is ulined, can speak regardless
118                                         return 0;
119                                 }
120                                 // user noticing a +M channel and is not registered
121                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
122                                 return 1;
123                         }
124                 }
125                 if (target_type == TYPE_USER)
126                 {
127                         userrec* u = (userrec*)dest;
128                         if ((strchr(u->modes,'R')) && (!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 +R user and is not registered
136                                 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
137                                 return 1;
138                         }
139                 }
140                 return 0;
141         }
142         
143         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
144         {
145                 if (chan)
146                 {
147                         if (chan->IsCustomModeSet('R'))
148                         {
149                                 if (!strchr(user->modes,'r'))
150                                 {
151                                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
152                                         {
153                                                 // user is ulined, won't be stopped from joining
154                                                 return 0;
155                                         }
156                                         // joining a +R channel and not identified
157                                         Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
158                                         return 1;
159                                 }
160                         }
161                 }
162                 return 0;
163         }
164
165         virtual ~ModuleServices()
166         {
167                 delete Srv;
168         }
169         
170         virtual Version GetVersion()
171         {
172                 return Version(1,0,0,0);
173         }
174         
175         virtual void OnUserConnect(userrec* user)
176         {
177         }
178
179 };
180
181
182 class ModuleServicesFactory : public ModuleFactory
183 {
184  public:
185         ModuleServicesFactory()
186         {
187         }
188         
189         ~ModuleServicesFactory()
190         {
191         }
192         
193         virtual Module * CreateModule()
194         {
195                 return new ModuleServices;
196         }
197         
198 };
199
200
201 extern "C" void * init_module( void )
202 {
203         return new ModuleServicesFactory;
204 }
205