From 52e6e17d3b3610afd6d6b997257b72e798d95c47 Mon Sep 17 00:00:00 2001 From: Sven Moritz Hallberg Date: Sun, 10 Feb 2008 14:36:43 +0100 Subject: Support halfops for 'notaway' status etc. --- irc.c | 1 + otr.c | 67 +++++++++++++++++++++++++++++++++++++----------------- protocols/nogaim.c | 4 ++++ set.c | 5 ++++ set.h | 1 + 5 files changed, 57 insertions(+), 21 deletions(-) diff --git a/irc.c b/irc.c index 279401d0..6205c631 100644 --- a/irc.c +++ b/irc.c @@ -112,6 +112,7 @@ irc_t *irc_new( int fd ) set_add( &irc->set, "default_target", "root", NULL, irc ); set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc ); set_add( &irc->set, "handle_unknown", "root", NULL, irc ); + set_add( &irc->set, "halfop_buddies", "false", set_eval_halfop_buddies, irc ); set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc ); set_add( &irc->set, "op_buddies", "false", set_eval_op_buddies, irc ); set_add( &irc->set, "op_root", "true", set_eval_op_root, irc ); diff --git a/otr.c b/otr.c index 60581ee6..ccb65887 100644 --- a/otr.c +++ b/otr.c @@ -981,31 +981,56 @@ const char *peernick(irc_t *irc, const char *handle, const char *protocol) int otr_update_modeflags(irc_t *irc, user_t *u) { - char *vo = set_getstr(&irc->set, "voice_buddies"); - char *oo = set_getstr(&irc->set, "op_buddies"); - char eflag=0, tflag=0; - int e = u->encrypted; - int t = (u->encrypted > 1); + char *vb = set_getstr(&irc->set, "voice_buddies"); + char *hb = set_getstr(&irc->set, "halfop_buddies"); + char *ob = set_getstr(&irc->set, "op_buddies"); + int encrypted = u->encrypted; + int trusted = u->encrypted > 1; + char flags[7]; + int nflags; + char *p = flags; + int i; - if(!strcmp(vo, "encrypted")) - eflag='v'; - else if(!strcmp(oo, "encrypted")) - eflag='o'; - if(!strcmp(vo, "trusted")) - tflag='v'; - else if(!strcmp(oo, "trusted")) - tflag='o'; + if(!strcmp(vb, "encrypted")) { + *(p++) = encrypted ? '+' : '-'; + *(p++) = 'v'; + nflags++; + } else if(!strcmp(vb, "trusted")) { + *(p++) = trusted ? '+' : '-'; + *(p++) = 'v'; + nflags++; + } + if(!strcmp(hb, "encrypted")) { + *(p++) = encrypted ? '+' : '-'; + *(p++) = 'h'; + nflags++; + } else if(!strcmp(hb, "trusted")) { + *(p++) = trusted ? '+' : '-'; + *(p++) = 'h'; + nflags++; + } + if(!strcmp(ob, "encrypted")) { + *(p++) = encrypted ? '+' : '-'; + *(p++) = 'o'; + nflags++; + } else if(!strcmp(ob, "trusted")) { + *(p++) = trusted ? '+' : '-'; + *(p++) = 'o'; + nflags++; + } + *p = '\0'; - if(!eflag) + p = g_malloc(nflags * (strlen(u->nick)+1) + 1); + *p = '\0'; + if(!p) return 0; - - if(tflag) { - irc_write( irc, ":%s!%s@%s MODE %s %c%c%c%c %s %s", irc->mynick, irc->mynick, irc->myhost, - irc->channel, e?'+':'-', eflag, t?'+':'-', tflag, u->nick, u->nick ); - } else { - irc_write( irc, ":%s!%s@%s MODE %s %c%c %s", irc->mynick, irc->mynick, irc->myhost, - irc->channel, e?'+':'-', eflag, u->nick ); + for(i=0; inick); } + irc_write( irc, ":%s!%s@%s MODE %s %s%s", irc->mynick, irc->mynick, irc->myhost, + irc->channel, flags, p ); + g_free(p); return 1; } diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 542a4269..c2966323 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -621,6 +621,10 @@ void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, u->away?'-':'+', u->nick ); } + if(!strcmp(set_getstr(&ic->irc->set, "halfop_buddies"), "notaway")) { + irc_write( ic->irc, ":%s MODE %s %ch %s", from, ic->irc->channel, + u->away?'-':'+', u->nick ); + } if(!strcmp(set_getstr(&ic->irc->set, "op_buddies"), "notaway")) { irc_write( ic->irc, ":%s MODE %s %co %s", from, ic->irc->channel, u->away?'-':'+', u->nick ); diff --git a/set.c b/set.c index fa1933d5..0e9ae5dc 100644 --- a/set.c +++ b/set.c @@ -344,6 +344,11 @@ char *set_eval_op_buddies( set_t *set, char *value ) return set_eval_mode_buddies(set, value, 'o'); } +char *set_eval_halfop_buddies( set_t *set, char *value ) +{ + return set_eval_mode_buddies(set, value, 'h'); +} + char *set_eval_voice_buddies( set_t *set, char *value ) { return set_eval_mode_buddies(set, value, 'v'); diff --git a/set.h b/set.h index b572cc2b..3e1b4f66 100644 --- a/set.h +++ b/set.h @@ -98,6 +98,7 @@ char *set_eval_to_char( set_t *set, char *value ); char *set_eval_op_root( set_t *set, char *value ); char *set_eval_op_user( set_t *set, char *value ); char *set_eval_op_buddies( set_t *set, char *value ); +char *set_eval_halfop_buddies( set_t *set, char *value ); char *set_eval_voice_buddies( set_t *set, char *value ); char *set_eval_charset( set_t *set, char *value ); -- cgit v1.2.3