private static void AddObjects( SceneInterface scene, List <ObjectGroup> sogs, LoadOptions options) { foreach (ObjectGroup sog in sogs) { sog.LastOwner = scene.AvatarNameService.ResolveName(sog.LastOwner); sog.Owner = scene.AvatarNameService.ResolveName(sog.Owner); foreach (ObjectPart part in sog.ValuesByKey1) { part.Creator = scene.AvatarNameService.ResolveName(part.Creator); foreach (ObjectPartInventoryItem item in part.Inventory.ValuesByKey1) { item.Owner = scene.AvatarNameService.ResolveName(item.Owner); item.Creator = scene.AvatarNameService.ResolveName(item.Creator); item.LastOwner = scene.AvatarNameService.ResolveName(item.LastOwner); } } scene.Add(sog); } foreach (ObjectGroup grp in sogs) { scene.RezScriptsForObject(grp); } sogs.Clear(); }
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); }
private void AttachFromInventory(AssetData data, UUID itemID) { List <ObjectGroup> objgroups; #if DEBUG m_Log.DebugFormat("Deserializing object asset {0} for agent {1} {2} ({3})", data.ID, NamedOwner.FirstName, NamedOwner.LastName, NamedOwner.ID); #endif try { objgroups = ObjectXML.FromAsset(data, Owner); } catch (Exception e) { m_Log.WarnFormat("Deserialization error for object asset {0} for agent {1} {2} ({3}): {4}: {5}", data.ID, NamedOwner.FirstName, NamedOwner.LastName, NamedOwner.ID, e.GetType().FullName, e.ToString()); return; } if (objgroups.Count != 1) { return; } ObjectGroup grp = objgroups[0]; foreach (ObjectPart part in grp.Values) { if (part.Shape.PCode == PrimitiveCode.Grass || part.Shape.PCode == PrimitiveCode.Tree || part.Shape.PCode == PrimitiveCode.NewTree) { return; } } AttachmentPoint attachAt = grp.AttachPoint; if (attachAt == AttachmentPoint.NotAttached) { grp.AttachPoint = AttachmentPoint.LeftHand; grp.AttachedPos = Vector3.Zero; grp.AttachedRot = Quaternion.Identity; } grp.FromItemID = itemID; grp.IsAttached = true; grp.Position = grp.AttachedPos; grp.Rotation = grp.AttachedRot; grp.IsChangedEnabled = true; #if DEBUG m_Log.DebugFormat("Adding attachment asset {0} at {4} for agent {1} {2} ({3})", data.ID, NamedOwner.FirstName, NamedOwner.LastName, NamedOwner.ID, grp.AttachPoint.ToString()); #endif SceneInterface scene = CurrentScene; try { scene.Add(grp); Attachments.Add(grp.AttachPoint, grp); } catch { return; } }