Make blockcolor only block known formatting codes.

This commit is contained in:
Sadie Powell 2024-08-30 17:00:22 +01:00
parent babb39cb17
commit ca0ea6e3d0

View File

@ -65,16 +65,31 @@ public:
if (!details.IsCTCP(ctcpname, message)) if (!details.IsCTCP(ctcpname, message))
message = details.text; message = details.text;
for (const auto chr : message) auto it = std::find_if(message.begin(), message.end(), [](const char& chr)
{ {
if (static_cast<unsigned char>(chr) < 32) switch (chr)
{ {
if (modeset) case '\x02': // Bold
user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc)); case '\x03': // Color
else case '\x04': // Hex Color
user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", extban)); case '\x1D': // Italic
return MOD_RES_DENY; case '\x11': // Monospace
case '\x16': // Reverse
case '\x1E': // Strikethrough
case '\x1F': // Underline
case '\x0F': // Reset
return true;
} }
return false;
});
if (it != message.end())
{
if (modeset)
user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc));
else
user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", extban));
return MOD_RES_DENY;
} }
} }
} }