From 090e88b34db29b681c7579472aafa211832d38af Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 17 Nov 2000 03:08:32 +0000 Subject: If other side replies to our DCC CHAT request with DCC CHAT request of their own (maybe we were inside firewall and other side noticed it), connect to it immediately. Don't allow more than one identical DCC request, if more is received just update the port of the previous request. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@844 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/dcc/dcc.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/irc/dcc/dcc.c') diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c index e8143442..b2223e6a 100644 --- a/src/irc/dcc/dcc.c +++ b/src/irc/dcc/dcc.c @@ -284,9 +284,9 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char char *type, *arg, *addrstr, *portstr, *sizestr, *str; void *free_arg; const char *cstr; - DCC_REC *dcc; + DCC_REC *dcc, *olddcc; long size; - int port; + int dcctype, port; g_return_if_fail(data != NULL); g_return_if_fail(sender != NULL); @@ -298,7 +298,27 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char if (sscanf(portstr, "%d", &port) != 1) port = 0; if (sscanf(sizestr, "%ld", &size) != 1) size = 0; - dcc = dcc_create(SWAP_SENDGET(dcc_str2type(type)), -1, sender, arg, server, chat); + dcctype = SWAP_SENDGET(dcc_str2type(type)); + olddcc = dcc_find_item(dcctype, sender, + dcctype == DCC_TYPE_CHAT ? NULL : arg); + if (olddcc != NULL) { + /* same DCC request offered again */ + if (olddcc->type == DCC_TYPE_CHAT && + olddcc->handle != -1 && olddcc->starttime == 0) { + /* we requested dcc chat, they requested + dcc chat from us .. allow it. */ + dcc_destroy(olddcc); + } else { + /* if the connection isn't open, update the port, + otherwise just ignore */ + if (olddcc->handle == -1) + olddcc->port = port; + cmd_params_free(free_arg); + return; + } + } + + dcc = dcc_create(dcctype, -1, sender, arg, server, chat); dcc_get_address(addrstr, &dcc->addr); net_ip2host(&dcc->addr, dcc->addrstr); dcc->port = port; @@ -327,7 +347,8 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char case DCC_TYPE_CHAT: cstr = settings_get_str("dcc_autochat_masks"); - if (*cstr != '\0' && masks_match(SERVER(server), cstr, sender, sendaddr)) + if (olddcc != NULL || + (*cstr != '\0' && masks_match(SERVER(server), cstr, sender, sendaddr))) { /* automatically accept chat */ str = g_strdup_printf("CHAT %s", dcc->nick); -- cgit v1.2.3