diff options
author | Philipp Sehmisch <mana@crushnet.org> | 2011-03-04 18:35:17 +0100 |
---|---|---|
committer | Philipp Sehmisch <mana@crushnet.org> | 2011-03-04 18:36:17 +0100 |
commit | 54d5f7e577db0639e42b18beae4b5c87af6d6843 (patch) | |
tree | 2a667f208be4191a54d08131d7c3984cdfd74132 /src/account-server/storage.cpp | |
parent | bc5a0495ba7fbf992a1733850cbbe1cfb14c7c8d (diff) | |
download | manaserv-54d5f7e577db0639e42b18beae4b5c87af6d6843.tar.gz manaserv-54d5f7e577db0639e42b18beae4b5c87af6d6843.tar.bz2 manaserv-54d5f7e577db0639e42b18beae4b5c87af6d6843.tar.xz manaserv-54d5f7e577db0639e42b18beae4b5c87af6d6843.zip |
Implemented persistent world and map variables
The gameserver now receive a copy of all world state variables when
they are accepted by the accountserver and receive a copy of all
map state variables of a map when they register it successfully.
Implemented LUA script bindings for getting and setting these variables.
When such a variable is set, the accountserver is notified about this
change. Changes to world state variables are then propagated to all
gameservers by the accountserver.
Be aware that when a gameserver is updating a map, there is no check if
it is actually responsible for said map. But I consider this not a
security flaw, because authenticated game servers are considered to be
trustworthy in a lot of other situations, too.
Also renamed "quest" to "character variable" in the sourcecode.
Reviewed-by: Bertram
Diffstat (limited to 'src/account-server/storage.cpp')
-rw-r--r-- | src/account-server/storage.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 9bc67edb..2326dec6 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -1505,6 +1505,48 @@ std::string Storage::getWorldStateVar(const std::string &name, int mapId) return std::string(); } +std::map<std::string, std::string> Storage::getAllWorldStateVars(int mapId) +{ + std::map<std::string, std::string> variables; + + try + { + std::ostringstream query; + query << "SELECT `state_name`, `value` " + << "FROM " << WORLD_STATES_TBL_NAME; + + // Add map filter if map_id is given + if (mapId >= 0) + query << " WHERE `map_id` = ?"; + + //query << ";"; <-- No ';' at the end of prepared statements. + + if (mDb->prepareSql(query.str())) + { + if (mapId >= 0) + mDb->bindValue(1, mapId); + const dal::RecordSet &results = mDb->processSql(); + + for (unsigned int i = 0; i < results.rows(); i++) + { + variables[results(i, 0)] = results(i, 1); + } + } + else + { + utils::throwError("(DALStorage:getAllWorldStateVar) " + "SQL query preparation failure."); + } + } + catch (const dal::DbSqlQueryExecFailure &e) + { + utils::throwError("(DALStorage::getWorldStateVar) SQL query failure: ", + e); + } + + return variables; +} + void Storage::setWorldStateVar(const std::string &name, const std::string &value) { |