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