From 54d5f7e577db0639e42b18beae4b5c87af6d6843 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Fri, 4 Mar 2011 18:35:17 +0100 Subject: 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 --- src/account-server/storage.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/account-server/storage.cpp') 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 Storage::getAllWorldStateVars(int mapId) +{ + std::map 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) { -- cgit v1.2.3-60-g2f50