1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

restore last used address in Multiplayer join dialog

in all other cases (when machine is host) hardcoded localhost address is displayed
This commit is contained in:
Andrey Filipenkov 2022-10-01 17:41:12 +03:00
parent 1aefbd14a7
commit 8f51a8756b
3 changed files with 18 additions and 6 deletions

View File

@ -59,6 +59,8 @@
template<typename T> class CApplyOnLobby; template<typename T> class CApplyOnLobby;
const std::string CServerHandler::localhostAddress{"127.0.0.1"};
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
extern std::atomic_bool androidTestServerReadyFlag; extern std::atomic_bool androidTestServerReadyFlag;
#endif #endif
@ -171,7 +173,7 @@ void CServerHandler::startLocalServerAndConnect()
auto errorMsg = CGI->generaltexth->localizedTexts["server"]["errors"]["existingProcess"].String(); auto errorMsg = CGI->generaltexth->localizedTexts["server"]["errors"]["existingProcess"].String();
try try
{ {
CConnection testConnection(settings["server"]["server"].String(), getDefaultPort(), NAME, uuid); CConnection testConnection(localhostAddress, getDefaultPort(), NAME, uuid);
logNetwork->error("Port is busy, check if another instance of vcmiserver is working"); logNetwork->error("Port is busy, check if another instance of vcmiserver is working");
CInfoWindow::showInfoDialog(errorMsg, {}); CInfoWindow::showInfoDialog(errorMsg, {});
return; return;
@ -243,7 +245,7 @@ void CServerHandler::startLocalServerAndConnect()
#else #else
const ui16 port = 0; const ui16 port = 0;
#endif #endif
justConnectToServer(settings["server"]["server"].String(), port); justConnectToServer(localhostAddress, port);
logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff()); logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff());
} }
@ -269,9 +271,17 @@ void CServerHandler::justConnectToServer(const std::string & addr, const ui16 po
} }
if(state == EClientState::CONNECTION_CANCELLED) if(state == EClientState::CONNECTION_CANCELLED)
{
logNetwork->info("Connection aborted by player!"); logNetwork->info("Connection aborted by player!");
else return;
c->handler = std::make_shared<boost::thread>(&CServerHandler::threadHandleConnection, this); }
c->handler = std::make_shared<boost::thread>(&CServerHandler::threadHandleConnection, this);
if(addr.empty() || addr == localhostAddress)
return;
Settings serverAddress = settings.write["server"]["server"];
serverAddress->String() = addr;
} }
void CServerHandler::applyPacksOnLobbyScreen() void CServerHandler::applyPacksOnLobbyScreen()
@ -633,7 +643,7 @@ void CServerHandler::debugStartTest(std::string filename, bool save)
screenType = ESelectionScreen::newGame; screenType = ESelectionScreen::newGame;
} }
if(settings["session"]["donotstartserver"].Bool()) if(settings["session"]["donotstartserver"].Bool())
justConnectToServer("127.0.0.1", 3030); justConnectToServer(localhostAddress, 3030);
else else
startLocalServerAndConnect(); startLocalServerAndConnect();

View File

@ -106,6 +106,8 @@ public:
CondSh<bool> campaignServerRestartLock; CondSh<bool> campaignServerRestartLock;
static const std::string localhostAddress;
CServerHandler(); CServerHandler();
void resetStateForLobby(const StartInfo::EMode mode, const std::vector<std::string> * names = nullptr); void resetStateForLobby(const StartInfo::EMode mode, const std::vector<std::string> * names = nullptr);

View File

@ -481,7 +481,7 @@ CSimpleJoinScreen::CSimpleJoinScreen(bool host)
inputAddress->giveFocus(); inputAddress->giveFocus();
} }
inputAddress->setText(settings["server"]["server"].String(), true); inputAddress->setText(host ? CServerHandler::localhostAddress : settings["server"]["server"].String(), true);
inputPort->setText(CServerHandler::getDefaultPortStr(), true); inputPort->setText(CServerHandler::getDefaultPortStr(), true);
buttonCancel = std::make_shared<CButton>(Point(142, 142), "MUBCANC.DEF", CGI->generaltexth->zelp[561], std::bind(&CSimpleJoinScreen::leaveScreen, this), SDLK_ESCAPE); buttonCancel = std::make_shared<CButton>(Point(142, 142), "MUBCANC.DEF", CGI->generaltexth->zelp[561], std::bind(&CSimpleJoinScreen::leaveScreen, this), SDLK_ESCAPE);