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. --- src/irc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src') 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