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 /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */
55 virtual void OnWhois(userrec* source, userrec* dest)
57 if (strchr(dest->modes, 'r'))
59 /* user is registered */
60 WriteServ(source->fd, "307 %s %s :is a registered nick", source->nick, dest->nick);
64 void Implements(char* List)
66 List[I_OnWhois] = 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, const std::string &oldnick)
71 /* On nickchange, if they have +r, remove it */
72 if (strchr(user->modes,'r'))
75 modechange[0] = user->nick;
78 Srv->SendMode(modechange,2,user);
83 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
88 if (type == MT_CHANNEL)
90 // only a u-lined server may add or remove the +r mode.
91 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
93 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
98 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
99 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
104 if ((kludgeme) || (Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
106 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
111 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
112 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
116 else if (modechar == 'R')
120 else if (modechar == 'M')
122 if (type == MT_CHANNEL)
131 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
133 if (target_type == TYPE_CHANNEL)
135 chanrec* c = (chanrec*)dest;
136 if ((c->IsModeSet('M')) && (!strchr(user->modes,'r')))
138 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
140 // user is ulined, can speak regardless
143 // user messaging a +M channel and is not registered
144 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
148 if (target_type == TYPE_USER)
150 userrec* u = (userrec*)dest;
151 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
153 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
155 // user is ulined, can speak regardless
158 // user messaging a +R user and is not registered
159 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
166 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
168 return OnUserPreMessage(user,dest,target_type,text,status);
171 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
175 if (chan->IsModeSet('R'))
177 if (!strchr(user->modes,'r'))
179 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
181 // user is ulined, won't be stopped from joining
184 // joining a +R channel and not identified
185 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
193 virtual ~ModuleServices()
197 virtual Version GetVersion()
199 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
204 class ModuleServicesFactory : public ModuleFactory
207 ModuleServicesFactory()
211 ~ModuleServicesFactory()
215 virtual Module * CreateModule(Server* Me)
217 return new ModuleServices(Me);
223 extern "C" void * init_module( void )
225 return new ModuleServicesFactory;