diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-06-01 19:35:16 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-06-01 19:35:16 +0300 |
commit | cce216b983ed4e36869046e7c537f47d34734340 (patch) | |
tree | a2fc63de315aa5d835357fb353c7cde5ad991a48 | |
parent | 49f27fffbe07e66a3047812a838f03d7636cc4a9 (diff) | |
download | plus-cce216b983ed4e36869046e7c537f47d34734340.tar.gz plus-cce216b983ed4e36869046e7c537f47d34734340.tar.bz2 plus-cce216b983ed4e36869046e7c537f47d34734340.tar.xz plus-cce216b983ed4e36869046e7c537f47d34734340.zip |
Add alternate host name to servers list.
First try will be by hostname, if it failed in name resolution
will be used alt host name
This allow connect to server with static ip address even if dns is broken.
-rw-r--r-- | src/gui/serverdialog.cpp | 4 | ||||
-rw-r--r-- | src/net/ea/network.cpp | 20 | ||||
-rw-r--r-- | src/net/serverinfo.h | 4 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 488a3c3d7..2da780046 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -379,6 +379,7 @@ void ServerDialog::connectToSelectedServer() ServerInfo server = mServers.at(index); mServerInfo->hostname = server.hostname; + mServerInfo->althostname = server.althostname; mServerInfo->port = server.port; mServerInfo->type = server.type; mServerInfo->name = server.name; @@ -642,6 +643,8 @@ void ServerDialog::loadServers(const bool addNew) if (xmlNameEqual(subNode, "connection")) { server.hostname = XML::getProperty(subNode, "hostname", ""); + server.althostname = XML::getProperty( + subNode, "althostname", ""); server.port = static_cast<uint16_t>( XML::getProperty(subNode, "port", 0)); @@ -687,6 +690,7 @@ void ServerDialog::loadServers(const bool addNew) mServers[i].description = server.description; mServers[i].registerUrl = server.registerUrl; mServers[i].onlineListUrl = server.onlineListUrl; + mServers[i].althostname = server.althostname; mServersListModel->setVersionString(i, version); found = true; break; diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index 2b9c048f7..085901743 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -105,6 +105,7 @@ bool Network::connect(ServerInfo server) server.hostname.c_str(), server.port); mServer.hostname = server.hostname; + mServer.althostname = server.althostname; mServer.port = server.port; // Reset to sane values @@ -190,13 +191,18 @@ bool Network::realConnect() if (TcpNet::resolveHost(&ipAddress, mServer.hostname.c_str(), mServer.port) == -1) { - const std::string errorMessage = std::string( - // TRANSLATORS: error message - _("Unable to resolve host \"")).append( - mServer.hostname).append("\""); - setError(errorMessage); - logger->log("TcpNet::ResolveHost: %s", errorMessage.c_str()); - return false; + if (mServer.althostname.empty() || TcpNet::resolveHost(&ipAddress, + mServer.althostname.c_str(), mServer.port) == -1) + { + const std::string errorMessage = std::string( + // TRANSLATORS: error message + _("Unable to resolve host \"")).append( + mServer.hostname).append("\""); + setError(errorMessage); + logger->log("TcpNet::ResolveHost: %s", errorMessage.c_str()); + return false; + } + logger->log("using alt host name: %s", mServer.althostname.c_str()); } mState = CONNECTING; diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index df7a854e7..515595f1f 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -49,6 +49,7 @@ public: Type type; std::string name; std::string hostname; + std::string althostname; uint16_t port; std::string description; @@ -62,6 +63,7 @@ public: type(TMWATHENA), name(), hostname(), + althostname(), port(6901), description(), registerUrl(), @@ -76,6 +78,7 @@ public: type(info.type), name(info.name), hostname(info.hostname), + althostname(info.althostname), port(info.port), description(info.description), registerUrl(info.registerUrl), @@ -97,6 +100,7 @@ public: type = UNKNOWN; name.clear(); hostname.clear(); + althostname.clear(); port = 0; description.clear(); registerUrl.clear(); |