diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-07-29 20:18:54 +0200 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-07-29 20:18:54 +0200 | 
| commit | f7ca5877b69d452ef2e2ab4dc4d06743072deca0 (patch) | |
| tree | 6ce785e43326ef0b638105eaf4ccc2b1760bfc43 | |
| parent | 2fe5eb939ff77697b578bf45ba23cd99daee9c5f (diff) | |
Restore default_target setting, kill last_root_cmd variable and just use
the last_channel variable, like for any other user.
| -rw-r--r-- | irc.c | 17 | ||||
| -rw-r--r-- | irc.h | 5 | ||||
| -rw-r--r-- | irc_channel.c | 31 | ||||
| -rw-r--r-- | irc_im.c | 1 | ||||
| -rw-r--r-- | irc_send.c | 32 | ||||
| -rw-r--r-- | irc_user.c | 3 | ||||
| -rw-r--r-- | root_commands.c | 8 | 
7 files changed, 42 insertions, 55 deletions
| @@ -243,7 +243,6 @@ void irc_free( irc_t * irc )  	g_free( irc->sendbuffer );  	g_free( irc->readbuffer );  	g_free( irc->password ); -	g_free( irc->last_root_cmd );  	g_free( irc ); @@ -728,15 +727,15 @@ int irc_check_login( irc_t *irc )  			set_setstr( &ic->set, "auto_join", "true" );  			irc_channel_auto_joins( irc, NULL ); -			irc->last_root_cmd = g_strdup( ROOT_CHAN ); +			irc->root->last_channel = irc->default_channel; -			irc_send_msg( irc->root, "PRIVMSG", ROOT_CHAN, -			              "Welcome to the BitlBee gateway!\n\n" -			              "If you've never used BitlBee before, please do read the help " -			              "information using the \x02help\x02 command. Lots of FAQs are " -			              "answered there.\n" -			              "If you already have an account on this server, just use the " -			              "\x02identify\x02 command to identify yourself.", NULL ); +			irc_usermsg( irc, +			             "Welcome to the BitlBee gateway!\n\n" +			             "If you've never used BitlBee before, please do read the help " +			             "information using the \x02help\x02 command. Lots of FAQs are " +			             "answered there.\n" +			             "If you already have an account on this server, just use the " +			             "\x02identify\x02 command to identify yourself." );  			/* This is for bug #209 (use PASS to identify to NickServ). */  			if( irc->password != NULL ) @@ -66,10 +66,6 @@ typedef struct irc  	struct irc_user *root;  	struct irc_user *user; -	char *last_root_cmd; /* Either the nickname from which the last root -	                        msg came, or the last channel root was talked -	                        to. */ -  	char *password; /* HACK: Used to save the user's password, but before  	                   logging in, this may contain a password we should  	                   send to identify after USER/NICK are received. */ @@ -154,6 +150,7 @@ typedef struct irc_channel  	time_t topic_time;  	GSList *users; /* struct irc_channel_user */ +	struct irc_user *last_target;  	struct set *set;  	GString *pastebuf; /* Paste buffer (combine lines into a multiline msg). */ diff --git a/irc_channel.c b/irc_channel.c index 7d805014..dfb2161e 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -480,6 +480,7 @@ char *set_eval_irc_channel_ops( set_t *set, char *value )  static gboolean control_channel_privmsg( irc_channel_t *ic, const char *msg )  {  	irc_t *irc = ic->irc; +	irc_user_t *iu;  	const char *s;  	/* Scan for non-whitespace chars followed by a colon: */ @@ -488,33 +489,27 @@ static gboolean control_channel_privmsg( irc_channel_t *ic, const char *msg )  	if( *s == ':' || *s == ',' )  	{  		char to[s-msg+1]; -		irc_user_t *iu;  		memset( to, 0, sizeof( to ) );  		strncpy( to, msg, s - msg );  		while( *(++s) && isspace( *s ) ) {} +		msg = s; -		iu = irc_user_by_name( irc, to ); -		if( iu && iu->f->privmsg ) -		{ -			iu->last_channel = ic; -			iu->f->privmsg( iu, s ); -		} -		else -		{ +		if( !( iu = irc_user_by_name( irc, to ) ) )  			irc_channel_printf( ic, "User does not exist: %s", to ); -		} +		else +			ic->last_target = iu;  	} +	else if( g_strcasecmp( set_getstr( &irc->b->set, "default_target" ), "last" ) == 0 && +	         ic->last_target && g_slist_find( irc->users, ic->last_target ) ) +		iu = ic->last_target;  	else +		iu = irc->root; +	 +	if( iu && iu->f->privmsg )  	{ -		/* TODO: Maybe just use root->privmsg here now? */ -		char cmd[strlen(msg)+1]; -		 -		g_free( ic->irc->last_root_cmd ); -		ic->irc->last_root_cmd = g_strdup( ic->name ); -		 -		strcpy( cmd, msg ); -		root_command_string( ic->irc, cmd ); +		iu->last_channel = ic; +		iu->f->privmsg( iu, msg );  	}  	return TRUE; @@ -214,6 +214,7 @@ static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, t  	if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) )  		ts = irc_format_timestamp( irc, sent_at ); +	/* Too similar to irc_usermsg()... */  	if( iu->last_channel )  	{  		if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) @@ -103,33 +103,31 @@ void irc_send_motd( irc_t *irc )  void irc_usermsg( irc_t *irc, char *format, ... )  { -	irc_channel_t *ic; -	irc_user_t *iu; +	irc_channel_t *ic = NULL; +	irc_user_t *iu = irc->root;  	char text[1024];  	va_list params; +	char *dst;  	va_start( params, format );  	g_vsnprintf( text, sizeof( text ), format, params );  	va_end( params ); -	if( irc->last_root_cmd && -	    irc_channel_name_ok( irc->last_root_cmd ) &&  -	    ( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) && -	    ic->flags & IRC_CHANNEL_JOINED ) -		irc_send_msg( irc->root, "PRIVMSG", irc->last_root_cmd, text, NULL ); -	else if( irc->last_root_cmd && -	         ( iu = irc_user_by_name( irc, irc->last_root_cmd ) ) && -	         iu->f == &irc_user_root_funcs ) -		irc_send_msg( iu, "PRIVMSG", irc->user->nick, text, NULL ); -	else +	/* Too similar to bee_irc_user_msg()... */ +	if( iu->last_channel )  	{ -		g_free( irc->last_root_cmd ); -		irc->last_root_cmd = NULL; -		 -		irc_send_msg( irc->root, "PRIVMSG", irc->user->nick, text, NULL ); +		if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) +			ic = iu->last_channel; +		else if( irc->default_channel->flags & IRC_CHANNEL_JOINED ) +			ic = irc->default_channel;  	} -	/*return( irc_msgfrom( irc, u->nick, text ) );*/ +	if( ic ) +		dst = ic->name; +	else +		dst = irc->user->nick; +	 +	irc_send_msg( irc->root, "PRIVMSG", dst, text, NULL );  }  void irc_send_join( irc_channel_t *ic, irc_user_t *iu ) @@ -221,9 +221,6 @@ static gboolean root_privmsg( irc_user_t *iu, const char *msg )  {  	char cmd[strlen(msg)+1]; -	g_free( iu->irc->last_root_cmd ); -	iu->irc->last_root_cmd = g_strdup( iu->nick ); -	  	strcpy( cmd, msg );  	root_command_string( iu->irc, cmd ); diff --git a/root_commands.c b/root_commands.c index 69aa3e98..fe445d26 100644 --- a/root_commands.c +++ b/root_commands.c @@ -559,9 +559,9 @@ static void cmd_channel( irc_t *irc, char **cmd )  	{  		/* If this doesn't match any channel, maybe this is the short  		   syntax (only works when used inside a channel). */ -		if( ( len = strlen( cmd[1] ) ) && -		    g_strncasecmp( cmd[1], "set", len ) == 0 && -		    ( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) ) +		if( ( ic = irc->root->last_channel ) && +		    ( len = strlen( cmd[1] ) ) && +		    g_strncasecmp( cmd[1], "set", len ) == 0 )  			cmd_set_real( irc, cmd + 1, &ic->set, NULL );  		else  			irc_usermsg( irc, "Could not find channel `%s'", cmd[1] ); @@ -641,7 +641,7 @@ static void cmd_add( irc_t *irc, char **cmd )  		irc_channel_t *ic;  		char *s, *group = NULL;; -		if( ( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) && +		if( ( ic = irc->root->last_channel ) &&  		    ( s = set_getstr( &ic->set, "fill_by" ) ) &&  		    strcmp( s, "group" ) == 0 &&  		    ( group = set_getstr( &ic->set, "group" ) ) ) | 
