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 + " ";
56 output = temp2.substr(0,temp2.length()-1);
59 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
64 if (type == MT_CHANNEL)
66 // only a u-lined server may add or remove the +r mode.
67 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
73 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
78 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
84 Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r user mode");
88 else if (modechar == 'R')
90 if (type == MT_CHANNEL)
95 else if (modechar == 'M')
97 if (type == MT_CHANNEL)
106 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
108 if (target_type == TYPE_CHANNEL)
110 chanrec* c = (chanrec*)dest;
111 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
113 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
115 // user is ulined, can speak regardless
118 // user messaging a +M channel and is not registered
119 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
123 if (target_type == TYPE_USER)
125 userrec* u = (userrec*)dest;
126 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
128 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
130 // user is ulined, can speak regardless
133 // user messaging a +R user and is not registered
134 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
141 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
143 if (target_type == TYPE_CHANNEL)
145 chanrec* c = (chanrec*)dest;
146 if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
148 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
150 // user is ulined, can speak regardless
153 // user noticing a +M channel and is not registered
154 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
158 if (target_type == TYPE_USER)
160 userrec* u = (userrec*)dest;
161 if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
163 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
165 // user is ulined, can speak regardless
168 // user noticing a +R user and is not registered
169 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
176 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
180 if (chan->IsCustomModeSet('R'))
182 if (!strchr(user->modes,'r'))
184 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
186 // user is ulined, won't be stopped from joining
189 // joining a +R channel and not identified
190 Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel");
198 virtual ~ModuleServices()
203 virtual Version GetVersion()
205 return Version(1,0,0,0);
208 virtual void OnUserConnect(userrec* user)
215 class ModuleServicesFactory : public ModuleFactory
218 ModuleServicesFactory()
222 ~ModuleServicesFactory()
226 virtual Module * CreateModule()
228 return new ModuleServices;
234 extern "C" void * init_module( void )
236 return new ModuleServicesFactory;