From bc3612dfe984de825b22edf2a4fd155d5e7bac14 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 28 May 2017 18:26:38 +0800 Subject: [PATCH] [Server] Add commit hash to password --- apps/openmw-mp/main.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index c02d271d5..f8f17a5e6 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -19,6 +19,9 @@ #include "MasterClient.hpp" +#include +#include + #ifdef ENABLE_BREAKPAD #include #endif @@ -26,7 +29,7 @@ using namespace std; using namespace mwmp; -void printVersion(string version, int protocol) +void printVersion(string version, Version::Version ver, int protocol) { cout << "TES3:MP dedicated server " << version; cout << " ("; @@ -56,6 +59,7 @@ void printVersion(string version, int protocol) #endif cout << ")" << endl; cout << "Protocol version: " << protocol << endl; + cout << "Commit hash: " << ver.mCommitHash << endl; cout << "------------------------------------------------------------" << endl; } @@ -148,6 +152,21 @@ private: std::ostream &out2; }; +boost::program_options::variables_map launchOptions(Files::ConfigurationManager &cfgMgr) +{ + namespace bpo = boost::program_options; + bpo::variables_map variables; + bpo::options_description desc; + + desc.add_options() + ("resources", bpo::value()->default_value("resources"), + "set resources directory"); + + cfgMgr.readConfiguration(variables, desc, true); + + return variables; +} + int main(int argc, char *argv[]) { Settings::Manager mgr; @@ -157,6 +176,12 @@ int main(int argc, char *argv[]) loadSettings(mgr); + auto variables = launchOptions(cfgMgr); + + auto version = Version::getOpenmwVersion(variables["resources"].as().toStdString()); + + cout << version.mCommitHash << endl; + int logLevel = mgr.getInt("loglevel", "General"); if (logLevel < Log::LOG_VERBOSE || logLevel > Log::LOG_FATAL) logLevel = Log::LOG_VERBOSE; @@ -196,7 +221,8 @@ int main(int argc, char *argv[]) vector plugins (Utils::split(mgr.getString("plugins", "Plugins"), ',')); - printVersion(TES3MP_VERSION, TES3MP_PROTO_VERSION); + + printVersion(TES3MP_VERSION, version, TES3MP_PROTO_VERSION); setenv("AMXFILE", moddir.c_str(), 1); @@ -219,6 +245,7 @@ int main(int argc, char *argv[]) stringstream sstr(TES3MP_VERSION); sstr << TES3MP_PROTO_VERSION; + sstr << version.mCommitHash; peer->SetIncomingPassword(sstr.str().c_str(), (int)sstr.str().size());