diff options
author | David Athay <ko2fan@gmail.com> | 2008-08-28 15:56:38 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-08-28 15:56:38 +0000 |
commit | 187dfc0418e44d4f20310b297d9d76e4d631ba9f (patch) | |
tree | ff7170046fec17a31709ad0d5cc744d5c39ba219 /src/account-server/dalstorage.cpp | |
parent | 70d580c479c5310c0f7a7efd1a3e7f324cfb99f9 (diff) | |
download | manaserv-187dfc0418e44d4f20310b297d9d76e4d631ba9f.tar.gz manaserv-187dfc0418e44d4f20310b297d9d76e4d631ba9f.tar.bz2 manaserv-187dfc0418e44d4f20310b297d9d76e4d631ba9f.tar.xz manaserv-187dfc0418e44d4f20310b297d9d76e4d631ba9f.zip |
Better SQL query used for expired bans.
Diffstat (limited to 'src/account-server/dalstorage.cpp')
-rw-r--r-- | src/account-server/dalstorage.cpp | 44 |
1 files changed, 5 insertions, 39 deletions
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,54 +1107,20 @@ 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()); } } |