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/serverhandler.cpp | 52 +++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'src/account-server/serverhandler.cpp') 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 variables; + variables = storage->getAllWorldStateVars(0); + for (std::map::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 variables; + variables = storage->getAllWorldStateVars(id); + for (std::map::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(); -- cgit