summaryrefslogtreecommitdiff
path: root/src/account-server/dalstorage.cpp
diff options
context:
space:
mode:
authorAndreas Habel <mail@exceptionfault.de>2008-12-01 18:27:14 +0100
committerAndreas Habel <mail@exceptionfault.de>2008-12-01 18:27:14 +0100
commitb3d6d3889390843374fe0b9184dd77c5fcb84e8b (patch)
tree1601f16d933b8c77b2021b44d659de5a23fd8f3f /src/account-server/dalstorage.cpp
parent82b412fa1d77c50689327d949029ff7f5d45fb6b (diff)
downloadmanaserv-b3d6d3889390843374fe0b9184dd77c5fcb84e8b.tar.gz
manaserv-b3d6d3889390843374fe0b9184dd77c5fcb84e8b.tar.bz2
manaserv-b3d6d3889390843374fe0b9184dd77c5fcb84e8b.tar.xz
manaserv-b3d6d3889390843374fe0b9184dd77c5fcb84e8b.zip
Added new table to store online users. See mantis #553
This upgrade will be the first, we provide database installation scripts and update scripts to upgrade from the previous version. For more details about database upgrades see http://wiki.themanaworld.org/index.php/Upgrade_Database and feel free to comment.
Diffstat (limited to 'src/account-server/dalstorage.cpp')
-rw-r--r--src/account-server/dalstorage.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index 20815a7d..6547d84a 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -41,7 +41,7 @@
// defines the supported db version
#define DB_VERSION_PARAMETER "database_version"
-#define SUPPORTED_DB_VERSION "1"
+#define SUPPORTED_DB_VERSION "2"
/**
@@ -95,6 +95,11 @@ void DALStorage::open()
// synchronize base data from xml files
SyncDatabase();
+
+ // clean list of online users, this should be empty after restart
+ std::ostringstream sql;
+ sql << "DELETE FROM " << ONLINE_USERS_TBL_NAME;
+ mDb->execSql(sql.str());
}
catch (const DbConnectionFailure& e) {
std::ostringstream errmsg;
@@ -1585,3 +1590,40 @@ void DALStorage::SyncDatabase(void)
mDb->commitTransaction();
xmlFreeDoc(doc);
}
+
+void DALStorage::setOnlineStatus(int charId, bool online)
+{
+ try
+ {
+ std::ostringstream sql;
+ if (online)
+ {
+ // first we try to update the online status. this prevents errors
+ // in case we get the online status twice
+ sql << "SELECT COUNT(*) FROM " << ONLINE_USERS_TBL_NAME
+ << " WHERE char_id = " << charId;
+ const std::string res = mDb->execSql(sql.str())(0, 0);
+
+ if (res != "0")
+ return;
+
+ sql.clear();
+ sql.str("");
+ sql << "INSERT INTO " << ONLINE_USERS_TBL_NAME
+ << " VALUES (" << charId << ", " << time(NULL) << ")";
+ mDb->execSql(sql.str());
+ }
+ else
+ {
+ sql << "DELETE FROM " << ONLINE_USERS_TBL_NAME
+ << " WHERE char_id = " << charId;
+ mDb->execSql(sql.str());
+ }
+
+
+ }
+ catch (dal::DbSqlQueryExecFailure const &e)
+ {
+ LOG_ERROR("(DALStorage::setOnlineStatus) SQL query failure: " << e.what());
+ }
+}