diff --git a/src/realmd/AuthSocket.cpp b/src/realmd/AuthSocket.cpp index f1c1027b6..cdbccb19c 100644 --- a/src/realmd/AuthSocket.cpp +++ b/src/realmd/AuthSocket.cpp @@ -379,15 +379,15 @@ bool AuthSocket::_HandleLogonChallenge() ///- Verify that this IP is not in the ip_banned table // No SQL injection possible (paste the IP address as passed by the socket) - loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); - std::string address = GetRemoteAddress(); loginDatabase.escape_string(address); - QueryResult *result = loginDatabase.PQuery( "SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); - if(result) + QueryResult *result = loginDatabase.PQuery("SELECT unbandate FROM ip_banned WHERE " + // permanent still banned + "(unbandate = bandate OR unbandate > UNIX_TIMESTAMP()) AND ip = '%s'", address.c_str()); + if (result) { pkt << (uint8)REALM_AUTH_ACCOUNT_BANNED; - sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!",GetRemoteAddress().c_str ()); + sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!", GetRemoteAddress().c_str()); delete result; } else @@ -422,13 +422,12 @@ bool AuthSocket::_HandleLogonChallenge() if (!locked) { - //set expired bans to inactive - loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); ///- If the account is banned, reject the logon attempt - QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32()); + QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE " + "id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)", (*result)[1].GetUInt32()); if(banresult) { - if((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64()) + if((*banresult)[0].GetUInt64() != (*banresult)[1].GetUInt64()) { pkt << (uint8) REALM_AUTH_ACCOUNT_BANNED; sLog.outBasic("[AuthChallenge] Banned account %s tries to login!",_login.c_str ()); diff --git a/src/realmd/Main.cpp b/src/realmd/Main.cpp index 70f93f431..c25d827d1 100644 --- a/src/realmd/Main.cpp +++ b/src/realmd/Main.cpp @@ -209,6 +209,11 @@ extern int main(int argc, char **argv) return 1; } + // cleanup query + //set expired bans to inactive + loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); + loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); + h.Add(&authListenSocket); ///- Catch termination signals diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 7fa18ce2b..d5fdb2f5f 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8822" + #define REVISION_NR "8823" #endif // __REVISION_NR_H__