diff options
| -rw-r--r-- | irc.h | 2 | ||||
| -rw-r--r-- | irc_channel.c | 2 | ||||
| -rw-r--r-- | irc_user.c | 6 | ||||
| -rw-r--r-- | root_commands.c | 54 | 
4 files changed, 28 insertions, 36 deletions
| @@ -204,7 +204,7 @@ void irc_send_nick( irc_user_t *iu, const char *new );  irc_user_t *irc_user_new( irc_t *irc, const char *nick );  int irc_user_free( irc_t *irc, const char *nick );  irc_user_t *irc_user_by_name( irc_t *irc, const char *nick ); -int irc_user_set_nick( irc_t *irc, const char *old, const char *new ); +int irc_user_set_nick( irc_user_t *iu, const char *new );  gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );  #endif diff --git a/irc_channel.c b/irc_channel.c index 27216f3c..27f33619 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -81,7 +81,7 @@ int irc_channel_free( irc_channel_t *ic )  int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )  { -	if( !irc_channel_has_user( ic, iu ) ) +	if( irc_channel_has_user( ic, iu ) )  		return 0;  	ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp ); @@ -82,9 +82,9 @@ irc_user_t *irc_user_by_name( irc_t *irc, const char *nick )  		return NULL;  } -int irc_user_set_nick( irc_t *irc, const char *old, const char *new ) +int irc_user_set_nick( irc_user_t *iu, const char *new )  { -	irc_user_t *iu = irc_user_by_name( irc, old ); +	irc_t *irc = iu->irc;  	char key[strlen(new)+1];  	GSList *cl; @@ -99,7 +99,7 @@ int irc_user_set_nick( irc_t *irc, const char *old, const char *new )  		/* Send a NICK update if we're renaming our user, or someone  		   who's in the same channel like our user. */  		if( iu == irc->user || -		    ( irc_channel_has_user( ic, irc->user ) && +		    ( ( ic->flags & IRC_CHANNEL_JOINED ) &&  		      irc_channel_has_user( ic, iu ) ) )  		{  			irc_send_nick( iu, new ); diff --git a/root_commands.c b/root_commands.c index 75f3af81..7e0b16d3 100644 --- a/root_commands.c +++ b/root_commands.c @@ -647,65 +647,55 @@ static void cmd_info( irc_t *irc, char **cmd )  		ic->acc->prpl->get_info( ic, cmd[2] );  	}  } +#endif  static void cmd_rename( irc_t *irc, char **cmd )  { -	user_t *u; +	irc_user_t *iu; -	if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) -	{ -		irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); -	} -	else if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) +	iu = irc_user_by_name( irc, cmd[1] ); +	 +	if( iu == NULL )  	{ -		if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) ) -		{ -			u = user_find( irc, irc->nick ); -			 -			irc_part( irc, u, irc->channel ); -			g_free( irc->channel ); -			irc->channel = g_strdup( cmd[2] ); -			irc_join( irc, u, irc->channel ); -			 -			if( strcmp( cmd[0], "set_rename" ) != 0 ) -				set_setstr( &irc->set, "control_channel", cmd[2] ); -		} +		irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );  	} -	else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) +	else if( iu == irc->user )  	{ -		irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); +		irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );  	}  	else if( !nick_ok( cmd[2] ) )  	{  		irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );  	} -	else if( !( u = user_find( irc, cmd[1] ) ) ) +	else if( irc_user_by_name( irc, cmd[2] ) )  	{ -		irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); +		irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );  	}  	else  	{ -		user_rename( irc, cmd[1], cmd[2] ); -		irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); -		if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) +		if( !irc_user_set_nick( iu, cmd[2] ) ) +		{ +			irc_usermsg( irc, "Error while changing nick" ); +			return; +		} +		 +		if( iu == irc->root )  		{ -			g_free( irc->mynick ); -			irc->mynick = g_strdup( cmd[2] ); -			  			/* If we're called internally (user did "set root_nick"),  			   let's not go O(INF). :-) */  			if( strcmp( cmd[0], "set_rename" ) != 0 ) -				set_setstr( &irc->set, "root_nick", cmd[2] ); +				set_setstr( &irc->b->set, "root_nick", cmd[2] );  		} -		else if( u->send_handler == buddy_send_handler ) +		else if( iu->bu )  		{ -			nick_set( u->ic->acc, u->handle, cmd[2] ); +			nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );  		}  		irc_usermsg( irc, "Nick successfully changed" );  	}  } +#if 0  char *set_eval_root_nick( set_t *set, char *new_nick )  {  	irc_t *irc = set->data; @@ -1231,7 +1221,9 @@ const command_t commands[] = {  	{ "drop",           1, cmd_drop,           0 },  	{ "add",            2, cmd_add,            0 },  	{ "info",           1, cmd_info,           0 }, +#endif  	{ "rename",         2, cmd_rename,         0 }, +#if 0  	{ "remove",         1, cmd_remove,         0 },  	{ "block",          1, cmd_block,          0 },  	{ "allow",          1, cmd_allow,          0 }, | 
