diff --git a/CMakeLists.txt b/CMakeLists.txt index 703531a..020e95d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ elseif (UNIX) endif () include_directories("include/sentry-native/include") - +set(BUILD_SHARED_LIBS OFF) # ------------------------ SENTRY --------------------------------- message(STATUS "Checking for Sentry URL") # this is set by the build system. diff --git a/Changelog.md b/Changelog.md index d0314c1..eeced3e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,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/README.md b/README.md index ab685da..c1156de 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ On windows, use git-bash for these commands. On Linux, these should work in your 1. Make sure you have all [prerequisites](#prerequisites) installed 2. Clone the repository in a location of your choice with `git clone --recurse-submodules https://github.com/BeamMP/BeamMP-Server`. 3. Ensure that all submodules are initialized by running `git submodule update --init --recursive`. Then change into the cloned directory by running `cd BeamMP-Server`. -4. Checkout the branch of the release you want to compile (`master` is often unstable), for example `git checkout tags/v2.3.3` for version 2.3.3. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags). +4. Checkout the branch of the release you want to compile (`master` is often unstable), for example `git checkout tags/v3.0.1` for version 3.0.1. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags). 5. Run `cmake . -DCMAKE_BUILD_TYPE=Release` (with `.`) 6. Run `make` 7. You will now have a `BeamMP-Server` file in your directory, which is executable with `./BeamMP-Server` (`.\BeamMP-Server.exe` for windows). Follow the (windows or linux, doesnt matter) instructions on the [wiki](https://wiki.beammp.com/en/home/Server_Mod) for further setup after installation (which we just did), such as port-forwarding and getting a key to actually run the server. diff --git a/deps/toml11 b/deps/toml11 index fda0a2b..1400dd2 160000 --- a/deps/toml11 +++ b/deps/toml11 @@ -1 +1 @@ -Subproject commit fda0a2b9abd16e356f777c40a675131821c71b00 +Subproject commit 1400dd223fb4297337266fcb5d04b700338aea71 diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 04d6acd..b9503b5 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -88,7 +88,8 @@ void SetComment(CommentsT& Comments, const std::string& Comment) { * whether it is in TConfig.cpp or the configuration file. */ void TConfig::FlushToFile() { - auto data = toml::parse(mConfigFileName); + // auto data = toml::parse(mConfigFileName); + auto data = toml::value {}; data["General"][StrAuthKey.data()] = Application::Settings.Key; SetComment(data["General"][StrAuthKey.data()].comments(), " AuthKey has to be filled out in order to run the server"); data["General"][StrLogChat.data()] = Application::Settings.LogChat; @@ -119,8 +120,22 @@ void TConfig::FlushToFile() { SetComment(data["HTTP"][StrHTTPServerUseSSL.data()].comments(), " Recommended to have enabled for servers which face the internet. With SSL the server will serve https and requires valid key and cert files"); data["HTTP"][StrHTTPServerEnabled.data()] = Application::Settings.HTTPServerEnabled; SetComment(data["HTTP"][StrHTTPServerEnabled.data()].comments(), " Enables the internal HTTP server"); - std::ofstream Stream(mConfigFileName, std::ios::trunc | std::ios::out); - Stream << data << std::flush; + std::stringstream Ss; + 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"); + } + std::fclose(File); } void TConfig::CreateConfigFile(std::string_view name) { @@ -135,32 +150,7 @@ 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(); - - size_t FileSize = fs::file_size(name); - std::fstream ofs { std::string(name), std::ios::in | std::ios::out }; - if (ofs.good()) { - std::string Contents {}; - Contents.resize(FileSize); - ofs.readsome(Contents.data(), FileSize); - ofs.seekp(0); - ofs << "# 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" - << '\n' - << Contents; - beammp_error("There was no \"" + std::string(mConfigFileName) + "\" file (this is normal for the first time running the server), so one was generated for you. It was automatically filled with the settings from your Server.cfg, if you have one. Please open ServerConfig.toml and ensure your AuthKey and other settings are filled in and correct, then restart the server. The old Server.cfg file will no longer be used and causes a warning if it exists from now on."); - mFailed = true; - ofs.close(); - } else { - beammp_error("Couldn't create " + std::string(name) + ". Check permissions, try again, and contact support if it continues not to work."); - Application::SetSubsystemStatus("Config", Application::Status::Bad); - mFailed = true; - } } void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, std::string& OutValue) {