summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-12 19:27:29 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-13 17:41:29 +0300
commitcb23bcec8f8a1d8863ab25adc39a58415e5be88c (patch)
treeef02b4c3e9028eac10118101aa090f4ad8a9d96e
parentba54aed00801d29e4b5b6c77e1aed23a038ba7e6 (diff)
downloadplus-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.tar.gz
plus-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.tar.bz2
plus-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.tar.xz
plus-cb23bcec8f8a1d8863ab25adc39a58415e5be88c.zip
In inventoryhandler use for each packet own function.
-rw-r--r--src/net/eathena/inventoryhandler.cpp87
-rw-r--r--src/net/eathena/inventoryhandler.h2
-rw-r--r--src/net/tmwa/inventoryhandler.cpp98
-rw-r--r--src/net/tmwa/inventoryhandler.h2
4 files changed, 118 insertions, 71 deletions
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp
index 6b4a54abe..646ecef97 100644
--- a/src/net/eathena/inventoryhandler.cpp
+++ b/src/net/eathena/inventoryhandler.cpp
@@ -82,10 +82,13 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
switch (msg.getId())
{
case SMSG_PLAYER_INVENTORY:
- case SMSG_PLAYER_STORAGE_ITEMS:
processPlayerInventory(msg);
break;
+ case SMSG_PLAYER_STORAGE_ITEMS:
+ processPlayerStorage(msg);
+ break;
+
case SMSG_PLAYER_STORAGE_EQUIP:
processPlayerStorageEquip(msg);
break;
@@ -377,38 +380,26 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg)
void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
{
BLOCK_START("InventoryHandler::processPlayerInventory")
- const bool playerInvintory = msg.getId() == SMSG_PLAYER_INVENTORY;
Inventory *const inventory = localPlayer
? PlayerInfo::getInventory() : nullptr;
- if (playerInvintory)
+ if (PlayerInfo::getEquipment())
{
- if (PlayerInfo::getEquipment())
- {
- // Clear inventory - this will be a complete refresh
- mEquips.clear();
- PlayerInfo::getEquipment()->setBackend(&mEquips);
- }
-
- if (inventory)
- inventory->clear();
- }
- else
- {
- mInventoryItems.clear();
+ // Clear inventory - this will be a complete refresh
+ mEquips.clear();
+ PlayerInfo::getEquipment()->setBackend(&mEquips);
}
- msg.readInt16("len");
+ if (inventory)
+ inventory->clear();
- if (!playerInvintory)
- msg.readString(24, "storage name");
+ msg.readInt16("len");
const int number = (msg.getLength() - 4) / 23;
const uint8_t identified = 1;
for (int loop = 0; loop < number; loop++)
{
- const int index = msg.readInt16("item index") - (playerInvintory
- ? INVENTORY_OFFSET : STORAGE_OFFSET);
+ const int index = msg.readInt16("item index") - INVENTORY_OFFSET;
const int itemId = msg.readInt16("item id");
msg.readUInt8("item type");
const int amount = msg.readInt16("count");
@@ -421,26 +412,52 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
msg.readInt8("flags");
// need get actual identify flag
- if (playerInvintory)
- {
- // Trick because arrows are not considered equipment
-// const bool isEquipment = arrow & 0x8000;
-
- if (inventory)
- {
- inventory->setItem(index, itemId, amount,
- 0, identified, false);
- }
- }
- else
+ // Trick because arrows are not considered equipment
+// const bool isEquipment = arrow & 0x8000;
+
+ if (inventory)
{
- mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
- amount, 0, identified, false));
+ inventory->setItem(index, itemId, amount,
+ 0, identified, false);
}
}
BLOCK_END("InventoryHandler::processPlayerInventory")
}
+void InventoryHandler::processPlayerStorage(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryHandler::processPlayerInventory")
+ Inventory *const inventory = localPlayer
+ ? PlayerInfo::getInventory() : nullptr;
+ mInventoryItems.clear();
+
+ msg.readInt16("len");
+ msg.readString(24, "storage name");
+
+ const int number = (msg.getLength() - 4) / 23;
+ const uint8_t identified = 1;
+
+ for (int loop = 0; loop < number; loop++)
+ {
+ const int index = msg.readInt16("item index") - STORAGE_OFFSET;
+ const int itemId = msg.readInt16("item id");
+ msg.readUInt8("item type");
+ const int amount = msg.readInt16("count");
+ msg.readInt32("wear state / equip");
+ msg.readInt16("card0");
+ msg.readInt16("card1");
+ msg.readInt16("card2");
+ msg.readInt16("card3");
+ msg.readInt32("hire expire date (?)");
+ msg.readInt8("flags");
+
+ // need get actual identify flag
+ mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
+ amount, 0, identified, false));
+ }
+ BLOCK_END("InventoryHandler::processPlayerInventory")
+}
+
void InventoryHandler::processPlayerEquip(Net::MessageIn &msg)
{
BLOCK_START("InventoryHandler::processPlayerEquip")
diff --git a/src/net/eathena/inventoryhandler.h b/src/net/eathena/inventoryhandler.h
index a35293aa4..ae4f864d6 100644
--- a/src/net/eathena/inventoryhandler.h
+++ b/src/net/eathena/inventoryhandler.h
@@ -70,6 +70,8 @@ class InventoryHandler final : public MessageHandler,
void processPlayerInventory(Net::MessageIn &msg);
+ void processPlayerStorage(Net::MessageIn &msg);
+
void processPlayerEquip(Net::MessageIn &msg);
void processPlayerUnEquip(Net::MessageIn &msg);
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 7e5bf3946..ed4630bb2 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -82,10 +82,13 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
switch (msg.getId())
{
case SMSG_PLAYER_INVENTORY:
- case SMSG_PLAYER_STORAGE_ITEMS:
processPlayerInventory(msg);
break;
+ case SMSG_PLAYER_STORAGE_ITEMS:
+ processPlayerStorage(msg);
+ break;
+
case SMSG_PLAYER_STORAGE_EQUIP:
processPlayerStorageEquip(msg);
break;
@@ -342,41 +345,33 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg)
void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
{
BLOCK_START("InventoryHandler::processPlayerInventory")
- const bool playerInvintory = msg.getId() == SMSG_PLAYER_INVENTORY;
Inventory *const inventory = localPlayer
? PlayerInfo::getInventory() : nullptr;
- if (playerInvintory)
- {
- if (PlayerInfo::getEquipment())
- {
- // Clear inventory - this will be a complete refresh
- mEquips.clear();
- PlayerInfo::getEquipment()->setBackend(&mEquips);
- }
- if (inventory)
- inventory->clear();
- }
- else
+ if (PlayerInfo::getEquipment())
{
- mInventoryItems.clear();
+ // Clear inventory - this will be a complete refresh
+ mEquips.clear();
+ PlayerInfo::getEquipment()->setBackend(&mEquips);
}
- msg.readInt16(); // length
+ if (inventory)
+ inventory->clear();
+
+ msg.readInt16("len");
const int number = (msg.getLength() - 4) / 18;
for (int loop = 0; loop < number; loop++)
{
int cards[4];
- const int index = msg.readInt16() - (playerInvintory
- ? INVENTORY_OFFSET : STORAGE_OFFSET);
- const int itemId = msg.readInt16();
- const uint8_t itemType = msg.readUInt8();
- uint8_t identified = msg.readUInt8();
- const int amount = msg.readInt16();
- const int arrow = msg.readInt16();
+ const int index = msg.readInt16("index") - INVENTORY_OFFSET;
+ const int itemId = msg.readInt16("item id");
+ const uint8_t itemType = msg.readUInt8("item type");
+ uint8_t identified = msg.readUInt8("identified");
+ const int amount = msg.readInt16("amount");
+ const int arrow = msg.readInt16("arrow");
for (int i = 0; i < 4; i++)
- cards[i] = msg.readInt16();
+ cards[i] = msg.readInt16("card");
if (mDebugInventory)
{
@@ -389,22 +384,53 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
if (serverVersion < 1 && identified > 1)
identified = 1;
- if (playerInvintory)
+ // Trick because arrows are not considered equipment
+ const bool isEquipment = arrow & 0x8000;
+
+ if (inventory)
{
- // Trick because arrows are not considered equipment
- const bool isEquipment = arrow & 0x8000;
-
- if (inventory)
- {
- inventory->setItem(index, itemId, amount,
- 0, identified, isEquipment);
- }
+ inventory->setItem(index, itemId, amount,
+ 0, identified, isEquipment);
}
- else
+ }
+ BLOCK_END("InventoryHandler::processPlayerInventory")
+}
+
+void InventoryHandler::processPlayerStorage(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryHandler::processPlayerInventory")
+ Inventory *const inventory = localPlayer
+ ? PlayerInfo::getInventory() : nullptr;
+ mInventoryItems.clear();
+
+ msg.readInt16("len");
+ const int number = (msg.getLength() - 4) / 18;
+
+ for (int loop = 0; loop < number; loop++)
+ {
+ int cards[4];
+ const int index = msg.readInt16("index") - STORAGE_OFFSET;
+ const int itemId = msg.readInt16("item id");
+ const uint8_t itemType = msg.readUInt8("item type");
+ uint8_t identified = msg.readUInt8("identified");
+ const int amount = msg.readInt16("amount");
+ const int arrow = msg.readInt16("arrow");
+ for (int i = 0; i < 4; i++)
+ cards[i] = msg.readInt16("card");
+
+ if (mDebugInventory)
{
- mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
- amount, 0, identified, false));
+ logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, "
+ "Qty: %d, Cards: %d, %d, %d, %d",
+ index, itemId, itemType, identified, amount,
+ cards[0], cards[1], cards[2], cards[3]);
}
+
+ if (serverVersion < 1 && identified > 1)
+ identified = 1;
+
+ mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
+ amount, 0, identified, false));
}
BLOCK_END("InventoryHandler::processPlayerInventory")
}
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index f6ca9aa00..3d9fea657 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -70,6 +70,8 @@ class InventoryHandler final : public MessageHandler,
void processPlayerInventory(Net::MessageIn &msg);
+ void processPlayerStorage(Net::MessageIn &msg);
+
void processPlayerEquip(Net::MessageIn &msg);
void processPlayerUnEquip(Net::MessageIn &msg);