From 101f284003eeed76fa2549f94d89db9bac0233a1 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 23 Dec 2018 13:26:33 +0100 Subject: [PATCH] More fw related cleanup --- src/api/main.cpp | 2 -- src/world/Action/EventAction.cpp | 2 +- src/world/Actor/BNpc.cpp | 3 -- src/world/Actor/EventObject.cpp | 4 --- src/world/Actor/Npc.cpp | 2 -- src/world/Actor/PlayerInventory.cpp | 21 ++++++------- src/world/Actor/PlayerSql.cpp | 10 ++++--- src/world/Inventory/ItemUtil.h | 27 ----------------- .../ItemUtil.cpp => Manager/ItemMgr.cpp} | 30 +++++++++++-------- src/world/Manager/ItemMgr.h | 30 +++++++++++++++++++ src/world/Network/GameConnection.cpp | 4 +-- src/world/ServerMgr.cpp | 4 ++- src/world/Session.cpp | 3 -- src/world/StatusEffect/StatusEffect.cpp | 2 +- src/world/Territory/Cell.cpp | 4 --- src/world/Territory/Land.cpp | 6 ++-- src/world/mainGameServer.cpp | 19 ++---------- 17 files changed, 78 insertions(+), 95 deletions(-) delete mode 100644 src/world/Inventory/ItemUtil.h rename src/world/{Inventory/ItemUtil.cpp => Manager/ItemMgr.cpp} (84%) create mode 100644 src/world/Manager/ItemMgr.h diff --git a/src/api/main.cpp b/src/api/main.cpp index b52f7824..81aa0024 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -32,8 +32,6 @@ #include "Forwards.h" #include "SapphireAPI.h" - -Sapphire::Framework g_fw; Sapphire::Db::DbWorkerPool< Sapphire::Db::ZoneDbConnection > g_charaDb; Sapphire::Data::ExdDataGenerated g_exdDataGen; Sapphire::Network::SapphireAPI g_sapphireAPI; diff --git a/src/world/Action/EventAction.cpp b/src/world/Action/EventAction.cpp index 14a6ed41..4463d99b 100644 --- a/src/world/Action/EventAction.cpp +++ b/src/world/Action/EventAction.cpp @@ -25,7 +25,7 @@ Sapphire::Action::EventAction::EventAction() } Sapphire::Action::EventAction::EventAction( Entity::CharaPtr pActor, uint32_t eventId, uint16_t action, - ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ) + ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ) { auto pExdData = g_fw.get< Data::ExdDataGenerated >(); diff --git a/src/world/Actor/BNpc.cpp b/src/world/Actor/BNpc.cpp index fee7bc56..b12e25d1 100644 --- a/src/world/Actor/BNpc.cpp +++ b/src/world/Actor/BNpc.cpp @@ -28,11 +28,8 @@ #include "BNpc.h" #include "BNpcTemplate.h" #include "Manager/TerritoryMgr.h" -#include "Framework.h" #include "Common.h" -extern Sapphire::Framework g_fw; - using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::Server; diff --git a/src/world/Actor/EventObject.cpp b/src/world/Actor/EventObject.cpp index 9265ef50..94c0d9bc 100644 --- a/src/world/Actor/EventObject.cpp +++ b/src/world/Actor/EventObject.cpp @@ -18,10 +18,6 @@ using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::Server; using namespace Sapphire::Network::ActorControl; -#include "Framework.h" - -extern Sapphire::Framework g_fw; - Sapphire::Entity::EventObject::EventObject( uint32_t actorId, uint32_t objectId, uint32_t gimmickId, uint8_t initialState, Common::FFXIVARR_POSITION3 pos, float rotation, const std::string& givenName ) : diff --git a/src/world/Actor/Npc.cpp b/src/world/Actor/Npc.cpp index 341dd5c5..89e6815c 100644 --- a/src/world/Actor/Npc.cpp +++ b/src/world/Actor/Npc.cpp @@ -30,8 +30,6 @@ #include "Framework.h" #include "Common.h" -extern Sapphire::Framework g_fw; - using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::Server; diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index 0224aabb..9cd96492 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -11,7 +11,7 @@ #include "Inventory/Item.h" #include "Inventory/ItemContainer.h" -#include "Inventory/ItemUtil.h" + #include "Player.h" #include "Framework.h" @@ -28,6 +28,7 @@ #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Manager/InventoryMgr.h" +#include "Manager/ItemMgr.h" #include "Framework.h" #include @@ -510,7 +511,7 @@ Sapphire::ItemPtr Sapphire::Entity::Player::addItem( uint32_t catalogId, uint32_ // add the related armoury bag to the applicable bags and try and fill a free slot there before falling back to regular inventory if( itemInfo->isEquippable && getEquipDisplayFlags() & StoreNewItemsInArmouryChest ) { - auto bag = Items::Util::getCharaEquipSlotCategoryToArmoryId( itemInfo->equipSlotCategory ); + auto bag = World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( itemInfo->equipSlotCategory ); bags.insert( bags.begin(), bag ); } @@ -622,7 +623,7 @@ Sapphire::Entity::Player::moveItem( uint16_t fromInventoryId, uint8_t fromSlotId bool Sapphire::Entity::Player::updateContainer( uint16_t storageId, uint8_t slotId, ItemPtr pItem ) { - auto containerType = Items::Util::getContainerType( storageId ); + auto containerType = World::Manager::ItemMgr::getContainerType( storageId ); m_storageMap[ storageId ]->setItem( slotId, pItem ); @@ -733,17 +734,17 @@ void Sapphire::Entity::Player::swapItem( uint16_t fromInventoryId, uint8_t fromS // An item is being moved from bag0-3 to equippment, meaning // the swapped out item will be placed in the matching armory. - if( Items::Util::isEquipment( toInventoryId ) - && !Items::Util::isEquipment( fromInventoryId ) - && !Items::Util::isArmory( fromInventoryId ) ) + if( World::Manager::ItemMgr::isEquipment( toInventoryId ) + && !World::Manager::ItemMgr::isEquipment( fromInventoryId ) + && !World::Manager::ItemMgr::isArmory( fromInventoryId ) ) { updateContainer( fromInventoryId, fromSlotId, nullptr ); - fromInventoryId = Items::Util::getCharaEquipSlotCategoryToArmoryId( toSlot ); + fromInventoryId = World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( toSlot ); fromSlotId = static_cast < uint8_t >( m_storageMap[ fromInventoryId ]->getFreeSlot() ); } - auto containerTypeFrom = Items::Util::getContainerType( fromInventoryId ); - auto containerTypeTo = Items::Util::getContainerType( toInventoryId ); + auto containerTypeFrom = World::Manager::ItemMgr::getContainerType( fromInventoryId ); + auto containerTypeTo = World::Manager::ItemMgr::getContainerType( toInventoryId ); updateContainer( toInventoryId, toSlot, fromItem ); updateContainer( fromInventoryId, fromSlotId, toItem ); @@ -805,7 +806,7 @@ uint16_t Sapphire::Entity::Player::calculateEquippedGearItemLevel() iLvlResult += currItem->getItemLevel(); // If item is weapon and isn't one-handed - if( currItem->isWeapon() && !Items::Util::isOneHandedWeapon( currItem->getCategory() ) ) + if( currItem->isWeapon() && !World::Manager::ItemMgr::isOneHandedWeapon( currItem->getCategory() ) ) { iLvlResult += currItem->getItemLevel(); } diff --git a/src/world/Actor/PlayerSql.cpp b/src/world/Actor/PlayerSql.cpp index 4754d835..37666dcb 100644 --- a/src/world/Actor/PlayerSql.cpp +++ b/src/world/Actor/PlayerSql.cpp @@ -16,7 +16,7 @@ #include "Territory/Zone.h" #include "Inventory/Item.h" #include "Inventory/ItemContainer.h" -#include "Inventory/ItemUtil.h" +#include "Manager/ItemMgr.h" #include "ServerMgr.h" #include "Framework.h" @@ -570,6 +570,7 @@ Sapphire::ItemPtr Sapphire::Entity::Player::createItem( uint32_t catalogId, uint auto pExdData = g_fw.get< Data::ExdDataGenerated >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto itemInfo = pExdData->get< Sapphire::Data::Item >( catalogId ); + auto itemMgr = g_fw.get< World::Manager::ItemMgr >(); if( !itemInfo ) return nullptr; @@ -579,7 +580,7 @@ Sapphire::ItemPtr Sapphire::Entity::Player::createItem( uint32_t catalogId, uint uint8_t flags = 0; - ItemPtr pItem = make_Item( Items::Util::getNextUId(), + ItemPtr pItem = make_Item( itemMgr->getNextUId(), catalogId, itemInfo->modelMain, itemInfo->modelSub ); @@ -598,6 +599,7 @@ Sapphire::ItemPtr Sapphire::Entity::Player::createItem( uint32_t catalogId, uint bool Sapphire::Entity::Player::loadInventory() { + auto itemMgr = g_fw.get< World::Manager::ItemMgr >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); ////////////////////////////////////////////////////////////////////////////////////////////////////// // load active gearset @@ -619,7 +621,7 @@ bool Sapphire::Entity::Player::loadInventory() if( uItemId == 0 ) continue; - ItemPtr pItem = Items::Util::loadItem( uItemId ); + ItemPtr pItem = itemMgr->loadItem( uItemId ); if( pItem == nullptr ) continue; @@ -652,7 +654,7 @@ bool Sapphire::Entity::Player::loadInventory() if( uItemId == 0 ) continue; - ItemPtr pItem = Items::Util::loadItem( uItemId ); + ItemPtr pItem = itemMgr->loadItem( uItemId ); if( pItem == nullptr ) continue; diff --git a/src/world/Inventory/ItemUtil.h b/src/world/Inventory/ItemUtil.h deleted file mode 100644 index 6645425c..00000000 --- a/src/world/Inventory/ItemUtil.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef SAPPHIRE_ITEMUTIL_H -#define SAPPHIRE_ITEMUTIL_H - -#include -#include "ForwardsZone.h" - -namespace Sapphire::Items::Util -{ - - ItemPtr loadItem( uint64_t uId ); - - /*! check if weapon category qualifies the weapon as onehanded */ - bool isOneHandedWeapon( Common::ItemUICategory weaponCategory ); - - bool isArmory( uint16_t containerId ); - - bool isEquipment( uint16_t containerId ); - - uint16_t getCharaEquipSlotCategoryToArmoryId( uint8_t slotId ); - - Common::ContainerType getContainerType( uint32_t containerId ); - - uint32_t getNextUId(); - -} - -#endif //SAPPHIRE_ITEMMGR_H diff --git a/src/world/Inventory/ItemUtil.cpp b/src/world/Manager/ItemMgr.cpp similarity index 84% rename from src/world/Inventory/ItemUtil.cpp rename to src/world/Manager/ItemMgr.cpp index bb036828..dca5cd2e 100644 --- a/src/world/Inventory/ItemUtil.cpp +++ b/src/world/Manager/ItemMgr.cpp @@ -1,7 +1,7 @@ -#include "ItemUtil.h" +#include "ItemMgr.h" -#include "ItemContainer.h" -#include "Item.h" +#include "Inventory/ItemContainer.h" +#include "Inventory/Item.h" #include "Framework.h" #include @@ -12,7 +12,13 @@ extern Sapphire::Framework g_fw; -bool Sapphire::Items::Util::isArmory( uint16_t containerId ) +Sapphire::World::Manager::ItemMgr::ItemMgr( Sapphire::FrameworkPtr pFw ) : + BaseManager( pFw ) +{ + +} + +bool Sapphire::World::Manager::ItemMgr::isArmory( uint16_t containerId ) { return containerId == Common::ArmoryBody || @@ -29,7 +35,8 @@ bool Sapphire::Items::Util::isArmory( uint16_t containerId ) containerId == Common::ArmorySoulCrystal; } -uint16_t Sapphire::Items::Util::getCharaEquipSlotCategoryToArmoryId( uint8_t slotId ) + +uint16_t Sapphire::World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( uint8_t slotId ) { switch( slotId ) @@ -87,13 +94,12 @@ uint16_t Sapphire::Items::Util::getCharaEquipSlotCategoryToArmoryId( uint8_t slo } -bool Sapphire::Items::Util::isEquipment( uint16_t containerId ) +bool Sapphire::World::Manager::ItemMgr::isEquipment( uint16_t containerId ) { return containerId == Common::GearSet0; } - -bool Sapphire::Items::Util::isOneHandedWeapon( Common::ItemUICategory weaponCategory ) +bool Sapphire::World::Manager::ItemMgr::isOneHandedWeapon( Common::ItemUICategory weaponCategory ) { switch( weaponCategory ) { @@ -117,7 +123,7 @@ bool Sapphire::Items::Util::isOneHandedWeapon( Common::ItemUICategory weaponCate } } -Sapphire::ItemPtr Sapphire::Items::Util::loadItem( uint64_t uId ) +Sapphire::ItemPtr Sapphire::World::Manager::ItemMgr::loadItem( uint64_t uId ) { auto pExdData = g_fw.get< Data::ExdDataGenerated >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); @@ -148,7 +154,8 @@ Sapphire::ItemPtr Sapphire::Items::Util::loadItem( uint64_t uId ) } } -Sapphire::Common::ContainerType Sapphire::Items::Util::getContainerType( uint32_t containerId ) + +Sapphire::Common::ContainerType Sapphire::World::Manager::ItemMgr::getContainerType( uint32_t containerId ) { if( containerId < 5 ) { @@ -172,8 +179,7 @@ Sapphire::Common::ContainerType Sapphire::Items::Util::getContainerType( uint32_ } } - -uint32_t Sapphire::Items::Util::getNextUId() +uint32_t Sapphire::World::Manager::ItemMgr::getNextUId() { uint32_t charId = 0; auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); diff --git a/src/world/Manager/ItemMgr.h b/src/world/Manager/ItemMgr.h new file mode 100644 index 00000000..795f7c2b --- /dev/null +++ b/src/world/Manager/ItemMgr.h @@ -0,0 +1,30 @@ +#ifndef SAPPHIRE_ITEMMGR_H +#define SAPPHIRE_ITEMMGR_H + +#include +#include "ForwardsZone.h" +#include "BaseManager.h" + +namespace Sapphire::World::Manager +{ + + class ItemMgr : public BaseManager + { + public: + ItemMgr( FrameworkPtr pFw ); + + ItemPtr loadItem( uint64_t uId ); + + uint32_t getNextUId(); + + /*! check if weapon category qualifies the weapon as onehanded */ + static bool isOneHandedWeapon( Common::ItemUICategory weaponCategory ); + static bool isArmory( uint16_t containerId ); + static bool isEquipment( uint16_t containerId ); + static uint16_t getCharaEquipSlotCategoryToArmoryId( uint8_t slotId ); + static Common::ContainerType getContainerType( uint32_t containerId ); + }; + +} + +#endif //SAPPHIRE_ITEMMGR_H diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index e76e4ad5..fd909be7 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -20,8 +20,6 @@ #include "Framework.h" #include "Forwards.h" -extern Sapphire::Framework g_fw; - using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::Server; @@ -386,7 +384,7 @@ void Sapphire::Network::GameConnection::injectPacket( const std::string& packetp void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network::Packets::FFXIVARR_PACKET_HEADER& ipcHeader, const std::vector< Sapphire::Network::Packets::FFXIVARR_PACKET_RAW >& packetData ) { - auto pServerZone = g_fw.get< World::ServerMgr >(); + auto pServerZone = m_pFw->get< World::ServerMgr >(); // if a session is set, update the last time it recieved a game packet if( m_pSession ) m_pSession->updateLastDataTime(); diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index 4260561b..be5d006b 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -38,6 +38,7 @@ #include "Manager/ShopMgr.h" #include "Manager/InventoryMgr.h" #include "Manager/EventMgr.h" +#include "Manager/ItemMgr.h" using namespace Sapphire::World::Manager; @@ -166,12 +167,13 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) auto pShopMgr = std::make_shared< Manager::ShopMgr >( framework() ); auto pInventoryMgr = std::make_shared< Manager::InventoryMgr >(); auto pEventMgr = std::make_shared< Manager::EventMgr >( framework() ); + auto pItemMgr = std::make_shared< Manager::ItemMgr >( framework() ); framework()->set< DebugCommandMgr >( pDebugCom ); framework()->set< Manager::PlayerMgr >( pPlayerMgr ); framework()->set< Manager::ShopMgr >( pShopMgr ); framework()->set< Manager::InventoryMgr >( pInventoryMgr ); - framework()->set< Manager::EventMgr >( pEventMgr ); + framework()->set< Manager::ItemMgr >( pItemMgr ); Logger::info( "World server running on " + m_ip + ":" + std::to_string( m_port ) ); diff --git a/src/world/Session.cpp b/src/world/Session.cpp index 001148c7..3830b1d3 100644 --- a/src/world/Session.cpp +++ b/src/world/Session.cpp @@ -9,10 +9,7 @@ #include "Actor/Player.h" #include "Session.h" -#include "Framework.h" - -extern Sapphire::Framework g_fw; namespace fs = std::experimental::filesystem; Sapphire::World::Session::Session( uint32_t sessionId ) : diff --git a/src/world/StatusEffect/StatusEffect.cpp b/src/world/StatusEffect/StatusEffect.cpp index ac5cb5ae..c98cc8db 100644 --- a/src/world/StatusEffect/StatusEffect.cpp +++ b/src/world/StatusEffect/StatusEffect.cpp @@ -20,7 +20,7 @@ using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::Server; Sapphire::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::CharaPtr sourceActor, Entity::CharaPtr targetActor, - uint32_t duration, uint32_t tickRate ) + uint32_t duration, uint32_t tickRate ) : m_id( id ), m_sourceActor( sourceActor ), m_targetActor( targetActor ), m_duration( duration ), m_startTime( 0 ), m_tickRate( tickRate ), m_lastTick( 0 ) diff --git a/src/world/Territory/Cell.cpp b/src/world/Territory/Cell.cpp index 87b8a428..2ac8da95 100644 --- a/src/world/Territory/Cell.cpp +++ b/src/world/Territory/Cell.cpp @@ -5,10 +5,6 @@ #include "Zone.h" #include -#include "Framework.h" - -extern Sapphire::Framework g_fw; - // TODO: the entire zone / areahandling is a bit outdated ( in parts i used this for the 1.0 iteration ) // likely this could be greatly improved or redone diff --git a/src/world/Territory/Land.cpp b/src/world/Territory/Land.cpp index a10b72ce..1255a427 100644 --- a/src/world/Territory/Land.cpp +++ b/src/world/Territory/Land.cpp @@ -16,7 +16,8 @@ #include "Actor/Player.h" #include "Inventory/ItemContainer.h" #include "Inventory/Item.h" -#include "Inventory/ItemUtil.h" + +#include "Manager/ItemMgr.h" #include "Forwards.h" #include "Land.h" @@ -122,6 +123,7 @@ void Sapphire::Land::loadItemContainerContents() Logger::debug( "Loading housing inventory for ident: " + std::to_string( ident ) ); auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); + auto pItemMgr = g_fw.get< World::Manager::ItemMgr >(); auto stmt = pDB->getPreparedStatement( Db::LAND_INV_SEL_HOUSE ); stmt->setUInt64( 1, ident ); @@ -148,7 +150,7 @@ void Sapphire::Land::loadItemContainerContents() // todo: delet this for( auto fuck = it->second.begin(); fuck != it->second.end(); fuck++ ) { - auto item = Sapphire::Items::Util::loadItem( fuck->second ); + auto item = pItemMgr->loadItem( fuck->second ); if( item ) container->setItem( fuck->first, item ); } diff --git a/src/world/mainGameServer.cpp b/src/world/mainGameServer.cpp index e73fec68..a39f068b 100644 --- a/src/world/mainGameServer.cpp +++ b/src/world/mainGameServer.cpp @@ -3,27 +3,14 @@ #include "ServerMgr.h" #include -#include - -Sapphire::Framework g_fw; - using namespace Sapphire; using namespace Sapphire::World; -bool setupFramework() +int main( int32_t argc, char* argv[] ) { auto pFramework = Sapphire::make_Framework(); auto pServer = std::make_shared< ServerMgr >( "config.ini", pFramework ); - g_fw.set< ServerMgr >( pServer ); - - return true; -} - -int main( int32_t argc, char* argv[] ) -{ - if( !setupFramework() ) - return 0; // too fucking bad... - - g_fw.get< ServerMgr >()->run( argc, argv ); + pFramework->set< ServerMgr >( pServer ); + pServer->run( argc, argv ); return 0; }