From 899b4aead3acff674cf34f5a2c2fd9bc1253f9d2 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Wed, 5 Dec 2018 19:58:43 +1100 Subject: [PATCH] handle internal/external housing storeroom inventory requests --- src/common/Network/CommonActorControl.h | 3 +- .../sapphire_zone/Manager/HousingMgr.cpp | 42 +++++++++++++++++++ .../sapphire_zone/Manager/HousingMgr.h | 10 +++++ .../Network/Handlers/ClientTriggerHandler.cpp | 29 +++++++++++++ .../Housing/HousingInteriorTerritory.cpp | 7 +++- .../Housing/HousingInteriorTerritory.h | 2 + src/servers/sapphire_zone/Territory/Land.cpp | 9 ++++ src/servers/sapphire_zone/Territory/Land.h | 4 +- 8 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/common/Network/CommonActorControl.h b/src/common/Network/CommonActorControl.h index e15c95c3..f90c9a70 100644 --- a/src/common/Network/CommonActorControl.h +++ b/src/common/Network/CommonActorControl.h @@ -311,12 +311,13 @@ enum ActorControlType : uint16_t RequestLandSignOwned = 0x452, RequestWardLandInfo = 0x453, RequestLandRelinquish = 0x454, + RequestExternalHousingInventory = 0x0458, RequestEstateRename = 0x45A, RequestEstateEditGreeting = 0x45B, RequestEstateGreeting = 0x45C, // sends FFXIVIpcHousingEstateGreeting in return RequestEstateEditGuestAccessSettings = 0x45D, RequestEstateTagSettings = 0x45F, - + RequestInternalHousingInventory = 0x0461, RequestHousingItemUI = 0x463, RequestSharedEstateSettings = 0x46F, UpdateEstateLightingLevel = 0x471, diff --git a/src/servers/sapphire_zone/Manager/HousingMgr.cpp b/src/servers/sapphire_zone/Manager/HousingMgr.cpp index 1f7b7f39..1f5f6bab 100644 --- a/src/servers/sapphire_zone/Manager/HousingMgr.cpp +++ b/src/servers/sapphire_zone/Manager/HousingMgr.cpp @@ -17,6 +17,7 @@ #include "TerritoryMgr.h" #include "Territory/Zone.h" #include "Territory/HousingZone.h" +#include "Territory/Housing/HousingInteriorTerritory.h" #include "HousingMgr.h" #include "Territory/Land.h" #include "Framework.h" @@ -462,4 +463,45 @@ Sapphire::Common::LandIdent Sapphire::World::Manager::HousingMgr::clientTriggerP ident.landId = param12 & 0xFFFF; return ident; +} + +void Sapphire::World::Manager::HousingMgr::sendHousingInventory( Entity::Player& player, uint16_t inventoryType, uint8_t plotNum ) +{ + Sapphire::LandPtr targetLand; + + // plotNum will be 255 in the event that it's an internal zone + // and we have to switch up our way of getting the LandPtr + if( plotNum == 255 ) + { + auto internalZone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( player.getCurrentZone() ); + if( !internalZone ) + return; + + auto ident = internalZone->getIdent(); + + auto landSetId = toLandSetId( ident.territoryTypeId, ident.wardNum ); + auto exteriorZone = getHousingZoneByLandSetId( landSetId ); + + if( !exteriorZone ) + return; + + targetLand = exteriorZone->getLand( ident.landId ); + } + else + { + auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() ); + if( !zone ) + return; + + targetLand = zone->getLand( plotNum ); + } + + if( !targetLand ) + return; + + // todo: add proper permissions checks + if( targetLand->getPlayerOwner() != player.getId() ) + return; + + player.sendDebug( "got inventory for plot: " + targetLand->getHouse()->getHouseName() ); } \ No newline at end of file diff --git a/src/servers/sapphire_zone/Manager/HousingMgr.h b/src/servers/sapphire_zone/Manager/HousingMgr.h index 9745b2f1..e0f5c232 100644 --- a/src/servers/sapphire_zone/Manager/HousingMgr.h +++ b/src/servers/sapphire_zone/Manager/HousingMgr.h @@ -30,6 +30,9 @@ namespace Sapphire::World::Manager void sendLandSignFree( Entity::Player& player, const Common::LandIdent ident ); LandPurchaseResult purchaseLand( Entity::Player& player, uint8_t plot, uint8_t state ); + /*! + * @brief Converts param1 of a client trigger into a Common::LandIndent + */ Common::LandIdent clientTriggerParamsToLandIdent( uint32_t param11, uint32_t param12 ) const; void sendWardLandInfo( Entity::Player& player, uint8_t wardId, uint16_t territoryTypeId ); @@ -47,6 +50,13 @@ namespace Sapphire::World::Manager void sendEstateGreeting( Entity::Player& player, const Common::LandIdent ident ); + /*! + * @brief Sends the house inventory for the specified type to a player. + * + * This enforces permissions on the inventory too so random players can't request a houses items + */ + void sendHousingInventory( Entity::Player& player, uint16_t inventoryType, uint8_t plotNum ); + }; } diff --git a/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp b/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp index 1e309533..13c3f640 100644 --- a/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp +++ b/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp @@ -421,6 +421,35 @@ void Sapphire::Network::GameConnection::clientTriggerHandler( const Packets::FFX break; } + case ClientTriggerType::RequestExternalHousingInventory: + { + if( param2 != 1 ) + return; + + uint8_t plot = ( param12 & 0xFF ); + + auto housingMgr = g_fw.get< HousingMgr >(); + if( !housingMgr ) + break; + + housingMgr->sendHousingInventory( player, Common::InventoryType::HousingOutdoorItemStoreroom, plot ); + + break; + } + case ClientTriggerType::RequestInternalHousingInventory: + { + // only sent if param1 is 1, because the client sends this with 0 when you open the ui for whatever reason + if( param1 != 1 ) + return; + + auto housingMgr = g_fw.get< HousingMgr >(); + if( !housingMgr ) + break; + + housingMgr->sendHousingInventory( player, Common::InventoryType::HousingIndoorItemStoreroom, 255 ); + + break; + } default: { diff --git a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp index 373d725a..da5c399d 100644 --- a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp +++ b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp @@ -68,7 +68,7 @@ void Housing::HousingInteriorTerritory::onPlayerZoneIn( Entity::Player& player ) for( auto i = 0; i < 10; i++ ) { - indoorInitPacket->data().indoorItems[ i ] = pHouse->getHouseInteriorPart( (Common::HousingInteriorSlot)i ); + indoorInitPacket->data().indoorItems[ i ] = pHouse->getHouseInteriorPart( static_cast< Common::HousingInteriorSlot >( i ) ); } @@ -102,4 +102,9 @@ void Housing::HousingInteriorTerritory::onUpdate( uint32_t currTime ) uint32_t Housing::HousingInteriorTerritory::getLastActivityTime() const { return m_lastActivityTime; +} + +const Common::LandIdent Housing::HousingInteriorTerritory::getIdent() const +{ + return m_landIdent; } \ No newline at end of file diff --git a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h index e5be57a9..f8287df8 100644 --- a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h +++ b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h @@ -20,6 +20,8 @@ namespace Sapphire::World::Territory::Housing uint32_t getLastActivityTime() const; + const Common::LandIdent getIdent() const; + private: Common::LandIdent m_landIdent; uint32_t m_lastActivityTime; diff --git a/src/servers/sapphire_zone/Territory/Land.cpp b/src/servers/sapphire_zone/Territory/Land.cpp index 4ef3bae8..31071b76 100644 --- a/src/servers/sapphire_zone/Territory/Land.cpp +++ b/src/servers/sapphire_zone/Territory/Land.cpp @@ -355,3 +355,12 @@ bool Sapphire::Land::setPreset( uint32_t itemId ) return true; } + +Sapphire::ItemContainerPtr Sapphire::Land::getInventory( uint16_t inventoryType ) const +{ + auto container = m_landInventoryMap.find( inventoryType ); + if( container == m_landInventoryMap.end() ) + return nullptr; + + return container->second; +} \ No newline at end of file diff --git a/src/servers/sapphire_zone/Territory/Land.h b/src/servers/sapphire_zone/Territory/Land.h index 1b4b2fa1..b509ea07 100644 --- a/src/servers/sapphire_zone/Territory/Land.h +++ b/src/servers/sapphire_zone/Territory/Land.h @@ -18,7 +18,7 @@ namespace Sapphire Land( uint16_t zoneId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, Sapphire::Data::HousingLandSetPtr info ); virtual ~Land(); - using LandInventoryMap = std::unordered_map< uint32_t, ItemContainerPtr >; + using LandInventoryMap = std::unordered_map< uint16_t, ItemContainerPtr >; //Primary state void setSize( uint8_t size ); @@ -61,6 +61,8 @@ namespace Sapphire void setLandTag( uint8_t slot, uint8_t tag ); uint8_t getLandTag( uint8_t slot ); + ItemContainerPtr getInventory( uint16_t inventoryType ) const; + private: uint32_t convertItemIdToHousingItemId( uint32_t itemId ); void init();