/** * Checks if player group can use @/#command * @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) { int result = 0; config_setting_t *commands = NULL; GroupSettings *group = NULL; if (pc_group_has_permission(group_id, PC_PERM_USE_ALL_COMMANDS)) return true; if ((group = id2group(group_id)) == NULL) return false; commands = group->commands; if (commands != NULL) { config_setting_t *cmd = NULL; // <commandname> : <bool> (only atcommand) if (type == COMMAND_ATCOMMAND && config_setting_lookup_bool(commands, command, &result)) return (bool)result; // <commandname> : [ <bool>, <bool> ] ([ atcommand, charcommand ]) if ((cmd = config_setting_get_member(commands, command)) != NULL && config_setting_is_aggregate(cmd) && config_setting_length(cmd) == 2) return (bool)config_setting_get_bool_elem(cmd, AtCommandType2idx(type)); } return false; }
static int processRequest(char *request) { int count = 0; int responseTotal = 0; config_setting_t *responseConfig = NULL; config_setting_t *responseCurrent = NULL; const char *responseValue = NULL; const char *requestName = NULL; const char *requestValue = NULL; long volume; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&lockConfig); responseConfig = config_lookup(&config, "response"); responseTotal = config_setting_length(responseConfig); for(count = 0; count < responseTotal; count++) { responseCurrent = config_setting_get_elem(responseConfig, count); if((responseValue = config_setting_get_string_elem(responseCurrent, 1)) != NULL && strcmp(responseValue, request) == 0) { responseValue = config_setting_get_string_elem(responseCurrent, 2); if(config_setting_get_bool_elem(responseCurrent, 0) == 1) { // formulating default response pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); common_data.interface->reply(responseValue, strlen(responseValue)); } else { // attempt to formulate custom response requestName = config_setting_name(responseCurrent); pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if(strcmp(requestName, "volume") == 0) { if(getMixer(&volume) == EXIT_FAILURE) { return EXIT_FAILURE; } replyVolumeCommand(&volume); } else { statusInfo.retrieve(requestName, &requestValue); if(requestValue != NULL) replyDeviceCommand((char *)requestName, (char *)requestValue); else // custom response not possible, reverting to default value replyDeviceCommand((char *)requestName, (char *)responseValue); } } syslog(LOG_DEBUG, "Successfully processed request: %s", request); return EXIT_SUCCESS; // command is matched, returning } else { pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); } } syslog(LOG_DEBUG, "Could not identify request: %s", request); return EXIT_SUCCESS; }