summaryrefslogtreecommitdiffstats
path: root/src/game-server/state.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2011-03-04 18:35:17 +0100
committerPhilipp Sehmisch <mana@crushnet.org>2011-03-04 18:36:17 +0100
commit54d5f7e577db0639e42b18beae4b5c87af6d6843 (patch)
tree2a667f208be4191a54d08131d7c3984cdfd74132 /src/game-server/state.cpp
parentbc5a0495ba7fbf992a1733850cbbe1cfb14c7c8d (diff)
downloadmanaserv-54d5f7e577db0639e42b18beae4b5c87af6d6843.tar.gz
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/game-server/state.cpp')
-rw-r--r--src/game-server/state.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index abfa234..642d5db 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -65,6 +65,12 @@ typedef std::map< Actor *, DelayedEvent > DelayedEvents;
static DelayedEvents delayedEvents;
/**
+ * Cached persistent script variables
+ */
+static std::map< std::string, std::string > mScriptVariables;
+
+
+/**
* Updates object states on the map.
*/
static void updateMap(MapComposite *map)
@@ -809,3 +815,26 @@ void GameState::sayToAll(const std::string &text)
// Sends it to everyone connected to the game server
gameHandler->sendToEveryone(msg);
}
+
+
+std::string GameState::getVariable(const std::string &key)
+{
+ std::map<std::string, std::string>::iterator iValue = mScriptVariables.find(key);
+ if (iValue != mScriptVariables.end())
+ {
+ return iValue->second;
+ } else {
+ return std::string();
+ }
+}
+
+void GameState::setVariable(const std::string &key, const std::string &value)
+{
+ mScriptVariables[key] = value;
+ accountHandler->updateWorldVar(key, value);
+}
+
+void GameState::setVariableFromDbserver(const std::string &key, const std::string &value)
+{
+ mScriptVariables[key] = value ;
+}