fix some channels not auto join

This commit is contained in:
2026-04-08 23:04:55 +08:00
parent 5a43139f75
commit 1f38d54b39
+30 -17
View File
@@ -1110,16 +1110,24 @@ static int srv_alloc(void) {
} }
static void srv_add_autojoin(int si, const char *chanlist) { static void srv_add_autojoin(int si, const char *chanlist) {
char tmp[512]; strncpy(tmp,chanlist,511); char tmp[MAX_LINE]; strncpy(tmp, chanlist, MAX_LINE-1);
char *tok=strtok(tmp,","); char *tok = strtok(tmp, ",");
while (tok) { while (tok) {
while (*tok==' ') tok++; /* trim leading and trailing spaces */
if (*tok && g_srv[si].autojoin_count<MAX_AUTOJOIN) { while (*tok == ' ') tok++;
char ch[MAX_CHAN]; strncpy(ch,tok,MAX_CHAN-1); char *end = tok + strlen(tok) - 1;
if (ch[0]!='#') { memmove(ch+1,ch,strlen(ch)+1); ch[0]='#'; } while (end > tok && *end == ' ') *end-- = '\0';
strncpy(g_srv[si].autojoin[g_srv[si].autojoin_count++],ch,MAX_CHAN-1); if (*tok && g_srv[si].autojoin_count < MAX_AUTOJOIN) {
char ch[MAX_CHAN]; strncpy(ch, tok, MAX_CHAN-1);
if (ch[0] != '#') { memmove(ch+1, ch, strlen(ch)+1); ch[0]='#'; }
/* avoid duplicates */
int dup = 0;
for (int i = 0; i < g_srv[si].autojoin_count; i++)
if (strcasecmp(g_srv[si].autojoin[i], ch) == 0) { dup=1; break; }
if (!dup)
strncpy(g_srv[si].autojoin[g_srv[si].autojoin_count++], ch, MAX_CHAN-1);
} }
tok=strtok(NULL,","); tok = strtok(NULL, ",");
} }
} }
@@ -1492,15 +1500,20 @@ static void build_windows(void) {
/* ── event handler ─────────────────────────────────────────────────────────── */ /* ── event handler ─────────────────────────────────────────────────────────── */
static void do_rejoin_channels(int si) { static void do_rejoin_channels(int si) {
int any=0; /* always join every configured autojoin channel */
for (int i=0;i<g_chan_count;i++) { for (int j = 0; j < g_srv[si].autojoin_count; j++)
if (g_chans[i].srv==si && g_chans[i].name[0]=='#') { srv_sendf(si, "JOIN %s", g_srv[si].autojoin[j]);
srv_sendf(si,"JOIN %s",g_chans[i].name); any=1;
} /* also rejoin any channels open from a previous session that aren't
} in the autojoin list (e.g. channels joined manually before disconnect) */
if (!any) { for (int i = 0; i < g_chan_count; i++) {
for (int j=0;j<g_srv[si].autojoin_count;j++) if (g_chans[i].srv != si || g_chans[i].name[0] != '#') continue;
srv_sendf(si,"JOIN %s",g_srv[si].autojoin[j]); int already = 0;
for (int j = 0; j < g_srv[si].autojoin_count; j++)
if (strcasecmp(g_srv[si].autojoin[j], g_chans[i].name) == 0)
{ already = 1; break; }
if (!already)
srv_sendf(si, "JOIN %s", g_chans[i].name);
} }
} }