Show channel privileges in nicklists

This commit is contained in:
Johannes Findeisen 2026-11-27 03:08:14 +01:00
commit 1fc6b0ae6c
2 changed files with 75 additions and 7 deletions

View file

@ -93,7 +93,8 @@ terminal's default background so transparency is preserved where supported.
The right pane shows the current window's scrollback with `[HH:MM]` timestamps. The right pane shows the current window's scrollback with `[HH:MM]` timestamps.
Joins, parts and quits include the full hostmask; joins and parts also name the Joins, parts and quits include the full hostmask; joins and parts also name the
channel. The status line above the input shows the time, nick, server, port, TLS state, and user modes. channel. The status line above the input shows the time, nick, server, port, TLS state, and user modes.
Joining a channel prints its nicklist; `/n` and `/names` print it again. Joining a channel prints its nicklist. `/n` and `/names` print it again.
Channel privileges such as operator or voice appear as a trailing `*` (for example, `alice*`).
CTCP `ACTION`, `VERSION`, `PING`, `TIME`, and `USERINFO` are understood; KICK, CTCP `ACTION`, `VERSION`, `PING`, `TIME`, and `USERINFO` are understood; KICK,
MODE, TOPIC, and INVITE events are shown in the relevant window. MODE, TOPIC, and INVITE events are shown in the relevant window.

79
irc9.c
View file

