summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-28 21:59:59 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-28 21:59:59 +0300
commit503a2b302d9e13b99be4574e5d7b8821dd31504d (patch)
tree34ecba674db95cdedb9fe8f5767b0dfa22571e86
parent6207ffb9a38c7e3718b7c4d87500ea9360d4d44f (diff)
downloadmanaverse-503a2b302d9e13b99be4574e5d7b8821dd31504d.tar.gz
manaverse-503a2b302d9e13b99be4574e5d7b8821dd31504d.tar.bz2
manaverse-503a2b302d9e13b99be4574e5d7b8821dd31504d.tar.xz
manaverse-503a2b302d9e13b99be4574e5d7b8821dd31504d.zip
Add validation for some xml parameters.
-rw-r--r--src/particleemitter.cpp10
-rw-r--r--src/resources/spritedef.cpp7
-rw-r--r--src/simpleanimation.cpp4
-rw-r--r--src/utils/xml.cpp17
-rw-r--r--src/utils/xml.h6
5 files changed, 35 insertions, 9 deletions
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index 27eb89291..4ba8c9c6b 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -221,10 +221,11 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target,
// Get animation frames
for_each_xml_child_node(frameNode, propertyNode)
{
- int delay = XML::getProperty(frameNode, "delay", 0);
+ int delay = XML::getIntProperty(
+ frameNode, "delay", 0, 0, 100000);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- int rand = XML::getProperty(frameNode, "rand", 100);
+ int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100);
offsetY -= imageset->getHeight() - 32;
offsetX -= imageset->getWidth() / 2 - 16;
@@ -300,10 +301,11 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target,
// Get animation frames
for_each_xml_child_node(frameNode, propertyNode)
{
- int delay = XML::getProperty(frameNode, "delay", 0);
+ int delay = XML::getIntProperty(
+ frameNode, "delay", 0, 0, 100000);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- int rand = XML::getProperty(frameNode, "rand", 100);
+ int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100);
offsetY -= imageset->getHeight() - 32;
offsetX -= imageset->getWidth() / 2 - 16;
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 5f3be9220..fd5178ec6 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -270,12 +270,13 @@ void SpriteDef::loadAnimation(XmlNodePtr animationNode,
// Get animation frames
for_each_xml_child_node(frameNode, animationNode)
{
- const int delay = XML::getProperty(frameNode, "delay", 0);
+ const int delay = XML::getIntProperty(
+ frameNode, "delay", 0, 0, 100000);
int offsetX = XML::getProperty(frameNode, "offsetX", 0) +
imageSet->getOffsetX();
int offsetY = XML::getProperty(frameNode, "offsetY", 0) +
imageSet->getOffsetY();
- int rand = XML::getProperty(frameNode, "rand", 100);
+ int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100);
offsetY -= imageSet->getHeight() - 32;
offsetX -= imageSet->getWidth() / 2 - 16;
@@ -305,7 +306,7 @@ void SpriteDef::loadAnimation(XmlNodePtr animationNode,
const int start = XML::getProperty(frameNode, "start", -1);
const int end = XML::getProperty(frameNode, "end", -1);
const std::string value = XML::getProperty(frameNode, "value", "");
- int repeat = XML::getProperty(frameNode, "repeat", 1);
+ int repeat = XML::getIntProperty(frameNode, "repeat", 1, 0, 100);
if (repeat < 1)
{
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 483061516..ebe9d4688 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -166,10 +166,10 @@ void SimpleAnimation::initializeAnimation(XmlNodePtr animationNode,
for (XmlNodePtr frameNode = animationNode->xmlChildrenNode;
frameNode; frameNode = frameNode->next)
{
- int delay = XML::getProperty(frameNode, "delay", 0);
+ int delay = XML::getIntProperty(frameNode, "delay", 0, 0, 100000);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- int rand = XML::getProperty(frameNode, "rand", 100);
+ int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100);
offsetY -= imageset->getHeight() - 32;
offsetX -= imageset->getWidth() / 2 - 16;
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 140da72df..f7350ce92 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -122,6 +122,23 @@ namespace XML
return ret;
}
+ int getIntProperty(XmlNodePtr node, const char* name, int def, int min, int max)
+ {
+ int &ret = def;
+
+ xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ if (prop)
+ {
+ ret = atoi(reinterpret_cast<char*>(prop));
+ xmlFree(prop);
+ }
+ if (ret < min)
+ ret = min;
+ else if (ret > max)
+ ret = max;
+ return ret;
+ }
+
double getFloatProperty(XmlNodePtr node, const char* name, double def)
{
double &ret = def;
diff --git a/src/utils/xml.h b/src/utils/xml.h
index eb5ee88b0..a4ff7eb2e 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -86,6 +86,12 @@ namespace XML
int getProperty(XmlNodePtr node, const char *name, int def);
/**
+ * Gets an integer property from an XmlNodePtr.
+ */
+ int getIntProperty(XmlNodePtr node, const char* name, int def,
+ int min, int max);
+
+ /**
* Gets a string property from an XmlNodePtr.
*/
std::string getProperty(XmlNodePtr node, const char *name,