summaryrefslogtreecommitdiff
path: root/src/game-server/attributemanager.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-22 13:09:25 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-22 13:16:30 +0200
commitbf6e38872829f87ff408f294184da14c8c24bfd4 (patch)
treef569a61013932b0988e90e83dbc553e93457639a /src/game-server/attributemanager.cpp
parent05130de24bf68d6ca427cbc126a03159ca777e5d (diff)
downloadmanaserv-bf6e38872829f87ff408f294184da14c8c24bfd4.tar.gz
manaserv-bf6e38872829f87ff408f294184da14c8c24bfd4.tar.bz2
manaserv-bf6e38872829f87ff408f294184da14c8c24bfd4.tar.xz
manaserv-bf6e38872829f87ff408f294184da14c8c24bfd4.zip
Made the servers check for positive id in xml db loading.
Also fixed a memleak when loading an invalid monster attack. Resolves: Mana-Mantis #215. Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/game-server/attributemanager.cpp')
-rw-r--r--src/game-server/attributemanager.cpp64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index 7e32d4dc..3c9fab23 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -61,23 +61,29 @@ void AttributeManager::reload()
{
if (xmlStrEqual(attributenode->name, BAD_CAST "attribute"))
{
- unsigned int id = XML::getProperty(attributenode, "id", 0);
+ int id = XML::getProperty(attributenode, "id", 0);
- mAttributeMap[id] = std::pair< bool ,
- std::vector<struct AttributeInfoType> >
- (false , std::vector<struct AttributeInfoType>());
+ if (id <= 0)
+ {
+ LOG_WARN("Attribute manager: attribute '" << id
+ << "' is invalid and will be ignored.");
+ continue;
+ }
+
+ mAttributeMap[id] = AttributeInfoMap(false,
+ std::vector<struct AttributeInfoType>());
unsigned int layerCount = 0;
for_each_xml_child_node(subnode, attributenode)
{
if (xmlStrEqual(subnode->name, BAD_CAST "modifier"))
{
- std::string sType = utils::toUpper(XML::getProperty(subnode,
- "stacktype", ""));
- std::string eType = utils::toUpper(XML::getProperty(subnode,
- "modtype", ""));
- std::string tag = utils::toUpper(XML::getProperty(subnode,
- "tag", ""));
+ std::string sType = utils::toUpper(
+ XML::getProperty(subnode, "stacktype", ""));
+ std::string eType = utils::toUpper(
+ XML::getProperty(subnode, "modtype", ""));
+ std::string tag = utils::toUpper(
+ XML::getProperty(subnode, "tag", ""));
AT_TY pSType;
AME_TY pEType;
if (!sType.empty())
@@ -93,11 +99,12 @@ void AttributeManager::reload()
pSType = TY_NSTB;
else
{
- LOG_WARN("Attribute manager: attribute '" << id
- << "' has unknown stack type '" << sType
- << "', skipping modifier!");
+ LOG_WARN("Attribute manager: attribute '"
+ << id << "' has unknown stack type '"
+ << sType << "', skipping modifier!");
fail = true;
}
+
if (!fail)
{
if (eType == "ADDITIVE")
@@ -106,36 +113,41 @@ void AttributeManager::reload()
pEType = AME_MULT;
else
{
- LOG_WARN("Attribute manager: attribute '" << id
- << "' has unknown modification type '" << sType
- << "', skipping modifier!");
+ LOG_WARN(
+ "Attribute manager: attribute '" << id
+ << "' has unknown modification type '"
+ << sType << "', skipping modifier!");
fail = true;
}
if (!fail)
{
- mAttributeMap[id].second.push_back(AttributeInfoType(pSType, pEType));
- std::string tag = XML::getProperty(subnode, "tag", "");
+ mAttributeMap[id].second.push_back(
+ AttributeInfoType(pSType, pEType));
+ std::string tag = XML::getProperty(
+ subnode, "tag", "");
if (!tag.empty())
- mTagMap.insert(std::make_pair(tag,
- std::make_pair(id, layerCount)));
+ mTagMap.insert(
+ std::make_pair(tag,
+ std::make_pair(id, layerCount)));
++layerCount;
}
}
}
else
- LOG_WARN("Attribute manager: attribute '" << id <<
- "' has undefined modification type, skipping modifier!");
+ LOG_WARN("Attribute manager: attribute '" << id
+ << "' has undefined modification type, "
+ << "skipping modifier!");
}
else
{
LOG_WARN("Attribute manager: attribute '" << id <<
- "' has undefined stack type, skipping modifier!");
+ "' has undefined stack type, skipping modifier!");
}
}
}
- std::string scope = utils::toUpper(XML::getProperty(attributenode,
- "scope", std::string()));
+ std::string scope = utils::toUpper(
+ XML::getProperty(attributenode, "scope", std::string()));
if (scope.empty())
{
// Give a warning unless scope has been explicitly set to "NONE"
@@ -165,7 +177,7 @@ void AttributeManager::reload()
LOG_DEBUG("Attribute manager: attribute '" << id
<< "' set to have no default scope.");
}
- }
+ } // End 'attribute'
}
LOG_DEBUG("attribute map:");