1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 #include "helperfuncs.h"
28 static bool kludgeme = false;
30 /* $ModDesc: Povides support for services +r user/chan modes and more */
32 extern InspIRCd* ServerInstance;
34 class Channel_r : public ModeHandler
38 Channel_r(InspIRCd* Instance, Server* srv) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_CHANNEL, false), Srv(srv) { }
40 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
42 // only a u-lined server may add or remove the +r mode.
43 if ((Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)) || (!*source->server || (strchr(source->nick,'.'))))
45 log(DEBUG,"Allowing cmode +r, server and nick are: '%s','%s'",source->nick,source->server);
46 channel->SetMode('r',adding);
47 return MODEACTION_ALLOW;
51 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",source->nick,source->server);
52 source->WriteServ("500 "+std::string(source->nick)+" :Only a server may modify the +r channel mode");
53 return MODEACTION_DENY;
58 class User_r : public ModeHandler
62 User_r(InspIRCd* Instance, Server* srv) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_USER, false), Srv(srv) { }
64 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
66 if ((kludgeme) || (Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)) || (!*source->server || (strchr(source->nick,'.'))))
68 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",source->nick,source->server);
69 dest->SetMode('r',adding);
70 return MODEACTION_ALLOW;
74 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",source->nick, source->server);
75 source->WriteServ("500 "+std::string(source->nick)+" :Only a server may modify the +r user mode");
76 return MODEACTION_DENY;
81 class Channel_R : public ModeHandler
84 Channel_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_CHANNEL, false) { }
86 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
90 if (!channel->IsModeSet('R'))
92 channel->SetMode('R',true);
93 return MODEACTION_ALLOW;
98 if (channel->IsModeSet('R'))
100 channel->SetMode('R',false);
101 return MODEACTION_ALLOW;
105 return MODEACTION_DENY;
109 class User_R : public ModeHandler
112 User_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_USER, false) { }
114 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
118 if (!dest->IsModeSet('R'))
120 dest->SetMode('R',true);
121 return MODEACTION_ALLOW;
126 if (dest->IsModeSet('R'))
128 dest->SetMode('R',false);
129 return MODEACTION_ALLOW;
133 return MODEACTION_DENY;
137 class Channel_M : public ModeHandler
140 Channel_M(InspIRCd* Instance) : ModeHandler(Instance, 'M', 0, 0, false, MODETYPE_CHANNEL, false) { }
142 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
146 if (!channel->IsModeSet('M'))
148 channel->SetMode('M',true);
149 return MODEACTION_ALLOW;
154 if (channel->IsModeSet('M'))
156 channel->SetMode('M',true);
157 return MODEACTION_ALLOW;
161 return MODEACTION_DENY;
165 class ModuleServices : public Module
174 ModuleServices(Server* Me)
178 m1 = new Channel_r(ServerInstance, Me);
179 m2 = new Channel_R(ServerInstance);
180 m3 = new Channel_M(ServerInstance);
181 m4 = new User_r(ServerInstance, Me);
182 m5 = new User_R(ServerInstance);
183 Srv->AddMode(m1, 'r');
184 Srv->AddMode(m2, 'R');
185 Srv->AddMode(m3, 'M');
186 Srv->AddMode(m4, 'r');
187 Srv->AddMode(m5, 'R');
191 virtual void On005Numeric(std::string &output)
193 ServerInstance->ModeGrok->InsertMode(output, "rRM", 4);
196 /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */
197 virtual void OnWhois(userrec* source, userrec* dest)
199 if (dest->IsModeSet('r'))
201 /* user is registered */
202 source->WriteServ("307 %s %s :is a registered nick", source->nick, dest->nick);
206 void Implements(char* List)
208 List[I_OnWhois] = List[I_OnUserPostNick] = List[I_OnUserPreMessage] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
211 virtual void OnUserPostNick(userrec* user, const std::string &oldnick)
213 /* On nickchange, if they have +r, remove it */
214 if (user->IsModeSet('r'))
216 const char* modechange[2];
217 modechange[0] = user->nick;
218 modechange[1] = "-r";
220 Srv->SendMode(modechange,2,user);
225 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
227 if (target_type == TYPE_CHANNEL)
229 chanrec* c = (chanrec*)dest;
230 if ((c->IsModeSet('M')) && (!user->IsModeSet('r')))
232 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
234 // user is ulined, can speak regardless
237 // user messaging a +M channel and is not registered
238 user->WriteServ("477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
242 if (target_type == TYPE_USER)
244 userrec* u = (userrec*)dest;
245 if ((u->IsModeSet('R')) && (user->IsModeSet('r')))
247 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
249 // user is ulined, can speak regardless
252 // user messaging a +R user and is not registered
253 user->WriteServ("477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
260 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
262 return OnUserPreMessage(user,dest,target_type,text,status);
265 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
269 if (chan->IsModeSet('R'))
271 if (user->IsModeSet('r'))
273 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
275 // user is ulined, won't be stopped from joining
278 // joining a +R channel and not identified
279 user->WriteServ("477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
287 virtual ~ModuleServices()
296 virtual Version GetVersion()
298 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
303 class ModuleServicesFactory : public ModuleFactory
306 ModuleServicesFactory()
310 ~ModuleServicesFactory()
314 virtual Module * CreateModule(Server* Me)
316 return new ModuleServices(Me);
322 extern "C" void * init_module( void )
324 return new ModuleServicesFactory;