From 0f36c3ea2442a4a2992f3e15dfdc9108ffaf97e7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 15 Jul 2018 22:50:16 +0300 Subject: [PATCH] [Server] Verify integrity of credits file --- apps/openmw-mp/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index 88142d1c7..12be4405f 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -200,6 +201,28 @@ int main(int argc, char *argv[]) Utils::printVersion("TES3MP dedicated server", TES3MP_VERSION, version.mCommitHash, TES3MP_PROTO_VERSION); + // Check for unmodified tes3mp-credits file; this makes it so people can't repackage official releases with + // their own made-up credits, though it obviously has no bearing on unofficial releases that change + // the checksum below + boost::filesystem::path folderPath(boost::filesystem::initial_path()); + folderPath = boost::filesystem::system_complete(boost::filesystem::path(argv[0])).remove_filename(); + std::string creditsPath = folderPath.string() + "/tes3mp-credits"; + + unsigned int expectedChecksumInt = Utils::hexStrToInt("E9CF9D8B"); + bool hasValidCredits = Utils::doesFileHaveChecksum(creditsPath + ".md", expectedChecksumInt); + + if (!hasValidCredits) + hasValidCredits = Utils::doesFileHaveChecksum(creditsPath + ".txt", expectedChecksumInt); + + if (!hasValidCredits) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "To respect the hard work that has gone into\n" + "creating TES3MP, you are required to keep an unmodified tes3mp-credits file\n" + "corresponding to this version of the code in the same folder as this\n" + "executable. It can have either an .md or a .txt extension."); + return 1; + } + setenv("MOD_DIR", moddir.c_str(), 1); // hack for lua setenv("LUA_PATH", Utils::convertPath(plugin_home + "/scripts/?.lua" + ";"