mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-02 00:47:45 +00:00
More preparation work for free companies.
This commit is contained in:
parent
1406549ced
commit
47e6fe8562
5 changed files with 272 additions and 8 deletions
|
@ -28,6 +28,7 @@ TYPE_FORWARD( Item );
|
||||||
TYPE_FORWARD( ItemContainer );
|
TYPE_FORWARD( ItemContainer );
|
||||||
TYPE_FORWARD( Land );
|
TYPE_FORWARD( Land );
|
||||||
TYPE_FORWARD( Linkshell );
|
TYPE_FORWARD( Linkshell );
|
||||||
|
TYPE_FORWARD( FreeCompany );
|
||||||
|
|
||||||
namespace World
|
namespace World
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,15 +2,12 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
Sapphire::FreeCompany::FreeCompany( uint64_t id, std::string name, std::string tag, uint64_t masterId, uint64_t chatChannelId, std::set< uint64_t > members,
|
Sapphire::FreeCompany::FreeCompany( uint64_t id, std::string name, std::string tag, uint64_t masterId, uint64_t chatChannelId ) :
|
||||||
std::set< uint64_t > invites ) :
|
|
||||||
m_id( id ),
|
m_id( id ),
|
||||||
m_name( std::move( name ) ),
|
m_name( std::move( name ) ),
|
||||||
m_tag( std::move( tag ) ),
|
m_tag( std::move( tag ) ),
|
||||||
m_chatChannelId( chatChannelId ),
|
m_chatChannelId( chatChannelId ),
|
||||||
m_masterCharacterId( masterId ),
|
m_masterCharacterId( masterId )
|
||||||
m_memberIds( std::move( members ) ),
|
|
||||||
m_inviteIds( std::move( invites ) )
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,7 @@ namespace Sapphire
|
||||||
std::string name,
|
std::string name,
|
||||||
std::string tag,
|
std::string tag,
|
||||||
uint64_t masterId,
|
uint64_t masterId,
|
||||||
uint64_t chatChannelId,
|
uint64_t chatChannelId );
|
||||||
std::set< uint64_t > members,
|
|
||||||
std::set< uint64_t > invites );
|
|
||||||
|
|
||||||
uint64_t getId() const;
|
uint64_t getId() const;
|
||||||
|
|
||||||
|
|
214
src/world/Manager/FreeCompanyMgr.cpp
Normal file
214
src/world/Manager/FreeCompanyMgr.cpp
Normal file
|
@ -0,0 +1,214 @@
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include <Common.h>
|
||||||
|
#include <Exd/ExdData.h>
|
||||||
|
#include <Service.h>
|
||||||
|
|
||||||
|
#include <Logging/Logger.h>
|
||||||
|
#include <Database/DatabaseDef.h>
|
||||||
|
#include <Manager/ChatChannelMgr.h>
|
||||||
|
#include <Network/GamePacket.h>
|
||||||
|
|
||||||
|
#include "FreeCompany/FreeCompany.h"
|
||||||
|
#include "FreeCompanyMgr.h"
|
||||||
|
|
||||||
|
#include "Actor/Player.h"
|
||||||
|
|
||||||
|
#include "WorldServer.h"
|
||||||
|
|
||||||
|
#include <Network/GameConnection.h>
|
||||||
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
||||||
|
//#include <Network/PacketWrappers/FreeCompanyResultPacket.h>
|
||||||
|
#include <Network/PacketDef/ClientIpcs.h>
|
||||||
|
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
|
using namespace Sapphire;
|
||||||
|
using namespace Sapphire::Network::Packets;
|
||||||
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
||||||
|
using namespace Sapphire::World::Manager;
|
||||||
|
|
||||||
|
bool FreeCompanyMgr::loadFreeCompanies()
|
||||||
|
{
|
||||||
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
||||||
|
auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref();
|
||||||
|
|
||||||
|
auto query = db.getPreparedStatement( Db::FC_SEL_ALL );
|
||||||
|
auto res = db.query( query );
|
||||||
|
|
||||||
|
/* FreeCompanyId, MasterCharacterId, FcName, FcTag, FcCredit, FcCreditAccumu, FcRank, FcPoint, CrestId, CreateDate, GrandCompanyID, "
|
||||||
|
" ReputationList, FcStatus, FcBoard, FcMotto, ActiveActionList, ActiveActionLeftTimeList, StockActionList */
|
||||||
|
while( res->next() )
|
||||||
|
{
|
||||||
|
uint64_t fcId = res->getUInt64( 1 );
|
||||||
|
uint64_t masterId = res->getUInt64( 2 );
|
||||||
|
std::string name = res->getString( 3 );
|
||||||
|
std::string tag = res->getString( 4 );
|
||||||
|
uint64_t credit = res->getUInt64( 5 );
|
||||||
|
uint64_t creditAcc = res->getUInt64( 6 );
|
||||||
|
uint8_t rank = res->getUInt8( 7 );
|
||||||
|
uint64_t points = res->getUInt64( 8 );
|
||||||
|
uint64_t crestId = res->getUInt64( 9 );
|
||||||
|
uint32_t creationDate = res->getUInt( 10 );
|
||||||
|
uint8_t gcId = res->getUInt8( 11 );
|
||||||
|
auto reputationListVec = res->getBlobVector( 12 );
|
||||||
|
uint8_t status = res->getUInt8( 13 );
|
||||||
|
std::string board = res->getString( 14 );
|
||||||
|
std::string motto = res->getString( 15 );
|
||||||
|
|
||||||
|
|
||||||
|
auto chatChannelId = chatChannelMgr.createChatChannel( Common::ChatChannelType::FreeCompanyChat );
|
||||||
|
|
||||||
|
auto fcPtr = std::make_shared< FreeCompany >( fcId, name, tag, chatChannelId, masterId );
|
||||||
|
m_fcIdMap[ fcId ] = fcPtr;
|
||||||
|
m_fcNameMap[ name ] = fcPtr;
|
||||||
|
|
||||||
|
fcPtr->setCredit( credit );
|
||||||
|
fcPtr->setCreditAccumulated( creditAcc );
|
||||||
|
fcPtr->setRank( rank );
|
||||||
|
fcPtr->setPoints( points );
|
||||||
|
fcPtr->setCrest( crestId );
|
||||||
|
fcPtr->setCreateDate( creationDate );
|
||||||
|
fcPtr->setGrandCompany( gcId );
|
||||||
|
fcPtr->setFcStatus( static_cast< Common::FreeCompanyStatus >( status ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreeCompanyMgr::writeFreeCompany( uint64_t fcId )
|
||||||
|
{
|
||||||
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
||||||
|
|
||||||
|
auto fc = getFreeCompanyById( fcId );
|
||||||
|
|
||||||
|
if( !fc )
|
||||||
|
{
|
||||||
|
Logger::error( "FreeCompany {} not found for write!", fcId );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto query = db.getPreparedStatement( Db::FC_UP );
|
||||||
|
|
||||||
|
/* MasterCharacterId = ?, FcName = ?, FcTag = ?, FcCredit = ?, FcCreditAccumu = ?,
|
||||||
|
* FcRank = ?, FcPoint = ?, ReputationList = ?, CrestId = ?,"
|
||||||
|
* CreateDate = ?, GrandCompanyID = ?, FcStatus = ?, FcBoard = ?, "
|
||||||
|
* FcMotto = ?, ActiveActionList = ?, , ActiveActionLeftTimeList = ?, StockActionList = ? "
|
||||||
|
*/
|
||||||
|
|
||||||
|
query->setUInt64( 1, fc->getMasterId() );
|
||||||
|
query->setString( 2, fc->getName() );
|
||||||
|
query->setString( 3, fc->getTag() );
|
||||||
|
query->setUInt64( 4, fc->getCredit() );
|
||||||
|
query->setUInt64( 5, fc->getCreditAccumulated() );
|
||||||
|
query->setUInt( 6, fc->getRank() );
|
||||||
|
query->setUInt64( 7, fc->getPoints() );
|
||||||
|
std::vector< uint8_t > repList( 24 );
|
||||||
|
query->setBinary( 8, repList );
|
||||||
|
query->setUInt64( 9, fc->getCrest() );
|
||||||
|
query->setUInt( 10, fc->getCreateDate() );
|
||||||
|
query->setUInt( 11, fc->getGrandCompany() );
|
||||||
|
query->setUInt( 12, static_cast< uint8_t >( fc->getFcStatus() ) );
|
||||||
|
query->setString( 13, fc->getFcBoard() );
|
||||||
|
query->setString( 14, fc->getFcMotto() );
|
||||||
|
std::vector< uint8_t > activeActionList( 24 );
|
||||||
|
query->setBinary( 15, activeActionList );
|
||||||
|
std::vector< uint8_t > activeActionLeftTimeList( 24 );
|
||||||
|
query->setBinary( 16, activeActionLeftTimeList );
|
||||||
|
std::vector< uint8_t > stockActionList( 120 );
|
||||||
|
query->setBinary( 17, stockActionList );
|
||||||
|
|
||||||
|
query->setInt64( 18, static_cast< int64_t >( fc->getId() ) );
|
||||||
|
db.execute( query );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeCompanyPtr FreeCompanyMgr::getFcByName( const std::string& name )
|
||||||
|
{
|
||||||
|
auto it = m_fcNameMap.find( name );
|
||||||
|
if( it == m_fcNameMap.end() )
|
||||||
|
return nullptr;
|
||||||
|
else
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeCompanyPtr FreeCompanyMgr::getFreeCompanyById( uint64_t fcId )
|
||||||
|
{
|
||||||
|
auto it = m_fcIdMap.find( fcId );
|
||||||
|
if( it == m_fcIdMap.end() )
|
||||||
|
return nullptr;
|
||||||
|
else
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeCompanyPtr FreeCompanyMgr::createFreeCompany( const std::string& name, const std::string& tag, Entity::Player& player )
|
||||||
|
{
|
||||||
|
uint64_t freeCompanyId = 1;
|
||||||
|
|
||||||
|
if( !m_fcIdMap.empty() )
|
||||||
|
{
|
||||||
|
auto lastIdx = ( --m_fcIdMap.end() )->first;
|
||||||
|
freeCompanyId = lastIdx + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if a fc with the same name already exists
|
||||||
|
auto lsIt = m_fcNameMap.find( name );
|
||||||
|
if( lsIt != m_fcNameMap.end() )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref();
|
||||||
|
auto chatChannelId = chatChannelMgr.createChatChannel( Common::ChatChannelType::FreeCompanyChat );
|
||||||
|
chatChannelMgr.addToChannel( chatChannelId, player );
|
||||||
|
|
||||||
|
uint64_t masterId = player.getCharacterId();
|
||||||
|
|
||||||
|
uint32_t createDate = Common::Util::getTimeSeconds();
|
||||||
|
|
||||||
|
auto fcPtr = std::make_shared< FreeCompany >( freeCompanyId, name, tag, chatChannelId, masterId );
|
||||||
|
fcPtr->setCreateDate( createDate );
|
||||||
|
fcPtr->setGrandCompany( player.getGc() );
|
||||||
|
m_fcIdMap[ freeCompanyId ] = fcPtr;
|
||||||
|
m_fcNameMap[ name ] = fcPtr;
|
||||||
|
|
||||||
|
//FreeCompanyId, MasterCharacterId, FcName, FcTag, FcCredit, FcCreditAccumu, FcRank, FcPoint,
|
||||||
|
//ReputationList, CrestId, CreateDate, GrandCompanyID, FcStatus, FcBoard, FcMotto
|
||||||
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
||||||
|
auto stmt = db.getPreparedStatement( Db::ZoneDbStatements::FC_INS );
|
||||||
|
stmt->setUInt64( 1, freeCompanyId );
|
||||||
|
stmt->setUInt64( 2, masterId );
|
||||||
|
stmt->setString( 3, std::string( name ) );
|
||||||
|
stmt->setString( 4, std::string( tag ) );
|
||||||
|
stmt->setUInt64( 5, 0 );
|
||||||
|
stmt->setUInt64( 6, 0 );
|
||||||
|
stmt->setUInt( 7, 1 );
|
||||||
|
stmt->setUInt64( 8, 0 );
|
||||||
|
std::vector< uint8_t > rep( 24 );
|
||||||
|
stmt->setBinary( 9, rep );
|
||||||
|
stmt->setUInt64( 10, 0 );
|
||||||
|
stmt->setUInt( 11, createDate );
|
||||||
|
stmt->setUInt( 12, fcPtr->getGrandCompany() );
|
||||||
|
stmt->setUInt( 13, static_cast< uint8_t >( Common::FreeCompanyStatus::InviteStart ) );
|
||||||
|
stmt->setString( 14, std::string( "" ) );
|
||||||
|
stmt->setString( 15, std::string( "" ) );
|
||||||
|
|
||||||
|
db.directExecute( stmt );
|
||||||
|
|
||||||
|
return fcPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreeCompanyMgr::finishFreeCompanyAction( const std::string& name, uint32_t result, Entity::Player& player, uint8_t action )
|
||||||
|
{
|
||||||
|
auto& server = Common::Service< World::WorldServer >::ref();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeCompanyPtr FreeCompanyMgr::getPlayerFreeCompany( Entity::Player& player ) const
|
||||||
|
{
|
||||||
|
|
||||||
|
for( const auto &[ key, value ] : m_fcIdMap )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
54
src/world/Manager/FreeCompanyMgr.h
Normal file
54
src/world/Manager/FreeCompanyMgr.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include "ForwardsZone.h"
|
||||||
|
|
||||||
|
namespace Sapphire::World::Manager
|
||||||
|
{
|
||||||
|
|
||||||
|
class FreeCompanyMgr
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::map< uint64_t, FreeCompanyPtr > m_fcIdMap;
|
||||||
|
std::map< std::string, FreeCompanyPtr > m_fcNameMap;
|
||||||
|
|
||||||
|
FreeCompanyPtr getFcByName( const std::string& name );
|
||||||
|
|
||||||
|
public:
|
||||||
|
FreeCompanyMgr() = default;
|
||||||
|
|
||||||
|
// initialize all fcs from db to memory
|
||||||
|
bool loadFreeCompanies();
|
||||||
|
void writeFreeCompany( uint64_t fcId );
|
||||||
|
|
||||||
|
// create new fc entry and insert into db
|
||||||
|
FreeCompanyPtr createFreeCompany( const std::string& name, const std::string& tag, Entity::Player& player );
|
||||||
|
|
||||||
|
bool renameFreeCompany( uint64_t fcId, const std::string& name, const std::string& tag, Entity::Player& player );
|
||||||
|
|
||||||
|
void finishFreeCompanyAction( const std::string& name, uint32_t result, Entity::Player& player, uint8_t action );
|
||||||
|
|
||||||
|
/* void invitePlayer( Entity::Player& sourcePlayer, Entity::Player& invitedPlayer, uint64_t linkshellId );
|
||||||
|
void kickPlayer( Entity::Player& sourcePlayer, Entity::Player& kickedPlayer, uint64_t linkshellId );
|
||||||
|
|
||||||
|
void addLeader( Entity::Player& sourcePlayer, Entity::Player& newLeaderPlayer, uint64_t linkshellId );
|
||||||
|
void removeLeader( Entity::Player& sourcePlayer, Entity::Player& leaderPlayer, uint64_t linkshellId );
|
||||||
|
void declineLeader( Entity::Player& sourcePlayer, uint64_t linkshellId );
|
||||||
|
void changeMaster( Entity::Player& sourcePlayer, Entity::Player& nextMasterPlayer, uint64_t linkshellId ); */
|
||||||
|
|
||||||
|
void sendFreeCompanyStatus( Entity::Player& player );
|
||||||
|
|
||||||
|
// get fc associated with player
|
||||||
|
FreeCompanyPtr getPlayerFreeCompany( Entity::Player& player ) const;
|
||||||
|
|
||||||
|
FreeCompanyPtr getFreeCompanyById( uint64_t fcId );
|
||||||
|
|
||||||
|
// void leaveLinkshell( uint64_t lsId, uint64_t characterId );
|
||||||
|
// void joinLinkshell( uint64_t lsId, uint64_t characterId );
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue