summaryrefslogtreecommitdiff
path: root/src/account-server/serverhandler.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-09-09 02:35:25 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-09-09 02:36:30 +0200
commit6ae2001e91eaaeb8b72031e96f88820711bb1ca0 (patch)
tree8ab01e1d9e59860837560e6cd8bbd7eabaa428de /src/account-server/serverhandler.cpp
parent40a31c52aebc19221cc9da8a0f764d21e672937b (diff)
downloadmanaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.tar.gz
manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.tar.bz2
manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.tar.xz
manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.zip
Add persistent items support based on seeseekey's work.
Also made some random changes where useful, including: - Code formatting fixes, - Design fix about the fact that only the game config option should be checked. - Fixed the size of the values sent and receive to follow the rest of the development. - Fixed variables names to make them show what they are, and not why they are used. Resolves: Mana-Mantis #142.
Diffstat (limited to 'src/account-server/serverhandler.cpp')
-rw-r--r--src/account-server/serverhandler.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index e5bfdc40..6a41d715 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -27,6 +27,7 @@
#include "account-server/accountclient.h"
#include "account-server/accounthandler.h"
#include "account-server/character.h"
+#include "account-server/flooritem.h"
#include "account-server/storage.h"
#include "chat-server/chathandler.h"
#include "chat-server/post.h"
@@ -241,9 +242,15 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
else
{
MessageOut outMsg(AGMSG_ACTIVE_MAP);
+
+ // Map variables
outMsg.writeInt16(id);
std::map<std::string, std::string> variables;
variables = storage->getAllWorldStateVars(id);
+
+ // Map vars number
+ outMsg.writeInt16(variables.size());
+
for (std::map<std::string, std::string>::iterator i = variables.begin();
i != variables.end();
i++)
@@ -251,6 +258,23 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
outMsg.writeString(i->first);
outMsg.writeString(i->second);
}
+
+ // Persistent Floor Items
+ std::list<FloorItem> items;
+ items = storage->getFloorItemsFromMap(id);
+
+ outMsg.writeInt16(items.size()); //number of floor items
+
+ // Send each map item: item_id, amount, pos_x, pos_y
+ for (std::list<FloorItem>::iterator i = items.begin();
+ i != items.end(); ++i)
+ {
+ outMsg.writeInt32(i->getItemId());
+ outMsg.writeInt16(i->getItemAmount());
+ outMsg.writeInt16(i->getPosX());
+ outMsg.writeInt16(i->getPosY());
+ }
+
comp->send(outMsg);
MapStatistics &m = server->maps[id];
m.nbThings = 0;
@@ -549,6 +573,34 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
chatHandler->handlePartyInvite(msg);
break;
+ case GAMSG_CREATE_ITEM_ON_MAP:
+ {
+ int mapId = msg.readInt32();
+ int itemId = msg.readInt32();
+ int amount = msg.readInt16();
+ int posX = msg.readInt16();
+ int posY = msg.readInt16();
+
+ LOG_DEBUG("Gameserver create item " << itemId
+ << " on map " << mapId);
+
+ storage->addFloorItem(mapId, itemId, amount, posX, posY);
+ } break;
+
+ case GAMSG_REMOVE_ITEM_ON_MAP:
+ {
+ int mapId = msg.readInt32();
+ int itemId = msg.readInt32();
+ int amount = msg.readInt16();
+ int posX = msg.readInt16();
+ int posY = msg.readInt16();
+
+ LOG_DEBUG("Gameserver removed item " << itemId
+ << " from map " << mapId);
+
+ storage->removeFloorItem(mapId, itemId, amount, posX, posY);
+ } break;
+
default:
LOG_WARN("ServerHandler::processMessage, Invalid message type: "
<< msg.getId());