InnerScene.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using Axiom.Math;
  31. using libsecondlife;
  32. using libsecondlife.Packets;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Environment.Types;
  36. using OpenSim.Region.Physics.Manager;
  37. namespace OpenSim.Region.Environment.Scenes
  38. {
  39. public delegate void PhysicsCrash();
  40. public class InnerScene
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. #region Events
  44. protected internal event PhysicsCrash UnRecoverableError;
  45. private PhysicsCrash handlerPhysicsCrash = null;
  46. #endregion
  47. #region Fields
  48. protected internal Dictionary<LLUUID, ScenePresence> ScenePresences = new Dictionary<LLUUID, ScenePresence>();
  49. // SceneObjects is not currently populated or used.
  50. //public Dictionary<LLUUID, SceneObjectGroup> SceneObjects;
  51. protected internal Dictionary<LLUUID, EntityBase> Entities = new Dictionary<LLUUID, EntityBase>();
  52. protected internal Dictionary<LLUUID, ScenePresence> RestorePresences = new Dictionary<LLUUID, ScenePresence>();
  53. protected internal BasicQuadTreeNode QuadTree;
  54. protected RegionInfo m_regInfo;
  55. protected Scene m_parentScene;
  56. protected List<EntityBase> m_updateList = new List<EntityBase>();
  57. protected int m_numRootAgents = 0;
  58. protected int m_numPrim = 0;
  59. protected int m_numChildAgents = 0;
  60. protected int m_physicalPrim = 0;
  61. protected int m_activeScripts = 0;
  62. protected int m_scriptLPS = 0;
  63. protected internal object m_syncRoot = new object();
  64. protected internal PhysicsScene _PhyScene;
  65. #endregion
  66. protected internal InnerScene(Scene parent, RegionInfo regInfo)
  67. {
  68. m_parentScene = parent;
  69. m_regInfo = regInfo;
  70. QuadTree = new BasicQuadTreeNode(null, "/0/", 0, 0, (short)Constants.RegionSize, (short)Constants.RegionSize);
  71. QuadTree.Subdivide();
  72. QuadTree.Subdivide();
  73. }
  74. public PhysicsScene PhysicsScene
  75. {
  76. get { return _PhyScene; }
  77. set
  78. {
  79. // If we're not doing the initial set
  80. // Then we've got to remove the previous
  81. // event handler
  82. try
  83. {
  84. _PhyScene.OnPhysicsCrash -= physicsBasedCrash;
  85. }
  86. catch (NullReferenceException)
  87. {
  88. // This occurs when storing to _PhyScene the first time.
  89. // Is there a better way to check the event handler before
  90. // getting here
  91. // This can be safely ignored. We're setting the first inital
  92. // there are no event handler's registered.
  93. }
  94. _PhyScene = value;
  95. _PhyScene.OnPhysicsCrash += physicsBasedCrash;
  96. }
  97. }
  98. protected internal void Close()
  99. {
  100. lock (ScenePresences)
  101. {
  102. ScenePresences.Clear();
  103. }
  104. //SceneObjects.Clear();
  105. Entities.Clear();
  106. }
  107. #region Update Methods
  108. protected internal void UpdatePreparePhysics()
  109. {
  110. // If we are using a threaded physics engine
  111. // grab the latest scene from the engine before
  112. // trying to process it.
  113. // PhysX does this (runs in the background).
  114. if (_PhyScene.IsThreaded)
  115. {
  116. _PhyScene.GetResults();
  117. }
  118. }
  119. protected internal void UpdateEntities()
  120. {
  121. List<EntityBase> updateEntities = GetEntities();
  122. foreach (EntityBase entity in updateEntities)
  123. {
  124. entity.Update();
  125. }
  126. }
  127. protected internal void UpdatePresences()
  128. {
  129. List<ScenePresence> updateScenePresences = GetScenePresences();
  130. foreach (ScenePresence pres in updateScenePresences)
  131. {
  132. pres.Update();
  133. }
  134. }
  135. protected internal float UpdatePhysics(double elapsed)
  136. {
  137. lock (m_syncRoot)
  138. {
  139. return _PhyScene.Simulate((float)elapsed);
  140. }
  141. }
  142. protected internal void UpdateEntityMovement()
  143. {
  144. List<EntityBase> moveEntities = GetEntities();
  145. foreach (EntityBase entity in moveEntities)
  146. {
  147. entity.UpdateMovement();
  148. }
  149. }
  150. #endregion
  151. #region Entity Methods
  152. /// <summary>
  153. /// Add an object into the scene that has come from storage
  154. /// </summary>
  155. /// <param name="sceneObject"></param>
  156. protected internal void AddSceneObjectFromStorage(SceneObjectGroup sceneObject)
  157. {
  158. sceneObject.RegionHandle = m_regInfo.RegionHandle;
  159. sceneObject.SetScene(m_parentScene);
  160. foreach (SceneObjectPart part in sceneObject.Children.Values)
  161. {
  162. part.LocalId = m_parentScene.PrimIDAllocate();
  163. }
  164. sceneObject.UpdateParentIDs();
  165. AddSceneObject(sceneObject);
  166. }
  167. /// <summary>
  168. /// Add an object to the scene.
  169. /// </summary>
  170. /// <param name="sceneObject"></param>
  171. /// <returns>true if the object was added, false if an object with the same uuid was already in the scene
  172. /// </returns>
  173. protected internal bool AddSceneObject(SceneObjectGroup sceneObject)
  174. {
  175. lock (Entities)
  176. {
  177. if (!Entities.ContainsKey(sceneObject.UUID))
  178. {
  179. // QuadTree.AddSceneObject(sceneObject);
  180. Entities.Add(sceneObject.UUID, sceneObject);
  181. m_numPrim++;
  182. return true;
  183. }
  184. return false;
  185. }
  186. }
  187. /// <summary>
  188. /// Delete an object from the scene
  189. /// </summary>
  190. /// <param name="sceneObject"></param>
  191. /// <returns>true if the object was deleted, false if there was no object to delete</returns>
  192. protected internal bool DeleteSceneObject(LLUUID uuid)
  193. {
  194. lock (Entities)
  195. {
  196. if (Entities.ContainsKey(uuid))
  197. {
  198. Entities.Remove(uuid);
  199. m_numPrim--;
  200. return true;
  201. }
  202. }
  203. return false;
  204. }
  205. /// <summary>
  206. /// Add an entity to the list of prims to process on the next update
  207. /// </summary>
  208. /// <param name="obj">
  209. /// A <see cref="EntityBase"/>
  210. /// </param>
  211. protected internal void AddToUpdateList(EntityBase obj)
  212. {
  213. lock (m_updateList)
  214. {
  215. if (!m_updateList.Contains(obj))
  216. {
  217. m_updateList.Add(obj);
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// Process all pending updates
  223. /// </summary>
  224. protected internal void ProcessUpdates()
  225. {
  226. lock (m_updateList)
  227. {
  228. for (int i = 0; i < m_updateList.Count; i++)
  229. {
  230. EntityBase entity = m_updateList[i];
  231. // Don't abort the whole update if one entity happens to give us an exception.
  232. try
  233. {
  234. // A null name signals that this group was deleted before the scheduled update
  235. // FIXME: This is merely a temporary measure to reduce the incidence of failure, when
  236. // an object has been deleted from a scene before update was processed.
  237. // A more fundamental overhaul of the update mechanism is required to eliminate all
  238. // the race conditions.
  239. if (entity.Name != null)
  240. {
  241. m_updateList[i].Update();
  242. }
  243. }
  244. catch (Exception e)
  245. {
  246. m_log.ErrorFormat("[INNER SCENE]: Failed to update {0}, - {1}", entity.Name, e);//entity.m_uuid
  247. }
  248. }
  249. m_updateList.Clear();
  250. }
  251. }
  252. protected internal void AddPhysicalPrim(int number)
  253. {
  254. m_physicalPrim++;
  255. }
  256. protected internal void RemovePhysicalPrim(int number)
  257. {
  258. m_physicalPrim--;
  259. }
  260. protected internal void AddToScriptLPS(int number)
  261. {
  262. m_scriptLPS += number;
  263. }
  264. protected internal void AddActiveScripts(int number)
  265. {
  266. m_activeScripts += number;
  267. }
  268. protected internal void DetachObject(uint objectLocalID, IClientAPI remoteClient)
  269. {
  270. List<EntityBase> EntityList = GetEntities();
  271. foreach (EntityBase obj in EntityList)
  272. {
  273. if (obj is SceneObjectGroup)
  274. {
  275. if (((SceneObjectGroup)obj).LocalId == objectLocalID)
  276. {
  277. SceneObjectGroup group = (SceneObjectGroup)obj;
  278. //group.DetachToGround();
  279. DetachSingleAttachmentToInv(group.GetFromAssetID(),remoteClient);
  280. }
  281. }
  282. }
  283. }
  284. protected internal void HandleUndo(IClientAPI remoteClient, LLUUID primId)
  285. {
  286. if (primId != LLUUID.Zero)
  287. {
  288. SceneObjectPart part = m_parentScene.GetSceneObjectPart(primId);
  289. if (part != null)
  290. part.Undo();
  291. }
  292. }
  293. protected internal void HandleObjectGroupUpdate(
  294. IClientAPI remoteClient, LLUUID GroupID, uint objectLocalID, LLUUID Garbage)
  295. {
  296. List<EntityBase> EntityList = GetEntities();
  297. foreach (EntityBase obj in EntityList)
  298. {
  299. if (obj is SceneObjectGroup)
  300. {
  301. if (((SceneObjectGroup)obj).LocalId == objectLocalID)
  302. {
  303. SceneObjectGroup group = (SceneObjectGroup)obj;
  304. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  305. group.SetGroup(GroupID, remoteClient);
  306. else
  307. remoteClient.SendAgentAlertMessage("You don't have permission to set the group", false);
  308. }
  309. }
  310. }
  311. }
  312. /// <summary>
  313. /// Event Handling routine for Attach Object
  314. /// </summary>
  315. /// <param name="remoteClient"></param>
  316. /// <param name="objectLocalID"></param>
  317. /// <param name="AttachmentPt"></param>
  318. /// <param name="rot"></param>
  319. protected internal void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot)
  320. {
  321. // Calls attach with a Zero position
  322. AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, LLVector3.Zero);
  323. }
  324. protected internal void RezSingleAttachment(
  325. IClientAPI remoteClient, LLUUID itemID, uint AttachmentPt,uint ItemFlags, uint NextOwnerMask)
  326. {
  327. SceneObjectGroup objatt = m_parentScene.RezObject(remoteClient, itemID, LLVector3.Zero, LLVector3.Zero, LLUUID.Zero, (byte)1, true,
  328. (uint)(PermissionMask.Copy | PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer),
  329. (uint)(PermissionMask.Copy | PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer),
  330. (uint)(PermissionMask.Copy | PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer),
  331. ItemFlags, false, false, remoteClient.AgentId, true);
  332. if (objatt != null)
  333. {
  334. AttachObject(remoteClient,objatt.LocalId,AttachmentPt,new LLQuaternion(0,0,0,1),objatt.AbsolutePosition);
  335. objatt.ScheduleGroupForFullUpdate();
  336. }
  337. }
  338. // What makes this method odd and unique is it tries to detach using an LLUUID.... Yay for standards.
  339. // To LocalId or LLUUID, *THAT* is the question. How now Brown LLUUID??
  340. protected internal void DetachSingleAttachmentToInv(LLUUID itemID, IClientAPI remoteClient)
  341. {
  342. if (itemID == LLUUID.Zero) // If this happened, someone made a mistake....
  343. return;
  344. List<EntityBase> EntityList = GetEntities();
  345. foreach (EntityBase obj in EntityList)
  346. {
  347. if (obj is SceneObjectGroup)
  348. {
  349. if (((SceneObjectGroup)obj).GetFromAssetID() == itemID)
  350. {
  351. SceneObjectGroup group = (SceneObjectGroup)obj;
  352. group.DetachToInventoryPrep();
  353. m_log.Debug("[DETACH]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString());
  354. m_parentScene.updateKnownAsset(remoteClient, group, group.GetFromAssetID(),group.OwnerID);
  355. m_parentScene.DeleteSceneObject(group);
  356. }
  357. }
  358. }
  359. }
  360. protected internal void AttachObject(
  361. IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot, LLVector3 attachPos)
  362. {
  363. List<EntityBase> EntityList = GetEntities();
  364. foreach (EntityBase obj in EntityList)
  365. {
  366. if (obj is SceneObjectGroup)
  367. {
  368. if (((SceneObjectGroup)obj).LocalId == objectLocalID)
  369. {
  370. SceneObjectGroup group = (SceneObjectGroup)obj;
  371. if (m_parentScene.ExternalChecks.ExternalChecksCanTakeObject(obj.UUID, remoteClient.AgentId))
  372. {
  373. // If the attachment point isn't the same as the one previously used
  374. // set it's offset position = 0 so that it appears on the attachment point
  375. // and not in a weird location somewhere unknown.
  376. if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint())
  377. {
  378. attachPos = LLVector3.Zero;
  379. }
  380. // AttachmentPt 0 means the client chose to 'wear' the attachment.
  381. if (AttachmentPt == 0)
  382. {
  383. // Check object for stored attachment point
  384. AttachmentPt = (uint)group.GetAttachmentPoint();
  385. }
  386. // if we still didn't find a suitable attachment point.......
  387. if (AttachmentPt == 0)
  388. {
  389. // Stick it on left hand with Zero Offset from the attachment point.
  390. AttachmentPt = (uint)AttachmentPoint.LeftHand;
  391. attachPos = LLVector3.Zero;
  392. }
  393. m_log.Debug("[ATTACH]: Using attachpoint: " + AttachmentPt.ToString());
  394. // Saves and gets assetID
  395. if (group.GetFromAssetID() == LLUUID.Zero)
  396. {
  397. LLUUID newAssetID = m_parentScene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId);
  398. // sets assetID so client can show asset as 'attached' in inventory
  399. group.SetFromAssetID(newAssetID);
  400. }
  401. group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos);
  402. }
  403. else
  404. {
  405. remoteClient.SendAgentAlertMessage("You don't have sufficient permissions to attach this object", false);
  406. }
  407. }
  408. }
  409. }
  410. }
  411. protected internal ScenePresence CreateAndAddScenePresence(IClientAPI client, bool child, AvatarAppearance appearance)
  412. {
  413. ScenePresence newAvatar = null;
  414. newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance);
  415. newAvatar.IsChildAgent = child;
  416. AddScenePresence(newAvatar);
  417. return newAvatar;
  418. }
  419. /// <summary>
  420. /// Add a presence to the scene
  421. /// </summary>
  422. /// <param name="presence"></param>
  423. protected internal void AddScenePresence(ScenePresence presence)
  424. {
  425. bool child = presence.IsChildAgent;
  426. if (child)
  427. {
  428. m_numChildAgents++;
  429. m_log.Info("[SCENE]" + m_regInfo.RegionName + ": Creating new child agent.");
  430. }
  431. else
  432. {
  433. m_numRootAgents++;
  434. m_log.Info("[SCENE] " + m_regInfo.RegionName + ": Creating new root agent.");
  435. m_log.Info("[SCENE] " + m_regInfo.RegionName + ": Adding Physical agent.");
  436. presence.AddToPhysicalScene();
  437. }
  438. lock (Entities)
  439. {
  440. Entities[presence.UUID] = presence;
  441. }
  442. lock (ScenePresences)
  443. {
  444. ScenePresences[presence.UUID] = presence;
  445. }
  446. }
  447. /// <summary>
  448. /// Remove a presence from the scene
  449. /// </summary>
  450. protected internal void RemoveScenePresence(LLUUID agentID)
  451. {
  452. lock (Entities)
  453. {
  454. if (Entities.Remove(agentID))
  455. {
  456. //m_log.InfoFormat("[SCENE] Removed scene presence {0} from entities list", agentID);
  457. }
  458. else
  459. {
  460. m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene Entities list", agentID);
  461. }
  462. }
  463. lock (ScenePresences)
  464. {
  465. if (ScenePresences.Remove(agentID))
  466. {
  467. //m_log.InfoFormat("[SCENE] Removed scene presence {0}", agentID);
  468. }
  469. else
  470. {
  471. m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
  472. }
  473. }
  474. }
  475. protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
  476. {
  477. if (direction_RC_CR_T_F)
  478. {
  479. m_numRootAgents--;
  480. m_numChildAgents++;
  481. }
  482. else
  483. {
  484. m_numChildAgents--;
  485. m_numRootAgents++;
  486. }
  487. }
  488. protected internal void removeUserCount(bool TypeRCTF)
  489. {
  490. if (TypeRCTF)
  491. {
  492. m_numRootAgents--;
  493. }
  494. else
  495. {
  496. m_numChildAgents--;
  497. }
  498. }
  499. protected internal int GetChildAgentCount()
  500. {
  501. // some network situations come in where child agents get closed twice.
  502. if (m_numChildAgents < 0)
  503. {
  504. m_numChildAgents = 0;
  505. }
  506. return m_numChildAgents;
  507. }
  508. protected internal int GetRootAgentCount()
  509. {
  510. return m_numRootAgents;
  511. }
  512. protected internal int GetTotalObjects()
  513. {
  514. return m_numPrim;
  515. }
  516. protected internal int GetActiveObjects()
  517. {
  518. return m_physicalPrim;
  519. }
  520. protected internal int GetActiveScripts()
  521. {
  522. return m_activeScripts;
  523. }
  524. protected internal int GetScriptLPS()
  525. {
  526. int returnval = m_scriptLPS;
  527. m_scriptLPS = 0;
  528. return returnval;
  529. }
  530. #endregion
  531. #region Get Methods
  532. /// <summary>
  533. /// Request a List of all m_scenePresences in this World
  534. /// </summary>
  535. /// <returns></returns>
  536. protected internal List<ScenePresence> GetScenePresences()
  537. {
  538. List<ScenePresence> result;
  539. lock (ScenePresences)
  540. {
  541. result = new List<ScenePresence>(ScenePresences.Values);
  542. }
  543. return result;
  544. }
  545. protected internal List<ScenePresence> GetAvatars()
  546. {
  547. List<ScenePresence> result =
  548. GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
  549. return result;
  550. }
  551. /// <summary>
  552. /// Get the controlling client for the given avatar, if there is one.
  553. ///
  554. /// FIXME: The only user of the method right now is Caps.cs, in order to resolve a client API since it can't
  555. /// use the ScenePresence. This could be better solved in a number of ways - we could establish an
  556. /// OpenSim.Framework.IScenePresence, or move the caps code into a region package (which might be the more
  557. /// suitable solution).
  558. /// </summary>
  559. /// <param name="agentId"></param>
  560. /// <returns>null if either the avatar wasn't in the scene, or they do not have a controlling client</returns>
  561. protected internal IClientAPI GetControllingClient(LLUUID agentId)
  562. {
  563. ScenePresence presence = GetScenePresence(agentId);
  564. if (presence != null)
  565. {
  566. return presence.ControllingClient;
  567. }
  568. return null;
  569. }
  570. /// <summary>
  571. /// Request a filtered list of m_scenePresences in this World
  572. /// </summary>
  573. /// <returns></returns>
  574. protected internal List<ScenePresence> GetScenePresences(FilterAvatarList filter)
  575. {
  576. // No locking of scene presences here since we're passing back a list...
  577. List<ScenePresence> result = new List<ScenePresence>();
  578. List<ScenePresence> ScenePresencesList = GetScenePresences();
  579. foreach (ScenePresence avatar in ScenePresencesList)
  580. {
  581. if (filter(avatar))
  582. {
  583. result.Add(avatar);
  584. }
  585. }
  586. return result;
  587. }
  588. /// <summary>
  589. /// Request a scene presence by UUID
  590. /// </summary>
  591. /// <param name="avatarID"></param>
  592. /// <returns>null if the agent was not found</returns>
  593. protected internal ScenePresence GetScenePresence(LLUUID agentID)
  594. {
  595. ScenePresence sp;
  596. ScenePresences.TryGetValue(agentID, out sp);
  597. return sp;
  598. }
  599. private SceneObjectGroup GetGroupByPrim(uint localID)
  600. {
  601. List<EntityBase> EntityList = GetEntities();
  602. foreach (EntityBase ent in EntityList)
  603. {
  604. if (ent is SceneObjectGroup)
  605. {
  606. if (((SceneObjectGroup)ent).HasChildPrim(localID))
  607. return (SceneObjectGroup)ent;
  608. }
  609. }
  610. return null;
  611. }
  612. private SceneObjectGroup GetGroupByPrim(LLUUID fullID)
  613. {
  614. List<EntityBase> EntityList = GetEntities();
  615. foreach (EntityBase ent in EntityList)
  616. {
  617. if (ent is SceneObjectGroup)
  618. {
  619. if (((SceneObjectGroup)ent).HasChildPrim(fullID))
  620. return (SceneObjectGroup)ent;
  621. }
  622. }
  623. return null;
  624. }
  625. protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
  626. {
  627. // Primitive Ray Tracing
  628. float closestDistance = 280f;
  629. EntityIntersection returnResult = new EntityIntersection();
  630. foreach (EntityBase ent in Entities.Values)
  631. {
  632. if (ent is SceneObjectGroup)
  633. {
  634. SceneObjectGroup reportingG = (SceneObjectGroup)ent;
  635. EntityIntersection result = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
  636. if (result.HitTF)
  637. {
  638. if (result.distance < closestDistance)
  639. {
  640. closestDistance = result.distance;
  641. returnResult = result;
  642. }
  643. }
  644. }
  645. }
  646. return returnResult;
  647. }
  648. protected internal SceneObjectPart GetSceneObjectPart(uint localID)
  649. {
  650. SceneObjectGroup group = GetGroupByPrim(localID);
  651. if (group != null)
  652. return group.GetChildPart(localID);
  653. else
  654. return null;
  655. }
  656. protected internal SceneObjectPart GetSceneObjectPart(LLUUID fullID)
  657. {
  658. SceneObjectGroup group = GetGroupByPrim(fullID);
  659. if (group != null)
  660. return group.GetChildPart(fullID);
  661. else
  662. return null;
  663. }
  664. protected internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar)
  665. {
  666. ScenePresence presence;
  667. if (ScenePresences.TryGetValue(avatarId, out presence))
  668. {
  669. if (!presence.IsChildAgent)
  670. {
  671. avatar = presence;
  672. return true;
  673. }
  674. else
  675. {
  676. m_log.WarnFormat(
  677. "[INNER SCENE]: Requested avatar {0} could not be found in scene {1} since it is only registered as a child agent!",
  678. avatarId, m_parentScene.RegionInfo.RegionName);
  679. }
  680. }
  681. avatar = null;
  682. return false;
  683. }
  684. protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
  685. {
  686. lock (ScenePresences)
  687. {
  688. foreach (ScenePresence presence in ScenePresences.Values)
  689. {
  690. if (!presence.IsChildAgent)
  691. {
  692. string name = presence.ControllingClient.Name;
  693. if (String.Compare(avatarName, name, true) == 0)
  694. {
  695. avatar = presence;
  696. return true;
  697. }
  698. }
  699. }
  700. }
  701. avatar = null;
  702. return false;
  703. }
  704. /// <summary>
  705. /// Returns a list of the entities in the scene. This is a new list so operations perform on the list itself
  706. /// will not affect the original list of objects in the scene.
  707. /// </summary>
  708. /// <returns></returns>
  709. protected internal List<EntityBase> GetEntities()
  710. {
  711. List<EntityBase> result;
  712. lock (Entities)
  713. {
  714. result = new List<EntityBase>(Entities.Values);
  715. }
  716. return result;
  717. }
  718. protected internal Dictionary<uint, float> GetTopScripts()
  719. {
  720. Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
  721. List<EntityBase> EntityList = GetEntities();
  722. int limit = 0;
  723. foreach (EntityBase ent in EntityList)
  724. {
  725. if (ent is SceneObjectGroup)
  726. {
  727. SceneObjectGroup grp = (SceneObjectGroup)ent;
  728. if ((grp.RootPart.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Scripted) != 0)
  729. {
  730. if (grp.scriptScore >= 0.01)
  731. {
  732. topScripts.Add(grp.LocalId, grp.scriptScore);
  733. limit++;
  734. if (limit >= 100)
  735. {
  736. break;
  737. }
  738. }
  739. grp.scriptScore = 0;
  740. }
  741. }
  742. }
  743. return topScripts;
  744. }
  745. #endregion
  746. #region Other Methods
  747. protected internal void physicsBasedCrash()
  748. {
  749. handlerPhysicsCrash = UnRecoverableError;
  750. if (handlerPhysicsCrash != null)
  751. {
  752. handlerPhysicsCrash();
  753. }
  754. }
  755. protected internal LLUUID ConvertLocalIDToFullID(uint localID)
  756. {
  757. SceneObjectGroup group = GetGroupByPrim(localID);
  758. if (group != null)
  759. return group.GetPartsFullID(localID);
  760. else
  761. return LLUUID.Zero;
  762. }
  763. protected internal void SendAllSceneObjectsToClient(ScenePresence presence)
  764. {
  765. List<EntityBase> EntityList = GetEntities();
  766. foreach (EntityBase ent in EntityList)
  767. {
  768. if (ent is SceneObjectGroup)
  769. {
  770. // Only send child agents stuff in their draw distance.
  771. // This will need to be done for every agent once we figure out
  772. // what we're going to use to store prim that agents already got
  773. // the initial update for and what we'll use to limit the
  774. // space we check for new objects on movement.
  775. if (presence.IsChildAgent && m_parentScene.m_seeIntoRegionFromNeighbor)
  776. {
  777. LLVector3 oLoc = ((SceneObjectGroup)ent).AbsolutePosition;
  778. float distResult = (float)Util.GetDistanceTo(presence.AbsolutePosition, oLoc);
  779. //m_log.Info("[DISTANCE]: " + distResult.ToString());
  780. if (distResult < presence.DrawDistance)
  781. {
  782. // Send Only if we don't already know about it.
  783. // KnownPrim also makes the prim known when called.
  784. if (!presence.KnownPrim(((SceneObjectGroup)ent).UUID))
  785. ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence);
  786. }
  787. }
  788. else
  789. {
  790. ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence);
  791. }
  792. }
  793. }
  794. }
  795. protected internal void ForEachClient(Action<IClientAPI> action)
  796. {
  797. lock (ScenePresences)
  798. {
  799. foreach (ScenePresence presence in ScenePresences.Values)
  800. {
  801. action(presence.ControllingClient);
  802. }
  803. }
  804. }
  805. #endregion
  806. #region Client Event handlers
  807. /// <summary>
  808. ///
  809. /// </summary>
  810. /// <param name="localID"></param>
  811. /// <param name="scale"></param>
  812. /// <param name="remoteClient"></param>
  813. protected internal void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
  814. {
  815. SceneObjectGroup group = GetGroupByPrim(localID);
  816. if (group != null)
  817. {
  818. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  819. {
  820. group.Resize(scale, localID);
  821. }
  822. }
  823. }
  824. protected internal void UpdatePrimGroupScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
  825. {
  826. SceneObjectGroup group = GetGroupByPrim(localID);
  827. if (group != null)
  828. {
  829. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  830. {
  831. group.GroupResize(scale, localID);
  832. }
  833. }
  834. }
  835. /// <summary>
  836. /// This handles the nifty little tool tip that you get when you drag your mouse over an object
  837. /// Send to the Object Group to process. We don't know enough to service the request
  838. /// </summary>
  839. /// <param name="remoteClient"></param>
  840. /// <param name="AgentID"></param>
  841. /// <param name="RequestFlags"></param>
  842. /// <param name="ObjectID"></param>
  843. protected internal void RequestObjectPropertiesFamily(
  844. IClientAPI remoteClient, LLUUID AgentID, uint RequestFlags, LLUUID ObjectID)
  845. {
  846. SceneObjectGroup group = GetGroupByPrim(ObjectID);
  847. if (group != null)
  848. {
  849. group.ServiceObjectPropertiesFamilyRequest(remoteClient, AgentID, RequestFlags);
  850. }
  851. }
  852. /// <summary>
  853. ///
  854. /// </summary>
  855. /// <param name="localID"></param>
  856. /// <param name="rot"></param>
  857. /// <param name="remoteClient"></param>
  858. protected internal void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
  859. {
  860. SceneObjectGroup group = GetGroupByPrim(localID);
  861. if (group != null)
  862. {
  863. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))
  864. {
  865. group.UpdateSingleRotation(rot, localID);
  866. }
  867. }
  868. }
  869. /// <summary>
  870. ///
  871. /// </summary>
  872. /// <param name="localID"></param>
  873. /// <param name="rot"></param>
  874. /// <param name="remoteClient"></param>
  875. protected internal void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
  876. {
  877. SceneObjectGroup group = GetGroupByPrim(localID);
  878. if (group != null)
  879. {
  880. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))
  881. {
  882. group.UpdateGroupRotation(rot);
  883. }
  884. }
  885. }
  886. /// <summary>
  887. ///
  888. /// </summary>
  889. /// <param name="localID"></param>
  890. /// <param name="pos"></param>
  891. /// <param name="rot"></param>
  892. /// <param name="remoteClient"></param>
  893. protected internal void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
  894. {
  895. SceneObjectGroup group = GetGroupByPrim(localID);
  896. if (group != null)
  897. {
  898. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))
  899. {
  900. group.UpdateGroupRotation(pos, rot);
  901. }
  902. }
  903. }
  904. protected internal void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
  905. {
  906. SceneObjectGroup group = GetGroupByPrim(localID);
  907. if (group != null)
  908. {
  909. LLVector3 oldPos = group.AbsolutePosition;
  910. if (!m_parentScene.ExternalChecks.ExternalChecksCanObjectEntry(group.UUID,pos) && !group.RootPart.m_IsAttachment)
  911. {
  912. group.SendGroupTerseUpdate();
  913. return;
  914. }
  915. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId) || group.RootPart.m_IsAttachment)
  916. {
  917. group.UpdateSinglePosition(pos, localID);
  918. }
  919. }
  920. }
  921. /// <summary>
  922. ///
  923. /// </summary>
  924. /// <param name="localID"></param>
  925. /// <param name="pos"></param>
  926. /// <param name="remoteClient"></param>
  927. protected internal void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
  928. {
  929. SceneObjectGroup group = GetGroupByPrim(localID);
  930. if (group != null)
  931. {
  932. LLVector3 oldPos = group.AbsolutePosition;
  933. if (group.RootPart.m_IsAttachment)
  934. {
  935. group.UpdateGroupPosition(pos);
  936. }
  937. else
  938. {
  939. if (!m_parentScene.ExternalChecks.ExternalChecksCanObjectEntry(group.UUID,pos) && !group.RootPart.m_IsAttachment)
  940. {
  941. group.SendGroupTerseUpdate();
  942. return;
  943. }
  944. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId) || group.RootPart.m_IsAttachment)
  945. {
  946. group.UpdateGroupPosition(pos);
  947. }
  948. }
  949. }
  950. }
  951. /// <summary>
  952. ///
  953. /// </summary>
  954. /// <param name="localID"></param>
  955. /// <param name="texture"></param>
  956. /// <param name="remoteClient"></param>
  957. protected internal void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
  958. {
  959. SceneObjectGroup group = GetGroupByPrim(localID);
  960. if (group != null)
  961. {
  962. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID,remoteClient.AgentId))
  963. {
  964. group.UpdateTextureEntry(localID, texture);
  965. }
  966. }
  967. }
  968. /// <summary>
  969. ///
  970. /// </summary>
  971. /// <param name="localID"></param>
  972. /// <param name="packet"></param>
  973. /// <param name="remoteClient"></param>
  974. protected internal void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
  975. {
  976. SceneObjectGroup group = GetGroupByPrim(localID);
  977. if (group != null)
  978. {
  979. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  980. {
  981. group.UpdatePrimFlags(localID, (ushort)packet.Type, true, packet.ToBytes());
  982. }
  983. }
  984. }
  985. protected internal void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
  986. {
  987. SceneObjectGroup group = GetGroupByPrim(objectID);
  988. if (group != null)
  989. {
  990. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
  991. {
  992. group.GrabMovement(offset, pos, remoteClient);
  993. }
  994. // This is outside the above permissions condition
  995. // so that if the object is locked the client moving the object
  996. // get's it's position on the simulator even if it was the same as before
  997. // This keeps the moving user's client in sync with the rest of the world.
  998. group.SendGroupTerseUpdate();
  999. }
  1000. }
  1001. /// <summary>
  1002. ///
  1003. /// </summary>
  1004. /// <param name="primLocalID"></param>
  1005. /// <param name="description"></param>
  1006. protected internal void PrimName(IClientAPI remoteClient, uint primLocalID, string name)
  1007. {
  1008. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1009. if (group != null)
  1010. {
  1011. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  1012. {
  1013. group.SetPartName(Util.CleanString(name), primLocalID);
  1014. }
  1015. }
  1016. }
  1017. /// <summary>
  1018. ///
  1019. /// </summary>
  1020. /// <param name="primLocalID"></param>
  1021. /// <param name="description"></param>
  1022. protected internal void PrimDescription(IClientAPI remoteClient, uint primLocalID, string description)
  1023. {
  1024. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1025. if (group != null)
  1026. {
  1027. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  1028. {
  1029. group.SetPartDescription(Util.CleanString(description), primLocalID);
  1030. }
  1031. }
  1032. }
  1033. protected internal void UpdateExtraParam(LLUUID agentID, uint primLocalID, ushort type, bool inUse, byte[] data)
  1034. {
  1035. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1036. if (group != null)
  1037. {
  1038. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID,agentID))
  1039. {
  1040. group.UpdateExtraParam(primLocalID, type, inUse, data);
  1041. }
  1042. }
  1043. }
  1044. /// <summary>
  1045. ///
  1046. /// </summary>
  1047. /// <param name="primLocalID"></param>
  1048. /// <param name="shapeBlock"></param>
  1049. protected internal void UpdatePrimShape(LLUUID agentID, uint primLocalID, UpdateShapeArgs shapeBlock)
  1050. {
  1051. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1052. if (group != null)
  1053. {
  1054. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.GetPartsFullID(primLocalID), agentID))
  1055. {
  1056. ObjectShapePacket.ObjectDataBlock shapeData = new ObjectShapePacket.ObjectDataBlock();
  1057. shapeData.ObjectLocalID = shapeBlock.ObjectLocalID;
  1058. shapeData.PathBegin = shapeBlock.PathBegin;
  1059. shapeData.PathCurve = shapeBlock.PathCurve;
  1060. shapeData.PathEnd = shapeBlock.PathEnd;
  1061. shapeData.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  1062. shapeData.PathRevolutions = shapeBlock.PathRevolutions;
  1063. shapeData.PathScaleX = shapeBlock.PathScaleX;
  1064. shapeData.PathScaleY = shapeBlock.PathScaleY;
  1065. shapeData.PathShearX = shapeBlock.PathShearX;
  1066. shapeData.PathShearY = shapeBlock.PathShearY;
  1067. shapeData.PathSkew = shapeBlock.PathSkew;
  1068. shapeData.PathTaperX = shapeBlock.PathTaperX;
  1069. shapeData.PathTaperY = shapeBlock.PathTaperY;
  1070. shapeData.PathTwist = shapeBlock.PathTwist;
  1071. shapeData.PathTwistBegin = shapeBlock.PathTwistBegin;
  1072. shapeData.ProfileBegin = shapeBlock.ProfileBegin;
  1073. shapeData.ProfileCurve = shapeBlock.ProfileCurve;
  1074. shapeData.ProfileEnd = shapeBlock.ProfileEnd;
  1075. shapeData.ProfileHollow = shapeBlock.ProfileHollow;
  1076. group.UpdateShape(shapeData, primLocalID);
  1077. }
  1078. }
  1079. }
  1080. /// <summary>
  1081. /// Initial method invoked when we receive a link objects request from the client.
  1082. /// </summary>
  1083. /// <param name="client"></param>
  1084. /// <param name="parentPrim"></param>
  1085. /// <param name="childPrims"></param>
  1086. protected internal void LinkObjects(IClientAPI client, uint parentPrim, List<uint> childPrims)
  1087. {
  1088. List<EntityBase> EntityList = GetEntities();
  1089. SceneObjectGroup parenPrim = null;
  1090. foreach (EntityBase ent in EntityList)
  1091. {
  1092. if (ent is SceneObjectGroup)
  1093. {
  1094. if (((SceneObjectGroup)ent).LocalId == parentPrim)
  1095. {
  1096. parenPrim = (SceneObjectGroup)ent;
  1097. break;
  1098. }
  1099. }
  1100. }
  1101. List<SceneObjectGroup> children = new List<SceneObjectGroup>();
  1102. if (parenPrim != null)
  1103. {
  1104. for (int i = 0; i < childPrims.Count; i++)
  1105. {
  1106. foreach (EntityBase ent in EntityList)
  1107. {
  1108. if (ent is SceneObjectGroup)
  1109. {
  1110. if (((SceneObjectGroup)ent).LocalId == childPrims[i])
  1111. {
  1112. children.Add((SceneObjectGroup)ent);
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. foreach (SceneObjectGroup sceneObj in children)
  1119. {
  1120. parenPrim.LinkToGroup(sceneObj);
  1121. }
  1122. // We need to explicitly resend the newly link prim's object properties since no other actions
  1123. // occur on link to invoke this elsewhere (such as object selection)
  1124. parenPrim.GetProperties(client);
  1125. }
  1126. /// <summary>
  1127. /// Delink a linkset
  1128. /// </summary>
  1129. /// <param name="prims"></param>
  1130. protected internal void DelinkObjects(List<uint> primIds)
  1131. {
  1132. SceneObjectGroup parenPrim = null;
  1133. // Need a list of the SceneObjectGroup local ids
  1134. // XXX I'm anticipating that building this dictionary once is more efficient than
  1135. // repeated scanning of the Entity.Values for a large number of primIds. However, it might
  1136. // be more efficient yet to keep this dictionary permanently on hand.
  1137. Dictionary<uint, SceneObjectGroup> sceneObjects = new Dictionary<uint, SceneObjectGroup>();
  1138. List<EntityBase> EntityList = GetEntities();
  1139. foreach (EntityBase ent in EntityList)
  1140. {
  1141. if (ent is SceneObjectGroup)
  1142. {
  1143. SceneObjectGroup obj = (SceneObjectGroup)ent;
  1144. sceneObjects.Add(obj.LocalId, obj);
  1145. }
  1146. }
  1147. // Find the root prim among the prim ids we've been given
  1148. for (int i = 0; i < primIds.Count; i++)
  1149. {
  1150. if (sceneObjects.ContainsKey(primIds[i]))
  1151. {
  1152. parenPrim = sceneObjects[primIds[i]];
  1153. primIds.RemoveAt(i);
  1154. break;
  1155. }
  1156. }
  1157. if (parenPrim != null)
  1158. {
  1159. foreach (uint childPrimId in primIds)
  1160. {
  1161. parenPrim.DelinkFromGroup(childPrimId);
  1162. }
  1163. }
  1164. else
  1165. {
  1166. // If the first scan failed, we need to do a /deep/ scan of the linkages. This is /really/ slow
  1167. // We know that this is not the root prim now essentially, so we don't have to worry about remapping
  1168. // which one is the root prim
  1169. bool delinkedSomething = false;
  1170. for (int i = 0; i < primIds.Count; i++)
  1171. {
  1172. foreach (SceneObjectGroup grp in sceneObjects.Values)
  1173. {
  1174. SceneObjectPart gPart = grp.GetChildPart(primIds[i]);
  1175. if (gPart != null)
  1176. {
  1177. grp.DelinkFromGroup(primIds[i]);
  1178. delinkedSomething = true;
  1179. }
  1180. }
  1181. }
  1182. if (!delinkedSomething)
  1183. {
  1184. m_log.InfoFormat("[SCENE]: " +
  1185. "DelinkObjects(): Could not find a root prim out of {0} as given to a delink request!",
  1186. primIds);
  1187. }
  1188. }
  1189. }
  1190. protected internal void MakeObjectSearchable(IClientAPI remoteClient, bool IncludeInSearch, uint localID)
  1191. {
  1192. LLUUID user = remoteClient.AgentId;
  1193. LLUUID objid = null;
  1194. SceneObjectPart obj = null;
  1195. List<EntityBase> EntityList = GetEntities();
  1196. foreach (EntityBase ent in EntityList)
  1197. {
  1198. if (ent is SceneObjectGroup)
  1199. {
  1200. foreach (KeyValuePair<LLUUID, SceneObjectPart> subent in ((SceneObjectGroup)ent).Children)
  1201. {
  1202. if (subent.Value.LocalId == localID)
  1203. {
  1204. objid = subent.Key;
  1205. obj = subent.Value;
  1206. }
  1207. }
  1208. }
  1209. }
  1210. //Protip: In my day, we didn't call them searchable objects, we called them limited point-to-point joints
  1211. //aka ObjectFlags.JointWheel = IncludeInSearch
  1212. //Permissions model: Object can be REMOVED from search IFF:
  1213. // * User owns object
  1214. //use CanEditObject
  1215. //Object can be ADDED to search IFF:
  1216. // * User owns object
  1217. // * Asset/DRM permission bit "modify" is enabled
  1218. //use CanEditObjectPosition
  1219. if (IncludeInSearch && m_parentScene.ExternalChecks.ExternalChecksCanEditObject(objid, user))
  1220. {
  1221. obj.ParentGroup.RootPart.AddFlag(LLObject.ObjectFlags.JointWheel);
  1222. }
  1223. else if (!IncludeInSearch && m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(objid,user))
  1224. {
  1225. obj.ParentGroup.RootPart.RemFlag(LLObject.ObjectFlags.JointWheel);
  1226. }
  1227. }
  1228. /// <summary>
  1229. /// Duplicate the given object.
  1230. /// </summary>
  1231. /// <param name="originalPrim"></param>
  1232. /// <param name="offset"></param>
  1233. /// <param name="flags"></param>
  1234. protected internal void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags, LLUUID AgentID, LLUUID GroupID)
  1235. {
  1236. //m_log.DebugFormat("[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", originalPrim, offset, AgentID);
  1237. List<EntityBase> EntityList = GetEntities();
  1238. SceneObjectGroup originPrim = null;
  1239. foreach (EntityBase ent in EntityList)
  1240. {
  1241. if (ent is SceneObjectGroup)
  1242. {
  1243. if (((SceneObjectGroup)ent).LocalId == originalPrim)
  1244. {
  1245. originPrim = (SceneObjectGroup)ent;
  1246. break;
  1247. }
  1248. }
  1249. }
  1250. if (originPrim != null)
  1251. {
  1252. if (m_parentScene.ExternalChecks.ExternalChecksCanDuplicateObject(originPrim.Children.Count, originPrim.UUID, AgentID, originPrim.AbsolutePosition))
  1253. {
  1254. SceneObjectGroup copy = originPrim.Copy(AgentID, GroupID, true);
  1255. copy.AbsolutePosition = copy.AbsolutePosition + offset;
  1256. copy.ResetIDs();
  1257. lock (Entities)
  1258. {
  1259. Entities.Add(copy.UUID, copy);
  1260. }
  1261. // Since we copy from a source group that is in selected
  1262. // state, but the copy is shown deselected in the viewer,
  1263. // We need to clear the selection flag here, else that
  1264. // prim never gets persisted at all. The client doesn't
  1265. // think it's selected, so it will never send a deselect...
  1266. copy.IsSelected = false;
  1267. m_numPrim++;
  1268. copy.StartScripts();
  1269. copy.ScheduleGroupForFullUpdate();
  1270. }
  1271. }
  1272. else
  1273. {
  1274. m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
  1275. }
  1276. }
  1277. /// <summary>
  1278. /// Calculates the distance between two Vector3s
  1279. /// </summary>
  1280. /// <param name="v1"></param>
  1281. /// <param name="v2"></param>
  1282. /// <returns></returns>
  1283. protected internal float Vector3Distance(Vector3 v1, Vector3 v2)
  1284. {
  1285. // We don't really need the double floating point precision...
  1286. // so casting it to a single
  1287. return
  1288. (float)
  1289. Math.Sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y) + (v1.z - v2.z) * (v1.z - v2.z));
  1290. }
  1291. #endregion
  1292. }
  1293. }