diff --git a/src/servers/sapphire_zone/ServerMgr.cpp b/src/servers/sapphire_zone/ServerMgr.cpp index 26aaa18e..d521f999 100644 --- a/src/servers/sapphire_zone/ServerMgr.cpp +++ b/src/servers/sapphire_zone/ServerMgr.cpp @@ -367,9 +367,9 @@ bool Core::ServerMgr::isRunning() const std::string Core::ServerMgr::getPlayerNameFromDb( uint32_t playerId ) { - auto it = m_payerNameMap.find( playerId ); + auto it = m_payerNameMapById.find( playerId ); - if( it != m_payerNameMap.end() ) + if( it != m_payerNameMapById.end() ) return ( it->second ); auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); @@ -380,11 +380,19 @@ std::string Core::ServerMgr::getPlayerNameFromDb( uint32_t playerId ) std::string playerName = res->getString( 1 ); - m_payerNameMap[ playerId ] = playerName; + m_payerNameMapById[ playerId ] = playerName; return playerName; } +void Core::ServerMgr::updatePlayerName( uint32_t playerId, const std::string & playerNewName ) +{ + auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); + pDb->execute( "UPDATE charainfo SET name = '" + playerNewName + "' WHERE name = " + std::to_string( playerId ) ); + + m_payerNameMapById[ playerId ] = playerNewName; +} + void Core::ServerMgr::loadBNpcTemplates() { auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); diff --git a/src/servers/sapphire_zone/ServerMgr.h b/src/servers/sapphire_zone/ServerMgr.h index 6a2721e9..7c2a91db 100644 --- a/src/servers/sapphire_zone/ServerMgr.h +++ b/src/servers/sapphire_zone/ServerMgr.h @@ -45,6 +45,7 @@ public: Entity::BNpcTemplatePtr getBNpcTemplate( uint32_t id ); std::string getPlayerNameFromDb( uint32_t playerId ); + void updatePlayerName( uint32_t playerId, const std::string& playerNewName ); private: uint16_t m_port; @@ -59,7 +60,7 @@ private: std::map< uint32_t, SessionPtr > m_sessionMapById; std::map< std::string, SessionPtr > m_sessionMapByName; - std::map< uint32_t, std::string > m_payerNameMap; + std::map< uint32_t, std::string > m_payerNameMapById; std::map< uint32_t, uint32_t > m_zones; std::map< std::string, Entity::BNpcTemplatePtr > m_bNpcTemplateMap;