+/****************************** NEW_ID packet *******************************/
+
+/* Received new ID packet from server during registering to SILC network */
+
+SILC_FSM_STATE(silc_client_new_id)
+{
+ SilcClientConnection conn = fsm_context;
+ SilcClient client = conn->client;
+ SilcPacket packet = state_context;
+ SilcID id;
+
+ if (conn->local_id)
+ goto out;
+
+ SILC_LOG_DEBUG(("New ID received from server"));
+
+ if (!silc_id_payload_parse_id(silc_buffer_data(&packet->buffer),
+ silc_buffer_len(&packet->buffer), &id))
+ goto out;
+
+ /* Create local client entry */
+ conn->local_entry = silc_client_add_client(client, conn,
+ (client->nickname ?
+ client->nickname :
+ client->username),
+ client->username,
+ client->realname,
+ &id.u.client_id, 0);
+ if (!conn->local_entry)
+ goto out;
+
+ /* Save the ID */
+ conn->local_id = &conn->local_entry->id;
+ conn->local_idp = silc_buffer_copy(&packet->buffer);
+
+ /* Save cache entry */
+ silc_idcache_find_by_id_one(conn->internal->client_cache, conn->local_id,
+ &conn->internal->local_entry);
+
+ /* Save remote ID */
+ if (packet->src_id_len) {
+ conn->remote_idp = silc_id_payload_encode_data(packet->src_id,
+ packet->src_id_len,
+ packet->src_id_type);
+ if (!conn->remote_idp)
+ goto out;
+ silc_id_payload_parse_id(silc_buffer_data(conn->remote_idp),
+ silc_buffer_len(conn->remote_idp),
+ &conn->remote_id);
+ }
+
+ /* Signal connection that new ID was received so it can continue
+ with the registering. */
+ if (conn->internal->registering)
+ silc_fsm_continue_sync(&conn->internal->event_thread);
+
+ out:
+ /** Packet processed */
+ silc_packet_free(packet);
+ return SILC_FSM_FINISH;
+}
+
+