commit 1f38d54b398e5328840f2f8a9af0e850a4ae5016
parent 5a43139f7520c2168c39dc9792aa9ecef510a89a
Author: emmett1 <me@emmett1.my>
Date: Wed, 8 Apr 2026 23:04:55 +0800
fix some channels not auto join
Diffstat:
| M | sirc.c | | | 47 | ++++++++++++++++++++++++++++++----------------- |
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/sirc.c b/sirc.c
@@ -1110,16 +1110,24 @@ static int srv_alloc(void) {
}
static void srv_add_autojoin(int si, const char *chanlist) {
- char tmp[512]; strncpy(tmp,chanlist,511);
- char *tok=strtok(tmp,",");
+ char tmp[MAX_LINE]; strncpy(tmp, chanlist, MAX_LINE-1);
+ char *tok = strtok(tmp, ",");
while (tok) {
- while (*tok==' ') tok++;
- 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]='#'; }
- strncpy(g_srv[si].autojoin[g_srv[si].autojoin_count++],ch,MAX_CHAN-1);
+ /* trim leading and trailing spaces */
+ while (*tok == ' ') tok++;
+ char *end = tok + strlen(tok) - 1;
+ while (end > tok && *end == ' ') *end-- = '\0';
+ 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 ─────────────────────────────────────────────────────────── */
static void do_rejoin_channels(int si) {
- int any=0;
- for (int i=0;i<g_chan_count;i++) {
- if (g_chans[i].srv==si && g_chans[i].name[0]=='#') {
- srv_sendf(si,"JOIN %s",g_chans[i].name); any=1;
- }
- }
- if (!any) {
- for (int j=0;j<g_srv[si].autojoin_count;j++)
- srv_sendf(si,"JOIN %s",g_srv[si].autojoin[j]);
+ /* always join every configured autojoin channel */
+ for (int j = 0; j < g_srv[si].autojoin_count; j++)
+ srv_sendf(si, "JOIN %s", g_srv[si].autojoin[j]);
+
+ /* also rejoin any channels open from a previous session that aren't
+ in the autojoin list (e.g. channels joined manually before disconnect) */
+ for (int i = 0; i < g_chan_count; i++) {
+ if (g_chans[i].srv != si || g_chans[i].name[0] != '#') continue;
+ 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);
}
}