+ conn->current_channel = channel;
+
+ /* Get hmac */
+ hmac = silc_argument_get_arg_type(cmd->args, 11, NULL);
+ if (hmac) {
+ if (!silc_hmac_alloc(hmac, NULL, &channel->hmac)) {
+ cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "Cannot join channel: Unsupported HMAC `%s'",
+ hmac);
+ COMMAND_REPLY_ERROR;
+ silc_free(channel_name);
+ goto out;
+ }
+ }
+
+ /* Get the list count */
+ tmp = silc_argument_get_arg_type(cmd->args, 12, &len);
+ if (!tmp)
+ goto out;
+ SILC_GET32_MSB(list_count, tmp);
+
+ /* Get Client ID list */
+ tmp = silc_argument_get_arg_type(cmd->args, 13, &len);
+ if (!tmp)
+ goto out;
+
+ client_id_list = silc_buffer_alloc(len);
+ silc_buffer_pull_tail(client_id_list, len);
+ silc_buffer_put(client_id_list, tmp, len);
+
+ /* Get client mode list */
+ tmp = silc_argument_get_arg_type(cmd->args, 14, &len);
+ if (!tmp)
+ goto out;
+
+ client_mode_list = silc_buffer_alloc(len);
+ silc_buffer_pull_tail(client_mode_list, len);
+ silc_buffer_put(client_mode_list, tmp, len);
+
+ /* Add clients we received in the reply to the channel */
+ for (i = 0; i < list_count; i++) {
+ uint16 idp_len;
+ uint32 mode;
+ SilcClientID *client_id;
+ SilcClientEntry client_entry;
+
+ /* Client ID */
+ SILC_GET16_MSB(idp_len, client_id_list->data + 2);
+ idp_len += 4;
+ client_id = silc_id_payload_parse_id(client_id_list->data, idp_len);
+ if (!client_id)
+ continue;
+
+ /* Mode */
+ SILC_GET32_MSB(mode, client_mode_list->data);
+
+ /* Check if we have this client cached already. */
+ if (!silc_idcache_find_by_id_one_ext(conn->client_cache,
+ (void *)client_id,
+ NULL, NULL,
+ silc_hash_client_id_compare, NULL,
+ &id_cache)) {
+ /* No, we don't have it, add entry for it. */
+ client_entry =
+ silc_client_add_client(cmd->client, conn, NULL, NULL, NULL,
+ silc_id_dup(client_id, SILC_ID_CLIENT), 0);
+ } else {
+ /* Yes, we have it already */
+ client_entry = (SilcClientEntry)id_cache->context;
+ }
+
+ /* Join the client to the channel */
+ chu = silc_calloc(1, sizeof(*chu));
+ chu->client = client_entry;
+ chu->mode = mode;
+ silc_list_add(channel->clients, chu);
+ silc_free(client_id);
+
+ silc_buffer_pull(client_id_list, idp_len);
+ silc_buffer_pull(client_mode_list, 4);
+ }
+ silc_buffer_push(client_id_list, client_id_list->data -
+ client_id_list->head);
+ silc_buffer_push(client_mode_list, client_mode_list->data -
+ client_mode_list->head);
+