Added triggers
This commit is contained in:
parent
53f7fb477b
commit
6fcc51746b
|
@ -16,7 +16,6 @@ struct _GmMcpIcecrewPlayerdbPrivate {
|
|||
gint self;
|
||||
GList *db;
|
||||
GList *last_init_keys;
|
||||
GList *signals;
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
|
@ -112,7 +111,6 @@ gm_mcp_icecrew_playerdb_init(GmMcpIcecrewPlayerdb *obj) {
|
|||
obj->priv->self = 0;
|
||||
obj->priv->db = NULL;
|
||||
obj->priv->last_init_keys = NULL;
|
||||
obj->priv->signals = NULL;
|
||||
}
|
||||
|
||||
GmMcpIcecrewPlayerdb *
|
||||
|
@ -144,6 +142,11 @@ gm_playerdb_player_info_get_prop(GmPlayerdbPlayerInfo *ppi, gchar const *key) {
|
|||
return g_hash_table_lookup(ppi->values, key);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gm_mcp_icecrew_playerdb_initializing(GmMcpIcecrewPlayerdb *package) {
|
||||
return package->priv->last_init_keys != NULL;
|
||||
}
|
||||
|
||||
void
|
||||
gm_mcp_icecrew_playerdb_find_players_with(GmMcpIcecrewPlayerdb *package,
|
||||
gchar const *key, gchar const *value, PlayerdbFindFunc func,
|
||||
|
|
|
@ -69,6 +69,7 @@ gchar const *gm_playerdb_player_info_get_prop(GmPlayerdbPlayerInfo *ppi,
|
|||
void gm_mcp_icecrew_playerdb_find_players_with(GmMcpIcecrewPlayerdb *package,
|
||||
gchar const *key, gchar const *value, PlayerdbFindFunc func,
|
||||
gpointer user_data);
|
||||
gboolean gm_mcp_icecrew_playerdb_initializing(GmMcpIcecrewPlayerdb *package);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GM_MCP_ICECREW_PLAYERDB_H__ */
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../gm-marshal.h"
|
||||
#include "../gm-debug.h"
|
||||
#include "../gm-world.h"
|
||||
#include "../gm-triggers.h"
|
||||
|
||||
#define GM_MCP_ICECREW_USERLIST_GET_PRIVATE(object)( \
|
||||
G_TYPE_INSTANCE_GET_PRIVATE((object), \
|
||||
|
@ -21,19 +22,19 @@
|
|||
#define USERLIST_ICON_SIZE 22
|
||||
|
||||
static GmKeyValuePair default_states[] = {
|
||||
{"away+idle", "ice-userlist/away+idle.svg"},
|
||||
{"busy+idle", "ice-userlist/busy+idle.svg"},
|
||||
{"away", "ice-userlist/away.svg"},
|
||||
{"busy", "ice-userlist/busy.svg"},
|
||||
{"avail+idle", "ice-userlist/avail+idle.svg"},
|
||||
{NULL, NULL}
|
||||
{"away+idle", "ice-userlist/away+idle.svg"},
|
||||
{"busy+idle", "ice-userlist/busy+idle.svg"},
|
||||
{"away", "ice-userlist/away.svg"},
|
||||
{"busy", "ice-userlist/busy.svg"},
|
||||
{"avail+idle", "ice-userlist/avail+idle.svg"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static GmKeyValuePair default_ranks[] = {
|
||||
{"inhabitant", "ice-userlist/inhabitant.svg"},
|
||||
{"programmer", "ice-userlist/programmer.svg"},
|
||||
{"wizard", "ice-userlist/wizard.svg"},
|
||||
{NULL, NULL}
|
||||
{"inhabitant", "ice-userlist/inhabitant.svg"},
|
||||
{"programmer", "ice-userlist/programmer.svg"},
|
||||
{"wizard", "ice-userlist/wizard.svg"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
struct _GmMcpIcecrewUserlistPrivate {
|
||||
|
@ -48,6 +49,8 @@ struct _GmMcpIcecrewUserlistPrivate {
|
|||
|
||||
gchar *rank_dir;
|
||||
gchar *state_dir;
|
||||
|
||||
gboolean initializing;
|
||||
};
|
||||
|
||||
static gchar *gm_mcp_icecrew_userlist_depends[] = {
|
||||
|
@ -754,6 +757,40 @@ gm_mcp_icecrew_userlist_fetch_progress(GmFetchHandle *g,
|
|||
}
|
||||
}
|
||||
|
||||
#define MAX_MATCHES 10
|
||||
|
||||
void
|
||||
gm_mcp_icecrew_userlist_process_triggers(GmMcpIcecrewUserlist *package,
|
||||
gchar const *username, GmTriggerConditionType condition) {
|
||||
GmWorld *world;
|
||||
GmTriggers *triggers;
|
||||
GList const *item;
|
||||
GmTrigger *trigger;
|
||||
regmatch_t matches[MAX_MATCHES];
|
||||
GmMcpPackage *playerdb = gm_mcp_session_find_package(
|
||||
GM_MCP_PACKAGE_SESSION(package), "dns-nl-icecrew-playerdb");
|
||||
|
||||
if (gm_mcp_icecrew_playerdb_initializing(
|
||||
GM_MCP_ICECREW_PLAYERDB(playerdb))) {
|
||||
return;
|
||||
}
|
||||
|
||||
world = GM_MCP_SESSION_WORLD(GM_MCP_PACKAGE_SESSION(package));
|
||||
triggers = gm_world_triggers(world);
|
||||
|
||||
for (item = gm_triggers_list(triggers); item; item = item->next) {
|
||||
trigger = (GmTrigger *)(item->data);
|
||||
|
||||
if (trigger->event == TT_USERS) {
|
||||
if (gm_trigger_match_user(trigger, username, condition, matches,
|
||||
MAX_MATCHES)) {
|
||||
gm_world_apply_trigger(world, trigger, username, matches);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
gm_mcp_icecrew_userlist_handle_ranks_states(GmMcpIcecrewUserlist *package,
|
||||
GList *values, gboolean rank) {
|
||||
|
@ -944,6 +981,36 @@ gm_mcp_icecrew_userlist_create_view(GmMcpPackage *package, GObject *parent) {
|
|||
gm_mcp_userlist_view_new(package, parent);
|
||||
}
|
||||
|
||||
void
|
||||
gm_mcp_icecrew_userlist_process_state_changed(GmMcpIcecrewUserlist *userlist,
|
||||
GmPlayerdbPlayerInfo *ppi, gchar const *value, gchar const *old) {
|
||||
gboolean was_away, was_idle;
|
||||
gboolean is_away, is_idle;
|
||||
gchar const *name = gm_playerdb_player_info_get_prop(ppi, "P_NAME");
|
||||
|
||||
was_away = (strstr(old, "away") != NULL || strstr(old, "busy") != NULL);
|
||||
was_idle = (strstr(old, "idle") != NULL);
|
||||
|
||||
is_away = (strstr(value, "away") != NULL || strstr(value, "busy") != NULL);
|
||||
is_idle = (strstr(value, "idle") != NULL);
|
||||
|
||||
if (was_away && !is_away) {
|
||||
gm_mcp_icecrew_userlist_process_triggers(userlist, name,
|
||||
TCT_USER_AWAY_OFF);
|
||||
} else if (!was_away && is_away) {
|
||||
gm_mcp_icecrew_userlist_process_triggers(userlist, name,
|
||||
TCT_USER_AWAY);
|
||||
}
|
||||
|
||||
if (was_idle && !is_idle) {
|
||||
gm_mcp_icecrew_userlist_process_triggers(userlist, name,
|
||||
TCT_USER_IDLE_OFF);
|
||||
} else if (!was_idle && is_idle) {
|
||||
gm_mcp_icecrew_userlist_process_triggers(userlist, name,
|
||||
TCT_USER_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
void
|
||||
on_gm_mcp_icecrew_userlist_add(GmMcpIcecrewPlayerdb *playerdb,
|
||||
|
@ -954,6 +1021,7 @@ on_gm_mcp_icecrew_userlist_add(GmMcpIcecrewPlayerdb *playerdb,
|
|||
|
||||
g_signal_emit(userlist, gm_mcp_icecrew_userlist_signals[PLAYER_ADDED],
|
||||
0, ppi->id, name, icon_path, sort);
|
||||
gm_mcp_icecrew_userlist_process_triggers(userlist, name, TCT_USER_ONLINE);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -963,11 +1031,13 @@ on_gm_mcp_icecrew_userlist_set(GmMcpIcecrewPlayerdb *playerdb,
|
|||
gchar *sort = NULL;
|
||||
|
||||
if (strcmp(key, "P_STATE") == 0) {
|
||||
sort = gm_mcp_icecrew_userlist_sort_string(userlist, ppi);
|
||||
|
||||
sort = gm_mcp_icecrew_userlist_sort_string(userlist, ppi);
|
||||
g_signal_emit(userlist, gm_mcp_icecrew_userlist_signals[STATE_CHANGED],
|
||||
0, ppi->id, gm_mcp_icecrew_userlist_icon_path(userlist, ppi),
|
||||
sort);
|
||||
|
||||
gm_mcp_icecrew_userlist_process_state_changed(userlist, ppi, value,
|
||||
old);
|
||||
} else if (strcmp(key, "P_RANK") == 0) {
|
||||
sort = gm_mcp_icecrew_userlist_sort_string(userlist, ppi);
|
||||
|
||||
|
@ -985,6 +1055,9 @@ on_gm_mcp_icecrew_userlist_set(GmMcpIcecrewPlayerdb *playerdb,
|
|||
void
|
||||
on_gm_mcp_icecrew_userlist_delete(GmMcpIcecrewPlayerdb *playerdb,
|
||||
GmPlayerdbPlayerInfo *ppi, GmMcpIcecrewUserlist *userlist) {
|
||||
gchar const *name = gm_playerdb_player_info_get_prop(ppi, "P_NAME");
|
||||
|
||||
g_signal_emit(userlist, gm_mcp_icecrew_userlist_signals[PLAYER_REMOVED],
|
||||
0, ppi->id);
|
||||
gm_mcp_icecrew_userlist_process_triggers(userlist, name, TCT_USER_OFFLINE);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ struct _GmMcpVmooUserlistPrivate {
|
|||
GList *fields;
|
||||
GList *icons;
|
||||
GList *users;
|
||||
|
||||
gboolean initializing;
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
|
@ -204,6 +206,37 @@ gm_mcp_vmoo_userlist_new() {
|
|||
return obj;
|
||||
}
|
||||
|
||||
#define MAX_MATCHES 10
|
||||
|
||||
void
|
||||
gm_mcp_vmoo_userlist_process_triggers(GmMcpVmooUserlist *package,
|
||||
gchar const *username, GmTriggerConditionType condition) {
|
||||
GmWorld *world;
|
||||
GmTriggers *triggers;
|
||||
GList const *item;
|
||||
GmTrigger *trigger;
|
||||
regmatch_t matches[MAX_MATCHES];
|
||||
|
||||
if (package->priv->initializing) {
|
||||
return;
|
||||
}
|
||||
|
||||
world = GM_MCP_SESSION_WORLD(GM_MCP_PACKAGE_SESSION(package));
|
||||
triggers = gm_world_triggers(world);
|
||||
|
||||
for (item = gm_triggers_list(triggers); item; item = item->next) {
|
||||
trigger = (GmTrigger *)(item->data);
|
||||
|
||||
if (trigger->event == TT_USERS) {
|
||||
if (gm_trigger_match_user(trigger, username, condition, matches,
|
||||
MAX_MATCHES)) {
|
||||
gm_world_apply_trigger(world, trigger, username, matches);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
gm_mcp_vmoo_userlist_handle_fields(GmMcpVmooUserlist *package, MOOVar *list) {
|
||||
MOOVar *field;
|
||||
|
@ -335,6 +368,9 @@ gm_mcp_vmoo_userlist_remove_user(GmMcpVmooUserlist *package, gint nr) {
|
|||
ui = (UserInfo *) (elem->data);
|
||||
|
||||
if (ui->nr == nr) {
|
||||
gm_mcp_vmoo_userlist_process_triggers(package, ui->name,
|
||||
TCT_USER_OFFLINE);
|
||||
|
||||
package->priv->users = g_list_remove(package->priv->users, ui);
|
||||
break;
|
||||
}
|
||||
|
@ -389,6 +425,9 @@ gm_mcp_vmoo_userlist_handle_user_update(GmMcpVmooUserlist *package, MOOVar *v) {
|
|||
g_signal_emit(package, gm_mcp_vmoo_userlist_signals[PLAYER_ADDED], 0,
|
||||
nr, name, gm_mcp_vmoo_userlist_get_icon(package, ui), sort);
|
||||
g_free(sort);
|
||||
|
||||
gm_mcp_vmoo_userlist_process_triggers(package, ui->name,
|
||||
TCT_USER_ONLINE);
|
||||
} else {
|
||||
if (ui->name || strcmp(ui->name, name) != 0) {
|
||||
g_free(ui->name);
|
||||
|
@ -420,6 +459,7 @@ gm_mcp_vmoo_userlist_handle_set(GmMcpVmooUserlist *package, MOOVar *v) {
|
|||
return;
|
||||
}
|
||||
|
||||
package->priv->initializing = TRUE;
|
||||
gm_mcp_vmoo_userlist_remove_users(package);
|
||||
|
||||
for (ui = v->list; ui; ui = ui->next) {
|
||||
|
@ -429,6 +469,8 @@ gm_mcp_vmoo_userlist_handle_set(GmMcpVmooUserlist *package, MOOVar *v) {
|
|||
|
||||
gm_mcp_vmoo_userlist_handle_user_update(package, ui->list);
|
||||
}
|
||||
|
||||
package->priv->initializing = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -470,6 +512,7 @@ gm_mcp_vmoo_userlist_handle_state(GmMcpVmooUserlist *package, MOOVar *v,
|
|||
MOOVar *nr;
|
||||
UserInfo *u;
|
||||
gchar *sort;
|
||||
GmTriggerConditionType condition = 0;
|
||||
|
||||
if (v->type != LIST) {
|
||||
return;
|
||||
|
@ -489,6 +532,12 @@ gm_mcp_vmoo_userlist_handle_state(GmMcpVmooUserlist *package, MOOVar *v,
|
|||
} else if (u->state == U_IDLE) {
|
||||
u->state = U_NORMAL;
|
||||
}
|
||||
|
||||
if (onOff) {
|
||||
condition = TCT_USER_IDLE;
|
||||
} else {
|
||||
condition = TCT_USER_IDLE_OFF;
|
||||
}
|
||||
break;
|
||||
case U_AWAY:
|
||||
if (u->state == U_IDLEAWAY && !onOff) {
|
||||
|
@ -500,16 +549,28 @@ gm_mcp_vmoo_userlist_handle_state(GmMcpVmooUserlist *package, MOOVar *v,
|
|||
} else if (u->state == U_AWAY) {
|
||||
u->state = U_NORMAL;
|
||||
}
|
||||
break;
|
||||
|
||||
if (onOff) {
|
||||
condition = TCT_USER_AWAY;
|
||||
} else {
|
||||
condition = TCT_USER_AWAY_OFF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
sort = gm_mcp_vmoo_userlist_sort_string(package, u);
|
||||
|
||||
g_signal_emit(package,
|
||||
gm_mcp_vmoo_userlist_signals[STATE_CHANGED], 0,
|
||||
nr->i, gm_mcp_vmoo_userlist_get_icon(package, u), sort);
|
||||
|
||||
if (condition != 0) {
|
||||
gm_mcp_vmoo_userlist_process_triggers(package, u->name,
|
||||
condition);
|
||||
}
|
||||
|
||||
g_free(sort);
|
||||
} else {
|
||||
GM_DEBUG("User %d does not exist!", nr->i);
|
||||
|
|
Reference in New Issue