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
27 std::string nickrequired, forwardmsg, forwardcmd;
33 Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
34 ServerInstance->Modules->Attach(eventlist, this, 2);
39 return Version("Sends server password to NickServ", VF_VENDOR);
42 void OnRehash(User* user)
45 nickrequired = Conf.ReadValue("passforward", "nick", "NickServ", 0);
46 forwardmsg = Conf.ReadValue("passforward", "forwardmsg", "NOTICE $nick :*** Forwarding PASS to $nickrequired", 0);
47 forwardcmd = Conf.ReadValue("passforward", "cmd", "PRIVMSG $nickrequired :IDENTIFY $pass", 0);
50 void FormatStr(std::string& result, const std::string& format, const LocalUser* user)
52 for (unsigned int i = 0; i < format.length(); i++)
57 if (format.substr(i, 13) == "$nickrequired")
59 result.append(nickrequired);
62 else if (format.substr(i, 5) == "$nick")
64 result.append(user->nick);
67 else if (format.substr(i, 5) == "$user")
69 result.append(user->ident);
72 else if (format.substr(i,5) == "$pass")
74 result.append(user->password);
85 virtual void OnPostConnect(User* ruser)
87 LocalUser* user = IS_LOCAL(ruser);
88 if (!user || user->password.empty())
91 if (!nickrequired.empty())
93 /* Check if nick exists and its server is ulined */
94 User* u = ServerInstance->FindNick(nickrequired.c_str());
95 if (!u || !ServerInstance->ULine(u->server))
100 FormatStr(tmp,forwardmsg, user);
101 user->WriteServ(tmp);
104 FormatStr(tmp,forwardcmd, user);
105 ServerInstance->Parser->ProcessBuffer(tmp,user);
109 MODULE_INIT(ModulePassForward)