📄 yahoochat.c
字号:
case 117: msg = pair->value; break; case 124: msgtype = strtol(pair->value, NULL, 10); break; } } c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (!who || !c) { if (room) g_free(room); /* we still get messages after we part, funny that */ return; } if (!msg) { gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); return; } msg2 = yahoo_string_decode(gc, msg, utf8); msg = yahoo_codes_to_html(msg2); g_free(msg2); if (msgtype == 2 || msgtype == 3) { char *tmp; tmp = g_strdup_printf("/me %s", msg); g_free(msg); msg = tmp; } serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); g_free(msg);}void yahoo_process_chat_addinvite(GaimConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *msg = NULL; char *who = NULL; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 104: room = yahoo_string_decode(gc, pair->value, TRUE); break; case 129: /* room id? */ break; case 126: /* ??? */ break; case 117: msg = yahoo_string_decode(gc, pair->value, FALSE); break; case 119: who = pair->value; break; case 118: /* us */ break; } } if (room && who) { GHashTable *components; components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_replace(components, g_strdup("room"), g_strdup(room)); serv_got_chat_invite(gc, room, who, msg, components); } if (room) g_free(room); if (msg) g_free(msg);}void yahoo_process_chat_goto(GaimConnection *gc, struct yahoo_packet *pkt){ if (pkt->status == -1) gaim_notify_error(gc, NULL, _("Failed to join buddy in chat"), _("Maybe they're not in a chat?"));}/* * Functions dealing with conferences * I think conference names are always ascii. */void yahoo_conf_leave(struct yahoo_data *yd, const char *room, const char *dn, GList *who){ struct yahoo_packet *pkt; GList *w; gaim_debug_misc("yahoo", "leaving conference %s\n", room); pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); for (w = who; w; w = w->next) { const char *name = gaim_conv_chat_cb_get_name(w->data); yahoo_packet_hash(pkt, 3, name); } yahoo_packet_hash(pkt, 57, room); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt);}static int yahoo_conf_send(GaimConnection *gc, const char *dn, const char *room, GList *members, const char *what){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; GList *who; char *msg, *msg2; int utf8 = 1; msg = yahoo_html_to_codes(what); msg2 = yahoo_string_encode(gc, msg, &utf8); pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); for (who = members; who; who = who->next) { const char *name = gaim_conv_chat_cb_get_name(who->data); yahoo_packet_hash(pkt, 53, name); } yahoo_packet_hash(pkt, 57, room); yahoo_packet_hash(pkt, 14, msg2); if (utf8) yahoo_packet_hash(pkt, 97, "1"); /* utf-8 */ yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); g_free(msg); g_free(msg2); return 0;}static void yahoo_conf_join(struct yahoo_data *yd, GaimConversation *c, const char *dn, const char *room, const char *topic, const char *members){ struct yahoo_packet *pkt; char **memarr = NULL; int i; if (members) memarr = g_strsplit(members, "\n", 0); pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); yahoo_packet_hash(pkt, 3, dn); yahoo_packet_hash(pkt, 57, room); if (memarr) { for(i = 0 ; memarr[i]; i++) { if (!strcmp(memarr[i], "") || !strcmp(memarr[i], dn)) continue; yahoo_packet_hash(pkt, 3, memarr[i]); gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), memarr[i], NULL, GAIM_CBFLAGS_NONE, TRUE); } } yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); if (memarr) g_strfreev(memarr);}static void yahoo_conf_invite(GaimConnection *gc, GaimConversation *c, const char *dn, const char *buddy, const char *room, const char *msg){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; GList *members; char *msg2 = NULL; if (msg) msg2 = yahoo_string_encode(gc, msg, NULL); members = gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)); pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); yahoo_packet_hash(pkt, 51, buddy); yahoo_packet_hash(pkt, 57, room); yahoo_packet_hash(pkt, 58, msg?msg2:""); yahoo_packet_hash(pkt, 13, "0"); for(; members; members = members->next) { const char *name = gaim_conv_chat_cb_get_name(members->data); if (!strcmp(name, dn)) continue; yahoo_packet_hash(pkt, 52, name); yahoo_packet_hash(pkt, 53, name); } yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); if (msg) g_free(msg2);}/* * Functions dealing with chats */static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; GaimConversation *c; char *eroom; gboolean utf8 = 1; if (yd->wm) { g_return_if_fail(yd->ycht != NULL); ycht_chat_leave(yd->ycht, room, logout); return; } eroom = yahoo_string_encode(gc, room, &utf8); pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 104, eroom); yahoo_packet_hash(pkt, 109, dn); yahoo_packet_hash(pkt, 108, "1"); yahoo_packet_hash(pkt, 112, "0"); /* what does this one mean? */ yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); yd->in_chat = 0; if (yd->chat_name) { g_free(yd->chat_name); yd->chat_name = NULL; } if ((c = gaim_find_chat(gc, YAHOO_CHAT_ID))) serv_got_chat_left(gc, YAHOO_CHAT_ID); if (!logout) return; pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); yd->chat_online = 0; g_free(eroom);}/* borrowed from gtkconv.c */static gbooleanmeify(char *message, size_t len){ /* * Read /me-ify: If the message (post-HTML) starts with /me, * remove the "/me " part of it (including that space) and return TRUE. */ char *c; gboolean inside_html = 0; /* Umm.. this would be very bad if this happens. */ g_return_val_if_fail(message != NULL, FALSE); if (len == -1) len = strlen(message); for (c = message; *c != '\0'; c++, len--) { if (inside_html) { if (*c == '>') inside_html = FALSE; } else { if (*c == '<') inside_html = TRUE; else break; } } if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) { memmove(c, c + 4, len - 3); return TRUE; } return FALSE;}static int yahoo_chat_send(GaimConnection *gc, const char *dn, const char *room, const char *what){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; int me = 0; char *msg1, *msg2, *room2; gboolean utf8 = TRUE; if (yd->wm) { g_return_val_if_fail(yd->ycht != NULL, 1); return ycht_chat_send(yd->ycht, room, what); } msg1 = g_strdup(what); if (meify(msg1, -1)) me = 1; msg2 = yahoo_html_to_codes(msg1); g_free(msg1); msg1 = yahoo_string_encode(gc, msg2, &utf8); g_free(msg2); room2 = yahoo_string_encode(gc, room, NULL); pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); yahoo_packet_hash(pkt, 104, room2); yahoo_packet_hash(pkt, 117, msg1); if (me) yahoo_packet_hash(pkt, 124, "2"); else yahoo_packet_hash(pkt, 124, "1"); /* fixme: what about /think? (124=3) */ if (utf8) yahoo_packet_hash(pkt, 97, "1"); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); g_free(msg1); g_free(room2); return 0;}static void yahoo_chat_join(GaimConnection *gc, const char *dn, const char *room, const char *topic){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; char *room2; gboolean utf8 = TRUE; if (yd->wm) { g_return_if_fail(yd->ycht != NULL); ycht_chat_join(yd->ycht, room); return; } /* apparently room names are always utf8, or else always not utf8, * so we don't have to actually pass the flag in the packet. Or something. */ room2 = yahoo_string_encode(gc, room, &utf8); pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); yahoo_packet_hash(pkt, 62, "2"); yahoo_packet_hash(pkt, 104, room2); yahoo_packet_hash(pkt, 129, "0"); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); g_free(room2);}static void yahoo_chat_invite(GaimConnection *gc, const char *dn, const char *buddy, const char *room, const char *msg){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; char *room2, *msg2 = NULL; gboolean utf8 = TRUE; if (yd->wm) { g_return_if_fail(yd->ycht != NULL); ycht_chat_send_invite(yd->ycht, room, buddy, msg); return; } room2 = yahoo_string_encode(gc, room, &utf8); if (msg) msg2 = yahoo_string_encode(gc, msg, NULL); pkt = yahoo_packet_new(YAHOO_SERVICE_CHATADDINVITE, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 1, dn); yahoo_packet_hash(pkt, 118, buddy); yahoo_packet_hash(pkt, 104, room2); yahoo_packet_hash(pkt, 117, (msg2?msg2:"")); yahoo_packet_hash(pkt, 129, "0"); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt); g_free(room2); if (msg2) g_free(msg2);}void yahoo_chat_goto(GaimConnection *gc, const char *name){ struct yahoo_data *yd; struct yahoo_packet *pkt; yd = gc->proto_data; if (yd->wm) { g_return_if_fail(yd->ycht != NULL); ycht_chat_goto_user(yd->ycht, name); return; } if (!yd->chat_online) yahoo_chat_online(gc); pkt = yahoo_packet_new(YAHOO_SERVICE_CHATGOTO, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 109, name); yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); yahoo_packet_hash(pkt, 62, "2"); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt);}/* * These are the functions registered with the core * which get called for both chats and conferences. */void yahoo_c_leave(GaimConnection *gc, int id){ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GaimConversation *c; if (!yd) return; c = gaim_find_chat(gc, id); if (!c) return; if (id != YAHOO_CHAT_ID) { yahoo_conf_leave(yd, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c))); yd->confs = g_slist_remove(yd->confs, c); } else { yahoo_chat_leave(gc, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), TRUE); } serv_got_chat_left(gc, id);}int yahoo_c_send(GaimConnection *gc, int id, const char *what){ GaimConversation *c; int ret; struct yahoo_data *yd; yd = (struct yahoo_data *) gc->proto_data; if (!yd) return -1; c = gaim_find_chat(gc, id); if (!c) return -1; if (id != YAHOO_CHAT_ID) { ret = yahoo_conf_send(gc, gaim_connection_get_display_name(gc), gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); } else { ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), gaim_conversation_get_name(c), what); if (!ret)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -