diff options
| -rw-r--r-- | channel.c | 32 | ||||
| -rw-r--r-- | ircd.h | 1 |
2 files changed, 32 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]; +} diff --git a/ircd.h b/ircd.h index 2c4b144..8def73a 100644 --- a/ircd.h +++ b/ircd.h @@ -92,6 +92,7 @@ void user_remove(size_t pid); int channel_join(struct Channel *channel, struct Peer *peer); int channel_exit(struct Channel *channel, struct Peer *peer); +void channel_remove(size_t cid); int parse_message(char *buf, struct Message *msg); int handle(struct Peer *peer); |