From 1e09ec92e38db5b8e9abc9e0b49351ee669348a0 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 26 Mar 2024 04:20:45 -0700 Subject: [PATCH 01/10] Update PlayerContainer.cpp (#1513) Prevents a bad actor from possibly spamming the server with sequential IDs and allocating a bunch of memory. Tested that I can still send and receive friend requests --- dChatServer/PlayerContainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 4e4d1be5..7feff763 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -390,7 +390,7 @@ LWOOBJID PlayerContainer::GetId(const std::u16string& playerName) { } PlayerData& PlayerContainer::GetPlayerDataMutable(const LWOOBJID& playerID) { - return m_Players[playerID]; + return m_Players.contains(playerID) ? m_Players[playerID] : m_Players[LWOOBJID_EMPTY]; } PlayerData& PlayerContainer::GetPlayerDataMutable(const std::string& playerName) { From 39b81b6263d9eeac0e4efb9aec939de327e3f849 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 26 Mar 2024 04:35:35 -0700 Subject: [PATCH 02/10] rename and shorted BehaviorTemplate enum (#1512) just a renaming of the enum and the value names and deletion of the empty cpp file. Code compiles still. --- dGame/dBehaviors/BasicAttackBehavior.cpp | 2 +- dGame/dBehaviors/Behavior.cpp | 148 ++++++++++---------- dGame/dBehaviors/Behavior.h | 6 +- dGame/dBehaviors/BehaviorTemplate.h | 70 +++++++++ dGame/dBehaviors/BehaviorTemplates.cpp | 1 - dGame/dBehaviors/BehaviorTemplates.h | 70 --------- dGame/dBehaviors/CMakeLists.txt | 1 - dGame/dBehaviors/ForceMovementBehavior.cpp | 4 +- dGame/dBehaviors/MovementSwitchBehavior.cpp | 16 +-- 9 files changed, 158 insertions(+), 160 deletions(-) create mode 100644 dGame/dBehaviors/BehaviorTemplate.h delete mode 100644 dGame/dBehaviors/BehaviorTemplates.cpp delete mode 100644 dGame/dBehaviors/BehaviorTemplates.h diff --git a/dGame/dBehaviors/BasicAttackBehavior.cpp b/dGame/dBehaviors/BasicAttackBehavior.cpp index 3d45d9a7..97ceb846 100644 --- a/dGame/dBehaviors/BasicAttackBehavior.cpp +++ b/dGame/dBehaviors/BasicAttackBehavior.cpp @@ -222,7 +222,7 @@ void BasicAttackBehavior::DoBehaviorCalculation(BehaviorContext* context, RakNet if (healthDamageDealt >= 1) { successState = eBasicAttackSuccessTypes::SUCCESS; } else if (armorDamageDealt >= 1) { - successState = this->m_OnFailArmor->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY ? eBasicAttackSuccessTypes::FAILIMMUNE : eBasicAttackSuccessTypes::FAILARMOR; + successState = this->m_OnFailArmor->m_templateId == BehaviorTemplate::EMPTY ? eBasicAttackSuccessTypes::FAILIMMUNE : eBasicAttackSuccessTypes::FAILARMOR; } bitStream.Write(armorDamageDealt); diff --git a/dGame/dBehaviors/Behavior.cpp b/dGame/dBehaviors/Behavior.cpp index ce1ee053..4d57a9df 100644 --- a/dGame/dBehaviors/Behavior.cpp +++ b/dGame/dBehaviors/Behavior.cpp @@ -5,7 +5,7 @@ #include "CDActivitiesTable.h" #include "Game.h" #include "Logger.h" -#include "BehaviorTemplates.h" +#include "BehaviorTemplate.h" #include "BehaviorBranchContext.h" #include @@ -110,176 +110,176 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) { Behavior* behavior = nullptr; switch (templateId) { - case BehaviorTemplates::BEHAVIOR_EMPTY: break; - case BehaviorTemplates::BEHAVIOR_BASIC_ATTACK: + case BehaviorTemplate::EMPTY: break; + case BehaviorTemplate::BASIC_ATTACK: behavior = new BasicAttackBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_TAC_ARC: + case BehaviorTemplate::TAC_ARC: behavior = new TacArcBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_AND: + case BehaviorTemplate::AND: behavior = new AndBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_PROJECTILE_ATTACK: + case BehaviorTemplate::PROJECTILE_ATTACK: behavior = new ProjectileAttackBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_HEAL: + case BehaviorTemplate::HEAL: behavior = new HealBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_MOVEMENT_SWITCH: + case BehaviorTemplate::MOVEMENT_SWITCH: behavior = new MovementSwitchBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_AREA_OF_EFFECT: + case BehaviorTemplate::AREA_OF_EFFECT: behavior = new AreaOfEffectBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_PLAY_EFFECT: + case BehaviorTemplate::PLAY_EFFECT: behavior = new PlayEffectBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_IMMUNITY: + case BehaviorTemplate::IMMUNITY: behavior = new ImmunityBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_DAMAGE_BUFF: break; - case BehaviorTemplates::BEHAVIOR_DAMAGE_ABSORBTION: + case BehaviorTemplate::DAMAGE_BUFF: break; + case BehaviorTemplate::DAMAGE_ABSORBTION: behavior = new DamageAbsorptionBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_OVER_TIME: + case BehaviorTemplate::OVER_TIME: behavior = new OverTimeBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_IMAGINATION: + case BehaviorTemplate::IMAGINATION: behavior = new ImaginationBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_TARGET_CASTER: + case BehaviorTemplate::TARGET_CASTER: behavior = new TargetCasterBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_STUN: + case BehaviorTemplate::STUN: behavior = new StunBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_DURATION: + case BehaviorTemplate::DURATION: behavior = new DurationBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_KNOCKBACK: + case BehaviorTemplate::KNOCKBACK: behavior = new KnockbackBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_ATTACK_DELAY: + case BehaviorTemplate::ATTACK_DELAY: behavior = new AttackDelayBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_CAR_BOOST: + case BehaviorTemplate::CAR_BOOST: behavior = new CarBoostBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_FALL_SPEED: + case BehaviorTemplate::FALL_SPEED: behavior = new FallSpeedBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SHIELD: break; - case BehaviorTemplates::BEHAVIOR_REPAIR_ARMOR: + case BehaviorTemplate::SHIELD: break; + case BehaviorTemplate::REPAIR_ARMOR: behavior = new RepairBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SPEED: + case BehaviorTemplate::SPEED: behavior = new SpeedBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_DARK_INSPIRATION: + case BehaviorTemplate::DARK_INSPIRATION: behavior = new DarkInspirationBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_LOOT_BUFF: + case BehaviorTemplate::LOOT_BUFF: behavior = new LootBuffBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_VENTURE_VISION: + case BehaviorTemplate::VENTURE_VISION: behavior = new VentureVisionBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SPAWN_OBJECT: + case BehaviorTemplate::SPAWN_OBJECT: behavior = new SpawnBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_LAY_BRICK: break; - case BehaviorTemplates::BEHAVIOR_SWITCH: + case BehaviorTemplate::LAY_BRICK: break; + case BehaviorTemplate::SWITCH: behavior = new SwitchBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_BUFF: + case BehaviorTemplate::BUFF: behavior = new BuffBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_JETPACK: + case BehaviorTemplate::JETPACK: behavior = new JetPackBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SKILL_EVENT: + case BehaviorTemplate::SKILL_EVENT: behavior = new SkillEventBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_CONSUME_ITEM: + case BehaviorTemplate::CONSUME_ITEM: behavior = new ConsumeItemBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SKILL_CAST_FAILED: + case BehaviorTemplate::SKILL_CAST_FAILED: behavior = new SkillCastFailedBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_IMITATION_SKUNK_STINK: break; - case BehaviorTemplates::BEHAVIOR_CHANGE_IDLE_FLAGS: + case BehaviorTemplate::IMITATION_SKUNK_STINK: break; + case BehaviorTemplate::CHANGE_IDLE_FLAGS: behavior = new ChangeIdleFlagsBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_APPLY_BUFF: + case BehaviorTemplate::APPLY_BUFF: behavior = new ApplyBuffBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_CHAIN: + case BehaviorTemplate::CHAIN: behavior = new ChainBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_CHANGE_ORIENTATION: + case BehaviorTemplate::CHANGE_ORIENTATION: behavior = new ChangeOrientationBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_FORCE_MOVEMENT: + case BehaviorTemplate::FORCE_MOVEMENT: behavior = new ForceMovementBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_INTERRUPT: + case BehaviorTemplate::INTERRUPT: behavior = new InterruptBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_ALTER_COOLDOWN: break; - case BehaviorTemplates::BEHAVIOR_CHARGE_UP: + case BehaviorTemplate::ALTER_COOLDOWN: break; + case BehaviorTemplate::CHARGE_UP: behavior = new ChargeUpBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SWITCH_MULTIPLE: + case BehaviorTemplate::SWITCH_MULTIPLE: behavior = new SwitchMultipleBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_START: + case BehaviorTemplate::START: behavior = new StartBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_END: + case BehaviorTemplate::END: behavior = new EndBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_ALTER_CHAIN_DELAY: break; - case BehaviorTemplates::BEHAVIOR_CAMERA: break; - case BehaviorTemplates::BEHAVIOR_REMOVE_BUFF: + case BehaviorTemplate::ALTER_CHAIN_DELAY: break; + case BehaviorTemplate::CAMERA: break; + case BehaviorTemplate::REMOVE_BUFF: behavior = new RemoveBuffBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_GRAB: break; - case BehaviorTemplates::BEHAVIOR_MODULAR_BUILD: break; - case BehaviorTemplates::BEHAVIOR_NPC_COMBAT_SKILL: + case BehaviorTemplate::GRAB: break; + case BehaviorTemplate::MODULAR_BUILD: break; + case BehaviorTemplate::NPC_COMBAT_SKILL: behavior = new NpcCombatSkillBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_BLOCK: + case BehaviorTemplate::BLOCK: behavior = new BlockBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_VERIFY: + case BehaviorTemplate::VERIFY: behavior = new VerifyBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_TAUNT: + case BehaviorTemplate::TAUNT: behavior = new TauntBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_AIR_MOVEMENT: + case BehaviorTemplate::AIR_MOVEMENT: behavior = new AirMovementBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_SPAWN_QUICKBUILD: + case BehaviorTemplate::SPAWN_QUICKBUILD: behavior = new SpawnBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_PULL_TO_POINT: + case BehaviorTemplate::PULL_TO_POINT: behavior = new PullToPointBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_PROPERTY_ROTATE: break; - case BehaviorTemplates::BEHAVIOR_DAMAGE_REDUCTION: + case BehaviorTemplate::PROPERTY_ROTATE: break; + case BehaviorTemplate::DAMAGE_REDUCTION: behavior = new DamageReductionBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_PROPERTY_TELEPORT: + case BehaviorTemplate::PROPERTY_TELEPORT: behavior = new PropertyTeleportBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_PROPERTY_CLEAR_TARGET: + case BehaviorTemplate::PROPERTY_CLEAR_TARGET: behavior = new ClearTargetBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_TAKE_PICTURE: break; - case BehaviorTemplates::BEHAVIOR_MOUNT: break; - case BehaviorTemplates::BEHAVIOR_SKILL_SET: break; + case BehaviorTemplate::TAKE_PICTURE: break; + case BehaviorTemplate::MOUNT: break; + case BehaviorTemplate::SKILL_SET: break; default: //LOG("Failed to load behavior with invalid template id (%i)!", templateId); break; @@ -296,19 +296,19 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) { return behavior; } -BehaviorTemplates Behavior::GetBehaviorTemplate(const uint32_t behaviorId) { +BehaviorTemplate Behavior::GetBehaviorTemplate(const uint32_t behaviorId) { auto behaviorTemplateTable = CDClientManager::GetTable(); - BehaviorTemplates templateID = BehaviorTemplates::BEHAVIOR_EMPTY; + BehaviorTemplate templateID = BehaviorTemplate::EMPTY; // Find behavior template by its behavior id. Default to 0. if (behaviorTemplateTable) { auto templateEntry = behaviorTemplateTable->GetByBehaviorID(behaviorId); if (templateEntry.behaviorID == behaviorId) { - templateID = static_cast(templateEntry.templateID); + templateID = static_cast(templateEntry.templateID); } } - if (templateID == BehaviorTemplates::BEHAVIOR_EMPTY && behaviorId != 0) { + if (templateID == BehaviorTemplate::EMPTY && behaviorId != 0) { LOG("Failed to load behavior template with id (%i)!", behaviorId); } @@ -419,7 +419,7 @@ Behavior::Behavior(const uint32_t behaviorId) { if (behaviorId == 0) { this->m_effectId = 0; - this->m_templateId = BehaviorTemplates::BEHAVIOR_EMPTY; + this->m_templateId = BehaviorTemplate::EMPTY; } // Make sure we do not proceed if we are trying to load an invalid behavior @@ -427,12 +427,12 @@ Behavior::Behavior(const uint32_t behaviorId) { LOG("Failed to load behavior with id (%i)!", behaviorId); this->m_effectId = 0; - this->m_templateId = BehaviorTemplates::BEHAVIOR_EMPTY; + this->m_templateId = BehaviorTemplate::EMPTY; return; } - this->m_templateId = static_cast(templateInDatabase.templateID); + this->m_templateId = static_cast(templateInDatabase.templateID); this->m_effectId = templateInDatabase.effectID; diff --git a/dGame/dBehaviors/Behavior.h b/dGame/dBehaviors/Behavior.h index e395701a..f9867ffe 100644 --- a/dGame/dBehaviors/Behavior.h +++ b/dGame/dBehaviors/Behavior.h @@ -6,7 +6,7 @@ #include #include "BitStream.h" -#include "BehaviorTemplates.h" +#include "BehaviorTemplate.h" #include "dCommonVars.h" struct BehaviorContext; @@ -26,7 +26,7 @@ public: static Behavior* CreateBehavior(uint32_t behaviorId); - static BehaviorTemplates GetBehaviorTemplate(uint32_t behaviorId); + static BehaviorTemplate GetBehaviorTemplate(uint32_t behaviorId); /* * Utilities @@ -39,7 +39,7 @@ public: */ uint32_t m_behaviorId; - BehaviorTemplates m_templateId; + BehaviorTemplate m_templateId; uint32_t m_effectId; std::string m_effectHandle; std::unordered_map m_effectNames; diff --git a/dGame/dBehaviors/BehaviorTemplate.h b/dGame/dBehaviors/BehaviorTemplate.h new file mode 100644 index 00000000..175dce50 --- /dev/null +++ b/dGame/dBehaviors/BehaviorTemplate.h @@ -0,0 +1,70 @@ +#pragma once + +enum class BehaviorTemplate : unsigned int { + EMPTY, // Not a real behavior, indicates invalid behaviors + BASIC_ATTACK, + TAC_ARC, + AND, + PROJECTILE_ATTACK, + HEAL, + MOVEMENT_SWITCH, + AREA_OF_EFFECT, + PLAY_EFFECT, + IMMUNITY, + DAMAGE_BUFF, + DAMAGE_ABSORBTION, + OVER_TIME, + IMAGINATION, + TARGET_CASTER, + STUN, + DURATION, + KNOCKBACK, + ATTACK_DELAY, + CAR_BOOST, + FALL_SPEED, + SHIELD, + REPAIR_ARMOR, + SPEED, + DARK_INSPIRATION, + LOOT_BUFF, + VENTURE_VISION, + SPAWN_OBJECT, + LAY_BRICK, + SWITCH, + BUFF, + JETPACK, + SKILL_EVENT, + CONSUME_ITEM, + SKILL_CAST_FAILED, + IMITATION_SKUNK_STINK, + CHANGE_IDLE_FLAGS, + APPLY_BUFF, + CHAIN, + CHANGE_ORIENTATION, + FORCE_MOVEMENT, + INTERRUPT, + ALTER_COOLDOWN, + CHARGE_UP, + SWITCH_MULTIPLE, + START, + END, + ALTER_CHAIN_DELAY, + CAMERA, + REMOVE_BUFF, + GRAB, + MODULAR_BUILD, + NPC_COMBAT_SKILL, + BLOCK, + VERIFY, + TAUNT, + AIR_MOVEMENT, + SPAWN_QUICKBUILD, + PULL_TO_POINT, + PROPERTY_ROTATE, + DAMAGE_REDUCTION, + PROPERTY_TELEPORT, + PROPERTY_CLEAR_TARGET, + TAKE_PICTURE, + MOUNT, + SKILL_SET +}; diff --git a/dGame/dBehaviors/BehaviorTemplates.cpp b/dGame/dBehaviors/BehaviorTemplates.cpp deleted file mode 100644 index 8719fbe7..00000000 --- a/dGame/dBehaviors/BehaviorTemplates.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "BehaviorTemplates.h" diff --git a/dGame/dBehaviors/BehaviorTemplates.h b/dGame/dBehaviors/BehaviorTemplates.h deleted file mode 100644 index 87cde694..00000000 --- a/dGame/dBehaviors/BehaviorTemplates.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -enum class BehaviorTemplates : unsigned int { - BEHAVIOR_EMPTY, // Not a real behavior, indicates invalid behaviors - BEHAVIOR_BASIC_ATTACK, - BEHAVIOR_TAC_ARC, - BEHAVIOR_AND, - BEHAVIOR_PROJECTILE_ATTACK, - BEHAVIOR_HEAL, - BEHAVIOR_MOVEMENT_SWITCH, - BEHAVIOR_AREA_OF_EFFECT, - BEHAVIOR_PLAY_EFFECT, - BEHAVIOR_IMMUNITY, - BEHAVIOR_DAMAGE_BUFF, - BEHAVIOR_DAMAGE_ABSORBTION, - BEHAVIOR_OVER_TIME, - BEHAVIOR_IMAGINATION, - BEHAVIOR_TARGET_CASTER, - BEHAVIOR_STUN, - BEHAVIOR_DURATION, - BEHAVIOR_KNOCKBACK, - BEHAVIOR_ATTACK_DELAY, - BEHAVIOR_CAR_BOOST, - BEHAVIOR_FALL_SPEED, - BEHAVIOR_SHIELD, - BEHAVIOR_REPAIR_ARMOR, - BEHAVIOR_SPEED, - BEHAVIOR_DARK_INSPIRATION, - BEHAVIOR_LOOT_BUFF, - BEHAVIOR_VENTURE_VISION, - BEHAVIOR_SPAWN_OBJECT, - BEHAVIOR_LAY_BRICK, - BEHAVIOR_SWITCH, - BEHAVIOR_BUFF, - BEHAVIOR_JETPACK, - BEHAVIOR_SKILL_EVENT, - BEHAVIOR_CONSUME_ITEM, - BEHAVIOR_SKILL_CAST_FAILED, - BEHAVIOR_IMITATION_SKUNK_STINK, - BEHAVIOR_CHANGE_IDLE_FLAGS, - BEHAVIOR_APPLY_BUFF, - BEHAVIOR_CHAIN, - BEHAVIOR_CHANGE_ORIENTATION, - BEHAVIOR_FORCE_MOVEMENT, - BEHAVIOR_INTERRUPT, - BEHAVIOR_ALTER_COOLDOWN, - BEHAVIOR_CHARGE_UP, - BEHAVIOR_SWITCH_MULTIPLE, - BEHAVIOR_START, - BEHAVIOR_END, - BEHAVIOR_ALTER_CHAIN_DELAY, - BEHAVIOR_CAMERA, - BEHAVIOR_REMOVE_BUFF, - BEHAVIOR_GRAB, - BEHAVIOR_MODULAR_BUILD, - BEHAVIOR_NPC_COMBAT_SKILL, - BEHAVIOR_BLOCK, - BEHAVIOR_VERIFY, - BEHAVIOR_TAUNT, - BEHAVIOR_AIR_MOVEMENT, - BEHAVIOR_SPAWN_QUICKBUILD, - BEHAVIOR_PULL_TO_POINT, - BEHAVIOR_PROPERTY_ROTATE, - BEHAVIOR_DAMAGE_REDUCTION, - BEHAVIOR_PROPERTY_TELEPORT, - BEHAVIOR_PROPERTY_CLEAR_TARGET, - BEHAVIOR_TAKE_PICTURE, - BEHAVIOR_MOUNT, - BEHAVIOR_SKILL_SET -}; diff --git a/dGame/dBehaviors/CMakeLists.txt b/dGame/dBehaviors/CMakeLists.txt index f00ba7e2..35d8cae6 100644 --- a/dGame/dBehaviors/CMakeLists.txt +++ b/dGame/dBehaviors/CMakeLists.txt @@ -7,7 +7,6 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp" "Behavior.cpp" "BehaviorBranchContext.cpp" "BehaviorContext.cpp" - "BehaviorTemplates.cpp" "BlockBehavior.cpp" "BuffBehavior.cpp" "CarBoostBehavior.cpp" diff --git a/dGame/dBehaviors/ForceMovementBehavior.cpp b/dGame/dBehaviors/ForceMovementBehavior.cpp index 83c6fabc..04dad715 100644 --- a/dGame/dBehaviors/ForceMovementBehavior.cpp +++ b/dGame/dBehaviors/ForceMovementBehavior.cpp @@ -7,7 +7,7 @@ #include "Logger.h" void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) { - if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) { + if (this->m_hitAction->m_templateId == BehaviorTemplate::EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplate::EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplate::EMPTY) { return; } @@ -38,7 +38,7 @@ void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream& bi } void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) { - if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) { + if (this->m_hitAction->m_templateId == BehaviorTemplate::EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplate::EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplate::EMPTY) { return; } diff --git a/dGame/dBehaviors/MovementSwitchBehavior.cpp b/dGame/dBehaviors/MovementSwitchBehavior.cpp index cc2d7b34..7d7d3a17 100644 --- a/dGame/dBehaviors/MovementSwitchBehavior.cpp +++ b/dGame/dBehaviors/MovementSwitchBehavior.cpp @@ -6,13 +6,13 @@ void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) { uint32_t movementType{}; if (!bitStream.Read(movementType)) { - if (this->m_groundAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && - this->m_jumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && - this->m_fallingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && - this->m_doubleJumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && - this->m_airAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && - this->m_jetpackAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && - this->m_movingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) { + if (this->m_groundAction->m_templateId == BehaviorTemplate::EMPTY && + this->m_jumpAction->m_templateId == BehaviorTemplate::EMPTY && + this->m_fallingAction->m_templateId == BehaviorTemplate::EMPTY && + this->m_doubleJumpAction->m_templateId == BehaviorTemplate::EMPTY && + this->m_airAction->m_templateId == BehaviorTemplate::EMPTY && + this->m_jetpackAction->m_templateId == BehaviorTemplate::EMPTY && + this->m_movingAction->m_templateId == BehaviorTemplate::EMPTY) { return; } LOG("Unable to read movementType from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); @@ -47,7 +47,7 @@ void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream& Behavior* MovementSwitchBehavior::LoadMovementType(std::string movementType) { float actionValue = GetFloat(movementType, -1.0f); auto loadedBehavior = GetAction(actionValue != -1.0f ? actionValue : 0.0f); - if (actionValue == -1.0f && loadedBehavior->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) { + if (actionValue == -1.0f && loadedBehavior->m_templateId == BehaviorTemplate::EMPTY) { loadedBehavior = this->m_groundAction; } return loadedBehavior; From bd9b790e1db5dd1e7e5d6127f4f5a970f052176c Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:06:22 -0700 Subject: [PATCH 03/10] feat: Add MovingAI pathing for NPCs without combatAI (#1509) * remove goto * Update MovementAIComponent.cpp * convert to PathWaypoint Easier for usage with paths * add path parsing * ref removal, simplification of work * it works * Update MovementAIComponent.cpp * disable pathing for combat we just need it for npcs for now, combat ai can be done later * fixed stuttery enemies wow * start at ramped up speed * add pausing and resuming * Update MovementAIComponent.cpp * Update MovementAIComponent.h * Update CMakeLists.txt --- dGame/Entity.cpp | 20 ++-- dGame/dComponents/MovementAIComponent.cpp | 99 +++++++++++++++---- dGame/dComponents/MovementAIComponent.h | 25 ++++- .../dComponents/ProximityMonitorComponent.cpp | 1 + dScripts/02_server/Map/AM/WanderingVendor.cpp | 5 +- .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 6 +- .../LUPs/RobotCity_Intro/WblRobotCitizen.cpp | 9 +- dZoneManager/Zone.h | 84 ++++++++-------- 8 files changed, 164 insertions(+), 85 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 23f65540..90763b4c 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -731,15 +731,21 @@ void Entity::Initialize() { // if we have a moving platform path, then we need a moving platform component if (path->pathType == PathType::MovingPlatform) { AddComponent(pathName); - // else if we are a movement path - } /*else if (path->pathType == PathType::Movement) { - auto movementAIcomp = GetComponent(); - if (movementAIcomp){ - // TODO: set path in existing movementAIComp + } else if (path->pathType == PathType::Movement) { + auto movementAIcomponent = GetComponent(); + if (movementAIcomponent && combatAiId == 0) { + movementAIcomponent->SetPath(pathName); } else { - // TODO: create movementAIcomp and set path + MovementAIInfo moveInfo = MovementAIInfo(); + moveInfo.movementType = ""; + moveInfo.wanderChance = 0; + moveInfo.wanderRadius = 16; + moveInfo.wanderSpeed = 2.5f; + moveInfo.wanderDelayMax = 5; + moveInfo.wanderDelayMin = 2; + AddComponent(moveInfo); } - }*/ + } } else { // else we still need to setup moving platform if it has a moving platform comp but no path int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1); diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index 8aefdb5b..358d8d11 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -50,9 +50,42 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : m_CurrentSpeed = 0; m_MaxSpeed = 0; m_LockRotation = false; + m_Path = nullptr; + m_SourcePosition = m_Parent->GetPosition(); + m_Paused = false; + m_SavedVelocity = NiPoint3Constant::ZERO; + + if (!m_Parent->GetComponent()) SetPath(m_Parent->GetVarAsString(u"attached_path")); +} + +void MovementAIComponent::SetPath(const std::string pathName) { + m_Path = Game::zoneManager->GetZone()->GetPath(pathName); + if (!pathName.empty()) LOG("WARNING: %s path %s", m_Path ? "Found" : "Failed to find", pathName.c_str()); + if (!m_Path) return; + SetMaxSpeed(1); + SetCurrentSpeed(m_BaseSpeed); + SetPath(m_Path->pathWaypoints); +} + +void MovementAIComponent::Pause() { + m_Paused = true; + SetPosition(ApproximateLocation()); + m_SavedVelocity = GetVelocity(); + SetVelocity(NiPoint3Constant::ZERO); + Game::entityManager->SerializeEntity(m_Parent); +} + +void MovementAIComponent::Resume() { + m_Paused = false; + SetVelocity(m_SavedVelocity); + m_SavedVelocity = NiPoint3Constant::ZERO; + SetRotation(NiQuaternion::LookAt(m_Parent->GetPosition(), m_NextWaypoint)); + Game::entityManager->SerializeEntity(m_Parent); } void MovementAIComponent::Update(const float deltaTime) { + if (m_Paused) return; + if (m_PullingToPoint) { const auto source = GetCurrentWaypoint(); @@ -81,27 +114,24 @@ void MovementAIComponent::Update(const float deltaTime) { } m_TimeTravelled += deltaTime; + + SetPosition(ApproximateLocation()); + if (m_TimeTravelled < m_TimeToTravel) return; m_TimeTravelled = 0.0f; const auto source = GetCurrentWaypoint(); SetPosition(source); - - NiPoint3 velocity = NiPoint3Constant::ZERO; + m_SourcePosition = source; if (m_Acceleration > 0 && m_BaseSpeed > 0 && AdvanceWaypointIndex()) // Do we have another waypoint to seek? { m_NextWaypoint = GetCurrentWaypoint(); - if (m_NextWaypoint == source) { m_TimeToTravel = 0.0f; } else { - if (m_CurrentSpeed < m_MaxSpeed) { - m_CurrentSpeed += m_Acceleration; - } - - m_CurrentSpeed = std::min(m_CurrentSpeed, m_MaxSpeed); + m_CurrentSpeed = std::min(m_CurrentSpeed + m_Acceleration, m_MaxSpeed); const auto speed = m_CurrentSpeed * m_BaseSpeed; // scale speed based on base speed @@ -110,7 +140,7 @@ void MovementAIComponent::Update(const float deltaTime) { // Normalize the vector const auto length = delta.Length(); if (length > 0.0f) { - velocity = (delta / length) * speed; + SetVelocity((delta / length) * speed); } // Calclute the time it will take to reach the next waypoint with the current speed @@ -122,17 +152,27 @@ void MovementAIComponent::Update(const float deltaTime) { } else { // Check if there are more waypoints in the queue, if so set our next destination to the next waypoint if (m_CurrentPath.empty()) { - Stop(); - - return; + if (m_Path) { + if (m_Path->pathBehavior == PathBehavior::Loop) { + SetPath(m_Path->pathWaypoints); + } else if (m_Path->pathBehavior == PathBehavior::Bounce) { + std::vector waypoints = m_Path->pathWaypoints; + std::reverse(waypoints.begin(), waypoints.end()); + SetPath(waypoints); + } else if (m_Path->pathBehavior == PathBehavior::Once) { + Stop(); + return; + } + } else { + Stop(); + return; + } } - SetDestination(m_CurrentPath.top()); + SetDestination(m_CurrentPath.top().position); m_CurrentPath.pop(); } - SetVelocity(velocity); - Game::entityManager->SerializeEntity(m_Parent); } @@ -155,7 +195,7 @@ NiPoint3 MovementAIComponent::GetCurrentWaypoint() const { } NiPoint3 MovementAIComponent::ApproximateLocation() const { - auto source = m_Parent->GetPosition(); + auto source = m_SourcePosition; if (AtFinalWaypoint()) return source; @@ -221,13 +261,13 @@ void MovementAIComponent::PullToPoint(const NiPoint3& point) { m_PullPoint = point; } -void MovementAIComponent::SetPath(std::vector path) { +void MovementAIComponent::SetPath(std::vector path) { if (path.empty()) return; - std::for_each(path.rbegin(), path.rend() - 1, [this](const NiPoint3& point) { + std::for_each(path.rbegin(), path.rend() - 1, [this](const PathWaypoint& point) { this->m_CurrentPath.push(point); }); - SetDestination(path.front()); + SetDestination(path.front().position); } float MovementAIComponent::GetBaseSpeed(LOT lot) { @@ -272,6 +312,23 @@ void MovementAIComponent::SetRotation(const NiQuaternion& value) { if (!m_LockRotation) m_Parent->SetRotation(value); } +NiPoint3 MovementAIComponent::GetVelocity() const { + auto* controllablePhysicsComponent = m_Parent->GetComponent(); + + if (controllablePhysicsComponent != nullptr) { + return controllablePhysicsComponent->GetVelocity(); + } + + auto* simplePhysicsComponent = m_Parent->GetComponent(); + + if (simplePhysicsComponent != nullptr) { + return simplePhysicsComponent->GetVelocity(); + } + + return NiPoint3Constant::ZERO; + +} + void MovementAIComponent::SetVelocity(const NiPoint3& value) { auto* controllablePhysicsComponent = m_Parent->GetComponent(); @@ -288,7 +345,7 @@ void MovementAIComponent::SetVelocity(const NiPoint3& value) { } } -void MovementAIComponent::SetDestination(const NiPoint3& destination) { +void MovementAIComponent::SetDestination(const NiPoint3 destination) { if (m_PullingToPoint) return; const auto location = ApproximateLocation(); @@ -297,6 +354,8 @@ void MovementAIComponent::SetDestination(const NiPoint3& destination) { SetPosition(location); } + m_SourcePosition = location; + std::vector computedPath; if (dpWorld::IsLoaded()) { computedPath = dpWorld::GetNavMesh()->GetPath(m_Parent->GetPosition(), destination, m_Info.wanderSpeed); diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index 852f7001..15b5aaed 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -14,11 +14,14 @@ #include "Logger.h" #include "Component.h" #include "eReplicaComponentType.h" +#include "Zone.h" #include class ControllablePhysicsComponent; class BaseCombatAIComponent; +struct Path; + /** * Information that describes the different variables used to make an entity move around */ @@ -61,6 +64,8 @@ public: MovementAIComponent(Entity* parentEntity, MovementAIInfo info); + void SetPath(const std::string pathName); + void Update(float deltaTime) override; /** @@ -73,7 +78,7 @@ public: * Set a destination point for the entity to move towards * @param value the destination point to move towards */ - void SetDestination(const NiPoint3& value); + void SetDestination(const NiPoint3 value); /** * Returns the current rotation this entity is moving towards @@ -189,7 +194,13 @@ public: * Sets a path to follow for the AI * @param path the path to follow */ - void SetPath(std::vector path); + void SetPath(std::vector path); + + void Pause(); + + void Resume(); + + NiPoint3 GetVelocity() const; /** * Returns the base speed from the DB for a given LOT @@ -301,7 +312,15 @@ private: /** * The path from the current position to the destination. */ - std::stack m_CurrentPath; + std::stack m_CurrentPath; + + const Path* m_Path = nullptr; + + NiPoint3 m_SourcePosition; + + bool m_Paused; + + NiPoint3 m_SavedVelocity; }; #endif // MOVEMENTAICOMPONENT_H diff --git a/dGame/dComponents/ProximityMonitorComponent.cpp b/dGame/dComponents/ProximityMonitorComponent.cpp index fbac8ddb..9ab3f1db 100644 --- a/dGame/dComponents/ProximityMonitorComponent.cpp +++ b/dGame/dComponents/ProximityMonitorComponent.cpp @@ -64,6 +64,7 @@ void ProximityMonitorComponent::Update(float deltaTime) { for (const auto& prox : m_ProximitiesData) { if (!prox.second) continue; + prox.second->SetPosition(m_Parent->GetPosition()); //Process enter events for (auto* en : prox.second->GetNewObjects()) { m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "ENTER"); diff --git a/dScripts/02_server/Map/AM/WanderingVendor.cpp b/dScripts/02_server/Map/AM/WanderingVendor.cpp index ae49aa94..77259e2f 100644 --- a/dScripts/02_server/Map/AM/WanderingVendor.cpp +++ b/dScripts/02_server/Map/AM/WanderingVendor.cpp @@ -5,7 +5,6 @@ void WanderingVendor::OnStartup(Entity* self) { auto movementAIComponent = self->GetComponent(); if (!movementAIComponent) return; - // movementAIComponent->Resume(); self->SetProximityRadius(10, "playermonitor"); } @@ -13,7 +12,7 @@ void WanderingVendor::OnProximityUpdate(Entity* self, Entity* entering, std::str if (status == "ENTER" && entering->IsPlayer()) { auto movementAIComponent = self->GetComponent(); if (!movementAIComponent) return; - // movementAIComponent->Pause(); + movementAIComponent->Pause(); self->CancelTimer("startWalking"); } else if (status == "LEAVE") { auto* proximityMonitorComponent = self->GetComponent(); @@ -28,6 +27,6 @@ void WanderingVendor::OnTimerDone(Entity* self, std::string timerName) { if (timerName == "startWalking") { auto movementAIComponent = self->GetComponent(); if (!movementAIComponent) return; - // movementAIComponent->Resume(); + movementAIComponent->Resume(); } } diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 1952831a..56f5b257 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -307,11 +307,7 @@ void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) { movementAI->SetCurrentSpeed(toSpawn.initialSpeed); movementAI->SetHaltDistance(0.0f); - std::vector pathWaypoints; - - for (const auto& waypoint : path->pathWaypoints) { - pathWaypoints.push_back(waypoint.position); - } + std::vector pathWaypoints = path->pathWaypoints; if (GeneralUtils::GenerateRandomNumber(0, 1) < 0.5f) { std::reverse(pathWaypoints.begin(), pathWaypoints.end()); diff --git a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp index 93bf2576..8ad303a6 100644 --- a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp +++ b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp @@ -5,20 +5,19 @@ void WblRobotCitizen::OnStartup(Entity* self) { auto movementAIComponent = self->GetComponent(); if (!movementAIComponent) return; - // movementAIComponent->Resume(); } void WblRobotCitizen::OnUse(Entity* self, Entity* user) { - // auto movementAIComponent = self->GetComponent(); - // if (!movementAIComponent) movementAIComponent->Pause(); + auto movementAIComponent = self->GetComponent(); + if (movementAIComponent) movementAIComponent->Pause(); auto face = NiQuaternion::LookAt(self->GetPosition(), user->GetPosition()); self->SetRotation(face); - auto timer = RenderComponent::PlayAnimation(self, "wave"); + auto timer = RenderComponent::PlayAnimation(self, "wave", 0.4f); self->AddTimer("animation time", timer); } void WblRobotCitizen::OnTimerDone(Entity* self, std::string timerName) { auto movementAIComponent = self->GetComponent(); if (!movementAIComponent) return; - // movementAIComponent->Resume(); + movementAIComponent->Resume(); } diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index c5bac6a6..299d675b 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -16,57 +16,57 @@ class Level; enum class eWaypointCommandType : uint32_t; struct WaypointCommand { - eWaypointCommandType command; + eWaypointCommandType command{}; std::string data; }; struct SceneRef { std::string filename; - uint32_t id; - uint32_t sceneType; //0 = general, 1 = audio? + uint32_t id{}; + uint32_t sceneType{}; //0 = general, 1 = audio? std::string name; NiPoint3 unknown1; - float unknown2; - uint8_t color_r; - uint8_t color_g; - uint8_t color_b; + float unknown2{}; + uint8_t color_r{}; + uint8_t color_g{}; + uint8_t color_b{}; Level* level; std::map triggers; }; struct SceneTransitionInfo { - uint64_t sceneID; //id of the scene being transitioned to. + uint64_t sceneID{}; //id of the scene being transitioned to. NiPoint3 position; }; struct SceneTransition { std::string name; std::vector points; - float width; + float width{}; }; struct MovingPlatformPathWaypoint { - uint8_t lockPlayer; - float wait; + uint8_t lockPlayer{}; + float wait{}; std::string departSound; std::string arriveSound; }; struct CameraPathWaypoint { - float time; - float fov; - float tension; - float continuity; - float bias; + float time{}; + float fov{}; + float tension{}; + float continuity{}; + float bias{}; }; struct RacingPathWaypoint { - uint8_t isResetNode; - uint8_t isNonHorizontalCamera; - float planeWidth; - float planeHeight; - float shortestDistanceToEnd; + uint8_t isResetNode{}; + uint8_t isNonHorizontalCamera{}; + float planeWidth{}; + float planeHeight{}; + float shortestDistanceToEnd{}; }; struct PathWaypoint { @@ -75,7 +75,7 @@ struct PathWaypoint { MovingPlatformPathWaypoint movingPlatform; CameraPathWaypoint camera; RacingPathWaypoint racing; - float speed; + float speed{}; std::vector config; std::vector commands; }; @@ -137,49 +137,49 @@ enum class PropertyAchievmentRequired : uint32_t { struct MovingPlatformPath { std::string platformTravelSound; - uint8_t timeBasedMovement; + uint8_t timeBasedMovement{}; }; struct PropertyPath { - PropertyPathType pathType; - int32_t price; - uint32_t rentalTime; - uint64_t associatedZone; + PropertyPathType pathType{}; + int32_t price{}; + uint32_t rentalTime{}; + uint64_t associatedZone{}; std::string displayName; std::string displayDesc; - PropertyType type; - uint32_t cloneLimit; - float repMultiplier; - PropertyRentalPeriod rentalPeriod; - PropertyAchievmentRequired achievementRequired; + PropertyType type{}; + uint32_t cloneLimit{}; + float repMultiplier{}; + PropertyRentalPeriod rentalPeriod{}; + PropertyAchievmentRequired achievementRequired{}; // Player respawn coordinates in the main zone (not the property zone) NiPoint3 playerZoneCoords; - float maxBuildHeight; + float maxBuildHeight{}; }; struct CameraPath { std::string nextPath; - uint8_t rotatePlayer; + uint8_t rotatePlayer{}; }; struct SpawnerPath { - LOT spawnedLOT; - uint32_t respawnTime; - int32_t maxToSpawn; - uint32_t amountMaintained; + LOT spawnedLOT{}; + uint32_t respawnTime{}; + int32_t maxToSpawn{}; + uint32_t amountMaintained{}; LWOOBJID spawnerObjID; - uint8_t spawnerNetActive; + uint8_t spawnerNetActive{}; }; struct Path { - uint32_t pathVersion; + uint32_t pathVersion{}; PathType pathType; std::string pathName; - uint32_t flags; + uint32_t flags{}; PathBehavior pathBehavior; - uint32_t waypointCount; + uint32_t waypointCount{}; std::vector pathWaypoints; SpawnerPath spawner; MovingPlatformPath movingPlatform; From 9d8e0a9c4a4ff62f623781f57a251985d69d152b Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 27 Mar 2024 00:10:39 -0500 Subject: [PATCH 04/10] unbreak the stacktraces (#1516) --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f2b1bb7..ae6455b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,9 @@ include(CTest) set(CMAKE_CXX_STANDARD 20) set(CXX_STANDARD_REQUIRED ON) -set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects -set(CMAKE_CXX_VISIBILITY_PRESET hidden) # Set C++ symbol visibility to default to hidden +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export the compile commands for debugging +set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects +set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # Read variables from file From 150031861d606ef873c342f177ab74908989ec5e Mon Sep 17 00:00:00 2001 From: jadebenn Date: Thu, 28 Mar 2024 21:32:46 -0500 Subject: [PATCH 05/10] Update README.md (#1518) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0dffaad..1caa0fb0 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ sudo apt install build-essential gcc zlib1g-dev libssl-dev openssl mariadb-serve ``` #### Required CMake version -This project uses **CMake version 3.18** or higher and as such you will need to ensure you have this version installed. +This project uses **CMake version 3.25** or higher and as such you will need to ensure you have this version installed. You can check your CMake version by using the following command in a terminal. ```bash cmake --version From 5996f3cbf4df8e72de2b04e371a6fb563ca5b196 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 30 Mar 2024 06:17:56 -0700 Subject: [PATCH 06/10] fix stewblaster stopping for non-players (#1521) fixes an issue when stew blaster would stop for non-players and would stand still permanently due to enemy hitboxes being removed. Tested that stewblaster only stops for players and starts moving when there are no players in the vicinity --- dGame/dComponents/MovementAIComponent.cpp | 2 ++ dScripts/02_server/Map/AM/WanderingVendor.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index 358d8d11..b6a16803 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -68,6 +68,7 @@ void MovementAIComponent::SetPath(const std::string pathName) { } void MovementAIComponent::Pause() { + if (m_Paused) return; m_Paused = true; SetPosition(ApproximateLocation()); m_SavedVelocity = GetVelocity(); @@ -76,6 +77,7 @@ void MovementAIComponent::Pause() { } void MovementAIComponent::Resume() { + if (!m_Paused) return; m_Paused = false; SetVelocity(m_SavedVelocity); m_SavedVelocity = NiPoint3Constant::ZERO; diff --git a/dScripts/02_server/Map/AM/WanderingVendor.cpp b/dScripts/02_server/Map/AM/WanderingVendor.cpp index 77259e2f..742741d3 100644 --- a/dScripts/02_server/Map/AM/WanderingVendor.cpp +++ b/dScripts/02_server/Map/AM/WanderingVendor.cpp @@ -1,6 +1,7 @@ #include "WanderingVendor.h" #include "MovementAIComponent.h" #include "ProximityMonitorComponent.h" +#include void WanderingVendor::OnStartup(Entity* self) { auto movementAIComponent = self->GetComponent(); @@ -19,7 +20,16 @@ void WanderingVendor::OnProximityUpdate(Entity* self, Entity* entering, std::str if (!proximityMonitorComponent) self->AddComponent(); const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor"); - if (proxObjs.empty()) self->AddTimer("startWalking", 1.5); + bool foundPlayer = false; + for (const auto id : proxObjs | std::views::keys) { + auto* entity = Game::entityManager->GetEntity(id); + if (entity && entity->IsPlayer()) { + foundPlayer = true; + break; + } + } + + if (!foundPlayer) self->AddTimer("startWalking", 1.5); } } From bbc0908989e386b88a84892b64a1fb37194752f1 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 30 Mar 2024 06:18:03 -0700 Subject: [PATCH 07/10] Update 9_Update_Leaderboard_Storage.sql (#1520) --- migrations/dlu/9_Update_Leaderboard_Storage.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/dlu/9_Update_Leaderboard_Storage.sql b/migrations/dlu/9_Update_Leaderboard_Storage.sql index c87e3501..9b5098eb 100644 --- a/migrations/dlu/9_Update_Leaderboard_Storage.sql +++ b/migrations/dlu/9_Update_Leaderboard_Storage.sql @@ -11,7 +11,7 @@ ALTER TABLE leaderboard CHANGE time secondaryScore FLOAT NOT NULL DEFAULT 0 AFTE /* A bit messy, but better than going through a bunch of code fixes all to be run once. */ UPDATE leaderboard SET primaryScore = secondaryScore, - secondaryScore = 0 WHERE game_id IN (1, 44, 46, 47, 48, 49, 53, 103, 104, 108, 1901); + secondaryScore = 0 WHERE game_id IN (1, 44, 46, 47, 48, 49, 53, 103, 104, 108, 1901) AND secondaryScore > 0; /* Do this last so we dont update entry times erroneously */ ALTER TABLE leaderboard From 884a41f36a7ca061afd90372eb5ff46d78f4fa0c Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 30 Mar 2024 09:16:06 -0700 Subject: [PATCH 08/10] update to current knowledge (#1523) Should be 100% live accurate as far as logic and bitstream reads goes. Tested with all valiant weapons and crux prime weapons (drops from dragons) that combat does not desync and that the client reports the same level and amount of skill deserialize issues as before. --- dGame/dBehaviors/InterruptBehavior.cpp | 51 +++++++++++++++++--------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/dGame/dBehaviors/InterruptBehavior.cpp b/dGame/dBehaviors/InterruptBehavior.cpp index 0b23c34d..c2f2fe70 100644 --- a/dGame/dBehaviors/InterruptBehavior.cpp +++ b/dGame/dBehaviors/InterruptBehavior.cpp @@ -8,36 +8,50 @@ void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) { - if (branch.target != context->originator) { - bool unknown = false; + LWOOBJID usedTarget = m_target ? branch.target : context->originator; - if (!bitStream.Read(unknown)) { - LOG("Unable to read unknown1 from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); + if (usedTarget != context->originator) { + bool isTargetImmuneStuns = false; + if (!bitStream.Read(isTargetImmuneStuns)) { + LOG("Unable to read isTargetImmune from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); return; }; - if (unknown) return; + if (isTargetImmuneStuns) return; } if (!this->m_interruptBlock) { - bool unknown = false; - - if (!bitStream.Read(unknown)) { - LOG("Unable to read unknown2 from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); + bool isBlockingInterrupts = false; + if (!bitStream.Read(isBlockingInterrupts)) { + LOG("Unable to read isBlockingInterrupts from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); return; }; - if (unknown) return; + if (isBlockingInterrupts) return; } - if (this->m_target) // Guess... - { - bool unknown = false; + bool hasInterruptedStatusEffects = false; + if (!bitStream.Read(hasInterruptedStatusEffects)) { + LOG("Unable to read hasInterruptedStatusEffects from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); + return; + }; - if (!bitStream.Read(unknown)) { - LOG("Unable to read unknown3 from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits()); - return; - }; + if (hasInterruptedStatusEffects) { + bool hasMoreInterruptedStatusEffects = false; + int32_t loopLimit = 0; + while (bitStream.Read(hasMoreInterruptedStatusEffects) && hasMoreInterruptedStatusEffects) { + int32_t statusEffectID = 0; + bitStream.Read(statusEffectID); + // nothing happens with this data yes. I have no idea why or what it was used for, but the client literally just reads it and does nothing with it. + // 0x004faca4 for a reference. it also has a hard loop limit of 100 soo, + loopLimit++; + if (loopLimit > 100) { + // if this is hit you have a problem + LOG("Loop limit reached for interrupted status effects, aborting Handle due to bad bitstream! %i", bitStream.GetNumberOfUnreadBits()); + break; + } + LOG_DEBUG("Interrupted status effect ID: %i", statusEffectID); + } } if (branch.target == context->originator) return; @@ -55,7 +69,8 @@ void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitS void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) { - if (branch.target != context->originator) { + LWOOBJID usedTarget = m_target ? branch.target : context->originator; + if (usedTarget != context->originator) { bitStream.Write(false); } From c1c5db6593ea74b6482f044450ea48414c4d04b7 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:46:51 -0700 Subject: [PATCH 09/10] update4 fp check (#1524) --- dCommon/GeneralUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index c3422b05..d502f55a 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -166,7 +166,7 @@ namespace GeneralUtils { return isParsed ? static_cast(result) : std::optional{}; } -#ifdef DARKFLAME_PLATFORM_MACOS +#if !(__GNUC__ >= 11 || _MSC_VER >= 1924) // MacOS floating-point parse helper function specializations namespace details { From 20408d8dfea510bb8a3e94bf8d0f825616940341 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 31 Mar 2024 22:27:50 -0500 Subject: [PATCH 10/10] chore: remove chat_internal and processes everything over chat connection (#1508) * WIP * get rid of redundent case and some formatting issues * move some things around for cleaner diffs * remove dead code that does nothing and add connection check * fix whitespace * address feedback --- dChatServer/ChatIgnoreList.cpp | 4 +- dChatServer/ChatPacketHandler.cpp | 27 ++- dChatServer/ChatServer.cpp | 79 ++++----- dChatServer/PlayerContainer.cpp | 6 +- dCommon/dEnums/eChatInternalMessageType.h | 31 ---- dCommon/dEnums/eChatMessageType.h | 4 +- dCommon/dEnums/eConnectionType.h | 3 +- dGame/UserManager.cpp | 4 +- dGame/dComponents/ActivityComponent.cpp | 4 +- dGame/dUtilities/SlashCommandHandler.cpp | 6 +- dWorldServer/WorldServer.cpp | 190 +++++++++++----------- 11 files changed, 151 insertions(+), 207 deletions(-) delete mode 100644 dCommon/dEnums/eChatInternalMessageType.h diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index f0c55eb0..6dfbd7fc 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -1,6 +1,6 @@ #include "ChatIgnoreList.h" #include "PlayerContainer.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "BitStreamUtils.h" #include "Game.h" #include "Logger.h" @@ -13,7 +13,7 @@ // The only thing not auto-handled is instance activities force joining the team on the server. void WriteOutgoingReplyHeader(RakNet::BitStream& bitStream, const LWOOBJID& receivingPlayer, const ChatIgnoreList::Response type) { - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receivingPlayer); //portion that will get routed: diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 5e2e58d7..d37777b6 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -14,7 +14,6 @@ #include "eObjectBits.h" #include "eConnectionType.h" #include "eChatMessageType.h" -#include "eChatInternalMessageType.h" #include "eClientMessageType.h" #include "eGameMessageType.h" #include "StringifiedEnum.h" @@ -60,7 +59,7 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) { //Now, we need to send the friendlist to the server they came from: CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(playerID); //portion that will get routed: @@ -454,7 +453,7 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) { void ChatPacketHandler::SendPrivateChatMessage(const PlayerData& sender, const PlayerData& receiver, const PlayerData& routeTo, const LUWString& message, const eChatChannel channel, const eChatMessageResponseCode responseCode) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(routeTo.playerID); BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE); @@ -696,7 +695,7 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) { void ChatPacketHandler::SendTeamInvite(const PlayerData& receiver, const PlayerData& sender) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -711,7 +710,7 @@ void ChatPacketHandler::SendTeamInvite(const PlayerData& receiver, const PlayerD void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -738,7 +737,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool b void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -763,7 +762,7 @@ void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64L void ChatPacketHandler::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i64PlayerID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -780,7 +779,7 @@ void ChatPacketHandler::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i void ChatPacketHandler::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -809,7 +808,7 @@ void ChatPacketHandler::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFr void ChatPacketHandler::SendTeamRemovePlayer(const PlayerData& receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -835,7 +834,7 @@ void ChatPacketHandler::SendTeamRemovePlayer(const PlayerData& receiver, bool bD void ChatPacketHandler::SendTeamSetOffWorldFlag(const PlayerData& receiver, LWOOBJID i64PlayerID, LWOZONEID zoneID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -869,7 +868,7 @@ void ChatPacketHandler::SendFriendUpdate(const PlayerData& friendData, const Pla [bool] - is FTP*/ CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(friendData.playerID); //portion that will get routed: @@ -906,7 +905,7 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play } CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -920,7 +919,7 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const PlayerData& sender, eAddFriendResponseType responseCode, uint8_t isBestFriendsAlready, uint8_t isBestFriendRequest) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); // Portion that will get routed: @@ -943,7 +942,7 @@ void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const Pla void ChatPacketHandler::SendRemoveFriend(const PlayerData& receiver, std::string& personToRemove, bool isSuccessful) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: diff --git a/dChatServer/ChatServer.cpp b/dChatServer/ChatServer.cpp index 84104726..cc938c3c 100644 --- a/dChatServer/ChatServer.cpp +++ b/dChatServer/ChatServer.cpp @@ -17,7 +17,6 @@ #include "PlayerContainer.h" #include "ChatPacketHandler.h" #include "eChatMessageType.h" -#include "eChatInternalMessageType.h" #include "eWorldMessageType.h" #include "ChatIgnoreList.h" #include "StringifiedEnum.h" @@ -182,47 +181,29 @@ int main(int argc, char** argv) { void HandlePacket(Packet* packet) { if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { LOG("A server has disconnected, erasing their connected players from the list."); - } - - if (packet->data[0] == ID_NEW_INCOMING_CONNECTION) { + } else if (packet->data[0] == ID_NEW_INCOMING_CONNECTION) { LOG("A server is connecting, awaiting user list."); - } + } else if (packet->length < 4 || packet->data[0] != ID_USER_PACKET_ENUM) return; // Nothing left to process or not the right packet type - if (packet->length < 4) return; // Nothing left to process. Need 4 bytes to continue. + CINSTREAM; + inStream.SetReadOffset(BYTES_TO_BITS(1)); - if (static_cast(packet->data[1]) == eConnectionType::CHAT_INTERNAL) { - switch (static_cast(packet->data[3])) { - case eChatInternalMessageType::PLAYER_ADDED_NOTIFICATION: - Game::playerContainer.InsertPlayer(packet); - break; + eConnectionType connection; + eChatMessageType chatMessageID; - case eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION: - Game::playerContainer.RemovePlayer(packet); - break; - - case eChatInternalMessageType::MUTE_UPDATE: + inStream.Read(connection); + if (connection != eConnectionType::CHAT) return; + inStream.Read(chatMessageID); + + switch (chatMessageID) { + case eChatMessageType::GM_MUTE: Game::playerContainer.MuteUpdate(packet); break; - case eChatInternalMessageType::CREATE_TEAM: + case eChatMessageType::CREATE_TEAM: Game::playerContainer.CreateTeamServer(packet); break; - case eChatInternalMessageType::ANNOUNCEMENT: { - //we just forward this packet to every connected server - CINSTREAM; - Game::server->Send(inStream, packet->systemAddress, true); //send to everyone except origin - break; - } - - default: - LOG("Unknown CHAT_INTERNAL id: %i", int(packet->data[3])); - } - } - - if (static_cast(packet->data[1]) == eConnectionType::CHAT) { - eChatMessageType chat_message_type = static_cast(packet->data[3]); - switch (chat_message_type) { case eChatMessageType::GET_FRIENDS_LIST: ChatPacketHandler::HandleFriendlistRequest(packet); break; @@ -296,6 +277,19 @@ void HandlePacket(Packet* packet) { ChatPacketHandler::HandleGMLevelUpdate(packet); break; case eChatMessageType::LOGIN_SESSION_NOTIFY: + Game::playerContainer.InsertPlayer(packet); + break; + case eChatMessageType::GM_ANNOUNCE:{ + // we just forward this packet to every connected server + inStream.ResetReadPointer(); + Game::server->Send(inStream, packet->systemAddress, true); // send to everyone except origin + } + break; + case eChatMessageType::UNEXPECTED_DISCONNECT: + Game::playerContainer.RemovePlayer(packet); + break; + case eChatMessageType::WHO: + case eChatMessageType::SHOW_ALL: case eChatMessageType::USER_CHANNEL_CHAT_MESSAGE: case eChatMessageType::WORLD_DISCONNECT_REQUEST: case eChatMessageType::WORLD_PROXIMITY_RESPONSE: @@ -308,7 +302,6 @@ void HandlePacket(Packet* packet) { case eChatMessageType::GUILD_KICK: case eChatMessageType::GUILD_GET_STATUS: case eChatMessageType::GUILD_GET_ALL: - case eChatMessageType::SHOW_ALL: case eChatMessageType::BLUEPRINT_MODERATED: case eChatMessageType::BLUEPRINT_MODEL_READY: case eChatMessageType::PROPERTY_READY_FOR_APPROVAL: @@ -323,7 +316,6 @@ void HandlePacket(Packet* packet) { case eChatMessageType::CSR_REQUEST: case eChatMessageType::CSR_REPLY: case eChatMessageType::GM_KICK: - case eChatMessageType::GM_ANNOUNCE: case eChatMessageType::WORLD_ROUTE_PACKET: case eChatMessageType::GET_ZONE_POPULATIONS: case eChatMessageType::REQUEST_MINIMUM_CHAT_MODE: @@ -332,33 +324,18 @@ void HandlePacket(Packet* packet) { case eChatMessageType::UGCMANIFEST_REPORT_DONE_FILE: case eChatMessageType::UGCMANIFEST_REPORT_DONE_BLUEPRINT: case eChatMessageType::UGCC_REQUEST: - case eChatMessageType::WHO: case eChatMessageType::WORLD_PLAYERS_PET_MODERATED_ACKNOWLEDGE: case eChatMessageType::ACHIEVEMENT_NOTIFY: case eChatMessageType::GM_CLOSE_PRIVATE_CHAT_WINDOW: - case eChatMessageType::UNEXPECTED_DISCONNECT: case eChatMessageType::PLAYER_READY: case eChatMessageType::GET_DONATION_TOTAL: case eChatMessageType::UPDATE_DONATION: case eChatMessageType::PRG_CSR_COMMAND: case eChatMessageType::HEARTBEAT_REQUEST_FROM_WORLD: case eChatMessageType::UPDATE_FREE_TRIAL_STATUS: - LOG("Unhandled CHAT Message id: %s (%i)", StringifiedEnum::ToString(chat_message_type).data(), chat_message_type); + LOG("Unhandled CHAT Message id: %s (%i)", StringifiedEnum::ToString(chatMessageID).data(), chatMessageID); break; default: - LOG("Unknown CHAT Message id: %i", chat_message_type); - } - } - - if (static_cast(packet->data[1]) == eConnectionType::WORLD) { - switch (static_cast(packet->data[3])) { - case eWorldMessageType::ROUTE_PACKET: { - LOG("Routing packet from world"); - break; - } - - default: - LOG("Unknown World id: %i", int(packet->data[3])); - } + LOG("Unknown CHAT Message id: %i", chatMessageID); } } diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 7feff763..57b3f233 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -9,9 +9,9 @@ #include "BitStreamUtils.h" #include "Database.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" #include "ChatPackets.h" #include "dConfig.h" +#include "eChatMessageType.h" void PlayerContainer::Initialize() { m_MaxNumberOfBestFriends = @@ -145,7 +145,7 @@ void PlayerContainer::CreateTeamServer(Packet* packet) { void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_MUTE); bitStream.Write(player); bitStream.Write(time); @@ -352,7 +352,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team) { void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::TEAM_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::TEAM_GET_STATUS); bitStream.Write(team->teamID); bitStream.Write(deleteTeam); diff --git a/dCommon/dEnums/eChatInternalMessageType.h b/dCommon/dEnums/eChatInternalMessageType.h deleted file mode 100644 index d3b7020b..00000000 --- a/dCommon/dEnums/eChatInternalMessageType.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __ECHATINTERNALMESSAGETYPE__H__ -#define __ECHATINTERNALMESSAGETYPE__H__ - -#include - -enum eChatInternalMessageType : uint32_t { - PLAYER_ADDED_NOTIFICATION = 0, - PLAYER_REMOVED_NOTIFICATION, - ADD_FRIEND, - ADD_BEST_FRIEND, - ADD_TO_TEAM, - ADD_BLOCK, - REMOVE_FRIEND, - REMOVE_BLOCK, - REMOVE_FROM_TEAM, - DELETE_TEAM, - REPORT, - PRIVATE_CHAT, - PRIVATE_CHAT_RESPONSE, - ANNOUNCEMENT, - MAIL_COUNT_UPDATE, - MAIL_SEND_NOTIFY, - REQUEST_USER_LIST, - FRIEND_LIST, - ROUTE_TO_PLAYER, - TEAM_UPDATE, - MUTE_UPDATE, - CREATE_TEAM, -}; - -#endif //!__ECHATINTERNALMESSAGETYPE__H__ diff --git a/dCommon/dEnums/eChatMessageType.h b/dCommon/dEnums/eChatMessageType.h index 52895ba3..38cd86de 100644 --- a/dCommon/dEnums/eChatMessageType.h +++ b/dCommon/dEnums/eChatMessageType.h @@ -72,7 +72,9 @@ enum class eChatMessageType :uint32_t { UPDATE_DONATION, PRG_CSR_COMMAND, HEARTBEAT_REQUEST_FROM_WORLD, - UPDATE_FREE_TRIAL_STATUS + UPDATE_FREE_TRIAL_STATUS, + // CUSTOM DLU MESSAGE ID FOR INTERNAL USE + CREATE_TEAM, }; #endif //!__ECHATMESSAGETYPE__H__ diff --git a/dCommon/dEnums/eConnectionType.h b/dCommon/dEnums/eConnectionType.h index ce1ff90c..406110a9 100644 --- a/dCommon/dEnums/eConnectionType.h +++ b/dCommon/dEnums/eConnectionType.h @@ -5,8 +5,7 @@ enum class eConnectionType : uint16_t { SERVER = 0, AUTH, CHAT, - CHAT_INTERNAL, - WORLD, + WORLD = 4, CLIENT, MASTER }; diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 0fde2eb6..b94e9de5 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -26,7 +26,7 @@ #include "eCharacterCreationResponse.h" #include "eRenameResponse.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "BitStreamUtils.h" #include "CheatDetection.h" @@ -422,7 +422,7 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) Database::Get()->DeleteCharacter(charID); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::UNEXPECTED_DISCONNECT); bitStream.Write(objectID); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index ce82abe0..1b2fc338 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -21,7 +21,7 @@ #include "eMissionTaskType.h" #include "eMatchUpdate.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "CDCurrencyTableTable.h" #include "CDActivityRewardsTable.h" @@ -501,7 +501,7 @@ void ActivityInstance::StartZone() { // only make a team if we have more than one participant if (participants.size() > 1) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::CREATE_TEAM); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::CREATE_TEAM); bitStream.Write(leader->GetObjectID()); bitStream.Write(m_Participants.size()); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index d0620121..0b26e85a 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -79,7 +79,7 @@ #include "RenderComponent.h" #include "eControlScheme.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "eMasterMessageType.h" #include "PlayerManager.h" @@ -1063,7 +1063,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit //Notify chat about it CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_MUTE); bitStream.Write(characterId); bitStream.Write(expire); @@ -2078,7 +2078,7 @@ void SlashCommandHandler::SendAnnouncement(const std::string& title, const std:: //Notify chat about it CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ANNOUNCEMENT); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_ANNOUNCE); bitStream.Write(title.size()); for (auto character : title) { diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 5f7a8b3e..1c85ef22 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -66,7 +66,7 @@ #include "eObjectBits.h" #include "eConnectionType.h" #include "eServerMessageType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "eWorldMessageType.h" #include "eMasterMessageType.h" #include "eGameMessageType.h" @@ -541,118 +541,116 @@ void HandlePacketChat(Packet* packet) { } if (packet->data[0] == ID_USER_PACKET_ENUM) { - if (static_cast(packet->data[1]) == eConnectionType::CHAT_INTERNAL) { - switch (static_cast(packet->data[3])) { - case eChatInternalMessageType::ROUTE_TO_PLAYER: { - CINSTREAM_SKIP_HEADER; - LWOOBJID playerID; - inStream.Read(playerID); + if (static_cast(packet->data[1]) == eConnectionType::CHAT) { + switch (static_cast(packet->data[3])) { + case eChatMessageType::WORLD_ROUTE_PACKET: { + CINSTREAM_SKIP_HEADER; + LWOOBJID playerID; + inStream.Read(playerID); - auto player = Game::entityManager->GetEntity(playerID); - if (!player) return; + auto player = Game::entityManager->GetEntity(playerID); + if (!player) return; - auto sysAddr = player->GetSystemAddress(); + auto sysAddr = player->GetSystemAddress(); - //Write our stream outwards: - CBITSTREAM; - for (BitSize_t i = 0; i < inStream.GetNumberOfBytesUsed(); i++) { - bitStream.Write(packet->data[i + 16]); //16 bytes == header + playerID to skip + //Write our stream outwards: + CBITSTREAM; + for (BitSize_t i = 0; i < inStream.GetNumberOfBytesUsed(); i++) { + bitStream.Write(packet->data[i + 16]); //16 bytes == header + playerID to skip + } + + SEND_PACKET; //send routed packet to player + break; } - SEND_PACKET; //send routed packet to player + case eChatMessageType::GM_ANNOUNCE: { + CINSTREAM_SKIP_HEADER; - break; - } + std::string title; + std::string msg; - case eChatInternalMessageType::ANNOUNCEMENT: { - CINSTREAM_SKIP_HEADER; + uint32_t len; + inStream.Read(len); + for (uint32_t i = 0; len > i; i++) { + char character; + inStream.Read(character); + title += character; + } - std::string title; - std::string msg; + len = 0; + inStream.Read(len); + for (uint32_t i = 0; len > i; i++) { + char character; + inStream.Read(character); + msg += character; + } - uint32_t len; - inStream.Read(len); - for (uint32_t i = 0; len > i; i++) { - char character; - inStream.Read(character); - title += character; - } + //Send to our clients: + AMFArrayValue args; - len = 0; - inStream.Read(len); - for (uint32_t i = 0; len > i; i++) { - char character; - inStream.Read(character); - msg += character; - } + args.Insert("title", title); + args.Insert("message", msg); - //Send to our clients: - AMFArrayValue args; - - args.Insert("title", title); - args.Insert("message", msg); - - GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args); - - break; - } - - case eChatInternalMessageType::MUTE_UPDATE: { - CINSTREAM_SKIP_HEADER; - LWOOBJID playerId; - time_t expire = 0; - inStream.Read(playerId); - inStream.Read(expire); - - auto* entity = Game::entityManager->GetEntity(playerId); - auto* character = entity != nullptr ? entity->GetCharacter() : nullptr; - auto* user = character != nullptr ? character->GetParentUser() : nullptr; - if (user) { - user->SetMuteExpire(expire); - - entity->GetCharacter()->SendMuteNotice(); - } - - break; - } - - case eChatInternalMessageType::TEAM_UPDATE: { - CINSTREAM_SKIP_HEADER; - - LWOOBJID teamID = 0; - char lootOption = 0; - char memberCount = 0; - std::vector members; - - inStream.Read(teamID); - bool deleteTeam = inStream.ReadBit(); - - if (deleteTeam) { - TeamManager::Instance()->DeleteTeam(teamID); - - LOG("Deleting team (%llu)", teamID); + GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args); break; } - inStream.Read(lootOption); - inStream.Read(memberCount); - LOG("Updating team (%llu), (%i), (%i)", teamID, lootOption, memberCount); - for (char i = 0; i < memberCount; i++) { - LWOOBJID member = LWOOBJID_EMPTY; - inStream.Read(member); - members.push_back(member); + case eChatMessageType::GM_MUTE: { + CINSTREAM_SKIP_HEADER; + LWOOBJID playerId; + time_t expire = 0; + inStream.Read(playerId); + inStream.Read(expire); - LOG("Updating team member (%llu)", member); + auto* entity = Game::entityManager->GetEntity(playerId); + auto* character = entity != nullptr ? entity->GetCharacter() : nullptr; + auto* user = character != nullptr ? character->GetParentUser() : nullptr; + if (user) { + user->SetMuteExpire(expire); + + entity->GetCharacter()->SendMuteNotice(); + } + + break; } - TeamManager::Instance()->UpdateTeam(teamID, lootOption, members); + case eChatMessageType::TEAM_GET_STATUS: { + CINSTREAM_SKIP_HEADER; - break; - } + LWOOBJID teamID = 0; + char lootOption = 0; + char memberCount = 0; + std::vector members; - default: - LOG("Received an unknown chat internal: %i", int(packet->data[3])); + inStream.Read(teamID); + bool deleteTeam = inStream.ReadBit(); + + if (deleteTeam) { + TeamManager::Instance()->DeleteTeam(teamID); + + LOG("Deleting team (%llu)", teamID); + + break; + } + + inStream.Read(lootOption); + inStream.Read(memberCount); + LOG("Updating team (%llu), (%i), (%i)", teamID, lootOption, memberCount); + for (char i = 0; i < memberCount; i++) { + LWOOBJID member = LWOOBJID_EMPTY; + inStream.Read(member); + members.push_back(member); + + LOG("Updating team member (%llu)", member); + } + + TeamManager::Instance()->UpdateTeam(teamID, lootOption, members); + + break; + } + default: + LOG("Received an unknown chat: %i", int(packet->data[3])); } } } @@ -817,7 +815,7 @@ void HandlePacket(Packet* packet) { { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::UNEXPECTED_DISCONNECT); bitStream.Write(user->GetLoggedInChar()); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -986,7 +984,7 @@ void HandlePacket(Packet* packet) { // This means we swapped characters and we need to remove the previous player from the container. if (static_cast(lastCharacter) != playerID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::UNEXPECTED_DISCONNECT); bitStream.Write(lastCharacter); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -1132,7 +1130,7 @@ void HandlePacket(Packet* packet) { const auto& playerName = character->GetName(); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_ADDED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::LOGIN_SESSION_NOTIFY); bitStream.Write(player->GetObjectID()); bitStream.Write(playerName.size()); for (size_t i = 0; i < playerName.size(); i++) {