summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-13 17:58:50 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-13 17:58:50 +0100
commit715d07feeb01a3f633aa42aeb40a524c16ca321e (patch)
tree68eec12d328476a9f303cc0584ecb3cd6fa868af /src
parent83a3b6f920f446b3001725554ab15bed34d6f368 (diff)
downloadmana-715d07feeb01a3f633aa42aeb40a524c16ca321e.tar.gz
mana-715d07feeb01a3f633aa42aeb40a524c16ca321e.tar.bz2
mana-715d07feeb01a3f633aa42aeb40a524c16ca321e.tar.xz
mana-715d07feeb01a3f633aa42aeb40a524c16ca321e.zip
Made the client handle better the lack of items.xml file.
Now the client returns to server choice dialog with a warning instead of aborting. I'm kinda certain I'm not the only one getting crazy with such a lazy behaviour. Reviewed-by: Jaxad.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp23
-rw-r--r--src/resources/itemdb.cpp10
-rw-r--r--src/resources/itemdb.h8
3 files changed, 37 insertions, 4 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 20d85ede..7ca90444 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -210,8 +210,16 @@ public:
}
} loginListener;
-} // anonymous namespace
+class ServerChoiceListener : public gcn::ActionListener
+{
+public:
+ void action(const gcn::ActionEvent &)
+ {
+ Client::setState(STATE_CHOOSE_SERVER);
+ }
+} serverChoiceListener;
+} // anonymous namespace
Client *Client::mInstance = 0;
@@ -782,6 +790,19 @@ int Client::exec()
// Load XML databases
ColorDB::load();
itemDb = new ItemDB;
+ if (!itemDb || !itemDb->isLoaded())
+ {
+ // Warn and return to login screen
+ errorMessage =
+ _("This server is missing needed world data. "
+ "Please contact the administrator(s).");
+ mCurrentDialog = new OkDialog(
+ _("ItemDB: Error while loading " ITEMS_DB_FILE "!"),
+ errorMessage);
+ mCurrentDialog->addActionListener(&serverChoiceListener);
+ mCurrentDialog = NULL; // OkDialog deletes itself
+ break;
+ }
Being::load(); // Hairstyles
MonsterDB::load();
SpecialDB::load();
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 019c66e3..435cdf96 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -89,11 +89,14 @@ void ItemDB::load()
mUnknown->setSprite(errFile, GENDER_MALE);
mUnknown->setSprite(errFile, GENDER_FEMALE);
- XML::Document doc("items.xml");
+ XML::Document doc(ITEMS_DB_FILE);
xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items"))
- logger->error("ItemDB: Error while loading items.xml!");
+ {
+ logger->log("ItemDB: Error while loading " ITEMS_DB_FILE "!");
+ return;
+ }
for_each_xml_child_node(node, rootNode)
{
@@ -104,7 +107,8 @@ void ItemDB::load()
if (!id)
{
- logger->log("ItemDB: Invalid or missing item ID in items.xml!");
+ logger->log("ItemDB: Invalid or missing item ID in "
+ ITEMS_DB_FILE "!");
continue;
}
else if (mItemInfos.find(id) != mItemInfos.end())
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index e4146131..9109898b 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -28,6 +28,8 @@
#include "utils/xml.h"
+#define ITEMS_DB_FILE "items.xml"
+
class ItemInfo;
class SpriteDisplay;
@@ -50,6 +52,12 @@ class ItemDB
*/
void unload();
+ /**
+ * Tells whether the item database is loaded.
+ */
+ bool isLoaded() const
+ { return mLoaded; }
+
bool exists(int id);
const ItemInfo &get(int id);