Changeset 5a75d15
- Timestamp:
- 2010-06-05T22:32:36Z (15 years ago)
- Branches:
- master
- Children:
- c1a8a16
- Parents:
- f5d87ea
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.h
rf5d87ea r5a75d15 193 193 struct bee_group *group; 194 194 struct account *account; 195 };196 197 struct irc_groupchat_stub198 {199 struct account *acc;200 char *room;201 195 }; 202 196 -
irc_channel.c
rf5d87ea r5a75d15 29 29 static gint irc_channel_user_cmp( gconstpointer a_, gconstpointer b_ ); 30 30 static const struct irc_channel_funcs control_channel_funcs; 31 static const struct irc_channel_funcs groupchat_stub_funcs; 31 32 extern const struct irc_channel_funcs irc_channel_im_chat_funcs; 32 33 33 34 irc_channel_t *irc_channel_new( irc_t *irc, const char *name ) … … 104 105 new = &control_channel_funcs; 105 106 else if( strcmp( value, "chat" ) == 0 ) 106 new = & groupchat_stub_funcs;107 new = &irc_channel_im_chat_funcs; 107 108 else 108 109 return SET_INVALID; … … 389 390 control_channel_free, 390 391 }; 391 392 /* Groupchat stub: Only handles /INVITE at least for now. */393 static gboolean groupchat_stub_invite( irc_channel_t *ic, irc_user_t *iu )394 {395 bee_user_t *bu = iu->bu;396 397 if( iu->bu->ic->acc->prpl->chat_with )398 {399 ic->flags |= IRC_CHANNEL_CHAT_PICKME;400 iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle );401 ic->flags &= ~IRC_CHANNEL_CHAT_PICKME;402 return TRUE;403 }404 else405 {406 irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name );407 return FALSE;408 }409 }410 411 static gboolean groupchat_stub_join( irc_channel_t *ic )412 {413 struct irc_groupchat_stub *igs = ic->data;414 415 if( igs && igs->acc->ic && igs->acc->prpl->chat_join )416 {417 ic->flags |= IRC_CHANNEL_CHAT_PICKME;418 igs->acc->prpl->chat_join( igs->acc->ic, igs->room, ic->irc->user->nick, NULL );419 ic->flags &= ~IRC_CHANNEL_CHAT_PICKME;420 return FALSE;421 }422 else423 {424 irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name );425 return FALSE;426 }427 }428 429 static const struct irc_channel_funcs groupchat_stub_funcs = {430 NULL,431 groupchat_stub_join,432 NULL,433 NULL,434 groupchat_stub_invite,435 }; -
irc_commands.c
rf5d87ea r5a75d15 399 399 } 400 400 401 if( ic->f->invite ) 402 ic->f->invite( ic, iu ); 403 else 401 if( !ic->f->invite || !ic->f->invite( ic, iu ) ) 404 402 irc_send_num( irc, 482, "%s :Can't invite people here", cmd[2] ); 405 403 } -
irc_im.c
rf5d87ea r5a75d15 318 318 319 319 /* IM->IRC: Groupchats */ 320 staticconst struct irc_channel_funcs irc_channel_im_chat_funcs;320 const struct irc_channel_funcs irc_channel_im_chat_funcs; 321 321 322 322 static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c ) … … 341 341 { 342 342 char name[16]; 343 sprintf( name, " &chat_%03d", i );343 sprintf( name, "#chat_%03d", i ); 344 344 if( ( ic = irc_channel_new( irc, name ) ) ) 345 345 break; … … 351 351 c->ui_data = ic; 352 352 ic->data = c; 353 ic->f = &irc_channel_im_chat_funcs;354 353 355 354 topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); … … 367 366 irc_channel_printf( ic, "Cleaning up channel, bye!" ); 368 367 369 irc_channel_free( ic ); 368 /* irc_channel_free( ic ); */ 369 370 irc_channel_del_user( ic, ic->irc->user ); 371 ic->data = NULL; 370 372 371 373 return TRUE; … … 468 470 struct groupchat *c = ic->data; 469 471 472 if( c == NULL ) 473 return FALSE; 474 470 475 bee_chat_msg( ic->irc->b, c, msg, 0 ); 471 476 472 477 return TRUE; 473 478 } 479 480 static gboolean bee_irc_channel_chat_join( irc_channel_t *ic ) 481 { 482 char *acc_s, *room; 483 account_t *acc; 484 485 if( strcmp( set_getstr( &ic->set, "chat_type" ), "room" ) != 0 ) 486 return TRUE; 487 488 if( ( acc_s = set_getstr( &ic->set, "account" ) ) && 489 ( room = set_getstr( &ic->set, "room" ) ) && 490 ( acc = account_get( ic->irc->b, acc_s ) ) && 491 acc->ic && acc->prpl->chat_join ) 492 { 493 char *nick; 494 495 if( !( nick = set_getstr( &ic->set, "nick" ) ) ) 496 nick = ic->irc->user->nick; 497 498 ic->flags |= IRC_CHANNEL_CHAT_PICKME; 499 acc->prpl->chat_join( acc->ic, room, nick, NULL ); 500 ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; 501 502 return FALSE; 503 } 504 else 505 { 506 irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name ); 507 return FALSE; 508 } 474 509 } 475 510 … … 478 513 struct groupchat *c = ic->data; 479 514 480 if( c ->ic->acc->prpl->chat_leave )515 if( c && c->ic->acc->prpl->chat_leave ) 481 516 c->ic->acc->prpl->chat_leave( c ); 482 517 483 518 return TRUE; 484 485 519 } 486 520 … … 488 522 { 489 523 struct groupchat *c = ic->data; 490 char *topic = g_strdup( new ); /* TODO: Need more const goodness here, sigh */ 524 525 if( c == NULL ) 526 return FALSE; 491 527 492 528 if( c->ic->acc->prpl->chat_topic == NULL ) … … 494 530 else 495 531 { 532 /* TODO: Need more const goodness here, sigh */ 533 char *topic = g_strdup( new ); 496 534 c->ic->acc->prpl->chat_topic( c, topic ); 535 g_free( topic ); 497 536 return TRUE; 498 537 } … … 504 543 { 505 544 struct groupchat *c = ic->data; 506 507 if( iu->bu->ic != c->ic ) 508 irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name ); 509 else if( c->ic->acc->prpl->chat_invite ) 510 c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL ); 511 else 545 bee_user_t *bu = iu->bu; 546 547 if( bu == NULL ) 548 return FALSE; 549 550 if( c ) 551 { 552 if( iu->bu->ic != c->ic ) 553 irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name ); 554 else if( c->ic->acc->prpl->chat_invite ) 555 c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL ); 556 else 557 irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); 558 } 559 else if( bu->ic->acc->prpl->chat_with && 560 strcmp( set_getstr( &ic->set, "chat_type" ), "groupchat" ) == 0 ) 561 { 562 ic->flags |= IRC_CHANNEL_CHAT_PICKME; 563 iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle ); 564 ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; 565 } 566 else 567 { 512 568 irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); 513 514 return TRUE; 515 } 516 517 static const struct irc_channel_funcs irc_channel_im_chat_funcs = { 569 } 570 571 return TRUE; 572 } 573 574 static char *set_eval_room_account( set_t *set, char *value ); 575 576 static gboolean bee_irc_channel_init( irc_channel_t *ic ) 577 { 578 set_add( &ic->set, "account", NULL, set_eval_room_account, ic ); 579 set_add( &ic->set, "chat_type", "groupchat", NULL, ic ); 580 set_add( &ic->set, "nick", NULL, NULL, ic ); 581 set_add( &ic->set, "room", NULL, NULL, ic ); 582 583 return TRUE; 584 } 585 586 static char *set_eval_room_account( set_t *set, char *value ) 587 { 588 struct irc_channel *ic = set->data; 589 account_t *acc; 590 591 if( !( acc = account_get( ic->irc->b, value ) ) ) 592 return SET_INVALID; 593 else if( !acc->prpl->chat_join ) 594 { 595 irc_usermsg( ic->irc, "Named chatrooms not supported on that account." ); 596 return SET_INVALID; 597 } 598 599 return g_strdup_printf( "%s(%s)", acc->prpl->name, acc->user ); 600 } 601 602 static gboolean bee_irc_channel_free( irc_channel_t *ic ) 603 { 604 set_del( &ic->set, "account" ); 605 set_del( &ic->set, "chat_type" ); 606 set_del( &ic->set, "nick" ); 607 set_del( &ic->set, "room" ); 608 609 return TRUE; 610 } 611 612 const struct irc_channel_funcs irc_channel_im_chat_funcs = { 518 613 bee_irc_channel_chat_privmsg, 519 NULL, /* join */614 bee_irc_channel_chat_join, 520 615 bee_irc_channel_chat_part, 521 616 bee_irc_channel_chat_topic, 522 617 bee_irc_channel_chat_invite, 618 619 bee_irc_channel_init, 620 bee_irc_channel_free, 523 621 }; 524 622 -
root_commands.c
rf5d87ea r5a75d15 980 980 return; 981 981 } 982 else if( !acc->prpl->chat_join ) 983 { 984 irc_usermsg( irc, "Named chatrooms not supported on that account." ); 985 return; 986 } 982 987 983 988 if( cmd[4] == NULL ) … … 999 1004 } 1000 1005 1001 if( ( ic = irc_channel_new( irc, channel ) ) ) 1002 { 1003 struct irc_groupchat_stub *igs; 1006 if( ( ic = irc_channel_new( irc, channel ) ) && 1007 set_setstr( &ic->set, "chat_type", "room" ) && 1008 set_setstr( &ic->set, "account", cmd[2] ) && 1009 set_setstr( &ic->set, "room", cmd[3] ) ) 1010 { 1011 irc_usermsg( irc, "Chatroom successfully added." ); 1012 } 1013 else 1014 { 1015 if( ic ) 1016 irc_channel_free( ic ); 1004 1017 1005 ic->data = igs = g_new0( struct irc_groupchat_stub, 1 ); 1006 igs->acc = acc; 1007 igs->room = g_strdup( cmd[3] ); 1018 irc_usermsg( irc, "Could not add chatroom." ); 1008 1019 } 1009 1020 }
Note: See TracChangeset
for help on using the changeset viewer.