summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-13 15:46:41 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-14 00:46:22 +0300
commit93feb7fbf408ccc9178832d5f21c3806cb2a9f16 (patch)
treeb0ee8c847e5933a86ea53dea5a3f87b8c6533191
parent99ecd9ba734a308ae374d4494856d8bb3617f8a0 (diff)
downloadplus-93feb7fbf408ccc9178832d5f21c3806cb2a9f16.tar.gz
plus-93feb7fbf408ccc9178832d5f21c3806cb2a9f16.tar.bz2
plus-93feb7fbf408ccc9178832d5f21c3806cb2a9f16.tar.xz
plus-93feb7fbf408ccc9178832d5f21c3806cb2a9f16.zip
Add support for different groups of update servers reading from servers list.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/client.cpp2
-rw-r--r--src/gui/models/updatelistmodel.h37
-rw-r--r--src/gui/windows/logindialog.cpp43
-rw-r--r--src/gui/windows/logindialog.h8
-rw-r--r--src/gui/windows/serverdialog.cpp34
-rw-r--r--src/net/hostsgroup.h38
-rw-r--r--src/net/serverinfo.h7
9 files changed, 152 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 506aac6b6..f3f8608c9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1681,6 +1681,7 @@ SET(SRCS_EATHENA
net/familyhandler.h
net/friendshandler.h
net/homunculushandler.h
+ net/hostsgroup.h
net/mailhandler.h
net/maphandler.h
net/markethandler.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 05f201fb5..3ba8baefe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1551,6 +1551,7 @@ manaplus_SOURCES += gui/windows/bankwindow.cpp \
net/familyhandler.h \
net/friendshandler.h \
net/homunculushandler.h \
+ net/hostsgroup.h \
net/mailhandler.h \
net/maphandler.h \
net/markethandler.h \
diff --git a/src/client.cpp b/src/client.cpp
index c027aae9e..472b6ad10 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1125,7 +1125,7 @@ int Client::gameExec()
{
CREATEWIDGETV(mCurrentDialog, LoginDialog,
loginData,
- mCurrentServer.hostname,
+ &mCurrentServer,
&settings.options.updateHost);
}
else
diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h
index 67fffc34e..0f1104200 100644
--- a/src/gui/models/updatelistmodel.h
+++ b/src/gui/models/updatelistmodel.h
@@ -25,17 +25,25 @@
#include "gui/models/listmodel.h"
-#include "net/logindata.h"
+#include "net/hostsgroup.h"
+
+#include "utils/stringvector.h"
#include "localconsts.h"
class UpdateListModel final : public ListModel
{
public:
- explicit UpdateListModel(LoginData *const data) :
+ explicit UpdateListModel(ServerInfo *const server) :
ListModel(),
- mLoginData(data)
+ mNames(),
+ mServer(server)
{
+ FOR_EACH(std::vector<HostsGroup>::const_iterator, it, server->updateHosts)
+ {
+ const HostsGroup &group = *it;
+ mNames.push_back(group.name);
+ }
}
A_DELETE_COPY(UpdateListModel)
@@ -45,20 +53,31 @@ class UpdateListModel final : public ListModel
int getNumberOfElements() override final
{
- if (!mLoginData)
- return 0;
- return CAST_S32(mLoginData->updateHosts.size());
+ return CAST_S32(mNames.size());
}
std::string getElementAt(int i) override final
{
- if (!mLoginData || i >= getNumberOfElements() || i < 0)
+ if (i >= getNumberOfElements() || i < 0)
return "???";
- return mLoginData->updateHosts[i];
+ return mNames[i];
+ }
+
+ HostsGroup &getSelectedGroup(const unsigned int sel)
+ {
+ if (sel >= mServer->updateHosts.size())
+ return mServer->updateHosts[0];
+ mServer->updateHosts[sel];
+ }
+
+ bool empty() const
+ {
+ return mNames.empty();
}
protected:
- LoginData *mLoginData;
+ StringVect mNames;
+ ServerInfo *mServer;
};
#endif // GUI_MODELS_UPDATELISTMODEL_H
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index 34f84fee4..937af72be 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -41,7 +41,9 @@
#include "gui/widgets/layoutcell.h"
#include "net/charserverhandler.h"
+#include "net/logindata.h"
#include "net/loginhandler.h"
+#include "net/serverinfo.h"
#include "net/updatetypeoperators.h"
#include "utils/delete2.h"
@@ -58,13 +60,14 @@ namespace
} // namespace
LoginDialog::LoginDialog(LoginData &data,
- std::string serverName,
+ ServerInfo *const server,
std::string *const updateHost) :
// TRANSLATORS: login dialog name
Window(_("Login"), Modal_false, nullptr, "login.xml"),
ActionListener(),
KeyListener(),
mLoginData(&data),
+ mServer(server),
mUserField(new TextField(this, mLoginData->username)),
mPassField(new PasswordField(this, mLoginData->password)),
// TRANSLATORS: login dialog label
@@ -89,7 +92,7 @@ LoginDialog::LoginDialog(LoginData &data,
mUpdateListModel(nullptr),
mUpdateHostDropDown(nullptr),
mUpdateHost(updateHost),
- mServerName(serverName)
+ mServerName(server->hostname)
{
setCloseButton(true);
setWindowName("Login");
@@ -97,20 +100,22 @@ LoginDialog::LoginDialog(LoginData &data,
if (charServerHandler)
charServerHandler->clear();
+ mergeUpdateHosts();
+
// TRANSLATORS: login dialog label
Label *const serverLabel1 = new Label(this, _("Server:"));
- Label *const serverLabel2 = new Label(this, serverName);
+ Label *const serverLabel2 = new Label(this, mServerName);
serverLabel2->adjustSize();
// TRANSLATORS: login dialog label
Label *const userLabel = new Label(this, _("Name:"));
// TRANSLATORS: login dialog label
Label *const passLabel = new Label(this, _("Password:"));
- if (mLoginData->updateHosts.size() > 1)
+ if (mServer->updateHosts.size() > 1)
{
// TRANSLATORS: login dialog label
mUpdateHostLabel = new Label(this, strprintf(_("Update host: %s"),
mLoginData->updateHost.c_str()));
- mUpdateListModel = new UpdateListModel(mLoginData);
+ mUpdateListModel = new UpdateListModel(mServer);
mUpdateHostDropDown = new DropDown(this, mUpdateListModel,
false, Modal_false, this, "updateselect");
const std::string str = serverConfig.getValue("updateHost2", "");
@@ -321,14 +326,28 @@ void LoginDialog::prepareUpdate()
std::string str;
if (mUpdateHostDropDown)
{
- str = mUpdateHostDropDown->getSelectedString();
+ const int sel = mUpdateHostDropDown->getSelected();
+ if (sel >= 0)
+ {
+ const HostsGroup &group = mServer->updateHosts[sel];
+ if (!group.hosts.empty())
+ {
+ str = group.hosts[0];
+ mLoginData->updateHosts = group.hosts;
+ serverConfig.setValue("updateHost2", group.name);
+ }
+ else
+ {
+ serverConfig.setValue("updateHost2", "");
+ }
+ }
}
else if (mLoginData->updateHost.empty()
&& !mLoginData->updateHosts.empty())
{
str = mLoginData->updateHosts[0];
+ serverConfig.setValue("updateHost2", str);
}
- serverConfig.setValue("updateHost2", str);
if (!str.empty() && checkPath(str))
{
mLoginData->updateHost = str;
@@ -360,3 +379,13 @@ void LoginDialog::close()
client->setState(State::SWITCH_SERVER);
Window::close();
}
+
+void LoginDialog::mergeUpdateHosts()
+{
+ HostsGroup group;
+
+ // TRANSLATORS: update hosts group default name
+ group.name = _("default");
+ group.hosts = mLoginData->updateHosts;
+ mServer->updateHosts.insert(mServer->updateHosts.begin(), group);
+}
diff --git a/src/gui/windows/logindialog.h b/src/gui/windows/logindialog.h
index 8feaa39f5..9047bf123 100644
--- a/src/gui/windows/logindialog.h
+++ b/src/gui/windows/logindialog.h
@@ -33,6 +33,7 @@ class CheckBox;
class DropDown;
class Label;
class LoginData;
+class ServerInfo;
class TextField;
class UpdateListModel;
class UpdateTypeModel;
@@ -53,8 +54,8 @@ class LoginDialog final : public Window,
* @see Window::Window
*/
LoginDialog(LoginData &data,
- std::string serverName,
- std::string *const updateHost);
+ ServerInfo *const server,
+ std::string *const updateHost) A_NONNULL(3, 4);
A_DELETE_COPY(LoginDialog)
@@ -86,7 +87,10 @@ class LoginDialog final : public Window,
void prepareUpdate();
+ void mergeUpdateHosts();
+
LoginData *mLoginData A_NONNULLPOINTER;
+ ServerInfo *mServer A_NONNULLPOINTER;
TextField *mUserField A_NONNULLPOINTER;
TextField *mPassField A_NONNULLPOINTER;
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index dac370887..04663de71 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -44,6 +44,7 @@
#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/langs.h"
+#include "utils/paths.h"
#include "debug.h"
@@ -237,6 +238,7 @@ void ServerDialog::connectToSelectedServer()
mServerInfo->persistentIp = server.persistentIp;
mServerInfo->updateMirrors = server.updateMirrors;
mServerInfo->packetVersion = server.packetVersion;
+ mServerInfo->updateHosts = server.updateHosts;
settings.persistentIp = mServerInfo->persistentIp;
settings.supportUrl = mServerInfo->supportUrl;
@@ -447,6 +449,33 @@ void ServerDialog::downloadServerList()
config.setValue("serverslistupdate", getDateString());
}
+static void loadHostsGroup(const XmlNodePtr node,
+ ServerInfo &server)
+{
+ HostsGroup group;
+ group.name = XML::getProperty(node,
+ "name",
+ // TRANSLATORS: unknown hosts group name
+ _("Unknown"));
+ for_each_xml_child_node(hostNode, node)
+ {
+ if (!xmlNameEqual(hostNode, "host"))
+ continue;
+ const std::string host = XmlChildContent(hostNode);
+ if (host.empty())
+ continue;
+ if (!checkPath(host))
+ {
+ logger->log1("Warning: incorrect update server name");
+ continue;
+ }
+
+ group.hosts.push_back(host);
+ }
+ if (!group.hosts.empty())
+ server.updateHosts.push_back(group);
+}
+
void ServerDialog::loadServers(const bool addNew)
{
XML::Document doc(std::string(mDir).append("/").append(
@@ -563,6 +592,10 @@ void ServerDialog::loadServers(const bool addNew)
{
server.updateMirrors.push_back(XmlChildContent(subNode));
}
+ else if (xmlNameEqual(subNode, "updates"))
+ {
+ loadHostsGroup(subNode, server);
+ }
}
server.version.first = font->getWidth(version);
@@ -587,6 +620,7 @@ void ServerDialog::loadServers(const bool addNew)
mServers[i].althostname = server.althostname;
mServers[i].persistentIp = server.persistentIp;
mServers[i].updateMirrors = server.updateMirrors;
+ mServers[i].updateHosts = server.updateHosts;
mServers[i].packetVersion = server.packetVersion;
mServersListModel->setVersionString(i, version);
found = true;
diff --git a/src/net/hostsgroup.h b/src/net/hostsgroup.h
new file mode 100644
index 000000000..ec217630f
--- /dev/null
+++ b/src/net/hostsgroup.h
@@ -0,0 +1,38 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NET_HOSTSGROUP_H
+#define NET_HOSTSGROUP_H
+
+#include "utils/stringvector.h"
+
+#include "localconsts.h"
+
+struct HostsGroup final
+{
+ HostsGroup()
+ {
+ }
+
+ std::string name;
+ StringVect hosts;
+};
+
+#endif // NET_HOSTSGROUP_H
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index 85d0f6bdd..e2949af0b 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -25,6 +25,8 @@
#include "enums/net/servertype.h"
+#include "net/hostsgroup.h"
+
#include "utils/stringutils.h"
#include "localconsts.h"
@@ -43,6 +45,7 @@ class ServerInfo final
std::string onlineListUrl;
std::string supportUrl;
std::vector<std::string> updateMirrors;
+ std::vector<HostsGroup> updateHosts;
uint16_t port;
VersionString version;
int packetVersion;
@@ -59,6 +62,7 @@ class ServerInfo final
onlineListUrl(),
supportUrl(),
updateMirrors(),
+ updateHosts(),
#ifdef TMWA_SUPPORT
port(6901),
#else
@@ -82,6 +86,7 @@ class ServerInfo final
onlineListUrl(info.onlineListUrl),
supportUrl(info.supportUrl),
updateMirrors(info.updateMirrors),
+ updateHosts(info.updateHosts),
port(info.port),
version(),
packetVersion(info.packetVersion),
@@ -103,6 +108,7 @@ class ServerInfo final
onlineListUrl = info.onlineListUrl;
supportUrl = info.supportUrl;
updateMirrors = info.updateMirrors;
+ updateHosts = info.updateHosts;
port = info.port;
save = info.save;
persistentIp = info.persistentIp;
@@ -131,6 +137,7 @@ class ServerInfo final
onlineListUrl.clear();
supportUrl.clear();
updateMirrors.clear();
+ updateHosts.clear();
version.first = 0;
version.second.clear();
packetVersion = 0;