aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-06-15 12:56:42 +0100
committerGravatar Sadie Powell2022-06-15 13:00:09 +0100
commit72ecbb328541bebb046d4776245d78656d2234a8 (patch)
treebdc9e3c98a99cdad3f77e5d2363c09370b51421f /src
parentAdd a basic function for templating strings. (diff)
Convert passforward to use the new template system.
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_passforward.cpp53
1 files changed, 11 insertions, 42 deletions
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));
}
};