Example #1
0
void BlackMarketMgr::Update()
{
    SQLTransaction trans = CharacterDatabase.BeginTransaction();

    // Delete expired auctions
    for (auto itr = m_bmAuctionsMap.begin(); itr != m_bmAuctionsMap.end();)
    {
        BMAuctionEntry* auction = itr->second;
        if (auction->IsExpired())
        {
            if (auction->bidder)
                SendAuctionWon(auction, trans);
            auction->DeleteFromDB(trans);
            itr = m_bmAuctionsMap.erase(itr);
        }
        else
            ++itr;
    }

    // Add New Auctions
    int32 add = sWorld->getIntConfig(CONFIG_BLACKMARKET_MAX_AUCTIONS) - m_bmAuctionsMap.size();
    if (add > 0)
        CreateAuctions(add, trans);

    CharacterDatabase.CommitTransaction(trans);
}
Example #2
0
void BlackMarketMgr::Update()
{
    uint32 curTime = time(NULL);
    SQLTransaction trans = CharacterDatabase.BeginTransaction();

    for (BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd();)
    {
        BMAuctionEntry* auction = itr->second;
        if (auction->IsExpired())
        {
            if (auction->bidder)
                SendAuctionWon(auction, trans);

            auction->DeleteFromDB(trans);
            BMAuctionsMap.erase((itr++)->first);
        } else
            ++itr;
    }

    int32 add = sWorld->getIntConfig(CONFIG_BLACKMARKET_MAX_AUCTIONS) - BMAuctionsMap.size();
    if (add > 0)
        CreateAuctions(add, trans);

    CharacterDatabase.CommitTransaction(trans);
}
void BlackMarketMgr::LoadAuctions()
{
	uint32 oldMSTime = getMSTime();

    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BLACKMARKET_AUCTIONS);
    PreparedQueryResult result = CharacterDatabase.Query(stmt);

    if (!result)
    {
        sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 BlackMarket Auctions. DB table `blackmarket` is empty.");

        return;
    }

    uint32 count = 0;

    SQLTransaction trans = CharacterDatabase.BeginTransaction();
    do
    {
        Field* fields = result->Fetch();

        BMAuctionEntry* auction = new BMAuctionEntry();
        if (!auction->LoadFromDB(fields))
        {
			auction->DeleteFromDB(trans);
            delete auction;
            continue;
        }

		BMAuctionsMap[auction->id] = auction;

        ++count;

    } while (result->NextRow());

    CharacterDatabase.CommitTransaction(trans);

    sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u BlackMarket Auctions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));

}