Ejemplo n.º 1
0
        private void RezActualScript(AgentCircuit circuit, ObjectPart part, RezScript req, AssetData data)
        {
            if (!part.CheckPermissions(Owner, Group, InventoryPermissionsMask.Modify))
            {
                var res = new AlertMessage
                {
                    Message = "ALERT: NoPermModifyObject"
                };
                circuit.SendMessage(res);
                return;
            }
            var item = new ObjectPartInventoryItem
            {
                Name           = req.InventoryBlock.Name,
                AssetID        = data.ID,
                Description    = req.InventoryBlock.Description,
                AssetType      = AssetType.LSLText,
                Creator        = Owner,
                Owner          = Owner,
                Flags          = 0,
                Group          = Group,
                IsGroupOwned   = false,
                InventoryType  = InventoryType.LSL,
                LastOwner      = Owner,
                ParentFolderID = part.ID
            };

            item.Permissions.Base      = req.InventoryBlock.BaseMask;
            item.Permissions.Current   = req.InventoryBlock.OwnerMask;
            item.Permissions.EveryOne  = req.InventoryBlock.EveryoneMask;
            item.Permissions.Group     = req.InventoryBlock.GroupMask;
            item.Permissions.NextOwner = req.InventoryBlock.NextOwnerMask;
            item.SaleInfo.Price        = req.InventoryBlock.SalePrice;
            item.SaleInfo.Type         = req.InventoryBlock.SaleType;

            part.Inventory.Add(item);
            part.SendObjectUpdate();

            ScriptInstance instance;

            try
            {
                SceneInterface scene = part.ObjectGroup.Scene;
                instance            = ScriptLoader.Load(part, item, item.Owner, data, CurrentCulture, openInclude: part.OpenScriptInclude);
                item.ScriptInstance = instance;
                item.ScriptInstance.IsRunningAllowed = scene.CanRunScript(item.Owner, part.ObjectGroup.GlobalPosition, item.AssetID);
                item.ScriptInstance.IsRunning        = true;
                item.ScriptInstance.Reset();
                part.ObjectGroup.Scene.SendObjectPropertiesToAgent(this, part);
            }
            catch
            {
                var res = new AlertMessage
                {
                    Message = this.GetLanguageString(circuit.Agent.CurrentCulture, "CouldNotCompileScript", "Could not compile script")
                };
                circuit.SendMessage(res);
                return;
            }
        }
Ejemplo n.º 2
0
 private void AdjustPermissionsAccordingly(IAgent agent, UGUI newOwner, ObjectPartInventoryItem item)
 {
     if (agent.Owner != newOwner && !agent.IsActiveGod)
     {
         item.Permissions.AdjustToNextOwner();
     }
 }
