comparison libpurple/protocols/qq/group_join.c @ 23754: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
23753:5f454b975a99 23754:967344bc404d
40 #include "group_opt.h" 40 #include "group_opt.h"
41 #include "group_search.h" 41 #include "group_search.h"
42 #include "header_info.h" 42 #include "header_info.h"
43 #include "packet_parse.h" 43 #include "packet_parse.h"
44 #include "qq_network.h" 44 #include "qq_network.h"
45 #include "qq_process.h"
45 46
46 enum { 47 enum {
47 QQ_GROUP_JOIN_OK = 0x01, 48 QQ_ROOM_JOIN_OK = 0x01,
48 QQ_GROUP_JOIN_NEED_AUTH = 0x02, 49 QQ_ROOM_JOIN_NEED_AUTH = 0x02,
49 }; 50 };
50 51
51 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g) 52 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g)
52 { 53 {
53 PurpleConnection *gc; 54 PurpleConnection *gc;
66 /* send packet to join a group without auth */ 67 /* send packet to join a group without auth */
67 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group) 68 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group)
68 { 69 {
69 g_return_if_fail(group != NULL); 70 g_return_if_fail(group != NULL);
70 71
71 if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { 72 if (group->my_role == QQ_ROOM_ROLE_NO) {
72 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; 73 group->my_role = QQ_ROOM_ROLE_REQUESTING;
73 qq_group_refresh(gc, group); 74 qq_group_refresh(gc, group);
74 } 75 }
75 76
76 switch (group->auth_type) { 77 switch (group->auth_type) {
77 case QQ_GROUP_AUTH_TYPE_NO_AUTH: 78 case QQ_ROOM_AUTH_TYPE_NO_AUTH:
78 case QQ_GROUP_AUTH_TYPE_NEED_AUTH: 79 case QQ_ROOM_AUTH_TYPE_NEED_AUTH:
79 break; 80 break;
80 case QQ_GROUP_AUTH_TYPE_NO_ADD: 81 case QQ_ROOM_AUTH_TYPE_NO_ADD:
81 purple_notify_warning(gc, NULL, _("This group does not allow others to join"), NULL); 82 purple_notify_warning(gc, NULL, _("The Qun does not allow others to join"), NULL);
82 return; 83 return;
83 default: 84 default:
84 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); 85 purple_debug_error("QQ", "Unknown room auth type: %d\n", group->auth_type);
85 break; 86 break;
86 } 87 }
87 88
88 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_JOIN, group->id); 89 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_JOIN, group->id);
89 } 90 }
97 gc = g->gc; 98 gc = g->gc;
98 id = g->uid; 99 id = g->uid;
99 100
100 group = qq_room_search_id(gc, id); 101 group = qq_room_search_id(gc, id);
101 if (group == NULL) { 102 if (group == NULL) {
102 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", id); 103 purple_debug_error("QQ", "Can not find qq_group by internal_id: %d\n", id);
103 return; 104 return;
104 } else { /* everything is OK */ 105 } else { /* everything is OK */
105 qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8); 106 qq_send_cmd_group_auth(gc, group, QQ_ROOM_AUTH_REQUEST_APPLY, 0, reason_utf8);
106 } 107 }
107 } 108 }
108 109
109 static void _qq_group_join_auth(PurpleConnection *gc, qq_group *group) 110 static void _qq_group_join_auth(PurpleConnection *gc, qq_group *group)
110 { 111 {
111 gchar *msg; 112 gchar *msg;
112 gc_and_uid *g; 113 gc_and_uid *g;
113 g_return_if_fail(group != NULL); 114 g_return_if_fail(group != NULL);
114 115
115 purple_debug(PURPLE_DEBUG_INFO, "QQ", 116 purple_debug_info("QQ", "Group (internal id: %d) needs authentication\n", group->id);
116 "Group (internal id: %d) needs authentication\n", group->id); 117
117 118 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->title_utf8);
118 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8);
119 g = g_new0(gc_and_uid, 1); 119 g = g_new0(gc_and_uid, 1);
120 g->gc = gc; 120 g->gc = gc;
121 g->uid = group->id; 121 g->uid = group->id;
122 purple_request_input(gc, NULL, msg, 122 purple_request_input(gc, NULL, msg,
123 _("Input request here"), 123 _("Input request here"),
124 _("Would you be my friend?"), TRUE, FALSE, NULL, 124 _("Would you be my friend?"), TRUE, FALSE, NULL,
125 _("Send"), 125 _("Send"),
126 G_CALLBACK(_qq_group_join_auth_with_gc_and_id), 126 G_CALLBACK(_qq_group_join_auth_with_gc_and_id),
127 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), 127 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid),
128 purple_connection_get_account(gc), group->group_name_utf8, NULL, 128 purple_connection_get_account(gc), group->title_utf8, NULL,
129 g); 129 g);
130 g_free(msg); 130 g_free(msg);
131 } 131 }
132 132
133 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) 133 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8)
141 if (reason_utf8 == NULL || strlen(reason_utf8) == 0) 141 if (reason_utf8 == NULL || strlen(reason_utf8) == 0)
142 reason_qq = g_strdup(""); 142 reason_qq = g_strdup("");
143 else 143 else
144 reason_qq = utf8_to_qq(reason_utf8, QQ_CHARSET_DEFAULT); 144 reason_qq = utf8_to_qq(reason_utf8, QQ_CHARSET_DEFAULT);
145 145
146 if (opt == QQ_GROUP_AUTH_REQUEST_APPLY) { 146 if (opt == QQ_ROOM_AUTH_REQUEST_APPLY) {
147 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; 147 group->my_role = QQ_ROOM_ROLE_REQUESTING;
148 qq_group_refresh(gc, group); 148 qq_group_refresh(gc, group);
149 uid = 0; 149 uid = 0;
150 } 150 }
151 151
152 raw_data = g_newa(guint8, 6 + strlen(reason_qq)); 152 raw_data = g_newa(guint8, 6 + strlen(reason_qq));
171 171
172 g_return_if_fail(data != NULL && len > 0); 172 g_return_if_fail(data != NULL && len > 0);
173 qd = (qq_data *) gc->proto_data; 173 qd = (qq_data *) gc->proto_data;
174 174
175 if (len < 4) { 175 if (len < 4) {
176 purple_debug(PURPLE_DEBUG_ERROR, "QQ", 176 purple_debug_error("QQ", "Invalid exit group reply, expect %d bytes, read %d bytes\n", 4, len);
177 "Invalid exit group reply, expect %d bytes, read %d bytes\n", 4, len);
178 return; 177 return;
179 } 178 }
180 179
181 bytes = 0; 180 bytes = 0;
182 bytes += qq_get32(&id, data + bytes); 181 bytes += qq_get32(&id, data + bytes);
187 (purple_connection_get_account(gc), g_strdup_printf("%d", group->ext_id)); 186 (purple_connection_get_account(gc), g_strdup_printf("%d", group->ext_id));
188 if (chat != NULL) 187 if (chat != NULL)
189 purple_blist_remove_chat(chat); 188 purple_blist_remove_chat(chat);
190 qq_group_delete_internal_record(qd, id); 189 qq_group_delete_internal_record(qd, id);
191 } 190 }
192 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully left the group"), NULL); 191 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully left the Qun"), NULL);
193 } 192 }
194 193
195 /* Process the reply to group_auth subcmd */ 194 /* Process the reply to group_auth subcmd */
196 void qq_process_group_cmd_join_group_auth(guint8 *data, gint len, PurpleConnection *gc) 195 void qq_process_group_cmd_join_group_auth(guint8 *data, gint len, PurpleConnection *gc)
197 { 196 {
201 200
202 g_return_if_fail(data != NULL && len > 0); 201 g_return_if_fail(data != NULL && len > 0);
203 qd = (qq_data *) gc->proto_data; 202 qd = (qq_data *) gc->proto_data;
204 203
205 if (len < 4) { 204 if (len < 4) {
206 purple_debug(PURPLE_DEBUG_ERROR, "QQ", 205 purple_debug_error("QQ",
207 "Invalid join group reply, expect %d bytes, read %d bytes\n", 4, len); 206 "Invalid join room reply, expect %d bytes, read %d bytes\n", 4, len);
208 return; 207 return;
209 } 208 }
210 bytes = 0; 209 bytes = 0;
211 bytes += qq_get32(&id, data + bytes); 210 bytes += qq_get32(&id, data + bytes);
212 g_return_if_fail(id > 0); 211 g_return_if_fail(id > 0);
213 212
214 purple_notify_info(gc, _("QQ Group Auth"), 213 purple_notify_info(gc, _("QQ Qun Auth"),
215 _("Your authorization request has been accepted by the QQ server"), NULL); 214 _("Your authorization request has been accepted by the QQ server"), NULL);
216 } 215 }
217 216
218 /* process group cmd reply "join group" */ 217 /* process group cmd reply "join group" */
219 void qq_process_group_cmd_join_group(guint8 *data, gint len, PurpleConnection *gc) 218 void qq_process_group_cmd_join_group(guint8 *data, gint len, PurpleConnection *gc)
224 qq_group *group; 223 qq_group *group;
225 224
226 g_return_if_fail(data != NULL && len > 0); 225 g_return_if_fail(data != NULL && len > 0);
227 226
228 if (len < 5) { 227 if (len < 5) {
229 purple_debug(PURPLE_DEBUG_ERROR, "QQ", 228 purple_debug_error("QQ",
230 "Invalid join group reply, expect %d bytes, read %d bytes\n", 5, len); 229 "Invalid join group reply, expect %d bytes, read %d bytes\n", 5, len);
231 return; 230 return;
232 } 231 }
233 232
234 bytes = 0; 233 bytes = 0;
235 bytes += qq_get32(&id, data + bytes); 234 bytes += qq_get32(&id, data + bytes);
236 bytes += qq_get8(&reply, data + bytes); 235 bytes += qq_get8(&reply, data + bytes);
237 236
238 /* join group OK */ 237 /* join group OK */
239 group = qq_room_search_id(gc, id); 238 group = qq_room_search_id(gc, id);
240 /* need to check if group is NULL or not. */ 239 /* need to check if group is NULL or not. */
241 g_return_if_fail(group != NULL); 240 g_return_if_fail(group != NULL);
242 switch (reply) { 241 switch (reply) {
243 case QQ_GROUP_JOIN_OK: 242 case QQ_ROOM_JOIN_OK:
244 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); 243 purple_debug_info("QQ", "Succeed joining group \"%s\"\n", group->title_utf8);
245 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; 244 group->my_role = QQ_ROOM_ROLE_YES;
246 qq_group_refresh(gc, group); 245 qq_group_refresh(gc, group);
247 /* this must be shown before getting online members */ 246 /* this must be shown before getting online members */
248 qq_group_conv_show_window(gc, group); 247 qq_group_conv_show_window(gc, group);
249 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id); 248 qq_room_update(gc, 0, group->id);
250 break; 249 break;
251 case QQ_GROUP_JOIN_NEED_AUTH: 250 case QQ_ROOM_JOIN_NEED_AUTH:
252 purple_debug(PURPLE_DEBUG_INFO, "QQ", 251 purple_debug_info("QQ",
253 "Fail joining group [%d] %s, needs authentication\n", 252 "Fail joining group [%d] %s, needs authentication\n",
254 group->ext_id, group->group_name_utf8); 253 group->ext_id, group->title_utf8);
255 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; 254 group->my_role = QQ_ROOM_ROLE_NO;
256 qq_group_refresh(gc, group); 255 qq_group_refresh(gc, group);
257 _qq_group_join_auth(gc, group); 256 _qq_group_join_auth(gc, group);
258 break; 257 break;
259 default: 258 default:
260 purple_debug(PURPLE_DEBUG_INFO, "QQ", 259 purple_debug_info("QQ",
261 "Error joining group [%d] %s, unknown reply: 0x%02x\n", 260 "Error joining group [%d] %s, unknown reply: 0x%02x\n",
262 group->ext_id, group->group_name_utf8, reply); 261 group->ext_id, group->title_utf8, reply);
263 } 262 }
264 } 263 }
265 264
266 /* Attempt to join a group without auth */ 265 /* Attempt to join a group without auth */
267 void qq_group_join(PurpleConnection *gc, GHashTable *data) 266 void qq_group_join(PurpleConnection *gc, GHashTable *data)
272 qq_group *group; 271 qq_group *group;
273 272
274 g_return_if_fail(data != NULL); 273 g_return_if_fail(data != NULL);
275 qd = (qq_data *) gc->proto_data; 274 qd = (qq_data *) gc->proto_data;
276 275
277 ext_id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID); 276 ext_id_ptr = g_hash_table_lookup(data, QQ_ROOM_KEY_EXTERNAL_ID);
278 g_return_if_fail(ext_id_ptr != NULL); 277 g_return_if_fail(ext_id_ptr != NULL);
279 errno = 0; 278 errno = 0;
280 ext_id = strtol(ext_id_ptr, NULL, 10); 279 ext_id = strtol(ext_id_ptr, NULL, 10);
281 if (errno != 0) { 280 if (errno != 0) {
282 purple_notify_error(gc, _("Error"), 281 purple_notify_error(gc, _("Error"),
299 guint32 id; 298 guint32 id;
300 gc_and_uid *g; 299 gc_and_uid *g;
301 300
302 g_return_if_fail(data != NULL); 301 g_return_if_fail(data != NULL);
303 302
304 id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_INTERNAL_ID); 303 id_ptr = g_hash_table_lookup(data, QQ_ROOM_KEY_INTERNAL_ID);
305 id = strtol(id_ptr, NULL, 10); 304 id = strtol(id_ptr, NULL, 10);
306 305
307 g_return_if_fail(id > 0); 306 g_return_if_fail(id > 0);
308 307
309 g = g_new0(gc_and_uid, 1); 308 g = g_new0(gc_and_uid, 1);
310 g->gc = gc; 309 g->gc = gc;
311 g->uid = id; 310 g->uid = id;
312 311
313 purple_request_action(gc, _("QQ Qun Operation"), 312 purple_request_action(gc, _("QQ Qun Operation"),
314 _("Are you sure you want to leave this Qun?"), 313 _("Are you sure you want to leave this Qun?"),
315 _ 314 _("Note, if you are the creator, \nthis operation will eventually remove this Qun."),
316 ("Note, if you are the creator, \nthis operation will eventually remove this Qun."),
317 1, 315 1,
318 purple_connection_get_account(gc), NULL, NULL, 316 purple_connection_get_account(gc), NULL, NULL,
319 g, 2, _("Cancel"), 317 g, 2, _("Cancel"),
320 G_CALLBACK(qq_do_nothing_with_gc_and_uid), 318 G_CALLBACK(qq_do_nothing_with_gc_and_uid),
321 _("Continue"), G_CALLBACK(_qq_group_exit_with_gc_and_id)); 319 _("Continue"), G_CALLBACK(_qq_group_exit_with_gc_and_id));