Exemplo n.º 1
0
        public void RebakeAppearance(Action <string> logOutput = null)
        {
            lock (m_DataLock)
            {
                if (m_BakeCache == null)
                {
                    m_BakeCache = new BakeCache(AssetService);
                }
            }

            try
            {
                m_BakeCache.LoadFromCurrentOutfit(Owner, InventoryService, AssetService, logOutput);
                Appearance = m_BakeCache.Bake(SceneAssetService, logOutput);
#if DEBUG
                logOutput?.Invoke(string.Format("Appearance for {0} at version {1}", Owner.ToString(), Appearance.Serial));
#endif
            }
            catch (AlreadyBakedException)
            {
                /* ignore exception */
            }
            catch (Exception e)
            {
                m_Log.Error("Rebake appearance failed for " + Owner.ToString(), e);
            }
        }
        ///<summary> Sets up Outputs, Info and variables for use. </summary>
        void Start()
        {
            output.RemoveAll(eOut => !eOut);

            appearance = (appearance) ? Instantiate(appearance) : ScriptableObject.CreateInstance(typeof(AppearanceInfo)) as AppearanceInfo;
            appearance.Setup(gameObject);
            appearance.SetupRenderer();

            if (destruction)
            {
                destruction = Instantiate(destruction);
                destruction.Setup(gameObject);
            }


            for (int i = 0; i < output.Count; i++)
            {
                output[i].firstSource = this;

                if (output[i].similarity == Similarity.UNIQUE)
                {
                    output[i] = Instantiate(output[i]);
                    output[i].SetID();
                }
            }

            SetHitpointsToMax(hitPoints == 0);      //Set hitpoints to hitpoint limit if they were not given a non-zero value
        }
        ///<summary> Checks if there's a different priority Appearance in the inputList. Returns true if the given AppearanceInfo is the priority. </summary>
        private bool IsPriority(AppearanceInfo apInfo)
        {
            if (apInfo && apInfo.canUseMaterial)
            {
                return(!inputList.Exists(eOut => eOut.appearanceI && eOut.appearanceI.IsPriority(apInfo)));
            }

            return(false);
        }
Exemplo n.º 4
0
    private void InitializeTabbedPanel()
    {
        AppearanceInfo dimensions = window.CurrentAppearanceInfo();
        float          tabbedPanelWidth = dimensions.centerWidth - 10, tabbedPanelHeight = dimensions.centerHeight - 10, tabbedPanelX = (Screen.width / 2f) - (tabbedPanelWidth / 2), tabbedPanelY = (Screen.height / 2f) - (tabbedPanelHeight / 2);

        tabbedPanel = new OxTabbedPanel(new Vector2(tabbedPanelX, tabbedPanelY), new Vector2(tabbedPanelWidth, tabbedPanelHeight));
        window.AddItems(tabbedPanel);
        //tabbedPanel.position = new Vector2(tabbedPanelX, tabbedPanelY);
    }
 public MainInfo(BinaryReader br)
 {
     Id             = br.ReadInt32();
     Name           = br.ReadNumberLengthUnicodeString();
     Hero           = br.ReadHero();
     Advancement    = br.ReadByte();
     Portrait       = br.ReadUInt32();
     Appearance     = new AppearanceInfo(br);
     Level          = br.ReadByte();
     Unknown1       = br.ReadByte();
     Unknown2       = new List <byte>(br.ReadBytes(10));
     EquippedWeapon = new EquippedWeaponInfo(br);
 }
        ///<summary> Sets Info and variables up for use. </summary>
        public void Setup(EnvironObject targetEO, EnvironObject lastSourceEO)
        {
            if (damageI)
            {
                damageI = Instantiate(damageI);
                damageI.Setup(targetEO.resistances);
            }

            if (appearanceI)
            {
                appearanceI = Instantiate(appearanceI);
                appearanceI.Setup(targetEO.gameObject);

                if (appearanceI.hideOnResistance && targetEO.resistances)   //Turns off Appearance particles and materials if hideOnResistance has been set up
                {
                    if (targetEO.resistances.HasTypeIDMatch(ResistanceType.NULLIFY_DAMAGE, appearanceI.hideIDList.Distinct()))
                    {
                        appearanceI.TurnOff();
                    }
                }
            }

            limit.ResetTimer();
            lastSource = lastSourceEO;
            target     = targetEO;

            if (similarity == Similarity.SELECTIVE)
            {
                uniqueID = selectiveDescription;
            }
            if (similarity == Similarity.UNIQUE)
            {
                uniqueID    = GetInstanceID().ToString();
                firstSource = lastSourceEO;
            }
        }
