2017-08-28 18:36:51 +02:00
|
|
|
#include "LinkshellMgr.h"
|
|
|
|
#include <boost/make_shared.hpp>
|
2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Logging/Logger.h>
|
|
|
|
#include <common/Database/DatabaseDef.h>
|
2017-08-28 18:36:51 +02:00
|
|
|
|
|
|
|
#include "Linkshell.h"
|
|
|
|
|
|
|
|
extern Core::Logger g_log;
|
|
|
|
|
|
|
|
Core::LinkshellMgr::LinkshellMgr()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::LinkshellMgr::loadLinkshells()
|
|
|
|
{
|
|
|
|
|
2017-10-28 22:47:25 +02:00
|
|
|
auto res = g_charaDb.query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
|
|
|
|
"LinkshellName, LeaderIdList, InviteIdList "
|
|
|
|
"FROM infolinkshell "
|
|
|
|
"ORDER BY LinkshellId ASC;" );
|
2017-08-29 17:35:25 +02:00
|
|
|
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2017-10-28 22:47:25 +02:00
|
|
|
while( res->next() )
|
2017-08-28 18:36:51 +02:00
|
|
|
{
|
2017-10-28 22:47:25 +02:00
|
|
|
uint64_t linkshellId = res->getUInt64( 1 );
|
|
|
|
uint32_t masterId = res->getUInt( 2 );
|
|
|
|
std::string name = res->getString( 4 );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2017-10-28 22:47:25 +02:00
|
|
|
auto func = []( std::set< uint64_t >& outList, std::vector< char >& inData )
|
2017-08-28 23:19:35 +02:00
|
|
|
{
|
2017-10-28 22:47:25 +02:00
|
|
|
if( inData.size() )
|
2017-08-28 23:19:35 +02:00
|
|
|
{
|
2017-10-28 22:47:25 +02:00
|
|
|
std::vector< uint64_t > list( inData.size() / 8 );
|
2017-08-28 23:19:35 +02:00
|
|
|
outList.insert( list.begin(), list.end() );
|
|
|
|
}
|
|
|
|
};
|
2017-08-28 18:36:51 +02:00
|
|
|
|
2017-08-28 23:19:35 +02:00
|
|
|
std::set< uint64_t > members;
|
2017-10-28 22:47:25 +02:00
|
|
|
std::vector< char > membersBin;
|
|
|
|
membersBin = res->getBlobVector( 3 );
|
|
|
|
func( members, membersBin );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
|
|
|
std::set< uint64_t > leaders;
|
2017-10-28 22:47:25 +02:00
|
|
|
std::vector< char > leadersBin;
|
|
|
|
leadersBin = res->getBlobVector( 5 );
|
|
|
|
func( members, leadersBin );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
|
|
|
std::set< uint64_t > invites;
|
2017-10-28 22:47:25 +02:00
|
|
|
std::vector< char > invitesBin;
|
|
|
|
invitesBin = res->getBlobVector( 6 );
|
|
|
|
func( members, invitesBin );
|
2017-08-28 18:36:51 +02:00
|
|
|
|
|
|
|
auto lsPtr = boost::make_shared< Linkshell >( linkshellId, name, masterId, members, leaders, invites );
|
|
|
|
m_linkshellIdMap[linkshellId] = lsPtr;
|
|
|
|
m_linkshellNameMap[name] = lsPtr;
|
|
|
|
|
2017-10-28 22:47:25 +02:00
|
|
|
}
|
2017-08-28 18:36:51 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
2017-08-28 23:43:52 +02:00
|
|
|
|
|
|
|
Core::LinkshellPtr Core::LinkshellMgr::getLinkshellByName( const std::string& name )
|
|
|
|
{
|
|
|
|
auto it = m_linkshellNameMap.find( name );
|
|
|
|
if( it == m_linkshellNameMap.end() )
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2017-10-23 08:33:47 -07:00
|
|
|
Core::LinkshellPtr Core::LinkshellMgr::getLinkshellById( uint64_t lsId )
|
2017-08-28 23:43:52 +02:00
|
|
|
{
|
|
|
|
auto it = m_linkshellIdMap.find( lsId );
|
|
|
|
if( it == m_linkshellIdMap.end() )
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return it->second;
|
|
|
|
}
|