about summary refs log tree commit diff
path: root/channel.c
diff options
context:
space:
mode:
authorNakidai Perumenei <nakidai@disroot.org>2026-12-02 20:29:21 +0300
committerNakidai <nakidai@disroot.org>2026-01-30 15:32:45 +0300
commit559fac39d83083f1720b235e33a8219ed07de653 (patch)
treec5e48f1e5513dbefb14dd2f88f2393a2bee3bffc /channel.c
parent20770f6fad769122248214ffe42268aa61c189cd (diff)
downloadlibreircd-559fac39d83083f1720b235e33a8219ed07de653.tar.gz
libreircd-559fac39d83083f1720b235e33a8219ed07de653.zip
Fix channel remove
Channels are removed just like users, hence they have the same
problem as users had before: when channel is removed, links to it
must be updated. For users that was fixed[1], for users this commit
provides the fix.

[1] Commit where user quit was fixed -
63c0a8860459c0c9bf3b66d4d4ec631ece4bf56e
Diffstat (limited to 'channel.c')
-rw-r--r--channel.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/channel.c b/channel.c
index 0cf0b30..94b0d6c 100644
--- a/channel.c
+++ b/channel.c
@@ -73,8 +73,38 @@ channel_exit(struct Channel *channel, struct Peer *peer)
 		ensure(i != channels_c, warnx(
 			"channel_exit(): couldn't find empty channel"
 		), 1);
-		channels[i] = channels[--channels_c];
+		channel_remove(i);
 	}
 
 	return 0;
 }
+
+void
+channel_remove(size_t cid)
+{
+	struct Channel *tofix;
+	size_t i, j;
+
+	tofix = &channels[channels_c-1];
+	for (i = 0; i < tofix->users_c; ++i)
+	{
+		for (j = 0; j < tofix->users[i]->channels_c; ++j)
+			if (!strcmp(tofix->users[i]->channels[j]->name, tofix->name))
+				break;
+		if (j == tofix->users[i]->channels_c)
+		{
+			warnx(
+				"channel_remove(): %s doesn't belong to %s@%s, "
+				"though they believe in the opposite",
+				tofix->name,
+				getnick(tofix->users[i]),
+				tofix->users[i]->host
+			);
+			continue;
+		}
+
+		tofix->users[i]->channels[j] = &channels[cid];
+	}
+
+	channels[cid] = channels[--channels_c];
+}