Changes in root_commands.c [a4d920b:ba7d16f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
ra4d920b rba7d16f 32 32 #include <string.h> 33 33 34 void root_command_string( irc_t *irc, char *command ) 35 { 36 root_command( irc, split_command_parts( command ) ); 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 ); 37 78 } 38 79 … … 51 92 void root_command( irc_t *irc, char *cmd[] ) 52 93 { 53 int i , len;94 int i; 54 95 55 96 if( !cmd[0] ) 56 97 return; 57 98 58 len = strlen( cmd[0] );59 99 for( i = 0; commands[i].command; i++ ) 60 if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 ) 61 { 62 if( commands[i+1].command && 63 g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 ) 64 /* Only match on the first letters if the match is unique. */ 65 break; 66 100 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) 101 { 67 102 MIN_ARGS( commands[i].required_parameters ); 68 103 … … 105 140 static void cmd_identify( irc_t *irc, char **cmd ) 106 141 { 107 storage_status_t status ;142 storage_status_t status = storage_load( irc, cmd[1] ); 108 143 char *account_on[] = { "account", "on", NULL }; 109 gboolean load = TRUE; 110 char *password = cmd[1]; 111 112 if( irc->status & USTATUS_IDENTIFIED ) 144 145 if( strchr( irc->umode, 'R' ) != NULL ) 113 146 { 114 147 irc_usermsg( irc, "You're already logged in." ); 115 148 return; 116 149 } 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 else145 status = storage_check_pass( irc->user->nick, password );146 150 147 151 switch (status) { … … 153 157 break; 154 158 case STORAGE_OK: 155 irc_usermsg( irc, "Password accepted%s", 156 load ? ", settings and accounts loaded" : "" ); 157 irc_setpass( irc, password ); 159 irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); 160 irc_setpass( irc, cmd[1] ); 158 161 irc->status |= USTATUS_IDENTIFIED; 159 162 irc_umode_set( irc, "+R", 1 ); 160 if( load && set_getbool( &irc->b->set, "auto_connect" ) )163 if( set_getbool( &irc->set, "auto_connect" ) ) 161 164 cmd_account( irc, account_on ); 162 165 break; … … 198 201 storage_status_t status; 199 202 200 status = storage_remove (irc-> user->nick, cmd[1]);203 status = storage_remove (irc->nick, cmd[1]); 201 204 switch (status) { 202 205 case STORAGE_NO_SUCH_USER: … … 210 213 irc->status &= ~USTATUS_IDENTIFIED; 211 214 irc_umode_set( irc, "-R", 1 ); 212 irc_usermsg( irc, "Account `%s' removed", irc-> user->nick );215 irc_usermsg( irc, "Account `%s' removed", irc->nick ); 213 216 break; 214 217 default: … … 218 221 } 219 222 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!" ); 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 ); 228 255 } 229 256 … … 258 285 set_name = set_full; 259 286 260 head = &irc-> b->set;287 head = &irc->set; 261 288 } 262 289 else … … 329 356 account_t *a; 330 357 331 if( ( a = account_get( irc ->b, id ) ) )358 if( ( a = account_get( irc, id ) ) ) 332 359 return &a->set; 333 360 else … … 377 404 } 378 405 379 a = account_add( irc ->b, prpl, cmd[3], cmd[4] );406 a = account_add( irc, prpl, cmd[3], cmd[4] ); 380 407 if( cmd[5] ) 381 408 { … … 391 418 MIN_ARGS( 2 ); 392 419 393 if( !( a = account_get( irc ->b, cmd[2] ) ) )420 if( !( a = account_get( irc, cmd[2] ) ) ) 394 421 { 395 422 irc_usermsg( irc, "Invalid account" ); … … 401 428 else 402 429 { 403 account_del( irc->b, a ); 404 irc_usermsg( irc, "Account deleted" ); 430 struct cmd_account_del_data *cad; 431 char *msg; 432 433 cad = g_malloc( sizeof( struct cmd_account_del_data ) ); 434 cad->a = a; 435 cad->irc = irc; 436 437 msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " 438 "also forget all your saved nicknames. If you want " 439 "to change your username/password, use the `account " 440 "set' command. Are you sure you want to delete this " 441 "account?", a->prpl->name, a->user ); 442 query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); 443 g_free( msg ); 405 444 } 406 445 } … … 412 451 irc_usermsg( irc, "Account list:" ); 413 452 414 for( a = irc-> b->accounts; a; a = a->next )453 for( a = irc->accounts; a; a = a->next ) 415 454 { 416 455 char *con; … … 435 474 if( cmd[2] ) 436 475 { 437 if( ( a = account_get( irc ->b, cmd[2] ) ) )476 if( ( a = account_get( irc, cmd[2] ) ) ) 438 477 { 439 478 if( a->ic ) … … 444 483 else 445 484 { 446 account_on( irc ->b, a );485 account_on( irc, a ); 447 486 } 448 487 } … … 455 494 else 456 495 { 457 if ( irc->b->accounts ) 458 { 496 if ( irc->accounts ) { 459 497 irc_usermsg( irc, "Trying to get all accounts connected..." ); 460 498 461 for( a = irc-> b->accounts; a; a = a->next )499 for( a = irc->accounts; a; a = a->next ) 462 500 if( !a->ic && a->auto_connect ) 463 account_on( irc ->b, a );501 account_on( irc, a ); 464 502 } 465 503 else … … 475 513 irc_usermsg( irc, "Deactivating all active (re)connections..." ); 476 514 477 for( a = irc-> b->accounts; a; a = a->next )515 for( a = irc->accounts; a; a = a->next ) 478 516 { 479 517 if( a->ic ) 480 account_off( irc ->b, a );518 account_off( irc, a ); 481 519 else if( a->reconnect ) 482 520 cancel_auto_reconnect( a ); 483 521 } 484 522 } 485 else if( ( a = account_get( irc ->b, cmd[2] ) ) )523 else if( ( a = account_get( irc, cmd[2] ) ) ) 486 524 { 487 525 if( a->ic ) 488 526 { 489 account_off( irc ->b, a );527 account_off( irc, a ); 490 528 } 491 529 else if( a->reconnect ) … … 515 553 { 516 554 irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] ); 517 }518 }519 520 static set_t **cmd_channel_set_findhead( irc_t *irc, char *id )521 {522 irc_channel_t *ic;523 524 if( ( ic = irc_channel_get( irc, id ) ) )525 return &ic->set;526 else527 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 else572 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 else577 {578 irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] );579 555 } 580 556 } … … 592 568 } 593 569 594 if( !( a = account_get( irc ->b, cmd[1] ) ) )570 if( !( a = account_get( irc, cmd[1] ) ) ) 595 571 { 596 572 irc_usermsg( irc, "Invalid account" ); … … 610 586 return; 611 587 } 612 else if( irc_user_by_name( irc, cmd[3] ) )588 else if( user_find( irc, cmd[3] ) ) 613 589 { 614 590 irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); … … 624 600 a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); 625 601 else 626 /* Only for add -tmp. For regular adds, this callback will 627 be called once the IM server confirms. */ 628 bee_user_new( irc->b, a->ic, cmd[2], BEE_USER_LOCAL ); 602 /* Yeah, officially this is a call-*back*... So if we just 603 called add_buddy, we'll wait for the IM server to respond 604 before we do this. */ 605 imcb_add_buddy( a->ic, cmd[2], NULL ); 629 606 630 607 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;654 608 } 655 609 … … 661 615 if( !cmd[2] ) 662 616 { 663 irc_user_t *iu = irc_user_by_name( irc, cmd[1] );664 if( ! iu || !iu->bu)617 user_t *u = user_find( irc, cmd[1] ); 618 if( !u || !u->ic ) 665 619 { 666 620 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 667 621 return; 668 622 } 669 ic = iu->bu->ic;670 cmd[2] = iu->bu->handle;671 } 672 else if( !( a = account_get( irc ->b, cmd[1] ) ) )623 ic = u->ic; 624 cmd[2] = u->handle; 625 } 626 else if( !( a = account_get( irc, cmd[1] ) ) ) 673 627 { 674 628 irc_usermsg( irc, "Invalid account" ); … … 693 647 static void cmd_rename( irc_t *irc, char **cmd ) 694 648 { 695 irc_user_t *iu; 696 697 iu = irc_user_by_name( irc, cmd[1] ); 698 699 if( iu == NULL ) 649 user_t *u; 650 651 if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) 652 { 653 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); 654 } 655 else if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) 656 { 657 if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) ) 658 { 659 u = user_find( irc, irc->nick ); 660 661 irc_part( irc, u, irc->channel ); 662 g_free( irc->channel ); 663 irc->channel = g_strdup( cmd[2] ); 664 irc_join( irc, u, irc->channel ); 665 666 if( strcmp( cmd[0], "set_rename" ) != 0 ) 667 set_setstr( &irc->set, "control_channel", cmd[2] ); 668 } 669 } 670 else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) 671 { 672 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); 673 } 674 else if( !nick_ok( cmd[2] ) ) 675 { 676 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); 677 } 678 else if( !( u = user_find( irc, cmd[1] ) ) ) 700 679 { 701 680 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 702 681 } 703 else if( iu == irc->user ) 704 { 705 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); 706 } 707 else if( !nick_ok( cmd[2] ) ) 708 { 709 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); 710 } 711 else if( irc_user_by_name( irc, cmd[2] ) ) 712 { 713 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); 714 } 715 else 716 { 717 if( !irc_user_set_nick( iu, cmd[2] ) ) 718 { 719 irc_usermsg( irc, "Error while changing nick" ); 720 return; 721 } 722 723 if( iu == irc->root ) 724 { 682 else 683 { 684 user_rename( irc, cmd[1], cmd[2] ); 685 irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); 686 if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) 687 { 688 g_free( irc->mynick ); 689 irc->mynick = g_strdup( cmd[2] ); 690 725 691 /* If we're called internally (user did "set root_nick"), 726 692 let's not go O(INF). :-) */ 727 693 if( strcmp( cmd[0], "set_rename" ) != 0 ) 728 set_setstr( &irc-> b->set, "root_nick", cmd[2] );729 } 730 else if( iu->bu)731 { 732 nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );694 set_setstr( &irc->set, "root_nick", cmd[2] ); 695 } 696 else if( u->send_handler == buddy_send_handler ) 697 { 698 nick_set( u->ic->acc, u->handle, cmd[2] ); 733 699 } 734 700 … … 741 707 irc_t *irc = set->data; 742 708 743 if( strcmp( irc-> root->nick, new_nick ) != 0 )744 { 745 char *cmd[] = { "set_rename", irc-> root->nick, new_nick, NULL };709 if( strcmp( irc->mynick, new_nick ) != 0 ) 710 { 711 char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL }; 746 712 747 713 cmd_rename( irc, cmd ); 748 714 } 749 715 750 return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID; 716 return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID; 717 } 718 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; 751 753 } 752 754 … … 756 758 account_t *a; 757 759 758 if( !cmd[2] && ( a = account_get( irc ->b, cmd[1] ) ) && a->ic )760 if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) 759 761 { 760 762 char *format; … … 769 771 for( l = a->ic->deny; l; l = l->next ) 770 772 { 771 bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); 772 irc_user_t *iu = bu ? bu->ui_data : NULL; 773 irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); 773 user_t *u = user_findhandle( a->ic, l->data ); 774 irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); 774 775 } 775 776 irc_usermsg( irc, "End of list." ); … … 779 780 else if( !cmd[2] ) 780 781 { 781 irc_user_t *iu = irc_user_by_name( irc, cmd[1] );782 if( ! iu || !iu->bu)782 user_t *u = user_find( irc, cmd[1] ); 783 if( !u || !u->ic ) 783 784 { 784 785 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 785 786 return; 786 787 } 787 ic = iu->bu->ic;788 cmd[2] = iu->bu->handle;789 } 790 else if( !( a = account_get( irc ->b, cmd[1] ) ) )788 ic = u->ic; 789 cmd[2] = u->handle; 790 } 791 else if( !( a = account_get( irc, cmd[1] ) ) ) 791 792 { 792 793 irc_usermsg( irc, "Invalid account" ); … … 816 817 account_t *a; 817 818 818 if( !cmd[2] && ( a = account_get( irc ->b, cmd[1] ) ) && a->ic )819 if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) 819 820 { 820 821 char *format; … … 829 830 for( l = a->ic->permit; l; l = l->next ) 830 831 { 831 bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); 832 irc_user_t *iu = bu ? bu->ui_data : NULL; 833 irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); 832 user_t *u = user_findhandle( a->ic, l->data ); 833 irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); 834 834 } 835 835 irc_usermsg( irc, "End of list." ); … … 839 839 else if( !cmd[2] ) 840 840 { 841 irc_user_t *iu = irc_user_by_name( irc, cmd[1] );842 if( ! iu || !iu->bu)841 user_t *u = user_find( irc, cmd[1] ); 842 if( !u || !u->ic ) 843 843 { 844 844 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 845 845 return; 846 846 } 847 ic = iu->bu->ic;848 cmd[2] = iu->bu->handle;849 } 850 else if( !( a = account_get( irc ->b, cmd[1] ) ) )847 ic = u->ic; 848 cmd[2] = u->handle; 849 } 850 else if( !( a = account_get( irc, cmd[1] ) ) ) 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 else 924 irc_usermsg( irc, "Configuration could not be saved!" ); 925 } 926 917 927 static void cmd_blist( irc_t *irc, char **cmd ) 918 928 { 919 929 int online = 0, away = 0, offline = 0; 920 GSList *l;930 user_t *u; 921 931 char s[256]; 922 932 char *format; … … 939 949 format = "%-16.16s %-40.40s %s"; 940 950 941 irc_usermsg( irc, format, "Nick", "Handle/Account", "Status" ); 942 943 for( l = irc->users; l; l = l->next ) 944 { 945 irc_user_t *iu = l->data; 946 bee_user_t *bu = iu->bu; 947 948 if( !bu || ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE ) 949 continue; 950 951 irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); 952 953 for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) 954 { 951 955 if( online == 1 ) 952 956 { 953 957 char st[256] = "Online"; 954 958 955 if( bu->status_msg )956 g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg );957 958 g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user );959 irc_usermsg( irc, format, iu->nick, s, st );959 if( u->status_msg ) 960 g_snprintf( st, sizeof( st ) - 1, "Online (%s)", u->status_msg ); 961 962 g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); 963 irc_usermsg( irc, format, u->nick, s, st ); 960 964 } 961 965 … … 963 967 } 964 968 965 for( l = irc->users; l; l = l->next ) 966 { 967 irc_user_t *iu = l->data; 968 bee_user_t *bu = iu->bu; 969 970 if( !bu || !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) ) 971 continue; 972 969 for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) 970 { 973 971 if( away == 1 ) 974 972 { 975 g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user );976 irc_usermsg( irc, format, iu->nick, s, irc_user_get_away( iu ));973 g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); 974 irc_usermsg( irc, format, u->nick, s, u->away ); 977 975 } 978 976 n_away ++; 979 977 } 980 978 981 for( l = irc->users; l; l = l->next ) 982 { 983 irc_user_t *iu = l->data; 984 bee_user_t *bu = iu->bu; 985 986 if( !bu || bu->flags & BEE_USER_ONLINE ) 987 continue; 988 979 for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) 980 { 989 981 if( offline == 1 ) 990 982 { 991 g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user );992 irc_usermsg( irc, format, iu->nick, s, "Offline" );983 g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); 984 irc_usermsg( irc, format, u->nick, s, "Offline" ); 993 985 } 994 986 n_offline ++; … … 996 988 997 989 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 } 998 1018 } 999 1019 … … 1018 1038 } 1019 1039 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 1020 1056 static void cmd_chat( irc_t *irc, char **cmd ) 1021 1057 { 1022 1058 account_t *acc; 1059 struct chat *c; 1023 1060 1024 1061 if( g_strcasecmp( cmd[1], "add" ) == 0 ) 1025 1062 { 1026 1063 char *channel, *s; 1027 struct irc_channel *ic;1028 1064 1029 1065 MIN_ARGS( 3 ); 1030 1066 1031 if( !( acc = account_get( irc ->b, cmd[2] ) ) )1067 if( !( acc = account_get( irc, cmd[2] ) ) ) 1032 1068 { 1033 1069 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." );1039 1070 return; 1040 1071 } … … 1053 1084 if( strchr( CTYPES, channel[0] ) == NULL ) 1054 1085 { 1055 s = g_strdup_printf( " #%s", channel );1086 s = g_strdup_printf( "%c%s", CTYPES[0], channel ); 1056 1087 g_free( channel ); 1057 1088 channel = s; 1058 1089 } 1059 1090 1060 if( ( ic = irc_channel_new( irc, channel ) ) && 1061 set_setstr( &ic->set, "chat_type", "room" ) && 1062 set_setstr( &ic->set, "account", cmd[2] ) && 1063 set_setstr( &ic->set, "room", cmd[3] ) ) 1064 { 1065 irc_usermsg( irc, "Chatroom successfully added." ); 1066 } 1067 else 1068 { 1069 if( ic ) 1070 irc_channel_free( ic ); 1071 1091 if( ( c = chat_add( irc, acc, cmd[3], channel ) ) ) 1092 irc_usermsg( irc, "Chatroom added successfully." ); 1093 else 1072 1094 irc_usermsg( irc, "Could not add chatroom." ); 1095 1096 g_free( channel ); 1097 } 1098 else if( g_strcasecmp( cmd[1], "list" ) == 0 ) 1099 { 1100 int i = 0; 1101 1102 if( strchr( irc->umode, 'b' ) ) 1103 irc_usermsg( irc, "Chatroom list:" ); 1104 1105 for( c = irc->chatrooms; c; c = c->next ) 1106 { 1107 irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name, 1108 c->acc->user, c->handle, c->channel ); 1109 1110 i ++; 1111 } 1112 irc_usermsg( irc, "End of chatroom list" ); 1113 } 1114 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 1115 { 1116 MIN_ARGS( 2 ); 1117 1118 cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead, NULL ); 1119 } 1120 else if( g_strcasecmp( cmd[1], "del" ) == 0 ) 1121 { 1122 MIN_ARGS( 2 ); 1123 1124 if( ( c = chat_get( irc, cmd[2] ) ) ) 1125 { 1126 chat_del( irc, c ); 1127 } 1128 else 1129 { 1130 irc_usermsg( irc, "Could not remove chat." ); 1073 1131 } 1074 1132 } 1075 1133 else if( g_strcasecmp( cmd[1], "with" ) == 0 ) 1076 1134 { 1077 irc_user_t *iu;1135 user_t *u; 1078 1136 1079 1137 MIN_ARGS( 2 ); 1080 1138 1081 if( ( iu = irc_user_by_name( irc, cmd[2] ) ) && 1082 iu->bu && iu->bu->ic->acc->prpl->chat_with ) 1083 { 1084 if( !iu->bu->ic->acc->prpl->chat_with( iu->bu->ic, iu->bu->handle ) ) 1139 if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with ) 1140 { 1141 if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) 1085 1142 { 1086 1143 irc_usermsg( irc, "(Possible) failure while trying to open " 1087 "a groupchat with %s.", iu->nick );1144 "a groupchat with %s.", u->nick ); 1088 1145 } 1089 1146 } … … 1147 1204 { 1148 1205 irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); 1149 imcb_file_canceled( file ->ic, file, "Denied by user" );1206 imcb_file_canceled( file, "Denied by user" ); 1150 1207 } 1151 1208 break; … … 1154 1211 { 1155 1212 irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); 1156 imcb_file_canceled( file ->ic, file, "Canceled by user" );1213 imcb_file_canceled( file, "Canceled by user" ); 1157 1214 } 1158 1215 break; … … 1161 1218 } 1162 1219 1163 /* IMPORTANT: Keep this list sorted! The short command logic needs that. */1164 1220 const command_t commands[] = { 1221 { "help", 0, cmd_help, 0 }, 1222 { "identify", 1, cmd_identify, 0 }, 1223 { "register", 1, cmd_register, 0 }, 1224 { "drop", 1, cmd_drop, 0 }, 1165 1225 { "account", 1, cmd_account, 0 }, 1166 1226 { "add", 2, cmd_add, 0 }, 1227 { "info", 1, cmd_info, 0 }, 1228 { "rename", 2, cmd_rename, 0 }, 1229 { "remove", 1, cmd_remove, 0 }, 1230 { "block", 1, cmd_block, 0 }, 1167 1231 { "allow", 1, cmd_allow, 0 }, 1168 { "blist", 0, cmd_blist, 0 },1169 { "block", 1, cmd_block, 0 },1170 { "channel", 1, cmd_channel, 0 },1171 { "chat", 1, cmd_chat, 0 },1172 { "drop", 1, cmd_drop, 0 },1173 { "ft", 0, cmd_transfer, 0 },1174 { "help", 0, cmd_help, 0 },1175 { "identify", 1, cmd_identify, 0 },1176 { "info", 1, cmd_info, 0 },1177 { "no", 0, cmd_yesno, 0 },1178 { "qlist", 0, cmd_qlist, 0 },1179 { "register", 1, cmd_register, 0 },1180 { "remove", 1, cmd_remove, 0 },1181 { "rename", 2, cmd_rename, 0 },1182 1232 { "save", 0, cmd_save, 0 }, 1183 1233 { "set", 0, cmd_set, 0 }, 1234 { "yes", 0, cmd_yesno, 0 }, 1235 { "no", 0, cmd_yesno, 0 }, 1236 { "blist", 0, cmd_blist, 0 }, 1237 { "nick", 1, cmd_nick, 0 }, 1238 { "qlist", 0, cmd_qlist, 0 }, 1239 { "join_chat", 2, cmd_join_chat, 0 }, 1240 { "chat", 1, cmd_chat, 0 }, 1184 1241 { "transfer", 0, cmd_transfer, 0 }, 1185 { "yes", 0, cmd_yesno, 0 },1186 1242 { NULL } 1187 1243 };
Note: See TracChangeset
for help on using the changeset viewer.