// Public Methods void mud_trigger_add_data(MudTrigger *self, const gchar *data, guint length) { gchar *stripped; g_return_if_fail(MUD_IS_TRIGGER(self)); stripped = utils_strip_ansi(data); mud_line_buffer_add_data(self->priv->line_buffer, stripped, strlen(stripped)); g_free(stripped); }
/* Public Methods */ gboolean mud_parse_trigger_do(MudParseTrigger *self, gchar *data) { gchar *profile_name; gchar *actions; gchar *regexstr; gchar *stripped_data; GSList *triggers, *entry; GConfClient *client; GError *error = NULL; gchar keyname[2048]; gint enabled; gint gag; gint ovector[1020]; gboolean doGag = FALSE; MudRegex *regex; MudConnectionView *view; if(!MUD_IS_PARSE_TRIGGER(self)) return FALSE; client = gconf_client_get_default(); g_object_get(self->priv->parent, "parent-view", &view, "regex", ®ex, NULL); g_object_get(view, "profile-name", &profile_name, NULL); g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/list", profile_name); triggers = gconf_client_get_list(client, keyname, GCONF_VALUE_STRING, &error); for (entry = triggers; entry != NULL; entry = g_slist_next(entry)) { g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/%s/enabled", profile_name, (gchar *)entry->data); enabled = gconf_client_get_int(client, keyname, &error); if(enabled) { g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/%s/regex", profile_name, (gchar *)entry->data); regexstr = gconf_client_get_string(client, keyname, &error); stripped_data = utils_strip_ansi((const gchar *) data); if(mud_regex_check(regex, (const gchar *)stripped_data, strlen(stripped_data), (const gchar *)regexstr, ovector)) { g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/%s/gag", profile_name, (gchar *)entry->data); gag = gconf_client_get_int(client, keyname, &error); // FIXME: Kill this global and get a sane // way of doing this in here. - lh if(gag) doGag = TRUE; g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/%s/actions", profile_name, (gchar *)entry->data); actions = gconf_client_get_string(client, keyname, &error); mud_parse_base_parse(self->priv->parent, (const gchar *)actions, stripped_data, ovector); if(actions) g_free(actions); } if(stripped_data) g_free(stripped_data); } } for(entry = triggers; entry != NULL; entry = g_slist_next(entry)) if(entry->data) g_free(entry->data); if(triggers) g_slist_free(triggers); g_object_unref(client); g_free(profile_name); return doGag; }
void mud_trigger_execute(MudTrigger *self, MudLineBufferLine *line, guint length) { gchar *stripped = utils_strip_ansi(line->line->str); guint len = strlen(stripped); switch(self->priv->type) { case MUD_TRIGGER_TYPE_SINGLE: if(self->priv->regex) // Regex match { if(g_regex_match_full(self->priv->regex, stripped, len, 0, 0, &self->priv->info, NULL)) { mud_trigger_do_action(self); if(self->priv->gag) line->gag = TRUE; g_match_info_free(self->priv->info); } } else if(self->priv->glob) // Glob match { if(g_pattern_match_string(self->priv->glob, stripped)) { mud_trigger_do_action(self); if(self->priv->gag) line->gag = TRUE; } } else if(self->priv->simple_regex) // Simple text match. { if(g_regex_match_full(self->priv->simple_regex, stripped, len, 0, 0, &self->priv->info, NULL)) { mud_trigger_do_action(self); if(self->priv->gag) line->gag = TRUE; g_match_info_free(self->priv->info); } } else g_return_if_reached(); break; case MUD_TRIGGER_TYPE_CONDITION: break; default: g_warn_if_reached(); break; } g_free(stripped); }