コード例 #1
0
ファイル: irc_commands.c プロジェクト: dkrisman/Bitlbee
static void irc_cmd_userhost( irc_t *irc, char **cmd )
{
	int i;
	
	/* [TV] Usable USERHOST-implementation according to
		RFC1459. Without this, mIRC shows an error
		while connecting, and the used way of rejecting
		breaks standards.
	*/
	
	for( i = 1; cmd[i]; i ++ )
	{
		irc_user_t *iu = irc_user_by_name( irc, cmd[i] );
		
		if( iu )
			irc_send_num( irc, 302, ":%s=%c%s@%s", iu->nick,
			              irc_user_get_away( iu ) ? '-' : '+',
			              iu->user, iu->host );
	}
}
コード例 #2
0
ファイル: root_commands.c プロジェクト: EionRobb/bitlbee
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);
	}
}