From 9ae659fd6c792407f3d80ea4d313bf850c2332ec Mon Sep 17 00:00:00 2001 From: Nakidai Date: Fri, 6 Feb 2026 17:04:09 +0300 Subject: Change way to deal with modes in channels I thought it'd be fine to store modes as an array. But using this is awful experience. Take a look at simple NAMES command: it just needs to check whether some user is oper or voice or not, and with that approach it will need to iterate over an array of users, and for each user iterate over an array of modes. Or it is possible to optimize it, saving all interesting modes to a local buffer and then iterating over it. But those are attempts to fix broken design So, instead of array of modes there'll be lots of fields regarding each mode or kind of mode From now on (struct Channel).peers is not a simple array of peers, but the one with metainformation. This is done by making an array of structures, so there are renames throughout the code Also, I didn't like that it was users and not peers and this is a nice opportunity to rename it: in first place this was done to avoid thing that compiler somehow could silently ignore type change, but this is also a stylistic change reflecting my view on naming --- user.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'user.c') diff --git a/user.c b/user.c index 719c60e..5d9bc15 100644 --- a/user.c +++ b/user.c @@ -88,17 +88,19 @@ skip: void user_remove(size_t pid) { + struct Peer *last; size_t i, j; for (i = 0; i < peers[pid].channels_c; ++i) channel_exit(peers[pid].channels[i], &peers[pid]); - for (i = 0; i < peers[peers_c-1].channels_c; ++i) + last = &peers[peers_c-1]; + for (i = 0; i < last->channels_c; ++i) { - for (j = 0; j < peers[peers_c-1].channels[i]->users_c; ++j) - if (peers[peers_c-1].channels[i]->users[j]->fd == peers[peers_c-1].fd) + for (j = 0; j < last->channels[i]->peers_c; ++j) + if (last->channels[i]->peers[j].p->fd == last->fd) break; - if (j == peers[peers_c-1].channels[i]->users_c) + if (j == last->channels[i]->peers_c) { warnx( "user_unlink(): %s@%s doesn't belong to %s, " @@ -110,7 +112,7 @@ user_remove(size_t pid) continue; } - peers[peers_c-1].channels[i]->users[j] = &peers[pid]; + last->channels[i]->peers[j].p = &peers[pid]; } peers[pid] = peers[--peers_c]; -- cgit 1.4.1