예제 #1
0
파일: World.cpp 프로젝트: vata/prebcwow
void
World::Update(time_t diff)
{
    _UpdateGameTime();
    for(int i = 0; i < WUPDATE_COUNT; ++i)
        m_timers[i].Update(diff);


	// TODO: make sure that all objects get their updates, not just characters and creatures
    if (m_timers[WUPDATE_OBJECTS].Passed())
    {
        m_timers[WUPDATE_OBJECTS].Reset();

		ObjectMgr::PlayerMap::iterator chriter;
        for( chriter = objmgr.Begin<Player>(); chriter != objmgr.End<Player>( ); ++ chriter )
            chriter->second->Update( (uint32)diff );

		// Update creatures and gameobjects in active map cells
		//
		MapMgr	*mapm;
		for (int mapid = 0; mapid<=1; ++mapid) 
		{
			if(isMapId(mapid))
			{
				mapm = sWorld.GetMap (mapid);
				mapm->UpdateActiveObjects ((uint32)diff);
			}
		}

		// Update dynamic objects (spell visual effects)
		//
		ObjectMgr::DynamicObjectMap::iterator diter;
        for( diter = objmgr.Begin<DynamicObject>(); diter != objmgr.End<DynamicObject>( ); ++ diter )
            diter->second->Update( (uint32)diff );
    }


	if (m_timers[WUPDATE_SESSIONS].Passed())
	{
		m_timers[WUPDATE_SESSIONS].Reset();

		SessionMap::iterator itr, next;
		for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next)
		{
			next = itr;
			++next;

			if(!itr->second->Update((uint32)diff))
			{
				ZThread::Guard<ZThread::Mutex> guard(m_sessions_lock);
				delete itr->second;
				m_sessions.erase(itr);
			}
		}
	}


	if (m_timers[WUPDATE_AUCTIONS].Passed())
	{
		m_timers[WUPDATE_AUCTIONS].Reset();
		ObjectMgr::AuctionEntryMap::iterator itr,next;
		for (itr = objmgr.GetAuctionsBegin(); itr != objmgr.GetAuctionsEnd();itr = next)
		{
			next = itr;
			++next;
			if (time(NULL) > (itr->second->time))
			{
				if (itr->second->bidder == 0)
				{
					Mail *m = new Mail;
					m->reciever = itr->second->owner;
					m->body = "";
					m->sender = itr->second->owner;
					m->checked = 0;
					m->COD = 0;
					m->messageID = objmgr.GenerateMailID();
					m->money = 0;
					m->time = time(NULL) + (29 * 3600);
					m->subject = "Your item failed to sell";
					m->item = itr->second->item;
					Item *it = objmgr.GetAItem(m->item);
					objmgr.AddMItem(it);

					std::stringstream ss;
					ss << "INSERT INTO mailed_items (guid, data) VALUES ("
						<< it->GetGUIDLow() << ", '";
					for(uint16 i = 0; i < it->GetValuesCount(); ++i )
					{
						ss << it->GetUInt32Value(i) << " ";
					}
					ss << "' )";
					sDatabase.Execute( ss.str().c_str() );

					std::stringstream md;
					md << "DELETE FROM mail WHERE mailID = " << m->messageID;
					sDatabase.Execute( md.str().c_str( ) );

					std::stringstream mi;
					mi << "INSERT INTO mail (mailId,sender,reciever,subject,body,item,"
						"time,money,COD,checked) VALUES ( " << m->messageID << ", "
						<< m->sender << ", " << m->reciever << ",' " << m->subject.c_str()
						<< "' ,' " << m->body.c_str() << "', " << m->item << ", "
						<< (uint32)m->time << ", " << m->money << ", " << 0 << ", "
						<< m->checked << " )";
					sDatabase.Execute( mi.str().c_str( ) );

					uint64 rcpl;
					GUID_LOPART(rcpl) = m->reciever;
					GUID_HIPART(rcpl) = 0;
					std::string pname;
					objmgr.GetPlayerNameByGUID(rcpl,pname);
					Player *rpl = objmgr.GetPlayer(pname.c_str());
					if (rpl)
					{
						rpl->AddMail(m);
					}
					std::stringstream delinvq;
					std::stringstream id;
					std::stringstream bd;
					delinvq << "DELETE FROM auctionhouse WHERE itemowner = " << m->reciever;
					sDatabase.Execute( delinvq.str().c_str( ) );

					id << "DELETE FROM auctioned_items WHERE guid = " << m->item;
					sDatabase.Execute( id.str().c_str( ) );

					bd << "DELETE FROM bids WHERE Id = " << itr->second->Id;
					sDatabase.Execute( bd.str().c_str( ) );

					objmgr.RemoveAuction(itr->second->Id);
				}
				else
				{
					Mail *m = new Mail;
					m->reciever = itr->second->owner;
					m->body = "";
					m->sender = itr->second->bidder;
					m->checked = 0;
					m->COD = 0;
					m->messageID = objmgr.GenerateMailID();
					m->money = itr->second->bid;
					m->time = time(NULL) + (29 * 3600);
					m->subject = "Your item sold!";
					m->item = 0;

					std::stringstream md;
					md << "DELETE FROM mail WHERE mailID = " << m->messageID;
					sDatabase.Execute( md.str().c_str( ) );

					std::stringstream mi;
					mi << "INSERT INTO mail (mailId,sender,reciever,subject,body,item,"
						"time,money,COD,checked) VALUES ( " << m->messageID << ", " << m->sender
						<< ", " << m->reciever << ",' " << m->subject.c_str() << "' ,' "
						<< m->body.c_str() << "', " << m->item << ", " << (uint32)m->time
						<< ", " << m->money << ", " << 0 << ", " << m->checked << " )";
					sDatabase.Execute( mi.str().c_str( ) );

					uint64 rcpl;
					GUID_LOPART(rcpl) = m->reciever;
					GUID_HIPART(rcpl) = 0;
					std::string pname;
					objmgr.GetPlayerNameByGUID(rcpl,pname);
					Player *rpl = objmgr.GetPlayer(pname.c_str());
					if (rpl)
					{
						rpl->AddMail(m);
					}

					Mail *mn = new Mail;
					mn->reciever = itr->second->bidder;
					mn->body = "";
					mn->sender = itr->second->owner;
					mn->checked = 0;
					mn->COD = 0;
					mn->messageID = objmgr.GenerateMailID();
					mn->money = 0;
					mn->time = time(NULL) + (29 * 3600);
					mn->subject = "Your won an item!";
					mn->item = itr->second->item;
					Item *it = objmgr.GetAItem(itr->second->item);
					objmgr.AddMItem(it);

					std::stringstream ss;
					ss << "INSERT INTO mailed_items (guid, data) VALUES ("
						<< it->GetGUIDLow() << ", '";
					for(uint16 i = 0; i < it->GetValuesCount(); ++i )
					{
						ss << it->GetUInt32Value(i) << " ";
					}
					ss << "' )";
					sDatabase.Execute( ss.str().c_str() );

					std::stringstream mdn;

					mdn << "DELETE FROM mail WHERE mailID = " << mn->messageID;
					sDatabase.Execute( mdn.str().c_str( ) );

					std::stringstream min;

					min << "INSERT INTO mail (mailId,sender,reciever,subject,body,"
						"item,time,money,COD,checked) VALUES ( "
						<< mn->messageID << ", " << mn->sender << ", " << mn->reciever
						<< ",' " << mn->subject.c_str() << "' ,' " << mn->body.c_str()
						<< "', " << mn->item << ", " << (uint32)mn->time << ", "
						<< mn->money << ", " << 0 << ", " << mn->checked << " )";

					sDatabase.Execute( min.str().c_str( ) );

					uint64 rcpl1;
					GUID_LOPART(rcpl1) = mn->reciever;
					GUID_HIPART(rcpl1) = 0;

					std::string pname1;
					objmgr.GetPlayerNameByGUID(rcpl1,pname1);
					Player *rpl1 = objmgr.GetPlayer(pname1.c_str());
					if (rpl1)
					{
						rpl1->AddMail(mn);
					}
					objmgr.RemoveAItem(itr->second->item);
					objmgr.RemoveAuction(itr->second->Id);
				}
			}
		}
	}

	if (m_Warden_Timer <= 0)
	{
		m_Warden_Timer = 720;
		ZThread::Guard<ZThread::Mutex> guard(m_sessions_lock);
		WorldPacket WardenPkt;

		sLog.outDetail("Initializing Full Warden Scan");
		WardenPkt.Initialize(SMSG_WARDEN_DATA);

		SessionMap::iterator itr;
		for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
		{
			itr->second->SendPacket(&WardenPkt);
		}
	}
	for (MapMgrMap::iterator iter = m_maps.begin(); iter != m_maps.end(); ++iter)
	{
		iter->second->Update(diff);
	}

	// When everything is safe, wipe recycles
	objmgr.WipeRecycles();
}
예제 #2
0
파일: World.cpp 프로젝트: Artea/mangos-svn
void World::Update(time_t diff)
{
    for(int i = 0; i < WUPDATE_COUNT; i++)
        if(m_timers[i].GetCurrent()>=0)
            m_timers[i].Update(diff);
    else m_timers[i].SetCurrent(0);

    _UpdateGameTime();

    if (m_timers[WUPDATE_AUCTIONS].Passed())
    {
        m_timers[WUPDATE_AUCTIONS].Reset();
        ObjectMgr::AuctionEntryMap::iterator itr,next;
        for (itr = objmgr.GetAuctionsBegin(); itr != objmgr.GetAuctionsEnd();itr = next)
        {
            next = itr;
            next++;
            if (time(NULL) > (itr->second->time))
            {
                if (itr->second->bidder == 0)               // if noone bidded auction...
                {
                    Item *it = objmgr.GetAItem(itr->second->item);
                    if(it)
                    {
                        Mail *m = new Mail;
                        m->receiver = itr->second->owner;
                        m->body = "";
                        m->sender = itr->second->owner;
                        m->checked = 0;
                        m->COD = 0;                         // there might be deposit
                        m->messageID = objmgr.GenerateMailID();
                        m->money = 0;
                        m->time = time(NULL) + (29 * 3600);
                        m->subject = "Your item failed to sell";
                        m->item = itr->second->item;
                        objmgr.AddMItem(it);

                        std::ostringstream ss;
                        ss << "INSERT INTO `mail_item` (`guid`,`data`) VALUES ("
                            << it->GetGUIDLow() << ", '";
                        for(uint16 i = 0; i < it->GetValuesCount(); i++ )
                        {
                            ss << it->GetUInt32Value(i) << " ";
                        }
                        ss << "' )";
                        sDatabase.Execute( ss.str().c_str() );

                        sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'",m->messageID);
                        sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", m->messageID, m->sender, m->receiver, m->subject.c_str(), m->body.c_str(), m->item, (uint64)m->time, m->money, 0, 0);

                        Player *rpl = objmgr.GetPlayer(m->receiver);
                        if (rpl)
                        {
                            rpl->AddMail(m);
                        }
                        else
                            delete m;
                    }
                    else
                        sLog.outError("Auction item %u not found, and lost.",itr->second->item);

                    sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `itemowner` = '%u'",itr->second->owner);
                    sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `id` = '%u'",itr->second->Id);
                    sDatabase.PExecute("DELETE FROM `auctionhouse_item` WHERE `guid` = '%u'",itr->second->item);

                    objmgr.RemoveAItem(itr->second->item);
                    objmgr.RemoveAuction(itr->second->Id);
                }
                else
                {
                    Mail *m = new Mail;
                    m->receiver = itr->second->owner;
                    m->body = "";
                    m->sender = itr->second->bidder;
                    m->checked = 0;
                    m->COD = 0;
                    m->messageID = objmgr.GenerateMailID();
                    m->money = itr->second->bid;
                    m->time = time(NULL) + (29 * 3600);
                    m->subject = "Your item sold!";
                    m->item = 0;

                    sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'",m->messageID);
                    sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", m->messageID, m->sender, m->receiver, m->subject.c_str(), m->body.c_str(), m->item, (uint64)m->time, m->money, 0, 0);

                    Player *rpl = objmgr.GetPlayer(m->receiver);
                    if (rpl)
                    {
                        rpl->AddMail(m);
                    }
                    else
                        delete m;

                    Mail *mn = new Mail;
                    mn->receiver = itr->second->bidder;
                    mn->body = "";
                    mn->sender = itr->second->owner;
                    mn->checked = 0;
                    mn->COD = 0;
                    mn->messageID = objmgr.GenerateMailID();
                    mn->money = 0;
                    mn->time = time(NULL) + (29 * 3600);
                    mn->subject = "Your won an item!";
                    mn->item = itr->second->item;
                    Item *it = objmgr.GetAItem(itr->second->item);
                    objmgr.AddMItem(it);

                    std::ostringstream ss;
                    ss << "INSERT INTO `mail_item` (`guid`,`data`) VALUES ("
                        << it->GetGUIDLow() << ", '";
                    for(uint16 i = 0; i < it->GetValuesCount(); i++ )
                    {
                        ss << it->GetUInt32Value(i) << " ";
                    }
                    ss << "' )";
                    sDatabase.Execute( ss.str().c_str() );

                    sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'", mn->messageID);
                    sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", mn->messageID, mn->sender, mn->receiver, mn->subject.c_str(), mn->body.c_str(), mn->item, (uint64)mn->time, mn->money, 0, 0);

                    Player *rpl1 = objmgr.GetPlayer(mn->receiver);
                    if (rpl1)
                    {
                        rpl1->AddMail(mn);
                    }
                    else
                        delete mn;

                    sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `id` = '%u'",itr->second->Id);
                    sDatabase.PExecute("DELETE FROM `auctionhouse_item` WHERE `guid` = '%u'",itr->second->item);

                    objmgr.RemoveAItem(itr->second->item);
                    objmgr.RemoveAuction(itr->second->Id);
                }
            }
        }
    }
    if (m_timers[WUPDATE_SESSIONS].Passed())
    {
        m_timers[WUPDATE_SESSIONS].Reset();

        SessionMap::iterator itr, next;
        for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next)
        {
            next = itr;
            next++;

            if(!itr->second->Update(diff))
            {
                delete itr->second;
                m_sessions.erase(itr);
            }
        }
    }

    if (m_timers[WUPDATE_WEATHERS].Passed())
    {
        m_timers[WUPDATE_WEATHERS].Reset();

        WeatherMap::iterator itr, next;
        for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next)
        {
            next = itr;
            next++;

            if(!itr->second->Update(diff))
            {
                delete itr->second;
                m_weathers.erase(itr);
            }
        }
    }

    if (m_timers[WUPDATE_OBJECTS].Passed())
    {
        m_timers[WUPDATE_OBJECTS].Reset();
        MapManager::Instance().Update(diff);
    }

    // move all creatures with delayed move and remove and delete all objects with delayed remove
    ObjectAccessor::Instance().DoDelayedMovesAndRemoves();
}