aboutsummaryrefslogtreecommitdiffstats
path: root/irc_channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'irc_channel.c')
-rw-r--r--irc_channel.c54
1 files changed, 47 insertions, 7 deletions
diff --git a/irc_channel.c b/irc_channel.c
index e8564da7..8ea348f2 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -245,7 +245,8 @@ int irc_channel_add_user(irc_channel_t *ic, irc_user_t *iu)
ic->users = g_slist_insert_sorted(ic->users, icu, irc_channel_user_cmp);
if (iu == ic->irc->user || iu == ic->irc->root) {
- irc_channel_update_ops(ic, set_getstr(&ic->irc->b->set, "ops"));
+ irc_channel_update_ops(ic, set_getstr(&ic->irc->b->set, "ops"),
+ set_getstr(&ic->irc->b->set, "ops_mode"));
}
if (iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED) {
@@ -679,14 +680,33 @@ static gint irc_channel_user_cmp(gconstpointer a_, gconstpointer b_)
return irc_user_cmp(a->iu, b->iu);
}
-void irc_channel_update_ops(irc_channel_t *ic, char *value)
+static int irc_channel_prefix_to_mode(char *value)
{
+ if (g_strcasecmp(value, "~") == 0) {
+ return IRC_CHANNEL_USER_OWNER;
+ } else if (g_strcasecmp(value, "&") == 0) {
+ return IRC_CHANNEL_USER_ADMIN;
+ } else if (g_strcasecmp(value, "@") == 0) {
+ return IRC_CHANNEL_USER_OP;
+ } else if (g_strcasecmp(value, "%") == 0) {
+ return IRC_CHANNEL_USER_HALFOP;
+ } else if (g_strcasecmp(value, "+") == 0) {
+ return IRC_CHANNEL_USER_VOICE;
+ } else {
+ return 0;
+ }
+}
+
+void irc_channel_update_ops(irc_channel_t *ic, char *ops, char *ops_mode)
+{
+ int mode = irc_channel_prefix_to_mode(ops_mode);
+
irc_channel_user_set_mode(ic, ic->irc->root,
- (strcmp(value, "both") == 0 ||
- strcmp(value, "root") == 0) ? IRC_CHANNEL_USER_OP : 0);
+ (strcmp(ops, "both") == 0 ||
+ strcmp(ops, "root") == 0) ? mode : 0);
irc_channel_user_set_mode(ic, ic->irc->user,
- (strcmp(value, "both") == 0 ||
- strcmp(value, "user") == 0) ? IRC_CHANNEL_USER_OP : 0);
+ (strcmp(ops, "both") == 0 ||
+ strcmp(ops, "user") == 0) ? mode : 0);
}
char *set_eval_irc_channel_ops(set_t *set, char *value)
@@ -700,12 +720,32 @@ char *set_eval_irc_channel_ops(set_t *set, char *value)
}
for (l = irc->channels; l; l = l->next) {
- irc_channel_update_ops(l->data, value);
+ irc_channel_update_ops(l->data, value, set_getstr(&irc->b->set, "ops_mode"));
}
return value;
}
+char *set_eval_irc_channel_ops_mode(set_t *set, char *value)
+{
+ irc_t *irc = set->data;
+ GSList *l;
+
+ if (g_strcasecmp(value, "~") != 0 &&
+ g_strcasecmp(value, "&") != 0 &&
+ g_strcasecmp(value, "@") != 0 &&
+ g_strcasecmp(value, "%") != 0 &&
+ g_strcasecmp(value, "+") != 0) {
+ return SET_INVALID;
+ }
+
+ for (l = irc->channels; l; l = l->next) {
+ irc_channel_update_ops(l->data, set_getstr(&irc->b->set, "ops"), value);
+ }
+
+ return 0;
+}
+
/* Channel-type dependent functions, for control channels: */
static gboolean control_channel_privmsg(irc_channel_t *ic, const char *msg)
{