1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 static bool kludgeme = false;
18 /* $ModDesc: Povides support for services +r user/chan modes and more */
20 /** Channel mode +r - mark a channel as identified
22 class Channel_r : public ModeHandler
26 Channel_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_CHANNEL, false) { }
28 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
30 // only a u-lined server may add or remove the +r mode.
31 if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server || (source->nick.find('.') != std::string::npos)))
33 // Only change the mode if it's not redundant
34 if ((adding && !channel->IsModeSet('r')) || (!adding && channel->IsModeSet('r')))
36 channel->SetMode('r',adding);
37 return MODEACTION_ALLOW;
40 return MODEACTION_DENY;
44 source->WriteNumeric(500, "%s :Only a server may modify the +r channel mode", source->nick.c_str());
45 return MODEACTION_DENY;
50 /** User mode +r - mark a user as identified
52 class User_r : public ModeHandler
56 User_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_USER, false) { }
58 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
60 if ((kludgeme) || (ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server || (source->nick.find('.') != std::string::npos)))
62 if ((adding && !dest->IsModeSet('r')) || (!adding && dest->IsModeSet('r')))
64 dest->SetMode('r',adding);
65 return MODEACTION_ALLOW;
67 return MODEACTION_DENY;
71 source->WriteNumeric(500, "%s :Only a server may modify the +r user mode", source->nick.c_str());
72 return MODEACTION_DENY;
77 /** Channel mode +R - registered users only
79 class Channel_R : public SimpleChannelModeHandler
82 Channel_R(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'R') { }
85 /** User mode +R - only allow PRIVMSG and NOTICE from registered users
87 class User_R : public SimpleUserModeHandler
90 User_R(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'R') { }
93 /** Channel mode +M - only allow privmsg and notice to channel from registered users
95 class Channel_M : public SimpleChannelModeHandler
98 Channel_M(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'M') { }
101 /** Dreamnforge-like services support
103 class ModuleServices : public Module
112 ModuleServices(InspIRCd* Me)
116 m1 = new Channel_r(ServerInstance);
117 m2 = new Channel_R(ServerInstance);
118 m3 = new Channel_M(ServerInstance);
119 m4 = new User_r(ServerInstance);
120 m5 = new User_R(ServerInstance);
122 if (!ServerInstance->Modes->AddMode(m1) || !ServerInstance->Modes->AddMode(m2) || !ServerInstance->Modes->AddMode(m3)
123 || !ServerInstance->Modes->AddMode(m4) || !ServerInstance->Modes->AddMode(m5))
125 throw ModuleException("You cannot load m_services.so and m_services_account.so at the same time (or some other module has claimed our modes)!");
129 Implementation eventlist[] = { I_OnWhois, I_OnUserPostNick, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin };
130 ServerInstance->Modules->Attach(eventlist, this, 5);
133 /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */
134 virtual void OnWhois(User* source, User* dest)
136 if (dest->IsModeSet('r'))
138 /* user is registered */
139 ServerInstance->SendWhoisLine(source, dest, 307, "%s %s :is a registered nick", source->nick.c_str(), dest->nick.c_str());
144 virtual void OnUserPostNick(User* user, const std::string &oldnick)
146 /* On nickchange, if they have +r, remove it */
147 if (user->IsModeSet('r') && assign(user->nick) != oldnick)
149 std::vector<std::string> modechange;
150 modechange.push_back(user->nick);
151 modechange.push_back("-r");
153 ServerInstance->SendMode(modechange,user);
158 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
163 if (target_type == TYPE_CHANNEL)
165 Channel* c = (Channel*)dest;
166 if ((c->IsModeSet('M')) && (!user->IsModeSet('r')))
168 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
170 // user is ulined, can speak regardless
173 // user messaging a +M channel and is not registered
174 user->WriteNumeric(477, "%s %s :You need a registered nickname to speak on this channel", user->nick.c_str(), c->name.c_str());
178 if (target_type == TYPE_USER)
180 User* u = (User*)dest;
181 if ((u->IsModeSet('R')) && (!user->IsModeSet('r')))
183 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
185 // user is ulined, can speak regardless
188 // user messaging a +R user and is not registered
189 user->WriteNumeric(477, "%s %s :You need a registered nickname to message this user", user->nick.c_str(), u->nick.c_str());
196 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
198 return OnUserPreMessage(user,dest,target_type,text,status, exempt_list);
201 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
205 if (chan->IsModeSet('R'))
207 if (!user->IsModeSet('r'))
209 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
211 // user is ulined, won't be stopped from joining
214 // joining a +R channel and not identified
215 user->WriteNumeric(477, "%s %s :You need a registered nickname to join this channel", user->nick.c_str(), chan->name.c_str());
223 virtual ~ModuleServices()
226 ServerInstance->Modes->DelMode(m1);
227 ServerInstance->Modes->DelMode(m2);
228 ServerInstance->Modes->DelMode(m3);
229 ServerInstance->Modes->DelMode(m4);
230 ServerInstance->Modes->DelMode(m5);
238 virtual Version GetVersion()
240 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
245 MODULE_INIT(ModuleServices)