diff --git a/src/servers/Server_Zone/Actor/PlayerSql.cpp b/src/servers/Server_Zone/Actor/PlayerSql.cpp index 26fb155f..7e9cfd71 100644 --- a/src/servers/Server_Zone/Actor/PlayerSql.cpp +++ b/src/servers/Server_Zone/Actor/PlayerSql.cpp @@ -177,7 +177,8 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession ) m_lastTickTime = 0; auto pPlayer = getAsPlayer(); - m_pInventory = InventoryPtr( new Inventory( pPlayer ) ); + // TODO: remove Inventory and actually inline it in Player class + m_pInventory = InventoryPtr( new Inventory( pPlayer.get() ) ); pPlayer->calculateStats(); diff --git a/src/servers/Server_Zone/Inventory/Inventory.cpp b/src/servers/Server_Zone/Inventory/Inventory.cpp index 116ffd51..6ac37b82 100644 --- a/src/servers/Server_Zone/Inventory/Inventory.cpp +++ b/src/servers/Server_Zone/Inventory/Inventory.cpp @@ -27,7 +27,7 @@ using namespace Core::Network; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; -Core::Inventory::Inventory( Core::Entity::PlayerPtr pOwner ) +Core::Inventory::Inventory( Core::Entity::Player* pOwner ) { m_pOwner = pOwner; diff --git a/src/servers/Server_Zone/Inventory/Inventory.h b/src/servers/Server_Zone/Inventory/Inventory.h index 1fb690a4..7a0c16ad 100644 --- a/src/servers/Server_Zone/Inventory/Inventory.h +++ b/src/servers/Server_Zone/Inventory/Inventory.h @@ -13,7 +13,7 @@ using InventoryMap = std::map< uint16_t, ItemContainerPtr >; class Inventory { public: - Inventory( Entity::PlayerPtr pOwner ); + Inventory( Entity::Player* pOwner ); ~Inventory(); enum ContainerType : uint16_t @@ -191,7 +191,7 @@ public: private: - Entity::PlayerPtr m_pOwner; + Entity::Player* m_pOwner; InventoryMap m_inventoryMap; }; diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index 67a47dd9..bf16a446 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -61,7 +61,7 @@ Core::XMLConfigPtr Core::ServerZone::getConfig() const size_t Core::ServerZone::getSessionCount() const { - return m_sessionMap.size(); + return m_sessionMapById.size(); } bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, @@ -263,7 +263,7 @@ void Core::ServerZone::mainLoop() auto currTime = static_cast< uint32_t >( time( nullptr ) ); lock_guard< std::mutex > lock( this->m_sessionMutex ); - for( auto sessionIt : this->m_sessionMap ) + for( auto sessionIt : this->m_sessionMapById ) { auto session = sessionIt.second; if( session && session->getPlayer() ) @@ -284,8 +284,8 @@ void Core::ServerZone::mainLoop() } - auto it = this->m_sessionMap.begin(); - for( ; it != this->m_sessionMap.end(); ) + auto it = this->m_sessionMapById.begin(); + for( ; it != this->m_sessionMapById.end(); ) { uint32_t diff = currTime - it->second->getLastDataTime(); @@ -298,7 +298,8 @@ void Core::ServerZone::mainLoop() // if( it->second.unique() ) { g_log.info("[" + std::to_string(it->second->getId() ) + "] Session removal" ); - it = this->m_sessionMap.erase( it ); + it = this->m_sessionMapById.erase( it ); + removeSession( pPlayer->getName() ); continue; } } @@ -310,7 +311,8 @@ void Core::ServerZone::mainLoop() it->second->close(); // if( it->second.unique() ) { - it = this->m_sessionMap.erase(it ); + it = this->m_sessionMapById.erase( it ); + removeSession( pPlayer->getName() ); } } else @@ -329,9 +331,9 @@ bool Core::ServerZone::createSession( uint32_t sessionId ) const std::string session_id_str = std::to_string( sessionId ); - auto it = m_sessionMap.find( sessionId ); + auto it = m_sessionMapById.find( sessionId ); - if( it != m_sessionMap.end() ) + if( it != m_sessionMapById.end() ) { g_log.error( "[" + session_id_str + "] Error creating session" ); return false; @@ -340,7 +342,7 @@ bool Core::ServerZone::createSession( uint32_t sessionId ) g_log.info( "[" + session_id_str + "] Creating new session" ); boost::shared_ptr newSession( new Session( sessionId ) ); - m_sessionMap[sessionId] = newSession; + m_sessionMapById[sessionId] = newSession; if( !newSession->loadPlayer() ) { @@ -348,7 +350,7 @@ bool Core::ServerZone::createSession( uint32_t sessionId ) return false; } - m_playerSessionMap[newSession->getPlayer()->getName()] = newSession; + m_sessionMapByName[newSession->getPlayer()->getName()] = newSession; return true; @@ -356,15 +358,15 @@ bool Core::ServerZone::createSession( uint32_t sessionId ) void Core::ServerZone::removeSession( uint32_t sessionId ) { - m_sessionMap.erase( sessionId ); + m_sessionMapById.erase( sessionId ); } void Core::ServerZone::updateSession( uint32_t id ) { std::lock_guard< std::mutex > lock( m_sessionMutex ); - auto it = m_sessionMap.find( id ); + auto it = m_sessionMapById.find( id ); - if( it != m_sessionMap.end() ) + if( it != m_sessionMapById.end() ) it->second->loadPlayer(); } @@ -372,9 +374,9 @@ Core::SessionPtr Core::ServerZone::getSession( uint32_t id ) { //std::lock_guard lock( m_sessionMutex ); - auto it = m_sessionMap.find( id ); + auto it = m_sessionMapById.find( id ); - if( it != m_sessionMap.end() ) + if( it != m_sessionMapById.end() ) return ( it->second ); return nullptr; @@ -384,9 +386,9 @@ Core::SessionPtr Core::ServerZone::getSession( std::string playerName ) { //std::lock_guard lock( m_sessionMutex ); - auto it = m_playerSessionMap.find( playerName ); + auto it = m_sessionMapByName.find( playerName ); - if (it != m_playerSessionMap.end()) + if (it != m_sessionMapByName.end()) return (it->second); return nullptr; @@ -394,15 +396,15 @@ Core::SessionPtr Core::ServerZone::getSession( std::string playerName ) void Core::ServerZone::removeSession( std::string playerName ) { - m_playerSessionMap.erase( playerName ); + m_sessionMapByName.erase( playerName ); } void Core::ServerZone::updateSession( std::string playerName ) { std::lock_guard< std::mutex > lock( m_sessionMutex ); - auto it = m_playerSessionMap.find( playerName ); + auto it = m_sessionMapByName.find( playerName ); - if( it != m_playerSessionMap.end() ) + if( it != m_sessionMapByName.end() ) it->second->loadPlayer(); } diff --git a/src/servers/Server_Zone/ServerZone.h b/src/servers/Server_Zone/ServerZone.h index 632409e1..33d6a329 100644 --- a/src/servers/Server_Zone/ServerZone.h +++ b/src/servers/Server_Zone/ServerZone.h @@ -61,8 +61,8 @@ namespace Core { std::mutex m_sessionMutex; - std::map< uint32_t, SessionPtr > m_sessionMap; - std::map< std::string, SessionPtr > m_playerSessionMap; + std::map< uint32_t, SessionPtr > m_sessionMapById; + std::map< std::string, SessionPtr > m_sessionMapByName; std::map< uint32_t, uint32_t > m_zones;