aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2015-11-06 20:30:06 +0100
committerMarius Halden <marius.h@lden.org>2015-11-06 20:30:06 +0100
commite41887d0505123fef792e47a9f7f1d5fdccc22c7 (patch)
tree23374f56a3e05dfa0ed128eb7872dd23e6ad513d
parentff37678cc076af9590f0e9ef427445f3b3bfa65f (diff)
Add support for different modes for user/root
-rw-r--r--doc/user-guide/commands.xml11
-rw-r--r--irc.c1
-rw-r--r--irc.h3
-rw-r--r--irc_channel.c58
4 files changed, 65 insertions, 8 deletions
diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml
index 0de4dfcf..1060962e 100644
--- a/doc/user-guide/commands.xml
+++ b/doc/user-guide/commands.xml
@@ -1680,6 +1680,17 @@
</description>
</bitlbee-setting>
+ <bitlbee-setting name="ops_mode" type="string" scope="global">
+ <default>@</default>
+ <possible-values>~, &amp;, @, %, +</possible-values>
+
+ <description>
+ <para>
+ Use the specified mode for root/user.
+ </para>
+ </description>
+ </bitlbee-setting>
+
<bitlbee-command name="rename">
<short-description>Rename (renick) a buddy</short-description>
<syntax>rename &lt;oldnick&gt; &lt;newnick&gt;</syntax>
diff --git a/irc.c b/irc.c
index 6b3fa737..9088cc16 100644
--- a/irc.c
+++ b/irc.c
@@ -116,6 +116,7 @@ irc_t *irc_new(int fd)
s = set_add(&b->set, "nick_format", "%-@nick", NULL, irc);
s = set_add(&b->set, "offline_user_quits", "true", set_eval_bool, irc);
s = set_add(&b->set, "ops", "both", set_eval_irc_channel_ops, irc);
+ s = set_add(&b->set, "ops_mode", "@", set_eval_irc_channel_ops_mode, irc);
s = set_add(&b->set, "paste_buffer", "false", set_eval_bool, irc);
s->old_key = g_strdup("buddy_sendbuffer");
s = set_add(&b->set, "paste_buffer_delay", "200", set_eval_int, irc);
diff --git a/irc.h b/irc.h
index 02b307df..d29c8d85 100644
--- a/irc.h
+++ b/irc.h
@@ -302,8 +302,9 @@ void irc_channel_name_strip(char *name);
int irc_channel_name_cmp(const char *a_, const char *b_);
char *irc_channel_name_gen(irc_t *irc, const char *name);
gboolean irc_channel_name_hint(irc_channel_t *ic, const char *name);
-void irc_channel_update_ops(irc_channel_t *ic, char *value);
+void irc_channel_update_ops(irc_channel_t *ic, char *ops, char *ops_mode);
char *set_eval_irc_channel_ops(struct set *set, char *value);
+char *set_eval_irc_channel_ops_mode(struct set *set, char *value);
gboolean irc_channel_wants_user(irc_channel_t *ic, irc_user_t *iu);
/* irc_commands.c */
diff --git a/irc_channel.c b/irc_channel.c
index acae85a7..04eb0c4f 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -239,7 +239,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);
- 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) {
ic->flags |= IRC_CHANNEL_JOINED;
@@ -642,14 +643,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)
@@ -663,7 +683,27 @@ 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 value;
@@ -887,6 +927,10 @@ static char *set_eval_show_users(set_t *set, char *value)
modechar = IRC_CHANNEL_USER_HALFOP;
} else if (last == '@') {
modechar = IRC_CHANNEL_USER_OP;
+ } else if (last == '&') {
+ modechar = IRC_CHANNEL_USER_ADMIN;
+ } else if (last == '~') {
+ modechar = IRC_CHANNEL_USER_OWNER;
}
if (strncmp(*part, "offline", 7) == 0) {