mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
feat: Abstract Logger and simplify code (#1207)
* Logger: Rename logger to Logger from dLogger * Logger: Add compile time filename Fix include issues Add writers Add macros Add macro to force compilation * Logger: Replace calls with macros Allows for filename and line number to be logged * Logger: Add comments and remove extra define Logger: Replace with unique_ptr also flush console at exit. regular file writer should be flushed on file close. Logger: Remove constexpr on variable * Logger: Simplify code * Update Logger.cpp
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "Entity.h"
|
||||
#include "Item.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "MissionComponent.h"
|
||||
@@ -175,14 +175,14 @@ void InventoryComponent::AddItem(
|
||||
const bool bound,
|
||||
int32_t preferredSlot) {
|
||||
if (count == 0) {
|
||||
Game::logger->Log("InventoryComponent", "Attempted to add 0 of item (%i) to the inventory!", lot);
|
||||
LOG("Attempted to add 0 of item (%i) to the inventory!", lot);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Inventory::IsValidItem(lot)) {
|
||||
if (lot > 0) {
|
||||
Game::logger->Log("InventoryComponent", "Attempted to add invalid item (%i) to the inventory!", lot);
|
||||
LOG("Attempted to add invalid item (%i) to the inventory!", lot);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -200,7 +200,7 @@ void InventoryComponent::AddItem(
|
||||
const auto slot = preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot) ? preferredSlot : inventory->FindEmptySlot();
|
||||
|
||||
if (slot == -1) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find empty slot for inventory (%i)!", inventoryType);
|
||||
LOG("Failed to find empty slot for inventory (%i)!", inventoryType);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -302,7 +302,7 @@ void InventoryComponent::AddItem(
|
||||
|
||||
void InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound) {
|
||||
if (count == 0) {
|
||||
Game::logger->Log("InventoryComponent", "Attempted to remove 0 of item (%i) from the inventory!", lot);
|
||||
LOG("Attempted to remove 0 of item (%i) from the inventory!", lot);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -496,7 +496,7 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
auto* inventoryElement = document->FirstChildElement("obj")->FirstChildElement("inv");
|
||||
|
||||
if (inventoryElement == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find 'inv' xml element!");
|
||||
LOG("Failed to find 'inv' xml element!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -504,7 +504,7 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
auto* bags = inventoryElement->FirstChildElement("bag");
|
||||
|
||||
if (bags == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find 'bags' xml element!");
|
||||
LOG("Failed to find 'bags' xml element!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -530,7 +530,7 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
auto* items = inventoryElement->FirstChildElement("items");
|
||||
|
||||
if (items == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find 'items' xml element!");
|
||||
LOG("Failed to find 'items' xml element!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -545,7 +545,7 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
auto* inventory = GetInventory(static_cast<eInventoryType>(type));
|
||||
|
||||
if (inventory == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find inventory (%i)!", type);
|
||||
LOG("Failed to find inventory (%i)!", type);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -618,7 +618,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
auto* inventoryElement = document->FirstChildElement("obj")->FirstChildElement("inv");
|
||||
|
||||
if (inventoryElement == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find 'inv' xml element!");
|
||||
LOG("Failed to find 'inv' xml element!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -641,7 +641,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
auto* bags = inventoryElement->FirstChildElement("bag");
|
||||
|
||||
if (bags == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find 'bags' xml element!");
|
||||
LOG("Failed to find 'bags' xml element!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -660,7 +660,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
auto* items = inventoryElement->FirstChildElement("items");
|
||||
|
||||
if (items == nullptr) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find 'items' xml element!");
|
||||
LOG("Failed to find 'items' xml element!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -935,7 +935,7 @@ void InventoryComponent::EquipScripts(Item* equippedItem) {
|
||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
||||
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
|
||||
if (!itemScript) {
|
||||
Game::logger->Log("InventoryComponent", "null script?");
|
||||
LOG("null script?");
|
||||
}
|
||||
itemScript->OnFactionTriggerItemEquipped(m_Parent, equippedItem->GetId());
|
||||
}
|
||||
@@ -950,7 +950,7 @@ void InventoryComponent::UnequipScripts(Item* unequippedItem) {
|
||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
||||
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
|
||||
if (!itemScript) {
|
||||
Game::logger->Log("InventoryComponent", "null script?");
|
||||
LOG("null script?");
|
||||
}
|
||||
itemScript->OnFactionTriggerItemUnequipped(m_Parent, unequippedItem->GetId());
|
||||
}
|
||||
@@ -1330,7 +1330,7 @@ std::vector<uint32_t> InventoryComponent::FindBuffs(Item* item, bool castOnEquip
|
||||
const auto entry = behaviors->GetSkillByID(result.skillID);
|
||||
|
||||
if (entry.skillID == 0) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to find buff behavior for skill (%i)!", result.skillID);
|
||||
LOG("Failed to find buff behavior for skill (%i)!", result.skillID);
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -1397,7 +1397,7 @@ std::vector<Item*> InventoryComponent::GenerateProxies(Item* parent) {
|
||||
try {
|
||||
lots.push_back(std::stoi(segment));
|
||||
} catch (std::invalid_argument& exception) {
|
||||
Game::logger->Log("InventoryComponent", "Failed to parse proxy (%s): (%s)!", segment.c_str(), exception.what());
|
||||
LOG("Failed to parse proxy (%s): (%s)!", segment.c_str(), exception.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user