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
33 ModuleServices(Server* Me)
38 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
39 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
40 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
41 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
42 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
45 virtual void On005Numeric(std::string &output)
47 std::stringstream line(output);
48 std::string temp1, temp2;
52 if (temp1.substr(0,10) == "CHANMODES=")
54 // append the chanmode to the end
55 temp1 = temp1.substr(10,temp1.length());
56 temp1 = "CHANMODES=" + temp1 + "rRM";
58 temp2 = temp2 + temp1 + " ";
61 output = temp2.substr(0,temp2.length()-1);
64 void Implements(char* List)
66 List[I_OnUserPostNick] = List[I_OnUserPreMessage] = List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
69 virtual void OnUserPostNick(userrec* user, std::string oldnick)
71 /* On nickchange, if they have +r, remove it */
72 if (strchr(user->modes,'r'))
75 modechange[0] = user->nick;
77 Srv->SendMode(modechange,2,user);
81 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
86 if (type == MT_CHANNEL)
88 // only a u-lined server may add or remove the +r mode.
89 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
91 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
96 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
97 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
102 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
104 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
109 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
110 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
114 else if (modechar == 'R')
118 else if (modechar == 'M')
120 if (type == MT_CHANNEL)
129 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
131 if (target_type == TYPE_CHANNEL)
133 chanrec* c = (chanrec*)dest;
134 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
136 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
138 // user is ulined, can speak regardless
141 // user messaging a +M channel and is not registered
142 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
146 if (target_type == TYPE_USER)
148 userrec* u = (userrec*)dest;
149 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
151 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
153 // user is ulined, can speak regardless
156 // user messaging a +R user and is not registered
157 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
164 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
166 if (target_type == TYPE_CHANNEL)
168 chanrec* c = (chanrec*)dest;
169 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
171 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
173 // user is ulined, can speak regardless
176 // user noticing a +M channel and is not registered
177 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
181 if (target_type == TYPE_USER)
183 userrec* u = (userrec*)dest;
184 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
186 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
188 // user is ulined, can speak regardless
191 // user noticing a +R user and is not registered
192 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
199 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
203 if (chan->IsCustomModeSet('R'))
205 if (!strchr(user->modes,'r'))
207 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
209 // user is ulined, won't be stopped from joining
212 // joining a +R channel and not identified
213 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
221 virtual ~ModuleServices()
225 virtual Version GetVersion()
227 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
232 class ModuleServicesFactory : public ModuleFactory
235 ModuleServicesFactory()
239 ~ModuleServicesFactory()
243 virtual Module * CreateModule(Server* Me)
245 return new ModuleServices(Me);
251 extern "C" void * init_module( void )
253 return new ModuleServicesFactory;