13870
|
1 /**
|
|
2 * The QQ2003C protocol plugin
|
|
3 *
|
|
4 * for gaim
|
|
5 *
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 *
|
|
22 *
|
|
23 * OICQ encryption algorithm
|
|
24 * Convert from ASM code provided by PerlOICQ
|
|
25 *
|
|
26 * Puzzlebird, Nov-Dec 2002
|
|
27 */
|
|
28
|
|
29 // START OF FILE
|
|
30 /*****************************************************************************/
|
|
31 #include "debug.h" // gaim_debug
|
|
32 #include "server.h" // serv_got_update
|
|
33
|
|
34 #include "utils.h" // uid_to_gaim_name
|
|
35 #include "packet_parse.h" // create_packet
|
|
36 #include "buddy_list.h" // qq_send_packet_get_buddies_online
|
|
37 #include "buddy_status.h" // QQ_BUDDY_ONLINE_NORMAL
|
|
38 #include "crypt.h" // qq_crypt
|
|
39 #include "header_info.h" // cmd alias
|
|
40 #include "keep_alive.h"
|
|
41 #include "send_core.h" // qq_send_cmd
|
|
42
|
|
43 #define QQ_UPDATE_ONLINE_INTERVAL 300 // in sec
|
|
44
|
|
45 /*****************************************************************************/
|
|
46 // send keep-alive packet to QQ server (it is a heart-beat)
|
|
47 void qq_send_packet_keep_alive(GaimConnection * gc)
|
|
48 {
|
|
49 qq_data *qd;
|
|
50 guint8 *raw_data, *cursor;
|
|
51
|
|
52 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
53
|
|
54 qd = (qq_data *) gc->proto_data;
|
|
55 raw_data = g_newa(guint8, 4);
|
|
56 cursor = raw_data;
|
|
57
|
|
58 // In fact, we can send whatever we like to server
|
|
59 // with this command, server return the same result including
|
|
60 // the amount of online QQ users, my ip and port
|
|
61 create_packet_dw(raw_data, &cursor, qd->uid);
|
|
62
|
|
63 qq_send_cmd(gc, QQ_CMD_KEEP_ALIVE, TRUE, 0, TRUE, raw_data, 4);
|
|
64
|
|
65 } // qq_send_packet_keep_alive
|
|
66
|
|
67 /*****************************************************************************/
|
|
68 // parse the return of keep-alive packet, it includes some system information
|
|
69 void qq_process_keep_alive_reply(guint8 * buf, gint buf_len, GaimConnection * gc) {
|
|
70 qq_data *qd;
|
|
71 gint len;
|
|
72 gchar *data, **segments; // the returns are gchar, no need guint8
|
|
73
|
|
74 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
75 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
76
|
|
77 qd = (qq_data *) gc->proto_data;
|
|
78 len = buf_len;
|
|
79 data = g_newa(guint8, len);
|
|
80
|
|
81 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
82 if (NULL == (segments = split_data(data, len, "\x1f", 6 /* 5->6, protocal changed by gfhuang*, the last one is 60, don't know what it is */)))
|
|
83 return;
|
|
84 // segments[0] and segment[1] are all 0x30 ("0")
|
|
85 qd->all_online = strtol(segments[2], NULL, 10);
|
|
86 if(0 == qd->all_online) //added by gfhuang
|
|
87 gaim_connection_error(gc, _("Keep alive error, seems connection lost!"));
|
|
88 g_free(qd->my_ip);
|
|
89 qd->my_ip = g_strdup(segments[3]);
|
|
90 qd->my_port = strtol(segments[4], NULL, 10);
|
|
91 g_strfreev(segments);
|
|
92 } else
|
|
93 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n");
|
|
94
|
|
95 // we refresh buddies's online status periodically
|
|
96 // qd->lasat_get_online is updated when setting get_buddies_online packet
|
|
97 if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL)
|
|
98 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
|
|
99
|
|
100 } // qq_process_keep_alive_reply
|
|
101
|
|
102 /*****************************************************************************/
|
|
103 // refresh all buddies online/offline,
|
|
104 // after receiving reply for get_buddies_online packet
|
|
105 void qq_refresh_all_buddy_status(GaimConnection * gc)
|
|
106 {
|
|
107 time_t now;
|
|
108 GList *list;
|
|
109 qq_data *qd;
|
|
110 qq_buddy *q_bud;
|
|
111
|
|
112 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
113
|
|
114 qd = (qq_data *) (gc->proto_data);
|
|
115 now = time(NULL);
|
|
116 list = qd->buddies;
|
|
117 g_return_if_fail(qd != NULL);
|
|
118
|
|
119 while (list != NULL) {
|
|
120 q_bud = (qq_buddy *) list->data;
|
|
121 if (q_bud != NULL && now > q_bud->last_refresh + QQ_UPDATE_ONLINE_INTERVAL
|
|
122 && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) { // by gfhuang
|
|
123 q_bud->status = QQ_BUDDY_ONLINE_OFFLINE;
|
|
124 qq_update_buddy_contact(gc, q_bud);
|
|
125 }
|
|
126 list = list->next;
|
|
127 } // while
|
|
128 } // qq_refresh_all_buddy_status
|
|
129
|
|
130 /*****************************************************************************/
|
|
131 void qq_update_buddy_contact(GaimConnection * gc, qq_buddy * q_bud)
|
|
132 {
|
|
133 gchar *name;
|
|
134 // gboolean online;
|
|
135 GaimBuddy *bud;
|
|
136 g_return_if_fail(gc != NULL && q_bud != NULL);
|
|
137
|
|
138 name = uid_to_gaim_name(q_bud->uid);
|
|
139 bud = gaim_find_buddy(gc->account, name);
|
|
140 g_return_if_fail(bud != NULL);
|
|
141
|
|
142 if (bud != NULL) {
|
|
143 gaim_blist_server_alias_buddy(bud, q_bud->nickname); //server by gfhuang
|
|
144 q_bud->last_refresh = time(NULL);
|
|
145
|
|
146 // gaim support signon and idle time
|
|
147 // but it is not much useful for QQ, I do not use them it
|
|
148 // serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); //disable by gfhuang
|
|
149 char *status_id = "available";
|
|
150 switch(q_bud->status) {
|
|
151 case QQ_BUDDY_OFFLINE:
|
|
152 status_id = "offline";
|
|
153 break;
|
|
154 case QQ_BUDDY_ONLINE_NORMAL:
|
|
155 status_id = "available";
|
|
156 break;
|
|
157 case QQ_BUDDY_ONLINE_OFFLINE:
|
|
158 status_id = "offline";
|
|
159 break;
|
|
160 case QQ_BUDDY_ONLINE_AWAY:
|
|
161 status_id = "away";
|
|
162 break;
|
|
163 case QQ_BUDDY_ONLINE_INVISIBLE:
|
|
164 status_id = "invisible";
|
|
165 break;
|
|
166 default:
|
|
167 status_id = "invisible";
|
|
168 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown status by gfhuang: %x\n", q_bud->status);
|
|
169 break;
|
|
170 }
|
|
171 gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id);
|
|
172 gaim_prpl_got_user_status(gc->account, name, status_id, NULL);
|
|
173 } // if bud
|
|
174 else
|
|
175 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy by gfhuang: %d\n", q_bud->uid);
|
|
176
|
|
177 gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version);
|
|
178 g_free(name);
|
|
179 } // qq_update_buddy_contact
|
|
180
|
|
181 /*****************************************************************************/
|
|
182 // END OF FILE
|