Ejemplo n.º 1
0
void WorldSession::HandleGuildBankSwapItem(WorldPacket & recv_data)
{
	uint64 guid;
	uint8 source_isfrombank;
	uint32 itementry, unk1;
	uint8 autostore;
	uint32 i;

	Guild * pGuild = _player->m_playerInfo->guild;
	GuildMember * pMember = _player->m_playerInfo->guildMember;

	if(pGuild== NULL || pMember== NULL)
		return;

	recv_data >> guid >> source_isfrombank;
	if(source_isfrombank)
	{
		GuildBankTab * pSourceTab;
		GuildBankTab * pDestTab;
		Item* pSourceItem;
		Item* pDestItem;
		uint8 dest_bank;
		uint8 dest_bankslot;
		uint8 source_bank;
		uint8 source_bankslot;
		int32 splitted_count;

		/* read packet */
		recv_data >> dest_bank;
		recv_data >> dest_bankslot;
		recv_data >> unk1;
		recv_data >> source_bank;
		recv_data >> source_bankslot;

		recv_data >> itementry;
		recv_data >> autostore;
		recv_data >> splitted_count;

		/* sanity checks to avoid overflows */
		if(source_bankslot >= MAX_GUILD_BANK_SLOTS ||
			dest_bankslot >= MAX_GUILD_BANK_SLOTS ||
			source_bank >= MAX_GUILD_BANK_TABS ||
			dest_bank >= MAX_GUILD_BANK_TABS)
		{
			return;
		}

		/* make sure we have permissions */
		if(!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, dest_bank) ||
			!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, source_bank))
			return;

		/* locate the tabs */
		pSourceTab = pGuild->GetBankTab( source_bank );
		pDestTab = pGuild->GetBankTab( dest_bank );

		if(pSourceTab == NULL || pDestTab == NULL)
			return;

		if(pSourceTab == pDestTab && source_bankslot == dest_bankslot)
			return;

		pSourceItem = pSourceTab->pSlots[source_bankslot];
		pDestItem = pDestTab->pSlots[dest_bankslot];

		if(pSourceItem == NULL && pDestItem == NULL)
			return;

		if(splitted_count)
		{
			uint32 source_count = pSourceItem->GetUInt32Value( ITEM_FIELD_STACK_COUNT );

			if(pDestItem == NULL)
			{
				if(source_count == (uint32)splitted_count)
				{
					// swap
					pSourceTab->pSlots[source_bankslot] = pDestItem;
					pDestTab->pSlots[dest_bankslot] = pSourceItem;
				}
				else
				{
					pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count );

					pDestItem = objmgr.CreateItem(pSourceItem->GetEntry(), NULL);
					pDestItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT, splitted_count);
					pDestItem->SetUInt32Value(ITEM_FIELD_CREATOR, pSourceItem->GetUInt32Value(ITEM_FIELD_CREATOR));

					pDestTab->pSlots[dest_bankslot] = pDestItem;
				}
			}
			else
			{
				pDestItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, splitted_count );

				if((uint32)splitted_count != source_count)
					pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count );
				else
				{
					pSourceItem->DeleteMe();
					pSourceItem = NULLITEM;
					pSourceTab->pSlots[source_bankslot] = NULLITEM;
				}
			}
		}
		else
		{
			// swap
			pSourceTab->pSlots[source_bankslot] = pDestItem;
			pDestTab->pSlots[dest_bankslot] = pSourceItem;
		}

		/* update the client */
		if(pSourceTab == pDestTab)
		{
			/* send both slots in the packet */
			pGuild->SendGuildBank(this, pSourceTab, source_bankslot, dest_bankslot);
		}
		else
		{
			/* send a packet for each different bag */
			pGuild->SendGuildBank(this, pSourceTab, source_bankslot, -1);
			pGuild->SendGuildBank(this, pDestTab, dest_bankslot, -1);
		}

		/* update in sql */
		if(pDestItem == NULL)
		{
			/* this means the source slot is no longer being used. */
			CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u",
				pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot);
		}
		else
		{
			/* insert the new Item* */
			CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)",
				pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot, pDestItem->GetLowGUID());
		}

		if(pSourceItem == NULL)
		{
			/* this means the destination slot is no longer being used. */
			CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u",
				pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot);
		}
		else
		{
			/* insert the new Item* */
			CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)",
				pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot, pSourceItem->GetLowGUID());
		}
	}
	else
	{
Ejemplo n.º 2
0
void WorldSession::HandleGuildBankDepositItem(WorldPacket & recv_data)
{
	uint64 guid;
	uint8 source_isfrombank;
	uint32 wtf;
	uint8 wtf2;
	uint32 i;

	Guild * pGuild = _player->m_playerInfo->guild;
	GuildMember * pMember = _player->m_playerInfo->guildMember;
	
	if(pGuild==NULL || pMember==NULL)
		return;

	recv_data >> guid >> source_isfrombank;
	if(source_isfrombank)
	{
		GuildBankTab * pSourceTab;
		GuildBankTab * pDestTab;
		Item * pSourceItem;
		Item * pDestItem;
		uint8 dest_bank;
		uint8 dest_bankslot;
		uint8 source_bank;
		uint8 source_bankslot;

		/* read packet */
		recv_data >> dest_bank;
		recv_data >> dest_bankslot;
		recv_data >> wtf;
		recv_data >> source_bank;
		recv_data >> source_bankslot;

		/* sanity checks to avoid overflows */
		if(source_bankslot >= MAX_GUILD_BANK_SLOTS ||
			dest_bankslot >= MAX_GUILD_BANK_SLOTS ||
			source_bank >= MAX_GUILD_BANK_TABS ||
			dest_bank >= MAX_GUILD_BANK_TABS)
		{
			return;
		}

		/* make sure we have permissions */
		if(!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, dest_bank) || 
			!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, source_bank))
			return;

		/* locate the tabs */
		pSourceTab = pGuild->GetBankTab((uint32)source_bank);
		pDestTab = pGuild->GetBankTab((uint32)dest_bank);
		if(pSourceTab == NULL || pDestTab == NULL)
			return;

		pSourceItem = pSourceTab->pSlots[source_bankslot];
		pDestItem = pDestTab->pSlots[dest_bankslot];

		if(pSourceItem == NULL && pDestItem == NULL)
			return;

		/* perform the actual swap */
		pSourceTab->pSlots[source_bankslot] = pDestItem;
		pDestTab->pSlots[dest_bankslot] = pSourceItem;

		/* update the client */
		if(pSourceTab == pDestTab)
		{
			/* send both slots in the packet */
			pGuild->SendGuildBank(this, pSourceTab, source_bankslot, dest_bankslot);
		}
		else
		{
			/* send a packet for each different bag */
			pGuild->SendGuildBank(this, pSourceTab, source_bankslot, -1);
			pGuild->SendGuildBank(this, pDestTab, dest_bankslot, -1);
		}

		/* update in sql */
		if(pDestItem == NULL)
		{
			/* this means the source slot is no longer being used. */
			CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u",
				pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot);
		}
		else
		{
			/* insert the new item */
			CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)", 
				pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot, pDestItem->GetLowGUID());
		}

		if(pSourceItem == NULL)
		{
			/* this means the destination slot is no longer being used. */
			CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u",
				pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot);
		}
		else
		{
			/* insert the new item */
			CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)", 
				pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot, pSourceItem->GetLowGUID());
		}
	}
	else
	{
Ejemplo n.º 3
0
bool ChatHandler::CreateGuildCommand(const char* args, WorldSession *m_session)
{
	if(!*args)
		return false;

	Player * ptarget = m_session->GetPlayer()->GetMapMgr()->GetPlayer(m_session->GetPlayer()->GetSelection());
	if(ptarget == 0)
	{
		ptarget = m_session->GetPlayer();
	}

	if(strlen((char*)args)>75)
	{
		// send message to user
		char buf[256];
		snprintf((char*)buf,256,"The name was too long by %i", strlen((char*)args)-75);
		SystemMessage(m_session, buf);
		return true;
	}

	for (uint32 i = 0; i < strlen(args); i++) {
		if(!isalpha(args[i]) && args[i]!=' ') {
			SystemMessage(m_session, "Error, name can only contain chars A-Z and a-z.");
			return true;
		}
	}

	if(objmgr.GetGuildByGuildName(args))
	{
		WorldPacket data(SMSG_GUILD_COMMAND_RESULT, 100);
		data << uint32(0);
		data << args;
		data << uint32(C_R_GUILD_NAME_EXISTS);
		m_session->SendPacket(&data);
		return true;
	}

	Guild *pGuild = new Guild;
	uint32 guildId = pGuild->GetFreeGuildIdFromDb();

	if(guildId == 0)
	{
		printf("Error Getting Free Guild ID");
		delete pGuild;
		return false;
	}

	//Guild Setup
	pGuild->SetGuildId( guildId );
	pGuild->SetGuildName( args );
	pGuild->CreateRank("Guild Master", GR_RIGHT_ALL);
	pGuild->CreateRank("Officer", GR_RIGHT_ALL);
	pGuild->CreateRank("Veteran", GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK);  
	pGuild->CreateRank("Member", GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK);
	pGuild->CreateRank("Initiate", GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK);
	pGuild->SetGuildEmblemStyle( 0xFFFF );
	pGuild->SetGuildEmblemColor( 0xFFFF );
	pGuild->SetGuildBorderStyle( 0xFFFF );
	pGuild->SetGuildBorderColor( 0xFFFF );
	pGuild->SetGuildBackgroundColor( 0xFFFF );

	objmgr.AddGuild(pGuild);

	//Guild Leader Setup
	ptarget->SetGuildId( pGuild->GetGuildId() );
	ptarget->SetUInt32Value(PLAYER_GUILDID, pGuild->GetGuildId() );
	ptarget->SetGuildRank(GUILDRANK_GUILD_MASTER);
	ptarget->SetUInt32Value(PLAYER_GUILDRANK,GUILDRANK_GUILD_MASTER);
	pGuild->SetGuildLeaderGuid( ptarget->GetGUID() );
	pGuild->AddNewGuildMember( ptarget );

	pGuild->SaveToDb();
	pGuild->SaveRanksToDb();

	return true;
}