diff options
| -rw-r--r-- | irc.c | 3 | ||||
| -rw-r--r-- | irc.h | 1 | ||||
| -rw-r--r-- | irc_channel.c | 49 | ||||
| -rw-r--r-- | root_commands.c | 1 | 
4 files changed, 52 insertions, 2 deletions
| @@ -652,7 +652,8 @@ int irc_check_login( irc_t *irc )  			ic = irc->default_channel = irc_channel_new( irc, ROOT_CHAN );  			irc_channel_set_topic( ic, CONTROL_TOPIC, irc->root ); -			irc_channel_add_user( ic, irc->user ); +			set_setstr( &ic->set, "auto_join", "true" ); +			irc_channel_auto_joins( irc, NULL );  			irc->last_root_cmd = g_strdup( ROOT_CHAN ); @@ -236,6 +236,7 @@ int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu, gboolean silent, co  irc_channel_user_t *irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu );  int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who );  void irc_channel_user_set_mode( irc_channel_t *ic, irc_user_t *iu, irc_channel_user_flags_t flags ); +void irc_channel_auto_joins( irc_t *irc, struct account *acc );  void irc_channel_printf( irc_channel_t *ic, char *format, ... );  gboolean irc_channel_name_ok( const char *name );  void irc_channel_name_strip( char *name ); diff --git a/irc_channel.c b/irc_channel.c index ffcfbffb..4aec9077 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -47,6 +47,7 @@ irc_channel_t *irc_channel_new( irc_t *irc, const char *name )  	irc->channels = g_slist_append( irc->channels, ic ); +	set_add( &ic->set, "auto_join", "false", set_eval_bool, ic );  	set_add( &ic->set, "type", "control", set_eval_channel_type, ic );  	if( name[0] == '&' ) @@ -308,6 +309,45 @@ void irc_channel_user_set_mode( irc_channel_t *ic, irc_user_t *iu, irc_channel_u  	icu->flags = flags;  } +void irc_channel_auto_joins( irc_t *irc, account_t *acc ) +{ +	GSList *l; +	 +	for( l = irc->channels; l; l = l->next ) +	{ +		irc_channel_t *ic = l->data; +		gboolean aj = set_getbool( &ic->set, "auto_join" ); +		char *type; +		 +		if( acc && +		    ( type = set_getstr( &ic->set, "chat_type" ) ) && +		    strcmp( type, "room" ) == 0 ) +		{ +			/* Bit of an ugly special case: Handle chatrooms here, we +			   can only auto-join them if their account is online. */ +			char *acc_s; +			 +			if( !aj && !( ic->flags & IRC_CHANNEL_JOINED ) ) +				/* Only continue if this one's marked as auto_join +				   or if we're in it already. (Possible if the +				   client auto-rejoined it before identyfing.) */ +				continue; +			else if( !( acc_s = set_getstr( &ic->set, "account" ) ) ) +				continue; +			else if( account_get( irc->b, acc_s ) != acc ) +				continue; +			else if( acc->ic == NULL || !( acc->ic->flags & OPT_LOGGED_IN ) ) +				continue; +			else +				ic->f->join( ic ); +		} +		else if( aj ) +		{ +			irc_channel_add_user( ic, irc->user ); +		} +	} +} +  void irc_channel_printf( irc_channel_t *ic, char *format, ... )  {  	va_list params; @@ -524,6 +564,13 @@ static gboolean control_channel_init( irc_channel_t *ic )  	return TRUE;  } +static gboolean control_channel_join( irc_channel_t *ic ) +{ +	bee_irc_channel_update( ic->irc, ic, NULL ); +	 +	return TRUE; +} +  static char *set_eval_by_account( set_t *set, char *value )  {  	struct irc_channel *ic = set->data; @@ -607,7 +654,7 @@ static gboolean control_channel_free( irc_channel_t *ic )  static const struct irc_channel_funcs control_channel_funcs = {  	control_channel_privmsg, -	NULL, +	control_channel_join,  	NULL,  	NULL,  	control_channel_invite, diff --git a/root_commands.c b/root_commands.c index 127570e6..62fe1e79 100644 --- a/root_commands.c +++ b/root_commands.c @@ -156,6 +156,7 @@ static void cmd_identify( irc_t *irc, char **cmd )  		irc_setpass( irc, password );  		irc->status |= USTATUS_IDENTIFIED;  		irc_umode_set( irc, "+R", 1 ); +		irc_channel_auto_joins( irc, NULL );  		if( load && set_getbool( &irc->b->set, "auto_connect" ) )  			cmd_account( irc, account_on );  		break; | 
