Beispiel #1
0
/// \todo refactoring
bool MailMessage::AddMessageDataToPacket(WorldPacket& data)
{
    uint8 i = 0;
    uint32 j;
    std::vector<uint32>::iterator itr;
    Item* pItem;

    // add stuff
    if (deleted_flag)
        return false;

    uint8 guidsize;
    if (message_type == 0)
        guidsize = 8;
    else
        guidsize = 4;

    size_t msize = 2 + 4 + 1 + guidsize + 7 * 4 + (subject.size() + 1) + (body.size() + 1) + 1 + (items.size() * (1 + 2 * 4 + 7 * (3 * 4) + 6 * 4 + 1));

    data << uint16(msize);     // message size
    data << uint32(message_id);
    data << uint8(message_type);

    switch (message_type)
    {
        case NORMAL:
            data << uint64(sender_guid);
            break;
        case COD:
        case AUCTION:
        case GAMEOBJECT:
        case ITEM:
            data << uint32(Arcemu::Util::GUID_LOPART(sender_guid));
            break;
        case CREATURE:
            data << uint32(Arcemu::Util::GET_CREATURE_ENTRY_FROM_GUID(sender_guid));
            break;
    }

    data << uint32(cod);            // cod
    data << uint32(0);
    data << uint32(stationery);
    data << uint32(money);        // money
    data << uint32(checked_flag);           // "checked" flag
    data << float((expire_time - uint32(UNIXTIME)) / 86400.0f);
    data << uint32(0);    // mail template
    data << subject;
    data << body;

    data << uint8(items.size());        // item count

    if (!items.empty())
    {
        for (itr = items.begin(); itr != items.end(); ++itr)
        {
            pItem = objmgr.LoadItem(*itr);
            if (pItem == NULL)
                continue;

            data << uint8(i++);
            data << uint32(pItem->GetLowGUID());
            data << uint32(pItem->GetEntry());

            for (j = 0; j < 7; ++j)
            {
                data << uint32(pItem->GetEnchantmentId(j));
                data << uint32(pItem->GetEnchantmentDuration(j));
                data << uint32(0);
            }

            data << uint32(pItem->GetItemRandomPropertyId());
            data << uint32(pItem->GetItemRandomSuffixFactor());
            data << uint32(pItem->GetStackCount());
            data << uint32(pItem->GetChargesLeft());
            data << uint32(pItem->GetDurabilityMax());
            data << uint32(pItem->GetDurability());
            data << uint8(0);   // unknown

            delete pItem;
        }

    }

    return true;
}
Beispiel #2
0
WorldPacket* Mailbox::BuildMailboxListingPacket()
{
    WorldPacket* data = new WorldPacket(SMSG_MAIL_LIST_RESULT, 200);
    MessageMap::iterator itr;
    uint8 i = 0;
    uint32 realCount = 0;
    uint32 mailsCount = 0;
    uint32 t = (uint32)UNIXTIME;
    *data << uint32(0);                                      // real mail's count
    *data << uint8(0);                                       // mail's count

    for (itr = Messages.begin(); itr != Messages.end(); ++itr)
    {
        if (itr->second.expire_time && t > itr->second.expire_time)
            continue;       // expired mail -> skip it

        if ((uint32)UNIXTIME < itr->second.delivery_time)
            continue;        // undelivered

        if (mailsCount >= 50) //VLack: We could calculate message sizes instead of this, but the original code did a break at 50, so I won't fix this up if no one felt the need to do so before ;-)
        {
            realCount += 1;
            continue;
        }

        uint8 item_count = itr->second.items.size();            // max count is MAX_MAIL_ITEMS (12)

        size_t next_mail_size = 2 + 4 + 1 + (itr->second.message_type == NORMAL ? 8 : 4) + 4 * 8 + (itr->second.subject.size() + 1) + (itr->second.body.size() + 1) + 1 + item_count*(1 + 4 + 4 + MAX_INSPECTED_ENCHANTMENT_SLOT * 3 * 4 + 4 + 4 + 4 + 4 + 4 + 4 + 1);


        *data << uint16(next_mail_size);                    // Message size
        *data << uint32(itr->second.message_id);                 // Message ID
        *data << uint8(itr->second.message_type);                // Message Type

        switch (itr->second.message_type)
        {
        case NORMAL:
            *data << uint64((itr->second.sender_guid));
            break;
        case COD:
        case AUCTION:
        case ITEM:
            *data << uint32(Arcemu::Util::GUID_LOPART((itr->second.sender_guid)));
            break;
        case GAMEOBJECT:
        case CREATURE:
            *data << uint32(static_cast<uint32>((itr->second.sender_guid)));
            break;
        }

        *data << uint64(itr->second.cod);                         // COD
        *data << uint32(0);                                   // Package.dbc ID ?
        *data << uint32(itr->second.stationery);                  // stationery (Stationery.dbc)
        *data << uint64(itr->second.money);                       // Gold
        *data << uint32(itr->second.checked_flag);                     // flags
        *data << float(float((itr->second.expire_time - uint32(UNIXTIME)) / DAY)); // Time
        *data << uint32(itr->second.message_id);              // mail template (MailTemplate.dbc)
        *data << itr->second.subject;                             // Subject string - once 00, when mail type = 3, max 256
        *data << itr->second.body;                                // message? max 8000
        *data << uint8(item_count);                           // client limit is 0x10

        Item* pItem;
        std::vector<uint32>::iterator itr2;
        for (uint8 i = 0; i < item_count; ++i)
        {
            pItem = objmgr.LoadItem(itr->second.items[i]);
            // item index (0-6?)
            *data << uint8(i);
            // item guid low?
            *data << uint32((pItem ? pItem->GetLowGUID() : 0));
            // entry
            *data << uint32((pItem ? pItem->GetEntry() : 0));
            for (uint8 j = 0; j < MAX_INSPECTED_ENCHANTMENT_SLOT; ++j)
            {
                *data << uint32((pItem ? pItem->GetEnchantmentId((EnchantmentSlot)j) : 0));
                *data << uint32((pItem ? pItem->GetEnchantmentDuration((EnchantmentSlot)j) : 0));
                *data << uint32((pItem ? pItem->GetEnchantmentCharges((EnchantmentSlot)j) : 0));
            }

            // can be negative
            *data << int32((pItem ? pItem->GetItemRandomPropertyId() : 0));
            // unk
            *data << uint32((pItem ? pItem->GetItemRandomSuffixFactor() : 0));
            // stack count
            *data << uint32((pItem ? pItem->GetStackCount() : 0));
            // charges
            *data << uint32((pItem ? pItem->GetChargesLeft() : 0));
            // durability
            *data << uint32((pItem ? pItem->GetDurabilityMax() : 0));
            // durability
            *data << uint32((pItem ? pItem->GetDurability() : 0));
            // unknown wotlk
            *data << uint8(0);
        }

        ++realCount;
        ++mailsCount;
    }

    data->put<uint32>(0, realCount);                         // this will display warning about undelivered mail to player if realCount > mailsCount
    data->put<uint8>(4, mailsCount);                        // set real send mails to client

    // do cleanup on request mail
    CleanupExpiredMessages();
    return data;
}