Mercurial > pidgin
comparison plugins/irc.c @ 1022:d5c022006a60
[gaim-migrate @ 1032]
Mucho changes.
Buddylist works now (mostly). If you have a buddylist larger than
512 bytes then some people won't show up as online. I know how to
fix this but I got sleepy.
I forget what else I fixed. It's cool stuff though, so check it out.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Tue, 24 Oct 2000 10:08:00 +0000 |
parents | 90e8714bf95b |
children | 4593605da0e2 |
comparison
equal
deleted
inserted
replaced
1021:90e8714bf95b | 1022:d5c022006a60 |
---|---|
50 #define IRC_SERVER "irc.mozilla.org" | 50 #define IRC_SERVER "irc.mozilla.org" |
51 #define IRC_PORT 6667 | 51 #define IRC_PORT 6667 |
52 | 52 |
53 #define IRC_BUF_LEN 4096 | 53 #define IRC_BUF_LEN 4096 |
54 | 54 |
55 | |
55 static int chat_id = 0; | 56 static int chat_id = 0; |
56 | 57 |
57 struct irc_channel { | 58 struct irc_channel { |
58 int id; | 59 int id; |
59 gchar *name; | 60 gchar *name; |
60 }; | 61 }; |
61 | 62 |
62 struct irc_data { | 63 struct irc_data { |
63 int fd; | 64 int fd; |
64 | 65 |
66 int timer; | |
67 | |
68 int totalblocks; | |
69 int recblocks; | |
70 | |
71 GSList *templist; | |
65 GList *channels; | 72 GList *channels; |
66 }; | 73 }; |
67 | 74 |
68 static char *irc_name() { | 75 static char *irc_name() { |
69 return "IRC"; | 76 return "IRC"; |
84 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); | 91 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); |
85 write(idata->fd, buf, strlen(buf)); | 92 write(idata->fd, buf, strlen(buf)); |
86 | 93 |
87 g_free(buf); | 94 g_free(buf); |
88 } | 95 } |
96 | |
97 void irc_update_user (struct gaim_connection *gc, char *name, int status) { | |
98 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
99 struct irc_channel *u; | |
100 GSList *temp = idata->templist; | |
101 | |
102 /* Loop through our list */ | |
103 | |
104 while (temp) { | |
105 u = (struct irc_channel *)temp->data; | |
106 if (g_strcasecmp(u->name, name) == 0) { | |
107 u->id = status; | |
108 return; | |
109 } | |
110 | |
111 temp = g_slist_next(temp); | |
112 } | |
113 return; | |
114 } | |
115 | |
116 void irc_request_buddy_update ( struct gaim_connection *gc ) { | |
117 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
118 GSList *grp = groups; | |
119 GList *person; | |
120 struct group *g; | |
121 struct buddy *b; | |
122 struct irc_channel *u; | |
123 gchar buf[IRC_BUF_LEN+1]; | |
124 | |
125 if (idata->templist != NULL) | |
126 return; | |
127 | |
128 idata->recblocks = 0; | |
129 idata->totalblocks = 1; | |
130 | |
131 /* Send the first part of our request */ | |
132 write(idata->fd, "ISON", 4); | |
133 | |
134 /* Step through our list of groups */ | |
135 while (grp) { | |
136 | |
137 g = (struct group *)grp->data; | |
138 person = g->members; | |
139 | |
140 while (person) { | |
141 b = (struct buddy *)person->data; | |
142 | |
143 /* We will store our buddy info here. I know, this is cheap | |
144 * but hey, its the exact same data structure. Why should we | |
145 * bother with making another one */ | |
146 | |
147 u = g_new0(struct irc_channel, 1); | |
148 u->id = 0; /* Assume by default that they're offline */ | |
149 u->name = strdup(b->name); | |
150 | |
151 write(idata->fd, " ", 1); | |
152 write(idata->fd, u->name, strlen(u->name)); | |
153 idata->templist = g_slist_append(idata->templist, u); | |
154 | |
155 person = person->next; | |
156 } | |
157 | |
158 grp = g_slist_next(grp); | |
159 } | |
160 write(idata->fd, "\n", 1); | |
161 } | |
162 | |
89 | 163 |
90 void irc_send_im( struct gaim_connection *gc, char *who, char *message, int away) { | 164 void irc_send_im( struct gaim_connection *gc, char *who, char *message, int away) { |
91 | 165 |
92 struct irc_data *idata = (struct irc_data *)gc->proto_data; | 166 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
93 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN + 1); | 167 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN + 1); |
372 | 446 |
373 return; | 447 return; |
374 | 448 |
375 } | 449 } |
376 | 450 |
451 /* Receive a list of users that are currently online */ | |
452 | |
453 if (((strstr(buf, " 303 ")) && (!strstr(buf, "PRIVMSG")) && | |
454 (!strstr(buf, "NOTICE")))) { | |
455 gchar u_host[255]; | |
456 gchar u_command[32]; | |
457 gchar u_names[IRC_BUF_LEN + 1]; | |
458 int j; | |
459 | |
460 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
461 u_host[j] = buf[i]; | |
462 } | |
463 | |
464 u_host[j] = '\0'; i++; | |
465 | |
466 for (j = 0; buf[i] != ' '; j++, i++) { | |
467 u_command[j] = buf[i]; | |
468 } | |
469 | |
470 u_command[j] = '\0'; i++; | |
471 | |
472 for (j = 0; buf[i] != ':'; j++, i++) { | |
473 /* My Nick */ | |
474 } | |
475 i++; | |
476 | |
477 strcpy(u_names, buf + i); | |
478 | |
479 buf2 = g_strsplit(u_names, " ", 0); | |
480 | |
481 /* Now that we've parsed the hell out of this big | |
482 * mess, let's try to split up the names properly */ | |
483 | |
484 for (i = 0; buf2[i] != NULL; i++) { | |
485 /* If we have a name here then our buddy is online. We should | |
486 * update our temporary gslist accordingly. When we achieve our maximum | |
487 * list of names then we should force an update */ | |
488 | |
489 irc_update_user(gc, buf2[i], 1); | |
490 } | |
491 | |
492 /* Increase our received blocks counter */ | |
493 idata->recblocks++; | |
494 | |
495 /* If we have our total number of blocks */ | |
496 if (idata->recblocks == idata->totalblocks) { | |
497 GSList *temp; | |
498 struct irc_channel *u; | |
499 | |
500 /* Let's grab our list of people and bring them all on or off line */ | |
501 temp = idata->templist; | |
502 | |
503 /* Loop */ | |
504 while (temp) { | |
505 | |
506 u = temp->data; | |
507 | |
508 /* Tell Gaim to bring the person on or off line */ | |
509 serv_got_update(u->name, u->id, 0, 0, 0, 0, 0); | |
510 | |
511 /* Grab the next entry */ | |
512 temp = g_slist_next(temp); | |
513 } | |
514 | |
515 /* And now, let's delete all of our entries */ | |
516 temp = idata->templist; | |
517 while (temp) { | |
518 u = temp->data; | |
519 g_free(u->name); | |
520 temp = g_slist_remove(temp, u); | |
521 } | |
522 | |
523 /* Reset our list */ | |
524 idata->totalblocks = 0; | |
525 idata->recblocks = 0; | |
526 | |
527 idata->templist = NULL; | |
528 | |
529 return; | |
530 } | |
531 | |
532 /* And free our pointers */ | |
533 g_strfreev (buf2); | |
534 | |
535 return; | |
536 | |
537 } | |
538 | |
377 | 539 |
378 if ( (strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { | 540 if ( (strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
379 | 541 |
380 gchar u_channel[128]; | 542 gchar u_channel[128]; |
381 gchar u_nick[128]; | 543 gchar u_nick[128]; |
412 channel->id = chat_id; | 574 channel->id = chat_id; |
413 channel->name = strdup(u_channel); | 575 channel->name = strdup(u_channel); |
414 | 576 |
415 idata->channels = g_list_append(idata->channels, channel); | 577 idata->channels = g_list_append(idata->channels, channel); |
416 | 578 |
417 printf("Started channel with ID %d\n", chat_id); | |
418 serv_got_joined_chat(gc, chat_id, u_channel); | 579 serv_got_joined_chat(gc, chat_id, u_channel); |
419 } else { | 580 } else { |
420 struct conversation *convo = NULL; | 581 struct conversation *convo = NULL; |
421 | 582 |
422 /* Someone else joined. Find their conversation | 583 /* Someone else joined. Find their conversation |
620 GList *chats = idata->channels; | 781 GList *chats = idata->channels; |
621 struct irc_channel *cc; | 782 struct irc_channel *cc; |
622 | 783 |
623 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN); | 784 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN); |
624 | 785 |
786 gtk_timeout_remove(idata->timer); | |
787 | |
625 g_snprintf(buf, IRC_BUF_LEN, "QUIT :Download GAIM [www.marko.net/gaim]\n"); | 788 g_snprintf(buf, IRC_BUF_LEN, "QUIT :Download GAIM [www.marko.net/gaim]\n"); |
626 write(idata->fd, buf, strlen(buf)); | 789 write(idata->fd, buf, strlen(buf)); |
627 | 790 |
628 g_free(buf); | 791 g_free(buf); |
629 | 792 |
722 refresh_buddy_window(); | 885 refresh_buddy_window(); |
723 | 886 |
724 serv_finish_login(gc); | 887 serv_finish_login(gc); |
725 gaim_setup(gc); | 888 gaim_setup(gc); |
726 | 889 |
890 if (bud_list_cache_exists(gc)) | |
891 do_import(NULL, gc); | |
892 | |
893 | |
727 gc->inpa = gdk_input_add(idata->fd, GDK_INPUT_READ, irc_handler, gc); | 894 gc->inpa = gdk_input_add(idata->fd, GDK_INPUT_READ, irc_handler, gc); |
895 | |
896 /* We want to update our buddlist every 20 seconds */ | |
897 idata->timer = gtk_timeout_add(20000, (GtkFunction)irc_request_buddy_update, gc); | |
898 | |
899 /* But first, let's go ahead and check our list */ | |
900 irc_request_buddy_update(gc); | |
728 } | 901 } |
729 | 902 |
730 struct prpl *irc_init() { | 903 struct prpl *irc_init() { |
731 struct prpl *ret = g_new0(struct prpl, 1); | 904 struct prpl *ret = g_new0(struct prpl, 1); |
732 | 905 |