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

Implemented db update for linkshells.

This commit is contained in:
Mordred 2021-12-04 12:29:54 +01:00
parent ee0cdfad0b
commit 85bbe38562
5 changed files with 65 additions and 5 deletions

View file

@ -319,6 +319,16 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements()
"WHERE ItemId = ?;",
CONNECTION_BOTH );
prepareStatement( LINKSHELL_SEL_ALL,
"SELECT LinkshellId, MasterCharacterId, CharacterIdList, LinkshellName, LeaderIdList, InviteIdList "
"FROM infolinkshell "
"ORDER BY LinkshellId ASC;",
CONNECTION_SYNC );
prepareStatement( LINKSHELL_UP,
"UPDATE infolinkshell SET CharacterIdList = ?, LinkshellName = ?, LeaderIdList = ?, InviteIdList = ? WHERE LinkshellId = ?;",
CONNECTION_BOTH );
/*prepareStatement( LAND_INS,
"INSERT INTO land ( LandSetId ) VALUES ( ? );",
CONNECTION_BOTH );

View file

@ -105,6 +105,10 @@ namespace Sapphire::Db
LAND_INV_UP_ITEMPOS,
LAND_INV_DEL_ITEMPOS,
LINKSHELL_SEL_ALL,
LINKSHELL_INS,
LINKSHELL_UP,
MAX_STATEMENTS
};

View file

@ -33,10 +33,8 @@ bool Sapphire::World::Manager::LinkshellMgr::loadLinkshells()
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref();
auto res = db.query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
"LinkshellName, LeaderIdList, InviteIdList "
"FROM infolinkshell "
"ORDER BY LinkshellId ASC;" );
auto query = db.getPreparedStatement( Db::LINKSHELL_SEL_ALL );
auto res = db.query( query );
while( res->next() )
{
@ -88,6 +86,48 @@ bool Sapphire::World::Manager::LinkshellMgr::loadLinkshells()
return true;
}
void LinkshellMgr::writeLinkshell( uint64_t lsId )
{
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
auto ls = getLinkshellById( lsId );
if( !ls )
{
Logger::error( "Linkshell {} not found for write!", lsId );
}
auto query = db.getPreparedStatement( Db::LINKSHELL_UP );
auto& members = ls->getMemberIdList();
auto& leaders = ls->getLeaderIdList();
auto& invites = ls->getInviteIdList();
std::vector< uint64_t > memberVec;
std::vector< uint64_t > leaderVec;
std::vector< uint64_t > inviteVec;
std::copy( members.begin(), members.end(), std::back_inserter( memberVec ) );
std::copy( leaders.begin(), leaders.end(), std::back_inserter( leaderVec ) );
std::copy( invites.begin(), invites.end(), std::back_inserter( inviteVec ) );
std::vector< uint8_t > memberBin( memberVec.size() * 8 );
memcpy( memberBin.data(), memberVec.data(), memberVec.size() * 8 );
std::vector< uint8_t > leaderBin( leaderVec.size() * 8 );
memcpy( leaderBin.data(), leaderVec.data(), leaderVec.size() * 8 );
std::vector< uint8_t > inviteBin( inviteVec.size() * 8 );
memcpy( inviteBin.data(), inviteVec.data(), inviteVec.size() * 8 );
query->setBinary( 1, memberBin );
query->setString( 2, ls->getName() );
query->setBinary( 3, leaderBin );
query->setBinary( 4, inviteBin );
query->setInt64( 5, lsId );
db.execute( query );
}
Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::getLinkshellByName( const std::string& name )
{
auto it = m_linkshellNameMap.find( name );
@ -204,4 +244,6 @@ const std::vector< Sapphire::LinkshellPtr > Sapphire::World::Manager::LinkshellM
}
return lsVec;
}
}

View file

@ -31,6 +31,7 @@ namespace Sapphire::World::Manager
// initialize all linkshells from db to memory
bool loadLinkshells();
void writeLinkshell( uint64_t lsId );
// create new linkshell entry and insert into db
LinkshellPtr createLinkshell( const std::string& name, Entity::Player& player );
@ -41,6 +42,8 @@ namespace Sapphire::World::Manager
const std::vector< LinkshellPtr > getPlayerLinkshells( Entity::Player& player ) const;
LinkshellPtr getLinkshellById( uint64_t lsId );
};
}

View file

@ -216,6 +216,7 @@ void Sapphire::Network::GameConnection::linkshellJoinHandler( const Packets::FFX
return Logger::warn( "Failed to invite player to linkshell - session/linkshell not found!" );
lsPtr->addInvite( invitedPlayer->getPlayer()->getCharacterId() );
lsMgr.writeLinkshell( lsPtr->getId() );
// TODO: send inv packets
}