summaryrefslogtreecommitdiff
path: root/src/map/pc_groups.h
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-11-04 21:13:19 -0200
committershennetsind <ind@henn.et>2013-11-04 22:32:36 -0200
commit0a965aafde882e905ea71f3bcef8f4ff81c1c327 (patch)
treeab98747ab350cf16847418c68be191db99765a34 /src/map/pc_groups.h
parentfa07bc455ebb511defa9623fedc8074d66135c19 (diff)
downloadhercules-0a965aafde882e905ea71f3bcef8f4ff81c1c327.tar.gz
hercules-0a965aafde882e905ea71f3bcef8f4ff81c1c327.tar.bz2
hercules-0a965aafde882e905ea71f3bcef8f4ff81c1c327.tar.xz
hercules-0a965aafde882e905ea71f3bcef8f4ff81c1c327.zip
pc_groups interfaced
The last file without a interface is now no more (date.h doesn't count :P). Modified the way permissions are stored in order to enable plugins to be able to create permissions ( pcg->add_permission("name") [returns permission key] ). Special Thanks to Haruna! Closes #121 Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/pc_groups.h')
-rw-r--r--src/map/pc_groups.h66
1 files changed, 43 insertions, 23 deletions
diff --git a/src/map/pc_groups.h b/src/map/pc_groups.h
index 8f350c2b6..28c82d619 100644
--- a/src/map/pc_groups.h
+++ b/src/map/pc_groups.h
@@ -32,34 +32,54 @@ enum e_pc_permission {
PC_PERM_HCHSYS_ADMIN = 0x200000,
};
-/// Total number of PC permissions (without PC_PERM_NONE).
-/// This is manifest constant for the size of pc_g_permission_name array,
-/// so it's possible to apply sizeof to it [C-FAQ 1.24]
-/// Whenever adding new permission: 1. add enum entry above, 2. add entry into
-/// pc_g_permission_name (in pc.c), 3. increase NUM_PC_PERM below by 1.
-#define NUM_PC_PERM 22
-
-struct pc_permission_name_table {
- const char *name;
- enum e_pc_permission permission;
+// Cached config settings for quick lookup
+struct GroupSettings {
+ unsigned int id; // groups.[].id
+ int level; // groups.[].level
+ char *name; // copy of groups.[].name
+ unsigned int e_permissions; // packed groups.[].permissions
+ bool log_commands; // groups.[].log_commands
+ int index; // internal index of the group (contiguous range starting at 0) [Ind]
+ /// Following are used/available 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.[]
};
-/// Name <-> enum table for PC permissions
-extern const struct pc_permission_name_table pc_g_permission_name[NUM_PC_PERM];
+struct pc_groups_permission_table {
+ char *name;
+ unsigned int permission;
+};
typedef struct GroupSettings GroupSettings;
-GroupSettings* pc_group_get_dummy_group(void);
-bool pc_group_exists(int group_id);
-GroupSettings* pc_group_id2group(int group_id);
-bool pc_group_has_permission(GroupSettings *group, enum e_pc_permission permission);
-bool pc_group_should_log_commands(GroupSettings *group);
-const char* pc_group_get_name(GroupSettings *group);
-int pc_group_get_level(GroupSettings *group);
-int pc_group_get_idx(GroupSettings *group);
+struct pc_groups_interface {
+ /* */
+ DBMap* db; // id -> GroupSettings
+ DBMap* name_db; // name -> GroupSettings
+ /* */
+ struct pc_groups_permission_table *permissions;
+ unsigned char permission_count;
+ /* */
+ void (*init) (void);
+ void (*final) (void);
+ void (*reload) (void);
+ /* */
+ GroupSettings* (*get_dummy_group) (void);
+ bool (*exists) (int group_id);
+ GroupSettings* (*id2group) (int group_id);
+ bool (*has_permission) (GroupSettings *group, unsigned int permission);
+ bool (*should_log_commands) (GroupSettings *group);
+ const char* (*get_name) (GroupSettings *group);
+ int (*get_level) (GroupSettings *group);
+ int (*get_idx) (GroupSettings *group);
+ unsigned int (*add_permission) (const char *name);
+};
+
+struct pc_groups_interface *pcg;
-void do_init_pc_groups(void);
-void do_final_pc_groups(void);
-void pc_groups_reload(void);
+void pc_groups_defaults(void);
#endif // _PC_GROUPS_H_