Ejemplo n.º 3
0
        public bool Run()
        {
            m_Log.Info("Create test object");
            var grp  = new ObjectGroup();
            var part = new ObjectPart();

            grp.Add(1, part.ID, part);
            var item = new ObjectPartInventoryItem
            {
                Name = "Test Item"
            };

            if (item.ParentFolderID != UUID.Zero)
            {
                m_Log.Info("Test item cannot have valid PartID yet");
                return(false);
            }
            part.Inventory.Add(item.ID, item.Name, item);
            if (part.Inventory.PartID != part.ID)
            {
                m_Log.Error("part.Inventory.PartID != part.ParentFolderID (A)");
                return(false);
            }
            if (part.Inventory.PartID != item.ParentFolderID)
            {
                m_Log.Error("part.Inventory.PartID != item.ParentFolderID (A)");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public void RemoveObjectBuyListen(ScriptInstance instance)
        {
            ObjectPart part = instance.Part;
            ObjectPartInventoryItem item = instance.Item;

            if (part != null && item != null)
            {
                UUID partID = part.ID;
                UUID itemID = item.ID;
                m_ObjectBuyListeners.Remove(ObjectBuyListen.GetKey(partID, itemID));
            }
        }
Ejemplo n.º 5
0
        private ObjectPartInventoryItem ObjectPartInventoryItemFromDbReader(NpgsqlDataReader dbReader)
        {
            var item = new ObjectPartInventoryItem(dbReader.GetUUID("InventoryID"))
            {
                AssetID          = dbReader.GetUUID("AssetID"),
                AssetType        = dbReader.GetEnum <AssetType>("AssetType"),
                CreationDate     = dbReader.GetDate("CreationDate"),
                Creator          = dbReader.GetUGUI("Creator"),
                Description      = (string)dbReader["Description"],
                Flags            = dbReader.GetEnum <InventoryFlags>("Flags"),
                Group            = dbReader.GetUGI("Group"),
                IsGroupOwned     = (bool)dbReader["GroupOwned"],
                InventoryType    = dbReader.GetEnum <InventoryType>("InventoryType"),
                LastOwner        = dbReader.GetUGUI("LastOwner"),
                Name             = (string)dbReader["Name"],
                Owner            = dbReader.GetUGUI("Owner"),
                ParentFolderID   = dbReader.GetUUID("PrimID"),
                NextOwnerAssetID = dbReader.GetUUID("NextOwnerAssetID"),
                ExperienceID     = dbReader.GetUEI("ExperienceID"),
                CollisionFilter  = new ObjectPartInventoryItem.CollisionFilterParam
                {
                    DbSerialization = dbReader.GetBytes("CollisionFilterData")
                },
            };

            item.Permissions.Base      = dbReader.GetEnum <InventoryPermissionsMask>("BasePermissions");
            item.Permissions.Current   = dbReader.GetEnum <InventoryPermissionsMask>("CurrentPermissions");
            item.Permissions.EveryOne  = dbReader.GetEnum <InventoryPermissionsMask>("EveryOnePermissions");
            item.Permissions.Group     = dbReader.GetEnum <InventoryPermissionsMask>("GroupPermissions");
            item.Permissions.NextOwner = dbReader.GetEnum <InventoryPermissionsMask>("NextOwnerPermissions");
            item.SaleInfo.Type         = dbReader.GetEnum <InventoryItem.SaleInfoData.SaleType>("SaleType");
            item.SaleInfo.Price        = (int)dbReader["SalePrice"];
            item.SaleInfo.PermMask     = dbReader.GetEnum <InventoryPermissionsMask>("SalePermMask");
            var grantinfo = new ObjectPartInventoryItem.PermsGranterInfo();

            if (((string)dbReader["PermsGranter"]).Length != 0)
            {
                try
                {
                    grantinfo.PermsGranter = dbReader.GetUGUI("PermsGranter");
                }
                catch
                {
                    /* no action required */
                }
            }
            grantinfo.PermsMask          = dbReader.GetEnum <ScriptPermissions>("PermsMask");
            grantinfo.DebitPermissionKey = dbReader.GetUUID("DebitPermissionKey");
            item.PermsGranter            = grantinfo;

            return(item);
        }
Ejemplo n.º 6
0
 public AddToObjectTransferItem(
     IAgent agent,
     SceneInterface scene,
     UUID assetid,
     ObjectPart part,
     ObjectPartInventoryItem item)
     : base(scene.AssetService, agent.AssetService, assetid, ReferenceSource.Source)
 {
     m_Part    = part;
     m_Item    = item;
     m_Part    = part;
     m_SceneID = scene.ID;
 }
        private ObjectPartInventoryItem ObjectPartInventoryItemFromMap(Map map)
        {
            var item = new ObjectPartInventoryItem(map["InventoryID"].AsUUID)
            {
                AssetID         = map["AssetID"].AsUUID,
                AssetType       = (AssetType)map["AssetType"].AsInt,
                CreationDate    = (Date)map["CreationDate"],
                Creator         = new UGUI(map["Creator"].ToString()),
                Description     = map["Description"].ToString(),
                Flags           = (InventoryFlags)map["Flags"].AsUInt,
                Group           = new UGI(map["Group"].ToString()),
                IsGroupOwned    = map["GroupOwned"].AsBoolean,
                InventoryType   = (InventoryType)map["InventoryType"].AsInt,
                LastOwner       = new UGUI(map["LastOwner"].ToString()),
                Name            = map["Name"].ToString(),
                Owner           = new UGUI(map["Owner"].ToString()),
                ParentFolderID  = map["ParentFolderID"].AsUUID,
                ExperienceID    = new UEI(map["ExperienceID"].ToString()),
                CollisionFilter = new ObjectPartInventoryItem.CollisionFilterParam
                {
                    DbSerialization = (BinaryData)map["CollisionFilterData"]
                }
            };

            item.Permissions.Base      = (InventoryPermissionsMask)map["BasePermissions"].AsUInt;
            item.Permissions.Current   = (InventoryPermissionsMask)map["CurrentPermissions"].AsUInt;
            item.Permissions.EveryOne  = (InventoryPermissionsMask)map["EveryOnePermissions"].AsUInt;
            item.Permissions.Group     = (InventoryPermissionsMask)map["GroupPermissions"].AsUInt;
            item.Permissions.NextOwner = (InventoryPermissionsMask)map["NextOwnerPermissions"].AsUInt;
            item.SaleInfo.Type         = (InventoryItem.SaleInfoData.SaleType)map["SaleType"].AsUInt;
            item.SaleInfo.Price        = map["SalePrice"].AsInt;
            item.SaleInfo.PermMask     = (InventoryPermissionsMask)map["SalePermMask"].AsInt;
            item.NextOwnerAssetID      = map["NextOwnerAssetID"].AsUUID;
            var grantinfo = new ObjectPartInventoryItem.PermsGranterInfo();

            if ((map["PermsGranter"].ToString()).Length != 0)
            {
                try
                {
                    grantinfo.PermsGranter = new UGUI(map["PermsGranter"].ToString());
                }
                catch
                {
                    /* no action required */
                }
            }
            grantinfo.PermsMask          = (ScriptPermissions)map["PermsMask"].AsUInt;
            grantinfo.DebitPermissionKey = map["DebitPermissionKey"].AsUUID;

            return(item);
        }
Ejemplo n.º 8
0
        public void AddObjectBuyListen(ScriptInstance instance)
        {
            ObjectPart part = instance.Part;
            ObjectPartInventoryItem item = instance.Item;

            if (part != null && item != null)
            {
                var listen = new ObjectBuyListen
                {
                    PrimitiveID = part.ID,
                    ItemID      = item.ID
                };
                m_ObjectBuyListeners.Add(listen.Key, listen);
            }
        }
        private ObjectPartInventoryItem ObjectPartInventoryItemFromDbReader(MySqlDataReader dbReader)
        {
            var item = new ObjectPartInventoryItem(dbReader.GetUUID("InventoryID"))
            {
                AssetID          = dbReader.GetUUID("AssetID"),
                AssetType        = dbReader.GetEnum <AssetType>("AssetType"),
                CreationDate     = dbReader.GetDate("CreationDate"),
                Creator          = dbReader.GetUUI("Creator"),
                Description      = dbReader.GetString("Description"),
                Flags            = dbReader.GetEnum <InventoryFlags>("Flags"),
                Group            = dbReader.GetUGI("Group"),
                IsGroupOwned     = dbReader.GetBool("GroupOwned"),
                InventoryType    = dbReader.GetEnum <InventoryType>("InventoryType"),
                LastOwner        = dbReader.GetUUI("LastOwner"),
                Name             = dbReader.GetString("Name"),
                Owner            = dbReader.GetUUI("Owner"),
                ParentFolderID   = dbReader.GetUUID("PrimID"),
                NextOwnerAssetID = dbReader.GetUUID("NextOwnerAssetID"),
                ExperienceID     = dbReader.GetUUID("ExperienceID")
            };

            item.Permissions.Base      = dbReader.GetEnum <InventoryPermissionsMask>("BasePermissions");
            item.Permissions.Current   = dbReader.GetEnum <InventoryPermissionsMask>("CurrentPermissions");
            item.Permissions.EveryOne  = dbReader.GetEnum <InventoryPermissionsMask>("EveryOnePermissions");
            item.Permissions.Group     = dbReader.GetEnum <InventoryPermissionsMask>("GroupPermissions");
            item.Permissions.NextOwner = dbReader.GetEnum <InventoryPermissionsMask>("NextOwnerPermissions");
            item.SaleInfo.Type         = dbReader.GetEnum <InventoryItem.SaleInfoData.SaleType>("SaleType");
            item.SaleInfo.Price        = dbReader.GetInt32("SalePrice");
            item.SaleInfo.PermMask     = dbReader.GetEnum <InventoryPermissionsMask>("SalePermMask");
            var grantinfo = new ObjectPartInventoryItem.PermsGranterInfo();

            if (((string)dbReader["PermsGranter"]).Length != 0)
            {
                try
                {
                    grantinfo.PermsGranter = dbReader.GetUUI("PermsGranter");
                }
                catch
                {
                    /* no action required */
                }
            }
            grantinfo.PermsMask = dbReader.GetEnum <ScriptPermissions>("PermsMask");

            return(item);
        }
Ejemplo n.º 10
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;
            }));
        }
