comparison plugins/irc.c @ 1014:bc4f6a535bd9

[gaim-migrate @ 1024] People are now properly listed in the channels when you join or when they enter or leave. committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Fri, 20 Oct 2000 23:47:35 +0000
parents 7e8dcc609b30
children bbd0d51b7d14
comparison
equal deleted inserted replaced
1013:966845e5ad29 1014:bc4f6a535bd9
227 serv_got_chat_in(gc, id, gc->username, 0, message); 227 serv_got_chat_in(gc, id, gc->username, 0, message);
228 228
229 g_free(buf); 229 g_free(buf);
230 } 230 }
231 231
232 struct conversation * find_conversation_by_id( struct gaim_connection * gc, int id) {
233 struct irc_data *idata = (struct irc_data *)gc->proto_data;
234 GSList *bc = gc->buddy_chats;
235 struct conversation *b = NULL;
236
237 while (bc) {
238 b = (struct conversation *)bc->data;
239 if (id == b->id) {
240 break;
241 }
242 bc = bc->next;
243 b = NULL;
244 }
245
246 if (!b) {
247 return NULL;
248 }
249
250 return b;
251 }
252
253 struct conversation * find_conversation_by_name( struct gaim_connection * gc, char *name) {
254 struct irc_data *idata = (struct irc_data *)gc->proto_data;
255 GSList *bc = gc->buddy_chats;
256 struct conversation *b = NULL;
257
258 while (bc) {
259 b = (struct conversation *)bc->data;
260
261 if (g_strcasecmp(name, b->name) == 0) {
262 break;
263 }
264 bc = bc->next;
265 b = NULL;
266 }
267
268 if (!b) {
269 return NULL;
270 }
271
272 return b;
273 }
274
275
276
232 void irc_callback ( struct gaim_connection * gc ) { 277 void irc_callback ( struct gaim_connection * gc ) {
233 278
234 int i = 0; 279 int i = 0;
235 char c; 280 char c;
236 gchar buf[4096]; 281 gchar buf[4096];
254 buf[i] = '\0'; 299 buf[i] = '\0';
255 300
256 /* And remove that damned trailing \n */ 301 /* And remove that damned trailing \n */
257 g_strchomp(buf); 302 g_strchomp(buf);
258 303
259 /* For now, lets display everything to the console too. Im such a bitch */ 304 /* For now, lets display everything to the console too. Im such
305 * a bitch */
260 printf("IRC:'%'s\n", buf); 306 printf("IRC:'%'s\n", buf);
261 307
308
309 /* Parse the list of names that we receive when we first sign on to
310 * a channel */
311
312 if (((strstr(buf, " 353 ")) && (!strstr(buf, "PRIVMSG")) &&
313 (!strstr(buf, "NOTICE")))) {
314 gchar u_host[255];
315 gchar u_command[32];
316 gchar u_channel[128];
317 gchar u_names[IRC_BUF_LEN + 1];
318 struct conversation *convo = NULL;
319 int j;
320
321 for (j = 0, i = 0; buf[i] != ' '; j++, i++) {
322 u_host[j] = buf[i];
323 }
324
325 u_host[j] = '\0'; i++;
326
327 for (j = 0; buf[i] != ' '; j++, i++) {
328 u_command[j] = buf[i];
329 }
330
331 u_command[j] = '\0'; i++;
332
333 for (j = 0; buf[i] != '#'; j++, i++) {
334 }
335 i++;
336
337 for (j = 0; buf[i] != ':'; j++, i++) {
338 u_channel[j] = buf[i];
339 }
340
341 u_channel[j-1] = '\0'; i++;
342
343 while ((buf[i] == ' ') || (buf[i] == ':')) {
344 i++;
345 }
346
347 strcpy(u_names, buf + i);
348
349 buf2 = g_strsplit(u_names, " ", 0);
350
351 /* Let's get our conversation window */
352 convo = find_conversation_by_name(gc, u_channel);
353
354 if (!convo) {
355 return;
356 }
357
358 /* Now that we've parsed the hell out of this big
359 * mess, let's try to split up the names properly */
360
361 for (i = 0; buf2[i] != NULL; i++) {
362 /* We shouldnt play with ourselves */
363 if (g_strcasecmp(buf2[i], gc->username) != 0) {
364 /* Add the person to the list */
365 add_chat_buddy(convo, buf2[i]);
366 }
367 }
368
369 return;
370
371 }
372
373
262 if ( (strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { 374 if ( (strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
263 375
264 gchar u_channel[128]; 376 gchar u_channel[128];
265 gchar u_nick[128]; 377 gchar u_nick[128];
266 378
279 391
280 i++; 392 i++;
281 393
282 strcpy(u_channel, buf+i); 394 strcpy(u_channel, buf+i);
283 395
284 /* Looks like we're going to join the channel for real now. Let's create 396 /* Looks like we're going to join the channel for real
285 * a valid channel structure and add it to our list. Let's make sure that 397 * now. Let's create a valid channel structure and add
398 * it to our list. Let's make sure that
286 * we are not already in a channel first */ 399 * we are not already in a channel first */
287 400
288 channel = find_channel_by_name(gc, u_channel); 401 channel = find_channel_by_name(gc, u_channel);
289 402
290 if (!channel) { 403 if (!channel) {
295 channel->id = chat_id; 408 channel->id = chat_id;
296 channel->name = strdup(u_channel); 409 channel->name = strdup(u_channel);
297 410
298 idata->channels = g_list_append(idata->channels, channel); 411 idata->channels = g_list_append(idata->channels, channel);
299 412
413 printf("Started channel with ID %d\n", chat_id);
300 serv_got_joined_chat(gc, chat_id, u_channel); 414 serv_got_joined_chat(gc, chat_id, u_channel);
301 printf("IIII: I joined '%s' with a strlen() of '%d'\n", u_channel, strlen(u_channel));
302 } else { 415 } else {
303 /* Someone else joined. */ 416 struct conversation *convo = NULL;
304 printf("%s has joined #%s\n", u_nick, u_channel); 417
418 /* Someone else joined. Find their conversation
419 * window */
420 convo = find_conversation_by_id(gc, channel->id);
421
422 /* And add their name to it */
423 add_chat_buddy(convo, u_nick);
424
305 } 425 }
306 426
307 return; 427 return;
308 } 428 }
309 429
330 i++; 450 i++;
331 451
332 strcpy(u_channel, buf+i); 452 strcpy(u_channel, buf+i);
333 453
334 454
335 /* Now, lets check to see if it was US that was leaving. If so, do the 455 /* Now, lets check to see if it was US that was leaving.
336 * correct thing by closing up all of our old channel stuff. Otherwise, 456 * If so, do the correct thing by closing up all of our
457 * old channel stuff. Otherwise,
337 * we should just print that someone left */ 458 * we should just print that someone left */
338 459
460 channel = find_channel_by_name(gc, u_channel);
461
462 if (!channel) {
463 return;
464 }
465
339 if (g_strcasecmp(u_nick, gc->username) == 0) { 466 if (g_strcasecmp(u_nick, gc->username) == 0) {
340 467
341 /* Looks like we're going to join the channel for real now. Let's create 468 /* Looks like we're going to leave the channel for
342 * a valid channel structure and add it to our list */ 469 * real now. Let's create a valid channel structure
343 470 * and add it to our list */
344 channel = find_channel_by_name(gc, u_channel);
345
346 if (!channel) {
347 return;
348 }
349 471
350 serv_got_chat_left(gc, channel->id); 472 serv_got_chat_left(gc, channel->id);
351 473
352 idata->channels = g_list_remove(idata->channels, channel); 474 idata->channels = g_list_remove(idata->channels, channel);
353 g_free(channel); 475 g_free(channel);
354 return; 476 } else {
355 } 477 struct conversation *convo = NULL;
356 478
357 /* Otherwise, lets just say someone left */ 479 /* Find their conversation window */
358 printf("%s has left #%s\n", u_nick, u_channel); 480 convo = find_conversation_by_id(gc, channel->id);
359 481
482 if (!convo) {
483 /* Some how the window doesn't exist.
484 * Let's get out of here */
485 return ;
486 }
487
488 /* And remove their name */
489 remove_chat_buddy(convo, u_nick);
490
491 }
492
493 /* Go Home! */
360 return; 494 return;
361 } 495 }
362 496
363 if ( (strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) { 497 if ( (strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) {
364 gchar u_nick[128]; 498 gchar u_nick[128];