aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-08 23:22:00 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-08 23:22:26 +0200
commit5e26dd726cdfcaa01ad7c3a95c17c83fbcc73031 (patch)
tree521da9d83f03dfc6a9e2091b76171f8bafc9741a
parent5b1690ede4ae5db0b7ba8ca9ee4559430c41b924 (diff)
downloadxK-5e26dd726cdfcaa01ad7c3a95c17c83fbcc73031.tar.gz
xK-5e26dd726cdfcaa01ad7c3a95c17c83fbcc73031.tar.xz
xK-5e26dd726cdfcaa01ad7c3a95c17c83fbcc73031.zip
kike: refactor INVITE a bit
-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;