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 ); } } }
static void cmd_blist(irc_t *irc, char **cmd) { int online = 0, away = 0, offline = 0, ismatch = 0; GSList *l; GRegex *regex = NULL; GError *error = NULL; char s[256]; char *format; int n_online = 0, n_away = 0, n_offline = 0; if (cmd[1] && g_strcasecmp(cmd[1], "all") == 0) { online = offline = away = 1; } else if (cmd[1] && g_strcasecmp(cmd[1], "offline") == 0) { offline = 1; } else if (cmd[1] && g_strcasecmp(cmd[1], "away") == 0) { away = 1; } else if (cmd[1] && g_strcasecmp(cmd[1], "online") == 0) { online = 1; } else { online = away = 1; } if (cmd[2]) { regex = g_regex_new(cmd[2], G_REGEX_CASELESS, 0, &error); } if (error) { irc_rootmsg(irc, error->message); g_error_free(error); } if (strchr(irc->umode, 'b') != NULL) { format = "%s\t%s\t%s"; } else { format = "%-16.16s %-40.40s %s"; } irc_rootmsg(irc, format, "Nick", "Handle/Account", "Status"); if (irc->root->last_channel && strcmp(set_getstr(&irc->root->last_channel->set, "type"), "control") != 0) { irc->root->last_channel = NULL; } for (l = irc->users; l; l = l->next) { irc_user_t *iu = l->data; bee_user_t *bu = iu->bu; if (!regex || g_regex_match(regex, iu->nick, 0, NULL)) { ismatch = 1; } else { ismatch = 0; } if (!bu || (irc->root->last_channel && !irc_channel_wants_user(irc->root->last_channel, iu))) { continue; } if ((bu->flags & (BEE_USER_ONLINE | BEE_USER_AWAY)) == BEE_USER_ONLINE) { if (ismatch == 1 && online == 1) { char st[256] = "Online"; if (bu->status_msg) { g_snprintf(st, sizeof(st) - 1, "Online (%s)", bu->status_msg); } g_snprintf(s, sizeof(s) - 1, "%s %s", bu->handle, bu->ic->acc->tag); irc_rootmsg(irc, format, iu->nick, s, st); } n_online++; } if ((bu->flags & BEE_USER_ONLINE) && (bu->flags & BEE_USER_AWAY)) { if (ismatch == 1 && away == 1) { g_snprintf(s, sizeof(s) - 1, "%s %s", bu->handle, bu->ic->acc->tag); irc_rootmsg(irc, format, iu->nick, s, irc_user_get_away(iu)); } n_away++; } if (!(bu->flags & BEE_USER_ONLINE)) { if (ismatch == 1 && offline == 1) { g_snprintf(s, sizeof(s) - 1, "%s %s", bu->handle, bu->ic->acc->tag); irc_rootmsg(irc, format, iu->nick, s, "Offline"); } n_offline++; } } irc_rootmsg(irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline); if (regex) { g_regex_unref(regex); } }