From 61af81c91480a4d09613a270ec907e43064d115a Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Fri, 20 Apr 2018 05:25:12 -0300 Subject: [PATCH] wesnothd/fuh: Check IP address bans before everything else There isn't much point in doing more expensive ban look ups first. (Also, yes, I am aware that as it is there's still two SELECT queries that could be coalesced into a single one -- namely, the ones for the user_email and user_id columns.) (cherry-picked from commit d48c84236c17adca9421fe15d0d0666f1c2b96cb) --- src/server/forum_user_handler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/forum_user_handler.cpp b/src/server/forum_user_handler.cpp index 446138b25786..43ad2cb66767 100644 --- a/src/server/forum_user_handler.cpp +++ b/src/server/forum_user_handler.cpp @@ -174,6 +174,11 @@ void fuh::set_is_moderator(const std::string& name, const bool& is_moderator) { fuh::BAN_TYPE fuh::user_is_banned(const std::string& name, const std::string& addr) { + if(!addr.empty() && prepared_statement("SELECT 1 FROM `" + db_banlist_table_ + "` WHERE UPPER(ban_ip) = UPPER(?) AND ban_exclude = 0", addr)) { + LOG_UH << "User '" << name << "' ip " << addr << " banned by IP address\n"; + return BAN_IP; + } + if(!user_exists(name)) { throw error("No user with the name '" + name + "' exists."); } @@ -188,11 +193,6 @@ fuh::BAN_TYPE fuh::user_is_banned(const std::string& name, const std::string& ad return BAN_USER; } - if(!addr.empty() && prepared_statement("SELECT 1 FROM `" + db_banlist_table_ + "` WHERE UPPER(ban_ip) = UPPER(?) AND ban_exclude = 0", addr)) { - LOG_UH << "User '" << name << "' ip " << addr << " banned by IP address\n"; - return BAN_IP; - } - auto email = get_detail_for_user(name, "user_email"); if(!email.empty() && prepared_statement("SELECT 1 FROM `" + db_banlist_table_ + "` WHERE UPPER(ban_email) = UPPER(?) AND ban_exclude = 0", email)) {