diff options
author | Andreas Habel <mail@exceptionfault.de> | 2008-09-15 10:43:11 +0000 |
---|---|---|
committer | Andreas Habel <mail@exceptionfault.de> | 2008-09-15 10:43:11 +0000 |
commit | a613c53609185c436dcdca7eae3221b792ad523d (patch) | |
tree | 8a367e8663fa96c955914f3179e80a80e4523be7 /src/account-server/dalstorage.cpp | |
parent | bfc0c10184442fba0b53e0aaafcf2532610e5cd7 (diff) | |
download | manaserv-a613c53609185c436dcdca7eae3221b792ad523d.tar.gz manaserv-a613c53609185c436dcdca7eae3221b792ad523d.tar.bz2 manaserv-a613c53609185c436dcdca7eae3221b792ad523d.tar.xz manaserv-a613c53609185c436dcdca7eae3221b792ad523d.zip |
* Added doxygen file, docu will be generated under docs/api/html
* Added table definition "tmw_world_states" to store map and world-specific variables
* Extended DALStorage to set and get those new variables
* Applied Kess's diff file from mantis #424 with modifications for PostgreSQL support
Diffstat (limited to 'src/account-server/dalstorage.cpp')
-rw-r--r-- | src/account-server/dalstorage.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index 26f99a12..601c0bb6 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -130,6 +130,8 @@ void DALStorage::open() createTable(GUILDS_TBL_NAME, SQL_GUILDS_TABLE); createTable(GUILD_MEMBERS_TBL_NAME, SQL_GUILD_MEMBERS_TABLE); createTable(QUESTS_TBL_NAME, SQL_QUESTS_TABLE); + createTable(WORLD_STATES_TBL_NAME, SQL_WORLD_STATES_TABLE); + // TODO: this is not the prefered way, but currently the complete // generation and maintenance of the database is a little dirty so @@ -1122,6 +1124,84 @@ std::string DALStorage::getQuestVar(int id, std::string const &name) return std::string(); } +std::string DALStorage::getWorldStateVar(std::string const &name) +{ + return getWorldStateVar(name, -1); +} + +std::string DALStorage::getWorldStateVar(std::string const &name, int map_id) +{ + try + { + std::ostringstream query; + query << "SELECT value " + << " FROM " << WORLD_STATES_TBL_NAME + << " WHERE state_name = '" << name << "'"; + + // add map filter if map_id is given + if (map_id >= 0) + { + query << " AND map_id = '" << map_id << "'"; + } + + query << ";"; + dal::RecordSet const &info = mDb->execSql(query.str()); + + if (!info.isEmpty()) return info(0, 0); + } + catch (dal::DbSqlQueryExecFailure const &e) + { + LOG_ERROR("(DALStorage::getWorldStateVar) SQL query failure: " << e.what()); + } + + return std::string(); +} + +void DALStorage::setWorldStateVar(std::string const &name, std::string const &value) +{ + return setWorldStateVar(name, -1, value); +} + +void DALStorage::setWorldStateVar(std::string const &name, + int map_id, + std::string const &value) +{ + try + { + std::ostringstream query1; + query1 << "DELETE FROM " << WORLD_STATES_TBL_NAME + << " WHERE state_name = '" << name << "'"; + if (map_id >= 0) + { + query1 << " AND map_id = '" << map_id << "'"; + } + query1 << ";"; + mDb->execSql(query1.str()); + + if (value.empty()) return; + + std::ostringstream query2; + query2 << "INSERT INTO " << WORLD_STATES_TBL_NAME + << " (state_name, map_id, value , moddate) VALUES (" + << "'" << name << "', "; + if (map_id >= 0) + { + query2 << "'" << map_id << "', "; + } + else + { + query2 << "NULL , "; + } + query2 << "'" << value << "', " + << "'" << time(NULL) << "');"; + mDb->execSql(query2.str()); + } + catch (dal::DbSqlQueryExecFailure const &e) + { + LOG_ERROR("(DALStorage::setWorldStateVar) SQL query failure: " << e.what()); + } +} + void DALStorage::setQuestVar(int id, std::string const &name, std::string const &value) { |