summaryrefslogtreecommitdiff
path: root/kike.c
diff options
context:
space:
mode:
Diffstat (limited to 'kike.c')
-rw-r--r--kike.c35
1 files changed, 7 insertions, 28 deletions
diff --git a/kike.c b/kike.c
index 538d0d3..d5136d7 100644
--- a/kike.c
+++ b/kike.c
@@ -327,8 +327,7 @@ struct client
unsigned mode; ///< User's mode
char *away_message; ///< Away message
time_t last_active; ///< Last PRIVMSG, to get idle time
- // XXX: maybe this should rather be a str_map
- struct str_vector invites; ///< Channel invitations
+ struct str_map invites; ///< Channel invitations by operators
struct flood_detector antiflood; ///< Flood detector
};
@@ -342,7 +341,8 @@ client_init (struct client *self)
str_init (&self->write_buffer);
// TODO: make this configurable and more fine-grained
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
@@ -364,7 +364,7 @@ client_free (struct client *self)
free (self->address);
free (self->away_message);
flood_detector_free (&self->antiflood);
- str_vector_free (&self->invites);
+ str_map_free (&self->invites);
}
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);
}
-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
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);
// Only storing the invite if it makes sense
- if (!irc_is_invited (client, channel_name))
- str_vector_add (&client->invites, channel_name);
+ str_map_set (&client->invites, channel_name, (void *) 1);
}
}
@@ -2351,17 +2341,6 @@ irc_handle_invite (const struct irc_message *msg, struct client *c)
}
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
irc_try_join (struct client *c, const char *channel_name, const char *key)
{
struct channel *chan = str_map_find (&c->ctx->channels, channel_name);
@@ -2376,7 +2355,7 @@ irc_try_join (struct client *c, const char *channel_name, const char *key)
else if (channel_get_user (chan, c))
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)
&& !client_in_mask_list (c, &chan->invite_list)
&& !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);
// 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;