From 38eeec39b49872d0d79ebd49f98d0e65d2ab25cb Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 22:27:05 +0200 Subject: [PATCH] another attempt to fix #105 --- Changelog.md | 1 + src/TConfig.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7ff6d04..0486505 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ - FIXED `MP.CreateEventTimer` filling up the queue (see ) - FIXED `MP.TriggerClientEvent` not kicking the client if it failed - FIXED Lua result queue handling not checking all results +- FIXED bug which caused ServerConfig.toml to generate incorrectly # v3.0.1 diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 4a414da..65c7ba0 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -92,13 +92,20 @@ void TConfig::FlushToFile() { data["HTTP"][StrHTTPServerEnabled.data()] = Application::Settings.HTTPServerEnabled; SetComment(data["HTTP"][StrHTTPServerEnabled.data()].comments(), " Enables the internal HTTP server"); std::stringstream Ss; - Ss << data; - std::ofstream Stream(mConfigFileName, std::ios::trunc | std::ios::out); - Stream << "# This is the BeamMP-Server config file.\n" - "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" - "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" - << Ss.str(); - Stream.flush(); + Ss << "# This is the BeamMP-Server config file.\n" + "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" + "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" + << data; + auto File = std::fopen(mConfigFileName.c_str(), "w+"); + if (!File) { + beammp_error("Failed to create/write to config file: " + GetPlatformAgnosticErrorString()); + throw std::runtime_error("Failed to create/write to config file"); + } + auto Str = Ss.str(); + auto N = std::fwrite(Str.data(), sizeof(char), Str.size(), File); + if (N != Str.size()) { + beammp_error("Failed to write to config file properly, config file might be misshapen"); + } } void TConfig::CreateConfigFile(std::string_view name) { @@ -113,10 +120,6 @@ void TConfig::CreateConfigFile(std::string_view name) { beammp_error("an error occurred and was ignored during config transfer: " + std::string(e.what())); } - { // create file context - std::ofstream ofs(name.data()); - } - FlushToFile(); }