diff options
Diffstat (limited to 'src/map/pc_groups.c')
-rw-r--r-- | src/map/pc_groups.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index 3111e2788..1a83c8b63 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/conf.h" #include "../common/db.h" @@ -13,28 +14,26 @@ #include "pc_groups.h" #include "pc.h" // e_pc_permission - typedef struct GroupSettings GroupSettings; // Cached config settings/pointers for quick lookup struct GroupSettings { unsigned int id; // groups.[].id int level; // groups.[].level - const char *name; // groups.[].name - config_setting_t *commands; // groups.[].commands + char name[60]; // copy of groups.[].name unsigned int e_permissions; // packed groups.[].permissions bool log_commands; // groups.[].log_commands - /// Following are used only during config reading + int group_pos;/* pos on load [Ind] */ + /// Following are used/avaialble only during config reading + config_setting_t *commands; // groups.[].commands config_setting_t *permissions; // groups.[].permissions config_setting_t *inherit; // groups.[].inherit bool inheritance_done; // have all inheritance rules been evaluated? config_setting_t *root; // groups.[] - int group_pos;/* pos on load */ }; int pc_group_max; /* known number of groups */ -static config_t pc_group_config; static DBMap* pc_group_db; // id -> GroupSettings static DBMap* pc_groupname_db; // name -> GroupSettings @@ -60,8 +59,8 @@ static inline GroupSettings* name2group(const char* group_name) * Loads group configuration from config file into memory. * @private */ -static void read_config(void) -{ +static void read_config(void) { + config_t pc_group_config; config_setting_t *groups = NULL; const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name int group_count = 0; @@ -126,7 +125,7 @@ static void read_config(void) CREATE(group_settings, GroupSettings, 1); group_settings->id = id; group_settings->level = level; - group_settings->name = groupname; + safestrncpy(group_settings->name, groupname, 60); group_settings->log_commands = (bool)log_commands; group_settings->inherit = config_setting_get_member(group, "inherit"); group_settings->commands = config_setting_get_member(group, "commands"); @@ -155,7 +154,7 @@ static void read_config(void) for (i = 0; i < count; ++i) { config_setting_t *command = config_setting_get_elem(commands, i); const char *name = config_setting_name(command); - if (!atcommand_exists(name)) { + if (!atcommand->exists(name)) { ShowConfigWarning(command, "pc_groups:read_config: non-existent command name '%s', removing...", name); config_setting_remove(commands, name); --i; @@ -278,26 +277,21 @@ static void read_config(void) if( ( pc_group_max = group_count ) ) { DBIterator *iter = db_iterator(pc_group_db); GroupSettings *group_settings = NULL; - int* group_ids = aMalloc( pc_group_max * sizeof(int) ); + unsigned int* group_ids = aMalloc( pc_group_max * sizeof(unsigned int) ); int i = 0; for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) { group_ids[i++] = group_settings->id; } - atcommand_db_load_groups(group_ids); - - aFree(group_ids); + if( atcommand->group_ids ) + aFree(atcommand->group_ids); + atcommand->group_ids = group_ids; + atcommand->load_groups(); + dbi_destroy(iter); } -} - -/** - * Removes group configuration from memory. - * @private - */ -static void destroy_config(void) -{ + config_destroy(&pc_group_config); } @@ -312,13 +306,12 @@ static void destroy_config(void) static inline int AtCommandType2idx(AtCommandType type) { return (type-1); } /** - * Checks if player group can use @/#command + * Checks if player group can use @/#command, used only during parse (only available during parse) * @param group_id ID of the group * @param command Command name without @/# and params * @param type enum AtCommanndType { COMMAND_ATCOMMAND = 1, COMMAND_CHARCOMMAND = 2 } */ -bool pc_group_can_use_command(int group_id, const char *command, AtCommandType type) -{ +bool pc_group_can_use_command(int group_id, const char *command, AtCommandType type) { int result = 0; config_setting_t *commands = NULL; GroupSettings *group = NULL; @@ -357,6 +350,7 @@ void pc_group_pc_load(struct map_session_data * sd) { sd->permissions = group->e_permissions; sd->group_pos = group->group_pos; sd->group_level = group->level; + sd->group_log_command = group->log_commands; } /** * Checks if player group has a permission @@ -442,7 +436,6 @@ void do_final_pc_groups(void) db_destroy(pc_group_db); if (pc_groupname_db != NULL ) db_destroy(pc_groupname_db); - destroy_config(); } /** @@ -452,17 +445,17 @@ void do_final_pc_groups(void) */ void pc_groups_reload(void) { struct map_session_data* sd = NULL; - struct s_mapiterator* iter = NULL; + struct s_mapiterator* iter; do_final_pc_groups(); do_init_pc_groups(); /* refresh online users permissions */ iter = mapit_getallusers(); - for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) { + for (sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter)) { pc_group_pc_load(sd); } - mapit_free(iter); + mapit->free(iter); } |