2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /* $ModDesc: Forwards a password users can send on connect (for example for NickServ identification). */
24 class ModulePassForward : public Module
26 std::string nickrequired, forwardmsg, forwardcmd;
29 void init() CXX11_OVERRIDE
32 Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
33 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
36 Version GetVersion() CXX11_OVERRIDE
38 return Version("Sends server password to NickServ", VF_VENDOR);
41 void OnRehash(User* user) CXX11_OVERRIDE
43 ConfigTag* tag = ServerInstance->Config->ConfValue("passforward");
44 nickrequired = tag->getString("nick", "NickServ");
45 forwardmsg = tag->getString("forwardmsg", "NOTICE $nick :*** Forwarding PASS to $nickrequired");
46 forwardcmd = tag->getString("cmd", "PRIVMSG $nickrequired :IDENTIFY $pass");
49 void FormatStr(std::string& result, const std::string& format, const LocalUser* user)
51 for (unsigned int i = 0; i < format.length(); i++)
56 if (format.substr(i, 13) == "$nickrequired")
58 result.append(nickrequired);
61 else if (format.substr(i, 5) == "$nick")
63 result.append(user->nick);
66 else if (format.substr(i, 5) == "$user")
68 result.append(user->ident);
71 else if (format.substr(i,5) == "$pass")
73 result.append(user->password);
84 void OnPostConnect(User* ruser) CXX11_OVERRIDE
86 LocalUser* user = IS_LOCAL(ruser);
87 if (!user || user->password.empty())
90 if (!nickrequired.empty())
92 /* Check if nick exists and its server is ulined */
93 User* u = ServerInstance->FindNick(nickrequired);
94 if (!u || !ServerInstance->ULine(u->server))
99 FormatStr(tmp,forwardmsg, user);
100 user->WriteServ(tmp);
103 FormatStr(tmp,forwardcmd, user);
104 ServerInstance->Parser->ProcessBuffer(tmp,user);
108 MODULE_INIT(ModulePassForward)