diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 0ac30b561..75d1051ea 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -140,6 +140,12 @@ CServerHandler::CServerHandler() { uuid = boost::uuids::to_string(boost::uuids::random_generator()()); registerTypesLobbyPacks(*applier); + + auto lastDifficulty = settings["general"]["lastDifficulty"]; + if (lastDifficulty.isNumber()) + { + si->difficulty = lastDifficulty.Integer(); + } } void CServerHandler::threadRunNetwork() @@ -193,8 +199,16 @@ void CServerHandler::startLocalServerAndConnect(bool connectToLobby) serverRunner.reset(new ServerThreadRunner()); #endif + auto si = std::make_shared(); + + auto lastDifficulty = settings["general"]["lastDifficulty"]; + if (lastDifficulty.isNumber()) + { + si->difficulty = lastDifficulty.Integer(); + } + logNetwork->trace("\tStarting local server"); - serverRunner->start(getLocalPort(), connectToLobby); + serverRunner->start(getLocalPort(), connectToLobby, si); logNetwork->trace("\tConnecting to local server"); connectToServer(getLocalHostname(), getLocalPort()); logNetwork->trace("\tWaiting for connection"); diff --git a/client/ServerRunner.cpp b/client/ServerRunner.cpp index 59cce1110..8ab4df84b 100644 --- a/client/ServerRunner.cpp +++ b/client/ServerRunner.cpp @@ -23,10 +23,15 @@ ServerThreadRunner::ServerThreadRunner() = default; ServerThreadRunner::~ServerThreadRunner() = default; -void ServerThreadRunner::start(uint16_t port, bool connectToLobby) +void ServerThreadRunner::start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) { server = std::make_unique(port, connectToLobby, true); + if (startingInfo) + { + server->si = startingInfo; //Else use default + } + threadRunLocalServer = boost::thread([this]{ setThreadName("runServer"); server->run(); @@ -68,7 +73,7 @@ int ServerProcessRunner::exitCode() return child->exit_code(); } -void ServerProcessRunner::start(uint16_t port, bool connectToLobby) +void ServerProcessRunner::start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) { boost::filesystem::path serverPath = VCMIDirs::get().serverPath(); boost::filesystem::path logPath = VCMIDirs::get().userLogsPath() / "server_log.txt"; diff --git a/client/ServerRunner.h b/client/ServerRunner.h index 115dcebfa..26503595e 100644 --- a/client/ServerRunner.h +++ b/client/ServerRunner.h @@ -10,11 +10,12 @@ #pragma once class CVCMIServer; +struct StartInfo; class IServerRunner { public: - virtual void start(uint16_t port, bool connectToLobby) = 0; + virtual void start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) = 0; virtual void shutdown() = 0; virtual void wait() = 0; virtual int exitCode() = 0; @@ -28,7 +29,7 @@ class ServerThreadRunner : public IServerRunner, boost::noncopyable std::unique_ptr server; boost::thread threadRunLocalServer; public: - void start(uint16_t port, bool connectToLobby) override; + void start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) override; void shutdown() override; void wait() override; int exitCode() override; @@ -50,7 +51,7 @@ class ServerProcessRunner : public IServerRunner, boost::noncopyable std::unique_ptr child; public: - void start(uint16_t port, bool connectToLobby) override; + void start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) override; void shutdown() override; void wait() override; int exitCode() override; diff --git a/client/lobby/CLobbyScreen.cpp b/client/lobby/CLobbyScreen.cpp index f08aacdfe..262dcb7f2 100644 --- a/client/lobby/CLobbyScreen.cpp +++ b/client/lobby/CLobbyScreen.cpp @@ -162,6 +162,10 @@ void CLobbyScreen::startScenario(bool allowOnlyAI) tabRand->saveOptions(*CSH->si->mapGenOptions); } + // Save chosen difficulty + Settings lastDifficulty = settings.write["general"]["lastDifficulty"]; + lastDifficulty->Integer() = getCurrentDifficulty(); + if (CSH->validateGameStart(allowOnlyAI)) { CSH->sendStartGame(allowOnlyAI); diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 890b90dfa..f566c3cc1 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -28,6 +28,7 @@ "lastSave", "lastSettingsTab", "lastCampaign", + "lastDifficulty", "saveFrequency", "notifications", "extraDump", @@ -85,6 +86,10 @@ "type" : "string", "default" : "" }, + "lastDifficulty" : { + "type" : "number", + "default" : 1 + }, "saveFrequency" : { "type" : "number", "default" : 1