From 479f6fcbf342e10714178fc6cf2925c8019bd8a7 Mon Sep 17 00:00:00 2001 From: Diamante Date: Sat, 4 May 2024 19:05:02 +0200 Subject: [PATCH] maint: remove links from server names (#87) --- src/services/elimination_handler.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/services/elimination_handler.cpp b/src/services/elimination_handler.cpp index 22c3109..def0d60 100644 --- a/src/services/elimination_handler.cpp +++ b/src/services/elimination_handler.cpp @@ -1,9 +1,20 @@ #include #include "elimination_handler.hpp" -constexpr auto T7_PROTOCOL = 7; +#include -constexpr size_t MAX_SERVERS_PER_GAME = 10; +namespace +{ + constexpr auto T7_PROTOCOL = 7; + + constexpr size_t MAX_SERVERS_PER_GAME = 10; + + std::array bad_names = + { + "http", + "discord.gg", + }; +} void elimination_handler::run_frame() { @@ -40,6 +51,16 @@ void elimination_handler::run_frame() console::log("Removing server '%s' because it exceeds MAX_SERVERS_PER_GAME", context.get_address().to_string().data()); context.remove(); } + + const auto name = utils::string::to_lower(server.name); + for (const auto& entry : bad_names) + { + if (const auto pos = name.find(entry); pos != std::string::npos) + { + console::log("Removing server '%s' (%s) because it contains a bad name", server.name.data(), context.get_address().to_string().data()); + context.remove(); + } + } }); now = std::chrono::high_resolution_clock::now();