Esempio n. 1
0
void irc_msg_topic(struct irc_conn *irc, const char *name, const char *from, char **args)
{
	char *chan, *topic, *msg, *nick, *tmp, *tmp2;
	PurpleConversation *convo;

	if (!strcmp(name, "topic")) {
		chan = args[0];
		topic = irc_mirc2txt (args[1]);
	} else {
		chan = args[1];
		topic = irc_mirc2txt (args[2]);
	}

	convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chan, irc->account);
	if (!convo) {
		purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got a topic for %s, which doesn't exist\n", chan);
		g_free(topic);
		return;
	}

	/* If this is an interactive update, print it out */
	tmp = g_markup_escape_text(topic, -1);
	tmp2 = purple_markup_linkify(tmp);
	g_free(tmp);
	if (!strcmp(name, "topic")) {
		const char *current_topic = purple_conv_chat_get_topic(PURPLE_CONV_CHAT(convo));
		if (!(current_topic != NULL && strcmp(tmp2, current_topic) == 0))
		{
			char *nick_esc;
			nick = irc_mask_nick(from);
			nick_esc = g_markup_escape_text(nick, -1);
			purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), nick, topic);
			if (*tmp2)
				msg = g_strdup_printf(_("%s has changed the topic to: %s"), nick_esc, tmp2);
			else
				msg = g_strdup_printf(_("%s has cleared the topic."), nick_esc);
			g_free(nick_esc);
			g_free(nick);
			purple_conv_chat_write(PURPLE_CONV_CHAT(convo), from, msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
			g_free(msg);
		}
	} else {
		char *chan_esc = g_markup_escape_text(chan, -1);
		msg = g_strdup_printf(_("The topic for %s is: %s"), chan_esc, tmp2);
		g_free(chan_esc);
		purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), NULL, topic);
		purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "", msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
		g_free(msg);
	}
	g_free(tmp2);
	g_free(topic);
}
Esempio n. 2
0
void yahoo_c_join(PurpleConnection *gc, GHashTable *data)
{
	YahooData *yd;
	char *room, *topic, *type;
	PurpleConversation *c;

	yd = (YahooData *) gc->proto_data;
	if (!yd)
		return;

	room = g_hash_table_lookup(data, "room");
	if (!room)
		return;

	topic = g_hash_table_lookup(data, "topic");
	if (!topic)
		topic = "";

	if ((type = g_hash_table_lookup(data, "type")) && !strcmp(type, "Conference")) {
		int id;
		const char *members = g_hash_table_lookup(data, "members");
		id = yd->conf_id++;
		c = serv_got_joined_chat(gc, id, room);
		yd->confs = g_slist_prepend(yd->confs, c);
		purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), purple_connection_get_display_name(gc), topic);
		yahoo_conf_join(yd, c, purple_connection_get_display_name(gc), room, topic, members);
		return;
	} else {
		const char *id;
		/*if (yd->in_chat)
			yahoo_chat_leave(gc, room,
					purple_connection_get_display_name(gc),
					FALSE);*/

		id = g_hash_table_lookup(data, "id");

		if (!yd->chat_online) {
			yahoo_chat_online(gc);
			g_free(yd->pending_chat_room);
			yd->pending_chat_room = g_strdup(room);
			g_free(yd->pending_chat_id);
			yd->pending_chat_id = g_strdup(id);
			g_free(yd->pending_chat_topic);
			yd->pending_chat_topic = g_strdup(topic);
			g_free(yd->pending_chat_goto);
			yd->pending_chat_goto = NULL;
		} else {
			yahoo_chat_join(gc, purple_connection_get_display_name(gc), room, topic, id);
		}
		return;
	}
}
Esempio n. 3
0
void hon_parse_chat_topic(PurpleConnection* gc,gchar* buffer){
    PurpleConversation *convo;
    gchar * topic_raw, * topic_html, * msg;
    guint32 chan_id = read_guint32(buffer);
    convo = purple_find_chat(gc,chan_id);
    if (!convo) {
        purple_debug(PURPLE_DEBUG_ERROR, HON_DEBUG_PREFIX, "Got a topic for %d, which doesn't exist\n", chan_id);
    }
    else
    {
        topic_raw = hon_strip(buffer,FALSE);
        topic_html = hon2html(buffer);
        msg = g_strdup_printf(_("Topic changed to '%s'."), topic_html);

        purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), NULL, topic_raw);
        purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "", msg, PURPLE_MESSAGE_SYSTEM, time(NULL));

        g_free(topic_raw);
        g_free(topic_html);
        g_free(msg);
    }
}
Esempio n. 4
0
/* show group conversation window */
PurpleConversation *qq_room_conv_open(PurpleConnection *gc, qq_room_data *rmd)
{
	PurpleConversation *conv;
	qq_data *qd;
	gchar *topic_utf8;

	g_return_val_if_fail(rmd != NULL, NULL);
	g_return_val_if_fail(rmd->title_utf8, NULL);
	qd = (qq_data *) gc->proto_data;

	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
			rmd->title_utf8, purple_connection_get_account(gc));
	if (conv != NULL)	{
		/* show only one conversation per room */
		return conv;
	}

	serv_got_joined_chat(gc, rmd->id, rmd->title_utf8);
	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, rmd->title_utf8, purple_connection_get_account(gc));
	if (conv != NULL) {
		if (rmd->notice_utf8 != NULL) {
			topic_utf8 = g_strdup_printf("%u %s", rmd->ext_id, rmd->notice_utf8);
		} else {
			topic_utf8 = g_strdup_printf("%u", rmd->ext_id);
		}
		purple_debug_info("QQ", "Chat topic = %s\n", topic_utf8);
		purple_conv_chat_set_topic(PURPLE_CONV_CHAT(conv), NULL, topic_utf8);
		g_free(topic_utf8);

		if (rmd->is_got_buddies)
			qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_ONLINES, rmd->id);
		else
			qq_update_room(gc, 0, rmd->id);
		return conv;
	}
	return NULL;
}
Esempio n. 5
0
void hon_parse_channel_update(PurpleConnection *gc,gchar* buffer){
    PurpleConversation *convo;
    guint8 unknown;
    guint32 op_count,chat_id;
    gchar* topic,*topic_raw;
    GHashTable* ops = NULL;
    gchar* buf;
    gchar* room; 
    chat_id = read_guint32(buffer);
    room = read_string(buffer);
    unknown = read_byte(buffer);
    buf = read_string(buffer);
    topic = hon2html(buf);
    topic_raw = hon_strip(buf,FALSE);
    op_count = read_guint32(buffer);
    ops = g_hash_table_new(g_direct_hash,g_direct_equal);
    if (op_count != 0)
    {
        guint32 op_id,op_type;
        while (op_count--)
        {
            op_id = read_guint32(buffer);
            op_type = read_byte(buffer);
            g_hash_table_insert(ops,GINT_TO_POINTER(op_id),GINT_TO_POINTER(op_type));
        }
    }
    convo = purple_find_chat(gc,chat_id);
    if (!convo)
        convo = serv_got_joined_chat(gc, chat_id, room);
    purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), NULL, topic_raw);
    if (convo->data != NULL)
        g_hash_table_destroy(convo->data);
    convo->data = ops;
    g_free(topic);
    g_free(topic_raw);
}
Esempio n. 6
0
static void
nap_callback(gpointer data, gint source, PurpleInputCondition condition) {
    PurpleConnection *gc = data;
    struct nap_data *ndata = gc->proto_data;
    PurpleAccount *account = NULL;
    PurpleConversation *c = NULL;
    PurpleNotifyUserInfo *pnui = NULL;
    gchar *buf = NULL, *buf2 = NULL, *buf3 = NULL, **res = NULL;
    unsigned short header[2] = { 0 , 0 };
    int len = 0;
    int command = 0;
    int i;

    account = purple_connection_get_account(gc);

    if (read(source, (void*)header, 4) != 4) {
        purple_connection_error(gc, _("Unable to read header from server"));
        return;
    }

    len = header[0];
    command = header[1];
    buf = (gchar *)g_malloc((len + 1) * sizeof(gchar));
    buf[len] = '\0';

    i = 0;
    do {
        int tmp = read(source, buf + i, len - i);
        if (tmp <= 0) {
            g_free(buf);
            buf = g_strdup_printf(_("Unable to read message from server: %s.  Command is %hd, length is %hd."), strerror(errno), len, command);
            purple_connection_error(gc, buf);
            g_free(buf);
            return;
        }
        i += tmp;
    } while (i != len);

    purple_debug(PURPLE_DEBUG_MISC, "napster", "R %3hd: %s\n", command, buf);

    switch (command) {
    case 000: /* MSG_SERVER_ERROR */
        purple_notify_error(gc, NULL, buf, NULL);
        purple_input_remove(gc->inpa);
        gc->inpa = 0;
        close(source);
        purple_connection_error(gc, _("Unknown server error."));
        break;

    case 003: /* MSG_SERVER_EMAIL */
        purple_debug(PURPLE_DEBUG_MISC, "napster", "Registered with e-mail address: %s\n", buf);
        ndata->email = g_strdup(buf);

        /* Our signon is complete */
        purple_connection_set_state(gc, PURPLE_CONNECTED);

        /* Send the server our buddy list */
        nap_send_buddylist(gc);

        break;

    case 201: /* MSG_SERVER_SEARCH_RESULT */
        res = g_strsplit(buf, " ", 0);
        purple_prpl_got_user_status(account, res[0], "available", NULL);
        g_strfreev(res);
        break;

    case 202: /* MSG_SERVER_SEARCH_END */
        purple_prpl_got_user_status(account, buf, "offline", NULL);
        break;

    case 205: /* MSG_CLIENT_PRIVMSG */
        res = g_strsplit(buf, " ", 2);
        buf2 = g_markup_escape_text(res[1], -1);
        serv_got_im(gc, res[0], buf2, 0, time(NULL));
        g_free(buf2);
        g_strfreev(res);
        break;

    case 209: /* MSG_SERVER_USER_SIGNON */
        /* USERNAME SPEED */
        res = g_strsplit(buf, " ", 2);
        purple_prpl_got_user_status(account, res[0], "available", NULL);
        g_strfreev(res);
        break;

    case 210: /* MSG_SERVER_USER_SIGNOFF */
        /* USERNAME SPEED */
        res = g_strsplit(buf, " ", 2);
        purple_prpl_got_user_status(account, res[0], "offline", NULL);
        g_strfreev(res);
        break;

    case 214: /* MSG_SERVER_STATS */
        res = g_strsplit(buf, " ", 3);
        buf2 = g_strdup_printf(_("users: %s, files: %s, size: %sGB"), res[0], res[1], res[2]);
        serv_got_im(gc, "server", buf2, 0, time(NULL));
        g_free(buf2);
        g_strfreev(res);
        break;

    case 301: /* MSG_SERVER_HOTLIST_ACK */
        /* Our buddy was added successfully */
        break;

    case 302: /* MSG_SERVER_HOTLIST_ERROR */
        buf2 = g_strdup_printf(_("Unable to add \"%s\" to your Napster hotlist"), buf);
        purple_notify_error(gc, NULL, buf2, NULL);
        g_free(buf2);
        break;

    case 316: /* MSG_SERVER_DISCONNECTING */
        /* we have been kicked off =^( */
        purple_connection_error(gc, _("You were disconnected from the server."));
        break;

    case 401: /* MSG_CLIENT_PART */
        c = nap_find_chat(gc, buf);
        if (c)
            serv_got_chat_left(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)));
        break;

    case 403: /* MSG_SERVER_PUBLIC */
        res = g_strsplit(buf, " ", 3);
        c = nap_find_chat(gc, res[0]);
        if (c)
            serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), res[1], 0, res[2], time((time_t)NULL));
        g_strfreev(res);
        break;

    case 404: /* MSG_SERVER_NOSUCH */
        /* abused by opennap servers to broadcast stuff */
        buf2 = g_markup_escape_text(buf, -1);
        serv_got_im(gc, "server", buf2, 0, time(NULL));
        g_free(buf2);
        break;

    case 405: /* MSG_SERVER_JOIN_ACK */
        c = nap_find_chat(gc, buf);
        if (!c)
            serv_got_joined_chat(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), buf);
        break;

    case 407: /* MSG_SERVER_PART */
        res = g_strsplit(buf, " ", 0);
        c = nap_find_chat(gc, res[0]);
        purple_conv_chat_remove_user(PURPLE_CONV_CHAT(c), res[1], NULL);
        g_strfreev(res);
        break;

    case 406: /* MSG_SERVER_JOIN */
    case 408: /* MSG_SERVER_CHANNEL_USER_LIST */
        res = g_strsplit(buf, " ", 4);
        c = nap_find_chat(gc, res[0]);
        purple_conv_chat_add_user(PURPLE_CONV_CHAT(c), res[1], NULL, PURPLE_CBFLAGS_NONE, TRUE);
        g_strfreev(res);
        break;

    case 409: /* MSG_SERVER_CHANNEL_USER_LIST_END */
        break;

    case 410: /* MSG_SERVER_TOPIC */
        /* display the topic in the channel */
        res = g_strsplit(buf, " ", 2);
        c = nap_find_chat(gc, res[0]);
        purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), res[0], res[1]);
        g_strfreev(res);
        break;

    case 603: /* MSG_CLIENT_WHOIS */
        buf2 = g_strdup_printf(_("%s requested your information"), buf);
        serv_got_im(gc, "server", buf2, 0, time(NULL));
        g_free(buf2);
        break;

    case 604: /* MSG_SERVER_WHOIS_RESPONSE */
        /* XXX - Format is:   "Elite" 37 " " "Active" 0 0 0 0 "purple 0.63cvs" 0 0 192.168.1.41 32798 0 unknown flounder */
        res = g_strsplit(buf, " ", 2);
        /* res[0] == username */
        pnui = purple_notify_user_info_new();
        purple_notify_user_info_add_pair(pnui, _("Napster User Info:"), res[1]);
        purple_notify_userinfo(gc, res[0], pnui, NULL, NULL);
        g_strfreev(res);
        break;

    case 621:
    case 622: /* MSG_CLIENT_MOTD */
        /* also replaces MSG_SERVER_MOTD, so we should display it */
        buf2 = g_markup_escape_text(buf, -1);
        serv_got_im(gc, "motd", buf2, 0, time(NULL));
        g_free(buf2);
        break;

    case 627: /* MSG_CLIENT_WALLOP */
        /* abused by opennap server maintainers to broadcast stuff */
        buf2 = g_markup_escape_text(buf, -1);
        serv_got_im(gc, "wallop", buf2, 0, time(NULL));
        g_free(buf2);
        break;

    case 628: /* MSG_CLIENT_ANNOUNCE */
        buf2 = g_markup_escape_text(buf, -1);
        serv_got_im(gc, "announce", buf2, 0, time(NULL));
        g_free(buf);
        break;

    case 748: /* MSG_SERVER_GHOST */
        /* Looks like someone logged in as us! =-O */
        purple_connection_error(gc, _("You have signed on from another location."));
        break;

    case 751: /* MSG_CLIENT_PING */
        buf2 = g_strdup_printf(_("%s requested a PING"), buf);
        serv_got_im(gc, "server", buf2, 0, time(NULL));
        g_free(buf2);
        /* send back a pong */
        /* MSG_CLIENT_PONG */
        nap_write_packet(gc, 752, "%s", buf);
        break;

    case 752: /* MSG_CLIENT_PONG */
        buf2 = g_strdup_printf("Received pong from %s", buf);
        purple_notify_info(gc, NULL, buf2, NULL);
        g_free(buf2);
        break;

    case 824: /* MSG_CLIENT_EMOTE */
        res = g_strsplit(buf, " ", 3);
        buf2 = g_strndup(res[2]+1, strlen(res[2]) - 2); /* chomp off the surround quotes */
        buf3 = g_strdup_printf("/me %s", buf2);
        g_free(buf2);
        if ((c = nap_find_chat(gc, res[0]))) {
            purple_conv_chat_write(PURPLE_CONV_CHAT(c), res[1], buf3, PURPLE_MESSAGE_NICK, time(NULL));
        }
        g_free(buf3);
        g_strfreev(res);
        break;

    default:
        purple_debug(PURPLE_DEBUG_MISC, "napster", "Unknown packet %hd: %s\n", command, buf);
        break;
    }

    g_free(buf);
}
Esempio n. 7
0
void hon_parse_chat_entering(PurpleConnection *gc,gchar* buffer)
{
    PurpleConversation *convo;
    hon_account* hon = gc->proto_data;
    guint8 unknown,flags;
    guint32 op_count,chat_id,count;
    guint32 purple_flags = 0;
    gchar* topic,*topic_raw;
    const gchar* extra;
    GHashTable* ops = NULL;
    gchar* buf;

    gchar* room = read_string(buffer);
    chat_id = read_guint32(buffer);
    unknown = read_byte(buffer);
    buf = read_string(buffer);
    topic = hon2html(buf);
    topic_raw = hon_strip(buf,FALSE);
    op_count = read_guint32(buffer);
    ops = g_hash_table_new(g_direct_hash,g_direct_equal);
    if (op_count != 0)
    {
        guint32 op_id,op_type;
        while (op_count--)
        {
            op_id = read_guint32(buffer);
            op_type = read_byte(buffer);
            g_hash_table_insert(ops,GINT_TO_POINTER(op_id),GINT_TO_POINTER(op_type));
        }
    }
    count = read_guint32(buffer);
    convo = serv_got_joined_chat(gc, chat_id, room);
    purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), NULL, topic_raw);

    while (count--)
    {
        guint32 account_id, unk32;
        guint8 status;
        const gchar* nickname;
        gchar *flag,*shield,*icon;
        buf = read_string(buffer);
        nickname = buf;
        account_id = read_guint32(buffer);
        status = read_byte(buffer);
        flags = read_byte(buffer);

        flag = read_string(buffer);
        shield = read_string(buffer);
        icon = read_string(buffer);
        unk32 = read_guint32(buffer);

        purple_debug_info(HON_DEBUG_PREFIX, "room participant: %s , id=%d,status=%d,flags=%d,flag:%s,shield=%s,icon=%s\n",
            nickname,account_id,status,flags,flag,shield,icon);
#if 0
        honpurple_get_icon(gc->account,nickname,icon,account_id);
#endif
        
        

        //flags |= GPOINTER_TO_INT(g_hash_table_lookup(ops,GINT_TO_POINTER(account_id)));
        flags = GPOINTER_TO_INT(g_hash_table_lookup(ops,GINT_TO_POINTER(account_id)));
        
        flags &= 0xF;
        purple_flags = PURPLE_CBFLAGS_NONE;

        if (flags == HON_FLAGS_CHAT_ADMINISTRATOR)
            purple_flags = PURPLE_CBFLAGS_FOUNDER;
        else if (flags == HON_FLAGS_CHAT_LEADER)
            purple_flags = PURPLE_CBFLAGS_OP;
        else if (flags == HON_FLAGS_CHAT_OFFICER)
            purple_flags = PURPLE_CBFLAGS_HALFOP;


        extra = nickname;
        nickname = hon_normalize_nick(gc->account,nickname);
        purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo), nickname, extra, purple_flags, FALSE);
        if (!g_hash_table_lookup(hon->id2nick,GINT_TO_POINTER(account_id)))
        {
            g_hash_table_insert(hon->id2nick,GINT_TO_POINTER(account_id),g_strdup(nickname));
        }
    }
    flags = 0;
    purple_flags = PURPLE_CBFLAGS_NONE;

    flags = GPOINTER_TO_INT(g_hash_table_lookup(ops,GINT_TO_POINTER(hon->self.account_id)));
    if (convo->data != NULL)
        g_hash_table_destroy(convo->data);
    convo->data = ops;
    
    
    if (flags == HON_FLAGS_CHAT_ADMINISTRATOR)
        purple_flags = PURPLE_CBFLAGS_FOUNDER;
    else if (flags == HON_FLAGS_CHAT_LEADER)
        purple_flags = PURPLE_CBFLAGS_OP;
    else if (flags == HON_FLAGS_CHAT_OFFICER)
        purple_flags = PURPLE_CBFLAGS_HALFOP;


    purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "", topic, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
    g_free(topic);
    g_free(topic_raw);

    purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo), hon->self.nickname, NULL,purple_flags , FALSE);
}
Esempio n. 8
0
void yahoo_process_chat_join(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	YahooData *yd = (YahooData *) gc->proto_data;
	PurpleConversation *c = NULL;
	GSList *l;
	GList *members = NULL;
	GList *roomies = NULL;
	char *room = NULL;
	char *topic = NULL;
	char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber;

	if (pkt->status == -1) {
		/* We can't join */
		struct yahoo_pair *pair = pkt->hash->data;
		gchar const *failed_to_join = _("Failed to join chat");
		switch (atoi(pair->value)) {
			case 0xFFFFFFFA: /* -6 */
				purple_notify_error(gc, NULL, failed_to_join, _("Unknown room"));
				break;
			case 0xFFFFFFF1: /* -15 */
				purple_notify_error(gc, NULL, failed_to_join, _("Maybe the room is full"));
				break;
			case 0xFFFFFFDD: /* -35 */
				purple_notify_error(gc, NULL, failed_to_join, _("Not available"));
				break;
			default:
				purple_notify_error(gc, NULL, failed_to_join,
						_("Unknown error. You may need to logout and wait five minutes before being able to rejoin a chatroom"));
		}
		return;
	}

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;

		switch (pair->key) {

		case 104:
			g_free(room);
			room = yahoo_string_decode(gc, pair->value, TRUE);
			break;
		case 105:
			g_free(topic);
			topic = yahoo_string_decode(gc, pair->value, TRUE);
			break;
		case 128:
			someid = pair->value;
			break;
		case 108: /* number of joiners */
			break;
		case 129:
			someotherid = pair->value;
			break;
		case 130:
			somebase64orhashosomething = pair->value;
			break;
		case 126:
			somenegativenumber = pair->value;
			break;
		case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */
			break;
		case 61: /*this looks similar to 130 */
			break;

		/* the previous section was just room info. this next section is
		   info about individual room members, (including us) */

		case 109: /* the yahoo id */
			members = g_list_append(members, pair->value);
			break;
		case 110: /* age */
			break;
		case 141: /* nickname */
			break;
		case 142: /* location */
			break;
		case 113: /* bitmask */
			break;
		}
	}

	if (room && yd->chat_name && purple_utf8_strcasecmp(room, yd->chat_name))
		yahoo_chat_leave(gc, room,
				purple_connection_get_display_name(gc), FALSE);

	c = purple_find_chat(gc, YAHOO_CHAT_ID);

	if (room && (!c || purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) &&
	    members && (members->next ||
	     !g_ascii_strcasecmp(members->data, purple_connection_get_display_name(gc)))) {
		GList *l;
		GList *flags = NULL;
		for (l = members; l; l = l->next)
			flags = g_list_prepend(flags, GINT_TO_POINTER(PURPLE_CBFLAGS_NONE));
		if (c && purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) {
			/* this might be a hack, but oh well, it should nicely */
			char *tmpmsg;

			purple_conversation_set_name(c, room);

			c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room);
			if (topic) {
				purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), NULL, topic);
				/* Also print the topic to the backlog so that the captcha link is clickable */
				purple_conv_chat_write(PURPLE_CONV_CHAT(c), "", topic, PURPLE_MESSAGE_SYSTEM, time(NULL));
			}
			yd->in_chat = 1;
			yd->chat_name = g_strdup(room);
			purple_conv_chat_add_users(PURPLE_CONV_CHAT(c), members, NULL, flags, FALSE);

			tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room);
			purple_conv_chat_write(PURPLE_CONV_CHAT(c), "", tmpmsg, PURPLE_MESSAGE_SYSTEM, time(NULL));
			g_free(tmpmsg);
		} else {
			c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room);
			if (topic) {
				purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), NULL, topic);
				/* Also print the topic to the backlog so that the captcha link is clickable */
				purple_conv_chat_write(PURPLE_CONV_CHAT(c), "", topic, PURPLE_MESSAGE_SYSTEM, time(NULL));
			}
			yd->in_chat = 1;
			yd->chat_name = g_strdup(room);
			purple_conv_chat_add_users(PURPLE_CONV_CHAT(c), members, NULL, flags, FALSE);
		}
		g_list_free(flags);
	} else if (c) {
		if (topic) {
			const char *cur_topic = purple_conv_chat_get_topic(PURPLE_CONV_CHAT(c));
			if (cur_topic == NULL || strcmp(cur_topic, topic) != 0)
				purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), NULL, topic);
		}
		yahoo_chat_add_users(PURPLE_CONV_CHAT(c), members);
	}

	if (account->deny && c) {
		PurpleConversationUiOps *ops = purple_conversation_get_ui_ops(c);
		for (l = account->deny; l != NULL; l = l->next) {
			for (roomies = members; roomies; roomies = roomies->next) {
				if (!purple_utf8_strcasecmp((char *)l->data, roomies->data)) {
					purple_debug_info("yahoo", "Ignoring room member %s in room %s\n" , (char *)roomies->data, room ? room : "");
					purple_conv_chat_ignore(PURPLE_CONV_CHAT(c),roomies->data);
					ops->chat_update_user(c, roomies->data);
				}
			}
		}
	}
	g_list_free(roomies);
	g_list_free(members);
	g_free(room);
	g_free(topic);
}
Esempio n. 9
0
void qq_process_room_cmd_get_info(guint8 *data, gint data_len, guint32 action, PurpleConnection *gc)
{
	qq_data *qd;
	qq_room_data *rmd;
	qq_buddy_data *bd;
	PurpleChat *chat;
	PurpleConversation *conv;
	guint8 organization, role;
	guint16 max_members;
	guint32 resend_flag, member_uid, id, qun_id, last_uid;
	gint bytes; 
	guint num=0;
	guint8 has_more=0;
	gchar *topic;

	g_return_if_fail(data != NULL && data_len > 0);
	qd = (qq_data *) gc->proto_data;

	/* qq_show_packet("Room Info", data, data_len); */

	bytes = 0;
	bytes += qq_get32(&id, data + bytes);
	g_return_if_fail(id > 0);

	bytes += qq_get32(&qun_id, data + bytes);
	g_return_if_fail(qun_id > 0);

	chat = qq_room_find_or_new(gc, id, qun_id);
	g_return_if_fail(chat != NULL);
	rmd = qq_room_data_find(gc, id);
	g_return_if_fail(rmd != NULL);

	bytes += qq_get32(&resend_flag, data + bytes);		//first 00 00 00 03, then 00 00 00 02

	if (resend_flag == 0x00000003)
	{
		bytes += qq_get8(&(rmd->type8), data + bytes);
		bytes += 4;	//maybe vip sign
		bytes += qq_get32(&(rmd->creator_uid), data + bytes);
		if (rmd->creator_uid == qd->uid)
			rmd->my_role = QQ_ROOM_ROLE_ADMIN;
		bytes += qq_get8(&(rmd->auth_type), data + bytes);
		bytes += 4	;	/* oldCategory */
		bytes += 2;	// 00 00
		bytes += qq_get32(&(rmd->category), data + bytes);
		bytes += qq_get16(&max_members, data + bytes);
		bytes += 1; 
		bytes += 8;
		purple_debug_info("QQ", "type: %u creator: %u category: %u max_members: %u\n",
			rmd->type8, rmd->creator_uid, rmd->category, max_members);

		bytes += qq_get_vstr(&(rmd->name), NULL, sizeof(guint8), data + bytes);
		bytes += 2;	/* 0x0000 */
		bytes += qq_get_vstr(&(rmd->bulletin), NULL, sizeof(guint8), data + bytes);
		bytes += qq_get_vstr(&(rmd->intro), NULL, sizeof(guint8), data + bytes);
		bytes += qq_get_vstr(&(rmd->token), NULL, sizeof(guint16), data + bytes);
		purple_debug_info("QQ", "room [%s] bulletin [%s] intro [%s] \n",
			rmd->name, rmd->bulletin, rmd->intro);
		bytes += 2;		//Unknown
		bytes += qq_get32(&last_uid, data + bytes);	/* last_uid of this recv, request more with it */
		bytes += qq_get8(&has_more, data + bytes);	/* if there are more, request again */
		/* now comes the member list separated by 0x00 */
	} else {
		/* resend_flag 00 00 00 02 is special, start with random one only 5 bytes */
		bytes += qq_get32(&member_uid, data + bytes);
		num++;
		bytes += qq_get8(&organization, data + bytes);
		bd = qq_room_buddy_find_or_new(gc, rmd, member_uid);
	}


	while (bytes < data_len) {
		bytes += qq_get32(&member_uid, data + bytes);
		num++;
		bytes += qq_get8(&organization, data + bytes);
		bytes += qq_get8(&role, data + bytes);

#if 0
		if(organization != 0 || role != 0) {
			purple_debug_info("QQ", "%u, organization=%d, role=%d\n", member_uid, organization, role);
		}
#endif
		
		bd = qq_room_buddy_find_or_new(gc, rmd, member_uid);
		if (bd != NULL)
			bd->role = role;
	}

	purple_debug_info("QQ", "Qun \"%s\" has received %d members\n", rmd->name, num);

	if (has_more)
	{
		qq_send_room_cmd_mess(gc, QQ_ROOM_CMD_GET_INFO, id, NULL, 0,
			0, last_uid);
	} else {
		qq_room_update_chat_info(chat, rmd);
		if (action == QQ_ROOM_INFO_DISPLAY) {
			room_info_display(gc, rmd);
		}

		conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
			rmd->name, purple_connection_get_account(gc));
		if(NULL == conv) {
			purple_debug_warning("QQ", "Conversation \"%s\" is not opened\n", rmd->name);
			return;
		}

		topic = g_strdup_printf("%u %s", rmd->qun_id, rmd->bulletin);
		purple_debug_info("QQ", "Set chat topic to %s\n", topic);
		purple_conv_chat_set_topic(PURPLE_CONV_CHAT(conv), NULL, topic);
		g_free(topic);
	}
}