1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00

Merge pull request #437 from XeAri/housing

saving player names in map to reduce SQL query
This commit is contained in:
Mordred 2018-11-26 15:05:55 +01:00 committed by GitHub
commit 7562cb5879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View file

@ -1533,6 +1533,13 @@ uint32_t Core::Entity::Player::getTerritoryTypeId() const
void Core::Entity::Player::sendZonePackets()
{
if( isLogin() )
{
//Update player map in servermgr - in case player name has been changed
auto pServerMgr = g_fw.get< Core::ServerMgr >();
pServerMgr->updatePlayerName( getId(), getName() );
}
getCurrentZone()->onBeforePlayerZoneIn( *this );
auto initPacket = makeZonePacket< FFXIVIpcInit >( getId() );

View file

@ -365,15 +365,31 @@ bool Core::ServerMgr::isRunning() const
return m_bRunning;
}
std::string Core::ServerMgr::getPlayerNameFromDb( uint32_t playerId )
std::string Core::ServerMgr::getPlayerNameFromDb( uint32_t playerId, bool forceDbLoad )
{
if( !forceDbLoad )
{
auto it = m_playerNameMapById.find( playerId );
if( it != m_playerNameMapById.end() )
return ( it->second );
}
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
auto res = pDb->query( "SELECT name FROM charainfo WHERE characterid = " + std::to_string( playerId ) );
if( !res->next() )
return "Unknown";
return res->getString( 1 );
std::string playerName = res->getString( 1 );
updatePlayerName( playerId, playerName );
return playerName;
}
void Core::ServerMgr::updatePlayerName( uint32_t playerId, const std::string & playerNewName )
{
m_playerNameMapById[ playerId ] = playerNewName;
}
void Core::ServerMgr::loadBNpcTemplates()

View file

@ -44,7 +44,8 @@ public:
Entity::BNpcTemplatePtr getBNpcTemplate( const std::string& key );
Entity::BNpcTemplatePtr getBNpcTemplate( uint32_t id );
std::string getPlayerNameFromDb( uint32_t playerId );
std::string getPlayerNameFromDb( uint32_t playerId, bool forceDbLoad = false );
void updatePlayerName( uint32_t playerId, const std::string& playerNewName );
private:
uint16_t m_port;
@ -59,6 +60,7 @@ private:
std::map< uint32_t, SessionPtr > m_sessionMapById;
std::map< std::string, SessionPtr > m_sessionMapByName;
std::map< uint32_t, std::string > m_playerNameMapById;
std::map< uint32_t, uint32_t > m_zones;
std::map< std::string, Entity::BNpcTemplatePtr > m_bNpcTemplateMap;