summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-05-13 22:53:57 +0300
committerAndrei Karas <akaras@inbox.ru>2016-05-13 22:53:57 +0300
commit9f8da99f6b6266a7456d3be4d38880a3bd761932 (patch)
tree96aeb55b21dcdd6389f7b1caf47a3628b29a7df7
parent546d5180247512270a2ccd114266fb36cd426e61 (diff)
downloadmanaverse-9f8da99f6b6266a7456d3be4d38880a3bd761932.tar.gz
manaverse-9f8da99f6b6266a7456d3be4d38880a3bd761932.tar.bz2
manaverse-9f8da99f6b6266a7456d3be4d38880a3bd761932.tar.xz
manaverse-9f8da99f6b6266a7456d3be4d38880a3bd761932.zip
Add into network code function readUInt16. Also fix reading cards id.
-rw-r--r--src/net/eathena/auctionrecv.cpp2
-rw-r--r--src/net/eathena/beingrecv.cpp4
-rw-r--r--src/net/eathena/inventoryrecv.cpp22
-rw-r--r--src/net/eathena/itemrecv.cpp4
-rw-r--r--src/net/eathena/mailrecv.cpp2
-rw-r--r--src/net/eathena/messagein.cpp21
-rw-r--r--src/net/eathena/messagein.h3
-rw-r--r--src/net/eathena/partyrecv.cpp2
-rw-r--r--src/net/eathena/searchstorerecv.cpp2
-rw-r--r--src/net/eathena/traderecv.cpp2
-rw-r--r--src/net/eathena/vendingrecv.cpp4
-rw-r--r--src/net/messagein.h2
-rw-r--r--src/net/tmwa/inventoryrecv.cpp12
-rw-r--r--src/net/tmwa/messagein.cpp21
-rw-r--r--src/net/tmwa/messagein.h3
-rw-r--r--src/net/tmwa/traderecv.cpp2
16 files changed, 79 insertions, 29 deletions
diff --git a/src/net/eathena/auctionrecv.cpp b/src/net/eathena/auctionrecv.cpp
index cc7723e5f..092020775 100644
--- a/src/net/eathena/auctionrecv.cpp
+++ b/src/net/eathena/auctionrecv.cpp
@@ -54,7 +54,7 @@ void AuctionRecv::processAuctionResults(Net::MessageIn &msg)
msg.readUInt8("attribute");
msg.readUInt8("refine");
for (int d = 0; d < maxCards; d ++)
- msg.readInt16("card");
+ msg.readUInt16("card");
msg.readInt32("price");
msg.readInt32("buy now");
msg.readString(24, "buyer name");
diff --git a/src/net/eathena/beingrecv.cpp b/src/net/eathena/beingrecv.cpp
index 3da2567f8..85c276e46 100644
--- a/src/net/eathena/beingrecv.cpp
+++ b/src/net/eathena/beingrecv.cpp
@@ -126,7 +126,7 @@ void BeingRecv::processBeingChangeLookCards(Net::MessageIn &msg)
id2 = 1;
for (int f = 0; f < maxCards; f ++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (!dstBeing)
return;
@@ -1692,7 +1692,7 @@ void BeingRecv::processBeingViewEquipment(Net::MessageIn &msg)
msg.readInt32("wear state");
msg.readInt8("refine");
for (int d = 0; d < maxCards; d ++)
- msg.readInt16("card");
+ msg.readUInt16("card");
msg.readInt32("hire expire date (?)");
msg.readInt16("equip type");
msg.readInt16("item sprite number");
diff --git a/src/net/eathena/inventoryrecv.cpp b/src/net/eathena/inventoryrecv.cpp
index 5ba7a81b3..dea3a411f 100644
--- a/src/net/eathena/inventoryrecv.cpp
+++ b/src/net/eathena/inventoryrecv.cpp
@@ -149,7 +149,7 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg)
const uint8_t refine = CAST_U8(msg.readInt8("refine"));
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (msg.getVersion() >= 20071002)
msg.readInt32("hire expire date (?)");
if (msg.getVersion() >= 20080102)
@@ -218,7 +218,7 @@ void InventoryRecv::processPlayerInventoryAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
int equipType;
if (msg.getVersion() >= 20120925)
equipType = msg.readInt32("location");
@@ -374,7 +374,7 @@ void InventoryRecv::processPlayerInventory(Net::MessageIn &msg)
if (packetVersion >= 5)
{
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
}
else
{
@@ -453,7 +453,7 @@ void InventoryRecv::processPlayerStorage(Net::MessageIn &msg)
if (msg.getVersion() >= 5)
{
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
}
else
{
@@ -659,7 +659,7 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine level");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (msg.getVersion() >= 20071002)
msg.readInt32("hire expire date");
if (msg.getVersion() >= 20080102)
@@ -717,7 +717,7 @@ void InventoryRecv::processPlayerStorageAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if ((serverVersion >= 8 || serverVersion == 0) &&
msg.getVersion() >= 20150226)
{
@@ -924,7 +924,7 @@ void InventoryRecv::processPlayerCartAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if ((serverVersion >= 8 || serverVersion == 0) &&
msg.getVersion() >= 20150226)
{
@@ -1016,7 +1016,7 @@ void InventoryRecv::processPlayerCartEquip(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine level");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (msg.getVersion() >= 20071002)
msg.readInt32("hire expire date");
if (msg.getVersion() >= 20080102)
@@ -1088,7 +1088,7 @@ void InventoryRecv::processPlayerCartItems(Net::MessageIn &msg)
if (msg.getVersion() >= 5)
{
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
}
else
{
@@ -1205,7 +1205,7 @@ void InventoryRecv::processPlayerRepairList(Net::MessageIn &msg)
msg.readInt16("item id");
msg.readUInt8("refine");
for (int d = 0; d < maxCards; d ++)
- msg.readInt16("card");
+ msg.readUInt16("card");
}
menu = MenuType::RepairWespon;
}
@@ -1230,7 +1230,7 @@ void InventoryRecv::processPlayerRefineList(Net::MessageIn &msg)
msg.readInt16("item id");
msg.readUInt8("refine");
for (int d = 0; d < maxCards; d ++)
- msg.readInt16("card");
+ msg.readUInt16("card");
}
menu = MenuType::WeaponeRefine;
}
diff --git a/src/net/eathena/itemrecv.cpp b/src/net/eathena/itemrecv.cpp
index d20072a21..321109290 100644
--- a/src/net/eathena/itemrecv.cpp
+++ b/src/net/eathena/itemrecv.cpp
@@ -77,7 +77,7 @@ void ItemRecv::processItemDropped2(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
@@ -152,7 +152,7 @@ void ItemRecv::processItemVisible2(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
diff --git a/src/net/eathena/mailrecv.cpp b/src/net/eathena/mailrecv.cpp
index 4450be2af..884b6fafb 100644
--- a/src/net/eathena/mailrecv.cpp
+++ b/src/net/eathena/mailrecv.cpp
@@ -103,7 +103,7 @@ void MailRecv::processReadMail(Net::MessageIn &msg)
mail->itemAttribute = msg.readUInt8("attribute");
mail->itemRefine = msg.readUInt8("refine");
for (int f = 0; f < maxCards; f ++)
- mail->card[f] = msg.readInt16("card");
+ mail->card[f] = msg.readUInt16("card");
const int msgLen = msg.readUInt8("msg len");
if (msgLen != sz)
logger->log("error: wrong message size");
diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp
index 7b21b7485..34edbe39d 100644
--- a/src/net/eathena/messagein.cpp
+++ b/src/net/eathena/messagein.cpp
@@ -95,6 +95,27 @@ int16_t MessageIn::readInt16(const char *const str)
return value;
}
+uint16_t MessageIn::readUInt16(const char *const str)
+{
+ uint16_t value = 0xffU;
+ if (mPos + 2 <= mLength)
+ {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ uint16_t swap;
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(uint16_t));
+ value = SDL_Swap16(swap);
+#else
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(uint16_t));
+#endif
+ }
+ DEBUGLOG2("readUInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
+ mPos, str);
+ mPos += 2;
+ PacketCounters::incInBytes(2);
+ return value;
+}
+
int32_t MessageIn::readInt32(const char *const str)
{
int32_t value = -1;
diff --git a/src/net/eathena/messagein.h b/src/net/eathena/messagein.h
index 5ba13ea9c..509dbf767 100644
--- a/src/net/eathena/messagein.h
+++ b/src/net/eathena/messagein.h
@@ -51,6 +51,9 @@ class MessageIn final : public Net::MessageIn
/**< Reads a short. */
int16_t readInt16(const char *const str) override final;
+
+ uint16_t readUInt16(const char *const str) override final;
+
/**< Reads a long. */
int32_t readInt32(const char *const str) override final;
diff --git a/src/net/eathena/partyrecv.cpp b/src/net/eathena/partyrecv.cpp
index e23959a1c..30918e120 100644
--- a/src/net/eathena/partyrecv.cpp
+++ b/src/net/eathena/partyrecv.cpp
@@ -288,7 +288,7 @@ void PartyRecv::processPartyItemPickup(Net::MessageIn &msg)
msg.readUInt8("attribute");
msg.readUInt8("refine");
for (int f = 0; f < maxCards; f++)
- msg.readInt16("card");
+ msg.readUInt16("card");
msg.readInt16("equip location");
msg.readUInt8("item type");
// for color can be used ItemColorManager
diff --git a/src/net/eathena/searchstorerecv.cpp b/src/net/eathena/searchstorerecv.cpp
index 3fb2f5460..c2cfda0d2 100644
--- a/src/net/eathena/searchstorerecv.cpp
+++ b/src/net/eathena/searchstorerecv.cpp
@@ -52,7 +52,7 @@ void SearchStoreRecv::processSearchAck(Net::MessageIn &msg)
msg.readInt16("amount");
msg.readUInt8("refine");
for (int d = 0; d < maxCards; d++)
- msg.readInt16("card");
+ msg.readUInt16("card");
// +++ need use ItemColorManager for colors
}
diff --git a/src/net/eathena/traderecv.cpp b/src/net/eathena/traderecv.cpp
index 6c09b05e6..5f7f4a957 100644
--- a/src/net/eathena/traderecv.cpp
+++ b/src/net/eathena/traderecv.cpp
@@ -86,7 +86,7 @@ void TradeRecv::processTradeItemAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if ((serverVersion >= 8 || serverVersion == 0) &&
msg.getVersion() >= 20150226)
{
diff --git a/src/net/eathena/vendingrecv.cpp b/src/net/eathena/vendingrecv.cpp
index 4a342d8eb..443e02d8e 100644
--- a/src/net/eathena/vendingrecv.cpp
+++ b/src/net/eathena/vendingrecv.cpp
@@ -111,7 +111,7 @@ void VendingRecv::processItemsList(Net::MessageIn &msg)
msg.readUInt8("attribute");
msg.readUInt8("refine");
for (int d = 0; d < maxCards; d ++)
- cards[d] = msg.readInt16("card");
+ cards[d] = msg.readUInt16("card");
// ++ need change to msg.getVersion()
if ((serverVersion >= 8 || serverVersion == 0) &&
msg.getVersion() >= 20150226)
@@ -163,7 +163,7 @@ void VendingRecv::processOpen(Net::MessageIn &msg)
msg.readUInt8("attribute");
msg.readUInt8("refine");
for (int d = 0; d < maxCards; d ++)
- msg.readInt16("card");
+ msg.readUInt16("card");
// ++ need change to msg.getVersion()
if ((serverVersion >= 8 || serverVersion == 0) &&
msg.getVersion() >= 20150226)
diff --git a/src/net/messagein.h b/src/net/messagein.h
index 44d6a9aab..29b6ef7fb 100644
--- a/src/net/messagein.h
+++ b/src/net/messagein.h
@@ -71,6 +71,8 @@ class MessageIn notfinal
/**< Reads a short. */
virtual int16_t readInt16(const char *const str) = 0;
+ virtual uint16_t readUInt16(const char *const str) = 0;
+
/**< Reads a long. */
virtual int32_t readInt32(const char *const str) = 0;
diff --git a/src/net/tmwa/inventoryrecv.cpp b/src/net/tmwa/inventoryrecv.cpp
index 9d4d202a0..878a03538 100644
--- a/src/net/tmwa/inventoryrecv.cpp
+++ b/src/net/tmwa/inventoryrecv.cpp
@@ -102,7 +102,7 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (Ea::InventoryRecv::mDebugInventory)
{
@@ -156,7 +156,7 @@ void InventoryRecv::processPlayerInventoryAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
const int equipType = msg.readInt16("equip type");
const ItemTypeT type = static_cast<ItemTypeT>(msg.readUInt8("item type"));
const ItemInfo &itemInfo = ItemDB::get(itemId);
@@ -275,7 +275,7 @@ void InventoryRecv::processPlayerInventory(Net::MessageIn &msg)
const int amount = msg.readInt16("amount");
const int arrow = msg.readInt16("arrow");
for (int i = 0; i < maxCards; i++)
- cards[i] = msg.readInt16("card");
+ cards[i] = msg.readUInt16("card");
if (Ea::InventoryRecv::mDebugInventory)
{
@@ -326,7 +326,7 @@ void InventoryRecv::processPlayerStorage(Net::MessageIn &msg)
const int amount = msg.readInt16("amount");
msg.readInt16("arrow");
for (int i = 0; i < maxCards; i++)
- cards[i] = msg.readInt16("card");
+ cards[i] = msg.readUInt16("card");
if (Ea::InventoryRecv::mDebugInventory)
{
@@ -410,7 +410,7 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg)
msg.readUInt8("attribute (broken)");
const uint8_t refine = msg.readUInt8("refine");
for (int i = 0; i < maxCards; i++)
- cards[i] = msg.readInt16("card");
+ cards[i] = msg.readUInt16("card");
if (Ea::InventoryRecv::mDebugInventory)
{
@@ -450,7 +450,7 @@ void InventoryRecv::processPlayerStorageAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (Item *const item = Ea::InventoryRecv::mStorage->getItem(index))
{
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 375e973f5..a5fac5ac9 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -86,6 +86,27 @@ int16_t MessageIn::readInt16(const char *const str)
return value;
}
+uint16_t MessageIn::readUInt16(const char *const str)
+{
+ uint16_t value = 0xffU;
+ if (mPos + 2 <= mLength)
+ {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ uint16_t swap;
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(uint16_t));
+ value = SDL_Swap16(swap);
+#else
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(uint16_t));
+#endif
+ }
+ DEBUGLOG2("readUInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
+ mPos, str);
+ mPos += 2;
+ PacketCounters::incInBytes(2);
+ return value;
+}
+
int32_t MessageIn::readInt32(const char *const str)
{
int32_t value = -1;
diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h
index 14c6b8156..52b6b3f73 100644
--- a/src/net/tmwa/messagein.h
+++ b/src/net/tmwa/messagein.h
@@ -50,6 +50,9 @@ class MessageIn final : public Net::MessageIn
/**< Reads a short. */
int16_t readInt16(const char *const str) override final;
+
+ uint16_t readUInt16(const char *const str) override final;
+
/**< Reads a long. */
int32_t readInt32(const char *const str) override final;
diff --git a/src/net/tmwa/traderecv.cpp b/src/net/tmwa/traderecv.cpp
index f68bee9f5..29e88b2c4 100644
--- a/src/net/tmwa/traderecv.cpp
+++ b/src/net/tmwa/traderecv.cpp
@@ -66,7 +66,7 @@ void TradeRecv::processTradeItemAdd(Net::MessageIn &msg)
const uint8_t refine = msg.readUInt8("refine");
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
- cards[f] = msg.readInt16("card");
+ cards[f] = msg.readUInt16("card");
if (tradeWindow)
{