void WorldSession::HandleTakeItem(WorldPacket & recv_data ) { uint8 i,slot; uint64 mailbox; uint32 message; WorldPacket data; recv_data >> mailbox; recv_data >> message; Player* pl = GetPlayer(); Mail* m = pl->GetMail(message); Item *it = objmgr.GetMItem(m->item); m->item = 0; pl->AddMail(m); for(i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; i++) { if (GetPlayer()->GetItemBySlot(i) == NULL) { slot = i; break; } } it->SetUInt64Value(ITEM_FIELD_CONTAINED,pl->GetGUID()); it->SetUInt64Value(ITEM_FIELD_OWNER,pl->GetGUID()); GetPlayer()->AddItemToSlot(slot, it); objmgr.RemoveMItem(it->GetGUIDLow()); data.Initialize(SMSG_SEND_MAIL_RESULT); data << uint32(message); data << uint32(2); data << uint32(0); SendPacket(&data); }
void WorldSession::HandleMarkAsRead(WorldPacket & recv_data ) { uint64 mailbox; uint32 message; recv_data >> mailbox; recv_data >> message; Player *pl = GetPlayer(); Mail *m = pl->GetMail(message); m->checked = 1; m->time = time(NULL) + (3 * 3600); pl->AddMail(m); }
void WorldSession::HandleReturnToSender(WorldPacket & recv_data ) { uint64 mailbox; uint32 message; WorldPacket data; recv_data >> mailbox; recv_data >> message; Player *pl = GetPlayer(); Mail *m = pl->GetMail(message); m->reciever = m->sender; m->sender = pl->GetGUIDLow(); m->time = sWorld.GetGameTime() + (30 * 3600); m->checked = 0; pl->RemoveMail(message); data.Initialize(SMSG_SEND_MAIL_RESULT); data << uint32(message); data << uint32(3); data << uint32(0); SendPacket(&data); uint64 rc; GUID_LOPART(rc) = m->reciever; GUID_HIPART(rc) = 0; std::string name; objmgr.GetPlayerNameByGUID(rc,name); Player *recieve = objmgr.GetPlayer(name.c_str()); if (recieve) { recieve->AddMail(m); } std::stringstream delinvq; delinvq << "DELETE FROM mail WHERE mailID = " << m->messageID; // TODO: use full guids sDatabase.Execute( delinvq.str().c_str( ) ); std::stringstream ss; ss << "INSERT INTO mail (mailId,sender,reciever,subject,body,item,time,money,COD,checked) " "VALUES ( " << m->messageID << ", " << pl->GetGUIDLow() << ", " << m->reciever << ",' " << m->subject.c_str() << "' ,' " << m->body.c_str() << "', " << m->item << ", " << (uint32)m->time << ", " << m->money << ", " << 0 << ", " << m->checked << " )"; sDatabase.Execute( ss.str().c_str( ) ); }
void WorldSession::HandleTakeMoney(WorldPacket & recv_data ) { WorldPacket data; uint64 mailbox; uint32 id; recv_data >> mailbox; recv_data >> id; Player *pl = GetPlayer(); Mail* m = pl->GetMail(id); uint32 money = pl->GetUInt32Value(PLAYER_FIELD_COINAGE); data.Initialize(SMSG_SEND_MAIL_RESULT); data << uint32(id); data << uint32(1); data << uint32(0); SendPacket(&data); pl->SetUInt32Value(PLAYER_FIELD_COINAGE,money + m->money); m->money = 0; pl->AddMail(m); }
/** * Sends a mail. * * @param receiver The MailReceiver to which this mail is sent. * @param sender The MailSender from which this mail is originated. * @param checked The mask used to specify the mail. * @param deliver_delay The delay after which the mail is delivered in seconds */ void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked, uint32 deliver_delay) { Player* pReceiver = receiver.GetPlayer(); // can be NULL uint32 pReceiverAccount = 0; if (!pReceiver) pReceiverAccount = sObjectMgr.GetPlayerAccountIdByGUID(receiver.GetPlayerGuid()); if (!pReceiver && !pReceiverAccount) // receiver not exist { deleteIncludedItems(true); return; } bool has_items = !m_items.empty(); // generate mail template items for online player, for offline player items will generated at open if (pReceiver) { if (prepareItems(pReceiver)) has_items = true; } uint32 mailId = sObjectMgr.GenerateMailID(); time_t deliver_time = time(NULL) + deliver_delay; uint32 expire_delay; // auction mail without any items and money (auction sale note) pending 1 hour if (sender.GetMailMessageType() == MAIL_AUCTION && m_items.empty() && !m_money) expire_delay = HOUR; // default case: expire time if COD 3 days, if no COD 30 days else expire_delay = (m_COD > 0) ? 3 * DAY : 30 * DAY; time_t expire_time = deliver_time + expire_delay; // Add to DB std::string safe_subject = GetSubject(); CharacterDatabase.escape_string(safe_subject); std::string safe_body = GetBody(); CharacterDatabase.escape_string(safe_body); CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("INSERT INTO mail (id,messageType,stationery,mailTemplateId,sender,receiver,subject,body,has_items,expire_time,deliver_time,money,cod,checked) " "VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '%s', '%s', '%u', '" UI64FMTD "','" UI64FMTD "', '%u', '%u', '%u')", mailId, sender.GetMailMessageType(), sender.GetStationery(), GetMailTemplateId(), sender.GetSenderId(), receiver.GetPlayerGuid().GetCounter(), safe_subject.c_str(), safe_body.c_str(), (has_items ? 1 : 0), (uint64)expire_time, (uint64)deliver_time, m_money, m_COD, checked); for(MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) { Item* item = mailItemIter->second; CharacterDatabase.PExecute("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver) VALUES ('%u', '%u', '%u','%u')", mailId, item->GetGUIDLow(), item->GetEntry(), receiver.GetPlayerGuid().GetCounter()); } CharacterDatabase.CommitTransaction(); // For online receiver update in game mail status and data if (pReceiver) { pReceiver->AddNewMailDeliverTime(deliver_time); Mail *m = new Mail; m->messageID = mailId; m->mailTemplateId = GetMailTemplateId(); m->subject = GetSubject(); m->body = GetBody(); m->money = GetMoney(); m->COD = GetCOD(); for(MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) { Item* item = mailItemIter->second; m->AddItem(item->GetGUIDLow(), item->GetEntry()); } m->messageType = sender.GetMailMessageType(); m->stationery = sender.GetStationery(); m->sender = sender.GetSenderId(); m->receiverGuid = receiver.GetPlayerGuid(); m->expire_time = expire_time; m->deliver_time = deliver_time; m->checked = checked; m->state = MAIL_STATE_UNCHANGED; pReceiver->AddMail(m); // to insert new mail to beginning of maillist if (!m_items.empty()) { for(MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) pReceiver->AddMItem(mailItemIter->second); } } else if (!m_items.empty()) deleteIncludedItems(); }
void MailDraft::SendMailTo(SQLTransaction& trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked, uint32 deliver_delay) { Player* pReceiver = receiver.GetPlayer(); // can be NULL Player* pSender = sObjectMgr->GetPlayerByLowGUID(sender.GetSenderId()); if (pReceiver) prepareItems(pReceiver, trans); // generate mail template items uint32 mailId = sObjectMgr->GenerateMailID(); time_t deliver_time = time(NULL) + deliver_delay; //expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour uint32 expire_delay; // auction mail without any items and money if (sender.GetMailMessageType() == MAIL_AUCTION && m_items.empty() && !m_money) expire_delay = sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY); // mail from battlemaster (rewardmarks) should last only one day else if (sender.GetMailMessageType() == MAIL_CREATURE && sBattlegroundMgr->GetBattleMasterBG(sender.GetSenderId()) != BATTLEGROUND_TYPE_NONE) expire_delay = DAY; // default case: expire time if COD 3 days, if no COD 30 days (or 90 days if sender is a game master) else { if (m_COD) expire_delay = 3 * DAY; else expire_delay = pSender && pSender->IsGameMaster() ? 90 * DAY : 30 * DAY; } time_t expire_time = deliver_time + expire_delay; // Add to DB uint8 index = 0; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_MAIL); stmt->setUInt32( index, mailId); stmt->setUInt8 (++index, uint8(sender.GetMailMessageType())); stmt->setInt8 (++index, int8(sender.GetStationery())); stmt->setUInt16(++index, GetMailTemplateId()); stmt->setUInt32(++index, sender.GetSenderId()); stmt->setUInt32(++index, receiver.GetPlayerGUIDLow()); stmt->setString(++index, GetSubject()); stmt->setString(++index, GetBody()); stmt->setBool (++index, !m_items.empty()); stmt->setUInt64(++index, uint64(expire_time)); stmt->setUInt64(++index, uint64(deliver_time)); stmt->setUInt32(++index, m_money); stmt->setUInt32(++index, m_COD); stmt->setUInt8 (++index, uint8(checked)); trans->Append(stmt); for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) { Item* pItem = mailItemIter->second; stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_MAIL_ITEM); stmt->setUInt32(0, mailId); stmt->setUInt32(1, pItem->GetGUID().GetCounter()); stmt->setUInt32(2, receiver.GetPlayerGUIDLow()); trans->Append(stmt); } // For online receiver update in game mail status and data if (pReceiver) { pReceiver->AddNewMailDeliverTime(deliver_time); if (pReceiver->IsMailsLoaded()) { Mail* m = new Mail; m->messageID = mailId; m->mailTemplateId = GetMailTemplateId(); m->subject = GetSubject(); m->body = GetBody(); m->money = GetMoney(); m->COD = GetCOD(); for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) { Item* item = mailItemIter->second; m->AddItem(item->GetGUID().GetCounter(), item->GetEntry()); } m->messageType = sender.GetMailMessageType(); m->stationery = sender.GetStationery(); m->sender = sender.GetSenderId(); m->receiver = receiver.GetPlayerGUIDLow(); m->expire_time = expire_time; m->deliver_time = deliver_time; m->checked = checked; m->state = MAIL_STATE_UNCHANGED; pReceiver->AddMail(m); // to insert new mail to beginning of maillist if (!m_items.empty()) { for (MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) pReceiver->AddMItem(mailItemIter->second); } } else if (!m_items.empty()) { SQLTransaction temp = SQLTransaction(NULL); deleteIncludedItems(temp); } } else if (!m_items.empty()) { SQLTransaction temp = SQLTransaction(NULL); deleteIncludedItems(temp); } }
void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked, uint32 deliver_delay) { Player* pReceiver = receiver.GetPlayer(); // can be NULL if (pReceiver) prepareItems(pReceiver); // generate mail template items uint32 mailId = objmgr.GenerateMailID(); time_t deliver_time = time(NULL) + deliver_delay; uint32 expire_delay; // auction mail without any items and money (auction sale note) pending 1 hour if (sender.GetMailMessageType() == MAIL_AUCTION && m_items.empty() && !m_money) expire_delay = HOUR; // mail from battlemaster (rewardmarks) should last only one day else if (sender.GetMailMessageType() == MAIL_CREATURE && sBattleGroundMgr.GetBattleMasterBG(sender.GetSenderId()) != BATTLEGROUND_TYPE_NONE) expire_delay = DAY; // default case: expire time if COD 3 days, if no COD 30 days else expire_delay = (m_COD > 0) ? 3 * DAY : 30 * DAY; time_t expire_time = deliver_time + expire_delay; // Add to DB std::string safe_subject = GetSubject(); CharacterDatabase.BeginTransaction(); CharacterDatabase.escape_string(safe_subject); CharacterDatabase.PExecute("INSERT INTO mail (id,messageType,stationery,mailTemplateId,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked) " "VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '%s', '%u', '%u', '" UI64FMTD "','" UI64FMTD "', '%u', '%u', '%d')", mailId, sender.GetMailMessageType(), sender.GetStationery(), GetMailTemplateId(), sender.GetSenderId(), receiver.GetPlayerGUIDLow(), safe_subject.c_str(), GetBodyId(), (m_items.empty() ? 0 : 1), (uint64)expire_time, (uint64)deliver_time, m_money, m_COD, checked); for(MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) { Item* item = mailItemIter->second; CharacterDatabase.PExecute("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver) VALUES ('%u', '%u', '%u','%u')", mailId, item->GetGUIDLow(), item->GetEntry(), receiver.GetPlayerGUIDLow()); } CharacterDatabase.CommitTransaction(); // For online receiver update in game mail status and data if (pReceiver) { pReceiver->AddNewMailDeliverTime(deliver_time); if (pReceiver->IsMailsLoaded()) { Mail *m = new Mail; m->messageID = mailId; m->mailTemplateId = GetMailTemplateId(); m->subject = GetSubject(); m->itemTextId = GetBodyId(); m->money = GetMoney(); m->COD = GetCOD(); for(MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) { Item* item = mailItemIter->second; m->AddItem(item->GetGUIDLow(), item->GetEntry()); } m->messageType = sender.GetMailMessageType(); m->stationery = sender.GetStationery(); m->sender = sender.GetSenderId(); m->receiver = receiver.GetPlayerGUIDLow(); m->expire_time = expire_time; m->deliver_time = deliver_time; m->checked = checked; m->state = MAIL_STATE_UNCHANGED; pReceiver->AddMail(m); // to insert new mail to beginning of maillist if (!m_items.empty()) { for(MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter) pReceiver->AddMItem(mailItemIter->second); } } else if (!m_items.empty()) deleteIncludedItems(); } else if (!m_items.empty()) deleteIncludedItems(); }
void WorldSession::HandleSendMail(WorldPacket & recv_data ) { time_t base = time(NULL); time_t etime = base + (30 * 3600); WorldPacket data; uint64 sender,item; std::string reciever,subject,body; uint32 unk1,unk2,money,COD,mID; recv_data >> sender; recv_data >> reciever >> subject >> body; recv_data >> unk1 >> unk2; recv_data >> item; recv_data >> money >> COD; Log::getSingleton().outString("Player %u is sending mail to %s with subject %s and body %s includes item %u and %u copper and %u COD copper",GUID_LOPART(sender),reciever.c_str(),subject.c_str(),body.c_str(),GUID_LOPART(item),money,COD); mID = objmgr.GenerateMailID(); data.Initialize(SMSG_SEND_MAIL_RESULT); data << uint32(0); data << uint32(0); data << uint32(0); SendPacket(&data); Player* pl = GetPlayer(); if (item != 0) { uint32 slot = pl->GetSlotByItemGUID(item); Item *it = pl->GetItemBySlot((uint8)slot); objmgr.AddMItem(it); std::stringstream ss; ss << "INSERT INTO mailed_items (guid, data) VALUES (" << it->GetGUIDLow() << ", '"; // TODO: use full guids for(uint16 i = 0; i < it->GetValuesCount(); i++ ) { ss << it->GetUInt32Value(i) << " "; } ss << "' )"; sDatabase.Execute( ss.str().c_str() ); pl->RemoveItemFromSlot((uint8)slot); } uint32 playerGold = pl->GetUInt32Value(PLAYER_FIELD_COINAGE); pl->SetUInt32Value( PLAYER_FIELD_COINAGE, playerGold - 30 - money ); uint64 rc = objmgr.GetPlayerGUIDByName(reciever.c_str()); Player *recieve = objmgr.GetPlayer(reciever.c_str()); if (recieve) { Mail* m = new Mail; m->messageID = mID; m->sender = GUID_LOPART(sender); m->reciever = GUID_LOPART(rc); m->subject = subject; m->body = body; m->item = GUID_LOPART(item); m->money = money; m->time = etime; m->COD = 0; m->checked = 0; recieve->AddMail(m); } std::stringstream delinvq; // TODO: use full guids delinvq << "DELETE FROM mail WHERE mailID = " << mID; sDatabase.Execute( delinvq.str().c_str( ) ); std::stringstream ss; ss << "INSERT INTO mail (mailId,sender,reciever,subject,body,item,time,money,COD,checked) VALUES ( " << mID << ", " << pl->GetGUIDLow() << ", " << GUID_LOPART(rc) << ",' " << subject.c_str() << "' ,' " << body.c_str() << "', " << GUID_LOPART(item) << ", " << etime << ", " << money << ", " << 0 << ", " << 0 << " )"; sDatabase.Execute( ss.str().c_str( ) ); }
void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) { uint64 auctioneer; uint32 auction,price; WorldPacket data; recv_data >> auctioneer; recv_data >> auction >> price; AuctionEntry *ah = objmgr.GetAuction(auction); Player *pl = GetPlayer(); if ((ah) && (ah->owner != pl->GetGUIDLow())) { if ((price < ah->buyout) || (ah->buyout == 0)) { Mail* n = new Mail; n->messageID = objmgr.GenerateMailID(); n->sender = ah->owner; n->reciever = ah->bidder; n->subject = "You have lost a bid"; n->body = ""; n->item = 0; n->money = ah->bid; n->time = time(NULL) + (30 * 3600); n->COD = 0; n->checked = 0; uint64 rc; GUID_LOPART(rc) = ah->bidder; GUID_HIPART(rc) = 0; std::string name; objmgr.GetPlayerNameByGUID(rc,name); Player *rpl = objmgr.GetPlayer(name.c_str()); std::stringstream ss; ss << "INSERT INTO mail (mailId,sender,reciever,subject,body,item,time,money,COD,checked) VALUES ( " << n->messageID << ", " << n->sender << ", " << n->reciever << ",' " << n->subject.c_str() << "' ,' " << n->body.c_str() << "', " << n->item << ", " << n->time << ", " << n->money << ", " << n->COD << ", " << n->checked << " )"; sDatabase.Execute( ss.str().c_str( ) ); if (rpl) { rpl->AddMail(n); } ah->bidder = pl->GetGUIDLow(); ah->bid = price; objmgr.RemoveAuction(ah->Id); objmgr.AddAuction(ah); bidentry *be = new bidentry; be->AuctionID = auction; be->amt = price; pl->SetUInt32Value(PLAYER_FIELD_COINAGE,(pl->GetUInt32Value(PLAYER_FIELD_COINAGE) - price)); bidentry *bo = pl->GetBid(auction); if (bo) { Mail* m = new Mail; m->messageID = objmgr.GenerateMailID(); m->sender = ah->owner; m->reciever = pl->GetGUIDLow(); m->subject = "You have lost a bid"; m->body = ""; m->item = 0; m->money = bo->amt; m->time = time(NULL) + (30 * 3600); m->COD = 0; m->checked = 0; pl->AddMail(m); } pl->AddBid(be); uint64 guid = auctioneer; data.Initialize( SMSG_AUCTION_BIDDER_LIST_RESULT ); uint32 cnt = 0; std::list<bidentry*>::iterator itr; for (itr = pl->GetBidBegin(); itr != pl->GetBidEnd(); itr++) { AuctionEntry *ae = objmgr.GetAuction((*itr)->AuctionID); if (ae->auctioneer = GUID_LOPART(guid)) { cnt++; } } if (cnt < 51) { data << cnt; } else { data << uint32(50); } uint32 cnter = 1; for (itr = pl->GetBidBegin(); itr != pl->GetBidEnd(); itr++) { AuctionEntry *ae = objmgr.GetAuction((*itr)->AuctionID); if ((ae->auctioneer = GUID_LOPART(guid)) && (cnter < 33)) { data << ae->Id; Item *it = objmgr.GetAItem(ae->item); data << it->GetUInt32Value(OBJECT_FIELD_ENTRY); data << uint32(0); data << uint32(0); data << uint32(0); data << uint32(1); data << uint32(0); data << it->GetUInt64Value(ITEM_FIELD_OWNER); data << ae->bid; data << uint32(0); data << ae->buyout; data << uint32((ae->time - time(NULL)) * 1000); data << uint64(0); data << ae->bid; cnter++; } } data << cnt; SendPacket(&data); data.clear(); data.Initialize( SMSG_AUCTION_LIST_RESULT ); data << uint32(0); data << uint32(0); SendPacket(&data); } else { pl->SetUInt32Value(PLAYER_FIELD_COINAGE,(pl->GetUInt32Value(PLAYER_FIELD_COINAGE) - ah->buyout)); Mail *m = new Mail; m->messageID = objmgr.GenerateMailID(); m->sender = ah->owner; m->reciever = pl->GetGUIDLow(); m->subject = "You won an item!"; m->body = ""; m->checked = 0; m->COD = 0; m->money = 0; m->item = ah->item; m->time = time(NULL) + (29 * 3600); Item *it = objmgr.GetAItem(ah->item); objmgr.AddMItem(it); std::stringstream ss; ss << "INSERT INTO mailed_items (guid, data) VALUES (" << it->GetGUIDLow() << ", '"; // TODO: use full guids for(uint16 i = 0; i < it->GetValuesCount(); i++ ) { ss << it->GetUInt32Value(i) << " "; } ss << "' )"; sDatabase.Execute( ss.str().c_str() ); std::stringstream md; // TODO: use full guids 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 << ", " << pl->GetGUIDLow() << ", " << m->reciever << ",' " << m->subject.c_str() << "' ,' " << m->body.c_str() << "', " << m->item << ", " << 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; // TODO: use full guids delinvq << "DELETE FROM auctionhouse WHERE itemowner = " << ah->owner; sDatabase.Execute( delinvq.str().c_str( ) ); // TODO: use full guids id << "DELETE FROM auctioned_items WHERE guid = " << ah->item; sDatabase.Execute( id.str().c_str( ) ); // TODO: use full guids bd << "DELETE FROM bids WHERE Id = " << ah->Id; sDatabase.Execute( bd.str().c_str( ) ); data.Initialize( SMSG_AUCTION_LIST_RESULT ); data << uint32(0); data << uint32(0); SendPacket(&data); Mail *mn = new Mail; mn->messageID = objmgr.GenerateMailID(); mn->sender = ah->bidder; mn->reciever = ah->owner; mn->subject = "Your item sold!"; mn->body = ""; mn->checked = 0; mn->COD = 0; mn->money = ah->bid; mn->item = 0; mn->time = time(NULL) + (29 * 3600); std::stringstream mdn; // TODO: use full guids 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 << ", " << mn->time << ", " << mn->money << ", " << 0 << ", " << mn->checked << " )"; sDatabase.Execute( min.str().c_str( ) ); uint64 rcpln; GUID_LOPART(rcpln) = mn->reciever; GUID_HIPART(rcpln) = 0; std::string pnamen; objmgr.GetPlayerNameByGUID(rcpln,pnamen); Player *rpln = objmgr.GetPlayer(pnamen.c_str()); if (rpln) { rpln->AddMail(mn); } objmgr.RemoveAItem(ah->item); objmgr.RemoveAuction(ah->Id); } } }
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(); }
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(); }