From e6d342d89ff25747da9fd45e7f04a861ee4d2e54 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 21 Jul 2023 18:12:46 +0100 Subject: Make the X-line quit message format a lot more flexible. --- src/configreader.cpp | 3 ++- src/modules/m_rline.cpp | 2 +- src/usermanager.cpp | 14 +++----------- src/xline.cpp | 29 +++++++++++++++++------------ 4 files changed, 23 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/configreader.cpp b/src/configreader.cpp index 3a0b70534..7901a6826 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -365,6 +365,7 @@ void ServerConfig::Fill() NoSnoticeStack = options->getBool("nosnoticestack"); SyntaxHints = options->getBool("syntaxhints"); XLineMessage = options->getString("xlinemessage", "You're banned!", 1); + XLineQuit = options->getString("xlinequit", "%type%-lined: %reason%", 1); RestrictBannedUsers = options->getEnum("restrictbannedusers", ServerConfig::BUT_RESTRICT_NOTIFY, { { "no", ServerConfig::BUT_NORMAL }, { "silent", ServerConfig::BUT_RESTRICT_SILENT }, @@ -386,9 +387,9 @@ void ServerConfig::Fill() // Read the config. const auto& security = ConfValue("security"); CustomVersion = security->getString("customversion"); - HideLines = security->getString("hidelines", security->getBool("hidebans") ? "%type%-lined" : ""); HideServer = security->getString("hideserver", {}, InspIRCd::IsFQDN); MaxTargets = security->getNum("maxtargets", 5, 1, 50); + XLineQuitPublic = security->getString("publicxlinequit", security->getBool("hidebans") ? "%type%-lined" : ""); // Read the config. const auto& cidr = ConfValue("cidr"); diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index ecdbbcc34..f303ca64a 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -87,7 +87,7 @@ public: else delete zl; } - DefaultApply(u, "R", false); + DefaultApply(u, false); } const std::string& Displayable() const override diff --git a/src/usermanager.cpp b/src/usermanager.cpp index db8fe0b5c..c7d22bf0d 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -207,17 +207,9 @@ void UserManager::AddUser(int socket, ListenSocket* via, const irc::sockets::soc if (!ServerInstance->Config->XLineMessage.empty()) New->WriteNumeric(ERR_YOUREBANNEDCREEP, ServerInstance->Config->XLineMessage); - if (ServerInstance->Config->HideLines.empty()) - this->QuitUser(New, b->Reason); - else - { - const std::string publicreason = Template::Replace(ServerInstance->Config->HideLines, - { - { "reason", b->Reason }, - { "type", b->Type }, - }); - this->QuitUser(New, publicreason, &b->Reason); - } + // IMPORTANT: we don't check XLineQuitPublic here because the only + // person who might see the ban at this point is the affected user. + this->QuitUser(New, b->Reason); return; } else diff --git a/src/xline.cpp b/src/xline.cpp index 6889665b3..4c1a4e765 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -550,27 +550,32 @@ bool XLine::IsBurstable() return !from_config; } -void XLine::DefaultApply(User* u, const std::string& line, bool bancache) +void XLine::DefaultApply(User* u, bool bancache) { if (!ServerInstance->Config->XLineMessage.empty()) u->WriteNumeric(ERR_YOUREBANNEDCREEP, ServerInstance->Config->XLineMessage); - const std::string banreason = line + "-lined: " + reason; - if (ServerInstance->Config->HideLines.empty()) + Template::VariableMap vars = { + { "duration", Duration::ToString(duration) }, + { "expiry", Time::ToString(expiry) }, + { "reason", reason }, + { "remaining", Duration::ToString(ServerInstance->Time() - expiry) }, + { "setter", source }, + { "type", type }, + }; + + const std::string banreason = Template::Replace(ServerInstance->Config->XLineQuit, vars); + if (ServerInstance->Config->XLineQuitPublic.empty()) ServerInstance->Users.QuitUser(u, banreason); else { - const std::string publicreason = Template::Replace(ServerInstance->Config->HideLines, - { - { "reason", banreason }, - { "type", line }, - }); + const std::string publicreason = Template::Replace(ServerInstance->Config->XLineQuitPublic, vars); ServerInstance->Users.QuitUser(u, publicreason, &banreason); } if (bancache) { - ServerInstance->Logs.Debug("BANCACHE", "Adding positive hit (" + line + ") for " + u->GetAddress()); + ServerInstance->Logs.Debug("BANCACHE", "Adding positive hit (" + type + ") for " + u->GetAddress()); ServerInstance->BanCache.AddHit(u->GetAddress(), this->type, banreason, (this->duration > 0 ? (this->expiry - ServerInstance->Time()) : 0)); } } @@ -595,7 +600,7 @@ bool KLine::Matches(User* u) const void KLine::Apply(User* u) { - DefaultApply(u, "K", this->usermask == "*"); + DefaultApply(u, this->usermask == "*"); } bool GLine::Matches(User* u) const @@ -618,7 +623,7 @@ bool GLine::Matches(User* u) const void GLine::Apply(User* u) { - DefaultApply(u, "G", this->usermask == "*"); + DefaultApply(u, this->usermask == "*"); } bool ELine::Matches(User* u) const @@ -646,7 +651,7 @@ bool ZLine::Matches(User* u) const void ZLine::Apply(User* u) { - DefaultApply(u, "Z", true); + DefaultApply(u, true); } bool QLine::Matches(User* u) const -- cgit v1.3.1-10-gc9f91