void WorldSession::HandleReturnToSender(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data,8+4); ObjectGuid mailboxGuid; uint32 mailId; recv_data >> mailboxGuid; recv_data >> mailId; recv_data.read_skip<uint64>(); // original sender GUID for return to, not used if (!CheckMailBox(mailboxGuid)) return; Player *pl = _player; Mail *m = pl->GetMail(mailId); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR); return; } //we can return mail now //so firstly delete the old one RealmDataDatabase.BeginTransaction(); RealmDataDatabase.PExecute("DELETE FROM mail WHERE id = '%u'", mailId); // needed? RealmDataDatabase.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", mailId); RealmDataDatabase.CommitTransaction(); pl->RemoveMail(mailId); // send back only to existing players and simple drop for other cases if (m->messageType == MAIL_NORMAL && m->sender) { MailDraft draft; if (m->mailTemplateId) draft.SetMailTemplate(m->mailTemplateId, false);// items already included else draft.SetSubjectAndBodyId(m->subject, m->itemTextId); if(m->HasItems()) { for(MailItemInfoVec::iterator itr = m->items.begin(); itr != m->items.end(); ++itr) { if(Item *item = pl->GetMItem(itr->item_guid)) draft.AddItem(item); else { //WTF? } pl->RemoveMItem(itr->item_guid); } } draft.SetMoney(m->money).SendReturnToSender(GetAccountId(), m->receiverGuid, ObjectGuid(HIGHGUID_PLAYER, m->sender)); } delete m; //we can deallocate old mail pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK); }
void WorldSession::SendExternalMails() { sLog->outCommand(0, "EXTERNAL MAIL> Sending mails in queue..."); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_EXTERNAL_MAIL); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (!result) { sLog->outCommand(0, "EXTERNAL MAIL> No mails in queue..."); return; } SQLTransaction trans = CharacterDatabase.BeginTransaction(); MailDraft* mail = NULL; do { Field *fields = result->Fetch(); uint32 id = fields[0].GetUInt32(); uint32 receiver_guid = fields[1].GetUInt32(); ObjectGuid receiverGuid(HIGHGUID_PLAYER, receiver_guid); std::string subject = fields[2].GetString(); std::string body = fields[3].GetString(); uint32 money = fields[4].GetUInt32(); uint32 itemId = fields[5].GetUInt32(); uint32 itemCount = fields[6].GetUInt32(); Player *receiver = ObjectAccessor::FindPlayer(receiverGuid); mail = new MailDraft(subject, body); if (money) { sLog->outCommand(0, "EXTERNAL MAIL> Adding money"); mail->AddMoney(money); } if (itemId) { sLog->outCommand(0, "EXTERNAL MAIL> Adding %u of item with id %u", itemCount, itemId); Item* mailItem = Item::CreateItem(itemId, itemCount); mailItem->SaveToDB(trans); mail->AddItem(mailItem); } mail->SendMailTo(trans, receiver ? receiver : MailReceiver(receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); delete mail; stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_EXTERNAL_MAIL); stmt->setUInt32(0, id); trans->Append(stmt); sLog->outCommand(0, "EXTERNAL MAIL> Mail sent"); } while (result->NextRow()); CharacterDatabase.CommitTransaction(trans); sLog->outCommand(0, "EXTERNAL MAIL> All Mails Sent..."); }
void WorldSession::SendExternalMails() { sLog.outDebug("External Mail - Send Mails from Queue..."); QueryResult* result = CharacterDatabase.Query("SELECT id,receiver,subject,message,money,item,item_count FROM mail_external"); if (!result) { sLog.outDebug("External Mail - No Mails in Queue..."); return; } else { do { Field *fields = result->Fetch(); uint32 id = fields[0].GetUInt32(); Player *pReceiver = sObjectMgr.GetPlayer(fields[1].GetUInt64()); std::string subject = fields[2].GetString(); std::string message = fields[3].GetString(); uint32 money = fields[4].GetUInt32(); uint32 ItemID = fields[5].GetUInt32(); uint32 ItemCount = fields[6].GetUInt32(); if (pReceiver) { MailDraft draft; draft.SetSubjectAndBody(subject, message); MailSender sender(MAIL_NORMAL, pReceiver ? pReceiver->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM); MailReceiver reciever(pReceiver, pReceiver->GetObjectGuid()); sLog.outDebug("External Mail - Sending mail to %u, Item:%u", pReceiver->GetObjectGuid().GetCounter(), ItemID); uint32 itemTextId = !message.empty() ? sObjectMgr.CreateItemText(message) : 0; if (ItemID != 0) { Item* ToMailItem = Item::CreateItem(ItemID, ItemCount, pReceiver); if (ToMailItem) { ToMailItem->SaveToDB(); draft.AddItem(ToMailItem); } draft.SetMoney(money); } else draft.SetMoney(money); draft.SendMailTo(reciever,sender,MAIL_CHECK_MASK_RETURNED); CharacterDatabase.PExecute("DELETE FROM mail_external WHERE id=%u", id); } else sLog.outDebug("External Mail - Mail with unknown player GUID %u in mail_external",fields[1].GetUInt32()); } while(result->NextRow()); } sLog.outDebug("External Mail - All Mails Sent..."); }
/** * Handles the Packet sent by the client when returning a mail to sender. * This method is called when a player chooses to return a mail to its sender. * It will create a new MailDraft and add the items, money, etc. associated with the mail * and then send the mail to the original sender. * * @param recv_data The packet containing information about the mail being returned. * */ void WorldSession::HandleMailReturnToSender(WorldPacket & recv_data ) { uint64 mailbox; uint32 mailId; recv_data >> mailbox; recv_data >> mailId; recv_data.read_skip<uint64>(); // original sender GUID for return to, not used if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player *pl = _player; Mail *m = pl->GetMail(mailId); if(!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR); return; } //we can return mail now //so firstly delete the old one CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM mail WHERE id = '%u'", mailId); // needed? CharacterDatabase.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", mailId); CharacterDatabase.CommitTransaction(); pl->RemoveMail(mailId); // send back only to existing players and simple drop for other cases if (m->messageType == MAIL_NORMAL && m->sender) { MailDraft draft; if (m->mailTemplateId) draft.SetMailTemplate(m->mailTemplateId, false);// items already included else draft.SetSubjectAndBodyId(m->subject, m->itemTextId); if(m->HasItems()) { for(std::vector<MailItemInfo>::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2) { if(Item *item = pl->GetMItem(itr2->item_guid)) draft.AddItem(item); pl->RemoveMItem(itr2->item_guid); } } draft.SetMoney(m->money).SendReturnToSender(GetAccountId(), m->receiverGuid, ObjectGuid(HIGHGUID_PLAYER, m->sender)); } delete m; // we can deallocate old mail pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK); }
void WorldSession::SendExternalMails() { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_EXTERNAL_MAIL); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (!result) { return; } SQLTransaction trans = CharacterDatabase.BeginTransaction(); MailDraft* mail = NULL; do { Field *fields = result->Fetch(); uint32 id = fields[0].GetUInt32(); uint32 receiver_guid = fields[1].GetUInt32(); std::string subject = fields[2].GetString(); std::string body = fields[3].GetString(); uint32 money = fields[4].GetUInt32(); uint32 itemId = fields[5].GetUInt32(); uint32 itemCount = fields[6].GetUInt32(); Player *receiver = sObjectMgr->GetPlayerByLowGUID(receiver_guid); mail = new MailDraft(subject, body); if (money) { mail->AddMoney(money); } if (itemId) { Item* mailItem = Item::CreateItem(itemId, itemCount); mailItem->SaveToDB(trans); mail->AddItem(mailItem); } mail->SendMailTo(trans, receiver ? receiver : MailReceiver(receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); delete mail; stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_EXTERNAL_MAIL); stmt->setUInt32(0, id); trans->Append(stmt); } while (result->NextRow()); CharacterDatabase.CommitTransaction(trans); }
void SendExternalMails() { QueryResult result = CharacterDatabase.PQuery(CHAR_GET_EXTERNAL_MAIL); if (!result) return; SQLTransaction trans = CharacterDatabase.BeginTransaction(); MailDraft* mail = NULL; do { Field *fields = result->Fetch(); uint32 id = fields[0].GetUInt32(); uint32 receiver_guid = fields[1].GetUInt32(); std::string subject = fields[2].GetString(); std::string body = fields[3].GetString(); uint32 money = fields[4].GetUInt32(); uint32 itemId = fields[5].GetUInt32(); uint32 itemCount = fields[6].GetUInt32(); Player* receiver = ObjectAccessor::FindPlayer(receiver_guid); mail = new MailDraft(subject, body); if (money) mail->AddMoney(money); if (itemId) { ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemId); if (pProto) { Item* mailItem = Item::CreateItem(itemId, itemCount); mailItem->SaveToDB(trans); mail->AddItem(mailItem); } else sLog->outError(LOG_FILTER_GENERAL, "EXTERNAL MAIL> Tried to add non-existing item with id %u, aborted", itemId); } mail->SendMailTo(trans, receiver ? receiver : MailReceiver(receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); delete mail; CharacterDatabase.PExecute(CHAR_DEL_EXTERNAL_MAIL, id); } while (result->NextRow()); CharacterDatabase.CommitTransaction(trans); }
void WorldSession::SendExternalMails() { sLog->outString("EXTERNAL MAIL> Sending mails in queue..."); QueryResult result = CharacterDatabase.Query("SELECT id,receiver,subject,message,money,item,item_count FROM mail_external"); SQLTransaction trans = CharacterDatabase.BeginTransaction(); if(!result) { sLog->outString("EXTERNAL MAIL> No mails in queue..."); // delete result; return; } else { uint32 last_id = 0; MailDraft* mail = NULL; uint32 last_receiver_guid; do { Field *fields = result->Fetch(); uint32 id = fields[0].GetUInt32(); uint64 receiver_guid = fields[1].GetUInt64(); std::string subject = fields[2].GetString(); std::string body = fields[3].GetString(); uint32 money = fields[4].GetUInt32(); uint32 itemId = fields[5].GetUInt32(); uint32 itemCount = fields[6].GetUInt32(); Player *receiver = sObjectMgr->GetPlayer( receiver_guid ); if (id != last_id) { // send mail if (last_id != 0) { sLog->outString("EXTERNAL MAIL> Sending mail to character with guid %d", last_receiver_guid); mail->SendMailTo(trans,MailReceiver(last_receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); delete mail; CharacterDatabase.PExecute("DELETE FROM mail_external WHERE id=%u", last_id); sLog->outString("EXTERNAL MAIL> Mail sent"); } //Create the maildraft mail = new MailDraft( subject, body ); if(money) { sLog->outString("EXTERNAL MAIL> Adding money"); mail->AddMoney(money); } } if (itemId) { sLog->outString("EXTERNAL MAIL> Adding %u of item with id %u", itemCount, itemId); Item* mailItem = Item::CreateItem( itemId, itemCount, receiver ); mailItem->SaveToDB(trans); mail->AddItem(mailItem); } last_id = id; last_receiver_guid = receiver_guid; } while( result->NextRow() ); // we only send a mail when mail_id!=last_mail_id, so we need to send the very last mail here: if (last_id != 0) { // send last mail sLog->outString("EXTERNAL MAIL> Sending mail to character with guid %d", last_receiver_guid); mail->SendMailTo(trans,MailReceiver(last_receiver_guid), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM), MAIL_CHECK_MASK_RETURNED); delete mail; CharacterDatabase.PExecute("DELETE FROM mail_external WHERE id=%u", last_id); sLog->outString("EXTERNAL MAIL> Mail sent"); } } CharacterDatabase.CommitTransaction(trans); sLog->outString("EXTERNAL MAIL> All Mails Sent..."); }