From 9094c99759a9c83bd9d41309a08a5d762fa586b8 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Mon, 28 Nov 2016 02:01:07 +0300 Subject: [PATCH] Fixed CID 1366403 --- client/CMT.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 5e69e36f6..87935bf52 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -70,7 +70,7 @@ namespace bfs = boost::filesystem; std::string NAME_AFFIX = "client"; std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name CGuiHandler GH; -static CClient *client=nullptr; +static CClient *client = nullptr; int preferredDriverIndex = -1; SDL_Window * mainWindow = nullptr; @@ -619,17 +619,22 @@ void processCommand(const std::string &message) } else if(cn=="save") { + if(!client) + { + std::cout << "Game in not active"; + return; + } std::string fname; readed >> fname; client->save(fname); } - else if(cn=="load") - { - // TODO: this code should end the running game and manage to call startGame instead - std::string fname; - readed >> fname; - client->loadGame(fname); - } +// else if(cn=="load") +// { +// // TODO: this code should end the running game and manage to call startGame instead +// std::string fname; +// readed >> fname; +// client->loadGame(fname); +// } else if(message=="get txt") { std::cout << "Command accepted.\t"; @@ -832,6 +837,11 @@ void processCommand(const std::string &message) else if(cn == "gosolo") { boost::unique_lock un(*CPlayerInterface::pim); + if(!client) + { + std::cout << "Game in not active"; + return; + } PlayerColor color; if(session["aiSolo"].Bool()) { @@ -866,6 +876,11 @@ void processCommand(const std::string &message) boost::to_lower(colorName); boost::unique_lock un(*CPlayerInterface::pim); + if(!client) + { + std::cout << "Game in not active"; + return; + } PlayerColor color; if(LOCPLINT) color = LOCPLINT->playerID; @@ -1245,7 +1260,7 @@ void startGame(StartInfo * options, CConnection *serv/* = nullptr*/) } } - client = new CClient; + client = new CClient(); CPlayerInterface::howManyPeople = 0; switch(options->mode) //new game { @@ -1264,7 +1279,7 @@ void startGame(StartInfo * options, CConnection *serv/* = nullptr*/) break; } - client->connectionHandler = new boost::thread(&CClient::run, client); + client->connectionHandler = new boost::thread(&CClient::run, client); } void endGame()