diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-03-18 06:30:11 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-03-18 06:30:11 -0400 |
| commit | b07cf8d151424ea0f6790e884af160e233943579 (patch) | |
| tree | a264fb666221439465af6949149810580d89fbce | |
| parent | a0a87c0a32fd891efcaf82f8d49b7221fa1ffe2b (diff) | |
| download | fujinet-chat-b07cf8d151424ea0f6790e884af160e233943579.tar.gz | |
Ping server after 1 min of inactivity; disconnect/reconnect if no PONG within the next minute.
| -rw-r--r-- | TODO | 1 | ||||
| -rw-r--r-- | doc/ui_keys.txt | 5 | ||||
| -rw-r--r-- | src/cmd.c | 4 | ||||
| -rw-r--r-- | src/irc.c | 51 | ||||
| -rw-r--r-- | src/irc.h | 5 |
5 files changed, 61 insertions, 5 deletions
@@ -14,6 +14,7 @@ FujiChat features, we're almost at parity! Other stuff: +- Add Start+Crtl+D keystroke, to forcibly disconnect from the server. - Filter out remaining ATASCII keystrokes we aren't using: Shift-Tab, Ctrl-Tab, Ctrl-2. Or else find a use for them :) - *Thoroughly* test the nick and channel tab completion for the [private] diff --git a/doc/ui_keys.txt b/doc/ui_keys.txt index 9d50173..d26a171 100644 --- a/doc/ui_keys.txt +++ b/doc/ui_keys.txt @@ -20,9 +20,12 @@ T - /topic #channel E - show full editbox (instead of screen). Ctrl-X - in a channel screen, /part the channel and close the screen. no effect elsewhere. +Ctrl-D - disconnect from server (without sending a /quit). This + *doesn't do anything useful* for users, it only exists as a + debugging aid (so I can test the automatic server ping code). + This will likely be removed before the first beta. Future plans: -Ctrl-D - disconnect from server (without sending a /quit). J - join last channel you were invited to. ? - Show help (also the Help key by itself will do this). @@ -275,7 +275,7 @@ static void rtclok_to_numbuf(void) { itoa(read_rtclok(), numbuf, 10); } -static void do_server_ping(void) { +static void cmd_server_ping(void) { rtclok_to_numbuf(); txbuf_set_str2("PING ", numbuf); txbuf_send(); @@ -346,7 +346,7 @@ static void do_ping(void) { if(arg1) do_ctcp_ping(); else - do_server_ping(); + cmd_server_ping(); } static void do_list(void) { @@ -42,6 +42,8 @@ char numbuf[10]; char last_pm_nick[33]; char last_chan[33]; /* without a screen */ +static char ping_sent = 0; + /* static void join_channel(void) { txbuf_set_str2("JOIN ", channel); @@ -134,7 +136,7 @@ static void print_ping_time(char *p) { scr_print_active("*** "); scr_print_active(msg_src); - scr_print_active(" ping time: "); + scr_print_active(" lag: "); itoa(sec, numbuf, 10); scr_print_active(numbuf); scr_print_active("."); @@ -151,9 +153,12 @@ static void print_ping_time(char *p) { } static void do_server_pong(void) { + if(*msg_text == 'A') return; /* don't print auto-pings */ msg_src = "Server"; // FIXME: what if the server doesn't :-quote the response? print_ping_time(msg_text); + scr_eol_active(); + ping_sent = 0; } /* FIXME: this isn't very fast */ @@ -670,9 +675,45 @@ void print_errnum(void) { scr_print_current(numbuf); } +/* gets called on *any* incoming network traffic */ +static void reset_watchdog() { + // scr_print_current("reset_watchdog()\n"); + OS.cdtmf4 = 0xff; + OS.cdtmv4 = 60 * hz; +} + +/* after 60 sec of inactivity from the server, send it a ping. + if it doesn't reply within another 60 seconds, assume it's dead. */ +static char check_watchdog() { + /* + scr_print_current("check_watchdog()\nping_sent=="); + if(ping_sent) + scr_print_current("1\n"); + else + scr_print_current("0\n"); + */ + + if(!OS.cdtmf4) { /* timer hath expired */ + if(ping_sent) { + ping_sent = 0; + // bell(); /* for testing only */ + scr_print_current("Server timed out"); + return 0; /* we pinged and didn't get a pong :( */ + } else { + ping_sent = 1; + // bell(); /* for testing only */ + // cmd_server_ping(); + txbuf_send_str("PING A"); + reset_watchdog(); + } + } + return 1; +} + int irc_read(void) { if(!trip) return 1; + reset_watchdog(); /* on any incoming network traffic */ err = nstatus(conf->url); if(err != 1) { @@ -944,6 +985,9 @@ static void start_keystroke(void) { case 'e': toggle_edbox_only(); break; + case 0x04: /* ^D */ + fn_disconnect(); /* testing only! */ + break; case 's': edbox_hide(); /* fall thru */ @@ -976,7 +1020,10 @@ void irc_loop(void) { txbuf_send_str("AWAY :ATRACT mode"); } } - if(!irc_read()) return; + if(!irc_read() || !check_watchdog()) { + regged = 0; + return; + } keystroke(); } } @@ -39,6 +39,9 @@ void txbuf_send_str(const char *str); void print_error(unsigned char err); +/* does exactly what you think */ +void fn_disconnect(void); + /**** irc.c */ #define MAX_MSG_ARGS 8 extern char bell_type; @@ -68,4 +71,6 @@ void cmd_execute(void); void cmd_rejoin_chans(void); void cmd_ctcp_ping(char *nick); void cmd_send_pm(char *args); +void cmd_ctcp_ping(char *nick); +void cmd_server_ping(void); unsigned int read_rtclok(void); /* irc.c needs this one so it's not static */ |
