From 70d580c479c5310c0f7a7efd1a3e7f324cfb99f9 Mon Sep 17 00:00:00 2001 From: David Athay Date: Thu, 28 Aug 2008 14:46:37 +0000 Subject: Added checking for expired bans. --- src/account-server/dalstorage.cpp | 52 +++++++++++++++++++++++++++++++++++++ src/account-server/dalstorage.hpp | 12 +++++++++ src/account-server/main-account.cpp | 3 +++ 3 files changed, 67 insertions(+) (limited to 'src') diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index cd618a43..3e3f8990 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -1106,3 +1106,55 @@ void DALStorage::banCharacter(int id, int duration) LOG_ERROR("(DALStorage::banAccount) SQL query failure: " << e.what()); } } + +void DALStorage::removeBan(int accountID) +{ + try + { + std::ostringstream sql; + sql << "update " << ACCOUNTS_TBL_NAME + << " set level = '" << AL_NORMAL << "', banned = '" + << 0 + << "' where id = '" << accountID << "';"; + 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()); + } +} diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp index 607b8187..87fd855f 100644 --- a/src/account-server/dalstorage.hpp +++ b/src/account-server/dalstorage.hpp @@ -125,6 +125,18 @@ class DALStorage */ void banCharacter(int id, int duration); + /** + * Removes a ban on an account (hence on all its characters). + * + * @param accountID account identifier. + */ + void removeBan(int accountID); + + /** + * Removes expired bans from accounts + */ + void checkBannedAccounts(); + /** * Tells if the user name already exists. * @return true if the user name exists. diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index 0af42775..5bd8a080 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -308,12 +308,15 @@ int main(int argc, char *argv[]) // Dump statistics every 10 seconds. utils::Timer statTimer(10000); + // Check for expired bans every 30 seconds + utils::Timer banTimer(30000); while (running) { AccountClientHandler::process(); GameServerHandler::process(); chatHandler->process(50); if (statTimer.poll()) dumpStatistics(); + if (banTimer.poll()) storage->checkBannedAccounts(); } LOG_INFO("Received: Quit signal, closing down..."); -- cgit v1.2.3-60-g2f50