mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +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:
@@ -309,7 +309,7 @@ void BossSpiderQueenEnemyServer::RainOfFireManager(Entity* self) {
|
||||
impactList.erase(impactList.begin());
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BossSpiderQueenEnemyServer", "Failed to find impact!");
|
||||
LOG("Failed to find impact!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ void BossSpiderQueenEnemyServer::RainOfFireManager(Entity* self) {
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
|
||||
if (skillComponent == nullptr) {
|
||||
Game::logger->Log("BossSpiderQueenEnemyServer", "Failed to find impact skill component!");
|
||||
LOG("Failed to find impact skill component!");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -366,7 +366,7 @@ void BossSpiderQueenEnemyServer::RunRapidFireShooter(Entity* self) {
|
||||
}
|
||||
|
||||
if (targets.empty()) {
|
||||
Game::logger->Log("BossSpiderQueenEnemyServer", "Failed to find RFS targets");
|
||||
LOG("Failed to find RFS targets");
|
||||
|
||||
self->AddTimer("RFS", GeneralUtils::GenerateRandomNumber<float>(5, 10));
|
||||
|
||||
|
@@ -67,7 +67,7 @@ void FvMaelstromDragon::OnHitOrHealResult(Entity* self, Entity* attacker, int32_
|
||||
auto weakpoint = self->GetVar<int32_t>(u"weakpoint");
|
||||
|
||||
if (weakpoint == 0) {
|
||||
Game::logger->Log("FvMaelstromDragon", "Activating weakpoint");
|
||||
LOG("Activating weakpoint");
|
||||
|
||||
self->AddTimer("ReviveTimer", 12);
|
||||
|
||||
|
@@ -37,7 +37,7 @@ void FlameJetServer::OnCollisionPhantom(Entity* self, Entity* target) {
|
||||
}
|
||||
|
||||
void FlameJetServer::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
|
||||
Game::logger->Log("FlameJetServer::OnFireEventServerSide", "Event: %s", args.c_str());
|
||||
LOG("Event: %s", args.c_str());
|
||||
|
||||
if (args == "OnActivated") {
|
||||
self->SetNetworkVar<bool>(u"FlameOn", false);
|
||||
|
@@ -101,7 +101,7 @@ void NjMonastryBossInstance::OnPlayerExit(Entity* self, Entity* player) {
|
||||
if (playerToRemove != totalPlayersLoaded.end()) {
|
||||
totalPlayersLoaded.erase(playerToRemove);
|
||||
} else {
|
||||
Game::logger->Log("NjMonastryBossInstance", "Failed to remove player at exit.");
|
||||
LOG("Failed to remove player at exit.");
|
||||
}
|
||||
|
||||
// Set the players loaded var back
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include "LeaderboardManager.h"
|
||||
#include "GameMessages.h"
|
||||
#include <algorithm>
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "Loot.h"
|
||||
|
||||
bool ActivityManager::IsPlayerInActivity(Entity* self, LWOOBJID playerID) {
|
||||
@@ -129,7 +129,7 @@ void ActivityManager::ActivityTimerStart(Entity* self, const std::string& timerN
|
||||
auto* timer = new ActivityTimer{ timerName, updateInterval, stopTime };
|
||||
activeTimers.push_back(timer);
|
||||
|
||||
Game::logger->LogDebug("ActivityManager", "Starting timer '%s', %f, %f", timerName.c_str(), updateInterval, stopTime);
|
||||
LOG_DEBUG("Starting timer '%s', %f, %f", timerName.c_str(), updateInterval, stopTime);
|
||||
|
||||
self->AddTimer(GetPrefixedName(timer->name), timer->updateInterval);
|
||||
}
|
||||
@@ -210,10 +210,10 @@ void ActivityManager::OnTimerDone(Entity* self, std::string timerName) {
|
||||
activeTimers.erase(std::remove(activeTimers.begin(), activeTimers.end(), timer),
|
||||
activeTimers.end());
|
||||
delete timer;
|
||||
Game::logger->LogDebug("ActivityManager", "Executing timer '%s'", activityTimerName.c_str());
|
||||
LOG_DEBUG("Executing timer '%s'", activityTimerName.c_str());
|
||||
OnActivityTimerDone(self, activityTimerName);
|
||||
} else {
|
||||
Game::logger->LogDebug("ActivityManager", "Updating timer '%s'", activityTimerName.c_str());
|
||||
LOG_DEBUG("Updating timer '%s'", activityTimerName.c_str());
|
||||
OnActivityTimerUpdate(self, timer->name, timer->stopTime - timer->runTime, timer->runTime);
|
||||
self->AddTimer(GetPrefixedName(timer->name), timer->updateInterval);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "BaseRandomServer.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Spawner.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "Entity.h"
|
||||
|
||||
void BaseRandomServer::BaseStartup(Entity* self) {
|
||||
@@ -34,7 +34,7 @@ void BaseRandomServer::SpawnSection(Entity* self, const std::string& sectionName
|
||||
Zone* spawnLoad = GetRandomLoad(self, sectionName);
|
||||
|
||||
if (spawnLoad == nullptr) {
|
||||
Game::logger->Log("BaseRandomServer", "Failed to find section: %s", sectionName.c_str());
|
||||
LOG("Failed to find section: %s", sectionName.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ void BaseRandomServer::SetSpawnerNetwork(Entity* self, const std::string& spawne
|
||||
}
|
||||
|
||||
if (spawners.empty()) {
|
||||
Game::logger->Log("BaseRandomServer", "Failed to find spawner: %s", spawnerName.c_str());
|
||||
LOG("Failed to find spawner: %s", spawnerName.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
#include "Entity.h"
|
||||
#include "ScriptComponent.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "InvalidScript.h"
|
||||
|
||||
//VE / AG scripts:
|
||||
@@ -930,7 +930,7 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
|
||||
(scriptName =="scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua") ||
|
||||
(scriptName == "scripts\\ai\\WILD\\L_WILD_GF_FROG.lua") ||
|
||||
(scriptName == "scripts\\empty.lua")
|
||||
)) Game::logger->LogDebug("CppScripts", "LOT %i attempted to load CppScript for '%s', but returned InvalidScript.", parent->GetLOT(), scriptName.c_str());
|
||||
)) LOG_DEBUG("LOT %i attempted to load CppScript for '%s', but returned InvalidScript.", parent->GetLOT(), scriptName.c_str());
|
||||
}
|
||||
|
||||
m_Scripts[scriptName] = script;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include "InventoryComponent.h"
|
||||
#include "SkillComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
|
||||
void TriggerGas::OnStartup(Entity* self) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "GfParrotCrash.h"
|
||||
#include "SkillComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
void GfParrotCrash::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
|
||||
auto* skillComponent = self->GetComponent<SkillComponent>();
|
||||
|
@@ -19,7 +19,7 @@
|
||||
#include "eGameActivity.h"
|
||||
|
||||
void SGCannon::OnStartup(Entity* self) {
|
||||
Game::logger->Log("SGCannon", "OnStartup");
|
||||
LOG("OnStartup");
|
||||
|
||||
m_Waves = GetWaves();
|
||||
constants = GetConstants();
|
||||
@@ -65,7 +65,7 @@ void SGCannon::OnStartup(Entity* self) {
|
||||
}
|
||||
|
||||
void SGCannon::OnPlayerLoaded(Entity* self, Entity* player) {
|
||||
Game::logger->Log("SGCannon", "Player loaded");
|
||||
LOG("Player loaded");
|
||||
self->SetVar<LWOOBJID>(PlayerIDVariable, player->GetObjectID());
|
||||
}
|
||||
|
||||
@@ -76,15 +76,15 @@ void SGCannon::OnFireEventServerSide(Entity* self, Entity* sender, std::string a
|
||||
|
||||
void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, int32_t value2,
|
||||
const std::u16string& stringValue) {
|
||||
Game::logger->Log("SGCannon", "Got activity state change request: %s", GeneralUtils::UTF16ToWTF8(stringValue).c_str());
|
||||
LOG("Got activity state change request: %s", GeneralUtils::UTF16ToWTF8(stringValue).c_str());
|
||||
if (stringValue == u"clientready") {
|
||||
auto* player = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(PlayerIDVariable));
|
||||
if (player != nullptr) {
|
||||
Game::logger->Log("SGCannon", "Player is ready");
|
||||
LOG("Player is ready");
|
||||
/*GameMessages::SendSetStunned(player->GetObjectID(), eStateChangeType::PUSH, player->GetSystemAddress(), LWOOBJID_EMPTY,
|
||||
true, true, true, true, true, true, true);*/
|
||||
|
||||
Game::logger->Log("SGCannon", "Sending ActivityEnter");
|
||||
LOG("Sending ActivityEnter");
|
||||
|
||||
GameMessages::SendActivityEnter(self->GetObjectID(), player->GetSystemAddress());
|
||||
|
||||
@@ -93,11 +93,11 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int
|
||||
if (shootingGalleryComponent != nullptr) {
|
||||
shootingGalleryComponent->SetCurrentPlayerID(player->GetObjectID());
|
||||
|
||||
Game::logger->Log("SGCannon", "Setting player ID");
|
||||
LOG("Setting player ID");
|
||||
|
||||
Game::entityManager->SerializeEntity(self);
|
||||
} else {
|
||||
Game::logger->Log("SGCannon", "Shooting gallery component is null");
|
||||
LOG("Shooting gallery component is null");
|
||||
}
|
||||
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
@@ -129,7 +129,7 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int
|
||||
|
||||
//GameMessages::SendRequestActivityEnter(self->GetObjectID(), player->GetSystemAddress(), false, player->GetObjectID());
|
||||
} else {
|
||||
Game::logger->Log("SGCannon", "Player not found");
|
||||
LOG("Player not found");
|
||||
}
|
||||
} else if (value1 == 1200) {
|
||||
StartGame(self);
|
||||
@@ -184,7 +184,7 @@ void SGCannon::SpawnWaveTimerFunc(Entity* self) {
|
||||
SpawnObject(self, enemyToSpawn, true);
|
||||
}
|
||||
|
||||
Game::logger->Log("SGCannon", "Current wave spawn: %i/%i", wave, m_Waves.size());
|
||||
LOG("Current wave spawn: %i/%i", wave, m_Waves.size());
|
||||
|
||||
// All waves completed
|
||||
const auto timeLimit = (float_t)self->GetVar<uint32_t>(TimeLimitVariable);
|
||||
@@ -199,7 +199,7 @@ void SGCannon::SpawnWaveTimerFunc(Entity* self) {
|
||||
GameMessages::SendPlayFXEffect(player->GetObjectID(), -1, u"SG-start", "");
|
||||
|
||||
GameMessages::SendStartActivityTime(self->GetObjectID(), timeLimit, player->GetSystemAddress());
|
||||
Game::logger->Log("SGCannon", "Sending ActivityPause false");
|
||||
LOG("Sending ActivityPause false");
|
||||
|
||||
GameMessages::SendActivityPause(self->GetObjectID(), false, player->GetSystemAddress());
|
||||
}
|
||||
@@ -222,7 +222,7 @@ void SGCannon::EndWaveTimerFunc(Entity* self) {
|
||||
self->SetNetworkVar<uint32_t>(WaveNumVariable, self->GetVar<uint32_t>(ThisWaveVariable) + 1);
|
||||
self->SetNetworkVar<uint32_t>(WaveStrVariable, self->GetVar<uint32_t>(TimeLimitVariable));
|
||||
|
||||
Game::logger->Log("SGCannon", "Current wave: %i/%i", self->GetVar<uint32_t>(ThisWaveVariable), m_Waves.size());
|
||||
LOG("Current wave: %i/%i", self->GetVar<uint32_t>(ThisWaveVariable), m_Waves.size());
|
||||
|
||||
if (self->GetVar<uint32_t>(ThisWaveVariable) >= m_Waves.size()) {
|
||||
ActivityTimerStart(self, GameOverTimer, 0.1, 0.1);
|
||||
@@ -230,7 +230,7 @@ void SGCannon::EndWaveTimerFunc(Entity* self) {
|
||||
ActivityTimerStart(self, SpawnWaveTimer, constants.inBetweenWavePause, constants.inBetweenWavePause);
|
||||
}
|
||||
|
||||
Game::logger->Log("SGCannon", "Sending ActivityPause true");
|
||||
LOG("Sending ActivityPause true");
|
||||
|
||||
GameMessages::SendActivityPause(self->GetObjectID(), true);
|
||||
if (self->GetVar<bool>(SuperChargeActiveVariable) && !self->GetVar<bool>(SuperChargePausedVariable)) {
|
||||
@@ -241,7 +241,7 @@ void SGCannon::EndWaveTimerFunc(Entity* self) {
|
||||
void SGCannon::GameOverTimerFunc(Entity* self) {
|
||||
auto* player = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(PlayerIDVariable));
|
||||
if (player != nullptr) {
|
||||
Game::logger->Log("SGCannon", "Sending ActivityPause true");
|
||||
LOG_DEBUG("Sending ActivityPause true");
|
||||
|
||||
GameMessages::SendActivityPause(self->GetObjectID(), true, player->GetSystemAddress());
|
||||
|
||||
@@ -261,27 +261,27 @@ void SGCannon::GameOverTimerFunc(Entity* self) {
|
||||
|
||||
void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) {
|
||||
if (self->GetVar<bool>(GameStartedVariable)) {
|
||||
Game::logger->LogDebug("SGCannon", "time name %s %s", name.c_str(), name.substr(7).c_str());
|
||||
LOG_DEBUG("time name %s %s", name.c_str(), name.substr(7).c_str());
|
||||
const auto spawnNumber = (uint32_t)std::stoi(name.substr(7));
|
||||
const auto& activeSpawns = self->GetVar<std::vector<SGEnemy>>(ActiveSpawnsVariable);
|
||||
Game::logger->LogDebug("SGCannon", "size %i, %i", activeSpawns.size(), spawnNumber);
|
||||
LOG_DEBUG("size %i, %i", activeSpawns.size(), spawnNumber);
|
||||
if (activeSpawns.size() <= spawnNumber) {
|
||||
Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size());
|
||||
LOG_DEBUG("Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size());
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& toSpawn = activeSpawns.at(spawnNumber);
|
||||
Game::logger->LogDebug("SGCannon", "toSpawn %i", toSpawn.spawnPaths.size());
|
||||
LOG_DEBUG("toSpawn %i", toSpawn.spawnPaths.size());
|
||||
const auto pathIndex = GeneralUtils::GenerateRandomNumber<float_t>(0, toSpawn.spawnPaths.size() - 1);
|
||||
Game::logger->LogDebug("SGCannon", "index %f", pathIndex);
|
||||
Game::logger->LogDebug("SGCannon", "%s", toSpawn.spawnPaths.at(pathIndex).c_str());
|
||||
LOG_DEBUG("index %f", pathIndex);
|
||||
LOG_DEBUG("%s", toSpawn.spawnPaths.at(pathIndex).c_str());
|
||||
const auto* path = Game::zoneManager->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex));
|
||||
if (!path) {
|
||||
Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex);
|
||||
LOG_DEBUG("Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
Game::logger->LogDebug("SGCannon", "%s", path->pathName.c_str());
|
||||
LOG_DEBUG("%s", path->pathName.c_str());
|
||||
|
||||
auto info = EntityInfo{};
|
||||
info.lot = toSpawn.lot;
|
||||
@@ -297,7 +297,7 @@ void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) {
|
||||
new LDFData<std::u16string>(u"groupID", u"SGEnemy")
|
||||
};
|
||||
|
||||
Game::logger->Log("SGCannon", "Spawning enemy %i on path %s", toSpawn.lot, path->pathName.c_str());
|
||||
LOG_DEBUG("Spawning enemy %i on path %s", toSpawn.lot, path->pathName.c_str());
|
||||
|
||||
auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self);
|
||||
Game::entityManager->ConstructEntity(enemy);
|
||||
@@ -374,7 +374,7 @@ void SGCannon::StartGame(Entity* self) {
|
||||
auto* player = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(PlayerIDVariable));
|
||||
if (player != nullptr) {
|
||||
GetLeaderboardData(self, player->GetObjectID(), GetActivityID(self), 1);
|
||||
Game::logger->Log("SGCannon", "Sending ActivityStart");
|
||||
LOG("Sending ActivityStart");
|
||||
GameMessages::SendActivityStart(self->GetObjectID(), player->GetSystemAddress());
|
||||
|
||||
GameMessages::SendPlayFXEffect(self->GetObjectID(), -1, u"start", "");
|
||||
@@ -656,7 +656,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time
|
||||
|
||||
auto scScore = self->GetVar<uint32_t>(TotalScoreVariable) - lastSuperTotal;
|
||||
|
||||
Game::logger->Log("SGCannon", "LastSuperTotal: %i, scScore: %i, constants.chargedPoints: %i",
|
||||
LOG("LastSuperTotal: %i, scScore: %i, constants.chargedPoints: %i",
|
||||
lastSuperTotal, scScore, constants.chargedPoints
|
||||
);
|
||||
|
||||
@@ -740,7 +740,7 @@ void SGCannon::ToggleSuperCharge(Entity* self, bool enable) {
|
||||
auto* player = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(PlayerIDVariable));
|
||||
|
||||
if (player == nullptr) {
|
||||
Game::logger->Log("SGCannon", "Player not found in toggle super charge");
|
||||
LOG("Player not found in toggle super charge");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -748,7 +748,7 @@ void SGCannon::ToggleSuperCharge(Entity* self, bool enable) {
|
||||
|
||||
auto equippedItems = inventoryComponent->GetEquippedItems();
|
||||
|
||||
Game::logger->Log("SGCannon", "Player has %d equipped items", equippedItems.size());
|
||||
LOG("Player has %d equipped items", equippedItems.size());
|
||||
|
||||
auto skillID = constants.cannonSkill;
|
||||
auto cooldown = constants.cannonRefireRate;
|
||||
@@ -756,12 +756,12 @@ void SGCannon::ToggleSuperCharge(Entity* self, bool enable) {
|
||||
auto* selfInventoryComponent = self->GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventoryComponent == nullptr) {
|
||||
Game::logger->Log("SGCannon", "Inventory component not found");
|
||||
LOG("Inventory component not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
Game::logger->Log("SGCannon", "Player is activating super charge");
|
||||
LOG("Player is activating super charge");
|
||||
selfInventoryComponent->UpdateSlot("greeble_r", { ObjectIDManager::GenerateRandomObjectID(), 6505, 1, 0 });
|
||||
selfInventoryComponent->UpdateSlot("greeble_l", { ObjectIDManager::GenerateRandomObjectID(), 6506, 1, 0 });
|
||||
|
||||
@@ -774,19 +774,19 @@ void SGCannon::ToggleSuperCharge(Entity* self, bool enable) {
|
||||
|
||||
self->SetNetworkVar<float>(u"SuperChargeBar", 0);
|
||||
|
||||
Game::logger->Log("SGCannon", "Player disables super charge");
|
||||
LOG("Player disables super charge");
|
||||
|
||||
// TODO: Unequip items
|
||||
for (const auto& equipped : equippedItems) {
|
||||
if (equipped.first == "special_r" || equipped.first == "special_l") {
|
||||
Game::logger->Log("SGCannon", "Trying to unequip a weapon, %i", equipped.second.lot);
|
||||
LOG("Trying to unequip a weapon, %i", equipped.second.lot);
|
||||
|
||||
auto* item = inventoryComponent->FindItemById(equipped.second.id);
|
||||
|
||||
if (item != nullptr) {
|
||||
inventoryComponent->UnEquipItem(item);
|
||||
} else {
|
||||
Game::logger->Log("SGCannon", "Item not found, %i", equipped.second.lot);
|
||||
LOG("Item not found, %i", equipped.second.lot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user