Esempio n. 1
0
void yahoo_c_join(PurpleConnection *gc, GHashTable *data)
{
	YahooData *yd;
	char *room, *topic, *type;
	PurpleChatConversation *c;

	yd = purple_connection_get_protocol_data(gc);
	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 = purple_serv_got_joined_chat(gc, id, room);
		yd->confs = g_slist_prepend(yd->confs, c);
		purple_chat_conversation_set_topic(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. 2
0
static void ycht_process_chatjoin(YchtConn *ycht, YchtPkt *pkt)
{
	char *room, *topic;
	PurpleConnection *gc = ycht->gc;
	PurpleChatConversation *c = NULL;
	gboolean new_room = FALSE;
	char **members;
	int i;

	room = g_list_nth_data(pkt->data, 0);
	topic = g_list_nth_data(pkt->data, 1);
	if (!g_list_nth_data(pkt->data, 4))
		return;
	if (!room)
		return;

	members = g_strsplit(g_list_nth_data(pkt->data, 4), "\001", 0);
	for (i = 0; members[i]; i++) {
		char *tmp = strchr(members[i], '\002');
		if (tmp)
			*tmp = '\0';
	}

	if (g_list_length(pkt->data) > 5)
		new_room = TRUE;

	if (new_room && ycht->changing_rooms) {
		purple_serv_got_chat_left(gc, YAHOO_CHAT_ID);
		ycht->changing_rooms = FALSE;
		c = purple_serv_got_joined_chat(gc, YAHOO_CHAT_ID, room);
	} else {
		c = purple_conversations_find_chat(gc, YAHOO_CHAT_ID);
	}

	if (topic)
		purple_chat_conversation_set_topic(c, NULL, topic);

	for (i = 0; members[i]; i++) {
		if (new_room) {
			/*if (!strcmp(members[i], purple_connection_get_display_name(ycht->gc)))
				continue;*/
			purple_chat_conversation_add_user(c, members[i], NULL, PURPLE_CHAT_USER_NONE, TRUE);
		} else {
			yahoo_chat_add_user(c, members[i], NULL);
		}
	}

	g_strfreev(members);
}
Esempio n. 3
0
static void set_chat_topic_fn(PurpleChatConversation *from, PurpleChatConversation *to,
                              int id, const char *room, gpointer userdata) {
  const char *topic = (const char *)userdata;
  const char *username = purple_account_get_username(purple_conversation_get_account(PURPLE_CONVERSATION(from)));
  char *msg;

  purple_chat_conversation_set_topic(to, username, topic);

  if (topic && *topic)
    msg = g_strdup_printf(_("%s sets topic to: %s"), username, topic);
  else
    msg = g_strdup_printf(_("%s clears topic"), username);

  purple_conversation_write_message(PURPLE_CONVERSATION(to), username, msg,
                                    PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,
                                    time(NULL));
  g_free(msg);
}
Esempio n. 4
0
void yahoo_process_chat_join(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	YahooData *yd = purple_connection_get_protocol_data(gc);
	PurpleChatConversation *c = NULL;
	GSList *l;
	GList *members = NULL;
	GList *roomies = NULL;
	char *room = NULL;
	char *topic = NULL;

	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"),
					purple_request_cpar_from_connection(gc));
				break;
			case 0xFFFFFFF1: /* -15 */
				purple_notify_error(gc, NULL, failed_to_join,
					_("Maybe the room is full"),
					purple_request_cpar_from_connection(gc));
				break;
			case 0xFFFFFFDD: /* -35 */
				purple_notify_error(gc, NULL, failed_to_join,
					_("Not available"),
					purple_request_cpar_from_connection(gc));
				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"),
					purple_request_cpar_from_connection(gc));
		}
		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: /* some id */
			break;
		case 108: /* number of joiners */
			break;
		case 129: /* some other id */
			break;
		case 130: /* some base64 or hash or something */
			break;
		case 126: /* some negative number */
			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 */
			if (g_utf8_validate(pair->value, -1, NULL)) {
				members = g_list_append(members, pair->value);
			} else {
				purple_debug_warning("yahoo", "yahoo_process_chat_join "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			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_conversations_find_chat(gc, YAHOO_CHAT_ID);

	if (room && (!c || purple_chat_conversation_has_left(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_CHAT_USER_NONE));
		if (c && purple_chat_conversation_has_left(c)) {
			/* this might be a hack, but oh well, it should nicely */
			char *tmpmsg;

			purple_conversation_set_name(PURPLE_CONVERSATION(c), room);

			c = purple_serv_got_joined_chat(gc, YAHOO_CHAT_ID, room);
			if (topic) {
				purple_chat_conversation_set_topic(c, NULL, topic);
				/* Also print the topic to the backlog so that the captcha link is clickable */
				purple_conversation_write_system_message(PURPLE_CONVERSATION(c), topic, 0);
			}
			yd->in_chat = 1;
			yd->chat_name = g_strdup(room);
			purple_chat_conversation_add_users(c, members, NULL, flags, FALSE);

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

	if (purple_account_privacy_get_denied(account) && c) {
		PurpleConversationUiOps *ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(c));
		for (l = purple_account_privacy_get_denied(account); 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_chat_conversation_ignore(c,roomies->data);
					ops->chat_update_user(purple_chat_conversation_find_user(c, roomies->data));
				}
			}
		}
	}
	g_list_free(roomies);
	g_list_free(members);
	g_free(room);
	g_free(topic);
}