kike: fix `struct channel_user'
Storing the nickname instead of a reference to `struct client' didn't play well with nickname changes. The client needs to be unlinked from any channels before his object can be deleted, anyway.
This commit is contained in:
parent
9d86d81851
commit
266626584d
35
src/kike.c
35
src/kike.c
@ -349,7 +349,7 @@ struct channel_user
|
||||
LIST_HEADER (channel_user)
|
||||
|
||||
unsigned modes;
|
||||
char nickname[];
|
||||
struct client *c;
|
||||
};
|
||||
|
||||
struct channel
|
||||
@ -554,17 +554,16 @@ static struct channel_user *
|
||||
channel_get_user (const struct channel *chan, const struct client *c)
|
||||
{
|
||||
for (struct channel_user *iter = chan->users; iter; iter = iter->next)
|
||||
if (!irc_strcmp (iter->nickname, c->nickname))
|
||||
if (iter->c == c)
|
||||
return iter;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct channel_user *
|
||||
channel_add_user (struct channel *chan, const struct client *c)
|
||||
channel_add_user (struct channel *chan, struct client *c)
|
||||
{
|
||||
size_t nick_len = strlen (c->nickname);
|
||||
struct channel_user *link = xcalloc (1, sizeof *link + nick_len + 1);
|
||||
memcpy (link->nickname, c->nickname, nick_len + 1);
|
||||
struct channel_user *link = xcalloc (1, sizeof *link);
|
||||
link->c = c;
|
||||
LIST_PREPEND (chan->users, link);
|
||||
return link;
|
||||
}
|
||||
@ -665,8 +664,8 @@ client_send_to_roommates (struct client *c, const char *message)
|
||||
// When we're unregistering, the str_map_find() will return zero,
|
||||
// which will prevent sending the QUIT message to ourselves.
|
||||
for (struct channel_user *iter = chan->users; iter; iter = iter->next)
|
||||
str_map_set (&targets, iter->nickname,
|
||||
str_map_find (&c->ctx->users, iter->nickname));
|
||||
str_map_set (&targets, iter->c->nickname,
|
||||
str_map_find (&c->ctx->users, iter->c->nickname));
|
||||
}
|
||||
|
||||
str_map_iter_init (&iter, &targets);
|
||||
@ -1333,9 +1332,8 @@ irc_channel_multicast (struct channel *chan, const char *message,
|
||||
{
|
||||
for (struct channel_user *iter = chan->users; iter; iter = iter->next)
|
||||
{
|
||||
struct client *c = str_map_find (&chan->ctx->users, iter->nickname);
|
||||
if (c != except)
|
||||
irc_send (c, "%s", message);
|
||||
if (iter->c != except)
|
||||
irc_send (iter->c, "%s", message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1496,7 +1494,7 @@ irc_handle_chan_mode_change (struct client *c,
|
||||
else if (irc_modify_mode (&target_user->modes, (mode), adding)) \
|
||||
{ \
|
||||
str_append_c (output, mode_char); \
|
||||
str_vector_add (output_params, target_user->nickname); \
|
||||
str_vector_add (output_params, client->nickname); \
|
||||
}
|
||||
|
||||
#define HANDLE_LIST(list, list_msg, end_msg) \
|
||||
@ -1842,8 +1840,7 @@ irc_send_rpl_namreply (struct client *c, const struct channel *chan)
|
||||
bool on_channel = channel_get_user (chan, c);
|
||||
for (struct channel_user *iter = chan->users; iter; iter = iter->next)
|
||||
{
|
||||
struct client *target = str_map_find (&c->ctx->users, iter->nickname);
|
||||
if (!on_channel && (target->mode & IRC_USER_MODE_INVISIBLE))
|
||||
if (!on_channel && (iter->c->mode & IRC_USER_MODE_INVISIBLE))
|
||||
continue;
|
||||
|
||||
struct str result;
|
||||
@ -1852,7 +1849,7 @@ irc_send_rpl_namreply (struct client *c, const struct channel *chan)
|
||||
str_append_c (&result, '@');
|
||||
else if (iter->modes & IRC_CHAN_MODE_VOICE)
|
||||
str_append_c (&result, '+');
|
||||
str_append (&result, target->nickname);
|
||||
str_append (&result, iter->c->nickname);
|
||||
str_vector_add_owned (&nicks, str_steal (&result));
|
||||
}
|
||||
|
||||
@ -1989,11 +1986,9 @@ irc_handle_who (const struct irc_message *msg, struct client *c)
|
||||
for (struct channel_user *iter = chan->users;
|
||||
iter; iter = iter->next)
|
||||
{
|
||||
struct client *target =
|
||||
str_map_find (&c->ctx->users, iter->nickname);
|
||||
if ((on_chan || !(target->mode & IRC_USER_MODE_INVISIBLE))
|
||||
&& (!only_ops || (target->mode & IRC_USER_MODE_OPERATOR)))
|
||||
irc_send_rpl_whoreply (c, chan, target);
|
||||
if ((on_chan || !(iter->c->mode & IRC_USER_MODE_INVISIBLE))
|
||||
&& (!only_ops || (iter->c->mode & IRC_USER_MODE_OPERATOR)))
|
||||
irc_send_rpl_whoreply (c, chan, iter->c);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user