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:
David Markowitz
2023-10-21 16:31:55 -07:00
committed by GitHub
parent 131239538b
commit 5942182486
160 changed files with 1013 additions and 985 deletions

View File

@@ -2,7 +2,7 @@
#include <string>
#include "Game.h"
#include "dServer.h"
#include "dLogger.h"
#include "Logger.h"
#include "dConfig.h"
#include "CDClientDatabase.h"
#include "CDClientManager.h"
@@ -13,7 +13,7 @@
#include "eConnectionType.h"
#include "eMasterMessageType.h"
InstanceManager::InstanceManager(dLogger* logger, const std::string& externalIP) {
InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) {
mLogger = logger;
mExternalIP = externalIP;
m_LastPort = std::atoi(Game::config->GetValue("world_port_start").c_str());
@@ -28,14 +28,13 @@ InstanceManager::~InstanceManager() {
}
Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID) {
mLogger->Log("InstanceManager", "Searching for an instance for mapID %i/%i", mapID, cloneID);
LOG("Searching for an instance for mapID %i/%i", mapID, cloneID);
Instance* instance = FindInstance(mapID, isFriendTransfer, cloneID);
if (instance) return instance;
// If we are shutting down, return a nullptr so a new instance is not created.
if (m_IsShuttingDown) {
Game::logger->Log("InstanceManager",
"Tried to create a new instance map/instance/clone %i/%i/%i, but Master is shutting down.",
LOG("Tried to create a new instance map/instance/clone %i/%i/%i, but Master is shutting down.",
mapID,
m_LastInstanceID + 1,
cloneID);
@@ -89,9 +88,9 @@ Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LW
m_Instances.push_back(instance);
if (instance) {
mLogger->Log("InstanceManager", "Created new instance: %i/%i/%i with min/max %i/%i", mapID, m_LastInstanceID, cloneID, softCap, maxPlayers);
LOG("Created new instance: %i/%i/%i with min/max %i/%i", mapID, m_LastInstanceID, cloneID, softCap, maxPlayers);
return instance;
} else mLogger->Log("InstanceManager", "Failed to create a new instance!");
} else LOG("Failed to create a new instance!");
return nullptr;
}
@@ -179,7 +178,7 @@ void InstanceManager::ReadyInstance(Instance* instance) {
for (const auto& request : pending) {
const auto& zoneId = instance->GetZoneID();
Game::logger->Log("InstanceManager", "Responding to pending request %llu -> %i (%i)", request, zoneId.GetMapID(), zoneId.GetCloneID());
LOG("Responding to pending request %llu -> %i (%i)", request, zoneId.GetMapID(), zoneId.GetCloneID());
MasterPackets::SendZoneTransferResponse(
Game::server,
@@ -208,7 +207,7 @@ void InstanceManager::RequestAffirmation(Instance* instance, const PendingInstan
Game::server->Send(&bitStream, instance->GetSysAddr(), false);
Game::logger->Log("MasterServer", "Sent affirmation request %llu to %i/%i", request.id,
LOG("Sent affirmation request %llu to %i/%i", request.id,
static_cast<int>(instance->GetZoneID().GetMapID()),
static_cast<int>(instance->GetZoneID().GetCloneID())
);
@@ -306,8 +305,7 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon
}
if (m_IsShuttingDown) {
Game::logger->Log("InstanceManager",
"Tried to create a new private instance map/instance/clone %i/%i/%i, but Master is shutting down.",
LOG("Tried to create a new private instance map/instance/clone %i/%i/%i, but Master is shutting down.",
mapID,
m_LastInstanceID + 1,
cloneID);
@@ -346,7 +344,7 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon
m_Instances.push_back(instance);
if (instance) return instance;
else mLogger->Log("InstanceManager", "Failed to create a new instance!");
else LOG("Failed to create a new instance!");
return instance;
}
@@ -359,7 +357,7 @@ Instance* InstanceManager::FindPrivateInstance(const std::string& password) {
continue;
}
mLogger->Log("InstanceManager", "Password: %s == %s => %d", password.c_str(), instance->GetPassword().c_str(), password == instance->GetPassword());
LOG("Password: %s == %s => %d", password.c_str(), instance->GetPassword().c_str(), password == instance->GetPassword());
if (instance->GetPassword() == password) {
return instance;
@@ -410,5 +408,5 @@ void Instance::Shutdown() {
Game::server->Send(&bitStream, this->m_SysAddr, false);
Game::logger->Log("Instance", "Triggered world shutdown for zone/clone/instance %i/%i/%i", GetMapID(), GetCloneID(), GetInstanceID());
LOG("Triggered world shutdown for zone/clone/instance %i/%i/%i", GetMapID(), GetCloneID(), GetInstanceID());
}

View File

@@ -3,7 +3,7 @@
#include "dCommonVars.h"
#include "RakNetTypes.h"
#include "dZMCommon.h"
#include "dLogger.h"
#include "Logger.h"
struct Player {
LWOOBJID id;
@@ -101,7 +101,7 @@ private:
class InstanceManager {
public:
InstanceManager(dLogger* logger, const std::string& externalIP);
InstanceManager(Logger* logger, const std::string& externalIP);
~InstanceManager();
Instance* GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID); //Creates an instance if none found
@@ -131,7 +131,7 @@ public:
void SetIsShuttingDown(bool value) { this->m_IsShuttingDown = value; };
private:
dLogger* mLogger;
Logger* mLogger;
std::string mExternalIP;
std::vector<Instance*> m_Instances;
unsigned short m_LastPort;

View File

@@ -23,7 +23,7 @@
#include "Diagnostics.h"
#include "dCommonVars.h"
#include "dConfig.h"
#include "dLogger.h"
#include "Logger.h"
#include "dServer.h"
#include "AssetManager.h"
#include "BinaryPathFinder.h"
@@ -45,7 +45,7 @@
#include "BitStreamUtils.h"
namespace Game {
dLogger* logger = nullptr;
Logger* logger = nullptr;
dServer* server = nullptr;
InstanceManager* im = nullptr;
dConfig* config = nullptr;
@@ -57,7 +57,7 @@ namespace Game {
bool shutdownSequenceStarted = false;
void ShutdownSequence(int32_t signal = -1);
int32_t FinalizeShutdown(int32_t signal = -1);
dLogger* SetupLogger();
Logger* SetupLogger();
void StartAuthServer();
void StartChatServer();
void HandlePacket(Packet* packet);
@@ -86,27 +86,27 @@ int main(int argc, char** argv) {
if (!Game::logger) return EXIT_FAILURE;
if (!std::filesystem::exists(BinaryPathFinder::GetBinaryDir() / "authconfig.ini")) {
Game::logger->Log("MasterServer", "Couldnt find authconfig.ini");
LOG("Couldnt find authconfig.ini");
return EXIT_FAILURE;
}
if (!std::filesystem::exists(BinaryPathFinder::GetBinaryDir() / "chatconfig.ini")) {
Game::logger->Log("MasterServer", "Couldnt find chatconfig.ini");
LOG("Couldnt find chatconfig.ini");
return EXIT_FAILURE;
}
if (!std::filesystem::exists(BinaryPathFinder::GetBinaryDir() / "masterconfig.ini")) {
Game::logger->Log("MasterServer", "Couldnt find masterconfig.ini");
LOG("Couldnt find masterconfig.ini");
return EXIT_FAILURE;
}
if (!std::filesystem::exists(BinaryPathFinder::GetBinaryDir() / "sharedconfig.ini")) {
Game::logger->Log("MasterServer", "Couldnt find sharedconfig.ini");
LOG("Couldnt find sharedconfig.ini");
return EXIT_FAILURE;
}
if (!std::filesystem::exists(BinaryPathFinder::GetBinaryDir() / "worldconfig.ini")) {
Game::logger->Log("MasterServer", "Couldnt find worldconfig.ini");
LOG("Couldnt find worldconfig.ini");
return EXIT_FAILURE;
}
@@ -116,18 +116,18 @@ int main(int argc, char** argv) {
uint32_t clientNetVersion = 0;
if (!GeneralUtils::TryParse(Game::config->GetValue("client_net_version"), clientNetVersion)) {
Game::logger->Log("MasterServer", "Failed to parse (%s) as net version. Cannot start server as no clients could connect.", Game::config->GetValue("client_net_version").c_str());
Game::logger->Log("MasterServer", "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.");
Game::logger->Log("MasterServer", "Rerun cmake to ensure all config values exist. If client_net_version already exists in sharedconfig.ini, please ensure it is a valid number.");
Game::logger->Log("MasterServer", "like 171022");
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;
}
Game::logger->Log("MasterServer", "Using net version %s", Game::config->GetValue("client_net_version").c_str());
LOG("Using net version %s", Game::config->GetValue("client_net_version").c_str());
Game::logger->Log("MasterServer", "Starting Master server...");
Game::logger->Log("MasterServer", "Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
Game::logger->Log("MasterServer", "Compiled on: %s", __TIMESTAMP__);
LOG("Starting Master server...");
LOG("Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
LOG("Compiled on: %s", __TIMESTAMP__);
//Connect to the MySQL Database
std::string mysql_host = Game::config->GetValue("mysql_host");
@@ -138,8 +138,8 @@ int main(int argc, char** argv) {
try {
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
} catch (sql::SQLException& ex) {
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s", ex.what());
Game::logger->Log("MigrationRunner", "Migrations not run");
LOG("Got an error while connecting to the database: %s", ex.what());
LOG("Migrations not run");
return EXIT_FAILURE;
}
@@ -153,7 +153,7 @@ int main(int argc, char** argv) {
Game::assetManager = new AssetManager(clientPath);
} catch (std::runtime_error& ex) {
Game::logger->Log("MasterServer", "Got an error while setting up assets: %s", ex.what());
LOG("Got an error while setting up assets: %s", ex.what());
return EXIT_FAILURE;
}
@@ -167,25 +167,24 @@ int main(int argc, char** argv) {
if (!cdServerExists) {
if (oldCDServerExists) {
// If the file doesn't exist in the new CDServer location, copy it there. We copy because we may not have write permissions from the previous directory.
Game::logger->Log("MasterServer", "CDServer.sqlite is not located at resServer, but is located at res path. Copying file...");
LOG("CDServer.sqlite is not located at resServer, but is located at res path. Copying file...");
std::filesystem::copy_file(Game::assetManager->GetResPath() / "CDServer.sqlite", BinaryPathFinder::GetBinaryDir() / "resServer" / "CDServer.sqlite");
} else {
Game::logger->Log("MasterServer",
"%s could not be found in resServer or res. Looking for %s to convert to sqlite.",
LOG("%s could not be found in resServer or res. Looking for %s to convert to sqlite.",
(BinaryPathFinder::GetBinaryDir() / "resServer" / "CDServer.sqlite").c_str(),
(Game::assetManager->GetResPath() / "cdclient.fdb").c_str());
AssetMemoryBuffer cdClientBuffer = Game::assetManager->GetFileAsBuffer("cdclient.fdb");
if (!cdClientBuffer.m_Success) {
Game::logger->Log("MasterServer", "Failed to load %s", (Game::assetManager->GetResPath() / "cdclient.fdb").c_str());
LOG("Failed to load %s", (Game::assetManager->GetResPath() / "cdclient.fdb").c_str());
throw std::runtime_error("Aborting initialization due to missing cdclient.fdb.");
}
Game::logger->Log("MasterServer", "Found %s. Converting to SQLite", (Game::assetManager->GetResPath() / "cdclient.fdb").c_str());
LOG("Found %s. Converting to SQLite", (Game::assetManager->GetResPath() / "cdclient.fdb").c_str());
Game::logger->Flush();
if (FdbToSqlite::Convert((BinaryPathFinder::GetBinaryDir() / "resServer").string()).ConvertDatabase(cdClientBuffer) == false) {
Game::logger->Log("MasterServer", "Failed to convert fdb to sqlite.");
LOG("Failed to convert fdb to sqlite.");
return EXIT_FAILURE;
}
cdClientBuffer.close();
@@ -196,9 +195,9 @@ int main(int argc, char** argv) {
try {
CDClientDatabase::Connect((BinaryPathFinder::GetBinaryDir() / "resServer" / "CDServer.sqlite").string());
} catch (CppSQLite3Exception& e) {
Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database");
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
LOG("Unable to connect to CDServer SQLite Database");
LOG("Error: %s", e.errorMessage());
LOG("Error Code: %i", e.errorCode());
return EXIT_FAILURE;
}
@@ -209,10 +208,10 @@ int main(int argc, char** argv) {
try {
CDClientManager::Instance();
} catch (CppSQLite3Exception& e) {
Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database");
Game::logger->Log("WorldServer", "May be caused by corrupted file: %s", (Game::assetManager->GetResPath() / "CDServer.sqlite").string().c_str());
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
LOG("Failed to initialize CDServer SQLite Database");
LOG("May be caused by corrupted file: %s", (Game::assetManager->GetResPath() / "CDServer.sqlite").string().c_str());
LOG("Error: %s", e.errorMessage());
LOG("Error Code: %i", e.errorCode());
return EXIT_FAILURE;
}
@@ -230,7 +229,7 @@ int main(int argc, char** argv) {
userLookupStatement->setString(1, username.c_str());
std::unique_ptr<sql::ResultSet> res(userLookupStatement->executeQuery());
if (res->rowsCount() > 0) {
Game::logger->Log("MasterServer", "Account with name \"%s\" already exists", username.c_str());
LOG("Account with name \"%s\" already exists", username.c_str());
std::cout << "Do you want to change the password of that account? [y/n]?";
std::string prompt = "";
std::cin >> prompt;
@@ -263,9 +262,9 @@ int main(int argc, char** argv) {
userUpdateStatement->setUInt(2, accountId);
userUpdateStatement->execute();
Game::logger->Log("MasterServer", "Account \"%s\" password updated successfully!", username.c_str());
LOG("Account \"%s\" password updated successfully!", username.c_str());
} else {
Game::logger->Log("MasterServer", "Account \"%s\" was not updated.", username.c_str());
LOG("Account \"%s\" was not updated.", username.c_str());
}
return EXIT_SUCCESS;
}
@@ -295,12 +294,12 @@ int main(int argc, char** argv) {
statement->setString(2, std::string(hash, BCRYPT_HASHSIZE).c_str());
statement->setInt(3, 9);
statement->execute();
} catch (sql::SQLException& e) {
Game::logger->Log("MasterServer", "A SQL error occurred!:\n %s", e.what());
} catch(sql::SQLException& e) {
LOG("A SQL error occurred!:\n %s", e.what());
return EXIT_FAILURE;
}
Game::logger->Log("MasterServer", "Account created successfully!");
LOG("Account created successfully!");
return EXIT_SUCCESS;
}
@@ -450,7 +449,7 @@ int main(int argc, char** argv) {
return FinalizeShutdown(EXIT_SUCCESS);
}
dLogger* SetupLogger() {
Logger* SetupLogger() {
std::string logPath =
(BinaryPathFinder::GetBinaryDir() / ("logs/MasterServer_" + std::to_string(time(nullptr)) + ".log")).string();
bool logToConsole = false;
@@ -460,19 +459,19 @@ dLogger* SetupLogger() {
logDebugStatements = true;
#endif
return new dLogger(logPath, logToConsole, logDebugStatements);
return new Logger(logPath, logToConsole, logDebugStatements);
}
void HandlePacket(Packet* packet) {
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION) {
Game::logger->Log("MasterServer", "A server has disconnected");
LOG("A server has disconnected");
//Since this disconnection is intentional, we'll just delete it as
//we'll start a new one anyway if needed:
Instance* instance =
Game::im->GetInstanceBySysAddr(packet->systemAddress);
if (instance) {
Game::logger->Log("MasterServer", "Actually disconnected from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
LOG("Actually disconnected from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
Game::im->RemoveInstance(instance); //Delete the old
}
@@ -488,7 +487,7 @@ void HandlePacket(Packet* packet) {
}
if (packet->data[0] == ID_CONNECTION_LOST) {
Game::logger->Log("MasterServer", "A server has lost the connection");
LOG("A server has lost the connection");
Instance* instance =
Game::im->GetInstanceBySysAddr(packet->systemAddress);
@@ -513,7 +512,7 @@ void HandlePacket(Packet* packet) {
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
switch (static_cast<eMasterMessageType>(packet->data[3])) {
case eMasterMessageType::REQUEST_PERSISTENT_ID: {
Game::logger->Log("MasterServer", "A persistent ID req");
LOG("A persistent ID req");
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
uint64_t requestID = 0;
@@ -525,7 +524,7 @@ void HandlePacket(Packet* packet) {
}
case eMasterMessageType::REQUEST_ZONE_TRANSFER: {
Game::logger->Log("MasterServer", "Received zone transfer req");
LOG("Received zone transfer req");
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
uint64_t requestID = 0;
@@ -538,24 +537,24 @@ void HandlePacket(Packet* packet) {
inStream.Read(zoneID);
inStream.Read(zoneClone);
if (shutdownSequenceStarted) {
Game::logger->Log("MasterServer", "Shutdown sequence has been started. Not creating a new zone.");
LOG("Shutdown sequence has been started. Not creating a new zone.");
break;
}
Instance* in = Game::im->GetInstance(zoneID, false, zoneClone);
for (auto* instance : Game::im->GetInstances()) {
Game::logger->Log("MasterServer", "Instance: %i/%i/%i -> %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance == in);
LOG("Instance: %i/%i/%i -> %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance == in);
}
if (in && !in->GetIsReady()) //Instance not ready, make a pending request
{
in->GetPendingRequests().push_back({ requestID, static_cast<bool>(mythranShift), packet->systemAddress });
Game::logger->Log("MasterServer", "Server not ready, adding pending request %llu %i %i", requestID, zoneID, zoneClone);
LOG("Server not ready, adding pending request %llu %i %i", requestID, zoneID, zoneClone);
break;
}
//Instance is ready, transfer
Game::logger->Log("MasterServer", "Responding to transfer request %llu for zone %i %i", requestID, zoneID, zoneClone);
LOG("Responding to transfer request %llu for zone %i %i", requestID, zoneID, zoneClone);
Game::im->RequestAffirmation(in, { requestID, static_cast<bool>(mythranShift), packet->systemAddress });
break;
}
@@ -616,7 +615,7 @@ void HandlePacket(Packet* packet) {
authServerMasterPeerSysAddr = copy;
}
Game::logger->Log("MasterServer", "Received server info, instance: %i port: %i", theirInstanceID, theirPort);
LOG("Received server info, instance: %i port: %i", theirInstanceID, theirPort);
break;
}
@@ -648,7 +647,7 @@ void HandlePacket(Packet* packet) {
}
activeSessions.insert(std::make_pair(sessionKey, username));
Game::logger->Log("MasterServer", "Got sessionKey %i for user %s", sessionKey, username.c_str());
LOG("Got sessionKey %i for user %s", sessionKey, username.c_str());
break;
}
@@ -754,7 +753,7 @@ void HandlePacket(Packet* packet) {
auto* instance = Game::im->FindPrivateInstance(password.c_str());
Game::logger->Log("MasterServer", "Join private zone: %llu %d %s %p", requestID, mythranShift, password.c_str(), instance);
LOG("Join private zone: %llu %d %s %p", requestID, mythranShift, password.c_str(), instance);
if (instance == nullptr) {
return;
@@ -777,16 +776,16 @@ void HandlePacket(Packet* packet) {
inStream.Read(zoneID);
inStream.Read(instanceID);
Game::logger->Log("MasterServer", "Got world ready %i %i", zoneID, instanceID);
LOG("Got world ready %i %i", zoneID, instanceID);
auto* instance = Game::im->FindInstance(zoneID, instanceID);
if (instance == nullptr) {
Game::logger->Log("MasterServer", "Failed to find zone to ready");
LOG("Failed to find zone to ready");
return;
}
Game::logger->Log("MasterServer", "Ready zone %i", zoneID);
LOG("Ready zone %i", zoneID);
Game::im->ReadyInstance(instance);
break;
}
@@ -798,10 +797,10 @@ void HandlePacket(Packet* packet) {
int32_t zoneID;
inStream.Read(zoneID);
if (shutdownSequenceStarted) {
Game::logger->Log("MasterServer", "Shutdown sequence has been started. Not prepping a new zone.");
LOG("Shutdown sequence has been started. Not prepping a new zone.");
break;
} else {
Game::logger->Log("MasterServer", "Prepping zone %i", zoneID);
LOG("Prepping zone %i", zoneID);
Game::im->GetInstance(zoneID, false, 0);
}
break;
@@ -815,7 +814,7 @@ void HandlePacket(Packet* packet) {
inStream.Read(requestID);
Game::logger->Log("MasterServer", "Got affirmation of transfer %llu", requestID);
LOG("Got affirmation of transfer %llu", requestID);
auto* instance = Game::im->GetInstanceBySysAddr(packet->systemAddress);
@@ -823,7 +822,7 @@ void HandlePacket(Packet* packet) {
return;
Game::im->AffirmTransfer(instance, requestID);
Game::logger->Log("MasterServer", "Affirmation complete %llu", requestID);
LOG("Affirmation complete %llu", requestID);
break;
}
@@ -837,26 +836,26 @@ void HandlePacket(Packet* packet) {
return;
}
Game::logger->Log("MasterServer", "Got shutdown response from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
LOG("Got shutdown response from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
instance->SetIsShuttingDown(true);
break;
}
case eMasterMessageType::SHUTDOWN_UNIVERSE: {
Game::logger->Log("MasterServer", "Received shutdown universe command, shutting down in 10 minutes.");
LOG("Received shutdown universe command, shutting down in 10 minutes.");
Game::shouldShutdown = true;
break;
}
default:
Game::logger->Log("MasterServer", "Unknown master packet ID from server: %i", packet->data[3]);
LOG("Unknown master packet ID from server: %i", packet->data[3]);
}
}
}
void StartChatServer() {
if (Game::shouldShutdown) {
Game::logger->Log("MasterServer", "Currently shutting down. Chat will not be restarted.");
LOG("Currently shutting down. Chat will not be restarted.");
return;
}
#ifdef __APPLE__
@@ -875,7 +874,7 @@ void StartChatServer() {
void StartAuthServer() {
if (Game::shouldShutdown) {
Game::logger->Log("MasterServer", "Currently shutting down. Auth will not be restarted.");
LOG("Currently shutting down. Auth will not be restarted.");
return;
}
#ifdef __APPLE__
@@ -908,13 +907,13 @@ void ShutdownSequence(int32_t signal) {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SHUTDOWN);
Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::logger->Log("MasterServer", "Triggered master shutdown");
LOG("Triggered master shutdown");
}
auto* objIdManager = ObjectIDManager::TryInstance();
if (objIdManager) {
objIdManager->SaveToDatabase();
Game::logger->Log("MasterServer", "Saved ObjectIDTracker to DB");
LOG("Saved ObjectIDTracker to DB");
}
// A server might not be finished spinning up yet, remove all of those here.
@@ -928,7 +927,7 @@ void ShutdownSequence(int32_t signal) {
instance->SetIsShuttingDown(true);
}
Game::logger->Log("MasterServer", "Attempting to shutdown instances, max 60 seconds...");
LOG("Attempting to shutdown instances, max 60 seconds...");
auto t = std::chrono::high_resolution_clock::now();
uint32_t framesSinceShutdownStart = 0;
@@ -956,7 +955,7 @@ void ShutdownSequence(int32_t signal) {
}
if (allInstancesShutdown && authServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS && chatServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
Game::logger->Log("MasterServer", "Finished shutting down MasterServer!");
LOG("Finished shutting down MasterServer!");
break;
}
@@ -966,7 +965,7 @@ void ShutdownSequence(int32_t signal) {
framesSinceShutdownStart++;
if (framesSinceShutdownStart == maxShutdownTime) {
Game::logger->Log("MasterServer", "Finished shutting down by timeout!");
LOG("Finished shutting down by timeout!");
break;
}
}

View File

@@ -2,13 +2,14 @@
// Custom Classes
#include "Database.h"
#include "dLogger.h"
#include "Logger.h"
#include "Game.h"
// Static Variables
ObjectIDManager* ObjectIDManager::m_Address = nullptr;
//! Initializes the manager
void ObjectIDManager::Initialize(dLogger* logger) {
void ObjectIDManager::Initialize(Logger* logger) {
this->mLogger = logger;
this->currentPersistentID = 1;
@@ -39,9 +40,8 @@ void ObjectIDManager::Initialize(dLogger* logger) {
delete result;
delete stmt;
} catch (sql::SQLException& e) {
mLogger->Log("ObjectIDManager", "Unable to fetch max persistent object "
"ID in use. Defaulting to 1.");
mLogger->Log("ObjectIDManager", "SQL error: %s", e.what());
LOG("Unable to fetch max persistent object ID in use. Defaulting to 1.");
LOG("SQL error: %s", e.what());
this->currentPersistentID = 1;
}
}

View File

@@ -3,7 +3,7 @@
// C++
#include <cstdint>
class dLogger;
class Logger;
/*!
\file ObjectIDManager.hpp
@@ -13,7 +13,7 @@ class dLogger;
//! The Object ID Manager
class ObjectIDManager {
private:
dLogger* mLogger;
Logger* mLogger;
static ObjectIDManager* m_Address; //!< The singleton instance
uint32_t currentPersistentID; //!< The highest current persistent ID in use
@@ -35,7 +35,7 @@ public:
}
//! Initializes the manager
void Initialize(dLogger* logger);
void Initialize(Logger* logger);
//! Generates a new persistent ID
/*!