Пример #1
0
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...");
}
Пример #2
0
void MailDraft::SendReturnToSender(uint32 sender_acc, ObjectGuid::LowType sender_guid, ObjectGuid::LowType receiver_guid, SQLTransaction& trans)
{
    ObjectGuid receiverGuid(HighGuid::Player, receiver_guid);
    Player* receiver = ObjectAccessor::FindConnectedPlayer(receiverGuid);

    uint32 rc_account = 0;
    if (!receiver)
        rc_account = sObjectMgr->GetPlayerAccountIdByGUID(receiverGuid);

    if (!receiver && !rc_account)                            // sender not exist
    {
        deleteIncludedItems(trans, true);
        return;
    }

    // prepare mail and send in other case
    bool needItemDelay = false;

    if (!m_items.empty())
    {
        // if item send to character at another account, then apply item delivery delay
        needItemDelay = sender_acc != rc_account;

        // set owner to new receiver (to prevent delete item with sender char deleting)
        for (MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
        {
            Item* item = mailItemIter->second;
            item->SaveToDB(trans);                      // item not in inventory and can be save standalone
            // owner in data will set at mail receive and item extracting
            PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_OWNER);
            stmt->setUInt32(0, receiver_guid);
            stmt->setUInt32(1, item->GetGUID().GetCounter());
            trans->Append(stmt);
        }
    }

    // If theres is an item, there is a one hour delivery delay.
    uint32 deliver_delay = needItemDelay ? sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY) : 0;

    // will delete item or place to receiver mail list
    SendMailTo(trans, MailReceiver(receiver, receiver_guid), MailSender(MAIL_NORMAL, sender_guid), MAIL_CHECK_MASK_RETURNED, deliver_delay);
}
Пример #3
0
bool SpectatorAddonMsg::SendPacket(SpectatorAddonMsg msg, uint32 receiver)
{
    std::string addonData = msg.GetMsgData();
    if (addonData == "")
        return false;

    ObjectGuid receiverGuid(HIGHGUID_PLAYER, receiver);
    Player* _player = ObjectAccessor::FindPlayer(receiverGuid);
    if (!_player)
        return false;

    WorldPacket data(SMSG_MESSAGECHAT, 200);
    data << uint8(CHAT_MSG_WHISPER);
    data << uint32(LANG_ADDON);
    data << uint64(0);
    data << uint32(LANG_ADDON);                               //language 2.1.0 ?
    data << uint64(0);
    data << uint32(addonData.length() + 1);
    data << addonData;
    data << uint8(CHAT_TAG_NONE);
    _player->GetSession()->SendPacket(&data);

    return true;
}