jcs
/wallops
/amendments
/64
chatter+irc: Show channel mode in tab, try to send QUIT when dying
jcs made amendment 64 2 months ago
--- chatter.c Thu Sep 5 10:12:05 2024
+++ chatter.c Thu Sep 5 11:06:01 2024
@@ -24,7 +24,7 @@
#define NICK_LIST_WIDTH 75
#define CHATTER_SCRAP_ELEMENTS 20
-#define MAX_TAB_WIDTH 100
+#define MAX_TAB_WIDTH 120
#define TAB_BAR_HEIGHT 15
static Handle scrp_rec_h = NULL;
@@ -470,6 +470,11 @@ chatter_idle(struct focusable *focusable, EventRecord
redraw = true;
}
+ if (chatter->need_tab_bar_redraw) {
+ redraw = true;
+ chatter->need_tab_bar_redraw = false;
+ }
+
if (redraw)
chatter_draw_tab_bar(chatter);
}
@@ -536,6 +541,8 @@ chatter_update(struct focusable *focusable, EventRecor
void
chatter_draw_tab_bar(struct chatter *chatter)
{
+ static char label[64];
+ char *tlabel;
Rect r, r2;
RgnHandle clip;
BitMap cur_bits;
@@ -543,7 +550,6 @@ chatter_draw_tab_bar(struct chatter *chatter)
size_t len;
static const char no_connection[] = "Disconnected";
struct chatter_tab *tab;
- char *label;
cur_bits = thePort->portBits;
@@ -604,23 +610,31 @@ chatter_draw_tab_bar(struct chatter *chatter)
ClipRect(&r);
if (tab->conn) {
- if (tab->channel)
- label = tab->channel->name;
- else
- label = tab->conn->hostname;
- } else
- label = (char *)&no_connection;
-
- len = strlen(label);
+ if (tab->channel) {
+ if (tab->channel->mode[0])
+ len = snprintf(label, sizeof(label), "%s (%s)",
+ tab->channel->name, tab->channel->mode);
+ else
+ len = strlcpy(label, tab->channel->name,
+ sizeof(label));
+ } else
+ len = snprintf(label, sizeof(label), "%s",
+ tab->conn->hostname);
+ tlabel = label;
+ } else {
+ tlabel = (char *)&no_connection;
+ len = sizeof(no_connection) - 1;
+ }
+
if (tab->have_activity)
TextFace(bold | condense);
else
TextFace(0);
- width = TextWidth(label, 0, len);
+ width = TextWidth(tlabel, 0, len);
if (width > tab_width - 4)
width = tab_width - 4;
MoveTo(r.left + ((tab_width - width) / 2), r.bottom - 3);
- DrawText(label, 0, len);
+ DrawText(tlabel, 0, len);
SetClip(clip);
--- chatter.h Thu Sep 5 09:19:25 2024
+++ chatter.h Thu Sep 5 10:54:24 2024
@@ -72,6 +72,7 @@ struct chatter {
Rect shadow_bounds;
TEHandle input_te;
bool quitting;
+ bool need_tab_bar_redraw;
BitMap tab_bar;
short ntabs;
struct chatter_tabs_head tabs_list;
--- irc.c Wed Sep 4 14:23:27 2024
+++ irc.c Thu Sep 5 11:14:52 2024
@@ -34,6 +34,7 @@ struct irc_channel * irc_find_channel(struct irc_conne
bool irc_process_server(struct irc_connection *conn);
struct irc_channel * irc_create_channel(struct irc_connection *conn,
char *channame);
+void irc_quit_with_message(struct irc_connection *conn, char *str);
void irc_dealloc_channel(struct irc_channel *channel);
void irc_set_active_channel(struct irc_connection *conn, char *channame);
void irc_parse_names(struct irc_channel *channel, char *line);
@@ -138,6 +139,9 @@ irc_connect(struct chatter *chatter, const char *serve
void
irc_close_connection(struct irc_connection *conn)
{
+ if (conn->state == IRC_STATE_CONNECTED)
+ irc_quit_with_message(conn, NULL);
+
if (conn->stream) {
_TCPClose(&conn->close_pb, conn->stream, nil, nil, false);
_TCPAbort(&conn->close_pb, conn->stream, nil, nil, false);
@@ -708,12 +712,9 @@ irc_process_server(struct irc_connection *conn)
"$B*** |$0 Server:$/ %s (%s)",
msg.arg[2], msg.msg);
return true;
- case 671:
- /* WHOIS server */
- chatter_printf(conn->chatter, conn, NULL,
- "$B*** |$0 Connection:$/ %s",
- msg.msg);
- return true;
+ case 315:
+ /* end of WHO */
+ goto unknown;
case 317:
/* WHOIS idle */
chatter_printf(conn->chatter, conn, NULL,
@@ -731,22 +732,30 @@ irc_process_server(struct irc_connection *conn)
"$B*** |$0 Channels:$/ %s",
msg.msg);
return true;
+ case 324:
+ /* channel mode */
+ channel = irc_find_channel(conn, msg.arg[1]);
+ if (channel)
+ strlcpy(channel->mode, msg.arg[2], sizeof(channel->topic));
+ chatter_printf(channel ? channel->chatter : conn->chatter,
+ conn, channel,
+ "$B***$0 Mode for $B%s$0:$/ %s",
+ msg.arg[1], msg.arg[2]);
+ if (channel && channel->chatter)
+ channel->chatter->need_tab_bar_redraw = true;
+ return true;
+ case 328:
+ /* channel URL, we probably can't do anything with it anyway */
+ return true;
+ case 329:
+ /* channel creation timestamp */
+ return true;
case 330:
/* WHOIS account */
chatter_printf(conn->chatter, conn, NULL,
"$B*** |$0 Account:$/ %s %s",
msg.msg, msg.arg[2]);
return true;
- case 338:
- case 378:
- /* WHOIS host */
- chatter_printf(conn->chatter, conn, NULL,
- "$B*** |$0 Host:$/ %s %s",
- msg.msg, msg.arg[2]);
- return true;
- case 328:
- /* channel URL, we probably can't do anything with it anyway */
- return true;
case 332:
/* TOPIC */
channel = irc_find_channel(conn, msg.arg[1]);
@@ -760,12 +769,16 @@ irc_process_server(struct irc_connection *conn)
case 333:
/* TOPIC creator */
return true;
+ case 338:
+ case 378:
+ /* WHOIS host */
+ chatter_printf(conn->chatter, conn, NULL,
+ "$B*** |$0 Host:$/ %s %s",
+ msg.msg, msg.arg[2]);
+ return true;
case 352:
/* WHO output */
goto unknown;
- case 315:
- /* end of WHO */
- goto unknown;
case 353:
/* NAMES output */
channel = irc_find_channel(conn, msg.arg[2]);
@@ -819,6 +832,12 @@ irc_process_server(struct irc_connection *conn)
irc_send(conn, conn->line, len);
return true;
}
+ case 671:
+ /* WHOIS server */
+ chatter_printf(conn->chatter, conn, NULL,
+ "$B*** |$0 Connection:$/ %s",
+ msg.msg);
+ return true;
case 900:
/* nickserv login */
chatter_printf(conn->chatter, conn, NULL,
@@ -934,11 +953,7 @@ irc_process_input(struct irc_connection *conn, struct
if (strcasecmp(arg0, "quit") == 0) {
if (conn == NULL)
goto not_connected;
- if (str == NULL)
- irc_printf(conn, "QUIT :%s %s on a %s\r\n",
- PROGRAM_NAME, get_version(false), gestalt_machine_type());
- else
- irc_printf(conn, "QUIT :%s\r\n", str);
+ irc_quit_with_message(conn, str);
return;
}
if (strcasecmp(arg0, "quote") == 0) {
@@ -949,6 +964,17 @@ irc_process_input(struct irc_connection *conn, struct
irc_printf(conn, "%s\r\n", str);
return;
}
+ if (strcasecmp(arg0, "topic") == 0) {
+ if (conn == NULL)
+ goto not_connected;
+ if (str && channel)
+ irc_printf(conn, "TOPIC %s: %s\r\n", channel->name, str);
+ else if (channel)
+ irc_printf(conn, "TOPIC %s\r\n", channel->name);
+ else
+ goto not_in_channel;
+ return;
+ }
if (strcasecmp(arg0, "whois") == 0) {
if (conn == NULL)
goto not_connected;
@@ -1002,7 +1028,19 @@ irc_create_channel(struct irc_connection *conn, char *
channel->chatter = conn->chatter;
chatter_add_tab(channel->chatter, NULL, conn, channel);
+ irc_printf(conn, "MODE %s\r\n", channel->name);
+
return channel;
+}
+
+void
+irc_quit_with_message(struct irc_connection *conn, char *str)
+{
+ if (str)
+ irc_printf(conn, "QUIT :%s\r\n", str);
+ else
+ irc_printf(conn, "QUIT :%s %s on a %s\r\n",
+ PROGRAM_NAME, get_version(false), gestalt_machine_type());
}
void
--- irc.h Fri Aug 30 14:16:22 2024
+++ irc.h Thu Sep 5 10:25:06 2024
@@ -61,6 +61,7 @@ struct irc_channel {
size_t nicks_size;
short first_nick;
char name[64];
+ char mode[10];
char topic[400];
};
SLIST_HEAD(irc_channels_head, irc_channel);