Add enabledpatches config option

The server administrator must now specify which patches they want the
server to load (if deviating from the defaults). There are multiple
reasons for this:

* It's useful to be able to pick and choose which patches you want to
boot the server with; without having to move the directories in and out
of the patch directory
* This way, we can have different default patches for different builds
of the game (104 vs 1013)
* ...ergo, it's easier to rapidly switch builds without having to
rearrange your workspace to properly run them
* This also allows us to remove the std::filesystem stuff, which has
spotty compatibility with slightly older (but still current) versions of
the compilers
This commit is contained in:
2021-05-07 21:29:18 +02:00
parent 32daa68458
commit 5c1bb0acc9
5 changed files with 25 additions and 8 deletions

View File

@@ -14,6 +14,7 @@
#include "JSON.hpp"
#include <fstream>
#include <sstream>
#include <cmath>
using namespace TableData;
@@ -1079,19 +1080,26 @@ void TableData::init() {
}
fstream.close();
// patching: loop through every directory within the patch directory, looking for a matching file
if (!std::filesystem::exists(settings::PATCHDIR)) continue; // patch dir doesn't exist
// patching: load each patch directory specified in the config file
// split config field into individual patch entries
std::stringstream ss(settings::ENABLEDPATCHES);
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
json patch;
for (const auto& patchModule : std::filesystem::directory_iterator(settings::PATCHDIR)) {
for (auto it = begin; it != end; it++) {
// this is the theoretical path of a corresponding patch for this file
std::string patchFile = patchModule.path().generic_u8string() + "/" + table.second;
if (std::filesystem::exists(patchFile)) {
// file exists
std::cout << "[INFO] Patching " << patchFile << std::endl;
std::string patchModuleName = *it;
std::string patchFile = settings::PATCHDIR + patchModuleName + "/" + table.second;
try {
fstream.open(patchFile);
fstream >> patch; // load into temporary json object
std::cout << "[INFO] Patching " << patchFile << std::endl;
patchJSON(table.first, &patch); // patch
fstream.close();
} catch (const std::exception& err) {
// no-op
}
}
}