static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { CHAT_DCC_REC *dcc; GHashTable *optlist; char *text, *target; void *free_arg; g_return_if_fail(data != NULL); if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST, "msg", &optlist, &target, &text)) return; /* handle only DCC messages */ if (strcmp(target, "*") == 0) dcc = item_get_dcc(item); else if (*target == '=') dcc = dcc_chat_find_id(target+1); else dcc = NULL; if (dcc == NULL && *target == '=') { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_DCC_CHAT_NOT_FOUND, target+1); } else if (dcc != NULL) { if (query_find(NULL, target) == NULL) completion_last_message_add(target); signal_emit("message dcc own", 2, dcc, text); } cmd_params_free(free_arg); }
/* Send text to DCC chat */ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { CHAT_DCC_REC *dcc; GHashTable *optlist; char *text, *target; void *free_arg; g_return_if_fail(data != NULL); if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST, "msg", &optlist, &target, &text)) return; /* handle only DCC messages */ if (g_strcmp0(target, "*") == 0) dcc = item_get_dcc(item); else if (*target == '=') dcc = dcc_chat_find_id(target+1); else dcc = NULL; if (dcc != NULL && dcc->sendbuf != NULL) { char *recoded; recoded = recode_out(server, text, dcc->nick); dcc_chat_send(dcc, recoded); g_free(recoded); } if (dcc != NULL || *target == '=') signal_stop(); cmd_params_free(free_arg); }
static void cmd_me(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { CHAT_DCC_REC *dcc; dcc = item_get_dcc(item); if (dcc != NULL) signal_emit("message dcc own_action", 2, dcc, data); }
/* DCC SEND [-append | -prepend | -flush | -rmtail | -rmhead] <nick> <file> [<file> ...] */ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { const char *servertag; char *nick, *fileargs; void *free_arg; CHAT_DCC_REC *chat; GHashTable *optlist; int queue, mode; if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST, "dcc send", &optlist, &nick, &fileargs)) return; chat = item_get_dcc(item); if (chat != NULL && (chat->mirc_ctcp || g_strcasecmp(nick, chat->nick) != 0)) chat = NULL; if (!IS_IRC_SERVER(server) || !server->connected) servertag = NULL; else servertag = server->tag; if (servertag == NULL && chat == NULL) cmd_param_error(CMDERR_NOT_CONNECTED); if (g_hash_table_lookup(optlist, "rmhead") != NULL) { queue = dcc_queue_old(nick, servertag); if (queue != -1) dcc_queue_remove_head(queue); } else if (g_hash_table_lookup(optlist, "rmtail") != NULL) { queue = dcc_queue_old(nick, servertag); if (queue != -1) dcc_queue_remove_tail(queue); } else if (g_hash_table_lookup(optlist, "flush") != NULL) { queue = dcc_queue_old(nick, servertag); if (queue != -1) dcc_queue_free(queue); } else { if (g_hash_table_lookup(optlist, "append") != NULL) mode = DCC_QUEUE_APPEND; else if (g_hash_table_lookup(optlist, "prepend") != NULL) mode = DCC_QUEUE_PREPEND; else mode = DCC_QUEUE_NORMAL; if (*fileargs == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); dcc_send_add(servertag, chat, nick, fileargs, mode); } cmd_params_free(free_arg); }
static void cmd_mircdcc(gchar *data, IRC_SERVER_REC *server, WI_IRC_REC *item) { DCC_REC *dcc; g_return_if_fail(data != NULL); dcc = item_get_dcc(item); if (dcc == NULL) return; dcc->mirc_ctcp = toupper(*data) == 'N' ? FALSE : TRUE; }
static void cmd_me(const char *data, SERVER_REC *server, WI_IRC_REC *item) { DCC_REC *dcc; g_return_if_fail(data != NULL); dcc = item_get_dcc(item); if (dcc == NULL) return; printformat(NULL, item->name, MSGLEVEL_DCC, IRCTXT_OWN_DCC_ME, dcc->mynick, data); }
/* SYNTAX: MIRCDCC ON|OFF */ static void cmd_mircdcc(const char *data, SERVER_REC *server, QUERY_REC *item) { CHAT_DCC_REC *dcc; g_return_if_fail(data != NULL); dcc = item_get_dcc((WI_ITEM_REC *) item); if (dcc == NULL) return; dcc->mirc_ctcp = i_toupper(*data) != 'N' && g_ascii_strncasecmp(data, "OF", 2) != 0; }
static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item) { DCC_REC *dcc; char *str; g_return_if_fail(data != NULL); dcc = item_get_dcc(item); if (dcc == NULL) return; str = g_strdup_printf("ACTION %s", data); dcc_ctcp_message(dcc->nick, NULL, dcc, FALSE, str); g_free(str); signal_stop(); }
static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { CHAT_DCC_REC *dcc; char *str; g_return_if_fail(data != NULL); dcc = item_get_dcc(item); if (dcc == NULL) return; str = g_strconcat("ACTION ", data, NULL); dcc_ctcp_message(server, dcc->nick, dcc, FALSE, str); g_free(str); signal_stop(); }
static void cmd_whois(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { CHAT_DCC_REC *dcc; g_return_if_fail(data != NULL); /* /WHOIS without target in DCC CHAT query? */ if (*data == '\0') { dcc = item_get_dcc(item); if (dcc != NULL) { signal_emit("command whois", 3, dcc->nick, server, item); signal_stop(); } } }
/* command: DCC SEND */ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item) { char *params, *target, *fname, *str, *ptr; char host[MAX_IP_LEN]; int hfile, hlisten, port; long fsize; DCC_REC *dcc, *chat; IPADDR own_ip; g_return_if_fail(data != NULL); params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &fname); if (*target == '\0' || *fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); /* if we're in dcc chat, send the request via it. */ chat = item_get_dcc(item); if (chat != NULL && (chat->mirc_ctcp || g_strcasecmp(target, chat->nick) != 0)) chat = NULL; if ((server == NULL || !server->connected) && chat == NULL) cmd_param_error(CMDERR_NOT_CONNECTED); if (dcc_find_item(DCC_TYPE_SEND, target, fname)) { signal_emit("dcc error send exists", 2, target, fname); g_free(params); return; } str = convert_home(fname); if (!g_path_is_absolute(str)) { char *path; g_free(str); path = convert_home(settings_get_str("dcc_upload_path")); str = g_strconcat(path, G_DIR_SEPARATOR_S, fname, NULL); g_free(path); } hfile = open(str, O_RDONLY); g_free(str); if (hfile == -1) { signal_emit("dcc error file not found", 2, target, fname); g_free(params); return; } fsize = lseek(hfile, 0, SEEK_END); lseek(hfile, 0, SEEK_SET); /* get the IP address we use with IRC server */ if (net_getsockname(chat != NULL ? chat->handle : server->handle, &own_ip, NULL) == -1) { close(hfile); cmd_param_error(CMDERR_ERRNO); } /* start listening */ port = settings_get_int("dcc_port"); hlisten = net_listen(&own_ip, &port); if (hlisten == -1) { close(hfile); cmd_param_error(CMDERR_ERRNO); } /* skip path, change all spaces to _ */ fname = g_strdup(g_basename(fname)); for (ptr = fname; *ptr != '\0'; ptr++) if (*ptr == ' ') *ptr = '_'; dcc = dcc_create(DCC_TYPE_SEND, hlisten, target, fname, server, chat); dcc->port = port; dcc->size = fsize; dcc->fhandle = hfile; dcc->tagread = g_input_add(hlisten, G_INPUT_READ, (GInputFunction) dcc_send_init, dcc); /* send DCC request */ dcc_make_address(&own_ip, host); str = g_strdup_printf("DCC SEND %s %s %d %lu", fname, host, port, fsize); dcc_ctcp_message(target, server, chat, FALSE, str); g_free(str); g_free(fname); g_free(params); }