diff options
-rw-r--r-- | src/gui/customserverdialog.cpp | 11 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 16 | ||||
-rw-r--r-- | src/net/serverinfo.h | 12 |
3 files changed, 20 insertions, 19 deletions
diff --git a/src/gui/customserverdialog.cpp b/src/gui/customserverdialog.cpp index 9d56a3ce..e0d25928 100644 --- a/src/gui/customserverdialog.cpp +++ b/src/gui/customserverdialog.cpp @@ -161,12 +161,10 @@ void CustomServerDialog::action(const gcn::ActionEvent &event) if (event.getId() == "addServer") { // Check the given information - if (mServerAddressField->getText().empty() - || mPortField->getText().empty()) + if (mServerAddressField->getText().empty()) { OkDialog *dlg = new OkDialog(_("Error"), - _("Please at least type both the address and the port " - "of the server.")); + _("Please type in at least the address of the server.")); dlg->addActionListener(this); } else @@ -178,7 +176,6 @@ void CustomServerDialog::action(const gcn::ActionEvent &event) serverInfo.name = mNameField->getText(); serverInfo.description = mDescriptionField->getText(); serverInfo.hostname = mServerAddressField->getText(); - serverInfo.port = (short) atoi(mPortField->getText().c_str()); #ifdef MANASERV_SUPPORT switch (mTypeField->getSelected()) { @@ -194,6 +191,10 @@ void CustomServerDialog::action(const gcn::ActionEvent &event) #else serverInfo.type = ServerInfo::TMWATHENA; #endif + if (mPortField->getText().empty()) + serverInfo.port = ServerInfo::defaultPortForServerType(serverInfo.type); + else + serverInfo.port = (short) atoi(mPortField->getText().c_str()); // Tell the server has to be saved serverInfo.save = true; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index f9fcb597..0a2b96f4 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -69,18 +69,6 @@ static std::string serverTypeToString(ServerInfo::Type type) } } -static unsigned short defaultPortForServerType(ServerInfo::Type type) -{ - switch (type) - { - default: - case ServerInfo::TMWATHENA: - return 6901; - case ServerInfo::MANASERV: - return 9601; - } -} - ServersListModel::ServersListModel(ServerInfos *servers, ServerDialog *parent): mServers(servers), mVersionStrings(servers->size(), VersionString(0, "")), @@ -510,7 +498,7 @@ void ServerDialog::loadServers() if (server.port == 0) { // If no port is given, use the default for the given type - server.port = defaultPortForServerType(server.type); + server.port = ServerInfo::defaultPortForServerType(server.type); } } else if (xmlStrEqual(subNode->name, BAD_CAST "description")) @@ -563,7 +551,7 @@ void ServerDialog::loadCustomServers() server.hostname = config.getValue(hostNameKey, ""); server.type = ServerInfo::parseType(config.getValue(typeKey, "")); - const int defaultPort = defaultPortForServerType(server.type); + const int defaultPort = ServerInfo::defaultPortForServerType(server.type); server.port = (unsigned short) config.getValue(portKey, defaultPort); server.description = config.getValue(descriptionKey, ""); diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index e709bed0..8e2ee5b0 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -108,6 +108,18 @@ public: return MANASERV; return UNKNOWN; } + + static unsigned short defaultPortForServerType(Type type) + { + switch (type) + { + default: + case ServerInfo::TMWATHENA: + return 6901; + case ServerInfo::MANASERV: + return 9601; + } + } }; typedef std::deque<ServerInfo> ServerInfos; |