summaryrefslogtreecommitdiff
path: root/src/map/pc_groups.h
diff options
context:
space:
mode:
authorPiotr HaƂaczkiewicz <piotr.halaczkiewicz@gmail.com>2013-07-24 12:41:50 +0200
committerPiotr HaƂaczkiewicz <piotr.halaczkiewicz@gmail.com>2013-07-29 21:51:08 +0200
commite7750ecfff5bf856ecc9f38ea327c6b6cc535761 (patch)
tree163859983acdced47483f0d4fb480377da5b5be2 /src/map/pc_groups.h
parent640c66779d8da4baa8af6bd0fee2583ec2b6143c (diff)
downloadhercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.tar.gz
hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.tar.bz2
hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.tar.xz
hercules-e7750ecfff5bf856ecc9f38ea327c6b6cc535761.zip
Permission cache overhaul
* Reworked group permission caching in session data (follow-up to cd45c30ab2dcc44bfbfac283d15bb09b3d4644bc) * Removed duplicated information from session data in favor of direct pointer to group settings. * Added getters for all group data required to process permissions and related stuff. * Added new functions to PC interface and updated calls everywhere. * Extracted function to set new group for a player (used at login, group config reload, manual adjustment of group). * Moved command permission config parsing to atcommand module. * Improved dummy map session handling. * Since it's required for all map sessions to have a valid group, dummy sessions are now created by a designated function. * Updated related code that uses dummy sessions (console `gm use` and script `atcommand`, `useatcmd`). * Various minor improvements and cleanups. * Eliminated some global variables related to loading atcommand permissions for group by passing them directly to function. * Moved definition of global array holding PC permission names from header file to source file. * Streamlined destuction of atcommands database to use DBApply helper function instead of DBIterator. * Replaced hardcoded position of console dummy session with defines from mapindex.h (thx Haruna for pointing it out). * Removed fixed length restriction on group names.
Diffstat (limited to 'src/map/pc_groups.h')
-rw-r--r--src/map/pc_groups.h84
1 files changed, 35 insertions, 49 deletions
diff --git a/src/map/pc_groups.h b/src/map/pc_groups.h
index 0ce7b0d51..8f350c2b6 100644
--- a/src/map/pc_groups.h
+++ b/src/map/pc_groups.h
@@ -5,26 +5,10 @@
#ifndef _PC_GROUPS_H_
#define _PC_GROUPS_H_
-#include "atcommand.h" // AtCommandType
-
-extern int pc_group_max;
-
-bool pc_group_exists(int group_id);
-bool pc_group_can_use_command(int group_id, const char *command, AtCommandType type);
-bool pc_group_has_permission(int group_id, int permission);
-bool pc_group_should_log_commands(int group_id);
-const char* pc_group_id2name(int group_id);
-int pc_group_id2level(int group_id);
-int pc_group_id2idx(int group_id);
-void pc_group_pc_load(struct map_session_data *);
-
-void do_init_pc_groups(void);
-void do_final_pc_groups(void);
-void pc_groups_reload(void);
-
+/// PC permissions
enum e_pc_permission {
- PC_PERM_NONE = 0,
- PC_PERM_TRADE = 0x000001,
+ PC_PERM_NONE = 0, // #0
+ PC_PERM_TRADE = 0x000001, // #1
PC_PERM_PARTY = 0x000002,
PC_PERM_ALL_SKILL = 0x000004,
PC_PERM_USE_ALL_EQUIPMENT = 0x000008,
@@ -33,7 +17,7 @@ enum e_pc_permission {
PC_PERM_NO_CHAT_KICK = 0x000040,
PC_PERM_HIDE_SESSION = 0x000080,
PC_PERM_WHO_DISPLAY_AID = 0x000100,
- PC_PERM_RECEIVE_HACK_INFO = 0x000200,
+ PC_PERM_RECEIVE_HACK_INFO = 0x000200, // #10
PC_PERM_WARP_ANYWHERE = 0x000400,
PC_PERM_VIEW_HPMETER = 0x000800,
PC_PERM_VIEW_EQUIPMENT = 0x001000,
@@ -41,39 +25,41 @@ enum e_pc_permission {
PC_PERM_USE_CHANGEMAPTYPE = 0x004000,
PC_PERM_USE_ALL_COMMANDS = 0x008000,
PC_PERM_RECEIVE_REQUESTS = 0x010000,
- PC_PERM_SHOW_BOSS = 0x020000,
- PC_PERM_DISABLE_PVM = 0x040000,
- PC_PERM_DISABLE_PVP = 0x080000,
+ PC_PERM_SHOW_BOSS = 0x020000,
+ PC_PERM_DISABLE_PVM = 0x040000,
+ PC_PERM_DISABLE_PVP = 0x080000, // #20
PC_PERM_DISABLE_CMD_DEAD = 0x100000,
- PC_PERM_HCHSYS_ADMIN = 0x200000,
+ PC_PERM_HCHSYS_ADMIN = 0x200000,
};
-static const struct {
+/// 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;
- unsigned int permission;
-} pc_g_permission_name[] = {
- { "can_trade", PC_PERM_TRADE },
- { "can_party", PC_PERM_PARTY },
- { "all_skill", PC_PERM_ALL_SKILL },
- { "all_equipment", PC_PERM_USE_ALL_EQUIPMENT },
- { "skill_unconditional", PC_PERM_SKILL_UNCONDITIONAL },
- { "join_chat", PC_PERM_JOIN_ALL_CHAT },
- { "kick_chat", PC_PERM_NO_CHAT_KICK },
- { "hide_session", PC_PERM_HIDE_SESSION },
- { "who_display_aid", PC_PERM_WHO_DISPLAY_AID },
- { "hack_info", PC_PERM_RECEIVE_HACK_INFO },
- { "any_warp", PC_PERM_WARP_ANYWHERE },
- { "view_hpmeter", PC_PERM_VIEW_HPMETER },
- { "view_equipment", PC_PERM_VIEW_EQUIPMENT },
- { "use_check", PC_PERM_USE_CHECK },
- { "use_changemaptype", PC_PERM_USE_CHANGEMAPTYPE },
- { "all_commands", PC_PERM_USE_ALL_COMMANDS },
- { "receive_requests", PC_PERM_RECEIVE_REQUESTS },
- { "show_bossmobs", PC_PERM_SHOW_BOSS },
- { "disable_pvm", PC_PERM_DISABLE_PVM },
- { "disable_pvp", PC_PERM_DISABLE_PVP },
- { "disable_commands_when_dead", PC_PERM_DISABLE_CMD_DEAD },
- { "hchsys_admin", PC_PERM_HCHSYS_ADMIN },
+ enum e_pc_permission permission;
};
+/// Name <-> enum table for PC permissions
+extern const struct pc_permission_name_table pc_g_permission_name[NUM_PC_PERM];
+
+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);
+
+void do_init_pc_groups(void);
+void do_final_pc_groups(void);
+void pc_groups_reload(void);
+
#endif // _PC_GROUPS_H_