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 channel->SetMode('r',adding);
34 return MODEACTION_ALLOW;
38 source->WriteNumeric(500, "%s :Only a server may modify the +r channel mode", source->nick.c_str());
39 return MODEACTION_DENY;
44 /** User mode +r - mark a user as identified
46 class User_r : public ModeHandler
50 User_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_USER, false) { }
52 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
54 if ((kludgeme) || (ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server || (source->nick.find('.') != std::string::npos)))
56 if ((adding && !dest->IsModeSet('r')) || (!adding && dest->IsModeSet('r')))
58 dest->SetMode('r',adding);
59 return MODEACTION_ALLOW;
61 return MODEACTION_DENY;
65 source->WriteNumeric(500, "%s :Only a server may modify the +r user mode", source->nick.c_str());
66 return MODEACTION_DENY;
71 /** Channel mode +R - registered users only
73 class Channel_R : public SimpleChannelModeHandler
76 Channel_R(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'R') { }
79 /** User mode +R - only allow PRIVMSG and NOTICE from registered users
81 class User_R : public SimpleUserModeHandler
84 User_R(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'R') { }
87 /** Channel mode +M - only allow privmsg and notice to channel from registered users
89 class Channel_M : public SimpleChannelModeHandler
92 Channel_M(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'M') { }
95 /** Dreamnforge-like services support
97 class ModuleServices : public Module
106 ModuleServices(InspIRCd* Me)
110 m1 = new Channel_r(ServerInstance);
111 m2 = new Channel_R(ServerInstance);
112 m3 = new Channel_M(ServerInstance);
113 m4 = new User_r(ServerInstance);
114 m5 = new User_R(ServerInstance);
116 if (!ServerInstance->Modes->AddMode(m1) || !ServerInstance->Modes->AddMode(m2) || !ServerInstance->Modes->AddMode(m3)
117 || !ServerInstance->Modes->AddMode(m4) || !ServerInstance->Modes->AddMode(m5))
119 throw ModuleException("Could not add user and channel modes!");
123 Implementation eventlist[] = { I_OnWhois, I_OnUserPostNick, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin };
124 ServerInstance->Modules->Attach(eventlist, this, 5);
127 /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */
128 virtual void OnWhois(User* source, User* dest)
130 if (dest->IsModeSet('r'))
132 /* user is registered */
133 ServerInstance->SendWhoisLine(source, dest, 307, "%s %s :is a registered nick", source->nick.c_str(), dest->nick.c_str());
138 virtual void OnUserPostNick(User* user, const std::string &oldnick)
140 /* On nickchange, if they have +r, remove it */
141 if (user->IsModeSet('r') && assign(user->nick) != oldnick)
143 std::vector<std::string> modechange;
144 modechange.push_back(user->nick);
145 modechange.push_back("-r");
147 ServerInstance->SendMode(modechange,user);
152 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
157 if (target_type == TYPE_CHANNEL)
159 Channel* c = (Channel*)dest;
160 if ((c->IsModeSet('M')) && (!user->IsModeSet('r')))
162 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
164 // user is ulined, can speak regardless
167 // user messaging a +M channel and is not registered
168 user->WriteNumeric(477, "%s %s :You need a registered nickname to speak on this channel", user->nick.c_str(), c->name.c_str());
172 if (target_type == TYPE_USER)
174 User* u = (User*)dest;
175 if ((u->IsModeSet('R')) && (!user->IsModeSet('r')))
177 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
179 // user is ulined, can speak regardless
182 // user messaging a +R user and is not registered
183 user->WriteNumeric(477, "%s %s :You need a registered nickname to message this user", user->nick.c_str(), u->nick.c_str());
190 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
192 return OnUserPreMessage(user,dest,target_type,text,status, exempt_list);
195 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
199 if (chan->IsModeSet('R'))
201 if (!user->IsModeSet('r'))
203 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
205 // user is ulined, won't be stopped from joining
208 // joining a +R channel and not identified
209 user->WriteNumeric(477, "%s %s :You need a registered nickname to join this channel", user->nick.c_str(), chan->name.c_str());
217 virtual ~ModuleServices()
220 ServerInstance->Modes->DelMode(m1);
221 ServerInstance->Modes->DelMode(m2);
222 ServerInstance->Modes->DelMode(m3);
223 ServerInstance->Modes->DelMode(m4);
224 ServerInstance->Modes->DelMode(m5);
232 virtual Version GetVersion()
234 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
239 MODULE_INIT(ModuleServices)