Exemplo n.º 1
0
        public static ScriptInstance Load(ObjectPart part, ObjectPartInventoryItem item, UGUI user, AssetData data, CultureInfo currentCulture, byte[] serializedState = null, Func <string, TextReader> openInclude = null)
        {
            return(m_CompilerLock.AcquireReaderLock(() =>
            {
                IScriptAssembly assembly = m_LoadedAssemblies.GetOrAddIfNotExists(data.ID, () =>
                {
                    using (var reader = new StreamReader(data.InputStream))
                    {
                        return CompilerRegistry.ScriptCompilers.Compile(AppDomain.CurrentDomain, user, data.ID, reader, currentCulture, openInclude);
                    }
                });

                ScriptInstance instance = assembly.Instantiate(part, item, serializedState);
                m_LoadedInstances.GetOrAddIfNotExists(data.ID, () => new RwLockedList <ScriptInstance>()).Add(instance);
                return instance;
            }));
        }
Exemplo n.º 2
0
        public bool Run()
        {
            m_Log.InfoFormat("Testing Execution of {1} ({0})", m_AssetID, m_ScriptFile);
            IScriptAssembly scriptAssembly = null;

            try
            {
                using (var reader = new StreamReader(m_ScriptFile, new UTF8Encoding(false)))
                {
                    scriptAssembly = CompilerRegistry.ScriptCompilers.Compile(AppDomain.CurrentDomain, UGUI.Unknown, m_AssetID, reader, includeOpen: OpenFile);
                }
                m_Log.InfoFormat("Compilation of {1} ({0}) successful", m_AssetID, m_ScriptFile);
            }
            catch (CompilerException e)
            {
                m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", m_AssetID, m_ScriptFile, e.Message);
                m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                return(false);
            }
            catch (Exception e)
            {
                m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", m_AssetID, m_ScriptFile, e.Message);
                m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                return(false);
            }

            RegionInfo rInfo;

            try
            {
                var estate = new EstateInfo
                {
                    ParentEstateID = 1,
                    ID             = m_EstateID,
                    Owner          = m_EstateOwner,
                    Name           = m_EstateName
                };
                m_EstateService.Add(estate);
                m_EstateService.RegionMap[m_RegionID] = m_EstateID;

                rInfo = new RegionInfo
                {
                    Name        = m_RegionName,
                    ID          = m_RegionID,
                    Location    = m_RegionLocation,
                    Size        = m_RegionSize,
                    ProductName = m_ProductName,
                    ServerPort  = (uint)m_RegionPort,
                    Owner       = m_RegionOwner,
                    Flags       = RegionFlags.RegionOnline,
                    Access      = m_RegionAccess,
                    GridURI     = m_GatekeeperURI
                };
                m_RegionStorage.RegisterRegion(rInfo);
            }
            catch (Exception e)
            {
                m_Log.Error("Registration of region failed", e);
                return(false);
            }

            SceneInterface scene;

            try
            {
                scene = m_SceneFactory.Instantiate(rInfo);
            }
            catch (Exception e)
            {
                m_Log.ErrorFormat("Running of {1} ({0}) failed: Failed to start region ID {2}: {3}: {4}\n{5}", m_AssetID, m_ScriptFile, m_RegionID, e.GetType().FullName, e.Message, e.StackTrace);
                return(false);
            }

            try
            {
                m_Scenes.Add(scene);
                scene.LoadSceneSync();
            }
            catch (Exception e)
            {
                m_Log.Error("Starting region failed", e);
                return(false);
            }

            try
            {
                ExperienceServiceInterface experienceService = scene.ExperienceService;
                if (experienceService != null)
                {
                    experienceService.Add(new ExperienceInfo
                    {
                        ID         = m_ExperienceID,
                        Creator    = m_ScriptOwner,
                        Owner      = m_ScriptOwner,
                        Properties = ExperiencePropertyFlags.Grid /* make this grid-wide since otherwise we have to configure a lot more */
                    });
                }
                else
                {
                    m_ExperienceID = UEI.Unknown;
                }
            }
            catch (Exception e)
            {
                m_Log.Error("Creating experience failed", e);
                return(false);
            }

            if (!string.IsNullOrEmpty(m_AssetSourcesConfig))
            {
                AddAssets(scene.AssetService);
            }

            if (!string.IsNullOrEmpty(m_ScriptStatesConfig))
            {
                AddScriptStates();
            }

            if (!string.IsNullOrEmpty(m_LoadOarFileName))
            {
                try
                {
                    using (var s = new FileStream(m_LoadOarFileName, FileMode.Open))
                    {
                        OAR.Load(m_Scenes, scene, OAR.LoadOptions.PersistUuids, s);
                    }
                }
                catch (Exception e)
                {
                    m_Log.Error("Loading oar failed", e);
                    return(false);
                }
            }

            m_Runner.OtherThreadResult = false;

            foreach (string additionalObject in m_AdditionalObjectConfigs)
            {
                m_Log.InfoFormat("Adding object from section {0}", additionalObject);
                if (!TryAddAdditionalObject(scene, additionalObject))
                {
                    m_Log.Info("Failed to add object");
                    return(false);
                }
            }

            try
            {
                var grp = new ObjectGroup
                {
                    RezzingObjectID = m_RezzingObjID
                };
                var part = new ObjectPart(m_ObjectID);
                grp.Add(1, part.ID, part);
                part.ObjectGroup    = grp;
                grp.Owner           = m_ObjectOwner;
                grp.LastOwner       = m_ObjectLastOwner;
                part.Creator        = m_ObjectCreator;
                part.Name           = m_ObjectName;
                part.Description    = m_ObjectDescription;
                part.GlobalPosition = m_Position;
                part.GlobalRotation = m_Rotation;
                part.BaseMask       = m_ObjectPermissionsBase;
                part.OwnerMask      = m_ObjectPermissionsOwner;
                part.NextOwnerMask  = m_ObjectPermissionsNext;
                part.EveryoneMask   = m_ObjectPermissionsEveryone;
                part.GroupMask      = m_ObjectPermissionsGroup;

                var item = new ObjectPartInventoryItem(m_ItemID)
                {
                    AssetType     = AssetType.LSLText,
                    AssetID       = m_AssetID,
                    InventoryType = InventoryType.LSL,
                    LastOwner     = m_ScriptLastOwner,
                    Creator       = m_ScriptCreator,
                    Owner         = m_ScriptOwner,
                    Name          = m_ScriptName,
                    Description   = m_ScriptDescription
                };
                item.Permissions.Base      = m_ScriptPermissionsBase;
                item.Permissions.Current   = m_ScriptPermissionsOwner;
                item.Permissions.EveryOne  = m_ScriptPermissionsEveryone;
                item.Permissions.Group     = m_ScriptPermissionsGroup;
                item.Permissions.NextOwner = m_ScriptPermissionsNext;
                item.ExperienceID          = m_ExperienceID;

                scene.Add(grp);

                foreach (string invconfig in m_AdditionalInventoryConfigs)
                {
                    AddAdditionalInventory(part, invconfig);
                }
                ChatServiceInterface chatService = scene.GetService <ChatServiceInterface>();
                if (chatService != null)
                {
                    chatService.AddRegionListener(PUBLIC_CHANNEL, string.Empty, UUID.Zero, "", GetUUID, null, PublicChannelLog);
                    chatService.AddRegionListener(DEBUG_CHANNEL, string.Empty, UUID.Zero, "", GetUUID, null, DebugChannelLog);
                }
                byte[] serializedState;
                m_ScriptStates.TryGetValue(item.ID, out serializedState);
                ScriptInstance scriptInstance = scriptAssembly.Instantiate(part, item, serializedState);
                part.Inventory.Add(item);
                item.ScriptInstance = scriptInstance;
                item.ScriptInstance.Start(m_StartParameter);
                m_Log.Info("Script started");

                if (Debugger.IsAttached)
                {
                    m_RunTimeoutEvent.WaitOne();
                }
                else
                {
                    m_KillTimer = new Timer(KillTimerCbk, null, m_TimeoutMs + 5000, Timeout.Infinite);
                    m_RunTimeoutEvent.WaitOne(m_TimeoutMs);
                }
                return(m_Runner.OtherThreadResult);
            }
            catch (Exception e)
            {
                m_Log.Error("Starting script failed", e);
                return(false);
            }
        }