Exemplo n.º 7
0
 private void SetAppearance(AppearanceInfo info)
 {
     hairRenderer.sprite = info.HairSprite;
     faceRenderer.sprite = info.FaceSprite;
     bodyRenderer.sprite = info.BodySprite;
 }
Exemplo n.º 8
0
        public void LoadAppearanceFromNotecard(Notecard nc)
        {
            AppearanceInfo appearance = AppearanceInfo.FromNotecard(nc);

            InventoryService.CheckInventory(ID);
            InventoryService.Folder.Purge(InventoryService.Folder[ID, AssetType.CurrentOutfitFolder].ID);

            UUID bodypartsFolder     = InventoryService.Folder[ID, AssetType.Bodypart].ID;
            UUID clothingFolder      = InventoryService.Folder[ID, AssetType.Clothing].ID;
            UUID objectFolder        = InventoryService.Folder[ID, AssetType.Object].ID;
            UUID currentOutfitFolder = InventoryService.Folder[ID, AssetType.CurrentOutfitFolder].ID;
            var  attachmentsToRez    = new List <InventoryItem>();

            /* generate inventory entries for wearables */
            foreach (KeyValuePair <WearableType, List <AgentWearables.WearableInfo> > kvp in appearance.Wearables.All)
            {
                UUID targetFolder = clothingFolder;
                var  assetType    = AssetType.Clothing;
                switch (kvp.Key)
                {
                case WearableType.Shape:
                case WearableType.Skin:
                case WearableType.Hair:
                case WearableType.Eyes:
                case WearableType.Physics:
                    targetFolder = bodypartsFolder;
                    assetType    = AssetType.Bodypart;
                    break;
                }

                int layer = 0;
                foreach (AgentWearables.WearableInfo wInfo in kvp.Value)
                {
                    var item = new InventoryItem(wInfo.ItemID)
                    {
                        AssetID        = wInfo.AssetID,
                        LastOwner      = Owner,
                        Owner          = Owner,
                        Creator        = UGUI.Unknown,
                        InventoryType  = InventoryType.Wearable,
                        AssetType      = assetType,
                        Flags          = (InventoryFlags)(uint)kvp.Key,
                        Name           = wInfo.ItemID.ToString(),
                        ParentFolderID = targetFolder
                    };
                    item.Permissions.Base      = InventoryPermissionsMask.None;
                    item.Permissions.Current   = InventoryPermissionsMask.None;
                    item.Permissions.EveryOne  = InventoryPermissionsMask.None;
                    item.Permissions.Group     = InventoryPermissionsMask.None;
                    item.Permissions.NextOwner = InventoryPermissionsMask.None;
                    try
                    {
                        InventoryService.Item.Add(item);
                    }
                    catch
                    {
                        InventoryService.Item.Update(item);
                    }

                    item = new InventoryItem
                    {
                        LastOwner      = Owner,
                        Owner          = Owner,
                        Creator        = Owner,
                        InventoryType  = InventoryType.Wearable,
                        AssetType      = AssetType.Link,
                        AssetID        = wInfo.ItemID,
                        ParentFolderID = currentOutfitFolder,
                        Name           = wInfo.AssetID.ToString(),
                        Description    = "@" + layer.ToString()
                    };
                    item.Permissions.Base      = InventoryPermissionsMask.All;
                    item.Permissions.Current   = InventoryPermissionsMask.All;
                    item.Permissions.EveryOne  = InventoryPermissionsMask.None;
                    item.Permissions.Group     = InventoryPermissionsMask.None;
                    item.Permissions.NextOwner = InventoryPermissionsMask.None;
                    InventoryService.Item.Add(item);
                    ++layer;
                }
            }

            /* generate inventory entries for attachments */
            foreach (KeyValuePair <AttachmentPoint, RwLockedDictionary <UUID, UUID> > kvp in appearance.Attachments)
            {
                foreach (KeyValuePair <UUID, UUID> kvpInner in kvp.Value)
                {
                    var item = new InventoryItem(kvpInner.Key)
                    {
                        AssetID        = kvpInner.Value,
                        LastOwner      = Owner,
                        Owner          = Owner,
                        Creator        = UGUI.Unknown,
                        ParentFolderID = objectFolder,
                        InventoryType  = InventoryType.Object,
                        AssetType      = AssetType.Object,
                        Flags          = (InventoryFlags)(uint)kvp.Key,
                        Name           = kvpInner.Key.ToString()
                    };
                    item.Permissions.Base      = InventoryPermissionsMask.None;
                    item.Permissions.Current   = InventoryPermissionsMask.None;
                    item.Permissions.EveryOne  = InventoryPermissionsMask.None;
                    item.Permissions.Group     = InventoryPermissionsMask.None;
                    item.Permissions.NextOwner = InventoryPermissionsMask.None;
                    try
                    {
                        InventoryService.Item.Add(item);
                    }
                    catch
                    {
                        InventoryService.Item.Update(item);
                    }
                    attachmentsToRez.Add(item);
                }
            }

            DetachAllAttachments();

            foreach (InventoryItem item in attachmentsToRez)
            {
                AssetData data;
                try
                {
                    data = AssetService[item.AssetID];
                }
                catch (Exception e)
                {
                    m_Log.WarnFormat("Fetch error for object asset {0} for NPC {1} {2} ({3}): {4}: {5}",
                                     item.AssetID, NamedOwner.FirstName, NamedOwner.LastName, NamedOwner.ID, e.GetType().FullName, e.ToString());
                    break;
                }

                if (data.Type != AssetType.Object)
                {
                    m_Log.WarnFormat("Wrong asset for object asset {0} for NPC {1} {2} ({3})",
                                     item.AssetID, NamedOwner.FirstName, NamedOwner.LastName, NamedOwner.ID);
                    break;
                }

                AttachFromInventory(data, item.ID);
            }

            try
            {
                RebakeAppearance();
            }
            catch
            {
                m_Log.WarnFormat("Failed to rebake NPC {0} {1} ({2})",
                                 NamedOwner.FirstName, NamedOwner.LastName, NamedOwner.ID);
            }
        }
