comparison libpurple/protocols/qq/group_im.c @ 24159:9be95f0b9472

2008.10.10 - ccpaging <ccpaging(at)gmail.com> * Keep group_search.c/h for later use * Update 'group'
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 28 Oct 2008 16:40:56 +0000
parents b6f09c1c79ce
children 7c0a56c5fea0
comparison
equal deleted inserted replaced
24158:b6f09c1c79ce 24159:9be95f0b9472
32 #include "util.h" 32 #include "util.h"
33 33
34 #include "char_conv.h" 34 #include "char_conv.h"
35 #include "group_internal.h" 35 #include "group_internal.h"
36 #include "group_info.h" 36 #include "group_info.h"
37 #include "group_join.h"
37 #include "group_im.h" 38 #include "group_im.h"
38 #include "group_opt.h" 39 #include "group_opt.h"
39 #include "im.h" 40 #include "im.h"
40 #include "qq_define.h" 41 #include "qq_define.h"
41 #include "packet_parse.h" 42 #include "packet_parse.h"
155 } 156 }
156 g_list_free(flags); 157 g_list_free(flags);
157 } 158 }
158 159
159 /* send IM to a group */ 160 /* send IM to a group */
160 void qq_send_packet_group_im(PurpleConnection *gc, guint32 room_id, const gchar *msg) 161 void qq_request_room_send_im(PurpleConnection *gc, guint32 room_id, const gchar *msg)
161 { 162 {
162 gint data_len, bytes; 163 gint data_len, bytes;
163 guint8 *raw_data, *send_im_tail; 164 guint8 *raw_data, *send_im_tail;
164 guint16 msg_len; 165 guint16 msg_len;
165 gchar *msg_filtered; 166 gchar *msg_filtered;
189 purple_debug_error("QQ", 190 purple_debug_error("QQ",
190 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes); 191 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes);
191 } 192 }
192 193
193 /* this is the ACK */ 194 /* this is the ACK */
194 void qq_process_group_cmd_im(guint8 *data, gint len, PurpleConnection *gc) 195 void qq_process_room_send_im(PurpleConnection *gc, guint8 *data, gint len)
195 { 196 {
196 /* return should be the internal group id 197 /* return should be the internal group id
197 * but we have nothing to do with it */ 198 * but we have nothing to do with it */
198 return; 199 return;
199 }
200
201 /* receive an application to join the group */
202 void qq_process_room_msg_apply_join(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
203 {
204 guint32 ext_id, user_uid;
205 guint8 type8;
206 gchar *reason_utf8, *msg, *reason;
207 group_member_opt *g;
208 gchar *nombre;
209 gint bytes = 0;
210
211 g_return_if_fail(id > 0 && data != NULL && len > 0);
212
213 /* FIXME: check length here */
214
215 bytes += qq_get32(&ext_id, data + bytes);
216 bytes += qq_get8(&type8, data + bytes);
217 bytes += qq_get32(&user_uid, data + bytes);
218
219 g_return_if_fail(ext_id > 0 && user_uid > 0);
220
221 bytes += qq_get_vstr(&reason_utf8, QQ_CHARSET_DEFAULT, data + bytes);
222
223 msg = g_strdup_printf(_("%d request to join Qun %d"), user_uid, ext_id);
224 reason = g_strdup_printf(_("Message: %s"), reason_utf8);
225
226 g = g_new0(group_member_opt, 1);
227 g->gc = gc;
228 g->id = id;
229 g->member = user_uid;
230
231 nombre = uid_to_purple_name(user_uid);
232
233 purple_request_action(gc, _("QQ Qun Operation"),
234 msg, reason,
235 PURPLE_DEFAULT_ACTION_NONE,
236 purple_connection_get_account(gc), nombre, NULL,
237 g, 3,
238 _("Approve"),
239 G_CALLBACK
240 (qq_group_approve_application_with_struct),
241 _("Reject"),
242 G_CALLBACK
243 (qq_group_reject_application_with_struct),
244 _("Search"), G_CALLBACK(qq_group_search_application_with_struct));
245
246 g_free(nombre);
247 g_free(reason);
248 g_free(msg);
249 g_free(reason_utf8);
250 } 200 }
251 201
252 void qq_room_got_chat_in(PurpleConnection *gc, 202 void qq_room_got_chat_in(PurpleConnection *gc,
253 guint32 room_id, guint32 uid_from, const gchar *msg, time_t in_time) 203 guint32 room_id, guint32 uid_from, const gchar *msg, time_t in_time)
254 { 204 {
283 } 233 }
284 serv_got_chat_in(gc, room_id, from, 0, msg, in_time); 234 serv_got_chat_in(gc, room_id, from, 0, msg, in_time);
285 g_free(from); 235 g_free(from);
286 } 236 }
287 237
288 /* the request to join a group is rejected */
289 void qq_process_room_msg_been_rejected(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
290 {
291 guint32 ext_id, admin_uid;
292 guint8 type8;
293 gchar *reason_utf8, *msg, *reason;
294 qq_room_data *rmd;
295 gint bytes;
296
297 g_return_if_fail(data != NULL && len > 0);
298
299 /* FIXME: check length here */
300 bytes = 0;
301 bytes += qq_get32(&ext_id, data + bytes);
302 bytes += qq_get8(&type8, data + bytes);
303 bytes += qq_get32(&admin_uid, data + bytes);
304
305 g_return_if_fail(ext_id > 0 && admin_uid > 0);
306
307 bytes += qq_get_vstr(&reason_utf8, QQ_CHARSET_DEFAULT, data + bytes);
308
309 msg = g_strdup_printf
310 (_("Failed to join Qun %d, operated by admin %d"), ext_id, admin_uid);
311 reason = g_strdup_printf(_("Message: %s"), reason_utf8);
312
313 purple_notify_warning(gc, _("QQ Qun Operation"), msg, reason);
314
315 qq_room_find_or_new(gc, id, ext_id);
316 rmd = qq_room_data_find(gc, id);
317 if (rmd != NULL) {
318 rmd->my_role = QQ_ROOM_ROLE_NO;
319 }
320
321 g_free(msg);
322 g_free(reason);
323 g_free(reason_utf8);
324 }
325
326 /* the request to join a group is approved */
327 void qq_process_room_msg_been_approved(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
328 {
329 guint32 ext_id, admin_uid;
330 guint8 type8;
331 gchar *msg, *reason;
332 qq_room_data *rmd;
333 gint bytes;
334 time_t now;
335
336 g_return_if_fail(data != NULL && len > 0);
337
338 /* FIXME: check length here */
339 bytes = 0;
340 bytes += qq_get32(&ext_id, data + bytes);
341 bytes += qq_get8(&type8, data + bytes);
342 bytes += qq_get32(&admin_uid, data + bytes);
343
344 g_return_if_fail(ext_id > 0 && admin_uid > 0);
345 /* it is also a "无" here, so do not display */
346 bytes += qq_get_vstr(&reason, QQ_CHARSET_DEFAULT, data + bytes);
347
348 qq_room_find_or_new(gc, id, ext_id);
349 rmd = qq_room_data_find(gc, id);
350 if (rmd != NULL) {
351 rmd->my_role = QQ_ROOM_ROLE_YES;
352 }
353
354 msg = g_strdup_printf(_("<b>Joinning Qun %d is approved by Admin %d for %s</b>"),
355 ext_id, admin_uid, reason);
356 now = time(NULL);
357 qq_room_got_chat_in(gc, id, 0, msg, now);
358
359 g_free(msg);
360 g_free(reason);
361 }
362
363 /* process the packet when removed from a group */
364 void qq_process_room_msg_been_removed(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
365 {
366 guint32 ext_id, uid;
367 guint8 type8;
368 gchar *msg;
369 qq_room_data *rmd;
370 gint bytes = 0;
371 time_t now = time(NULL);
372
373 g_return_if_fail(data != NULL && len > 0);
374
375 /* FIXME: check length here */
376 bytes = 0;
377 bytes += qq_get32(&ext_id, data + bytes);
378 bytes += qq_get8(&type8, data + bytes);
379 bytes += qq_get32(&uid, data + bytes);
380
381 g_return_if_fail(ext_id > 0 && uid > 0);
382
383 qq_room_find_or_new(gc, id, ext_id);
384 rmd = qq_room_data_find(gc, id);
385 if (rmd != NULL) {
386 rmd->my_role = QQ_ROOM_ROLE_NO;
387 }
388
389 msg = g_strdup_printf(_("<b>Removed buddy %d.</b>"), uid);
390 qq_room_got_chat_in(gc, id, 0, msg, now);
391 g_free(msg);
392 }
393
394 /* process the packet when added to a group */
395 void qq_process_room_msg_been_added(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
396 {
397 guint32 ext_id, uid;
398 guint8 type8;
399 qq_room_data *rmd;
400 gint bytes;
401 gchar *msg;
402 time_t now = time(NULL);
403
404 g_return_if_fail(data != NULL && len > 0);
405
406 /* FIXME: check length here */
407 bytes = 0;
408 bytes += qq_get32(&ext_id, data + bytes);
409 bytes += qq_get8(&type8, data + bytes);
410 bytes += qq_get32(&uid, data + bytes);
411
412 g_return_if_fail(ext_id > 0 && id > 0);
413
414 qq_room_find_or_new(gc, id, ext_id);
415 rmd = qq_room_data_find(gc, id);
416 g_return_if_fail(rmd != NULL);
417
418 rmd->my_role = QQ_ROOM_ROLE_YES;
419
420 qq_update_room(gc, 0, rmd->id);
421
422 msg = g_strdup_printf(_("<b>Added new buddy %d.</b>"), uid);
423 qq_room_got_chat_in(gc, id, 0, msg, now);
424 g_free(msg);
425 }
426
427 /* recv an IM from a group chat */ 238 /* recv an IM from a group chat */
428 void qq_process_room_msg_normal(guint8 *data, gint data_len, guint32 id, PurpleConnection *gc, guint16 msg_type) 239 void qq_process_room_im(guint8 *data, gint data_len, guint32 id, PurpleConnection *gc, guint16 msg_type)
429 { 240 {
430 gchar *msg_with_purple_smiley, *msg_utf8_encoded; 241 gchar *msg_with_purple_smiley, *msg_utf8_encoded;
431 qq_data *qd; 242 qq_data *qd;
432 gint skip_len; 243 gint skip_len;
433 gint bytes ; 244 gint bytes ;
504 packet.font_attr = g_memdup(data + bytes, packet.font_attr_len); 315 packet.font_attr = g_memdup(data + bytes, packet.font_attr_len);
505 qq_show_packet("font_attr", packet.font_attr, packet.font_attr_len); 316 qq_show_packet("font_attr", packet.font_attr, packet.font_attr_len);
506 } else { 317 } else {
507 packet.font_attr = NULL; 318 packet.font_attr = NULL;
508 } 319 }
509 320
510 /* group im_group has no flag to indicate whether it has font_attr or not */ 321 /* group im_group has no flag to indicate whether it has font_attr or not */
511 msg_with_purple_smiley = qq_smiley_to_purple(packet.msg); 322 msg_with_purple_smiley = qq_smiley_to_purple(packet.msg);
512 if (packet.font_attr_len > 0) { 323 if (packet.font_attr_len > 0) {
513 msg_utf8_encoded = qq_encode_to_purple(packet.font_attr, 324 msg_utf8_encoded = qq_encode_to_purple(packet.font_attr,
514 packet.font_attr_len, msg_with_purple_smiley, qd->client_version); 325 packet.font_attr_len, msg_with_purple_smiley, qd->client_version);