Allow servers to be run from directories other than build. Read/write files relative to binary instead of cwd (#834)

Allows the server to be run from a non-build directory.  Also only read or write files relative to the build directory, regardless of where the server is run from
This commit is contained in:
Jonathan Romano
2022-11-27 06:59:59 -05:00
committed by GitHub
parent e40a597f18
commit f8f5b731f1
16 changed files with 158 additions and 46 deletions

View File

@@ -13,6 +13,7 @@
#include "dChatFilter.h"
#include "Diagnostics.h"
#include "AssetManager.h"
#include "BinaryPathFinder.h"
#include "PlayerContainer.h"
#include "ChatPacketHandler.h"
@@ -53,9 +54,14 @@ int main(int argc, char** argv) {
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
try {
std::string client_path = config.GetValue("client_location");
if (client_path.empty()) client_path = "./res";
Game::assetManager = new AssetManager(client_path);
std::string clientPathStr = config.GetValue("client_location");
if (clientPathStr.empty()) clientPathStr = "./res";
std::filesystem::path clientPath = std::filesystem::path(clientPathStr);
if (clientPath.is_relative()) {
clientPath = BinaryPathFinder::GetBinaryDir() / clientPath;
}
Game::assetManager = new AssetManager(clientPath);
} catch (std::runtime_error& ex) {
Game::logger->Log("ChatServer", "Got an error while setting up assets: %s", ex.what());
@@ -167,7 +173,7 @@ int main(int argc, char** argv) {
}
dLogger* SetupLogger() {
std::string logPath = "./logs/ChatServer_" + std::to_string(time(nullptr)) + ".log";
std::string logPath = (BinaryPathFinder::GetBinaryDir() / ("logs/ChatServer_" + std::to_string(time(nullptr)) + ".log")).string();
bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG