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 /* $ModDesc: Povides support for services +r user/chan modes and more */
26 class ModuleServices : public Module
34 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
35 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
36 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
37 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
38 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
41 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
46 if (type == MT_CHANNEL)
48 // only a u-lined server may add or remove the +r mode.
49 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
51 // FCS - BugFix for #27 :)
52 if ((!strchr(user->modes,'r')) && (mode_on == false)) {
54 } else if (strchr(user->modes,'r')) && (mode_on == true)) {
62 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
67 if (!strcmp(user->server,""))
73 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
77 else if (modechar == 'R')
79 if (type == MT_CHANNEL)
84 else if (modechar == 'M')
86 if (type == MT_CHANNEL)
95 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
97 if (target_type == TYPE_CHANNEL)
99 chanrec* c = (chanrec*)dest;
100 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
102 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
104 // user is ulined, can speak regardless
107 // user messaging a +M channel and is not registered
108 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
112 if (target_type == TYPE_USER)
114 userrec* u = (userrec*)dest;
115 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
117 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
119 // user is ulined, can speak regardless
122 // user messaging a +R user and is not registered
123 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
130 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
132 if (target_type == TYPE_CHANNEL)
134 chanrec* c = (chanrec*)dest;
135 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
137 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
139 // user is ulined, can speak regardless
142 // user noticing a +M channel and is not registered
143 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
147 if (target_type == TYPE_USER)
149 userrec* u = (userrec*)dest;
150 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
152 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
154 // user is ulined, can speak regardless
157 // user noticing a +R user and is not registered
158 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
165 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
169 if (chan->IsCustomModeSet('R'))
171 if (!strchr(user->modes,'r'))
173 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
175 // user is ulined, won't be stopped from joining
178 // joining a +R channel and not identified
179 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
187 virtual ~ModuleServices()
192 virtual Version GetVersion()
194 return Version(1,0,0,0);
197 virtual void OnUserConnect(userrec* user)
204 class ModuleServicesFactory : public ModuleFactory
207 ModuleServicesFactory()
211 ~ModuleServicesFactory()
215 virtual Module * CreateModule()
217 return new ModuleServices;
223 extern "C" void * init_module( void )
225 return new ModuleServicesFactory;