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 // START OF FILE
|
|
24 /*****************************************************************************/
|
|
25 #include "debug.h" // gaim_debug
|
|
26 #include "conversation.h" // gaim_find_conversation_with_account
|
|
27
|
|
28 #include "buddy_status.h" // QQ_BUDDY_ONLINE_NORMAL
|
|
29 #include "char_conv.h" // convert_as_pascal_string
|
|
30 #include "group_find.h" // qq_group_find_by_internal_group_id
|
|
31 #include "group_hash.h" // qq_group_refresh
|
|
32 #include "group_info.h"
|
|
33 #include "buddy_status.h" // is_online
|
|
34 #include "group_network.h" // qq_send_group_cmd
|
|
35
|
|
36 // we check who needs to update member info every minutes
|
|
37 // this interval determines if their member info is outdated
|
|
38 #define QQ_GROUP_CHAT_REFRESH_NICKNAME_INTERNAL 180
|
|
39
|
|
40 /*****************************************************************************/
|
|
41 static gboolean _is_group_member_need_update_info(qq_buddy * member)
|
|
42 {
|
|
43 g_return_val_if_fail(member != NULL, FALSE);
|
|
44 return (member->nickname == NULL) ||
|
|
45 (time(NULL) - member->last_refresh) > QQ_GROUP_CHAT_REFRESH_NICKNAME_INTERNAL;
|
|
46 } // _is_group_member_need_update_info
|
|
47
|
|
48 /*****************************************************************************/
|
|
49 // this is done when we receive the reply to get_online_member sub_cmd
|
|
50 // all member are set offline, and then only those in reply packets are online
|
|
51 static void _qq_group_set_members_all_offline(qq_group * group)
|
|
52 {
|
|
53 GList *list;
|
|
54 qq_buddy *member;
|
|
55 g_return_if_fail(group != NULL);
|
|
56
|
|
57 list = group->members;
|
|
58 while (list != NULL) {
|
|
59 member = (qq_buddy *) list->data;
|
|
60 member->status = QQ_BUDDY_ONLINE_OFFLINE;
|
|
61 list = list->next;
|
|
62 } // while list
|
|
63 } // _qq_group_set_members_all_offline
|
|
64
|
|
65 /*****************************************************************************/
|
|
66 // send packet to get detailed information of one group
|
|
67 void qq_send_cmd_group_get_group_info(GaimConnection * gc, qq_group * group)
|
|
68 {
|
|
69 guint8 *raw_data, *cursor;
|
|
70 gint bytes, data_len;
|
|
71
|
|
72 g_return_if_fail(gc != NULL && group != NULL);
|
|
73
|
|
74 data_len = 5;
|
|
75 raw_data = g_newa(guint8, data_len);
|
|
76 cursor = raw_data;
|
|
77
|
|
78 bytes = 0;
|
|
79 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_GET_GROUP_INFO);
|
|
80 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
81
|
|
82 if (bytes != data_len)
|
|
83 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
84 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_GET_GROUP_INFO));
|
|
85 else
|
|
86 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
87 } // qq_send_cmd_group_get_group_info
|
|
88
|
|
89 /*****************************************************************************/
|
|
90 // send packet to get online group member, called by keep_alive
|
|
91 void qq_send_cmd_group_get_online_member(GaimConnection * gc, qq_group * group) {
|
|
92 guint8 *raw_data, *cursor;
|
|
93 gint bytes, data_len;
|
|
94
|
|
95 g_return_if_fail(gc != NULL && group != NULL);
|
|
96
|
|
97 // only get online members when conversation window is on
|
|
98 if (NULL == gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT/*gfhuang*/,group->group_name_utf8, gaim_connection_get_account(gc))) {
|
|
99 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
100 "Conv windows for \"%s\" is not on, do not get online members\n", group->group_name_utf8);
|
|
101 return;
|
|
102 } // if gaim_find_conversation_with_account
|
|
103
|
|
104 data_len = 5;
|
|
105 raw_data = g_newa(guint8, data_len);
|
|
106 cursor = raw_data;
|
|
107
|
|
108 bytes = 0;
|
|
109 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_GET_ONLINE_MEMBER);
|
|
110 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
111
|
|
112 if (bytes != data_len)
|
|
113 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
114 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_GET_ONLINE_MEMBER));
|
|
115 else
|
|
116 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
117 } // qq_send_cmd_group_search_group
|
|
118
|
|
119 /*****************************************************************************/
|
|
120 // send packet to get group member info
|
|
121 void qq_send_cmd_group_get_member_info(GaimConnection * gc, qq_group * group) {
|
|
122 guint8 *raw_data, *cursor;
|
|
123 gint bytes, data_len, i;
|
|
124 GList *list;
|
|
125 qq_buddy *member;
|
|
126
|
|
127 g_return_if_fail(gc != NULL && group != NULL);
|
|
128 for (i = 0, list = group->members; list != NULL; list = list->next) {
|
|
129 member = (qq_buddy *) list->data;
|
|
130 if (_is_group_member_need_update_info(member))
|
|
131 i++;
|
|
132 } // for i
|
|
133
|
|
134 if (i <= 0) {
|
|
135 gaim_debug(GAIM_DEBUG_INFO, "QQ", "No group member needs to to update info now.\n");
|
|
136 return;
|
|
137 } // if i
|
|
138
|
|
139 data_len = 5 + 4 * i;
|
|
140 raw_data = g_newa(guint8, data_len);
|
|
141 cursor = raw_data;
|
|
142
|
|
143 bytes = 0;
|
|
144 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_GET_MEMBER_INFO);
|
|
145 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
146
|
|
147 list = group->members;
|
|
148 while (list != NULL) {
|
|
149 member = (qq_buddy *) list->data;
|
|
150 if (_is_group_member_need_update_info(member))
|
|
151 bytes += create_packet_dw(raw_data, &cursor, member->uid);
|
|
152 list = list->next;
|
|
153 } // while list
|
|
154
|
|
155 if (bytes != data_len)
|
|
156 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
157 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_GET_MEMBER_INFO));
|
|
158 else
|
|
159 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
160 } // qq_send_cmd_group_get_member_info
|
|
161
|
|
162 /*****************************************************************************/
|
|
163 void qq_process_group_cmd_get_group_info(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
164 qq_group *group;
|
|
165 qq_data *qd;
|
|
166 guint8 orgnization, role; //gfhuang
|
|
167 guint16 unknown;
|
|
168 guint32 member_uid, internal_group_id;
|
|
169 gint pascal_len, i;
|
|
170 guint32 unknown4;
|
|
171 guint8 unknown1;
|
|
172
|
|
173 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
174 g_return_if_fail(data != NULL && len > 0);
|
|
175 qd = (qq_data *) gc->proto_data;
|
|
176
|
|
177 read_packet_dw(data, cursor, len, &(internal_group_id));
|
|
178 g_return_if_fail(internal_group_id > 0);
|
|
179
|
|
180 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
181 g_return_if_fail(group != NULL);
|
|
182
|
|
183 read_packet_dw(data, cursor, len, &(group->external_group_id));
|
|
184 read_packet_b(data, cursor, len, &(group->group_type));
|
|
185 read_packet_dw(data, cursor, len, &unknown4); //unknown 4 bytes, protocal changed by gfhuang
|
|
186 read_packet_dw(data, cursor, len, &(group->creator_uid));
|
|
187 read_packet_b(data, cursor, len, &(group->auth_type));
|
|
188 read_packet_dw(data, cursor, len, &unknown4); // oldCategory, by gfhuang
|
|
189 read_packet_w(data, cursor, len, &unknown);
|
|
190 read_packet_dw(data, cursor, len, &(group->group_category));
|
|
191 read_packet_w(data, cursor, len, &(unknown)); // 0x0000
|
|
192 read_packet_b(data, cursor, len, &unknown1);
|
|
193 read_packet_dw(data, cursor, len, &(unknown4)); // versionID, by gfhuang
|
|
194
|
|
195 pascal_len = convert_as_pascal_string(*cursor, &(group->group_name_utf8), QQ_CHARSET_DEFAULT);
|
|
196 *cursor += pascal_len;
|
|
197 read_packet_w(data, cursor, len, &(unknown)); // 0x0000
|
|
198 pascal_len = convert_as_pascal_string(*cursor, &(group->notice_utf8), QQ_CHARSET_DEFAULT);
|
|
199 *cursor += pascal_len;
|
|
200 pascal_len = convert_as_pascal_string(*cursor, &(group->group_desc_utf8), QQ_CHARSET_DEFAULT);
|
|
201 *cursor += pascal_len;
|
|
202
|
|
203 i = 0;
|
|
204 // now comes the member list separated by 0x00
|
|
205 while (*cursor < data + len) {
|
|
206 read_packet_dw(data, cursor, len, &member_uid);
|
|
207 i++;
|
|
208 read_packet_b(data, cursor, len, &orgnization); // protocal changed, gfhuang
|
|
209 read_packet_b(data, cursor, len, &role);// gfhuang
|
|
210
|
|
211 if(orgnization != 0 || role != 0) {
|
|
212 gaim_debug(GAIM_DEBUG_INFO, "QQ", "group member %d: orgnizatio=%d, role=%d\n", member_uid, orgnization, role);
|
|
213 }
|
|
214 qq_buddy *member = qq_group_find_or_add_member(gc, group, member_uid);
|
|
215 member->role = role;
|
|
216 } // while *cursor
|
|
217 if(*cursor > (data + len)) {
|
|
218 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_group_info: Dangerous error! maybe protocal changed, notify me!");
|
|
219 }
|
|
220
|
|
221 gaim_debug(GAIM_DEBUG_INFO, "QQ", "group \"%s\" has %d members\n", group->group_name_utf8, i);
|
|
222
|
|
223 if (group->creator_uid == qd->uid)
|
|
224 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_ADMIN;
|
|
225
|
|
226 qq_group_refresh(gc, group);
|
|
227
|
|
228 //added topic by gfhuang
|
|
229 GaimConversation *gaim_conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT,group->group_name_utf8, gaim_connection_get_account(gc));
|
|
230 if(NULL == gaim_conv) {
|
|
231 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
232 "Conv windows for \"%s\" is not on, do not set topic\n", group->group_name_utf8);
|
|
233 }
|
|
234 else {
|
|
235 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(gaim_conv), NULL, group->notice_utf8);
|
|
236 }
|
|
237 } // qq_process_group_cmd_get_group_info
|
|
238
|
|
239 /*****************************************************************************/
|
|
240 void qq_process_group_cmd_get_online_member(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
241 guint32 internal_group_id, member_uid;
|
|
242 guint8 unknown;
|
|
243 gint bytes, i;
|
|
244 qq_group *group;
|
|
245 qq_buddy *member;
|
|
246
|
|
247 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
248
|
|
249 if (data + len - *cursor < 4) {
|
|
250 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid group online member reply, discard it!\n");
|
|
251 return;
|
|
252 } // if data_len-*cursor
|
|
253
|
|
254 bytes = 0;
|
|
255 i = 0;
|
|
256 bytes += read_packet_dw(data, cursor, len, &internal_group_id);
|
|
257 bytes += read_packet_b(data, cursor, len, &unknown); // 0x3c ??
|
|
258 g_return_if_fail(internal_group_id > 0);
|
|
259
|
|
260 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
261 if (group == NULL) {
|
|
262 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "We have no group info for internal id [%d]\n", internal_group_id);
|
|
263 return;
|
|
264 } // if group == NULL
|
|
265
|
|
266 // set all offline first, then update those online
|
|
267 _qq_group_set_members_all_offline(group);
|
|
268 while (*cursor < data + len) {
|
|
269 bytes += read_packet_dw(data, cursor, len, &member_uid);
|
|
270 i++;
|
|
271 member = qq_group_find_or_add_member(gc, group, member_uid);
|
|
272 if (member != NULL)
|
|
273 member->status = QQ_BUDDY_ONLINE_NORMAL;
|
|
274 } // while
|
|
275 if(*cursor > (data + len)) {
|
|
276 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_online_member: Dangerous error! maybe protocal changed, notify me!");
|
|
277 }
|
|
278
|
|
279 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group \"%s\" has %d online members\n", group->group_name_utf8, i);
|
|
280
|
|
281 } // qq_process_group_cmd_get_online_member
|
|
282
|
|
283 /*****************************************************************************/
|
|
284 // process the reply to get_member_info packet
|
|
285 void qq_process_group_cmd_get_member_info(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
286 guint32 internal_group_id, member_uid;
|
|
287 guint16 unknown;
|
|
288 guint8 bar;
|
|
289 gint pascal_len, i;
|
|
290 qq_group *group;
|
|
291 qq_buddy *member;
|
|
292
|
|
293 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
294
|
|
295 read_packet_dw(data, cursor, len, &internal_group_id);
|
|
296 g_return_if_fail(internal_group_id > 0);
|
|
297
|
|
298 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
299 g_return_if_fail(group != NULL);
|
|
300
|
|
301 i = 0;
|
|
302 // now starts the member info, as get buddy list reply
|
|
303 while (*cursor < data + len) {
|
|
304 read_packet_dw(data, cursor, len, &member_uid);
|
|
305 g_return_if_fail(member_uid > 0);
|
|
306 member = qq_group_find_member_by_uid(group, member_uid);
|
|
307 g_return_if_fail(member != NULL);
|
|
308
|
|
309 i++;
|
|
310 read_packet_b(data, cursor, len, &bar);
|
|
311 read_packet_b(data, cursor, len, &(member->icon));
|
|
312 read_packet_b(data, cursor, len, &(member->age));
|
|
313 read_packet_b(data, cursor, len, &(member->gender));
|
|
314 pascal_len = convert_as_pascal_string(*cursor, &(member->nickname), QQ_CHARSET_DEFAULT);
|
|
315 *cursor += pascal_len;
|
|
316 read_packet_w(data, cursor, len, &unknown);
|
|
317 read_packet_b(data, cursor, len, &(member->flag1));
|
|
318 read_packet_b(data, cursor, len, &(member->comm_flag));
|
|
319
|
|
320 member->last_refresh = time(NULL);
|
|
321 } // while
|
|
322 if(*cursor > (data + len)) {
|
|
323 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_member_info: Dangerous error! maybe protocal changed, notify me!");
|
|
324 }
|
|
325 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group \"%s\" obtained %d member info\n", group->group_name_utf8, i);
|
|
326
|
|
327 } // qq_process_group_cmd_get_member_info
|
|
328
|
|
329 /*****************************************************************************/
|
|
330 // END OF FILE
|