From 7471bcbf38bb895a1bdad8562fa11d78248761a2 Mon Sep 17 00:00:00 2001 From: dongresource Date: Wed, 28 Dec 2022 17:57:37 +0100 Subject: [PATCH] Fix vehicle rental periods not showing up in vendor listings Fixes #250. --- src/Vendors.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Vendors.cpp b/src/Vendors.cpp index 6ec6603..732cc28 100644 --- a/src/Vendors.cpp +++ b/src/Vendors.cpp @@ -1,6 +1,9 @@ #include "Vendors.hpp" #include "Rand.hpp" +// 7 days +#define VEHICLE_EXPIRY_DURATION 604800 + using namespace Vendors; std::map> Vendors::VendorTables; @@ -53,8 +56,8 @@ static void vendorBuy(CNSocket* sock, CNPacketData* data) { // if vehicle if (req->Item.iType == 10) { - // set time limit: current time + 7days - req->Item.iTimeLimit = getTimestamp() + 604800; + // set time limit: current time + expiry duration + req->Item.iTimeLimit = getTimestamp() + VEHICLE_EXPIRY_DURATION; } if (slot != req->iInvenSlotNum) { @@ -224,12 +227,20 @@ static void vendorTable(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, resp); for (int i = 0; i < (int)listings.size() && i < 20; i++) { // 20 is the max - sItemBase base; + sItemBase base = {}; base.iID = listings[i].id; - base.iOpt = 0; - base.iTimeLimit = 0; base.iType = listings[i].type; + /* + * Set vehicle expiry value. + * + * Note: sItemBase.iTimeLimit in the context of vendor listings contains + * a duration, unlike in most other contexts where it contains the + * expiration timestamp. + */ + if (listings[i].type == 10) + base.iTimeLimit = VEHICLE_EXPIRY_DURATION; + sItemVendor vItem; vItem.item = base; vItem.iSortNum = listings[i].sort;