1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 14:07:46 +00:00

Created linkshellMgr class and added basic linkshell caching

This commit is contained in:
Mordred 2017-08-28 18:36:51 +02:00
parent ee2f651cb5
commit d1cec57259
11 changed files with 192 additions and 60 deletions

View file

@ -30,7 +30,9 @@ QueryResult::~QueryResult()
bool QueryResult::nextRow()
{
MYSQL_ROW row = mysql_fetch_row( m_result );
auto length = mysql_fetch_lengths( m_result );
if( row == NULL )
{
return false;
@ -39,6 +41,9 @@ bool QueryResult::nextRow()
for( uint32_t i = 0; i < m_fieldCount; ++i )
{
m_currentRow[i].setValue( row[i] );
m_currentRow[i].setLength( 0 );
if( length )
m_currentRow[i].setLength( length[i] );
}
return true;

View file

@ -23,6 +23,12 @@ namespace Core {
m_pValue = value;
}
// set value
__inline void setLength( uint32_t value )
{
m_size = value;
}
// return as string
__inline const char *getString()
{
@ -91,6 +97,11 @@ namespace Core {
return m_pValue ? static_cast< int32_t >( atol( m_pValue ) ) : 0;
}
__inline uint32_t getLength()
{
return m_size;
}
// return as unsigned 64 bit integer
uint64_t getUInt64()
{
@ -113,6 +124,7 @@ namespace Core {
private:
char *m_pValue;
uint32_t m_size;
};

View file

@ -47,16 +47,24 @@ namespace Packets {
Ping = 0x0065, // updated for sb
Init = 0x0066, // updated for sb
Chat = 0x0067, // updated for sb
Logout = 0x0077, // updated for sb
CFNotify = 0x0078,
CFMemberStatus = 0x0079,
CFDutyInfo = 0x007A,
CFPlayerInNeed = 0x007F,
Playtime = 0x00AF, // updated for sb
SocialRequestError = 0x00AD,
SocialRequestResponse = 0x11AF,
CFRegistered = 0x00B0,
SocialList = 0x00B4, // updated for sb
UpdateSearchInfo = 0x00B6, // updated for sb
InitSearchInfo = 0x00B7, // updated for sb
ServerNotice = 0x00BC, // updated for sb
SetOnlineStatus = 0x00BD, // updated for sb
BlackList = 0x00CA, // updated for sb
LogMessage = 0x00D0, // updated for sb
LinkshellList = 0x00D1, // updated for sb
StatusEffectList = 0x00F0, // updated for sb
Effect = 0x00F1, // updated for sb
@ -77,10 +85,10 @@ namespace Packets {
ModelEquip = 0x0124, // updated for sb
ItemInfo = 0x0139, // updated for sb
ContainerInfo = 0x013A, // updated for sb
InventoryTransactionFinish = 0x013B,
InventoryTransaction = 0x012A,
InventoryTransactionFinish = 0x013B, // updated for sb
InventoryTransaction = 0x013C, // updated for sb
CurrencyCrystalInfo = 0x013D,
InventoryActionAck = 0x0139,
InventoryActionAck = 0x1139,
UpdateInventorySlot = 0x0140, // updated for sb
AddStatusEffect = 0x0141,
ActorControl142 = 0x0142, // unchanged for sb
@ -88,12 +96,7 @@ namespace Packets {
ActorControl144 = 0x0144, // unchanged for sb
UpdateHpMpTp = 0x0145, // unchanged for sb
CFNotify = 0x0078,
CFMemberStatus = 0x0079,
CFDutyInfo = 0x007A,
CFPlayerInNeed = 0x007F,
CFRegistered = 0x00B0,
CFAvailableContents = 0x01CF,
EventPlay = 0x0154, // updated for sb
EventStart = 0x015D, // updated for sb
@ -113,6 +116,9 @@ namespace Packets {
WeatherChange = 0x01AF, // updated for sb
Discovery = 0x01B2, // updated for sb
CFAvailableContents = 0x01CF,
PrepareZoning = 0x0239, // updated for sb
// Unknown IPC types that still need to be sent

View file

@ -152,6 +152,20 @@ struct FFXIVIpcBlackList : FFXIVIpcBasePacket<BlackList>
uint32_t padding2;
};
struct FFXIVIpcLogMessage : FFXIVIpcBasePacket<LogMessage>
{
uint32_t field_0;
uint32_t field_4;
uint32_t field_8;
uint32_t field_12;
uint32_t category;
uint32_t logMessage;
uint8_t field_24;
uint8_t field_25;
uint8_t field_26[32];
uint32_t field_58;
};
struct FFXIVIpcLinkshellList : FFXIVIpcBasePacket<LinkshellList>
{
struct LsEntry

View file

@ -128,11 +128,11 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
m_pos.z = field[8].getFloat();
setRotation( field[9].getFloat() );
field[11].getBinary( reinterpret_cast< char* >( m_customize ), 26 );
field[11].getBinary( reinterpret_cast< char* >( m_customize ), sizeof( m_customize ) );
m_modelMainWeapon = field[12].getUInt64();
field[14].getBinary( reinterpret_cast< char* >( m_modelEquip ), 40 );
field[14].getBinary( reinterpret_cast< char* >( m_modelEquip ), sizeof( m_modelEquip ) );
m_guardianDeity = field[15].getUInt8();
m_birthDay = field[16].getUInt8();
@ -147,15 +147,15 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
m_voice = field[23].getUInt32();
field[24].getBinary( reinterpret_cast< char* >( m_questCompleteFlags ), 200 );
field[24].getBinary( reinterpret_cast< char* >( m_questCompleteFlags ), sizeof( m_questCompleteFlags ) );
field[25].getBinary( reinterpret_cast< char* >( m_questTracking ), 10 );
field[25].getBinary( reinterpret_cast< char* >( m_questTracking ), sizeof( m_questTracking ) );
m_bNewGame = field[26].getBool();
field[27].getBinary( reinterpret_cast< char* >( m_aetheryte ), sizeof( m_aetheryte ) );
field[28].getBinary( reinterpret_cast< char* >( m_unlocks ), 64 );
field[28].getBinary( reinterpret_cast< char* >( m_unlocks ), sizeof( m_unlocks ) );
field[29].getBinary( reinterpret_cast< char* >( m_discovery ), sizeof( m_discovery ) );
@ -165,7 +165,7 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
m_bNewAdventurer = field[32].getBool();
m_gc = field[33].getUInt8();
field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), 3 );
field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), sizeof( m_gcRank ) );
m_cfPenaltyUntil = field[35].getUInt32();

View file

@ -16,6 +16,7 @@ file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
DebugCommand/*.c*
Event/*.c*
Inventory/*.c*
Linkshell/*.c*
Network/*.c*
Network/Handlers/*.c*
Network/PacketWrappers/*.c*
@ -89,7 +90,7 @@ endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/")
add_executable(server_zone ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
add_executable(server_zone ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES} Linkshell/Linkshell.cpp Linkshell/Linkshell.h)
add_dependencies(server_zone Common xivdat)
set_target_properties(server_zone PROPERTIES

View file

@ -1,11 +1,12 @@
#include "Linkshell.h"
Core::Linkshell::Linkshell( uint32_t id,
Core::Linkshell::Linkshell( uint64_t id,
const std::string &name,
uint32_t masterId,
const std::set<uint32_t> &members,
const std::set<uint32_t> &leaders,
const std::set<uint32_t> &invites ) :
uint64_t masterId,
const std::set<uint64_t> &members,
const std::set<uint64_t> &leaders,
const std::set<uint64_t> &invites ) :
m_linkshellId( id ),
m_name( name ),
m_masterCharacterId( masterId ),
@ -16,22 +17,22 @@ Core::Linkshell::Linkshell( uint32_t id,
}
uint32_t Core::Linkshell::getId() const
uint64_t Core::Linkshell::getId() const
{
return m_linkshellId;
}
uint32_t Core::Linkshell::getMasterId() const
uint64_t Core::Linkshell::getMasterId() const
{
return m_masterCharacterId;
}
const std::set< uint32_t >& Core::Linkshell::getMemberIdList() const
const std::set< uint64_t >& Core::Linkshell::getMemberIdList() const
{
return m_memberIds;
}
std::set< uint32_t >& Core::Linkshell::getMemberIdList()
std::set< uint64_t >& Core::Linkshell::getMemberIdList()
{
return m_memberIds;
}
@ -41,52 +42,52 @@ const std::string& Core::Linkshell::getName() const
return m_name;
}
const std::set< uint32_t >& Core::Linkshell::getLeaderIdList() const
const std::set< uint64_t >& Core::Linkshell::getLeaderIdList() const
{
return m_leaderIds;
}
std::set< uint32_t >& Core::Linkshell::getLeaderIdList()
std::set< uint64_t >& Core::Linkshell::getLeaderIdList()
{
return m_leaderIds;
}
const std::set< uint32_t >& Core::Linkshell::getInviteIdList() const
const std::set< uint64_t >& Core::Linkshell::getInviteIdList() const
{
return m_inviteIds;
}
std::set< uint32_t > &Core::Linkshell::getInviteIdList()
std::set< uint64_t > &Core::Linkshell::getInviteIdList()
{
return m_inviteIds;
}
void Core::Linkshell::addMember( uint32_t memberId )
void Core::Linkshell::addMember( uint64_t memberId )
{
m_memberIds.insert( memberId );
}
void Core::Linkshell::removeMember( uint32_t memberId )
void Core::Linkshell::removeMember( uint64_t memberId )
{
m_memberIds.erase( memberId );
}
void Core::Linkshell::addLeader( uint32_t memberId )
void Core::Linkshell::addLeader( uint64_t memberId )
{
m_leaderIds.insert( memberId );
}
void Core::Linkshell::removeLeader( uint32_t memberId )
void Core::Linkshell::removeLeader( uint64_t memberId )
{
m_leaderIds.erase( memberId );
}
void Core::Linkshell::addInvite( uint32_t memberId )
void Core::Linkshell::addInvite( uint64_t memberId )
{
m_inviteIds.insert( memberId );
}
void Core::Linkshell::removeInvite( uint32_t memberId )
void Core::Linkshell::removeInvite( uint64_t memberId )
{
m_inviteIds.erase( memberId );
}

View file

@ -11,49 +11,49 @@ class Linkshell
{
private:
/*! unique ID of the linkshell */
uint32_t m_linkshellId;
uint64_t m_linkshellId;
/*! ID of the master character */
uint32_t m_masterCharacterId;
uint64_t m_masterCharacterId;
/*! ID list of all linkshell members */
std::set< uint32_t > m_memberIds;
std::set< uint64_t > m_memberIds;
/*! Name of the linkshell */
std::string m_name;
/*! List of member IDs with leader rank */
std::set< uint32_t > m_leaderIds;
std::set< uint64_t > m_leaderIds;
/*! list of IDs of pending character invites */
std::set< uint32_t > m_inviteIds;
std::set< uint64_t > m_inviteIds;
public:
Linkshell( uint32_t id,
Linkshell( uint64_t id,
const std::string& name,
uint32_t masterId,
const std::set< uint32_t >& members,
const std::set< uint32_t >& leaders,
const std::set< uint32_t >& invites );
uint64_t masterId,
const std::set< uint64_t >& members,
const std::set< uint64_t >& leaders,
const std::set< uint64_t >& invites );
uint32_t getId() const;
uint64_t getId() const;
const std::string& getName() const;
uint32_t getMasterId() const;
uint64_t getMasterId() const;
const std::set< uint32_t >& getMemberIdList() const;
std::set< uint32_t >& getMemberIdList();
const std::set< uint64_t >& getMemberIdList() const;
std::set< uint64_t >& getMemberIdList();
const std::set< uint32_t >& getLeaderIdList() const;
std::set< uint32_t >& getLeaderIdList();
const std::set< uint64_t >& getLeaderIdList() const;
std::set< uint64_t >& getLeaderIdList();
const std::set< uint32_t >& getInviteIdList() const;
std::set< uint32_t >& getInviteIdList();
const std::set< uint64_t >& getInviteIdList() const;
std::set< uint64_t >& getInviteIdList();
void addMember( uint32_t memberId );
void removeMember( uint32_t memberId );
void addMember( uint64_t memberId );
void removeMember( uint64_t memberId );
void addLeader( uint32_t memberId );
void removeLeader( uint32_t memberId );
void addLeader( uint64_t memberId );
void removeLeader( uint64_t memberId );
void addInvite( uint32_t memberId );
void removeInvite( uint32_t memberId );
void addInvite( uint64_t memberId );
void removeInvite( uint64_t memberId );
};

View file

@ -0,0 +1,59 @@
#include "LinkshellMgr.h"
#include <Server_Common/Database/Database.h>
#include <Server_Common/Logging/Logger.h>
#include <boost/make_shared.hpp>
#include "Linkshell.h"
extern Core::Logger g_log;
extern Core::Db::Database g_database;
Core::LinkshellMgr::LinkshellMgr()
{
}
bool Core::LinkshellMgr::loadLinkshells()
{
auto res = g_database.query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
"LinkshellName, LeaderIdList, InviteIdList "
"FROM infolinkshell "
"ORDER BY LinkshellId ASC;" );
if( !res )
return false;
Db::Field *field = res->fetch();
do
{
uint32_t linkshellId = field[0].getUInt32();
uint32_t masterId = field[1].getUInt32();
std::string name = field[3].getString();
std::vector< uint64_t > characterIdList( field[2].getLength() / 8 );
field[2].getBinary( reinterpret_cast< char* >( &characterIdList[0] ), field[2].getLength() );
std::set< uint64_t > members( characterIdList.begin(), characterIdList.end() );
//std::vector< uint64_t > leaderIdList( field[4].getLength() / 8 );
//field[4].getBinary( reinterpret_cast< char* >( &leaderIdList[0] ), field[4].getLength() );
//std::set< uint64_t > leaders( leaderIdList.begin(), leaderIdList.end() );
std::set< uint64_t > leaders;
//std::vector< uint64_t > inviteIdList( field[5].getLength() / 8 );
//field[5].getBinary( reinterpret_cast< char* >( &leaderIdList[0] ), field[5].getLength() );
//std::set< uint64_t > invites( inviteIdList.begin(), inviteIdList.end() );
std::set< uint64_t > invites;
auto lsPtr = boost::make_shared< Linkshell >( linkshellId, name, masterId, members, leaders, invites );
m_linkshellIdMap[linkshellId] = lsPtr;
m_linkshellNameMap[name] = lsPtr;
} while( res->nextRow() );
return true;
}

View file

@ -0,0 +1,25 @@
#ifndef CORE_LINKSHELLMGR_H
#define CORE_LINKSHELLMGR_H
#include <boost/shared_ptr.hpp>
#include <map>
namespace Core
{
class Linkshell;
typedef boost::shared_ptr< Linkshell > LinkshellPtr;
class LinkshellMgr
{
private:
std::map< uint32_t, LinkshellPtr > m_linkshellIdMap;
std::map< std::string, LinkshellPtr > m_linkshellNameMap;
public:
LinkshellMgr();
bool loadLinkshells();
};
}
#endif //CORE_LINKSHELLMGR_H

View file

@ -23,6 +23,7 @@
#include "src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h"
#include "Script/ScriptManager.h"
#include "Linkshell/LinkshellMgr.h"
#include "Forwards.h"
#include <boost/foreach.hpp>
@ -36,6 +37,7 @@ Core::DebugCommandHandler g_gameCommandMgr;
Core::Scripting::ScriptManager g_scriptMgr;
Core::Data::ExdData g_exdData;
Core::ZoneMgr g_zoneMgr;
Core::LinkshellMgr g_linkshellMgr;
Core::ServerZone::ServerZone( const std::string& configPath, uint16_t serverId )
@ -211,12 +213,19 @@ void Core::ServerZone::run( int32_t argc, char* argv[] )
g_exdData.loadAetheryteInfo();
g_exdData.loadTribeInfo();
g_log.info( "LinkshellMgr: Caching linkshells" );
if( !g_linkshellMgr.loadLinkshells() )
{
g_log.fatal( "Unable to load linkshells!" );
return;
}
Network::HivePtr hive( new Network::Hive() );
Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive );
g_scriptMgr.init();
g_log.info( "ZoneHandler: Setting up zones" );
g_log.info( "ZoneMgr: Setting up zones" );
g_zoneMgr.createZones();
std::vector< std::thread > thread_list;