private void killTrees() { foreach (Copse copse in m_copse) { if (!copse.m_frozen && copse.m_trees.Count >= copse.m_tree_quantity) { List <SceneObjectGroup> groups = new List <SceneObjectGroup>(); foreach (UUID tree in copse.m_trees) { double killLikelyhood = 0.0; IEntity entity; if (m_scene.Entities.TryGetValue(tree, out entity) && entity is SceneObjectGroup) { SceneObjectPart selectedTree = ((SceneObjectGroup)entity).RootPart; double selectedTreeScale = Math.Sqrt(Math.Pow(selectedTree.Scale.X, 2) + Math.Pow(selectedTree.Scale.Y, 2) + Math.Pow(selectedTree.Scale.Z, 2)); foreach (UUID picktree in copse.m_trees) { if (picktree != tree) { IEntity ent; if (m_scene.Entities.TryGetValue(tree, out ent) && ent is SceneObjectGroup) { SceneObjectPart pickedTree = ((SceneObjectGroup)ent).RootPart; double pickedTreeScale = Math.Sqrt(Math.Pow(pickedTree.Scale.X, 2) + Math.Pow(pickedTree.Scale.Y, 2) + Math.Pow(pickedTree.Scale.Z, 2)); double pickedTreeDistance = Vector3.Distance(pickedTree.AbsolutePosition, selectedTree.AbsolutePosition); killLikelyhood += (selectedTreeScale / (pickedTreeScale * pickedTreeDistance)) * 0.1; } } } if (Util.RandomClass.NextDouble() < killLikelyhood) { groups.Add(selectedTree.ParentGroup); copse.m_trees.Remove(selectedTree.ParentGroup.UUID); break; } } else { m_log.DebugFormat("[TREES]: Tree not in scene {0}", tree); } } IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(groups.ToArray(), true); } } } }
public bool EventSchProcessQIS(ref QueueItemStruct QIS) { try { Exception ex = null; EnumeratorInfo Running = QIS.ID.Script.ExecuteEvent(QIS.State, QIS.functionName, QIS.param, QIS.CurrentlyAt, out ex); if (ex != null) { //Check exceptions, some are ours to deal with, and others are to be logged if (ex.Message.Contains("SelfDeleteException")) { if (QIS.ID.Part != null && QIS.ID.Part.ParentEntity != null) { IBackupModule backup = QIS.ID.Part.ParentEntity.Scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects( new ISceneEntity[1] { QIS.ID.Part.ParentEntity }, true, true); } } } else if (ex.Message.Contains("ScriptDeleteException")) { if (QIS.ID.Part != null && QIS.ID.Part.ParentEntity != null) { QIS.ID.Part.Inventory.RemoveInventoryItem(QIS.ID.ItemID); } } //Log it for the user else if (!(ex.Message.Contains("EventAbortException")) && !(ex.Message.Contains("MinEventDelayException"))) { QIS.ID.DisplayUserNotification(ex.ToString(), "executing", false, true); } EventManager.EventComplete(QIS); return(false); } else if (Running != null) { //Did not finish so requeue it QIS.CurrentlyAt = Running; QIS.RunningNumber++; return(true); //Do the return... otherwise we open the queue for this event back up } } catch (Exception ex) { //Error, tell the user QIS.ID.DisplayUserNotification(ex.ToString(), "executing", false, true); } //Tell the event manager about it so that the events will be removed from the queue EventManager.EventComplete(QIS); return(false); }
public void SuspendAvatar(IScenePresence presence, GridRegion destination) { IAvatarAppearanceModule appearance = presence.RequestModuleInterface <IAvatarAppearanceModule>(); presence.AttachmentsLoaded = false; ISceneEntity[] attachments = GetAttachmentsForAvatar(presence.UUID); foreach (ISceneEntity group in attachments) { if (group.RootChild.AttachedPos != group.RootChild.SavedAttachedPos || group.RootChild.SavedAttachmentPoint != group.RootChild.AttachmentPoint) { group.RootChild.SavedAttachedPos = group.RootChild.AttachedPos; group.RootChild.SavedAttachmentPoint = group.RootChild.AttachmentPoint; //Make sure we get updated group.HasGroupChanged = true; } // If an item contains scripts, it's always changed. // This ensures script state is saved on detach foreach (ISceneChildEntity p in group.ChildrenEntities()) { if (p.Inventory.ContainsScripts()) { group.HasGroupChanged = true; break; } } if (group.HasGroupChanged) { UUID assetID = UpdateKnownItem(presence.ControllingClient, group, group.RootChild.FromUserInventoryItemID, group.OwnerID); group.RootChild.FromUserInventoryAssetID = assetID; } } if (appearance != null) { appearance.Appearance.SetAttachments(attachments); presence.Scene.AvatarService.SetAppearance(presence.UUID, appearance.Appearance); } IBackupModule backup = presence.Scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { bool sendUpdates = destination == null; if (!sendUpdates) { List <GridRegion> regions = presence.Scene.RequestModuleInterface <IGridRegisterModule>() .GetNeighbors(presence.Scene); regions.RemoveAll((r) => r.RegionID != destination.RegionID); sendUpdates = regions.Count == 0; } backup.DeleteSceneObjects(attachments, false, sendUpdates); } }
public bool DeleteObject() { DeleteToInventoryHolder x = null; try { if (m_removeFromSimQueue.TryDequeue(out x)) { MainConsole.Instance.DebugFormat( "[SCENE]: Sending object to user's inventory, {0} item(s) remaining.", m_removeFromSimQueue.Count); if (x.permissionToTake) { try { IInventoryAccessModule invAccess = m_scene.RequestModuleInterface <IInventoryAccessModule>(); UUID itemID; if (invAccess != null) { invAccess.DeleteToInventory(x.action, x.folderID, x.objectGroups, x.agentId, out itemID); } } catch (Exception e) { MainConsole.Instance.ErrorFormat( "[ASYNC DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace); } } //Moved Delete To After Object Taken To Inventory. Prevents script variables not being updated before taken to inventory if (x.permissionToDelete) { IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(x.objectGroups.ToArray(), true, true); } } return(true); } } catch (Exception e) { // We can't put the object group details in here since the root part may have disappeared (which is where these sit). // FIXME: This needs to be fixed. MainConsole.Instance.ErrorFormat( "[SCENE]: Queued sending of scene object to agent {0} {1} failed: {2}", (x != null ? x.agentId.ToString() : "unavailable"), (x != null ? x.agentId.ToString() : "unavailable"), e); } //MainConsole.Instance.Debug("[SCENE]: No objects left in delete queue."); return(false); }
/// <summary> /// Kill an object given its UUID. /// </summary> /// <param name="cmdparams"></param> protected void KillUUID(string module, string[] cmdparams) { if (cmdparams.Length > 2) { UUID id = UUID.Zero; ISceneEntity grp = null; Scene sc = null; if (!UUID.TryParse(cmdparams[2], out id)) { m_log.Info("[KillUUID]: Error bad UUID format!"); return; } ForEachScene(delegate(Scene scene) { ISceneChildEntity part = scene.GetSceneObjectPart(id); if (part == null) { return; } grp = part.ParentEntity; sc = scene; }); if (grp == null) { m_log.Info(String.Format("[KillUUID]: Given UUID {0} not found!", id)); } else { m_log.Info(String.Format("[KillUUID]: Found UUID {0} in scene {1}", id, sc.RegionInfo.RegionName)); try { IBackupModule backup = sc.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(new ISceneEntity[1] { grp }, true); } } catch (Exception e) { m_log.ErrorFormat("[KillUUID]: Error while removing objects from scene: " + e); } } } else { m_log.Info("[KillUUID]: Usage: kill uuid <UUID>"); } }
public void DetachSingleAttachmentToInventory(UUID itemID, IClientAPI remoteClient) { ISceneEntity[] attachments = GetAttachmentsForAvatar(remoteClient.AgentId); IScenePresence presence; if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence)) { IAvatarAppearanceModule appearance = presence.RequestModuleInterface <IAvatarAppearanceModule>(); if (!appearance.Appearance.DetachAttachment(itemID)) { bool found = false; foreach (ISceneEntity grp in attachments) { if (grp.RootChild.FromUserInventoryItemID == itemID) { found = true; } } if (!found) { return; //Its not attached! What are we doing! } } MainConsole.Instance.Debug("[ATTACHMENTS MODULE]: Detaching from UserID: " + remoteClient.AgentId + ", ItemID: " + itemID); if (AvatarFactory != null) { AvatarFactory.QueueAppearanceSave(remoteClient.AgentId); } } DetachSingleAttachmentToInventoryInternal(itemID, remoteClient, true); //Find the attachment we are trying to edit by ItemID foreach (ISceneEntity grp in attachments) { if (grp.RootChild.FromUserInventoryItemID == itemID) { //And from storage as well IBackupModule backup = presence.Scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(new[] { grp }, false, true); } } } }
private void HandleTreeRemove(string module, string[] cmd) { if (MainConsole.Instance.ConsoleScene != m_scene) { return; } string copsename = (cmd[2]).Trim(); Copse copseIdentity = null; foreach (Copse cp in m_copse) { if (cp.m_name == copsename) { copseIdentity = cp; } } if (copseIdentity != null) { List <SceneObjectGroup> groups = new List <SceneObjectGroup>(); foreach (UUID tree in copseIdentity.m_trees) { IEntity entity; if (m_scene.Entities.TryGetValue(tree, out entity)) { if (entity is SceneObjectGroup) { groups.Add((SceneObjectGroup)entity); } } } IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(groups.ToArray(), true); } copseIdentity.m_trees = new List <UUID>(); m_copse.Remove(copseIdentity); m_log.InfoFormat("[TREES]: Copse {0} has been removed", copsename); } else { m_log.InfoFormat("[TREES]: Copse {0} was not found - command failed", copsename); } }
/// <summary> /// Adds a Scene Object group to the Scene. /// Verifies that the creator of the object is not banned from the simulator. /// Checks if the item is an Attachment /// </summary> /// <param name="scene"></param> /// <param name="sceneObject"></param> /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> public bool AddSceneObject(IScene scene, ISceneEntity sceneObject) { // If the user is banned, we won't let any of their objects // enter. Period. // if (scene.RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) { MainConsole.Instance.Info("[EntityTransferModule]: Denied prim crossing for banned avatar"); return(false); } //if (!sceneObject.IsAttachmentCheckFull()) // Not Attachment { if (!scene.Permissions.CanObjectEntry(sceneObject.UUID, true, sceneObject.AbsolutePosition, sceneObject.OwnerID)) { // Deny non attachments based on parcel settings // MainConsole.Instance.Info("[EntityTransferModule]: Denied prim crossing " + "because of parcel settings"); IBackupModule backup = scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(new[] { sceneObject }, true, true); } return(false); } sceneObject.IsInTransit = false; //Reset this now that it's entering here if (scene.SceneGraph.AddPrimToScene(sceneObject)) { if (sceneObject.IsSelected) { sceneObject.RootChild.CreateSelected = true; } sceneObject.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate); return(true); } } return(false); }
public void SuspendAvatar(IScenePresence presence) { ISceneEntity[] attachments = GetAttachmentsForAvatar(presence.UUID); foreach (ISceneEntity group in attachments) { if (group.RootChild.AttachedPos != group.RootChild.SavedAttachedPos || group.RootChild.SavedAttachmentPoint != group.RootChild.AttachmentPoint) { group.RootChild.SavedAttachedPos = group.RootChild.AttachedPos; group.RootChild.SavedAttachmentPoint = group.RootChild.AttachmentPoint; //Make sure we get updated group.HasGroupChanged = true; } // If an item contains scripts, it's always changed. // This ensures script state is saved on detach foreach (ISceneChildEntity p in group.ChildrenEntities()) { if (p.Inventory.ContainsScripts()) { group.HasGroupChanged = true; break; } } if (group.HasGroupChanged) { UpdateKnownItem(presence.ControllingClient, group, group.RootChild.FromUserInventoryItemID, group.OwnerID); } } IBackupModule backup = presence.Scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(attachments, false, true); } }
/// <summary> /// Move the given scene object into a new region /// </summary> /// <param name="destination"></param> /// <param name="grp">Scene Object Group that we're crossing</param> /// <param name="attemptedPos"></param> /// <returns> /// true if the crossing itself was successful, false on failure /// </returns> protected bool CrossPrimGroupIntoNewRegion(GridRegion destination, ISceneEntity grp, Vector3 attemptedPos) { bool successYN = false; if (destination != null) { if (grp.SitTargetAvatar.Count != 0) { foreach (UUID avID in grp.SitTargetAvatar) { IScenePresence SP = grp.Scene.GetScenePresence(avID); SP.Velocity = grp.RootChild.PhysActor.Velocity; InternalCross(SP, attemptedPos, false, destination); } foreach (ISceneChildEntity part in grp.ChildrenEntities()) { part.SitTargetAvatar = new List <UUID> (); } IBackupModule backup = grp.Scene.RequestModuleInterface <IBackupModule> (); if (backup != null) { return(backup.DeleteSceneObjects(new [] { grp }, false, false)); } return(true); //They do all the work adding the prim in the other region } ISceneEntity copiedGroup = grp.Copy(false); copiedGroup.SetAbsolutePosition(true, attemptedPos); if (grp.Scene != null) { successYN = grp.Scene.RequestModuleInterface <ISimulationService> () .CreateObject(destination, copiedGroup); } if (successYN) { // We remove the object here try { IBackupModule backup = grp.Scene.RequestModuleInterface <IBackupModule> (); if (backup != null) { return(backup.DeleteSceneObjects(new [] { grp }, false, true)); } } catch (Exception e) { MainConsole.Instance.ErrorFormat( "[Entity transfer]: Exception deleting the old object left behind on a border crossing for {0}, {1}", grp, e); } } else { if (!grp.IsDeleted) { if (grp.RootChild.PhysActor != null) { grp.RootChild.PhysActor.CrossingFailure(); } } MainConsole.Instance.ErrorFormat("[Entity transfer]r]: Prim crossing failed for {0}", grp); } } else { MainConsole.Instance.Error( "[Entity transfer]: destination was unexpectedly null in Scene.CrossPrimGroupIntoNewRegion()"); } return(successYN); }
/// <summary> /// Move the given scene object into a new region depending on which region its absolute position has moved /// into. /// This method locates the new region handle and offsets the prim position for the new region /// </summary> /// <param name="attemptedPosition">the attempted out of region position of the scene object</param> /// <param name="grp">the scene object that we're crossing</param> /// <param name="destination"></param> public bool CrossGroupToNewRegion(ISceneEntity grp, Vector3 attemptedPosition, GridRegion destination) { if (grp == null) { return(false); } if (grp.IsDeleted) { return(false); } if (grp.Scene == null) { return(false); } if (grp.RootChild.DIE_AT_EDGE) { // We remove the object here try { IBackupModule backup = grp.Scene.RequestModuleInterface <IBackupModule> (); if (backup != null) { return(backup.DeleteSceneObjects(new [] { grp }, true, true)); } } catch (Exception) { MainConsole.Instance.Warn( "[Database]: exception when trying to remove the prim that crossed the border."); } return(false); } if (grp.RootChild.RETURN_AT_EDGE) { // We remove the object here try { List <ISceneEntity> objects = new List <ISceneEntity> { grp }; ILLClientInventory inventoryModule = grp.Scene.RequestModuleInterface <ILLClientInventory> (); if (inventoryModule != null) { return(inventoryModule.ReturnObjects(objects.ToArray(), UUID.Zero)); } } catch (Exception) { MainConsole.Instance.Warn( "[Scene]: exception when trying to return the prim that crossed the border."); } return(false); } Vector3 oldGroupPosition = grp.RootChild.GroupPosition; // If we fail to cross the border, then reset the position of the scene object on that border. if (destination != null && !CrossPrimGroupIntoNewRegion(destination, grp, attemptedPosition)) { grp.OffsetForNewRegion(oldGroupPosition); grp.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate); return(false); } return(true); }
// What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards. // To LocalId or UUID, *THAT* is the question. How now Brown UUID?? protected void DetachSingleAttachmentToInventoryInternal(UUID itemID, IClientAPI remoteClient, bool fireEvent) { if (itemID == UUID.Zero) // If this happened, someone made a mistake.... { return; } // We can NOT use the dictionaries here, as we are looking // for an entity by the fromAssetID, which is NOT the prim UUID ISceneEntity[] attachments = GetAttachmentsForAvatar(remoteClient.AgentId); foreach (ISceneEntity group in attachments) { if (group.RootChild.FromUserInventoryItemID == itemID) { if (fireEvent) { m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero); group.DetachToInventoryPrep(); } IScenePresence presence = m_scene.GetScenePresence(remoteClient.AgentId); if (presence != null) { AvatarAttachments attModule = presence.RequestModuleInterface <AvatarAttachments>(); if (attModule != null) { attModule.RemoveAttachment(group); } } m_log.Debug("[ATTACHMENTS MODULE]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString()); //Update the saved attach points if (group.RootChild.AttachedPos != group.RootChild.SavedAttachedPos || group.RootChild.SavedAttachmentPoint != group.RootChild.AttachmentPoint) { group.RootChild.SavedAttachedPos = group.RootChild.AttachedPos; group.RootChild.SavedAttachmentPoint = group.RootChild.AttachmentPoint; //Make sure we get updated group.HasGroupChanged = true; } // If an item contains scripts, it's always changed. // This ensures script state is saved on detach foreach (ISceneChildEntity p in group.ChildrenEntities()) { if (p.Inventory.ContainsScripts()) { group.HasGroupChanged = true; break; } } UpdateKnownItem(remoteClient, group, group.RootChild.FromUserInventoryItemID, group.OwnerID); IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { backup.DeleteSceneObjects(new ISceneEntity[1] { group }, true); } return; //All done, end } } }
/// <summary> /// Move the given scene object into a new region /// </summary> /// <param name="newRegionHandle"></param> /// <param name="grp">Scene Object Group that we're crossing</param> /// <returns> /// true if the crossing itself was successful, false on failure /// </returns> protected bool CrossPrimGroupIntoNewRegion(GridRegion destination, SceneObjectGroup grp, Vector3 attemptedPos) { bool successYN = false; grp.RootPart.ClearUpdateScheduleOnce(); if (destination != null) { if (grp.RootPart.SitTargetAvatar.Count != 0) { lock (grp.RootPart.SitTargetAvatar) { foreach (UUID avID in grp.RootPart.SitTargetAvatar) { IScenePresence SP = grp.Scene.GetScenePresence(avID); CrossAgentToNewRegionAsync(SP, grp.AbsolutePosition, destination, false); } } } SceneObjectGroup copiedGroup = (SceneObjectGroup)grp.Copy(false); copiedGroup.SetAbsolutePosition(true, attemptedPos); if (grp.Scene != null && grp.Scene.SimulationService != null) { successYN = grp.Scene.SimulationService.CreateObject(destination, copiedGroup); } if (successYN) { // We remove the object here try { foreach (SceneObjectPart part in grp.ChildrenList) { lock (part.SitTargetAvatar) { part.SitTargetAvatar.Clear(); } } IBackupModule backup = grp.Scene.RequestModuleInterface <IBackupModule>(); if (backup != null) { return(backup.DeleteSceneObjects(new SceneObjectGroup[1] { grp }, false)); } } catch (Exception e) { m_log.ErrorFormat( "[ENTITY TRANSFER MODULE]: Exception deleting the old object left behind on a border crossing for {0}, {1}", grp, e); } } else { if (!grp.IsDeleted) { if (grp.RootPart.PhysActor != null) { grp.RootPart.PhysActor.CrossingFailure(); } } m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: Prim crossing failed for {0}", grp); } } else { m_log.Error("[ENTITY TRANSFER MODULE]: destination was unexpectedly null in Scene.CrossPrimGroupIntoNewRegion()"); } return(successYN); }