void bee_irc_channel_update( irc_t *irc, irc_channel_t *ic, irc_user_t *iu ) { GSList *l; if( ic == NULL ) { for( l = irc->channels; l; l = l->next ) { ic = l->data; /* TODO: Just add a type flag or so.. */ if( ic->f == irc->default_channel->f && ( ic->flags & IRC_CHANNEL_JOINED ) ) bee_irc_channel_update( irc, ic, iu ); } return; } if( iu == NULL ) { for( l = irc->users; l; l = l->next ) { iu = l->data; if( iu->bu ) bee_irc_channel_update( irc, ic, l->data ); } return; } if( !irc_channel_wants_user( ic, iu ) ) { irc_channel_del_user( ic, iu, IRC_CDU_PART, NULL ); } else { struct irc_control_channel *icc = ic->data; int mode = 0; if( !( iu->bu->flags & BEE_USER_ONLINE ) ) mode = icc->modes[0]; else if( iu->bu->flags & BEE_USER_AWAY ) mode = icc->modes[1]; else mode = icc->modes[2]; if( !mode ) irc_channel_del_user( ic, iu, IRC_CDU_PART, NULL ); else { irc_channel_add_user( ic, iu ); irc_channel_user_set_mode( ic, iu, mode ); } } }
int irc_channel_free(irc_channel_t *ic) { irc_t *irc; GSList *l; if (ic == NULL) { return 0; } irc = ic->irc; if (ic->flags & IRC_CHANNEL_JOINED) { irc_channel_del_user(ic, irc->user, IRC_CDU_KICK, "Cleaning up channel"); } if (ic->f->_free) { ic->f->_free(ic); } while (ic->set) { set_del(&ic->set, ic->set->key); } irc->channels = g_slist_remove(irc->channels, ic); while (ic->users) { g_free(ic->users->data); ic->users = g_slist_remove(ic->users, ic->users->data); } for (l = irc->users; l; l = l->next) { irc_user_t *iu = l->data; if (iu->last_channel == ic) { iu->last_channel = irc->default_channel; } } if (ic->pastebuf_timer) { b_event_remove(ic->pastebuf_timer); } g_free(ic->name); g_free(ic->topic); g_free(ic->topic_who); g_free(ic); return 1; }
static void irc_cmd_part( irc_t *irc, char **cmd ) { irc_channel_t *ic; if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) { irc_send_num( irc, 403, "%s :No such channel", cmd[1] ); } else if( irc_channel_del_user( ic, irc->user, IRC_CDU_PART, cmd[2] ) ) { if( ic->f->part ) ic->f->part( ic, NULL ); } else { irc_send_num( irc, 442, "%s :You're not on that channel", cmd[1] ); } }
static void cmd_identify(irc_t *irc, char **cmd) { storage_status_t status; gboolean load = TRUE; char *password = cmd[1]; if (irc->status & USTATUS_IDENTIFIED) { irc_rootmsg(irc, "You're already logged in."); return; } if (cmd[1] == NULL) { } else if (strncmp(cmd[1], "-no", 3) == 0) { load = FALSE; password = cmd[2]; if (password == NULL) { irc->status |= OPER_HACK_IDENTIFY_NOLOAD; } } else if (strncmp(cmd[1], "-force", 6) == 0) { password = cmd[2]; if (password == NULL) { irc->status |= OPER_HACK_IDENTIFY_FORCE; } } else if (irc->b->accounts != NULL) { irc_rootmsg(irc, "You're trying to identify yourself, but already have " "at least one IM account set up. " "Use \x02identify -noload\x02 or \x02identify -force\x02 " "instead (see \x02help identify\x02)."); return; } if (password == NULL) { irc_rootmsg(irc, "About to identify, use /OPER to enter the password"); irc->status |= OPER_HACK_IDENTIFY; return; } status = auth_check_pass(irc, irc->user->nick, password); if (load && (status == STORAGE_OK)) { status = storage_load(irc, password); } switch (status) { case STORAGE_INVALID_PASSWORD: irc_rootmsg(irc, "Incorrect password"); break; case STORAGE_NO_SUCH_USER: irc_rootmsg(irc, "The nick is (probably) not registered"); break; case STORAGE_OK: irc_rootmsg(irc, "Password accepted%s", load ? ", settings and accounts loaded" : ""); irc->status |= USTATUS_IDENTIFIED; irc_umode_set(irc, "+R", 1); if (irc->caps & CAP_SASL) { irc_user_t *iu = irc->user; irc_send_num(irc, 900, "%s!%s@%s %s :You are now logged in as %s", iu->nick, iu->user, iu->host, iu->nick, iu->nick); } bitlbee_whatsnew(irc); /* The following code is a bit hairy now. With takeover support, we shouldn't immediately auto_connect in case we're going to offer taking over an existing session. Do it in 200ms since that should give the parent process enough time to come back to us. */ if (load) { irc_channel_auto_joins(irc, NULL); if (!set_getbool(&irc->default_channel->set, "auto_join")) { irc_channel_del_user(irc->default_channel, irc->user, IRC_CDU_PART, "auto_join disabled " "for this channel."); } if (set_getbool(&irc->b->set, "auto_connect")) { irc->login_source_id = b_timeout_add(200, cmd_identify_finish, irc); } } /* If ipc_child_identify() returns FALSE, it means we're already sure that there's no takeover target (only possible in 1-process daemon mode). Start auto_connect immediately. */ if (!ipc_child_identify(irc) && load) { cmd_identify_finish(irc, 0, 0); } break; case STORAGE_OTHER_ERROR: default: irc_rootmsg(irc, "Unknown error while loading configuration"); break; } }