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"
|
|
29 #include "group_hash.h"
|
|
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
|
|
45 /* this is done when we receive the reply to get_online_member sub_cmd
|
|
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 */
|
|
85 void qq_send_cmd_group_get_online_member(GaimConnection *gc, qq_group *group)
|
|
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
|
|
114 /* send packet to get group member info */
|
|
115 void qq_send_cmd_group_get_member_info(GaimConnection *gc, qq_group *group)
|
|
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;
|
|
163 guint8 orgnization, role;
|
|
164 guint16 unknown;
|
|
165 guint32 member_uid, internal_group_id;
|
|
166 gint pascal_len, i;
|
|
167 guint32 unknown4;
|
|
168 guint8 unknown1;
|
|
169
|
|
170 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
171 g_return_if_fail(data != NULL && len > 0);
|
|
172 qd = (qq_data *) gc->proto_data;
|
|
173
|
|
174 read_packet_dw(data, cursor, len, &(internal_group_id));
|
|
175 g_return_if_fail(internal_group_id > 0);
|
|
176
|
|
177 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
178 g_return_if_fail(group != NULL);
|
|
179
|
|
180 read_packet_dw(data, cursor, len, &(group->external_group_id));
|
|
181 read_packet_b(data, cursor, len, &(group->group_type));
|
|
182 read_packet_dw(data, cursor, len, &unknown4); /* unknown 4 bytes */
|
|
183 read_packet_dw(data, cursor, len, &(group->creator_uid));
|
|
184 read_packet_b(data, cursor, len, &(group->auth_type));
|
|
185 read_packet_dw(data, cursor, len, &unknown4); /* oldCategory */
|
|
186 read_packet_w(data, cursor, len, &unknown);
|
|
187 read_packet_dw(data, cursor, len, &(group->group_category));
|
|
188 read_packet_w(data, cursor, len, &(unknown)); /* 0x0000 */
|
|
189 read_packet_b(data, cursor, len, &unknown1);
|
|
190 read_packet_dw(data, cursor, len, &(unknown4)); /* versionID */
|
|
191
|
|
192 pascal_len = convert_as_pascal_string(*cursor, &(group->group_name_utf8), QQ_CHARSET_DEFAULT);
|
|
193 *cursor += pascal_len;
|
|
194 read_packet_w(data, cursor, len, &(unknown)); /* 0x0000 */
|
|
195 pascal_len = convert_as_pascal_string(*cursor, &(group->notice_utf8), QQ_CHARSET_DEFAULT);
|
|
196 *cursor += pascal_len;
|
|
197 pascal_len = convert_as_pascal_string(*cursor, &(group->group_desc_utf8), QQ_CHARSET_DEFAULT);
|
|
198 *cursor += pascal_len;
|
|
199
|
|
200 i = 0;
|
|
201 /* now comes the member list separated by 0x00 */
|
|
202 while (*cursor < data + len) {
|
|
203 read_packet_dw(data, cursor, len, &member_uid);
|
|
204 i++;
|
|
205 read_packet_b(data, cursor, len, &orgnization);
|
|
206 read_packet_b(data, cursor, len, &role);
|
|
207
|
|
208 if(orgnization != 0 || role != 0) {
|
|
209 gaim_debug(GAIM_DEBUG_INFO, "QQ", "group member %d: orgnizatio=%d, role=%d\n", member_uid, orgnization, role);
|
|
210 }
|
|
211 member = qq_group_find_or_add_member(gc, group, member_uid);
|
|
212 member->role = role;
|
|
213 }
|
|
214 if(*cursor > (data + len)) {
|
|
215 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_group_info: Dangerous error! maybe protocal changed, notify me!");
|
|
216 }
|
|
217
|
|
218 gaim_debug(GAIM_DEBUG_INFO, "QQ", "group \"%s\" has %d members\n", group->group_name_utf8, i);
|
|
219
|
|
220 if (group->creator_uid == qd->uid)
|
|
221 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_ADMIN;
|
|
222
|
|
223 qq_group_refresh(gc, group);
|
|
224
|
|
225 gaim_conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT,
|
|
226 group->group_name_utf8, gaim_connection_get_account(gc));
|
|
227 if(NULL == gaim_conv) {
|
|
228 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
229 "Conv windows for \"%s\" is not on, do not set topic\n", group->group_name_utf8);
|
|
230 }
|
|
231 else {
|
|
232 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(gaim_conv), NULL, group->notice_utf8);
|
|
233 }
|
|
234 }
|
|
235
|
|
236 void qq_process_group_cmd_get_online_member(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
237 {
|
|
238 guint32 internal_group_id, member_uid;
|
|
239 guint8 unknown;
|
|
240 gint bytes, i;
|
|
241 qq_group *group;
|
|
242 qq_buddy *member;
|
|
243
|
|
244 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
245
|
|
246 if (data + len - *cursor < 4) {
|
|
247 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid group online member reply, discard it!\n");
|
|
248 return;
|
|
249 }
|
|
250
|
|
251 bytes = 0;
|
|
252 i = 0;
|
|
253 bytes += read_packet_dw(data, cursor, len, &internal_group_id);
|
|
254 bytes += read_packet_b(data, cursor, len, &unknown); /* 0x3c ?? */
|
|
255 g_return_if_fail(internal_group_id > 0);
|
|
256
|
|
257 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
258 if (group == NULL) {
|
|
259 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
260 "We have no group info for internal id [%d]\n", internal_group_id);
|
|
261 return;
|
|
262 }
|
|
263
|
|
264 /* set all offline first, then update those online */
|
|
265 _qq_group_set_members_all_offline(group);
|
|
266 while (*cursor < data + len) {
|
|
267 bytes += read_packet_dw(data, cursor, len, &member_uid);
|
|
268 i++;
|
|
269 member = qq_group_find_or_add_member(gc, group, member_uid);
|
|
270 if (member != NULL)
|
|
271 member->status = QQ_BUDDY_ONLINE_NORMAL;
|
|
272 }
|
|
273 if(*cursor > (data + len)) {
|
|
274 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
275 "group_cmd_get_online_member: Dangerous error! maybe protocol changed, notify developers!");
|
|
276 }
|
|
277
|
|
278 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group \"%s\" has %d online members\n", group->group_name_utf8, i);
|
|
279 }
|
|
280
|
|
281 /* process the reply to get_member_info packet */
|
|
282 void qq_process_group_cmd_get_member_info(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
283 {
|
|
284 guint32 internal_group_id, member_uid;
|
|
285 guint16 unknown;
|
|
286 guint8 bar;
|
|
287 gint pascal_len, i;
|
|
288 qq_group *group;
|
|
289 qq_buddy *member;
|
|
290
|
|
291 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
292
|
|
293 read_packet_dw(data, cursor, len, &internal_group_id);
|
|
294 g_return_if_fail(internal_group_id > 0);
|
|
295
|
|
296 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
297 g_return_if_fail(group != NULL);
|
|
298
|
|
299 i = 0;
|
|
300 /* now starts the member info, as get buddy list reply */
|
|
301 while (*cursor < data + len) {
|
|
302 read_packet_dw(data, cursor, len, &member_uid);
|
|
303 g_return_if_fail(member_uid > 0);
|
|
304 member = qq_group_find_member_by_uid(group, member_uid);
|
|
305 g_return_if_fail(member != NULL);
|
|
306
|
|
307 i++;
|
|
308 read_packet_b(data, cursor, len, &bar);
|
|
309 read_packet_b(data, cursor, len, &(member->icon));
|
|
310 read_packet_b(data, cursor, len, &(member->age));
|
|
311 read_packet_b(data, cursor, len, &(member->gender));
|
|
312 pascal_len = convert_as_pascal_string(*cursor, &(member->nickname), QQ_CHARSET_DEFAULT);
|
|
313 *cursor += pascal_len;
|
|
314 read_packet_w(data, cursor, len, &unknown);
|
|
315 read_packet_b(data, cursor, len, &(member->flag1));
|
|
316 read_packet_b(data, cursor, len, &(member->comm_flag));
|
|
317
|
|
318 member->last_refresh = time(NULL);
|
|
319 }
|
|
320 if(*cursor > (data + len)) {
|
|
321 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
322 "group_cmd_get_member_info: Dangerous error! maybe protocol changed, notify developers!");
|
|
323 }
|
|
324 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group \"%s\" obtained %d member info\n", group->group_name_utf8, i);
|
|
325 }
|