summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/HPMi.h5
-rw-r--r--src/map/HPMmap.c29
-rw-r--r--src/map/HPMmap.h2
-rw-r--r--src/map/map.c1
-rw-r--r--src/map/pc_groups.c13
-rw-r--r--src/map/pc_groups.h13
6 files changed, 57 insertions, 6 deletions
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index 742132cde..78a3a9ab5 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -138,6 +138,9 @@ enum HPluginConfType {
/* HPMi->addBattleConf */
#define addBattleConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_BATTLE,bcname,funcname)
+/* HPMi->addPCGPermission */
+#define addGroupPermission(pcgname,maskptr) HPMi->addPCGPermission(HPMi->pid,pcgname,&maskptr)
+
/* Hercules Plugin Mananger Include Interface */
HPExport struct HPMi_interface {
/* */
@@ -161,6 +164,8 @@ HPExport struct HPMi_interface {
bool (*addArg) (unsigned int pluginID, char *name, bool has_param,void (*func) (char *param),void (*help) (void));
/* battle-config recv param */
bool (*addConf) (unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val));
+ /* pc group permission */
+ void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);
} HPMi_s;
#ifndef _HPM_H_
HPExport struct HPMi_interface *HPMi;
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index 8d7c74ef2..9c09a7ad1 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -65,8 +65,9 @@ void HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataType
}
void HPM_map_plugin_load_sub(struct hplugin *plugin) {
- plugin->hpi->addCommand = HPM->import_symbol("addCommand",plugin->idx);
- plugin->hpi->addScript = HPM->import_symbol("addScript",plugin->idx);
+ plugin->hpi->addCommand = HPM->import_symbol("addCommand",plugin->idx);
+ plugin->hpi->addScript = HPM->import_symbol("addScript",plugin->idx);
+ plugin->hpi->addPCGPermission = HPM->import_symbol("addGroupPermission",plugin->idx);
}
bool HPM_map_add_atcommand(char *name, AtCommandFunc func) {
@@ -98,6 +99,30 @@ void HPM_map_atcommands(void) {
}
void HPM_map_do_final(void) {
+ unsigned char i;
+
if( atcommand_list )
aFree(atcommand_list);
+ /**
+ * why is pcg->HPM being cleared here? because PCG's do_final is not final,
+ * is used on reload, and would thus cause plugin-provided permissions to go away
+ **/
+ for( i = 0; i < pcg->HPMpermissions_count; i++ ) {
+ aFree(pcg->HPMpermissions[i].name);
+ }
+ if( pcg->HPMpermissions )
+ aFree(pcg->HPMpermissions);
+}
+
+/**
+ * Adds a new group permission to the HPM-provided list
+ **/
+void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned int *mask) {
+ unsigned char index = pcg->HPMpermissions_count;
+
+ RECREATE(pcg->HPMpermissions, struct pc_groups_new_permission, ++pcg->HPMpermissions_count);
+
+ pcg->HPMpermissions[index].pID = pluginID;
+ pcg->HPMpermissions[index].name = aStrdup(name);
+ pcg->HPMpermissions[index].mask = mask;
}
diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h
index f5fe70276..f86f02eb9 100644
--- a/src/map/HPMmap.h
+++ b/src/map/HPMmap.h
@@ -20,4 +20,6 @@ void HPM_map_plugin_load_sub(struct hplugin *plugin);
void HPM_map_do_final(void);
+void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned int *mask);
+
#endif /* _HPM_MAP_ */
diff --git a/src/map/map.c b/src/map/map.c
index 68a675a37..5344d11bf 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -5379,6 +5379,7 @@ void map_hp_symbols(void) {
/* specific */
HPM->share(atcommand->create,"addCommand");
HPM->share(script->addScript,"addScript");
+ HPM->share(HPM_map_add_group_permission,"addGroupPermission");
}
void map_load_defaults(void) {
diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c
index 59dd951c7..4ddb95c9b 100644
--- a/src/map/pc_groups.c
+++ b/src/map/pc_groups.c
@@ -423,10 +423,17 @@ void do_init_pc_groups(void) {
for(i = 0; i < len; i++) {
unsigned int p;
- if( ( p = pcg->add_permission(pc_g_defaults[i].name) ) != pc_g_defaults[i].permission )
+ if( ( p = pc_groups_add_permission(pc_g_defaults[i].name) ) != pc_g_defaults[i].permission )
ShowError("do_init_pc_groups: %s error : %d != %d\n",pc_g_defaults[i].name,p,pc_g_defaults[i].permission);
}
+ /**
+ * Handle plugin-provided permissions
+ **/
+ for(i = 0; i < pcg->HPMpermissions_count; i++) {
+ *pcg->HPMpermissions[i].mask = pc_groups_add_permission(pcg->HPMpermissions[i].name);
+ }
+
pcg->db = idb_alloc(DB_OPT_RELEASE_DATA);
pcg->name_db = stridb_alloc(DB_OPT_DUP_KEY, 0);
@@ -502,6 +509,9 @@ void pc_groups_defaults(void) {
pcg->permissions = NULL;
pcg->permission_count = 0;
/* */
+ pcg->HPMpermissions = NULL;
+ pcg->HPMpermissions_count = 0;
+ /* */
pcg->init = do_init_pc_groups;
pcg->final = do_final_pc_groups;
pcg->reload = pc_groups_reload;
@@ -514,5 +524,4 @@ void pc_groups_defaults(void) {
pcg->get_name = pc_group_get_name;
pcg->get_level = pc_group_get_level;
pcg->get_idx = pc_group_get_idx;
- pcg->add_permission = pc_groups_add_permission;
}
diff --git a/src/map/pc_groups.h b/src/map/pc_groups.h
index 943fb7fa5..3396512ea 100644
--- a/src/map/pc_groups.h
+++ b/src/map/pc_groups.h
@@ -49,12 +49,19 @@ struct GroupSettings {
config_setting_t *root; // groups.[]
};
+typedef struct GroupSettings GroupSettings;
+
struct pc_groups_permission_table {
char *name;
unsigned int permission;
};
-typedef struct GroupSettings GroupSettings;
+/* used by plugins to list permissions */
+struct pc_groups_new_permission {
+ unsigned int pID;/* plugin identity (for the future unload during runtime support) */
+ char *name;/* aStrdup' of the permission name */
+ unsigned int *mask;/* pointer to the plugin val that will store the value of the mask */
+};
struct pc_groups_interface {
/* */
@@ -64,6 +71,9 @@ struct pc_groups_interface {
struct pc_groups_permission_table *permissions;
unsigned char permission_count;
/* */
+ struct pc_groups_new_permission *HPMpermissions;
+ unsigned char HPMpermissions_count;
+ /* */
void (*init) (void);
void (*final) (void);
void (*reload) (void);
@@ -76,7 +86,6 @@ struct pc_groups_interface {
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;