Exemplo n.º 1
0
//发信
void   CMailManager::SendMailToClient(CGUID guid,CMail *pMail)
{
	CPlayer *pPlayer = GetGame()->FindPlayer(pMail->GetReceiver().c_str());

	if (pPlayer && pMail)
	{
		pPlayer->AddReceiveMailList(pMail->GetExID());
		
		if(SetMapMail(pMail))
		{
			CMessage msg(MSG_S2C_MAIL_SEND);			
			msg.SendToPlayer(pPlayer->GetExID());
			long lGoodsNum = 0;
			for (vector<CGoods*>::iterator it=pMail->GetMGoodsContainer().begin(); it!=pMail->GetMGoodsContainer().end(); ++it)
			{
				lGoodsNum += (*it)->GetAmount();
			}
			GetGameLogInterface()->logT600_Receive_mail_log(pPlayer,pMail->GetExID(),pMail->GetWriter().c_str(),pMail->GetType(),pMail->GetGold(),lGoodsNum,pMail->GetSGood().size(),2);
		}		
	}
	else
	{
		pMail->DeleteMailGoods();
		MP_DELETE(pMail);
	}		
}
Exemplo n.º 2
0
void DoW2SMailReceive( CMessage *pMsg )
{
	BYTE *ByteData = NULL;
	list<CGUID> lMailGuid;
	list<CMail*> lMailList;
	CGUID playerGuid;
	pMsg->GetGUID(playerGuid);

	long lByteDataLen = pMsg->GetLong();
	ByteData = (BYTE*)M_ALLOC(sizeof(BYTE)*lByteDataLen);	
	pMsg->GetEx(ByteData,lByteDataLen);
	time_t t_CurrentTime = time(NULL);

	CPlayer *pPlayer =  GetGame()->FindPlayer(playerGuid);
	if (pPlayer)
	{				
		long Pos = 0;
		long lNum = _GetLongFromByteArray(ByteData,Pos);
		for (int i=0; i<lNum; ++i)
		{
			tagMailParam *pMailParam = OBJ_CREATE(tagMailParam);
			GameManager::GetInstance()->GetMailManager()->DecordFromByteArray(ByteData,Pos,pMailParam);

			CMail *pMail = OBJ_CREATE_PVOID(CMail, (void*)pMailParam);

			if(!GameManager::GetInstance()->GetMailManager()->SetMapMail(pMail))
			{
				lMailGuid.push_back(pMailParam->guid);					
			}
			else
			{
				lMailList.push_back(pMail);
			}
		}
		if(lMailGuid.size()>0)
		{
			//删除邮件		
			GameManager::GetInstance()->GetMailManager()->DeleteMailToWS(lMailGuid,pPlayer);				
		}

		vector<BYTE> vectorByte;
		vectorByte.clear();

		_AddToByteArray(&vectorByte,(long)lMailList.size());
			
		pPlayer->SetReceiveMail(true);	
		for (list<CMail*>::iterator it=lMailList.begin();it!=lMailList.end();++it)
		{
			pPlayer->AddReceiveMailList((*it)->GetExID());
		}

		GameManager::GetInstance()->GetMailManager()->SendReceiveMail( pPlayer );
	}
	M_FREE(ByteData, lByteDataLen);
}