Exemplo n.º 9
0
        public bool Run()
        {
            InventoryFolder rootFolder;

            SceneInterface.ResourceAssetService resourceAssets = new SceneInterface.ResourceAssetService();

            m_Log.Info("Loading all default assets");
            /* copy all default assets */
            foreach (UUID id in resourceAssets.GetKnownAssets())
            {
                m_AssetService.Store(resourceAssets[id]);
            }

            if (!m_InventoryService.Folder.TryGetValue(m_AgentOwner.ID, AssetType.RootFolder, out rootFolder))
            {
                rootFolder = new InventoryFolder(m_RootFolderID)
                {
                    Owner          = m_AgentOwner,
                    Name           = "My Inventory",
                    DefaultType    = AssetType.RootFolder,
                    ParentFolderID = UUID.Zero,
                    Version        = 1
                };
                m_InventoryService.Folder.Add(rootFolder);
            }

            UUID rootFolderID = m_InventoryService.Folder[m_AgentOwner.ID, AssetType.RootFolder].ID;

            foreach (KeyValuePair <UUID, string> kvp in m_AssetFiles)
            {
                AssetData asset = new AssetData
                {
                    ID       = kvp.Key,
                    FileName = Path.GetFileName(kvp.Value)
                };
                using (var fs = new FileStream(kvp.Value, FileMode.Open, FileAccess.Read))
                {
                    asset.Data = fs.ReadToStreamEnd();
                }
                m_AssetService.Store(asset);
            }

            foreach (KeyValuePair <UUID, string> kvp in m_InventoryFolders)
            {
                var       folder = new InventoryFolder(kvp.Key);
                AssetType folderType;
                if (m_InventoryFolderTypes.TryGetValue(kvp.Key, out folderType))
                {
                    folder.DefaultType = folderType;
                }

                UUID parentFolderID;
                if (m_InventoryFolderParents.TryGetValue(kvp.Key, out parentFolderID))
                {
                    folder.ParentFolderID = parentFolderID;
                }
                else
                {
                    folder.ParentFolderID = rootFolderID;
                }

                folder.Owner = m_AgentOwner;
                folder.Name  = kvp.Value;
                m_InventoryService.Folder.Add(folder);
            }

            foreach (KeyValuePair <UUID, string> kvp in m_InventoryFiles)
            {
                InventoryItem item;
                using (var fs = new FileStream(kvp.Value, FileMode.Open, FileAccess.Read))
                {
                    item = LoadInventoryItem(fs);
                }
                item.SetNewID(kvp.Key);

                UUID parentFolderID;
                if (m_InventoryItemParents.TryGetValue(kvp.Key, out parentFolderID))
                {
                    item.ParentFolderID = parentFolderID;
                }
                else
                {
                    item.ParentFolderID = rootFolderID;
                }
                UUID assetid;
                if (m_InventoryItemAssetIDs.TryGetValue(kvp.Key, out assetid))
                {
                    item.AssetID = assetid;
                }
                string linkDescription;
                if (m_AssetLinkDescriptions.TryGetValue(kvp.Key, out linkDescription))
                {
                    item.Description = linkDescription;
                    item.AssetType   = AssetType.Link;
                }
                item.Owner = m_AgentOwner;
                m_InventoryService.Item.Add(item);
            }

            AppearanceInfo appearance  = RunBake();
            UUID           bakeEyesId  = appearance.AvatarTextures[(int)AvatarTextureIndex.EyesBaked];
            UUID           bakeHeadId  = appearance.AvatarTextures[(int)AvatarTextureIndex.HeadBaked];
            UUID           bakeUpperId = appearance.AvatarTextures[(int)AvatarTextureIndex.UpperBaked];
            UUID           bakeLowerId = appearance.AvatarTextures[(int)AvatarTextureIndex.LowerBaked];
            UUID           bakeHairId  = appearance.AvatarTextures[(int)AvatarTextureIndex.HairBaked];
            UUID           bakeSkirtId = appearance.AvatarTextures[(int)AvatarTextureIndex.SkirtBaked];

            if (!string.IsNullOrEmpty(m_BakeEyesFilename))
            {
                using (var fs = new FileStream(m_BakeEyesFilename, FileMode.Create, FileAccess.Write))
                {
                    m_AssetService.Data[bakeEyesId].CopyTo(fs);
                }
            }
            if (!string.IsNullOrEmpty(m_BakeHeadFilename))
            {
                using (var fs = new FileStream(m_BakeHeadFilename, FileMode.Create, FileAccess.Write))
                {
                    m_AssetService.Data[bakeHeadId].CopyTo(fs);
                }
            }
            if (!string.IsNullOrEmpty(m_BakeUpperFilename))
            {
                using (var fs = new FileStream(m_BakeUpperFilename, FileMode.Create, FileAccess.Write))
                {
                    m_AssetService.Data[bakeUpperId].CopyTo(fs);
                }
            }
            if (!string.IsNullOrEmpty(m_BakeLowerFilename))
            {
                using (var fs = new FileStream(m_BakeLowerFilename, FileMode.Create, FileAccess.Write))
                {
                    m_AssetService.Data[bakeLowerId].CopyTo(fs);
                }
            }
            if (!string.IsNullOrEmpty(m_BakeHairFilename))
            {
                using (var fs = new FileStream(m_BakeHairFilename, FileMode.Create, FileAccess.Write))
                {
                    m_AssetService.Data[bakeHairId].CopyTo(fs);
                }
            }
            if (!string.IsNullOrEmpty(m_BakeSkirtFilename))
            {
                using (var fs = new FileStream(m_BakeSkirtFilename, FileMode.Create, FileAccess.Write))
                {
                    m_AssetService.Data[bakeSkirtId].CopyTo(fs);
                }
            }

            bool referenceok = true;

            if (!string.IsNullOrEmpty(m_ReferenceBakeEyesFilename))
            {
                double actTolerance = CompareImages(m_AssetService[bakeEyesId], m_ReferenceBakeHairFilename);
                if (actTolerance > m_ReferenceBakeEyesTolerance)
                {
                    referenceok = false;
                    m_Log.ErrorFormat("Eyes reference bake tolerance exceeded {0} > {1}", actTolerance, m_ReferenceBakeHairTolerance);
                }
            }
            if (!string.IsNullOrEmpty(m_ReferenceBakeHeadFilename))
            {
                double actTolerance = CompareImages(m_AssetService[bakeHeadId], m_ReferenceBakeHeadFilename);
                if (actTolerance > m_ReferenceBakeHeadTolerance)
                {
                    referenceok = false;
                    m_Log.ErrorFormat("Head reference bake tolerance exceeded {0} > {1}", actTolerance, m_ReferenceBakeHeadTolerance);
                }
            }
            if (!string.IsNullOrEmpty(m_ReferenceBakeUpperFilename))
            {
                double actTolerance = CompareImages(m_AssetService[bakeEyesId], m_ReferenceBakeUpperFilename);
                if (actTolerance > m_ReferenceBakeUpperTolerance)
                {
                    referenceok = false;
                    m_Log.ErrorFormat("Upper reference bake tolerance exceeded {0} > {1}", actTolerance, m_ReferenceBakeUpperTolerance);
                }
            }
            if (!string.IsNullOrEmpty(m_ReferenceBakeLowerFilename))
            {
                double actTolerance = CompareImages(m_AssetService[bakeEyesId], m_ReferenceBakeLowerFilename);
                if (actTolerance > m_ReferenceBakeLowerTolerance)
                {
                    referenceok = false;
                    m_Log.ErrorFormat("Lower reference bake tolerance exceeded {0} > {1}", actTolerance, m_ReferenceBakeLowerTolerance);
                }
            }
            if (!string.IsNullOrEmpty(m_ReferenceBakeHairFilename))
            {
                double actTolerance = CompareImages(m_AssetService[bakeEyesId], m_ReferenceBakeHairFilename);
                if (actTolerance > m_ReferenceBakeHairTolerance)
                {
                    referenceok = false;
                    m_Log.ErrorFormat("Hair reference bake tolerance exceeded {0} > {1}", actTolerance, m_ReferenceBakeHairTolerance);
                }
            }
            if (!string.IsNullOrEmpty(m_ReferenceBakeSkirtFilename))
            {
                double actTolerance = CompareImages(m_AssetService[bakeEyesId], m_ReferenceBakeSkirtFilename);
                if (actTolerance > m_ReferenceBakeSkirtTolerance)
                {
                    referenceok = false;
                    m_Log.ErrorFormat("Skirt reference bake tolerance exceeded {0} > {1}", actTolerance, m_ReferenceBakeSkirtTolerance);
                }
            }

            foreach (KeyValuePair <AvatarTextureIndex, UUID> kvp in m_ExpectedTextureIDs)
            {
                UUID actId = appearance.AvatarTextures[(int)kvp.Key];
                if (actId != kvp.Value)
                {
                    m_Log.ErrorFormat("Unexpected texture at {0}: act={1} exp={2}", kvp.Key.ToString(), actId, kvp.Value);
                    referenceok = false;
                }
            }

            if (m_ReferenceVisualParams != null)
            {
                if (m_ReferenceVisualParams.Length != appearance.VisualParams.Length)
                {
                    m_Log.ErrorFormat("Length of visual params not identical (ref {0} != act {1})", m_ReferenceVisualParams.Length, appearance.VisualParams.Length);
                    referenceok = false;
                }

                int minLength = Math.Min(m_ReferenceVisualParams.Length, appearance.VisualParams.Length);
                var sb        = new StringBuilder();
                for (int i = 0; i < minLength; ++i)
                {
                    if (m_ReferenceVisualParams[i] != appearance.VisualParams[i])
                    {
                        if (sb.Length == 0)
                        {
                            sb.Append("Data mismatch!\n");
                        }
                        sb.AppendFormat("vp index {0}: ref {1} != act {2}\n", i, m_ReferenceVisualParams[i], appearance.VisualParams[i]);
                        referenceok = false;
                    }
                }

                if (sb.Length != 0)
                {
                    m_Log.Error(sb.ToString());
                }
            }

            return(referenceok);
        }
