Mercurial > pidgin
comparison src/protocols/irc/irc.c @ 2339:9bda60d2d2e6
[gaim-migrate @ 2352]
removing some duplicate code and handling CTCP VERSION ;)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 21 Sep 2001 08:59:42 +0000 |
parents | 1ea2792b6004 |
children | 569ae9f2bb89 |
comparison
equal
deleted
inserted
replaced
2338:2bf8a8131479 | 2339:9bda60d2d2e6 |
---|---|
645 } | 645 } |
646 bcs = bcs->next; | 646 bcs = bcs->next; |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 static void handle_privmsg(struct gaim_connection *gc, char *to, char *nick, char *msg) | |
651 { | |
652 if (is_channel(gc, to)) { | |
653 struct conversation *c = irc_find_chat(gc, to); | |
654 if (!c) | |
655 return; | |
656 irc_got_chat_in(gc, c->id, nick, 0, msg, time(NULL)); | |
657 } else { | |
658 char *tmp = g_malloc(strlen(nick) + 2); | |
659 g_snprintf(tmp, strlen(nick) + 2, "@%s", nick); | |
660 if (find_conversation(tmp)) | |
661 irc_got_im(gc, tmp, msg, 0, time(NULL)); | |
662 else { | |
663 *tmp = '+'; | |
664 if (find_conversation(tmp)) | |
665 irc_got_im(gc, tmp, msg, 0, time(NULL)); | |
666 else | |
667 irc_got_im(gc, nick, msg, 0, time(NULL)); | |
668 } | |
669 g_free(tmp); | |
670 } | |
671 } | |
672 | |
673 static void handle_ctcp(struct gaim_connection *gc, char *to, char *nick, | |
674 char *msg, char *word[], char *word_eol[]) | |
675 { | |
676 struct irc_data *id = gc->proto_data; | |
677 char buf[IRC_BUF_LEN]; | |
678 | |
679 if (!g_strncasecmp(msg, "VERSION", 7)) { | |
680 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001VERSION GAIM " VERSION ": The Pimpin " | |
681 "Penguin AIM Clone: " WEBSITE "\001\r\n", nick); | |
682 irc_write(id->fd, buf, strlen(buf)); | |
683 } | |
684 if (!g_strncasecmp(msg, "ACTION", 6)) { | |
685 char *po = strchr(msg + 6, 1); | |
686 char *tmp; | |
687 if (po) *po = 0; | |
688 tmp = g_strconcat("/me", msg + 6, NULL); | |
689 handle_privmsg(gc, to, nick, tmp); | |
690 g_free(tmp); | |
691 } | |
692 /* XXX should probably write_to_conv or something here */ | |
693 } | |
694 | |
650 static void irc_callback(gpointer data, gint source, GaimInputCondition condition) | 695 static void irc_callback(gpointer data, gint source, GaimInputCondition condition) |
651 { | 696 { |
652 struct gaim_connection *gc = data; | 697 struct gaim_connection *gc = data; |
653 struct irc_data *idata = gc->proto_data; | 698 struct irc_data *idata = gc->proto_data; |
654 int i = 0; | 699 int i = 0; |
795 if (!*word[3]) | 840 if (!*word[3]) |
796 return; | 841 return; |
797 to = word[3]; | 842 to = word[3]; |
798 msg = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; | 843 msg = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; |
799 if (msg[0] == 1 && msg[strlen (msg) - 1] == 1) { /* ctcp */ | 844 if (msg[0] == 1 && msg[strlen (msg) - 1] == 1) { /* ctcp */ |
800 if (!g_strncasecmp(msg + 1, "ACTION", 6)) { | 845 if (!g_strncasecmp(msg + 1, "DCC ", 4)) |
801 char *po = strchr(msg + 7, 1); | 846 process_data_init(pdibuf, buf, word, word_eol, TRUE); |
802 char *tmp; | 847 handle_ctcp(gc, to, nick, msg + 1, word, word_eol); |
803 if (po) *po = 0; | |
804 if (is_channel(gc, to)) { | |
805 struct conversation *c = irc_find_chat(gc, to); | |
806 if (!c) | |
807 return; | |
808 tmp = g_strconcat("/me", msg + 7, NULL); | |
809 irc_got_chat_in(gc, c->id, nick, 0, tmp, time(NULL)); | |
810 g_free(tmp); | |
811 } else { | |
812 tmp = g_strconcat("/me", msg + 7, NULL); | |
813 to = g_malloc(strlen(nick) + 2); | |
814 g_snprintf(to, strlen(nick) + 2, "@%s", nick); | |
815 if (find_conversation(to)) | |
816 irc_got_im(gc, to, tmp, 0, time(NULL)); | |
817 else { | |
818 *to = '+'; | |
819 if (find_conversation(to)) | |
820 irc_got_im(gc, to, tmp, 0, time(NULL)); | |
821 else | |
822 irc_got_im(gc, nick, tmp, 0, time(NULL)); | |
823 } | |
824 g_free(to); | |
825 g_free(tmp); | |
826 } | |
827 } | |
828 } else { | 848 } else { |
829 if (is_channel(gc, to)) { | 849 handle_privmsg(gc, to, nick, msg); |
830 struct conversation *c = irc_find_chat(gc, to); | |
831 if (!c) | |
832 return; | |
833 irc_got_chat_in(gc, c->id, nick, 0, msg, time(NULL)); | |
834 } else { | |
835 to = g_malloc(strlen(nick) + 2); | |
836 g_snprintf(to, strlen(nick) + 2, "@%s", nick); | |
837 if (find_conversation(to)) | |
838 irc_got_im(gc, to, msg, 0, time(NULL)); | |
839 else { | |
840 *to = '+'; | |
841 if (find_conversation(to)) | |
842 irc_got_im(gc, to, msg, 0, time(NULL)); | |
843 else | |
844 irc_got_im(gc, nick, msg, 0, time(NULL)); | |
845 } | |
846 g_free(to); | |
847 } | |
848 } | 850 } |
849 } else if (!strcmp(cmd, "PONG")) { /* */ | 851 } else if (!strcmp(cmd, "PONG")) { /* */ |
850 } else if (!strcmp(cmd, "QUIT")) { | 852 } else if (!strcmp(cmd, "QUIT")) { |
851 irc_rem_chat_bud(gc, nick); | 853 irc_rem_chat_bud(gc, nick); |
852 } else if (!strcmp(cmd, "TOPIC")) { | 854 } else if (!strcmp(cmd, "TOPIC")) { |