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_OnUserPreMessage] = List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
69 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
74 if (type == MT_CHANNEL)
76 // only a u-lined server may add or remove the +r mode.
77 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
79 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
84 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
85 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
90 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
92 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
97 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
98 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
102 else if (modechar == 'R')
106 else if (modechar == 'M')
108 if (type == MT_CHANNEL)
117 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
119 if (target_type == TYPE_CHANNEL)
121 chanrec* c = (chanrec*)dest;
122 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
124 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
126 // user is ulined, can speak regardless
129 // user messaging a +M channel and is not registered
130 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
134 if (target_type == TYPE_USER)
136 userrec* u = (userrec*)dest;
137 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
139 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
141 // user is ulined, can speak regardless
144 // user messaging a +R user and is not registered
145 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
152 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
154 if (target_type == TYPE_CHANNEL)
156 chanrec* c = (chanrec*)dest;
157 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
159 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
161 // user is ulined, can speak regardless
164 // user noticing a +M channel and is not registered
165 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
169 if (target_type == TYPE_USER)
171 userrec* u = (userrec*)dest;
172 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
174 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
176 // user is ulined, can speak regardless
179 // user noticing a +R user and is not registered
180 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
187 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
191 if (chan->IsCustomModeSet('R'))
193 if (!strchr(user->modes,'r'))
195 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
197 // user is ulined, won't be stopped from joining
200 // joining a +R channel and not identified
201 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
209 virtual ~ModuleServices()
213 virtual Version GetVersion()
215 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
220 class ModuleServicesFactory : public ModuleFactory
223 ModuleServicesFactory()
227 ~ModuleServicesFactory()
231 virtual Module * CreateModule(Server* Me)
233 return new ModuleServices(Me);
239 extern "C" void * init_module( void )
241 return new ModuleServicesFactory;