mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Show info dialog when connection to multiplayer server fails
This commit is contained in:
parent
43636af2e4
commit
7c627d8163
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
"vcmi.mainMenu.serverConnecting" : "Connecting...",
|
"vcmi.mainMenu.serverConnecting" : "Connecting...",
|
||||||
"vcmi.mainMenu.serverAddressEnter" : "Enter address:",
|
"vcmi.mainMenu.serverAddressEnter" : "Enter address:",
|
||||||
|
"vcmi.mainMenu.serverConnectionFailed" : "Failed to connect",
|
||||||
"vcmi.mainMenu.serverClosing" : "Closing...",
|
"vcmi.mainMenu.serverClosing" : "Closing...",
|
||||||
"vcmi.mainMenu.hostTCP" : "Host TCP/IP game",
|
"vcmi.mainMenu.hostTCP" : "Host TCP/IP game",
|
||||||
"vcmi.mainMenu.joinTCP" : "Join TCP/IP game",
|
"vcmi.mainMenu.joinTCP" : "Join TCP/IP game",
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
"vcmi.mainMenu.serverConnecting" : "Verbinde...",
|
"vcmi.mainMenu.serverConnecting" : "Verbinde...",
|
||||||
"vcmi.mainMenu.serverAddressEnter" : "Addresse eingeben:",
|
"vcmi.mainMenu.serverAddressEnter" : "Addresse eingeben:",
|
||||||
|
"vcmi.mainMenu.serverConnectionFailed" : "Verbindung fehlgeschlagen",
|
||||||
"vcmi.mainMenu.serverClosing" : "Trenne...",
|
"vcmi.mainMenu.serverClosing" : "Trenne...",
|
||||||
"vcmi.mainMenu.hostTCP" : "Hoste TCP/IP Spiel",
|
"vcmi.mainMenu.hostTCP" : "Hoste TCP/IP Spiel",
|
||||||
"vcmi.mainMenu.joinTCP" : "Trete TCP/IP Spiel bei",
|
"vcmi.mainMenu.joinTCP" : "Trete TCP/IP Spiel bei",
|
||||||
|
@ -251,25 +251,23 @@ void CServerHandler::startLocalServerAndConnect()
|
|||||||
void CServerHandler::justConnectToServer(const std::string & addr, const ui16 port)
|
void CServerHandler::justConnectToServer(const std::string & addr, const ui16 port)
|
||||||
{
|
{
|
||||||
state = EClientState::CONNECTING;
|
state = EClientState::CONNECTING;
|
||||||
|
|
||||||
logNetwork->info("justConnectToServer(%s, %d)", addr, port);
|
|
||||||
|
|
||||||
std::string hostAddressFromSettings = getHostAddressFromSettings();
|
std::string hostAddressFromSettings = getHostAddressFromSettings();
|
||||||
ui16 hostPortFromSettings = getHostPortFromSettings();
|
ui16 hostPortFromSettings = getHostPortFromSettings();
|
||||||
|
|
||||||
logNetwork->info("Host settings %s:%d", hostAddressFromSettings, hostPortFromSettings);
|
|
||||||
|
|
||||||
std::string connectionAddress = addr.size() ? addr : hostAddressFromSettings;
|
std::string connectionAddress = addr.size() ? addr : hostAddressFromSettings;
|
||||||
ui16 connectionPort = port ? port : hostPortFromSettings;
|
ui16 connectionPort = port ? port : hostPortFromSettings;
|
||||||
|
|
||||||
|
logNetwork->info("Connecting to %s:%d", connectionAddress, connectionPort);
|
||||||
|
|
||||||
boost::chrono::duration<long, boost::ratio<1, 1000>> sleepDuration{};
|
boost::chrono::duration<long, boost::ratio<1, 1000>> sleepDuration{};
|
||||||
int maxConnectionAttempts;
|
int maxConnectionAttempts;
|
||||||
|
|
||||||
if(connectionAddress == "127.0.0.1" || connectionAddress == "localhost")
|
if(connectionAddress == "127.0.0.1" || connectionAddress == "localhost")
|
||||||
{
|
{
|
||||||
logNetwork->info("Local server");
|
logNetwork->info("Local server");
|
||||||
sleepDuration = boost::chrono::milliseconds(10);
|
sleepDuration = boost::chrono::milliseconds(10);
|
||||||
maxConnectionAttempts = 1000;
|
maxConnectionAttempts = 100;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -279,14 +277,15 @@ void CServerHandler::justConnectToServer(const std::string & addr, const ui16 po
|
|||||||
}
|
}
|
||||||
|
|
||||||
logNetwork->info("Waiting for %d ms between each of the %d attempts to connect", sleepDuration.count(), maxConnectionAttempts);
|
logNetwork->info("Waiting for %d ms between each of the %d attempts to connect", sleepDuration.count(), maxConnectionAttempts);
|
||||||
|
|
||||||
ui16 connectionAttemptCount = 0;
|
ui16 connectionAttemptCount = 0;
|
||||||
while(!c && state != EClientState::CONNECTION_CANCELLED)
|
while(!c && state != EClientState::CONNECTION_CANCELLED)
|
||||||
{
|
{
|
||||||
connectionAttemptCount++;
|
connectionAttemptCount++;
|
||||||
if(connectionAttemptCount > maxConnectionAttempts)
|
if(connectionAttemptCount > maxConnectionAttempts)
|
||||||
{
|
{
|
||||||
logNetwork->error("\nExceeded maximum of %d connection attempts", maxConnectionAttempts);
|
state = EClientState::CONNECTION_FAILED;
|
||||||
|
logNetwork->error("Exceeded maximum of %d connection attempts", maxConnectionAttempts);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ enum class EClientState : ui8
|
|||||||
LOBBY_CAMPAIGN, // Client is on scenario bonus selection screen
|
LOBBY_CAMPAIGN, // Client is on scenario bonus selection screen
|
||||||
STARTING, // Gameplay interfaces being created, we pause netpacks retrieving
|
STARTING, // Gameplay interfaces being created, we pause netpacks retrieving
|
||||||
GAMEPLAY, // In-game, used by some UI
|
GAMEPLAY, // In-game, used by some UI
|
||||||
DISCONNECTING // We disconnecting, drop all netpacks
|
DISCONNECTING, // We disconnecting, drop all netpacks
|
||||||
|
CONNECTION_FAILED // We could not connect to server
|
||||||
};
|
};
|
||||||
|
|
||||||
class IServerAPI
|
class IServerAPI
|
||||||
|
@ -589,6 +589,15 @@ void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
|
|||||||
|
|
||||||
// async call to prevent thread race
|
// async call to prevent thread race
|
||||||
GH.dispatchMainThread([this](){
|
GH.dispatchMainThread([this](){
|
||||||
|
if(CSH->state == EClientState::CONNECTION_FAILED)
|
||||||
|
{
|
||||||
|
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.mainMenu.serverConnectionFailed"), {});
|
||||||
|
|
||||||
|
textTitle->setText(CGI->generaltexth->translate("vcmi.mainMenu.serverAddressEnter"));
|
||||||
|
GH.startTextInput(inputAddress->pos);
|
||||||
|
buttonOk->block(false);
|
||||||
|
}
|
||||||
|
|
||||||
if(GH.windows().isTopWindow(this))
|
if(GH.windows().isTopWindow(this))
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
Loading…
Reference in New Issue
Block a user