AmendHub

Download:

jcs

/

wallops

/

amendments

/

49

main: Add a connect dialog option to suppress MOTD printing

Some servers have ridiculously long MOTDs that are slow to print.

jcs made amendment 49 about 1 year ago
--- chatter.h Tue Jan 17 23:17:51 2023 +++ chatter.h Fri Sep 29 21:12:39 2023 @@ -51,7 +51,8 @@ #define CONNECT_NICK_ID 5 #define CONNECT_IDENT_ID 6 #define CONNECT_REALNAME_ID 7 -#define CONNECT_CHANNEL_ID 8 +#define CONNECT_HIDE_MOTD_ID 8 +#define CONNECT_CHANNEL_ID 9 #define STR_SERVER_ID 1000 #define STR_PORT_ID 1001 @@ -60,12 +61,14 @@ #define STR_REALNAME_ID 1004 #define STR_CHANNEL_ID 1005 #define STR_PASSWORD_ID 1006 +#define STR_HIDE_MOTD_ID 1007 #define DEFAULT_SERVER_NAME "irc.libera.chat" #define DEFAULT_PORT "6667" #define DEFAULT_IDENT "wallops" #define DEFAULT_REALNAME "A Macintosh User" #define DEFAULT_CHANNEL "#cyberpals" +#define DEFAULT_HIDE_MOTD "0" #define WAIT_TYPE_NONE (1 << 0) #define WAIT_TYPE_BACKGROUND (1 << 1) @@ -101,11 +104,14 @@ void cancel_notification(void); struct chatter * chatter_init(const char *server, const unsigned short port, const char *password, const char *nick, - const char *ident, const char *realname, const char *channel); + const char *ident, const char *realname, bool hide_motd, + const char *channel); void chatter_update_titlebar(struct chatter *chatter); size_t chatter_printf(struct chatter *chatter, struct irc_connection *conn, struct irc_channel *channel, const char *format, ...); void chatter_insert_to_nick_list(struct chatter *chatter, + struct irc_channel *channel, struct irc_channel_nick *nick, short pos); +void chatter_remove_from_nick_list(struct chatter *chatter, struct irc_channel *channel, struct irc_channel_nick *nick, short pos); void chatter_sync_nick_list(struct chatter *chatter, struct irc_channel *channel, bool just_summary); --- irc.c Tue Jan 17 14:23:25 2023 +++ irc.c Fri Sep 29 21:11:57 2023 @@ -54,7 +54,8 @@ struct irc_connections_head irc_connections_list = struct irc_connection * irc_connect(struct chatter *chatter, const char *server, const unsigned short port, const char *password, const char *nick, - const char *ident, const char *realname, const char *channel) + const char *ident, const char *realname, bool hide_motd, + const char *channel) { struct irc_connection *conn; char ip_str[] = "255.255.255.255"; @@ -79,6 +80,7 @@ irc_connect(struct chatter *chatter, const char *serve conn->nick = xstrdup(nick, "nick"); conn->ident = xstrdup(ident, "ident"); conn->realname = xstrdup(realname, "realname"); + conn->hide_motd = hide_motd; if (channel && channel[0]) conn->channel_autojoin = xstrdup(channel, "chan"); @@ -178,8 +180,6 @@ irc_dealloc_connection(struct irc_connection *conn) void irc_process(struct irc_connection *conn) { - short was_state = conn->state; - if (conn->state >= IRC_STATE_CONNECTED) irc_recv(conn); @@ -779,6 +779,8 @@ irc_process_server(struct irc_connection *conn) case 372: case 375: /* MOTD */ + if (conn->hide_motd) + return true; goto print_msg; case 376: /* end of MOTD */ @@ -787,6 +789,8 @@ irc_process_server(struct irc_connection *conn) irc_printf(conn, "JOIN %s\r\n", conn->channel_autojoin); conn->did_autojoin = true; } + if (conn->hide_motd) + return true; goto print_msg; case 396: /* Cloak */ @@ -1152,7 +1156,8 @@ irc_remove_nick_from_channel(struct irc_channel *chann channel->nnicks--; cnick->nick[0] = '\0'; -// LDelRow(1, cidx, channel->chatter->nick_list); + chatter_remove_from_nick_list(channel->chatter, channel, + cnick, cidx); return; } } --- irc.h Mon Jan 9 15:49:34 2023 +++ irc.h Mon Sep 25 17:25:27 2023 @@ -77,6 +77,7 @@ struct irc_connection { char *realname; char *channel_autojoin; bool did_autojoin; + bool hide_motd; struct irc_channels_head channels_list; short nchannels; TCPiopb rcv_pb, send_pb, close_pb; @@ -84,12 +85,12 @@ struct irc_connection { StreamPtr stream; wdsEntry wds[2]; char obuf[512]; - char ibuf[512]; /* RFC2812 says max line will be 512 */ + char ibuf[2048]; /* RFC2812 says max line will be 512 */ char line[512]; short ibuflen; short linelen; /* docs say 4*MTU+1024, but MTU will probably be <1500 */ - unsigned char tcp_buf[(4 * 1500) + 1024]; + unsigned char tcp_buf[(4 * 1500) + 2048]; }; SLIST_HEAD(irc_connections_head, irc_connection); extern struct irc_connections_head irc_connections_list; @@ -97,7 +98,7 @@ extern struct irc_connections_head irc_connections_lis struct irc_connection * irc_connect(struct chatter *chatter, const char *server, const unsigned short port, const char *password, const char *nick, const char *ident, const char *realname, - const char *channel); + bool hide_motd, const char *channel); void irc_close_connection(struct irc_connection *conn); void irc_dealloc_connection(struct irc_connection *conn); void irc_process(struct irc_connection *conn); --- main.c Tue Jan 17 13:48:47 2023 +++ main.c Mon Sep 25 17:23:14 2023 @@ -26,7 +26,8 @@ NMRec notification = { 0 }; enum { CONFIG_TYPE_STRING, CONFIG_TYPE_SHORT, - CONFIG_TYPE_PASSWORD + CONFIG_TYPE_PASSWORD, + CONFIG_TYPE_BOOL }; struct config_field { @@ -51,6 +52,8 @@ struct config_field { CONNECT_IDENT_ID, STR_IDENT_ID, DEFAULT_IDENT }, { "Realname", CONFIG_TYPE_STRING, 1, 0, CONNECT_REALNAME_ID, STR_REALNAME_ID, DEFAULT_REALNAME }, + { "Hide MOTD", CONFIG_TYPE_BOOL, 0, 1, + CONNECT_HIDE_MOTD_ID, STR_HIDE_MOTD_ID, DEFAULT_HIDE_MOTD }, { "Channel", CONFIG_TYPE_STRING, 0, 0, CONNECT_CHANNEL_ID, STR_CHANNEL_ID, DEFAULT_CHANNEL }, }; @@ -122,13 +125,7 @@ main(void) if (event.what != nullEvent) { event_in = FindWindow(event.where, &event_win); - found_focusable = NULL; - for (n = 0; n < nfocusables; n++) { - if (focusables[n]->win == event_win) { - found_focusable = focusables[n]; - break; - } - } + found_focusable = focusable_find(event_win); } switch (event.what) { @@ -240,7 +237,7 @@ show_connect_dialog(void) Rect irect; size_t size, n, m; long port; - short hit, itype, ret; + short hit, itype, ret, hide_motd; /* center dialog in screen */ dlgh = (DialogTHndl)xGetResource('DLOG', CONNECT_DLOG_ID); @@ -278,11 +275,15 @@ show_connect_dialog(void) memcpy(cf->password_storage, *h, size); cf->password_storage[size] = '\0'; PtoCstr(cf->password_storage); + } else if (cf->type == CONFIG_TYPE_BOOL) { + SetCtlValue(ihandle, ((*h)[1] == '1')); } else { SetIText(ihandle, *h); } HUnlock(h); ReleaseResource(h); + } else if (cf->type == CONFIG_TYPE_BOOL) { + SetCtlValue(ihandle, (cf->sdefault[0] == '1')); } else if (cf->sdefault[0] != '\0') { strlcpy((char *)&txt, cf->sdefault, sizeof(txt)); CtoPstr(txt); @@ -301,6 +302,10 @@ get_input: return; case OK: goto verify; + case CONNECT_HIDE_MOTD_ID: + GetDItem(dlg, hit, &itype, &ihandle, &irect); + SetCtlValue(ihandle, 1 - GetCtlValue(ihandle)); + /* FALLTHROUGH */ default: goto get_input; } @@ -311,10 +316,14 @@ verify: long lval; short sval; + GetDItem(dlg, cf->ditl_id, &itype, &ihandle, &irect); + if (cf->type == CONFIG_TYPE_PASSWORD) { memcpy((char *)&txt, cf->password_storage, sizeof(txt)); + } else if (cf->type == CONFIG_TYPE_BOOL) { + snprintf((char *)&txt, sizeof(txt), "%d", + GetCtlValue(ihandle)); } else { - GetDItem(dlg, cf->ditl_id, &itype, &ihandle, &irect); GetIText(ihandle, txt); PtoCstr(txt); } @@ -342,6 +351,8 @@ verify: goto get_input; } break; + case CONFIG_TYPE_BOOL: + break; } switch (cf->ditl_id) { @@ -363,6 +374,9 @@ verify: case CONNECT_REALNAME_ID: strlcpy((char *)&realname, (char *)txt, sizeof(realname)); break; + case CONNECT_HIDE_MOTD_ID: + hide_motd = (txt[0] == '1'); + break; case CONNECT_CHANNEL_ID: strlcpy((char *)&channel, (char *)txt, sizeof(channel)); break; @@ -387,7 +401,8 @@ verify: ReleaseResource(dlgh); chatter_init((char *)&server, port, (char *)&password, - (char *)&nick, (char *)&ident, (char *)&realname, (char *)&channel); + (char *)&nick, (char *)&ident, (char *)&realname, + hide_motd, (char *)&channel); } bool