summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-04-16 03:46:44 -0300
committershennetsind <ind@henn.et>2013-04-16 03:46:44 -0300
commitc653a703757acc13edbff5a2624c16df74cca4f1 (patch)
tree887e9e464b13680ed67d8636fb136b60121655d3 /src/map/npc.c
parent8ec2352c28f7495b7e3c81a8920e40b57d5074e9 (diff)
downloadhercules-c653a703757acc13edbff5a2624c16df74cca4f1.tar.gz
hercules-c653a703757acc13edbff5a2624c16df74cca4f1.tar.bz2
hercules-c653a703757acc13edbff5a2624c16df74cca4f1.tar.xz
hercules-c653a703757acc13edbff5a2624c16df74cca4f1.zip
Fixed Bug #419
added coodinate checks on a number of locations (parse duplicate/warp/shop/etc). http://hercules.ws/board/tracker/issue-419-loading-of-badly-placed-npcs/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index a3340de78..0e4c84455 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2151,6 +2151,11 @@ static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const
return strchr(start,'\n');// skip and continue
}
+ if( m != -1 && ( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys ) ) {
+ ShowError("npc_parse_warp: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d, in file '%s', line '%d'\n", map[m].name, x, y, map[m].xs, map[m].ys,filepath,strline(buffer,start-buffer));
+ return strchr(start,'\n');;//try next
+ }
+
CREATE(nd, struct npc_data, 1);
nd->bl.id = npc_get_new_npc_id();
@@ -2198,13 +2203,10 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
struct npc_data *nd;
enum npc_subtype type;
- if( strcmp(w1,"-") == 0 )
- {// 'floating' shop?
+ if( strcmp(w1,"-") == 0 ) {// 'floating' shop?
x = y = dir = 0;
m = -1;
- }
- else
- {// w1=<map name>,<x>,<y>,<facing>
+ } else {// w1=<map name>,<x>,<y>,<facing>
char mapname[32];
if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4
|| strchr(w4, ',') == NULL )
@@ -2216,6 +2218,11 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
m = map_mapname2mapid(mapname);
}
+ if( m != -1 && ( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys ) ) {
+ ShowError("npc_parse_shop: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d, in file '%s', line '%d'\n", map[m].name, x, y, map[m].xs, map[m].ys,filepath,strline(buffer,start-buffer));
+ return strchr(start,'\n');;//try next
+ }
+
if( !strcasecmp(w2,"cashshop") )
type = CASHSHOP;
else
@@ -2601,6 +2608,11 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
m = map_mapname2mapid(mapname);
}
+ if( m != -1 && ( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys ) ) {
+ ShowError("npc_parse_duplicate: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d, in file '%s', line '%d'\n", map[m].name, x, y, map[m].xs, map[m].ys,filepath,strline(buffer,start-buffer));
+ return end;//try next
+ }
+
if( type == WARP && sscanf(w4, "%d,%d", &xs, &ys) == 2 );// <spanx>,<spany>
else if( type == SCRIPT && sscanf(w4, "%d,%d,%d", &class_, &xs, &ys) == 3);// <sprite id>,<triggerX>,<triggerY>
else if( type != WARP ) class_ = atoi(w4);// <sprite id>