mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-11-25 02:38:27 +00:00
Merge branch 'DarkflameUniverse:main' into PetFixes
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include <vector>
|
||||
#include "../thirdparty/tinyxml2/tinyxml2.h"
|
||||
#include "tinyxml2.h"
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "CDClientManager.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include <PacketUtils.h>
|
||||
#include "PacketUtils.h"
|
||||
#include <functional>
|
||||
#include "CDDestructibleComponentTable.h"
|
||||
#include "CDClientDatabase.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "RakNetTypes.h"
|
||||
#include "Game.h"
|
||||
#include "User.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "Character.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "dServer.h"
|
||||
@@ -89,7 +89,7 @@ Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentE
|
||||
|
||||
// Entities with no ID already set, often spawned entities, we'll generate a new sequencial ID
|
||||
if (info.id == 0) {
|
||||
id = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
id = ObjectIDManager::GenerateObjectID();
|
||||
}
|
||||
|
||||
// Entities with an ID already set, often level entities, we'll use that ID as a base
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "EntityManager.h"
|
||||
#include "GameMessages.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "Item.h"
|
||||
@@ -273,7 +273,7 @@ void TradingManager::CancelTrade(LWOOBJID tradeId) {
|
||||
}
|
||||
|
||||
Trade* TradingManager::NewTrade(LWOOBJID participantA, LWOOBJID participantB) {
|
||||
const LWOOBJID tradeId = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
const LWOOBJID tradeId = ObjectIDManager::GenerateObjectID();
|
||||
|
||||
auto* trade = new Trade(tradeId, participantA, participantB);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../thirdparty/raknet/Source/RakNetTypes.h"
|
||||
#include "RakNetTypes.h"
|
||||
#include "dCommonVars.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "User.h"
|
||||
#include <WorldPackets.h>
|
||||
#include "WorldPackets.h"
|
||||
#include "Character.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "Logger.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
@@ -263,7 +263,7 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
}
|
||||
|
||||
//Now that the name is ok, we can get an objectID from Master:
|
||||
ObjectIDManager::Instance()->RequestPersistentID([=, this](uint32_t objectID) {
|
||||
ObjectIDManager::RequestPersistentID([=, this](uint32_t objectID) {
|
||||
if (Database::Get()->GetCharacterInfo(objectID)) {
|
||||
LOG("Character object id unavailable, check object_id_tracker!");
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::OBJECT_ID_UNAVAILABLE);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "SkillComponent.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "eObjectBits.h"
|
||||
|
||||
void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
@@ -106,7 +106,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
const auto maxTime = this->m_maxDistance / this->m_projectileSpeed;
|
||||
|
||||
for (auto i = 0u; i < this->m_projectileCount; ++i) {
|
||||
auto id = static_cast<LWOOBJID>(ObjectIDManager::Instance()->GenerateObjectID());
|
||||
auto id = static_cast<LWOOBJID>(ObjectIDManager::GenerateObjectID());
|
||||
|
||||
GeneralUtils::SetBit(id, eObjectBits::SPAWNED);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "ZoneInstanceManager.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include <WorldPackets.h>
|
||||
#include "WorldPackets.h"
|
||||
#include "EntityManager.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "Player.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "BaseCombatAIComponent.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "GameMessages.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include "eTriggerEventType.h"
|
||||
|
||||
BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "BuffComponent.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include <stdexcept>
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "CharacterComponent.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include "tinyxml2.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../thirdparty/tinyxml2/tinyxml2.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "DestroyableComponent.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "MissionComponent.h"
|
||||
#include "GameMessages.h"
|
||||
#include "SkillComponent.h"
|
||||
@@ -68,7 +68,7 @@ InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* do
|
||||
continue;
|
||||
}
|
||||
|
||||
const LWOOBJID id = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
const LWOOBJID id = ObjectIDManager::GenerateObjectID();
|
||||
|
||||
const auto& info = Inventory::FindItemComponent(item.itemid);
|
||||
|
||||
@@ -86,7 +86,7 @@ InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* do
|
||||
const auto proxyLOT = static_cast<LOT>(std::stoi(proxyLotAsString));
|
||||
|
||||
const auto& proxyInfo = Inventory::FindItemComponent(proxyLOT);
|
||||
const LWOOBJID proxyId = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
const LWOOBJID proxyId = ObjectIDManager::GenerateObjectID();
|
||||
|
||||
// Use item.count since we equip item.count number of the item this is a requested proxy of
|
||||
UpdateSlot(proxyInfo.equipLocation, { proxyId, proxyLOT, item.count, slot++ });
|
||||
@@ -1341,7 +1341,7 @@ void InventoryComponent::SetNPCItems(const std::vector<LOT>& items) {
|
||||
auto slot = 0u;
|
||||
|
||||
for (const auto& item : items) {
|
||||
const LWOOBJID id = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
const LWOOBJID id = ObjectIDManager::GenerateObjectID();
|
||||
|
||||
const auto& info = Inventory::FindItemComponent(item);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
#include "dpWorld.h"
|
||||
#include "PetDigServer.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "eUnequippableActiveType.h"
|
||||
#include "eTerminateType.h"
|
||||
#include "ePetTamingNotifyType.h"
|
||||
@@ -460,7 +460,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
|
||||
auto* inventoryComponent = tamer->GetComponent<InventoryComponent>();
|
||||
if (!inventoryComponent) return;
|
||||
|
||||
LWOOBJID petSubKey = ObjectIDManager::Instance()->GenerateRandomObjectID();
|
||||
LWOOBJID petSubKey = ObjectIDManager::GenerateRandomObjectID();
|
||||
|
||||
GeneralUtils::SetBit(petSubKey, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(petSubKey, eObjectBits::PERSISTENT);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "PropertyEntranceComponent.h"
|
||||
|
||||
#include <CDPropertyEntranceComponentTable.h>
|
||||
#include "CDPropertyEntranceComponentTable.h"
|
||||
|
||||
#include "Character.h"
|
||||
#include "Database.h"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "Game.h"
|
||||
#include "Item.h"
|
||||
#include "Database.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "Player.h"
|
||||
#include "RocketLaunchpadControlComponent.h"
|
||||
#include "PropertyEntranceComponent.h"
|
||||
@@ -334,7 +334,7 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
node->position = position;
|
||||
node->rotation = rotation;
|
||||
|
||||
ObjectIDManager::Instance()->RequestPersistentID([this, node, modelLOT, entity, position, rotation, originalRotation](uint32_t persistentId) {
|
||||
ObjectIDManager::RequestPersistentID([this, node, modelLOT, entity, position, rotation, originalRotation](uint32_t persistentId) {
|
||||
SpawnerInfo info{};
|
||||
|
||||
info.templateID = modelLOT;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef QUICKBUILDCOMPONENT_H
|
||||
#define QUICKBUILDCOMPONENT_H
|
||||
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "dCommonVars.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef RENDERCOMPONENT_H
|
||||
#define RENDERCOMPONENT_H
|
||||
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "MissionComponent.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "dServer.h"
|
||||
#include "../thirdparty/raknet/Source/RakNetworkFactory.h"
|
||||
#include "RakNetworkFactory.h"
|
||||
#include <future>
|
||||
#include "User.h"
|
||||
#include "UserManager.h"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "EntityManager.h"
|
||||
#include "Database.h"
|
||||
#include "dServer.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "CppScripts.h"
|
||||
#include "UserManager.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
@@ -52,7 +52,7 @@
|
||||
#include <chrono>
|
||||
#include "RakString.h"
|
||||
|
||||
#include "../thirdparty/cpp-httplib/httplib.h" //sorry not sorry.
|
||||
#include "httplib.h" //sorry not sorry.
|
||||
|
||||
//CDB includes:
|
||||
#include "CDClientManager.h"
|
||||
@@ -1058,7 +1058,7 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID,
|
||||
LWOOBJID owner = entity->GetObjectID();
|
||||
|
||||
if (item != LOT_NULL && item != 0) {
|
||||
lootID = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
lootID = ObjectIDManager::GenerateObjectID();
|
||||
|
||||
Loot::Info info;
|
||||
info.id = lootID;
|
||||
@@ -2578,12 +2578,12 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
//But we don't want the server to go unresponsive, because then the client would disconnect.
|
||||
|
||||
//We need to get a new ID for our model first:
|
||||
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t newID) {
|
||||
ObjectIDManager::RequestPersistentID([=](uint32_t newID) {
|
||||
LWOOBJID newIDL = newID;
|
||||
GeneralUtils::SetBit(newIDL, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(newIDL, eObjectBits::PERSISTENT);
|
||||
|
||||
uint32_t blueprintIDSmall = ObjectIDManager::Instance()->GenerateRandomObjectID();
|
||||
uint32_t blueprintIDSmall = ObjectIDManager::GenerateRandomObjectID();
|
||||
LWOOBJID blueprintID = blueprintIDSmall;
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
||||
@@ -5605,7 +5605,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity*
|
||||
}
|
||||
}
|
||||
|
||||
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t newId) {
|
||||
ObjectIDManager::RequestPersistentID([=](uint32_t newId) {
|
||||
LOG("Build finished");
|
||||
GameMessages::SendFinishArrangingWithItem(character, entity->GetObjectID()); // kick them from modular build
|
||||
GameMessages::SendModularBuildEnd(character); // i dont know if this does anything but DLUv2 did it
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Entity.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Game.h"
|
||||
#include "GameMessages.h"
|
||||
#include "ModelComponent.h"
|
||||
#include "../../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "Logger.h"
|
||||
#include "BehaviorStates.h"
|
||||
#include "AssetManager.h"
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "UpdateStripUiMessage.h"
|
||||
|
||||
void ControlBehaviors::RequestUpdatedID(ControlBehaviorContext& context) {
|
||||
ObjectIDManager::Instance()->RequestPersistentID(
|
||||
ObjectIDManager::RequestPersistentID(
|
||||
[context](uint32_t persistentId) {
|
||||
if (!context) {
|
||||
LOG("Model to update behavior ID for is null. Cannot update ID.");
|
||||
|
||||
@@ -3,6 +3,7 @@ set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
|
||||
"GUID.cpp"
|
||||
"Loot.cpp"
|
||||
"Mail.cpp"
|
||||
"ObjectIDManager.cpp"
|
||||
"Preconditions.cpp"
|
||||
"SlashCommandHandler.cpp"
|
||||
"VanityUtilities.cpp")
|
||||
|
||||
51
dGame/dUtilities/ObjectIDManager.cpp
Normal file
51
dGame/dUtilities/ObjectIDManager.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "ObjectIDManager.h"
|
||||
|
||||
// Custom Classes
|
||||
#include "MasterPackets.h"
|
||||
#include "Database.h"
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
|
||||
//! The persistent ID request
|
||||
struct PersistentIDRequest {
|
||||
PersistentIDRequest(const uint64_t& requestID, const std::function<void(uint32_t)>& callback) : requestID(requestID), callback(callback) {}
|
||||
uint64_t requestID;
|
||||
|
||||
std::function<void(uint32_t)> callback;
|
||||
};
|
||||
|
||||
namespace {
|
||||
std::vector<PersistentIDRequest> Requests; //!< All outstanding persistent ID requests
|
||||
uint64_t CurrentRequestID = 0; //!< The current request ID
|
||||
uint32_t CurrentObjectID = uint32_t(1152921508165007067); //!< The current object ID
|
||||
std::uniform_int_distribution<int> Uni(10000000, INT32_MAX);
|
||||
};
|
||||
|
||||
//! Requests a persistent ID
|
||||
void ObjectIDManager::RequestPersistentID(const std::function<void(uint32_t)> callback) {
|
||||
const auto& request = Requests.emplace_back(++CurrentRequestID, callback);
|
||||
|
||||
MasterPackets::SendPersistentIDRequest(Game::server, request.requestID);
|
||||
}
|
||||
|
||||
//! Handles a persistent ID response
|
||||
void ObjectIDManager::HandleRequestPersistentIDResponse(const uint64_t requestID, const uint32_t persistentID) {
|
||||
auto it = std::find_if(Requests.begin(), Requests.end(), [requestID](const PersistentIDRequest& request) {
|
||||
return request.requestID == requestID;
|
||||
});
|
||||
|
||||
if (it == Requests.end()) return;
|
||||
|
||||
it->callback(persistentID);
|
||||
Requests.erase(it);
|
||||
}
|
||||
|
||||
//! Handles cases where we have to get a unique object ID synchronously
|
||||
uint32_t ObjectIDManager::GenerateRandomObjectID() {
|
||||
return Uni(Game::randomEngine);
|
||||
}
|
||||
|
||||
//! Generates an object ID server-sided (used for regular entities like smashables)
|
||||
uint32_t ObjectIDManager::GenerateObjectID() {
|
||||
return ++CurrentObjectID;
|
||||
}
|
||||
40
dGame/dUtilities/ObjectIDManager.h
Normal file
40
dGame/dUtilities/ObjectIDManager.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
// C++
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
/*!
|
||||
\file ObjectIDManager.h
|
||||
\brief A manager for handling object ID generation
|
||||
*/
|
||||
|
||||
//! The Object ID Manager
|
||||
namespace ObjectIDManager {
|
||||
//! Requests a persistent ID
|
||||
/*!
|
||||
\param callback The callback function
|
||||
*/
|
||||
void RequestPersistentID(const std::function<void(uint32_t)> callback);
|
||||
|
||||
|
||||
//! Handles a persistent ID response
|
||||
/*!
|
||||
\param requestID The request ID
|
||||
\param persistentID The persistent ID
|
||||
*/
|
||||
void HandleRequestPersistentIDResponse(const uint64_t requestID, const uint32_t persistentID);
|
||||
|
||||
//! Generates an object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
uint32_t GenerateObjectID();
|
||||
|
||||
//! Generates a random object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
uint32_t GenerateRandomObjectID();
|
||||
};
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "EntityInfo.h"
|
||||
#include "Spawner.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "Level.h"
|
||||
|
||||
#include <fstream>
|
||||
@@ -182,7 +182,7 @@ LWOOBJID VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const
|
||||
obj.lot = lot;
|
||||
// guratantee we have no collisions
|
||||
do {
|
||||
obj.id = ObjectIDManager::Instance()->GenerateObjectID();
|
||||
obj.id = ObjectIDManager::GenerateObjectID();
|
||||
} while(Game::zoneManager->GetSpawner(obj.id));
|
||||
obj.position = position;
|
||||
obj.rotation = rotation;
|
||||
|
||||
Reference in New Issue
Block a user