Merge branch 'DarkflameUniverse:main' into PetFixes

This commit is contained in:
jadebenn 2024-01-05 15:37:17 -06:00 committed by GitHub
commit 0f365e0ae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 259 additions and 337 deletions

View File

@ -243,6 +243,7 @@ set(INCLUDED_DIRECTORIES
"thirdparty/recastnavigation"
"thirdparty/SQLite"
"thirdparty/cpplinq"
"thirdparty/cpp-httplib"
"tests"
"tests/dCommonTests"

View File

@ -16,7 +16,7 @@
//RakNet includes:
#include "RakNetDefines.h"
#include <MessageIdentifiers.h>
#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();

View File

@ -25,7 +25,7 @@
//RakNet includes:
#include "RakNetDefines.h"
#include <MessageIdentifiers.h>
#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));

View File

@ -4,7 +4,7 @@
#include "Amf3.h"
// RakNet
#include <BitStream.h>
#include "BitStream.h"
/*!
\file AmfSerialize.h

View File

@ -9,7 +9,7 @@
#include <functional>
#include <type_traits>
#include <stdexcept>
#include <BitStream.h>
#include "BitStream.h"
#include "NiPoint3.h"
#include "Game.h"

View File

@ -1,6 +1,6 @@
#include "ZCompression.h"
#include <zlib.h>
#include "zlib.h"
namespace ZCompression {
int32_t GetMaxCompressedLength(int32_t nLenSrc) {

View File

@ -4,7 +4,7 @@
#include "Game.h"
#include "Logger.h"
#include <zlib.h>
#include "zlib.h"
AssetManager::AssetManager(const std::filesystem::path& path) {
if (!std::filesystem::is_directory(path)) {

View File

@ -3,7 +3,7 @@
#include "dCommonVars.h"
#include <vector>
#include "../thirdparty/tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
#include <unordered_map>
#include <map>

View File

@ -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"

View File

@ -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

View File

@ -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);

View File

@ -3,7 +3,7 @@
#include <string>
#include <vector>
#include "../thirdparty/raknet/Source/RakNetTypes.h"
#include "RakNetTypes.h"
#include "dCommonVars.h"
#include <unordered_map>

View File

@ -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);

View File

@ -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);

View File

@ -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"

View File

@ -1,5 +1,5 @@
#include "BaseCombatAIComponent.h"
#include <BitStream.h>
#include "BitStream.h"
#include "Entity.h"
#include "EntityManager.h"

View File

@ -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) {

View File

@ -1,5 +1,5 @@
#include "BuffComponent.h"
#include <BitStream.h>
#include "BitStream.h"
#include "CDClientDatabase.h"
#include <stdexcept>
#include "DestroyableComponent.h"

View File

@ -1,5 +1,5 @@
#include "CharacterComponent.h"
#include <BitStream.h>
#include "BitStream.h"
#include "tinyxml2.h"
#include "Game.h"
#include "Logger.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include "../thirdparty/tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
class Entity;

View File

@ -1,5 +1,5 @@
#include "DestroyableComponent.h"
#include <BitStream.h>
#include "BitStream.h"
#include "Logger.h"
#include "Game.h"
#include "dConfig.h"

View File

@ -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);

View File

@ -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);

View File

@ -1,6 +1,6 @@
#include "PropertyEntranceComponent.h"
#include <CDPropertyEntranceComponentTable.h>
#include "CDPropertyEntranceComponentTable.h"
#include "Character.h"
#include "Database.h"

View File

@ -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;

View File

@ -1,7 +1,7 @@
#ifndef QUICKBUILDCOMPONENT_H
#define QUICKBUILDCOMPONENT_H
#include <BitStream.h>
#include "BitStream.h"
#include <vector>
#include <string>
#include "dCommonVars.h"

View File

@ -1,7 +1,7 @@
#ifndef RENDERCOMPONENT_H
#define RENDERCOMPONENT_H
#include <BitStream.h>
#include "BitStream.h"
#include <vector>
#include <string>
#include <unordered_map>

View File

@ -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"

View File

@ -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

View File

@ -2,7 +2,7 @@
#include <sstream>
#include "../dWorldServer/ObjectIDManager.h"
#include "ObjectIDManager.h"
#include "GeneralUtils.h"
#include "GameMessages.h"
#include "Entity.h"

View File

@ -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.");

View File

@ -3,6 +3,7 @@ set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
"GUID.cpp"
"Loot.cpp"
"Mail.cpp"
"ObjectIDManager.cpp"
"Preconditions.cpp"
"SlashCommandHandler.cpp"
"VanityUtilities.cpp")

View 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;
}

View 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();
};

View File

@ -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;

View File

@ -1,6 +1,6 @@
set(DMASTERSERVER_SOURCES
"InstanceManager.cpp"
"ObjectIDManager.cpp"
"PersistentIDManager.cpp"
"Start.cpp"
)

View File

@ -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;
}

View File

@ -134,7 +134,7 @@ private:
Logger* mLogger;
std::string mExternalIP;
std::vector<Instance*> m_Instances;
unsigned short m_LastPort;
unsigned short m_LastPort = 3000;
LWOINSTANCEID m_LastInstanceID;
/**

View File

@ -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,7 +257,7 @@ int main(int argc, char** argv) {
//Create account
try {
Database::Get()->InsertNewAccount(username, std::string(hash, BCRYPT_HASHSIZE));
} catch(sql::SQLException& e) {
} 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"));
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;
Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal);
Game::server = new dServer(ourIP, ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal);
//Query for the database for a server labeled "master"
std::string master_server_ip = "localhost";
const auto masterServerIPString = Game::config->GetValue("master_ip");
if (!masterServerIPString.empty()) master_server_ip = masterServerIPString;
auto master_server_ip = Game::config->GetValue("master_ip");
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();
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()) {

View File

@ -1,47 +0,0 @@
#pragma once
// C++
#include <cstdint>
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();
};

View File

@ -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);
}

View File

@ -0,0 +1,23 @@
#pragma once
// C++
#include <cstdint>
/*!
\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();
};

View File

@ -13,7 +13,7 @@
#include <bcrypt/BCrypt.hpp>
#include <BitStream.h>
#include "BitStream.h"
#include <future>
#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<uint32_t>(netVersion);
uint32_t clientNetVersion = 171022;
const auto clientNetVersionString = Game::config->GetValue("client_net_version");
if (!clientNetVersionString.empty()) GeneralUtils::TryParse(clientNetVersionString, clientNetVersion);
bitStream.Write<uint32_t>(clientNetVersion);
bitStream.Write<uint32_t>(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);

View File

@ -1,8 +1,8 @@
#ifndef PACKETUTILS_H
#define PACKETUTILS_H
#include <MessageIdentifiers.h>
#include <BitStream.h>
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include <string>
enum class eConnectionType : uint16_t;

View File

@ -7,7 +7,7 @@
#include <string>
// RakNet
#include <RakNetTypes.h>
#include "RakNetTypes.h"
class dServer;

View File

@ -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);

View File

@ -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.

View File

@ -36,7 +36,7 @@ public:
private:
dpGrid* m_Grid;
bool phys_spatial_partitioning = 1;
bool phys_spatial_partitioning = true;
int phys_sp_tilesize = 205;
int phys_sp_tilecount = 12;

View File

@ -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"

View File

@ -1,5 +1,4 @@
set(DWORLDSERVER_SOURCES
"ObjectIDManager.cpp"
"PerformanceManager.cpp"
)

View File

@ -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<int> 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<void(uint32_t)> 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;
}

View File

@ -1,75 +0,0 @@
#pragma once
// C++
#include <functional>
#include <vector>
#include <stdint.h>
/*!
\file ObjectIDManager.hpp
\brief A manager for handling object ID generation
*/
//! The persistent ID request
struct PersistentIDRequest {
uint64_t requestID;
std::function<void(uint32_t)> callback;
};
//! The Object ID Manager
class ObjectIDManager {
private:
static ObjectIDManager* m_Address; //!< The singleton instance
std::vector<PersistentIDRequest*> 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<void(uint32_t)> 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);
};

View File

@ -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;
}

View File

@ -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;

View File

@ -4,8 +4,6 @@
#include "Game.h"
#include "Logger.h"
#include "dServer.h"
#include "EntityInfo.h"
#include "EntityManager.h"
#include "dConfig.h"
#include <gtest/gtest.h>