diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 40bb64ce1..46495145c 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -17,6 +17,7 @@ #include "lobby/CSelectionBase.h" #include "lobby/CLobbyScreen.h" +#include "windows/InfoWindows.h" #include "mainmenu/CMainMenu.h" @@ -161,6 +162,20 @@ void CServerHandler::startLocalServerAndConnect() threadRunLocalServer->join(); th->update(); + + auto errorMsg = CGI->generaltexth->localizedTexts["server"]["errors"]["existingProcess"].String(); + try + { + CConnection testConnection(settings["server"]["server"].String(), getDefaultPort(), NAME, uuid); + logNetwork->error("Port is busy, check if another instance of vcmiserver is working"); + CInfoWindow::showInfoDialog(errorMsg, {}); + return; + } + catch(...) + { + //no connection means that port is not busy and we can start local server + } + #ifdef VCMI_ANDROID { CAndroidVMHelper envHelper; diff --git a/config/translate.json b/config/translate.json index 2deb170aa..ba797d4d9 100644 --- a/config/translate.json +++ b/config/translate.json @@ -27,6 +27,13 @@ "spellUnknownProblem": "Unknown problem with this spell, no more information available.", "playerAttacked" : "Player has been attacked: %s" }, + "server" : + { + "errors" : + { + "existingProcess" : "Another vcmiserver process is running, please terminate it first" + } + }, "systemOptions" : { "fullscreenButton" : @@ -67,18 +74,18 @@ "allOf" : "All of the following:", "noneOf" : "None of the following:" }, - "heroWindow": - { - "openCommander": - { - "label": "Open commander window", - "help": "Displays information about commander of this hero" - } - }, - "commanderWindow": - { - "artifactMessage": "Do you want to give this artifact back to hero?" - }, + "heroWindow" : + { + "openCommander" : + { + "label" : "Open commander window", + "help" : "Displays information about commander of this hero" + } + }, + "commanderWindow": + { + "artifactMessage": "Do you want to give this artifact back to hero?" + }, "creatureWindow" : { "showBonuses" :