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

Merge remote-tracking branch 'origin/master' into actor_rewrite

This commit is contained in:
Mordred 2018-03-06 00:10:36 +01:00
commit ec0335b64a
46 changed files with 805 additions and 625 deletions

View file

@ -1,5 +1,3 @@
#include "ActionCast.h"
#include <common/Common.h>
#include <common/Util/Util.h>
#include <common/Util/UtilMath.h>
@ -9,17 +7,20 @@
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/ActorControlPacket144.h"
#include "Actor/Player.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
#include "ActionCast.h"
#include "Framework.h"
using namespace Core::Common;
using namespace Core::Network;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Logger g_log;
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::Framework g_framework;
Core::Action::ActionCast::ActionCast()
{
@ -31,7 +32,7 @@ Core::Action::ActionCast::ActionCast( Entity::CharaPtr pActor, Entity::CharaPtr
m_startTime = 0;
m_id = actionId;
m_handleActionType = HandleActionType::Spell;
m_castTime = g_exdDataGen.get< Core::Data::Action >( actionId )->cast100ms * 100; // TODO: Add security checks.
m_castTime = g_framework.getExdDataGen().get< Core::Data::Action >( actionId )->cast100ms * 100; // TODO: Add security checks.
m_pSource = pActor;
m_pTarget = pTarget;
m_bInterrupt = false;
@ -75,7 +76,7 @@ void Core::Action::ActionCast::onFinish()
0x219, m_id, m_id, m_id, m_id );
m_pSource->sendToInRangeSet( control, true );*/
g_scriptMgr.onCastFinish( *pPlayer, m_pTarget, m_id );
g_framework.getScriptMgr().onCastFinish( *pPlayer, m_pTarget, m_id );
}
void Core::Action::ActionCast::onInterrupt()

View file

@ -4,7 +4,12 @@
#include <common/Common.h>
#include "Action.h"
namespace Core {
namespace Data
{
struct Action;
}
namespace Entity {
enum class TargetFilter

View file

@ -1,5 +1,3 @@
#include "ActionMount.h"
#include <common/Common.h>
#include <common/Util/Util.h>
#include <common/Util/UtilMath.h>
@ -8,16 +6,19 @@
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/ActorControlPacket144.h"
#include "Actor/Player.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
#include "ActionMount.h"
#include "Framework.h"
using namespace Core::Common;
using namespace Core::Network;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
extern Core::Logger g_log;
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::Framework g_framework;
Core::Action::ActionMount::ActionMount()
{

View file

@ -1,20 +1,21 @@
#include "ActionTeleport.h"
#include <common/Util/Util.h>
#include <common/Exd/ExdDataGenerated.h>
#include <common/Logging/Logger.h>
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Actor/Player.h"
#include "ActionTeleport.h"
#include "Framework.h"
using namespace Core::Common;
using namespace Core::Network;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Logger g_log;
extern Core::Framework g_framework;
Core::Action::ActionTeleport::ActionTeleport()
{
@ -26,7 +27,7 @@ Core::Action::ActionTeleport::ActionTeleport( Entity::CharaPtr pActor, uint16_t
m_startTime = 0;
m_id = 5;
m_handleActionType = HandleActionType::Teleport;
m_castTime = g_exdDataGen.get< Core::Data::Action >( 5 )->cast100ms * 100; // TODO: Add security checks.
m_castTime = g_framework.getExdDataGen().get< Core::Data::Action >( 5 )->cast100ms * 100; // TODO: Add security checks.
m_pSource = pActor;
m_bInterrupt = false;
m_targetAetheryte = targetZone;

View file

@ -2,14 +2,16 @@
#include <common/Logging/Logger.h>
#include <common/Exd/ExdDataGenerated.h>
#include "EventAction.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Actor/Player.h"
#include "Event/EventHandler.h"
extern Core::Logger g_log;
extern Core::Data::ExdDataGenerated g_exdDataGen;
#include "EventAction.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network;
@ -28,7 +30,7 @@ Core::Action::EventAction::EventAction( Entity::CharaPtr pActor, uint32_t eventI
m_handleActionType = HandleActionType::Event;
m_eventId = eventId;
m_id = action;
m_castTime = g_exdDataGen.get< Core::Data::EventAction >( action )->castTime * 1000; // TODO: Add security checks.
m_castTime = g_framework.getExdDataGen().get< Core::Data::EventAction >( action )->castTime * 1000; // TODO: Add security checks.
m_onActionFinishClb = finishRef;
m_onActionInterruptClb = interruptRef;
m_pSource = pActor;
@ -91,7 +93,7 @@ void Core::Action::EventAction::onFinish()
}
catch( std::exception& e )
{
g_log.error( e.what() );
g_framework.getLogger().error( e.what() );
}
}
@ -130,7 +132,7 @@ void Core::Action::EventAction::onInterrupt()
}
catch( std::exception& e )
{
g_log.error( e.what() );
g_framework.getLogger().error( e.what() );
}
}

View file

@ -1,16 +1,18 @@
#include "EventItemAction.h"
#include <string.h>
#include <common/Util/Util.h>
#include <common/Util/UtilMath.h>
#include <common/Logging/Logger.h>
#include <string.h>
#include "Actor/Player.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
extern Core::Logger g_log;
#include "Actor/Player.h"
#include "EventItemAction.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network;
@ -84,7 +86,7 @@ void Core::Action::EventItemAction::onFinish()
}
catch( std::exception& e )
{
g_log.error( e.what() );
g_framework.getLogger().error( e.what() );
}
}
@ -113,7 +115,7 @@ void Core::Action::EventItemAction::onInterrupt()
}
catch( std::exception& e )
{
g_log.error( e.what() );
g_framework.getLogger().error( e.what() );
}
}

View file

@ -5,6 +5,11 @@
#include <common/Util/Util.h>
#include <common/Util/UtilMath.h>
#include "Forwards.h"
#include "Action/Action.h"
#include "Action/ActionCollision.h"
#include "Zone/Zone.h"
#include "Network/GameConnection.h"
@ -16,7 +21,25 @@
#include "Session.h"
#include "Zone/Zone.h"
extern Core::ServerZone g_serverZone;
#include "Zone/TerritoryMgr.h"
#include "StatusEffect/StatusEffect.h"
#include "Math/CalcBattle.h"
#include "ServerZone.h"
#include "Session.h"
#include "Actor.h"
#include "Player.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
//using namespace Core::Network::Packets::Server;
Core::Entity::Actor::Actor( ObjKind type ) :
m_objKind( type )
@ -270,7 +293,7 @@ void Core::Entity::Actor::sendToInRangeSet( Network::Packets::GamePacketPtr pPac
{
auto pPlayer = getAsPlayer();
auto pSession = g_serverZone.getSession( pPlayer->getId() );
auto pSession = g_framework.getServerZone().getSession( pPlayer->getId() );
// it might be that the player DC'd in which case the session would be invalid
if( pSession )
@ -340,4 +363,4 @@ Set the current cell the actor is in
void Core::Entity::Actor::setCell( Cell * pCell )
{
m_pCell = pCell;
}
}

View file

@ -23,10 +23,9 @@
#include "Chara.h"
#include "Player.h"
#include "Zone/TerritoryMgr.h"
#include "Framework.h"
extern Core::ServerZone g_serverZone;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -429,7 +428,7 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u
getAsPlayer()->sendDebug( "Handle script skill type: " + std::to_string( type ) );
}
auto actionInfoPtr = g_exdDataGen.get< Core::Data::Action >( actionId );
auto actionInfoPtr = g_framework.getExdDataGen().get< Core::Data::Action >( actionId );
// Todo: Effect packet generator. 90% of this is basically setting params and it's basically unreadable.
// Prepare packet. This is seemingly common for all packets in the action handler.

View file

