2018-03-06 22:22:19 +01:00
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Database/DatabaseDef.h>
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-12-02 02:01:41 +01:00
|
|
|
#include "Linkshell/Linkshell.h"
|
2018-03-02 07:22:25 -03:00
|
|
|
#include "Framework.h"
|
|
|
|
#include "LinkshellMgr.h"
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-12-22 22:25:03 +01:00
|
|
|
Sapphire::World::Manager::LinkshellMgr::LinkshellMgr( FrameworkPtr pFw ) :
|
|
|
|
BaseManager( pFw )
|
2017-08-28 18:36:51 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-02 02:01:41 +01:00
|
|
|
bool Sapphire::World::Manager::LinkshellMgr::loadLinkshells()
|
2017-08-28 18:36:51 +02:00
|
|
|
{
|
2018-12-22 22:25:03 +01:00
|
|
|
auto pDb = framework()->get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
2018-08-29 21:40:59 +02:00
|
|
|
auto res = pDb->query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
|
|
|
|
"LinkshellName, LeaderIdList, InviteIdList "
|
|
|
|
"FROM infolinkshell "
|
|
|
|
"ORDER BY LinkshellId ASC;" );
|
|
|
|
|
|
|
|
|
|
|
|
while( res->next() )
|
|
|
|
{
|
|
|
|
uint64_t linkshellId = res->getUInt64( 1 );
|
|
|
|
uint32_t masterId = res->getUInt( 2 );
|
|
|
|
std::string name = res->getString( 4 );
|
|
|
|
|
|
|
|
auto func = []( std::set< uint64_t >& outList, std::vector< char >& inData )
|
|
|
|
{
|
|
|
|
if( inData.size() )
|
2017-08-28 23:19:35 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
std::vector< uint64_t > list( inData.size() / 8 );
|
|
|
|
outList.insert( list.begin(), list.end() );
|
|
|
|
}
|
|
|
|
};
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::set< uint64_t > members;
|
|
|
|
std::vector< char > membersBin;
|
|
|
|
membersBin = res->getBlobVector( 3 );
|
|
|
|
func( members, membersBin );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::set< uint64_t > leaders;
|
|
|
|
std::vector< char > leadersBin;
|
|
|
|
leadersBin = res->getBlobVector( 5 );
|
|
|
|
func( members, leadersBin );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::set< uint64_t > invites;
|
|
|
|
std::vector< char > invitesBin;
|
|
|
|
invitesBin = res->getBlobVector( 6 );
|
|
|
|
func( members, invitesBin );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-10-25 12:44:51 +11:00
|
|
|
auto lsPtr = std::make_shared< Linkshell >( linkshellId, name, masterId, members, leaders, invites );
|
2018-08-29 21:40:59 +02:00
|
|
|
m_linkshellIdMap[ linkshellId ] = lsPtr;
|
|
|
|
m_linkshellNameMap[ name ] = lsPtr;
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2017-08-28 18:36:51 +02:00
|
|
|
|
|
|
|
}
|
2017-08-28 23:43:52 +02:00
|
|
|
|
2018-12-02 02:01:41 +01:00
|
|
|
Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::getLinkshellByName( const std::string& name )
|
2017-08-28 23:43:52 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto it = m_linkshellNameMap.find( name );
|
|
|
|
if( it == m_linkshellNameMap.end() )
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return it->second;
|
2017-08-28 23:43:52 +02:00
|
|
|
}
|
|
|
|
|
2018-12-02 02:01:41 +01:00
|
|
|
Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::getLinkshellById( uint64_t lsId )
|
2017-08-28 23:43:52 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto it = m_linkshellIdMap.find( lsId );
|
|
|
|
if( it == m_linkshellIdMap.end() )
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return it->second;
|
2017-08-28 23:43:52 +02:00
|
|
|
}
|