Replace enabledpatches config option with patchmap.json

This should make it a lot easier to manage patch directories when we add
support for each known client build.
This commit is contained in:
dongresource 2023-06-26 05:42:57 +02:00
parent 23ab908366
commit 6537e38987
4 changed files with 39 additions and 16 deletions

View File

@ -1,3 +1,8 @@
# name of the client build the server is targetting.
# used for determining which patches to apply.
# default is beta-20111013 for Academy, beta-20100104 otherwise.
#buildname=beta-20100104
# verbosity level
# 0 = mostly silence
# 1 = debug prints and unknown packets
@ -46,11 +51,6 @@ motd=Welcome to OpenFusion!
# location of the patch folder
#patchdir=tdata/patch/
# Space-separated list of patch folders in patchdir to load from.
# If you uncomment this, note that Academy builds *must* contain 1013,
# and pre-Academy builds must *not* contain it.
#enabledpatches=1013
# xdt json filename
#xdtdata=xdt.json
# NPC json filename
@ -61,6 +61,8 @@ motd=Welcome to OpenFusion!
#pathdata=paths.json
# drop json filename
#dropdata=drops.json
# patchmap json filename
#patchmapdata=patchmap.json
# gruntwork output filename (this is what you submit)
#gruntwork=gruntwork.json
# location of the database

View File

@ -1086,6 +1086,26 @@ static void patchJSON(json* base, json* patch) {
void TableData::init() {
int32_t nextId = INT32_MAX; // next dynamic ID to hand out
json patchmap;
// load patch map
{
std::fstream fstream;
fstream.open(settings::TDATADIR + "/" + settings::PATCHMAPJSON);
if (fstream.fail()) {
std::cerr << "[FATAL] Critical tdata file missing: " << settings::PATCHMAPJSON << std::endl;
exit(1);
}
if (fstream.peek() == std::ifstream::traits_type::eof()) {
std::cerr << "[FATAL] Critical tdata file is empty: " << settings::PATCHMAPJSON << std::endl;
exit(1);
}
fstream >> patchmap;
fstream.close();
}
// base JSON tables
json xdt, paths, drops, eggs, npcs, mobs, gruntwork;
@ -1134,15 +1154,13 @@ void TableData::init() {
fstream >> *table.first;
}
// 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;
// patching: load each patch directory specified in patchmap.json
// fetch list of patches that need to be applied for the current build
json patch;
for (auto it = begin; it != end; it++) {
json patchlist = patchmap["patchmap"][settings::BUILDNAME];
for (auto it = patchlist.begin(); it != patchlist.end(); it++) {
// this is the theoretical path of a corresponding patch for this file
std::string patchModuleName = *it;
std::string patchFile = settings::PATCHDIR + patchModuleName + "/" + table.second;

View File

@ -47,12 +47,13 @@ std::string settings::GRUNTWORKJSON = "gruntwork.json";
std::string settings::MOTDSTRING = "Welcome to OpenFusion!";
std::string settings::DROPSJSON = "drops.json";
std::string settings::PATHJSON = "paths.json";
std::string settings::PATCHMAPJSON = "patchmap.json";
#ifdef ACADEMY
std::string settings::XDTJSON = "xdt1013.json";
std::string settings::ENABLEDPATCHES = "1013";
std::string settings::BUILDNAME = "beta-20111013";
#else
std::string settings::XDTJSON = "xdt.json";
std::string settings::ENABLEDPATCHES = "";
std::string settings::BUILDNAME = "beta-20100104";
#endif // ACADEMY
int settings::ACCLEVEL = 1;
@ -78,6 +79,7 @@ void settings::init() {
return;
}
BUILDNAME = reader.Get("", "buildname", BUILDNAME);
VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY);
SANDBOX = reader.GetBoolean("", "sandbox", SANDBOX);
LOGINPORT = reader.GetInteger("login", "port", LOGINPORT);
@ -105,7 +107,7 @@ void settings::init() {
DBPATH = reader.Get("shard", "dbpath", DBPATH);
TDATADIR = reader.Get("shard", "tdatadir", TDATADIR);
PATCHDIR = reader.Get("shard", "patchdir", PATCHDIR);
ENABLEDPATCHES = reader.Get("shard", "enabledpatches", ENABLEDPATCHES);
PATCHMAPJSON = reader.Get("shard", "patchmapdata", PATCHMAPJSON);
ACCLEVEL = reader.GetInteger("shard", "accountlevel", ACCLEVEL);
EVENTMODE = reader.GetInteger("shard", "eventmode", EVENTMODE);
DISABLEFIRSTUSEFLAG = reader.GetBoolean("shard", "disablefirstuseflag", DISABLEFIRSTUSEFLAG);

View File

@ -29,7 +29,8 @@ namespace settings {
extern std::string GRUNTWORKJSON;
extern std::string DBPATH;
extern std::string PATCHDIR;
extern std::string ENABLEDPATCHES;
extern std::string PATCHMAPJSON;
extern std::string BUILDNAME;
extern std::string TDATADIR;
extern int EVENTMODE;
extern bool MONITORENABLED;