1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 00:47:45 +00:00

renamed sessionMap and playerSessionMap to make more sense, also fixed player object not being destructed properly

This commit is contained in:
Mordred Admin 2017-12-07 12:09:08 +01:00
parent dbf4bd957b
commit f979793b5b
5 changed files with 29 additions and 26 deletions

View file

@ -177,7 +177,8 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
m_lastTickTime = 0; m_lastTickTime = 0;
auto pPlayer = getAsPlayer(); 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(); pPlayer->calculateStats();

View file

@ -27,7 +27,7 @@ using namespace Core::Network;
using namespace Core::Network::Packets; using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server; using namespace Core::Network::Packets::Server;
Core::Inventory::Inventory( Core::Entity::PlayerPtr pOwner ) Core::Inventory::Inventory( Core::Entity::Player* pOwner )
{ {
m_pOwner = pOwner; m_pOwner = pOwner;

View file

@ -13,7 +13,7 @@ using InventoryMap = std::map< uint16_t, ItemContainerPtr >;
class Inventory class Inventory
{ {
public: public:
Inventory( Entity::PlayerPtr pOwner ); Inventory( Entity::Player* pOwner );
~Inventory(); ~Inventory();
enum ContainerType : uint16_t enum ContainerType : uint16_t
@ -191,7 +191,7 @@ public:
private: private:
Entity::PlayerPtr m_pOwner; Entity::Player* m_pOwner;
InventoryMap m_inventoryMap; InventoryMap m_inventoryMap;
}; };

View file

@ -61,7 +61,7 @@ Core::XMLConfigPtr Core::ServerZone::getConfig() const
size_t Core::ServerZone::getSessionCount() 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, 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 ) ); auto currTime = static_cast< uint32_t >( time( nullptr ) );
lock_guard< std::mutex > lock( this->m_sessionMutex ); lock_guard< std::mutex > lock( this->m_sessionMutex );
for( auto sessionIt : this->m_sessionMap ) for( auto sessionIt : this->m_sessionMapById )
{ {
auto session = sessionIt.second; auto session = sessionIt.second;
if( session && session->getPlayer() ) if( session && session->getPlayer() )
@ -284,8 +284,8 @@ void Core::ServerZone::mainLoop()
} }
auto it = this->m_sessionMap.begin(); auto it = this->m_sessionMapById.begin();
for( ; it != this->m_sessionMap.end(); ) for( ; it != this->m_sessionMapById.end(); )
{ {
uint32_t diff = currTime - it->second->getLastDataTime(); uint32_t diff = currTime - it->second->getLastDataTime();
@ -298,7 +298,8 @@ void Core::ServerZone::mainLoop()
// if( it->second.unique() ) // if( it->second.unique() )
{ {
g_log.info("[" + std::to_string(it->second->getId() ) + "] Session removal" ); 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; continue;
} }
} }
@ -310,7 +311,8 @@ void Core::ServerZone::mainLoop()
it->second->close(); it->second->close();
// if( it->second.unique() ) // if( it->second.unique() )
{ {
it = this->m_sessionMap.erase(it ); it = this->m_sessionMapById.erase( it );
removeSession( pPlayer->getName() );
} }
} }
else else
@ -329,9 +331,9 @@ bool Core::ServerZone::createSession( uint32_t sessionId )
const std::string session_id_str = std::to_string( 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" ); g_log.error( "[" + session_id_str + "] Error creating session" );
return false; return false;
@ -340,7 +342,7 @@ bool Core::ServerZone::createSession( uint32_t sessionId )
g_log.info( "[" + session_id_str + "] Creating new session" ); g_log.info( "[" + session_id_str + "] Creating new session" );
boost::shared_ptr<Session> newSession( new Session( sessionId ) ); boost::shared_ptr<Session> newSession( new Session( sessionId ) );
m_sessionMap[sessionId] = newSession; m_sessionMapById[sessionId] = newSession;
if( !newSession->loadPlayer() ) if( !newSession->loadPlayer() )
{ {
@ -348,7 +350,7 @@ bool Core::ServerZone::createSession( uint32_t sessionId )
return false; return false;
} }
m_playerSessionMap[newSession->getPlayer()->getName()] = newSession; m_sessionMapByName[newSession->getPlayer()->getName()] = newSession;
return true; return true;
@ -356,15 +358,15 @@ bool Core::ServerZone::createSession( uint32_t sessionId )
void Core::ServerZone::removeSession( 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 ) void Core::ServerZone::updateSession( uint32_t id )
{ {
std::lock_guard< std::mutex > lock( m_sessionMutex ); 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(); it->second->loadPlayer();
} }
@ -372,9 +374,9 @@ Core::SessionPtr Core::ServerZone::getSession( uint32_t id )
{ {
//std::lock_guard<std::mutex> lock( m_sessionMutex ); //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() )
return ( it->second ); return ( it->second );
return nullptr; return nullptr;
@ -384,9 +386,9 @@ Core::SessionPtr Core::ServerZone::getSession( std::string playerName )
{ {
//std::lock_guard<std::mutex> lock( m_sessionMutex ); //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())
return (it->second); return (it->second);
return nullptr; return nullptr;
@ -394,15 +396,15 @@ Core::SessionPtr Core::ServerZone::getSession( std::string playerName )
void Core::ServerZone::removeSession( 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 ) void Core::ServerZone::updateSession( std::string playerName )
{ {
std::lock_guard< std::mutex > lock( m_sessionMutex ); 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(); it->second->loadPlayer();
} }

View file

@ -61,8 +61,8 @@ namespace Core {
std::mutex m_sessionMutex; std::mutex m_sessionMutex;
std::map< uint32_t, SessionPtr > m_sessionMap; std::map< uint32_t, SessionPtr > m_sessionMapById;
std::map< std::string, SessionPtr > m_playerSessionMap; std::map< std::string, SessionPtr > m_sessionMapByName;
std::map< uint32_t, uint32_t > m_zones; std::map< uint32_t, uint32_t > m_zones;