aboutsummaryrefslogtreecommitdiff
path: root/src/irc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc.c')
-rw-r--r--src/irc.c125
1 files changed, 95 insertions, 30 deletions
diff --git a/src/irc.c b/src/irc.c
index 0572700..8343897 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -31,6 +31,8 @@ static int msgbuf_len = 0, msg_len = 0;
static char regged = 0, hilite = 0;
static char scr_prev = SCR_PRIV;
+char numbuf[10];
+
/*
static void join_channel(void) {
txbuf_set_str2("JOIN ", channel);
@@ -85,8 +87,42 @@ static void do_priv_nick(void) {
bell();
}
+static void print_ping_time(char *p) {
+ static long now, pingtime;
+ static int sec, frac;
+
+ now = read_rtclok();
+ pingtime = atol(p);
+
+ /* correct for rtclock rollover (every 77 hours) */
+ if(now < pingtime) now |= 0x01000000L;
+
+ pingtime = now - pingtime;
+
+ sec = pingtime / hz;
+ frac = pingtime % hz;
+ frac *= 1000;
+ frac /= (hz * 10);
+
+ scr_print_active("*** ");
+ scr_print_active(msg_src);
+ scr_print_active(" ping time: ");
+ itoa(sec, numbuf, 10);
+ scr_print_active(numbuf);
+ scr_print_active(".");
+ itoa(frac, numbuf, 10);
+ scr_print_active(numbuf);
+ scr_print_active(" sec");
+
+ /* for debugging:
+ scr_print_active(" ");
+ ltoa(pingtime, numbuf, 10);
+ scr_print_active(numbuf);
+ */
+}
+
/* FIXME: this isn't very fast */
-static void do_ctcp(void) {
+static void do_ctcp(int is_notice) {
static char *p, *ctcp_type, *resp;
resp = 0;
@@ -101,36 +137,54 @@ static void do_ctcp(void) {
*p++ = 0;
}
- if(streq_i(ctcp_type, "ACTION")) {
- scr_print_active("* ");
+ if(is_notice) {
+ /* NOTICEs are responses */
+ if(p && streq_i(ctcp_type, "PING")) {
+ print_ping_time(p);
+ } else {
+ scr_print_active("*** CTCP ");
+ scr_print_active(ctcp_type);
+ scr_print_active(" response from ");
+ scr_print_active(msg_src);
+ if(p) {
+ scr_print_active(": ");
+ scr_print_active(p);
+ }
+ }
+ scr_eol_active();
+ } else {
+ /* this is a PRIVMSG (aka a request) */
+ 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("*** CTCP ");
+ scr_print_active(ctcp_type);
+ scr_print_active(" request from ");
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;
+ }
- 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();
}
-
- txbuf_set_str3("NOTICE ", msg_src, " :\x01");
- txbuf_append_str3(ctcp_type, " ", resp);
- txbuf_append_str("\x01");
- txbuf_send();
}
static void do_privmsg(void) {
@@ -141,7 +195,7 @@ static void do_privmsg(void) {
hilite = 0;
if(*msg_text == '\x01') {
- do_ctcp();
+ do_ctcp(0);
return;
}
@@ -154,6 +208,15 @@ static void do_privmsg(void) {
scr_eol_active();
}
+static void do_notice(void) {
+ if(*msg_text == '\x01') {
+ do_ctcp(1);
+ } else {
+ scr_print_active("NOTICE ");
+ do_privmsg();
+ }
+}
+
static void do_join(void) {
if(streq_i(usernick, msg_src)) {
scr_print_active("You have ");
@@ -382,6 +445,8 @@ static void dispatch_msg(void) {
if(streq_i(msg_cmd, "PRIVMSG")) {
do_privmsg();
+ } else if(streq_i(msg_cmd, "NOTICE")) {
+ do_notice();
} else if(streq_i(msg_cmd, "JOIN")) {
do_join();
} else if(streq_i(msg_cmd, "NICK")) {
@@ -520,10 +585,9 @@ static void irc_split_Lines(void) {
/* TODO: there needs to be a scr_printnum() */
void print_errnum(void) {
extern unsigned char err;
- char tmp[10];
scr_print_current("Error #");
- itoa(err, tmp, 10);
- scr_print_current(tmp);
+ itoa(err, numbuf, 10);
+ scr_print_current(numbuf);
scr_print_current(", press any key...\n");
}
@@ -539,6 +603,7 @@ int irc_read(void) {
} else {
print_errnum();
}
+ bell();
cgetc();
scr_display(0);
return 0;