Skip to content

Enum-ify several marked flag/result parameters - #3462

Open
MrKeiKun wants to merge 12 commits into
HerculesWS:masterfrom
MrKeiKun:enum-ify-flag-parameters
Open

Enum-ify several marked flag/result parameters#3462
MrKeiKun wants to merge 12 commits into
HerculesWS:masterfrom
MrKeiKun:enum-ify-flag-parameters

Conversation

@MrKeiKun

@MrKeiKun MrKeiKun commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Pull Request Prelude

Changes Proposed

  • chrif_save() / chrif->save() flag → enum chrif_save_flag
  • clif_createchat() / clif->createchat() flag → enum clif_createchat_flag
  • clif_authfail_fd() / chr->authfail_fd() type → enum notify_ban_errorcode (shared across both independent map-server and char-server implementations, including their HPM hook definitions)
  • unit_walk_toxy() / unit->walk_toxy() flag → bitmask enum unit_walk_toxy_flag
  • battle_calc_defense() / battle->calc_defense() flag → bitmask enum battle_calc_defense_flag
  • login_mmo_auth() and related helpers (login_mmo_auth_new(), check_client_version(), auth_failed()) → enum login_auth_result, covering every value already documented in login_auth_failed()'s switch statement
  • loginlog_log() rcode → separate enum loginlog_rcode for the success/ip-banned codes not part of login_auth_result
  • battle_calc_base_damage() flag → bitmask enum battle_calc_base_damage_flag (the TODO also flagged the values as possibly incorrect; verified against all call sites/macros and confirmed correct)
  • struct Damage.typeenum battle_dmg_type, matching the type already used by every assignment site and by clif_damage()'s parameter
  • map_zone_mf_cache()'s mapflag-name dispatch: replaced 57 near-identical strcmpi branches (of 75 total) with a single name/getter lookup table, resolving the TODO about repeatedly re-comparing the flag string on every call. The remaining 18 mapflags with parameterized or non-boolean revert logic are left as an explicit chain; npc_parse_mapflag() (a separate, higher-risk function that mutates live map state) is intentionally untouched.
  • Item stack-restriction bitmask (inventory/cart/storage/guildstorage) → new enum ItemStackRestrictions, matching the existing enum ItemNouseRestrictions style, applied to both db2sql.c's plugin encoder and itemdb.c's matching decoder

flag2 on battle_calc_base_damage() was intentionally left as int, since it's the pre-existing BF_* combat flag shared by several sibling functions that still use plain int — retyping it would be a separate, wider change.

Also includes an unrelated but related bug fix found during this work: map_zone_mf_cache()'s noviewid branch treated a uint32 equip-position bitmask as a boolean, silently discarding the mask on zone-mapflag revert; fixed by promoting the correct (but dead/unreachable) implementation that already existed further down in the same function. Two harmless dead duplicate branches (cvc, src4instance) were removed in the same commit.

Issues addressed: N/A

Replaces the raw int flag on chrif_save()/chrif->save() with enum
chrif_save_flag (CSAVE_NORMAL, CSAVE_QUITTING, CSAVE_CHANGE_MAPSERV),
matching the values already documented in the function's header comment.
Replaces the raw int flag on clif_createchat()/clif->createchat() with
enum clif_createchat_flag, matching the values already documented in
the function's ZC_ACK_CREATE_CHATROOM packet comment.
Introduces enum notify_ban_errorcode in common/mmo.h with the BAN_*
error codes already documented on clif_authfail_fd(), and applies it to
both independent implementations: clif->authfail_fd() (map-server) and
chr->authfail_fd() (char-server), including their HPM hook plugin defs.
Replaces the raw int flag on unit_walk_toxy()/unit->walk_toxy() with
bitmask enum unit_walk_toxy_flag, matching the values already
documented in the function's header comment.
Replaces the raw int flag on battle_calc_defense()/battle->calc_defense()
with bitmask enum battle_calc_defense_flag (BCD_IGNORE_DEFENSE,
BCD_PIERCE_DEFENSE, BCD_TOTAL_DEFENSE_REDUCTION), matching the values
already documented in the function's header comment.
Introduces enum login_auth_result in login.h, covering every value
documented in login_auth_failed()'s switch statement, and applies it to
login_mmo_auth(), login_mmo_auth_new(), check_client_version(), and
auth_failed(). Introduces a separate enum loginlog_rcode for the
success/ip-banned codes used only by loginlog_log(), which otherwise
receives login_auth_result values passed through on failure.
Verified the flag values documented in battle_calc_base_damage()'s
header comment against every call site (direct calls and the
GET_NORMAL_ATTACK/GET_NORMAL_ATTACK2 macros) and confirmed they match,
resolving the TODO's correctness concern. Introduces bitmask enum
battle_calc_base_damage_flag for the flag parameter; flag2 (the
separate BF_* combat flag already used as plain int across several
sibling functions) is left untouched, matching the TODO's original
scope.
Retypes Damage.type from plain int to enum battle_dmg_type: every
assignment already used the BDT_* named constants, and it flows
directly into clif_damage()'s enum battle_dmg_type parameter.
noviewid is a uint32 equip-position bitmask (set via atoi in
npc_parse_mapflag), but the live noviewid branch treated it as a plain
boolean and cached a valueless revert string, silently discarding the
original mask on zone-mapflag revert. A correct implementation already
existed further down as dead code, unreachable because the buggy
branch matched first; promoted it to the live position instead.
Also removes two harmless dead duplicate branches (cvc, src4instance)
that were shadowed by earlier identical branches in the same chain.
Resolves the TODO about map_zone_mf_cache() re-comparing the flag
string against every known mapflag name on every call: 57 of the 75
mapflags follow an identical boolean on/off revert pattern, so they are
now matched via a single name/getter lookup table and a shared helper
(map_zone_mf_cache_bool_flag), replacing 57 near-identical strcmpi
branches with one table (each getter reads its backing struct map_flag
member, preserving the few cases where the mapflag name and its
backing field differ, e.g. nopenalty/noexppenalty).

The remaining 18 mapflags with parameterized or otherwise non-boolean
revert logic (nosave, zone, nocommand, jexp, adjust_skill_damage, the
damage-rate flags, etc.) are left as an explicit strcmpi chain,
unchanged in behavior. npc_parse_mapflag(), which does the actual
mapflag application (as opposed to this function's revert-caching
role), is intentionally left untouched -- it mutates live map state and
carries additional cross-flag validation, making it a separate,
higher-risk refactor.
Introduces enum ItemStackRestrictions in itemdb.h, matching the
existing enum ItemNouseRestrictions style, and applies it to both
sides of the item stack-limit bitmask: db2sql.c's plugin encoder
(resolving its 'FIXME: Use an enum') and itemdb.c's item DB parser,
which decoded the same bits from raw literals.
…s.py

The mapflag dispatch table refactor (map_zone_mf_cache in map.c)
introduced 54 map_zone_mf_get_* getters and map_zone_mf_cache_bool_flag,
all private static helpers not meant to be part of the map interface,
following the same pattern as the already-whitelisted
map_zone_mf_cache_add. Without this, CI's interface validator flags
each of them as a method that should be registered on map->.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant