diff --git a/CMakeLists.txt b/CMakeLists.txt index 91a26dc5c..00c12e28d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,6 +243,7 @@ set(INCLUDED_DIRECTORIES "thirdparty/recastnavigation" "thirdparty/SQLite" "thirdparty/cpplinq" + "thirdparty/cpp-httplib" "tests" "tests/dCommonTests" diff --git a/dAuthServer/AuthServer.cpp b/dAuthServer/AuthServer.cpp index 974ee27e0..c2cfbfccb 100644 --- a/dAuthServer/AuthServer.cpp +++ b/dAuthServer/AuthServer.cpp @@ -16,7 +16,7 @@ //RakNet includes: #include "RakNetDefines.h" -#include +#include "MessageIdentifiers.h" //Auth includes: #include "AuthPackets.h" @@ -83,12 +83,15 @@ int main(int argc, char** argv) { Game::randomEngine = std::mt19937(time(0)); //It's safe to pass 'localhost' here, as the IP is only used as the external IP. - uint32_t maxClients = 50; + uint32_t maxClients = 999; uint32_t ourPort = 1001; //LU client is hardcoded to use this for auth port, so I'm making it the default. - if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients")); - if (Game::config->GetValue("auth_server_port") != "") ourPort = std::atoi(Game::config->GetValue("auth_server_port").c_str()); + std::string ourIP = "localhost"; + GeneralUtils::TryParse(Game::config->GetValue("max_clients"), maxClients); + GeneralUtils::TryParse(Game::config->GetValue("auth_server_port"), ourPort); + const auto externalIPString = Game::config->GetValue("external_ip"); + if (!externalIPString.empty()) ourIP = externalIPString; - Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth, Game::config, &Game::lastSignal); + Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth, Game::config, &Game::lastSignal); //Run it until server gets a kill message from Master: auto t = std::chrono::high_resolution_clock::now(); diff --git a/dChatServer/ChatServer.cpp b/dChatServer/ChatServer.cpp index 1642ff9c9..8e1d3adfd 100644 --- a/dChatServer/ChatServer.cpp +++ b/dChatServer/ChatServer.cpp @@ -25,7 +25,7 @@ //RakNet includes: #include "RakNetDefines.h" -#include +#include "MessageIdentifiers.h" namespace Game { Logger* logger = nullptr; @@ -99,14 +99,19 @@ int main(int argc, char** argv) { masterPort = masterInfo->port; } //It's safe to pass 'localhost' here, as the IP is only used as the external IP. - uint32_t maxClients = 50; + uint32_t maxClients = 999; uint32_t ourPort = 1501; - if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients")); - if (Game::config->GetValue("chat_server_port") != "") ourPort = std::atoi(Game::config->GetValue("chat_server_port").c_str()); + std::string ourIP = "localhost"; + GeneralUtils::TryParse(Game::config->GetValue("max_clients"), maxClients); + GeneralUtils::TryParse(Game::config->GetValue("chat_server_port"), ourPort); + const auto externalIPString = Game::config->GetValue("external_ip"); + if (!externalIPString.empty()) ourIP = externalIPString; - Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat, Game::config, &Game::lastSignal); + Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat, Game::config, &Game::lastSignal); - Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf")))); + bool dontGenerateDCF = false; + GeneralUtils::TryParse(Game::config->GetValue("dont_generate_dcf"), dontGenerateDCF); + Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF); Game::randomEngine = std::mt19937(time(0)); diff --git a/dCommon/AmfSerialize.h b/dCommon/AmfSerialize.h index 9a6f56f28..06abae74a 100644 --- a/dCommon/AmfSerialize.h +++ b/dCommon/AmfSerialize.h @@ -4,7 +4,7 @@ #include "Amf3.h" // RakNet -#include +#include "BitStream.h" /*! \file AmfSerialize.h diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 964a864bb..37291ab80 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include "BitStream.h" #include "NiPoint3.h" #include "Game.h" diff --git a/dCommon/ZCompression.cpp b/dCommon/ZCompression.cpp index d5d4c126d..e5b3c8fb4 100644 --- a/dCommon/ZCompression.cpp +++ b/dCommon/ZCompression.cpp @@ -1,6 +1,6 @@ #include "ZCompression.h" -#include +#include "zlib.h" namespace ZCompression { int32_t GetMaxCompressedLength(int32_t nLenSrc) { diff --git a/dCommon/dClient/AssetManager.cpp b/dCommon/dClient/AssetManager.cpp index 98a71e372..59427ee52 100644 --- a/dCommon/dClient/AssetManager.cpp +++ b/dCommon/dClient/AssetManager.cpp @@ -4,7 +4,7 @@ #include "Game.h" #include "Logger.h" -#include +#include "zlib.h" AssetManager::AssetManager(const std::filesystem::path& path) { if (!std::filesystem::is_directory(path)) { diff --git a/dGame/Character.h b/dGame/Character.h index 77a52f447..6c8ead30b 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -3,7 +3,7 @@ #include "dCommonVars.h" #include -#include "../thirdparty/tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include #include diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index fce2aefe7..aaa01e975 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -3,7 +3,7 @@ #include "CDClientManager.h" #include "Game.h" #include "Logger.h" -#include +#include "PacketUtils.h" #include #include "CDDestructibleComponentTable.h" #include "CDClientDatabase.h" diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index 493e910e5..a098dbcf6 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -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 diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 7c3c9bb67..3d9a209c5 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -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); diff --git a/dGame/User.h b/dGame/User.h index 5d9ea8f13..54e6ad529 100644 --- a/dGame/User.h +++ b/dGame/User.h @@ -3,7 +3,7 @@ #include #include -#include "../thirdparty/raknet/Source/RakNetTypes.h" +#include "RakNetTypes.h" #include "dCommonVars.h" #include diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 9afd38b21..736339a43 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -8,11 +8,11 @@ #include "Game.h" #include "Logger.h" #include "User.h" -#include +#include "WorldPackets.h" #include "Character.h" -#include +#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); diff --git a/dGame/dBehaviors/ProjectileAttackBehavior.cpp b/dGame/dBehaviors/ProjectileAttackBehavior.cpp index c63a3d6fe..732ff186c 100644 --- a/dGame/dBehaviors/ProjectileAttackBehavior.cpp +++ b/dGame/dBehaviors/ProjectileAttackBehavior.cpp @@ -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(ObjectIDManager::Instance()->GenerateObjectID()); + auto id = static_cast(ObjectIDManager::GenerateObjectID()); GeneralUtils::SetBit(id, eObjectBits::SPAWNED); diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index 55bc4c08a..7ea7500b1 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -7,7 +7,7 @@ #include "ZoneInstanceManager.h" #include "Game.h" #include "Logger.h" -#include +#include "WorldPackets.h" #include "EntityManager.h" #include "ChatPackets.h" #include "Player.h" diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index cf585bafe..9cc92c26a 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -1,5 +1,5 @@ #include "BaseCombatAIComponent.h" -#include +#include "BitStream.h" #include "Entity.h" #include "EntityManager.h" diff --git a/dGame/dComponents/BouncerComponent.cpp b/dGame/dComponents/BouncerComponent.cpp index 56002ac40..78ee3637f 100644 --- a/dGame/dComponents/BouncerComponent.cpp +++ b/dGame/dComponents/BouncerComponent.cpp @@ -6,7 +6,7 @@ #include "Game.h" #include "Logger.h" #include "GameMessages.h" -#include +#include "BitStream.h" #include "eTriggerEventType.h" BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) { diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 1819438b9..10ac4ebbe 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -1,5 +1,5 @@ #include "BuffComponent.h" -#include +#include "BitStream.h" #include "CDClientDatabase.h" #include #include "DestroyableComponent.h" diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index efc5d9d51..702ab70fc 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -1,5 +1,5 @@ #include "CharacterComponent.h" -#include +#include "BitStream.h" #include "tinyxml2.h" #include "Game.h" #include "Logger.h" diff --git a/dGame/dComponents/Component.h b/dGame/dComponents/Component.h index c0debb0bc..d1ad08600 100644 --- a/dGame/dComponents/Component.h +++ b/dGame/dComponents/Component.h @@ -1,6 +1,6 @@ #pragma once -#include "../thirdparty/tinyxml2/tinyxml2.h" +#include "tinyxml2.h" class Entity; diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 1ced2f545..64dca4f1d 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -1,5 +1,5 @@ #include "DestroyableComponent.h" -#include +#include "BitStream.h" #include "Logger.h" #include "Game.h" #include "dConfig.h" diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index fc3793988..92b5171a0 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -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(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& 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); diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 2f0478add..d52f7cf74 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -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(); if (!inventoryComponent) return; - LWOOBJID petSubKey = ObjectIDManager::Instance()->GenerateRandomObjectID(); + LWOOBJID petSubKey = ObjectIDManager::GenerateRandomObjectID(); GeneralUtils::SetBit(petSubKey, eObjectBits::CHARACTER); GeneralUtils::SetBit(petSubKey, eObjectBits::PERSISTENT); diff --git a/dGame/dComponents/PropertyEntranceComponent.cpp b/dGame/dComponents/PropertyEntranceComponent.cpp index c49d89859..2bb6ea309 100644 --- a/dGame/dComponents/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/PropertyEntranceComponent.cpp @@ -1,6 +1,6 @@ #include "PropertyEntranceComponent.h" -#include +#include "CDPropertyEntranceComponentTable.h" #include "Character.h" #include "Database.h" diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index de37308fe..833b7d734 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -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; diff --git a/dGame/dComponents/QuickBuildComponent.h b/dGame/dComponents/QuickBuildComponent.h index feef1f74f..f1106a61c 100644 --- a/dGame/dComponents/QuickBuildComponent.h +++ b/dGame/dComponents/QuickBuildComponent.h @@ -1,7 +1,7 @@ #ifndef QUICKBUILDCOMPONENT_H #define QUICKBUILDCOMPONENT_H -#include +#include "BitStream.h" #include #include #include "dCommonVars.h" diff --git a/dGame/dComponents/RenderComponent.h b/dGame/dComponents/RenderComponent.h index d4d1e5c3c..74f39625a 100644 --- a/dGame/dComponents/RenderComponent.h +++ b/dGame/dComponents/RenderComponent.h @@ -1,7 +1,7 @@ #ifndef RENDERCOMPONENT_H #define RENDERCOMPONENT_H -#include +#include "BitStream.h" #include #include #include diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index c4ac19100..6e313ab1e 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -7,7 +7,7 @@ #include "MissionComponent.h" #include "BitStreamUtils.h" #include "dServer.h" -#include "../thirdparty/raknet/Source/RakNetworkFactory.h" +#include "RakNetworkFactory.h" #include #include "User.h" #include "UserManager.h" diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 42d1571e7..0ea53f0f2 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -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 #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 diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index e68cdebc9..4a13cd92c 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -2,7 +2,7 @@ #include -#include "../dWorldServer/ObjectIDManager.h" +#include "ObjectIDManager.h" #include "GeneralUtils.h" #include "GameMessages.h" #include "Entity.h" diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index 248ce4e7d..c541257ce 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -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."); diff --git a/dGame/dUtilities/CMakeLists.txt b/dGame/dUtilities/CMakeLists.txt index b6bb6059b..055cc7061 100644 --- a/dGame/dUtilities/CMakeLists.txt +++ b/dGame/dUtilities/CMakeLists.txt @@ -3,6 +3,7 @@ set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp" "GUID.cpp" "Loot.cpp" "Mail.cpp" + "ObjectIDManager.cpp" "Preconditions.cpp" "SlashCommandHandler.cpp" "VanityUtilities.cpp") diff --git a/dGame/dUtilities/ObjectIDManager.cpp b/dGame/dUtilities/ObjectIDManager.cpp new file mode 100644 index 000000000..a30ede05d --- /dev/null +++ b/dGame/dUtilities/ObjectIDManager.cpp @@ -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& callback) : requestID(requestID), callback(callback) {} + uint64_t requestID; + + std::function callback; +}; + +namespace { + std::vector 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 Uni(10000000, INT32_MAX); +}; + +//! Requests a persistent ID +void ObjectIDManager::RequestPersistentID(const std::function 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; +} diff --git a/dGame/dUtilities/ObjectIDManager.h b/dGame/dUtilities/ObjectIDManager.h new file mode 100644 index 000000000..7650e4ccf --- /dev/null +++ b/dGame/dUtilities/ObjectIDManager.h @@ -0,0 +1,40 @@ +#pragma once + +// C++ +#include +#include +#include + +/*! + \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 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(); +}; diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index 6d5f996c7..fa1a3eac3 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -17,7 +17,7 @@ #include "EntityInfo.h" #include "Spawner.h" #include "dZoneManager.h" -#include "../dWorldServer/ObjectIDManager.h" +#include "ObjectIDManager.h" #include "Level.h" #include @@ -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; diff --git a/dMasterServer/CMakeLists.txt b/dMasterServer/CMakeLists.txt index 2ebdee376..108cddc24 100644 --- a/dMasterServer/CMakeLists.txt +++ b/dMasterServer/CMakeLists.txt @@ -1,6 +1,6 @@ set(DMASTERSERVER_SOURCES "InstanceManager.cpp" - "ObjectIDManager.cpp" + "PersistentIDManager.cpp" "Start.cpp" ) diff --git a/dMasterServer/InstanceManager.cpp b/dMasterServer/InstanceManager.cpp index 193ff9405..a5a6d8dcc 100644 --- a/dMasterServer/InstanceManager.cpp +++ b/dMasterServer/InstanceManager.cpp @@ -17,7 +17,7 @@ InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) { mLogger = logger; mExternalIP = externalIP; - m_LastPort = std::atoi(Game::config->GetValue("world_port_start").c_str()); + GeneralUtils::TryParse(Game::config->GetValue("world_port_start"), m_LastPort); m_LastInstanceID = LWOINSTANCEID_INVALID; } diff --git a/dMasterServer/InstanceManager.h b/dMasterServer/InstanceManager.h index a665a7d33..b9f1ec5a1 100644 --- a/dMasterServer/InstanceManager.h +++ b/dMasterServer/InstanceManager.h @@ -134,7 +134,7 @@ class InstanceManager { Logger* mLogger; std::string mExternalIP; std::vector m_Instances; - unsigned short m_LastPort; + unsigned short m_LastPort = 3000; LWOINSTANCEID m_LastInstanceID; /** diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 19a067062..e5997b512 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -35,7 +35,7 @@ #include "Game.h" #include "InstanceManager.h" #include "MasterPackets.h" -#include "ObjectIDManager.h" +#include "PersistentIDManager.h" #include "PacketUtils.h" #include "FdbToSqlite.h" #include "BitStreamUtils.h" @@ -81,45 +81,21 @@ int main(int argc, char** argv) { Game::logger = SetupLogger(); if (!Game::logger) return EXIT_FAILURE; - if (!dConfig::Exists("authconfig.ini")) { - LOG("Couldnt find authconfig.ini"); - return EXIT_FAILURE; - } - - if (!dConfig::Exists("chatconfig.ini")) { - LOG("Couldnt find chatconfig.ini"); - return EXIT_FAILURE; - } - - if (!dConfig::Exists("masterconfig.ini")) { - LOG("Couldnt find masterconfig.ini"); - return EXIT_FAILURE; - } - - if (!dConfig::Exists("sharedconfig.ini")) { - LOG("Couldnt find sharedconfig.ini"); - return EXIT_FAILURE; - } - - if (!dConfig::Exists("worldconfig.ini")) { - LOG("Couldnt find worldconfig.ini"); - return EXIT_FAILURE; - } + if (!dConfig::Exists("authconfig.ini")) LOG("Could not find authconfig.ini, using default settings"); + if (!dConfig::Exists("chatconfig.ini")) LOG("Could not find chatconfig.ini, using default settings"); + if (!dConfig::Exists("masterconfig.ini")) LOG("Could not find masterconfig.ini, using default settings"); + if (!dConfig::Exists("sharedconfig.ini")) LOG("Could not find sharedconfig.ini, using default settings"); + if (!dConfig::Exists("worldconfig.ini")) LOG("Could not find worldconfig.ini, using default settings"); Game::config = new dConfig("masterconfig.ini"); Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0"); Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1"); - uint32_t clientNetVersion = 0; - if (!GeneralUtils::TryParse(Game::config->GetValue("client_net_version"), clientNetVersion)) { - LOG("Failed to parse (%s) as net version. Cannot start server as no clients could connect.",Game::config->GetValue("client_net_version").c_str()); - LOG("As of version 1.1.1, client_net_version is required to be defined in sharedconfig.ini as opposed to in CMakeVariables.txt as NET_VERSION."); - LOG("Rerun cmake to ensure all config values exist. If client_net_version already exists in sharedconfig.ini, please ensure it is a valid number."); - LOG("like 171022"); - return EXIT_FAILURE; - } + uint32_t clientNetVersion = 171022; + const auto clientNetVersionString = Game::config->GetValue("client_net_version"); + if (!clientNetVersionString.empty()) GeneralUtils::TryParse(clientNetVersionString, clientNetVersion); - LOG("Using net version %s", Game::config->GetValue("client_net_version").c_str()); + LOG("Using net version %i", clientNetVersion); LOG("Starting Master server..."); LOG("Version: %s", PROJECT_VERSION); @@ -158,7 +134,7 @@ int main(int argc, char** argv) { if (!resServerPathExists) { LOG("%s does not exist, creating it.", (resServerPath).c_str()); - if(!std::filesystem::create_directories(resServerPath)){ + if (!std::filesystem::create_directories(resServerPath)) { LOG("Failed to create %s", (resServerPath).string().c_str()); return EXIT_FAILURE; } @@ -281,8 +257,8 @@ int main(int argc, char** argv) { //Create account try { Database::Get()->InsertNewAccount(username, std::string(hash, BCRYPT_HASHSIZE)); - } catch(sql::SQLException& e) { - LOG("A SQL error occurred!:\n %s", e.what()); + } catch (sql::SQLException& e) { + LOG("A SQL error occurred!:\n %s", e.what()); return EXIT_FAILURE; } @@ -292,28 +268,31 @@ int main(int argc, char** argv) { Game::randomEngine = std::mt19937(time(0)); uint32_t maxClients = 999; - uint32_t ourPort = 1000; - if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients")); - if (Game::config->GetValue("master_server_port") != "") ourPort = std::stoi(Game::config->GetValue("master_server_port")); - - Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal); + uint32_t ourPort = 2000; + std::string ourIP = "localhost"; + const auto maxClientsString = Game::config->GetValue("max_clients"); + if (!maxClientsString.empty()) maxClients = std::stoi(maxClientsString); + const auto masterServerPortString = Game::config->GetValue("master_server_port"); + if (!masterServerPortString.empty()) ourPort = std::atoi(masterServerPortString.c_str()); + const auto externalIPString = Game::config->GetValue("external_ip"); + if (!externalIPString.empty()) ourIP = externalIPString; - //Query for the database for a server labeled "master" + Game::server = new dServer(ourIP, ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal); - auto master_server_ip = Game::config->GetValue("master_ip"); + std::string master_server_ip = "localhost"; + const auto masterServerIPString = Game::config->GetValue("master_ip"); + if (!masterServerIPString.empty()) master_server_ip = masterServerIPString; - if (master_server_ip == "") { - master_server_ip = Game::server->GetIP(); - } + if (master_server_ip == "") master_server_ip = Game::server->GetIP(); Database::Get()->SetMasterIp(master_server_ip, Game::server->GetPort()); //Create additional objects here: - ObjectIDManager::Instance()->Initialize(Game::logger); + PersistentIDManager::Initialize(); Game::im = new InstanceManager(Game::logger, Game::server->GetIP()); //Depending on the config, start up servers: - if (Game::config->GetValue("prestart_servers") != "" && Game::config->GetValue("prestart_servers") == "1") { + if (Game::config->GetValue("prestart_servers") != "0") { StartChatServer(); Game::im->GetInstance(0, false, 0); @@ -485,7 +464,7 @@ void HandlePacket(Packet* packet) { uint64_t requestID = 0; inStream.Read(requestID); - uint32_t objID = ObjectIDManager::Instance()->GeneratePersistentID(); + uint32_t objID = PersistentIDManager::GeneratePersistentID(); MasterPackets::SendPersistentIDResponse(Game::server, packet->systemAddress, requestID, objID); break; } @@ -843,11 +822,8 @@ int ShutdownSequence(int32_t signal) { LOG("Triggered master shutdown"); } - auto* objIdManager = ObjectIDManager::TryInstance(); - if (objIdManager) { - objIdManager->SaveToDatabase(); - LOG("Saved ObjectIDTracker to DB"); - } + PersistentIDManager::SaveToDatabase(); + LOG("Saved ObjectIDTracker to DB"); // A server might not be finished spinning up yet, remove all of those here. for (auto* instance : Game::im->GetInstances()) { diff --git a/dMasterServer/ObjectIDManager.h b/dMasterServer/ObjectIDManager.h deleted file mode 100644 index cdb6dcdf2..000000000 --- a/dMasterServer/ObjectIDManager.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -// C++ -#include - -class Logger; - -/*! - \file ObjectIDManager.hpp - \brief A manager that handles requests for object IDs - */ - - //! The Object ID Manager -class ObjectIDManager { -private: - Logger* mLogger; - static ObjectIDManager* m_Address; //!< The singleton instance - - uint32_t currentPersistentID; //!< The highest current persistent ID in use - -public: - - //! Return the singleton if it is initialized - static ObjectIDManager* TryInstance() { - return m_Address; - } - - //! The singleton method - static ObjectIDManager* Instance() { - if (m_Address == nullptr) { - m_Address = new ObjectIDManager; - } - - return m_Address; - } - - //! Initializes the manager - void Initialize(Logger* logger); - - //! Generates a new persistent ID - /*! - \return The new persistent ID - */ - uint32_t GeneratePersistentID(); - - void SaveToDatabase(); -}; diff --git a/dMasterServer/ObjectIDManager.cpp b/dMasterServer/PersistentIDManager.cpp similarity index 58% rename from dMasterServer/ObjectIDManager.cpp rename to dMasterServer/PersistentIDManager.cpp index 4739addff..3e56fadca 100644 --- a/dMasterServer/ObjectIDManager.cpp +++ b/dMasterServer/PersistentIDManager.cpp @@ -1,48 +1,45 @@ -#include "ObjectIDManager.h" +#include "PersistentIDManager.h" // Custom Classes #include "Database.h" #include "Logger.h" #include "Game.h" -// Static Variables -ObjectIDManager* ObjectIDManager::m_Address = nullptr; +namespace { + uint32_t CurrentPersistentID = 1; //!< The highest current persistent ID in use +}; //! Initializes the manager -void ObjectIDManager::Initialize(Logger* logger) { - this->mLogger = logger; - this->currentPersistentID = 1; - +void PersistentIDManager::Initialize() { try { auto lastObjectId = Database::Get()->GetCurrentPersistentId(); if (!lastObjectId) { Database::Get()->InsertDefaultPersistentId(); - return; } else { - this->currentPersistentID = lastObjectId.value(); + CurrentPersistentID = lastObjectId.value(); } - if (this->currentPersistentID <= 0) { + if (CurrentPersistentID <= 0) { LOG("Invalid persistent object ID in database. Aborting to prevent bad id generation."); throw std::runtime_error("Invalid persistent object ID in database. Aborting to prevent bad id generation."); } } catch (sql::SQLException& e) { LOG("Unable to fetch max persistent object ID in use. This will cause issues. Aborting to prevent collisions."); LOG("SQL error: %s", e.what()); - throw; + throw e; } } //! Generates a new persistent ID -uint32_t ObjectIDManager::GeneratePersistentID() { - uint32_t toReturn = ++this->currentPersistentID; +uint32_t PersistentIDManager::GeneratePersistentID() { + uint32_t toReturn = ++CurrentPersistentID; SaveToDatabase(); return toReturn; } -void ObjectIDManager::SaveToDatabase() { - Database::Get()->UpdatePersistentId(this->currentPersistentID); +void PersistentIDManager::SaveToDatabase() { + Database::Get()->UpdatePersistentId(CurrentPersistentID); } diff --git a/dMasterServer/PersistentIDManager.h b/dMasterServer/PersistentIDManager.h new file mode 100644 index 000000000..916ee33a6 --- /dev/null +++ b/dMasterServer/PersistentIDManager.h @@ -0,0 +1,23 @@ +#pragma once + +// C++ +#include + +/*! + \file PersistentIDManager.h + \brief A manager that handles requests for object IDs + */ + + //! The Object ID Manager +namespace PersistentIDManager { + //! Initializes the manager + void Initialize(); + + //! Generates a new persistent ID + /*! + \return The new persistent ID + */ + uint32_t GeneratePersistentID(); + + void SaveToDatabase(); +}; diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index 9ddf7bf7a..7feb0cc3a 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -13,7 +13,7 @@ #include -#include +#include "BitStream.h" #include #include "Game.h" @@ -54,14 +54,12 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) { void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) { RakNet::BitStream bitStream; BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM); - uint32_t netVersion; - const std::string& expectedVersion = Game::config->GetValue("client_net_version"); - LOG("Expected Version: '%s'", expectedVersion.c_str()); - if (!GeneralUtils::TryParse(expectedVersion, netVersion)) { - LOG("Failed to parse client_net_version. Cannot authenticate to %s:%i", nextServerIP.c_str(), nextServerPort); - return; - } - bitStream.Write(netVersion); + + uint32_t clientNetVersion = 171022; + const auto clientNetVersionString = Game::config->GetValue("client_net_version"); + if (!clientNetVersionString.empty()) GeneralUtils::TryParse(clientNetVersionString, clientNetVersion); + + bitStream.Write(clientNetVersion); bitStream.Write(0x93); if (serverType == ServerType::Auth) bitStream.Write(uint32_t(1)); //Conn: auth @@ -95,7 +93,6 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) { } if (Game::config->GetValue("dont_use_keys") != "1" && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) { - LOG(""); //Check to see if we have a play key: if (accountInfo->playKeyId == 0) { AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username); diff --git a/dNet/PacketUtils.h b/dNet/PacketUtils.h index 2afd53c76..f8558dfd1 100644 --- a/dNet/PacketUtils.h +++ b/dNet/PacketUtils.h @@ -1,8 +1,8 @@ #ifndef PACKETUTILS_H #define PACKETUTILS_H -#include -#include +#include "MessageIdentifiers.h" +#include "BitStream.h" #include enum class eConnectionType : uint16_t; diff --git a/dNet/ZoneInstanceManager.h b/dNet/ZoneInstanceManager.h index a8e32c4e8..3f8da1ae6 100644 --- a/dNet/ZoneInstanceManager.h +++ b/dNet/ZoneInstanceManager.h @@ -7,7 +7,7 @@ #include // RakNet -#include +#include "RakNetTypes.h" class dServer; diff --git a/dNet/dServer.cpp b/dNet/dServer.cpp index 702a2d443..e60e04f9f 100644 --- a/dNet/dServer.cpp +++ b/dNet/dServer.cpp @@ -14,6 +14,7 @@ #include "BitStreamUtils.h" #include "MasterPackets.h" #include "ZoneInstanceManager.h" +#include "StringifiedEnum.h" //! Replica Constructor class class ReplicaConstructor : public ReceiveConstructionInterface { @@ -65,9 +66,9 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect if (mIsOkay) { if (zoneID == 0) - LOG("Server is listening on %s:%i with encryption: %i", ip.c_str(), port, int(useEncryption)); + LOG("%s Server is listening on %s:%i with encryption: %i", StringifiedEnum::ToString(serverType).data(), ip.c_str(), port, int(useEncryption)); else - LOG("Server is listening on %s:%i with encryption: %i, running zone %i / %i", ip.c_str(), port, int(useEncryption), zoneID, instanceID); + LOG("%s Server is listening on %s:%i with encryption: %i, running zone %i / %i", StringifiedEnum::ToString(serverType).data(), ip.c_str(), port, int(useEncryption), zoneID, instanceID); } else { LOG("FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); return; } mLogger->SetLogToConsole(prevLogSetting); diff --git a/dPhysics/dpWorld.cpp b/dPhysics/dpWorld.cpp index 1abcb04a5..698ceb630 100644 --- a/dPhysics/dpWorld.cpp +++ b/dPhysics/dpWorld.cpp @@ -10,14 +10,17 @@ #include "dConfig.h" void dpWorld::Initialize(unsigned int zoneID, bool generateNewNavMesh) { - phys_sp_tilecount = std::atoi(Game::config->GetValue("phys_sp_tilecount").c_str()); - phys_sp_tilesize = std::atoi(Game::config->GetValue("phys_sp_tilesize").c_str()); + const auto physSpTilecount = Game::config->GetValue("phys_sp_tilecount"); + if (!physSpTilecount.empty()) GeneralUtils::TryParse(physSpTilecount, phys_sp_tilecount); + const auto physSpTilesize = Game::config->GetValue("phys_sp_tilesize"); + if (!physSpTilesize.empty()) GeneralUtils::TryParse(physSpTilesize, phys_sp_tilesize); + const auto physSpatialPartitioning = Game::config->GetValue("phys_spatial_partitioning"); + if (!physSpatialPartitioning.empty()) phys_spatial_partitioning = physSpatialPartitioning == "1"; //If spatial partitioning is enabled, then we need to create the m_Grid. //if m_Grid exists, then the old method will be used. //SP will NOT be used unless it is added to ShouldUseSP(); - if (std::atoi(Game::config->GetValue("phys_spatial_partitioning").c_str()) == 1 - && ShouldUseSP(zoneID)) { + if (ShouldUseSP(zoneID)) { m_Grid = new dpGrid(phys_sp_tilecount, phys_sp_tilesize); } @@ -123,6 +126,8 @@ void dpWorld::RemoveEntity(dpEntity* entity) { } bool dpWorld::ShouldUseSP(unsigned int zoneID) { + if (!phys_spatial_partitioning) return false; + // TODO: Add to this list as needed. // Only large maps should be added as tiling likely makes little difference on small maps. diff --git a/dPhysics/dpWorld.h b/dPhysics/dpWorld.h index d48435d0e..bf2af06dc 100644 --- a/dPhysics/dpWorld.h +++ b/dPhysics/dpWorld.h @@ -36,7 +36,7 @@ class dpWorld : public Singleton { private: dpGrid* m_Grid; - bool phys_spatial_partitioning = 1; + bool phys_spatial_partitioning = true; int phys_sp_tilesize = 205; int phys_sp_tilecount = 12; diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 55c82b958..1a2988433 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -9,7 +9,7 @@ #include "CharacterComponent.h" #include "SimplePhysicsComponent.h" #include "MovementAIComponent.h" -#include "../dWorldServer/ObjectIDManager.h" +#include "ObjectIDManager.h" #include "MissionComponent.h" #include "Loot.h" #include "InventoryComponent.h" diff --git a/dWorldServer/CMakeLists.txt b/dWorldServer/CMakeLists.txt index a790487e9..336a60f92 100644 --- a/dWorldServer/CMakeLists.txt +++ b/dWorldServer/CMakeLists.txt @@ -1,5 +1,4 @@ set(DWORLDSERVER_SOURCES - "ObjectIDManager.cpp" "PerformanceManager.cpp" ) diff --git a/dWorldServer/ObjectIDManager.cpp b/dWorldServer/ObjectIDManager.cpp deleted file mode 100644 index 44a45437e..000000000 --- a/dWorldServer/ObjectIDManager.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "ObjectIDManager.h" - -// Custom Classes -#include "MasterPackets.h" -#include "Database.h" -#include "Logger.h" -#include "Game.h" - -// Static Variables -ObjectIDManager* ObjectIDManager::m_Address = nullptr; -static std::uniform_int_distribution uni(10000000, INT32_MAX); - -//! Initializes the manager -void ObjectIDManager::Initialize(void) { - //this->currentRequestID = 0; - this->currentObjectID = uint32_t(1152921508165007067); //Initial value for this server's objectIDs -} - -//! Requests a persistent ID -void ObjectIDManager::RequestPersistentID(std::function callback) { - PersistentIDRequest* request = new PersistentIDRequest(); - request->requestID = ++this->currentRequestID; - request->callback = callback; - - this->requests.push_back(request); - - MasterPackets::SendPersistentIDRequest(Game::server, request->requestID); -} - -//! Handles a persistent ID response -void ObjectIDManager::HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID) { - for (uint32_t i = 0; i < this->requests.size(); ++i) { - if (this->requests[i]->requestID == requestID) { - - // Call the callback function - this->requests[i]->callback(persistentID); - - // Then delete the request - delete this->requests[i]; - this->requests.erase(this->requests.begin() + i); - return; - } - } -} - -//! 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(void) { - return ++this->currentObjectID; -} diff --git a/dWorldServer/ObjectIDManager.h b/dWorldServer/ObjectIDManager.h deleted file mode 100644 index deef89fdf..000000000 --- a/dWorldServer/ObjectIDManager.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -// C++ -#include -#include -#include - -/*! - \file ObjectIDManager.hpp - \brief A manager for handling object ID generation - */ - - //! The persistent ID request -struct PersistentIDRequest { - uint64_t requestID; - - std::function callback; -}; - -//! The Object ID Manager -class ObjectIDManager { -private: - static ObjectIDManager* m_Address; //!< The singleton instance - - std::vector requests; //!< All outstanding persistent ID requests - uint64_t currentRequestID; //!< The current request ID - - uint32_t currentObjectID; //!< The current object ID - -public: - - //! The singleton instance - static ObjectIDManager* Instance() { - if (m_Address == 0) { - m_Address = new ObjectIDManager; - } - - return m_Address; - } - - //! Initializes the manager - void Initialize(void); - - //! Requests a persistent ID - /*! - \param callback The callback function - */ - void RequestPersistentID(std::function callback); - - - //! Handles a persistent ID response - /*! - \param requestID The request ID - \param persistentID The persistent ID - */ - void HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID); - - //! Generates an object ID server-sided - /*! - \return A generated object ID - */ - uint32_t GenerateObjectID(void); - - //! Generates a random object ID server-sided - /*! - \return A generated object ID - */ - static uint32_t GenerateRandomObjectID(); - - //! Generates a persistent object ID server-sided - /*! - \return A generated object ID - */ - uint32_t GeneratePersistentObjectID(void); -}; diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 31fd488cb..f911f8046 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -208,9 +208,11 @@ int main(int argc, char** argv) { masterPort = masterInfo->port; } - ObjectIDManager::Instance()->Initialize(); UserManager::Instance()->Initialize(); - Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf")))); + + bool dontGenerateDCF = false; + GeneralUtils::TryParse(Game::config->GetValue("dont_generate_dcf"), dontGenerateDCF); + Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF); Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, zoneID); @@ -733,7 +735,7 @@ void HandlePacket(Packet* packet) { case eMasterMessageType::REQUEST_PERSISTENT_ID_RESPONSE: { uint64_t requestID = PacketUtils::ReadU64(8, packet); uint32_t objectID = PacketUtils::ReadU32(16, packet); - ObjectIDManager::Instance()->HandleRequestPersistentIDResponse(requestID, objectID); + ObjectIDManager::HandleRequestPersistentIDResponse(requestID, objectID); break; } diff --git a/dZoneManager/dZoneManager.cpp b/dZoneManager/dZoneManager.cpp index fa1675e5e..1da1bce8e 100644 --- a/dZoneManager/dZoneManager.cpp +++ b/dZoneManager/dZoneManager.cpp @@ -15,7 +15,7 @@ #include "CDZoneTableTable.h" #include "AssetManager.h" -#include "../dWorldServer/ObjectIDManager.h" +#include "ObjectIDManager.h" void dZoneManager::Initialize(const LWOZONEID& zoneID) { LOG("Preparing zone: %i/%i/%i", zoneID.GetMapID(), zoneID.GetInstanceID(), zoneID.GetCloneID()); @@ -112,7 +112,7 @@ LWOOBJID dZoneManager::MakeSpawner(SpawnerInfo info) { auto objectId = info.spawnerID; if (objectId == LWOOBJID_EMPTY) { - objectId = ObjectIDManager::Instance()->GenerateObjectID(); + objectId = ObjectIDManager::GenerateObjectID(); GeneralUtils::SetBit(objectId, eObjectBits::CLIENT); info.spawnerID = objectId; diff --git a/tests/dCommonTests/dCommonDependencies.h b/tests/dCommonTests/dCommonDependencies.h index 228c3c521..e82f4a4b1 100644 --- a/tests/dCommonTests/dCommonDependencies.h +++ b/tests/dCommonTests/dCommonDependencies.h @@ -4,8 +4,6 @@ #include "Game.h" #include "Logger.h" #include "dServer.h" -#include "EntityInfo.h" -#include "EntityManager.h" #include "dConfig.h" #include