libpurple/protocols/qq/qq.c

changeset 23950
a974649cdb89
parent 23877
bfcad9d2254d
child 23957
398b1414aa67
equal deleted inserted replaced
23949:9ec519c1b341 23950:a974649cdb89
38 #include "server.h" 38 #include "server.h"
39 #include "util.h" 39 #include "util.h"
40 40
41 #include "buddy_info.h" 41 #include "buddy_info.h"
42 #include "buddy_opt.h" 42 #include "buddy_opt.h"
43 #include "buddy_status.h" 43 #include "buddy_list.h"
44 #include "char_conv.h" 44 #include "char_conv.h"
45 #include "crypt.h" 45 #include "crypt.h"
46 #include "group.h" 46 #include "group.h"
47 #include "group_find.h" 47 #include "group_find.h"
48 #include "group_im.h" 48 #include "group_im.h"
49 #include "group_info.h" 49 #include "group_info.h"
50 #include "group_join.h" 50 #include "group_join.h"
51 #include "group_opt.h" 51 #include "group_opt.h"
52 #include "header_info.h" 52 #include "header_info.h"
53 #include "im.h" 53 #include "im.h"
54 #include "keep_alive.h" 54 #include "qq_process.h"
55 #include "login_logout.h" 55 #include "qq_base.h"
56 #include "packet_parse.h" 56 #include "packet_parse.h"
57 #include "qq.h" 57 #include "qq.h"
58 #include "qq_network.h" 58 #include "qq_network.h"
59 #include "send_file.h" 59 #include "send_file.h"
60 #include "utils.h" 60 #include "utils.h"
235 235
236 /* a floating text when mouse is on the icon, show connection status here */ 236 /* a floating text when mouse is on the icon, show connection status here */
237 static void _qq_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) 237 static void _qq_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full)
238 { 238 {
239 qq_buddy *q_bud; 239 qq_buddy *q_bud;
240 gchar *ip_str; 240 gchar *tmp;
241 char *tmp; 241 GString *str;
242 const char *tmp2;
243 242
244 g_return_if_fail(b != NULL); 243 g_return_if_fail(b != NULL);
245 244
246 q_bud = (qq_buddy *) b->proto_data; 245 q_bud = (qq_buddy *) b->proto_data;
247 g_return_if_fail(q_bud != NULL); 246 if (q_bud == NULL)
248 247 return;
249 if (PURPLE_BUDDY_IS_ONLINE(b) && q_bud != NULL) 248
250 { 249 /* if (PURPLE_BUDDY_IS_ONLINE(b) && q_bud != NULL) */
251 ip_str = gen_ip_str(q_bud->ip); 250 if (q_bud->ip.s_addr != 0) {
252 if (strlen(ip_str) != 0) { 251 str = g_string_new(NULL);
253 if (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE) 252 g_string_printf(str, "%s:%d", inet_ntoa(q_bud->ip), q_bud->port);
254 tmp2 = _("TCP Address"); 253 if (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE) {
255 else 254 g_string_append(str, " TCP");
256 tmp2 = _("UDP Address"); 255 } else {
257 tmp = g_strdup_printf("%s:%d", ip_str, q_bud->port); 256 g_string_append(str, " UDP");
258 purple_notify_user_info_add_pair(user_info, tmp2, tmp);
259 g_free(tmp);
260 } 257 }
261 g_free(ip_str); 258 g_string_free(str, TRUE);
262 259 }
263 tmp = g_strdup_printf("%d", q_bud->age); 260
264 purple_notify_user_info_add_pair(user_info, _("Age"), tmp); 261 tmp = g_strdup_printf("%d", q_bud->age);
262 purple_notify_user_info_add_pair(user_info, _("Age"), tmp);
263 g_free(tmp);
264
265 switch (q_bud->gender) {
266 case QQ_BUDDY_GENDER_GG:
267 purple_notify_user_info_add_pair(user_info, _("Gender"), _("Male"));
268 break;
269 case QQ_BUDDY_GENDER_MM:
270 purple_notify_user_info_add_pair(user_info, _("Gender"), _("Female"));
271 break;
272 case QQ_BUDDY_GENDER_UNKNOWN:
273 purple_notify_user_info_add_pair(user_info, _("Gender"), _("Unknown"));
274 break;
275 default:
276 tmp = g_strdup_printf("Error (%d)", q_bud->gender);
277 purple_notify_user_info_add_pair(user_info, _("Gender"), tmp);
265 g_free(tmp); 278 g_free(tmp);
266 279 }
267 switch (q_bud->gender) { 280
268 case QQ_BUDDY_GENDER_GG: 281 if (q_bud->level) {
269 purple_notify_user_info_add_pair(user_info, _("Gender"), _("Male")); 282 tmp = g_strdup_printf("%d", q_bud->level);
270 break; 283 purple_notify_user_info_add_pair(user_info, _("Level"), tmp);
271 case QQ_BUDDY_GENDER_MM: 284 g_free(tmp);
272 purple_notify_user_info_add_pair(user_info, _("Gender"), _("Female")); 285 }
273 break; 286
274 case QQ_BUDDY_GENDER_UNKNOWN: 287 str = g_string_new(NULL);
275 purple_notify_user_info_add_pair(user_info, _("Gender"), _("Unknown")); 288 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) {
276 break; 289 g_string_append( str, _("Member") );
277 default: 290 }
278 tmp = g_strdup_printf("Error (%d)", q_bud->gender); 291 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_VIP) {
279 purple_notify_user_info_add_pair(user_info, _("Gender"), tmp); 292 g_string_append( str, _(" VIP") );
280 g_free(tmp); 293 }
281 } 294 if (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE) {
282 295 g_string_append( str, _(" TCP") );
283 if (q_bud->level) { 296 }
284 tmp = g_strdup_printf("%d", q_bud->level); 297 if (q_bud->comm_flag & QQ_COMM_FLAG_MOBILE) {
285 purple_notify_user_info_add_pair(user_info, _("Level"), tmp); 298 g_string_append( str, _(" FromMobile") );
286 g_free(tmp); 299 }
287 } 300 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) {
288 /* For debugging */ 301 g_string_append( str, _(" BindMobile") );
289 /* 302 }
290 g_string_append_printf(tooltip, "\n<b>Flag:</b> %01x", q_bud->flag1); 303 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO) {
291 g_string_append_printf(tooltip, "\n<b>CommFlag:</b> %01x", q_bud->comm_flag); 304 g_string_append( str, _(" Video") );
292 g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version); 305 }
293 */ 306
294 } 307 if (q_bud->ext_flag & QQ_EXT_FLAG_SPACE) {
308 g_string_append( str, _(" Space") );
309 }
310 purple_notify_user_info_add_pair(user_info, _("Flag"), str->str);
311
312 g_string_free(str, TRUE);
313
314 #ifdef DEBUG
315 tmp = g_strdup_printf( "%s (%04X)",
316 qq_get_ver_desc(q_bud->client_version),
317 q_bud->client_version );
318 purple_notify_user_info_add_pair(user_info, _("Ver"), tmp);
319 g_free(tmp);
320
321 tmp = g_strdup_printf( "Ext 0x%X, Comm 0x%X",
322 q_bud->ext_flag, q_bud->comm_flag );
323 purple_notify_user_info_add_pair(user_info, _("Flag"), tmp);
324 g_free(tmp);
325 #endif
295 } 326 }
296 327
297 /* we can show tiny icons on the four corners of buddy icon, */ 328 /* we can show tiny icons on the four corners of buddy icon, */
298 static const char *_qq_list_emblem(PurpleBuddy *b) 329 static const char *_qq_list_emblem(PurpleBuddy *b)
299 { 330 {
300 /* each char** are refering to a filename in pixmaps/purple/status/default/ */ 331 /* each char** are refering to a filename in pixmaps/purple/status/default/ */
301 332 qq_buddy *q_bud;
302 qq_buddy *q_bud = b->proto_data; 333
303 334 if (!b || !(q_bud = b->proto_data)) {
304 if (q_bud) { 335 return NULL;
305 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) 336 }
306 return "qq_member"; 337
307 /* 338 if (q_bud->comm_flag & QQ_COMM_FLAG_MOBILE)
308 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO) 339 return "mobile";
309 return "video"; 340 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO)
310 */ 341 return "video";
311 } 342 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER)
343 return "qq_member";
312 344
313 return NULL; 345 return NULL;
314 } 346 }
315 347
316 /* QQ away status (used to initiate QQ away packet) */ 348 /* QQ away status (used to initiate QQ away packet) */
391 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); 423 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG);
392 424
393 group = qq_group_find_by_channel(gc, channel); 425 group = qq_group_find_by_channel(gc, channel);
394 g_return_val_if_fail(group != NULL, -1); 426 g_return_val_if_fail(group != NULL, -1);
395 427
428 purple_debug_info("QQ_MESG", "Send qun mesg in utf8: %s\n", message);
396 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); 429 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT);
397 msg_with_qq_smiley = purple_smiley_to_qq(msg); 430 msg_with_qq_smiley = purple_smiley_to_qq(msg);
398 qq_send_packet_group_im(gc, group, msg_with_qq_smiley); 431 qq_send_packet_group_im(gc, group, msg_with_qq_smiley);
399 g_free(msg); 432 g_free(msg);
400 g_free(msg_with_qq_smiley); 433 g_free(msg_with_qq_smiley);
477 GString *info; 510 GString *info;
478 511
479 qd = (qq_data *) gc->proto_data; 512 qd = (qq_data *) gc->proto_data;
480 info = g_string_new("<html><body>\n"); 513 info = g_string_new("<html><body>\n");
481 514
482 g_string_append_printf(info, _("<b>Current Online</b>: %d<br>\n"), qd->all_online); 515 g_string_append_printf(info, _("<b>Current Online</b>: %d<br>\n"), qd->total_online);
483 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->last_get_online)); 516 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->last_get_online));
484 517
485 g_string_append(info, "<hr>\n"); 518 g_string_append(info, "<hr>\n");
486 519
487 g_string_append_printf(info, _("<b>Server</b>: %s: %d<br>\n"), qd->server_name, qd->real_port); 520 g_string_append_printf(info, _("<b>Server</b>: %s: %d<br>\n"), qd->server_name, qd->real_port);
488 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP"); 521 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP");
489 g_string_append_printf(info, _("<b>Real hostname</b>: %s: %d<br>\n"), qd->real_hostname, qd->real_port); 522 g_string_append_printf(info, _("<b>Real hostname</b>: %s: %d<br>\n"), qd->real_hostname, qd->real_port);
490 g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), qd->my_ip); 523 g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), inet_ntoa(qd->my_ip));
491 524
492 g_string_append(info, "<hr>\n"); 525 g_string_append(info, "<hr>\n");
493 g_string_append(info, "<i>Information below may not be accurate</i><br>\n"); 526 g_string_append(info, "<i>Information below may not be accurate</i><br>\n");
494 527
495 g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time)); 528 g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time));
632 m = g_list_append(m, act); 665 m = g_list_append(m, act);
633 /* } */ 666 /* } */
634 #endif 667 #endif
635 668
636 return m; 669 return m;
637 }
638
639
640 static void qq_keep_alive(PurpleConnection *gc)
641 {
642 qq_group *group;
643 qq_data *qd;
644 GList *list;
645
646 if (NULL == (qd = (qq_data *) gc->proto_data))
647 return;
648
649 list = qd->groups;
650 while (list != NULL) {
651 group = (qq_group *) list->data;
652 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER ||
653 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN)
654 /* no need to get info time and time again, online members enough */
655 qq_send_cmd_group_get_online_members(gc, group);
656
657 list = list->next;
658 }
659
660 qq_send_packet_keep_alive(gc);
661 } 670 }
662 671
663 /* convert chat nickname to qq-uid to get this buddy info */ 672 /* convert chat nickname to qq-uid to get this buddy info */
664 /* who is the nickname of buddy in QQ chat-room (Qun) */ 673 /* who is the nickname of buddy in QQ chat-room (Qun) */
665 static void _qq_get_chat_buddy_info(PurpleConnection *gc, gint channel, const gchar *who) 674 static void _qq_get_chat_buddy_info(PurpleConnection *gc, gint channel, const gchar *who)
716 NULL, /* reject chat invite */ 725 NULL, /* reject chat invite */
717 NULL, /* get_chat_name */ 726 NULL, /* get_chat_name */
718 NULL, /* chat_invite */ 727 NULL, /* chat_invite */
719 NULL, /* chat_leave */ 728 NULL, /* chat_leave */
720 NULL, /* chat_whisper */ 729 NULL, /* chat_whisper */
721 _qq_chat_send, /* chat_send */ 730 _qq_chat_send, /* chat_send */
722 qq_keep_alive, /* keepalive */ 731 NULL, /* keepalive */
723 NULL, /* register_user */ 732 NULL, /* register_user */
724 _qq_get_chat_buddy_info, /* get_cb_info */ 733 _qq_get_chat_buddy_info, /* get_cb_info */
725 NULL, /* get_cb_away */ 734 NULL, /* get_cb_away */
726 NULL, /* alias_buddy */ 735 NULL, /* alias_buddy */
727 NULL, /* group_buddy */ 736 NULL, /* group_buddy */
736 NULL, /* find_blist_chat */ 745 NULL, /* find_blist_chat */
737 qq_roomlist_get_list, /* roomlist_get_list */ 746 qq_roomlist_get_list, /* roomlist_get_list */
738 qq_roomlist_cancel, /* roomlist_cancel */ 747 qq_roomlist_cancel, /* roomlist_cancel */
739 NULL, /* roomlist_expand_category */ 748 NULL, /* roomlist_expand_category */
740 NULL, /* can_receive_file */ 749 NULL, /* can_receive_file */
741 qq_send_file, /* send_file */ 750 NULL, /* qq_send_file send_file */
742 NULL, /* new xfer */ 751 NULL, /* new xfer */
743 NULL, /* offline_message */ 752 NULL, /* offline_message */
744 NULL, /* PurpleWhiteboardPrplOps */ 753 NULL, /* PurpleWhiteboardPrplOps */
745 NULL, /* send_raw */ 754 NULL, /* send_raw */
746 NULL, /* roomlist_room_serialize */ 755 NULL, /* roomlist_room_serialize */
800 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 809 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
801 810
802 option = purple_account_option_bool_new(_("Connect using TCP"), "use_tcp", TRUE); 811 option = purple_account_option_bool_new(_("Connect using TCP"), "use_tcp", TRUE);
803 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 812 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
804 813
814 option = purple_account_option_int_new(_("resend interval(s)"), "resend_interval", 10);
815 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
816
817 option = purple_account_option_int_new(_("Keep alive interval(s)"), "keep_alive_interval", 60);
818 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
819
820 option = purple_account_option_int_new(_("Update interval(s)"), "update_interval", 300);
821 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
822
805 my_protocol = plugin; 823 my_protocol = plugin;
806 824
807 purple_prefs_add_none("/plugins/prpl/qq"); 825 purple_prefs_add_none("/plugins/prpl/qq");
808 purple_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE); 826 purple_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE);
809 purple_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE); 827 purple_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE);

mercurial