From 9ef0c24ba9c2cff4ae6fcf5884a14aa8111faf27 Mon Sep 17 00:00:00 2001 From: gumi Date: Mon, 15 May 2017 11:51:09 -0400 Subject: allow custom atcommands to have different permissions for each group --- src/map/atcommand.c | 8 ++++++-- src/map/atcommand.h | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 4d3a82ee2..221e9a311 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1408,7 +1408,7 @@ ACMD(baselevelup) pc->baselevelchanged(sd); if(sd->status.party_id) party->send_levelup(sd); - + if (level > 0 && battle_config.atcommand_levelup_events) npc->script_event(sd, NPCE_BASELVUP); // Trigger OnPCBaseLvUpEvent @@ -8398,7 +8398,9 @@ void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommand int gm_lvl = pc_get_group_level(sd); for (i = 0; i < atcommand->binding_count; i++) { - if (gm_lvl >= ((type == COMMAND_ATCOMMAND) ? atcommand->binding[i]->group_lv : atcommand->binding[i]->group_lv_char)) { + if (gm_lvl >= ((type == COMMAND_ATCOMMAND) ? atcommand->binding[i]->group_lv : atcommand->binding[i]->group_lv_char) + || (type == COMMAND_ATCOMMAND && atcommand->binding[i]->at_groups[pcg->get_idx(sd->group)] > 0) + || (type == COMMAND_CHARCOMMAND && atcommand->binding[i]->char_groups[pcg->get_idx(sd->group)] > 0)) { size_t slen = strlen(atcommand->binding[i]->command); if (count_bind == 0) { cur = line_buff; @@ -9961,6 +9963,8 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa && ( (is_atcommand && pc_get_group_level(sd) >= binding->group_lv) || (!is_atcommand && pc_get_group_level(sd) >= binding->group_lv_char) + || (is_atcommand && binding->at_groups[pcg->get_idx(sd->group)] > 0) + || (!is_atcommand && binding->char_groups[pcg->get_idx(sd->group)] > 0) ) ) { if (binding->log) /* log only if this command should be logged [Ind/Hercules] */ diff --git a/src/map/atcommand.h b/src/map/atcommand.h index 35b3c382e..efcf6dd31 100644 --- a/src/map/atcommand.h +++ b/src/map/atcommand.h @@ -79,8 +79,10 @@ struct AtCommandInfo { struct atcmd_binding_data { char command[ATCOMMAND_LENGTH]; char npc_event[ATCOMMAND_LENGTH]; - int group_lv; - int group_lv_char; + int group_lv; // DEPRECATED + int group_lv_char; // DEPRECATED + char *at_groups; // quick @commands "can-use" lookup + char *char_groups; // quick @charcommands "can-use" lookup bool log; }; -- cgit v1.2.3-60-g2f50 From 5ceccb77064b557a2f616040f937417c8f002a72 Mon Sep 17 00:00:00 2001 From: gumi Date: Tue, 16 May 2017 21:34:11 -0400 Subject: add buildin add_group_command() --- src/map/script.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index 75f747fb6..1f3c2801f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -21499,6 +21499,43 @@ BUILDIN(issit) return true; } +BUILDIN(add_group_command) +{ + AtCommandInfo *acmd_d; + struct atcmd_binding_data *bcmd_d; + GroupSettings *group; + int group_index; + const char *atcmd = script_getstr(st, 2); + int group_id = script_getnum(st, 3); + bool self_perm = (script_getnum(st, 4) == 1); + bool char_perm = (script_getnum(st, 5) == 1); + + if (!pcg->exists(group_id)) { + ShowWarning("script:add_group_command: group does not exist: %i\n", group_id); + script_pushint(st, 0); + return false; + } + + group = pcg->id2group(group_id); + group_index = pcg->get_idx(group); + + if ((bcmd_d = atcommand->get_bind_byname(atcmd)) != NULL) { + bcmd_d->at_groups[group_index] = self_perm; + bcmd_d->char_groups[group_index] = char_perm; + script_pushint(st, 1); + return true; + } else if ((acmd_d = atcommand->get_info_byname(atcmd)) != NULL) { + acmd_d->at_groups[group_index] = self_perm; + acmd_d->char_groups[group_index] = char_perm; + script_pushint(st, 1); + return true; + } + + ShowWarning("script:add_group_command: command does not exist: %s\n", atcmd); + script_pushint(st, 0); + return false; +} + /** * @commands (script based) **/ @@ -21548,6 +21585,8 @@ BUILDIN(bindatcmd) atcommand->binding[i]->group_lv = group_lv; atcommand->binding[i]->group_lv_char = group_lv_char; atcommand->binding[i]->log = log; + CREATE(atcommand->binding[i]->at_groups, char, db_size(pcg->db)); + CREATE(atcommand->binding[i]->char_groups, char, db_size(pcg->db)); } return true; @@ -23719,6 +23758,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(useatcmd, "s"), BUILDIN_DEF(has_permission, "v?"), BUILDIN_DEF(can_use_command, "s?"), + BUILDIN_DEF(add_group_command, "siii"), /** * Item bound [Xantara] [Akinari] [Mhalicot/Hercules] -- cgit v1.2.3-60-g2f50 From a24eeb0c19b5301330fe532ecf575a84c13a6c9b Mon Sep 17 00:00:00 2001 From: gumi Date: Mon, 15 May 2017 12:04:38 -0400 Subject: add support for custom atcommands in can_use_command --- src/map/atcommand.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 221e9a311..19a7e360b 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -10228,31 +10228,34 @@ void atcommand_db_load_groups(GroupSettings **groups, struct config_setting_t ** } bool atcommand_can_use(struct map_session_data *sd, const char *command) { - AtCommandInfo *info = atcommand->get_info_byname(atcommand->check_alias(command + 1)); + AtCommandInfo *acmd_d; + struct atcmd_binding_data *bcmd_d; nullpo_retr(false, sd); - nullpo_retr(false, command); - if (info == NULL) - return false; - if ((*command == atcommand->at_symbol && info->at_groups[pcg->get_idx(sd->group)] != 0) || - (*command == atcommand->char_symbol && info->char_groups[pcg->get_idx(sd->group)] != 0) ) { - return true; + if ((acmd_d = atcommand->get_info_byname(atcommand->check_alias(command + 1))) != NULL) { + return ((*command == atcommand->at_symbol && acmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (*command == atcommand->char_symbol && acmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); + } else if ((bcmd_d = atcommand->get_bind_byname(atcommand->check_alias(command + 1))) != NULL) { + return ((*command == atcommand->at_symbol && bcmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (*command == atcommand->char_symbol && bcmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); } return false; } + bool atcommand_can_use2(struct map_session_data *sd, const char *command, AtCommandType type) { - AtCommandInfo *info = atcommand->get_info_byname(atcommand->check_alias(command)); + AtCommandInfo *acmd_d; + struct atcmd_binding_data *bcmd_d; nullpo_retr(false, sd); - nullpo_retr(false, command); - if (info == NULL) - return false; - if ((type == COMMAND_ATCOMMAND && info->at_groups[pcg->get_idx(sd->group)] != 0) || - (type == COMMAND_CHARCOMMAND && info->char_groups[pcg->get_idx(sd->group)] != 0) ) { - return true; + if ((acmd_d = atcommand->get_info_byname(atcommand->check_alias(command))) != NULL) { + return ((type == COMMAND_ATCOMMAND && acmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (type == COMMAND_CHARCOMMAND && acmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); + } else if ((bcmd_d = atcommand->get_bind_byname(atcommand->check_alias(command))) != NULL) { + return ((type == COMMAND_ATCOMMAND && bcmd_d->at_groups[pcg->get_idx(sd->group)] > 0) || + (type == COMMAND_CHARCOMMAND && bcmd_d->char_groups[pcg->get_idx(sd->group)] > 0)); } return false; -- cgit v1.2.3-60-g2f50