Ejemplo n.º 11
0
        private void AddAdditionalInventory(ObjectPart part, string sectionName)
        {
            IConfig config  = m_Loader.Config.Configs[sectionName];
            var     creator = new UGUIWithName(config.GetString("Creator", m_ObjectCreator.ToString()))
            {
                IsAuthoritative = true
            };
            var owner = new UGUIWithName(config.GetString("Owner", m_ObjectOwner.ToString()))
            {
                IsAuthoritative = true
            };
            var lastOwner = new UGUIWithName(config.GetString("LastOwner", m_ObjectLastOwner.ToString()))
            {
                IsAuthoritative = true
            };

            m_AvatarNameService.Store(creator);
            m_AvatarNameService.Store(owner);
            m_AvatarNameService.Store(lastOwner);
            var item = new ObjectPartInventoryItem(new UUID(config.GetString("ItemID", UUID.Random.ToString())))
            {
                Name              = config.GetString("Name"),
                Description       = config.GetString("Description", string.Empty),
                AssetID           = new UUID(config.GetString("AssetID", UUID.Random.ToString())),
                AssetTypeName     = config.GetString("AssetType"),
                Creator           = creator,
                Owner             = owner,
                LastOwner         = lastOwner,
                InventoryTypeName = config.GetString("InventoryType"),
                Flags             = (InventoryFlags)config.GetInt("Flags", 0),
                IsGroupOwned      = config.GetBoolean("IsGroupOwned", false)
            };

            item.Permissions.Base      = (InventoryPermissionsMask)config.GetInt("BasePermissions", (int)InventoryPermissionsMask.Every);
            item.Permissions.Current   = (InventoryPermissionsMask)config.GetInt("CurrentPermissions", (int)InventoryPermissionsMask.Every);
            item.Permissions.EveryOne  = (InventoryPermissionsMask)config.GetInt("EveryOnePermissions", (int)InventoryPermissionsMask.Every);
            item.Permissions.Group     = (InventoryPermissionsMask)config.GetInt("GroupPermissions", (int)InventoryPermissionsMask.Every);
            item.Permissions.NextOwner = (InventoryPermissionsMask)config.GetInt("NextOwnerPermissions", (int)InventoryPermissionsMask.Every);

            part.Inventory.Add(item);
        }
            private Map GenerateUpdateObjectPartInventoryItem(UUID primID, ObjectPartInventoryItem item)
            {
                var grantinfo = item.PermsGranter;

                return(new Map
                {
                    { "AssetID", item.AssetID },
                    { "AssetType", (int)item.AssetType },
                    { "CreationDate", item.CreationDate },
                    { "Creator", item.Creator.ToString() },
                    { "Description", item.Description },
                    { "Flags", (int)item.Flags },
                    { "Group", item.Group.ToString() },
                    { "GroupOwned", item.IsGroupOwned },
                    { "PrimID", primID },
                    { "Name", item.Name },
                    { "InventoryID", item.ID },
                    { "InventoryType", (int)item.InventoryType },
                    { "LastOwner", item.LastOwner.ToString() },
                    { "Owner", item.Owner.ToString() },
                    { "ParentFolderID", item.ParentFolderID },
                    { "BasePermissions", (int)item.Permissions.Base },
                    { "CurrentPermissions", (int)item.Permissions.Current },
                    { "EveryOnePermissions", (int)item.Permissions.EveryOne },
                    { "GroupPermissions", (int)item.Permissions.Group },
                    { "NextOwnerPermissions", (int)item.Permissions.NextOwner },
                    { "SaleType", (int)item.SaleInfo.Type },
                    { "SalePrice", item.SaleInfo.Price },
                    { "SalePermMask", (int)item.SaleInfo.PermMask },
                    { "PermsGranter", grantinfo.PermsGranter.ToString() },
                    { "PermsMask", (int)grantinfo.PermsMask },
                    { "DebitPermissionKey", item.PermsGranter.DebitPermissionKey },
                    { "NextOwnerAssetID", item.NextOwnerAssetID },
                    { "ExperienceID", item.ExperienceID.ToString() },
                    { "CollisionFilterData", new BinaryData(item.CollisionFilter.DbSerialization) }
                });
            }