Exemplo n.º 3
0
        private bool TryAddAdditionalObject(SceneInterface scene, string sectionName)
        {
            IConfig    config         = m_Loader.Config.Configs[sectionName];
            Vector3    position       = Vector3.Parse(config.GetString("Position", m_Position.ToString()));
            Quaternion rotation       = Quaternion.Parse(config.GetString("Rotation", m_Rotation.ToString()));
            UUID       objectid       = UUID.Parse(config.GetString("ID", UUID.Random.ToString()));
            int        scriptPin      = config.GetInt("ScriptAccessPin", 0);
            string     objectName     = config.GetString("ObjectName", sectionName);
            string     scriptName     = config.GetString("ScriptName", "Script");
            string     experienceName = config.GetString("ExperienceName", "My Experience");
            UUID       itemID         = UUID.Parse(config.GetString("ScriptItemID", UUID.Zero.ToString()));
            UUID       rezzingObjID   = UUID.Parse(config.GetString("RezzingObjectID", UUID.Zero.ToString()));
            UEI        experienceID;
            UUID       expID;

            UUID.TryParse(config.GetString("ExperienceID", m_ExperienceID.ToString()), out expID);
            experienceID = new UEI(expID, experienceName, null);

            string objectDescription = config.GetString("ObjectDescription", "");
            string scriptDescription = config.GetString("ScriptDescription", "");

            var objectOwner = new UGUIWithName(config.GetString("ObjectOwner", m_ObjectOwner.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(objectOwner);
            try
            {
                m_UserAccountService.Add(new UserAccount
                {
                    Principal     = objectOwner,
                    IsLocalToGrid = true,
                });
            }
            catch
            {
                /* intentionally ignored */
            }
            var objectCreator = new UGUIWithName(config.GetString("ObjectCreator", m_ObjectCreator.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(objectCreator);
            try
            {
                m_UserAccountService.Add(new UserAccount
                {
                    Principal     = objectCreator,
                    IsLocalToGrid = true,
                });
            }
            catch
            {
                /* intentionally ignored */
            }
            var objectLastOwner = new UGUIWithName(config.GetString("ObjectLastOwner", m_ObjectLastOwner.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(objectLastOwner);
            try
            {
                m_UserAccountService.Add(new UserAccount
                {
                    Principal     = objectLastOwner,
                    IsLocalToGrid = true,
                });
            }
            catch
            {
                /* intentionally ignored */
            }
            var scriptOwner = new UGUIWithName(config.GetString("ScriptOwner", m_ScriptOwner.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(scriptOwner);
            try
            {
                m_UserAccountService.Add(new UserAccount
                {
                    Principal     = scriptOwner,
                    IsLocalToGrid = true,
                });
            }
            catch
            {
                /* intentionally ignored */
            }
            var scriptCreator = new UGUIWithName(config.GetString("ScriptCreator", m_ScriptCreator.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(scriptCreator);
            try
            {
                m_UserAccountService.Add(new UserAccount
                {
                    Principal     = scriptCreator,
                    IsLocalToGrid = true,
                });
            }
            catch
            {
                /* intentionally ignored */
            }
            var scriptLastOwner = new UGUIWithName(config.GetString("ScriptLastOwner", m_ScriptLastOwner.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(scriptLastOwner);
            try
            {
                m_UserAccountService.Add(new UserAccount
                {
                    Principal     = scriptLastOwner,
                    IsLocalToGrid = true,
                });
            }
            catch
            {
                /* intentionally ignored */
            }
            int startParameter = config.GetInt("StartParameter", m_StartParameter);

            InventoryPermissionsMask objectPermissionsBase     = GetPermissions(config, "ObjectPermisionsBase", m_ObjectPermissionsBase);
            InventoryPermissionsMask objectPermissionsOwner    = GetPermissions(config, "ObjectPermisionsOwner", m_ObjectPermissionsOwner);
            InventoryPermissionsMask objectPermissionsGroup    = GetPermissions(config, "ObjectPermisionsGroup", m_ObjectPermissionsGroup);
            InventoryPermissionsMask objectPermissionsNext     = GetPermissions(config, "ObjectPermisionsNext", m_ObjectPermissionsNext);
            InventoryPermissionsMask objectPermissionsEveryone = GetPermissions(config, "ObjectPermisionsEveryone", m_ObjectPermissionsEveryone);

            InventoryPermissionsMask scriptPermissionsBase     = GetPermissions(config, "ScriptPermisionsBase", m_ScriptPermissionsBase);
            InventoryPermissionsMask scriptPermissionsOwner    = GetPermissions(config, "ScriptPermisionsOwner", m_ScriptPermissionsOwner);
            InventoryPermissionsMask scriptPermissionsGroup    = GetPermissions(config, "ScriptPermisionsGroup", m_ScriptPermissionsGroup);
            InventoryPermissionsMask scriptPermissionsNext     = GetPermissions(config, "ScriptPermisionsNext", m_ScriptPermissionsNext);
            InventoryPermissionsMask scriptPermissionsEveryone = GetPermissions(config, "ScriptPermisionsEveryone", m_ScriptPermissionsEveryone);

            UUID   assetID    = UUID.Zero;
            string scriptFile = string.Empty;

            /* we use same asset id keying here so to make them compatible with the other scripts */
            foreach (string key in config.GetKeys())
            {
                if (UUID.TryParse(key, out assetID))
                {
                    scriptFile = config.GetString(key);
                    break;
                }
            }

            IScriptAssembly scriptAssembly = null;

            if (!string.IsNullOrEmpty(scriptFile))
            {
                if (itemID == UUID.Zero)
                {
                    itemID = UUID.Random;
                }
                try
                {
                    using (var reader = new StreamReader(scriptFile, new UTF8Encoding(false)))
                    {
                        scriptAssembly = CompilerRegistry.ScriptCompilers.Compile(AppDomain.CurrentDomain, UGUI.Unknown, m_AssetID, reader);
                    }
                    m_Log.InfoFormat("Compilation of {1} ({0}) successful", m_AssetID, scriptFile);
                }
                catch (CompilerException e)
                {
                    m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", m_AssetID, scriptFile, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace.ToString());
                    return(false);
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", m_AssetID, scriptFile, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace.ToString());
                    return(false);
                }
            }

            try
            {
                ExperienceServiceInterface experienceService = scene.ExperienceService;
                if (null != experienceService)
                {
                    ExperienceInfo test;
                    if (!experienceService.TryGetValue(experienceID, out test))
                    {
                        experienceService.Add(new ExperienceInfo
                        {
                            ID         = experienceID,
                            Creator    = scriptOwner,
                            Owner      = scriptOwner,
                            Properties = ExperiencePropertyFlags.Grid /* make this grid-wide since otherwise we have to configure a lot more */
                        });
                    }
                }
                else
                {
                    experienceID = UEI.Unknown;
                }
            }
            catch (Exception e)
            {
                m_Log.Error("Creating experience failed", e);
                return(false);
            }

            string[] additionalInventoryConfigs = config.GetString("AdditionalInventories", string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (additionalInventoryConfigs.Length == 1 && additionalInventoryConfigs[0] == string.Empty)
            {
                additionalInventoryConfigs = new string[0];
            }

            try
            {
                var grp = new ObjectGroup
                {
                    RezzingObjectID = rezzingObjID
                };
                var part = new ObjectPart(objectid);
                grp.Add(1, part.ID, part);
                part.ObjectGroup     = grp;
                grp.Owner            = objectOwner;
                grp.LastOwner        = objectLastOwner;
                part.Creator         = objectCreator;
                part.Name            = objectName;
                part.Description     = objectDescription;
                part.GlobalPosition  = position;
                part.GlobalRotation  = rotation;
                part.BaseMask        = objectPermissionsBase;
                part.OwnerMask       = objectPermissionsOwner;
                part.NextOwnerMask   = objectPermissionsNext;
                part.EveryoneMask    = objectPermissionsEveryone;
                part.GroupMask       = objectPermissionsGroup;
                part.ScriptAccessPin = scriptPin;

                var item = new ObjectPartInventoryItem(itemID)
                {
                    AssetType     = AssetType.LSLText,
                    AssetID       = assetID,
                    InventoryType = InventoryType.LSL,
                    LastOwner     = scriptLastOwner,
                    Creator       = scriptCreator,
                    Owner         = scriptOwner,
                    Name          = scriptName,
                    Description   = scriptDescription
                };
                item.Permissions.Base      = scriptPermissionsBase;
                item.Permissions.Current   = scriptPermissionsOwner;
                item.Permissions.EveryOne  = scriptPermissionsEveryone;
                item.Permissions.Group     = scriptPermissionsGroup;
                item.Permissions.NextOwner = scriptPermissionsNext;
                item.ExperienceID          = experienceID;

                scene.Add(grp);

                foreach (string invconfig in additionalInventoryConfigs)
                {
                    AddAdditionalInventory(part, invconfig);
                }

                if (scriptAssembly != null)
                {
                    byte[] serializedState;
                    m_ScriptStates.TryGetValue(item.ID, out serializedState);
                    ScriptInstance scriptInstance = scriptAssembly.Instantiate(part, item, serializedState);
                    part.Inventory.Add(item);
                    item.ScriptInstance = scriptInstance;
                    item.ScriptInstance.Start(startParameter);
                }
            }
            catch (Exception e)
            {
                m_Log.Error("Adding object failed", e);
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public int InjectScript(ScriptInstance instance, string name, string filename, int startparameter, LSLKey experienceID)
        {
            lock (instance)
            {
                UUID assetid = UUID.Random;
                ObjectPartInventoryItem item = new ObjectPartInventoryItem(UUID.Random, instance.Item)
                {
                    Name         = name,
                    AssetID      = assetid,
                    ExperienceID = new UEI(experienceID.ToString())
                };

                IScriptAssembly scriptAssembly = null;
                try
                {
                    using (var reader = new StreamReader(filename, new UTF8Encoding(false)))
                    {
                        m_AssetService.Store(new AssetData
                        {
                            ID   = assetid,
                            Type = AssetType.LSLText,
                            Data = reader.ReadToEnd().ToUTF8Bytes()
                        });
                    }
                    using (var reader = new StreamReader(filename, new UTF8Encoding(false)))
                    {
                        scriptAssembly = CompilerRegistry.ScriptCompilers.Compile(AppDomain.CurrentDomain, UGUI.Unknown, assetid, reader, includeOpen: instance.Part.OpenScriptInclude);
                    }
                    m_Log.InfoFormat("Compilation of injected {1} ({0}) successful", assetid, name);
                }
                catch (CompilerException e)
                {
                    m_Log.ErrorFormat("Compilation of injected {1} ({0}) failed: {2}", assetid, name, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                    return(0);
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Compilation of injected {1} ({0}) failed: {2}", assetid, name, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                    return(0);
                }

                ScriptInstance scriptInstance;
                try
                {
                    scriptInstance = scriptAssembly.Instantiate(instance.Part, item);
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Instancing of injected {1} ({0}) failed: {2}", assetid, name, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                    return(0);
                }
                instance.Part.Inventory.Add(item);
                item.ScriptInstance = scriptInstance;
                try
                {
                    item.ScriptInstance.Start(startparameter);
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Starting of injected {1} ({0}) failed: {2}", assetid, name, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                    return(0);
                }
                return(1);
            }
        }