From 72ecbb328541bebb046d4776245d78656d2234a8 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 15 Jun 2022 12:56:42 +0100 Subject: Convert passforward to use the new template system. --- docs/conf/modules.conf.example | 12 +++++----- src/modules/m_passforward.cpp | 53 +++++++++--------------------------------- 2 files changed, 17 insertions(+), 48 deletions(-) diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index d040739be..ab8a51cd2 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -1647,14 +1647,14 @@ # forwardmsg: Message to send to users when forwarding their # password. You can use the following variables in this message: # - # $nick The nickname of the authenticating user. - # $nickrequired The nickname of the service to forward to (see above). - # $pass The password to forward to services. - # $user The username (ident) of the authenticating user. - forwardmsg="NOTICE $nick :*** Forwarding password to $nickrequired" + # %nick% The nickname of the authenticating user. + # %nickrequired% The nickname of the service to forward to (see above). + # %pass% The password to forward to services. + # %user% The username (ident) of the authenticating user. + forwardmsg="NOTICE %nick% :*** Forwarding password to %nickrequired%" # cmd: The message to send to forward passwords to services. - cmd="SQUERY $nickrequired :IDENTIFY $nick $pass"> + cmd="SQUERY %nickrequired% :IDENTIFY %nick% %pass%"> #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Password hash module: Allows hashed passwords to be used. diff --git a/src/modules/m_passforward.cpp b/src/modules/m_passforward.cpp index f9046032c..c6e4ecfd6 100644 --- a/src/modules/m_passforward.cpp +++ b/src/modules/m_passforward.cpp @@ -44,43 +44,18 @@ public: { auto tag = ServerInstance->Config->ConfValue("passforward"); nickrequired = tag->getString("nick", "NickServ"); - forwardmsg = tag->getString("forwardmsg", "NOTICE $nick :*** Forwarding password to $nickrequired"); - forwardcmd = tag->getString("cmd", "SQUERY $nickrequired :IDENTIFY $nick $pass", 1); + forwardmsg = tag->getString("forwardmsg", "NOTICE %nick% :*** Forwarding password to %nickrequired%"); + forwardcmd = tag->getString("cmd", "SQUERY %nickrequired% :IDENTIFY %nick% %pass%", 1); } - void FormatStr(const LocalUser* user, const std::string& format, const std::string& pass, std::string& result) + std::string FormatStr(const LocalUser* user, const std::string& format, const std::string& pass) { - for (unsigned int i = 0; i < format.length(); i++) - { - char c = format[i]; - if (c == '$') - { - if (!format.compare(i, 13, "$nickrequired", 13)) - { - result.append(nickrequired); - i += 12; - } - else if (!format.compare(i, 5, "$nick", 5)) - { - result.append(user->nick); - i += 4; - } - else if (!format.compare(i, 5, "$user", 5)) - { - result.append(user->ident); - i += 4; - } - else if (!format.compare(i, 5, "$pass", 5)) - { - result.append(pass); - i += 4; - } - else - result.push_back(c); - } - else - result.push_back(c); - } + return Template::Replace(format, { + { "nick", user->nick, }, + { "nickrequired", nickrequired, }, + { "pass", pass, }, + { "user", user->ident, }, + }); } void OnPostConnect(User* ruser) override @@ -118,16 +93,10 @@ public: return; } - std::string tmp; if (!forwardmsg.empty()) - { - FormatStr(user, forwardmsg, pass, tmp); - ServerInstance->Parser.ProcessBuffer(user, tmp); - tmp.clear(); - } + ServerInstance->Parser.ProcessBuffer(user, FormatStr(user, forwardmsg, pass)); - FormatStr(user, forwardcmd, pass, tmp); - ServerInstance->Parser.ProcessBuffer(user, tmp); + ServerInstance->Parser.ProcessBuffer(user, FormatStr(user, forwardcmd, pass)); } }; -- cgit v1.3.1-10-gc9f91