diff options
author | gumi <mekolat@users.noreply.github.com> | 2017-04-24 12:17:15 -0400 |
---|---|---|
committer | gumi <mekolat@users.noreply.github.com> | 2017-04-25 11:14:56 -0400 |
commit | 7afb1a56559f4b1e35c68b20e282b923c4d7a0ba (patch) | |
tree | 28541065c57f8ae4c67bd393e0a26e97726831a6 /src/map | |
parent | 89ffb3db746b016ea1cc12ef2f148152ed280172 (diff) | |
download | hercules-7afb1a56559f4b1e35c68b20e282b923c4d7a0ba.tar.gz hercules-7afb1a56559f4b1e35c68b20e282b923c4d7a0ba.tar.bz2 hercules-7afb1a56559f4b1e35c68b20e282b923c4d7a0ba.tar.xz hercules-7afb1a56559f4b1e35c68b20e282b923c4d7a0ba.zip |
add permission checking buildins
add has_permission()
add can_use_command()
expose PC permission constants
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/script.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c index a6d3ac852..c136c7bc5 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -21593,6 +21593,67 @@ BUILDIN(useatcmd) return true; } +BUILDIN(has_permission) +{ + struct map_session_data *sd; + enum e_pc_permission perm; + + if (script_hasdata(st, 3)) { + sd = map->id2sd(script_getnum(st, 3)); + } else { + sd = script->rid2sd(st); + } + + if (sd == NULL) { + script_pushint(st, 0); + return false; + } + + if (script_isstringtype(st, 2)) { + // to check for plugin permissions + int i = 0, j = -1; + const char *name = script_getstr(st, 2); + for (; i < pcg->permission_count; ++i) { + if (strcmp(pcg->permissions[i].name, name) == 0) { + j = i; + break; + } + } + if (j < 0) { + ShowError("script:has_permission: unknown permission: %s\n", name); + script_pushint(st, 0); + return false; + } + script_pushint(st, pc_has_permission(sd, pcg->permissions[j].permission)); + return true; + } + + // to ckeck for built-in permission + perm = script_getnum(st, 2); + script_pushint(st, pc_has_permission(sd, perm)); + return true; +} + +BUILDIN(can_use_command) +{ + struct map_session_data *sd; + const char *cmd = script_getstr(st, 2); + + if (script_hasdata(st, 3)) { + sd = map->id2sd(script_getnum(st, 3)); + } else { + sd = script->rid2sd(st); + } + + if (sd == NULL) { + script_pushint(st, 0); + return false; + } + + script_pushint(st, pc->can_use_command(sd, cmd)); + return true; +} + /* getrandgroupitem <container_item_id>,<quantity> */ BUILDIN(getrandgroupitem) { @@ -23567,6 +23628,8 @@ void script_parse_builtin(void) { BUILDIN_DEF(bindatcmd, "ss???"), BUILDIN_DEF(unbindatcmd, "s"), BUILDIN_DEF(useatcmd, "s"), + BUILDIN_DEF(has_permission, "v?"), + BUILDIN_DEF(can_use_command, "s?"), /** * Item bound [Xantara] [Akinari] [Mhalicot/Hercules] @@ -23811,6 +23874,34 @@ void script_hardcoded_constants(void) script->set_constant("BL_CHAR",BL_CHAR,false, false); script->set_constant("BL_ALL",BL_ALL,false, false); + script->constdb_comment("Player permissions"); + script->set_constant("PERM_TRADE", PC_PERM_TRADE, false, false); + script->set_constant("PERM_PARTY", PC_PERM_PARTY, false, false); + script->set_constant("PERM_ALL_SKILL", PC_PERM_ALL_SKILL, false, false); + script->set_constant("PERM_USE_ALL_EQUIPMENT", PC_PERM_USE_ALL_EQUIPMENT, false, false); + script->set_constant("PERM_SKILL_UNCONDITIONAL", PC_PERM_SKILL_UNCONDITIONAL, false, false); + script->set_constant("PERM_JOIN_ALL_CHAT", PC_PERM_JOIN_ALL_CHAT, false, false); + script->set_constant("PERM_NO_CHAT_KICK", PC_PERM_NO_CHAT_KICK, false, false); + script->set_constant("PERM_HIDE_SESSION", PC_PERM_HIDE_SESSION, false, false); + script->set_constant("PERM_RECEIVE_HACK_INFO", PC_PERM_RECEIVE_HACK_INFO, false, false); + script->set_constant("PERM_WARP_ANYWHERE", PC_PERM_WARP_ANYWHERE, false, false); + script->set_constant("PERM_VIEW_HPMETER", PC_PERM_VIEW_HPMETER, false, false); + script->set_constant("PERM_VIEW_EQUIPMENT", PC_PERM_VIEW_EQUIPMENT, false, false); + script->set_constant("PERM_USE_CHECK", PC_PERM_USE_CHECK, false, false); + script->set_constant("PERM_USE_CHANGEMAPTYPE", PC_PERM_USE_CHANGEMAPTYPE, false, false); + script->set_constant("PERM_USE_ALL_COMMANDS", PC_PERM_USE_ALL_COMMANDS, false, false); + script->set_constant("PERM_RECEIVE_REQUESTS", PC_PERM_RECEIVE_REQUESTS, false, false); + script->set_constant("PERM_SHOW_BOSS", PC_PERM_SHOW_BOSS, false, false); + script->set_constant("PERM_DISABLE_PVM", PC_PERM_DISABLE_PVM, false, false); + script->set_constant("PERM_DISABLE_PVP", PC_PERM_DISABLE_PVP, false, false); + script->set_constant("PERM_DISABLE_CMD_DEAD", PC_PERM_DISABLE_CMD_DEAD, false, false); + script->set_constant("PERM_HCHSYS_ADMIN", PC_PERM_HCHSYS_ADMIN, false, false); + script->set_constant("PERM_TRADE_BOUND", PC_PERM_TRADE_BOUND, false, false); + script->set_constant("PERM_DISABLE_PICK_UP", PC_PERM_DISABLE_PICK_UP, false, false); + script->set_constant("PERM_DISABLE_STORE", PC_PERM_DISABLE_STORE, false, false); + script->set_constant("PERM_DISABLE_EXP", PC_PERM_DISABLE_EXP, false, false); + script->set_constant("PERM_DISABLE_SKILL_USAGE", PC_PERM_DISABLE_SKILL_USAGE, false, false); + script->constdb_comment("Renewal"); #ifdef RENEWAL script->set_constant("RENEWAL", 1, false, false); |