From 25365ce71652e0e6fee548c88f1ddecab50084fb Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Wed, 27 May 2020 00:14:58 +0100 Subject: [PATCH] Keep client channel lists sorted --- ircd/channel.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ircd/channel.c b/ircd/channel.c index fdf9c25a..70eb5c2b 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -221,6 +221,7 @@ void add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) { struct membership *msptr; + rb_dlink_node *p; s_assert(client_p->user != NULL); if(client_p->user == NULL) @@ -232,7 +233,17 @@ add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) msptr->client_p = client_p; msptr->flags = flags; - rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel); + RB_DLINK_FOREACH(p, client_p->user->channel.head) + { + struct membership *ms2 = p->data; + if (irccmp(chptr->chname, ms2->chptr->chname) < 0) + break; + } + if (p == NULL) + rb_dlinkAddTail(msptr, &msptr->usernode, &client_p->user->channel); + else + rb_dlinkAddBefore(p, msptr, &msptr->usernode, &client_p->user->channel); + rb_dlinkAdd(msptr, &msptr->channode, &chptr->members); if(MyClient(client_p))