From 187dfc0418e44d4f20310b297d9d76e4d631ba9f Mon Sep 17 00:00:00 2001 From: David Athay Date: Thu, 28 Aug 2008 15:56:38 +0000 Subject: Better SQL query used for expired bans. --- src/account-server/dalstorage.cpp | 44 +++++---------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) (limited to 'src/account-server/dalstorage.cpp') diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index 3e3f8990..991acf19 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -1107,53 +1107,19 @@ void DALStorage::banCharacter(int id, int duration) } } -void DALStorage::removeBan(int accountID) +void DALStorage::checkBannedAccounts() { try { + // update expired bans std::ostringstream sql; sql << "update " << ACCOUNTS_TBL_NAME - << " set level = '" << AL_NORMAL << "', banned = '" - << 0 - << "' where id = '" << accountID << "';"; + << " set level = " << AL_NORMAL << ", banned = 0" + << " where level = " << AL_BANNED + << " AND banned <= " << time(NULL) << ";"; mDb->execSql(sql.str()); } catch (dal::DbSqlQueryExecFailure const &e) - { - LOG_ERROR("(DALStorage::removeBan) SQL query failure: " << e.what()); - } -} - -void DALStorage::checkBannedAccounts() -{ - try - { - // get all banned users - std::ostringstream sql; - sql << "select id,banned from " << ACCOUNTS_TBL_NAME - << " where level = '" << AL_BANNED << "';"; - dal::RecordSet const &info = mDb->execSql(sql.str()); - - // loop through all banned users, and see if they have expired - for (int i = 0; i < info.rows(); ++i) - { - int t = time(NULL); - std::stringstream expiry; - expiry << info(i, 1); - int banned; - expiry >> banned; - if (t > banned) - { - // ban has expired, remove it - std::stringstream user; - user << info(i,0); - int id; - user >> id; - removeBan(id); - } - } - } - catch (dal::DbSqlQueryExecFailure const &e) { LOG_ERROR("(DALStorage::checkBannedAccounts) SQL query failure: " << e.what()); } -- cgit v1.2.3-60-g2f50