Changes in root_commands.c [ba7d16f:a4d920b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
rba7d16f ra4d920b 32 32 #include <string.h> 33 33 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 ); 34 void root_command_string( irc_t *irc, char *command ) 35 { 36 root_command( irc, split_command_parts( command ) ); 78 37 } 79 38 … … 92 51 void root_command( irc_t *irc, char *cmd[] ) 93 52 { 94 int i ;53 int i, len; 95 54 96 55 if( !cmd[0] ) 97 56 return; 98 57 58 len = strlen( cmd[0] ); 99 59 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 102 67 MIN_ARGS( commands[i].required_parameters ); 103 68 … … 140 105 static void cmd_identify( irc_t *irc, char **cmd ) 141 106 { 142 storage_status_t status = storage_load( irc, cmd[1] );107 storage_status_t status; 143 108 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 ) 146 113 { 147 114 irc_usermsg( irc, "You're already logged in." ); 148 115 return; 149 116 } 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 ); 150 146 151 147 switch (status) { … … 157 153 break; 158 154 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 ); 161 158 irc->status |= USTATUS_IDENTIFIED; 162 159 irc_umode_set( irc, "+R", 1 ); 163 if( set_getbool( &irc->set, "auto_connect" ) )160 if( load && set_getbool( &irc->b->set, "auto_connect" ) ) 164 161 cmd_account( irc, account_on ); 165 162 break; … … 201 198 storage_status_t status; 202 199 203 status = storage_remove (irc-> nick, cmd[1]);200 status = storage_remove (irc->user->nick, cmd[1]); 204 201 switch (status) { 205 202 case STORAGE_NO_SUCH_USER: … … 213 210 irc->status &= ~USTATUS_IDENTIFIED; 214 211 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 ); 216 213 break; 217 214 default: … … 221 218 } 222 219 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 ); 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!" ); 255 228 } 256 229 … … 285 258 set_name = set_full; 286 259 287 head = &irc-> set;260 head = &irc->b->set; 288 261 } 289 262 else … … 356 329 account_t *a; 357 330 358 if( ( a = account_get( irc , id ) ) )331 if( ( a = account_get( irc->b, id ) ) ) 359 332 return &a->set; 360 333 else … … 404 377 } 405 378 406 a = account_add( irc , prpl, cmd[3], cmd[4] );379 a = account_add( irc->b, prpl, cmd[3], cmd[4] ); 407 380 if( cmd[5] ) 408 381 { … … 418 391 MIN_ARGS( 2 ); 419 392 420 if( !( a = account_get( irc , cmd[2] ) ) )393 if( !( a = account_get( irc->b, cmd[2] ) ) ) 421 394 { 422 395 irc_usermsg( irc, "Invalid account" ); … … 428 401 else 429 402 { 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" ); 444 405 } 445 406 } … … 451 412 irc_usermsg( irc, "Account list:" ); 452 413 453 for( a = irc-> accounts; a; a = a->next )414 for( a = irc->b->accounts; a; a = a->next ) 454 415 { 455 416 char *con; … … 474 435 if( cmd[2] ) 475 436 { 476 if( ( a = account_get( irc , cmd[2] ) ) )437 if( ( a = account_get( irc->b, cmd[2] ) ) ) 477 438 { 478 439 if( a->ic ) … … 483 444 else 484 445 { 485 account_on( irc , a );446 account_on( irc->b, a ); 486 447 } 487 448 } … … 494 455 else 495 456 { 496 if ( irc->accounts ) { 457 if ( irc->b->accounts ) 458 { 497 459 irc_usermsg( irc, "Trying to get all accounts connected..." ); 498 460 499 for( a = irc-> accounts; a; a = a->next )461 for( a = irc->b->accounts; a; a = a->next ) 500 462 if( !a->ic && a->auto_connect ) 501 account_on( irc , a );463 account_on( irc->b, a ); 502 464 } 503 465 else … … 513 475 irc_usermsg( irc, "Deactivating all active (re)connections..." ); 514 476 515 for( a = irc-> accounts; a; a = a->next )477 for( a = irc->b->accounts; a; a = a->next ) 516 478 { 517 479 if( a->ic ) 518 account_off( irc , a );480 account_off( irc->b, a ); 519 481 else if( a->reconnect ) 520 482 cancel_auto_reconnect( a ); 521 483 } 522 484 } 523 else if( ( a = account_get( irc , cmd[2] ) ) )485 else if( ( a = account_get( irc->b, cmd[2] ) ) ) 524 486 { 525 487 if( a->ic ) 526 488 { 527 account_off( irc , a );489 account_off( irc->b, a ); 528 490 } 529 491 else if( a->reconnect ) … … 556 518 } 557 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] ); 579 } 580 } 581 558 582 static void cmd_add( irc_t *irc, char **cmd ) 559 583 { … … 568 592 } 569 593 570 if( !( a = account_get( irc , cmd[1] ) ) )594 if( !( a = account_get( irc->b, cmd[1] ) ) ) 571 595 { 572 596 irc_usermsg( irc, "Invalid account" ); … … 586 610 return; 587 611 } 588 else if( user_find( irc, cmd[3] ) )612 else if( irc_user_by_name( irc, cmd[3] ) ) 589 613 { 590 614 irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); … … 600 624 a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); 601 625 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 ); 606 629 607 630 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; 608 654 } 609 655 … … 615 661 if( !cmd[2] ) 616 662 { 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 ) 619 665 { 620 666 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 621 667 return; 622 668 } 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] ) ) ) 627 673 { 628 674 irc_usermsg( irc, "Invalid account" ); … … 647 693 static void cmd_rename( irc_t *irc, char **cmd ) 648 694 { 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 ) 652 704 { 653 705 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); 654 706 } 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] ) ) 671 712 { 672 713 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); 673 714 } 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 { 691 725 /* If we're called internally (user did "set root_nick"), 692 726 let's not go O(INF). :-) */ 693 727 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] ); 699 733 } 700 734 … … 707 741 irc_t *irc = set->data; 708 742 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 }; 712 746 713 747 cmd_rename( irc, cmd ); 714 748 } 715 749 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; 753 751 } 754 752 … … 758 756 account_t *a; 759 757 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 ) 761 759 { 762 760 char *format; … … 771 769 for( l = a->ic->deny; l; l = l->next ) 772 770 { 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)" ); 775 774 } 776 775 irc_usermsg( irc, "End of list." ); … … 780 779 else if( !cmd[2] ) 781 780 { 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 ) 784 783 { 785 784 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 786 785 return; 787 786 } 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] ) ) ) 792 791 { 793 792 irc_usermsg( irc, "Invalid account" ); … … 817 816 account_t *a; 818 817 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 ) 820 819 { 821 820 char *format; … … 830 829 for( l = a->ic->permit; l; l = l->next ) 831 830 { 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)" ); 834 834 } 835 835 irc_usermsg( irc, "End of list." ); … … 839 839 else if( !cmd[2] ) 840 840 { 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 ) 843 843 { 844 844 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 845 845 return; 846 846 } 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] ) ) ) 851 851 { 852 852 irc_usermsg( irc, "Invalid account" ); … … 915 915 } 916 916 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 else924 irc_usermsg( irc, "Configuration could not be saved!" );925 }926 927 917 static void cmd_blist( irc_t *irc, char **cmd ) 928 918 { 929 919 int online = 0, away = 0, offline = 0; 930 user_t *u;920 GSList *l; 931 921 char s[256]; 932 922 char *format; … … 949 939 format = "%-16.16s %-40.40s %s"; 950 940 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 955 951 if( online == 1 ) 956 952 { 957 953 char st[256] = "Online"; 958 954 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 ); 961 957 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 ); 964 960 } 965 961 … … 967 963 } 968 964 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 971 973 if( away == 1 ) 972 974 { 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 ) ); 975 977 } 976 978 n_away ++; 977 979 } 978 980 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 981 989 if( offline == 1 ) 982 990 { 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" ); 985 993 } 986 994 n_offline ++; … … 988 996 989 997 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 else1013 {1014 irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );1015 1016 a->prpl->set_my_name( a->ic, cmd[2] );1017 }1018 998 } 1019 999 … … 1038 1018 } 1039 1019 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 else1053 return NULL;1054 }1055 1056 1020 static void cmd_chat( irc_t *irc, char **cmd ) 1057 1021 { 1058 1022 account_t *acc; 1059 struct chat *c;1060 1023 1061 1024 if( g_strcasecmp( cmd[1], "add" ) == 0 ) 1062 1025 { 1063 1026 char *channel, *s; 1027 struct irc_channel *ic; 1064 1028 1065 1029 MIN_ARGS( 3 ); 1066 1030 1067 if( !( acc = account_get( irc , cmd[2] ) ) )1031 if( !( acc = account_get( irc->b, cmd[2] ) ) ) 1068 1032 { 1069 1033 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." ); 1070 1039 return; 1071 1040 } … … 1084 1053 if( strchr( CTYPES, channel[0] ) == NULL ) 1085 1054 { 1086 s = g_strdup_printf( " %c%s", CTYPES[0], channel );1055 s = g_strdup_printf( "#%s", channel ); 1087 1056 g_free( channel ); 1088 1057 channel = s; 1089 1058 } 1090 1059 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 1094 1072 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 1116 1079 MIN_ARGS( 2 ); 1117 1080 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 ) ) 1142 1085 { 1143 1086 irc_usermsg( irc, "(Possible) failure while trying to open " 1144 "a groupchat with %s.", u->nick );1087 "a groupchat with %s.", iu->nick ); 1145 1088 } 1146 1089 } … … 1204 1147 { 1205 1148 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" ); 1207 1150 } 1208 1151 break; … … 1211 1154 { 1212 1155 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" ); 1214 1157 } 1215 1158 break; … … 1218 1161 } 1219 1162 1163 /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ 1220 1164 const 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 }, 1221 1174 { "help", 0, cmd_help, 0 }, 1222 1175 { "identify", 1, cmd_identify, 0 }, 1176 { "info", 1, cmd_info, 0 }, 1177 { "no", 0, cmd_yesno, 0 }, 1178 { "qlist", 0, cmd_qlist, 0 }, 1223 1179 { "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 }, 1228 1181 { "rename", 2, cmd_rename, 0 }, 1229 { "remove", 1, cmd_remove, 0 },1230 { "block", 1, cmd_block, 0 },1231 { "allow", 1, cmd_allow, 0 },1232 1182 { "save", 0, cmd_save, 0 }, 1233 1183 { "set", 0, cmd_set, 0 }, 1184 { "transfer", 0, cmd_transfer, 0 }, 1234 1185 { "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 },1242 1186 { NULL } 1243 1187 };
Note: See TracChangeset
for help on using the changeset viewer.