Changeset 57c96f7


Ignore:
Timestamp:
2010-04-05T01:00:02Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1f92a58
Parents:
0b5cc72
Message:

Restored the rename command.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • irc.h

    r0b5cc72 r57c96f7  
    205205int irc_user_free( irc_t *irc, const char *nick );
    206206irc_user_t *irc_user_by_name( irc_t *irc, const char *nick );
    207 int irc_user_set_nick( irc_t *irc, const char *old, const char *new );
     207int irc_user_set_nick( irc_user_t *iu, const char *new );
    208208gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );
    209209
  • irc_channel.c

    r0b5cc72 r57c96f7  
    8282int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
    8383{
    84         if( !irc_channel_has_user( ic, iu ) )
     84        if( irc_channel_has_user( ic, iu ) )
    8585                return 0;
    8686       
  • irc_user.c

    r0b5cc72 r57c96f7  
    8383}
    8484
    85 int irc_user_set_nick( irc_t *irc, const char *old, const char *new )
     85int irc_user_set_nick( irc_user_t *iu, const char *new )
    8686{
    87         irc_user_t *iu = irc_user_by_name( irc, old );
     87        irc_t *irc = iu->irc;
    8888        char key[strlen(new)+1];
    8989        GSList *cl;
     
    100100                   who's in the same channel like our user. */
    101101                if( iu == irc->user ||
    102                     ( irc_channel_has_user( ic, irc->user ) &&
     102                    ( ( ic->flags & IRC_CHANNEL_JOINED ) &&
    103103                      irc_channel_has_user( ic, iu ) ) )
    104104                {
  • root_commands.c

    r0b5cc72 r57c96f7  
    648648        }
    649649}
     650#endif
    650651
    651652static void cmd_rename( irc_t *irc, char **cmd )
    652653{
    653         user_t *u;
    654        
    655         if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
     654        irc_user_t *iu;
     655       
     656        iu = irc_user_by_name( irc, cmd[1] );
     657       
     658        if( iu == NULL )
     659        {
     660                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
     661        }
     662        else if( iu == irc->user )
    656663        {
    657664                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
    658665        }
    659         else if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
    660         {
    661                 if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) )
    662                 {
    663                         u = user_find( irc, irc->nick );
    664                        
    665                         irc_part( irc, u, irc->channel );
    666                         g_free( irc->channel );
    667                         irc->channel = g_strdup( cmd[2] );
    668                         irc_join( irc, u, irc->channel );
    669                        
    670                         if( strcmp( cmd[0], "set_rename" ) != 0 )
    671                                 set_setstr( &irc->set, "control_channel", cmd[2] );
    672                 }
    673         }
    674         else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
     666        else if( !nick_ok( cmd[2] ) )
     667        {
     668                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
     669        }
     670        else if( irc_user_by_name( irc, cmd[2] ) )
    675671        {
    676672                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
    677673        }
    678         else if( !nick_ok( cmd[2] ) )
    679         {
    680                 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
    681         }
    682         else if( !( u = user_find( irc, cmd[1] ) ) )
    683         {
    684                 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    685         }
    686         else
    687         {
    688                 user_rename( irc, cmd[1], cmd[2] );
    689                 irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
    690                 if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
    691                 {
    692                         g_free( irc->mynick );
    693                         irc->mynick = g_strdup( cmd[2] );
    694                        
     674        else
     675        {
     676                if( !irc_user_set_nick( iu, cmd[2] ) )
     677                {
     678                        irc_usermsg( irc, "Error while changing nick" );
     679                        return;
     680                }
     681               
     682                if( iu == irc->root )
     683                {
    695684                        /* If we're called internally (user did "set root_nick"),
    696685                           let's not go O(INF). :-) */
    697686                        if( strcmp( cmd[0], "set_rename" ) != 0 )
    698                                 set_setstr( &irc->set, "root_nick", cmd[2] );
    699                 }
    700                 else if( u->send_handler == buddy_send_handler )
    701                 {
    702                         nick_set( u->ic->acc, u->handle, cmd[2] );
     687                                set_setstr( &irc->b->set, "root_nick", cmd[2] );
     688                }
     689                else if( iu->bu )
     690                {
     691                        nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );
    703692                }
    704693               
     
    707696}
    708697
     698#if 0
    709699char *set_eval_root_nick( set_t *set, char *new_nick )
    710700{
     
    12321222        { "add",            2, cmd_add,            0 },
    12331223        { "info",           1, cmd_info,           0 },
     1224#endif
    12341225        { "rename",         2, cmd_rename,         0 },
     1226#if 0
    12351227        { "remove",         1, cmd_remove,         0 },
    12361228        { "block",          1, cmd_block,          0 },
Note: See TracChangeset for help on using the changeset viewer.