mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-29 07:37:45 +00:00
Implemented db update for linkshells.
This commit is contained in:
parent
ee0cdfad0b
commit
85bbe38562
5 changed files with 65 additions and 5 deletions
|
@ -319,6 +319,16 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements()
|
||||||
"WHERE ItemId = ?;",
|
"WHERE ItemId = ?;",
|
||||||
CONNECTION_BOTH );
|
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,
|
/*prepareStatement( LAND_INS,
|
||||||
"INSERT INTO land ( LandSetId ) VALUES ( ? );",
|
"INSERT INTO land ( LandSetId ) VALUES ( ? );",
|
||||||
CONNECTION_BOTH );
|
CONNECTION_BOTH );
|
||||||
|
|
|
@ -105,6 +105,10 @@ namespace Sapphire::Db
|
||||||
LAND_INV_UP_ITEMPOS,
|
LAND_INV_UP_ITEMPOS,
|
||||||
LAND_INV_DEL_ITEMPOS,
|
LAND_INV_DEL_ITEMPOS,
|
||||||
|
|
||||||
|
LINKSHELL_SEL_ALL,
|
||||||
|
LINKSHELL_INS,
|
||||||
|
LINKSHELL_UP,
|
||||||
|
|
||||||
|
|
||||||
MAX_STATEMENTS
|
MAX_STATEMENTS
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,10 +33,8 @@ bool Sapphire::World::Manager::LinkshellMgr::loadLinkshells()
|
||||||
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
||||||
auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref();
|
auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref();
|
||||||
|
|
||||||
auto res = db.query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
|
auto query = db.getPreparedStatement( Db::LINKSHELL_SEL_ALL );
|
||||||
"LinkshellName, LeaderIdList, InviteIdList "
|
auto res = db.query( query );
|
||||||
"FROM infolinkshell "
|
|
||||||
"ORDER BY LinkshellId ASC;" );
|
|
||||||
|
|
||||||
while( res->next() )
|
while( res->next() )
|
||||||
{
|
{
|
||||||
|
@ -88,6 +86,48 @@ bool Sapphire::World::Manager::LinkshellMgr::loadLinkshells()
|
||||||
return true;
|
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 )
|
Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::getLinkshellByName( const std::string& name )
|
||||||
{
|
{
|
||||||
auto it = m_linkshellNameMap.find( name );
|
auto it = m_linkshellNameMap.find( name );
|
||||||
|
@ -205,3 +245,5 @@ const std::vector< Sapphire::LinkshellPtr > Sapphire::World::Manager::LinkshellM
|
||||||
|
|
||||||
return lsVec;
|
return lsVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace Sapphire::World::Manager
|
||||||
|
|
||||||
// initialize all linkshells from db to memory
|
// initialize all linkshells from db to memory
|
||||||
bool loadLinkshells();
|
bool loadLinkshells();
|
||||||
|
void writeLinkshell( uint64_t lsId );
|
||||||
|
|
||||||
// create new linkshell entry and insert into db
|
// create new linkshell entry and insert into db
|
||||||
LinkshellPtr createLinkshell( const std::string& name, Entity::Player& player );
|
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;
|
const std::vector< LinkshellPtr > getPlayerLinkshells( Entity::Player& player ) const;
|
||||||
|
|
||||||
LinkshellPtr getLinkshellById( uint64_t lsId );
|
LinkshellPtr getLinkshellById( uint64_t lsId );
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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!" );
|
return Logger::warn( "Failed to invite player to linkshell - session/linkshell not found!" );
|
||||||
|
|
||||||
lsPtr->addInvite( invitedPlayer->getPlayer()->getCharacterId() );
|
lsPtr->addInvite( invitedPlayer->getPlayer()->getCharacterId() );
|
||||||
|
lsMgr.writeLinkshell( lsPtr->getId() );
|
||||||
// TODO: send inv packets
|
// TODO: send inv packets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue