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 SQLTransaction trans = CharacterDatabase.BeginTransaction(); trans->PAppend("DELETE FROM mail WHERE id = '%u'", mailId); // needed? trans->PAppend("DELETE FROM mail_items WHERE mail_id = '%u'", mailId); CharacterDatabase.CommitTransaction(trans); pl->RemoveMail(mailId); // only return mail if the player exists (and delete if not existing) if (m->messageType == MAIL_NORMAL && m->sender) { MailDraft draft(m->subject, m->body); if (m->mailTemplateId) draft = MailDraft(m->mailTemplateId, false); // items already included if (m->HasItems()) { for (std::vector<MailItemInfo>::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2) { Item *item = pl->GetMItem(itr2->item_guid); if (item) draft.AddItem(item); else { //WTF? } pl->RemoveMItem(itr2->item_guid); } } draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiver, m->sender); } delete m; //we can deallocate old mail pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK); }
/** * 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.SetSubjectAndBody(m->subject, m->body); if(m->HasItems()) { for(MailItemInfoVec::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::HandleReturnToSender(WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,8+4); uint64 mailbox; uint32 mailId; recv_data >> mailbox; recv_data >> mailId; 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); MailItemsInfo mi; if(m->HasItems()) { for(std::vector<MailItemInfo>::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2) { Item *item = pl->GetMItem(itr2->item_guid); if(item) mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item); else { //WTF? } pl->RemoveMItem(itr2->item_guid); } } if (m->sender == auctionbot.GetAHBplayerGUID()) { SendReturnToSender(MAIL_CREATURE, GetAccountId(), m->receiver, m->sender, m->subject, m->itemTextId, &mi, m->money, m->mailTemplateId); } else { SendReturnToSender(MAIL_NORMAL, GetAccountId(), m->receiver, m->sender, m->subject, m->itemTextId, &mi, m->money, m->mailTemplateId); } delete m; //we can deallocate old mail pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, 0); }
/** Test mail empty Given a mail of uint32_t data with size of 1 before data is inserted the mail shouldn't be full after data is inserted the mail should be full */ void test_mail_full() { Mail<mail_t, 1> m; mail_t *mail = m.alloc(); TEST_ASSERT_EQUAL(false, m.full()); m.put(mail); TEST_ASSERT_EQUAL(true, m.full()); }
void send_thread (void const *argument) { uint32_t i = 0; while (true) { i++; // fake data update mail_t *mail = mail_box.alloc(); mail->voltage = (i * 0.1) * 33; mail->current = (i * 0.1) * 11; mail->counter = i; mail_box.put(mail); Thread::wait(1000); } }
void send_thread (void const *argument) { static uint32_t i = 10; while (true) { i++; // fake data update mail_t *mail = mail_box.alloc(); mail->voltage = CREATE_VOLTAGE(i); mail->current = CREATE_CURRENT(i); mail->counter = i; mail_box.put(mail); Thread::wait(QUEUE_PUT_DELAY); } }
/** Test Serial / CDC line coding change * * Given the device transmits a set of line coding params to host * When the host updates serial port settings * Then line_coding_changed() callback is called * and the line coding is set as expected */ void test_serial_line_coding_change() { TestUSBSerial usb_serial(USB_SERIAL_VID, USB_SERIAL_PID, 1, usb_dev_sn); usb_serial.connect(); greentea_send_kv(MSG_KEY_CHANGE_LINE_CODING, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); usb_serial.attach(line_coding_changed_cb); size_t num_line_codings = sizeof test_codings / sizeof test_codings[0]; line_coding_t *lc_prev = &default_lc; line_coding_t *lc_expected = NULL; line_coding_t *lc_actual = NULL; int num_expected_callbacks, rc; for (size_t i = 0; i < num_line_codings; i++) { lc_expected = &(test_codings[i]); num_expected_callbacks = lc_prev->get_num_diffs(*lc_expected); rc = usb_serial.printf("%06i,%02i,%01i,%01i", lc_expected->baud, lc_expected->bits, lc_expected->parity, lc_expected->stop); TEST_ASSERT_EQUAL_INT(LINE_CODING_STRLEN, rc); // The pyserial Python module does not update all line coding params // at once. It updates params one by one instead, and since every // update is followed by port reconfiguration we get multiple // calls to line_coding_changed callback on the device. while (num_expected_callbacks > 0) { num_expected_callbacks--; osEvent event = lc_mail.get(); TEST_ASSERT_EQUAL_UINT32(osEventMail, event.status); lc_actual = (line_coding_t *) event.value.p; if (lc_expected->get_num_diffs(*lc_actual) == 0) { break; } else if (num_expected_callbacks > 0) { // Discard lc_actual only if there is still a chance to get new // set of params. lc_mail.free(lc_actual); } } TEST_ASSERT_EQUAL_INT(lc_expected->baud, lc_actual->baud); TEST_ASSERT_EQUAL_INT(lc_expected->bits, lc_actual->bits); TEST_ASSERT_EQUAL_INT(lc_expected->parity, lc_actual->parity); TEST_ASSERT_EQUAL_INT(lc_expected->stop, lc_actual->stop); lc_mail.free(lc_actual); lc_prev = lc_expected; } // Wait for the host to close its port. while (usb_serial.ready()) { wait_ms(1); } usb_serial.disconnect(); }
void WorldSession::HandleMailReturnToSender(WorldPackets::Mail::MailReturnToSender& packet) { //TODO: find a proper way to replace this check. Idea: Save Guid form MailGetList until CMSG_CLOSE_INTERACTION is sent /*if (!CanOpenMailBox(mailbox)) return;*/ Player* player = _player; Mail* m = player->GetMail(packet.MailID); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(nullptr) || m->sender != packet.SenderGUID.GetCounter()) { player->SendMailResult(packet.MailID, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR); return; } //we can return mail now, so firstly delete the old one SQLTransaction trans = CharacterDatabase.BeginTransaction(); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_BY_ID); stmt->setUInt32(0, packet.MailID); trans->Append(stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM_BY_ID); stmt->setUInt32(0, packet.MailID); trans->Append(stmt); player->RemoveMail(packet.MailID); // only return mail if the player exists (and delete if not existing) if (m->messageType == MAIL_NORMAL && m->sender) { MailDraft draft(m->subject, m->body); if (m->mailTemplateId) draft = MailDraft(m->mailTemplateId, false); // items already included if (m->HasItems()) { for (MailItemInfoVec::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2) { if (Item* const item = player->GetMItem(itr2->item_guid)) draft.AddItem(item); player->RemoveMItem(itr2->item_guid); } } draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiver, m->sender, trans); } CharacterDatabase.CommitTransaction(trans); delete m; //we can deallocate old mail player->SendMailResult(packet.MailID, MAIL_RETURNED_TO_SENDER, MAIL_OK); }
int main (void) { Thread thread(send_thread); while (true) { osEvent evt = mail_box.get(); if (evt.status == osEventMail) { mail_t *mail = (mail_t*)evt.value.p; printf("\nVoltage: %.2f V\n\r" , mail->voltage); printf("Current: %.2f A\n\r" , mail->current); printf("Number of cycles: %u\n\r", mail->counter); mail_box.free(mail); } } }
QScriptValue Mail::constructor(QScriptContext *context, QScriptEngine *engine) { Mail *mail = new Mail; QScriptValueIterator it(context->argument(0)); while(it.hasNext()) { it.next(); if(it.name() == "username") mail->setUsername(it.value().toString()); else if(it.name() == "password") mail->setPassword(it.value().toString()); else if(it.name() == "onConnected") mail->mOnConnected = it.value(); else if(it.name() == "onConnectionFailed") mail->mOnConnectionFailed = it.value(); else if(it.name() == "onEncrypted") mail->mOnEncrypted = it.value(); else if(it.name() == "onEncryptionFailed") mail->mOnEncryptionFailed = it.value(); else if(it.name() == "onAuthenticated") mail->mOnAuthenticated = it.value(); else if(it.name() == "onAuthenticationFailed") mail->mOnAuthenticationFailed = it.value(); else if(it.name() == "onSenderRejected") mail->mOnSenderRejected = it.value(); else if(it.name() == "onRecipientRejected") mail->mOnRecipientRejected = it.value(); else if(it.name() == "onMailFailed") mail->mOnMailFailed = it.value(); else if(it.name() == "onMailSent") mail->mOnMailSent = it.value(); else if(it.name() == "onFinished") mail->mOnFinished = it.value(); else if(it.name() == "onDisconnected") mail->mOnDisconnected = it.value(); } return CodeClass::constructor(mail, context, engine); }
// --------------------------------------------------------------------------------- void KReportTable::export_data_to_file() { Uuid const&id = _M_data_model->report().reportType().id(); //fetching the target file name from the most recent representation of the report type (instead of using the cached report type definition): QString filename = context()->reportManager()->load ( id ).exportDataFileName ( _M_data_model->report() ); filename = KFileDialog::getSaveFileName ( detail::url ( filename ), QString(), 0, i18n ( "Export Report Data to" ) ); if ( filename.isEmpty() ) {return;} QFile out ( filename ); QFileInfo out_info ( out ); if ( out_info.exists() ) { if ( KMessageBox::questionYesNo ( 0, i18n ( "The target file <b>'%1'</b> already exists. Do you really want to overwrite it?" ).arg ( filename ), i18n ( "File already exists - Don't Panik" ) ) == KMessageBox::No ) { return; } } if ( !out.open ( QIODevice::WriteOnly ) ) { KMessageBox::error ( 0, i18n ( "Unable to export Report Data to file <b>'%1'</b>." ).arg ( filename ), i18n ( "Report Export Error" ) ); return; } out.write ( _M_data_model->report().reportData().exportDataString().toAscii() ); out.close(); KDialog *dlg = new ReportExportedSuccessfullyDialog ( out_info, this ); int result = KMessageBox::createKMessageBox ( dlg , QMessageBox::Information , i18n ( "Report exported successfully to <b>'%1'</b>." ).arg ( filename ) , QStringList() , QString ( "" ) , 0 , KMessageBox::Notify ); if ( result == KDialog::User1 ) { Mail mail; mail.setSubject ( out_info.fileName() ); mail.addAttachement ( out_info.absoluteFilePath() ); MailInterface interface; interface.send ( mail ); } }
int32_t main (int32_t argc,char *argv[]) { // we need 2 or 4 arguments! if (argc!=2 && argc!=4) { cout << "Usage: ./eval_flow result_sha [user_sha email]" << endl; return 1; } // read arguments string result_sha = argv[1]; // init notification mail Mail *mail; if (argc==4) mail = new Mail(argv[3]); else mail = new Mail(); mail->msg("Thank you for participating in our evaluation!"); // run evaluation if (eval(result_sha,mail)) { mail->msg("Your evaluation results are available at:"); mail->msg("http://www.cvlibs.net/datasets/kitti/user_submit_check_login.php?benchmark=flow&user=%s&result=%s",argv[2], result_sha.c_str()); } else { system(("rm -r results/" + result_sha).c_str()); mail->msg("An error occured while processing your results."); mail->msg("Please make sure that the data in your zip archive has the right format!"); } // send mail and exit delete mail; return 0; }
// Send speed, accelerometer and brake values to a 100 element MAIL queue // car mail semaphore used to protect messages // average speed and input semphore used to fix vales // Repetition rate 0.2 Hz = 5 seconds void sendToMail(void const *args){ while(true){ mail_t *mail = mail_box.alloc(); CAR_MAIL_SEM.wait(); AVR_SPEED_SEM.wait(); mail->speedVal = averageSpeed; AVR_SPEED_SEM.release(); INPUT_SEM.wait(); mail->accelerometerVal = accelerationValue; mail->breakVal = brakeValue; INPUT_SEM.release(); write++; mail_box.put(mail); CAR_MAIL_SEM.release(); Thread::wait(5000); } }
//Normal priority thread (consumer) void thread1() { static int count = 0; while (true) { //Block on the queue osEvent evt = mail_box.get(); //Check status if (evt.status == osEventMail) { message_t *pMessage = (message_t*)evt.value.p; //This is the pointer (address) //Make a copy message_t msg(pMessage->adcValue, pMessage->sw1State, pMessage->sw2State); //We are done with this, so give back the memory to the pool mail_box.free(pMessage); //Echo to the terminal printf("ADC Value: %.2f\t", msg.adcValue); printf("SW1: %u\t", msg.sw1State); printf("SW2: %u\n\r", msg.sw2State); //Update state if ((msg.sw1State == 1) && (msg.sw2State == 1)) { count++; } else { count = 0; } if (count == 10) { greenLED = !greenLED; count = 0; } } else { printf("ERROR: %x\n\r", evt.status); } } //end while }
// Call this on precise intervals void adcISR() { //Read sample - make a copy float sample = adcIn; //Grab switch state uint32_t switch1State = sw1; uint32_t switch2State = sw2; //Allocate a block from the memory pool message_t *message = mail_box.alloc(); if (message == NULL) { //Out of memory printf("Out of memory\n\r"); redLED = 1; return; } //Fill in the data message->adcValue = sample; message->sw1State = switch1State; message->sw2State = switch2State; //Write to queue osStatus stat = mail_box.put(message); //Note we are sending the "pointer" //Check if succesful if (stat == osErrorResource) { redLED = 1; printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat); mail_box.free(message); return; } }
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); } }
//called when player takes item attached in mail void WorldSession::HandleTakeItem(WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,8+4+4); uint64 mailbox; uint32 mailId; uint32 itemId; recv_data >> mailbox; recv_data >> mailId; recv_data >> itemId; // item guid low? Player* pl = _player; Mail* m = pl->GetMail(mailId); if(!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // prevent cheating with skip client money check if(pl->GetMoney() < m->COD) { pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_NOT_ENOUGH_MONEY); return; } Item *it = pl->GetMItem(itemId); ItemPosCountVec dest; uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, it, false ); if( msg == EQUIP_ERR_OK ) { m->RemoveItem(itemId); m->removedItems.push_back(itemId); if (m->COD > 0) //if there is COD, take COD money from player and send them to sender by mail { uint64 sender_guid = MAKE_NEW_GUID(m->sender, 0, HIGHGUID_PLAYER); Player *receive = objmgr.GetPlayer(sender_guid); uint32 sender_accId = 0; if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) { std::string sender_name; if(receive) { sender_accId = receive->GetSession()->GetAccountId(); sender_name = receive->GetName(); } else { // can be calculated early sender_accId = objmgr.GetPlayerAccountIdByGUID(sender_guid); if(!objmgr.GetPlayerNameByGUID(sender_guid,sender_name)) sender_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN); } sLog.outCommand(GetAccountId(),"GM %s (Account: %u) receive mail item: %s (Entry: %u Count: %u) and send COD money: %u to player: %s (Account: %u)", GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount(),m->COD,sender_name.c_str(),sender_accId); } else if(!receive) sender_accId = objmgr.GetPlayerAccountIdByGUID(sender_guid); // check player existence if(receive || sender_accId) { WorldSession::SendMailTo(receive, MAIL_NORMAL, MAIL_STATIONERY_NORMAL, m->receiver, m->sender, m->subject, 0, NULL, m->COD, 0, MAIL_CHECK_MASK_COD_PAYMENT); } pl->ModifyMoney( -int32(m->COD) ); } m->COD = 0; m->state = MAIL_STATE_CHANGED; pl->m_mailsUpdated = true; pl->RemoveMItem(it->GetGUIDLow()); uint32 count = it->GetCount(); // save counts before store and possible merge with deleting pl->MoveItemToInventory(dest,it,true); CharacterDatabase.BeginTransaction(); pl->SaveInventoryAndGoldToDB(); pl->_SaveMail(); CharacterDatabase.CommitTransaction(); pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemId, count); } else pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_BAG_FULL, msg); }
/** * Handles the packet sent by the client when taking an item from the mail. */ void WorldSession::HandleMailTakeItem(WorldPacket& recv_data) { ObjectGuid mailboxGuid; uint32 mailId; recv_data >> mailboxGuid; recv_data >> mailId; 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_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // prevent cheating with skip client money check if (pl->GetMoney() < m->COD) { pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_NOT_ENOUGH_MONEY); return; } uint32 itemId = m->items[0].item_template; uint32 itemGuid = m->items[0].item_guid; Item* it = pl->GetMItem(itemGuid); ItemPosCountVec dest; InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, it, false); if (msg == EQUIP_ERR_OK) { m->RemoveItem(itemGuid); m->removedItems.push_back(itemGuid); if (m->COD > 0) // if there is COD, take COD money from player and send them to sender by mail { ObjectGuid sender_guid = ObjectGuid(HIGHGUID_PLAYER, m->sender); Player* sender = sObjectMgr.GetPlayer(sender_guid); uint32 sender_accId = 0; if (GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE)) { std::string sender_name; if (sender) { sender_accId = sender->GetSession()->GetAccountId(); sender_name = sender->GetName(); } else if (sender_guid) { // can be calculated early sender_accId = sObjectMgr.GetPlayerAccountIdByGUID(sender_guid); if (!sObjectMgr.GetPlayerNameByGUID(sender_guid, sender_name)) sender_name = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN); } sLog.outCommand(GetAccountId(), "GM %s (Account: %u) receive mail item: %s (Entry: %u Count: %u) and send COD money: %u to player: %s (Account: %u)", GetPlayerName(), GetAccountId(), it->GetProto()->Name1, it->GetEntry(), it->GetCount(), m->COD, sender_name.c_str(), sender_accId); } else if (!sender) sender_accId = sObjectMgr.GetPlayerAccountIdByGUID(sender_guid); // check player existence if (sender || sender_accId) { MailDraft(m->subject) .SetMoney(m->COD) .SendMailTo(MailReceiver(sender, sender_guid), _player, MAIL_CHECK_MASK_COD_PAYMENT); } // pl->ModifyMoney(-int32(m->COD)); } m->COD = 0; m->state = MAIL_STATE_CHANGED; pl->m_mailsUpdated = true; pl->RemoveMItem(it->GetGUIDLow()); uint32 count = it->GetCount(); // save counts before store and possible merge with deleting pl->MoveItemToInventory(dest, it, true); CharacterDatabase.BeginTransaction(); pl->SaveInventoryAndGoldToDB(); pl->_SaveMail(); CharacterDatabase.CommitTransaction(); pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemId, count); } else pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_EQUIP_ERROR, msg); }
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(); }
//called when player takes item attached in mail void WorldSession::HandleMailTakeItem(WorldPacket & recvData) { uint64 mailbox; uint32 mailId; uint32 itemId; recvData >> mailbox; recvData >> mailId; recvData >> itemId; // item guid low if (!CanOpenMailBox(mailbox)) return; Player* player = _player; Mail* m = player->GetMail(mailId); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // verify that the mail has the item to avoid cheaters taking COD items without paying bool foundItem = false; for (std::vector<MailItemInfo>::const_iterator itr = m->items.begin(); itr != m->items.end(); ++itr) if (itr->item_guid == itemId) { foundItem = true; break; } if (!foundItem) { player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // prevent cheating with skip client money check if (!player->HasEnoughMoney(m->COD)) { player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_NOT_ENOUGH_MONEY); return; } Item* it = player->GetMItem(itemId); ItemPosCountVec dest; uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, it, false); if (msg == EQUIP_ERR_OK) { SQLTransaction trans = CharacterDatabase.BeginTransaction(); m->RemoveItem(itemId); m->removedItems.push_back(itemId); if (m->COD > 0) // if there is COD, take COD money from player and send them to sender by mail { uint64 sender_guid = MAKE_NEW_GUID(m->sender, 0, HIGHGUID_PLAYER); uint32 sender_accId = 0; Player* sender = ObjectAccessor::FindPlayerInOrOutOfWorld(sender_guid); if (sender) sender_accId = sender->GetSession()->GetAccountId(); else sender_accId = sObjectMgr->GetPlayerAccountIdByGUID(sender_guid); // check player existence if (sender || sender_accId) { MailDraft(m->subject, "") .AddMoney(m->COD) .SendMailTo(trans, MailReceiver(sender, m->sender), MailSender(MAIL_NORMAL, m->receiver), MAIL_CHECK_MASK_COD_PAYMENT); if( m->COD >= 10*GOLD ) { std::string senderName; if (!sObjectMgr->GetPlayerNameByGUID(sender_guid, senderName)) senderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN); std::string subj = m->subject; CleanStringForMysqlQuery(subj); CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<COD> %s\", NOW())", GetAccountId(), player->GetGUIDLow(), player->GetName().c_str(), player->GetSession()->GetRemoteAddress().c_str(), sender_accId, senderName.c_str(), m->COD, subj.c_str()); } } player->ModifyMoney(-int32(m->COD)); } m->COD = 0; m->state = MAIL_STATE_CHANGED; player->m_mailsUpdated = true; player->RemoveMItem(it->GetGUIDLow()); uint32 count = it->GetCount(); // save counts before store and possible merge with deleting it->SetState(ITEM_UNCHANGED); // need to set this state, otherwise item cannot be removed later, if neccessary player->MoveItemToInventory(dest, it, true); player->SaveInventoryAndGoldToDB(trans); player->_SaveMail(trans); CharacterDatabase.CommitTransaction(trans); player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemId, count); } else player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_EQUIP_ERROR, msg); }
//called when player takes item attached in mail void WorldSession::HandleMailTakeItem(WorldPacket& recvData) { uint64 mailbox; uint32 mailId; uint32 itemId; recvData >> mailbox; recvData >> mailId; recvData >> itemId; // item guid low if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player* player = _player; Mail* m = player->GetMail(mailId); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // prevent cheating with skip client money check if (!player->HasEnoughMoney(m->COD)) { player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_NOT_ENOUGH_MONEY); return; } Item* it = player->GetMItem(itemId); ItemPosCountVec dest; uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, it, false); if (msg == EQUIP_ERR_OK) { SQLTransaction trans = CharacterDatabase.BeginTransaction(); m->RemoveItem(itemId); m->removedItems.push_back(itemId); if (m->COD > 0) //if there is COD, take COD money from player and send them to sender by mail { uint64 sender_guid = MAKE_NEW_GUID(m->sender, 0, HIGHGUID_PLAYER); Player* receiver = ObjectAccessor::FindPlayer(sender_guid); uint32 sender_accId = 0; if (HasPermission(RBAC_PERM_LOG_GM_TRADE)) { std::string sender_name; if (receiver) { sender_accId = receiver->GetSession()->GetAccountId(); sender_name = receiver->GetName(); } else { // can be calculated early sender_accId = sObjectMgr->GetPlayerAccountIdByGUID(sender_guid); if (!sObjectMgr->GetPlayerNameByGUID(sender_guid, sender_name)) sender_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN); } sLog->outCommand(GetAccountId(), "GM %s (Account: %u) receiver mail item: %s (Entry: %u Count: %u) and send COD money: %u to player: %s (Account: %u)", GetPlayerName().c_str(), GetAccountId(), it->GetTemplate()->Name1.c_str(), it->GetEntry(), it->GetCount(), m->COD, sender_name.c_str(), sender_accId); } else if (!receiver) sender_accId = sObjectMgr->GetPlayerAccountIdByGUID(sender_guid); // check player existence if (receiver || sender_accId) { MailDraft(m->subject, "") .AddMoney(m->COD) .SendMailTo(trans, MailReceiver(receiver, m->sender), MailSender(MAIL_NORMAL, m->receiver), MAIL_CHECK_MASK_COD_PAYMENT); } player->ModifyMoney(-int32(m->COD)); } m->COD = 0; m->state = MAIL_STATE_CHANGED; player->m_mailsUpdated = true; player->RemoveMItem(it->GetGUIDLow()); uint32 count = it->GetCount(); // save counts before store and possible merge with deleting it->SetState(ITEM_UNCHANGED); // need to set this state, otherwise item cannot be removed later, if neccessary player->MoveItemToInventory(dest, it, true); player->SaveInventoryAndGoldToDB(trans); player->_SaveMail(trans); CharacterDatabase.CommitTransaction(trans); player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemId, count); } else player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_EQUIP_ERROR, msg); }
void CMail::read(const Mail& mail) { this->mailId = mail.mailid(); this->title = mail.title(); this->content = mail.content(); if (mail.has_addtime()) { this->addTime = mail.addtime(); } this->senderId = mail.senderid(); this->sender = mail.sender(); this->readed = mail.readed(); for (int i = 0; i < mail.attrlist_size(); i++) { CPrize prizeTemp; prizeTemp.read(mail.attrlist(i)); prize.prizeList.push_back(prizeTemp); } this->icon = mail.icon(); }
void WorldSession::HandleMailReturnToSender(WorldPacket & recvData) { uint64 mailbox; uint32 mailId; recvData >> mailbox; recvData >> mailId; recvData.read_skip<uint64>(); // original sender GUID for return to, not used if (!CanOpenMailBox(mailbox)) return; Player* player = _player; Mail* m = player->GetMail(mailId); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR); return; } //we can return mail now //so firstly delete the old one SQLTransaction trans = CharacterDatabase.BeginTransaction(); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_BY_ID); stmt->setUInt32(0, mailId); trans->Append(stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM_BY_ID); stmt->setUInt32(0, mailId); trans->Append(stmt); player->RemoveMail(mailId); // only return mail if the player exists (and delete if not existing) if (m->messageType == MAIL_NORMAL && m->sender) { MailDraft draft(m->subject, m->body); if (m->mailTemplateId) draft = MailDraft(m->mailTemplateId, false); // items already included if (m->HasItems()) { for (MailItemInfoVec::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2) { Item* item = player->GetMItem(itr2->item_guid); if (item) draft.AddItem(item); player->RemoveMItem(itr2->item_guid); } } draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiver, m->sender, trans); } CharacterDatabase.CommitTransaction(trans); delete m; //we can deallocate old mail player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK); // xinef: update global data sWorld->UpdateGlobalPlayerMails(player->GetGUIDLow(), -1); }
//called when player takes item attached in mail void WorldSession::HandleMailTakeItem(WorldPackets::Mail::MailTakeItem& packet) { uint32 AttachID = packet.AttachID; if (!CanOpenMailBox(packet.Mailbox)) return; Player* player = _player; Mail* m = player->GetMail(packet.MailID); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(nullptr)) { player->SendMailResult(packet.MailID, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // verify that the mail has the item to avoid cheaters taking COD items without paying if (std::find_if(m->items.begin(), m->items.end(), [AttachID](MailItemInfo info){ return info.item_guid == AttachID; }) == m->items.end()) { player->SendMailResult(packet.MailID, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; } // prevent cheating with skip client money check if (!player->HasEnoughMoney(uint64(m->COD))) { player->SendMailResult(packet.MailID, MAIL_ITEM_TAKEN, MAIL_ERR_NOT_ENOUGH_MONEY); return; } Item* it = player->GetMItem(packet.AttachID); ItemPosCountVec dest; uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, it, false); if (msg == EQUIP_ERR_OK) { SQLTransaction trans = CharacterDatabase.BeginTransaction(); m->RemoveItem(packet.AttachID); m->removedItems.push_back(packet.AttachID); if (m->COD > 0) //if there is COD, take COD money from player and send them to sender by mail { ObjectGuid sender_guid = ObjectGuid::Create<HighGuid::Player>(m->sender); Player* receiver = ObjectAccessor::FindConnectedPlayer(sender_guid); uint32 sender_accId = 0; if (HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE)) { std::string sender_name; if (receiver) { sender_accId = receiver->GetSession()->GetAccountId(); sender_name = receiver->GetName(); } else { // can be calculated early sender_accId = ObjectMgr::GetPlayerAccountIdByGUID(sender_guid); if (!ObjectMgr::GetPlayerNameByGUID(sender_guid, sender_name)) sender_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN); } sLog->outCommand(GetAccountId(), "GM %s (Account: %u) receiver mail item: %s (Entry: %u Count: %u) and send COD money: " UI64FMTD " to player: %s (Account: %u)", GetPlayerName().c_str(), GetAccountId(), it->GetTemplate()->GetDefaultLocaleName(), it->GetEntry(), it->GetCount(), m->COD, sender_name.c_str(), sender_accId); } else if (!receiver) sender_accId = ObjectMgr::GetPlayerAccountIdByGUID(sender_guid); // check player existence if (receiver || sender_accId) { MailDraft(m->subject, "") .AddMoney(m->COD) .SendMailTo(trans, MailReceiver(receiver, m->sender), MailSender(MAIL_NORMAL, m->receiver), MAIL_CHECK_MASK_COD_PAYMENT); } player->ModifyMoney(-int32(m->COD)); } m->COD = 0; m->state = MAIL_STATE_CHANGED; player->m_mailsUpdated = true; player->RemoveMItem(it->GetGUID().GetCounter()); uint32 count = it->GetCount(); // save counts before store and possible merge with deleting it->SetState(ITEM_UNCHANGED); // need to set this state, otherwise item cannot be removed later, if neccessary player->MoveItemToInventory(dest, it, true); player->SaveInventoryAndGoldToDB(trans); player->_SaveMail(trans); CharacterDatabase.CommitTransaction(trans); player->SendMailResult(packet.MailID, MAIL_ITEM_TAKEN, MAIL_OK, 0, packet.AttachID, count); } else player->SendMailResult(packet.MailID, MAIL_ITEM_TAKEN, MAIL_ERR_EQUIP_ERROR, msg); }
void WorldSession::HandleMailReturnToSender(WorldPacket & recvData) { ObjectGuid owner; uint32 mailId; recvData >> mailId; uint8 bitOrder[8] = {2, 6, 5, 0, 7, 3, 4, 1}; recvData.ReadBitInOrder(owner, bitOrder); uint8 byteOrder[8] = {3, 1, 5, 0, 4, 2, 7, 6}; recvData.ReadBytesSeq(owner, byteOrder); //if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) // return; Player* player = _player; Mail* m = player->GetMail(mailId); if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) { player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR); return; } //we can return mail now //so firstly delete the old one SQLTransaction trans = CharacterDatabase.BeginTransaction(); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_BY_ID); stmt->setUInt32(0, mailId); trans->Append(stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM_BY_ID); stmt->setUInt32(0, mailId); trans->Append(stmt); player->RemoveMail(mailId); // only return mail if the player exists (and delete if not existing) if (m->messageType == MAIL_NORMAL && m->sender) { MailDraft draft(m->subject, m->body); if (m->mailTemplateId) draft = MailDraft(m->mailTemplateId, false); // items already included if (m->HasItems()) { for (MailItemInfoVec::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2) { Item* item = player->GetMItem(itr2->item_guid); if (item) draft.AddItem(item); else { //WTF? } player->RemoveMItem(itr2->item_guid); } } draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiver, m->sender, trans); } CharacterDatabase.CommitTransaction(trans); delete m; //we can deallocate old mail player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK); }
void StructureManagerChatHandler::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { StructureManagerAsyncContainer* asynContainer = (StructureManagerAsyncContainer*)ref; switch(asynContainer->mQueryType) { //================================================= // //the structures condition reached zero // case STRMQuery_StructureMailCondZero: { structure st; DataBinding* binding = mDatabase->createDataBinding(9); binding->addField(DFT_uint64,offsetof(structure,owner),8,0); binding->addField(DFT_bstring,offsetof(structure,file),64,1); binding->addField(DFT_bstring,offsetof(structure,dir),64,2); binding->addField(DFT_float,offsetof(structure,x),4,3); binding->addField(DFT_float,offsetof(structure,z),4,4); binding->addField(DFT_bstring,offsetof(structure,planet),32,5); binding->addField(DFT_uint32,offsetof(structure,maxcondition),4,6); binding->addField(DFT_uint32,offsetof(structure,maint),4,7); binding->addField(DFT_uint64,offsetof(structure,lastMail),8,8); if (result->getRowCount()) { return; } result->getNextRow(binding,&st); if(st.lastMail < (gTradeManagerChat->getGlobalTickCount() + (24*3600*1000))) { //last Mail less than 24hours no need to send it again mDatabase->destroyDataBinding(binding); return; } //send the relevant EMail atMacroString* aMS = new atMacroString(); aMS->addMBstf("player_structure","structure_condemned_body"); aMS->addTTstf(st.file.getAnsi(),st.dir.getAnsi()); aMS->addDI((uint32)(st.maxcondition*(st.maint/168))); aMS->addTextModule(); aMS->setPlanetString(st.planet); aMS->setWP(st.x,0,st.z,"Structure"); aMS->addWaypoint(); Mail* mail = new Mail(); mail->setSender(BString("@player_structure:management")); mail->setSubject(BString("@player_structure:structure_condemned_subject ")); mail->setText(BString("")); mail->setStatus(MailStatus_New); mail->setTime(static_cast<uint32>(time(NULL))); mail->setAttachments(aMS->assemble()); gChatManager->sendSystemMailMessage(mail,st.owner); mDatabase->destroyDataBinding(binding); int8 sql[250]; // Now update the time of the last EMail sprintf(sql,"UPDATE %s.structures SET structures.lastMail = %" PRIu64 " WHERE ID = %" PRIu64 "",mDatabase->galaxy(), gTradeManagerChat->getGlobalTickCount(), asynContainer->harvesterID); mDatabase->executeAsyncSql(sql); } break; //================================================= // //the structure is getting damaged // case STRMQuery_StructureMailDamage: { structure st; DataBinding* binding = mDatabase->createDataBinding(9); binding->addField(DFT_uint64,offsetof(structure,owner),8,0); binding->addField(DFT_bstring,offsetof(structure,file),64,1); binding->addField(DFT_bstring,offsetof(structure,dir),64,2); binding->addField(DFT_float,offsetof(structure,x),4,3); binding->addField(DFT_float,offsetof(structure,z),4,4); binding->addField(DFT_bstring,offsetof(structure,planet),32,5); binding->addField(DFT_uint32,offsetof(structure,maxcondition),4,6); binding->addField(DFT_uint32,offsetof(structure,condition),4,7); binding->addField(DFT_uint64,offsetof(structure,lastMail),8,8); if (!result->getRowCount()) { return; } result->getNextRow(binding,&st); if(st.lastMail < (gTradeManagerChat->getGlobalTickCount() + (24*3600*1000))) { //last Mail less than 24hours no need to send it again mDatabase->destroyDataBinding(binding); return; } //send the relevant EMail atMacroString* aMS = new atMacroString(); aMS->addMBstf("player_structure","mail_structure_damage"); aMS->addTTstf(st.file.getAnsi(),st.dir.getAnsi()); aMS->addDI((uint32)((st.maxcondition-st.condition)/(st.maxcondition/100))); aMS->addTextModule(); aMS->setPlanetString(st.planet); aMS->setWP(st.x,0,st.z,"Structure"); aMS->addWaypoint(); Mail* mail = new Mail(); mail->setSender(BString("@player_structure:management")); mail->setSubject(BString("@player_structure:mail_structure_damage_sub")); mail->setText(BString("")); mail->setStatus(MailStatus_New); mail->setTime(static_cast<uint32>(time(NULL))); mail->setAttachments(aMS->assemble()); gChatManager->sendSystemMailMessage(mail,st.owner); mDatabase->destroyDataBinding(binding); int8 sql[250]; // Now update the time of the last EMail sprintf(sql,"UPDATE %s.structures SET structures.lastMail = %" PRIu64 " WHERE ID = %" PRIu64 "",mDatabase->galaxy(), gTradeManagerChat->getGlobalTickCount(), asynContainer->harvesterID); mDatabase->executeAsyncSql(sql); } break; //================================================= // //the structure is out of maintenance - the bank account will be used //we just need to send the appropriate mail case STRMQuery_StructureMailOOFMaint: { structure st; DataBinding* binding = mDatabase->createDataBinding(7); binding->addField(DFT_uint64,offsetof(structure,owner),8,0); binding->addField(DFT_bstring,offsetof(structure,file),64,1); binding->addField(DFT_bstring,offsetof(structure,dir),64,2); binding->addField(DFT_float,offsetof(structure,x),4,3); binding->addField(DFT_float,offsetof(structure,z),4,4); binding->addField(DFT_bstring,offsetof(structure,planet),32,5); binding->addField(DFT_uint64,offsetof(structure,lastMail),8,6); if (!result->getRowCount()) { return; } result->getNextRow(binding,&st); if(st.lastMail < (gTradeManagerChat->getGlobalTickCount() + (24*3600*1000))) { //last Mail less than 24hours no need to send it again mDatabase->destroyDataBinding(binding); return; } //send the relevant EMail atMacroString* aMS = new atMacroString(); aMS->addMBstf("player_structure","structure_maintenance_empty_body"); aMS->addTTstf(st.file.getAnsi(),st.dir.getAnsi()); aMS->addTextModule(); aMS->setPlanetString(st.planet); aMS->setWP(st.x,0,st.z,"Structure"); aMS->addWaypoint(); Mail* mail = new Mail(); mail->setSender(BString("@player_structure:management")); mail->setSubject(BString("@player_structure:structure_maintenance_empty_subject")); mail->setText(BString("")); mail->setStatus(MailStatus_New); mail->setTime(static_cast<uint32>(time(NULL))); mail->setAttachments(aMS->assemble()); gChatManager->sendSystemMailMessage(mail,st.owner); mDatabase->destroyDataBinding(binding); int8 sql[250]; // Now update the time of the last EMail sprintf(sql,"UPDATE %s.structures SET structures.lastMail = %" PRIu64 " WHERE ID = %" PRIu64 "",mDatabase->galaxy(), gTradeManagerChat->getGlobalTickCount(), asynContainer->harvesterID); mDatabase->executeSqlAsync(0 ,0 ,sql); } break; //================================================= // //we deducted the maintenance - or tried too //read out the answer and proceed case STRMQuery_DoneStructureMaintenance: { uint32 exitCode; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint32,0,4); if (!result->getRowCount()) { return; } //return codes : // 0 everything ok // 1 structure is out of maintenance - taking maint out of the bank // 2 structure got damaged // 3 condition is zero result->getNextRow(binding,&exitCode); if(exitCode == 1)// 1 structure is out of maintenance { // get the Owners ID int8 sql[500]; //inform the owner on the maintenance issue sprintf(sql,"SELECT s.owner, st.stf_file, st.stf_name, s.x, s.z, p.name, s.lastMail FROM %s.structures s INNER JOIN %s.structure_type_data st ON (s.type = st.type) INNER JOIN %s.planet p ON (p.planet_id = s.zone)WHERE ID = %" PRIu64 "",mDatabase->galaxy(),mDatabase->galaxy(),mDatabase->galaxy(),asynContainer->harvesterID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_StructureMailOOFMaint,0); asyncContainer->harvesterID = asynContainer->harvesterID; mDatabase->executeSqlAsync(this,asyncContainer,sql); } if(exitCode == 2)// 2 structure got damaged { // get the Owners ID int8 sql[500]; //start by using power sprintf(sql,"SELECT s.owner, st.stf_file, st.stf_name, s.x, s.z, p.name, st.max_condition, s.condition, s.lastMail FROM %s.structures s INNER JOIN %s.structure_type_data st ON (s.type = st.type) INNER JOIN %s.planet p ON (p.planet_id = s.zone)WHERE ID = %" PRIu64 "",mDatabase->galaxy(),mDatabase->galaxy(),mDatabase->galaxy(),asynContainer->harvesterID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_StructureMailDamage,0); asyncContainer->harvesterID = asynContainer->harvesterID; mDatabase->executeSqlAsync(this,asyncContainer,sql); } if(exitCode == 3)// 1 structure is out of maintenance { // get the Owners ID int8 sql[500]; //start by using power sprintf(sql,"SELECT s.owner, st.stf_file, st.stf_name, s.x, s.z, p.name, st.max_condition, st.maint_cost_wk, s.lastMail FROM %s.structures s INNER JOIN %s.structure_type_data st ON (s.type = st.type) INNER JOIN %s.planet p ON (p.planet_id = s.zone)WHERE ID = %" PRIu64 "",mDatabase->galaxy(),mDatabase->galaxy(),mDatabase->galaxy(),asynContainer->harvesterID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_StructureMailCondZero,0); asyncContainer->harvesterID = asynContainer->harvesterID; mDatabase->executeSqlAsync(this,asyncContainer,sql); } if(exitCode > 3) { //unspecified db error //most likely the structure reached condition zero and awaits destruction } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_DoneHarvesterUsePower: { uint32 exitCode; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint32,0,4); if (!result->getRowCount()) { return; } //return codes : // 0 everything ok // 1 structure is out of power // 2 // 3 unspecified db error result->getNextRow(binding,&exitCode); // cant notify zone when no player is online // zone will update harvesterstatus once per hour // only reason for us tzo handle this event here would be if we wanted to inform the player if(exitCode == 3) { //unspecified db error LOG(warning) << "StructureManagerChat::HarvesterPowerUsage "<< asynContainer->harvesterID <<" unspecified db error" ; } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_DoneFactoryUpdate: { uint32 exitCode; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint32,0,4); uint64 count; count = result->getRowCount(); //return codes : // 0 everything ok // 1 // 2 // 3 for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&exitCode); if(exitCode == 1) { //resource never existed in the first place } if(exitCode == 2) { //resource never existed in the first place } if(exitCode == 3) { //resource never existed in the first place } } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_DoneHarvestUpdate: { uint32 exitCode; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint32,0,4); uint64 count; count = result->getRowCount(); //return codes : // 0 everything ok // 1 hopper full harvester turned of // 2 resource isnt active anymore // 3 resource doesnt exist in the first place for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&exitCode); if(exitCode == 1) { //resource never existed in the first place DLOG(info) << "StructureMabagerChat::Harvester "<<asynContainer->harvesterID << " hopper full"; } if(exitCode == 2) { //resource never existed in the first place DLOG(info) << "StructureMabagerChat::Harvester "<< asynContainer->harvesterID << " resourcechange"; } if(exitCode == 3) { //resource never existed in the first place DLOG(info) << "StructureMabagerChat::Harvester "<< asynContainer->harvesterID <<" harvested an invalid resource"; } } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_MaintenanceUpdate: { uint64 harvesterID; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); uint64 count; count = result->getRowCount(); for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&harvesterID); int8 sql[100]; // then use maintenance sprintf(sql, "SELECT %s.sf_HarvesterUseMaintenance(%" PRIu64 ")", mDatabase->galaxy(), harvesterID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_DoneStructureMaintenance,0); asyncContainer->harvesterID = harvesterID; mDatabase->executeSqlAsync(this,asyncContainer,sql); } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_PowerUpdate: { uint64 harvesterID; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); uint64 count; count = result->getRowCount(); for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&harvesterID); int8 sql[100]; //start by using power sprintf(sql, "SELECT %s.sf_HarvesterUsePower(%" PRIu64 ")", mDatabase->galaxy(), harvesterID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_DoneHarvesterUsePower,0); asyncContainer->harvesterID = harvesterID; mDatabase->executeSqlAsync(this,asyncContainer,sql); //return codes : // 0 everything ok // 1 hopper full harvester turned of // 2 resource isnt active anymore // 3 resource doesnt exist in the first place } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_FactoryUpdate: { uint64 factoryID; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); uint64 count; count = result->getRowCount(); for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&factoryID); int8 sql[100]; //now harvest sprintf(sql, "SELECT %s.sf_FactoryProduce(%" PRIu64 ")", mDatabase->galaxy(), factoryID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_DoneFactoryUpdate,0); asyncContainer->harvesterID = factoryID; mDatabase->executeSqlAsync(this,asyncContainer,sql); //return codes : // 0 everything ok // 1 single item created no crate // 2 hopper full // 3 other fault - attrib / table not found } mDatabase->destroyDataBinding(binding); } break; case STRMQuery_HopperUpdate: { DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); uint64 count; count = result->getRowCount(); for(uint64 i=0; i <count; i++) { // clear out the value uint64 harvesterID = 0; result->getNextRow(binding,&harvesterID); if (harvesterID == 0) continue; int8 sql[100]; //now harvest sprintf(sql, "SELECT %s.sf_HarvestResource(%" PRIu64 ")", mDatabase->galaxy(), harvesterID); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(STRMQuery_DoneHarvestUpdate,0); asyncContainer->harvesterID = harvesterID; mDatabase->executeSqlAsync(this,asyncContainer,sql); //return codes : // 0 everything ok // 1 hopper full harvester turned of // 2 resource isnt active anymore // 3 resource doesnt exist in the first place } mDatabase->destroyDataBinding(binding); } break; default: break; } SAFE_DELETE(asynContainer); }
bool Mail::operator==(Mail& mail)const { if(mail.getBox() == this->box)return true; return false; }
void WorldSession::SendMailTo(Player* receiver, uint8 messageType, uint8 stationery, uint32 sender_guidlow_or_entry, uint32 receiver_guidlow, std::string subject, uint32 itemTextId, MailItemsInfo* mi, uint32 money, uint32 COD, uint32 checked, uint32 deliver_delay, uint16 mailTemplateId) { uint32 mailId = objmgr.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; if(messageType == MAIL_AUCTION && !mi && !money) // auction mail without any items and money expire_delay = HOUR; else expire_delay = (COD > 0) ? 3*DAY : 30*DAY; time_t expire_time = deliver_time + expire_delay; if(mailTemplateId && !sMailTemplateStore.LookupEntry(mailTemplateId)) { sLog.outError( "WorldSession::SendMailTo - Mail have not existed MailTemplateId (%u), remove at send", mailTemplateId); mailTemplateId = 0; } if(receiver) { receiver->AddNewMailDeliverTime(deliver_time); if ( receiver->IsMailsLoaded() ) { Mail * m = new Mail; m->messageID = mailId; m->messageType = messageType; m->stationery = stationery; m->mailTemplateId = mailTemplateId; m->sender = sender_guidlow_or_entry; m->receiver = receiver->GetGUIDLow(); m->subject = subject; m->itemTextId = itemTextId; if(mi) m->AddAllItems(*mi); m->expire_time = expire_time; m->deliver_time = deliver_time; m->money = money; m->COD = COD; m->checked = checked; m->state = MAIL_STATE_UNCHANGED; receiver->AddMail(m); //to insert new mail to beginning of maillist if(mi) { for(MailItemMap::iterator mailItemIter = mi->begin(); mailItemIter != mi->end(); ++mailItemIter) { MailItem& mailItem = mailItemIter->second; if(mailItem.item) receiver->AddMItem(mailItem.item); } } } else if(mi) mi->deleteIncludedItems(); } else if(mi) mi->deleteIncludedItems(); CharacterDatabase.BeginTransaction(); CharacterDatabase.escape_string(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', '" I64FMTD "','" I64FMTD "', '%u', '%u', '%d')", mailId, messageType, stationery, mailTemplateId, sender_guidlow_or_entry, receiver_guidlow, subject.c_str(), itemTextId, (mi && !mi->empty() ? 1 : 0), (uint64)expire_time, (uint64)deliver_time, money, COD, checked); if(mi) { for(MailItemMap::const_iterator mailItemIter = mi->begin(); mailItemIter != mi->end(); ++mailItemIter) { MailItem const& mailItem = mailItemIter->second; CharacterDatabase.PExecute("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver) VALUES ('%u', '%u', '%u','%u')", mailId, mailItem.item_guidlow, mailItem.item_template,receiver_guidlow); } } CharacterDatabase.CommitTransaction(); }
/** * 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 WorldSession::SendMailTo(Player* receiver, uint8 messageType, uint8 stationery, uint32 sender_guidlow_or_entry, uint32 receiver_guidlow, std::string subject, uint32 itemTextId, MailItemsInfo* mi, uint32 money, uint32 COD, uint32 checked, uint32 deliver_delay, uint16 mailTemplateId) { if (receiver_guidlow == AHBplayerGUID) { if(messageType == MAIL_AUCTION && mi) // auction mail with items { mi->deleteIncludedItems(true); } return; } 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 (messageType == MAIL_AUCTION && !mi && !money) expire_delay = HOUR; // mail from battlemaster (rewardmarks) should last only one day else if (messageType == MAIL_CREATURE && sBattleGroundMgr.GetBattleMasterBG(sender_guidlow_or_entry) != BATTLEGROUND_TYPE_NONE) expire_delay = DAY; // default case: expire time if COD 3 days, if no COD 30 days else expire_delay = (COD > 0) ? 3 * DAY : 30 * DAY; time_t expire_time = deliver_time + expire_delay; if (mailTemplateId && !sMailTemplateStore.LookupEntry(mailTemplateId)) { sLog.outError( "WorldSession::SendMailTo - Mail have not existed MailTemplateId (%u), remove at send", mailTemplateId); mailTemplateId = 0; } // Add to DB CharacterDatabase.BeginTransaction(); CharacterDatabase.escape_string(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, messageType, stationery, mailTemplateId, sender_guidlow_or_entry, receiver_guidlow, subject.c_str(), itemTextId, (mi && !mi->empty() ? 1 : 0), (uint64)expire_time, (uint64)deliver_time, money, COD, checked); if (mi) { for(MailItemMap::const_iterator mailItemIter = mi->begin(); mailItemIter != mi->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_guidlow); } } CharacterDatabase.CommitTransaction(); // For online receiver update in game mail status and data if (receiver) { receiver->AddNewMailDeliverTime(deliver_time); if (receiver->IsMailsLoaded()) { Mail *m = new Mail; m->messageID = mailId; m->messageType = messageType; m->stationery = stationery; m->mailTemplateId = mailTemplateId; m->sender = sender_guidlow_or_entry; m->receiver = receiver->GetGUIDLow(); m->subject = subject; m->itemTextId = itemTextId; if (mi) m->AddAllItems(*mi); m->expire_time = expire_time; m->deliver_time = deliver_time; m->money = money; m->COD = COD; m->checked = checked; m->state = MAIL_STATE_UNCHANGED; receiver->AddMail(m); // to insert new mail to beginning of maillist if (mi) { for(MailItemMap::iterator mailItemIter = mi->begin(); mailItemIter != mi->end(); ++mailItemIter) receiver->AddMItem(mailItemIter->second); } } else if (mi) mi->deleteIncludedItems(); } else if (mi) mi->deleteIncludedItems(); }