From 110134603554e06adab93a132ef8f82e55db68ad Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 Apr 2011 23:02:52 +0300 Subject: Add more checks. --- src/net/tmwa/playerhandler.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 50f47e532..ba881858e 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -220,15 +220,23 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) if (player_node) { - /* Scroll if neccessary */ - if (!sameMap - || (abs(x - player_node->getTileX()) - > MAP_TELEPORT_SCROLL_DISTANCE) - || (abs(y - player_node->getTileY()) - > MAP_TELEPORT_SCROLL_DISTANCE)) + Map *map = game->getCurrentMap(); + if (map) { - Map *map = game->getCurrentMap(); - if (map) + if (x >= map->getWidth()) + x = map->getWidth() - 1; + if (y >= map->getHeight()) + y = map->getHeight() - 1; + if (x < 0) + x = 0; + if (y < 0) + y = 0; + /* Scroll if neccessary */ + if (!sameMap + || (abs(x - player_node->getTileX()) + > MAP_TELEPORT_SCROLL_DISTANCE) + || (abs(y - player_node->getTileY()) + > MAP_TELEPORT_SCROLL_DISTANCE)) { scrollOffsetX = static_cast((x - player_node->getTileX()) -- cgit v1.2.3-70-g09d2