diff options
| -rw-r--r-- | nick.c | 25 | ||||
| -rw-r--r-- | nick.h | 3 | ||||
| -rw-r--r-- | protocols/nogaim.c | 25 | 
3 files changed, 41 insertions, 12 deletions
| @@ -1,7 +1,7 @@    /********************************************************************\    * BitlBee -- An IRC to other IM-networks gateway                     *    *                                                                    * -  * Copyright 2002-2006 Wilmer van der Gaast and others                * +  * Copyright 2002-2007 Wilmer van der Gaast and others                *    \********************************************************************/  /* Some stuff to fetch, save and handle nicknames for your buddies      */ @@ -52,7 +52,7 @@ void nick_set( account_t *acc, const char *handle, const char *nick )  	g_hash_table_replace( acc->nicks, store_handle, store_nick );  } -char *nick_get( account_t *acc, const char *handle, const char *realname ) +char *nick_get( account_t *acc, const char *handle )  {  	static char nick[MAX_NICK_LENGTH+1];  	char *store_handle, *found_nick; @@ -76,12 +76,6 @@ char *nick_get( account_t *acc, const char *handle, const char *realname )  			while( *s )  				*(s++) = 0; -		/* All-digit handles (mainly ICQ UINs) aren't cool, try to -		   use the realname instead. */ -		for( s = nick; *s && isdigit( *s ); s ++ ); -		if( !*s && realname && *realname ) -			g_snprintf( nick, MAX_NICK_LENGTH, "%s", realname ); -		  		nick_strip( nick );  		if( set_getbool( &acc->irc->set, "lcnicks" ) )  			nick_lc( nick ); @@ -129,6 +123,19 @@ char *nick_get( account_t *acc, const char *handle, const char *realname )  	return nick;  } +/* Just check if there is a nickname set for this buddy or if we'd have to +   generate one. */ +int nick_saved( account_t *acc, const char *handle ) +{ +	char *store_handle, *found; +	 +	store_handle = clean_handle( handle ); +	found = g_hash_table_lookup( acc->nicks, store_handle ); +	g_free( store_handle ); +	 +	return found != NULL; +} +  void nick_del( account_t *acc, const char *handle )  {  	g_hash_table_remove( acc->nicks, handle ); @@ -175,7 +182,7 @@ int nick_ok( const char *nick )  int nick_lc( char *nick )  { -	static char tab[256] = { 0 }; +	static char tab[128] = { 0 };  	int i;  	if( tab['A'] == 0 ) @@ -24,7 +24,8 @@  */  void nick_set( account_t *acc, const char *handle, const char *nick ); -char *nick_get( account_t *acc, const char *handle, const char *realname ); +char *nick_get( account_t *acc, const char *handle ); +int nick_saved( account_t *acc, const char *handle );  void nick_del( account_t *acc, const char *handle );  void nick_strip( char *nick ); diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 02a1bf71..2fa6277e 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -371,7 +371,7 @@ void imcb_add_buddy( struct im_connection *ic, char *handle, char *group )  	}  	memset( nick, 0, MAX_NICK_LENGTH + 1 ); -	strcpy( nick, nick_get( ic->acc, handle, NULL ) ); +	strcpy( nick, nick_get( ic->acc, handle ) );  	u = user_add( ic->irc, nick ); @@ -425,10 +425,10 @@ struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )  	return( b );  } -  void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )  {  	user_t *u = user_findhandle( ic, handle ); +	char *s, newnick[MAX_NICK_LENGTH+1];  	if( !u || !realname ) return; @@ -440,6 +440,27 @@ void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )  		if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )  			imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); +		 +		if( !u->online && !nick_saved( ic->acc, handle ) ) +		{ +			/* Detect numeric handles: */ +			for( s = u->user; isdigit( *s ); s++ ); +			 +			if( *s == 0 ) +			{ +				/* If we reached the end of the string, it only contained numbers. +				   Seems to be an ICQ# then, so hopefully realname contains +				   something more useful. */ +				strcpy( newnick, realname ); +				 +				/* Some processing to make sure this string is a valid IRC nickname. */ +				nick_strip( newnick ); +				if( set_getbool( &ic->irc->set, "lcnicks" ) ) +					nick_lc( newnick ); +				 +				u->nick = g_strdup( newnick ); +			} +		}  	}  } | 