@ -61,6 +61,7 @@ typedef enum { W_SERVER, W_CHANNEL, W_QUERY } Wintype;
typedef struct Member { typedef struct Member {
char nick[NICKLEN]; char nick[NICKLEN];
uint32_t status;
struct Member *next; struct Member *next;
} Member; } Member;
@ -108,6 +109,7 @@ typedef struct Server {
int cap_state; int cap_state;
char caps[512]; /* accumulated multi-line CAP LS reply */ char caps[512]; /* accumulated multi-line CAP LS reply */
char umode[32]; char umode[32];
char prefix_modes[32], prefix_symbols[32], chanmodes[128];
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
SSL *ssl; SSL *ssl;
#endif #endif
@ -437,13 +439,48 @@ static Member *member_find(Window *w, const char *nick)
return NULL; return NULL;
} }
static void member_add(Window *w, const char *nick) static Member *member_add(Window *w, const char *nick)
{ {
if (member_find(w, nick)) return; Member *existing = member_find(w, nick);
if (existing) return existing;
Member *m = xmalloc(sizeof *m); Member *m = xmalloc(sizeof *m);
snprintf(m->nick, sizeof m->nick, "%s", nick); snprintf(m->nick, sizeof m->nick, "%s", nick);
m->status = 0;
m->next = w->members; m->next = w->members;
w->members = m; w->members = m;
return m;
}
static void member_modes(Window *w, const char *modes, char **args, int count)
{
Server *s = w->srv;
int adding = 1;
int param = 0;
for (const char *p = modes; *p; p++) {
if (*p == '+' || *p == '-') {
adding = *p == '+';
continue;
}
const char *prefix = strchr(s->prefix_modes, *p);
if (prefix) {
if (param >= count) break;
Member *m = member_find(w, args[param++]);
if (m) {
uint32_t bit = UINT32_C(1) << (prefix - s->prefix_modes);
if (adding) m->status |= bit;
else m->status &= ~bit;
}
} else {
int group = 0;
for (const char *c = s->chanmodes; *c; c++) {
if (*c == ',') group++;
else if (*c == *p) {
if (group < 2 || (group == 2 && adding)) param++;
break;
}
}
}
}
} }
static void member_remove(Window *w, const char *nick) static void member_remove(Window *w, const char *nick)
@ -485,7 +522,7 @@ static void show_names(Window *w)
for (Member *m = w->members; m; m = m->next) { for (Member *m = w->members; m; m = m->next) {
size_t room = sizeof line - (size_t)len - 1; size_t room = sizeof line - (size_t)len - 1;
int add = snprintf(line + len, room, " %s", m->nick); int add = snprintf(line + len, room, " %s%s", m->nick, m->status ? "*" : "");
if (add <= 0 || (size_t)add >= room) break; if (add <= 0 || (size_t)add >= room) break;
len += add; len += add;
} }
@ -551,6 +588,9 @@ static void load_config(const char *path)
snprintf(s->nick, sizeof s->nick, "%s", g_nick); snprintf(s->nick, sizeof s->nick, "%s", g_nick);
snprintf(s->user, sizeof s->user, "%s", g_user); snprintf(s->user, sizeof s->user, "%s", g_user);
snprintf(s->real, sizeof s->real, "%s", g_real); snprintf(s->real, sizeof s->real, "%s", g_real);
strcpy(s->prefix_modes, "qaohv");
strcpy(s->prefix_symbols, "~&@%+");
strcpy(s->chanmodes, "beI,k,l,imnst");
s->fd = -1; s->fd = -1;
s->retry_at = 0; s->retry_at = 0;
if (!servers) servers = s; else last->next = s; if (!servers) servers = s; else last->next = s;
@ -1152,7 +1192,8 @@ static void handle_line(Server *s, char *line)
if (i > 1) strncat(params, " ", sizeof params - strlen(params) - 1); if (i > 1) strncat(params, " ", sizeof params - strlen(params) - 1);
strncat(params, arg[i], sizeof params - strlen(params) - 1); strncat(params, arg[i], sizeof params - strlen(params) - 1);
} }
if (!is_channel(arg[0]) && strcasecmp(arg[0], s->nick) == 0) if (w->type == W_CHANNEL) member_modes(w, arg[1], arg + 2, narg - 2);
else if (strcasecmp(arg[0], s->nick) == 0)
snprintf(s->umode, sizeof s->umode, "%s", arg[1]); snprintf(s->umode, sizeof s->umode, "%s", arg[1]);
appendf(w, "* %s sets mode %s on %s", *nick ? nick : "server", appendf(w, "* %s sets mode %s on %s", *nick ? nick : "server",
params, arg[0]); params, arg[0]);
@ -1176,6 +1217,25 @@ static void handle_line(Server *s, char *line)
return; return;
} }
if (strcmp(cmd, "005") == 0) {
for (int i = 1; i < narg; i++) {
if (strncmp(arg[i], "PREFIX=(", 8) == 0) {
const char *modes = arg[i] + 8;
const char *end = strchr(modes, ')');
if (end && (size_t)(end - modes) == strlen(end + 1) &&
(size_t)(end - modes) < sizeof s->prefix_modes) {
size_t len = (size_t)(end - modes);
memcpy(s->prefix_modes, modes, len);
s->prefix_modes[len] = 0;
strcpy(s->prefix_symbols, end + 1);
}
} else if (strncmp(arg[i], "CHANMODES=", 10) == 0 &&
strlen(arg[i] + 10) < sizeof s->chanmodes) {
strcpy(s->chanmodes, arg[i] + 10);
}
}
}
if (strcmp(cmd, "353") == 0) { if (strcmp(cmd, "353") == 0) {
/* 353 <me> <symbol> <channel> :<names> */ /* 353 <me> <symbol> <channel> :<names> */
if (narg < 4) return; if (narg < 4) return;
@ -1186,13 +1246,20 @@ static void handle_line(Server *s, char *line)
if (!*p) break; if (!*p) break;
char *e = strchr(p, ' '); char *e = strchr(p, ' ');
size_t len = e ? (size_t)(e - p) : strlen(p); size_t len = e ? (size_t)(e - p) : strlen(p);
while (len && (*p == '@' || *p == '+' || *p == '%')) { p++; len--; } uint32_t status = 0;
while (len) {
const char *prefix = strchr(s->prefix_symbols, *p);
if (!prefix) break;
status |= UINT32_C(1) << (prefix - s->prefix_symbols);
p++;
len--;
}
if (len) { if (len) {
char tmp[NICKLEN]; char tmp[NICKLEN];
size_t cp = len < sizeof tmp - 1 ? len : sizeof tmp - 1; size_t cp = len < sizeof tmp - 1 ? len : sizeof tmp - 1;
memcpy(tmp, p, cp); memcpy(tmp, p, cp);
tmp[cp] = 0; tmp[cp] = 0;
member_add(w, tmp); member_add(w, tmp)->status = status;
} }
p = e ? e + 1 : p + len; p = e ? e + 1 : p + len;
} }