From d19630bc7952a22acc11169be42f410e222fb904 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sun, 8 Mar 2026 07:12:34 -0400 Subject: Respond to incoming CTCPs. --- commands.txt | 20 +++++++++++++++++++- src/irc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/commands.txt b/commands.txt index 9641d6d..eb7fa0b 100644 --- a/commands.txt +++ b/commands.txt @@ -16,6 +16,11 @@ Joins a channel, creates a new screen if possible. If a screen can't be created, channel text will be sent to the [server] screen, and "/m #channel" must be used, to send to the channel. +/j1 +/join1 +Joins a channel without creating a new screen. Channel test will be +sent to the [server] screen. Use "/m #channel" to send to the channel. + /m /msg PRIVMSG to nick or channel. @@ -36,11 +41,21 @@ Parts (leaves) a channel. If no #chan is given, the current screen's channel is parted (if you're in a channel screen). If there's a screen for the channel, it gets closed. +/names [] +Shows the list of users in a channel. Uses the current screen's channel, +if no given. On most networks, it's not very useful to use +/names on a channel you haven't joined. + +/topic [] +Shows the channel topic and its creator. With no , uses the +current screen's channel. + /ping [] With no argument: ping the server. With arg: CTCP ping the nick. The contents of RTCLOK are sent as the ping data, so when the PONG response is received, the round-trip time can be shown, with up to 1/60 (NTSC) or 1/50 (PAL) second accuracy. +TODO: not implemented yet. /me CTCP ACTION. Only works in a channel or query screen (eventually @@ -60,10 +75,13 @@ any arguments lists every channel on the server, which isn't useful. /color [] [] [] Set colors. This should be on a per-screen basis, eventually. +TODO: this only takes bg and fg arguments, currently. /chans List all channels we've joined. This will actually be limited to something like 20 (who joins more than 20 channels anyway?) +TODO: not implemented yet. /quote -Send raw IRC protocol. +Send raw IRC protocol to the server. This bypasses local command +parsing. diff --git a/src/irc.c b/src/irc.c index 3a57015..f5ac809 100644 --- a/src/irc.c +++ b/src/irc.c @@ -78,6 +78,54 @@ static void do_priv_nick(void) { scr_print_active("* "); } +/* FIXME: this isn't very fast */ +static void do_ctcp(void) { + static char *p, *ctcp_type, *resp; + + resp = 0; + ctcp_type = ++msg_text; /* skip leading ^A */ + + if( (p = strchr(msg_text, '\x01')) ) { + /* kill trailing ^A */ + *p = 0; + } + + if( (p = strchr(msg_text, ' ')) ) { + *p++ = 0; + } + + if(streq_i(ctcp_type, "ACTION")) { + scr_print_active("* "); + scr_print_active(msg_src); + scr_print_active(" "); + scr_print_active(p); + scr_eol_active(); + return; + } + + scr_print_active("*** Got CTCP "); + scr_print_active(ctcp_type); + scr_print_active(" request from "); + scr_print_active(msg_src); + scr_eol_active(); + + if(streq_i(ctcp_type, "PING")) { + resp = p; + } else if(streq_i(ctcp_type, "CLIENTINFO")) { + resp = "PING VERSION CLIENTINFO"; + } else if(streq_i(ctcp_type, "VERSION")) { + resp = "FujiNetChat pre-alpha on an Atari 8-bit"; + } else { + /* unknown CTCP type, ignore */ + return; + } + + txbuf_set_str3("NOTICE ", msg_src, " :\x01"); + txbuf_append_str3(ctcp_type, " ", resp); + txbuf_append_str("\x01"); + txbuf_send(); +} + static void do_privmsg(void) { /* TODO: this shouldn't be case-sensitive */ if(strstr(msg_text, usernick)) @@ -85,6 +133,11 @@ static void do_privmsg(void) { else hilite = 0; + if(*msg_text == '\x01') { + do_ctcp(); + return; + } + if(*msg_dest == '#') do_chan_nick(); else -- cgit v1.2.3