Exemplo n.º 10
0
        public AppearanceInfo Bake(AssetServiceInterface destService, Action <string> logOutput = null)
        {
            BakeOutput bakes;

            using (var proc = new BakeProcessor())
            {
                bakes = proc.Process(this, AssetService, logOutput);
            }

            logOutput?.Invoke("Store assets");
            destService.Store(bakes.EyeBake);
            destService.Store(bakes.HeadBake);
            destService.Store(bakes.UpperBake);
            destService.Store(bakes.LowerBake);
            destService.Store(bakes.HairBake);

            AvatarTextures[(int)AvatarTextureIndex.EyesBaked]  = bakes.EyeBake.ID;
            AvatarTextures[(int)AvatarTextureIndex.HairBaked]  = bakes.HairBake.ID;
            AvatarTextures[(int)AvatarTextureIndex.UpperBaked] = bakes.UpperBake.ID;
            AvatarTextures[(int)AvatarTextureIndex.LowerBaked] = bakes.LowerBake.ID;
            AvatarTextures[(int)AvatarTextureIndex.HeadBaked]  = bakes.HeadBake.ID;

            if (bakes.SkirtBake != null)
            {
                destService.Store(bakes.SkirtBake);
                AvatarTextures[(int)AvatarTextureIndex.SkirtBaked] = bakes.SkirtBake.ID;
            }
            else
            {
                AvatarTextures[(int)AvatarTextureIndex.SkirtBaked] = AppearanceInfo.AvatarTextureData.DefaultAvatarTextureID;
            }

            if (bakes.LeftArmBake != null)
            {
                destService.Store(bakes.LeftArmBake);
                AvatarTextures[(int)AvatarTextureIndex.LeftArmBaked] = bakes.LeftArmBake.ID;
            }
            else
            {
                AvatarTextures[(int)AvatarTextureIndex.LeftArmBaked] = AppearanceInfo.AvatarTextureData.DefaultAvatarTextureID;
            }

            if (bakes.LeftLegBake != null)
            {
                destService.Store(bakes.LeftLegBake);
                AvatarTextures[(int)AvatarTextureIndex.LeftLegBaked] = bakes.LeftLegBake.ID;
            }
            else
            {
                AvatarTextures[(int)AvatarTextureIndex.LeftLegBaked] = AppearanceInfo.AvatarTextureData.DefaultAvatarTextureID;
            }

            if (bakes.Aux1Bake != null)
            {
                destService.Store(bakes.Aux1Bake);
                AvatarTextures[(int)AvatarTextureIndex.Aux1Baked] = bakes.Aux1Bake.ID;
            }
            else
            {
                AvatarTextures[(int)AvatarTextureIndex.Aux1Baked] = AppearanceInfo.AvatarTextureData.DefaultAvatarTextureID;
            }

            if (bakes.Aux2Bake != null)
            {
                destService.Store(bakes.Aux2Bake);
                AvatarTextures[(int)AvatarTextureIndex.Aux2Baked] = bakes.Aux2Bake.ID;
            }
            else
            {
                AvatarTextures[(int)AvatarTextureIndex.Aux2Baked] = AppearanceInfo.AvatarTextureData.DefaultAvatarTextureID;
            }

            if (bakes.Aux3Bake != null)
            {
                destService.Store(bakes.Aux3Bake);
                AvatarTextures[(int)AvatarTextureIndex.Aux3Baked] = bakes.Aux3Bake.ID;
            }
            else
            {
                AvatarTextures[(int)AvatarTextureIndex.Aux3Baked] = AppearanceInfo.AvatarTextureData.DefaultAvatarTextureID;
            }

            var info = new AppearanceInfo
            {
                Serial       = AppearanceSerial,
                VisualParams = bakes.VisualParams,
                AvatarHeight = bakes.AvatarHeight
            };

            info.AvatarTextures.All = AvatarTextures;
            info.Wearables.All      = AvatarWearables;
            return(info);
        }
