当前位置: 首页>>代码示例>>C++>>正文


C++ Mail类代码示例

本文整理汇总了C++中Mail的典型用法代码示例。如果您正苦于以下问题:C++ Mail类的具体用法?C++ Mail怎么用?C++ Mail使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Mail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draft

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);
}
开发者ID:Bootz,项目名称:CactusEMU,代码行数:54,代码来源:MailHandler.cpp

示例2: ObjectGuid

/**
 * 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);
}
开发者ID:xXNembiXx,项目名称:mangos_335,代码行数:63,代码来源:Mail.cpp

示例3: CHECK_PACKET_SIZE

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);
}
开发者ID:Bootz,项目名称:TC-One,代码行数:54,代码来源:Mail.cpp

示例4: test_mail_full

/** 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());
}
开发者ID:betzw,项目名称:mbed,代码行数:18,代码来源:main.cpp

示例5: test_serial_line_coding_change

/** 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();
}
开发者ID:0xc0170,项目名称:mbed,代码行数:59,代码来源:main.cpp

示例6: draft

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);
}
开发者ID:Regigicas,项目名称:TrinityCore,代码行数:50,代码来源:MailHandler.cpp

示例7: main

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);
        }
    }
}
开发者ID:3eggert,项目名称:mbed,代码行数:15,代码来源:main.cpp

示例8: it

    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);
    }
开发者ID:Danielweber7624,项目名称:actiona,代码行数:42,代码来源:mail.cpp

示例9: context

    // ---------------------------------------------------------------------------------
    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 );
      }
    }
开发者ID:frankHa,项目名称:dontpanic,代码行数:42,代码来源:kreporttable.cpp

示例10: main

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;
}
开发者ID:gitter-badger,项目名称:OpenPV,代码行数:31,代码来源:evaluate_flow.cpp

示例11: sendToMail

// 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);  
    }
}
开发者ID:rm32,项目名称:Lab3,代码行数:27,代码来源:main.cpp

示例12: thread1

//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
}
开发者ID:SoCM,项目名称:ELEC143,代码行数:38,代码来源:main.cpp

示例13: prepareItems

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())
//.........这里部分代码省略.........
开发者ID:AwkwardDev,项目名称:RE,代码行数:101,代码来源:Mail.cpp

示例14: CHECK_PACKET_SIZE

//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);
}
开发者ID:megamage,项目名称:mangos,代码行数:91,代码来源:Mail.cpp

示例15: ObjectGuid

/**
 * 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);
}
开发者ID:Lillecarl,项目名称:mangos-classic,代码行数:98,代码来源:MailHandler.cpp


注:本文中的Mail类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。