diff options
-rw-r--r-- | irc.c | 6 | ||||
-rw-r--r-- | irc.h | 2 | ||||
-rw-r--r-- | irc_channel.c | 32 |
3 files changed, 31 insertions, 9 deletions
@@ -106,7 +106,7 @@ irc_t *irc_new( int fd ) s = set_add( &b->set, "display_timestamps", "true", set_eval_bool, irc ); s = set_add( &b->set, "handle_unknown", "add_channel", NULL, irc ); s = set_add( &b->set, "lcnicks", "true", set_eval_bool, irc ); - s = set_add( &b->set, "ops", "both", NULL/*set_eval_ops*/, irc ); + s = set_add( &b->set, "ops", "both", set_eval_irc_channel_ops, 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 ); @@ -662,10 +662,6 @@ int irc_check_login( irc_t *irc ) irc_channel_set_topic( ic, CONTROL_TOPIC, irc->root ); irc_channel_add_user( ic, irc->user ); - if( strcmp( set_getstr( &irc->b->set, "ops" ), "both" ) == 0 || - strcmp( set_getstr( &irc->b->set, "ops" ), "user" ) == 0 ) - irc_channel_user_set_mode( ic, irc->user, IRC_CHANNEL_USER_OP ); - irc->last_root_cmd = g_strdup( ROOT_CHAN ); irc_send_msg( irc->root, "PRIVMSG", ROOT_CHAN, @@ -228,6 +228,8 @@ int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_ void irc_channel_user_set_mode( irc_channel_t *ic, irc_user_t *iu, irc_channel_user_flags_t flags ); void irc_channel_printf( irc_channel_t *ic, char *format, ... ); gboolean irc_channel_name_ok( const char *name ); +void irc_channel_update_ops( irc_channel_t *ic, char *value ); +char *set_eval_irc_channel_ops( struct set *set, char *value ); /* irc_commands.c */ void irc_exec( irc_t *irc, char **cmd ); diff --git a/irc_channel.c b/irc_channel.c index 8abc0486..d98d0652 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -44,9 +44,6 @@ irc_channel_t *irc_channel_new( irc_t *irc, const char *name ) strcpy( ic->mode, CMODE ); irc_channel_add_user( ic, irc->root ); - if( strcmp( set_getstr( &irc->b->set, "ops" ), "both" ) == 0 || - strcmp( set_getstr( &irc->b->set, "ops" ), "root" ) == 0 ) - irc_channel_user_set_mode( ic, irc->root, IRC_CHANNEL_USER_OP ); irc->channels = g_slist_append( irc->channels, ic ); @@ -172,6 +169,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" ) ); + if( iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED ) { ic->flags |= IRC_CHANNEL_JOINED; @@ -238,7 +237,7 @@ void irc_channel_user_set_mode( irc_channel_t *ic, irc_user_t *iu, irc_channel_u { irc_channel_user_t *icu = irc_channel_has_user( ic, iu ); - if( icu->flags == flags ) + if( !icu || icu->flags == flags ) return; if( ic->flags & IRC_CHANNEL_JOINED ) @@ -283,6 +282,31 @@ 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 ) +{ + irc_channel_user_set_mode( ic, ic->irc->root, + ( strcmp( value, "both" ) == 0 || + strcmp( value, "root" ) == 0 ) ? IRC_CHANNEL_USER_OP : 0 ); + irc_channel_user_set_mode( ic, ic->irc->user, + ( strcmp( value, "both" ) == 0 || + strcmp( value, "user" ) == 0 ) ? IRC_CHANNEL_USER_OP : 0 ); +} + +char *set_eval_irc_channel_ops( set_t *set, char *value ) +{ + irc_t *irc = set->data; + GSList *l; + + if( strcmp( value, "both" ) != 0 && strcmp( value, "none" ) != 0 && + strcmp( value, "user" ) != 0 && strcmp( value, "root" ) != 0 ) + return SET_INVALID; + + for( l = irc->channels; l; l = l->next ) + irc_channel_update_ops( l->data, value ); + + return value; +} + /* Channel-type dependent functions, for control channels: */ static gboolean control_channel_privmsg( irc_channel_t *ic, const char *msg ) { |