diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-30 18:41:04 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-30 18:41:04 +0000 |
commit | 7f1c499e4e09ab939d6d31188aaaaf785250a1d5 (patch) | |
tree | 0d57377da58cf9817b0261130e0812870c0da1f1 | |
parent | af8b15193ebaed1de77a8a77ec2a0fed75a0d253 (diff) | |
download | manaserv-7f1c499e4e09ab939d6d31188aaaaf785250a1d5.tar.gz manaserv-7f1c499e4e09ab939d6d31188aaaaf785250a1d5.tar.bz2 manaserv-7f1c499e4e09ab939d6d31188aaaaf785250a1d5.tar.xz manaserv-7f1c499e4e09ab939d6d31188aaaaf785250a1d5.zip |
Controlled map activation from the account server, so that clients are not kept on the wrong server when warped.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 10 | ||||
-rw-r--r-- | src/defines.h | 1 | ||||
-rw-r--r-- | src/game-server/accountconnection.cpp | 6 | ||||
-rw-r--r-- | src/game-server/mapmanager.cpp | 25 | ||||
-rw-r--r-- | src/game-server/mapmanager.hpp | 19 |
6 files changed, 54 insertions, 11 deletions
@@ -23,6 +23,10 @@ the original files. * src/game-server/mapmanager.hpp, src/game-server/mapmanager.cpp: Added on-the-fly map loading. + * src/defines.h, src/game-server/accountconnection.cpp, + src/account-server/serverhandler.cpp: Controlled map activation from + the account server, so that clients are not kept on the wrong server + when warped. 2006-12-29 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 99d872f8..7de37126 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -109,9 +109,15 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) while (msg.getUnreadLength()) { - unsigned id = msg.readShort(); + int id = msg.readShort(); LOG_INFO("Registering map " << id << '.', 0); - if (!servers.insert(std::make_pair(id, s)).second) + if (servers.insert(std::make_pair(id, s)).second) + { + MessageOut outMsg(AGMSG_ACTIVE_MAP); + outMsg.writeShort(id); + comp->send(outMsg); + } + else { LOG_ERROR("Server Handler: map is already registered.", 0); } diff --git a/src/defines.h b/src/defines.h index b25526be..0a5f383c 100644 --- a/src/defines.h +++ b/src/defines.h @@ -182,6 +182,7 @@ enum { // Inter-server GAMSG_REGISTER = 0x500, // S address, W port, { W map id }* + AGMSG_ACTIVE_MAP = 0x501, // W map id AGMSG_PLAYER_ENTER = 0x510, // L id, S name, B gender, B hair style, B hair color, B level, W money, // W*6 stats, W x, W y, W map id, B*32 token diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index a0f51f16..ee00a440 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -78,6 +78,12 @@ void AccountConnection::processMessage(MessageIn &msg) registerGameClient(token, ptr); } break; + case AGMSG_ACTIVE_MAP: + { + int id = msg.readShort(); + mapManager->raiseActive(id); + } break; + default: LOG_WARN("Invalid message type", 0); break; diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp index 6ba7464b..f4bb33bd 100644 --- a/src/game-server/mapmanager.cpp +++ b/src/game-server/mapmanager.cpp @@ -68,11 +68,11 @@ MapManager::MapManager(std::string const &mapReferenceFile) continue; } - unsigned id = XML::getProperty(node, "id", 0); + int id = XML::getProperty(node, "id", 0); std::string name = XML::getProperty(node, "name", std::string()); if (id != 0 && !name.empty()) { - LoadedMap m = { name, NULL }; + LoadedMap m = { false, name, NULL }; maps[id] = m; } } @@ -88,7 +88,7 @@ MapManager::~MapManager() } } -Map *MapManager::getMap(unsigned mapId) +Map *MapManager::getMap(int mapId) { Maps::iterator i = maps.find(mapId); assert(i != maps.end()); @@ -107,9 +107,24 @@ Map *MapManager::getMap(unsigned mapId) return map; } -std::string MapManager::getMapName(unsigned mapId) +std::string MapManager::getMapName(int mapId) const { - Maps::iterator i = maps.find(mapId); + Maps::const_iterator i = maps.find(mapId); assert(i != maps.end()); return i->second.fileName; } + +void MapManager::raiseActive(int mapId) +{ + Maps::iterator i = maps.find(mapId); + assert(i != maps.end()); + i->second.isActive = true; + LOG_INFO("Activating map \"" << i->second.fileName << "\" (id " << i->first << ")", 0); +} + +bool MapManager::isActive(int mapId) const +{ + Maps::const_iterator i = maps.find(mapId); + assert(i != maps.end()); + return i->second.isActive; +} diff --git a/src/game-server/mapmanager.hpp b/src/game-server/mapmanager.hpp index 7ac3970b..1ba7c8c7 100644 --- a/src/game-server/mapmanager.hpp +++ b/src/game-server/mapmanager.hpp @@ -31,6 +31,7 @@ class Map; struct LoadedMap { + bool isActive; std::string fileName; Map *map; }; @@ -41,7 +42,7 @@ struct LoadedMap class MapManager { public: - typedef std::map< unsigned, LoadedMap > Maps; + typedef std::map< unsigned short, LoadedMap > Maps; /** * Constructor (loads map reference file). @@ -51,17 +52,27 @@ class MapManager /** * Returns the requested map. */ - Map *getMap(unsigned); + Map *getMap(int); /** * Returns the requested map name. */ - std::string getMapName(unsigned); + std::string getMapName(int) const; /** * Returns all the maps. */ - Maps const &getMaps() { return maps; } + Maps const &getMaps() const { return maps; } + + /** + * Sets the activity status of the map. + */ + void raiseActive(int); + + /** + * Gets the activity status of the map. + */ + bool isActive(int) const; /** * Destructor. |