diff options
author | jurkan <jurkan@gmx.de> | 2012-03-21 19:53:50 +0800 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-21 22:03:25 +0800 |
commit | 347cb6477d1394148340ed0f4650a6ecfaaaaf94 (patch) | |
tree | 135ec2a0a233b3063ce548a1631935d01eeb6f11 /src | |
parent | b3b7a6763ed8d16397965db50a1197f78aaec65a (diff) | |
download | mana-347cb6477d1394148340ed0f4650a6ecfaaaaf94.tar.gz mana-347cb6477d1394148340ed0f4650a6ecfaaaaf94.tar.bz2 mana-347cb6477d1394148340ed0f4650a6ecfaaaaf94.tar.xz mana-347cb6477d1394148340ed0f4650a6ecfaaaaf94.zip |
Added default ports when connecting to a custom server.
When creating a custom server entry, the default port is used if no
other port is specified.
Reviewed-by: Thorbjørn Lindeijer
Mantis-issue: 464
Diffstat (limited to 'src')
-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; |