@ -1,3 +1,5 @@
#include <boost/make_shared.hpp>
#include <common/Common.h>
#include <common/Util/Util.h>
#include <common/Util/UtilMath.h>
@ -12,8 +14,7 @@
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "ServerZone.h"
#include "Zone/ZonePosition.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
@ -27,26 +28,25 @@
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
#include "Network/PacketWrappers/PlayerSpawnPacket.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
#include "Inventory/Item.h"
#include "Inventory/Inventory.h"
#include "Event/EventHandler.h"
#include "Action/Action.h"
#include "Action/ActionTeleport.h"
#include "Action/EventAction.h"
#include "Action/EventItemAction.h"
#include "Action/ActionTeleport.h"
#include "Zone/ZonePosition.h"
#include "Math/CalcStats.h"
#include "Math/CalcBattle.h"
#include <boost/make_shared.hpp>
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Scripting::ScriptManager g_scriptMgr;
#include "ServerZone.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -100,7 +100,7 @@ Core::Entity::Player::~Player()
void Core::Entity::Player::injectPacket( std::string path )
{
auto session = g_serverZone.getSession( getId() );
auto session = g_framework.getServerZone().getSession( getId() );
if( session )
session->getZoneConnection()->injectPacket( path, *this );
}
@ -223,9 +223,9 @@ void Core::Entity::Player::calculateStats()
uint8_t level = getLevel();
uint8_t job = static_cast< uint8_t >( getClass() );
auto classInfo = g_exdDataGen.get< Core::Data::ClassJob >( job );
auto tribeInfo = g_exdDataGen.get< Core::Data::Tribe >( tribe );
auto paramGrowthInfo = g_exdDataGen.get< Core::Data::ParamGrow >( level );
auto classInfo = g_framework.getExdDataGen().get< Core::Data::ClassJob >( job );
auto tribeInfo = g_framework.getExdDataGen().get< Core::Data::Tribe >( tribe );
auto paramGrowthInfo = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( level );
// TODO: put formula somewhere else...
float base = Math::CalcStats::calculateBaseStat( getAsPlayer() );
@ -303,7 +303,7 @@ void Core::Entity::Player::sendStats()
void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
{
auto data = g_exdDataGen.get< Core::Data::Aetheryte >( aetheryteId );
auto data = g_framework.getExdDataGen().get< Core::Data::Aetheryte >( aetheryteId );
if( data == nullptr )
{
@ -311,8 +311,7 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
}
setStateFlag( PlayerStateFlag::BetweenAreas );
auto targetPos = g_territoryMgr.getTerritoryPosition( data->levelId );
auto targetPos = g_framework.getTerritoryMgr().getTerritoryPosition( data->levelId );
Common::FFXIVARR_POSITION3 pos;
pos.x = 0;
@ -326,8 +325,8 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
rot = targetPos->getTargetRotation();
}
sendDebug( "Teleport: " + g_exdDataGen.get< Core::Data::PlaceName >( data->placeName )->name + " " +
g_exdDataGen.get< Core::Data::PlaceName >( data->aethernetName )->name +
sendDebug( "Teleport: " + g_framework.getExdDataGen().get< Core::Data::PlaceName >( data->placeName )->name + " " +
g_framework.getExdDataGen().get< Core::Data::PlaceName >( data->aethernetName )->name +
"(" + std::to_string( data->territory ) + ")" );
// TODO: this should be simplified and a type created in server_common/common.h.
@ -370,14 +369,14 @@ void Core::Entity::Player::returnToHomepoint()
void Core::Entity::Player::setZone( uint32_t zoneId )
{
m_onEnterEventDone = false;
if( !g_territoryMgr.movePlayer( zoneId, getAsPlayer() ) )
if( !g_framework.getTerritoryMgr().movePlayer( zoneId, getAsPlayer() ) )
{
// todo: this will require proper handling, for now just return the player to their previous area
m_pos = m_prevPos;
m_rot = m_prevRot;
m_zoneId = m_prevZoneId;
if( !g_territoryMgr.movePlayer( m_zoneId, getAsPlayer() ) )
if( !g_framework.getTerritoryMgr().movePlayer( m_zoneId, getAsPlayer() ) )
return;
}
@ -387,7 +386,7 @@ void Core::Entity::Player::setZone( uint32_t zoneId )
bool Core::Entity::Player::setInstance( uint32_t instanceContentId )
{
m_onEnterEventDone = false;
auto instance = g_territoryMgr.getInstanceZonePtr( instanceContentId );
auto instance = g_framework.getTerritoryMgr().getInstanceZonePtr( instanceContentId );
if( !instance )
return false;
@ -408,7 +407,7 @@ bool Core::Entity::Player::setInstance( ZonePtr instance )
m_prevZoneId = m_zoneId;
}
if( !g_territoryMgr.movePlayer( instance, getAsPlayer() ) )
if( !g_framework.getTerritoryMgr().movePlayer( instance, getAsPlayer() ) )
return false;
sendZonePackets();
@ -418,7 +417,7 @@ bool Core::Entity::Player::setInstance( ZonePtr instance )
bool Core::Entity::Player::exitInstance()
{
if( !g_territoryMgr.movePlayer( m_prevZoneId, getAsPlayer() ) )
if( !g_framework.getTerritoryMgr().movePlayer( m_prevZoneId, getAsPlayer() ) )
return false;
m_pos = m_prevPos;
@ -493,7 +492,7 @@ void Core::Entity::Player::discover( int16_t map_id, int16_t sub_id )
int32_t offset = 4;
auto info = g_exdDataGen.get< Core::Data::Map >( g_exdDataGen.get< Core::Data::TerritoryType >( getCurrentZone()->getTerritoryId() )->map );
auto info = g_framework.getExdDataGen().get< Core::Data::Map >( g_framework.getExdDataGen().get< Core::Data::TerritoryType >( getCurrentZone()->getTerritoryId() )->map );
if( info->discoveryArrayByte )
offset = 4 + 2 * info->discoveryIndex;
else
@ -508,7 +507,7 @@ void Core::Entity::Player::discover( int16_t map_id, int16_t sub_id )
uint16_t level = getLevel();
uint32_t exp = ( g_exdDataGen.get< Core::Data::ParamGrow >( level )->expToNext * 5 / 100 );
uint32_t exp = ( g_framework.getExdDataGen().get< Core::Data::ParamGrow >( level )->expToNext * 5 / 100 );
gainExp( exp );
@ -585,9 +584,9 @@ void Core::Entity::Player::gainExp( uint32_t amount )
uint16_t level = getLevel();
uint32_t neededExpToLevel = g_exdDataGen.get< Core::Data::ParamGrow >( level )->expToNext;
uint32_t neededExpToLevel = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( level )->expToNext;
uint32_t neededExpToLevelplus1 = g_exdDataGen.get< Core::Data::ParamGrow >( level + 1 )->expToNext;
uint32_t neededExpToLevelplus1 = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( level + 1 )->expToNext;
queuePacket( ActorControlPacket143( getId(), GainExpMsg, static_cast< uint8_t >( getClass() ), amount ) );
@ -660,25 +659,25 @@ void Core::Entity::Player::sendStatusUpdate( bool toSelf )
uint8_t Core::Entity::Player::getLevel() const
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
return static_cast< uint8_t >( m_classArray[classJobIndex] );
}
uint8_t Core::Entity::Player::getLevelForClass( Common::ClassJob pClass ) const
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( pClass ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( pClass ) )->expArrayIndex;
return static_cast< uint8_t >( m_classArray[classJobIndex] );
}
uint32_t Core::Entity::Player::getExp() const
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
return m_expArray[classJobIndex];
}
void Core::Entity::Player::setExp( uint32_t amount )
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
m_expArray[classJobIndex] = amount;
}
@ -718,13 +717,13 @@ void Core::Entity::Player::setClassJob( Common::ClassJob classJob )
void Core::Entity::Player::setLevel( uint8_t level )
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
m_classArray[classJobIndex] = level;
}
void Core::Entity::Player::setLevelForClass( uint8_t level, Common::ClassJob classjob )
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( classjob ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( classjob ) )->expArrayIndex;
if( m_classArray[classJobIndex] == 0 )
insertDbClass( classJobIndex );
@ -798,7 +797,7 @@ void Core::Entity::Player::setLookAt( uint8_t index, uint8_t value )
// spawn this player for pTarget
void Core::Entity::Player::spawn( Entity::PlayerPtr pTarget )
{
g_log.debug( "[" + std::to_string( pTarget->getId() ) + "] Spawning " +
g_framework.getLogger().debug( "[" + std::to_string( pTarget->getId() ) + "] Spawning " +
getName() + " for " +
pTarget->getName() );
@ -811,7 +810,7 @@ void Core::Entity::Player::despawn( Entity::PlayerPtr pTarget )
{
auto pPlayer = pTarget;
g_log.debug( "despawning " + getName() + " for " + pTarget->getName() );
g_framework.getLogger().debug( "despawning " + getName() + " for " + pTarget->getName() );
pPlayer->freePlayerSpawnId( getId() );
@ -876,7 +875,7 @@ const uint8_t* Core::Entity::Player::getStateFlags() const
bool Core::Entity::Player::actionHasCastTime( uint32_t actionId ) //TODO: Add logic for special cases
{
auto actionInfoPtr = g_exdDataGen.get< Core::Data::Action >( actionId );
auto actionInfoPtr = g_framework.getExdDataGen().get< Core::Data::Action >( actionId );
if( actionInfoPtr->preservesCombo )
return false;
@ -1036,7 +1035,7 @@ void Core::Entity::Player::update( int64_t currTime )
void Core::Entity::Player::onMobKill( uint16_t nameId )
{
g_scriptMgr.onMobKill( *getAsPlayer(), nameId );
g_framework.getScriptMgr().onMobKill( *getAsPlayer(), nameId );
}
void Core::Entity::Player::freePlayerSpawnId( uint32_t actorId )
@ -1146,7 +1145,7 @@ const uint8_t* Core::Entity::Player::getGcRankArray() const
void Core::Entity::Player::queuePacket( Network::Packets::GamePacketPtr pPacket )
{
auto pSession = g_serverZone.getSession( m_id );
auto pSession = g_framework.getServerZone().getSession( m_id );
if( !pSession )
return;
@ -1160,7 +1159,7 @@ void Core::Entity::Player::queuePacket( Network::Packets::GamePacketPtr pPacket
void Core::Entity::Player::queueChatPacket( Network::Packets::GamePacketPtr pPacket )
{
auto pSession = g_serverZone.getSession( m_id );
auto pSession = g_framework.getServerZone().getSession( m_id );
if( !pSession )
return;
@ -1623,12 +1622,13 @@ void Core::Entity::Player::emote( uint32_t emoteId, uint64_t targetId )
void Core::Entity::Player::teleportQuery( uint16_t aetheryteId )
{
// TODO: only register this action if enough gil is in possession
auto targetAetheryte = g_exdDataGen.get< Core::Data::Aetheryte >( aetheryteId );
auto& exdDataGen = g_framework.getExdDataGen();
auto targetAetheryte = exdDataGen.get< Core::Data::Aetheryte >( aetheryteId );
if( targetAetheryte )
{
auto fromAetheryte = g_exdDataGen.get< Core::Data::Aetheryte >(
g_exdDataGen.get< Core::Data::TerritoryType >( getZoneId() )->aetheryte );
auto fromAetheryte = exdDataGen.get< Core::Data::Aetheryte >(
exdDataGen.get< Core::Data::TerritoryType >( getZoneId() )->aetheryte );
// calculate cost - does not apply for favorite points or homepoints neither checks for aether tickets
auto cost = static_cast< uint16_t > ( ( sqrt( pow( fromAetheryte->aetherstreamX - targetAetheryte->aetherstreamX, 2 ) +

View file

@ -4,12 +4,6 @@
#include <common/Network/PacketContainer.h>
#include <common/Config/XMLConfig.h>
#include "Player.h"
#include "Zone/Zone.h"
#include "Forwards.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/InitUIPacket.h"
@ -24,10 +18,15 @@
#include "Event/EventHandler.h"
#include "Event/EventHandler.h"
#include "ServerZone.h"
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
#include "Zone/Zone.h"
#include "Player.h"
#include "Forwards.h"
#include "ServerZone.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -85,7 +84,7 @@ void Core::Entity::Player::directorPlayScene( uint32_t eventId, uint32_t scene,
auto pEvent = getEvent( eventId );
if( !pEvent )
{
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
g_framework.getLogger().error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
return;
}
@ -148,7 +147,7 @@ void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene,
}
else if( !pEvent )
{
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
g_framework.getLogger().error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
return;
}
@ -176,7 +175,7 @@ void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene,
}
else if( !pEvent )
{
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
g_framework.getLogger().error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
return;
}
@ -194,7 +193,7 @@ void Core::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlayer )
if( !pEvent )
{
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
g_framework.getLogger().error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
return;
}
@ -263,7 +262,7 @@ void Core::Entity::Player::eventActionStart( uint32_t eventId,
}
else if( !pEvent )
{
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
g_framework.getLogger().error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
return;
}
@ -291,7 +290,7 @@ void Core::Entity::Player::eventItemActionStart( uint32_t eventId,
void Core::Entity::Player::onLogin()
{
for( auto& child : g_serverZone.getConfig()->getChild( "Settings.Parameters.MotDArray" ) )
for( auto& child : g_framework.getServerZone().getConfig()->getChild( "Settings.Parameters.MotDArray" ) )
{
sendNotice( child.second.data() );
}

View file

@ -2,8 +2,6 @@
#include <common/Network/GamePacket.h>
#include <common/Logging/Logger.h>
#include "Player.h"
#include "Zone/Zone.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
@ -12,7 +10,10 @@
#include "Inventory/Inventory.h"
#include "Inventory/Item.h"
extern Core::Logger g_log;
#include "Player.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -87,7 +88,7 @@ void Core::Entity::Player::equipWeapon( ItemPtr pItem )
void Core::Entity::Player::equipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem, bool sendUpdate )
{
//g_log.debug( "Equipping into slot " + std::to_string( equipSlotId ) );
//g_framework.getLogger().debug( "Equipping into slot " + std::to_string( equipSlotId ) );
uint64_t model = pItem->getModelId1();
uint64_t model2 = pItem->getModelId2();

View file

@ -5,14 +5,14 @@
#include <common/Network/PacketContainer.h>
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/QuestMessagePacket.h"
#include "Session.h"
#include "Inventory/Inventory.h"
#include "Player.h"
#include "Framework.h"
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -1015,13 +1015,13 @@ void Core::Entity::Player::removeQuestsCompleted( uint32_t questId )
bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optionalChoice )
{
uint32_t playerLevel = getLevel();
auto questInfo = g_exdDataGen.get< Core::Data::Quest >( questId );
auto questInfo = g_framework.getExdDataGen().get< Core::Data::Quest >( questId );
if( !questInfo )
return false;
auto paramGrowth = g_exdDataGen.get< Core::Data::ParamGrow >( questInfo->classJobLevel0 );
auto paramGrowth = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( questInfo->classJobLevel0 );
// TODO: use the correct formula, this one is wrong
uint32_t exp = ( questInfo->expFactor * paramGrowth->questExpModifier * ( 45 + 5 * questInfo->classJobLevel0 ) ) / 100;
@ -1030,7 +1030,7 @@ bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optional
exp = questInfo->expFactor;
auto rewardItemCount = questInfo->itemReward0.size();
uint16_t optionalItemCount = questInfo->itemReward1.size();
uint16_t optionalItemCount = static_cast< uint16_t >( questInfo->itemReward1.size() );
uint32_t gilReward = questInfo->gilReward;

View file

@ -1,3 +1,7 @@
#include <set>
#include <stdio.h>
#include <time.h>
#include <common/Common.h>
#include <common/Network/GamePacket.h>
#include <common/Util/Util.h>
@ -9,30 +13,20 @@
#include <common/Common.h>
#include <common/Database/DatabaseDef.h>
#include <set>
#include <stdio.h>
#include <time.h>
#include "Player.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "ServerZone.h"
#include "Forwards.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "Inventory/Inventory.h"
#include "Player.h"
#include "ServerZone.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -43,10 +37,10 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
{
const std::string char_id_str = std::to_string( charId );
auto stmt = g_charaDb.getPreparedStatement( Db::CharaDbStatements::CHARA_SEL );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CharaDbStatements::CHARA_SEL );
stmt->setUInt( 1, charId );
auto res = g_charaDb.query( stmt );
auto res = g_framework.getCharaDb().query( stmt );
if( !res->next() )
return false;
@ -74,10 +68,10 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
ZonePtr pCurrZone = nullptr;
// if the zone is an instanceContent zone, we need to actually find the instance
if( g_territoryMgr.isInstanceContentTerritory( zoneId ) )
if( g_framework.getTerritoryMgr().isInstanceContentTerritory( zoneId ) )
{
// try to find an instance actually linked to this player
pCurrZone = g_territoryMgr.getLinkedInstance( m_id );
pCurrZone = g_framework.getTerritoryMgr().getLinkedInstance( m_id );
// if none found, revert to previous zone and position
if( !pCurrZone )
{
@ -86,12 +80,12 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
m_pos.y = m_prevPos.y;
m_pos.z = m_prevPos.z;
setRot( m_prevRot );
pCurrZone = g_territoryMgr.getZoneByTerriId( zoneId );
pCurrZone = g_framework.getTerritoryMgr().getZoneByTerriId( zoneId );
}
}
else
{
pCurrZone = g_territoryMgr.getZoneByTerriId( zoneId );
pCurrZone = g_framework.getTerritoryMgr().getZoneByTerriId( zoneId );
}
m_zoneId = zoneId;
@ -100,12 +94,12 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
// see if a valid zone could be found for the character
if( !pCurrZone )
{
g_log.error( "[" + char_id_str + "] Zone " + std::to_string( zoneId ) + " not found!" );
g_log.error( "[" + char_id_str + "] Setting default zone instead" );
g_framework.getLogger().error( "[" + char_id_str + "] Zone " + std::to_string( zoneId ) + " not found!" );
g_framework.getLogger().error( "[" + char_id_str + "] Setting default zone instead" );
// default to new gridania
// TODO: should probably just abort and mark character as corrupt
pCurrZone = g_territoryMgr.getZoneByTerriId( 132 );
pCurrZone = g_framework.getTerritoryMgr().getZoneByTerriId( 132 );
m_pos.x = 0.0f;
m_pos.y = 0.0f;
@ -192,7 +186,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
m_pCell = nullptr;
if( !loadActiveQuests() || !loadClassData() || !loadSearchInfo() )
g_log.error( "Player id " + char_id_str + " data corrupt!" );
g_framework.getLogger().error( "Player id " + char_id_str + " data corrupt!" );
m_maxHp = getMaxHp();
m_maxMp = getMaxMp();
@ -210,7 +204,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
// first login, run the script event
if( m_bNewGame )
{
//g_scriptMgr.onPlayerFirstEnterWorld( pPlayer );
//g_framework.getScriptMgr().onPlayerFirstEnterWorld( pPlayer );
m_bNewGame = false;
m_hp = getMaxHp();
m_mp = getMaxMp();
@ -236,7 +230,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
initSpawnIdQueue();
if( !g_territoryMgr.movePlayer( pCurrZone, getAsPlayer() ) )
if( !g_framework.getTerritoryMgr().movePlayer( pCurrZone, getAsPlayer() ) )
return false;
return true;
@ -245,10 +239,10 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
bool Core::Entity::Player::loadActiveQuests()
{
auto stmt = g_charaDb.getPreparedStatement( Db::CharaDbStatements::CHARA_QUEST_SEL );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CharaDbStatements::CHARA_QUEST_SEL );
stmt->setUInt( 1, m_id );
auto res = g_charaDb.query( stmt );
auto res = g_framework.getCharaDb().query( stmt );
while( res->next() )
{
@ -282,9 +276,9 @@ bool Core::Entity::Player::loadClassData()
{
// ClassIdx, Exp, Lvl
auto stmt = g_charaDb.getPreparedStatement( Db::CharaDbStatements::CHARA_CLASS_SEL );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CharaDbStatements::CHARA_CLASS_SEL );
stmt->setUInt( 1, m_id );
auto res = g_charaDb.query( stmt );
auto res = g_framework.getCharaDb().query( stmt );
while( res->next() )
{
@ -301,9 +295,9 @@ bool Core::Entity::Player::loadClassData()
bool Core::Entity::Player::loadSearchInfo()
{
auto stmt = g_charaDb.getPreparedStatement( Db::CharaDbStatements::CHARA_SEARCHINFO_SEL );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CharaDbStatements::CHARA_SEARCHINFO_SEL );
stmt->setUInt( 1, m_id );
auto res = g_charaDb.query( stmt );
auto res = g_framework.getCharaDb().query( stmt );
if( !res->next() )
return false;
@ -332,7 +326,7 @@ void Core::Entity::Player::updateSql()
"EquippedMannequin 44, ConfigFlags 45, QuestCompleteFlags 46, OpeningSequence 47, "
"QuestTracking 48, GrandCompany 49, GrandCompanyRank 50, Discovery 51, GMRank 52, Unlocks 53, "
"CFPenaltyUntil 54"*/
auto stmt = g_charaDb.getPreparedStatement( Db::CharaDbStatements::CHARA_UP );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CharaDbStatements::CHARA_UP );
stmt->setInt( 1, getHp() );
stmt->setInt( 2, getMp() );
@ -441,7 +435,7 @@ void Core::Entity::Player::updateSql()
stmt->setInt( 55, m_id );
g_charaDb.execute( stmt );
g_framework.getCharaDb().execute( stmt );
////// Searchinfo
updateDbSearchInfo();
@ -456,43 +450,43 @@ void Core::Entity::Player::updateSql()
void Core::Entity::Player::updateDbClass() const
{
uint8_t classJobIndex = g_exdDataGen.get< Core::Data::ClassJob >( static_cast<uint8_t>( getClass() ) )->expArrayIndex;
uint8_t classJobIndex = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast<uint8_t>( getClass() ) )->expArrayIndex;
//Exp = ?, Lvl = ? WHERE CharacterId = ? AND ClassIdx = ?
auto stmtS = g_charaDb.getPreparedStatement( Db::CHARA_CLASS_UP );
auto stmtS = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_CLASS_UP );
stmtS->setInt( 1, getExp() );
stmtS->setInt( 2, getLevel() );
stmtS->setInt( 3, m_id );
stmtS->setInt( 4, classJobIndex );
g_charaDb.execute( stmtS );
g_framework.getCharaDb().execute( stmtS );
}
void Core::Entity::Player::insertDbClass( const uint8_t classJobIndex ) const
{
auto stmtClass = g_charaDb.getPreparedStatement( Db::CHARA_CLASS_INS );
auto stmtClass = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_CLASS_INS );
stmtClass->setInt( 1, getId() );
stmtClass->setInt( 2, classJobIndex );
stmtClass->setInt( 3, 0 );
stmtClass->setInt( 4, 1 );
g_charaDb.directExecute( stmtClass );
g_framework.getCharaDb().directExecute( stmtClass );
}
void Core::Entity::Player::updateDbSearchInfo() const
{
auto stmtS = g_charaDb.getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTCLASS );
auto stmtS = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTCLASS );
stmtS->setInt( 1, m_searchSelectClass );
stmtS->setInt( 2, m_id );
g_charaDb.execute( stmtS );
g_framework.getCharaDb().execute( stmtS );
auto stmtS1 = g_charaDb.getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTREGION );
auto stmtS1 = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTREGION );
stmtS1->setInt( 1, m_searchSelectRegion );
stmtS1->setInt( 2, m_id );
g_charaDb.execute( stmtS1 );
g_framework.getCharaDb().execute( stmtS1 );
auto stmtS2 = g_charaDb.getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTREGION );
auto stmtS2 = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTREGION );
stmtS2->setString( 1, string( m_searchMessage != nullptr ? m_searchMessage : "" ) );
stmtS2->setInt( 2, m_id );
g_charaDb.execute( stmtS2 );
g_framework.getCharaDb().execute( stmtS2 );
}
void Core::Entity::Player::updateDbAllQuests() const
@ -503,7 +497,7 @@ void Core::Entity::Player::updateDbAllQuests() const
if( !m_activeQuests[i] )
continue;
auto stmtS3 = g_charaDb.getPreparedStatement( Db::CHARA_QUEST_UP );
auto stmtS3 = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_QUEST_UP );
stmtS3->setInt( 1, m_activeQuests[i]->c.sequence );
stmtS3->setInt( 2, m_activeQuests[i]->c.flags );
stmtS3->setInt( 3, m_activeQuests[i]->c.UI8A );
@ -515,22 +509,22 @@ void Core::Entity::Player::updateDbAllQuests() const
stmtS3->setInt( 9, m_activeQuests[i]->c.padding1 );
stmtS3->setInt( 10, m_id);
stmtS3->setInt( 11, m_activeQuests[i]->c.questId );
g_charaDb.execute( stmtS3 );
g_framework.getCharaDb().execute( stmtS3 );
}
}
void Core::Entity::Player::deleteQuest( uint16_t questId ) const
{
auto stmt = g_charaDb.getPreparedStatement( Db::CHARA_QUEST_DEL );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_QUEST_DEL );
stmt->setInt( 1, m_id );
stmt->setInt( 2, questId );
g_charaDb.execute( stmt );
g_framework.getCharaDb().execute( stmt );
}
void Core::Entity::Player::insertQuest( uint16_t questId, uint8_t index, uint8_t seq ) const
{
auto stmt = g_charaDb.getPreparedStatement( Db::CHARA_QUEST_INS );
auto stmt = g_framework.getCharaDb().getPreparedStatement( Db::CHARA_QUEST_INS );
stmt->setInt( 1, m_id );
stmt->setInt( 2, index );
stmt->setInt( 3, questId );
@ -543,5 +537,5 @@ void Core::Entity::Player::insertQuest( uint16_t questId, uint8_t index, uint8_t
stmt->setInt( 10, 0 );
stmt->setInt( 11, 0 );
stmt->setInt( 12, 0 );
g_charaDb.execute( stmt );
g_framework.getCharaDb().execute( stmt );
}

View file

@ -1,4 +1,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
#include <boost/format.hpp>
#include <cinttypes>
#include <common/Common.h>
#include <common/Version.h>
@ -17,33 +20,25 @@
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "Network/PacketWrappers/PlayerSpawnPacket.h"
#include "Network/GameConnection.h"
#include "Script/ScriptManager.h"
#include "Script/NativeScriptManager.h"
#include "Script/ScriptMgr.h"
#include "Script/NativeScriptMgr.h"
#include "Actor/Player.h"
#include "Actor/EventObject.h"
#include "Zone/Zone.h"
#include "Zone/InstanceContent.h"
#include "Zone/TerritoryMgr.h"
#include "ServerZone.h"
#include "StatusEffect/StatusEffect.h"
#include "Session.h"
#include <boost/make_shared.hpp>
#include <boost/format.hpp>
#include "Framework.h"
#include <cinttypes>
#include "Network/PacketWrappers/PlayerSpawnPacket.h"
#include "Zone/TerritoryMgr.h"
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::Framework g_framework;
// instanciate and initialize commands
Core::DebugCommandHandler::DebugCommandHandler()
@ -156,7 +151,7 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost:
if( command->getName().length() + 1 + pos + 1 < strlen( data ) )
params = std::string( data + command->getName().length() + 1 + pos + 1 );
g_log.debug( "[" + std::to_string( player.getId() ) + "] " +
g_framework.getLogger().debug( "[" + std::to_string( player.getId() ) + "] " +
"subCommand " + subCommand + " params: " + params );
@ -224,8 +219,8 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost:
"', '" + std::to_string( map_id ) +
"', '" + std::to_string( discover_id ) + "')";
g_charaDb.execute( query1 );
g_charaDb.execute( query2 );
g_framework.getCharaDb().execute( query1 );
g_framework.getCharaDb().execute( query2 );
}
@ -339,7 +334,7 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost:
if( command->getName().length() + 1 + pos + 1 < strlen( data ) )
params = std::string( data + command->getName().length() + 1 + pos + 1 );
g_log.debug( "[" + std::to_string( player.getId() ) + "] " +
g_framework.getLogger().debug( "[" + std::to_string( player.getId() ) + "] " +
"subCommand " + subCommand + " params: " + params );
@ -440,14 +435,14 @@ void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost:
if( command->getName().length() + 1 + pos + 1 < strlen( data ) )
params = std::string( data + command->getName().length() + 1 + pos + 1 );
g_log.debug( "[" + std::to_string( player.getId() ) + "] " +
g_framework.getLogger().debug( "[" + std::to_string( player.getId() ) + "] " +
"subCommand " + subCommand + " params: " + params );
if( ( subCommand == "pos" ) )
{
int16_t map_id = g_exdDataGen.get< Core::Data::TerritoryType >( player.getCurrentZone()->getTerritoryId() )->map;
int16_t map_id = g_framework.getExdDataGen().get< Core::Data::TerritoryType >( player.getCurrentZone()->getTerritoryId() )->map;
player.sendNotice( "Pos:\n" +
std::to_string( player.getPos().x ) + "\n" +
@ -466,14 +461,14 @@ void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost:
void Core::DebugCommandHandler::injectPacket( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command )
{
auto pSession = g_serverZone.getSession( player.getId() );
auto pSession = g_framework.getServerZone().getSession( player.getId() );
if( pSession )
pSession->getZoneConnection()->injectPacket( data + 7, player );
}
void Core::DebugCommandHandler::injectChatPacket( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command )
{
auto pSession = g_serverZone.getSession( player.getId() );
auto pSession = g_framework.getServerZone().getSession( player.getId() );
if( pSession )
pSession->getChatConnection()->injectPacket( data + 8, player );
}
@ -498,25 +493,25 @@ void Core::DebugCommandHandler::replay( char * data, Entity::Player& player, boo
if( command->getName().length() + 1 + pos + 1 < strlen( data ) )
params = std::string( data + command->getName().length() + 1 + pos + 1 );
g_log.debug( "[" + std::to_string( player.getId() ) + "] " +
g_framework.getLogger().debug( "[" + std::to_string( player.getId() ) + "] " +
"subCommand " + subCommand + " params: " + params );
if( subCommand == "start" )
{
auto pSession = g_serverZone.getSession( player.getId() );
auto pSession = g_framework.getServerZone().getSession( player.getId() );
if( pSession )
pSession->startReplay( params );
}
else if( subCommand == "stop" )
{
auto pSession = g_serverZone.getSession( player.getId() );
auto pSession = g_framework.getServerZone().getSession( player.getId() );
if( pSession )
pSession->stopReplay();
}
else if( subCommand == "info" )
{
auto pSession = g_serverZone.getSession( player.getId() );
auto pSession = g_framework.getServerZone().getSession( player.getId() );
if( pSession )
pSession->sendReplayInfo();
}
@ -579,7 +574,7 @@ void Core::DebugCommandHandler::serverInfo( char * data, Entity::Player& player,
{
player.sendDebug( "SapphireZone " + Version::VERSION + "\nRev: " + Version::GIT_HASH );
player.sendDebug( "Compiled: " __DATE__ " " __TIME__ );
player.sendDebug( "Sessions: " + std::to_string( g_serverZone.getSessionCount() ) );
player.sendDebug( "Sessions: " + std::to_string( g_framework.getServerZone().getSessionCount() ) );
}
void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boost::shared_ptr< DebugCommand > command )
@ -603,7 +598,7 @@ void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boos
if( command->getName().length() + 1 + pos + 1 < strlen( data ) )
params = std::string( data + command->getName().length() + 1 + pos + 1 );
g_log.debug( "[" + std::to_string( player.getId() ) + "] " +
g_framework.getLogger().debug( "[" + std::to_string( player.getId() ) + "] " +
"subCommand " + subCommand + " params: " + params );
if( subCommand == "unload" )
@ -611,7 +606,7 @@ void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boos
if ( subCommand == params )
player.sendDebug( "Command failed: requires name of script" );
else
if( g_scriptMgr.getNativeScriptHandler().unloadScript( params ) )
if( g_framework.getScriptMgr().getNativeScriptHandler().unloadScript( params ) )
player.sendDebug( "Unloaded script successfully." );
else
player.sendDebug( "Failed to unload script: " + params );
@ -623,7 +618,7 @@ void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boos
else
{
std::set< Core::Scripting::ScriptInfo* > scripts;
g_scriptMgr.getNativeScriptHandler().findScripts( scripts, params );
g_framework.getScriptMgr().getNativeScriptHandler().findScripts( scripts, params );
if( !scripts.empty() )
{
@ -647,7 +642,7 @@ void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boos
player.sendDebug( "Command failed: requires relative path to script" );
else
{
if ( g_scriptMgr.getNativeScriptHandler().loadScript( params ) )
if ( g_framework.getScriptMgr().getNativeScriptHandler().loadScript( params ) )
player.sendDebug( "Loaded '" + params + "' successfully" );
else
player.sendDebug( "Failed to load '" + params + "'" );
@ -660,7 +655,7 @@ void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boos
player.sendDebug( "Command failed: requires name of script to reload" );
else
{
g_scriptMgr.getNativeScriptHandler().queueScriptReload( params );
g_framework.getScriptMgr().getNativeScriptHandler().queueScriptReload( params );
player.sendDebug( "Queued script reload for script: " + params );
}
}
@ -695,7 +690,7 @@ void Core::DebugCommandHandler::instance( char* data, Entity::Player &player, bo
uint32_t instanceContentId;
sscanf( params.c_str(), "%d", &instanceContentId );
auto instance = g_territoryMgr.createInstanceContent( instanceContentId );
auto instance = g_framework.getTerritoryMgr().createInstanceContent( instanceContentId );
if( instance )
player.sendDebug( "Created instance with id: " + std::to_string( instance->getGuId() ) + " -> " + instance->getName() );
else
@ -706,7 +701,7 @@ void Core::DebugCommandHandler::instance( char* data, Entity::Player &player, bo
uint32_t terriId;
sscanf( params.c_str(), "%d", &terriId );
if( g_territoryMgr.removeTerritoryInstance( terriId ) )
if( g_framework.getTerritoryMgr().removeTerritoryInstance( terriId ) )
player.sendDebug( "Removed instance with id: " + std::to_string( terriId ) );
else
player.sendDebug( "Failed to remove instance with id: " + std::to_string( terriId ) );
@ -721,6 +716,7 @@ void Core::DebugCommandHandler::instance( char* data, Entity::Player &player, bo
uint32_t value;
sscanf( params.c_str(), "%d %d", &index, &value );
auto instance = boost::dynamic_pointer_cast< InstanceContent >( player.getCurrentZone() );
if( !instance )
return;

View file

@ -1,12 +1,13 @@
#include "EventHelper.h"
#include "EventHandler.h"
#include <common/Common.h>
#include <common/Exd/ExdDataGenerated.h>
#include "Framework.h"
#include "EventHelper.h"
#include "EventHandler.h"
#include <boost/range/algorithm/remove_if.hpp>
#include <boost/algorithm/string/classification.hpp>
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
using namespace Core::Common;
@ -20,7 +21,7 @@ std::string Core::Event::getEventName( uint32_t eventId )
{
case Event::EventHandler::EventHandlerType::Quest:
{
auto questInfo = g_exdDataGen.get< Core::Data::Quest >( eventId );
auto questInfo = g_framework.getExdDataGen().get< Core::Data::Quest >( eventId );
if( !questInfo )
return unknown + "Quest";
@ -31,7 +32,7 @@ std::string Core::Event::getEventName( uint32_t eventId )
}
case Event::EventHandler::EventHandlerType::CustomTalk:
{
auto customTalkInfo = g_exdDataGen.get< Core::Data::CustomTalk >( eventId );
auto customTalkInfo = g_framework.getExdDataGen().get< Core::Data::CustomTalk >( eventId );
if( !customTalkInfo )
return unknown + "CustomTalk";
@ -42,21 +43,21 @@ std::string Core::Event::getEventName( uint32_t eventId )
}
case Event::EventHandler::EventHandlerType::Opening:
{
auto openingInfo = g_exdDataGen.get< Core::Data::Opening >( eventId );
auto openingInfo = g_framework.getExdDataGen().get< Core::Data::Opening >( eventId );
if( openingInfo )
return openingInfo->name;
return unknown + "Opening";
}
case Event::EventHandler::EventHandlerType::Aetheryte:
{
auto aetherInfo = g_exdDataGen.get< Core::Data::Aetheryte >( eventId & 0xFFFF );
auto aetherInfo = g_framework.getExdDataGen().get< Core::Data::Aetheryte >( eventId & 0xFFFF );
if( aetherInfo->isAetheryte )
return "Aetheryte";
return "Aethernet";
}
case Event::EventHandler::EventHandlerType::ICDirector:
{
auto contentInfo = g_exdDataGen.get< Core::Data::InstanceContent >( eventId & 0xFFFF );
auto contentInfo = g_framework.getExdDataGen().get< Core::Data::InstanceContent >( eventId & 0xFFFF );
std::string name = contentInfo->name;
name.erase( boost::remove_if( name, boost::is_any_of( "★_ '()[]-\x1a\x1\x2\x1f\x1\x3.:" ) ), name.end() );
@ -77,7 +78,7 @@ std::string Core::Event::getEventName( uint32_t eventId )
uint32_t Core::Event::mapEventActorToRealActor( uint32_t eventActorId )
{
auto levelInfo = g_exdDataGen.get< Core::Data::Level >( eventActorId );
auto levelInfo = g_framework.getExdDataGen().get< Core::Data::Level >( eventActorId );
if( levelInfo )
return levelInfo->objectKey;

View file

@ -78,7 +78,7 @@ namespace Core
namespace Scripting
{
class NativeScriptManager;
class NativeScriptMgr;
}
typedef std::function< void( Entity::Player&, uint32_t, uint64_t ) > ActionCallback;

View file

@ -0,0 +1,45 @@
#include <boost/make_shared.hpp>
#include "Framework.h"
Core::ServerZone g_serverZone( "config/settings_zone.xml" );
Core::Logger& Core::Framework::getLogger()
{
return g_log;
}
Core::DebugCommandHandler& Core::Framework::getDebugCommandHandler()
{
return g_debugCmdHandler;
}
Core::Scripting::ScriptMgr& Core::Framework::getScriptMgr()
{
return g_scriptMgr;
}
Core::Data::ExdDataGenerated& Core::Framework::getExdDataGen()
{
return g_exdDataGen;
}
Core::TerritoryMgr& Core::Framework::getTerritoryMgr()
{
return g_territoryMgr;
}
Core::LinkshellMgr& Core::Framework::getLinkshellMgr()
{
return g_linkshellMgr;
}
Core::Db::DbWorkerPool< Core::Db::CharaDbConnection >& Core::Framework::getCharaDb()
{
return g_charaDb;
}
Core::ServerZone& Core::Framework::getServerZone()
{
return g_serverZone;
}

View file

@ -0,0 +1,56 @@
#ifndef CORE_FRAMEWORK_H
#define CORE_FRAMEWORK_H
#include <boost/shared_ptr.hpp>
#include <map>
#include "Forwards.h"
#include "ServerZone.h"
#include <common/Logging/Logger.h>
#include <common/Exd/ExdDataGenerated.h>
#include "Script/ScriptMgr.h"
#include "Linkshell/LinkshellMgr.h"
#include "Zone/TerritoryMgr.h"
#include "DebugCommand/DebugCommandHandler.h"
#include <common/Database/CharaDbConnection.h>
#include <common/Database/DbWorkerPool.h>
namespace Core
{
class Framework
{
private:
Logger g_log;
DebugCommandHandler g_debugCmdHandler;
Scripting::ScriptMgr g_scriptMgr;
Data::ExdDataGenerated g_exdDataGen;
TerritoryMgr g_territoryMgr;
LinkshellMgr g_linkshellMgr;
Db::DbWorkerPool< Db::CharaDbConnection > g_charaDb;
public:
Logger& getLogger();
DebugCommandHandler& getDebugCommandHandler();
Scripting::ScriptMgr& getScriptMgr();
Data::ExdDataGenerated& getExdDataGen();
TerritoryMgr& getTerritoryMgr();
LinkshellMgr& getLinkshellMgr();
Db::DbWorkerPool< Db::CharaDbConnection >& getCharaDb();
ServerZone& getServerZone();
};
}
#endif // CORE_FRAMEWORK_H

View file

@ -1,27 +1,24 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/clamp.hpp>
#include <common/Network/PacketDef/Zone/ServerZoneDef.h>
#include <common/Common.h>
#include <common/Exd/ExdDataGenerated.h>
#include <common/Logging/Logger.h>
#include <common/Database/DatabaseDef.h>
#include "Inventory.h"
#include "Actor/Player.h"
#include "ItemContainer.h"
#include "Item.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/clamp.hpp>
#include "../Forwards.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Forwards.h"
#include "Inventory.h"
#include "ItemContainer.h"
#include "Item.h"
#include "Framework.h"
extern Core::Logger g_log;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network;
@ -135,7 +132,7 @@ Core::ItemPtr Core::Inventory::getItemAt( uint16_t containerId, uint8_t slotId )
Core::ItemPtr Core::Inventory::createItem( uint32_t catalogId, uint8_t quantity )
{
auto itemInfo = g_exdDataGen.get< Core::Data::Item >( catalogId );
auto itemInfo = g_framework.getExdDataGen().get< Core::Data::Item >( catalogId );
uint8_t itemAmount = quantity;
@ -156,7 +153,7 @@ Core::ItemPtr Core::Inventory::createItem( uint32_t catalogId, uint8_t quantity
pItem->setModelIds( itemInfo->modelMain, itemInfo->modelSub );
pItem->setCategory( static_cast< ItemUICategory >( itemInfo->itemUICategory ) );
g_charaDb.execute( "INSERT INTO charaglobalitem ( CharacterId, itemId, catalogId, stack, flags ) VALUES ( " +
g_framework.getCharaDb().execute( "INSERT INTO charaglobalitem ( CharacterId, itemId, catalogId, stack, flags ) VALUES ( " +
std::to_string( m_pOwner->getId() ) + ", " +
std::to_string( pItem->getUId() ) + ", " +
std::to_string( pItem->getId() ) + ", " +
@ -259,7 +256,7 @@ void Core::Inventory::updateCurrencyDb()
query += " WHERE CharacterId = " + std::to_string( m_pOwner->getId() );
g_charaDb.execute( query );
g_framework.getCharaDb().execute( query );
}
@ -286,7 +283,7 @@ void Core::Inventory::updateCrystalDb()
query += " WHERE CharacterId = " + std::to_string( m_pOwner->getId() );
g_charaDb.execute( query );
g_framework.getCharaDb().execute( query );
}
void Core::Inventory::updateBagDb( InventoryType type )
@ -306,7 +303,7 @@ void Core::Inventory::updateBagDb( InventoryType type )
query += " WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) +
" AND storageId = " + std::to_string( static_cast< uint16_t >( type ) );
g_charaDb.execute( query );
g_framework.getCharaDb().execute( query );
}
bool Core::Inventory::isArmory( uint16_t containerId )
@ -389,14 +386,14 @@ void Core::Inventory::updateMannequinDb( InventoryType type )
query += " WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) +
" AND storageId = " + std::to_string( static_cast< uint16_t >( type ) );
g_log.Log( LoggingSeverity::debug, query );
g_charaDb.execute( query );
g_framework.getLogger().debug( query );
g_framework.getCharaDb().execute( query );
}
void Core::Inventory::updateItemDb( Core::ItemPtr pItem ) const
{
g_charaDb.execute( "UPDATE charaglobalitem SET stack = " + std::to_string( pItem->getStackSize() ) + " " +
g_framework.getCharaDb().execute( "UPDATE charaglobalitem SET stack = " + std::to_string( pItem->getStackSize() ) + " " +
// TODO: add other attributes
" WHERE itemId = " + std::to_string( pItem->getUId() ) );
}
@ -473,7 +470,7 @@ bool Core::Inventory::isObtainable( uint32_t catalogId, uint8_t quantity )
int16_t Core::Inventory::addItem( uint16_t inventoryId, int8_t slotId, uint32_t catalogId, uint8_t quantity )
{
auto itemInfo = g_exdDataGen.get< Core::Data::Item >( catalogId );
auto itemInfo = g_framework.getExdDataGen().get< Core::Data::Item >( catalogId );
// if item data doesn't exist or it's a blank field
if( !itemInfo || itemInfo->levelItem == 0 )
@ -506,7 +503,7 @@ int16_t Core::Inventory::addItem( uint16_t inventoryId, int8_t slotId, uint32_t
m_inventoryMap[inventoryId]->setItem( rSlotId, item );
g_charaDb.execute( "UPDATE charaiteminventory SET container_" + std::to_string( rSlotId ) + " = " + std::to_string( item->getUId() ) +
g_framework.getCharaDb().execute( "UPDATE charaiteminventory SET container_" + std::to_string( rSlotId ) + " = " + std::to_string( item->getUId() ) +
" WHERE storageId = " + std::to_string( inventoryId ) +
" AND CharacterId = " + std::to_string( m_pOwner->getId() ) );
@ -650,13 +647,13 @@ void Core::Inventory::discardItem( uint16_t fromInventoryId, uint8_t fromSlotId
Core::ItemPtr Core::Inventory::loadItem( uint64_t uId )
{
// load actual item
auto itemRes = g_charaDb.query( "SELECT catalogId, stack, flags FROM charaglobalitem WHERE itemId = " + std::to_string( uId ) + ";" );
auto itemRes = g_framework.getCharaDb().query( "SELECT catalogId, stack, flags FROM charaglobalitem WHERE itemId = " + std::to_string( uId ) + ";" );
if( !itemRes->next() )
return nullptr;
try
{
auto itemInfo = g_exdDataGen.get< Core::Data::Item >( itemRes->getUInt( 1 ) );
auto itemInfo = g_framework.getExdDataGen().get< Core::Data::Item >( itemRes->getUInt( 1 ) );
bool isHq = itemRes->getUInt( 3 ) == 1 ? true : false;
ItemPtr pItem( new Item( uId,
itemRes->getUInt( 1 ),
@ -678,7 +675,7 @@ bool Core::Inventory::load()
{
//////////////////////////////////////////////////////////////////////////////////////////////////////
// load active gearset
auto res = g_charaDb.query( "SELECT storageId, container_0, container_1, container_2, container_3, "
auto res = g_framework.getCharaDb().query( "SELECT storageId, container_0, container_1, container_2, container_3, "
"container_4, container_5, container_6, container_7, "
"container_8, container_9, container_10, container_11, "
"container_12, container_13 "
@ -708,7 +705,7 @@ bool Core::Inventory::load()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Load Bags
auto bagRes = g_charaDb.query( "SELECT storageId, "
auto bagRes = g_framework.getCharaDb().query( "SELECT storageId, "
"container_0, container_1, container_2, container_3, container_4, "
"container_5, container_6, container_7, container_8, container_9, "
"container_10, container_11, container_12, container_13, container_14, "
@ -741,7 +738,7 @@ bool Core::Inventory::load()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Load Currency
auto curRes = g_charaDb.query( "SELECT storageId, "
auto curRes = g_framework.getCharaDb().query( "SELECT storageId, "
"container_0, container_1, container_2, container_3, container_4, "
"container_5, container_6, container_7, container_8, container_9, "
"container_10, container_11 "
@ -770,7 +767,7 @@ bool Core::Inventory::load()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Load Crystals
auto crystalRes = g_charaDb.query( "SELECT storageId, "
auto crystalRes = g_framework.getCharaDb().query( "SELECT storageId, "
"container_0, container_1, container_2, container_3, container_4, "
"container_5, container_6, container_7, container_8, container_9, "
"container_10, container_11, container_12, container_13, container_14, "
@ -877,7 +874,7 @@ uint16_t Core::Inventory::calculateEquippedGearItemLevel()
}
else
{
g_log.debug( "Is one handed" );
g_framework.getLogger().debug( "Is one handed" );
}
}
@ -927,7 +924,7 @@ uint32_t Core::Inventory::getNextUId()
{
uint32_t charId = 0;
auto pQR = g_charaDb.query( "SELECT MAX(ItemId) FROM charaglobalitem" );
auto pQR = g_framework.getCharaDb().query( "SELECT MAX(ItemId) FROM charaglobalitem" );
if( !pQR->next() )
return 0x00500001;

View file

@ -1,8 +1,10 @@
#include <common/Common.h>
#include <common/Exd/ExdDataGenerated.h>
#include "Framework.h"
#include "Item.h"
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
Core::Item::Item()
{
@ -24,7 +26,7 @@ Core::Item::Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t mo
m_model2( model2 ),
m_isHq( isHq )
{
auto itemInfo = g_exdDataGen.get< Core::Data::Item >( catalogId );
auto itemInfo = g_framework.getExdDataGen().get< Core::Data::Item >( catalogId );
m_delayMs = itemInfo->delayms;
m_physicalDmg = itemInfo->damagePhys;
m_magicalDmg = itemInfo->damageMag;

View file

@ -1,6 +1,3 @@
#include "../Forwards.h"
#include "ItemContainer.h"
#include <common/Common.h>
#include <common/Logging/Logger.h>
#include <common/Database/DatabaseDef.h>
@ -8,9 +5,11 @@
#include "Actor/Player.h"
#include "Item.h"
#include "Framework.h"
#include "Forwards.h"
#include "ItemContainer.h"
extern Core::Logger g_log;
extern Core::Framework g_framework;
Core::ItemContainer::ItemContainer( uint16_t locationId ) :
m_id( locationId ),
@ -40,15 +39,15 @@ void Core::ItemContainer::removeItem( uint8_t slotId )
if( it != m_itemMap.end() )
{
g_charaDb.execute( "DELETE FROM charaglobalitem WHERE itemId = " + std::to_string( it->second->getUId() ) );
g_framework.getCharaDb().execute( "DELETE FROM charaglobalitem WHERE itemId = " + std::to_string( it->second->getUId() ) );
m_itemMap.erase( it );
g_log.debug( "Dropped item from slot " + std::to_string( slotId ) );
g_framework.getLogger().debug( "Dropped item from slot " + std::to_string( slotId ) );
}
else
{
g_log.debug( "Item could not be dropped from slot " + std::to_string( slotId ) );
g_framework.getLogger().debug( "Item could not be dropped from slot " + std::to_string( slotId ) );
}
}
@ -79,7 +78,7 @@ Core::ItemPtr Core::ItemContainer::getItem( uint8_t slotId )
if( ( slotId > m_size ) || ( slotId == -1 ) )
{
g_log.error( "Slot out of range " + std::to_string( slotId ) );
g_framework.getLogger().error( "Slot out of range " + std::to_string( slotId ) );
return nullptr;
}

View file

@ -1,11 +1,13 @@
#include "LinkshellMgr.h"
#include <boost/make_shared.hpp>
#include <common/Logging/Logger.h>
#include <common/Database/DatabaseDef.h>
#include "Linkshell.h"
#include "Framework.h"
#include "LinkshellMgr.h"
extern Core::Logger g_log;
extern Core::Framework g_framework;
Core::LinkshellMgr::LinkshellMgr()
{
@ -15,7 +17,7 @@ Core::LinkshellMgr::LinkshellMgr()
bool Core::LinkshellMgr::loadLinkshells()
{
auto res = g_charaDb.query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
auto res = g_framework.getCharaDb().query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, "
"LinkshellName, LeaderIdList, InviteIdList "
"FROM infolinkshell "
"ORDER BY LinkshellId ASC;" );

View file

@ -2,16 +2,19 @@
#include <common/Exd/ExdDataGenerated.h>
#include <common/Common.h>
#include "Actor/Chara.h"
#include "Actor/Player.h"
#include "CalcBattle.h"
#include "Actor/Chara.h"
#include "Actor/Player.h"
#include "CalcBattle.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Math;
using namespace Core::Entity;
extern Core::Data::ExdDataGenerated g_exdDataGen;
/*
Class used for battle-related formulas and calculations.
Big thanks to the Theoryjerks group!
@ -30,10 +33,10 @@ extern Core::Data::ExdDataGenerated g_exdDataGen;
uint32_t CalcBattle::calculateHealValue( PlayerPtr pPlayer, uint32_t potency )
{
auto classInfo = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( pPlayer->getClass() ) );
auto paramGrowthInfo = g_exdDataGen.get< Core::Data::ParamGrow >( pPlayer->getLevel() );
auto classInfo = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( pPlayer->getClass() ) );
auto paramGrowthInfo = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( pPlayer->getLevel() );
if ( !classInfo || !paramGrowthInfo )
if( !classInfo || !paramGrowthInfo )
return 0;
//auto jobModVal = classInfoIt->second;

View file

@ -2,16 +2,18 @@
#include <common/Exd/ExdDataGenerated.h>
#include <common/Common.h>
#include "Actor/Chara.h"
#include "Actor/Player.h"
#include "CalcStats.h"
#include "Framework.h"
using namespace Core::Math;
using namespace Core::Entity;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
/*
Class used for battle-related formulas and calculations.
@ -38,7 +40,7 @@ float CalcStats::calculateBaseStat( PlayerPtr pPlayer )
uint8_t level = pPlayer->getLevel();
// SB Base Stat Formula (Aligned)
if ( level > 60 )
if( level > 60 )
{
base = static_cast< float >( ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8) );
}
@ -61,10 +63,10 @@ uint32_t CalcStats::calculateMaxHp( PlayerPtr pPlayer )
// Is there any way to pull reliable BaseHP without having to manually use a pet for every level, and using the values from a table?
// More info here: https://docs.google.com/spreadsheets/d/1de06KGT0cNRUvyiXNmjNgcNvzBCCQku7jte5QxEQRbs/edit?usp=sharing
auto classInfo = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( pPlayer->getClass() ) );
auto paramGrowthInfo = g_exdDataGen.get< Core::Data::ParamGrow >( pPlayer->getLevel() );
auto classInfo = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( pPlayer->getClass() ) );
auto paramGrowthInfo = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( pPlayer->getLevel() );
if ( !classInfo || !paramGrowthInfo )
if( !classInfo || !paramGrowthInfo )
return 0;
uint8_t level = pPlayer->getLevel();
@ -94,10 +96,10 @@ uint32_t CalcStats::calculateMaxHp( PlayerPtr pPlayer )
uint32_t CalcStats::calculateMaxMp( PlayerPtr pPlayer )
{
auto classInfo = g_exdDataGen.get< Core::Data::ClassJob >( static_cast< uint8_t >( pPlayer->getClass() ) );
auto paramGrowthInfo = g_exdDataGen.get< Core::Data::ParamGrow >( pPlayer->getLevel() );
auto classInfo = g_framework.getExdDataGen().get< Core::Data::ClassJob >( static_cast< uint8_t >( pPlayer->getClass() ) );
auto paramGrowthInfo = g_framework.getExdDataGen().get< Core::Data::ParamGrow >( pPlayer->getLevel() );
if ( !classInfo || !paramGrowthInfo )
if( !classInfo || !paramGrowthInfo )
return 0;
float baseStat = calculateBaseStat( pPlayer );

View file

@ -1,24 +1,27 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Network/CommonNetwork.h>
#include <common/Util/Util.h>
#include <common/Logging/Logger.h>
#include <common/Network/PacketContainer.h>
#include <common/Network/GamePacketParser.h>
#include <boost/format.hpp>
#include "Zone/Zone.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "DebugCommand/DebugCommandHandler.h"
#include "Actor/Player.h"
#include "GameConnection.h"
#include "ServerZone.h"
#include "Session.h"
#include "Zone/Zone.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "DebugCommand/DebugCommandHandler.h"
#include "Actor/Player.h"
#include "Framework.h"
#include "Forwards.h"
extern Core::DebugCommandHandler g_gameCommandMgr;
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -109,13 +112,13 @@ void Core::Network::GameConnection::OnAccept( const std::string & host, uint16_t
GameConnectionPtr connection( new GameConnection( m_hive, m_pAcceptor ) );
m_pAcceptor->Accept( connection );
g_log.info( "Connect from " + m_socket.remote_endpoint().address().to_string() );
g_framework.getLogger().info( "Connect from " + m_socket.remote_endpoint().address().to_string() );
}
void Core::Network::GameConnection::OnDisconnect()
{
g_log.debug( "GameConnection DISCONNECT" );
g_framework.getLogger().debug( "GameConnection DISCONNECT" );
m_pSession = nullptr;
}
@ -128,14 +131,14 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer )
if( headerResult == Incomplete )
{
g_log.info( "Dropping connection due to incomplete packet header." );
g_log.info( "FIXME: Packet message bounary is not implemented." );
g_framework.getLogger().info( "Dropping connection due to incomplete packet header." );
g_framework.getLogger().info( "FIXME: Packet message bounary is not implemented." );
Disconnect();
return;
}
else if( headerResult == Malformed )
{
g_log.info( "Dropping connection due to malformed packet header." );
g_framework.getLogger().info( "Dropping connection due to malformed packet header." );
Disconnect();
return;
}
@ -147,14 +150,14 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer )
if( packetResult == Incomplete )
{
g_log.info( "Dropping connection due to incomplete packets." );
g_log.info( "FIXME: Packet message bounary is not implemented." );
g_framework.getLogger().info( "Dropping connection due to incomplete packets." );
g_framework.getLogger().info( "FIXME: Packet message bounary is not implemented." );
Disconnect();
return;
}
else if( packetResult == Malformed )
{
g_log.info( "Dropping connection due to malformed packets." );
g_framework.getLogger().info( "Dropping connection due to malformed packets." );
Disconnect();
return;
}
@ -165,7 +168,7 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer )
void Core::Network::GameConnection::OnError( const boost::system::error_code & error )
{
g_log.debug( "GameConnection ERROR: " + error.message() );
g_framework.getLogger().debug( "GameConnection ERROR: " + error.message() );
}
void Core::Network::GameConnection::queueInPacket( Core::Network::Packets::GamePacketPtr inPacket )
@ -192,7 +195,7 @@ void Core::Network::GameConnection::handleZonePacket( const Packets::GamePacket&
if( pPacket.getSubType() != PingHandler &&
pPacket.getSubType() != UpdatePositionHandler )
g_log.debug( sessionStr + " Handling Zone IPC : " + name + "( " +
g_framework.getLogger().debug( sessionStr + " Handling Zone IPC : " + name + "( " +
boost::str( boost::format( "%|04X|" ) %
static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" );
@ -200,10 +203,10 @@ void Core::Network::GameConnection::handleZonePacket( const Packets::GamePacket&
}
else
{
g_log.debug( sessionStr + " Undefined Zone IPC : Unknown ( " +
g_framework.getLogger().debug( sessionStr + " Undefined Zone IPC : Unknown ( " +
boost::str( boost::format( "%|04X|" ) %
static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" );
g_log.debug( "\n" + pPacket.toString() );
g_framework.getLogger().debug( "\n" + pPacket.toString() );
}
}
@ -220,7 +223,7 @@ void Core::Network::GameConnection::handleChatPacket( const Packets::GamePacket&
std::string name = itStr != m_chatHandlerStrMap.end() ? itStr->second : "unknown";
// dont display packet notification if it is a ping or pos update, don't want the spam
g_log.debug( sessionStr + " Handling Chat IPC : " + name + "( " +
g_framework.getLogger().debug( sessionStr + " Handling Chat IPC : " + name + "( " +
boost::str( boost::format( "%|04X|" ) %
static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" );
@ -228,10 +231,10 @@ void Core::Network::GameConnection::handleChatPacket( const Packets::GamePacket&
}
else
{
g_log.debug( sessionStr + " Undefined Chat IPC : Unknown ( " +
g_framework.getLogger().debug( sessionStr + " Undefined Chat IPC : Unknown ( " +
boost::str( boost::format( "%|04X|" ) %
static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" );
g_log.debug( pPacket.toString() );
g_framework.getLogger().debug( pPacket.toString() );
}
}
@ -287,7 +290,7 @@ void Core::Network::GameConnection::processOutQueue()
{
if( pPacket->getSize() == 0 )
{
g_log.debug( "end of packet set" );
g_framework.getLogger().debug( "end of packet set" );
break;
}
@ -374,23 +377,23 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
auto pCon = boost::static_pointer_cast< GameConnection, Connection >( shared_from_this() );
// try to retrieve the session for this id
auto session = g_serverZone.getSession( playerId );
auto session = g_framework.getServerZone().getSession( playerId );
if( !session )
{
g_log.info( "[" + std::string( id ) + "] Session not registered, creating" );
g_framework.getLogger().info( "[" + std::string( id ) + "] Session not registered, creating" );
// return;
if( !g_serverZone.createSession( playerId ) )
if( !g_framework.getServerZone().createSession( playerId ) )
{
Disconnect();
return;
}
session = g_serverZone.getSession( playerId );
session = g_framework.getServerZone().getSession( playerId );
}
//TODO: Catch more things in lobby and send real errors
else if( !session->isValid() || ( session->getPlayer() && session->getPlayer()->getLastPing() != 0 ) )
{
g_log.error( "[" + std::string(id) + "] Session INVALID, disconnecting" );
g_framework.getLogger().error( "[" + std::string(id) + "] Session INVALID, disconnecting" );
Disconnect();
return;
}
@ -411,7 +414,7 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
pPe = GamePacket( 0x00, 0x38, 0, 0, 0x02 );
pPe.setValAt< uint32_t >( 0x10, playerId );
sendSinglePacket( &pPe );
g_log.info( "[" + std::string( id ) + "] Setting session for zone connection" );
g_framework.getLogger().info( "[" + std::string( id ) + "] Setting session for zone connection" );
session->setZoneConnection( pCon );
}
// chat connection, assinging it to the session
@ -421,7 +424,7 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
pPe.setValAt< uint32_t >( 0x10, playerId );
sendSinglePacket( &pPe );
g_log.info( "[" + std::string( id ) + "] Setting session for chat connection" );
g_framework.getLogger().info( "[" + std::string( id ) + "] Setting session for chat connection" );
session->setChatConnection( pCon );
pPe = GamePacket( 0x02, 0x28, playerId, playerId, 0x03 );
sendSinglePacket( &pPe );

View file

@ -1,3 +1,5 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Network/CommonNetwork.h>
#include <common/Network/GamePacketNew.h>
@ -5,15 +7,10 @@
#include <common/Exd/ExdDataGenerated.h>
#include <common/Network/PacketContainer.h>
#include <boost/format.hpp>
#include "Network/GameConnection.h"
#include "Session.h"
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
#include "ServerZone.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "Network/PacketWrappers/PingPacket.h"
#include "Network/PacketWrappers/MoveActorPacket.h"
@ -27,17 +24,22 @@
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
#include "DebugCommand/DebugCommandHandler.h"
#include "Actor/Player.h"
#include "Inventory/Inventory.h"
#include "Forwards.h"
#include "Event/EventHelper.h"
#include "Action/Action.h"
#include "Action/ActionTeleport.h"
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::DebugCommandHandler g_gameCommandMgr;
#include "Session.h"
#include "ServerZone.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -112,7 +114,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
uint32_t param2 = inPacket.getValAt< uint32_t >( 0x2C );
uint64_t param3 = inPacket.getValAt< uint64_t >( 0x38 );
g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Incoming action: " +
g_framework.getLogger().debug( "[" + std::to_string( m_pSession->getId() ) + "] Incoming action: " +
boost::str( boost::format( "%|04X|" ) % ( uint32_t ) ( commandId & 0xFFFF ) ) +
"\nparam1: " + boost::str( boost::format( "%|016X|" ) % ( uint64_t ) ( param1 & 0xFFFFFFFFFFFFFFF ) ) +
"\nparam2: " + boost::str( boost::format( "%|08X|" ) % ( uint32_t ) ( param2 & 0xFFFFFFFF ) ) +
@ -244,6 +246,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
case ClientTrigger::Teleport: // Teleport
{
player.teleportQuery( param11 );
break;
}
@ -268,7 +271,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
}
default:
{
g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Unhandled action: " +
g_framework.getLogger().debug( "[" + std::to_string( m_pSession->getId() ) + "] Unhandled action: " +
boost::str( boost::format( "%|04X|" ) % (uint32_t) ( commandId & 0xFFFF ) ) );
break;
}

View file

@ -3,24 +3,26 @@
#include <common/Network/GamePacketNew.h>
#include <common/Logging/Logger.h>
#include <common/Network/PacketContainer.h>
#include <common/Exd/ExdDataGenerated.h>
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "Network/GameConnection.h"
#include "Session.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/ActorControlPacket144.h"
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
#include "Actor/Player.h"
#include "Forwards.h"
#include <common/Exd/ExdDataGenerated.h>
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "Framework.h"
#include "Session.h"
extern Core::Logger g_log;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -70,11 +72,11 @@ void Core::Network::GameConnection::cfRegisterDuty( const Packets::GamePacket& i
cfCancelPacket.data().state2 = 1; // Your registration is withdrawn.
queueOutPacket( cfCancelPacket );
auto cfCondition = g_exdDataGen.get< Core::Data::ContentFinderCondition >( contentId1 );
auto cfCondition = g_framework.getExdDataGen().get< Core::Data::ContentFinderCondition >( contentId1 );
if( !cfCondition )
return;
auto instance = g_territoryMgr.createInstanceContent( cfCondition->instanceContent );
auto instance = g_framework.getTerritoryMgr().createInstanceContent( cfCondition->instanceContent );
if( !instance )
return;

View file

@ -1,3 +1,5 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Exd/ExdDataGenerated.h>
#include <common/Network/CommonNetwork.h>
@ -5,10 +7,7 @@
#include <common/Network/PacketContainer.h>
#include <common/Network/PacketDef/Zone/ServerZoneDef.h>
#include <boost/format.hpp>
#include "Network/GameConnection.h"
#include "Session.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
@ -16,14 +15,20 @@
#include "Network/PacketWrappers/EventStartPacket.h"
#include "Network/PacketWrappers/EventFinishPacket.h"
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
#include "Actor/Player.h"
#include "Forwards.h"
#include "Event/EventHelper.h"
#include "Zone/InstanceContent.h"
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Scripting::ScriptManager g_scriptMgr;
#include "Session.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -55,11 +60,11 @@ void Core::Network::GameConnection::eventHandlerTalk( const Packets::GamePacket&
{
instance->onTalk( player, eventId, actorId );
}
else if( !g_scriptMgr.onTalk( player, actorId, eventId ) &&
eventType == Event::EventHandler::EventHandlerType::Quest )
else if( !g_framework.getScriptMgr().onTalk( player, actorId, eventId ) &&
eventType == Event::EventHandler::EventHandlerType::Quest )
{
auto questInfo = g_exdDataGen.get< Core::Data::Quest >( eventId );
if ( questInfo )
auto questInfo = g_framework.getExdDataGen().get< Core::Data::Quest >( eventId );
if( questInfo )
player.sendUrgent( "Quest not implemented: " + questInfo->name + " (" + questInfo->id + ")" );
}
@ -90,10 +95,10 @@ void Core::Network::GameConnection::eventHandlerEmote( const Packets::GamePacket
player.eventStart( actorId, eventId, Event::EventHandler::Emote, 0, emoteId );
if( !g_scriptMgr.onEmote( player, actorId, eventId, static_cast< uint8_t >( emoteId ) ) &&
if( !g_framework.getScriptMgr().onEmote( player, actorId, eventId, static_cast< uint8_t >( emoteId ) ) &&
eventType == Event::EventHandler::EventHandlerType::Quest )
{
auto questInfo = g_exdDataGen.get< Core::Data::Quest >( eventId );
auto questInfo = g_framework.getExdDataGen().get< Core::Data::Quest >( eventId );
if( questInfo )
player.sendUrgent( "Quest not implemented: " + questInfo->name );
}
@ -118,7 +123,7 @@ void Core::Network::GameConnection::eventHandlerWithinRange( const Packets::Game
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
g_scriptMgr.onWithinRange( player, eventId, param1, x, y, z );
g_framework.getScriptMgr().onWithinRange( player, eventId, param1, x, y, z );
player.checkEvent( eventId );
}
@ -140,7 +145,7 @@ void Core::Network::GameConnection::eventHandlerOutsideRange( const Packets::Gam
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
g_scriptMgr.onOutsideRange( player, eventId, param1, x, y, z );
g_framework.getScriptMgr().onOutsideRange( player, eventId, param1, x, y, z );
player.checkEvent( eventId );
}
@ -165,14 +170,14 @@ void Core::Network::GameConnection::eventHandlerEnterTerritory( const Packets::G
// param2 of eventStart
// 0 = default state?
// 1 = restore state?
// (^ Mordred: Nope, i don't think thats it )
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId(), instance->getDirectorId() & 0xFFFF );
instance->onEnterTerritory( player, eventId, param1, param2 );
}
else
{
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId() );
g_scriptMgr.onEnterTerritory( player, eventId, param1, param2 );
g_framework.getScriptMgr().onEnterTerritory( player, eventId, param1, param2 );
}
player.checkEvent( eventId );

View file

@ -1,3 +1,5 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Network/CommonNetwork.h>
#include <common/Network/GamePacketNew.h>
@ -10,11 +12,12 @@
#include "Network/GameConnection.h"
#include "Session.h"
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
#include "ServerZone.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/InitUIPacket.h"
#include "Network/PacketWrappers/PingPacket.h"
#include "Network/PacketWrappers/MoveActorPacket.h"
@ -28,17 +31,22 @@
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
#include "DebugCommand/DebugCommandHandler.h"
#include "Actor/Player.h"
#include "Inventory/Inventory.h"
#include "Forwards.h"
#include "Event/EventHelper.h"
#include "Action/Action.h"
#include "Action/ActionTeleport.h"
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::DebugCommandHandler g_gameCommandMgr;
#include "Session.h"
#include "ServerZone.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -101,7 +109,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
uint32_t param2 = inPacket.getValAt< uint32_t >( 0x28 );
uint32_t param3 = inPacket.getValAt< uint32_t >( 0x38 );
g_log.debug( player.getName() + " used GM1 commandId: " + std::to_string( commandId ) +
g_framework.getLogger().debug( player.getName() + " used GM1 commandId: " + std::to_string( commandId ) +
", params: " + std::to_string( param1 ) + ", " +
std::to_string( param2 ) + ", " + std::to_string( param3 ) );
@ -401,19 +409,19 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
}
case GmCommand::Teri:
{
if( auto instance = g_territoryMgr.getInstanceZonePtr( param1 ) )
if( auto instance = g_framework.getTerritoryMgr().getInstanceZonePtr( param1 ) )
{
player.sendDebug( "Found instance: " + instance->getName() + ", id: " + std::to_string( param1 ) );
player.setInstance( instance );
}
else if( !g_territoryMgr.isValidTerritory( param1 ) )
else if( !g_framework.getTerritoryMgr().isValidTerritory( param1 ) )
{
player.sendUrgent( "Invalid zone " + std::to_string( param1 ) );
}
else
{
auto pZone = g_territoryMgr.getZoneByTerriId( param1 );
auto pZone = g_framework.getTerritoryMgr().getZoneByTerriId( param1 );
if( !pZone )
{
player.sendUrgent( "No zone instance found for " + std::to_string( param1 ) );
@ -463,9 +471,9 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac
uint32_t commandId = inPacket.getValAt< uint32_t >( 0x20 );
std::string param1 = inPacket.getStringAt( 0x34 );
g_log.debug( player.getName() + " used GM2 commandId: " + std::to_string( commandId ) + ", params: " + param1 );
g_framework.getLogger().debug( player.getName() + " used GM2 commandId: " + std::to_string( commandId ) + ", params: " + param1 );
auto targetSession = g_serverZone.getSession( param1 );
auto targetSession = g_framework.getServerZone().getSession( param1 );
Core::Entity::CharaPtr targetActor;
if( targetSession != nullptr )

View file

@ -1,36 +1,43 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Network/CommonNetwork.h>
#include <common/Network/GamePacketNew.h>
#include <common/Logging/Logger.h>
#include <common/Network/PacketContainer.h>
#include <boost/format.hpp>
#include "Network/GameConnection.h"
#include "Session.h"
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
#include "ServerZone.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/ActorControlPacket144.h"
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
#include "DebugCommand/DebugCommandHandler.h"
#include "Actor/Player.h"
#include "Inventory/Inventory.h"
#include "Forwards.h"
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::DebugCommandHandler g_gameCommandMgr;
#include "Session.h"
#include "ServerZone.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
enum InventoryOperation
{
Discard = 0x07,
Move = 0x08,
Swap = 0x09,
Merge = 0x0C,
Split = 0x0A
};
void Core::Network::GameConnection::inventoryModifyHandler( const Packets::GamePacket& inPacket,
Entity::Player& player )
@ -48,38 +55,38 @@ void Core::Network::GameConnection::inventoryModifyHandler( const Packets::GameP
player.queuePacket( ackPacket );
g_log.debug( inPacket.toString() );
g_log.debug( "InventoryAction: " + std::to_string( action ) );
g_framework.getLogger().debug( inPacket.toString() );
g_framework.getLogger().debug( "InventoryAction: " + std::to_string( action ) );
// TODO: other inventory operations need to be implemented
switch( action )
{
case 0x07: // discard item action
case InventoryOperation::Discard: // discard item action
{
player.getInventory()->discardItem( fromContainer, fromSlot );
}
break;
case 0x08: // move item action
case InventoryOperation::Move: // move item action
{
player.getInventory()->moveItem( fromContainer, fromSlot, toContainer, toSlot );
}
break;
case 0x09: // swap item action
case InventoryOperation::Swap: // swap item action
{
player.getInventory()->swapItem( fromContainer, fromSlot, toContainer, toSlot );
}
break;
case 0x0C: // merge stack action
case InventoryOperation::Merge: // merge stack action
{
}
break;
case 0x0A: // split stack action
case InventoryOperation::Split: // split stack action
{
}

View file

@ -1,3 +1,5 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Network/CommonNetwork.h>
#include <common/Network/GamePacketNew.h>
@ -5,14 +7,10 @@
#include <common/Network/PacketContainer.h>
#include <common/Network/PacketDef/Chat/ServerChatDef.h>
#include <common/Database/DatabaseDef.h>
#include <boost/format.hpp>
#include <unordered_map>
#include "Network/GameConnection.h"
#include "Session.h"
#include "ServerZone.h"
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
@ -30,18 +28,22 @@
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
#include "DebugCommand/DebugCommandHandler.h"
#include "Actor/Player.h"
#include "Inventory/Inventory.h"
#include "Forwards.h"
#include "Event/EventHelper.h"
#include "Action/Action.h"
#include "Action/ActionTeleport.h"
#include "Session.h"
#include "ServerZone.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::TerritoryMgr g_territoryMgr;
extern Core::DebugCommandHandler g_gameCommandMgr;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -283,7 +285,7 @@ void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePa
void Core::Network::GameConnection::reqEquipDisplayFlagsHandler( const Packets::GamePacket& inPacket,
Entity::Player& player )
{
g_log.info( "[" + std::to_string( player.getId() ) + "] Setting EquipDisplayFlags to " + std::to_string( inPacket.getValAt< uint8_t >( 0x20 ) ) );
g_framework.getLogger().info( "[" + std::to_string( player.getId() ) + "] Setting EquipDisplayFlags to " + std::to_string( inPacket.getValAt< uint8_t >( 0x20 ) ) );
player.setEquipDisplayFlags( inPacket.getValAt< uint8_t >( 0x20 ) );
}
@ -296,7 +298,7 @@ void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket&
auto pZone = player.getCurrentZone();
auto pLine = g_territoryMgr.getTerritoryPosition( zoneLineId );
auto pLine = g_framework.getTerritoryMgr().getTerritoryPosition( zoneLineId );
Common::FFXIVARR_POSITION3 targetPos{};
uint32_t targetZone;
@ -335,7 +337,7 @@ void Core::Network::GameConnection::discoveryHandler( const Packets::GamePacket&
{
uint32_t ref_position_id = inPacket.getValAt< uint32_t >( 0x20 );
auto pQR = g_charaDb.query( "SELECT id, map_id, discover_id "
auto pQR = g_framework.getCharaDb().query( "SELECT id, map_id, discover_id "
"FROM discoveryinfo "
"WHERE id = " + std::to_string( ref_position_id ) + ";" );
@ -494,7 +496,7 @@ void Core::Network::GameConnection::chatHandler( const Packets::GamePacket& inPa
if( chatString.at( 0 ) == '!' )
{
// execute game console command
g_gameCommandMgr.execCommand( const_cast< char * >( chatString.c_str() ) + 1, player );
g_framework.getDebugCommandHandler().execCommand( const_cast< char * >( chatString.c_str() ) + 1, player );
return;
}
@ -551,7 +553,7 @@ void Core::Network::GameConnection::tellHandler( const Packets::GamePacket& inPa
std::string targetPcName = inPacket.getStringAt( 0x21 );
std::string msg = inPacket.getStringAt( 0x41 );
auto pSession = g_serverZone.getSession( targetPcName );
auto pSession = g_framework.getServerZone().getSession( targetPcName );
if( !pSession )
{
@ -559,7 +561,7 @@ void Core::Network::GameConnection::tellHandler( const Packets::GamePacket& inPa
strcpy( tellErrPacket.data().receipientName, targetPcName.c_str() );
sendSinglePacket( tellErrPacket );
g_log.debug( "TargetPc not found" );
g_framework.getLogger().debug( "TargetPc not found" );
return;
}

View file

@ -1,3 +1,5 @@
#include <boost/format.hpp>
#include <common/Common.h>
#include <common/Network/CommonNetwork.h>
#include <common/Exd/ExdDataGenerated.h>
@ -5,12 +7,7 @@
#include <common/Network/PacketContainer.h>
#include <common/Logging/Logger.h>
#include <boost/format.hpp>
#include "Network/GameConnection.h"
#include "Session.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
@ -23,17 +20,17 @@
#include "Actor/Player.h"
#include "Forwards.h"
#include "Action/Action.h"
#include "Action/ActionCast.h"
#include "Action/ActionMount.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Logger g_log;
#include "Session.h"
#include "Forwards.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -60,7 +57,7 @@ void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inP
std::string actionIdStr = boost::str( boost::format( "%|04X|" ) % action );
player.sendDebug( "---------------------------------------" );
player.sendDebug( "ActionHandler ( " + actionIdStr + " | " +
g_exdDataGen.get< Core::Data::Action >( action )->name +
g_framework.getExdDataGen().get< Core::Data::Action >( action )->name +
" | " + std::to_string( targetId ) + " )" );
player.queuePacket( ActorControlPacket142( player.getId(), ActorControlType::ActionStart, 0x01, action ) );
@ -83,7 +80,7 @@ void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inP
if( !player.actionHasCastTime( action ) )
{
g_scriptMgr.onCastFinish( player, targetActor->getAsChara(), action );
g_framework.getScriptMgr().onCastFinish( player, targetActor->getAsChara(), action );
}
else
{
@ -100,11 +97,11 @@ void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inP
}
else if( action < 3000000 ) // item action
{
auto info = g_exdDataGen.get< Core::Data::EventItem >( action );
auto info = g_framework.getExdDataGen().get< Core::Data::EventItem >( action );
if( info )
{
g_log.debug( info->name );
g_scriptMgr.onEventItem( player, action, info->quest, info->castTime, targetId );
g_framework.getLogger().debug( info->name );
g_framework.getScriptMgr().onEventItem( player, action, info->quest, info->castTime, targetId );
}
}
else if( action > 3000000 ) // unknown

View file

@ -1,4 +1,4 @@
#include "NativeScriptManager.h"
#include "NativeScriptMgr.h"
#include <boost/filesystem.hpp>
#include <common/Crypt/md5.h>
@ -6,7 +6,7 @@
namespace Core {
namespace Scripting {
bool NativeScriptManager::loadScript( const std::string& path )
bool NativeScriptMgr::loadScript( const std::string& path )
{
auto module = m_loader.loadModule( path );
if( !module )
@ -44,12 +44,12 @@ namespace Scripting {
return true;
}
const std::string NativeScriptManager::getModuleExtension()
const std::string NativeScriptMgr::getModuleExtension()
{
return m_loader.getModuleExtension();
}
bool NativeScriptManager::unloadScript( const std::string& name )
bool NativeScriptMgr::unloadScript( const std::string& name )
{
auto info = m_loader.getScriptInfo( name );
if( !info )
@ -58,7 +58,7 @@ namespace Scripting {
return unloadScript( info );
}
bool NativeScriptManager::unloadScript( ScriptInfo* info )
bool NativeScriptMgr::unloadScript( ScriptInfo* info )
{
for( auto& script : info->scripts )
{
@ -70,7 +70,7 @@ namespace Scripting {
return m_loader.unloadScript( info );
}
void NativeScriptManager::queueScriptReload( const std::string &name )
void NativeScriptMgr::queueScriptReload( const std::string &name )
{
auto info = m_loader.getScriptInfo( name );
if( !info )
@ -85,7 +85,7 @@ namespace Scripting {
m_scriptLoadQueue.push( libPath );
}
void NativeScriptManager::processLoadQueue()
void NativeScriptMgr::processLoadQueue()
{
std::vector< std::string > deferredLoads;
@ -107,21 +107,21 @@ namespace Scripting {
}
}
void NativeScriptManager::findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search )
void NativeScriptMgr::findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search )
{
return m_loader.findScripts( scripts, search );
}
bool NativeScriptManager::isModuleLoaded( const std::string &name )
bool NativeScriptMgr::isModuleLoaded( const std::string &name )
{
return m_loader.isModuleLoaded( name );
}
boost::shared_ptr< NativeScriptManager > createNativeScriptMgr()
boost::shared_ptr< NativeScriptMgr > createNativeScriptMgr()
{
return boost::make_shared< NativeScriptManager >();
return boost::make_shared< NativeScriptMgr >();
}
}
}

View file

@ -13,7 +13,7 @@
namespace Core {
namespace Scripting {
class NativeScriptManager
class NativeScriptMgr
{
protected:
std::unordered_map< std::size_t, std::unordered_map< uint32_t, ScriptObject* > > m_scripts;
@ -25,7 +25,7 @@ namespace Scripting {
bool unloadScript( ScriptInfo* info );
public:
NativeScriptManager( ) = default;
NativeScriptMgr( ) = default;
bool loadScript( const std::string& path );
bool unloadScript( const std::string& name );
@ -52,7 +52,7 @@ namespace Scripting {
boost::shared_ptr< NativeScriptManager > createNativeScriptMgr();
boost::shared_ptr< NativeScriptMgr > createNativeScriptMgr();
} }

View file

@ -1,11 +1,12 @@
#ifndef SAPPHIRE_SCRIPTINFO_H
#define SAPPHIRE_SCRIPTINFO_H
#ifndef CORE_SCRIPTINFO_H
#define CORE_SCRIPTINFO_H
#include <vector>
#include "NativeScriptApi.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef HMODULE ModuleHandle;
#else

View file

@ -2,14 +2,13 @@
#include <common/Logging/Logger.h>
#include <common/Config/XMLConfig.h>
#include "ServerZone.h"
#include "Framework.h"
#include <boost/format.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::Framework g_framework;
namespace fs = boost::filesystem;
@ -37,12 +36,12 @@ bool Core::Scripting::ScriptLoader::unloadModule( ModuleHandle handle )
if( !success )
{
g_log.error( "Failed to unload module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );
g_framework.getLogger().error( "Failed to unload module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );
return false;
}
g_log.debug( "Unloaded module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );
g_framework.getLogger().debug( "Unloaded module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );
return true;
}
@ -51,14 +50,14 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
{
fs::path f( path );
if ( isModuleLoaded( f.stem().string() ) )
if( isModuleLoaded( f.stem().string() ) )
{
g_log.error( "Unable to load module '" + f.stem().string() + "' as it is already loaded" );
g_framework.getLogger().error( "Unable to load module '" + f.stem().string() + "' as it is already loaded" );
return nullptr;
}
// copy to temp dir
fs::path cacheDir( f.parent_path() /= g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) );
fs::path cacheDir( f.parent_path() /= g_framework.getServerZone().getConfig()->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) );
fs::create_directories( cacheDir );
fs::path dest( cacheDir /= f.filename().string() );
@ -68,7 +67,7 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
}
catch( const boost::filesystem::filesystem_error& err )
{
g_log.error( "Error copying file to cache: " + err.code().message() );
g_framework.getLogger().error( "Error copying file to cache: " + err.code().message() );
return nullptr;
}
@ -82,12 +81,12 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
if( !handle )
{
g_log.error( "Failed to load module from: " + path );
g_framework.getLogger().error( "Failed to load module from: " + path );
return nullptr;
}
g_log.debug( "Loaded module '" + f.filename().string() + "' @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );
g_framework.getLogger().debug( "Loaded module '" + f.filename().string() + "' @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );
auto info = new ScriptInfo;
info->handle = handle;
@ -102,7 +101,7 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
ScriptObject** Core::Scripting::ScriptLoader::getScripts( ModuleHandle handle )
{
using getScripts = ScriptObject**(*)();
using getScripts = ScriptObject**( *)( );
#ifdef _WIN32
getScripts func = reinterpret_cast< getScripts >( GetProcAddress( handle, "getScripts" ) );
@ -114,7 +113,7 @@ ScriptObject** Core::Scripting::ScriptLoader::getScripts( ModuleHandle handle )
{
auto ptr = func();
g_log.debug( "got ScriptObject array @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) );
g_framework.getLogger().debug( "got ScriptObject array @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) );
return ptr;
}
@ -147,7 +146,7 @@ bool Core::Scripting::ScriptLoader::unloadScript( ModuleHandle handle )
return true;
}
g_log.error( "failed to unload module: " + info->library_name );
g_framework.getLogger().error( "failed to unload module: " + info->library_name );
return false;
}

View file

@ -1,5 +1,5 @@
#ifndef SAPPHIRE_SCRIPTLOADER_H
#define SAPPHIRE_SCRIPTLOADER_H
#ifndef CORE_SCRIPTLOADER_H
#define CORE_SCRIPTLOADER_H
#include <string>
#include <unordered_map>
@ -10,6 +10,7 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <winbase.h>
typedef HMODULE ModuleHandle;
#else
@ -52,4 +53,4 @@ namespace Scripting {
#endif //SAPPHIRE_SCRIPTLOADER_H
#endif // CORE_SCRIPTLOADER_H

View file

@ -1,56 +1,58 @@
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <common/Logging/Logger.h>
#include <common/Exd/ExdDataGenerated.h>
#include <common/Config/XMLConfig.h>
#include "NativeScriptManager.h"
#include "Zone/Zone.h"
#include "Zone/InstanceContent.h"
#include "Actor/Player.h"
#include "ServerZone.h"
#include "Event/EventHandler.h"
#include "Event/EventHelper.h"
#include "StatusEffect/StatusEffect.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Script/ScriptManager.h"
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include "Script/ScriptMgr.h"
#include "NativeScriptMgr.h"
#include "ServerZone.h"
#include "Framework.h"
// enable the ambiguity fix for every platform to avoid #define nonsense
#define WIN_AMBIGUITY_FIX
#include <libraries/external/watchdog/Watchdog.h>
extern Core::Logger g_log;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::ServerZone g_serverZone;
extern Core::Framework g_framework;
Core::Scripting::ScriptManager::ScriptManager() :
Core::Scripting::ScriptMgr::ScriptMgr() :
m_firstScriptChangeNotificiation( false )
{
m_nativeScriptManager = createNativeScriptMgr();
m_nativeScriptMgr = createNativeScriptMgr();
}
Core::Scripting::ScriptManager::~ScriptManager()
Core::Scripting::ScriptMgr::~ScriptMgr()
{
Watchdog::unwatchAll();
}
void Core::Scripting::ScriptManager::update()
void Core::Scripting::ScriptMgr::update()
{
m_nativeScriptManager->processLoadQueue();
m_nativeScriptMgr->processLoadQueue();
}
bool Core::Scripting::ScriptManager::init()
bool Core::Scripting::ScriptMgr::init()
{
std::set< std::string > files;
loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ),
files, m_nativeScriptManager->getModuleExtension() );
loadDir( g_framework.getServerZone().getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ),
files, m_nativeScriptMgr->getModuleExtension() );
uint32_t scriptsFound = 0;
uint32_t scriptsLoaded = 0;
@ -61,24 +63,24 @@ bool Core::Scripting::ScriptManager::init()
scriptsFound++;
if( m_nativeScriptManager->loadScript( path ) )
if( m_nativeScriptMgr->loadScript( path ) )
scriptsLoaded++;
}
g_log.info( "ScriptManager: Loaded " + std::to_string( scriptsLoaded ) + "/" + std::to_string( scriptsFound ) + " scripts successfully" );
g_framework.getLogger().info( "ScriptMgr: Loaded " + std::to_string( scriptsLoaded ) + "/" + std::to_string( scriptsFound ) + " scripts successfully" );
watchDirectories();
return true;
}
void Core::Scripting::ScriptManager::watchDirectories()
void Core::Scripting::ScriptMgr::watchDirectories()
{
auto shouldWatch = g_serverZone.getConfig()->getValue< bool >( "Settings.General.Scripts.HotSwap.Enabled", true );
auto shouldWatch = g_framework.getServerZone().getConfig()->getValue< bool >( "Settings.General.Scripts.HotSwap.Enabled", true );
if( !shouldWatch )
return;
Watchdog::watchMany( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ) + "*" + m_nativeScriptManager->getModuleExtension(),
Watchdog::watchMany( g_framework.getServerZone().getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ) + "*" + m_nativeScriptMgr->getModuleExtension(),
[ this ]( const std::vector< ci::fs::path >& paths )
{
if( !m_firstScriptChangeNotificiation )
@ -91,26 +93,26 @@ void Core::Scripting::ScriptManager::watchDirectories()
for( auto path : paths )
{
if( m_nativeScriptManager->isModuleLoaded( path.stem().string() ) )
if( m_nativeScriptMgr->isModuleLoaded( path.stem().string() ) )
{
g_log.debug( "Reloading changed script: " + path.stem().string() );
g_framework.getLogger().debug( "Reloading changed script: " + path.stem().string() );
m_nativeScriptManager->queueScriptReload( path.stem( ).string( ));
m_nativeScriptMgr->queueScriptReload( path.stem( ).string( ));
}
else
{
g_log.debug( "Loading new script: " + path.stem().string() );
g_framework.getLogger().debug( "Loading new script: " + path.stem().string() );
m_nativeScriptManager->loadScript( path.string() );
m_nativeScriptMgr->loadScript( path.string() );
}
}
});
}
void Core::Scripting::ScriptManager::loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext )
void Core::Scripting::ScriptMgr::loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext )
{
g_log.info( "ScriptEngine: loading scripts from " + dirname );
g_framework.getLogger().info( "ScriptEngine: loading scripts from " + dirname );
boost::filesystem::path targetDir( dirname );
@ -126,7 +128,7 @@ void Core::Scripting::ScriptManager::loadDir( const std::string& dirname, std::s
}
}
void Core::Scripting::ScriptManager::onPlayerFirstEnterWorld( Entity::Player& player )
void Core::Scripting::ScriptMgr::onPlayerFirstEnterWorld( Entity::Player& player )
{
// try
// {
@ -139,7 +141,7 @@ void Core::Scripting::ScriptManager::onPlayerFirstEnterWorld( Entity::Player& pl
// }
}
bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId )
bool Core::Scripting::ScriptMgr::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId )
{
uint16_t eventType = eventId >> 16;
@ -148,60 +150,60 @@ bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t ac
// aethernet/aetherytes need to be handled separately
if( eventType == Event::EventHandler::EventHandlerType::Aetheryte )
{
auto aetherInfo = g_exdDataGen.get< Core::Data::Aetheryte >( eventId & 0xFFFF );
auto aetherInfo = g_framework.getExdDataGen().get< Core::Data::Aetheryte >( eventId & 0xFFFF );
scriptId = EVENTSCRIPT_AETHERYTE_ID;
if( !aetherInfo->isAetheryte )
scriptId = EVENTSCRIPT_AETHERNET_ID;
}
auto script = m_nativeScriptManager->getScript< EventScript >( scriptId );
auto script = m_nativeScriptMgr->getScript< EventScript >( scriptId );
if( !script )
return false;
script->onTalk( eventId, player, actorId );
return true;
}
bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId,
bool Core::Scripting::ScriptMgr::onEnterTerritory( Entity::Player& player, uint32_t eventId,
uint16_t param1, uint16_t param2 )
{
auto script = m_nativeScriptManager->getScript< EventScript >( eventId );
auto script = m_nativeScriptMgr->getScript< EventScript >( eventId );
if( !script )
return false;
script->onEnterTerritory( player, eventId, param1, param2 );
return true;
}
bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
bool Core::Scripting::ScriptMgr::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
float x, float y, float z )
{
auto script = m_nativeScriptManager->getScript< EventScript >( eventId );
auto script = m_nativeScriptMgr->getScript< EventScript >( eventId );
if( !script )
return false;
script->onWithinRange( player, eventId, param1, x, y, z );
return true;
}
bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
bool Core::Scripting::ScriptMgr::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
float x, float y, float z )
{
auto script = m_nativeScriptManager->getScript< EventScript >( eventId );
auto script = m_nativeScriptMgr->getScript< EventScript >( eventId );
if( !script )
return false;
script->onOutsideRange( player, eventId, param1, x, y, z );
return true;
}
bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId,
bool Core::Scripting::ScriptMgr::onEmote( Entity::Player& player, uint64_t actorId,
uint32_t eventId, uint8_t emoteId )
{
auto script = m_nativeScriptManager->getScript< EventScript >( eventId );
auto script = m_nativeScriptMgr->getScript< EventScript >( eventId );
if( !script )
return false;
script->onEmote( actorId, eventId, emoteId, player );
return true;
}
bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& player, uint32_t eventId,
bool Core::Scripting::ScriptMgr::onEventHandlerReturn( Entity::Player& player, uint32_t eventId,
uint16_t subEvent, uint16_t param1, uint16_t param2,
uint16_t param3 )
{
@ -209,10 +211,10 @@ bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& playe
return false;
}
bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId,
bool Core::Scripting::ScriptMgr::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId,
uint16_t subEvent, uint16_t param, uint32_t catalogId )
{
auto script = m_nativeScriptManager->getScript< EventScript >( eventId );
auto script = m_nativeScriptMgr->getScript< EventScript >( eventId );
if( script )
{
script->onEventHandlerTradeReturn( player, eventId, subEvent, param, catalogId );
@ -222,14 +224,14 @@ bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player&
return false;
}
bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId,
bool Core::Scripting::ScriptMgr::onEventItem( Entity::Player& player, uint32_t eventItemId,
uint32_t eventId, uint32_t castTime, uint64_t targetId )
{
std::string eventName = "onEventItem";
std::string objName = Event::getEventName( eventId );
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
auto script = m_nativeScriptManager->getScript< EventScript >( eventId );
auto script = m_nativeScriptMgr->getScript< EventScript >( eventId );
if( script )
{
player.eventStart( targetId, eventId, Event::EventHandler::Item, 0, 0 );
@ -241,7 +243,7 @@ bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32
return false;
}
bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t nameId )
bool Core::Scripting::ScriptMgr::onMobKill( Entity::Player& player, uint16_t nameId )
{
std::string eventName = "onBnpcKill_" + std::to_string( nameId );
@ -255,7 +257,7 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t
uint16_t questId = activeQuests->c.questId;
auto script = m_nativeScriptManager->getScript< EventScript >( questId );
auto script = m_nativeScriptMgr->getScript< EventScript >( questId );
if( script )
{
std::string objName = Event::getEventName( 0x00010000 | questId );
@ -269,18 +271,18 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t
return true;
}
bool Core::Scripting::ScriptManager::onCastFinish( Entity::Player& player, Entity::CharaPtr pTarget, uint32_t actionId )
bool Core::Scripting::ScriptMgr::onCastFinish( Entity::Player& player, Entity::CharaPtr pTarget, uint32_t actionId )
{
auto script = m_nativeScriptManager->getScript< ActionScript >( actionId );
auto script = m_nativeScriptMgr->getScript< ActionScript >( actionId );
if( script )
script->onCastFinish( player, *pTarget );
return true;
}
bool Core::Scripting::ScriptManager::onStatusReceive( Entity::CharaPtr pActor, uint32_t effectId )
bool Core::Scripting::ScriptMgr::onStatusReceive( Entity::CharaPtr pActor, uint32_t effectId )
{
auto script = m_nativeScriptManager->getScript< StatusEffectScript >( effectId );
auto script = m_nativeScriptMgr->getScript< StatusEffectScript >( effectId );
if( script )
{
@ -294,9 +296,9 @@ bool Core::Scripting::ScriptManager::onStatusReceive( Entity::CharaPtr pActor, u
return false;
}
bool Core::Scripting::ScriptManager::onStatusTick( Entity::CharaPtr pChara, Core::StatusEffect::StatusEffect& effect )
bool Core::Scripting::ScriptMgr::onStatusTick( Entity::CharaPtr pChara, Core::StatusEffect::StatusEffect& effect )
{
auto script = m_nativeScriptManager->getScript< StatusEffectScript >( effect.getId() );
auto script = m_nativeScriptMgr->getScript< StatusEffectScript >( effect.getId() );
if( script )
{
if( pChara->isPlayer() )
@ -309,9 +311,9 @@ bool Core::Scripting::ScriptManager::onStatusTick( Entity::CharaPtr pChara, Core
return false;
}
bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::CharaPtr pChara, uint32_t effectId )
bool Core::Scripting::ScriptMgr::onStatusTimeOut( Entity::CharaPtr pChara, uint32_t effectId )
{
auto script = m_nativeScriptManager->getScript< StatusEffectScript >( effectId );
auto script = m_nativeScriptMgr->getScript< StatusEffectScript >( effectId );
if( script )
{
if( pChara->isPlayer() )
@ -324,9 +326,9 @@ bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::CharaPtr pChara, u
return false;
}
bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone )
bool Core::Scripting::ScriptMgr::onZoneInit( ZonePtr pZone )
{
auto script = m_nativeScriptManager->getScript< ZoneScript >( pZone->getTerritoryId() );
auto script = m_nativeScriptMgr->getScript< ZoneScript >( pZone->getTerritoryId() );
if( script )
{
script->onZoneInit();
@ -336,9 +338,9 @@ bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone )
return false;
}
bool Core::Scripting::ScriptManager::onInstanceInit( InstanceContentPtr instance )
bool Core::Scripting::ScriptMgr::onInstanceInit( InstanceContentPtr instance )
{
auto script = m_nativeScriptManager->getScript< InstanceContentScript >( instance->getDirectorId() );
auto script = m_nativeScriptMgr->getScript< InstanceContentScript >( instance->getDirectorId() );
if( script )
{
script->onInit( instance );
@ -348,9 +350,10 @@ bool Core::Scripting::ScriptManager::onInstanceInit( InstanceContentPtr instance
return false;
}
bool Core::Scripting::ScriptManager::onInstanceUpdate( InstanceContentPtr instance, uint32_t currTime )
bool Core::Scripting::ScriptMgr::onInstanceUpdate( InstanceContentPtr instance, uint32_t currTime )
{
auto script = m_nativeScriptManager->getScript< InstanceContentScript >( instance->getDirectorId() );
auto script = m_nativeScriptMgr->getScript< InstanceContentScript >( instance->getDirectorId() );
if( script )
{
script->onUpdate( instance, currTime );
@ -360,9 +363,9 @@ bool Core::Scripting::ScriptManager::onInstanceUpdate( InstanceContentPtr instan
return false;
}
bool Core::Scripting::ScriptManager::onInstanceEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 )
bool Core::Scripting::ScriptMgr::onInstanceEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 )
{
auto script = m_nativeScriptManager->getScript< InstanceContentScript >( instance->getDirectorId() );
auto script = m_nativeScriptMgr->getScript< InstanceContentScript >( instance->getDirectorId() );
if( script )
{
script->onEnterTerritory( player, eventId, param1, param2 );
@ -372,7 +375,7 @@ bool Core::Scripting::ScriptManager::onInstanceEnterTerritory( InstanceContentPt
return false;
}
Scripting::NativeScriptManager& Core::Scripting::ScriptManager::getNativeScriptHandler()
Scripting::NativeScriptMgr& Core::Scripting::ScriptMgr::getNativeScriptHandler()
{
return *m_nativeScriptManager;
return *m_nativeScriptMgr;
}

View file

@ -1,5 +1,5 @@
#ifndef _SCRIPTMANAGER_H_
#define _SCRIPTMANAGER_H_
#ifndef _ScriptMgr_H_
#define _ScriptMgr_H_
#include <boost/shared_ptr.hpp>
#include <mutex>
@ -13,11 +13,11 @@ namespace Core
namespace Scripting
{
class ScriptManager
class ScriptMgr
{
private:
boost::shared_ptr< NativeScriptManager > m_nativeScriptManager;
boost::shared_ptr< NativeScriptMgr > m_nativeScriptMgr;
std::function< std::string( Entity::Player& ) > m_onFirstEnterWorld;
// auto fn = m_pChaiHandler->eval< std::function<const std::string( Entity::Player ) > >( "onFirstEnterWorld" );
@ -25,8 +25,8 @@ namespace Core
bool m_firstScriptChangeNotificiation;
public:
ScriptManager();
~ScriptManager();
ScriptMgr();
~ScriptMgr();
bool init();
void reload();
@ -63,7 +63,7 @@ namespace Core
void loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext );
NativeScriptManager& getNativeScriptHandler();
NativeScriptMgr& getNativeScriptHandler();
};
}
}

View file

@ -27,7 +27,7 @@
#include "DebugCommand/DebugCommandHandler.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
#include "Linkshell/LinkshellMgr.h"
#include "Forwards.h"
@ -37,13 +37,10 @@
#include <thread>
#include <common/Util/Util.h>
#include "Framework.h"
Core::Framework g_framework;
Core::Logger g_log;
Core::DebugCommandHandler g_gameCommandMgr;
Core::Scripting::ScriptManager g_scriptMgr;
Core::Data::ExdDataGenerated g_exdDataGen;
Core::TerritoryMgr g_territoryMgr;
Core::LinkshellMgr g_linkshellMgr;
Core::Db::DbWorkerPool< Core::Db::CharaDbConnection > g_charaDb;
Core::ServerZone::ServerZone( const std::string& configPath )
: m_configPath( configPath ),
@ -69,11 +66,11 @@ size_t Core::ServerZone::getSessionCount() const
bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
{
g_log.info( "Loading config " + m_configPath );
g_framework.getLogger().info( "Loading config " + m_configPath );
if( !m_pConfig->loadConfig( m_configPath ) )
{
g_log.fatal( "Error loading config " + m_configPath );
g_framework.getLogger().fatal( "Error loading config " + m_configPath );
return false;
}
@ -131,15 +128,15 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
}
catch( ... )
{
g_log.error( "Error parsing argument: " + arg + " " + "value: " + val + "\n" );
g_log.error( "Usage: <arg> <val> \n" );
g_framework.getLogger().error( "Error parsing argument: " + arg + " " + "value: " + val + "\n" );
g_framework.getLogger().error( "Usage: <arg> <val> \n" );
}
}
g_log.info( "Setting up generated EXD data" );
if( !g_exdDataGen.init( m_pConfig->getValue< std::string >( "Settings.General.DataPath", "" ) ) )
g_framework.getLogger().info( "Setting up generated EXD data" );
if( !g_framework.getExdDataGen().init( m_pConfig->getValue< std::string >( "Settings.General.DataPath", "" ) ) )
{
g_log.fatal( "Error setting up generated EXD data " );
g_framework.getLogger().fatal( "Error setting up generated EXD data " );
return false;
}
@ -154,7 +151,7 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
info.syncThreads = m_pConfig->getValue< uint8_t >( "Settings.General.Mysql.SyncThreads", 2 );
info.asyncThreads = m_pConfig->getValue< uint8_t >( "Settings.General.Mysql.AsyncThreads", 2 );
loader.addDb( g_charaDb, info );
loader.addDb( g_framework.getCharaDb(), info );
if( !loader.initDbs() )
return false;
@ -167,37 +164,43 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
void Core::ServerZone::run( int32_t argc, char* argv[] )
{
// TODO: add more error checks for the entire initialisation
g_log.setLogPath( "log/SapphireZone_" );
g_log.init();
/*g_log.setLogPath( "log/SapphireZone_" );
g_log.init();*/
printBanner();
g_framework.getLogger().setLogPath( "log/SapphireZone_" );
g_framework.getLogger().init();
g_log = g_framework.getLogger();
if( !loadSettings( argc, argv ) )
{
g_log.fatal( "Unable to load settings!" );
g_framework.getLogger().fatal( "Unable to load settings!" );
return;
}
g_log.info( "LinkshellMgr: Caching linkshells" );
if( !g_linkshellMgr.loadLinkshells() )
g_framework.getLogger().info( "LinkshellMgr: Caching linkshells" );
if( !g_framework.getLinkshellMgr().loadLinkshells() )
{
g_log.fatal( "Unable to load linkshells!" );
g_framework.getLogger().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_framework.getScriptMgr().init();
g_log.info( "TerritoryMgr: Setting up zones" );
g_territoryMgr.init();
g_framework.getLogger().info( "TerritoryMgr: Setting up zones" );
g_framework.getTerritoryMgr().init();
std::vector< std::thread > thread_list;
thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) );
g_log.info( "Server listening on port: " + std::to_string( m_port ) );
g_log.info( "Ready for connections..." );
g_framework.getLogger().info( "Server listening on port: " + std::to_string( m_port ) );
g_framework.getLogger().info( "Ready for connections..." );
mainLoop();
@ -210,12 +213,12 @@ void Core::ServerZone::run( int32_t argc, char* argv[] )
void Core::ServerZone::printBanner() const
{
g_log.info("===========================================================" );
g_log.info( "Sapphire Server Project " );
g_log.info( "Version: " + Version::VERSION );
g_log.info( "Git Hash: " + Version::GIT_HASH );
g_log.info( "Compiled: " __DATE__ " " __TIME__ );
g_log.info( "===========================================================" );
g_framework.getLogger().info("===========================================================" );
g_framework.getLogger().info( "Sapphire Server Project " );
g_framework.getLogger().info( "Version: " + Version::VERSION );
g_framework.getLogger().info( "Git Hash: " + Version::GIT_HASH );
g_framework.getLogger().info( "Compiled: " __DATE__ " " __TIME__ );
g_framework.getLogger().info( "===========================================================" );
}
void Core::ServerZone::mainLoop()
@ -226,9 +229,9 @@ void Core::ServerZone::mainLoop()
auto currTime = Util::getTimeSeconds();
g_territoryMgr.updateTerritoryInstances( currTime );
g_framework.getTerritoryMgr().updateTerritoryInstances( currTime );
g_scriptMgr.update();
g_framework.getScriptMgr().update();
lock_guard< std::mutex > lock( this->m_sessionMutex );
for( auto sessionIt : this->m_sessionMapById )
@ -247,7 +250,7 @@ void Core::ServerZone::mainLoop()
if( currTime - m_lastDBPingTime > 3 )
{
g_charaDb.keepAlive();
g_framework.getCharaDb().keepAlive();
m_lastDBPingTime = currTime;
}
@ -265,7 +268,7 @@ void Core::ServerZone::mainLoop()
it->second->close();
// if( it->second.unique() )
{
g_log.info("[" + std::to_string(it->second->getId() ) + "] Session removal" );
g_framework.getLogger().info("[" + std::to_string(it->second->getId() ) + "] Session removal" );
it = this->m_sessionMapById.erase( it );
removeSession( pPlayer->getName() );
continue;
@ -275,7 +278,7 @@ void Core::ServerZone::mainLoop()
// remove sessions that simply timed out
if( diff > 20 )
{
g_log.info("[" + std::to_string( it->second->getId() ) + "] Session time out" );
g_framework.getLogger().info("[" + std::to_string( it->second->getId() ) + "] Session time out" );
it->second->close();
// if( it->second.unique() )
@ -304,18 +307,18 @@ bool Core::ServerZone::createSession( uint32_t sessionId )
if( it != m_sessionMapById.end() )
{
g_log.error( "[" + session_id_str + "] Error creating session" );
g_framework.getLogger().error( "[" + session_id_str + "] Error creating session" );
return false;
}
g_log.info( "[" + session_id_str + "] Creating new session" );
g_framework.getLogger().info( "[" + session_id_str + "] Creating new session" );
boost::shared_ptr<Session> newSession( new Session( sessionId ) );
m_sessionMapById[sessionId] = newSession;
if( !newSession->loadPlayer() )
{
g_log.error( "[" + session_id_str + "] Error loading player " + session_id_str );
g_framework.getLogger().error( "[" + session_id_str + "] Error loading player " + session_id_str );
return false;
}

View file

@ -1,15 +1,18 @@
#include <boost/filesystem/operations.hpp>
#include <time.h>
#include <common/Util/Util.h>
#include <common/Network/PacketContainer.h>
#include "Network/GameConnection.h"
#include "Session.h"
#include "Actor/Player.h"
#include <boost/filesystem/operations.hpp>
#include <common/Logging/Logger.h>
extern Core::Logger g_log;
#include "Network/GameConnection.h"
#include "Actor/Player.h"
#include "Session.h"
#include "Framework.h"
extern Core::Framework g_framework;
Core::Session::Session( uint32_t sessionId ) :
m_sessionId( sessionId ),
@ -145,7 +148,7 @@ void Core::Session::startReplay( const std::string& path )
m_replayCache.push_back( std::tuple< uint64_t, std::string >(
Util::getTimeMs() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ) );
g_log.info( "Registering " + std::get< 1 >( set ) + " for " + std::to_string( std::get< 0 >( set ) - startTime ) );
g_framework.getLogger().info( "Registering " + std::get< 1 >( set ) + " for " + std::to_string( std::get< 0 >( set ) - startTime ) );
}
getPlayer()->sendDebug( "Registered " + std::to_string( m_replayCache.size() ) + " sets for replay" );
@ -167,7 +170,7 @@ void Core::Session::processReplay()
{
m_pZoneConnection->injectPacket( std::get< 1 >( set ), *getPlayer().get() );
m_replayCache.erase( m_replayCache.begin() + at );
//g_log.info( "Sent for " + std::to_string( std::get< 0 >( set ) ) + ", left: " + std::to_string( m_replayCache.size() ) );
//g_framework.getLogger().info( "Sent for " + std::to_string( std::get< 0 >( set ) ) + ", left: " + std::to_string( m_replayCache.size() ) );
}
at++;
}

View file

@ -1,3 +1,6 @@
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <common/Exd/ExdDataGenerated.h>
#include <common/Util/Util.h>
#include <common/Network/PacketDef/Zone/ServerZoneDef.h>
@ -7,18 +10,18 @@
#include <algorithm>
#include "Actor/Chara.h"
#include "Actor/Actor.h"
#include "Script/ScriptMgr.h"
#include "StatusEffect.h"
#include "Script/ScriptManager.h"
#include "Framework.h"
extern Core::Logger g_log;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
extern Core::Scripting::ScriptManager g_scriptMgr;
Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::CharaPtr sourceActor, Entity::CharaPtr targetActor,
uint32_t duration, uint32_t tickRate )
@ -30,7 +33,7 @@ Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::CharaPtr so
, m_tickRate( tickRate )
, m_lastTick( 0 )
{
auto entry = g_exdDataGen.get< Core::Data::Status >( id );
auto entry = g_framework.getExdDataGen().get< Core::Data::Status >( id );
m_name = entry->name;
std::replace( m_name.begin(), m_name.end(), ' ', '_' );
@ -64,7 +67,7 @@ std::pair< uint8_t, uint32_t> Core::StatusEffect::StatusEffect::getTickEffect()
void Core::StatusEffect::StatusEffect::onTick()
{
m_lastTick = Util::getTimeMs();
g_scriptMgr.onStatusTick( m_targetActor, *this );
g_framework.getScriptMgr().onStatusTick( m_targetActor, *this );
}
uint32_t Core::StatusEffect::StatusEffect::getSrcActorId() const
@ -104,14 +107,14 @@ void Core::StatusEffect::StatusEffect::applyStatus()
//effectPacket.data().effects[4].unknown_5 = 0x80;
//m_sourceActor->sendToInRangeSet( effectPacket, true );
g_log.debug( "StatusEffect applied: " + m_name );
g_scriptMgr.onStatusReceive( m_targetActor, m_id );
g_framework.getLogger().debug( "StatusEffect applied: " + m_name );
g_framework.getScriptMgr().onStatusReceive( m_targetActor, m_id );
}
void Core::StatusEffect::StatusEffect::removeStatus()
{
g_log.debug( "StatusEffect removed: " + m_name );
g_scriptMgr.onStatusTimeOut( m_targetActor, m_id );
g_framework.getLogger().debug( "StatusEffect removed: " + m_name );
g_framework.getScriptMgr().onStatusTimeOut( m_targetActor, m_id );
}
uint32_t Core::StatusEffect::StatusEffect::getId() const

View file

@ -1,4 +1,3 @@
#include "InstanceContent.h"
#include <common/Common.h>
#include <common/Logging/Logger.h>
@ -7,7 +6,7 @@
#include <common/Exd/ExdDataGenerated.h>
#include "Event/Director.h"
#include "Script/ScriptManager.h"
#include "Script/ScriptMgr.h"
#include "Actor/Player.h"
#include "Actor/EventObject.h"
@ -15,11 +14,13 @@
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Event/EventHandler.h"
extern Core::Logger g_log;
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::Data::ExdDataGenerated g_exdDataGen;
#include "InstanceContent.h"
#include "Framework.h"
extern Core::Framework g_framework;
using namespace Core::Common;
using namespace Core::Network::Packets;
@ -42,7 +43,7 @@ Core::InstanceContent::InstanceContent( boost::shared_ptr< Core::Data::InstanceC
bool Core::InstanceContent::init()
{
g_scriptMgr.onInstanceInit( getAsInstanceContent() );
g_framework.getScriptMgr().onInstanceInit( getAsInstanceContent() );
return true;
}
@ -65,7 +66,7 @@ Core::Data::ExdDataGenerated::InstanceContentPtr Core::InstanceContent::getInsta
void Core::InstanceContent::onPlayerZoneIn( Entity::Player& player )
{
g_log.debug( "InstanceContent::onPlayerZoneIn: Zone#" + std::to_string( getGuId() ) + "|"
g_framework.getLogger().debug( "InstanceContent::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|"
+ std::to_string( getInstanceContentId() ) +
+ ", Entity#" + std::to_string( player.getId() ) );
@ -81,7 +82,7 @@ void Core::InstanceContent::onPlayerZoneIn( Entity::Player& player )
void Core::InstanceContent::onLeaveTerritory( Entity::Player& player )
{
g_log.debug( "InstanceContent::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|"
g_framework.getLogger().debug( "InstanceContent::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|"
+ std::to_string( getInstanceContentId() ) +
+ ", Entity#" + std::to_string( player.getId() ) );
sendDirectorClear( player );
@ -137,7 +138,8 @@ void Core::InstanceContent::onUpdate( uint32_t currTime )
break;
}
g_scriptMgr.onInstanceUpdate( getAsInstanceContent(), currTime );
g_framework.getScriptMgr().onInstanceUpdate( getAsInstanceContent(), currTime );
}
void Core::InstanceContent::onFinishLoading( Entity::Player& player )
@ -261,12 +263,14 @@ void Core::InstanceContent::onRegisterEObj( Entity::EventObjectPtr object )
if( object->getObjectId() == 2000182 ) // start
m_pEntranceEObj = object;
auto objData = g_exdDataGen.get< Core::Data::EObj >( object->getObjectId() );
auto objData = g_framework.getExdDataGen().get< Core::Data::EObj >( object->getObjectId() );
if( objData )
// todo: data should be renamed to eventId
m_eventIdToObjectMap[objData->data] = object;
else
g_log.error( "InstanceContent::onRegisterEObj Zone " + m_internalName + ": No EObj data found for EObj with ID: " + std::to_string( object->getObjectId() ) );
g_framework.getLogger().error( "InstanceContent::onRegisterEObj Zone " +
m_internalName + ": No EObj data found for EObj with ID: " +
std::to_string( object->getObjectId() ) );
}
void Core::InstanceContent::onBeforePlayerZoneIn( Core::Entity::Player& player )
@ -311,5 +315,5 @@ void Core::InstanceContent::onTalk( Core::Entity::Player& player, uint32_t event
void Core::InstanceContent::onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 )
{
g_scriptMgr.onInstanceEnterTerritory( getAsInstanceContent(), player, eventId, param1, param2 );
g_framework.getScriptMgr().onInstanceEnterTerritory( getAsInstanceContent(), player, eventId, param1, param2 );
}

View file

@ -1,5 +1,3 @@
#include "TerritoryMgr.h"
#include <common/Logging/Logger.h>
#include <common/Database/DatabaseDef.h>
#include <common/Exd/ExdDataGenerated.h>
@ -11,9 +9,10 @@
#include "Zone.h"
#include "ZonePosition.h"
#include "InstanceContent.h"
#include "TerritoryMgr.h"
#include "Framework.h"
extern Core::Logger g_log;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Framework g_framework;
Core::TerritoryMgr::TerritoryMgr() :
m_lastInstanceId( 10000 )
@ -23,11 +22,11 @@ Core::TerritoryMgr::TerritoryMgr() :
void Core::TerritoryMgr::loadTerritoryTypeDetailCache()
{
auto idList = g_exdDataGen.getTerritoryTypeIdList();
auto idList = g_framework.getExdDataGen().getTerritoryTypeIdList();
for( auto id : idList )
{
auto teri1 = g_exdDataGen.get< Core::Data::TerritoryType >( id );
auto teri1 = g_framework.getExdDataGen().get< Core::Data::TerritoryType >( id );
if( !teri1->name.empty() )
m_territoryTypeDetailCacheMap[id] = teri1;
@ -108,13 +107,13 @@ bool Core::TerritoryMgr::createDefaultTerritories()
if( territoryInfo->name.empty() )
continue;
auto pPlaceName = g_exdDataGen.get< Core::Data::PlaceName >( territoryInfo->placeName );
auto pPlaceName = g_framework.getExdDataGen().get< Core::Data::PlaceName >( territoryInfo->placeName );
if( !pPlaceName || pPlaceName->name.empty() || !isDefaultTerritory( territoryId ) )
continue;
uint32_t guid = getNextInstanceId();
g_log.Log( LoggingSeverity::info, std::to_string( territoryId ) +
g_framework.getLogger().info( std::to_string( territoryId ) +
"\t" + std::to_string( guid ) +
"\t" + std::to_string( territoryInfo->territoryIntendedUse ) +
"\t" + ( territoryInfo->name.length() <= 4 ? territoryInfo->name + "\t" : territoryInfo->name ) +
@ -144,12 +143,12 @@ Core::ZonePtr Core::TerritoryMgr::createTerritoryInstance( uint32_t territoryTyp
return nullptr;
auto pTeri = getTerritoryDetail( territoryTypeId );
auto pPlaceName = g_exdDataGen.get< Core::Data::PlaceName >( pTeri->placeName );
auto pPlaceName = g_framework.getExdDataGen().get< Core::Data::PlaceName >( pTeri->placeName );
if( !pTeri || !pPlaceName )
return nullptr;
g_log.debug( "Starting instance for territory: " + std::to_string( territoryTypeId ) + " (" + pPlaceName->name + ")" );
g_framework.getLogger().debug( "Starting instance for territory: " + std::to_string( territoryTypeId ) + " (" + pPlaceName->name + ")" );
auto pZone = make_Zone( territoryTypeId, getNextInstanceId(), pTeri->name, pPlaceName->name );
pZone->init();
@ -162,7 +161,7 @@ Core::ZonePtr Core::TerritoryMgr::createTerritoryInstance( uint32_t territoryTyp
Core::ZonePtr Core::TerritoryMgr::createInstanceContent( uint32_t instanceContentId )
{
auto pInstanceContent = g_exdDataGen.get< Core::Data::InstanceContent >( instanceContentId );
auto pInstanceContent = g_framework.getExdDataGen().get< Core::Data::InstanceContent >( instanceContentId );
if( !pInstanceContent )
return nullptr;
@ -174,7 +173,7 @@ Core::ZonePtr Core::TerritoryMgr::createInstanceContent( uint32_t instanceConten
if( !pTeri || pInstanceContent->name.empty() )
return nullptr;
g_log.debug( "Starting instance for InstanceContent id: " + std::to_string( instanceContentId ) +
g_framework.getLogger().debug( "Starting instance for InstanceContent id: " + std::to_string( instanceContentId ) +
" (" + pInstanceContent->name + ")" );
auto pZone = make_InstanceContent( pInstanceContent, getNextInstanceId(),
@ -222,7 +221,7 @@ Core::ZonePtr Core::TerritoryMgr::getInstanceZonePtr( uint32_t instanceId ) cons
void Core::TerritoryMgr::loadTerritoryPositionMap()
{
auto pQR = g_charaDb.query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" );
auto pQR = g_framework.getCharaDb().query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" );
while( pQR->next() )
{
@ -311,7 +310,7 @@ bool Core::TerritoryMgr::movePlayer( ZonePtr pZone, Core::Entity::PlayerPtr pPla
{
if( !pZone )
{
g_log.error( "Zone not found on this server." );
g_framework.getLogger().error( "Zone not found on this server." );
return false;
}

View file

@ -1,5 +1,6 @@
#include <stdio.h>
#include <vector>
#include <time.h>
#include <common/Logging/Logger.h>
#include <common/Util/Util.h>
@ -18,29 +19,29 @@
#include "Session.h"
#include "Actor/Chara.h"
#include "Actor/Actor.h"
#include "Actor/Player.h"
#include "Actor/EventObject.h"
#include "Forwards.h"
#include "Network/GameConnection.h"
#include "Script/ScriptMgr.h"
#include "Session.h"
#include "Forwards.h"
#include "ServerZone.h"
#include "Script/ScriptManager.h"
#include "CellHandler.h"
#include <time.h>
extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;
extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::TerritoryMgr g_territoryMgr;
#include "Zone.h"
#include "TerritoryMgr.h"
#include "Framework.h"
using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
extern Core::Framework g_framework;
/**
* \brief
*/
@ -67,7 +68,7 @@ Core::Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& intern
m_lastMobUpdate = 0;
m_weatherOverride = Weather::None;
m_territoryTypeInfo = g_exdDataGen.get< Core::Data::TerritoryType >( territoryId );
m_territoryTypeInfo = g_framework.getExdDataGen().get< Core::Data::TerritoryType >( territoryId );
loadWeatherRates();
@ -78,15 +79,16 @@ void Core::Zone::loadWeatherRates()
{
if( !m_territoryTypeInfo )
{
g_log.error( std::string( __FUNCTION__ ) + " TerritoryTypeInfo not loaded!" );
g_framework.getLogger().error( std::string( __FUNCTION__ ) + " TerritoryTypeInfo not loaded!" );
return;
}
uint8_t weatherRateId = m_territoryTypeInfo->weatherRate > g_exdDataGen.getWeatherRateIdList().size() ?
uint8_t weatherRateId = m_territoryTypeInfo->weatherRate > g_framework.getExdDataGen().getWeatherRateIdList().size() ?
uint8_t{ 0 } : m_territoryTypeInfo->weatherRate;
uint8_t sumPc = 0;
auto weatherRateFields = g_exdDataGen.m_WeatherRateDat.get_row( weatherRateId );
auto weatherRateFields = g_framework.getExdDataGen().m_WeatherRateDat.get_row( weatherRateId );
for( size_t i = 0; i < 16; )
{
int32_t weatherId = boost::get< int32_t >( weatherRateFields[i] );
@ -107,7 +109,7 @@ Core::Zone::~Zone()
bool Core::Zone::init()
{
if( g_scriptMgr.onZoneInit( shared_from_this() ) )
if( g_framework.getScriptMgr().onZoneInit( shared_from_this() ) )
{
// all good
}
@ -139,7 +141,6 @@ void Core::Zone::setCurrentFestival( uint16_t festivalId )
void Core::Zone::loadCellCache()
{
}
Weather Core::Zone::getNextWeather()
@ -213,7 +214,7 @@ void Core::Zone::pushActor( Entity::ActorPtr pActor )
{
auto pPlayer = pActor->getAsPlayer();
auto pSession = g_serverZone.getSession( pPlayer->getId() );
auto pSession = g_framework.getServerZone().getSession( pPlayer->getId() );
if( pSession )
m_sessionSet.insert( pSession );
m_playerMap[pPlayer->getId()] = pPlayer;
@ -256,7 +257,7 @@ void Core::Zone::removeActor( Entity::ActorPtr pActor )
void Core::Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, GamePacketPtr pPacketEntry )
{
if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) )
if( g_framework.getTerritoryMgr().isPrivateTerritory( getTerritoryId() ) )
return;
for( auto entry : m_playerMap )
@ -271,7 +272,8 @@ void Core::Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t
if( ( distance < range ) && sourcePlayer.getId() != player->getId() )
{
auto pSession = g_serverZone.getSession( player->getId() );
auto pSession = g_framework.getServerZone().getSession( player->getId() );
pPacketEntry->setValAt< uint32_t >( 0x08, player->getId() );
if( pSession )
pSession->getZoneConnection()->queueOutPacket( pPacketEntry );
@ -311,8 +313,9 @@ bool Core::Zone::checkWeather()
if( m_weatherOverride != m_currentWeather )
{
m_currentWeather = m_weatherOverride;
g_log.debug( "[Zone:" + m_internalName + "] overriding weather to : " +
std::to_string( static_cast< uint8_t >( m_weatherOverride ) ) );
g_framework.getLogger().debug( "[Zone:" + m_internalName + "] overriding weather to : " +
std::to_string( static_cast< uint8_t >( m_weatherOverride ) ) );
return true;
}
}
@ -322,8 +325,9 @@ bool Core::Zone::checkWeather()
if( nextWeather != m_currentWeather )
{
m_currentWeather = nextWeather;
g_log.debug( "[Zone:" + m_internalName + "] changing weather to : " +
std::to_string( static_cast< uint8_t >( nextWeather ) ) );
g_framework.getLogger().debug( "[Zone:" + m_internalName + "] changing weather to : " +
std::to_string( static_cast< uint8_t >( nextWeather ) ) );
return true;
}
}
@ -585,7 +589,7 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
return;
// TODO: make sure gms can overwrite this. Potentially temporary solution
if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) )
if( g_framework.getTerritoryMgr().isPrivateTerritory( getTerritoryId() ) )
return;
auto iter = pCell->m_actors.begin();
@ -633,13 +637,13 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
void Core::Zone::onPlayerZoneIn( Entity::Player &player )
{
g_log.debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
g_framework.getLogger().debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( player.getId() ) );
}
void Core::Zone::onLeaveTerritory( Entity::Player& player )
{
g_log.debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
g_framework.getLogger().debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( player.getId() ) );
}
@ -675,7 +679,7 @@ void Core::Zone::registerEObj( Entity::EventObjectPtr object )
onRegisterEObj( object );
g_log.debug( "Registered instance eobj: " + std::to_string( object->getId() ) );
g_framework.getLogger().debug( "Registered instance eobj: " + std::to_string( object->getId() ) );
}
Core::Entity::EventObjectPtr Core::Zone::getEObj( uint32_t objId )

View file

@ -3,10 +3,12 @@
#include "ServerZone.h"
#include <boost/algorithm/string.hpp>
Core::ServerZone g_serverZone( "config/settings_zone.xml" );
#include "Framework.h"
extern Core::Framework g_framework;
int main( int32_t argc, char* argv[] )
{
g_serverZone.run( argc, argv );
g_framework.getServerZone().run( argc, argv );
return 0;
}
}