From 4db2e5b8da6016812e11abac235f1113a78d60d0 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Tue, 9 Jul 2013 14:34:52 -0300 Subject: Fixed missing map id boundary checking Signed-off-by: shennetsind --- src/map/script.c | 86 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/src/map/script.c b/src/map/script.c index aef636d0e..b5edec220 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6228,7 +6228,13 @@ BUILDIN(makeitem) m=sd->bl.m; } else m=iMap->mapname2mapid(mapname); + + if( m == -1 ) { + ShowError("makeitem: creating map on unexistent map '%s'!\n", mapname); + return false; + } + memset(&item_tmp,0,sizeof(item_tmp)); item_tmp.nameid=nameid; if(!flag) @@ -8555,7 +8561,10 @@ BUILDIN(areamonster) if (sd && strcmp(mapn, "this") == 0) m = sd->bl.m; else { - m = iMap->mapname2mapid(mapn); + if ( ( m = iMap->mapname2mapid(mapn) ) == -1 ) { + ShowWarning("buildin_areamonster: Attempted to spawn monster class %d on non-existing map '%s'\n",class_, mapn); + return false; + } if (map[m].flag.src4instance && st->instance_id >= 0) { // Try to redirect to the instance map, not the src map if ((m = instance->mapid2imapid(m, st->instance_id)) < 0) { ShowError("buildin_areamonster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn); @@ -11901,14 +11910,26 @@ BUILDIN(playBGMall) int y0 = script_getnum(st,5); int x1 = script_getnum(st,6); int y1 = script_getnum(st,7); + int m; + + if ( ( m = iMap->mapname2mapid(map) ) == -1 ) { + ShowWarning("playBGMall: Attempted to play song '%s' on non-existent map '%s'\n",name, map); + return true; + } - iMap->foreachinarea(playBGM_sub, iMap->mapname2mapid(map), x0, y0, x1, y1, BL_PC, name); + iMap->foreachinarea(playBGM_sub, m, x0, y0, x1, y1, BL_PC, name); } else if( script_hasdata(st,3) ) {// entire map const char* map = script_getstr(st,3); + int m; - iMap->foreachinmap(playBGM_sub, iMap->mapname2mapid(map), BL_PC, name); + if ( ( m = iMap->mapname2mapid(map) ) == -1 ) { + ShowWarning("playBGMall: Attempted to play song '%s' on non-existent map '%s'\n",name, map); + return true; + } + + iMap->foreachinmap(playBGM_sub, m, BL_PC, name); } else {// entire server @@ -11963,30 +11984,37 @@ BUILDIN(soundeffectall) //FIXME: enumerating map squares (iMap->foreach) is slower than enumerating the list of online players (iMap->foreachpc?) [ultramage] - if(!script_hasdata(st,4)) - { // area around + if(!script_hasdata(st,4)) { // area around clif->soundeffectall(bl, name, type, AREA); - } - else - if(!script_hasdata(st,5)) - { // entire map + } else { + if(!script_hasdata(st,5)) { // entire map const char* map = script_getstr(st,4); - iMap->foreachinmap(soundeffect_sub, iMap->mapname2mapid(map), BL_PC, name, type); - } - else - if(script_hasdata(st,8)) - { // specified part of map - const char* map = script_getstr(st,4); - int x0 = script_getnum(st,5); - int y0 = script_getnum(st,6); - int x1 = script_getnum(st,7); - int y1 = script_getnum(st,8); - iMap->foreachinarea(soundeffect_sub, iMap->mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); + int m; + + if ( ( m = iMap->mapname2mapid(map) ) == -1 ) { + ShowWarning("soundeffectall: Attempted to play song '%s' (type %d) on non-existent map '%s'\n",name,type, map); + return true; } - else - { - ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n"); + + iMap->foreachinmap(soundeffect_sub, m, BL_PC, name, type); + } else if(script_hasdata(st,8)) { // specified part of map + const char* map = script_getstr(st,4); + int x0 = script_getnum(st,5); + int y0 = script_getnum(st,6); + int x1 = script_getnum(st,7); + int y1 = script_getnum(st,8); + int m; + + if ( ( m = iMap->mapname2mapid(map) ) == -1 ) { + ShowWarning("soundeffectall: Attempted to play song '%s' (type %d) on non-existent map '%s'\n",name,type, map); + return true; } + + iMap->foreachinarea(soundeffect_sub, m, x0, y0, x1, y1, BL_PC, name, type); + } else { + ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n"); + } + } return true; } @@ -15335,6 +15363,11 @@ BUILDIN(checkcell) int16 y = script_getnum(st,4); cell_chk type = (cell_chk)script_getnum(st,5); + if ( m == -1 ) { + ShowWarning("checkcell: Attempted to run on unexsitent map '%s', type %d, x/y %d,%d\n",script_getstr(st,2),type,x,y); + return true; + } + script_pushint(st, iMap->getcell(m, x, y, type)); return true; @@ -15357,6 +15390,11 @@ BUILDIN(setcell) int x,y; + if ( m == -1 ) { + ShowWarning("setcell: Attempted to run on unexistent map '%s', type %d, x1/y1 - %d,%d | x2/y2 - %d,%d\n",script_getstr(st, 2),type,x1,y1,x2,y2); + return true; + } + if( x1 > x2 ) swap(x1,x2); if( y1 > y2 ) swap(y1,y2); @@ -17003,7 +17041,7 @@ BUILDIN(cleanmap) map = script_getstr(st, 2); m = iMap->mapname2mapid(map); - if (!m) + if ( m == -1 ) return false; if ((script_lastdata(st) - 2) < 4) { -- cgit v1.2.3-60-g2f50 From 172315bdc45220bc2edeed57b8e6f6a781c2b640 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Tue, 9 Jul 2013 15:55:30 -0300 Subject: Follow up 144a9d0843dfe47e0b58c8857762f58ae70543c8 fixed counter going off if target died while timer was running. Signed-off-by: shennetsind --- src/map/battle.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/map/battle.c b/src/map/battle.c index d90ba5e0c..0530510c4 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -211,16 +211,19 @@ struct delay_damage { enum damage_lv dmg_lv; unsigned short attack_type; bool additional_effects; + enum bl_type src_type; }; int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr_t data) { struct delay_damage *dat = (struct delay_damage *)data; if ( dat ) { - struct block_list* src; + struct block_list* src = NULL; struct block_list* target = iMap->id2bl(dat->target_id); if( !target || iStatus->isdead(target) ) {/* nothing we can do */ + if( dat->src_type == BL_PC && ( src = iMap->id2bl(dat->src_id) ) ) + ((TBL_PC*)src)->delayed_damage--; ers_free(delay_damage_ers, dat); return 0; } @@ -287,6 +290,7 @@ int battle_delay_damage (unsigned int tick, int amotion, struct block_list *src, dat->delay = ddelay; dat->distance = distance_bl(src, target)+10; //Attack should connect regardless unless you teleported. dat->additional_effects = additional_effects; + dat->src_type = src->type; if (src->type != BL_PC && amotion > 1000) amotion = 1000; //Aegis places a damage-delay cap of 1 sec to non player attacks. [Skotlex] -- cgit v1.2.3-60-g2f50