Example #1
0
        private void GetAvatarServiceResponse(XmlNode avatarXmlNode, string nickname, Guid sessionId, ZoneId zoneId, Action <bool> gotAvatarServiceResponse)
        {
            List <ItemId> itemIds = null;
            AvatarId      avatarId;

            try
            {
                if (AvatarXmlUtil.GetAvatarInfoFromAvatarXmlNode(avatarXmlNode, out avatarId, out itemIds))
                {
                    Dna savedDna = mServerAssetRepository.GetDna(itemIds);

                    // Create an updated dna by starting with the reference dna and updating it with the savedDna
                    GetReferenceAvatar(delegate(Dna referenceAvatarDna)
                    {
                        Dna avatarDna = new Dna(mReferenceAvatarDna);
                        avatarDna.UpdateDna(savedDna);
                        // TODO?  If UpdateDna overwrites something or fills in missing data we should save the dna back to the db

                        // Get xml from updated avatar dna
                        XmlDocument dnaXml = mServerAssetRepository.GetXmlDna(avatarDna.GetItemIdList());

                        DistributedObjectId distributedObjectId = mDistributedObjectIdManager.GetNewId();

                        ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId);
                        ServerDistributedAvatar serverDistributedAvatar = new ServerDistributedAvatar(distributedObjectId, avatarId, sessionId, nickname, dnaXml, serverAccount, mServerObjectRepository, mServerAssetRepository);
                        //register object with object repository
                        mServerObjectRepository.AddObjectToSessionId(sessionId, serverDistributedAvatar);
                        //register object with session manager
                        mServerEngine.ProcessZoneChange(serverDistributedAvatar, zoneId);
                        gotAvatarServiceResponse(true);
                    });
                }
                else
                {
                    gotAvatarServiceResponse(false);
                }
            }
            catch (System.Exception ex)
            {
                StateServerAssert.Assert(ex);
                gotAvatarServiceResponse(false);
            }
        }
Example #2
0
        /// <summary>
        /// Get a reference system avatar.  This avatar is used to fill in missing required info when pulling an avatar from the db
        /// </summary>
        private void GetReferenceAvatar(Action <Dna> gotReferenceAvatarFinished)
        {
            Action <XmlDocument> systemAvatarCallback = delegate(XmlDocument xmlResponse)
            {
                // Get the avatars for the friends without Hangout Avatars
                XmlNode       avatarXmlNode = xmlResponse.SelectSingleNode("/Avatars/Avatar[@AvatarId='1']");
                AvatarId      avatarId;
                List <ItemId> itemIds = null;
                if (AvatarXmlUtil.GetAvatarInfoFromAvatarXmlNode(avatarXmlNode, out avatarId, out itemIds))
                {
                    //use the ServerAssetRepo to composite the List<ItemId> into an XmlNode
                    XmlDocument itemsXml = mServerAssetRepository.GetXmlDna(itemIds);

                    // Get a list of AssetInfos from this xml
                    IEnumerable <AssetInfo> assetInfoList = ServerAssetInfo.Parse(itemsXml);

                    // Make dna
                    mReferenceAvatarDna = new Dna();
                    mReferenceAvatarDna.UpdateDna(assetInfoList);
                    gotReferenceAvatarFinished(mReferenceAvatarDna);
                    mLogger.Debug("System avatar xml = " + xmlResponse.OuterXml);
                }
                else
                {
                    StateServerAssert.Assert(new Exception("Didn't get a valid system avatar for reference avatar, using an empty DNA"));
                    mReferenceAvatarDna = new Dna();
                    gotReferenceAvatarFinished(mReferenceAvatarDna);
                }
            };

            if (mReferenceAvatarDna == null)
            {
                AvatarManagerServiceAPI.GetSystemAvatars(systemAvatarCallback);
            }
            else
            {
                gotReferenceAvatarFinished(mReferenceAvatarDna);
            }
        }