📄 yahoochat.c
字号:
/* * gaim * * Gaim is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> * (marv on irc.freenode.net) * Some code borrowed from libyahoo2, copyright (C) 2002, Philip * S Tellis <philip . tellis AT gmx . net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "debug.h"#include "prpl.h"#include "conversation.h"#include "notify.h"#include "util.h"#include "internal.h"#include "yahoo.h"#include "yahoochat.h"#include "ycht.h"#define YAHOO_CHAT_ID (1)/* prototype(s) */static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout);/* special function to log us on to the yahoo chat service */static void yahoo_chat_online(GaimConnection *gc){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; if (yd->wm) { ycht_connection_open(gc); return; } pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YAHOO_STATUS_AVAILABLE,0); yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); yahoo_packet_hash(pkt, 6, "abcde"); yahoo_send_packet(yd, pkt); yahoo_packet_free(pkt);}/* this is slow, and different from the gaim_* version in that it (hopefully) won't add a user twice */void yahoo_chat_add_users(GaimConvChat *chat, GList *newusers){ GList *i; for (i = newusers; i; i = i->next) { if (gaim_conv_chat_find_user(chat, i->data)) continue; gaim_conv_chat_add_user(chat, i->data, NULL, GAIM_CBFLAGS_NONE, TRUE); }}void yahoo_chat_add_user(GaimConvChat *chat, const char *user, const char *reason){ if (gaim_conv_chat_find_user(chat, user)) return; gaim_conv_chat_add_user(chat, user, reason, GAIM_CBFLAGS_NONE, TRUE);}static GaimConversation *yahoo_find_conference(GaimConnection *gc, const char *name){ struct yahoo_data *yd; GSList *l; yd = gc->proto_data; for (l = yd->confs; l; l = l->next) { GaimConversation *c = l->data; if (!gaim_utf8_strcasecmp(gaim_conversation_get_name(c), name)) return c; } return NULL;}void yahoo_process_conference_invite(GaimConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; GString *members = NULL; GHashTable *components; if (pkt->status == 2) return; /* XXX */ members = g_string_sized_new(512); for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 1: /* us, but we already know who we are */ break; case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 50: /* inviter */ who = pair->value; g_string_append_printf(members, "%s\n", who); break; case 52: /* invitee (me) */ case 53: /* members */ g_string_append_printf(members, "%s\n", pair->value); break; case 58: msg = yahoo_string_decode(gc, pair->value, FALSE); break; case 13: /* ? */ break; } } if (!room) { g_string_free(members, TRUE); return; } components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_replace(components, g_strdup("room"), room); if (msg) g_hash_table_replace(components, g_strdup("topic"), msg); g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); if (members) { g_hash_table_replace(components, g_strdup("members"), g_strdup(members->str)); } serv_got_chat_invite(gc, room, who, msg, components); g_string_free(members, TRUE);}void yahoo_process_conference_decline(GaimConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 54: who = pair->value; break; case 14: msg = yahoo_string_decode(gc, pair->value, FALSE); break; } } if (who && room) { /* make sure we're in the room before we process a decline message for it */ if(yahoo_find_conference(gc, room)) { char *tmp; tmp = g_strdup_printf(_("%s declined your conference invitation to room \"%s\" because \"%s\"."), who, room, msg?msg:""); gaim_notify_info(gc, NULL, _("Invitation Rejected"), tmp); g_free(tmp); } g_free(room); if (msg) g_free(msg); }}void yahoo_process_conference_logon(GaimConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; GaimConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 53: who = pair->value; break; } } if (who && room) { c = yahoo_find_conference(gc, room); if (c) yahoo_chat_add_user(GAIM_CONV_CHAT(c), who, NULL); g_free(room); }}void yahoo_process_conference_logoff(GaimConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; GaimConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 56: who = pair->value; break; } } if (who && room) { c = yahoo_find_conference(gc, room); if (c) gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); g_free(room); }}void yahoo_process_conference_message(GaimConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; char *msg2; int utf8 = 0; GaimConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 3: who = pair->value; break; case 14: msg = pair->value; break; case 97: utf8 = strtol(pair->value, NULL, 10); break; } } if (room && who && msg) { msg2 = yahoo_string_decode(gc, msg, utf8); c = yahoo_find_conference(gc, room); if (!c) return; msg = yahoo_codes_to_html(msg2); serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), who, 0, msg, time(NULL)); g_free(msg); g_free(msg2); } if (room) g_free(room);}/* this is a confirmation of yahoo_chat_online(); */void yahoo_process_chat_online(GaimConnection *gc, struct yahoo_packet *pkt){ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; if (pkt->status == 1) yd->chat_online = 1;}/* this is basicly the opposite of chat_online */void yahoo_process_chat_logout(GaimConnection *gc, struct yahoo_packet *pkt){ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GSList *l; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; if (pair->key == 1) if (g_ascii_strcasecmp(pair->value, gaim_connection_get_display_name(gc))) return; } if (pkt->status == 1) { yd->chat_online = 0; if (yd->in_chat) yahoo_c_leave(gc, YAHOO_CHAT_ID); }}void yahoo_process_chat_join(GaimConnection *gc, struct yahoo_packet *pkt){ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GaimConversation *c = NULL; GSList *l; GList *members = NULL; char *room = NULL; char *topic = NULL; char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; if (pkt->status == -1) { gaim_notify_error(gc, NULL, _("Failed to join chat"), _("Maybe the room is full?")); return; } 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 105: 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 && gaim_utf8_strcasecmp(room, yd->chat_name)) yahoo_chat_leave(gc, room, gaim_connection_get_display_name(gc), FALSE); c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (room && (!c || gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) && members && ((g_list_length(members) > 1) || !g_ascii_strcasecmp(members->data, gaim_connection_get_display_name(gc)))) { int i; GList *flags = NULL; for (i = 0; i < g_list_length(members); i++) flags = g_list_append(flags, GINT_TO_POINTER(GAIM_CBFLAGS_NONE)); if (c && gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) { /* this might be a hack, but oh well, it should nicely */ char *tmpmsg; gaim_conversation_set_name(c, room); c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members, flags); tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room); gaim_conv_chat_write(GAIM_CONV_CHAT(c), "", tmpmsg, GAIM_MESSAGE_SYSTEM, time(NULL)); g_free(tmpmsg); } else { c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members, flags); } } else if (c) { yahoo_chat_add_users(GAIM_CONV_CHAT(c), members); } g_list_free(members); g_free(room); if (topic) g_free(topic);}void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt){ char *who = NULL; char *room = NULL; GSList *l; struct yahoo_data *yd; yd = gc->proto_data; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; if (pair->key == 104) room = yahoo_string_decode(gc, pair->value, TRUE); if (pair->key == 109) who = pair->value; } if (who && room) { GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (c && !gaim_utf8_strcasecmp(gaim_conversation_get_name(c), room)) gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); } if (room) g_free(room);}void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt){ char *room = NULL, *who = NULL, *msg = NULL, *msg2; int msgtype = 1, utf8 = 1; /* default to utf8 */ GaimConversation *c = NULL; GSList *l; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 97: utf8 = strtol(pair->value, NULL, 10); break; case 104: room = yahoo_string_decode(gc, pair->value, TRUE); break; case 109: who = pair->value; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -