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 * ---------------------------------------------------
26 /* $ModDesc: Povides support for services +r user/chan modes and more */
28 class ModuleServices : public Module
36 Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
37 Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
38 Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
39 Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
40 Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
43 virtual void On005Numeric(std::string &output)
45 std::stringstream line(output);
46 std::string temp1, temp2;
50 if (temp1.substr(0,10) == "CHANMODES=")
52 // append the chanmode to the end
53 temp1 = temp1.substr(10,temp1.length());
54 temp1 = "CHANMODES=" + temp1 + "rRM";
56 temp2 = temp2 + temp1 + " ";
59 output = temp2.substr(0,temp2.length()-1);
62 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
67 if (type == MT_CHANNEL)
69 // only a u-lined server may add or remove the +r mode.
70 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
76 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
81 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
87 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r user mode");
91 else if (modechar == 'R')
93 if (type == MT_CHANNEL)
98 else if (modechar == 'M')
100 if (type == MT_CHANNEL)
109 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
111 if (target_type == TYPE_CHANNEL)
113 chanrec* c = (chanrec*)dest;
114 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
116 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
118 // user is ulined, can speak regardless
121 // user messaging a +M channel and is not registered
122 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
126 if (target_type == TYPE_USER)
128 userrec* u = (userrec*)dest;
129 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
131 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
133 // user is ulined, can speak regardless
136 // user messaging a +R user and is not registered
137 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
144 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
146 if (target_type == TYPE_CHANNEL)
148 chanrec* c = (chanrec*)dest;
149 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
151 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
153 // user is ulined, can speak regardless
156 // user noticing a +M channel and is not registered
157 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
161 if (target_type == TYPE_USER)
163 userrec* u = (userrec*)dest;
164 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
166 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
168 // user is ulined, can speak regardless
171 // user noticing a +R user and is not registered
172 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
179 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
183 if (chan->IsCustomModeSet('R'))
185 if (!strchr(user->modes,'r'))
187 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
189 // user is ulined, won't be stopped from joining
192 // joining a +R channel and not identified
193 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
201 virtual ~ModuleServices()
206 virtual Version GetVersion()
208 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
211 virtual void OnUserConnect(userrec* user)
218 class ModuleServicesFactory : public ModuleFactory
221 ModuleServicesFactory()
225 ~ModuleServicesFactory()
229 virtual Module * CreateModule()
231 return new ModuleServices;
237 extern "C" void * init_module( void )
239 return new ModuleServicesFactory;