Exemplo n.º 11
0
        private void PostAgent_Local(UserAccount account, ClientInfo clientInfo, SessionInfo sessionInfo, DestinationInfo destinationInfo, CircuitInfo circuitInfo, AppearanceInfo appearance, UUID capsId, int maxAllowedWearables, out string capsPath)
        {
            SceneInterface scene;

            if (!m_Scenes.TryGetValue(destinationInfo.ID, out scene))
            {
                throw new LoginFailedException(string.Format("No destination for agent {0}", account.Principal.FullName));
            }

            /* We have established trust of home grid by verifying its agent.
             * At least agent and grid belong together.
             *
             * Now, we can validate the access of the agent.
             */
            var ad = new AuthorizationServiceInterface.AuthorizationData
            {
                ClientInfo      = clientInfo,
                SessionInfo     = sessionInfo,
                AccountInfo     = account,
                DestinationInfo = destinationInfo,
                AppearanceInfo  = appearance
            };

            foreach (AuthorizationServiceInterface authService in m_AuthorizationServices)
            {
                authService.Authorize(ad);
            }

            try
            {
                IAgent sceneAgent = scene.Agents[account.Principal.ID];
                if (sceneAgent.Owner.EqualsGrid(account.Principal))
                {
                    if (circuitInfo.IsChild && !sceneAgent.IsInScene(scene))
                    {
                        /* already got an agent here */
                        m_Log.WarnFormat("Failed to create agent due to duplicate agent id. {0} != {1}", sceneAgent.Owner.ToString(), account.Principal.ToString());
                        throw new LoginFailedException("Failed to create agent due to duplicate agent id");
                    }
                    else if (!circuitInfo.IsChild && !sceneAgent.IsInScene(scene))
                    {
                        /* child becomes root */
                        throw new LoginFailedException("Teleport destination not yet implemented");
                    }
                }
                else if (sceneAgent.Owner.ID == account.Principal.ID)
                {
                    /* we got an agent already and no grid match? */
                    m_Log.WarnFormat("Failed to create agent due to duplicate agent id. {0} != {1}", sceneAgent.Owner.ToString(), account.Principal.ToString());
                    throw new LoginFailedException("Failed to create agent due to duplicate agent id");
                }
            }
            catch
            {
                /* no action needed */
            }

            GridServiceInterface gridService = scene.GridService;

            var serviceList = new AgentServiceList
            {
                m_LocalAssetService,
                m_LocalInventoryService
            };

            if (m_LocalGroupsService != null)
            {
                serviceList.Add(m_LocalGroupsService);
            }
            if (m_LocalExperienceService != null)
            {
                serviceList.Add(m_LocalExperienceService);
            }
            if (m_LocalProfileService != null)
            {
                serviceList.Add(m_LocalProfileService);
            }
            serviceList.Add(m_LocalFriendsService);
            serviceList.Add(new StandalonePresenceService(m_LocalUserAccountService, account.Principal, m_LocalUserSessionService, sessionInfo.SessionID, m_UserSessionStatusServices));
            serviceList.Add(gridService);
            serviceList.Add(m_LocalOfflineIMService);
            if (m_LocalEconomyService != null)
            {
                serviceList.Add(m_LocalEconomyService);
            }
            foreach (ITeleportHandlerFactoryServiceInterface factory in m_TeleportProtocols)
            {
                serviceList.Add(factory.Instantiate(m_CommandRegistry, m_CapsRedirector, m_PacketHandlerPlugins, m_Scenes));
            }

            var agent = new ViewerAgent(
                m_Scenes,
                account.Principal.ID,
                account.Principal.FirstName,
                account.Principal.LastName,
                account.Principal.HomeURI,
                sessionInfo.SessionID,
                sessionInfo.SecureSessionID,
                clientInfo,
                account,
                serviceList)
            {
                ServiceURLs = account.ServiceURLs,

                Appearance = appearance
            };

            try
            {
                scene.DetermineInitialAgentLocation(agent, destinationInfo.TeleportFlags, destinationInfo.Location, destinationInfo.LookAt);
            }
            catch (Exception e)
            {
                m_Log.InfoFormat("Failed to determine initial location for agent {0}: {1}: {2}", account.Principal.FullName, e.GetType().FullName, e.Message);
#if DEBUG
                m_Log.Debug("Exception", e);
#endif
                throw new LoginFailedException(e.Message);
            }

            var udpServer = (UDPCircuitsManager)scene.UDPServer;

            IPAddress ipAddr;
            if (!IPAddress.TryParse(clientInfo.ClientIP, out ipAddr))
            {
                m_Log.InfoFormat("Invalid IP address for agent {0}", account.Principal.FullName);
                throw new LoginFailedException("Invalid IP address");
            }
            var ep      = new IPEndPoint(ipAddr, 0);
            var circuit = new AgentCircuit(
                Commands,
                agent,
                udpServer,
                circuitInfo.CircuitCode,
                m_CapsRedirector,
                circuitInfo.CapsPath,
                agent.ServiceURLs,
                m_GatekeeperURI,
                m_PacketHandlerPlugins,
                ep)
            {
                LastTeleportFlags = destinationInfo.TeleportFlags,
                Agent             = agent,
                AgentID           = account.Principal.ID,
                SessionID         = sessionInfo.SessionID
            };
            agent.Circuits.Add(circuit.Scene.ID, circuit);

            try
            {
                scene.Add(agent);
                try
                {
                    udpServer.AddCircuit(circuit);
                }
                catch
                {
                    scene.Remove(agent);
                    throw;
                }
            }
            catch (Exception e)
            {
                m_Log.Debug("Failed agent post", e);
                agent.Circuits.Clear();
                throw new LoginFailedException(e.Message);
            }

            try
            {
                agent.EconomyService?.Login(destinationInfo.ID, account.Principal, sessionInfo.SessionID, sessionInfo.SecureSessionID);
            }
            catch (Exception e)
            {
                m_Log.Warn("Could not contact EconomyService", e);
            }

            if (!circuitInfo.IsChild)
            {
                /* make agent a root agent */
                agent.SceneID = scene.ID;
                try
                {
                    m_LocalUserAccountService.SetPosition(account.Principal.ID, new UserRegionData
                    {
                        RegionID      = scene.ID,
                        Position      = agent.GlobalPosition,
                        LookAt        = agent.LookAt,
                        GatekeeperURI = new URI(scene.GatekeeperURI)
                    });
                }
                catch (Exception e)
                {
                    m_Log.Warn("Could not contact UserAccountService", e);
                }
            }

            try
            {
                m_LocalUserSessionService[agent.SessionID, KnownUserSessionInfoVariables.LocationRegionID] = scene.ID.ToString();
            }
            catch (Exception e)
            {
                m_Log.Warn("Could not contact PresenceService", e);
            }
            circuit.LogIncomingAgent(m_Log, circuitInfo.IsChild);
            capsPath = m_CapsRedirector.NewCapsURL(circuitInfo.CapsPath);
        }
