summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2006-02-05 19:00:43 +0000
committerYohann Ferreira <bertram@cegetel.net>2006-02-05 19:00:43 +0000
commit851ca8b9be55db5d2d2f596097f6196ef5ef6c0b (patch)
tree058a136c8e5ae206a0a81a15a3a5f9dee6581067 /src
parent9d12db6aa73611eb221e7b6d9a522aecf8ae67cd (diff)
downloadmana-851ca8b9be55db5d2d2f596097f6196ef5ef6c0b.tar.gz
mana-851ca8b9be55db5d2d2f596097f6196ef5ef6c0b.tar.bz2
mana-851ca8b9be55db5d2d2f596097f6196ef5ef6c0b.tar.xz
mana-851ca8b9be55db5d2d2f596097f6196ef5ef6c0b.zip
Fixed a gcc 4.0 issue in the tradehandler. Strengthened the xml parser in the itemmanager so tmw doesn't crash anymore if an item lacks some parameters.
Diffstat (limited to 'src')
-rw-r--r--src/net/tradehandler.cpp3
-rw-r--r--src/resources/itemmanager.cpp55
2 files changed, 37 insertions, 21 deletions
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index 5675fab8..940c3e09 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -80,7 +80,8 @@ void TradeHandler::handleMessage(MessageIn *msg)
player_node->setTrading(true);
tradePartnerName = msg->readString(24);
- ConfirmDialog *dlg = new ConfirmDialog("Request for trade",
+ ConfirmDialog *dlg;
+ dlg = new ConfirmDialog("Request for trade",
tradePartnerName +
" wants to trade with you, do you accept?");
dlg->addActionListener(&requestTradeListener);
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp
index 6fac63fd..507185fc 100644
--- a/src/resources/itemmanager.cpp
+++ b/src/resources/itemmanager.cpp
@@ -54,47 +54,62 @@ ItemManager::ItemManager()
{
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
+ int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0;
+ std::string name = "", description = "", effect = "";
+
if (xmlStrEqual(node->name, BAD_CAST "item"))
{
- xmlChar *prop;
+ xmlChar *prop = NULL;
+ // Item id
prop = xmlGetProp(node, BAD_CAST "id");
- int id = atoi((const char*)prop);
+ if (prop) id = atoi((const char*)prop);
xmlFree(prop);
+ // Image id
prop = xmlGetProp(node, BAD_CAST "image");
- int image = atoi((const char*)prop);
+ if (prop) image = atoi((const char*)prop);
xmlFree(prop);
+ // Art id
prop = xmlGetProp(node, BAD_CAST "art");
- int art = atoi((const char*)prop);
+ if (prop) art = atoi((const char*)prop);
xmlFree(prop);
+ // Name
prop = xmlGetProp(node, BAD_CAST "name");
- std::string name((const char*)prop);
+ if (prop) name = (const char*)prop;
xmlFree(prop);
+ // Description
prop = xmlGetProp(node, BAD_CAST "description");
- std::string description((const char*)prop);
+ if (prop) description = (const char*)prop;
xmlFree(prop);
+ // Effect
prop = xmlGetProp(node, BAD_CAST "effect");
- std::string effect((const char*)prop);
+ if (prop) effect = (const char*)prop;
xmlFree(prop);
+ // Type id
prop = xmlGetProp(node, BAD_CAST "type");
- int type = atoi((const char*)prop);
+ if (prop) type = atoi((const char*)prop);
xmlFree(prop);
+ // Weight
prop = xmlGetProp(node, BAD_CAST "weight");
- int weight = atoi((const char*)prop);
+ if (prop) weight = atoi((const char*)prop);
xmlFree(prop);
+ // Slot
prop = xmlGetProp(node, BAD_CAST "slot");
- int slot = atoi((const char*)prop);
+ if (prop) slot = atoi((const char*)prop);
xmlFree(prop);
- ItemInfo *itemInfo = new ItemInfo();
- itemInfo->setImage(image);
- itemInfo->setArt(art);
- itemInfo->setName(name);
- itemInfo->setDescription(description);
- itemInfo->setEffect(effect);
- itemInfo->setType(type);
- itemInfo->setWeight(weight);
- itemInfo->setSlot(slot);
- db[id] = itemInfo;
+ if (id && name != "")
+ {
+ ItemInfo *itemInfo = new ItemInfo();
+ itemInfo->setImage(image);
+ itemInfo->setArt(art);
+ itemInfo->setName(name);
+ itemInfo->setDescription(description);
+ itemInfo->setEffect(effect);
+ itemInfo->setType(type);
+ itemInfo->setWeight(weight);
+ itemInfo->setSlot(slot);
+ db[id] = itemInfo;
+ }
/*logger->log("Item: %i %i %i %s %s %i %i %i", id,
getImage(id), getArt(id), getName(id).c_str(),