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"
27 /* $ModDesc: Povides support for services +r user/chan modes and more */
29 class ModuleServices : public Module
35 ModuleServices(Server* Me)
40 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
41 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
42 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
43 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
44 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
49 virtual void On005Numeric(std::string &output)
51 InsertMode(output, "rRM", 4);
54 void Implements(char* List)
56 List[I_OnUserPostNick] = List[I_OnUserPreMessage] = List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
59 virtual void OnUserPostNick(userrec* user, std::string oldnick)
61 /* On nickchange, if they have +r, remove it */
62 if (strchr(user->modes,'r'))
65 modechange[0] = user->nick;
68 Srv->SendMode(modechange,2,user);
73 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
78 if (type == MT_CHANNEL)
80 // only a u-lined server may add or remove the +r mode.
81 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
83 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
88 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
89 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
94 if ((kludgeme) || (Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
96 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
101 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
102 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
106 else if (modechar == 'R')
110 else if (modechar == 'M')
112 if (type == MT_CHANNEL)
121 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
123 if (target_type == TYPE_CHANNEL)
125 chanrec* c = (chanrec*)dest;
126 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
128 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
130 // user is ulined, can speak regardless
133 // user messaging a +M channel and is not registered
134 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
138 if (target_type == TYPE_USER)
140 userrec* u = (userrec*)dest;
141 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
143 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
145 // user is ulined, can speak regardless
148 // user messaging a +R user and is not registered
149 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
156 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
158 if (target_type == TYPE_CHANNEL)
160 chanrec* c = (chanrec*)dest;
161 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
163 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
165 // user is ulined, can speak regardless
168 // user noticing a +M channel and is not registered
169 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
173 if (target_type == TYPE_USER)
175 userrec* u = (userrec*)dest;
176 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
178 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
180 // user is ulined, can speak regardless
183 // user noticing a +R user and is not registered
184 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
191 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
195 if (chan->IsCustomModeSet('R'))
197 if (!strchr(user->modes,'r'))
199 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
201 // user is ulined, won't be stopped from joining
204 // joining a +R channel and not identified
205 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
213 virtual ~ModuleServices()
217 virtual Version GetVersion()
219 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
224 class ModuleServicesFactory : public ModuleFactory
227 ModuleServicesFactory()
231 ~ModuleServicesFactory()
235 virtual Module * CreateModule(Server* Me)
237 return new ModuleServices(Me);
243 extern "C" void * init_module( void )
245 return new ModuleServicesFactory;