kike: refactor INVITE a bit
This commit is contained in:
parent
5b1690ede4
commit
5e26dd726c
35
kike.c
35
kike.c
|
@ -327,8 +327,7 @@ struct client
|
||||||
unsigned mode; ///< User's mode
|
unsigned mode; ///< User's mode
|
||||||
char *away_message; ///< Away message
|
char *away_message; ///< Away message
|
||||||
time_t last_active; ///< Last PRIVMSG, to get idle time
|
time_t last_active; ///< Last PRIVMSG, to get idle time
|
||||||
// XXX: maybe this should rather be a str_map
|
struct str_map invites; ///< Channel invitations by operators
|
||||||
struct str_vector invites; ///< Channel invitations
|
|
||||||
struct flood_detector antiflood; ///< Flood detector
|
struct flood_detector antiflood; ///< Flood detector
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -342,7 +341,8 @@ client_init (struct client *self)
|
||||||
str_init (&self->write_buffer);
|
str_init (&self->write_buffer);
|
||||||
// TODO: make this configurable and more fine-grained
|
// TODO: make this configurable and more fine-grained
|
||||||
flood_detector_init (&self->antiflood, 10, 20);
|
flood_detector_init (&self->antiflood, 10, 20);
|
||||||
str_vector_init (&self->invites);
|
str_map_init (&self->invites);
|
||||||
|
self->invites.key_xfrm = irc_strxfrm;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -364,7 +364,7 @@ client_free (struct client *self)
|
||||||
free (self->address);
|
free (self->address);
|
||||||
free (self->away_message);
|
free (self->away_message);
|
||||||
flood_detector_free (&self->antiflood);
|
flood_detector_free (&self->antiflood);
|
||||||
str_vector_free (&self->invites);
|
str_map_free (&self->invites);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void client_close_link (struct client *, const char *);
|
static void client_close_link (struct client *, const char *);
|
||||||
|
@ -2300,15 +2300,6 @@ irc_handle_kick (const struct irc_message *msg, struct client *c)
|
||||||
str_vector_free (&users);
|
str_vector_free (&users);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
irc_is_invited (struct client *c, const char *channel_name)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < c->invites.len; i++)
|
|
||||||
if (!irc_strcmp (c->invites.vector[i], channel_name))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
irc_handle_invite (const struct irc_message *msg, struct client *c)
|
irc_handle_invite (const struct irc_message *msg, struct client *c)
|
||||||
{
|
{
|
||||||
|
@ -2337,8 +2328,7 @@ irc_handle_invite (const struct irc_message *msg, struct client *c)
|
||||||
RETURN_WITH_REPLY (c, IRC_ERR_CHANOPRIVSNEEDED, channel_name);
|
RETURN_WITH_REPLY (c, IRC_ERR_CHANOPRIVSNEEDED, channel_name);
|
||||||
|
|
||||||
// Only storing the invite if it makes sense
|
// Only storing the invite if it makes sense
|
||||||
if (!irc_is_invited (client, channel_name))
|
str_map_set (&client->invites, channel_name, (void *) 1);
|
||||||
str_vector_add (&client->invites, channel_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2350,17 +2340,6 @@ irc_handle_invite (const struct irc_message *msg, struct client *c)
|
||||||
irc_send_reply (c, IRC_RPL_INVITING, client->nickname, channel_name);
|
irc_send_reply (c, IRC_RPL_INVITING, client->nickname, channel_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
irc_remove_invite (struct client *c, const char *channel_name)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < c->invites.len; i++)
|
|
||||||
if (!irc_strcmp (c->invites.vector[i], channel_name))
|
|
||||||
{
|
|
||||||
str_vector_remove (&c->invites, i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
irc_try_join (struct client *c, const char *channel_name, const char *key)
|
irc_try_join (struct client *c, const char *channel_name, const char *key)
|
||||||
{
|
{
|
||||||
|
@ -2376,7 +2355,7 @@ irc_try_join (struct client *c, const char *channel_name, const char *key)
|
||||||
else if (channel_get_user (chan, c))
|
else if (channel_get_user (chan, c))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool invited = irc_is_invited (c, channel_name);
|
bool invited = str_map_find (&c->invites, channel_name);
|
||||||
if ((chan->modes & IRC_CHAN_MODE_INVITE_ONLY)
|
if ((chan->modes & IRC_CHAN_MODE_INVITE_ONLY)
|
||||||
&& !client_in_mask_list (c, &chan->invite_list)
|
&& !client_in_mask_list (c, &chan->invite_list)
|
||||||
&& !invited)
|
&& !invited)
|
||||||
|
@ -2392,7 +2371,7 @@ irc_try_join (struct client *c, const char *channel_name, const char *key)
|
||||||
RETURN_WITH_REPLY (c, IRC_ERR_BANNEDFROMCHAN, channel_name);
|
RETURN_WITH_REPLY (c, IRC_ERR_BANNEDFROMCHAN, channel_name);
|
||||||
|
|
||||||
// Destroy any invitation as there's no other way to get rid of it
|
// Destroy any invitation as there's no other way to get rid of it
|
||||||
irc_remove_invite (c, channel_name);
|
str_map_set (&c->invites, channel_name, NULL);
|
||||||
|
|
||||||
channel_add_user (chan, c)->modes = user_mode;
|
channel_add_user (chan, c)->modes = user_mode;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue