Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • root_commands.c

    ra4d920b rba7d16f  
    3232#include <string.h>
    3333
    34 void root_command_string( irc_t *irc, char *command )
    35 {
    36         root_command( irc, split_command_parts( command ) );
     34void root_command_string( irc_t *irc, user_t *u, char *command, int flags )
     35{
     36        char *cmd[IRC_MAX_ARGS];
     37        char *s;
     38        int k;
     39        char q = 0;
     40       
     41        memset( cmd, 0, sizeof( cmd ) );
     42        cmd[0] = command;
     43        k = 1;
     44        for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
     45                if( *s == ' ' && !q )
     46                {
     47                        *s = 0;
     48                        while( *++s == ' ' );
     49                        if( *s == '"' || *s == '\'' )
     50                        {
     51                                q = *s;
     52                                s ++;
     53                        }
     54                        if( *s )
     55                        {
     56                                cmd[k++] = s;
     57                                s --;
     58                        }
     59                        else
     60                        {
     61                                break;
     62                        }
     63                }
     64                else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
     65                {
     66                        char *cpy;
     67                       
     68                        for( cpy = s; *cpy; cpy ++ )
     69                                cpy[0] = cpy[1];
     70                }
     71                else if( *s == q )
     72                {
     73                        q = *s = 0;
     74                }
     75        cmd[k] = NULL;
     76       
     77        root_command( irc, cmd );
    3778}
    3879
     
    5192void root_command( irc_t *irc, char *cmd[] )
    5293{       
    53         int i, len;
     94        int i;
    5495       
    5596        if( !cmd[0] )
    5697                return;
    5798       
    58         len = strlen( cmd[0] );
    5999        for( i = 0; commands[i].command; i++ )
    60                 if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 )
    61                 {
    62                         if( commands[i+1].command &&
    63                             g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 )
    64                                 /* Only match on the first letters if the match is unique. */
    65                                 break;
    66                        
     100                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
     101                {
    67102                        MIN_ARGS( commands[i].required_parameters );
    68103                       
     
    105140static void cmd_identify( irc_t *irc, char **cmd )
    106141{
    107         storage_status_t status;
     142        storage_status_t status = storage_load( irc, cmd[1] );
    108143        char *account_on[] = { "account", "on", NULL };
    109         gboolean load = TRUE;
    110         char *password = cmd[1];
    111        
    112         if( irc->status & USTATUS_IDENTIFIED )
     144       
     145        if( strchr( irc->umode, 'R' ) != NULL )
    113146        {
    114147                irc_usermsg( irc, "You're already logged in." );
    115148                return;
    116149        }
    117        
    118         if( strncmp( cmd[1], "-no", 3 ) == 0 )
    119         {
    120                 load = FALSE;
    121                 password = cmd[2];
    122         }
    123         else if( strncmp( cmd[1], "-force", 6 ) == 0 )
    124         {
    125                 password = cmd[2];
    126         }
    127         else if( irc->b->accounts != NULL )
    128         {
    129                 irc_usermsg( irc,
    130                              "You're trying to identify yourself, but already have "
    131                              "at least one IM account set up. "
    132                              "Use \x02identify -noload\x02 or \x02identify -force\x02 "
    133                              "instead (see \x02help identify\x02)." );
    134                 return;
    135         }
    136        
    137         if( password == NULL )
    138         {
    139                 MIN_ARGS( 2 );
    140         }
    141        
    142         if( load )
    143                 status = storage_load( irc, password );
    144         else
    145                 status = storage_check_pass( irc->user->nick, password );
    146150       
    147151        switch (status) {
     
    153157                break;
    154158        case STORAGE_OK:
    155                 irc_usermsg( irc, "Password accepted%s",
    156                              load ? ", settings and accounts loaded" : "" );
    157                 irc_setpass( irc, password );
     159                irc_usermsg( irc, "Password accepted, settings and accounts loaded" );
     160                irc_setpass( irc, cmd[1] );
    158161                irc->status |= USTATUS_IDENTIFIED;
    159162                irc_umode_set( irc, "+R", 1 );
    160                 if( load && set_getbool( &irc->b->set, "auto_connect" ) )
     163                if( set_getbool( &irc->set, "auto_connect" ) )
    161164                        cmd_account( irc, account_on );
    162165                break;
     
    198201        storage_status_t status;
    199202       
    200         status = storage_remove (irc->user->nick, cmd[1]);
     203        status = storage_remove (irc->nick, cmd[1]);
    201204        switch (status) {
    202205        case STORAGE_NO_SUCH_USER:
     
    210213                irc->status &= ~USTATUS_IDENTIFIED;
    211214                irc_umode_set( irc, "-R", 1 );
    212                 irc_usermsg( irc, "Account `%s' removed", irc->user->nick );
     215                irc_usermsg( irc, "Account `%s' removed", irc->nick );
    213216                break;
    214217        default:
     
    218221}
    219222
    220 static void cmd_save( irc_t *irc, char **cmd )
    221 {
    222         if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
    223                 irc_usermsg( irc, "Please create an account first" );
    224         else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
    225                 irc_usermsg( irc, "Configuration saved" );
    226         else
    227                 irc_usermsg( irc, "Configuration could not be saved!" );
     223struct cmd_account_del_data
     224{
     225        account_t *a;
     226        irc_t *irc;
     227};
     228
     229void cmd_account_del_yes( void *data )
     230{
     231        struct cmd_account_del_data *cad = data;
     232        account_t *a;
     233       
     234        for( a = cad->irc->accounts; a && a != cad->a; a = a->next );
     235       
     236        if( a == NULL )
     237        {
     238                irc_usermsg( cad->irc, "Account already deleted" );
     239        }
     240        else if( a->ic )
     241        {
     242                irc_usermsg( cad->irc, "Account is still logged in, can't delete" );
     243        }
     244        else
     245        {
     246                account_del( cad->irc, a );
     247                irc_usermsg( cad->irc, "Account deleted" );
     248        }
     249        g_free( data );
     250}
     251
     252void cmd_account_del_no( void *data )
     253{
     254        g_free( data );
    228255}
    229256
     
    258285                set_name = set_full;
    259286               
    260                 head = &irc->b->set;
     287                head = &irc->set;
    261288        }
    262289        else
     
    329356        account_t *a;
    330357       
    331         if( ( a = account_get( irc->b, id ) ) )
     358        if( ( a = account_get( irc, id ) ) )
    332359                return &a->set;
    333360        else
     
    377404                }
    378405
    379                 a = account_add( irc->b, prpl, cmd[3], cmd[4] );
     406                a = account_add( irc, prpl, cmd[3], cmd[4] );
    380407                if( cmd[5] )
    381408                {
     
    391418                MIN_ARGS( 2 );
    392419
    393                 if( !( a = account_get( irc->b, cmd[2] ) ) )
     420                if( !( a = account_get( irc, cmd[2] ) ) )
    394421                {
    395422                        irc_usermsg( irc, "Invalid account" );
     
    401428                else
    402429                {
    403                         account_del( irc->b, a );
    404                         irc_usermsg( irc, "Account deleted" );
     430                        struct cmd_account_del_data *cad;
     431                        char *msg;
     432                       
     433                        cad = g_malloc( sizeof( struct cmd_account_del_data ) );
     434                        cad->a = a;
     435                        cad->irc = irc;
     436                       
     437                        msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will "
     438                                               "also forget all your saved nicknames. If you want "
     439                                               "to change your username/password, use the `account "
     440                                               "set' command. Are you sure you want to delete this "
     441                                               "account?", a->prpl->name, a->user );
     442                        query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );
     443                        g_free( msg );
    405444                }
    406445        }
     
    412451                        irc_usermsg( irc, "Account list:" );
    413452               
    414                 for( a = irc->b->accounts; a; a = a->next )
     453                for( a = irc->accounts; a; a = a->next )
    415454                {
    416455                        char *con;
     
    435474                if( cmd[2] )
    436475                {
    437                         if( ( a = account_get( irc->b, cmd[2] ) ) )
     476                        if( ( a = account_get( irc, cmd[2] ) ) )
    438477                        {
    439478                                if( a->ic )
     
    444483                                else
    445484                                {
    446                                         account_on( irc->b, a );
     485                                        account_on( irc, a );
    447486                                }
    448487                        }
     
    455494                else
    456495                {
    457                         if ( irc->b->accounts )
    458                         {
     496                        if ( irc->accounts ) {
    459497                                irc_usermsg( irc, "Trying to get all accounts connected..." );
    460498                       
    461                                 for( a = irc->b->accounts; a; a = a->next )
     499                                for( a = irc->accounts; a; a = a->next )
    462500                                        if( !a->ic && a->auto_connect )
    463                                                 account_on( irc->b, a );
     501                                                account_on( irc, a );
    464502                        }
    465503                        else
     
    475513                        irc_usermsg( irc, "Deactivating all active (re)connections..." );
    476514                       
    477                         for( a = irc->b->accounts; a; a = a->next )
     515                        for( a = irc->accounts; a; a = a->next )
    478516                        {
    479517                                if( a->ic )
    480                                         account_off( irc->b, a );
     518                                        account_off( irc, a );
    481519                                else if( a->reconnect )
    482520                                        cancel_auto_reconnect( a );
    483521                        }
    484522                }
    485                 else if( ( a = account_get( irc->b, cmd[2] ) ) )
     523                else if( ( a = account_get( irc, cmd[2] ) ) )
    486524                {
    487525                        if( a->ic )
    488526                        {
    489                                 account_off( irc->b, a );
     527                                account_off( irc, a );
    490528                        }
    491529                        else if( a->reconnect )
     
    515553        {
    516554                irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] );
    517         }
    518 }
    519 
    520 static set_t **cmd_channel_set_findhead( irc_t *irc, char *id )
    521 {
    522         irc_channel_t *ic;
    523        
    524         if( ( ic = irc_channel_get( irc, id ) ) )
    525                 return &ic->set;
    526         else
    527                 return NULL;
    528 }
    529 
    530 static void cmd_channel( irc_t *irc, char **cmd )
    531 {
    532         if( g_strcasecmp( cmd[1], "set" ) == 0 )
    533         {
    534                 MIN_ARGS( 2 );
    535                
    536                 cmd_set_real( irc, cmd + 1, cmd_channel_set_findhead, NULL );
    537         }
    538         else if( g_strcasecmp( cmd[1], "list" ) == 0 )
    539         {
    540                 GSList *l;
    541                 int i = 0;
    542                
    543                 if( strchr( irc->umode, 'b' ) )
    544                         irc_usermsg( irc, "Channel list:" );
    545                
    546                 for( l = irc->channels; l; l = l->next )
    547                 {
    548                         irc_channel_t *ic = l->data;
    549                        
    550                         irc_usermsg( irc, "%2d. %s, %s channel%s", i, ic->name,
    551                                      set_getstr( &ic->set, "type" ),
    552                                      ic->flags & IRC_CHANNEL_JOINED ? " (joined)" : "" );
    553                        
    554                         i ++;
    555                 }
    556                 irc_usermsg( irc, "End of channel list" );
    557         }
    558         else if( g_strcasecmp( cmd[1], "del" ) == 0 )
    559         {
    560                 irc_channel_t *ic;
    561                
    562                 MIN_ARGS( 2 );
    563                
    564                 if( ( ic = irc_channel_get( irc, cmd[2] ) ) &&
    565                    !( ic->flags & IRC_CHANNEL_JOINED ) &&
    566                     ic != ic->irc->default_channel )
    567                 {
    568                         irc_usermsg( irc, "Channel %s deleted.", ic->name );
    569                         irc_channel_free( ic );
    570                 }
    571                 else
    572                         irc_usermsg( irc, "Couldn't remove channel (main channel %s or "
    573                                           "channels you're still in cannot be deleted).",
    574                                           ic->irc->default_channel->name );
    575         }
    576         else
    577         {
    578                 irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] );
    579555        }
    580556}
     
    592568        }
    593569       
    594         if( !( a = account_get( irc->b, cmd[1] ) ) )
     570        if( !( a = account_get( irc, cmd[1] ) ) )
    595571        {
    596572                irc_usermsg( irc, "Invalid account" );
     
    610586                        return;
    611587                }
    612                 else if( irc_user_by_name( irc, cmd[3] ) )
     588                else if( user_find( irc, cmd[3] ) )
    613589                {
    614590                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
     
    624600                a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL );
    625601        else
    626                 /* Only for add -tmp. For regular adds, this callback will
    627                    be called once the IM server confirms. */
    628                 bee_user_new( irc->b, a->ic, cmd[2], BEE_USER_LOCAL );
     602                /* Yeah, officially this is a call-*back*... So if we just
     603                   called add_buddy, we'll wait for the IM server to respond
     604                   before we do this. */
     605                imcb_add_buddy( a->ic, cmd[2], NULL );
    629606       
    630607        irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2]  );
    631 }
    632 
    633 static void cmd_remove( irc_t *irc, char **cmd )
    634 {
    635         irc_user_t *iu;
    636         bee_user_t *bu;
    637         char *s;
    638        
    639         if( !( iu = irc_user_by_name( irc, cmd[1] ) ) || !( bu = iu->bu ) )
    640         {
    641                 irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
    642                 return;
    643         }
    644         s = g_strdup( bu->handle );
    645        
    646         bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL );
    647         nick_del( bu->ic->acc, bu->handle );
    648         //TODO(wilmer): bee_user_free() and/or let the IM mod do it? irc_user_free( irc, cmd[1] );
    649        
    650         irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] );
    651         g_free( s );
    652        
    653         return;
    654608}
    655609
     
    661615        if( !cmd[2] )
    662616        {
    663                 irc_user_t *iu = irc_user_by_name( irc, cmd[1] );
    664                 if( !iu || !iu->bu )
     617                user_t *u = user_find( irc, cmd[1] );
     618                if( !u || !u->ic )
    665619                {
    666620                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    667621                        return;
    668622                }
    669                 ic = iu->bu->ic;
    670                 cmd[2] = iu->bu->handle;
    671         }
    672         else if( !( a = account_get( irc->b, cmd[1] ) ) )
     623                ic = u->ic;
     624                cmd[2] = u->handle;
     625        }
     626        else if( !( a = account_get( irc, cmd[1] ) ) )
    673627        {
    674628                irc_usermsg( irc, "Invalid account" );
     
    693647static void cmd_rename( irc_t *irc, char **cmd )
    694648{
    695         irc_user_t *iu;
    696        
    697         iu = irc_user_by_name( irc, cmd[1] );
    698        
    699         if( iu == NULL )
     649        user_t *u;
     650       
     651        if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
     652        {
     653                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
     654        }
     655        else if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
     656        {
     657                if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) )
     658                {
     659                        u = user_find( irc, irc->nick );
     660                       
     661                        irc_part( irc, u, irc->channel );
     662                        g_free( irc->channel );
     663                        irc->channel = g_strdup( cmd[2] );
     664                        irc_join( irc, u, irc->channel );
     665                       
     666                        if( strcmp( cmd[0], "set_rename" ) != 0 )
     667                                set_setstr( &irc->set, "control_channel", cmd[2] );
     668                }
     669        }
     670        else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
     671        {
     672                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
     673        }
     674        else if( !nick_ok( cmd[2] ) )
     675        {
     676                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
     677        }
     678        else if( !( u = user_find( irc, cmd[1] ) ) )
    700679        {
    701680                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    702681        }
    703         else if( iu == irc->user )
    704         {
    705                 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
    706         }
    707         else if( !nick_ok( cmd[2] ) )
    708         {
    709                 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
    710         }
    711         else if( irc_user_by_name( irc, cmd[2] ) )
    712         {
    713                 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
    714         }
    715         else
    716         {
    717                 if( !irc_user_set_nick( iu, cmd[2] ) )
    718                 {
    719                         irc_usermsg( irc, "Error while changing nick" );
    720                         return;
    721                 }
    722                
    723                 if( iu == irc->root )
    724                 {
     682        else
     683        {
     684                user_rename( irc, cmd[1], cmd[2] );
     685                irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
     686                if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
     687                {
     688                        g_free( irc->mynick );
     689                        irc->mynick = g_strdup( cmd[2] );
     690                       
    725691                        /* If we're called internally (user did "set root_nick"),
    726692                           let's not go O(INF). :-) */
    727693                        if( strcmp( cmd[0], "set_rename" ) != 0 )
    728                                 set_setstr( &irc->b->set, "root_nick", cmd[2] );
    729                 }
    730                 else if( iu->bu )
    731                 {
    732                         nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );
     694                                set_setstr( &irc->set, "root_nick", cmd[2] );
     695                }
     696                else if( u->send_handler == buddy_send_handler )
     697                {
     698                        nick_set( u->ic->acc, u->handle, cmd[2] );
    733699                }
    734700               
     
    741707        irc_t *irc = set->data;
    742708       
    743         if( strcmp( irc->root->nick, new_nick ) != 0 )
    744         {
    745                 char *cmd[] = { "set_rename", irc->root->nick, new_nick, NULL };
     709        if( strcmp( irc->mynick, new_nick ) != 0 )
     710        {
     711                char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL };
    746712               
    747713                cmd_rename( irc, cmd );
    748714        }
    749715       
    750         return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID;
     716        return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID;
     717}
     718
     719char *set_eval_control_channel( set_t *set, char *new_name )
     720{
     721        irc_t *irc = set->data;
     722       
     723        if( strcmp( irc->channel, new_name ) != 0 )
     724        {
     725                char *cmd[] = { "set_rename", irc->channel, new_name, NULL };
     726               
     727                cmd_rename( irc, cmd );
     728        }
     729       
     730        return strcmp( irc->channel, new_name ) == 0 ? new_name : SET_INVALID;
     731}
     732
     733static void cmd_remove( irc_t *irc, char **cmd )
     734{
     735        user_t *u;
     736        char *s;
     737       
     738        if( !( u = user_find( irc, cmd[1] ) ) || !u->ic )
     739        {
     740                irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
     741                return;
     742        }
     743        s = g_strdup( u->handle );
     744       
     745        u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL );
     746        nick_del( u->ic->acc, u->handle );
     747        user_del( irc, cmd[1] );
     748       
     749        irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] );
     750        g_free( s );
     751       
     752        return;
    751753}
    752754
     
    756758        account_t *a;
    757759       
    758         if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic )
     760        if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic )
    759761        {
    760762                char *format;
     
    769771                for( l = a->ic->deny; l; l = l->next )
    770772                {
    771                         bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data );
    772                         irc_user_t *iu = bu ? bu->ui_data : NULL;
    773                         irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" );
     773                        user_t *u = user_findhandle( a->ic, l->data );
     774                        irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
    774775                }
    775776                irc_usermsg( irc, "End of list." );
     
    779780        else if( !cmd[2] )
    780781        {
    781                 irc_user_t *iu = irc_user_by_name( irc, cmd[1] );
    782                 if( !iu || !iu->bu )
     782                user_t *u = user_find( irc, cmd[1] );
     783                if( !u || !u->ic )
    783784                {
    784785                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    785786                        return;
    786787                }
    787                 ic = iu->bu->ic;
    788                 cmd[2] = iu->bu->handle;
    789         }
    790         else if( !( a = account_get( irc->b, cmd[1] ) ) )
     788                ic = u->ic;
     789                cmd[2] = u->handle;
     790        }
     791        else if( !( a = account_get( irc, cmd[1] ) ) )
    791792        {
    792793                irc_usermsg( irc, "Invalid account" );
     
    816817        account_t *a;
    817818       
    818         if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic )
     819        if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic )
    819820        {
    820821                char *format;
     
    829830                for( l = a->ic->permit; l; l = l->next )
    830831                {
    831                         bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data );
    832                         irc_user_t *iu = bu ? bu->ui_data : NULL;
    833                         irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" );
     832                        user_t *u = user_findhandle( a->ic, l->data );
     833                        irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
    834834                }
    835835                irc_usermsg( irc, "End of list." );
     
    839839        else if( !cmd[2] )
    840840        {
    841                 irc_user_t *iu = irc_user_by_name( irc, cmd[1] );
    842                 if( !iu || !iu->bu )
     841                user_t *u = user_find( irc, cmd[1] );
     842                if( !u || !u->ic )
    843843                {
    844844                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    845845                        return;
    846846                }
    847                 ic = iu->bu->ic;
    848                 cmd[2] = iu->bu->handle;
    849         }
    850         else if( !( a = account_get( irc->b, cmd[1] ) ) )
     847                ic = u->ic;
     848                cmd[2] = u->handle;
     849        }
     850        else if( !( a = account_get( irc, cmd[1] ) ) )
    851851        {
    852852                irc_usermsg( irc, "Invalid account" );
     
    915915}
    916916
     917static void cmd_save( irc_t *irc, char **cmd )
     918{
     919        if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
     920                irc_usermsg( irc, "Please create an account first" );
     921        else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
     922                irc_usermsg( irc, "Configuration saved" );
     923        else
     924                irc_usermsg( irc, "Configuration could not be saved!" );
     925}
     926
    917927static void cmd_blist( irc_t *irc, char **cmd )
    918928{
    919929        int online = 0, away = 0, offline = 0;
    920         GSList *l;
     930        user_t *u;
    921931        char s[256];
    922932        char *format;
     
    939949                format = "%-16.16s  %-40.40s  %s";
    940950       
    941         irc_usermsg( irc, format, "Nick", "Handle/Account", "Status" );
    942        
    943         for( l = irc->users; l; l = l->next )
    944         {
    945                 irc_user_t *iu = l->data;
    946                 bee_user_t *bu = iu->bu;
    947                
    948                 if( !bu || ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE )
    949                         continue;
    950                
     951        irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" );
     952       
     953        for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away )
     954        {
    951955                if( online == 1 )
    952956                {
    953957                        char st[256] = "Online";
    954958                       
    955                         if( bu->status_msg )
    956                                 g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg );
    957                        
    958                         g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user );
    959                         irc_usermsg( irc, format, iu->nick, s, st );
     959                        if( u->status_msg )
     960                                g_snprintf( st, sizeof( st ) - 1, "Online (%s)", u->status_msg );
     961                       
     962                        g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user );
     963                        irc_usermsg( irc, format, u->nick, s, st );
    960964                }
    961965               
     
    963967        }
    964968
    965         for( l = irc->users; l; l = l->next )
    966         {
    967                 irc_user_t *iu = l->data;
    968                 bee_user_t *bu = iu->bu;
    969                
    970                 if( !bu || !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) )
    971                         continue;
    972                
     969        for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away )
     970        {
    973971                if( away == 1 )
    974972                {
    975                         g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user );
    976                         irc_usermsg( irc, format, iu->nick, s, irc_user_get_away( iu ) );
     973                        g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user );
     974                        irc_usermsg( irc, format, u->nick, s, u->away );
    977975                }
    978976                n_away ++;
    979977        }
    980978       
    981         for( l = irc->users; l; l = l->next )
    982         {
    983                 irc_user_t *iu = l->data;
    984                 bee_user_t *bu = iu->bu;
    985                
    986                 if( !bu || bu->flags & BEE_USER_ONLINE )
    987                         continue;
    988                
     979        for( u = irc->users; u; u = u->next ) if( u->ic && !u->online )
     980        {
    989981                if( offline == 1 )
    990982                {
    991                         g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user );
    992                         irc_usermsg( irc, format, iu->nick, s, "Offline" );
     983                        g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user );
     984                        irc_usermsg( irc, format, u->nick, s, "Offline" );
    993985                }
    994986                n_offline ++;
     
    996988       
    997989        irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
     990}
     991
     992static void cmd_nick( irc_t *irc, char **cmd )
     993{
     994        account_t *a;
     995
     996        if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
     997        {
     998                irc_usermsg( irc, "Invalid account");
     999        }
     1000        else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) )
     1001        {
     1002                irc_usermsg( irc, "That account is not on-line" );
     1003        }
     1004        else if ( !cmd[2] )
     1005        {
     1006                irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" );
     1007        }
     1008        else if ( !a->prpl->set_my_name )
     1009        {
     1010                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
     1011        }
     1012        else
     1013        {
     1014                irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
     1015               
     1016                a->prpl->set_my_name( a->ic, cmd[2] );
     1017        }
    9981018}
    9991019
     
    10181038}
    10191039
     1040static void cmd_join_chat( irc_t *irc, char **cmd )
     1041{
     1042        irc_usermsg( irc, "This command is now obsolete. "
     1043                          "Please try the `chat' command instead." );
     1044}
     1045
     1046static set_t **cmd_chat_set_findhead( irc_t *irc, char *id )
     1047{
     1048        struct chat *c;
     1049       
     1050        if( ( c = chat_get( irc, id ) ) )
     1051                return &c->set;
     1052        else
     1053                return NULL;
     1054}
     1055
    10201056static void cmd_chat( irc_t *irc, char **cmd )
    10211057{
    10221058        account_t *acc;
     1059        struct chat *c;
    10231060       
    10241061        if( g_strcasecmp( cmd[1], "add" ) == 0 )
    10251062        {
    10261063                char *channel, *s;
    1027                 struct irc_channel *ic;
    10281064               
    10291065                MIN_ARGS( 3 );
    10301066               
    1031                 if( !( acc = account_get( irc->b, cmd[2] ) ) )
     1067                if( !( acc = account_get( irc, cmd[2] ) ) )
    10321068                {
    10331069                        irc_usermsg( irc, "Invalid account" );
    1034                         return;
    1035                 }
    1036                 else if( !acc->prpl->chat_join )
    1037                 {
    1038                         irc_usermsg( irc, "Named chatrooms not supported on that account." );
    10391070                        return;
    10401071                }
     
    10531084                if( strchr( CTYPES, channel[0] ) == NULL )
    10541085                {
    1055                         s = g_strdup_printf( "#%s", channel );
     1086                        s = g_strdup_printf( "%c%s", CTYPES[0], channel );
    10561087                        g_free( channel );
    10571088                        channel = s;
    10581089                }
    10591090               
    1060                 if( ( ic = irc_channel_new( irc, channel ) ) &&
    1061                     set_setstr( &ic->set, "chat_type", "room" ) &&
    1062                     set_setstr( &ic->set, "account", cmd[2] ) &&
    1063                     set_setstr( &ic->set, "room", cmd[3] ) )
    1064                 {
    1065                         irc_usermsg( irc, "Chatroom successfully added." );
    1066                 }
    1067                 else
    1068                 {
    1069                         if( ic )
    1070                                 irc_channel_free( ic );
    1071                        
     1091                if( ( c = chat_add( irc, acc, cmd[3], channel ) ) )
     1092                        irc_usermsg( irc, "Chatroom added successfully." );
     1093                else
    10721094                        irc_usermsg( irc, "Could not add chatroom." );
     1095               
     1096                g_free( channel );
     1097        }
     1098        else if( g_strcasecmp( cmd[1], "list" ) == 0 )
     1099        {
     1100                int i = 0;
     1101               
     1102                if( strchr( irc->umode, 'b' ) )
     1103                        irc_usermsg( irc, "Chatroom list:" );
     1104               
     1105                for( c = irc->chatrooms; c; c = c->next )
     1106                {
     1107                        irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name,
     1108                                          c->acc->user, c->handle, c->channel );
     1109                       
     1110                        i ++;
     1111                }
     1112                irc_usermsg( irc, "End of chatroom list" );
     1113        }
     1114        else if( g_strcasecmp( cmd[1], "set" ) == 0 )
     1115        {
     1116                MIN_ARGS( 2 );
     1117               
     1118                cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead, NULL );
     1119        }
     1120        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
     1121        {
     1122                MIN_ARGS( 2 );
     1123               
     1124                if( ( c = chat_get( irc, cmd[2] ) ) )
     1125                {
     1126                        chat_del( irc, c );
     1127                }
     1128                else
     1129                {
     1130                        irc_usermsg( irc, "Could not remove chat." );
    10731131                }
    10741132        }
    10751133        else if( g_strcasecmp( cmd[1], "with" ) == 0 )
    10761134        {
    1077                 irc_user_t *iu;
     1135                user_t *u;
    10781136               
    10791137                MIN_ARGS( 2 );
    10801138               
    1081                 if( ( iu = irc_user_by_name( irc, cmd[2] ) ) &&
    1082                     iu->bu && iu->bu->ic->acc->prpl->chat_with )
    1083                 {
    1084                         if( !iu->bu->ic->acc->prpl->chat_with( iu->bu->ic, iu->bu->handle ) )
     1139                if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with )
     1140                {
     1141                        if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) )
    10851142                        {
    10861143                                irc_usermsg( irc, "(Possible) failure while trying to open "
    1087                                                   "a groupchat with %s.", iu->nick );
     1144                                                  "a groupchat with %s.", u->nick );
    10881145                        }
    10891146                }
     
    11471204                        {
    11481205                                irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name );
    1149                                 imcb_file_canceled( file->ic, file, "Denied by user" );
     1206                                imcb_file_canceled( file, "Denied by user" );
    11501207                        }
    11511208                        break;
     
    11541211                        {
    11551212                                irc_usermsg( irc, "Canceling file transfer for %s", file->file_name );
    1156                                 imcb_file_canceled( file->ic, file, "Canceled by user" );
     1213                                imcb_file_canceled( file, "Canceled by user" );
    11571214                        }
    11581215                        break;
     
    11611218}
    11621219
    1163 /* IMPORTANT: Keep this list sorted! The short command logic needs that. */
    11641220const command_t commands[] = {
     1221        { "help",           0, cmd_help,           0 },
     1222        { "identify",       1, cmd_identify,       0 },
     1223        { "register",       1, cmd_register,       0 },
     1224        { "drop",           1, cmd_drop,           0 },
    11651225        { "account",        1, cmd_account,        0 },
    11661226        { "add",            2, cmd_add,            0 },
     1227        { "info",           1, cmd_info,           0 },
     1228        { "rename",         2, cmd_rename,         0 },
     1229        { "remove",         1, cmd_remove,         0 },
     1230        { "block",          1, cmd_block,          0 },
    11671231        { "allow",          1, cmd_allow,          0 },
    1168         { "blist",          0, cmd_blist,          0 },
    1169         { "block",          1, cmd_block,          0 },
    1170         { "channel",        1, cmd_channel,        0 },
    1171         { "chat",           1, cmd_chat,           0 },
    1172         { "drop",           1, cmd_drop,           0 },
    1173         { "ft",             0, cmd_transfer,       0 },
    1174         { "help",           0, cmd_help,           0 },
    1175         { "identify",       1, cmd_identify,       0 },
    1176         { "info",           1, cmd_info,           0 },
    1177         { "no",             0, cmd_yesno,          0 },
    1178         { "qlist",          0, cmd_qlist,          0 },
    1179         { "register",       1, cmd_register,       0 },
    1180         { "remove",         1, cmd_remove,         0 },
    1181         { "rename",         2, cmd_rename,         0 },
    11821232        { "save",           0, cmd_save,           0 },
    11831233        { "set",            0, cmd_set,            0 },
     1234        { "yes",            0, cmd_yesno,          0 },
     1235        { "no",             0, cmd_yesno,          0 },
     1236        { "blist",          0, cmd_blist,          0 },
     1237        { "nick",           1, cmd_nick,           0 },
     1238        { "qlist",          0, cmd_qlist,          0 },
     1239        { "join_chat",      2, cmd_join_chat,      0 },
     1240        { "chat",           1, cmd_chat,           0 },
    11841241        { "transfer",       0, cmd_transfer,       0 },
    1185         { "yes",            0, cmd_yesno,          0 },
    11861242        { NULL }
    11871243};
Note: See TracChangeset for help on using the changeset viewer.