+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientWindow win = NULL;
+ SilcBuffer buffer;
+ SilcIDCache *id_cache;
+ unsigned char *client_id, *channel_id;
+
+#define CIDC(x) win->client_id_cache[(x) - 32], \
+ win->client_id_cache_count[(x) - 32]
+#define CHIDC(x) win->channel_id_cache[(x) - 32], \
+ win->channel_id_cache_count[(x) - 32]
+
+ if (cmd->argc != 3) {
+ silc_say(cmd->client, "Usage: /INVITE <nickname>[@<server>] <channel>");
+ goto out;
+ }
+
+ if (!cmd->client->current_win->sock) {
+ SILC_NOT_CONNECTED(cmd->client);
+ goto out;
+ }
+
+ win = (SilcClientWindow)cmd->sock->user_data;
+
+ /* Get client ID of the client to be invited. If we don't have it
+ we will request it and cache it. This same command will be called
+ again after we have received the reply (ie. pending). */
+ if (!silc_idcache_find_by_data(CIDC(cmd->argv[1][0]), cmd->argv[1],
+ &id_cache)) {
+ SilcClientCommandContext ctx;
+ char ident[512];
+
+ ctx = silc_calloc(1, sizeof(*ctx));
+ ctx->client = cmd->client;
+ ctx->sock = cmd->sock;
+ memset(ident, 0, sizeof(ident));
+ snprintf(ident, sizeof(ident), "/IDENTIFY %s", cmd->argv[1]);
+ silc_client_parse_command_line(ident, &ctx->argv, &ctx->argv_lens,
+ &ctx->argv_types, &ctx->argc, 2);
+ silc_client_command_identify(ctx);
+ silc_client_command_pending(SILC_COMMAND_IDENTIFY,
+ silc_client_command_invite, context);
+ return;
+ }
+
+ client_id = silc_id_id2str(id_cache->id, SILC_ID_CLIENT);
+
+ /* Get Channel ID of the channel. */
+ if (!silc_idcache_find_by_data(CHIDC(cmd->argv[2][0]), cmd->argv[2],
+ &id_cache)) {
+ silc_say(cmd->client, "You are not on that channel");
+ silc_free(client_id);
+ goto out;
+ }
+
+ channel_id = silc_id_id2str(id_cache->id, SILC_ID_CHANNEL);
+
+ buffer = silc_command_encode_payload_va(SILC_COMMAND_INVITE, 2,
+ client_id, SILC_ID_CLIENT_LEN,
+ channel_id, SILC_ID_CHANNEL_LEN);
+ silc_client_packet_send(cmd->client, cmd->sock,
+ SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
+ buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+
+ silc_say(cmd->client, "Inviting %s to channel %s", cmd->argv[1],
+ cmd->argv[2]);
+
+ out:
+ silc_client_command_free(cmd);
+#undef CIDC
+#undef CHIDC