Changes in root_commands.c [0baed0d:7cd2e8a]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
r0baed0d r7cd2e8a 26 26 #define BITLBEE_CORE 27 27 #include "commands.h" 28 #include "crypting.h"29 28 #include "bitlbee.h" 30 29 #include "help.h" … … 33 32 #include <string.h> 34 33 35 void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) 36 { 37 char *cmd[IRC_MAX_ARGS]; 38 char *s; 39 int k; 40 char q = 0; 41 42 memset( cmd, 0, sizeof( cmd ) ); 43 cmd[0] = command; 44 k = 1; 45 for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) 46 if( *s == ' ' && !q ) 47 { 48 *s = 0; 49 while( *++s == ' ' ); 50 if( *s == '"' || *s == '\'' ) 51 { 52 q = *s; 53 s ++; 54 } 55 if( *s ) 56 { 57 cmd[k++] = s; 58 s --; 59 } 60 else 61 { 62 break; 63 } 64 } 65 else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) 66 { 67 char *cpy; 68 69 for( cpy = s; *cpy; cpy ++ ) 70 cpy[0] = cpy[1]; 71 } 72 else if( *s == q ) 73 { 74 q = *s = 0; 75 } 76 cmd[k] = NULL; 77 78 root_command( irc, cmd ); 34 void root_command_string( irc_t *irc, char *command ) 35 { 36 root_command( irc, split_command_parts( command ) ); 79 37 } 80 38 … … 93 51 void root_command( irc_t *irc, char *cmd[] ) 94 52 { 95 int i ;53 int i, len; 96 54 97 55 if( !cmd[0] ) 98 56 return; 99 57 58 len = strlen( cmd[0] ); 100 59 for( i = 0; commands[i].command; i++ ) 101 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) 102 { 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 103 67 MIN_ARGS( commands[i].required_parameters ); 104 68 … … 141 105 static void cmd_identify( irc_t *irc, char **cmd ) 142 106 { 143 storage_status_t status = storage_load( irc, cmd[1] );107 storage_status_t status; 144 108 char *account_on[] = { "account", "on", NULL }; 145 146 if( strchr( irc->umode, 'R' ) != NULL ) 109 gboolean load = TRUE; 110 char *password = cmd[1]; 111 112 if( irc->status & USTATUS_IDENTIFIED ) 147 113 { 148 114 irc_usermsg( irc, "You're already logged in." ); 149 115 return; 150 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 ); 151 146 152 147 switch (status) { … … 158 153 break; 159 154 case STORAGE_OK: 160 irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); 161 irc_setpass( irc, cmd[1] ); 155 irc_usermsg( irc, "Password accepted%s", 156 load ? ", settings and accounts loaded" : "" ); 157 irc_setpass( irc, password ); 162 158 irc->status |= USTATUS_IDENTIFIED; 163 159 irc_umode_set( irc, "+R", 1 ); 164 if( set_getbool( &irc->set, "auto_connect" ) )160 if( load && set_getbool( &irc->b->set, "auto_connect" ) ) 165 161 cmd_account( irc, account_on ); 166 162 break; … … 202 198 storage_status_t status; 203 199 204 status = storage_remove (irc-> nick, cmd[1]);200 status = storage_remove (irc->user->nick, cmd[1]); 205 201 switch (status) { 206 202 case STORAGE_NO_SUCH_USER: … … 214 210 irc->status &= ~USTATUS_IDENTIFIED; 215 211 irc_umode_set( irc, "-R", 1 ); 216 irc_usermsg( irc, "Account `%s' removed", irc-> nick );212 irc_usermsg( irc, "Account `%s' removed", irc->user->nick ); 217 213 break; 218 214 default: … … 222 218 } 223 219 224 struct cmd_account_del_data 225 { 226 account_t *a; 227 irc_t *irc; 228 }; 229 230 void cmd_account_del_yes( void *data ) 231 { 232 struct cmd_account_del_data *cad = data; 233 account_t *a; 234 235 for( a = cad->irc->accounts; a && a != cad->a; a = a->next ); 236 237 if( a == NULL ) 238 { 239 irc_usermsg( cad->irc, "Account already deleted" ); 240 } 241 else if( a->ic ) 242 { 243 irc_usermsg( cad->irc, "Account is still logged in, can't delete" ); 244 } 245 else 246 { 247 account_del( cad->irc, a ); 248 irc_usermsg( cad->irc, "Account deleted" ); 249 } 250 g_free( data ); 251 } 252 253 void cmd_account_del_no( void *data ) 254 { 255 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!" ); 256 228 } 257 229 … … 286 258 set_name = set_full; 287 259 288 head = &irc-> set;260 head = &irc->b->set; 289 261 } 290 262 else … … 357 329 account_t *a; 358 330 359 if( ( a = account_get( irc , id ) ) )331 if( ( a = account_get( irc->b, id ) ) ) 360 332 return &a->set; 361 333 else … … 405 377 } 406 378 407 a = account_add( irc , prpl, cmd[3], cmd[4] );379 a = account_add( irc->b, prpl, cmd[3], cmd[4] ); 408 380 if( cmd[5] ) 409 381 { … … 419 391 MIN_ARGS( 2 ); 420 392 421 if( !( a = account_get( irc , cmd[2] ) ) )393 if( !( a = account_get( irc->b, cmd[2] ) ) ) 422 394 { 423 395 irc_usermsg( irc, "Invalid account" ); … … 429 401 else 430 402 { 431 struct cmd_account_del_data *cad; 432 char *msg; 433 434 cad = g_malloc( sizeof( struct cmd_account_del_data ) ); 435 cad->a = a; 436 cad->irc = irc; 437 438 msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " 439 "also forget all your saved nicknames. If you want " 440 "to change your username/password, use the `account " 441 "set' command. Are you sure you want to delete this " 442 "account?", a->prpl->name, a->user ); 443 query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); 444 g_free( msg ); 403 account_del( irc->b, a ); 404 irc_usermsg( irc, "Account deleted" ); 445 405 } 446 406 } … … 452 412 irc_usermsg( irc, "Account list:" ); 453 413 454 for( a = irc-> accounts; a; a = a->next )414 for( a = irc->b->accounts; a; a = a->next ) 455 415 { 456 416 char *con; … … 475 435 if( cmd[2] ) 476 436 { 477 if( ( a = account_get( irc , cmd[2] ) ) )437 if( ( a = account_get( irc->b, cmd[2] ) ) ) 478 438 { 479 439 if( a->ic ) … … 484 444 else 485 445 { 486 account_on( irc , a );446 account_on( irc->b, a ); 487 447 } 488 448 } … … 495 455 else 496 456 { 497 if ( irc->accounts ) { 457 if ( irc->b->accounts ) 458 { 498 459 irc_usermsg( irc, "Trying to get all accounts connected..." ); 499 460 500 for( a = irc-> accounts; a; a = a->next )461 for( a = irc->b->accounts; a; a = a->next ) 501 462 if( !a->ic && a->auto_connect ) 502 account_on( irc , a );463 account_on( irc->b, a ); 503 464 } 504 465 else … … 514 475 irc_usermsg( irc, "Deactivating all active (re)connections..." ); 515 476 516 for( a = irc-> accounts; a; a = a->next )477 for( a = irc->b->accounts; a; a = a->next ) 517 478 { 518 479 if( a->ic ) 519 account_off( irc , a );480 account_off( irc->b, a ); 520 481 else if( a->reconnect ) 521 482 cancel_auto_reconnect( a ); 522 483 } 523 484 } 524 else if( ( a = account_get( irc , cmd[2] ) ) )485 else if( ( a = account_get( irc->b, cmd[2] ) ) ) 525 486 { 526 487 if( a->ic ) 527 488 { 528 account_off( irc , a );489 account_off( irc->b, a ); 529 490 } 530 491 else if( a->reconnect ) … … 557 518 } 558 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 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 559 582 static void cmd_add( irc_t *irc, char **cmd ) 560 583 { … … 569 592 } 570 593 571 if( !( a = account_get( irc , cmd[1] ) ) )594 if( !( a = account_get( irc->b, cmd[1] ) ) ) 572 595 { 573 596 irc_usermsg( irc, "Invalid account" ); … … 587 610 return; 588 611 } 589 else if( user_find( irc, cmd[3] ) )612 else if( irc_user_by_name( irc, cmd[3] ) ) 590 613 { 591 614 irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); … … 599 622 600 623 if( add_on_server ) 601 a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); 602 else 603 /* Yeah, officially this is a call-*back*... So if we just 604 called add_buddy, we'll wait for the IM server to respond 605 before we do this. */ 606 imcb_add_buddy( a->ic, cmd[2], NULL ); 624 a->prpl->add_buddy( a->ic, cmd[2], NULL ); 625 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 ); 607 629 608 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; 609 654 } 610 655 … … 616 661 if( !cmd[2] ) 617 662 { 618 user_t *u = user_find( irc, cmd[1] );619 if( ! u || !u->ic)663 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 664 if( !iu || !iu->bu ) 620 665 { 621 666 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 622 667 return; 623 668 } 624 ic = u->ic;625 cmd[2] = u->handle;626 } 627 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] ) ) ) 628 673 { 629 674 irc_usermsg( irc, "Invalid account" ); … … 648 693 static void cmd_rename( irc_t *irc, char **cmd ) 649 694 { 650 user_t *u; 651 652 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 ) 653 704 { 654 705 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); 655 706 } 656 else if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) 657 { 658 if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) ) 659 { 660 u = user_find( irc, irc->nick ); 661 662 irc_part( irc, u, irc->channel ); 663 g_free( irc->channel ); 664 irc->channel = g_strdup( cmd[2] ); 665 irc_join( irc, u, irc->channel ); 666 667 if( strcmp( cmd[0], "set_rename" ) != 0 ) 668 set_setstr( &irc->set, "control_channel", cmd[2] ); 669 } 670 } 671 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] ) ) 672 712 { 673 713 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); 674 714 } 675 else if( !nick_ok( cmd[2] ) ) 676 { 677 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); 678 } 679 else if( !( u = user_find( irc, cmd[1] ) ) ) 680 { 681 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 682 } 683 else 684 { 685 user_rename( irc, cmd[1], cmd[2] ); 686 irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); 687 if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) 688 { 689 g_free( irc->mynick ); 690 irc->mynick = g_strdup( cmd[2] ); 691 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 { 692 725 /* If we're called internally (user did "set root_nick"), 693 726 let's not go O(INF). :-) */ 694 727 if( strcmp( cmd[0], "set_rename" ) != 0 ) 695 set_setstr( &irc-> set, "root_nick", cmd[2] );696 } 697 else if( u->send_handler == buddy_send_handler)698 { 699 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] ); 700 733 } 701 734 … … 708 741 irc_t *irc = set->data; 709 742 710 if( strcmp( irc-> mynick, new_nick ) != 0 )711 { 712 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 }; 713 746 714 747 cmd_rename( irc, cmd ); 715 748 } 716 749 717 return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID; 718 } 719 720 char *set_eval_control_channel( set_t *set, char *new_name ) 721 { 722 irc_t *irc = set->data; 723 724 if( strcmp( irc->channel, new_name ) != 0 ) 725 { 726 char *cmd[] = { "set_rename", irc->channel, new_name, NULL }; 727 728 cmd_rename( irc, cmd ); 729 } 730 731 return strcmp( irc->channel, new_name ) == 0 ? new_name : SET_INVALID; 732 } 733 734 static void cmd_remove( irc_t *irc, char **cmd ) 735 { 736 user_t *u; 737 char *s; 738 739 if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) 740 { 741 irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); 742 return; 743 } 744 s = g_strdup( u->handle ); 745 746 u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); 747 nick_del( u->ic->acc, u->handle ); 748 user_del( irc, cmd[1] ); 749 750 irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); 751 g_free( s ); 752 753 return; 750 return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID; 754 751 } 755 752 … … 759 756 account_t *a; 760 757 761 if( !cmd[2] && ( a = account_get( irc , cmd[1] ) ) && a->ic )758 if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) 762 759 { 763 760 char *format; … … 772 769 for( l = a->ic->deny; l; l = l->next ) 773 770 { 774 user_t *u = user_findhandle( a->ic, l->data ); 775 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)" ); 776 774 } 777 775 irc_usermsg( irc, "End of list." ); … … 781 779 else if( !cmd[2] ) 782 780 { 783 user_t *u = user_find( irc, cmd[1] );784 if( ! u || !u->ic)781 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 782 if( !iu || !iu->bu ) 785 783 { 786 784 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 787 785 return; 788 786 } 789 ic = u->ic;790 cmd[2] = u->handle;791 } 792 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] ) ) ) 793 791 { 794 792 irc_usermsg( irc, "Invalid account" ); … … 818 816 account_t *a; 819 817 820 if( !cmd[2] && ( a = account_get( irc , cmd[1] ) ) && a->ic )818 if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) 821 819 { 822 820 char *format; … … 831 829 for( l = a->ic->permit; l; l = l->next ) 832 830 { 833 user_t *u = user_findhandle( a->ic, l->data ); 834 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)" ); 835 834 } 836 835 irc_usermsg( irc, "End of list." ); … … 840 839 else if( !cmd[2] ) 841 840 { 842 user_t *u = user_find( irc, cmd[1] );843 if( ! u || !u->ic)841 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 842 if( !iu || !iu->bu ) 844 843 { 845 844 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 846 845 return; 847 846 } 848 ic = u->ic;849 cmd[2] = u->handle;850 } 851 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] ) ) ) 852 851 { 853 852 irc_usermsg( irc, "Invalid account" ); … … 916 915 } 917 916 918 static void cmd_save( irc_t *irc, char **cmd )919 {920 if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )921 irc_usermsg( irc, "Please create an account first" );922 else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )923 irc_usermsg( irc, "Configuration saved" );924 else925 irc_usermsg( irc, "Configuration could not be saved!" );926 }927 928 917 static void cmd_blist( irc_t *irc, char **cmd ) 929 918 { 930 919 int online = 0, away = 0, offline = 0; 931 user_t *u;920 GSList *l; 932 921 char s[256]; 933 922 char *format; … … 950 939 format = "%-16.16s %-40.40s %s"; 951 940 952 irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); 953 954 for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) 955 { 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 956 951 if( online == 1 ) 957 952 { 958 953 char st[256] = "Online"; 959 954 960 if( u->status_msg )961 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 ); 962 957 963 g_snprintf( s, sizeof( s ) - 1, "%s @%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name,u->ic->acc->user );964 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 ); 965 960 } 966 961 … … 968 963 } 969 964 970 for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) 971 { 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 972 973 if( away == 1 ) 973 974 { 974 g_snprintf( s, sizeof( s ) - 1, "%s @%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name,u->ic->acc->user );975 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 ) ); 976 977 } 977 978 n_away ++; 978 979 } 979 980 980 for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) 981 { 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 982 989 if( offline == 1 ) 983 990 { 984 g_snprintf( s, sizeof( s ) - 1, "%s @%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name,u->ic->acc->user );985 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" ); 986 993 } 987 994 n_offline ++; … … 989 996 990 997 irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); 991 }992 993 static void cmd_nick( irc_t *irc, char **cmd )994 {995 account_t *a;996 997 if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )998 {999 irc_usermsg( irc, "Invalid account");1000 }1001 else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) )1002 {1003 irc_usermsg( irc, "That account is not on-line" );1004 }1005 else if ( !cmd[2] )1006 {1007 irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" );1008 }1009 else if ( !a->prpl->set_my_name )1010 {1011 irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );1012 }1013 else1014 {1015 irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );1016 1017 a->prpl->set_my_name( a->ic, cmd[2] );1018 }1019 998 } 1020 999 … … 1039 1018 } 1040 1019 1041 static void cmd_join_chat( irc_t *irc, char **cmd )1042 {1043 irc_usermsg( irc, "This command is now obsolete. "1044 "Please try the `chat' command instead." );1045 }1046 1047 static set_t **cmd_chat_set_findhead( irc_t *irc, char *id )1048 {1049 struct chat *c;1050 1051 if( ( c = chat_get( irc, id ) ) )1052 return &c->set;1053 else1054 return NULL;1055 }1056 1057 1020 static void cmd_chat( irc_t *irc, char **cmd ) 1058 1021 { 1059 1022 account_t *acc; 1060 struct chat *c;1061 1023 1062 1024 if( g_strcasecmp( cmd[1], "add" ) == 0 ) 1063 1025 { 1064 1026 char *channel, *s; 1027 struct irc_channel *ic; 1065 1028 1066 1029 MIN_ARGS( 3 ); 1067 1030 1068 if( !( acc = account_get( irc , cmd[2] ) ) )1031 if( !( acc = account_get( irc->b, cmd[2] ) ) ) 1069 1032 { 1070 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." ); 1071 1039 return; 1072 1040 } … … 1085 1053 if( strchr( CTYPES, channel[0] ) == NULL ) 1086 1054 { 1087 s = g_strdup_printf( " %c%s", CTYPES[0], channel );1055 s = g_strdup_printf( "#%s", channel ); 1088 1056 g_free( channel ); 1089 1057 channel = s; 1090 1058 } 1091 1059 1092 if( ( c = chat_add( irc, acc, cmd[3], channel ) ) ) 1093 irc_usermsg( irc, "Chatroom added successfully." ); 1094 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 1095 1072 irc_usermsg( irc, "Could not add chatroom." ); 1096 1073 } 1097 1074 g_free( channel ); 1098 1075 } 1099 else if( g_strcasecmp( cmd[1], "list" ) == 0 ) 1100 { 1101 int i = 0; 1102 1103 if( strchr( irc->umode, 'b' ) ) 1104 irc_usermsg( irc, "Chatroom list:" ); 1105 1106 for( c = irc->chatrooms; c; c = c->next ) 1107 { 1108 irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name, 1109 c->acc->user, c->handle, c->channel ); 1110 1111 i ++; 1112 } 1113 irc_usermsg( irc, "End of chatroom list" ); 1114 } 1115 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 1116 { 1076 else if( g_strcasecmp( cmd[1], "with" ) == 0 ) 1077 { 1078 irc_user_t *iu; 1079 1117 1080 MIN_ARGS( 2 ); 1118 1081 1119 cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead, NULL ); 1120 } 1121 else if( g_strcasecmp( cmd[1], "del" ) == 0 ) 1122 { 1123 MIN_ARGS( 2 ); 1124 1125 if( ( c = chat_get( irc, cmd[2] ) ) ) 1126 { 1127 chat_del( irc, c ); 1128 } 1129 else 1130 { 1131 irc_usermsg( irc, "Could not remove chat." ); 1132 } 1133 } 1134 else if( g_strcasecmp( cmd[1], "with" ) == 0 ) 1135 { 1136 user_t *u; 1137 1138 MIN_ARGS( 2 ); 1139 1140 if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with ) 1141 { 1142 if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) 1082 if( ( iu = irc_user_by_name( irc, cmd[2] ) ) && 1083 iu->bu && iu->bu->ic->acc->prpl->chat_with ) 1084 { 1085 if( !iu->bu->ic->acc->prpl->chat_with( iu->bu->ic, iu->bu->handle ) ) 1143 1086 { 1144 1087 irc_usermsg( irc, "(Possible) failure while trying to open " 1145 "a groupchat with %s.", u->nick );1088 "a groupchat with %s.", iu->nick ); 1146 1089 } 1147 1090 } … … 1151 1094 } 1152 1095 } 1096 else if( g_strcasecmp( cmd[1], "list" ) == 0 || 1097 g_strcasecmp( cmd[1], "set" ) == 0 || 1098 g_strcasecmp( cmd[1], "del" ) == 0 ) 1099 { 1100 irc_usermsg( irc, "Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command." ); 1101 cmd_channel( irc, cmd ); 1102 } 1153 1103 else 1154 1104 { … … 1157 1107 } 1158 1108 1109 static void cmd_transfer( irc_t *irc, char **cmd ) 1110 { 1111 GSList *files = irc->file_transfers; 1112 enum { LIST, REJECT, CANCEL }; 1113 int subcmd = LIST; 1114 int fid; 1115 1116 if( !files ) 1117 { 1118 irc_usermsg( irc, "No pending transfers" ); 1119 return; 1120 } 1121 1122 if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) 1123 { 1124 subcmd = REJECT; 1125 } 1126 else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && 1127 cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) 1128 { 1129 subcmd = CANCEL; 1130 } 1131 1132 for( ; files; files = g_slist_next( files ) ) 1133 { 1134 file_transfer_t *file = files->data; 1135 1136 switch( subcmd ) { 1137 case LIST: 1138 if ( file->status == FT_STATUS_LISTENING ) 1139 irc_usermsg( irc, 1140 "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); 1141 else 1142 { 1143 int kb_per_s = 0; 1144 time_t diff = time( NULL ) - file->started ? : 1; 1145 if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) 1146 kb_per_s = file->bytes_transferred / 1024 / diff; 1147 1148 irc_usermsg( irc, 1149 "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, 1150 file->bytes_transferred/1024, file->file_size/1024, kb_per_s); 1151 } 1152 break; 1153 case REJECT: 1154 if( file->status == FT_STATUS_LISTENING ) 1155 { 1156 irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); 1157 imcb_file_canceled( file->ic, file, "Denied by user" ); 1158 } 1159 break; 1160 case CANCEL: 1161 if( file->local_id == fid ) 1162 { 1163 irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); 1164 imcb_file_canceled( file->ic, file, "Canceled by user" ); 1165 } 1166 break; 1167 } 1168 } 1169 } 1170 1171 /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ 1159 1172 const command_t commands[] = { 1173 { "account", 1, cmd_account, 0 }, 1174 { "add", 2, cmd_add, 0 }, 1175 { "allow", 1, cmd_allow, 0 }, 1176 { "blist", 0, cmd_blist, 0 }, 1177 { "block", 1, cmd_block, 0 }, 1178 { "channel", 1, cmd_channel, 0 }, 1179 { "chat", 1, cmd_chat, 0 }, 1180 { "drop", 1, cmd_drop, 0 }, 1181 { "ft", 0, cmd_transfer, 0 }, 1160 1182 { "help", 0, cmd_help, 0 }, 1161 1183 { "identify", 1, cmd_identify, 0 }, 1184 { "info", 1, cmd_info, 0 }, 1185 { "no", 0, cmd_yesno, 0 }, 1186 { "qlist", 0, cmd_qlist, 0 }, 1162 1187 { "register", 1, cmd_register, 0 }, 1163 { "drop", 1, cmd_drop, 0 }, 1164 { "account", 1, cmd_account, 0 }, 1165 { "add", 2, cmd_add, 0 }, 1166 { "info", 1, cmd_info, 0 }, 1188 { "remove", 1, cmd_remove, 0 }, 1167 1189 { "rename", 2, cmd_rename, 0 }, 1168 { "remove", 1, cmd_remove, 0 },1169 { "block", 1, cmd_block, 0 },1170 { "allow", 1, cmd_allow, 0 },1171 1190 { "save", 0, cmd_save, 0 }, 1172 1191 { "set", 0, cmd_set, 0 }, 1192 { "transfer", 0, cmd_transfer, 0 }, 1173 1193 { "yes", 0, cmd_yesno, 0 }, 1174 { "no", 0, cmd_yesno, 0 },1175 { "blist", 0, cmd_blist, 0 },1176 { "nick", 1, cmd_nick, 0 },1177 { "qlist", 0, cmd_qlist, 0 },1178 { "join_chat", 2, cmd_join_chat, 0 },1179 { "chat", 1, cmd_chat, 0 },1180 1194 { NULL } 1181 1195 };
Note: See TracChangeset
for help on using the changeset viewer.