diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-18 22:30:18 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-18 22:35:14 +0200 |
commit | 8eb31ad2e11038a17f66c84f48befda6b3b807d2 (patch) | |
tree | 45b4722a0a4f8d669a5e9d8d31631335dd4d7203 | |
parent | bdad7bd7c205bd8d2e1b067d89be88b68b9da34f (diff) | |
download | xK-8eb31ad2e11038a17f66c84f48befda6b3b807d2.tar.gz xK-8eb31ad2e11038a17f66c84f48befda6b3b807d2.tar.xz xK-8eb31ad2e11038a17f66c84f48befda6b3b807d2.zip |
degesch: fix /invite
-rw-r--r-- | common.c | 11 | ||||
-rw-r--r-- | degesch.c | 29 |
2 files changed, 33 insertions, 7 deletions
@@ -70,6 +70,17 @@ str_vector_find (const struct str_vector *v, const char *s) return -1; } +static char * +str_vector_steal (struct str_vector *self, size_t i) +{ + // TODO: str_vector_remove() is then just free(str_vector_steal()) + hard_assert (i < self->len); + char *tmp = self->vector[i]; + memmove (self->vector + i, self->vector + i + 1, + (self->len-- - i) * sizeof *self->vector); + return tmp; +} + static int strncasecmp_ascii (const char *a, const char *b, size_t n) { @@ -6502,18 +6502,33 @@ handle_command_invite (struct app_context *ctx, char *arguments) if (!server_command_check (ctx, "invite", true)) return true; - // XXX: the order of arguments should probably be reverse struct server *s = ctx->current_buffer->server; - char *channel_name = try_get_channel (ctx, &arguments); + + struct str_vector v; + str_vector_init (&v); + split_str_ignore_empty (arguments, ' ', &v); + + char *channel_name = NULL; + size_t last = v.len - 1; + if (v.len && irc_is_channel (s, v.vector[last])) + channel_name = str_vector_steal (&v, last); + else if (ctx->current_buffer->type == BUFFER_CHANNEL) + channel_name = xstrdup (ctx->current_buffer->channel->name); + + bool result = true; if (!channel_name) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't invite", "no channel name given and this buffer is not a channel"); - else if (*arguments) - irc_send (s, "INVITE %s %s", arguments, channel_name); + else if (v.len) + for (size_t i = 0; i < v.len; i++) + irc_send (s, "INVITE %s %s", v.vector[i], channel_name); else - return false; - return true; + result = false; + + str_vector_free (&v); + free (channel_name); + return result; } static bool @@ -6807,7 +6822,7 @@ g_command_handlers[] = "[<channel>] <mask>...", handle_command_unban }, { "invite", "Invite user to channel", - "[<channel>] <user>", + "<user>... [<channel>]", handle_command_invite }, { "connect", "Connect to the server", |