fix names not update when user leaves

This commit is contained in:
2026-04-09 07:39:26 +08:00
parent 1f38d54b39
commit 6a85dc86cf
+21 -4
View File
@@ -151,6 +151,7 @@ typedef struct {
int mention;
int scroll;
char topic[MAX_LINE];
int names_pending; /* 1 while receiving fresh 353 NAMES reply */
} Channel;
typedef struct {
@@ -162,7 +163,7 @@ typedef enum {
EV_CONNECTED, EV_STATUS, EV_ERROR, EV_SERVER_TEXT,
EV_PRIVMSG, EV_JOIN, EV_PART, EV_QUIT_MSG,
EV_NICK_CHANGE, EV_NAMES, EV_KICK, EV_RAW,
EV_RECONNECT, EV_TOPIC
EV_RECONNECT, EV_TOPIC, EV_NAMES_END
} EvType;
typedef struct {
@@ -881,7 +882,12 @@ static void handle_irc_line(int si, const char *raw) {
ev_simple(EV_STATUS, si, NULL, NULL, "[list] end"); return;
}
if (strcmp(m.cmd,"366")==0) return;
if (strcmp(m.cmd,"366")==0) {
/* end of NAMES — reset pending flag so next /names clears again */
const char *ch = m.nparams>=2 ? m.params[1] : (m.nparams>=1 ? m.params[0] : "");
ev_simple(EV_NAMES_END, si, NULL, ch, NULL);
return;
}
/* AWAY */
if (strcmp(m.cmd,"301")==0) {
@@ -1102,7 +1108,7 @@ static int srv_alloc(void) {
memset(s,0,sizeof(Server));
strncpy(s->host,"irc.libera.chat",MAX_HOST-1);
s->port=6697;
strncpy(s->nick,"sirc_user",MAX_NICK-1);
strncpy(s->nick,"circ_user",MAX_NICK-1);
s->use_tls=1;
s->sock=-1;
pthread_mutex_init(&s->send_lock,NULL);
@@ -1144,7 +1150,7 @@ static void load_config(const char *path) {
if (!f) return;
/* defaults that apply before any [server] block */
char def_nick[MAX_NICK]="sirc_user";
char def_nick[MAX_NICK]="circ_user";
/* current server being parsed; -1 = not inside a [server] block */
int cur_si=-1;
@@ -1646,6 +1652,11 @@ static void handle_event(const Event *ev) {
case EV_NAMES: {
int ci=chan_find(si,ev->chan); if(ci<0) break;
/* first nick of a fresh NAMES reply — wipe the stale list */
if (!g_chans[ci].names_pending) {
g_chans[ci].user_count = 0;
g_chans[ci].names_pending = 1;
}
chan_adduser(&g_chans[ci], ev->extra[0], ev->nick);
chan_sort_users(&g_chans[ci]);
break;
@@ -1666,6 +1677,12 @@ static void handle_event(const Event *ev) {
break;
}
case EV_NAMES_END: {
int ci=chan_find(si,ev->chan); if(ci<0) break;
g_chans[ci].names_pending = 0;
break;
}
}
}