1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Povides support for ircu-style services accounts, including chmode +R, etc. */
19 /** Channel mode +r - mark a channel as identified
21 class Channel_r : public ModeHandler
24 Channel_r(Module* Creator) : ModeHandler(Creator, "c_registered", 'r', PARAM_NONE, MODETYPE_CHANNEL) { }
26 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
28 // only a u-lined server may add or remove the +r mode.
29 if (!IS_LOCAL(source) || ServerInstance->ULine(source->nick.c_str()) || ServerInstance->ULine(source->server))
31 // Only change the mode if it's not redundant
32 if ((adding && !channel->IsModeSet('r')) || (!adding && channel->IsModeSet('r')))
34 channel->SetMode('r',adding);
35 return MODEACTION_ALLOW;
38 return MODEACTION_DENY;
42 source->WriteNumeric(500, "%s :Only a server may modify the +r channel mode", source->nick.c_str());
43 return MODEACTION_DENY;
48 /** User mode +r - mark a user as identified
50 class User_r : public ModeHandler
54 User_r(Module* Creator) : ModeHandler(Creator, "u_registered", 'r', PARAM_NONE, MODETYPE_USER) { }
56 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
58 if (!IS_LOCAL(source) || ServerInstance->ULine(source->nick.c_str()) || ServerInstance->ULine(source->server))
60 if ((adding && !dest->IsModeSet('r')) || (!adding && dest->IsModeSet('r')))
62 dest->SetMode('r',adding);
63 return MODEACTION_ALLOW;
65 return MODEACTION_DENY;
69 source->WriteNumeric(500, "%s :Only a server may modify the +r user mode", source->nick.c_str());
70 return MODEACTION_DENY;
75 /** Channel mode +R - unidentified users cannot join
77 class AChannel_R : public SimpleChannelModeHandler
80 AChannel_R(Module* Creator) : SimpleChannelModeHandler(Creator, "reginvite", 'R') { }
83 /** User mode +R - unidentified users cannot message
85 class AUser_R : public SimpleUserModeHandler
88 AUser_R(Module* Creator) : SimpleUserModeHandler(Creator, "regdeaf", 'R') { }
91 /** Channel mode +M - unidentified users cannot message channel
93 class AChannel_M : public SimpleChannelModeHandler
96 AChannel_M(Module* Creator) : SimpleChannelModeHandler(Creator, "regmoderated", 'M') { }
99 class ModuleServicesAccount : public Module
106 AccountExtItem accountname;
108 ModuleServicesAccount() : m1(this), m2(this), m3(this), m4(this), m5(this),
109 accountname("accountname", this)
115 ServerInstance->Modules->AddService(m1);
116 ServerInstance->Modules->AddService(m2);
117 ServerInstance->Modules->AddService(m3);
118 ServerInstance->Modules->AddService(m4);
119 ServerInstance->Modules->AddService(m5);
120 ServerInstance->Modules->AddService(accountname);
121 Implementation eventlist[] = { I_OnWhois, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin, I_OnCheckBan,
122 I_OnDecodeMetaData, I_On005Numeric, I_OnUserPostNick, I_OnSetConnectClass };
124 ServerInstance->Modules->Attach(eventlist, this, 9);
127 void On005Numeric(std::string &t)
129 ServerInstance->AddExtBanChar('R');
132 /* <- :twisted.oscnet.org 330 w00t2 w00t2 w00t :is logged in as */
133 void OnWhois(User* source, User* dest)
135 std::string *account = accountname.get(dest);
139 ServerInstance->SendWhoisLine(source, dest, 330, "%s %s %s :is logged in as", source->nick.c_str(), dest->nick.c_str(), account->c_str());
142 if (dest->IsModeSet('r'))
144 /* user is registered */
145 ServerInstance->SendWhoisLine(source, dest, 307, "%s %s :is a registered nick", source->nick.c_str(), dest->nick.c_str());
149 void OnUserPostNick(User* user, const std::string &oldnick)
151 /* On nickchange, if they have +r, remove it */
152 if (user->IsModeSet('r') && assign(user->nick) != oldnick)
154 std::vector<std::string> modechange;
155 modechange.push_back(user->nick);
156 modechange.push_back("-r");
157 ServerInstance->SendMode(modechange, ServerInstance->FakeClient);
161 ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
164 return MOD_RES_PASSTHRU;
166 std::string *account = accountname.get(user);
167 bool is_registered = account && !account->empty();
169 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
171 // user is ulined, can speak regardless
172 return MOD_RES_PASSTHRU;
175 if (target_type == TYPE_CHANNEL)
177 Channel* c = (Channel*)dest;
178 ModResult res = ServerInstance->OnCheckExemption(user,c,"regmoderated");
180 if (c->IsModeSet('M') && !is_registered && res != MOD_RES_ALLOW)
182 // user messaging a +M channel and is not registered
183 user->WriteNumeric(477, ""+std::string(user->nick)+" "+std::string(c->name)+" :You need to be identified to a registered account to message this channel");
187 else if (target_type == TYPE_USER)
189 User* u = (User*)dest;
191 if (u->IsModeSet('R') && !is_registered)
193 // user messaging a +R user and is not registered
194 user->WriteNumeric(477, ""+ user->nick +" "+ u->nick +" :You need to be identified to a registered account to message this user");
198 return MOD_RES_PASSTHRU;
201 ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask)
203 if (mask[0] == 'R' && mask[1] == ':')
205 std::string *account = accountname.get(user);
206 if (account && InspIRCd::Match(*account, mask.substr(2)))
209 return MOD_RES_PASSTHRU;
212 ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
214 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
217 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
220 return MOD_RES_PASSTHRU;
222 std::string *account = accountname.get(user);
223 bool is_registered = account && !account->empty();
227 if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server)))
229 // user is ulined, won't be stopped from joining
230 return MOD_RES_PASSTHRU;
233 if (chan->IsModeSet('R'))
237 // joining a +R channel and not identified
238 user->WriteNumeric(477, user->nick + " " + chan->name + " :You need to be identified to a registered account to join this channel");
243 return MOD_RES_PASSTHRU;
246 // Whenever the linking module receives metadata from another server and doesnt know what
247 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
248 // module in turn to figure out if this metadata key belongs to them, and what they want
250 // In our case we're only sending a single string around, so we just construct a std::string.
251 // Some modules will probably get much more complex and format more detailed structs and classes
252 // in a textual way for sending over the link.
253 void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
255 User* dest = dynamic_cast<User*>(target);
256 // check if its our metadata key, and its associated with a user
257 if (dest && (extname == "accountname"))
259 std::string *account = accountname.get(dest);
260 if (account && !account->empty())
265 dest->WriteNumeric(900, "%s %s %s :You are now logged in as %s",
266 dest->nick.c_str(), dest->GetFullHost().c_str(), account->c_str(), account->c_str());
268 AccountEvent(this, dest, *account).Send();
273 ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
275 if (myclass->config->getBool("requireaccount") && !accountname.get(user))
277 return MOD_RES_PASSTHRU;
282 return Version("Povides support for ircu-style services accounts, including chmode +R, etc.",VF_OPTCOMMON|VF_VENDOR);
286 MODULE_INIT(ModuleServicesAccount)