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 void On005Numeric(std::string &output)
43 std::stringstream line(output);
44 std::string temp1, temp2;
48 if (temp1.substr(0,10) == "CHANMODES=")
50 // append the chanmode to the end
51 temp1 = temp1.substr(10,temp1.length());
52 temp1 = "CHANMODES=" + temp1 + "rRM";
54 temp2 = temp2 + temp1 + " ";
57 output = temp2.substr(0,temp2.length()-1);
60 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
65 if (type == MT_CHANNEL)
67 // only a u-lined server may add or remove the +r mode.
68 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
74 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
79 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
85 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r user mode");
89 else if (modechar == 'R')
91 if (type == MT_CHANNEL)
96 else if (modechar == 'M')
98 if (type == MT_CHANNEL)
107 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
109 if (target_type == TYPE_CHANNEL)
111 chanrec* c = (chanrec*)dest;
112 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
114 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
116 // user is ulined, can speak regardless
119 // user messaging a +M channel and is not registered
120 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
124 if (target_type == TYPE_USER)
126 userrec* u = (userrec*)dest;
127 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
129 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
131 // user is ulined, can speak regardless
134 // user messaging a +R user and is not registered
135 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
142 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
144 if (target_type == TYPE_CHANNEL)
146 chanrec* c = (chanrec*)dest;
147 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
149 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
151 // user is ulined, can speak regardless
154 // user noticing a +M channel and is not registered
155 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
159 if (target_type == TYPE_USER)
161 userrec* u = (userrec*)dest;
162 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
164 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
166 // user is ulined, can speak regardless
169 // user noticing a +R user and is not registered
170 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
177 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
181 if (chan->IsCustomModeSet('R'))
183 if (!strchr(user->modes,'r'))
185 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
187 // user is ulined, won't be stopped from joining
190 // joining a +R channel and not identified
191 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
199 virtual ~ModuleServices()
204 virtual Version GetVersion()
206 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
209 virtual void OnUserConnect(userrec* user)
216 class ModuleServicesFactory : public ModuleFactory
219 ModuleServicesFactory()
223 ~ModuleServicesFactory()
227 virtual Module * CreateModule()
229 return new ModuleServices;
235 extern "C" void * init_module( void )
237 return new ModuleServicesFactory;