comparison libpurple/protocols/qq/group_im.c @ 23878:967344bc404d

applied changes from f12c8903079425d7850fa183df0b3f937b2952be through 8cebefbc6cd5d84acb69c74e69e8821f11dd225d Backport of 8cebefbc6cd5d84acb69c74e69e8821f11dd225d to avoid having other changes overwritten. 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com> * Rename group to room. If you used pidginqq before, this may create a new room with same title, you may delete old one * Replace purple_debug with purple_debug_info, purple_debug_warning, purple_debug_error * Add server notice and server new, and two options to turn on/off * Minor modify for reducing transaction's debug infor * Minor modifies for system notice and QQ news. * Add 4 new strings need translate compare with p10. committer: Daniel Atallah <daniel.atallah@gmail.com>
author SHiNE CsyFeK <csyfek@gmail.com>
date Mon, 15 Sep 2008 02:59:23 +0000
parents 5f454b975a99
children 23cec4360d4a 25f62d21b3f8
comparison
equal deleted inserted replaced
23695:5f454b975a99 23878:967344bc404d
39 #include "group_opt.h" 39 #include "group_opt.h"
40 #include "im.h" 40 #include "im.h"
41 #include "header_info.h" 41 #include "header_info.h"
42 #include "packet_parse.h" 42 #include "packet_parse.h"
43 #include "qq_network.h" 43 #include "qq_network.h"
44 #include "qq_process.h"
44 #include "utils.h" 45 #include "utils.h"
45 46
46 typedef struct _qq_recv_group_im { 47 typedef struct _qq_recv_group_im {
47 guint32 ext_id; 48 guint32 ext_id;
48 guint8 type8; 49 guint8 type8;
83 g_free(msg_filtered); 84 g_free(msg_filtered);
84 85
85 if (bytes == data_len) /* create OK */ 86 if (bytes == data_len) /* create OK */
86 qq_send_room_cmd(gc, QQ_ROOM_CMD_SEND_MSG, group->id, raw_data, data_len); 87 qq_send_room_cmd(gc, QQ_ROOM_CMD_SEND_MSG, group->id, raw_data, data_len);
87 else 88 else
88 purple_debug(PURPLE_DEBUG_ERROR, "QQ", 89 purple_debug_error("QQ",
89 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes); 90 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes);
90 } 91 }
91 92
92 /* this is the ACK */ 93 /* this is the ACK */
93 void qq_process_group_cmd_im(guint8 *data, gint len, PurpleConnection *gc) 94 void qq_process_group_cmd_im(guint8 *data, gint len, PurpleConnection *gc)
94 { 95 {
95 /* return should be the internal group id 96 /* return should be the internal group id
96 * but we have nothing to do with it */ 97 * but we have nothing to do with it */
97 return; 98 return;
98 } 99 }
99 100
100 /* receive an application to join the group */ 101 /* receive an application to join the group */
101 void qq_process_recv_group_im_apply_join(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 102 void qq_process_room_msg_apply_join(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
102 { 103 {
103 guint32 ext_id, user_uid; 104 guint32 ext_id, user_uid;
104 guint8 type8; 105 guint8 type8;
105 gchar *reason_utf8, *msg, *reason; 106 gchar *reason_utf8, *msg, *reason;
106 group_member_opt *g; 107 group_member_opt *g;
117 118
118 g_return_if_fail(ext_id > 0 && user_uid > 0); 119 g_return_if_fail(ext_id > 0 && user_uid > 0);
119 120
120 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT); 121 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT);
121 122
122 msg = g_strdup_printf(_("User %d requested to join group %d"), user_uid, ext_id); 123 msg = g_strdup_printf(_("%d requested to join Qun %d"), user_uid, ext_id);
123 reason = g_strdup_printf(_("Reason: %s"), reason_utf8); 124 reason = g_strdup_printf(_("Message: %s"), reason_utf8);
124 125
125 g = g_new0(group_member_opt, 1); 126 g = g_new0(group_member_opt, 1);
126 g->gc = gc; 127 g->gc = gc;
127 g->id = id; 128 g->id = id;
128 g->member = user_uid; 129 g->member = user_uid;
147 g_free(msg); 148 g_free(msg);
148 g_free(reason_utf8); 149 g_free(reason_utf8);
149 } 150 }
150 151
151 /* the request to join a group is rejected */ 152 /* the request to join a group is rejected */
152 void qq_process_recv_group_im_been_rejected(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 153 void qq_process_room_msg_been_rejected(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
153 { 154 {
154 guint32 ext_id, admin_uid; 155 guint32 ext_id, admin_uid;
155 guint8 type8; 156 guint8 type8;
156 gchar *reason_utf8, *msg, *reason; 157 gchar *reason_utf8, *msg, *reason;
157 qq_group *group; 158 qq_group *group;
168 g_return_if_fail(ext_id > 0 && admin_uid > 0); 169 g_return_if_fail(ext_id > 0 && admin_uid > 0);
169 170
170 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT); 171 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT);
171 172
172 msg = g_strdup_printf 173 msg = g_strdup_printf
173 (_("Your request to join group %d has been rejected by admin %d"), ext_id, admin_uid); 174 (_("Your request to join Qun %d has been rejected by admin %d"), ext_id, admin_uid);
174 reason = g_strdup_printf(_("Reason: %s"), reason_utf8); 175 reason = g_strdup_printf(_("Message: %s"), reason_utf8);
175 176
176 purple_notify_warning(gc, _("QQ Qun Operation"), msg, reason); 177 purple_notify_warning(gc, _("QQ Qun Operation"), msg, reason);
177 178
178 group = qq_room_search_id(gc, id); 179 group = qq_room_search_id(gc, id);
179 if (group != NULL) { 180 if (group != NULL) {
180 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; 181 group->my_role = QQ_ROOM_ROLE_NO;
181 qq_group_refresh(gc, group); 182 qq_group_refresh(gc, group);
182 } 183 }
183 184
184 g_free(reason); 185 g_free(reason);
185 g_free(msg); 186 g_free(msg);
186 g_free(reason_utf8); 187 g_free(reason_utf8);
187 } 188 }
188 189
189 /* the request to join a group is approved */ 190 /* the request to join a group is approved */
190 void qq_process_recv_group_im_been_approved(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 191 void qq_process_room_msg_been_approved(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
191 { 192 {
192 guint32 ext_id, admin_uid; 193 guint32 ext_id, admin_uid;
193 guint8 type8; 194 guint8 type8;
194 gchar *reason_utf8, *msg; 195 gchar *reason_utf8, *msg;
195 qq_group *group; 196 qq_group *group;
206 g_return_if_fail(ext_id > 0 && admin_uid > 0); 207 g_return_if_fail(ext_id > 0 && admin_uid > 0);
207 /* it is also a "无" here, so do not display */ 208 /* it is also a "无" here, so do not display */
208 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT); 209 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT);
209 210
210 msg = g_strdup_printf 211 msg = g_strdup_printf
211 (_("Your request to join group %d has been approved by admin %d"), ext_id, admin_uid); 212 (_("Your request to join Qun %d has been approved by admin %d"), ext_id, admin_uid);
212 213
213 purple_notify_warning(gc, _("QQ Qun Operation"), msg, NULL); 214 purple_notify_warning(gc, _("QQ Qun Operation"), msg, NULL);
214 215
215 group = qq_room_search_id(gc, id); 216 group = qq_room_search_id(gc, id);
216 if (group != NULL) { 217 if (group != NULL) {
217 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; 218 group->my_role = QQ_ROOM_ROLE_YES;
218 qq_group_refresh(gc, group); 219 qq_group_refresh(gc, group);
219 } 220 }
220 221
221 g_free(msg); 222 g_free(msg);
222 g_free(reason_utf8); 223 g_free(reason_utf8);
223 } 224 }
224 225
225 /* process the packet when removed from a group */ 226 /* process the packet when removed from a group */
226 void qq_process_recv_group_im_been_removed(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 227 void qq_process_room_msg_been_removed(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
227 { 228 {
228 guint32 ext_id, uid; 229 guint32 ext_id, uid;
229 guint8 type8; 230 guint8 type8;
230 gchar *msg; 231 gchar *msg;
231 qq_group *group; 232 qq_group *group;
239 bytes += qq_get8(&type8, data + bytes); 240 bytes += qq_get8(&type8, data + bytes);
240 bytes += qq_get32(&uid, data + bytes); 241 bytes += qq_get32(&uid, data + bytes);
241 242
242 g_return_if_fail(ext_id > 0 && uid > 0); 243 g_return_if_fail(ext_id > 0 && uid > 0);
243 244
244 msg = g_strdup_printf(_("You [%d] have left group \"%d\""), uid, ext_id); 245 msg = g_strdup_printf(_("[%d] removed from Qun \"%d\""), uid, ext_id);
245 purple_notify_info(gc, _("QQ Qun Operation"), msg, NULL); 246 purple_notify_info(gc, _("QQ Qun Operation"), msg, NULL);
246 247
247 group = qq_room_search_id(gc, id); 248 group = qq_room_search_id(gc, id);
248 if (group != NULL) { 249 if (group != NULL) {
249 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; 250 group->my_role = QQ_ROOM_ROLE_NO;
250 qq_group_refresh(gc, group); 251 qq_group_refresh(gc, group);
251 } 252 }
252 253
253 g_free(msg); 254 g_free(msg);
254 } 255 }
255 256
256 /* process the packet when added to a group */ 257 /* process the packet when added to a group */
257 void qq_process_recv_group_im_been_added(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 258 void qq_process_room_msg_been_added(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
258 { 259 {
259 guint32 ext_id, uid; 260 guint32 ext_id, uid;
260 guint8 type8; 261 guint8 type8;
261 qq_group *group; 262 qq_group *group;
262 gchar *msg; 263 gchar *msg;
270 bytes += qq_get8(&type8, data + bytes); 271 bytes += qq_get8(&type8, data + bytes);
271 bytes += qq_get32(&uid, data + bytes); 272 bytes += qq_get32(&uid, data + bytes);
272 273
273 g_return_if_fail(ext_id > 0 && uid > 0); 274 g_return_if_fail(ext_id > 0 && uid > 0);
274 275
275 msg = g_strdup_printf(_("You [%d] have been added to group \"%d\""), uid, ext_id); 276 msg = g_strdup_printf(_("[%d] added to Qun \"%d\""), uid, ext_id);
276 purple_notify_info(gc, _("QQ Qun Operation"), msg, _("This group has been added to your buddy list")); 277 purple_notify_info(gc, _("QQ Qun Operation"), msg, _("Qun is in buddy list"));
277 278
278 group = qq_room_search_id(gc, id); 279 group = qq_room_search_id(gc, id);
279 if (group != NULL) { 280 if (group != NULL) {
280 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; 281 group->my_role = QQ_ROOM_ROLE_YES;
281 qq_group_refresh(gc, group); 282 qq_group_refresh(gc, group);
282 } else { /* no such group, try to create a dummy first, and then update */ 283 } else { /* no such group, try to create a dummy first, and then update */
283 group = qq_group_create_internal_record(gc, id, ext_id, NULL); 284 group = qq_group_create_internal_record(gc, id, ext_id, NULL);
284 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; 285 group->my_role = QQ_ROOM_ROLE_YES;
285 qq_group_refresh(gc, group); 286 qq_group_refresh(gc, group);
286 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id); 287 qq_room_update(gc, 0, group->id);
287 /* the return of this cmd will automatically update the group in blist */ 288 /* the return of this cmd will automatically update the group in blist */
288 } 289 }
289 290
290 g_free(msg); 291 g_free(msg);
291 } 292 }
292 293
293 /* recv an IM from a group chat */ 294 /* recv an IM from a group chat */
294 void qq_process_recv_group_im(guint8 *data, gint data_len, guint32 id, PurpleConnection *gc, guint16 im_type) 295 void qq_process_room_msg_normal(guint8 *data, gint data_len, guint32 id, PurpleConnection *gc, guint16 im_type)
295 { 296 {
296 gchar *msg_with_purple_smiley, *msg_utf8_encoded, *im_src_name; 297 gchar *msg_with_purple_smiley, *msg_utf8_encoded, *im_src_name;
297 guint16 unknown; 298 guint16 unknown;
298 guint32 unknown4; 299 guint32 unknown4;
299 PurpleConversation *conv; 300 PurpleConversation *conv;
308 309
309 /* FIXME: check length here */ 310 /* FIXME: check length here */
310 311
311 qd = (qq_data *) gc->proto_data; 312 qd = (qq_data *) gc->proto_data;
312 313
313 /* qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", data, data_len, "group im hex dump"); */ 314 #if 0
315 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", data, data_len, "group im hex dump");
316 #endif
314 317
315 im_group = g_newa(qq_recv_group_im, 1); 318 im_group = g_newa(qq_recv_group_im, 1);
316 319
317 bytes += qq_get32(&(im_group->ext_id), data + bytes); 320 bytes += qq_get32(&(im_group->ext_id), data + bytes);
318 bytes += qq_get8(&(im_group->type8), data + bytes); 321 bytes += qq_get8(&(im_group->type8), data + bytes);
372 msg_utf8_encoded = qq_to_utf8(msg_with_purple_smiley, QQ_CHARSET_DEFAULT); 375 msg_utf8_encoded = qq_to_utf8(msg_with_purple_smiley, QQ_CHARSET_DEFAULT);
373 376
374 group = qq_room_search_id(gc, id); 377 group = qq_room_search_id(gc, id);
375 g_return_if_fail(group != NULL); 378 g_return_if_fail(group != NULL);
376 379
377 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->group_name_utf8, purple_connection_get_account(gc)); 380 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->title_utf8, purple_connection_get_account(gc));
378 if (conv == NULL && purple_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) { 381 if (conv == NULL && purple_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) {
379 /* New conv should open, get group info*/ 382 /* New conv should open, get group info*/
380 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id); 383 qq_room_update(gc, 0, group->id);
381 384
382 serv_got_joined_chat(gc, qd->channel++, group->group_name_utf8); 385 serv_got_joined_chat(gc, qd->channel++, group->title_utf8);
383 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->group_name_utf8, purple_connection_get_account(gc)); 386 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->title_utf8, purple_connection_get_account(gc));
384 } 387 }
385 388
386 if (conv != NULL) { 389 if (conv != NULL) {
387 member = qq_group_find_member_by_uid(group, im_group->member_uid); 390 member = qq_group_find_member_by_uid(group, im_group->member_uid);
388 if (member == NULL || member->nickname == NULL) 391 if (member == NULL || member->nickname == NULL)