diff options
| -rw-r--r-- | commands.txt | 4 | ||||
| -rw-r--r-- | src/cmd.c | 19 | ||||
| -rw-r--r-- | src/irc.c | 125 | ||||
| -rw-r--r-- | src/irc.h | 3 | ||||
| -rw-r--r-- | src/main.c | 4 |
5 files changed, 123 insertions, 32 deletions
diff --git a/commands.txt b/commands.txt index 1bc1d77..cba40ef 100644 --- a/commands.txt +++ b/commands.txt @@ -88,3 +88,7 @@ TODO: not implemented yet. /quote <cmd> Send raw IRC protocol to the server. This bypasses local command parsing. + +/bell <number> +Set the type of alert that happens when you're PMed or highlighted +in a channel. 0 = none, 1 = beep, 2 = flash, 3 = beep and flash. @@ -13,6 +13,7 @@ char *command, *arg1, *arg2, *arg3; static char *target; static void do_away(void); +static void do_bell(void); static void do_color(void); static void do_ctcp(void); static void do_info(void); @@ -41,6 +42,7 @@ typedef struct { */ cmd_t command_defs[] = { { "AWAY", do_away, 1 }, + { "BELL", do_bell, 1 }, { "COLOR", do_color, 1 }, { "CTCP", do_ctcp, 1 }, { "INFO", do_info, 0 }, @@ -227,9 +229,20 @@ static void send_ctcp(void) { txbuf_send(); } +long read_rtclok(void) { + return (OS.rtclok[0] << 16) | (OS.rtclok[1] << 8) | OS.rtclok[2]; +} + +static void rtclok_to_numbuf(void) { + long r; + r = read_rtclok(); + ltoa(r, numbuf, 10); +} + static void do_ctcp_ping(void) { arg2 = "PING"; - arg3 = "0xdeadbeef"; + rtclok_to_numbuf(); + arg3 = numbuf; send_ctcp(); } @@ -353,6 +366,10 @@ static void do_away(void) { txbuf_send(); } +static void do_bell(void) { + bell_type = *arg1 - '0'; +} + static int cmd_local(void) { arg1 = nextarg(command); @@ -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; @@ -11,6 +11,7 @@ extern char *rx_buf; extern unsigned short rxbuflen; extern unsigned char err; extern unsigned char trip; +extern char hz; extern unsigned int txbuflen; extern char *tx_buf; @@ -41,6 +42,7 @@ void print_error(unsigned char err); /**** irc.c */ #define MAX_MSG_ARGS 8 +extern char numbuf[10]; extern char *msg_src, *msg_cmd, *msg_dest, *msg_text; extern char *msg_args[MAX_MSG_ARGS]; extern int msg_argcount; @@ -59,3 +61,4 @@ void print_errnum(void); /**** cmd.c */ void cmd_command(char *cmd); void cmd_execute(void); +long read_rtclok(void); /* irc.c needs this one so it's not static */ @@ -23,13 +23,13 @@ char url[256] = DEF_URL; // URL char usernick[32] = DEF_NICK; -char tmp[8]; // temporary # to string unsigned char err; // error code of last operation. unsigned char trip=0; // if trip=1, fujinet is asking us for attention. bool old_enabled=false; // were interrupts enabled for old vector void* old_vprced; // old PROCEED vector, restored on exit. unsigned short rxbuflen; unsigned int txbuflen; // TX buffer length +char hz; /* 50 for PAL, 60 for NSTC */ /* TODO: user modes (default +iw), fg/bg color... */ @@ -142,6 +142,8 @@ int main(void) { OS.color2 = 0xc0; /* darkest green background */ OS.color1 = 0x0c; /* bright text */ + hz = (GTIA_READ.pal & 0x0e) ? 60 : 50; + scr_init(); while(1) { |
