mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 07:07:45 +00:00
Merge branch 'develop' of https://github.com/SapphireMordred/Sapphire into develop
This commit is contained in:
commit
a4a60ca057
25 changed files with 246 additions and 54 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -4,3 +4,6 @@
|
||||||
[submodule "deps/spdlog"]
|
[submodule "deps/spdlog"]
|
||||||
path = deps/spdlog
|
path = deps/spdlog
|
||||||
url = https://github.com/gabime/spdlog.git
|
url = https://github.com/gabime/spdlog.git
|
||||||
|
[submodule "deps/recastnavigation"]
|
||||||
|
path = deps/recastnavigation
|
||||||
|
url = https://github.com/SapphireServer/recastnavigation
|
||||||
|
|
|
@ -44,6 +44,7 @@ add_subdirectory( "deps/zlib" )
|
||||||
add_subdirectory( "deps/MySQL" )
|
add_subdirectory( "deps/MySQL" )
|
||||||
add_subdirectory( "deps/datReader" )
|
add_subdirectory( "deps/datReader" )
|
||||||
add_subdirectory( "deps/mysqlConnector" )
|
add_subdirectory( "deps/mysqlConnector" )
|
||||||
|
add_subdirectory( "deps/recastnavigation" )
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
# Main Sapphire Components #
|
# Main Sapphire Components #
|
||||||
|
|
1
deps/recastnavigation
vendored
Submodule
1
deps/recastnavigation
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit d24db2de131d6be5a1bc38067fa8b649544a0dd2
|
|
@ -258,7 +258,7 @@ namespace Sapphire::Network::Packets
|
||||||
|
|
||||||
// The IPC type itself.
|
// The IPC type itself.
|
||||||
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
|
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
|
||||||
m_ipcHdr.timestamp = static_cast< uint32_t >( Util::getTimeSeconds() );
|
m_ipcHdr.timestamp = Util::getTimeSeconds();
|
||||||
m_segHdr.size = sizeof( T ) + sizeof( FFXIVARR_IPC_HEADER ) + sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
m_segHdr.size = sizeof( T ) + sizeof( FFXIVARR_IPC_HEADER ) + sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -119,35 +119,39 @@ namespace Sapphire::Network::Packets
|
||||||
|
|
||||||
PlayerSpawn = 0x0175, // updated 4.5
|
PlayerSpawn = 0x0175, // updated 4.5
|
||||||
NpcSpawn = 0x0176, // updated 4.5
|
NpcSpawn = 0x0176, // updated 4.5
|
||||||
|
NpcSpawn2 = 0x0177, // ( Bigger statuseffectlist? ) updated 4.5
|
||||||
ActorMove = 0x0178, // updated 4.5
|
ActorMove = 0x0178, // updated 4.5
|
||||||
|
|
||||||
ActorSetPos = 0x017A, // updated 4.5
|
ActorSetPos = 0x017A, // updated 4.5
|
||||||
|
|
||||||
ActorCast = 0x017C, // updated 4.5
|
ActorCast = 0x017C, // updated 4.5
|
||||||
|
|
||||||
PartyList = 0x017E, // updated 4.5
|
PartyList = 0x017E, // updated 4.5
|
||||||
HateList = 0x017F, // updated 4.5
|
|
||||||
|
|
||||||
|
HateList = 0x0180, // updated 4.5
|
||||||
ObjectSpawn = 0x0181, // updated 4.5
|
ObjectSpawn = 0x0181, // updated 4.5
|
||||||
ObjectDespawn = 0x0182, // updated 4.5
|
ObjectDespawn = 0x0182, // updated 4.5
|
||||||
|
|
||||||
UpdateClassInfo = 0x0183, // updated 4.5
|
UpdateClassInfo = 0x0183, // updated 4.5
|
||||||
SilentSetClassJob = 0x0184, // updated 4.5 - seems to be the case, not sure if it's actually used for anything
|
SilentSetClassJob = 0x0184, // updated 4.5 - seems to be the case, not sure if it's actually used for anything
|
||||||
|
|
||||||
InitUI = 0x0185, // updated 4.5
|
InitUI = 0x0185, // updated 4.5
|
||||||
PlayerStats = 0x0186, // updated 4.5
|
PlayerStats = 0x0186, // updated 4.5
|
||||||
ActorOwner = 0x0187, // updated 4.5
|
ActorOwner = 0x0187, // updated 4.5
|
||||||
PlayerStateFlags = 0x0188, // updated 4.5
|
PlayerStateFlags = 0x0188, // updated 4.5
|
||||||
PlayerClassInfo = 0x0189, // updated 4.5
|
PlayerClassInfo = 0x0189, // updated 4.5
|
||||||
|
|
||||||
ModelEquip = 0x018B, // updated 4.5
|
ModelEquip = 0x018B, // updated 4.5
|
||||||
Examine = 0x018C, // updated 4.5
|
Examine = 0x018C, // updated 4.5
|
||||||
CharaNameReq = 0x018D, // updated 4.5
|
CharaNameReq = 0x018D, // updated 4.5
|
||||||
|
|
||||||
SetLevelSync = 0x1186, // not updated for 4.4, not sure what it is anymore
|
SetLevelSync = 0x1186, // not updated for 4.4, not sure what it is anymore
|
||||||
|
|
||||||
ItemInfo = 0x0196, // updated 4.5
|
ItemInfo = 0x0196, // updated 4.5
|
||||||
ContainerInfo = 0x0197, // updated 4.5
|
ContainerInfo = 0x0197, // updated 4.5
|
||||||
InventoryTransactionFinish = 0x0198, // updated 4.5
|
InventoryTransactionFinish = 0x0198, // updated 4.5
|
||||||
InventoryTransaction = 0x0199, // updated 4.5
|
InventoryTransaction = 0x0199, // updated 4.5
|
||||||
|
|
||||||
CurrencyCrystalInfo = 0x019B, // updated 4.5
|
CurrencyCrystalInfo = 0x019B, // updated 4.5
|
||||||
|
|
||||||
InventoryActionAck = 0x019D, // updated 4.5
|
InventoryActionAck = 0x019D, // updated 4.5
|
||||||
UpdateInventorySlot = 0x019E, // updated 4.5
|
UpdateInventorySlot = 0x019E, // updated 4.5
|
||||||
|
|
||||||
|
|
|
@ -698,8 +698,7 @@ struct FFXIVIpcActorSetPos :
|
||||||
* Structural representation of the packet sent by the server
|
* Structural representation of the packet sent by the server
|
||||||
* to start an actors casting
|
* to start an actors casting
|
||||||
*/
|
*/
|
||||||
struct FFXIVIpcActorCast :
|
struct FFXIVIpcActorCast : FFXIVIpcBasePacket< ActorCast >
|
||||||
FFXIVIpcBasePacket< ActorCast >
|
|
||||||
{
|
{
|
||||||
uint16_t action_id;
|
uint16_t action_id;
|
||||||
Common::SkillType skillType;
|
Common::SkillType skillType;
|
||||||
|
@ -715,11 +714,10 @@ struct FFXIVIpcActorCast :
|
||||||
uint16_t unknown_3;
|
uint16_t unknown_3;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FFXIVIpcHateList :
|
struct FFXIVIpcHateList : FFXIVIpcBasePacket< HateList >
|
||||||
FFXIVIpcBasePacket< HateList >
|
|
||||||
{
|
{
|
||||||
uint32_t numEntries;
|
uint32_t numEntries;
|
||||||
struct LsEntry
|
struct
|
||||||
{
|
{
|
||||||
uint32_t actorId;
|
uint32_t actorId;
|
||||||
uint8_t hatePercent;
|
uint8_t hatePercent;
|
||||||
|
@ -729,8 +727,7 @@ struct FFXIVIpcHateList :
|
||||||
uint32_t padding;
|
uint32_t padding;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FFXIVIpcUpdateClassInfo :
|
struct FFXIVIpcUpdateClassInfo : FFXIVIpcBasePacket< UpdateClassInfo >
|
||||||
FFXIVIpcBasePacket< UpdateClassInfo >
|
|
||||||
{
|
{
|
||||||
uint8_t classId;
|
uint8_t classId;
|
||||||
uint8_t level1;
|
uint8_t level1;
|
||||||
|
|
|
@ -119,10 +119,10 @@ uint64_t Sapphire::Util::getTimeMs()
|
||||||
return epoch.count();
|
return epoch.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Sapphire::Util::getTimeSeconds()
|
uint32_t Sapphire::Util::getTimeSeconds()
|
||||||
{
|
{
|
||||||
std::chrono::seconds epoch = std::chrono::seconds( std::time( nullptr ) );
|
auto currClock = std::chrono::system_clock::now();
|
||||||
return epoch.count();
|
return std::chrono::time_point_cast< std::chrono::seconds >( currClock ).time_since_epoch().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Sapphire::Util::getEorzeanTimeStamp()
|
uint64_t Sapphire::Util::getEorzeanTimeStamp()
|
||||||
|
|
|
@ -21,7 +21,12 @@ namespace Sapphire::Util
|
||||||
|
|
||||||
uint64_t getTimeMs();
|
uint64_t getTimeMs();
|
||||||
|
|
||||||
int64_t getTimeSeconds();
|
/*!
|
||||||
|
* @brief Get a POSIX epoch representation of the current time
|
||||||
|
* @return 32-bit unsigned integer
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t getTimeSeconds();
|
||||||
|
|
||||||
uint64_t getEorzeanTimeStamp();
|
uint64_t getEorzeanTimeStamp();
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,12 @@ file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*")
|
||||||
add_executable(pcb_reader2 ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
|
add_executable(pcb_reader2 ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
target_link_libraries (pcb_reader2 common xivdat pthread mysqlclient dl z stdc++fs )
|
target_link_libraries( pcb_reader2 common xivdat pthread mysqlclient dl z stdc++fs Recast Detour )
|
||||||
else()
|
else()
|
||||||
target_link_libraries (pcb_reader2 common xivdat mysql zlib)
|
target_link_libraries( pcb_reader2 common xivdat mysql zlib Recast Detour )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_include_directories( pcb_reader2
|
||||||
|
PUBLIC
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../../deps/" )
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, BNpcTemplatePtr pTemplate, float posX
|
||||||
m_pos.z = posZ;
|
m_pos.z = posZ;
|
||||||
m_rot = rot;
|
m_rot = rot;
|
||||||
m_level = level;
|
m_level = level;
|
||||||
|
m_invincibilityType = InvincibilityNone;
|
||||||
|
|
||||||
m_pCurrentZone = pZone;
|
m_pCurrentZone = pZone;
|
||||||
|
|
||||||
|
@ -130,6 +131,11 @@ void Sapphire::Entity::BNpc::spawn( PlayerPtr pTarget )
|
||||||
pTarget->queuePacket( std::make_shared< NpcSpawnPacket >( *getAsBNpc(), *pTarget ) );
|
pTarget->queuePacket( std::make_shared< NpcSpawnPacket >( *getAsBNpc(), *pTarget ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sapphire::Entity::BNpc::despawn( PlayerPtr pTarget )
|
||||||
|
{
|
||||||
|
pTarget->freePlayerSpawnId( getId() );
|
||||||
|
}
|
||||||
|
|
||||||
Sapphire::Entity::BNpcState Sapphire::Entity::BNpc::getState() const
|
Sapphire::Entity::BNpcState Sapphire::Entity::BNpc::getState() const
|
||||||
{
|
{
|
||||||
return m_state;
|
return m_state;
|
||||||
|
@ -243,7 +249,7 @@ void Sapphire::Entity::BNpc::hateListRemove( Sapphire::Entity::CharaPtr pChara )
|
||||||
if( pChara->isPlayer() )
|
if( pChara->isPlayer() )
|
||||||
{
|
{
|
||||||
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
||||||
//tmpPlayer->onMobDeaggro( getAsBattleNpc() );
|
tmpPlayer->onMobDeaggro( getAsBNpc() );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +279,7 @@ void Sapphire::Entity::BNpc::aggro( Sapphire::Entity::CharaPtr pChara )
|
||||||
{
|
{
|
||||||
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
||||||
tmpPlayer->queuePacket( makeActorControl142( getId(), ActorControlType::ToggleWeapon, 0, 1, 1 ) );
|
tmpPlayer->queuePacket( makeActorControl142( getId(), ActorControlType::ToggleWeapon, 0, 1, 1 ) );
|
||||||
//tmpPlayer->onMobAggro( getAsBattleNpc() );
|
tmpPlayer->onMobAggro( getAsBNpc() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +291,7 @@ void Sapphire::Entity::BNpc::deaggro( Sapphire::Entity::CharaPtr pChara )
|
||||||
if( pChara->isPlayer() )
|
if( pChara->isPlayer() )
|
||||||
{
|
{
|
||||||
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
||||||
//tmpPlayer->onMobDeaggro( getAsBattleNpc() );
|
tmpPlayer->onMobDeaggro( getAsBNpc() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +301,9 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
||||||
const uint8_t aggroRange = 8;
|
const uint8_t aggroRange = 8;
|
||||||
const uint8_t maxDistanceToOrigin = 30;
|
const uint8_t maxDistanceToOrigin = 30;
|
||||||
|
|
||||||
|
if( m_status == ActorStatus::Dead )
|
||||||
|
return;
|
||||||
|
|
||||||
switch( m_state )
|
switch( m_state )
|
||||||
{
|
{
|
||||||
case BNpcState::Retreat:
|
case BNpcState::Retreat:
|
||||||
|
@ -306,6 +315,10 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
||||||
|
|
||||||
case BNpcState::Idle:
|
case BNpcState::Idle:
|
||||||
{
|
{
|
||||||
|
// passive mobs should ignore players unless aggro'd
|
||||||
|
if( m_aggressionMode == 1 )
|
||||||
|
return;
|
||||||
|
|
||||||
CharaPtr pClosestChara = getClosestChara();
|
CharaPtr pClosestChara = getClosestChara();
|
||||||
|
|
||||||
if( pClosestChara && pClosestChara->isAlive() )
|
if( pClosestChara && pClosestChara->isAlive() )
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace Sapphire::Entity
|
||||||
virtual ~BNpc() override;
|
virtual ~BNpc() override;
|
||||||
|
|
||||||
void spawn( PlayerPtr pTarget ) override;
|
void spawn( PlayerPtr pTarget ) override;
|
||||||
|
void despawn( PlayerPtr pTarget ) override;
|
||||||
|
|
||||||
uint16_t getModelChara() const;
|
uint16_t getModelChara() const;
|
||||||
uint8_t getLevel() const override;
|
uint8_t getLevel() const override;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
|
#include "BNpc.h"
|
||||||
|
|
||||||
#include "Manager/HousingMgr.h"
|
#include "Manager/HousingMgr.h"
|
||||||
#include "Manager/TerritoryMgr.h"
|
#include "Manager/TerritoryMgr.h"
|
||||||
|
@ -1348,6 +1349,45 @@ void Sapphire::Entity::Player::initHateSlotQueue()
|
||||||
m_freeHateSlotQueue.push( i );
|
m_freeHateSlotQueue.push( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sapphire::Entity::Player::hateListAdd( BNpcPtr pBNpc )
|
||||||
|
{
|
||||||
|
if( !m_freeHateSlotQueue.empty() )
|
||||||
|
{
|
||||||
|
uint8_t hateId = m_freeHateSlotQueue.front();
|
||||||
|
m_freeHateSlotQueue.pop();
|
||||||
|
m_actorIdTohateSlotMap[ pBNpc->getId() ] = hateId;
|
||||||
|
sendHateList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sapphire::Entity::Player::hateListRemove( BNpcPtr pBNpc )
|
||||||
|
{
|
||||||
|
|
||||||
|
auto it = m_actorIdTohateSlotMap.begin();
|
||||||
|
for( ; it != m_actorIdTohateSlotMap.end(); ++it )
|
||||||
|
{
|
||||||
|
if( it->first == pBNpc->getId() )
|
||||||
|
{
|
||||||
|
uint8_t hateSlot = it->second;
|
||||||
|
m_freeHateSlotQueue.push( hateSlot );
|
||||||
|
m_actorIdTohateSlotMap.erase( it );
|
||||||
|
sendHateList();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Sapphire::Entity::Player::hateListHasEntry( BNpcPtr pBNpc )
|
||||||
|
{
|
||||||
|
for( const auto& entry : m_actorIdTohateSlotMap )
|
||||||
|
{
|
||||||
|
if( entry.first == pBNpc->getId() )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Sapphire::Entity::Player::sendHateList()
|
void Sapphire::Entity::Player::sendHateList()
|
||||||
{
|
{
|
||||||
auto hateListPacket = makeZonePacket< FFXIVIpcHateList >( getId() );
|
auto hateListPacket = makeZonePacket< FFXIVIpcHateList >( getId() );
|
||||||
|
@ -1361,6 +1401,19 @@ void Sapphire::Entity::Player::sendHateList()
|
||||||
queuePacket( hateListPacket );
|
queuePacket( hateListPacket );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sapphire::Entity::Player::onMobAggro( BNpcPtr pBNpc )
|
||||||
|
{
|
||||||
|
hateListAdd( pBNpc );
|
||||||
|
queuePacket( makeActorControl142( getId(), ToggleAggro, 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sapphire::Entity::Player::onMobDeaggro( BNpcPtr pBNpc )
|
||||||
|
{
|
||||||
|
hateListRemove( pBNpc );
|
||||||
|
if( m_actorIdTohateSlotMap.empty() )
|
||||||
|
queuePacket( makeActorControl142( getId(), ToggleAggro ) );
|
||||||
|
}
|
||||||
|
|
||||||
bool Sapphire::Entity::Player::isLogin() const
|
bool Sapphire::Entity::Player::isLogin() const
|
||||||
{
|
{
|
||||||
return m_bIsLogin;
|
return m_bIsLogin;
|
||||||
|
@ -1533,7 +1586,7 @@ uint32_t Sapphire::Entity::Player::getCFPenaltyMinutes() const
|
||||||
void Sapphire::Entity::Player::setCFPenaltyMinutes( uint32_t minutes )
|
void Sapphire::Entity::Player::setCFPenaltyMinutes( uint32_t minutes )
|
||||||
{
|
{
|
||||||
auto currentTimestamp = Sapphire::Util::getTimeSeconds();
|
auto currentTimestamp = Sapphire::Util::getTimeSeconds();
|
||||||
setCFPenaltyTimestamp( static_cast< uint32_t >( currentTimestamp + minutes * 60 ) );
|
setCFPenaltyTimestamp( currentTimestamp + minutes * 60 );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Sapphire::Entity::Player::getOpeningSequence() const
|
uint8_t Sapphire::Entity::Player::getOpeningSequence() const
|
||||||
|
|
|
@ -798,6 +798,11 @@ namespace Sapphire::Entity
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void initHateSlotQueue();
|
void initHateSlotQueue();
|
||||||
|
|
||||||
|
void hateListAdd( BNpcPtr pBNpc );
|
||||||
|
void hateListRemove( BNpcPtr pBNpc );
|
||||||
|
|
||||||
|
bool hateListHasEntry( BNpcPtr pBNpc );
|
||||||
|
|
||||||
void sendHateList();
|
void sendHateList();
|
||||||
|
|
||||||
bool actionHasCastTime( uint32_t actionId );
|
bool actionHasCastTime( uint32_t actionId );
|
||||||
|
@ -831,6 +836,9 @@ namespace Sapphire::Entity
|
||||||
|
|
||||||
bool isAutoattackOn() const;
|
bool isAutoattackOn() const;
|
||||||
|
|
||||||
|
void onMobAggro( BNpcPtr pBNpc );
|
||||||
|
void onMobDeaggro( BNpcPtr pBNpc );
|
||||||
|
|
||||||
// Content Finder handling
|
// Content Finder handling
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/*! Get an unix time when the player can register into content finder again. */
|
/*! Get an unix time when the player can register into content finder again. */
|
||||||
|
|
|
@ -83,12 +83,11 @@ void Sapphire::World::Manager::MarketMgr::requestItemListingInfo( Sapphire::Enti
|
||||||
|
|
||||||
listing.itemCatalogId = catalogId;
|
listing.itemCatalogId = catalogId;
|
||||||
listing.quantity = i + 1;
|
listing.quantity = i + 1;
|
||||||
listing.purchaseTime = time( nullptr );
|
listing.purchaseTime = Sapphire::Util::getTimeSeconds();
|
||||||
listing.salePrice = 69420420;
|
listing.salePrice = 69420420;
|
||||||
listing.isHq = 1;
|
listing.isHq = 1;
|
||||||
listing.onMannequin = 1;
|
listing.onMannequin = 1;
|
||||||
|
|
||||||
|
|
||||||
strcpy( listing.buyerName, name.c_str() );
|
strcpy( listing.buyerName, name.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/world/Manager/RNGMgr.cpp
Normal file
10
src/world/Manager/RNGMgr.cpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include "RNGMgr.h"
|
||||||
|
#include <Logging/Logger.h>
|
||||||
|
|
||||||
|
Sapphire::World::Manager::RNGMgr::RNGMgr( FrameworkPtr pFw ) :
|
||||||
|
BaseManager( pFw ),
|
||||||
|
m_engine( *engineSeed< std::mt19937::state_size >() )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
94
src/world/Manager/RNGMgr.h
Normal file
94
src/world/Manager/RNGMgr.h
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#ifndef SAPPHIRE_RNGMGR_H
|
||||||
|
#define SAPPHIRE_RNGMGR_H
|
||||||
|
|
||||||
|
#include "Forwards.h"
|
||||||
|
#include "BaseManager.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <random>
|
||||||
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace Sapphire::World::Manager
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* @brief Generator object that is used on multiple state situations
|
||||||
|
*/
|
||||||
|
template< typename T, typename = typename std::enable_if< std::is_arithmetic< T >::value, T >::type >
|
||||||
|
class RandGenerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RandGenerator( T minRange = std::numeric_limits< T >::min(), T maxRange = std::numeric_limits< T >::max() )
|
||||||
|
: m_engine( *engineSeed< std::mt19937::state_size >() ), m_dist( minRange, maxRange )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
T next()
|
||||||
|
{
|
||||||
|
return m_dist( m_engine );
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
template< std::size_t STATE_SIZE >
|
||||||
|
std::unique_ptr< std::seed_seq > engineSeed()
|
||||||
|
{
|
||||||
|
std::array< uint32_t, STATE_SIZE > seedArray;
|
||||||
|
std::random_device rd;
|
||||||
|
|
||||||
|
std::generate_n( seedArray.data(), seedArray.size(), std::ref( rd ) );
|
||||||
|
auto pSeq = std::make_unique< std::seed_seq >( std::begin( seedArray ), std::end( seedArray ) );
|
||||||
|
|
||||||
|
return pSeq;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uniform_real_distribution< T > m_dist;
|
||||||
|
std::mt19937 m_engine;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RNGMgr : public BaseManager
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
RNGMgr( FrameworkPtr pFw );
|
||||||
|
virtual ~RNGMgr() = default;
|
||||||
|
|
||||||
|
RNGMgr( const RNGMgr& pRNGMgr ) = delete;
|
||||||
|
RNGMgr& operator=( const RNGMgr& pRNGMgr ) = delete;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Creates a RNG with specified parameters for multiple uses
|
||||||
|
* @tparam Numeric type to be used for the generator
|
||||||
|
* @param Minimum value possible for the random value
|
||||||
|
* @param Maximum value possible for the random value
|
||||||
|
* @return Random number generator object
|
||||||
|
*/
|
||||||
|
template< typename T, typename = typename std::enable_if< std::is_arithmetic< T >::value, T >::type >
|
||||||
|
RandGenerator< T > getRandGenerator( T minRange, T maxRange )
|
||||||
|
{
|
||||||
|
return RandGenerator< T >( minRange, maxRange );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
template< std::size_t STATE_SIZE >
|
||||||
|
std::unique_ptr< std::seed_seq > engineSeed()
|
||||||
|
{
|
||||||
|
std::array< uint32_t, STATE_SIZE > seedArray;
|
||||||
|
std::random_device rd;
|
||||||
|
|
||||||
|
std::generate_n( seedArray.data(), seedArray.size(), std::ref( rd ) );
|
||||||
|
auto pSeq = std::make_unique< std::seed_seq >( std::begin( seedArray ), std::end( seedArray ) );
|
||||||
|
|
||||||
|
return pSeq;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mt19937 m_engine;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SAPPHIRE_RNGMGR_H
|
|
@ -385,6 +385,7 @@ void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network::
|
||||||
const std::vector< Sapphire::Network::Packets::FFXIVARR_PACKET_RAW >& packetData )
|
const std::vector< Sapphire::Network::Packets::FFXIVARR_PACKET_RAW >& packetData )
|
||||||
{
|
{
|
||||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||||
|
|
||||||
// if a session is set, update the last time it recieved a game packet
|
// if a session is set, update the last time it recieved a game packet
|
||||||
if( m_pSession )
|
if( m_pSession )
|
||||||
m_pSession->updateLastDataTime();
|
m_pSession->updateLastDataTime();
|
||||||
|
@ -427,7 +428,7 @@ void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network::
|
||||||
|
|
||||||
auto pe = std::make_shared< FFXIVRawPacket >( 0x07, 0x18, 0, 0 );
|
auto pe = std::make_shared< FFXIVRawPacket >( 0x07, 0x18, 0, 0 );
|
||||||
*( unsigned int* ) ( &pe->data()[ 0 ] ) = 0xE0037603;
|
*( unsigned int* ) ( &pe->data()[ 0 ] ) = 0xE0037603;
|
||||||
*( unsigned int* ) ( &pe->data()[ 4 ] ) = static_cast< uint32_t >( time( nullptr ) );
|
*( unsigned int* ) ( &pe->data()[ 4 ] ) = Sapphire::Util::getTimeSeconds();
|
||||||
sendSinglePacket( pe );
|
sendSinglePacket( pe );
|
||||||
|
|
||||||
// main connection, assinging it to the session
|
// main connection, assinging it to the session
|
||||||
|
|
|
@ -14,10 +14,8 @@
|
||||||
|
|
||||||
#include "Network/GameConnection.h"
|
#include "Network/GameConnection.h"
|
||||||
|
|
||||||
#include "Manager/TerritoryMgr.h"
|
|
||||||
#include "Territory/Zone.h"
|
#include "Territory/Zone.h"
|
||||||
#include "Territory/HousingZone.h"
|
#include "Territory/HousingZone.h"
|
||||||
#include "Manager/HousingMgr.h"
|
|
||||||
#include "Territory/Land.h"
|
#include "Territory/Land.h"
|
||||||
#include "Territory/ZonePosition.h"
|
#include "Territory/ZonePosition.h"
|
||||||
#include "Territory/House.h"
|
#include "Territory/House.h"
|
||||||
|
@ -37,6 +35,9 @@
|
||||||
#include "Manager/DebugCommandMgr.h"
|
#include "Manager/DebugCommandMgr.h"
|
||||||
#include "Manager/EventMgr.h"
|
#include "Manager/EventMgr.h"
|
||||||
#include "Manager/MarketMgr.h"
|
#include "Manager/MarketMgr.h"
|
||||||
|
#include "Manager/TerritoryMgr.h"
|
||||||
|
#include "Manager/HousingMgr.h"
|
||||||
|
#include "Manager/RNGMgr.h"
|
||||||
|
|
||||||
#include "Action/Action.h"
|
#include "Action/Action.h"
|
||||||
#include "Action/ActionTeleport.h"
|
#include "Action/ActionTeleport.h"
|
||||||
|
@ -440,7 +441,7 @@ void Sapphire::Network::GameConnection::pingHandler( FrameworkPtr pFw,
|
||||||
|
|
||||||
queueOutPacket( std::make_shared< Server::PingPacket >( player, packet.data().timestamp ) );
|
queueOutPacket( std::make_shared< Server::PingPacket >( player, packet.data().timestamp ) );
|
||||||
|
|
||||||
player.setLastPing( static_cast< uint32_t >( time( nullptr ) ) );
|
player.setLastPing( Sapphire::Util::getTimeSeconds() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,18 +75,13 @@ namespace Sapphire::Network::Packets::Server
|
||||||
m_data.bNPCBase = bnpc.getBNpcBaseId();
|
m_data.bNPCBase = bnpc.getBNpcBaseId();
|
||||||
m_data.bNPCName = bnpc.getBNpcNameId();
|
m_data.bNPCName = bnpc.getBNpcNameId();
|
||||||
|
|
||||||
m_data.state = 1;
|
assert( target.getId() != bnpc.getId() );
|
||||||
if( target.getId() == bnpc.getId() )
|
|
||||||
{
|
m_data.spawnIndex = target.getSpawnIdForActorId( bnpc.getId() );
|
||||||
m_data.spawnIndex = 0x00;
|
|
||||||
}
|
if( !target.isActorSpawnIdValid( m_data.spawnIndex ) )
|
||||||
else
|
return;
|
||||||
{
|
|
||||||
m_data.spawnIndex = target.getSpawnIdForActorId( bnpc.getId() );
|
|
||||||
|
|
||||||
if( !target.isActorSpawnIdValid( m_data.spawnIndex ) )
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 0x20 == spawn hidden to be displayed by the spawneffect control
|
// 0x20 == spawn hidden to be displayed by the spawneffect control
|
||||||
//m_data.displayFlags = bnpc.getDisplayFlags();
|
//m_data.displayFlags = bnpc.getDisplayFlags();
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "Manager/EventMgr.h"
|
#include "Manager/EventMgr.h"
|
||||||
#include "Manager/ItemMgr.h"
|
#include "Manager/ItemMgr.h"
|
||||||
#include "Manager/MarketMgr.h"
|
#include "Manager/MarketMgr.h"
|
||||||
|
#include "Manager/RNGMgr.h"
|
||||||
|
|
||||||
using namespace Sapphire::World::Manager;
|
using namespace Sapphire::World::Manager;
|
||||||
|
|
||||||
|
@ -205,6 +206,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
|
||||||
auto pInventoryMgr = std::make_shared< Manager::InventoryMgr >( framework() );
|
auto pInventoryMgr = std::make_shared< Manager::InventoryMgr >( framework() );
|
||||||
auto pEventMgr = std::make_shared< Manager::EventMgr >( framework() );
|
auto pEventMgr = std::make_shared< Manager::EventMgr >( framework() );
|
||||||
auto pItemMgr = std::make_shared< Manager::ItemMgr >( framework() );
|
auto pItemMgr = std::make_shared< Manager::ItemMgr >( framework() );
|
||||||
|
auto pRNGMgr = std::make_shared< Manager::RNGMgr >( framework() );
|
||||||
|
|
||||||
framework()->set< DebugCommandMgr >( pDebugCom );
|
framework()->set< DebugCommandMgr >( pDebugCom );
|
||||||
framework()->set< Manager::PlayerMgr >( pPlayerMgr );
|
framework()->set< Manager::PlayerMgr >( pPlayerMgr );
|
||||||
|
@ -212,6 +214,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
|
||||||
framework()->set< Manager::InventoryMgr >( pInventoryMgr );
|
framework()->set< Manager::InventoryMgr >( pInventoryMgr );
|
||||||
framework()->set< Manager::EventMgr >( pEventMgr );
|
framework()->set< Manager::EventMgr >( pEventMgr );
|
||||||
framework()->set< Manager::ItemMgr >( pItemMgr );
|
framework()->set< Manager::ItemMgr >( pItemMgr );
|
||||||
|
framework()->set< Manager::RNGMgr >( pRNGMgr );
|
||||||
|
|
||||||
Logger::info( "World server running on {0}:{1}", m_ip, m_port );
|
Logger::info( "World server running on {0}:{1}", m_ip, m_port );
|
||||||
|
|
||||||
|
@ -256,7 +259,7 @@ void Sapphire::World::ServerMgr::mainLoop()
|
||||||
|
|
||||||
auto currTime = Util::getTimeSeconds();
|
auto currTime = Util::getTimeSeconds();
|
||||||
|
|
||||||
pTeriMgr->updateTerritoryInstances( static_cast< uint32_t >( currTime ) );
|
pTeriMgr->updateTerritoryInstances( currTime );
|
||||||
|
|
||||||
pScriptMgr->update();
|
pScriptMgr->update();
|
||||||
|
|
||||||
|
@ -473,7 +476,7 @@ Sapphire::Entity::BNpcTemplatePtr Sapphire::World::ServerMgr::getBNpcTemplate( c
|
||||||
|
|
||||||
Sapphire::Entity::BNpcTemplatePtr Sapphire::World::ServerMgr::getBNpcTemplate( uint32_t id )
|
Sapphire::Entity::BNpcTemplatePtr Sapphire::World::ServerMgr::getBNpcTemplate( uint32_t id )
|
||||||
{
|
{
|
||||||
for( auto entry : m_bNpcTemplateMap )
|
for( const auto& entry : m_bNpcTemplateMap )
|
||||||
{
|
{
|
||||||
if( entry.second->getId() == id )
|
if( entry.second->getId() == id )
|
||||||
return entry.second;
|
return entry.second;
|
||||||
|
|
|
@ -206,7 +206,7 @@ void Sapphire::World::Session::update()
|
||||||
// SESSION LOGIC
|
// SESSION LOGIC
|
||||||
m_pPlayer->update( Util::getTimeMs() );
|
m_pPlayer->update( Util::getTimeMs() );
|
||||||
|
|
||||||
if( ( static_cast< uint32_t >( Util::getTimeSeconds() ) - static_cast< uint32_t >( getLastSqlTime() ) ) > 10 )
|
if( Util::getTimeSeconds() - static_cast< uint32_t >( getLastSqlTime() ) > 10 )
|
||||||
{
|
{
|
||||||
updateLastSqlTime();
|
updateLastSqlTime();
|
||||||
m_pPlayer->updateSql();
|
m_pPlayer->updateSql();
|
||||||
|
|
|
@ -56,9 +56,9 @@ namespace Sapphire::World
|
||||||
|
|
||||||
Entity::PlayerPtr m_pPlayer;
|
Entity::PlayerPtr m_pPlayer;
|
||||||
|
|
||||||
int64_t m_lastDataTime;
|
uint32_t m_lastDataTime;
|
||||||
|
|
||||||
int64_t m_lastSqlTime;
|
uint32_t m_lastSqlTime;
|
||||||
bool m_isValid;
|
bool m_isValid;
|
||||||
|
|
||||||
bool m_isReplaying;
|
bool m_isReplaying;
|
||||||
|
|
|
@ -39,7 +39,7 @@ Sapphire::World::Territory::Housing::HousingInteriorTerritory::HousingInteriorTe
|
||||||
Zone( territoryTypeId, guId, internalName, contentName, pFw ),
|
Zone( territoryTypeId, guId, internalName, contentName, pFw ),
|
||||||
m_landIdent( ident )
|
m_landIdent( ident )
|
||||||
{
|
{
|
||||||
m_lastActivityTime = static_cast< uint32_t >( Util::getTimeSeconds() );
|
m_lastActivityTime = Util::getTimeSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
Housing::HousingInteriorTerritory::~HousingInteriorTerritory() = default;
|
Housing::HousingInteriorTerritory::~HousingInteriorTerritory() = default;
|
||||||
|
|
|
@ -30,7 +30,7 @@ Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId,
|
||||||
Sapphire::Data::HousingLandSetPtr info, FrameworkPtr pFw ) :
|
Sapphire::Data::HousingLandSetPtr info, FrameworkPtr pFw ) :
|
||||||
m_currentPrice( 0 ),
|
m_currentPrice( 0 ),
|
||||||
m_minPrice( 0 ),
|
m_minPrice( 0 ),
|
||||||
m_nextDrop( static_cast< uint32_t >( Util::getTimeSeconds() ) + 21600 ),
|
m_nextDrop( Util::getTimeSeconds() + 21600 ),
|
||||||
m_ownerId( 0 ),
|
m_ownerId( 0 ),
|
||||||
m_landSetId( landSetId ),
|
m_landSetId( landSetId ),
|
||||||
m_landInfo( info ),
|
m_landInfo( info ),
|
||||||
|
@ -185,7 +185,7 @@ uint64_t Sapphire::Land::getOwnerId()
|
||||||
|
|
||||||
uint32_t Sapphire::Land::getDevaluationTime()
|
uint32_t Sapphire::Land::getDevaluationTime()
|
||||||
{
|
{
|
||||||
return m_nextDrop - static_cast< uint32_t >( Util::getTimeSeconds() );
|
return m_nextDrop - Util::getTimeSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::Land::setCurrentPrice( uint32_t currentPrice )
|
void Sapphire::Land::setCurrentPrice( uint32_t currentPrice )
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include "Zone.h"
|
#include "Zone.h"
|
||||||
#include "Framework.h"
|
#include "Framework.h"
|
||||||
|
|
||||||
|
#include <Manager/RNGMgr.h>
|
||||||
|
|
||||||
using namespace Sapphire::Common;
|
using namespace Sapphire::Common;
|
||||||
using namespace Sapphire::Network::Packets;
|
using namespace Sapphire::Network::Packets;
|
||||||
using namespace Sapphire::Network::Packets::Server;
|
using namespace Sapphire::Network::Packets::Server;
|
||||||
|
@ -159,7 +161,7 @@ void Sapphire::Zone::loadCellCache()
|
||||||
|
|
||||||
Weather Sapphire::Zone::getNextWeather()
|
Weather Sapphire::Zone::getNextWeather()
|
||||||
{
|
{
|
||||||
uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() );
|
uint32_t unixTime = Util::getTimeSeconds();
|
||||||
// Get Eorzea hour for weather start
|
// Get Eorzea hour for weather start
|
||||||
uint32_t bell = unixTime / 175;
|
uint32_t bell = unixTime / 175;
|
||||||
// Do the magic 'cause for calculations 16:00 is 0, 00:00 is 8 and 08:00 is 16
|
// Do the magic 'cause for calculations 16:00 is 0, 00:00 is 8 and 08:00 is 16
|
||||||
|
@ -381,9 +383,8 @@ void Sapphire::Zone::updateBNpcs( int64_t tickCount )
|
||||||
{
|
{
|
||||||
if( ( tickCount - m_lastMobUpdate ) > 250 )
|
if( ( tickCount - m_lastMobUpdate ) > 250 )
|
||||||
{
|
{
|
||||||
|
|
||||||
m_lastMobUpdate = tickCount;
|
m_lastMobUpdate = tickCount;
|
||||||
uint32_t currTime = static_cast< uint32_t >( time( nullptr ) );
|
uint32_t currTime = Sapphire::Util::getTimeSeconds();
|
||||||
|
|
||||||
/*for( auto it3 = m_BattleNpcDeadMap.begin(); it3 != m_BattleNpcDeadMap.end(); ++it3 )
|
/*for( auto it3 = m_BattleNpcDeadMap.begin(); it3 != m_BattleNpcDeadMap.end(); ++it3 )
|
||||||
{
|
{
|
||||||
|
@ -802,7 +803,7 @@ bool Sapphire::Zone::loadSpawnGroups()
|
||||||
float r = res->getFloat( 5 );
|
float r = res->getFloat( 5 );
|
||||||
uint32_t gimmickId = res->getUInt( 6 );
|
uint32_t gimmickId = res->getUInt( 6 );
|
||||||
|
|
||||||
group.getSpawnPointList().push_back( std::make_shared< Entity::SpawnPoint >( x, y, z, r, gimmickId ) );
|
group.getSpawnPointList().emplace_back( std::make_shared< Entity::SpawnPoint >( x, y, z, r, gimmickId ) );
|
||||||
|
|
||||||
Logger::debug( "id: {0}, x: {1}, y: {2}, z: {3}, gimmickId: {4}", id, x, y, z, gimmickId );
|
Logger::debug( "id: {0}, x: {1}, y: {2}, z: {3}, gimmickId: {4}", id, x, y, z, gimmickId );
|
||||||
}
|
}
|
||||||
|
@ -812,9 +813,8 @@ bool Sapphire::Zone::loadSpawnGroups()
|
||||||
|
|
||||||
void Sapphire::Zone::updateSpawnPoints()
|
void Sapphire::Zone::updateSpawnPoints()
|
||||||
{
|
{
|
||||||
std::random_device rd;
|
auto pRNGMgr = m_pFw->get< World::Manager::RNGMgr >();
|
||||||
std::mt19937 mt( rd() );
|
auto rng = pRNGMgr->getRandGenerator< float >( 0.f, PI * 2 );
|
||||||
std::uniform_real_distribution< float > dist( 0.0, PI * 2 );
|
|
||||||
|
|
||||||
for( auto& group : m_spawnGroups )
|
for( auto& group : m_spawnGroups )
|
||||||
{
|
{
|
||||||
|
@ -837,7 +837,7 @@ void Sapphire::Zone::updateSpawnPoints()
|
||||||
point->getPosX(),
|
point->getPosX(),
|
||||||
point->getPosY(),
|
point->getPosY(),
|
||||||
point->getPosZ(),
|
point->getPosZ(),
|
||||||
dist( mt ),
|
rng.next(),
|
||||||
group.getLevel(),
|
group.getLevel(),
|
||||||
group.getMaxHp(), shared_from_this(), m_pFw );
|
group.getMaxHp(), shared_from_this(), m_pFw );
|
||||||
point->setLinkedBNpc( pBNpc );
|
point->setLinkedBNpc( pBNpc );
|
||||||
|
|
Loading…
Add table
Reference in a new issue