changeset 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 2bf8a8131479
children b16642ac87b2
files src/protocols/irc/irc.c
diffstat 1 files changed, 49 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/irc/irc.c	Fri Sep 21 01:58:44 2001 +0000
+++ b/src/protocols/irc/irc.c	Fri Sep 21 08:59:42 2001 +0000
@@ -647,6 +647,51 @@
 	}
 }
 
+static void handle_privmsg(struct gaim_connection *gc, char *to, char *nick, char *msg)
+{
+	if (is_channel(gc, to)) {
+		struct conversation *c = irc_find_chat(gc, to);
+		if (!c)
+			return;
+		irc_got_chat_in(gc, c->id, nick, 0, msg, time(NULL));
+	} else {
+		char *tmp = g_malloc(strlen(nick) + 2);
+		g_snprintf(tmp, strlen(nick) + 2, "@%s", nick);
+		if (find_conversation(tmp))
+			irc_got_im(gc, tmp, msg, 0, time(NULL));
+		else {
+			*tmp = '+';
+			if (find_conversation(tmp))
+				irc_got_im(gc, tmp, msg, 0, time(NULL));
+			else
+				irc_got_im(gc, nick, msg, 0, time(NULL));
+		}
+		g_free(tmp);
+	}
+}
+
+static void handle_ctcp(struct gaim_connection *gc, char *to, char *nick,
+			char *msg, char *word[], char *word_eol[])
+{
+	struct irc_data *id = gc->proto_data;
+	char buf[IRC_BUF_LEN];
+
+	if (!g_strncasecmp(msg, "VERSION", 7)) {
+		g_snprintf(buf, sizeof(buf), "NOTICE %s :\001VERSION GAIM " VERSION ": The Pimpin "
+					     "Penguin AIM Clone: " WEBSITE "\001\r\n", nick);
+		irc_write(id->fd, buf, strlen(buf));
+	}
+	if (!g_strncasecmp(msg, "ACTION", 6)) {
+		char *po = strchr(msg + 6, 1);
+		char *tmp;
+		if (po) *po = 0;
+		tmp = g_strconcat("/me", msg + 6, NULL);
+		handle_privmsg(gc, to, nick, tmp);
+		g_free(tmp);
+	}
+	/* XXX should probably write_to_conv or something here */
+}
+
 static void irc_callback(gpointer data, gint source, GaimInputCondition condition)
 {
 	struct gaim_connection *gc = data;
@@ -797,54 +842,11 @@
 		to = word[3];
 		msg = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4];
 		if (msg[0] == 1 && msg[strlen (msg) - 1] == 1) { /* ctcp */
-			if (!g_strncasecmp(msg + 1, "ACTION", 6)) {
-				char *po = strchr(msg + 7, 1);
-				char *tmp;
-				if (po) *po = 0;
-				if (is_channel(gc, to)) {
-					struct conversation *c = irc_find_chat(gc, to);
-					if (!c)
-						return;
-					tmp = g_strconcat("/me", msg + 7, NULL);
-					irc_got_chat_in(gc, c->id, nick, 0, tmp, time(NULL));
-					g_free(tmp);
-				} else {
-					tmp = g_strconcat("/me", msg + 7, NULL);
-					to = g_malloc(strlen(nick) + 2);
-					g_snprintf(to, strlen(nick) + 2, "@%s", nick);
-					if (find_conversation(to))
-						irc_got_im(gc, to, tmp, 0, time(NULL));
-					else {
-						*to = '+';
-						if (find_conversation(to))
-							irc_got_im(gc, to, tmp, 0, time(NULL));
-						else
-							irc_got_im(gc, nick, tmp, 0, time(NULL));
-					}
-					g_free(to);
-					g_free(tmp);
-				}
-			}
+			if (!g_strncasecmp(msg + 1, "DCC ", 4))
+				process_data_init(pdibuf, buf, word, word_eol, TRUE);
+			handle_ctcp(gc, to, nick, msg + 1, word, word_eol);
 		} else {
-			if (is_channel(gc, to)) {
-				struct conversation *c = irc_find_chat(gc, to);
-				if (!c)
-					return;
-				irc_got_chat_in(gc, c->id, nick, 0, msg, time(NULL));
-			} else {
-				to = g_malloc(strlen(nick) + 2);
-				g_snprintf(to, strlen(nick) + 2, "@%s", nick);
-				if (find_conversation(to))
-					irc_got_im(gc, to, msg, 0, time(NULL));
-				else {
-					*to = '+';
-					if (find_conversation(to))
-						irc_got_im(gc, to, msg, 0, time(NULL));
-					else
-						irc_got_im(gc, nick, msg, 0, time(NULL));
-				}
-				g_free(to);
-			}
+			handle_privmsg(gc, to, nick, msg);
 		}
 	} else if (!strcmp(cmd, "PONG")) { /* */
 	} else if (!strcmp(cmd, "QUIT")) {