diff options
Diffstat (limited to 'src/game-server/accountconnection.cpp')
-rw-r--r-- | src/game-server/accountconnection.cpp | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index a6dc552f..36f30f33 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -26,6 +26,7 @@ #include "game-server/map.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" +#include "game-server/item.h" #include "game-server/itemmanager.h" #include "game-server/postman.h" #include "game-server/quest.h" @@ -158,18 +159,45 @@ void AccountConnection::processMessage(MessageIn &msg) case AGMSG_ACTIVE_MAP: { - int id = msg.readInt16(); - if (MapManager::activateMap(id)) + int mapId = msg.readInt16(); + if (MapManager::activateMap(mapId)) { - // set map variables - MapComposite *m = MapManager::getMap(id); - while (msg.getUnreadLength()) + // Set map variables + MapComposite *m = MapManager::getMap(mapId); + int mapVarsNumber = msg.readInt16(); + for(int i = 0; i < mapVarsNumber; ++i) { std::string key = msg.readString(); std::string value = msg.readString(); if (!key.empty() && !value.empty()) - { m->setVariableFromDbserver(key, value); + } + + // Recreate potential persistent floor items + LOG_DEBUG("Recreate persistant items on map " << mapId); + int floorItemsNumber = msg.readInt16(); + + for(int i = 0; i < floorItemsNumber; i += 4) + { + int itemId = msg.readInt32(); + int amount = msg.readInt16(); + int posX = msg.readInt16(); + int posY = msg.readInt16(); + + if (ItemClass *ic = itemManager->getItem(itemId)) + { + Item *item = new Item(ic, amount); + item->setMap(m); + Point dst(posX, posY); + item->setPosition(dst); + + if (!GameState::insertOrDelete(item)) + { + // The map is full. + LOG_WARN("Couldn't add floor item(s) " << itemId + << " into map " << mapId); + return; + } } } } @@ -469,3 +497,27 @@ void AccountConnection::sendTransaction(int id, int action, const std::string &m msg.writeString(message); send(msg); } + +void AccountConnection::createFloorItems(int mapId, int itemId, int amount, + int posX, int posY) +{ + MessageOut msg(GAMSG_CREATE_ITEM_ON_MAP); + msg.writeInt32(mapId); + msg.writeInt32(itemId); + msg.writeInt16(amount); + msg.writeInt16(posX); + msg.writeInt16(posY); + send(msg); +} + +void AccountConnection::removeFloorItems(int mapId, int itemId, int amount, + int posX, int posY) +{ + MessageOut msg(GAMSG_REMOVE_ITEM_ON_MAP); + msg.writeInt32(mapId); + msg.writeInt32(itemId); + msg.writeInt16(amount); + msg.writeInt16(posX); + msg.writeInt16(posY); + send(msg); +} |