summaryrefslogtreecommitdiff
path: root/src/net/tmwa
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 /src/net/tmwa
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.
Diffstat (limited to 'src/net/tmwa')
-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
4 files changed, 31 insertions, 7 deletions
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)
{