Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • root_commands.c

    r1f92a58 rba7d16f  
    3232#include <string.h>
    3333
    34 void root_command_string( irc_t *irc, char *command )
     34void root_command_string( irc_t *irc, user_t *u, char *command, int flags )
    3535{
    3636        char *cmd[IRC_MAX_ARGS];
     
    161161                irc->status |= USTATUS_IDENTIFIED;
    162162                irc_umode_set( irc, "+R", 1 );
    163                 if( set_getbool( &irc->b->set, "auto_connect" ) )
     163                if( set_getbool( &irc->set, "auto_connect" ) )
    164164                        cmd_account( irc, account_on );
    165165                break;
     
    201201        storage_status_t status;
    202202       
    203         status = storage_remove (irc->user->nick, cmd[1]);
     203        status = storage_remove (irc->nick, cmd[1]);
    204204        switch (status) {
    205205        case STORAGE_NO_SUCH_USER:
     
    213213                irc->status &= ~USTATUS_IDENTIFIED;
    214214                irc_umode_set( irc, "-R", 1 );
    215                 irc_usermsg( irc, "Account `%s' removed", irc->user->nick );
     215                irc_usermsg( irc, "Account `%s' removed", irc->nick );
    216216                break;
    217217        default:
     
    221221}
    222222
    223 static void cmd_save( irc_t *irc, char **cmd )
    224 {
    225         if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
    226                 irc_usermsg( irc, "Please create an account first" );
    227         else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
    228                 irc_usermsg( irc, "Configuration saved" );
    229         else
    230                 irc_usermsg( irc, "Configuration could not be saved!" );
    231 }
    232 
    233223struct cmd_account_del_data
    234224{
     
    242232        account_t *a;
    243233       
    244         for( a = cad->irc->b->accounts; a && a != cad->a; a = a->next );
     234        for( a = cad->irc->accounts; a && a != cad->a; a = a->next );
    245235       
    246236        if( a == NULL )
     
    254244        else
    255245        {
    256                 account_del( cad->irc->b, a );
     246                account_del( cad->irc, a );
    257247                irc_usermsg( cad->irc, "Account deleted" );
    258248        }
     
    295285                set_name = set_full;
    296286               
    297                 head = &irc->b->set;
     287                head = &irc->set;
    298288        }
    299289        else
     
    366356        account_t *a;
    367357       
    368         if( ( a = account_get( irc->b, id ) ) )
     358        if( ( a = account_get( irc, id ) ) )
    369359                return &a->set;
    370360        else
     
    414404                }
    415405
    416                 a = account_add( irc->b, prpl, cmd[3], cmd[4] );
     406                a = account_add( irc, prpl, cmd[3], cmd[4] );
    417407                if( cmd[5] )
    418408                {
     
    428418                MIN_ARGS( 2 );
    429419
    430                 if( !( a = account_get( irc->b, cmd[2] ) ) )
     420                if( !( a = account_get( irc, cmd[2] ) ) )
    431421                {
    432422                        irc_usermsg( irc, "Invalid account" );
     
    450440                                               "set' command. Are you sure you want to delete this "
    451441                                               "account?", a->prpl->name, a->user );
    452                         //query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );
     442                        query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );
    453443                        g_free( msg );
    454444                }
     
    461451                        irc_usermsg( irc, "Account list:" );
    462452               
    463                 for( a = irc->b->accounts; a; a = a->next )
     453                for( a = irc->accounts; a; a = a->next )
    464454                {
    465455                        char *con;
     
    484474                if( cmd[2] )
    485475                {
    486                         if( ( a = account_get( irc->b, cmd[2] ) ) )
     476                        if( ( a = account_get( irc, cmd[2] ) ) )
    487477                        {
    488478                                if( a->ic )
     
    493483                                else
    494484                                {
    495                                         account_on( irc->b, a );
     485                                        account_on( irc, a );
    496486                                }
    497487                        }
     
    504494                else
    505495                {
    506                         if ( irc->b->accounts )
    507                         {
     496                        if ( irc->accounts ) {
    508497                                irc_usermsg( irc, "Trying to get all accounts connected..." );
    509498                       
    510                                 for( a = irc->b->accounts; a; a = a->next )
     499                                for( a = irc->accounts; a; a = a->next )
    511500                                        if( !a->ic && a->auto_connect )
    512                                                 account_on( irc->b, a );
     501                                                account_on( irc, a );
    513502                        }
    514503                        else
     
    524513                        irc_usermsg( irc, "Deactivating all active (re)connections..." );
    525514                       
    526                         for( a = irc->b->accounts; a; a = a->next )
     515                        for( a = irc->accounts; a; a = a->next )
    527516                        {
    528517                                if( a->ic )
    529                                         account_off( irc->b, a );
     518                                        account_off( irc, a );
    530519                                else if( a->reconnect )
    531520                                        cancel_auto_reconnect( a );
    532521                        }
    533522                }
    534                 else if( ( a = account_get( irc->b, cmd[2] ) ) )
     523                else if( ( a = account_get( irc, cmd[2] ) ) )
    535524                {
    536525                        if( a->ic )
    537526                        {
    538                                 account_off( irc->b, a );
     527                                account_off( irc, a );
    539528                        }
    540529                        else if( a->reconnect )
     
    567556}
    568557
    569 #if 0
    570558static void cmd_add( irc_t *irc, char **cmd )
    571559{
     
    656644        }
    657645}
    658 #endif
    659646
    660647static void cmd_rename( irc_t *irc, char **cmd )
    661648{
    662         irc_user_t *iu;
    663        
    664         iu = irc_user_by_name( irc, cmd[1] );
    665        
    666         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] ) ) )
    667679        {
    668680                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    669681        }
    670         else if( iu == irc->user )
    671         {
    672                 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
    673         }
    674         else if( !nick_ok( cmd[2] ) )
    675         {
    676                 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
    677         }
    678         else if( irc_user_by_name( irc, cmd[2] ) )
    679         {
    680                 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
    681         }
    682         else
    683         {
    684                 if( !irc_user_set_nick( iu, cmd[2] ) )
    685                 {
    686                         irc_usermsg( irc, "Error while changing nick" );
    687                         return;
    688                 }
    689                
    690                 if( iu == irc->root )
    691                 {
     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                       
    692691                        /* If we're called internally (user did "set root_nick"),
    693692                           let's not go O(INF). :-) */
    694693                        if( strcmp( cmd[0], "set_rename" ) != 0 )
    695                                 set_setstr( &irc->b->set, "root_nick", cmd[2] );
    696                 }
    697                 else if( iu->bu )
    698                 {
    699                         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] );
    700699                }
    701700               
     
    704703}
    705704
    706 #if 0
    707705char *set_eval_root_nick( set_t *set, char *new_nick )
    708706{
     
    915913{
    916914        cmd_set_real( irc, cmd, NULL, NULL );
     915}
     916
     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!" );
    917925}
    918926
     
    982990}
    983991
     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        }
     1018}
     1019
    9841020static void cmd_qlist( irc_t *irc, char **cmd )
    9851021{
     
    10001036                else
    10011037                        irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
     1038}
     1039
     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." );
    10021044}
    10031045
     
    11751217        }
    11761218}
    1177 #endif
    11781219
    11791220const command_t commands[] = {
    11801221        { "help",           0, cmd_help,           0 },
    1181         { "account",        1, cmd_account,        0 },
    11821222        { "identify",       1, cmd_identify,       0 },
    11831223        { "register",       1, cmd_register,       0 },
    11841224        { "drop",           1, cmd_drop,           0 },
    1185         { "save",           0, cmd_save,           0 },
    1186 #if 0
     1225        { "account",        1, cmd_account,        0 },
    11871226        { "add",            2, cmd_add,            0 },
    11881227        { "info",           1, cmd_info,           0 },
    1189 #endif
    11901228        { "rename",         2, cmd_rename,         0 },
    1191 #if 0
    11921229        { "remove",         1, cmd_remove,         0 },
    11931230        { "block",          1, cmd_block,          0 },
    11941231        { "allow",          1, cmd_allow,          0 },
     1232        { "save",           0, cmd_save,           0 },
    11951233        { "set",            0, cmd_set,            0 },
    11961234        { "yes",            0, cmd_yesno,          0 },
     
    12021240        { "chat",           1, cmd_chat,           0 },
    12031241        { "transfer",       0, cmd_transfer,       0 },
    1204 #endif
    12051242        { NULL }
    12061243};
Note: See TracChangeset for help on using the changeset viewer.