1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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
37 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
38 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
39 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
40 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
41 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
44 virtual void On005Numeric(std::string &output)
46 std::stringstream line(output);
47 std::string temp1, temp2;
51 if (temp1.substr(0,10) == "CHANMODES=")
53 // append the chanmode to the end
54 temp1 = temp1.substr(10,temp1.length());
55 temp1 = "CHANMODES=" + temp1 + "rRM";
57 temp2 = temp2 + temp1 + " ";
60 output = temp2.substr(0,temp2.length()-1);
63 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
68 if (type == MT_CHANNEL)
70 // only a u-lined server may add or remove the +r mode.
71 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
73 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
78 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
79 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
84 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
86 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
91 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
92 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
96 else if (modechar == 'R')
98 if (type == MT_CHANNEL)
103 else if (modechar == 'M')
105 if (type == MT_CHANNEL)
114 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
116 if (target_type == TYPE_CHANNEL)
118 chanrec* c = (chanrec*)dest;
119 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
121 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
123 // user is ulined, can speak regardless
126 // user messaging a +M channel and is not registered
127 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
131 if (target_type == TYPE_USER)
133 userrec* u = (userrec*)dest;
134 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
136 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
138 // user is ulined, can speak regardless
141 // user messaging a +R user and is not registered
142 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
149 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
151 if (target_type == TYPE_CHANNEL)
153 chanrec* c = (chanrec*)dest;
154 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
156 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
158 // user is ulined, can speak regardless
161 // user noticing a +M channel and is not registered
162 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
166 if (target_type == TYPE_USER)
168 userrec* u = (userrec*)dest;
169 if ((strchr(u->modes,'R')) && (!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 +R user and is not registered
177 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
184 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
188 if (chan->IsCustomModeSet('R'))
190 if (!strchr(user->modes,'r'))
192 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
194 // user is ulined, won't be stopped from joining
197 // joining a +R channel and not identified
198 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
206 virtual ~ModuleServices()
211 virtual Version GetVersion()
213 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
216 virtual void OnUserConnect(userrec* user)
223 class ModuleServicesFactory : public ModuleFactory
226 ModuleServicesFactory()
230 ~ModuleServicesFactory()
234 virtual Module * CreateModule()
236 return new ModuleServices;
242 extern "C" void * init_module( void )
244 return new ModuleServicesFactory;