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
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 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
69 if (type == MT_CHANNEL)
71 // only a u-lined server may add or remove the +r mode.
72 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
74 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
79 log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
80 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
85 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
87 log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
92 log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
93 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
97 else if (modechar == 'R')
99 if (type == MT_CHANNEL)
104 else if (modechar == 'M')
106 if (type == MT_CHANNEL)
115 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
117 if (target_type == TYPE_CHANNEL)
119 chanrec* c = (chanrec*)dest;
120 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
122 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
124 // user is ulined, can speak regardless
127 // user messaging a +M channel and is not registered
128 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
132 if (target_type == TYPE_USER)
134 userrec* u = (userrec*)dest;
135 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
137 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
139 // user is ulined, can speak regardless
142 // user messaging a +R user and is not registered
143 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
150 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
152 if (target_type == TYPE_CHANNEL)
154 chanrec* c = (chanrec*)dest;
155 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
157 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
159 // user is ulined, can speak regardless
162 // user noticing a +M channel and is not registered
163 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
167 if (target_type == TYPE_USER)
169 userrec* u = (userrec*)dest;
170 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
172 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
174 // user is ulined, can speak regardless
177 // user noticing a +R user and is not registered
178 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
185 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
189 if (chan->IsCustomModeSet('R'))
191 if (!strchr(user->modes,'r'))
193 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
195 // user is ulined, won't be stopped from joining
198 // joining a +R channel and not identified
199 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
207 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(Server* Me)
236 return new ModuleServices(Me);
242 extern "C" void * init_module( void )
244 return new ModuleServicesFactory;