示例#1
0
void WorldSession::HandleReturnToSender(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_RETURNED_TO_SENDER);

	MailMessage * msg = _player->m_mailBox->GetMessage(message_id);
	if(msg == 0 || msg->Expired())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}
	if(msg->returned_flag)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	sMailSystem.ReturnToSender(msg);

	// finish the packet
	data << uint32(MAIL_OK);
	SendPacket(&data);
}
示例#2
0
void WorldSession::HandleTakeMoney(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_MONEY_TAKEN);

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired() || !message->money)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// add the money to the player
	if((_player->GetUInt32Value(PLAYER_FIELD_COINAGE) + message->money) >= PLAYER_MAX_GOLD )
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);
		return;
	}
	else
		_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, message->money);
	
	// force save
	_player->SaveToDB(false);

	// message no longer has any money
	message->money = 0;

	if ((message->items.size() == 0) && (message->money == 0))
	{
		// mail now has a 3 day expiry time
		if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
			message->expire_time = (uint32)UNIXTIME + (TIME_DAY * 3);
	}
	// update in sql!
	message->SaveToDB();

	// send result
	data << uint32(MAIL_OK);
	SendPacket(&data);
}
示例#3
0
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_MADE_PERMANENT);

	ItemPrototype * proto = ItemPrototypeStorage.LookupEntry(8383);
	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired() || message->copy_made || !proto)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	SlotResult result = _player->GetItemInterface()->FindFreeInventorySlot(proto);
	if(result.Result == 0)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	ItemPointer pItem = objmgr.CreateItem(8383, _player);
	pItem->SetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID, message_id);
	if( _player->GetItemInterface()->AddItemToFreeSlot(pItem) )
	{
		// mail now has an item after it
		message->copy_made = true;
		// update in sql
		message->SaveToDB();

		data << uint32(MAIL_OK);
		SendPacket(&data);
	}
	else
	{
		pItem->Destructor();
		pItem = NULLITEM;
	}
}
示例#4
0
void WorldSession::HandleMarkAsRead(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired()) return;

	message->read_flag = true;
	if(!message->returned_flag)
	{
		// mail now has a 3 day expiry time
		if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
			message->expire_time = (uint32)UNIXTIME + (TIME_DAY * 3);
	}
	message->SaveToDB();
}
示例#5
0
void WorldSession::HandleMailDelete(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_DELETED);

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);
		return;
	}

	_player->m_mailBox->DeleteMessage(message);

	data << uint32(MAIL_OK);
	SendPacket(&data);
}
示例#6
0
void WorldSession::HandleTakeItem(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	uint32 lowguid;
	vector< uint64 >::iterator itr;

	recv_data >> mailbox >> message_id >> lowguid;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_ITEM_TAKEN);
	
	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired() || message->items.empty())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	for( itr = message->items.begin( ); itr != message->items.end( ); ++itr )
	{
		if ( (*itr) == lowguid )
			break;
	}

	if( itr == message->items.end( ) )
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// check for cod credit
	if(message->cod > 0)
	{
		if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < message->cod)
		{
			data << uint32(MAIL_ERR_NOT_ENOUGH_MONEY);
			SendPacket(&data);
			return;
		}
	}

	// grab the item
	ItemPointer item = objmgr.LoadItem( *itr );
	if(item == 0)
	{
		// doesn't exist
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);
		
		return;
	}

	// find a free bag slot
	SlotResult result = _player->GetItemInterface()->FindFreeInventorySlot(item->GetProto());
	if(result.Result == 0)
	{
		// no free slots left!
		data << uint32(MAIL_ERR_BAG_FULL);
		SendPacket(&data);

		item->Destructor();
		item = NULLITEM;
		return;
	}

	item->m_isDirty = true;

	if( !_player->GetItemInterface()->SafeAddItem(item, result.ContainerSlot, result.Slot) )
	{
		if( !_player->GetItemInterface()->AddItemToFreeSlot(item) )
		{
			// no free slots left!
			data << uint32(MAIL_ERR_BAG_FULL);
			SendPacket(&data);
			item->Destructor();
			item = NULLITEM;
			return;
		}
	}
	else												// true so it waitexecute's
		item->SaveToDB(result.ContainerSlot, result.Slot, true, NULL);

	// send complete packet
	data << uint32(MAIL_OK);
	data << item->GetUInt32Value(OBJECT_FIELD_GUID);
	data << item->GetUInt32Value(ITEM_FIELD_STACK_COUNT);

	message->items.erase( itr );

	if ((message->items.size() == 0) && (message->money == 0))
	{
		// mail now has a 3 day expiry time
		if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
			message->expire_time = (uint32)UNIXTIME + (TIME_DAY * 3);
	}

	if( message->cod > 0 )
	{
		_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -int32(message->cod));
		string subject = "COD Payment: ";
		subject += message->subject;
		sMailSystem.DeliverMessage(NORMAL, message->player_guid, message->sender_guid, subject, "", message->cod, 0, 0, 1, true);

		message->cod = 0;
	}

	// re-save (update the items field)
	message->SaveToDB();// sMailSystem.SaveMessageToSQL( message);
	SendPacket(&data);

	// prolly need to send an item push here
}