Exemplo n.º 12
0
        public void LoginTo(UserAccount account, ClientInfo clientInfo, SessionInfo sessionInfo, DestinationInfo destinationInfo, CircuitInfo circuitInfo, AppearanceInfo appearance, TeleportFlags flags, out string seedCapsURI)
        {
            if (!destinationInfo.LocalToGrid)
            {
                throw new NotSupportedException("Remote login not supported");
            }

            string lastMessage = string.Empty;

            if (destinationInfo.ID != UUID.Zero)
            {
                /* try specified destination first */
                destinationInfo.TeleportFlags = flags | TeleportFlags.ViaLogin;
                try
                {
                    QueryAccess(destinationInfo, account, destinationInfo.Position);
                    PostAgent_Local(account, clientInfo, sessionInfo, destinationInfo, circuitInfo, appearance, UUID.Random, (int)WearableType.NumWearables, out seedCapsURI);
                    return;
                }
                catch (Exception e)
                {
                    m_Log.Debug(string.Format("Failed to login {0} {1} to original destination {2} ({3})", account.Principal.FirstName, account.Principal.LastName, destinationInfo.Name, destinationInfo.ID), e);
                    lastMessage = e.Message;
                }
            }

            foreach (RegionInfo fallbackRegion in m_GridService.GetFallbackRegions())
            {
                destinationInfo.UpdateFromRegion(fallbackRegion);
                destinationInfo.StartLocation = "safe";
                destinationInfo.Position      = new Vector3(128, 128, 23);
                destinationInfo.LookAt        = Vector3.UnitX;
                destinationInfo.TeleportFlags = flags | TeleportFlags.ViaRegionID;

                try
                {
                    QueryAccess(destinationInfo, account, destinationInfo.Position);
                    PostAgent_Local(account, clientInfo, sessionInfo, destinationInfo, circuitInfo, appearance, UUID.Random, (int)WearableType.NumWearables, out seedCapsURI);
                    return;
                }
                catch (Exception e)
                {
                    m_Log.Debug(string.Format("Failed to login {0} {1} to fallback destination {2} ({3})", account.Principal.FirstName, account.Principal.LastName, destinationInfo.Name, destinationInfo.ID), e);
                    if (string.IsNullOrEmpty(lastMessage))
                    {
                        lastMessage = e.Message;
                    }
                }
            }
            throw new LoginFailedException("No suitable destination found");
        }