Skip to content

Commit

Permalink
wesnothd/fuh: Check IP address bans before everything else
Browse files Browse the repository at this point in the history
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 d48c842)
  • Loading branch information
irydacea committed Oct 7, 2018
1 parent 3dc31e6 commit 61af81c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/server/forum_user_handler.cpp
Expand Up @@ -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<bool>("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.");
}
Expand All @@ -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<bool>("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<std::string>(name, "user_email");

if(!email.empty() && prepared_statement<bool>("SELECT 1 FROM `" + db_banlist_table_ + "` WHERE UPPER(ban_email) = UPPER(?) AND ban_exclude = 0", email)) {
Expand Down

0 comments on commit 61af81c

Please sign in to comment.