Merge branch 'main' into rotation-behaviors

This commit is contained in:
David Markowitz
2026-09-30 19:29:23 -07:00
8 changed files with 49 additions and 22 deletions

View File

@@ -503,3 +503,5 @@ This is a Work in Progress, but below are some quick links to documentaion for s
* pwjones1969 * pwjones1969
* [Simon](https://github.com/SimonNitzsche) * [Simon](https://github.com/SimonNitzsche)
* [ALL OF THE NETDEVIL AND LEGO TEAMS!](https://www.mobygames.com/game/macintosh/lego-universe/credits) * [ALL OF THE NETDEVIL AND LEGO TEAMS!](https://www.mobygames.com/game/macintosh/lego-universe/credits)
This codebase uses some amount of AI assistance. Some larger portions may be AI generated as well. Do not use AI tools against the repo however to work on issues. Auto generated PR's/issues may be discarded as spam if done in large amounts.

View File

@@ -40,7 +40,9 @@ void HandlePacket(Packet* packet);
int main(int argc, char** argv) { int main(int argc, char** argv) {
constexpr uint32_t authFramerate = mediumFramerate; constexpr uint32_t authFramerate = mediumFramerate;
constexpr uint32_t authFrameDelta = mediumFrameDelta; constexpr uint32_t authFrameDelta = mediumFrameDelta;
Diagnostics::SetProcessName("Auth"); const auto curTimeStr = std::to_string(time(nullptr));
const auto serviceName = "AuthServer_" + curTimeStr;
Diagnostics::SetProcessName(serviceName);
Diagnostics::SetProcessFileName(argv[0]); Diagnostics::SetProcessFileName(argv[0]);
Diagnostics::Initialize(); Diagnostics::Initialize();
@@ -50,7 +52,7 @@ int main(int argc, char** argv) {
Game::config = new dConfig("authconfig.ini"); Game::config = new dConfig("authconfig.ini");
//Create all the objects we need to run our service: //Create all the objects we need to run our service:
Server::SetupLogger("AuthServer"); Server::SetupLogger(serviceName, "AuthServer");
if (!Game::logger) return EXIT_FAILURE; if (!Game::logger) return EXIT_FAILURE;
Game::config->LogSettings(); Game::config->LogSettings();
@@ -62,7 +64,7 @@ int main(int argc, char** argv) {
Database::Connect(); Database::Connect();
} catch (std::exception& ex) { } catch (std::exception& ex) {
LOG("Got an error while connecting to the database: %s", ex.what()); LOG("Got an error while connecting to the database: %s", ex.what());
Database::Destroy("AuthServer"); Database::Destroy(serviceName);
delete Game::server; delete Game::server;
delete Game::logger; delete Game::logger;
return EXIT_FAILURE; return EXIT_FAILURE;
@@ -156,7 +158,7 @@ int main(int argc, char** argv) {
LOG("Exited Main Loop! (signal %d)", Game::lastSignal); LOG("Exited Main Loop! (signal %d)", Game::lastSignal);
//Delete our objects here: //Delete our objects here:
Database::Destroy("AuthServer"); Database::Destroy(serviceName);
delete Game::server; delete Game::server;
delete Game::logger; delete Game::logger;
delete Game::config; delete Game::config;

View File

@@ -47,7 +47,9 @@ void HandlePacket(Packet* packet);
int main(int argc, char** argv) { int main(int argc, char** argv) {
constexpr uint32_t chatFramerate = mediumFramerate; constexpr uint32_t chatFramerate = mediumFramerate;
constexpr uint32_t chatFrameDelta = mediumFrameDelta; constexpr uint32_t chatFrameDelta = mediumFrameDelta;
Diagnostics::SetProcessName("Chat"); const auto curTimeStr = std::to_string(time(nullptr));
const auto serviceName = "ChatServer_" + curTimeStr;
Diagnostics::SetProcessName(serviceName);
Diagnostics::SetProcessFileName(argv[0]); Diagnostics::SetProcessFileName(argv[0]);
Diagnostics::Initialize(); Diagnostics::Initialize();
@@ -57,7 +59,7 @@ int main(int argc, char** argv) {
Game::config = new dConfig("chatconfig.ini"); Game::config = new dConfig("chatconfig.ini");
//Create all the objects we need to run our service: //Create all the objects we need to run our service:
Server::SetupLogger("ChatServer"); Server::SetupLogger(serviceName, "ChatServer");
if (!Game::logger) return EXIT_FAILURE; if (!Game::logger) return EXIT_FAILURE;
Game::config->LogSettings(); Game::config->LogSettings();
@@ -88,7 +90,7 @@ int main(int argc, char** argv) {
Database::Connect(); Database::Connect();
} catch (std::exception& ex) { } catch (std::exception& ex) {
LOG("Got an error while connecting to the database: %s", ex.what()); LOG("Got an error while connecting to the database: %s", ex.what());
Database::Destroy("ChatServer"); Database::Destroy(serviceName);
delete Game::logger; delete Game::logger;
delete Game::config; delete Game::config;
return EXIT_FAILURE; return EXIT_FAILURE;
@@ -99,7 +101,7 @@ int main(int argc, char** argv) {
if (Game::config->GetValue("web_server_enabled") == "1" && !Game::web.Startup("localhost", web_server_port)) { if (Game::config->GetValue("web_server_enabled") == "1" && !Game::web.Startup("localhost", web_server_port)) {
// if we want the web server and it fails to start, exit // if we want the web server and it fails to start, exit
LOG("Failed to start web server, shutting down."); LOG("Failed to start web server, shutting down.");
Database::Destroy("ChatServer"); Database::Destroy(serviceName);
delete Game::logger; delete Game::logger;
delete Game::config; delete Game::config;
return EXIT_FAILURE; return EXIT_FAILURE;
@@ -200,7 +202,7 @@ int main(int argc, char** argv) {
Game::playerContainer.Shutdown(); Game::playerContainer.Shutdown();
TeamContainer::Shutdown(); TeamContainer::Shutdown();
//Delete our objects here: //Delete our objects here:
Database::Destroy("ChatServer"); Database::Destroy(serviceName);
delete Game::server; delete Game::server;
Game::server = nullptr; Game::server = nullptr;
delete Game::logger; delete Game::logger;

View File

@@ -82,7 +82,7 @@ struct bt_ctx {
}; };
static inline void Bt(struct backtrace_state* state) { static inline void Bt(struct backtrace_state* state) {
std::string fileName = Diagnostics::GetOutDirectory() + "crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log"; std::string fileName = Diagnostics::GetOutDirectory() + "Crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log";
LOG("backtrace is enabled, crash dump located at %s", fileName.c_str()); LOG("backtrace is enabled, crash dump located at %s", fileName.c_str());
FILE* file = fopen(fileName.c_str(), "w+"); FILE* file = fopen(fileName.c_str(), "w+");
if (file != nullptr) { if (file != nullptr) {
@@ -98,7 +98,7 @@ static void ErrorCallback(void* data, const char* msg, int errnum) {
fprintf(stderr, "ERROR: %s (%d)", msg, errnum); fprintf(stderr, "ERROR: %s (%d)", msg, errnum);
ctx->error = 1; ctx->error = 1;
std::string fileName = Diagnostics::GetOutDirectory() + "crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log"; std::string fileName = Diagnostics::GetOutDirectory() + "Crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log";
FILE* file = fopen(fileName.c_str(), "w+"); FILE* file = fopen(fileName.c_str(), "w+");
if (file != nullptr) { if (file != nullptr) {
fprintf(file, "ERROR: %s (%d)", msg, errnum); fprintf(file, "ERROR: %s (%d)", msg, errnum);
@@ -126,7 +126,7 @@ void CatchUnhandled(int sig) {
#ifndef INCLUDE_BACKTRACE #ifndef INCLUDE_BACKTRACE
std::string fileName = Diagnostics::GetOutDirectory() + "crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log"; std::string fileName = Diagnostics::GetOutDirectory() + "Crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log";
LOG("Encountered signal %i, creating crash dump %s", sig, fileName.c_str()); LOG("Encountered signal %i, creating crash dump %s", sig, fileName.c_str());
if (Diagnostics::GetProduceMemoryDump()) { if (Diagnostics::GetProduceMemoryDump()) {
GenerateDump(); GenerateDump();

View File

@@ -61,6 +61,10 @@ namespace Game {
std::mt19937 randomEngine; std::mt19937 randomEngine;
} //namespace Game } //namespace Game
namespace {
std::string g_ServiceName;
}
bool shutdownSequenceStarted = false; bool shutdownSequenceStarted = false;
int ShutdownSequence(int32_t signal = -1); int ShutdownSequence(int32_t signal = -1);
int32_t FinalizeShutdown(int32_t signal = -1); int32_t FinalizeShutdown(int32_t signal = -1);
@@ -80,7 +84,9 @@ int GenerateBCryptPassword(const std::string& password, const int workFactor, ch
int main(int argc, char** argv) { int main(int argc, char** argv) {
constexpr uint32_t masterFramerate = mediumFramerate; constexpr uint32_t masterFramerate = mediumFramerate;
constexpr uint32_t masterFrameDelta = mediumFrameDelta; constexpr uint32_t masterFrameDelta = mediumFrameDelta;
Diagnostics::SetProcessName("Master"); const auto curTimeStr = std::to_string(time(nullptr));
g_ServiceName = "MasterServer_" + curTimeStr;
Diagnostics::SetProcessName(g_ServiceName);
Diagnostics::SetProcessFileName(argv[0]); Diagnostics::SetProcessFileName(argv[0]);
Diagnostics::Initialize(); Diagnostics::Initialize();
@@ -96,7 +102,7 @@ int main(int argc, char** argv) {
Game::config = new dConfig("masterconfig.ini"); Game::config = new dConfig("masterconfig.ini");
//Create all the objects we need to run our service: //Create all the objects we need to run our service:
Server::SetupLogger("MasterServer"); Server::SetupLogger(g_ServiceName, "MasterServer");
if (!Game::logger) return EXIT_FAILURE; if (!Game::logger) return EXIT_FAILURE;
Game::config->LogSettings(); Game::config->LogSettings();
@@ -914,7 +920,7 @@ int ShutdownSequence(int32_t signal) {
int32_t FinalizeShutdown(int32_t signal) { int32_t FinalizeShutdown(int32_t signal) {
//Delete our objects here: //Delete our objects here:
Database::Destroy("MasterServer"); Database::Destroy(g_ServiceName);
if (Game::config) delete Game::config; if (Game::config) delete Game::config;
Game::config = nullptr; Game::config = nullptr;
if (Game::im) delete Game::im; if (Game::im) delete Game::im;

View File

@@ -5,17 +5,18 @@
#include "Logger.h" #include "Logger.h"
#include "dConfig.h" #include "dConfig.h"
void Server::SetupLogger(const std::string_view serviceName) { void Server::SetupLogger(const std::string_view serviceName, const std::string_view folder) {
if (Game::logger) { if (Game::logger) {
LOG("A logger has already been setup, skipping."); LOG("A logger has already been setup, skipping.");
return; return;
} }
const auto logsDir = BinaryPathFinder::GetBinaryDir() / "logs"; auto logsDir = BinaryPathFinder::GetBinaryDir() / "logs";
if (!folder.empty()) logsDir /= folder;
if (!std::filesystem::exists(logsDir)) std::filesystem::create_directories(logsDir); if (!std::filesystem::exists(logsDir)) std::filesystem::create_directories(logsDir);
std::string logPath = (logsDir / serviceName).string() + "_" + std::to_string(time(nullptr)) + ".log"; std::string logPath = (logsDir / serviceName).string() + ".log";
bool logToConsole = false; bool logToConsole = false;
bool logDebugStatements = false; bool logDebugStatements = false;
#ifdef _DEBUG #ifdef _DEBUG

View File

@@ -4,7 +4,8 @@
#include <string_view> #include <string_view>
namespace Server { namespace Server {
void SetupLogger(const std::string_view serviceName); // takes in an optional argument of folder should you want to place the logs in a sub-folder
void SetupLogger(const std::string_view serviceName, const std::string_view folder = "");
}; };
#endif //!__SERVER__H__ #endif //!__SERVER__H__

View File

@@ -99,6 +99,10 @@ namespace Game {
std::string projectVersion = PROJECT_VERSION; std::string projectVersion = PROJECT_VERSION;
} // namespace Game } // namespace Game
namespace {
std::string g_ServiceName;
}
namespace { namespace {
struct TempSessionInfo { struct TempSessionInfo {
SystemAddress sysAddr; SystemAddress sysAddr;
@@ -125,7 +129,10 @@ void HandleMasterPacket(Packet* packet);
void HandlePacket(Packet* packet); void HandlePacket(Packet* packet);
int main(int argc, char** argv) { int main(int argc, char** argv) {
Diagnostics::SetProcessName("World"); const auto curTimeStr = std::to_string(time(nullptr));
g_ServiceName = "WorldServer";
// Set this once here before we parse a bunch of options in case we crash early
Diagnostics::SetProcessName(g_ServiceName);
Diagnostics::SetProcessFileName(argv[0]); Diagnostics::SetProcessFileName(argv[0]);
Diagnostics::Initialize(); Diagnostics::Initialize();
@@ -158,7 +165,13 @@ int main(int argc, char** argv) {
Game::config = new dConfig("worldconfig.ini"); Game::config = new dConfig("worldconfig.ini");
//Create all the objects we need to run our service: //Create all the objects we need to run our service:
Server::SetupLogger("WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(g_InstanceID)); const auto zoneStr = std::to_string(zoneID);
const auto cloneStr = std::to_string(cloneID);
const auto instanceStr = std::to_string(g_InstanceID);
g_ServiceName += "_" + zoneStr + "_" + cloneStr + "_" + instanceStr + "_" + curTimeStr;
// Here we re-set the process name since it'll have more info now
Diagnostics::SetProcessName(g_ServiceName);
Server::SetupLogger(g_ServiceName, "WorldServer/" + zoneStr + "/" + cloneStr + "/");
if (!Game::logger) return EXIT_FAILURE; if (!Game::logger) return EXIT_FAILURE;
Game::config->LogSettings(); Game::config->LogSettings();
@@ -1586,7 +1599,7 @@ void FinalizeShutdown() {
//Delete our objects here: //Delete our objects here:
dpWorld::Shutdown(); dpWorld::Shutdown();
Database::Destroy("WorldServer"); Database::Destroy(g_ServiceName);
if (Game::chatFilter) delete Game::chatFilter; if (Game::chatFilter) delete Game::chatFilter;
Game::chatFilter = nullptr; Game::chatFilter = nullptr;
if (Game::zoneManager) delete Game::zoneManager; if (Game::zoneManager) delete Game::zoneManager;