Skip to content

Commit

Permalink
Fixes a potential map crash for atcommand mapflag (#6255)
Browse files Browse the repository at this point in the history
* Fixes #6254.
* Adds a few checks for MF_RESTRICTED so the status is not disabled if other zones are active for the same map.
Thanks to @xEasycore and @Lemongrass3110!
  • Loading branch information
aleos89 committed Sep 16, 2021
1 parent b84bbf7 commit 393ec53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/map/atcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8418,7 +8418,7 @@ ACMD_FUNC(mapflag) {
MF_SKILL_DAMAGE,
MF_SKILL_DURATION };

if (flag && std::find(disabled_mf.begin(), disabled_mf.end(), mapflag) != disabled_mf.end()) {
if (flag > 0 && util::vector_exists(disabled_mf, mapflag)) {
sprintf(atcmd_output,"[ @mapflag ] %s flag cannot be enabled as it requires unique values.", flag_name);
clif_displaymessage(sd->fd,atcmd_output);
} else {
Expand Down
20 changes: 15 additions & 5 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4745,13 +4745,23 @@ bool map_setmapflag_sub(int16 m, enum e_mapflag mapflag, bool status, union u_ma
mapdata->flag[mapflag] = status;
break;
case MF_RESTRICTED:
nullpo_retr(false, args);
if (!status) {
if (args == nullptr) {
mapdata->zone = 0;
} else {
mapdata->zone ^= (1 << (args->flag_val + 1)) << 3;
}

// Don't completely disable the mapflag's status if other zones are active
if (mapdata->zone == 0) {
mapdata->flag[mapflag] = status;
}
} else {
nullpo_retr(false, args);

mapdata->flag[mapflag] = status;
if (!status)
mapdata->zone ^= (1 << (args->flag_val + 1)) << 3;
else
mapdata->zone |= (1 << (args->flag_val + 1)) << 3;
mapdata->flag[mapflag] = status;
}
break;
case MF_NOCOMMAND:
if (status) {
Expand Down

0 comments on commit 393ec53

Please sign in to comment.