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 d48c84236c)
This commit is contained in:
Iris Morelle 2018-04-20 05:25:12 -03:00
parent 3dc31e66f5
commit 61af81c914

View file

@ -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.");
}
@ -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)) {