diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-04-06 16:33:38 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-04-06 17:05:49 -0600 |
commit | db3bc0a260cd26ee58d53d2b0531d0c0c471ccd0 (patch) | |
tree | e0b24d1593e752df328aa0e7252efefee460dcb4 | |
parent | d17c63e1bb5579fb05c58f9abc3fb4be5bb9d58f (diff) | |
download | mana-db3bc0a260cd26ee58d53d2b0531d0c0c471ccd0.tar.gz mana-db3bc0a260cd26ee58d53d2b0531d0c0c471ccd0.tar.bz2 mana-db3bc0a260cd26ee58d53d2b0531d0c0c471ccd0.tar.xz mana-db3bc0a260cd26ee58d53d2b0531d0c0c471ccd0.zip |
Fix a crash when adding new servers
Reviewed-by: Chuck Miller
-rw-r--r-- | src/gui/serverdialog.cpp | 32 | ||||
-rw-r--r-- | src/gui/serverdialog.h | 5 | ||||
-rw-r--r-- | src/net/serverinfo.h | 12 |
3 files changed, 17 insertions, 32 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 6cd364cc..340536d1 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -113,20 +113,6 @@ void ServersListModel::setVersionString(int index, const std::string &version) } } -void ServersListModel::addServer(const ServerInfo &info, - const std::string &version) -{ - mServers->push_back(info); - - if (version.empty()) - mVersionStrings.push_back(VersionString(0, "")); - else - { - int width = gui->getFont()->getWidth(version); - mVersionStrings.push_back(VersionString(width, version)); - } -} - std::string TypeListModel::getElementAt(int elementIndex) { if (elementIndex == 0) @@ -188,13 +174,12 @@ public: graphics->drawText(model->getElementAt(i), 2, top); - const ServersListModel::VersionString versionInfo = model->getVersionString(i); - if (versionInfo.first > 0) + if (info.version.first > 0) { graphics->setColor(unsupported); - graphics->drawText(versionInfo.second, - getWidth() - versionInfo.first - 2, top); + graphics->drawText(info.version.second, + getWidth() - info.version.first - 2, top); } } } @@ -538,11 +523,11 @@ void ServerDialog::loadServers() std::string version = XML::getProperty(serverNode, "minimumVersion", std::string()); - server.meetsMinimumVersion = (compareStrI(version, PACKAGE_VERSION) + bool meetsMinimumVersion = (compareStrI(version, PACKAGE_VERSION) <= 0); // For display in the list - if (server.meetsMinimumVersion) + if (meetsMinimumVersion) version.clear(); else version = strprintf(_("requires v%s"), version.c_str()); @@ -571,6 +556,8 @@ void ServerDialog::loadServers() } } + server.version.first = gui->getFont()->getWidth(version); + server.version.second = version; MutexLocker lock(&mMutex); // Add the server to the local list if it's not already present @@ -581,7 +568,7 @@ void ServerDialog::loadServers() { // Use the name listed in the server list mServers[i].name = server.name; - mServers[i].meetsMinimumVersion = server.meetsMinimumVersion; + mServers[i].version = server.version; mServersListModel->setVersionString(i, version); found = true; break; @@ -589,7 +576,7 @@ void ServerDialog::loadServers() } if (!found) - mServersListModel->addServer(server, version); + mServers.push_back(server); } } @@ -614,7 +601,6 @@ void ServerDialog::loadCustomServers() break; server.save = true; - server.meetsMinimumVersion = true; mServers.push_back(server); } } diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index 5b9d53fd..03ed0f7a 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -71,13 +71,8 @@ class ServersListModel : public gcn::ListModel const ServerInfo &getServer(int elementIndex) const { return mServers->at(elementIndex); } - const VersionString &getVersionString(int index) const - { return mVersionStrings[index]; } - void setVersionString(int index, const std::string &version); - void addServer(const ServerInfo &info, const std::string &version); - private: typedef std::vector<VersionString> VersionStrings; diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index adfdee7e..8b5b8f9d 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -36,22 +36,24 @@ public: EATHENA }; + typedef std::pair<int, std::string> VersionString; + Type type; std::string name; std::string hostname; unsigned short port; std::string description; + VersionString version; bool save; - bool meetsMinimumVersion; ServerInfo() { type = UNKNOWN; port = 0; save = false; - meetsMinimumVersion = true; + version.first = 0; } ServerInfo(const ServerInfo &info) @@ -61,8 +63,9 @@ public: hostname = info.hostname; port = info.port; description = info.description; + version.first = info.version.first; + version.second = info.version.second; save = info.save; - meetsMinimumVersion = info.meetsMinimumVersion; } bool isValid() const @@ -77,8 +80,9 @@ public: hostname.clear(); port = 0; description.clear(); + version.first = 0; + version.second.clear(); save = false; - meetsMinimumVersion = true; } bool operator==(const ServerInfo &other) const |