Disallow attaching the same item to an email twice

Also fix vendor buying validation not allowing crates to be bought,
since apparently their maximum stack size is 0 in TableData.
This commit is contained in:
dongresource 2021-03-09 22:26:07 +01:00
parent 89eb0b140b
commit f7e9cc2cea
2 changed files with 16 additions and 2 deletions

View File

@ -750,6 +750,7 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
bool invalid = false; bool invalid = false;
int itemCount = 0; int itemCount = 0;
std::set<int> seen;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
int slot = pkt->aItem[i].iSlotNum; int slot = pkt->aItem[i].iSlotNum;
if (slot < 0 || slot >= AINVEN_COUNT) { if (slot < 0 || slot >= AINVEN_COUNT) {
@ -763,9 +764,16 @@ void BuddyManager::emailSend(CNSocket* sock, CNPacketData* data) {
if (item->iID == 0) if (item->iID == 0)
continue; continue;
// was the same item added multiple times?
if (seen.count(slot) > 0) {
invalid = true;
break;
}
seen.insert(slot);
itemCount++; itemCount++;
if (item->iType != real->iType || item->iID != real->iID if (item->iType != real->iType || item->iID != real->iID
|| item->iOpt < 0 || item->iOpt > real->iOpt) { || item->iOpt <= 0 || item->iOpt > real->iOpt) {
invalid = true; invalid = true;
break; break;
} }

View File

@ -135,7 +135,13 @@ void NPCManager::npcVendorBuy(CNSocket* sock, CNPacketData* data) {
int itemCost = itemDat->buyPrice * (itemDat->stackSize > 1 ? req->Item.iOpt : 1); int itemCost = itemDat->buyPrice * (itemDat->stackSize > 1 ? req->Item.iOpt : 1);
int slot = ItemManager::findFreeSlot(plr); int slot = ItemManager::findFreeSlot(plr);
if (itemCost > plr->money || slot == -1 || req->Item.iOpt > itemDat->stackSize) { if (itemCost > plr->money || slot == -1) {
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL));
return;
}
// crates don't have a stack size in TableData, so we can't check those
if (itemDat->stackSize != 0 && req->Item.iOpt > itemDat->stackSize) {
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL)); sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL));
return; return;
} }