summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Dombrowski <stefan@uni-bonn.de>2011-05-01 01:30:04 +0200
committerStefan Dombrowski <stefan@uni-bonn.de>2011-05-01 01:30:30 +0200
commit92fd074aa85e2357bfe1ab642209dd5a0d87e4d5 (patch)
treed4f43886bdaf1ad7710470e13a525edc1816c77a
parentb7a04b08bb5b8283fadefb7fc57695720a7ddd9e (diff)
downloadMana-92fd074aa85e2357bfe1ab642209dd5a0d87e4d5.tar.gz
Mana-92fd074aa85e2357bfe1ab642209dd5a0d87e4d5.tar.bz2
Mana-92fd074aa85e2357bfe1ab642209dd5a0d87e4d5.tar.xz
Mana-92fd074aa85e2357bfe1ab642209dd5a0d87e4d5.zip
Checking being positions send by the server
Reviewed-by: Bertram
-rw-r--r--src/map.cpp5
-rw-r--r--src/map.h5
-rw-r--r--src/net/manaserv/beinghandler.cpp26
3 files changed, 36 insertions, 0 deletions
diff --git a/src/map.cpp b/src/map.cpp
index da962253..f1d27e4f 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -618,6 +618,11 @@ bool Map::contains(int x, int y) const
return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
}
+bool Map::containsPixel(int x, int y) const
+{
+ return contains(x ? x / mTileWidth : 0, y ? y / mTileHeight : 0);
+}
+
MetaTile *Map::getMetaTile(int x, int y) const
{
return &mMetaTiles[x + y * mWidth];
diff --git a/src/map.h b/src/map.h
index 67135a99..32644299 100644
--- a/src/map.h
+++ b/src/map.h
@@ -324,6 +324,11 @@ class Map : public Properties
*/
TileAnimation *getAnimationForGid(int gid) const;
+ /**
+ * Tells whether the given pixel falls within the map boundaries.
+ */
+ bool containsPixel(int x, int y) const;
+
protected:
friend class Actor;
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp
index 4c91a36e..ac4a2404 100644
--- a/src/net/manaserv/beinghandler.cpp
+++ b/src/net/manaserv/beinghandler.cpp
@@ -129,6 +129,14 @@ void BeingHandler::handleBeingEnterMessage(Net::MessageIn &msg)
BeingDirection direction = (BeingDirection)msg.readInt8();
Being *being;
+ if(!Game::instance()->getCurrentMap()->containsPixel(px ,py))
+ {
+ logger->log("Warning: Received GPMSG_BEING_ENTER for being id "
+ "%i with position outside the map boundaries "
+ "(x = %i, y = %i)", id, px, py);
+ return;
+ }
+
switch (type)
{
case OBJECT_CHARACTER:
@@ -229,6 +237,14 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg)
// the being position
if (flags & MOVING_POSITION)
{
+ if (!being->getMap()->containsPixel(sx, sy))
+ {
+ logger->log("Warning: Received GPMSG_BEINGS_MOVE for being id "
+ "%i with position outside the map boundaries "
+ "(x = %i, y = %i)", id, sx, sy);
+ return;
+ }
+
Vector serverPos(sx, sy);
if (serverPos.length()
- being->getPosition().length() > POSITION_DIFF_TOLERANCE)
@@ -236,7 +252,17 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg)
}
if (flags & MOVING_DESTINATION)
+ {
+ if (!being->getMap()->containsPixel(dx, dy))
+ {
+ logger->log("Warning: Received GPMSG_BEINGS_MOVE for being id "
+ "%i with destination outside the map boundaries "
+ "(x = %i, y = %i)", id, dx, dy);
+ return;
+ }
+
being->setDestination(dx, dy);
+ }
}
}