Ejemplo n.º 13
0
 protected ScriptEventInstance(ObjectPart part, ObjectPartInventoryItem item)
 {
     Part = part;
     Item = item;
 }
Ejemplo n.º 14
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);
            }
        }
        List <ObjectGroup> ISimulationDataObjectStorageInterface.this[UUID regionID]
        {
            get
            {
                var objGroups               = new Dictionary <UUID, ObjectGroup>();
                var originalAssetIDs        = new Dictionary <UUID, UUID>();
                var nextOwnerAssetIDs       = new Dictionary <UUID, UUID>();
                var objGroupParts           = new Dictionary <UUID, SortedDictionary <int, ObjectPart> >();
                var objPartIDs              = new List <UUID>();
                var objParts                = new Dictionary <UUID, ObjectPart>();
                var orphanedPrims           = new List <UUID>();
                var orphanedPrimInventories = new List <KeyValuePair <UUID, UUID> >();

                using (var connection = new MySqlConnection(m_ConnectionString))
                {
                    connection.Open();
                    UUID objgroupID = UUID.Zero;
                    m_Log.InfoFormat("Loading object groups for region ID {0}", regionID);

                    using (var cmd = new MySqlCommand("SELECT * FROM objects WHERE RegionID = '" + regionID.ToString() + "'", connection))
                    {
                        cmd.CommandTimeout = 3600;
                        using (MySqlDataReader dbReader = cmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                try
                                {
                                    objgroupID = MySQLUtilities.GetUUID(dbReader, "id");
                                    originalAssetIDs[objgroupID]  = dbReader.GetUUID("OriginalAssetID");
                                    nextOwnerAssetIDs[objgroupID] = dbReader.GetUUID("NextOwnerAssetID");
                                    objGroups[objgroupID]         = ObjectGroupFromDbReader(dbReader);
                                }
                                catch (Exception e)
                                {
                                    m_Log.WarnFormat("Failed to load object {0}: {1}\n{2}", objgroupID, e.Message, e.StackTrace);
                                    objGroups.Remove(objgroupID);
                                }
                            }
                        }
                    }

                    m_Log.InfoFormat("Loading prims for region ID {0}", regionID);
                    int primcount = 0;
                    using (var cmd = new MySqlCommand("SELECT * FROM prims WHERE RegionID = '" + regionID.ToString() + "'", connection))
                    {
                        cmd.CommandTimeout = 3600;
                        using (MySqlDataReader dbReader = cmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                UUID rootPartID = dbReader.GetUUID("RootPartID");
                                if (objGroups.ContainsKey(rootPartID))
                                {
                                    if (!objGroupParts.ContainsKey(rootPartID))
                                    {
                                        objGroupParts.Add(rootPartID, new SortedDictionary <int, ObjectPart>());
                                    }

                                    ObjectPart objpart = ObjectPartFromDbReader(dbReader);

                                    objGroupParts[rootPartID].Add(objpart.LoadedLinkNumber, objpart);
                                    objPartIDs.Add(objpart.ID);
                                    objParts[objpart.ID] = objpart;
                                    if ((++primcount) % 5000 == 0)
                                    {
                                        m_Log.InfoFormat("Loading prims for region ID {0} - {1} loaded", regionID, primcount);
                                    }
                                }
                                else
                                {
                                    m_Log.WarnFormat("deleting orphan prim in region ID {0}: {1}", regionID, dbReader.GetUUID("ID"));
                                    orphanedPrims.Add(dbReader.GetUUID("ID"));
                                }
                            }
                        }
                    }
                    m_Log.InfoFormat("Loaded prims for region ID {0} - {1} loaded", regionID, primcount);

                    int primitemcount = 0;
                    m_Log.InfoFormat("Loading prim inventories for region ID {0}", regionID);
                    using (var cmd = new MySqlCommand("SELECT * FROM primitems WHERE RegionID = '" + regionID.ToString() + "'", connection))
                    {
                        cmd.CommandTimeout = 3600;
                        using (MySqlDataReader dbReader = cmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                UUID       partID = dbReader.GetUUID("PrimID");
                                ObjectPart part;
                                if (objParts.TryGetValue(partID, out part))
                                {
                                    ObjectPartInventoryItem item = ObjectPartInventoryItemFromDbReader(dbReader);

                                    part.Inventory.Add(item.ID, item.Name, item);
                                    if ((++primitemcount) % 5000 == 0)
                                    {
                                        m_Log.InfoFormat("Loading prim inventories for region ID {0} - {1} loaded", regionID, primitemcount);
                                    }
                                }
                                else
                                {
                                    m_Log.WarnFormat("deleting orphan prim inventory in region ID {0}: {1}", regionID, dbReader.GetUUID("InventoryID"));
                                    orphanedPrimInventories.Add(new KeyValuePair <UUID, UUID>(dbReader.GetUUID("PrimID"), dbReader.GetUUID("InventoryID")));
                                }
                            }
                        }
                    }
                    m_Log.InfoFormat("Loaded prim inventories for region ID {0} - {1} loaded", regionID, primitemcount);
                }

                var removeObjGroups = new List <UUID>();
                foreach (KeyValuePair <UUID, ObjectGroup> kvp in objGroups)
                {
                    if (!objGroupParts.ContainsKey(kvp.Key))
                    {
                        removeObjGroups.Add(kvp.Key);
                    }
                    else
                    {
                        foreach (ObjectPart objpart in objGroupParts[kvp.Key].Values)
                        {
                            kvp.Value.Add(objpart.LoadedLinkNumber, objpart.ID, objpart);
                        }

                        try
                        {
                            kvp.Value.OriginalAssetID  = originalAssetIDs[kvp.Value.ID];
                            kvp.Value.NextOwnerAssetID = nextOwnerAssetIDs[kvp.Value.ID];
                            kvp.Value.FinalizeObject();
                        }
                        catch
                        {
                            m_Log.WarnFormat("deleting orphan object in region ID {0}: {1}", regionID, kvp.Key);
                            removeObjGroups.Add(kvp.Key);
                        }
                    }
                }

                foreach (UUID objid in removeObjGroups)
                {
                    objGroups.Remove(objid);
                }

                for (int idx = 0; idx < removeObjGroups.Count; idx += 256)
                {
                    int    elemcnt = Math.Min(removeObjGroups.Count - idx, 256);
                    string sqlcmd  = "DELETE FROM objects WHERE RegionID = '" + regionID.ToString() + "' AND ID IN (" +
                                     string.Join(",", from id in removeObjGroups.GetRange(idx, elemcnt) select "'" + id.ToString() + "'") +
                                     ")";
                    using (var conn = new MySqlConnection(m_ConnectionString))
                    {
                        conn.Open();
                        using (var cmd = new MySqlCommand(sqlcmd, conn))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                }

                for (int idx = 0; idx < orphanedPrims.Count; idx += 256)
                {
                    int    elemcnt = Math.Min(orphanedPrims.Count - idx, 256);
                    string sqlcmd  = "DELETE FROM prims WHERE RegionID = '" + regionID.ToString() + "' AND ID IN (" +
                                     string.Join(",", from id in orphanedPrims.GetRange(idx, elemcnt) select "'" + id.ToString() + "'") +
                                     ")";
                    using (var conn = new MySqlConnection(m_ConnectionString))
                    {
                        conn.Open();
                        using (var cmd = new MySqlCommand(sqlcmd, conn))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                for (int idx = 0; idx < orphanedPrimInventories.Count; idx += 256)
                {
                    int    elemcnt = Math.Min(orphanedPrimInventories.Count - idx, 256);
                    string sqlcmd  = "DELETE FROM primitems WHERE RegionID = '" + regionID.ToString() + "' AND (" +
                                     string.Join(" OR ", from id in orphanedPrimInventories.GetRange(idx, elemcnt) select
                                                 string.Format("(PrimID = '{0}' AND InventoryID = '{1}')", id.Key.ToString(), id.Value.ToString())) + ")";
                    using (var conn = new MySqlConnection(m_ConnectionString))
                    {
                        conn.Open();
                        using (var cmd = new MySqlCommand(sqlcmd, conn))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                }

                return(new List <ObjectGroup>(objGroups.Values));
            }
        }
        public void HandleObjectDuplicate(Message m)
        {
            var req = (Viewer.Messages.Object.ObjectDuplicate)m;

            if (req.AgentID != m.CircuitAgentID ||
                req.SessionID != m.CircuitSessionID)
            {
                return;
            }

            IAgent agent;
            var    objectgroups = new List <ObjectGroup>();

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            bool isGod = agent.IsInScene(this) && agent.IsActiveGod;

            foreach (UInt32 localid in req.ObjectLocalIDs)
            {
                try
                {
                    ObjectGroup grp = Primitives[localid].ObjectGroup;
                    if (isGod || CanTakeCopy(agent, grp, grp.Position))
                    {
                        objectgroups.Add(grp);
                    }
                }
                catch
                {
                    agent.SendAlertMessage("ALERT: CantFindObject", ID);
                }
            }

            foreach (ObjectGroup grp in objectgroups)
            {
                var newgrp = new ObjectGroup(grp);
                foreach (ObjectPart part in grp.ValuesByKey1)
                {
                    var newpart = new ObjectPart(UUID.Random, part)
                    {
                        RezDate     = Date.Now,
                        ObjectGroup = newgrp
                    };
                    newgrp.Add(part.LinkNumber, newpart.ID, newpart);
                    newpart.UpdateData(ObjectPartLocalizedInfo.UpdateDataFlags.All);

                    foreach (KeyValuePair <UUID, ObjectPartInventoryItem> kvp in part.Inventory.Key1ValuePairs)
                    {
                        ScriptInstance instance = kvp.Value.ScriptInstance;
                        var            newItem  = new ObjectPartInventoryItem(UUID.Random, kvp.Value)
                        {
                            ExperienceID = kvp.Value.ExperienceID
                        };
                        if (instance != null)
                        {
                            try
                            {
                                newItem.ScriptState = instance.ScriptState;
                            }
                            catch
                            {
                                /* if taking script state fails, we do not bail out */
                            }
                        }
                        newpart.Inventory.Add(newItem);
                    }
                    newgrp.GlobalPosition   += req.Offset;
                    newpart.IsChangedEnabled = true;
                }

                UGI ugi = UGI.Unknown;
                GroupsNameService?.TryGetValue(req.GroupID, out ugi);
                newgrp.Group = ugi;
                newgrp.Owner = agent.Owner;

                RezObject(newgrp, grp.Owner);
#if DEBUG
                m_Log.DebugFormat("Duplicated object {0} ({1}, {2}) as {3} ({4}, {5})", grp.Name, grp.LocalID, grp.ID, newgrp.Name, newgrp.LocalID, newgrp.ID);
#endif
            }
        }
Ejemplo n.º 17
0
        private void AddTaskInventoryItem(UpdateTaskInventory req, IAgent agent, ObjectPart part)
        {
            switch (req.InvType)
            {
            case InventoryType.Animation:
            case InventoryType.Attachable:
            case InventoryType.CallingCard:
            case InventoryType.Gesture:
            case InventoryType.Landmark:
            case InventoryType.Notecard:
            case InventoryType.Object:
            case InventoryType.Snapshot:
            case InventoryType.Sound:
            case InventoryType.Texture:
            case InventoryType.Wearable:
                break;

            default:
                /* do not allow anything else than the ones above */
                return;
            }

            switch (req.AssetType)
            {
            case AssetType.LSLText:
            case AssetType.LSLBytecode:
            case AssetType.Link:
            case AssetType.LinkFolder:
                /* no addition here of scripts, item links or folder links */
                return;

            default:
                break;
            }

            if (part.IsAllowedDrop)
            {
                /* llAllowInventoryDrop active, so we can drop anything except scripts */
            }
            else if (!CanEdit(agent, part.ObjectGroup, part.ObjectGroup.GlobalPosition))
            {
                /* not allowed */
                return;
            }

            InventoryItem agentItem;

            if (agent.InventoryService.Item.TryGetValue(agent.Owner.ID, req.ItemID, out agentItem) &&
                agentItem.AssetType == req.AssetType &&
                agentItem.InventoryType == req.InvType)
            {
                var item = new ObjectPartInventoryItem(UUID.Random, agentItem);
                AdjustPermissionsAccordingly(agent, part.Owner, item);
                item.LastOwner = item.Owner;
                item.Owner     = part.Owner;

                if (AssetService.Exists(agentItem.AssetID))
                {
                    /* no need for an assettransferer here */

                    if ((item.Permissions.Base & InventoryPermissionsMask.Transfer) == 0)
                    {
                        part.OwnerMask &= ~InventoryPermissionsMask.Transfer;
                    }

                    if (item.AssetType.IsNoCopyAffectingContainingObject() && (item.Permissions.Base & InventoryPermissionsMask.Copy) == 0)
                    {
                        part.OwnerMask &= ~InventoryPermissionsMask.Copy;
                    }

                    part.Inventory.Add(item);

                    part.SendObjectUpdate();

                    SendObjectPropertiesToAgent(agent, part);

                    if (agentItem.CheckPermissions(agent.Owner, agent.Group, InventoryPermissionsMask.Copy))
                    {
                        agent.InventoryService.Item.Delete(agent.Owner.ID, agentItem.ID);
                    }
                }
                else
                {
                    new AddToObjectTransferItem(agent, this, item.AssetID, part, item).QueueWorkItem();
                }
            }
        }
Ejemplo n.º 18
0
        private void ThreadMain(object obj)
        {
            var            tc   = (ScriptThreadContext)obj;
            var            pool = tc.ThreadPool;
            ScriptInstance ev;

            while (!m_ShutdownThreads)
            {
                try
                {
                    ev = pool.m_ScriptTriggerQueue.Dequeue(1000);
                }
                catch
                {
                    lock (m_Threads)
                    {
                        if (m_Threads.Count > m_MinimumThreads)
                        {
                            break;
                        }
                    }
                    continue;
                }

                long executionStart = TimeSource.TickCount;
                tc.ExecutionStartTickCount = executionStart;
                tc.IsExecuting             = true;
                ObjectPartInventoryItem item = ev.Item;
                try
                {
                    Interlocked.Increment(ref m_ExecutingScripts);
                    lock (tc)
                    {
                        if (Interlocked.CompareExchange(ref ev.ThreadPool, this, null) != null)
                        {
                            continue;
                        }
                        tc.CurrentScriptInstance = ev;
                    }
                    ev.ProcessEvent();
                }
                catch (ThreadAbortException)
                {
                    /* no in script event should abort us */
                    Thread.ResetAbort();
                    try
                    {
                        item.ScriptInstance = null;
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                    catch (Exception e)
                    {
                        m_Log.WarnFormat("Exception at script removal {0} ({1}): {2}\n{3}",
                                         item.Name, item.AssetID.ToString(),
                                         e.Message,
                                         e.StackTrace);
                    }
                    ScriptLoader.Remove(item.AssetID, ev);
                    continue;
                }
                catch (ScriptAbortException)
                {
                    ev.AbortBegin();
                    try
                    {
                        item.ScriptInstance = null;
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                    catch (Exception e)
                    {
                        m_Log.WarnFormat("Exception at script removal {0} ({1}): {2}\n{3}",
                                         item.Name, item.AssetID.ToString(),
                                         e.Message,
                                         e.StackTrace);
                    }
                    ScriptLoader.Remove(item.AssetID, ev);
                    continue;
                }
                catch (InvalidProgramException e)
                {
                    /* stop the broken script */
                    m_Log.WarnFormat("Automatically stopped script {0} ({1}) of {2} ({3}) in {4} ({5}) due to program error: {6}\n{7}",
                                     item.Name, item.AssetID.ToString(),
                                     ev.Part?.Name ?? "?", ev.Part?.ID.ToString() ?? "?",
                                     ev.Part?.ObjectGroup?.Name ?? "?", ev.Part?.ObjectGroup?.ID.ToString() ?? "?",
                                     e.Message,
                                     e.StackTrace);
                    ev.IsRunning = false;
                    continue;
                }
                catch (Exception e)
                {
                    m_Log.WarnFormat("Exception at script {0} ({1}) of {2} ({3}) in {4} ({5}) due to program error: {6}\n{7}",
                                     item.Name, item.AssetID.ToString(),
                                     ev.Part?.Name ?? "?", ev.Part?.ID.ToString() ?? "?",
                                     ev.Part?.ObjectGroup?.Name, ev.Part?.ObjectGroup?.ID.ToString() ?? "?",
                                     e.Message,
                                     e.StackTrace);
                }
                finally
                {
                    Interlocked.Decrement(ref m_ExecutingScripts);
                    tc.IsExecuting = false;
                    uint localId;
                    lock (tc)
                    {
                        try
                        {
                            localId        = tc.CurrentScriptInstance.Part.LocalID[m_SceneID];
                            executionStart = TimeSource.TicksElapsed(TimeSource.TickCount, executionStart);
                            if (executionStart > 0)
                            {
                                RwLockedDictionary <uint, ScriptReportData> execTime = m_TopScripts;
                                ScriptReportData prevexectime;
                                if (!execTime.TryGetValue(localId, out prevexectime))
                                {
                                    prevexectime = new ScriptReportData();
                                    execTime.Add(localId, prevexectime);
                                }
                                prevexectime.AddScore(TimeSource.TicksToMsecs(executionStart));
                                Interlocked.Add(ref m_ScriptRuntimeAccumulatingTickCount, executionStart);
                            }
                        }
                        catch
                        {
                            /* ignore it here */
                        }
                        tc.CurrentScriptInstance = null;
                    }
                }

                ev.ThreadPool = null;
                if (ev.HasEventsPending)
                {
                    pool.m_ScriptTriggerQueue.Enqueue(ev);
                }
            }

            lock (m_Threads)
            {
                m_Threads.Remove(tc);
                if (m_ShutdownThreads && m_Threads.Count == 0)
                {
                    m_WaitShutdownEvent.Set();
                }
            }
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
 private Dictionary <string, object> GenerateUpdateObjectPartInventoryItem(UUID primID, ObjectPartInventoryItem item)
 {
     ObjectPartInventoryItem.PermsGranterInfo grantinfo = item.PermsGranter;
     return(new Dictionary <string, object>
     {
         ["AssetId"] = item.AssetID,
         ["AssetType"] = item.AssetType,
         ["CreationDate"] = item.CreationDate,
         ["Creator"] = item.Creator,
         ["Description"] = item.Description,
         ["Flags"] = item.Flags,
         ["Group"] = item.Group,
         ["GroupOwned"] = item.IsGroupOwned,
         ["PrimID"] = primID,
         ["Name"] = item.Name,
         ["InventoryID"] = item.ID,
         ["InventoryType"] = item.InventoryType,
         ["LastOwner"] = item.LastOwner,
         ["Owner"] = item.Owner,
         ["BasePermissions"] = item.Permissions.Base,
         ["CurrentPermissions"] = item.Permissions.Current,
         ["EveryOnePermissions"] = item.Permissions.EveryOne,
         ["GroupPermissions"] = item.Permissions.Group,
         ["NextOwnerPermissions"] = item.Permissions.NextOwner,
         ["SaleType"] = item.SaleInfo.Type,
         ["SalePrice"] = item.SaleInfo.Price,
         ["SalePermMask"] = item.SaleInfo.PermMask,
         ["PermsGranter"] = grantinfo.PermsGranter.ToString(),
         ["PermsMask"] = grantinfo.PermsMask,
         ["DebitPermissionKey"] = grantinfo.DebitPermissionKey,
         ["NextOwnerAssetID"] = item.NextOwnerAssetID,
         ["ExperienceID"] = item.ExperienceID,
         ["CollisionFilterData"] = item.CollisionFilter.DbSerialization
     });
 }
Ejemplo n.º 21
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);
            }
        }
Ejemplo n.º 22
0
        public override bool Run()
        {
            var owner    = new UGUI("11223344-1122-1122-1122-123456789012");
            var regionID = new UUID("12345678-1234-1234-1234-123456789012");
            var scene    = new DummyScene(256, 256, regionID);
            var objgrp   = new ObjectGroup();
            var part     = new ObjectPart
            {
                Name = "Test Object"
            };
            var item = new ObjectPartInventoryItem
            {
                Name          = "Test Item",
                AssetType     = AssetType.CallingCard,
                InventoryType = InventoryType.CallingCard,
                Owner         = owner
            };

            part.Inventory.Add(item);
            objgrp.Add(1, part);
            objgrp.Owner     = owner;
            part.ObjectGroup = objgrp;
            objgrp.Scene     = scene;

            SceneListener listener = SimulationData.GetSceneListener(regionID);

            listener.StartStorageThread();
            try
            {
                m_Log.Info("Checking that region object data is empty");
                if (SimulationData.Objects.ObjectsInRegion(regionID).Count != 0)
                {
                    return(false);
                }
                m_Log.Info("Checking that region prim data is empty");
                if (SimulationData.Objects.PrimitivesInRegion(regionID).Count != 0)
                {
                    return(false);
                }
                m_Log.Info("Checking that actual object does not exist");
                if (SimulationData.Objects.LoadObjects(regionID).Count != 0)
                {
                    return(false);
                }

                m_Log.Info("Store object");
                listener.ScheduleUpdate(part.UpdateInfo, regionID);
                /* ensure working time for listener */
                m_Log.Info("Wait 2s for processing");
                Thread.Sleep(2000);

                List <UUID> resultList;
                m_Log.Info("Checking that region contains one object");
                resultList = SimulationData.Objects.ObjectsInRegion(regionID);
                if (resultList.Count != 1)
                {
                    return(false);
                }

                if (resultList[0] != objgrp.ID)
                {
                    return(false);
                }

                m_Log.Info("Checking that region contains one prim");
                resultList = SimulationData.Objects.PrimitivesInRegion(regionID);
                if (resultList.Count != 1)
                {
                    return(false);
                }
                m_Log.Info("Checking that actual object exists");
                List <ObjectGroup> objectList = SimulationData.Objects.LoadObjects(regionID);
                if (objectList.Count != 1)
                {
                    return(false);
                }

                m_Log.Info("Check that actual object contains one prim");
                if (objectList[0].Count != 1)
                {
                    return(false);
                }

                ObjectPart resPart;
                m_Log.Info("Try retrieving known prim");
                if (!objectList[0].TryGetValue(part.ID, out resPart))
                {
                    return(false);
                }

                m_Log.Info("Check that actual prim contains one item");
                if (resPart.Inventory.Count != 1)
                {
                    return(false);
                }

                m_Log.Info("Check that actual item has known ID");
                if (!resPart.Inventory.ContainsKey(item.ID))
                {
                    return(false);
                }

                m_Log.Info("Remove inventory item");
                resPart.Inventory.Remove(item.ID);
                item.UpdateInfo.SetRemovedItem();
                listener.ScheduleUpdate(item.UpdateInfo, regionID);
                /* ensure working time for listener */
                m_Log.Info("Wait 2s for processing");
                Thread.Sleep(2000);

                m_Log.Info("check that inventory item got deleted");
                objectList = SimulationData.Objects.LoadObjects(regionID);
                if (objectList.Count != 1 || !objectList[0].TryGetValue(part.ID, out resPart) || resPart.Inventory.Count != 0)
                {
                    return(false);
                }

                m_Log.Info("Remove prim");
                part.UpdateInfo.KillObject();
                listener.ScheduleUpdate(part.UpdateInfo, regionID);

                /* ensure working time for listener */
                m_Log.Info("Wait 2s for processing");
                Thread.Sleep(2000);

                m_Log.Info("Checking that region object data is empty");
                if (SimulationData.Objects.ObjectsInRegion(regionID).Count != 0)
                {
                    return(false);
                }
                m_Log.Info("Checking that region prim data is empty");
                if (SimulationData.Objects.PrimitivesInRegion(regionID).Count != 0)
                {
                    return(false);
                }
                m_Log.Info("Checking that actual object does not exist");
                if (SimulationData.Objects.LoadObjects(regionID).Count != 0)
                {
                    return(false);
                }
            }
            finally
            {
                listener.StopStorageThread();
            }
            return(true);
        }