• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

IOMarket::updateStatistics() bug

edwinaaa

Member
Joined
Jan 31, 2014
Messages
72
Reaction score
11
hello guys how are you, back here to know how to solve a bug that I have in the market, I explain what happens, when I enter the market and buy or sell something it does normal but after I restart the server and I will see the statistics of said item where it shows the low and high prices that have been sold because when selecting the item the customer cracks and closes.

Here is the line of code from where it reads the information when starting the server.

C++:
otserv.cpp

IOMarket::getInstance().updateStatistics();


here the code that is giving problems

C++:
ioMarket.cpp


void IOMarket::updateStatistics()
{
    DBResult_ptr result = Database::getInstance().storeQuery(fmt::format("SELECT `sale` AS `sale`, `itemtype` AS `itemtype`, COUNT(`price`) AS `num`, MIN(`price`) AS `min`, MAX(`price`) AS `max`, SUM(`price`) AS `sum` FROM `market_history` WHERE `state` = {:d} GROUP BY `itemtype`, `sale`", OFFERSTATE_ACCEPTED));
    if (!result) {
        return;
    }

    do {
        MarketStatistics* statistics;
        if (result->getNumber<uint16_t>("sale") == MARKETACTION_BUY) {
            statistics = &purchaseStatistics[result->getNumber<uint16_t>("itemtype")];
        }
        else {
            statistics = &saleStatistics[result->getNumber<uint16_t>("itemtype")];
        }

        statistics->numTransactions = result->getNumber<uint32_t>("num");
        statistics->lowestPrice = result->getNumber<uint32_t>("min");
        statistics->totalPrice = result->getNumber<uint64_t>("sum");
        statistics->highestPrice = result->getNumber<uint32_t>("max");
    } while (result->next());
}
 
Back
Top