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/serverhandler.cpp | |
parent | bc5a0495ba7fbf992a1733850cbbe1cfb14c7c8d (diff) | |
download | manaserv-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/account-server/serverhandler.cpp')
-rw-r--r-- | src/account-server/serverhandler.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 1fd574c..dd6a82e 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -204,6 +204,17 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { outMsg.writeInt16(PASSWORD_OK); comp->send(outMsg); + + // transmit global world state variables + std::map<std::string, std::string> variables; + variables = storage->getAllWorldStateVars(0); + for (std::map<std::string, std::string>::iterator i = variables.begin(); + i != variables.end(); + i++) + { + outMsg.writeString(i->first); + outMsg.writeString(i->second); + } } else { @@ -230,6 +241,15 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { MessageOut outMsg(AGMSG_ACTIVE_MAP); outMsg.writeInt16(id); + std::map<std::string, std::string> variables; + variables = storage->getAllWorldStateVars(id); + for (std::map<std::string, std::string>::iterator i = variables.begin(); + i != variables.end(); + i++) + { + outMsg.writeString(i->first); + outMsg.writeString(i->second); + } comp->send(outMsg); MapStatistics &m = server->maps[id]; m.nbThings = 0; @@ -315,18 +335,18 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) } } break; - case GAMSG_GET_QUEST: + case GAMSG_GET_VAR_CHR: { int id = msg.readInt32(); std::string name = msg.readString(); std::string value = storage->getQuestVar(id, name); - result.writeInt16(AGMSG_GET_QUEST_RESPONSE); + result.writeInt16(AGMSG_GET_VAR_CHR_RESPONSE); result.writeInt32(id); result.writeString(name); result.writeString(value); } break; - case GAMSG_SET_QUEST: + case GAMSG_SET_VAR_CHR: { int id = msg.readInt32(); std::string name = msg.readString(); @@ -334,6 +354,32 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) storage->setQuestVar(id, name, value); } break; + case GAMSG_SET_VAR_WORLD: + { + std::string name = msg.readString(); + std::string value = msg.readString(); + // save the new value to the database + storage->setWorldStateVar(name, value); + // relay the new value to all gameservers + for (ServerHandler::NetComputers::iterator i = clients.begin(); + i != clients.end(); + i++) + { + MessageOut varUpdateMessage(AGMSG_SET_VAR_WORLD); + varUpdateMessage.writeString(name); + varUpdateMessage.writeString(value); + (*i)->send(varUpdateMessage); + } + } break; + + case GAMSG_SET_VAR_MAP: + { + int mapid = msg.readInt32(); + std::string name = msg.readString(); + std::string value = msg.readString(); + storage->setWorldStateVar(name, mapid, value); + } break; + case GAMSG_BAN_PLAYER: { int id = msg.readInt32(); |