From 5747c244791dbb3efc738e1e22f579d359cc8b70 Mon Sep 17 00:00:00 2001 From: dongresource Date: Sat, 12 Sep 2020 02:25:45 +0200 Subject: [PATCH] [bugfix] Don't set iType on empty item slots. This confuses ItemManager::findFreeSlot(). --- src/CNLoginServer.cpp | 2 +- src/Database.cpp | 2 +- src/ItemManager.cpp | 5 +---- src/MissionManager.cpp | 2 +- src/NPCManager.cpp | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index deeec7a..6ec17c0 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -130,7 +130,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { for (int i = 5; i < AEQUIP_COUNT; i++) { // empty equips charInfo.aEquip[i].iID = 0; - charInfo.aEquip[i].iType = i; + charInfo.aEquip[i].iType = 0; charInfo.aEquip[i].iOpt = 0; } diff --git a/src/Database.cpp b/src/Database.cpp index 7a55895..8884827 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -337,7 +337,7 @@ Player Database::DbToPlayer(DbPlayer player) { for (int i = 4; i < AEQUIP_COUNT; i++) { // empty equips result.Equip[i].iID = 0; - result.Equip[i].iType = i; + result.Equip[i].iType = 0; result.Equip[i].iOpt = 0; } for (int i = 0; i < AINVEN_COUNT; i++) { diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index bcce490..14e7f29 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -720,12 +720,9 @@ void ItemManager::chestOpenHandler(CNSocket *sock, CNPacketData *data) { // TODO: use this in cleaned up ItemManager int ItemManager::findFreeSlot(Player *plr) { int i; - sItemBase free; - - memset((void*)&free, 0, sizeof(sItemBase)); for (i = 0; i < AINVEN_COUNT; i++) - if (memcmp((void*)&plr->Inven[i], (void*)&free, sizeof(sItemBase)) == 0) + if (plr->Inven[i].iType == 0 && plr->Inven[i].iID == 0 && plr->Inven[i].iOpt == 0) return i; // not found diff --git a/src/MissionManager.cpp b/src/MissionManager.cpp index 1620d61..a298568 100644 --- a/src/MissionManager.cpp +++ b/src/MissionManager.cpp @@ -141,7 +141,7 @@ void MissionManager::quitMission(CNSocket* sock, CNPacketData* data) { /* * It's ok to do this only server-side, because the server decides which - * slot latter items will be placed in. + * slot later items will be placed in. */ for (int j = 0; j < AQINVEN_COUNT; j++) if (plr->QInven[j].iID == task["m_iSUItem"][i] || plr->QInven[j].iID == task["m_iCSUItem"][i]) diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 3f9ba8f..85553ec 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -44,7 +44,7 @@ void NPCManager::npcVendorBuy(CNSocket* sock, CNPacketData* data) { if (slot != req->iInvenSlotNum) { // possible item stacking? - std::cout << "[WARN] Client and server disagree on bought item slot" << std::endl; + std::cout << "[WARN] Client and server disagree on bought item slot (" << req->iInvenSlotNum << " vs " << slot << ")" << std::endl; } INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_SUCC, resp);