summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-08-28 14:46:37 +0000
committerDavid Athay <ko2fan@gmail.com>2008-08-28 14:46:37 +0000
commit70d580c479c5310c0f7a7efd1a3e7f324cfb99f9 (patch)
treeda31ea41744ae5e86d24a372ba067214e6908dbd /src
parent9f982fe1a4728dbbcbd5089f6d4b6c4e08414b6a (diff)
downloadmanaserv-70d580c479c5310c0f7a7efd1a3e7f324cfb99f9.tar.gz
manaserv-70d580c479c5310c0f7a7efd1a3e7f324cfb99f9.tar.bz2
manaserv-70d580c479c5310c0f7a7efd1a3e7f324cfb99f9.tar.xz
manaserv-70d580c479c5310c0f7a7efd1a3e7f324cfb99f9.zip
Added checking for expired bans.
Diffstat (limited to 'src')
-rw-r--r--src/account-server/dalstorage.cpp52
-rw-r--r--src/account-server/dalstorage.hpp12
-rw-r--r--src/account-server/main-account.cpp3
3 files changed, 67 insertions, 0 deletions
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
@@ -126,6 +126,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...");