Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • root_commands.c

    rba7d16f ra4d920b  
    3232#include <string.h>
    3333
    34 void 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 );
     34void root_command_string( irc_t *irc, char *command )
     35{
     36        root_command( irc, split_command_parts( command ) );
    7837}
    7938
     
    9251void root_command( irc_t *irc, char *cmd[] )
    9352{       
    94         int i;
     53        int i, len;
    9554       
    9655        if( !cmd[0] )
    9756                return;
    9857       
     58        len = strlen( cmd[0] );
    9959        for( i = 0; commands[i].command; i++ )
    100                 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
    101                 {
     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                       
    10267                        MIN_ARGS( commands[i].required_parameters );
    10368                       
     
    140105static void cmd_identify( irc_t *irc, char **cmd )
    141106{
    142         storage_status_t status = storage_load( irc, cmd[1] );
     107        storage_status_t status;
    143108        char *account_on[] = { "account", "on", NULL };
    144        
    145         if( strchr( irc->umode, 'R' ) != NULL )
     109        gboolean load = TRUE;
     110        char *password = cmd[1];
     111       
     112        if( irc->status & USTATUS_IDENTIFIED )
    146113        {
    147114                irc_usermsg( irc, "You're already logged in." );
    148115                return;
    149116        }
     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 );
    150146       
    151147        switch (status) {
     
    157153                break;
    158154        case STORAGE_OK:
    159                 irc_usermsg( irc, "Password accepted, settings and accounts loaded" );
    160                 irc_setpass( irc, cmd[1] );
     155                irc_usermsg( irc, "Password accepted%s",
     156                             load ? ", settings and accounts loaded" : "" );
     157                irc_setpass( irc, password );
    161158                irc->status |= USTATUS_IDENTIFIED;
    162159                irc_umode_set( irc, "+R", 1 );
    163                 if( set_getbool( &irc->set, "auto_connect" ) )
     160                if( load && set_getbool( &irc->b->set, "auto_connect" ) )
    164161                        cmd_account( irc, account_on );
    165162                break;
     
    201198        storage_status_t status;
    202199       
    203         status = storage_remove (irc->nick, cmd[1]);
     200        status = storage_remove (irc->user->nick, cmd[1]);
    204201        switch (status) {
    205202        case STORAGE_NO_SUCH_USER:
     
    213210                irc->status &= ~USTATUS_IDENTIFIED;
    214211                irc_umode_set( irc, "-R", 1 );
    215                 irc_usermsg( irc, "Account `%s' removed", irc->nick );
     212                irc_usermsg( irc, "Account `%s' removed", irc->user->nick );
    216213                break;
    217214        default:
     
    221218}
    222219
    223 struct cmd_account_del_data
    224 {
    225         account_t *a;
    226         irc_t *irc;
    227 };
    228 
    229 void 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 
    252 void cmd_account_del_no( void *data )
    253 {
    254         g_free( data );
     220static 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!" );
    255228}
    256229
     
    285258                set_name = set_full;
    286259               
    287                 head = &irc->set;
     260                head = &irc->b->set;
    288261        }
    289262        else
     
    356329        account_t *a;
    357330       
    358         if( ( a = account_get( irc, id ) ) )
     331        if( ( a = account_get( irc->b, id ) ) )
    359332                return &a->set;
    360333        else
     
    404377                }
    405378
    406                 a = account_add( irc, prpl, cmd[3], cmd[4] );
     379                a = account_add( irc->b, prpl, cmd[3], cmd[4] );
    407380                if( cmd[5] )
    408381                {
     
    418391                MIN_ARGS( 2 );
    419392
    420                 if( !( a = account_get( irc, cmd[2] ) ) )
     393                if( !( a = account_get( irc->b, cmd[2] ) ) )
    421394                {
    422395                        irc_usermsg( irc, "Invalid account" );
     
    428401                else
    429402                {
    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 );
     403                        account_del( irc->b, a );
     404                        irc_usermsg( irc, "Account deleted" );
    444405                }
    445406        }
     
    451412                        irc_usermsg( irc, "Account list:" );
    452413               
    453                 for( a = irc->accounts; a; a = a->next )
     414                for( a = irc->b->accounts; a; a = a->next )
    454415                {
    455416                        char *con;
     
    474435                if( cmd[2] )
    475436                {
    476                         if( ( a = account_get( irc, cmd[2] ) ) )
     437                        if( ( a = account_get( irc->b, cmd[2] ) ) )
    477438                        {
    478439                                if( a->ic )
     
    483444                                else
    484445                                {
    485                                         account_on( irc, a );
     446                                        account_on( irc->b, a );
    486447                                }
    487448                        }
     
    494455                else
    495456                {
    496                         if ( irc->accounts ) {
     457                        if ( irc->b->accounts )
     458                        {
    497459                                irc_usermsg( irc, "Trying to get all accounts connected..." );
    498460                       
    499                                 for( a = irc->accounts; a; a = a->next )
     461                                for( a = irc->b->accounts; a; a = a->next )
    500462                                        if( !a->ic && a->auto_connect )
    501                                                 account_on( irc, a );
     463                                                account_on( irc->b, a );
    502464                        }
    503465                        else
     
    513475                        irc_usermsg( irc, "Deactivating all active (re)connections..." );
    514476                       
    515                         for( a = irc->accounts; a; a = a->next )
     477                        for( a = irc->b->accounts; a; a = a->next )
    516478                        {
    517479                                if( a->ic )
    518                                         account_off( irc, a );
     480                                        account_off( irc->b, a );
    519481                                else if( a->reconnect )
    520482                                        cancel_auto_reconnect( a );
    521483                        }
    522484                }
    523                 else if( ( a = account_get( irc, cmd[2] ) ) )
     485                else if( ( a = account_get( irc->b, cmd[2] ) ) )
    524486                {
    525487                        if( a->ic )
    526488                        {
    527                                 account_off( irc, a );
     489                                account_off( irc->b, a );
    528490                        }
    529491                        else if( a->reconnect )
     
    556518}
    557519
     520static 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
     530static 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] );
     579        }
     580}
     581
    558582static void cmd_add( irc_t *irc, char **cmd )
    559583{
     
    568592        }
    569593       
    570         if( !( a = account_get( irc, cmd[1] ) ) )
     594        if( !( a = account_get( irc->b, cmd[1] ) ) )
    571595        {
    572596                irc_usermsg( irc, "Invalid account" );
     
    586610                        return;
    587611                }
    588                 else if( user_find( irc, cmd[3] ) )
     612                else if( irc_user_by_name( irc, cmd[3] ) )
    589613                {
    590614                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
     
    600624                a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL );
    601625        else
    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 );
     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 );
    606629       
    607630        irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2]  );
     631}
     632
     633static 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;
    608654}
    609655
     
    615661        if( !cmd[2] )
    616662        {
    617                 user_t *u = user_find( irc, cmd[1] );
    618                 if( !u || !u->ic )
     663                irc_user_t *iu = irc_user_by_name( irc, cmd[1] );
     664                if( !iu || !iu->bu )
    619665                {
    620666                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    621667                        return;
    622668                }
    623                 ic = u->ic;
    624                 cmd[2] = u->handle;
    625         }
    626         else if( !( a = account_get( irc, cmd[1] ) ) )
     669                ic = iu->bu->ic;
     670                cmd[2] = iu->bu->handle;
     671        }
     672        else if( !( a = account_get( irc->b, cmd[1] ) ) )
    627673        {
    628674                irc_usermsg( irc, "Invalid account" );
     
    647693static void cmd_rename( irc_t *irc, char **cmd )
    648694{
    649         user_t *u;
    650        
    651         if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
     695        irc_user_t *iu;
     696       
     697        iu = irc_user_by_name( irc, cmd[1] );
     698       
     699        if( iu == NULL )
     700        {
     701                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
     702        }
     703        else if( iu == irc->user )
    652704        {
    653705                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
    654706        }
    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 ) )
     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] ) )
    671712        {
    672713                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
    673714        }
    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] ) ) )
    679         {
    680                 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    681         }
    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                        
     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                {
    691725                        /* If we're called internally (user did "set root_nick"),
    692726                           let's not go O(INF). :-) */
    693727                        if( strcmp( cmd[0], "set_rename" ) != 0 )
    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] );
     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] );
    699733                }
    700734               
     
    707741        irc_t *irc = set->data;
    708742       
    709         if( strcmp( irc->mynick, new_nick ) != 0 )
    710         {
    711                 char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL };
     743        if( strcmp( irc->root->nick, new_nick ) != 0 )
     744        {
     745                char *cmd[] = { "set_rename", irc->root->nick, new_nick, NULL };
    712746               
    713747                cmd_rename( irc, cmd );
    714748        }
    715749       
    716         return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID;
    717 }
    718 
    719 char *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 
    733 static 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;
     750        return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID;
    753751}
    754752
     
    758756        account_t *a;
    759757       
    760         if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic )
     758        if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic )
    761759        {
    762760                char *format;
     
    771769                for( l = a->ic->deny; l; l = l->next )
    772770                {
    773                         user_t *u = user_findhandle( a->ic, l->data );
    774                         irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
     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)" );
    775774                }
    776775                irc_usermsg( irc, "End of list." );
     
    780779        else if( !cmd[2] )
    781780        {
    782                 user_t *u = user_find( irc, cmd[1] );
    783                 if( !u || !u->ic )
     781                irc_user_t *iu = irc_user_by_name( irc, cmd[1] );
     782                if( !iu || !iu->bu )
    784783                {
    785784                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    786785                        return;
    787786                }
    788                 ic = u->ic;
    789                 cmd[2] = u->handle;
    790         }
    791         else if( !( a = account_get( irc, cmd[1] ) ) )
     787                ic = iu->bu->ic;
     788                cmd[2] = iu->bu->handle;
     789        }
     790        else if( !( a = account_get( irc->b, cmd[1] ) ) )
    792791        {
    793792                irc_usermsg( irc, "Invalid account" );
     
    817816        account_t *a;
    818817       
    819         if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic )
     818        if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic )
    820819        {
    821820                char *format;
     
    830829                for( l = a->ic->permit; l; l = l->next )
    831830                {
    832                         user_t *u = user_findhandle( a->ic, l->data );
    833                         irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
     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)" );
    834834                }
    835835                irc_usermsg( irc, "End of list." );
     
    839839        else if( !cmd[2] )
    840840        {
    841                 user_t *u = user_find( irc, cmd[1] );
    842                 if( !u || !u->ic )
     841                irc_user_t *iu = irc_user_by_name( irc, cmd[1] );
     842                if( !iu || !iu->bu )
    843843                {
    844844                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    845845                        return;
    846846                }
    847                 ic = u->ic;
    848                 cmd[2] = u->handle;
    849         }
    850         else if( !( a = account_get( irc, cmd[1] ) ) )
     847                ic = iu->bu->ic;
     848                cmd[2] = iu->bu->handle;
     849        }
     850        else if( !( a = account_get( irc->b, cmd[1] ) ) )
    851851        {
    852852                irc_usermsg( irc, "Invalid account" );
     
    915915}
    916916
    917 static 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 
    927917static void cmd_blist( irc_t *irc, char **cmd )
    928918{
    929919        int online = 0, away = 0, offline = 0;
    930         user_t *u;
     920        GSList *l;
    931921        char s[256];
    932922        char *format;
     
    949939                format = "%-16.16s  %-40.40s  %s";
    950940       
    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         {
     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               
    955951                if( online == 1 )
    956952                {
    957953                        char st[256] = "Online";
    958954                       
    959                         if( u->status_msg )
    960                                 g_snprintf( st, sizeof( st ) - 1, "Online (%s)", u->status_msg );
     955                        if( bu->status_msg )
     956                                g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg );
    961957                       
    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 );
     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 );
    964960                }
    965961               
     
    967963        }
    968964
    969         for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away )
    970         {
     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               
    971973                if( away == 1 )
    972974                {
    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 );
     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 ) );
    975977                }
    976978                n_away ++;
    977979        }
    978980       
    979         for( u = irc->users; u; u = u->next ) if( u->ic && !u->online )
    980         {
     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               
    981989                if( offline == 1 )
    982990                {
    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" );
     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" );
    985993                }
    986994                n_offline ++;
     
    988996       
    989997        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 
    992 static 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         }
    1018998}
    1019999
     
    10381018}
    10391019
    1040 static 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 
    1046 static 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 
    10561020static void cmd_chat( irc_t *irc, char **cmd )
    10571021{
    10581022        account_t *acc;
    1059         struct chat *c;
    10601023       
    10611024        if( g_strcasecmp( cmd[1], "add" ) == 0 )
    10621025        {
    10631026                char *channel, *s;
     1027                struct irc_channel *ic;
    10641028               
    10651029                MIN_ARGS( 3 );
    10661030               
    1067                 if( !( acc = account_get( irc, cmd[2] ) ) )
     1031                if( !( acc = account_get( irc->b, cmd[2] ) ) )
    10681032                {
    10691033                        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." );
    10701039                        return;
    10711040                }
     
    10841053                if( strchr( CTYPES, channel[0] ) == NULL )
    10851054                {
    1086                         s = g_strdup_printf( "%c%s", CTYPES[0], channel );
     1055                        s = g_strdup_printf( "#%s", channel );
    10871056                        g_free( channel );
    10881057                        channel = s;
    10891058                }
    10901059               
    1091                 if( ( c = chat_add( irc, acc, cmd[3], channel ) ) )
    1092                         irc_usermsg( irc, "Chatroom added successfully." );
    1093                 else
     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                       
    10941072                        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         {
     1073                }
     1074        }
     1075        else if( g_strcasecmp( cmd[1], "with" ) == 0 )
     1076        {
     1077                irc_user_t *iu;
     1078               
    11161079                MIN_ARGS( 2 );
    11171080               
    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." );
    1131                 }
    1132         }
    1133         else if( g_strcasecmp( cmd[1], "with" ) == 0 )
    1134         {
    1135                 user_t *u;
    1136                
    1137                 MIN_ARGS( 2 );
    1138                
    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 ) )
     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 ) )
    11421085                        {
    11431086                                irc_usermsg( irc, "(Possible) failure while trying to open "
    1144                                                   "a groupchat with %s.", u->nick );
     1087                                                  "a groupchat with %s.", iu->nick );
    11451088                        }
    11461089                }
     
    12041147                        {
    12051148                                irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name );
    1206                                 imcb_file_canceled( file, "Denied by user" );
     1149                                imcb_file_canceled( file->ic, file, "Denied by user" );
    12071150                        }
    12081151                        break;
     
    12111154                        {
    12121155                                irc_usermsg( irc, "Canceling file transfer for %s", file->file_name );
    1213                                 imcb_file_canceled( file, "Canceled by user" );
     1156                                imcb_file_canceled( file->ic, file, "Canceled by user" );
    12141157                        }
    12151158                        break;
     
    12181161}
    12191162
     1163/* IMPORTANT: Keep this list sorted! The short command logic needs that. */
    12201164const command_t commands[] = {
     1165        { "account",        1, cmd_account,        0 },
     1166        { "add",            2, cmd_add,            0 },
     1167        { "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 },
    12211174        { "help",           0, cmd_help,           0 },
    12221175        { "identify",       1, cmd_identify,       0 },
     1176        { "info",           1, cmd_info,           0 },
     1177        { "no",             0, cmd_yesno,          0 },
     1178        { "qlist",          0, cmd_qlist,          0 },
    12231179        { "register",       1, cmd_register,       0 },
    1224         { "drop",           1, cmd_drop,           0 },
    1225         { "account",        1, cmd_account,        0 },
    1226         { "add",            2, cmd_add,            0 },
    1227         { "info",           1, cmd_info,           0 },
     1180        { "remove",         1, cmd_remove,         0 },
    12281181        { "rename",         2, cmd_rename,         0 },
    1229         { "remove",         1, cmd_remove,         0 },
    1230         { "block",          1, cmd_block,          0 },
    1231         { "allow",          1, cmd_allow,          0 },
    12321182        { "save",           0, cmd_save,           0 },
    12331183        { "set",            0, cmd_set,            0 },
     1184        { "transfer",       0, cmd_transfer,       0 },
    12341185        { "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 },
    1241         { "transfer",       0, cmd_transfer,       0 },
    12421186        { NULL }
    12431187};
Note: See TracChangeset for help on using the changeset viewer.