aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs6
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityInventory.cs3
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs4
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEstateModule.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/IInterregionComms.cs8
-rw-r--r--OpenSim/Region/Framework/Interfaces/IScriptModule.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISnmpModule.cs27
-rw-r--r--OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs13
-rw-r--r--OpenSim/Region/Framework/ModuleLoader.cs3
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs220
-rw-r--r--OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs7
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/Prioritizer.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs355
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs3
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Permissions.cs17
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs446
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs50
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs224
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs7
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs563
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs228
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs794
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs1395
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs23
-rw-r--r--OpenSim/Region/Framework/Scenes/UndoState.cs87
-rw-r--r--OpenSim/Region/Framework/Scenes/UuidGatherer.cs4
29 files changed, 3256 insertions, 1267 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
index e668dae..a7770ad 100644
--- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using OpenMetaverse; 31using OpenMetaverse;
31using OpenSim.Framework; 32using OpenSim.Framework;
@@ -75,6 +76,10 @@ namespace OpenSim.Region.Framework.Interfaces
75 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns> 76 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
76 ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt); 77 ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt);
77 78
79 // Same as above, but also load script states from a separate doc
80 ISceneEntity RezSingleAttachmentFromInventory(
81 IScenePresence presence, UUID itemID, uint AttachmentPt, bool updateInventoryStatus, XmlDocument doc);
82
78 /// <summary> 83 /// <summary>
79 /// Rez multiple attachments from a user's inventory 84 /// Rez multiple attachments from a user's inventory
80 /// </summary> 85 /// </summary>
@@ -96,7 +101,6 @@ namespace OpenSim.Region.Framework.Interfaces
96 /// <param name="itemID"></param> 101 /// <param name="itemID"></param>
97 void DetachSingleAttachmentToInv(IScenePresence sp, UUID itemID); 102 void DetachSingleAttachmentToInv(IScenePresence sp, UUID itemID);
98 103
99 /// <summary>
100 /// Update the position of an attachment. 104 /// Update the position of an attachment.
101 /// </summary> 105 /// </summary>
102 /// <param name="sog"></param> 106 /// <param name="sog"></param>
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
index 15060fd..4b17b9a 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
@@ -115,6 +115,8 @@ namespace OpenSim.Region.Framework.Interfaces
115 /// <param name="stateSource"></param> 115 /// <param name="stateSource"></param>
116 void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource); 116 void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
117 117
118 ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
119
118 /// <summary> 120 /// <summary>
119 /// Stop a script which is in this prim's inventory. 121 /// Stop a script which is in this prim's inventory.
120 /// </summary> 122 /// </summary>
@@ -229,5 +231,6 @@ namespace OpenSim.Region.Framework.Interfaces
229 /// A <see cref="Dictionary`2"/> 231 /// A <see cref="Dictionary`2"/>
230 /// </returns> 232 /// </returns>
231 Dictionary<UUID, string> GetScriptStates(); 233 Dictionary<UUID, string> GetScriptStates();
234 Dictionary<UUID, string> GetScriptStates(bool oldIDs);
232 } 235 }
233} 236}
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
index 07e97d5..c38ecd9 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
@@ -40,11 +40,11 @@ namespace OpenSim.Region.Framework.Interfaces
40 void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, 40 void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position,
41 Vector3 lookAt, uint teleportFlags); 41 Vector3 lookAt, uint teleportFlags);
42 42
43 bool TeleportHome(UUID id, IClientAPI client);
44
43 void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, 45 void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination,
44 Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq); 46 Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq);
45 47
46 void TeleportHome(UUID id, IClientAPI client);
47
48 bool Cross(ScenePresence agent, bool isFlying); 48 bool Cross(ScenePresence agent, bool isFlying);
49 49
50 void AgentArrivedAtDestination(UUID agent); 50 void AgentArrivedAtDestination(UUID agent);
diff --git a/OpenSim/Region/Framework/Interfaces/IEstateModule.cs b/OpenSim/Region/Framework/Interfaces/IEstateModule.cs
index 721f0ee..72e79ed 100644
--- a/OpenSim/Region/Framework/Interfaces/IEstateModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEstateModule.cs
@@ -45,5 +45,7 @@ namespace OpenSim.Region.Framework.Interfaces
45 /// Tell all clients about the current state of the region (terrain textures, water height, etc.). 45 /// Tell all clients about the current state of the region (terrain textures, water height, etc.).
46 /// </summary> 46 /// </summary>
47 void sendRegionHandshakeToAll(); 47 void sendRegionHandshakeToAll();
48 void TriggerEstateInfoChange();
49 void TriggerRegionInfoChange();
48 } 50 }
49} 51}
diff --git a/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs b/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs
index 2d6287f..67a500f 100644
--- a/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs
+++ b/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs
@@ -68,6 +68,14 @@ namespace OpenSim.Region.Framework.Interfaces
68 bool SendReleaseAgent(ulong regionHandle, UUID id, string uri); 68 bool SendReleaseAgent(ulong regionHandle, UUID id, string uri);
69 69
70 /// <summary> 70 /// <summary>
71 /// Close chid agent.
72 /// </summary>
73 /// <param name="regionHandle"></param>
74 /// <param name="id"></param>
75 /// <returns></returns>
76 bool SendCloseChildAgent(ulong regionHandle, UUID id);
77
78 /// <summary>
71 /// Close agent. 79 /// Close agent.
72 /// </summary> 80 /// </summary>
73 /// <param name="regionHandle"></param> 81 /// <param name="regionHandle"></param>
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
index b27b7da..7dde586 100644
--- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
@@ -51,6 +51,8 @@ namespace OpenSim.Region.Framework.Interfaces
51 51
52 ArrayList GetScriptErrors(UUID itemID); 52 ArrayList GetScriptErrors(UUID itemID);
53 53
54 bool HasScript(UUID itemID, out bool running);
55
54 void SaveAllState(); 56 void SaveAllState();
55 57
56 /// <summary> 58 /// <summary>
diff --git a/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs b/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs
new file mode 100644
index 0000000..e01f649
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs
@@ -0,0 +1,27 @@
1///////////////////////////////////////////////////////////////////
2//
3// (c) Careminster LImited, Melanie Thielker and the Meta7 Team
4//
5// This file is not open source. All rights reserved
6// Mod 2
7
8using OpenSim.Region.Framework.Scenes;
9
10public interface ISnmpModule
11{
12 void Trap(int code, string Message, Scene scene);
13 void Critical(string Message, Scene scene);
14 void Warning(string Message, Scene scene);
15 void Major(string Message, Scene scene);
16 void ColdStart(int step , Scene scene);
17 void Shutdown(int step , Scene scene);
18 //
19 // Node Start/stop events
20 //
21 void LinkUp(Scene scene);
22 void LinkDown(Scene scene);
23 void BootInfo(string data, Scene scene);
24 void trapDebug(string Module,string data, Scene scene);
25 void trapXMRE(int data, string Message, Scene scene);
26
27}
diff --git a/OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs b/OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs
new file mode 100644
index 0000000..d1a4d8e
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs
@@ -0,0 +1,13 @@
1///////////////////////////////////////////////////////////////////
2//
3// (c) Careminster Limited, Melanie Thielker and the Meta7 Team
4//
5// This file is not open source. All rights reserved
6//
7
8using OpenSim.Region.Framework.Scenes;
9
10public interface IUserAccountCacheModule
11{
12 void Remove(string name);
13}
diff --git a/OpenSim/Region/Framework/ModuleLoader.cs b/OpenSim/Region/Framework/ModuleLoader.cs
index 14ecd44..32ee674 100644
--- a/OpenSim/Region/Framework/ModuleLoader.cs
+++ b/OpenSim/Region/Framework/ModuleLoader.cs
@@ -227,7 +227,8 @@ namespace OpenSim.Region.Framework
227 pluginAssembly.FullName, e.Message, e.StackTrace); 227 pluginAssembly.FullName, e.Message, e.StackTrace);
228 228
229 // justincc: Right now this is fatal to really get the user's attention 229 // justincc: Right now this is fatal to really get the user's attention
230 throw e; 230 // TomMeta: WTF? No, how about we /don't/ throw a fatal exception when there's no need to?
231 //throw e;
231 } 232 }
232 } 233 }
233 234
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index e9e1845..904a657 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -57,11 +57,17 @@ namespace OpenSim.Region.Framework.Scenes.Animation
57 { 57 {
58 get { return m_movementAnimation; } 58 get { return m_movementAnimation; }
59 } 59 }
60 protected string m_movementAnimation = "DEFAULT"; 60 // protected string m_movementAnimation = "DEFAULT"; //KF: 'DEFAULT' does not exist!
61 61 protected string m_movementAnimation = "CROUCH"; //KF: CROUCH ensures reliable Av Anim. init.
62 private int m_animTickFall; 62 private int m_animTickFall;
63 private int m_animTickJump; 63// private int m_animTickJump;
64 64 public int m_animTickJump; // ScenePresence has to see this to control +Z force
65 public bool m_jumping = false; // Add for jumping
66 public float m_jumpVelocity = 0f; // Add for jumping
67 private int m_landing = 0; // Add for jumping
68 public bool m_falling = false; // Add for falling
69 private float m_fallHeight; // Add for falling
70
65 /// <value> 71 /// <value>
66 /// The scene presence that this animator applies to 72 /// The scene presence that this animator applies to
67 /// </value> 73 /// </value>
@@ -122,7 +128,9 @@ namespace OpenSim.Region.Framework.Scenes.Animation
122 128
123 public void ResetAnimations() 129 public void ResetAnimations()
124 { 130 {
131Console.WriteLine("ResetA.............");
125 m_animations.Clear(); 132 m_animations.Clear();
133TrySetMovementAnimation("STAND");
126 } 134 }
127 135
128 /// <summary> 136 /// <summary>
@@ -152,14 +160,14 @@ namespace OpenSim.Region.Framework.Scenes.Animation
152 /// </summary> 160 /// </summary>
153 public string GetMovementAnimation() 161 public string GetMovementAnimation()
154 { 162 {
155 const float FALL_DELAY = 0.33f; 163//Console.WriteLine("GMA-------"); //##
156 const float PREJUMP_DELAY = 0.25f; 164//#@ const float FALL_DELAY = 0.33f;
157 165 const float FALL_DELAY = 800f; //## mS
166//rm for jumping const float PREJUMP_DELAY = 0.25f;
167 const float PREJUMP_DELAY = 200f; // mS add for jumping
168 const float JUMP_PERIOD = 800f; // mS add for jumping
158 #region Inputs 169 #region Inputs
159 if (m_scenePresence.SitGround) 170
160 {
161 return "SIT_GROUND_CONSTRAINED";
162 }
163 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; 171 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
164 PhysicsActor actor = m_scenePresence.PhysicsActor; 172 PhysicsActor actor = m_scenePresence.PhysicsActor;
165 173
@@ -169,11 +177,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
169 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); 177 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
170 178
171 // Check control flags 179 // Check control flags
172 bool heldForward = 180 bool heldForward = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS);
173 (((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) || ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS)); 181 bool heldBack = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG);
174 bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG; 182 bool heldLeft = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS);
175 bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS; 183 bool heldRight = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG);
176 bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG;
177 bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; 184 bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
178 bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; 185 bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
179 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; 186 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
@@ -192,8 +199,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
192 199
193 // Is the avatar trying to move? 200 // Is the avatar trying to move?
194// bool moving = (move != Vector3.Zero); 201// bool moving = (move != Vector3.Zero);
195 bool jumping = m_animTickJump != 0; 202// rm for jumping bool jumping = m_animTickJump != 0;
196
197 #endregion Inputs 203 #endregion Inputs
198 204
199 #region Flying 205 #region Flying
@@ -202,6 +208,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation
202 { 208 {
203 m_animTickFall = 0; 209 m_animTickFall = 0;
204 m_animTickJump = 0; 210 m_animTickJump = 0;
211 m_jumping = false; //add for jumping
212 m_falling = true; //add for falling
213 m_jumpVelocity = 0f; //add for jumping
214 actor.Selected = false; //add for jumping flag
215 m_fallHeight = actor.Position.Z; // save latest flying height
205 216
206 if (move.X != 0f || move.Y != 0f) 217 if (move.X != 0f || move.Y != 0f)
207 { 218 {
@@ -213,8 +224,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation
213 } 224 }
214 else if (move.Z < 0f) 225 else if (move.Z < 0f)
215 { 226 {
216 if (actor != null && actor.IsColliding) 227 if (actor != null && actor.IsColliding)
228 { //##
229//Console.WriteLine("LAND FLYING"); // ##
217 return "LAND"; 230 return "LAND";
231 } //#
218 else 232 else
219 return "HOVER_DOWN"; 233 return "HOVER_DOWN";
220 } 234 }
@@ -228,48 +242,127 @@ namespace OpenSim.Region.Framework.Scenes.Animation
228 242
229 #region Falling/Floating/Landing 243 #region Falling/Floating/Landing
230 244
231 if (actor == null || !actor.IsColliding) 245// rm for jumping if (actor == null || !actor.IsColliding)
246 if ((actor == null || !actor.IsColliding) && !m_jumping) // add for jumping
232 { 247 {
233 float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; 248// rm float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
249 float fallElapsed = (float)(Environment.TickCount - m_animTickFall); // add, in mS
234 float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f; 250 float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f;
251//Console.WriteLine("falling t={0} v={1}", fallElapsed, fallVelocity); //##
235 252
236 if (m_animTickFall == 0 || (fallElapsed > FALL_DELAY && fallVelocity >= 0.0f)) 253// rm for fall if (m_animTickFall == 0 || (fallElapsed > FALL_DELAY && fallVelocity >= 0.0f))
254 if (!m_jumping && (fallVelocity < -3.0f) ) m_falling = true; // add for falling and jumping
255
256 if (m_animTickFall == 0 || (fallVelocity >= 0.0f)) // add for jumping
257 // not falling yet or going up
237 { 258 {
238 // Just started falling 259 // reset start of fall time
239 m_animTickFall = Environment.TickCount; 260 m_animTickFall = Environment.TickCount;
240 } 261 }
241 else if (!jumping && fallElapsed > FALL_DELAY) 262// else if (!jumping && fallElapsed > FALL_DELAY)
263 else if (!m_jumping && (fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f) && (m_scenePresence.m_wasFlying)) // add for falling and jumping
242 { 264 {
243 // Falling long enough to trigger the animation 265 // Falling long enough to trigger the animation
266//Console.WriteLine("FALLDOWN"); //##
244 return "FALLDOWN"; 267 return "FALLDOWN";
245 } 268 }
246 else if (m_animTickJump == -1)
247 {
248 m_animTickJump = 0;
249 return "STAND";
250 }
251 269
252 return m_movementAnimation; 270 return m_movementAnimation;
253 } 271 }
254 272
255 #endregion Falling/Floating/Landing 273 #endregion Falling/Floating/Landing
256 274
275
276 #region Jumping // section added for jumping...
277
278 int jumptime;
279 jumptime = Environment.TickCount - m_animTickJump;
280
281
282 if ((move.Z > 0f) && (!m_jumping))
283 {
284//Console.WriteLine("PJ {0}", jumptime); //##
285 // Start jumping, prejump
286 m_animTickFall = 0;
287 m_jumping = true;
288 m_falling = false;
289 actor.Selected = true; // borrowed for jmping flag
290 m_animTickJump = Environment.TickCount;
291 m_jumpVelocity = 0.35f;
292 return "PREJUMP";
293 }
294
295 if(m_jumping)
296 {
297 if ( (jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding)
298 {
299//Console.WriteLine("LA {0}", jumptime); //##
300 // end jumping
301 m_jumping = false;
302 m_falling = false;
303 actor.Selected = false; // borrowed for jumping flag
304 m_jumpVelocity = 0f;
305 m_animTickFall = Environment.TickCount;
306 return "LAND";
307 }
308 else if (jumptime > JUMP_PERIOD)
309 {
310//Console.WriteLine("JD {0}", jumptime); //##
311 // jump down
312 m_jumpVelocity = 0f;
313 return "JUMP";
314 }
315 else if (jumptime > PREJUMP_DELAY)
316 {
317//Console.WriteLine("JU {0}", jumptime); //##
318 // jump up
319 m_jumping = true;
320 m_jumpVelocity = 10f;
321 return "JUMP";
322 }
323 }
324
325 #endregion Jumping // end added section
326
257 #region Ground Movement 327 #region Ground Movement
258 328
259 if (m_movementAnimation == "FALLDOWN") 329 if (m_movementAnimation == "FALLDOWN")
260 { 330 {
331 m_falling = false;
261 m_animTickFall = Environment.TickCount; 332 m_animTickFall = Environment.TickCount;
262
263 // TODO: SOFT_LAND support 333 // TODO: SOFT_LAND support
264 return "LAND"; 334 float fallHeight = m_fallHeight - actor.Position.Z;
335//Console.WriteLine("Hit from {0}", fallHeight); //##
336 if (fallHeight > 15.0f) // add for falling
337 return "STANDUP";
338 else if (fallHeight > 8.0f) // add for falling
339 return "SOFT_LAND"; // add for falling
340 else // add for falling
341 return "LAND"; // add for falling
265 } 342 }
266 else if (m_movementAnimation == "LAND") 343// rm jumping float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
344// rm jumping if ((m_animTickFall != 0) && (landElapsed <= FALL_DELAY))
345// rm for landing return "LAND";
346 else if ((m_movementAnimation == "LAND") || (m_movementAnimation == "SOFT_LAND") || (m_movementAnimation == "STANDUP"))
267 { 347 {
268 float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; 348 int landElapsed = Environment.TickCount - m_animTickFall; // add for jumping
269 if ((m_animTickFall != 0) && (landElapsed <= FALL_DELAY)) 349 int limit = 1000; // add for jumping
270 return "LAND"; 350 if(m_movementAnimation == "LAND") limit = 350; // add for jumping
271 } 351 // NB if the above is set too long a weird anim reset from some place prevents STAND from being sent to client
272 352
353 if ((m_animTickFall != 0) && (landElapsed <= limit)) // add for jumping
354 {
355//Console.WriteLine("Lelapse {0}", m_movementAnimation); //##
356 return m_movementAnimation;
357 }
358 else
359 {
360//Console.WriteLine("end/STAND"); //##
361 m_fallHeight = actor.Position.Z; // save latest flying height
362 return "STAND";
363 }
364 }
365/* This section removed, replaced by jumping section
273 m_animTickFall = 0; 366 m_animTickFall = 0;
274 367
275 if (move.Z > 0.2f) 368 if (move.Z > 0.2f)
@@ -281,7 +374,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
281 m_animTickJump = Environment.TickCount; 374 m_animTickJump = Environment.TickCount;
282 return "PREJUMP"; 375 return "PREJUMP";
283 } 376 }
284 else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f) 377 else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 800.0f)
285 { 378 {
286 // Start actual jump 379 // Start actual jump
287 if (m_animTickJump == -1) 380 if (m_animTickJump == -1)
@@ -294,24 +387,22 @@ namespace OpenSim.Region.Framework.Scenes.Animation
294 m_animTickJump = -1; 387 m_animTickJump = -1;
295 return "JUMP"; 388 return "JUMP";
296 } 389 }
297 else
298 return "JUMP";
299 } 390 }
300 else 391 else
301 { 392 {
302 // Not jumping 393 // Not jumping
303 m_animTickJump = 0; 394 m_animTickJump = 0;
304 395 */
305 if (move.X != 0f || move.Y != 0f) 396 // next section moved outside paren. and realigned for jumping
306 { 397 if (move.X != 0f || move.Y != 0f)
307 // Walking / crouchwalking / running 398 {
308 if (move.Z < 0) 399 m_fallHeight = actor.Position.Z; // save latest flying height
309 return "CROUCHWALK"; 400 m_falling = false; // Add for falling
310 else if (m_scenePresence.SetAlwaysRun) 401 // Walking / crouchwalking / running
311 return "RUN"; 402 if (move.Z < 0f)
312 else 403 return "CROUCHWALK";
313 return "WALK"; 404 else if (m_scenePresence.SetAlwaysRun)
314 } 405 return "RUN";
315 else 406 else
316 { 407 {
317 // Not walking 408 // Not walking
@@ -322,13 +413,24 @@ namespace OpenSim.Region.Framework.Scenes.Animation
322 else if (heldTurnRight) 413 else if (heldTurnRight)
323 return "TURNRIGHT"; 414 return "TURNRIGHT";
324 else 415 else
325 return "STAND"; 416 return "WALK";
326 } 417 }
327 } 418 }
328 419// rm for jumping else
420 else if (!m_jumping) // add for jumping
421 {
422 m_falling = false; // Add for falling
423 // Not walking
424 if (move.Z < 0f)
425 return "CROUCH";
426 else
427 return "STAND";
428 }
429 // end section realign for jumping
329 #endregion Ground Movement 430 #endregion Ground Movement
330 431
331 //return m_movementAnimation; 432 m_falling = false; // Add for falling
433 return m_movementAnimation;
332 } 434 }
333 435
334 /// <summary> 436 /// <summary>
@@ -337,9 +439,15 @@ namespace OpenSim.Region.Framework.Scenes.Animation
337 public void UpdateMovementAnimations() 439 public void UpdateMovementAnimations()
338 { 440 {
339 m_movementAnimation = GetMovementAnimation(); 441 m_movementAnimation = GetMovementAnimation();
340// m_log.DebugFormat( 442/* if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump)
341// "[SCENE PRESENCE ANIMATOR]: Got animation {0} for {1}", m_movementAnimation, m_scenePresence.Name); 443 {
342 TrySetMovementAnimation(m_movementAnimation); 444 // This was the previous behavior before PREJUMP
445 TrySetMovementAnimation("JUMP");
446 }
447 else
448 { removed for jumping */
449 TrySetMovementAnimation(m_movementAnimation);
450// rm for jumping }
343 } 451 }
344 452
345 public UUID[] GetAnimationArray() 453 public UUID[] GetAnimationArray()
diff --git a/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs b/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
index 0ac3899..12688bd 100644
--- a/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
+++ b/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
@@ -104,8 +104,15 @@ namespace OpenSim.Region.Framework.Scenes
104 // better than losing the object for now. 104 // better than losing the object for now.
105 if (permissionToDelete) 105 if (permissionToDelete)
106 { 106 {
107 List<uint> killIDs = new List<uint>();
108
107 foreach (SceneObjectGroup g in objectGroups) 109 foreach (SceneObjectGroup g in objectGroups)
110 {
111 killIDs.Add(g.LocalId);
108 g.DeleteGroupFromScene(false); 112 g.DeleteGroupFromScene(false);
113 }
114
115 m_scene.SendKillObject(killIDs);
109 } 116 }
110 } 117 }
111 118
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 96da2c3..65c6a29 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -55,8 +55,12 @@ namespace OpenSim.Region.Framework.Scenes
55 55
56 public delegate void OnTerrainTickDelegate(); 56 public delegate void OnTerrainTickDelegate();
57 57
58 public delegate void OnTerrainUpdateDelegate();
59
58 public event OnTerrainTickDelegate OnTerrainTick; 60 public event OnTerrainTickDelegate OnTerrainTick;
59 61
62 public event OnTerrainUpdateDelegate OnTerrainUpdate;
63
60 public delegate void OnBackupDelegate(ISimulationDataService datastore, bool forceBackup); 64 public delegate void OnBackupDelegate(ISimulationDataService datastore, bool forceBackup);
61 65
62 public event OnBackupDelegate OnBackup; 66 public event OnBackupDelegate OnBackup;
@@ -775,6 +779,26 @@ namespace OpenSim.Region.Framework.Scenes
775 } 779 }
776 } 780 }
777 } 781 }
782 public void TriggerTerrainUpdate()
783 {
784 OnTerrainUpdateDelegate handlerTerrainUpdate = OnTerrainUpdate;
785 if (handlerTerrainUpdate != null)
786 {
787 foreach (OnTerrainUpdateDelegate d in handlerTerrainUpdate.GetInvocationList())
788 {
789 try
790 {
791 d();
792 }
793 catch (Exception e)
794 {
795 m_log.ErrorFormat(
796 "[EVENT MANAGER]: Delegate for TriggerTerrainUpdate failed - continuing. {0} {1}",
797 e.Message, e.StackTrace);
798 }
799 }
800 }
801 }
778 802
779 public void TriggerTerrainTick() 803 public void TriggerTerrainTick()
780 { 804 {
diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
index 1b10e3c..0a34a4c 100644
--- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs
+++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
@@ -157,7 +157,7 @@ namespace OpenSim.Region.Framework.Scenes
157 157
158 private uint GetPriorityByBestAvatarResponsiveness(IClientAPI client, ISceneEntity entity) 158 private uint GetPriorityByBestAvatarResponsiveness(IClientAPI client, ISceneEntity entity)
159 { 159 {
160 uint pqueue = ComputeDistancePriority(client,entity,true); 160 uint pqueue = ComputeDistancePriority(client,entity,false);
161 161
162 ScenePresence presence = m_scene.GetScenePresence(client.AgentId); 162 ScenePresence presence = m_scene.GetScenePresence(client.AgentId);
163 if (presence != null) 163 if (presence != null)
@@ -226,7 +226,7 @@ namespace OpenSim.Region.Framework.Scenes
226 226
227 for (int i = 0; i < queues - 1; i++) 227 for (int i = 0; i < queues - 1; i++)
228 { 228 {
229 if (distance < 10 * Math.Pow(2.0,i)) 229 if (distance < 30 * Math.Pow(2.0,i))
230 break; 230 break;
231 pqueue++; 231 pqueue++;
232 } 232 }
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 663aa22..53f0f2e 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -124,34 +124,22 @@ namespace OpenSim.Region.Framework.Scenes
124 /// <param name="item"></param> 124 /// <param name="item"></param>
125 public bool AddInventoryItem(InventoryItemBase item) 125 public bool AddInventoryItem(InventoryItemBase item)
126 { 126 {
127 if (UUID.Zero == item.Folder) 127 InventoryFolderBase folder;
128
129 if (item.Folder == UUID.Zero)
128 { 130 {
129 InventoryFolderBase f = InventoryService.GetFolderForType(item.Owner, (AssetType)item.AssetType); 131 folder = InventoryService.GetFolderForType(item.Owner, (AssetType)item.AssetType);
130 if (f != null) 132 if (folder == null)
131 { 133 {
132// m_log.DebugFormat( 134 folder = InventoryService.GetRootFolder(item.Owner);
133// "[LOCAL INVENTORY SERVICES CONNECTOR]: Found folder {0} type {1} for item {2}", 135
134// f.Name, (AssetType)f.Type, item.Name); 136 if (folder == null)
135
136 item.Folder = f.ID;
137 }
138 else
139 {
140 f = InventoryService.GetRootFolder(item.Owner);
141 if (f != null)
142 {
143 item.Folder = f.ID;
144 }
145 else
146 {
147 m_log.WarnFormat(
148 "[AGENT INVENTORY]: Could not find root folder for {0} when trying to add item {1} with no parent folder specified",
149 item.Owner, item.Name);
150 return false; 137 return false;
151 }
152 } 138 }
139
140 item.Folder = folder.ID;
153 } 141 }
154 142
155 if (InventoryService.AddItem(item)) 143 if (InventoryService.AddItem(item))
156 { 144 {
157 int userlevel = 0; 145 int userlevel = 0;
@@ -271,8 +259,7 @@ namespace OpenSim.Region.Framework.Scenes
271 259
272 // Update item with new asset 260 // Update item with new asset
273 item.AssetID = asset.FullID; 261 item.AssetID = asset.FullID;
274 if (group.UpdateInventoryItem(item)) 262 group.UpdateInventoryItem(item);
275 remoteClient.SendAgentAlertMessage("Script saved", false);
276 263
277 part.SendPropertiesToClient(remoteClient); 264 part.SendPropertiesToClient(remoteClient);
278 265
@@ -283,12 +270,7 @@ namespace OpenSim.Region.Framework.Scenes
283 { 270 {
284 // Needs to determine which engine was running it and use that 271 // Needs to determine which engine was running it and use that
285 // 272 //
286 part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0); 273 errors = part.Inventory.CreateScriptInstanceEr(item.ItemID, 0, false, DefaultScriptEngine, 0);
287 errors = part.Inventory.GetScriptErrors(item.ItemID);
288 }
289 else
290 {
291 remoteClient.SendAgentAlertMessage("Script saved", false);
292 } 274 }
293 part.ParentGroup.ResumeScripts(); 275 part.ParentGroup.ResumeScripts();
294 return errors; 276 return errors;
@@ -351,6 +333,7 @@ namespace OpenSim.Region.Framework.Scenes
351 { 333 {
352 if (UUID.Zero == transactionID) 334 if (UUID.Zero == transactionID)
353 { 335 {
336 item.Flags = (item.Flags & ~(uint)255) | (itemUpd.Flags & (uint)255);
354 item.Name = itemUpd.Name; 337 item.Name = itemUpd.Name;
355 item.Description = itemUpd.Description; 338 item.Description = itemUpd.Description;
356 if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions)) 339 if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions))
@@ -728,6 +711,8 @@ namespace OpenSim.Region.Framework.Scenes
728 return; 711 return;
729 } 712 }
730 713
714 if (newName == null) newName = item.Name;
715
731 AssetBase asset = AssetService.Get(item.AssetID.ToString()); 716 AssetBase asset = AssetService.Get(item.AssetID.ToString());
732 717
733 if (asset != null) 718 if (asset != null)
@@ -784,6 +769,24 @@ namespace OpenSim.Region.Framework.Scenes
784 } 769 }
785 770
786 /// <summary> 771 /// <summary>
772 /// Move an item within the agent's inventory, and leave a copy (used in making a new outfit)
773 /// </summary>
774 public void MoveInventoryItemsLeaveCopy(IClientAPI remoteClient, List<InventoryItemBase> items, UUID destfolder)
775 {
776 List<InventoryItemBase> moveitems = new List<InventoryItemBase>();
777 foreach (InventoryItemBase b in items)
778 {
779 CopyInventoryItem(remoteClient, 0, remoteClient.AgentId, b.ID, b.Folder, null);
780 InventoryItemBase n = InventoryService.GetItem(b);
781 n.Folder = destfolder;
782 moveitems.Add(n);
783 remoteClient.SendInventoryItemCreateUpdate(n, 0);
784 }
785
786 MoveInventoryItem(remoteClient, moveitems);
787 }
788
789 /// <summary>
787 /// Move an item within the agent's inventory. 790 /// Move an item within the agent's inventory.
788 /// </summary> 791 /// </summary>
789 /// <param name="remoteClient"></param> 792 /// <param name="remoteClient"></param>
@@ -984,25 +987,29 @@ namespace OpenSim.Region.Framework.Scenes
984 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) 987 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
985 { 988 {
986 SceneObjectPart part = GetSceneObjectPart(localID); 989 SceneObjectPart part = GetSceneObjectPart(localID);
987 if (part == null) 990 SceneObjectGroup group = null;
988 return; 991 if (part != null)
992 {
993 group = part.ParentGroup;
994 }
995 if (part != null && group != null)
996 {
997 if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
998 return;
989 999
990 SceneObjectGroup group = part.ParentGroup; 1000 TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
991 if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)) 1001 if (item == null)
992 return; 1002 return;
993
994 TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
995 if (item == null)
996 return;
997 1003
998 if (item.Type == 10) 1004 if (item.Type == 10)
999 { 1005 {
1000 part.RemoveScriptEvents(itemID); 1006 part.RemoveScriptEvents(itemID);
1001 EventManager.TriggerRemoveScript(localID, itemID); 1007 EventManager.TriggerRemoveScript(localID, itemID);
1008 }
1009
1010 group.RemoveInventoryItem(localID, itemID);
1011 part.SendPropertiesToClient(remoteClient);
1002 } 1012 }
1003
1004 group.RemoveInventoryItem(localID, itemID);
1005 part.SendPropertiesToClient(remoteClient);
1006 } 1013 }
1007 1014
1008 private InventoryItemBase CreateAgentInventoryItemFromTask(UUID destAgent, SceneObjectPart part, UUID itemId) 1015 private InventoryItemBase CreateAgentInventoryItemFromTask(UUID destAgent, SceneObjectPart part, UUID itemId)
@@ -1213,6 +1220,10 @@ namespace OpenSim.Region.Framework.Scenes
1213 if ((part.OwnerID != destPart.OwnerID) && ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)) 1220 if ((part.OwnerID != destPart.OwnerID) && ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
1214 return; 1221 return;
1215 1222
1223 bool overrideNoMod = false;
1224 if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) != 0)
1225 overrideNoMod = true;
1226
1216 if (part.OwnerID != destPart.OwnerID && (part.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0) 1227 if (part.OwnerID != destPart.OwnerID && (part.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
1217 { 1228 {
1218 // object cannot copy items to an object owned by a different owner 1229 // object cannot copy items to an object owned by a different owner
@@ -1222,7 +1233,7 @@ namespace OpenSim.Region.Framework.Scenes
1222 } 1233 }
1223 1234
1224 // must have both move and modify permission to put an item in an object 1235 // must have both move and modify permission to put an item in an object
1225 if ((part.OwnerMask & ((uint)PermissionMask.Move | (uint)PermissionMask.Modify)) == 0) 1236 if (((part.OwnerMask & (uint)PermissionMask.Modify) == 0) && (!overrideNoMod))
1226 { 1237 {
1227 return; 1238 return;
1228 } 1239 }
@@ -1281,6 +1292,14 @@ namespace OpenSim.Region.Framework.Scenes
1281 1292
1282 public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items) 1293 public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
1283 { 1294 {
1295 SceneObjectPart destPart = GetSceneObjectPart(destID);
1296 if (destPart != null) // Move into a prim
1297 {
1298 foreach(UUID itemID in items)
1299 MoveTaskInventoryItem(destID, host, itemID);
1300 return destID; // Prim folder ID == prim ID
1301 }
1302
1284 InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID); 1303 InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
1285 1304
1286 UUID newFolderID = UUID.Random(); 1305 UUID newFolderID = UUID.Random();
@@ -1460,13 +1479,6 @@ namespace OpenSim.Region.Framework.Scenes
1460 { 1479 {
1461 agentTransactions.HandleTaskItemUpdateFromTransaction( 1480 agentTransactions.HandleTaskItemUpdateFromTransaction(
1462 remoteClient, part, transactionID, currentItem); 1481 remoteClient, part, transactionID, currentItem);
1463
1464 if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
1465 remoteClient.SendAgentAlertMessage("Notecard saved", false);
1466 else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
1467 remoteClient.SendAgentAlertMessage("Script saved", false);
1468 else
1469 remoteClient.SendAgentAlertMessage("Item saved", false);
1470 } 1482 }
1471 1483
1472 // Base ALWAYS has move 1484 // Base ALWAYS has move
@@ -1607,7 +1619,7 @@ namespace OpenSim.Region.Framework.Scenes
1607 return; 1619 return;
1608 1620
1609 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, 1621 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
1610 Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"), 1622 Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n\n touch_start(integer num)\n {\n }\n}"),
1611 remoteClient.AgentId); 1623 remoteClient.AgentId);
1612 AssetService.Store(asset); 1624 AssetService.Store(asset);
1613 1625
@@ -1760,23 +1772,32 @@ namespace OpenSim.Region.Framework.Scenes
1760 // build a list of eligible objects 1772 // build a list of eligible objects
1761 List<uint> deleteIDs = new List<uint>(); 1773 List<uint> deleteIDs = new List<uint>();
1762 List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>(); 1774 List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>();
1763 1775 List<SceneObjectGroup> takeGroups = new List<SceneObjectGroup>();
1764 // Start with true for both, then remove the flags if objects
1765 // that we can't derez are part of the selection
1766 bool permissionToTake = true;
1767 bool permissionToTakeCopy = true;
1768 bool permissionToDelete = true;
1769 1776
1770 foreach (uint localID in localIDs) 1777 foreach (uint localID in localIDs)
1771 { 1778 {
1779 // Start with true for both, then remove the flags if objects
1780 // that we can't derez are part of the selection
1781 bool permissionToTake = true;
1782 bool permissionToTakeCopy = true;
1783 bool permissionToDelete = true;
1784
1772 // Invalid id 1785 // Invalid id
1773 SceneObjectPart part = GetSceneObjectPart(localID); 1786 SceneObjectPart part = GetSceneObjectPart(localID);
1774 if (part == null) 1787 if (part == null)
1788 {
1789 //Client still thinks the object exists, kill it
1790 deleteIDs.Add(localID);
1775 continue; 1791 continue;
1792 }
1776 1793
1777 // Already deleted by someone else 1794 // Already deleted by someone else
1778 if (part.ParentGroup.IsDeleted) 1795 if (part.ParentGroup.IsDeleted)
1796 {
1797 //Client still thinks the object exists, kill it
1798 deleteIDs.Add(localID);
1779 continue; 1799 continue;
1800 }
1780 1801
1781 // Can't delete child prims 1802 // Can't delete child prims
1782 if (part != part.ParentGroup.RootPart) 1803 if (part != part.ParentGroup.RootPart)
@@ -1784,9 +1805,6 @@ namespace OpenSim.Region.Framework.Scenes
1784 1805
1785 SceneObjectGroup grp = part.ParentGroup; 1806 SceneObjectGroup grp = part.ParentGroup;
1786 1807
1787 deleteIDs.Add(localID);
1788 deleteGroups.Add(grp);
1789
1790 if (remoteClient == null) 1808 if (remoteClient == null)
1791 { 1809 {
1792 // Autoreturn has a null client. Nothing else does. So 1810 // Autoreturn has a null client. Nothing else does. So
@@ -1803,81 +1821,193 @@ namespace OpenSim.Region.Framework.Scenes
1803 } 1821 }
1804 else 1822 else
1805 { 1823 {
1806 if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId)) 1824 if (action == DeRezAction.TakeCopy)
1825 {
1826 if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId))
1827 permissionToTakeCopy = false;
1828 }
1829 else
1830 {
1807 permissionToTakeCopy = false; 1831 permissionToTakeCopy = false;
1808 1832 }
1809 if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId)) 1833 if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId))
1810 permissionToTake = false; 1834 permissionToTake = false;
1811 1835
1812 if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId)) 1836 if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId))
1813 permissionToDelete = false; 1837 permissionToDelete = false;
1814 } 1838 }
1815 }
1816 1839
1817 // Handle god perms 1840 // Handle god perms
1818 if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId)) 1841 if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
1819 { 1842 {
1820 permissionToTake = true; 1843 permissionToTake = true;
1821 permissionToTakeCopy = true; 1844 permissionToTakeCopy = true;
1822 permissionToDelete = true; 1845 permissionToDelete = true;
1823 } 1846 }
1824 1847
1825 // If we're re-saving, we don't even want to delete 1848 // If we're re-saving, we don't even want to delete
1826 if (action == DeRezAction.SaveToExistingUserInventoryItem) 1849 if (action == DeRezAction.SaveToExistingUserInventoryItem)
1827 permissionToDelete = false; 1850 permissionToDelete = false;
1828 1851
1829 // if we want to take a copy, we also don't want to delete 1852 // if we want to take a copy, we also don't want to delete
1830 // Note: after this point, the permissionToTakeCopy flag 1853 // Note: after this point, the permissionToTakeCopy flag
1831 // becomes irrelevant. It already includes the permissionToTake 1854 // becomes irrelevant. It already includes the permissionToTake
1832 // permission and after excluding no copy items here, we can 1855 // permission and after excluding no copy items here, we can
1833 // just use that. 1856 // just use that.
1834 if (action == DeRezAction.TakeCopy) 1857 if (action == DeRezAction.TakeCopy)
1835 { 1858 {
1836 // If we don't have permission, stop right here 1859 // If we don't have permission, stop right here
1837 if (!permissionToTakeCopy) 1860 if (!permissionToTakeCopy)
1838 return; 1861 return;
1839 1862
1840 permissionToTake = true; 1863 permissionToTake = true;
1841 // Don't delete 1864 // Don't delete
1842 permissionToDelete = false; 1865 permissionToDelete = false;
1843 } 1866 }
1844 1867
1845 if (action == DeRezAction.Return) 1868 if (action == DeRezAction.Return)
1846 {
1847 if (remoteClient != null)
1848 { 1869 {
1849 if (Permissions.CanReturnObjects( 1870 if (remoteClient != null)
1850 null,
1851 remoteClient.AgentId,
1852 deleteGroups))
1853 { 1871 {
1854 permissionToTake = true; 1872 if (Permissions.CanReturnObjects(
1855 permissionToDelete = true; 1873 null,
1856 1874 remoteClient.AgentId,
1857 foreach (SceneObjectGroup g in deleteGroups) 1875 deleteGroups))
1858 { 1876 {
1859 AddReturn(g.OwnerID, g.Name, g.AbsolutePosition, "parcel owner return"); 1877 permissionToTake = true;
1878 permissionToDelete = true;
1879
1880 AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return");
1860 } 1881 }
1861 } 1882 }
1883 else // Auto return passes through here with null agent
1884 {
1885 permissionToTake = true;
1886 permissionToDelete = true;
1887 }
1862 } 1888 }
1863 else // Auto return passes through here with null agent 1889
1890 if (permissionToTake && (!permissionToDelete))
1891 takeGroups.Add(grp);
1892
1893 if (permissionToDelete)
1864 { 1894 {
1865 permissionToTake = true; 1895 if (permissionToTake)
1866 permissionToDelete = true; 1896 deleteGroups.Add(grp);
1897 deleteIDs.Add(grp.LocalId);
1867 } 1898 }
1868 } 1899 }
1869 1900
1870 if (permissionToTake) 1901 SendKillObject(deleteIDs);
1902
1903 if (deleteGroups.Count > 0)
1871 { 1904 {
1905 foreach (SceneObjectGroup g in deleteGroups)
1906 deleteIDs.Remove(g.LocalId);
1907
1872 m_asyncSceneObjectDeleter.DeleteToInventory( 1908 m_asyncSceneObjectDeleter.DeleteToInventory(
1873 action, destinationID, deleteGroups, remoteClient, 1909 action, destinationID, deleteGroups, remoteClient,
1874 permissionToDelete); 1910 true);
1875 } 1911 }
1876 else if (permissionToDelete) 1912 if (takeGroups.Count > 0)
1913 {
1914 m_asyncSceneObjectDeleter.DeleteToInventory(
1915 action, destinationID, takeGroups, remoteClient,
1916 false);
1917 }
1918 if (deleteIDs.Count > 0)
1877 { 1919 {
1878 foreach (SceneObjectGroup g in deleteGroups) 1920 foreach (SceneObjectGroup g in deleteGroups)
1879 DeleteSceneObject(g, false); 1921 DeleteSceneObject(g, true);
1922 }
1923 }
1924
1925 public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
1926 {
1927 itemID = UUID.Zero;
1928 if (grp != null)
1929 {
1930 Vector3 inventoryStoredPosition = new Vector3
1931 (((grp.AbsolutePosition.X > (int)Constants.RegionSize)
1932 ? 250
1933 : grp.AbsolutePosition.X)
1934 ,
1935 (grp.AbsolutePosition.X > (int)Constants.RegionSize)
1936 ? 250
1937 : grp.AbsolutePosition.X,
1938 grp.AbsolutePosition.Z);
1939
1940 Vector3 originalPosition = grp.AbsolutePosition;
1941
1942 grp.AbsolutePosition = inventoryStoredPosition;
1943
1944 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
1945
1946 grp.AbsolutePosition = originalPosition;
1947
1948 AssetBase asset = CreateAsset(
1949 grp.GetPartName(grp.LocalId),
1950 grp.GetPartDescription(grp.LocalId),
1951 (sbyte)AssetType.Object,
1952 Utils.StringToBytes(sceneObjectXml),
1953 remoteClient.AgentId);
1954 AssetService.Store(asset);
1955
1956 InventoryItemBase item = new InventoryItemBase();
1957 item.CreatorId = grp.RootPart.CreatorID.ToString();
1958 item.CreatorData = grp.RootPart.CreatorData;
1959 item.Owner = remoteClient.AgentId;
1960 item.ID = UUID.Random();
1961 item.AssetID = asset.FullID;
1962 item.Description = asset.Description;
1963 item.Name = asset.Name;
1964 item.AssetType = asset.Type;
1965 item.InvType = (int)InventoryType.Object;
1966
1967 InventoryFolderBase folder = InventoryService.GetFolderForType(remoteClient.AgentId, AssetType.Object);
1968 if (folder != null)
1969 item.Folder = folder.ID;
1970 else // oopsies
1971 item.Folder = UUID.Zero;
1972
1973 // Set up base perms properly
1974 uint permsBase = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify);
1975 permsBase &= grp.RootPart.BaseMask;
1976 permsBase |= (uint)PermissionMask.Move;
1977
1978 // Make sure we don't lock it
1979 grp.RootPart.NextOwnerMask |= (uint)PermissionMask.Move;
1980
1981 if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
1982 {
1983 item.BasePermissions = permsBase & grp.RootPart.NextOwnerMask;
1984 item.CurrentPermissions = permsBase & grp.RootPart.NextOwnerMask;
1985 item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
1986 item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
1987 item.GroupPermissions = permsBase & grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
1988 }
1989 else
1990 {
1991 item.BasePermissions = permsBase;
1992 item.CurrentPermissions = permsBase & grp.RootPart.OwnerMask;
1993 item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
1994 item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask;
1995 item.GroupPermissions = permsBase & grp.RootPart.GroupMask;
1996 }
1997 item.CreationDate = Util.UnixTimeSinceEpoch();
1998
1999 // sets itemID so client can show item as 'attached' in inventory
2000 grp.SetFromItemID(item.ID);
2001
2002 if (AddInventoryItem(item))
2003 remoteClient.SendInventoryItemCreateUpdate(item, 0);
2004 else
2005 m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
2006
2007 itemID = item.ID;
2008 return item.AssetID;
1880 } 2009 }
2010 return UUID.Zero;
1881 } 2011 }
1882 2012
1883 /// <summary> 2013 /// <summary>
@@ -2006,6 +2136,9 @@ namespace OpenSim.Region.Framework.Scenes
2006 2136
2007 public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running) 2137 public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
2008 { 2138 {
2139 if (!Permissions.CanEditScript(itemID, objectID, controllingClient.AgentId))
2140 return;
2141
2009 SceneObjectPart part = GetSceneObjectPart(objectID); 2142 SceneObjectPart part = GetSceneObjectPart(objectID);
2010 if (part == null) 2143 if (part == null)
2011 return; 2144 return;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
index 270e582..575079f 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
@@ -374,7 +374,10 @@ namespace OpenSim.Region.Framework.Scenes
374 List<UserAccount> accounts = UserAccountService.GetUserAccounts(RegionInfo.ScopeID, query); 374 List<UserAccount> accounts = UserAccountService.GetUserAccounts(RegionInfo.ScopeID, query);
375 375
376 if (accounts == null) 376 if (accounts == null)
377 {
378 m_log.DebugFormat("[LLCIENT]: ProcessAvatarPickerRequest: returned null result");
377 return; 379 return;
380 }
378 381
379 AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply); 382 AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
380 // TODO: don't create new blocks if recycling an old packet 383 // TODO: don't create new blocks if recycling an old packet
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
index e1fedf4..48beb9c 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
@@ -49,6 +49,7 @@ namespace OpenSim.Region.Framework.Scenes
49 public delegate bool DuplicateObjectHandler(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition); 49 public delegate bool DuplicateObjectHandler(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition);
50 public delegate bool EditObjectHandler(UUID objectID, UUID editorID, Scene scene); 50 public delegate bool EditObjectHandler(UUID objectID, UUID editorID, Scene scene);
51 public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene); 51 public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene);
52 public delegate bool ViewObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene);
52 public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene); 53 public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene);
53 public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene); 54 public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene);
54 public delegate bool ReturnObjectsHandler(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene); 55 public delegate bool ReturnObjectsHandler(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene);
@@ -116,6 +117,7 @@ namespace OpenSim.Region.Framework.Scenes
116 public event DuplicateObjectHandler OnDuplicateObject; 117 public event DuplicateObjectHandler OnDuplicateObject;
117 public event EditObjectHandler OnEditObject; 118 public event EditObjectHandler OnEditObject;
118 public event EditObjectInventoryHandler OnEditObjectInventory; 119 public event EditObjectInventoryHandler OnEditObjectInventory;
120 public event ViewObjectInventoryHandler OnViewObjectInventory;
119 public event MoveObjectHandler OnMoveObject; 121 public event MoveObjectHandler OnMoveObject;
120 public event ObjectEntryHandler OnObjectEntry; 122 public event ObjectEntryHandler OnObjectEntry;
121 public event ReturnObjectsHandler OnReturnObjects; 123 public event ReturnObjectsHandler OnReturnObjects;
@@ -401,6 +403,21 @@ namespace OpenSim.Region.Framework.Scenes
401 return true; 403 return true;
402 } 404 }
403 405
406 public bool CanViewObjectInventory(UUID objectID, UUID editorID)
407 {
408 ViewObjectInventoryHandler handler = OnViewObjectInventory;
409 if (handler != null)
410 {
411 Delegate[] list = handler.GetInvocationList();
412 foreach (ViewObjectInventoryHandler h in list)
413 {
414 if (h(objectID, editorID, m_scene) == false)
415 return false;
416 }
417 }
418 return true;
419 }
420
404 #endregion 421 #endregion
405 422
406 #region MOVE OBJECT 423 #region MOVE OBJECT
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index b1755ac..cd4b14d 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -93,6 +93,7 @@ namespace OpenSim.Region.Framework.Scenes
93 // TODO: need to figure out how allow client agents but deny 93 // TODO: need to figure out how allow client agents but deny
94 // root agents when ACL denies access to root agent 94 // root agents when ACL denies access to root agent
95 public bool m_strictAccessControl = true; 95 public bool m_strictAccessControl = true;
96 public bool m_seeIntoBannedRegion = false;
96 public int MaxUndoCount = 5; 97 public int MaxUndoCount = 5;
97 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 98 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
98 public bool LoginLock = false; 99 public bool LoginLock = false;
@@ -108,12 +109,14 @@ namespace OpenSim.Region.Framework.Scenes
108 109
109 protected int m_splitRegionID; 110 protected int m_splitRegionID;
110 protected Timer m_restartWaitTimer = new Timer(); 111 protected Timer m_restartWaitTimer = new Timer();
112 protected Timer m_timerWatchdog = new Timer();
111 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 113 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
112 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 114 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
113 protected string m_simulatorVersion = "OpenSimulator Server"; 115 protected string m_simulatorVersion = "OpenSimulator Server";
114 protected ModuleLoader m_moduleLoader; 116 protected ModuleLoader m_moduleLoader;
115 protected AgentCircuitManager m_authenticateHandler; 117 protected AgentCircuitManager m_authenticateHandler;
116 protected SceneCommunicationService m_sceneGridService; 118 protected SceneCommunicationService m_sceneGridService;
119 protected ISnmpModule m_snmpService = null;
117 120
118 protected ISimulationDataService m_SimulationDataService; 121 protected ISimulationDataService m_SimulationDataService;
119 protected IEstateDataService m_EstateDataService; 122 protected IEstateDataService m_EstateDataService;
@@ -180,7 +183,7 @@ namespace OpenSim.Region.Framework.Scenes
180 private int m_update_events = 1; 183 private int m_update_events = 1;
181 private int m_update_backup = 200; 184 private int m_update_backup = 200;
182 private int m_update_terrain = 50; 185 private int m_update_terrain = 50;
183// private int m_update_land = 1; 186 private int m_update_land = 10;
184 private int m_update_coarse_locations = 50; 187 private int m_update_coarse_locations = 50;
185 188
186 private int agentMS; 189 private int agentMS;
@@ -195,14 +198,17 @@ namespace OpenSim.Region.Framework.Scenes
195 private int landMS; 198 private int landMS;
196 private int lastCompletedFrame; 199 private int lastCompletedFrame;
197 200
201 public bool CombineRegions = false;
198 private bool m_physics_enabled = true; 202 private bool m_physics_enabled = true;
199 private bool m_scripts_enabled = true; 203 private bool m_scripts_enabled = true;
200 private string m_defaultScriptEngine; 204 private string m_defaultScriptEngine;
201 private int m_LastLogin; 205 private int m_LastLogin;
202 private Thread HeartbeatThread; 206 private Thread HeartbeatThread = null;
203 private volatile bool shuttingdown; 207 private volatile bool shuttingdown;
204 208
205 private int m_lastUpdate; 209 private int m_lastUpdate;
210 private int m_lastIncoming;
211 private int m_lastOutgoing;
206 private bool m_firstHeartbeat = true; 212 private bool m_firstHeartbeat = true;
207 213
208 private object m_deleting_scene_object = new object(); 214 private object m_deleting_scene_object = new object();
@@ -255,6 +261,19 @@ namespace OpenSim.Region.Framework.Scenes
255 get { return m_sceneGridService; } 261 get { return m_sceneGridService; }
256 } 262 }
257 263
264 public ISnmpModule SnmpService
265 {
266 get
267 {
268 if (m_snmpService == null)
269 {
270 m_snmpService = RequestModuleInterface<ISnmpModule>();
271 }
272
273 return m_snmpService;
274 }
275 }
276
258 public ISimulationDataService SimulationDataService 277 public ISimulationDataService SimulationDataService
259 { 278 {
260 get 279 get
@@ -583,7 +602,10 @@ namespace OpenSim.Region.Framework.Scenes
583 m_regInfo = regInfo; 602 m_regInfo = regInfo;
584 m_regionHandle = m_regInfo.RegionHandle; 603 m_regionHandle = m_regInfo.RegionHandle;
585 m_regionName = m_regInfo.RegionName; 604 m_regionName = m_regInfo.RegionName;
605 m_datastore = m_regInfo.DataStore;
586 m_lastUpdate = Util.EnvironmentTickCount(); 606 m_lastUpdate = Util.EnvironmentTickCount();
607 m_lastIncoming = 0;
608 m_lastOutgoing = 0;
587 609
588 m_physicalPrim = physicalPrim; 610 m_physicalPrim = physicalPrim;
589 m_seeIntoRegionFromNeighbor = SeeIntoRegionFromNeighbor; 611 m_seeIntoRegionFromNeighbor = SeeIntoRegionFromNeighbor;
@@ -715,9 +737,10 @@ namespace OpenSim.Region.Framework.Scenes
715 //Animation states 737 //Animation states
716 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 738 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
717 // TODO: Change default to true once the feature is supported 739 // TODO: Change default to true once the feature is supported
718 m_usePreJump = startupConfig.GetBoolean("enableprejump", false); 740 m_usePreJump = startupConfig.GetBoolean("enableprejump", true);
719
720 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 741 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
742
743 m_log.DebugFormat("[SCENE]: prejump is {0}", m_usePreJump ? "ON" : "OFF");
721 if (RegionInfo.NonphysPrimMax > 0) 744 if (RegionInfo.NonphysPrimMax > 0)
722 { 745 {
723 m_maxNonphys = RegionInfo.NonphysPrimMax; 746 m_maxNonphys = RegionInfo.NonphysPrimMax;
@@ -749,6 +772,7 @@ namespace OpenSim.Region.Framework.Scenes
749 m_persistAfter *= 10000000; 772 m_persistAfter *= 10000000;
750 773
751 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 774 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
775 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
752 776
753 IConfig packetConfig = m_config.Configs["PacketPool"]; 777 IConfig packetConfig = m_config.Configs["PacketPool"];
754 if (packetConfig != null) 778 if (packetConfig != null)
@@ -758,6 +782,8 @@ namespace OpenSim.Region.Framework.Scenes
758 } 782 }
759 783
760 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 784 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
785 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
786 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
761 787
762 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 788 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
763 if (m_generateMaptiles) 789 if (m_generateMaptiles)
@@ -782,9 +808,9 @@ namespace OpenSim.Region.Framework.Scenes
782 } 808 }
783 } 809 }
784 } 810 }
785 catch 811 catch (Exception e)
786 { 812 {
787 m_log.Warn("[SCENE]: Failed to load StartupConfig"); 813 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
788 } 814 }
789 815
790 #endregion Region Config 816 #endregion Region Config
@@ -1161,7 +1187,9 @@ namespace OpenSim.Region.Framework.Scenes
1161 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1187 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1162 if (HeartbeatThread != null) 1188 if (HeartbeatThread != null)
1163 { 1189 {
1190 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1164 HeartbeatThread.Abort(); 1191 HeartbeatThread.Abort();
1192 Watchdog.RemoveThread(HeartbeatThread.ManagedThreadId);
1165 HeartbeatThread = null; 1193 HeartbeatThread = null;
1166 } 1194 }
1167 m_lastUpdate = Util.EnvironmentTickCount(); 1195 m_lastUpdate = Util.EnvironmentTickCount();
@@ -1204,9 +1232,6 @@ namespace OpenSim.Region.Framework.Scenes
1204 { 1232 {
1205 while (!shuttingdown) 1233 while (!shuttingdown)
1206 Update(); 1234 Update();
1207
1208 m_lastUpdate = Util.EnvironmentTickCount();
1209 m_firstHeartbeat = false;
1210 } 1235 }
1211 catch (ThreadAbortException) 1236 catch (ThreadAbortException)
1212 { 1237 {
@@ -1305,6 +1330,13 @@ namespace OpenSim.Region.Framework.Scenes
1305 eventMS = Util.EnvironmentTickCountSubtract(evMS); ; 1330 eventMS = Util.EnvironmentTickCountSubtract(evMS); ;
1306 } 1331 }
1307 1332
1333 // if (Frame % m_update_land == 0)
1334 // {
1335 // int ldMS = Util.EnvironmentTickCount();
1336 // UpdateLand();
1337 // landMS = Util.EnvironmentTickCountSubtract(ldMS);
1338 // }
1339
1308 if (Frame % m_update_backup == 0) 1340 if (Frame % m_update_backup == 0)
1309 { 1341 {
1310 int backMS = Util.EnvironmentTickCount(); 1342 int backMS = Util.EnvironmentTickCount();
@@ -1406,12 +1438,16 @@ namespace OpenSim.Region.Framework.Scenes
1406 maintc = Util.EnvironmentTickCountSubtract(maintc); 1438 maintc = Util.EnvironmentTickCountSubtract(maintc);
1407 maintc = (int)(m_minFrameTimespan * 1000) - maintc; 1439 maintc = (int)(m_minFrameTimespan * 1000) - maintc;
1408 1440
1441
1442 m_lastUpdate = Util.EnvironmentTickCount();
1443 m_firstHeartbeat = false;
1444
1409 if (maintc > 0) 1445 if (maintc > 0)
1410 Thread.Sleep(maintc); 1446 Thread.Sleep(maintc);
1411 1447
1412 // Tell the watchdog that this thread is still alive 1448 // Tell the watchdog that this thread is still alive
1413 Watchdog.UpdateThread(); 1449 Watchdog.UpdateThread();
1414 } 1450 }
1415 1451
1416 public void AddGroupTarget(SceneObjectGroup grp) 1452 public void AddGroupTarget(SceneObjectGroup grp)
1417 { 1453 {
@@ -1427,9 +1463,9 @@ namespace OpenSim.Region.Framework.Scenes
1427 1463
1428 private void CheckAtTargets() 1464 private void CheckAtTargets()
1429 { 1465 {
1430 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1466 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1431 lock (m_groupsWithTargets) 1467 lock (m_groupsWithTargets)
1432 objs = m_groupsWithTargets.Values; 1468 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1433 1469
1434 foreach (SceneObjectGroup entry in objs) 1470 foreach (SceneObjectGroup entry in objs)
1435 entry.checkAtTargets(); 1471 entry.checkAtTargets();
@@ -1749,14 +1785,24 @@ namespace OpenSim.Region.Framework.Scenes
1749 /// <returns></returns> 1785 /// <returns></returns>
1750 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1786 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1751 { 1787 {
1788
1789 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1790 Vector3 wpos = Vector3.Zero;
1791 // Check for water surface intersection from above
1792 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1793 {
1794 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1795 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1796 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1797 wpos.Z = wheight;
1798 }
1799
1752 Vector3 pos = Vector3.Zero; 1800 Vector3 pos = Vector3.Zero;
1753 if (RayEndIsIntersection == (byte)1) 1801 if (RayEndIsIntersection == (byte)1)
1754 { 1802 {
1755 pos = RayEnd; 1803 pos = RayEnd;
1756 return pos;
1757 } 1804 }
1758 1805 else if (RayTargetID != UUID.Zero)
1759 if (RayTargetID != UUID.Zero)
1760 { 1806 {
1761 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1807 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1762 1808
@@ -1778,7 +1824,7 @@ namespace OpenSim.Region.Framework.Scenes
1778 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1824 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1779 1825
1780 // Un-comment out the following line to Get Raytrace results printed to the console. 1826 // Un-comment out the following line to Get Raytrace results printed to the console.
1781 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1827 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1782 float ScaleOffset = 0.5f; 1828 float ScaleOffset = 0.5f;
1783 1829
1784 // If we hit something 1830 // If we hit something
@@ -1801,13 +1847,10 @@ namespace OpenSim.Region.Framework.Scenes
1801 //pos.Z -= 0.25F; 1847 //pos.Z -= 0.25F;
1802 1848
1803 } 1849 }
1804
1805 return pos;
1806 } 1850 }
1807 else 1851 else
1808 { 1852 {
1809 // We don't have a target here, so we're going to raytrace all the objects in the scene. 1853 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1810
1811 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 1854 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1812 1855
1813 // Un-comment the following line to print the raytrace results to the console. 1856 // Un-comment the following line to print the raytrace results to the console.
@@ -1816,13 +1859,12 @@ namespace OpenSim.Region.Framework.Scenes
1816 if (ei.HitTF) 1859 if (ei.HitTF)
1817 { 1860 {
1818 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 1861 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1819 } else 1862 }
1863 else
1820 { 1864 {
1821 // fall back to our stupid functionality 1865 // fall back to our stupid functionality
1822 pos = RayEnd; 1866 pos = RayEnd;
1823 } 1867 }
1824
1825 return pos;
1826 } 1868 }
1827 } 1869 }
1828 else 1870 else
@@ -1833,8 +1875,12 @@ namespace OpenSim.Region.Framework.Scenes
1833 //increase height so its above the ground. 1875 //increase height so its above the ground.
1834 //should be getting the normal of the ground at the rez point and using that? 1876 //should be getting the normal of the ground at the rez point and using that?
1835 pos.Z += scale.Z / 2f; 1877 pos.Z += scale.Z / 2f;
1836 return pos; 1878// return pos;
1837 } 1879 }
1880
1881 // check against posible water intercept
1882 if (wpos.Z > pos.Z) pos = wpos;
1883 return pos;
1838 } 1884 }
1839 1885
1840 1886
@@ -1918,7 +1964,10 @@ namespace OpenSim.Region.Framework.Scenes
1918 public bool AddRestoredSceneObject( 1964 public bool AddRestoredSceneObject(
1919 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 1965 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
1920 { 1966 {
1921 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 1967 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
1968 if (result)
1969 sceneObject.IsDeleted = false;
1970 return result;
1922 } 1971 }
1923 1972
1924 /// <summary> 1973 /// <summary>
@@ -2008,6 +2057,15 @@ namespace OpenSim.Region.Framework.Scenes
2008 /// </summary> 2057 /// </summary>
2009 public void DeleteAllSceneObjects() 2058 public void DeleteAllSceneObjects()
2010 { 2059 {
2060 DeleteAllSceneObjects(false);
2061 }
2062
2063 /// <summary>
2064 /// Delete every object from the scene. This does not include attachments worn by avatars.
2065 /// </summary>
2066 public void DeleteAllSceneObjects(bool exceptNoCopy)
2067 {
2068 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2011 lock (Entities) 2069 lock (Entities)
2012 { 2070 {
2013 EntityBase[] entities = Entities.GetEntities(); 2071 EntityBase[] entities = Entities.GetEntities();
@@ -2016,11 +2074,24 @@ namespace OpenSim.Region.Framework.Scenes
2016 if (e is SceneObjectGroup) 2074 if (e is SceneObjectGroup)
2017 { 2075 {
2018 SceneObjectGroup sog = (SceneObjectGroup)e; 2076 SceneObjectGroup sog = (SceneObjectGroup)e;
2019 if (!sog.IsAttachment) 2077 if (sog != null && !sog.IsAttachment)
2020 DeleteSceneObject((SceneObjectGroup)e, false); 2078 {
2079 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2080 {
2081 DeleteSceneObject((SceneObjectGroup)e, false);
2082 }
2083 else
2084 {
2085 toReturn.Add((SceneObjectGroup)e);
2086 }
2087 }
2021 } 2088 }
2022 } 2089 }
2023 } 2090 }
2091 if (toReturn.Count > 0)
2092 {
2093 returnObjects(toReturn.ToArray(), UUID.Zero);
2094 }
2024 } 2095 }
2025 2096
2026 /// <summary> 2097 /// <summary>
@@ -2069,6 +2140,8 @@ namespace OpenSim.Region.Framework.Scenes
2069 } 2140 }
2070 2141
2071 group.DeleteGroupFromScene(silent); 2142 group.DeleteGroupFromScene(silent);
2143 if (!silent)
2144 SendKillObject(new List<uint>() { group.LocalId });
2072 2145
2073// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2146// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2074 } 2147 }
@@ -2423,10 +2496,17 @@ namespace OpenSim.Region.Framework.Scenes
2423 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2496 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2424 public bool AddSceneObject(SceneObjectGroup sceneObject) 2497 public bool AddSceneObject(SceneObjectGroup sceneObject)
2425 { 2498 {
2499 if (sceneObject.OwnerID == UUID.Zero)
2500 {
2501 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2502 return false;
2503 }
2504
2426 // If the user is banned, we won't let any of their objects 2505 // If the user is banned, we won't let any of their objects
2427 // enter. Period. 2506 // enter. Period.
2428 // 2507 //
2429 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2508 int flags = GetUserFlags(sceneObject.OwnerID);
2509 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2430 { 2510 {
2431 m_log.Info("[INTERREGION]: Denied prim crossing for " + 2511 m_log.Info("[INTERREGION]: Denied prim crossing for " +
2432 "banned avatar"); 2512 "banned avatar");
@@ -2473,12 +2553,23 @@ namespace OpenSim.Region.Framework.Scenes
2473 } 2553 }
2474 else 2554 else
2475 { 2555 {
2556 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2476 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2557 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2477 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2558 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2478 } 2559 }
2560 if (sceneObject.OwnerID == UUID.Zero)
2561 {
2562 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2563 return false;
2564 }
2479 } 2565 }
2480 else 2566 else
2481 { 2567 {
2568 if (sceneObject.OwnerID == UUID.Zero)
2569 {
2570 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2571 return false;
2572 }
2482 AddRestoredSceneObject(sceneObject, true, false); 2573 AddRestoredSceneObject(sceneObject, true, false);
2483 2574
2484 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2575 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2508,6 +2599,24 @@ namespace OpenSim.Region.Framework.Scenes
2508 return 2; // StateSource.PrimCrossing 2599 return 2; // StateSource.PrimCrossing
2509 } 2600 }
2510 2601
2602 public int GetUserFlags(UUID user)
2603 {
2604 //Unfortunately the SP approach means that the value is cached until region is restarted
2605 /*
2606 ScenePresence sp;
2607 if (TryGetScenePresence(user, out sp))
2608 {
2609 return sp.UserFlags;
2610 }
2611 else
2612 {
2613 */
2614 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2615 if (uac == null)
2616 return 0;
2617 return uac.UserFlags;
2618 //}
2619 }
2511 #endregion 2620 #endregion
2512 2621
2513 #region Add/Remove Avatar Methods 2622 #region Add/Remove Avatar Methods
@@ -2529,6 +2638,7 @@ namespace OpenSim.Region.Framework.Scenes
2529 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2638 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2530 2639
2531 CheckHeartbeat(); 2640 CheckHeartbeat();
2641 ScenePresence presence;
2532 2642
2533 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here 2643 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here
2534 { 2644 {
@@ -2562,7 +2672,14 @@ namespace OpenSim.Region.Framework.Scenes
2562 2672
2563 EventManager.TriggerOnNewClient(client); 2673 EventManager.TriggerOnNewClient(client);
2564 if (vialogin) 2674 if (vialogin)
2675 {
2565 EventManager.TriggerOnClientLogin(client); 2676 EventManager.TriggerOnClientLogin(client);
2677
2678 // Send initial parcel data
2679 Vector3 pos = createdSp.AbsolutePosition;
2680 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2681 land.SendLandUpdateToClient(client);
2682 }
2566 } 2683 }
2567 } 2684 }
2568 2685
@@ -2651,19 +2768,12 @@ namespace OpenSim.Region.Framework.Scenes
2651 // and the scene presence and the client, if they exist 2768 // and the scene presence and the client, if they exist
2652 try 2769 try
2653 { 2770 {
2654 // We need to wait for the client to make UDP contact first. 2771 ScenePresence sp = GetScenePresence(agentID);
2655 // It's the UDP contact that creates the scene presence 2772 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2656 ScenePresence sp = WaitGetScenePresence(agentID); 2773
2657 if (sp != null) 2774 if (sp != null)
2658 {
2659 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2660
2661 sp.ControllingClient.Close(); 2775 sp.ControllingClient.Close();
2662 } 2776
2663 else
2664 {
2665 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2666 }
2667 // BANG! SLASH! 2777 // BANG! SLASH!
2668 m_authenticateHandler.RemoveCircuit(agentID); 2778 m_authenticateHandler.RemoveCircuit(agentID);
2669 2779
@@ -2763,6 +2873,7 @@ namespace OpenSim.Region.Framework.Scenes
2763 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 2873 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2764 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 2874 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2765 client.OnCopyInventoryItem += CopyInventoryItem; 2875 client.OnCopyInventoryItem += CopyInventoryItem;
2876 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2766 client.OnMoveInventoryItem += MoveInventoryItem; 2877 client.OnMoveInventoryItem += MoveInventoryItem;
2767 client.OnRemoveInventoryItem += RemoveInventoryItem; 2878 client.OnRemoveInventoryItem += RemoveInventoryItem;
2768 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 2879 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2940,15 +3051,16 @@ namespace OpenSim.Region.Framework.Scenes
2940 /// </summary> 3051 /// </summary>
2941 /// <param name="agentId">The avatar's Unique ID</param> 3052 /// <param name="agentId">The avatar's Unique ID</param>
2942 /// <param name="client">The IClientAPI for the client</param> 3053 /// <param name="client">The IClientAPI for the client</param>
2943 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3054 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
2944 { 3055 {
2945 if (m_teleportModule != null) 3056 if (m_teleportModule != null)
2946 m_teleportModule.TeleportHome(agentId, client); 3057 return m_teleportModule.TeleportHome(agentId, client);
2947 else 3058 else
2948 { 3059 {
2949 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3060 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
2950 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3061 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
2951 } 3062 }
3063 return false;
2952 } 3064 }
2953 3065
2954 /// <summary> 3066 /// <summary>
@@ -3040,6 +3152,16 @@ namespace OpenSim.Region.Framework.Scenes
3040 /// <param name="flags"></param> 3152 /// <param name="flags"></param>
3041 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3153 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3042 { 3154 {
3155 //Add half the avatar's height so that the user doesn't fall through prims
3156 ScenePresence presence;
3157 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3158 {
3159 if (presence.Appearance != null)
3160 {
3161 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3162 }
3163 }
3164
3043 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3165 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3044 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3166 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3045 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3167 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3114,8 +3236,9 @@ namespace OpenSim.Region.Framework.Scenes
3114 regions.Remove(RegionInfo.RegionHandle); 3236 regions.Remove(RegionInfo.RegionHandle);
3115 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3237 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3116 } 3238 }
3117 3239 m_log.Debug("[Scene] Beginning ClientClosed");
3118 m_eventManager.TriggerClientClosed(agentID, this); 3240 m_eventManager.TriggerClientClosed(agentID, this);
3241 m_log.Debug("[Scene] Finished ClientClosed");
3119 } 3242 }
3120 catch (NullReferenceException) 3243 catch (NullReferenceException)
3121 { 3244 {
@@ -3123,7 +3246,12 @@ namespace OpenSim.Region.Framework.Scenes
3123 // Avatar is already disposed :/ 3246 // Avatar is already disposed :/
3124 } 3247 }
3125 3248
3249 m_log.Debug("[Scene] Beginning OnRemovePresence");
3126 m_eventManager.TriggerOnRemovePresence(agentID); 3250 m_eventManager.TriggerOnRemovePresence(agentID);
3251 m_log.Debug("[Scene] Finished OnRemovePresence");
3252
3253 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3254 AttachmentsModule.SaveChangedAttachments(avatar);
3127 3255
3128 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc) 3256 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3129 AttachmentsModule.SaveChangedAttachments(avatar); 3257 AttachmentsModule.SaveChangedAttachments(avatar);
@@ -3132,7 +3260,7 @@ namespace OpenSim.Region.Framework.Scenes
3132 delegate(IClientAPI client) 3260 delegate(IClientAPI client)
3133 { 3261 {
3134 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway 3262 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway
3135 try { client.SendKillObject(avatar.RegionHandle, avatar.LocalId); } 3263 try { client.SendKillObject(avatar.RegionHandle, new List<uint>() { avatar.LocalId}); }
3136 catch (NullReferenceException) { } 3264 catch (NullReferenceException) { }
3137 }); 3265 });
3138 3266
@@ -3143,8 +3271,11 @@ namespace OpenSim.Region.Framework.Scenes
3143 } 3271 }
3144 3272
3145 // Remove the avatar from the scene 3273 // Remove the avatar from the scene
3274 m_log.Debug("[Scene] Begin RemoveScenePresence");
3146 m_sceneGraph.RemoveScenePresence(agentID); 3275 m_sceneGraph.RemoveScenePresence(agentID);
3276 m_log.Debug("[Scene] Finished RemoveScenePresence. Removing the client manager");
3147 m_clientManager.Remove(agentID); 3277 m_clientManager.Remove(agentID);
3278 m_log.Debug("[Scene] Removed the client manager. Firing avatar.close");
3148 3279
3149 try 3280 try
3150 { 3281 {
@@ -3158,9 +3289,10 @@ namespace OpenSim.Region.Framework.Scenes
3158 { 3289 {
3159 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3290 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3160 } 3291 }
3161 3292 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3162 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3293 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3163// CleanDroppedAttachments(); 3294// CleanDroppedAttachments();
3295 m_log.Debug("[Scene] The avatar has left the building");
3164 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3296 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3165 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3297 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3166 } 3298 }
@@ -3191,19 +3323,24 @@ namespace OpenSim.Region.Framework.Scenes
3191 3323
3192 #region Entities 3324 #region Entities
3193 3325
3194 public void SendKillObject(uint localID) 3326 public void SendKillObject(List<uint> localIDs)
3195 { 3327 {
3196 SceneObjectPart part = GetSceneObjectPart(localID); 3328 List<uint> deleteIDs = new List<uint>();
3197 if (part != null) // It is a prim 3329
3330 foreach (uint localID in localIDs)
3198 { 3331 {
3199 if (!part.ParentGroup.IsDeleted) // Valid 3332 SceneObjectPart part = GetSceneObjectPart(localID);
3333 if (part != null) // It is a prim
3200 { 3334 {
3201 if (part.ParentGroup.RootPart != part) // Child part 3335 if (part.ParentGroup != null && !part.ParentGroup.IsDeleted) // Valid
3202 return; 3336 {
3337 if (part.ParentGroup.RootPart != part) // Child part
3338 continue;
3339 }
3203 } 3340 }
3341 deleteIDs.Add(localID);
3204 } 3342 }
3205 3343 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, deleteIDs); });
3206 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); });
3207 } 3344 }
3208 3345
3209 #endregion 3346 #endregion
@@ -3221,7 +3358,6 @@ namespace OpenSim.Region.Framework.Scenes
3221 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate; 3358 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3222 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar; 3359 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar;
3223 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3360 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3224 m_sceneGridService.KiPrimitive += SendKillObject;
3225 m_sceneGridService.OnGetLandData += GetLandData; 3361 m_sceneGridService.OnGetLandData += GetLandData;
3226 } 3362 }
3227 3363
@@ -3230,7 +3366,6 @@ namespace OpenSim.Region.Framework.Scenes
3230 /// </summary> 3366 /// </summary>
3231 public void UnRegisterRegionWithComms() 3367 public void UnRegisterRegionWithComms()
3232 { 3368 {
3233 m_sceneGridService.KiPrimitive -= SendKillObject;
3234 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid; 3369 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid;
3235 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar; 3370 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar;
3236 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate; 3371 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
@@ -3310,13 +3445,16 @@ namespace OpenSim.Region.Framework.Scenes
3310 sp = null; 3445 sp = null;
3311 } 3446 }
3312 3447
3313 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3314 3448
3315 //On login test land permisions 3449 //On login test land permisions
3316 if (vialogin) 3450 if (vialogin)
3317 { 3451 {
3318 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3452 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3453 if (cache != null)
3454 cache.Remove(agent.firstname + " " + agent.lastname);
3455 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3319 { 3456 {
3457 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3320 return false; 3458 return false;
3321 } 3459 }
3322 } 3460 }
@@ -3339,8 +3477,13 @@ namespace OpenSim.Region.Framework.Scenes
3339 3477
3340 try 3478 try
3341 { 3479 {
3342 if (!AuthorizeUser(agent, out reason)) 3480 // Always check estate if this is a login. Always
3343 return false; 3481 // check if banned regions are to be blacked out.
3482 if (vialogin || (!m_seeIntoBannedRegion))
3483 {
3484 if (!AuthorizeUser(agent, out reason))
3485 return false;
3486 }
3344 } 3487 }
3345 catch (Exception e) 3488 catch (Exception e)
3346 { 3489 {
@@ -3442,6 +3585,8 @@ namespace OpenSim.Region.Framework.Scenes
3442 } 3585 }
3443 } 3586 }
3444 // Honor parcel landing type and position. 3587 // Honor parcel landing type and position.
3588 /*
3589 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3445 if (land != null) 3590 if (land != null)
3446 { 3591 {
3447 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3592 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3449,26 +3594,34 @@ namespace OpenSim.Region.Framework.Scenes
3449 agent.startpos = land.LandData.UserLocation; 3594 agent.startpos = land.LandData.UserLocation;
3450 } 3595 }
3451 } 3596 }
3597 */// This is now handled properly in ScenePresence.MakeRootAgent
3452 } 3598 }
3453 3599
3454 return true; 3600 return true;
3455 } 3601 }
3456 3602
3457 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3603 private bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3458 { 3604 {
3459 3605 reason = String.Empty;
3460 bool banned = land.IsBannedFromLand(agent.AgentID); 3606 if (Permissions.IsGod(agentID))
3461 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3607 return true;
3608
3609 ILandObject land = LandChannel.GetLandObject(posX, posY);
3610 if (land == null)
3611 return false;
3612
3613 bool banned = land.IsBannedFromLand(agentID);
3614 bool restricted = land.IsRestrictedFromLand(agentID);
3462 3615
3463 if (banned || restricted) 3616 if (banned || restricted)
3464 { 3617 {
3465 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3618 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3466 if (nearestParcel != null) 3619 if (nearestParcel != null)
3467 { 3620 {
3468 //Move agent to nearest allowed 3621 //Move agent to nearest allowed
3469 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3622 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3470 agent.startpos.X = newPosition.X; 3623 posX = newPosition.X;
3471 agent.startpos.Y = newPosition.Y; 3624 posY = newPosition.Y;
3472 } 3625 }
3473 else 3626 else
3474 { 3627 {
@@ -3530,7 +3683,7 @@ namespace OpenSim.Region.Framework.Scenes
3530 3683
3531 if (!m_strictAccessControl) return true; 3684 if (!m_strictAccessControl) return true;
3532 if (Permissions.IsGod(agent.AgentID)) return true; 3685 if (Permissions.IsGod(agent.AgentID)) return true;
3533 3686
3534 if (AuthorizationService != null) 3687 if (AuthorizationService != null)
3535 { 3688 {
3536 if (!AuthorizationService.IsAuthorizedForRegion( 3689 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3538,14 +3691,14 @@ namespace OpenSim.Region.Framework.Scenes
3538 { 3691 {
3539 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region", 3692 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region",
3540 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3693 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
3541 3694
3542 return false; 3695 return false;
3543 } 3696 }
3544 } 3697 }
3545 3698
3546 if (m_regInfo.EstateSettings != null) 3699 if (m_regInfo.EstateSettings != null)
3547 { 3700 {
3548 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3701 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3549 { 3702 {
3550 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3703 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3551 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3704 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3735,6 +3888,13 @@ namespace OpenSim.Region.Framework.Scenes
3735 3888
3736 // We have to wait until the viewer contacts this region after receiving EAC. 3889 // We have to wait until the viewer contacts this region after receiving EAC.
3737 // That calls AddNewClient, which finally creates the ScenePresence 3890 // That calls AddNewClient, which finally creates the ScenePresence
3891 int flags = GetUserFlags(cAgentData.AgentID);
3892 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
3893 {
3894 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
3895 return false;
3896 }
3897
3738 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 3898 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3739 if (nearestParcel == null) 3899 if (nearestParcel == null)
3740 { 3900 {
@@ -3750,7 +3910,6 @@ namespace OpenSim.Region.Framework.Scenes
3750 return false; 3910 return false;
3751 } 3911 }
3752 3912
3753
3754 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID); 3913 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID);
3755 3914
3756 if (childAgentUpdate != null) 3915 if (childAgentUpdate != null)
@@ -3817,12 +3976,22 @@ namespace OpenSim.Region.Framework.Scenes
3817 return false; 3976 return false;
3818 } 3977 }
3819 3978
3979 public bool IncomingCloseAgent(UUID agentID)
3980 {
3981 return IncomingCloseAgent(agentID, false);
3982 }
3983
3984 public bool IncomingCloseChildAgent(UUID agentID)
3985 {
3986 return IncomingCloseAgent(agentID, true);
3987 }
3988
3820 /// <summary> 3989 /// <summary>
3821 /// Tell a single agent to disconnect from the region. 3990 /// Tell a single agent to disconnect from the region.
3822 /// </summary> 3991 /// </summary>
3823 /// <param name="regionHandle"></param>
3824 /// <param name="agentID"></param> 3992 /// <param name="agentID"></param>
3825 public bool IncomingCloseAgent(UUID agentID) 3993 /// <param name="childOnly"></param>
3994 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
3826 { 3995 {
3827 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 3996 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
3828 3997
@@ -3834,7 +4003,7 @@ namespace OpenSim.Region.Framework.Scenes
3834 { 4003 {
3835 m_sceneGraph.removeUserCount(false); 4004 m_sceneGraph.removeUserCount(false);
3836 } 4005 }
3837 else 4006 else if (!childOnly)
3838 { 4007 {
3839 m_sceneGraph.removeUserCount(true); 4008 m_sceneGraph.removeUserCount(true);
3840 } 4009 }
@@ -3850,9 +4019,12 @@ namespace OpenSim.Region.Framework.Scenes
3850 } 4019 }
3851 else 4020 else
3852 presence.ControllingClient.SendShutdownConnectionNotice(); 4021 presence.ControllingClient.SendShutdownConnectionNotice();
4022 presence.ControllingClient.Close(false);
4023 }
4024 else if (!childOnly)
4025 {
4026 presence.ControllingClient.Close(true);
3853 } 4027 }
3854
3855 presence.ControllingClient.Close();
3856 return true; 4028 return true;
3857 } 4029 }
3858 4030
@@ -4467,34 +4639,66 @@ namespace OpenSim.Region.Framework.Scenes
4467 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4639 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4468 } 4640 }
4469 4641
4470 public int GetHealth() 4642 public int GetHealth(out int flags, out string message)
4471 { 4643 {
4472 // Returns: 4644 // Returns:
4473 // 1 = sim is up and accepting http requests. The heartbeat has 4645 // 1 = sim is up and accepting http requests. The heartbeat has
4474 // stopped and the sim is probably locked up, but a remote 4646 // stopped and the sim is probably locked up, but a remote
4475 // admin restart may succeed 4647 // admin restart may succeed
4476 // 4648 //
4477 // 2 = Sim is up and the heartbeat is running. The sim is likely 4649 // 2 = Sim is up and the heartbeat is running. The sim is likely
4478 // usable for people within and logins _may_ work 4650 // usable for people within
4651 //
4652 // 3 = Sim is up and one packet thread is running. Sim is
4653 // unstable and will not accept new logins
4654 //
4655 // 4 = Sim is up and both packet threads are running. Sim is
4656 // likely usable
4479 // 4657 //
4480 // 3 = We have seen a new user enter within the past 4 minutes 4658 // 5 = We have seen a new user enter within the past 4 minutes
4481 // which can be seen as positive confirmation of sim health 4659 // which can be seen as positive confirmation of sim health
4482 // 4660 //
4661
4662 flags = 0;
4663 message = String.Empty;
4664
4665 CheckHeartbeat();
4666
4667 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4668 {
4669 // We're still starting
4670 // 0 means "in startup", it can't happen another way, since
4671 // to get here, we must be able to accept http connections
4672 return 0;
4673 }
4674
4483 int health=1; // Start at 1, means we're up 4675 int health=1; // Start at 1, means we're up
4484 4676
4485 if ((Util.EnvironmentTickCountSubtract(m_lastUpdate)) < 1000) 4677 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) < 1000)
4678 {
4486 health+=1; 4679 health+=1;
4487 else 4680 flags |= 1;
4681 }
4682
4683 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4684 {
4685 health+=1;
4686 flags |= 2;
4687 }
4688
4689 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4690 {
4691 health+=1;
4692 flags |= 4;
4693 }
4694
4695 if (flags != 7)
4488 return health; 4696 return health;
4489 4697
4490 // A login in the last 4 mins? We can't be doing too badly 4698 // A login in the last 4 mins? We can't be doing too badly
4491 // 4699 //
4492 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4700 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4493 health++; 4701 health++;
4494 else
4495 return health;
4496
4497 CheckHeartbeat();
4498 4702
4499 return health; 4703 return health;
4500 } 4704 }
@@ -4687,7 +4891,7 @@ namespace OpenSim.Region.Framework.Scenes
4687 if (m_firstHeartbeat) 4891 if (m_firstHeartbeat)
4688 return; 4892 return;
4689 4893
4690 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4894 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 5000)
4691 StartTimer(); 4895 StartTimer();
4692 } 4896 }
4693 4897
@@ -5136,6 +5340,19 @@ namespace OpenSim.Region.Framework.Scenes
5136// } 5340// }
5137// } 5341// }
5138 5342
5343 public void ThreadAlive(int threadCode)
5344 {
5345 switch(threadCode)
5346 {
5347 case 1: // Incoming
5348 m_lastIncoming = Util.EnvironmentTickCount();
5349 break;
5350 case 2: // Incoming
5351 m_lastOutgoing = Util.EnvironmentTickCount();
5352 break;
5353 }
5354 }
5355
5139 // This method is called across the simulation connector to 5356 // This method is called across the simulation connector to
5140 // determine if a given agent is allowed in this region 5357 // determine if a given agent is allowed in this region
5141 // AS A ROOT AGENT. Returning false here will prevent them 5358 // AS A ROOT AGENT. Returning false here will prevent them
@@ -5144,6 +5361,14 @@ namespace OpenSim.Region.Framework.Scenes
5144 // child agent creation, thereby emulating the SL behavior. 5361 // child agent creation, thereby emulating the SL behavior.
5145 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5362 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5146 { 5363 {
5364 reason = "You are banned from the region";
5365
5366 if (Permissions.IsGod(agentID))
5367 {
5368 reason = String.Empty;
5369 return true;
5370 }
5371
5147 int num = m_sceneGraph.GetNumberOfScenePresences(); 5372 int num = m_sceneGraph.GetNumberOfScenePresences();
5148 5373
5149 if (num >= RegionInfo.RegionSettings.AgentLimit) 5374 if (num >= RegionInfo.RegionSettings.AgentLimit)
@@ -5155,11 +5380,60 @@ namespace OpenSim.Region.Framework.Scenes
5155 } 5380 }
5156 } 5381 }
5157 5382
5383 try
5384 {
5385 if (!AuthorizeUser(GetScenePresence(agentID).ControllingClient.RequestClientInfo(), out reason))
5386 {
5387 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5388 return false;
5389 }
5390 }
5391 catch
5392 {
5393 return false;
5394 }
5395
5396 if (position == Vector3.Zero) // Teleport
5397 {
5398 float posX = 128.0f;
5399 float posY = 128.0f;
5400
5401 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5402 {
5403 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5404 return false;
5405 }
5406 }
5407 else // Walking
5408 {
5409 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5410 if (land == null)
5411 return false;
5412
5413 bool banned = land.IsBannedFromLand(agentID);
5414 bool restricted = land.IsRestrictedFromLand(agentID);
5415
5416 if (banned || restricted)
5417 return false;
5418 }
5419
5158 reason = String.Empty; 5420 reason = String.Empty;
5159 return true; 5421 return true;
5160 } 5422 }
5161 5423
5162 /// <summary> 5424 public void StartTimerWatchdog()
5425 {
5426 m_timerWatchdog.Interval = 1000;
5427 m_timerWatchdog.Elapsed += TimerWatchdog;
5428 m_timerWatchdog.AutoReset = true;
5429 m_timerWatchdog.Start();
5430 }
5431
5432 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5433 {
5434 CheckHeartbeat();
5435 }
5436
5163 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5437 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5164 /// autopilot that moves an avatar to a sit target!. 5438 /// autopilot that moves an avatar to a sit target!.
5165 /// </summary> 5439 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index ec94f10..bf861b8 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -136,6 +136,8 @@ namespace OpenSim.Region.Framework.Scenes
136 get { return m_permissions; } 136 get { return m_permissions; }
137 } 137 }
138 138
139 protected string m_datastore;
140
139 /* Used by the loadbalancer plugin on GForge */ 141 /* Used by the loadbalancer plugin on GForge */
140 protected RegionStatus m_regStatus; 142 protected RegionStatus m_regStatus;
141 public RegionStatus RegionStatus 143 public RegionStatus RegionStatus
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 837e655..19cb0c1 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -44,8 +44,6 @@ using GridRegion = OpenSim.Services.Interfaces.GridRegion;
44 44
45namespace OpenSim.Region.Framework.Scenes 45namespace OpenSim.Region.Framework.Scenes
46{ 46{
47 public delegate void KiPrimitiveDelegate(uint localID);
48
49 public delegate void RemoveKnownRegionsFromAvatarList(UUID avatarID, List<ulong> regionlst); 47 public delegate void RemoveKnownRegionsFromAvatarList(UUID avatarID, List<ulong> regionlst);
50 48
51 /// <summary> 49 /// <summary>
@@ -113,8 +111,6 @@ namespace OpenSim.Region.Framework.Scenes
113// private LogOffUser handlerLogOffUser = null; 111// private LogOffUser handlerLogOffUser = null;
114// private GetLandData handlerGetLandData = null; // OnGetLandData 112// private GetLandData handlerGetLandData = null; // OnGetLandData
115 113
116 public KiPrimitiveDelegate KiPrimitive;
117
118 public SceneCommunicationService() 114 public SceneCommunicationService()
119 { 115 {
120 } 116 }
@@ -168,7 +164,7 @@ namespace OpenSim.Region.Framework.Scenes
168 164
169 if (neighbour != null) 165 if (neighbour != null)
170 { 166 {
171 m_log.DebugFormat("[INTERGRID]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize); 167 // m_log.DebugFormat("[INTERGRID]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize);
172 m_scene.EventManager.TriggerOnRegionUp(neighbour); 168 m_scene.EventManager.TriggerOnRegionUp(neighbour);
173 } 169 }
174 else 170 else
@@ -183,7 +179,7 @@ namespace OpenSim.Region.Framework.Scenes
183 //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName); 179 //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName);
184 180
185 List<GridRegion> neighbours = m_scene.GridService.GetNeighbours(m_scene.RegionInfo.ScopeID, m_scene.RegionInfo.RegionID); 181 List<GridRegion> neighbours = m_scene.GridService.GetNeighbours(m_scene.RegionInfo.ScopeID, m_scene.RegionInfo.RegionID);
186 m_log.DebugFormat("[INTERGRID]: Informing {0} neighbours that this region is up", neighbours.Count); 182 //m_log.DebugFormat("[INTERGRID]: Informing {0} neighbours that this region is up", neighbours.Count);
187 foreach (GridRegion n in neighbours) 183 foreach (GridRegion n in neighbours)
188 { 184 {
189 InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync; 185 InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync;
@@ -259,46 +255,42 @@ namespace OpenSim.Region.Framework.Scenes
259 255
260 } 256 }
261 257
262 //public delegate void SendCloseChildAgentDelegate(UUID agentID, ulong regionHandle); 258 public delegate void SendCloseChildAgentDelegate(UUID agentID, ulong regionHandle);
263 //private void SendCloseChildAgentCompleted(IAsyncResult iar)
264 //{
265 // SendCloseChildAgentDelegate icon = (SendCloseChildAgentDelegate)iar.AsyncState;
266 // icon.EndInvoke(iar);
267 //}
268 259
269 /// <summary> 260 /// <summary>
270 /// Closes a child agent on a given region 261 /// This Closes child agents on neighboring regions
262 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
271 /// </summary> 263 /// </summary>
272 protected void SendCloseChildAgent(UUID agentID, ulong regionHandle) 264 protected void SendCloseChildAgentAsync(UUID agentID, ulong regionHandle)
273 { 265 {
274 266
275 m_log.Debug("[INTERGRID]: Sending close agent to " + regionHandle); 267 //m_log.Debug("[INTERGRID]: Sending close agent to " + regionHandle);
276 // let's do our best, but there's not much we can do if the neighbour doesn't accept. 268 // let's do our best, but there's not much we can do if the neighbour doesn't accept.
277 269
278 //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); 270 //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID);
279 uint x = 0, y = 0; 271 uint x = 0, y = 0;
280 Utils.LongToUInts(regionHandle, out x, out y); 272 Utils.LongToUInts(regionHandle, out x, out y);
281 GridRegion destination = m_scene.GridService.GetRegionByPosition(m_regionInfo.ScopeID, (int)x, (int)y); 273 GridRegion destination = m_scene.GridService.GetRegionByPosition(m_regionInfo.ScopeID, (int)x, (int)y);
282 m_scene.SimulationService.CloseAgent(destination, agentID); 274 m_scene.SimulationService.CloseChildAgent(destination, agentID);
275 }
276
277 private void SendCloseChildAgentCompleted(IAsyncResult iar)
278 {
279 SendCloseChildAgentDelegate icon = (SendCloseChildAgentDelegate)iar.AsyncState;
280 icon.EndInvoke(iar);
283 } 281 }
284 282
285 /// <summary>
286 /// Closes a child agents in a collection of regions. Does so asynchronously
287 /// so that the caller doesn't wait.
288 /// </summary>
289 /// <param name="agentID"></param>
290 /// <param name="regionslst"></param>
291 public void SendCloseChildAgentConnections(UUID agentID, List<ulong> regionslst) 283 public void SendCloseChildAgentConnections(UUID agentID, List<ulong> regionslst)
292 { 284 {
293 Util.FireAndForget(delegate 285 foreach (ulong handle in regionslst)
294 { 286 {
295 foreach (ulong handle in regionslst) 287 SendCloseChildAgentDelegate d = SendCloseChildAgentAsync;
296 { 288 d.BeginInvoke(agentID, handle,
297 SendCloseChildAgent(agentID, handle); 289 SendCloseChildAgentCompleted,
298 } 290 d);
299 }); 291 }
300 } 292 }
301 293
302 public List<GridRegion> RequestNamedRegions(string name, int maxNumber) 294 public List<GridRegion> RequestNamedRegions(string name, int maxNumber)
303 { 295 {
304 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); 296 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber);
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index caec704..13668ab 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -43,6 +43,12 @@ namespace OpenSim.Region.Framework.Scenes
43 43
44 public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone); 44 public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone);
45 45
46 public delegate void AttachToBackupDelegate(SceneObjectGroup sog);
47
48 public delegate void DetachFromBackupDelegate(SceneObjectGroup sog);
49
50 public delegate void ChangedBackupDelegate(SceneObjectGroup sog);
51
46 public delegate void ObjectCreateDelegate(EntityBase obj); 52 public delegate void ObjectCreateDelegate(EntityBase obj);
47 53
48 public delegate void ObjectDeleteDelegate(EntityBase obj); 54 public delegate void ObjectDeleteDelegate(EntityBase obj);
@@ -61,6 +67,9 @@ namespace OpenSim.Region.Framework.Scenes
61 private PhysicsCrash handlerPhysicsCrash = null; 67 private PhysicsCrash handlerPhysicsCrash = null;
62 68
63 public event ObjectDuplicateDelegate OnObjectDuplicate; 69 public event ObjectDuplicateDelegate OnObjectDuplicate;
70 public event AttachToBackupDelegate OnAttachToBackup;
71 public event DetachFromBackupDelegate OnDetachFromBackup;
72 public event ChangedBackupDelegate OnChangeBackup;
64 public event ObjectCreateDelegate OnObjectCreate; 73 public event ObjectCreateDelegate OnObjectCreate;
65 public event ObjectDeleteDelegate OnObjectRemove; 74 public event ObjectDeleteDelegate OnObjectRemove;
66 75
@@ -68,7 +77,7 @@ namespace OpenSim.Region.Framework.Scenes
68 77
69 #region Fields 78 #region Fields
70 79
71 protected object m_presenceLock = new object(); 80 protected OpenMetaverse.ReaderWriterLockSlim m_scenePresencesLock = new OpenMetaverse.ReaderWriterLockSlim();
72 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>(); 81 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>();
73 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>(); 82 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>();
74 83
@@ -132,13 +141,18 @@ namespace OpenSim.Region.Framework.Scenes
132 141
133 protected internal void Close() 142 protected internal void Close()
134 { 143 {
135 lock (m_presenceLock) 144 m_scenePresencesLock.EnterWriteLock();
145 try
136 { 146 {
137 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); 147 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>();
138 List<ScenePresence> newlist = new List<ScenePresence>(); 148 List<ScenePresence> newlist = new List<ScenePresence>();
139 m_scenePresenceMap = newmap; 149 m_scenePresenceMap = newmap;
140 m_scenePresenceArray = newlist; 150 m_scenePresenceArray = newlist;
141 } 151 }
152 finally
153 {
154 m_scenePresencesLock.ExitWriteLock();
155 }
142 156
143 lock (SceneObjectGroupsByFullID) 157 lock (SceneObjectGroupsByFullID)
144 SceneObjectGroupsByFullID.Clear(); 158 SceneObjectGroupsByFullID.Clear();
@@ -281,6 +295,33 @@ namespace OpenSim.Region.Framework.Scenes
281 protected internal bool AddRestoredSceneObject( 295 protected internal bool AddRestoredSceneObject(
282 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 296 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
283 { 297 {
298 if (!m_parentScene.CombineRegions)
299 {
300 // KF: Check for out-of-region, move inside and make static.
301 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
302 sceneObject.RootPart.GroupPosition.Y,
303 sceneObject.RootPart.GroupPosition.Z);
304 if (!(((sceneObject.RootPart.Shape.PCode == (byte)PCode.Prim) && (sceneObject.RootPart.Shape.State != 0))) && (npos.X < 0.0 || npos.Y < 0.0 || npos.Z < 0.0 ||
305 npos.X > Constants.RegionSize ||
306 npos.Y > Constants.RegionSize))
307 {
308 if (npos.X < 0.0) npos.X = 1.0f;
309 if (npos.Y < 0.0) npos.Y = 1.0f;
310 if (npos.Z < 0.0) npos.Z = 0.0f;
311 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
312 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
313
314 foreach (SceneObjectPart part in sceneObject.Parts)
315 {
316 part.GroupPosition = npos;
317 }
318 sceneObject.RootPart.Velocity = Vector3.Zero;
319 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
320 sceneObject.RootPart.Acceleration = Vector3.Zero;
321 sceneObject.RootPart.Velocity = Vector3.Zero;
322 }
323 }
324
284 if (attachToBackup && (!alreadyPersisted)) 325 if (attachToBackup && (!alreadyPersisted))
285 { 326 {
286 sceneObject.ForceInventoryPersistence(); 327 sceneObject.ForceInventoryPersistence();
@@ -498,6 +539,30 @@ namespace OpenSim.Region.Framework.Scenes
498 m_updateList[obj.UUID] = obj; 539 m_updateList[obj.UUID] = obj;
499 } 540 }
500 541
542 public void FireAttachToBackup(SceneObjectGroup obj)
543 {
544 if (OnAttachToBackup != null)
545 {
546 OnAttachToBackup(obj);
547 }
548 }
549
550 public void FireDetachFromBackup(SceneObjectGroup obj)
551 {
552 if (OnDetachFromBackup != null)
553 {
554 OnDetachFromBackup(obj);
555 }
556 }
557
558 public void FireChangeBackup(SceneObjectGroup obj)
559 {
560 if (OnChangeBackup != null)
561 {
562 OnChangeBackup(obj);
563 }
564 }
565
501 /// <summary> 566 /// <summary>
502 /// Process all pending updates 567 /// Process all pending updates
503 /// </summary> 568 /// </summary>
@@ -629,7 +694,8 @@ namespace OpenSim.Region.Framework.Scenes
629 694
630 Entities[presence.UUID] = presence; 695 Entities[presence.UUID] = presence;
631 696
632 lock (m_presenceLock) 697 m_scenePresencesLock.EnterWriteLock();
698 try
633 { 699 {
634 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 700 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
635 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 701 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -653,6 +719,10 @@ namespace OpenSim.Region.Framework.Scenes
653 m_scenePresenceMap = newmap; 719 m_scenePresenceMap = newmap;
654 m_scenePresenceArray = newlist; 720 m_scenePresenceArray = newlist;
655 } 721 }
722 finally
723 {
724 m_scenePresencesLock.ExitWriteLock();
725 }
656 } 726 }
657 727
658 /// <summary> 728 /// <summary>
@@ -667,7 +737,8 @@ namespace OpenSim.Region.Framework.Scenes
667 agentID); 737 agentID);
668 } 738 }
669 739
670 lock (m_presenceLock) 740 m_scenePresencesLock.EnterWriteLock();
741 try
671 { 742 {
672 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 743 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
673 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 744 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -689,6 +760,10 @@ namespace OpenSim.Region.Framework.Scenes
689 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); 760 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
690 } 761 }
691 } 762 }
763 finally
764 {
765 m_scenePresencesLock.ExitWriteLock();
766 }
692 } 767 }
693 768
694 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) 769 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
@@ -1388,8 +1463,13 @@ namespace OpenSim.Region.Framework.Scenes
1388 { 1463 {
1389 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0)) 1464 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
1390 { 1465 {
1391 if (m_parentScene.AttachmentsModule != null) 1466 // Set the new attachment point data in the object
1392 m_parentScene.AttachmentsModule.UpdateAttachmentPosition(group, pos); 1467 byte attachmentPoint = group.GetAttachmentPoint();
1468 group.UpdateGroupPosition(pos);
1469 group.IsAttachment = false;
1470 group.AbsolutePosition = group.RootPart.AttachedPos;
1471 group.AttachmentPoint = attachmentPoint;
1472 group.HasGroupChanged = true;
1393 } 1473 }
1394 else 1474 else
1395 { 1475 {
@@ -1653,10 +1733,13 @@ namespace OpenSim.Region.Framework.Scenes
1653 /// <param name="childPrims"></param> 1733 /// <param name="childPrims"></param>
1654 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children) 1734 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children)
1655 { 1735 {
1736 SceneObjectGroup parentGroup = root.ParentGroup;
1737 if (parentGroup == null) return;
1656 Monitor.Enter(m_updateLock); 1738 Monitor.Enter(m_updateLock);
1739
1657 try 1740 try
1658 { 1741 {
1659 SceneObjectGroup parentGroup = root.ParentGroup; 1742 parentGroup.areUpdatesSuspended = true;
1660 1743
1661 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); 1744 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1662 1745
@@ -1668,9 +1751,13 @@ namespace OpenSim.Region.Framework.Scenes
1668 // Make sure no child prim is set for sale 1751 // Make sure no child prim is set for sale
1669 // So that, on delink, no prims are unwittingly 1752 // So that, on delink, no prims are unwittingly
1670 // left for sale and sold off 1753 // left for sale and sold off
1671 child.RootPart.ObjectSaleType = 0; 1754
1672 child.RootPart.SalePrice = 10; 1755 if (child != null)
1673 childGroups.Add(child); 1756 {
1757 child.RootPart.ObjectSaleType = 0;
1758 child.RootPart.SalePrice = 10;
1759 childGroups.Add(child);
1760 }
1674 } 1761 }
1675 1762
1676 foreach (SceneObjectGroup child in childGroups) 1763 foreach (SceneObjectGroup child in childGroups)
@@ -1686,12 +1773,13 @@ namespace OpenSim.Region.Framework.Scenes
1686 // occur on link to invoke this elsewhere (such as object selection) 1773 // occur on link to invoke this elsewhere (such as object selection)
1687 parentGroup.RootPart.CreateSelected = true; 1774 parentGroup.RootPart.CreateSelected = true;
1688 parentGroup.TriggerScriptChangedEvent(Changed.LINK); 1775 parentGroup.TriggerScriptChangedEvent(Changed.LINK);
1689 parentGroup.HasGroupChanged = true;
1690 parentGroup.ScheduleGroupForFullUpdate();
1691
1692 } 1776 }
1693 finally 1777 finally
1694 { 1778 {
1779 parentGroup.areUpdatesSuspended = false;
1780 parentGroup.HasGroupChanged = true;
1781 parentGroup.ProcessBackup(m_parentScene.SimulationDataService, true);
1782 parentGroup.ScheduleGroupForFullUpdate();
1695 Monitor.Exit(m_updateLock); 1783 Monitor.Exit(m_updateLock);
1696 } 1784 }
1697 } 1785 }
@@ -1723,21 +1811,24 @@ namespace OpenSim.Region.Framework.Scenes
1723 1811
1724 SceneObjectGroup group = part.ParentGroup; 1812 SceneObjectGroup group = part.ParentGroup;
1725 if (!affectedGroups.Contains(group)) 1813 if (!affectedGroups.Contains(group))
1814 {
1815 group.areUpdatesSuspended = true;
1726 affectedGroups.Add(group); 1816 affectedGroups.Add(group);
1817 }
1727 } 1818 }
1728 } 1819 }
1729 } 1820 }
1730 1821
1731 foreach (SceneObjectPart child in childParts) 1822 if (childParts.Count > 0)
1732 { 1823 {
1733 // Unlink all child parts from their groups 1824 foreach (SceneObjectPart child in childParts)
1734 // 1825 {
1735 child.ParentGroup.DelinkFromGroup(child, true); 1826 // Unlink all child parts from their groups
1736 1827 //
1737 // These are not in affected groups and will not be 1828 child.ParentGroup.DelinkFromGroup(child, true);
1738 // handled further. Do the honors here. 1829 child.ParentGroup.HasGroupChanged = true;
1739 child.ParentGroup.HasGroupChanged = true; 1830 child.ParentGroup.ScheduleGroupForFullUpdate();
1740 child.ParentGroup.ScheduleGroupForFullUpdate(); 1831 }
1741 } 1832 }
1742 1833
1743 foreach (SceneObjectPart root in rootParts) 1834 foreach (SceneObjectPart root in rootParts)
@@ -1747,56 +1838,68 @@ namespace OpenSim.Region.Framework.Scenes
1747 // However, editing linked parts and unlinking may be different 1838 // However, editing linked parts and unlinking may be different
1748 // 1839 //
1749 SceneObjectGroup group = root.ParentGroup; 1840 SceneObjectGroup group = root.ParentGroup;
1841 group.areUpdatesSuspended = true;
1750 1842
1751 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts); 1843 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1752 int numChildren = newSet.Count; 1844 int numChildren = newSet.Count;
1753 1845
1846 if (numChildren == 1)
1847 break;
1848
1754 // If there are prims left in a link set, but the root is 1849 // If there are prims left in a link set, but the root is
1755 // slated for unlink, we need to do this 1850 // slated for unlink, we need to do this
1851 // Unlink the remaining set
1756 // 1852 //
1757 if (numChildren != 1) 1853 bool sendEventsToRemainder = true;
1758 { 1854 if (numChildren > 1)
1759 // Unlink the remaining set 1855 sendEventsToRemainder = false;
1760 //
1761 bool sendEventsToRemainder = true;
1762 if (numChildren > 1)
1763 sendEventsToRemainder = false;
1764 1856
1765 foreach (SceneObjectPart p in newSet) 1857 foreach (SceneObjectPart p in newSet)
1858 {
1859 if (p != group.RootPart)
1766 { 1860 {
1767 if (p != group.RootPart) 1861 group.DelinkFromGroup(p, sendEventsToRemainder);
1768 group.DelinkFromGroup(p, sendEventsToRemainder); 1862 if (numChildren > 2)
1863 {
1864 p.ParentGroup.areUpdatesSuspended = true;
1865 }
1866 else
1867 {
1868 p.ParentGroup.HasGroupChanged = true;
1869 p.ParentGroup.ScheduleGroupForFullUpdate();
1870 }
1769 } 1871 }
1872 }
1770 1873
1771 // If there is more than one prim remaining, we 1874 // If there is more than one prim remaining, we
1772 // need to re-link 1875 // need to re-link
1876 //
1877 if (numChildren > 2)
1878 {
1879 // Remove old root
1880 //
1881 if (newSet.Contains(root))
1882 newSet.Remove(root);
1883
1884 // Preserve link ordering
1773 // 1885 //
1774 if (numChildren > 2) 1886 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1775 { 1887 {
1776 // Remove old root 1888 return a.LinkNum.CompareTo(b.LinkNum);
1777 // 1889 });
1778 if (newSet.Contains(root))
1779 newSet.Remove(root);
1780
1781 // Preserve link ordering
1782 //
1783 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1784 {
1785 return a.LinkNum.CompareTo(b.LinkNum);
1786 });
1787 1890
1788 // Determine new root 1891 // Determine new root
1789 // 1892 //
1790 SceneObjectPart newRoot = newSet[0]; 1893 SceneObjectPart newRoot = newSet[0];
1791 newSet.RemoveAt(0); 1894 newSet.RemoveAt(0);
1792 1895
1793 foreach (SceneObjectPart newChild in newSet) 1896 foreach (SceneObjectPart newChild in newSet)
1794 newChild.UpdateFlag = 0; 1897 newChild.UpdateFlag = 0;
1795 1898
1796 LinkObjects(newRoot, newSet); 1899 newRoot.ParentGroup.areUpdatesSuspended = true;
1797 if (!affectedGroups.Contains(newRoot.ParentGroup)) 1900 LinkObjects(newRoot, newSet);
1798 affectedGroups.Add(newRoot.ParentGroup); 1901 if (!affectedGroups.Contains(newRoot.ParentGroup))
1799 } 1902 affectedGroups.Add(newRoot.ParentGroup);
1800 } 1903 }
1801 } 1904 }
1802 1905
@@ -1804,8 +1907,14 @@ namespace OpenSim.Region.Framework.Scenes
1804 // 1907 //
1805 foreach (SceneObjectGroup g in affectedGroups) 1908 foreach (SceneObjectGroup g in affectedGroups)
1806 { 1909 {
1910 // Child prims that have been unlinked and deleted will
1911 // return unless the root is deleted. This will remove them
1912 // from the database. They will be rewritten immediately,
1913 // minus the rows for the unlinked child prims.
1914 m_parentScene.SimulationDataService.RemoveObject(g.UUID, m_parentScene.RegionInfo.RegionID);
1807 g.TriggerScriptChangedEvent(Changed.LINK); 1915 g.TriggerScriptChangedEvent(Changed.LINK);
1808 g.HasGroupChanged = true; // Persist 1916 g.HasGroupChanged = true; // Persist
1917 g.areUpdatesSuspended = false;
1809 g.ScheduleGroupForFullUpdate(); 1918 g.ScheduleGroupForFullUpdate();
1810 } 1919 }
1811 } 1920 }
@@ -1923,9 +2032,6 @@ namespace OpenSim.Region.Framework.Scenes
1923 child.ApplyNextOwnerPermissions(); 2032 child.ApplyNextOwnerPermissions();
1924 } 2033 }
1925 } 2034 }
1926
1927 copy.RootPart.ObjectSaleType = 0;
1928 copy.RootPart.SalePrice = 10;
1929 } 2035 }
1930 2036
1931 // FIXME: This section needs to be refactored so that it just calls AddSceneObject() 2037 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
index 905ecc9..6bd9183 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
@@ -69,10 +69,6 @@ namespace OpenSim.Region.Framework.Scenes
69 /// <summary> 69 /// <summary>
70 /// Stop the scripts contained in all the prims in this group 70 /// Stop the scripts contained in all the prims in this group
71 /// </summary> 71 /// </summary>
72 /// <param name="sceneObjectBeingDeleted">
73 /// Should be true if these scripts are being removed because the scene
74 /// object is being deleted. This will prevent spurious updates to the client.
75 /// </param>
76 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 72 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
77 { 73 {
78 SceneObjectPart[] parts = m_parts.GetArray(); 74 SceneObjectPart[] parts = m_parts.GetArray();
@@ -385,6 +381,9 @@ namespace OpenSim.Region.Framework.Scenes
385 381
386 public void ResumeScripts() 382 public void ResumeScripts()
387 { 383 {
384 if (m_scene.RegionInfo.RegionSettings.DisableScripts)
385 return;
386
388 SceneObjectPart[] parts = m_parts.GetArray(); 387 SceneObjectPart[] parts = m_parts.GetArray();
389 for (int i = 0; i < parts.Length; i++) 388 for (int i = 0; i < parts.Length; i++)
390 parts[i].Inventory.ResumeScripts(); 389 parts[i].Inventory.ResumeScripts();
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index d983d7f..7493368 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -24,11 +24,12 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing; 30using System.Drawing;
31using System.IO; 31using System.IO;
32using System.Diagnostics;
32using System.Linq; 33using System.Linq;
33using System.Threading; 34using System.Threading;
34using System.Xml; 35using System.Xml;
@@ -105,8 +106,29 @@ namespace OpenSim.Region.Framework.Scenes
105 /// since the group's last persistent backup 106 /// since the group's last persistent backup
106 /// </summary> 107 /// </summary>
107 private bool m_hasGroupChanged = false; 108 private bool m_hasGroupChanged = false;
108 private long timeFirstChanged; 109 private long timeFirstChanged = 0;
109 private long timeLastChanged; 110 private long timeLastChanged = 0;
111 private long m_maxPersistTime = 0;
112 private long m_minPersistTime = 0;
113 private Random m_rand;
114 private bool m_suspendUpdates;
115 private List<ScenePresence> m_linkedAvatars = new List<ScenePresence>();
116
117 public bool areUpdatesSuspended
118 {
119 get
120 {
121 return m_suspendUpdates;
122 }
123 set
124 {
125 m_suspendUpdates = value;
126 if (!value)
127 {
128 QueueForUpdateCheck();
129 }
130 }
131 }
110 132
111 public bool HasGroupChanged 133 public bool HasGroupChanged
112 { 134 {
@@ -114,9 +136,39 @@ namespace OpenSim.Region.Framework.Scenes
114 { 136 {
115 if (value) 137 if (value)
116 { 138 {
139 if (m_isBackedUp)
140 {
141 m_scene.SceneGraph.FireChangeBackup(this);
142 }
117 timeLastChanged = DateTime.Now.Ticks; 143 timeLastChanged = DateTime.Now.Ticks;
118 if (!m_hasGroupChanged) 144 if (!m_hasGroupChanged)
119 timeFirstChanged = DateTime.Now.Ticks; 145 timeFirstChanged = DateTime.Now.Ticks;
146 if (m_rootPart != null && m_rootPart.UUID != null && m_scene != null)
147 {
148 if (m_rand == null)
149 {
150 byte[] val = new byte[16];
151 m_rootPart.UUID.ToBytes(val, 0);
152 m_rand = new Random(BitConverter.ToInt32(val, 0));
153 }
154
155 if (m_scene.GetRootAgentCount() == 0)
156 {
157 //If the region is empty, this change has been made by an automated process
158 //and thus we delay the persist time by a random amount between 1.5 and 2.5.
159
160 float factor = 1.5f + (float)(m_rand.NextDouble());
161 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor);
162 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor);
163 }
164 else
165 {
166 //If the region is not empty, we want to obey the minimum and maximum persist times
167 //but add a random factor so we stagger the object persistance a little
168 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
169 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
170 }
171 }
120 } 172 }
121 m_hasGroupChanged = value; 173 m_hasGroupChanged = value;
122 174
@@ -131,7 +183,7 @@ namespace OpenSim.Region.Framework.Scenes
131 /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since 183 /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since
132 /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation. 184 /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation.
133 /// </summary> 185 /// </summary>
134 public bool HasGroupChangedDueToDelink { get; private set; } 186 public bool HasGroupChangedDueToDelink { get; set; }
135 187
136 private bool isTimeToPersist() 188 private bool isTimeToPersist()
137 { 189 {
@@ -141,8 +193,19 @@ namespace OpenSim.Region.Framework.Scenes
141 return false; 193 return false;
142 if (m_scene.ShuttingDown) 194 if (m_scene.ShuttingDown)
143 return true; 195 return true;
196
197 if (m_minPersistTime == 0 || m_maxPersistTime == 0)
198 {
199 m_maxPersistTime = m_scene.m_persistAfter;
200 m_minPersistTime = m_scene.m_dontPersistBefore;
201 }
202
144 long currentTime = DateTime.Now.Ticks; 203 long currentTime = DateTime.Now.Ticks;
145 if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) 204
205 if (timeLastChanged == 0) timeLastChanged = currentTime;
206 if (timeFirstChanged == 0) timeFirstChanged = currentTime;
207
208 if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
146 return true; 209 return true;
147 return false; 210 return false;
148 } 211 }
@@ -247,10 +310,10 @@ namespace OpenSim.Region.Framework.Scenes
247 310
248 private bool m_scriptListens_atTarget; 311 private bool m_scriptListens_atTarget;
249 private bool m_scriptListens_notAtTarget; 312 private bool m_scriptListens_notAtTarget;
250
251 private bool m_scriptListens_atRotTarget; 313 private bool m_scriptListens_atRotTarget;
252 private bool m_scriptListens_notAtRotTarget; 314 private bool m_scriptListens_notAtRotTarget;
253 315
316 public bool m_dupeInProgress = false;
254 internal Dictionary<UUID, string> m_savedScriptState; 317 internal Dictionary<UUID, string> m_savedScriptState;
255 318
256 #region Properties 319 #region Properties
@@ -286,7 +349,9 @@ namespace OpenSim.Region.Framework.Scenes
286 public virtual Quaternion Rotation 349 public virtual Quaternion Rotation
287 { 350 {
288 get { return m_rotation; } 351 get { return m_rotation; }
289 set { m_rotation = value; } 352 set {
353 m_rotation = value;
354 }
290 } 355 }
291 356
292 public Quaternion GroupRotation 357 public Quaternion GroupRotation
@@ -397,7 +462,11 @@ namespace OpenSim.Region.Framework.Scenes
397 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 462 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
398 } 463 }
399 } 464 }
400 465
466 foreach (SceneObjectPart part in m_parts.GetArray())
467 {
468 part.IgnoreUndoUpdate = true;
469 }
401 if (RootPart.GetStatusSandbox()) 470 if (RootPart.GetStatusSandbox())
402 { 471 {
403 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) 472 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
@@ -411,10 +480,29 @@ namespace OpenSim.Region.Framework.Scenes
411 return; 480 return;
412 } 481 }
413 } 482 }
414
415 SceneObjectPart[] parts = m_parts.GetArray(); 483 SceneObjectPart[] parts = m_parts.GetArray();
416 for (int i = 0; i < parts.Length; i++) 484 foreach (SceneObjectPart part in parts)
417 parts[i].GroupPosition = val; 485 {
486 part.GroupPosition = val;
487 if (!m_dupeInProgress)
488 {
489 part.TriggerScriptChangedEvent(Changed.POSITION);
490 }
491 }
492 if (!m_dupeInProgress)
493 {
494 foreach (ScenePresence av in m_linkedAvatars)
495 {
496 SceneObjectPart p;
497 if (m_parts.TryGetValue(av.LinkedPrim, out p))
498 {
499 Vector3 offset = p.GetWorldPosition() - av.ParentPosition;
500 av.AbsolutePosition += offset;
501 av.ParentPosition = p.GetWorldPosition(); //ParentPosition gets cleared by AbsolutePosition
502 av.SendAvatarDataToAllAgents();
503 }
504 }
505 }
418 506
419 //if (m_rootPart.PhysActor != null) 507 //if (m_rootPart.PhysActor != null)
420 //{ 508 //{
@@ -573,6 +661,7 @@ namespace OpenSim.Region.Framework.Scenes
573 /// </summary> 661 /// </summary>
574 public SceneObjectGroup() 662 public SceneObjectGroup()
575 { 663 {
664
576 } 665 }
577 666
578 /// <summary> 667 /// <summary>
@@ -589,7 +678,7 @@ namespace OpenSim.Region.Framework.Scenes
589 /// Constructor. This object is added to the scene later via AttachToScene() 678 /// Constructor. This object is added to the scene later via AttachToScene()
590 /// </summary> 679 /// </summary>
591 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) 680 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
592 { 681 {
593 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); 682 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
594 } 683 }
595 684
@@ -637,6 +726,9 @@ namespace OpenSim.Region.Framework.Scenes
637 /// </summary> 726 /// </summary>
638 public virtual void AttachToBackup() 727 public virtual void AttachToBackup()
639 { 728 {
729 if (IsAttachment) return;
730 m_scene.SceneGraph.FireAttachToBackup(this);
731
640 if (InSceneBackup) 732 if (InSceneBackup)
641 { 733 {
642 //m_log.DebugFormat( 734 //m_log.DebugFormat(
@@ -679,6 +771,9 @@ namespace OpenSim.Region.Framework.Scenes
679 771
680 ApplyPhysics(m_scene.m_physicalPrim); 772 ApplyPhysics(m_scene.m_physicalPrim);
681 773
774 if (RootPart.PhysActor != null)
775 RootPart.Buoyancy = RootPart.Buoyancy;
776
682 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 777 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
683 // for the same object with very different properties. The caller must schedule the update. 778 // for the same object with very different properties. The caller must schedule the update.
684 //ScheduleGroupForFullUpdate(); 779 //ScheduleGroupForFullUpdate();
@@ -724,9 +819,9 @@ namespace OpenSim.Region.Framework.Scenes
724 result.normal = inter.normal; 819 result.normal = inter.normal;
725 result.distance = inter.distance; 820 result.distance = inter.distance;
726 } 821 }
822
727 } 823 }
728 } 824 }
729
730 return result; 825 return result;
731 } 826 }
732 827
@@ -746,17 +841,19 @@ namespace OpenSim.Region.Framework.Scenes
746 minZ = 8192f; 841 minZ = 8192f;
747 842
748 SceneObjectPart[] parts = m_parts.GetArray(); 843 SceneObjectPart[] parts = m_parts.GetArray();
749 for (int i = 0; i < parts.Length; i++) 844 foreach (SceneObjectPart part in parts)
750 { 845 {
751 SceneObjectPart part = parts[i];
752
753 Vector3 worldPos = part.GetWorldPosition(); 846 Vector3 worldPos = part.GetWorldPosition();
754 Vector3 offset = worldPos - AbsolutePosition; 847 Vector3 offset = worldPos - AbsolutePosition;
755 Quaternion worldRot; 848 Quaternion worldRot;
756 if (part.ParentID == 0) 849 if (part.ParentID == 0)
850 {
757 worldRot = part.RotationOffset; 851 worldRot = part.RotationOffset;
852 }
758 else 853 else
854 {
759 worldRot = part.GetWorldRotation(); 855 worldRot = part.GetWorldRotation();
856 }
760 857
761 Vector3 frontTopLeft; 858 Vector3 frontTopLeft;
762 Vector3 frontTopRight; 859 Vector3 frontTopRight;
@@ -768,6 +865,8 @@ namespace OpenSim.Region.Framework.Scenes
768 Vector3 backBottomLeft; 865 Vector3 backBottomLeft;
769 Vector3 backBottomRight; 866 Vector3 backBottomRight;
770 867
868 // Vector3[] corners = new Vector3[8];
869
771 Vector3 orig = Vector3.Zero; 870 Vector3 orig = Vector3.Zero;
772 871
773 frontTopLeft.X = orig.X - (part.Scale.X / 2); 872 frontTopLeft.X = orig.X - (part.Scale.X / 2);
@@ -802,6 +901,38 @@ namespace OpenSim.Region.Framework.Scenes
802 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 901 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
803 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 902 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
804 903
904
905
906 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
907 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
908 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
909 //m_log.InfoFormat("pre corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
910 //m_log.InfoFormat("pre corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
911 //m_log.InfoFormat("pre corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
912 //m_log.InfoFormat("pre corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
913 //m_log.InfoFormat("pre corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
914
915 //for (int i = 0; i < 8; i++)
916 //{
917 // corners[i] = corners[i] * worldRot;
918 // corners[i] += offset;
919
920 // if (corners[i].X > maxX)
921 // maxX = corners[i].X;
922 // if (corners[i].X < minX)
923 // minX = corners[i].X;
924
925 // if (corners[i].Y > maxY)
926 // maxY = corners[i].Y;
927 // if (corners[i].Y < minY)
928 // minY = corners[i].Y;
929
930 // if (corners[i].Z > maxZ)
931 // maxZ = corners[i].Y;
932 // if (corners[i].Z < minZ)
933 // minZ = corners[i].Z;
934 //}
935
805 frontTopLeft = frontTopLeft * worldRot; 936 frontTopLeft = frontTopLeft * worldRot;
806 frontTopRight = frontTopRight * worldRot; 937 frontTopRight = frontTopRight * worldRot;
807 frontBottomLeft = frontBottomLeft * worldRot; 938 frontBottomLeft = frontBottomLeft * worldRot;
@@ -823,6 +954,15 @@ namespace OpenSim.Region.Framework.Scenes
823 backTopLeft += offset; 954 backTopLeft += offset;
824 backTopRight += offset; 955 backTopRight += offset;
825 956
957 //m_log.InfoFormat("corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
958 //m_log.InfoFormat("corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
959 //m_log.InfoFormat("corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
960 //m_log.InfoFormat("corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
961 //m_log.InfoFormat("corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
962 //m_log.InfoFormat("corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
963 //m_log.InfoFormat("corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
964 //m_log.InfoFormat("corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
965
826 if (frontTopRight.X > maxX) 966 if (frontTopRight.X > maxX)
827 maxX = frontTopRight.X; 967 maxX = frontTopRight.X;
828 if (frontTopLeft.X > maxX) 968 if (frontTopLeft.X > maxX)
@@ -968,15 +1108,20 @@ namespace OpenSim.Region.Framework.Scenes
968 1108
969 public void SaveScriptedState(XmlTextWriter writer) 1109 public void SaveScriptedState(XmlTextWriter writer)
970 { 1110 {
1111 SaveScriptedState(writer, false);
1112 }
1113
1114 public void SaveScriptedState(XmlTextWriter writer, bool oldIDs)
1115 {
971 XmlDocument doc = new XmlDocument(); 1116 XmlDocument doc = new XmlDocument();
972 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1117 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
973 1118
974 SceneObjectPart[] parts = m_parts.GetArray(); 1119 SceneObjectPart[] parts = m_parts.GetArray();
975 for (int i = 0; i < parts.Length; i++) 1120 for (int i = 0; i < parts.Length; i++)
976 { 1121 {
977 Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(); 1122 Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs);
978 foreach (KeyValuePair<UUID, string> kvp in pstates) 1123 foreach (KeyValuePair<UUID, string> kvp in pstates)
979 states.Add(kvp.Key, kvp.Value); 1124 states[kvp.Key] = kvp.Value;
980 } 1125 }
981 1126
982 if (states.Count > 0) 1127 if (states.Count > 0)
@@ -996,6 +1141,168 @@ namespace OpenSim.Region.Framework.Scenes
996 } 1141 }
997 1142
998 /// <summary> 1143 /// <summary>
1144 /// Add the avatar to this linkset (avatar is sat).
1145 /// </summary>
1146 /// <param name="agentID"></param>
1147 public void AddAvatar(UUID agentID)
1148 {
1149 ScenePresence presence;
1150 if (m_scene.TryGetScenePresence(agentID, out presence))
1151 {
1152 if (!m_linkedAvatars.Contains(presence))
1153 {
1154 m_linkedAvatars.Add(presence);
1155 }
1156 }
1157 }
1158
1159 /// <summary>
1160 /// Delete the avatar from this linkset (avatar is unsat).
1161 /// </summary>
1162 /// <param name="agentID"></param>
1163 public void DeleteAvatar(UUID agentID)
1164 {
1165 ScenePresence presence;
1166 if (m_scene.TryGetScenePresence(agentID, out presence))
1167 {
1168 if (m_linkedAvatars.Contains(presence))
1169 {
1170 m_linkedAvatars.Remove(presence);
1171 }
1172 }
1173 }
1174
1175 /// <summary>
1176 /// Returns the list of linked presences (avatars sat on this group)
1177 /// </summary>
1178 /// <param name="agentID"></param>
1179 public List<ScenePresence> GetLinkedAvatars()
1180 {
1181 return m_linkedAvatars;
1182 }
1183
1184 /// <summary>
1185 /// Attach this scene object to the given avatar.
1186 /// </summary>
1187 /// <param name="agentID"></param>
1188 /// <param name="attachmentpoint"></param>
1189 /// <param name="AttachOffset"></param>
1190 private void AttachToAgent(
1191 ScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
1192 {
1193 if (avatar != null)
1194 {
1195 // don't attach attachments to child agents
1196 if (avatar.IsChildAgent) return;
1197
1198 // Remove from database and parcel prim count
1199 m_scene.DeleteFromStorage(so.UUID);
1200 m_scene.EventManager.TriggerParcelPrimCountTainted();
1201
1202 so.AttachedAvatar = avatar.UUID;
1203
1204 if (so.RootPart.PhysActor != null)
1205 {
1206 m_scene.PhysicsScene.RemovePrim(so.RootPart.PhysActor);
1207 so.RootPart.PhysActor = null;
1208 }
1209
1210 so.AbsolutePosition = attachOffset;
1211 so.RootPart.AttachedPos = attachOffset;
1212 so.IsAttachment = true;
1213 so.RootPart.SetParentLocalId(avatar.LocalId);
1214 so.AttachmentPoint = attachmentpoint;
1215
1216 avatar.AddAttachment(this);
1217
1218 if (!silent)
1219 {
1220 // Killing it here will cause the client to deselect it
1221 // It then reappears on the avatar, deselected
1222 // through the full update below
1223 //
1224 if (IsSelected)
1225 {
1226 m_scene.SendKillObject(new List<uint> { m_rootPart.LocalId });
1227 }
1228
1229 IsSelected = false; // fudge....
1230 ScheduleGroupForFullUpdate();
1231 }
1232 }
1233 else
1234 {
1235 m_log.WarnFormat(
1236 "[SOG]: Tried to add attachment {0} to avatar with UUID {1} in region {2} but the avatar is not present",
1237 UUID, avatar.ControllingClient.AgentId, Scene.RegionInfo.RegionName);
1238 }
1239 }
1240
1241 public byte GetAttachmentPoint()
1242 {
1243 return m_rootPart.Shape.State;
1244 }
1245
1246 public void DetachToGround()
1247 {
1248 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
1249 if (avatar == null)
1250 return;
1251
1252 avatar.RemoveAttachment(this);
1253
1254 Vector3 detachedpos = new Vector3(127f,127f,127f);
1255 if (avatar == null)
1256 return;
1257
1258 detachedpos = avatar.AbsolutePosition;
1259 RootPart.FromItemID = UUID.Zero;
1260
1261 AbsolutePosition = detachedpos;
1262 AttachedAvatar = UUID.Zero;
1263
1264 //SceneObjectPart[] parts = m_parts.GetArray();
1265 //for (int i = 0; i < parts.Length; i++)
1266 // parts[i].AttachedAvatar = UUID.Zero;
1267
1268 m_rootPart.SetParentLocalId(0);
1269 AttachmentPoint = (byte)0;
1270 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_scene.m_physicalPrim);
1271 HasGroupChanged = true;
1272 RootPart.Rezzed = DateTime.Now;
1273 RootPart.RemFlag(PrimFlags.TemporaryOnRez);
1274 AttachToBackup();
1275 m_scene.EventManager.TriggerParcelPrimCountTainted();
1276 m_rootPart.ScheduleFullUpdate();
1277 m_rootPart.ClearUndoState();
1278 }
1279
1280 public void DetachToInventoryPrep()
1281 {
1282 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
1283 //Vector3 detachedpos = new Vector3(127f, 127f, 127f);
1284 if (avatar != null)
1285 {
1286 //detachedpos = avatar.AbsolutePosition;
1287 avatar.RemoveAttachment(this);
1288 }
1289
1290 AttachedAvatar = UUID.Zero;
1291
1292 /*SceneObjectPart[] parts = m_parts.GetArray();
1293 for (int i = 0; i < parts.Length; i++)
1294 parts[i].AttachedAvatar = UUID.Zero;*/
1295
1296 m_rootPart.SetParentLocalId(0);
1297 //m_rootPart.SetAttachmentPoint((byte)0);
1298 IsAttachment = false;
1299 AbsolutePosition = m_rootPart.AttachedPos;
1300 //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
1301 //AttachToBackup();
1302 //m_rootPart.ScheduleFullUpdate();
1303 }
1304
1305 /// <summary>
999 /// 1306 ///
1000 /// </summary> 1307 /// </summary>
1001 /// <param name="part"></param> 1308 /// <param name="part"></param>
@@ -1045,7 +1352,10 @@ namespace OpenSim.Region.Framework.Scenes
1045 public void AddPart(SceneObjectPart part) 1352 public void AddPart(SceneObjectPart part)
1046 { 1353 {
1047 part.SetParent(this); 1354 part.SetParent(this);
1048 part.LinkNum = m_parts.Add(part.UUID, part); 1355 m_parts.Add(part.UUID, part);
1356
1357 part.LinkNum = m_parts.Count;
1358
1049 if (part.LinkNum == 2) 1359 if (part.LinkNum == 2)
1050 RootPart.LinkNum = 1; 1360 RootPart.LinkNum = 1;
1051 } 1361 }
@@ -1153,6 +1463,11 @@ namespace OpenSim.Region.Framework.Scenes
1153 /// <param name="silent">If true then deletion is not broadcast to clients</param> 1463 /// <param name="silent">If true then deletion is not broadcast to clients</param>
1154 public void DeleteGroupFromScene(bool silent) 1464 public void DeleteGroupFromScene(bool silent)
1155 { 1465 {
1466 // We need to keep track of this state in case this group is still queued for backup.
1467 IsDeleted = true;
1468
1469 DetachFromBackup();
1470
1156 SceneObjectPart[] parts = m_parts.GetArray(); 1471 SceneObjectPart[] parts = m_parts.GetArray();
1157 for (int i = 0; i < parts.Length; i++) 1472 for (int i = 0; i < parts.Length; i++)
1158 { 1473 {
@@ -1164,17 +1479,19 @@ namespace OpenSim.Region.Framework.Scenes
1164 avatar.StandUp(); 1479 avatar.StandUp();
1165 1480
1166 if (!silent) 1481 if (!silent)
1167 { 1482 {
1168 part.UpdateFlag = 0; 1483 part.UpdateFlag = 0;
1169 if (part == m_rootPart) 1484 if (part == m_rootPart)
1170 { 1485 {
1171 if (!IsAttachment || (AttachedAvatar == avatar.ControllingClient.AgentId) || 1486 if (!IsAttachment || (AttachedAvatar == avatar.ControllingClient.AgentId) ||
1172 (AttachmentPoint < 31) || (AttachmentPoint > 38)) 1487 (AttachmentPoint < 31) || (AttachmentPoint > 38))
1173 avatar.ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1488 avatar.ControllingClient.SendKillObject(m_regionHandle, new List<uint>() {part.LocalId});
1174 } 1489 }
1175 } 1490 }
1176 }); 1491 });
1177 } 1492 }
1493
1494
1178 } 1495 }
1179 1496
1180 public void AddScriptLPS(int count) 1497 public void AddScriptLPS(int count)
@@ -1271,7 +1588,12 @@ namespace OpenSim.Region.Framework.Scenes
1271 1588
1272 public void SetOwnerId(UUID userId) 1589 public void SetOwnerId(UUID userId)
1273 { 1590 {
1274 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1591 ForEachPart(delegate(SceneObjectPart part)
1592 {
1593
1594 part.OwnerID = userId;
1595
1596 });
1275 } 1597 }
1276 1598
1277 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1599 public void ForEachPart(Action<SceneObjectPart> whatToDo)
@@ -1303,11 +1625,17 @@ namespace OpenSim.Region.Framework.Scenes
1303 return; 1625 return;
1304 } 1626 }
1305 1627
1628 if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1629 return;
1630
1306 // Since this is the top of the section of call stack for backing up a particular scene object, don't let 1631 // Since this is the top of the section of call stack for backing up a particular scene object, don't let
1307 // any exception propogate upwards. 1632 // any exception propogate upwards.
1308 try 1633 try
1309 { 1634 {
1310 if (!m_scene.ShuttingDown) // if shutting down then there will be nothing to handle the return so leave till next restart 1635 if (!m_scene.ShuttingDown || // if shutting down then there will be nothing to handle the return so leave till next restart
1636 m_scene.LoginsDisabled || // We're starting up or doing maintenance, don't mess with things
1637 m_scene.LoadingPrims) // Land may not be valid yet
1638
1311 { 1639 {
1312 ILandObject parcel = m_scene.LandChannel.GetLandObject( 1640 ILandObject parcel = m_scene.LandChannel.GetLandObject(
1313 m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); 1641 m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
@@ -1334,6 +1662,7 @@ namespace OpenSim.Region.Framework.Scenes
1334 } 1662 }
1335 } 1663 }
1336 } 1664 }
1665
1337 } 1666 }
1338 1667
1339 if (m_scene.UseBackup && HasGroupChanged) 1668 if (m_scene.UseBackup && HasGroupChanged)
@@ -1341,6 +1670,20 @@ namespace OpenSim.Region.Framework.Scenes
1341 // don't backup while it's selected or you're asking for changes mid stream. 1670 // don't backup while it's selected or you're asking for changes mid stream.
1342 if (isTimeToPersist() || forcedBackup) 1671 if (isTimeToPersist() || forcedBackup)
1343 { 1672 {
1673 if (m_rootPart.PhysActor != null &&
1674 (!m_rootPart.PhysActor.IsPhysical))
1675 {
1676 // Possible ghost prim
1677 if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition)
1678 {
1679 foreach (SceneObjectPart part in m_parts.GetArray())
1680 {
1681 // Re-set physics actor positions and
1682 // orientations
1683 part.GroupPosition = m_rootPart.GroupPosition;
1684 }
1685 }
1686 }
1344// m_log.DebugFormat( 1687// m_log.DebugFormat(
1345// "[SCENE]: Storing {0}, {1} in {2}", 1688// "[SCENE]: Storing {0}, {1} in {2}",
1346// Name, UUID, m_scene.RegionInfo.RegionName); 1689// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -1418,7 +1761,7 @@ namespace OpenSim.Region.Framework.Scenes
1418 // This is only necessary when userExposed is false! 1761 // This is only necessary when userExposed is false!
1419 1762
1420 bool previousAttachmentStatus = dupe.IsAttachment; 1763 bool previousAttachmentStatus = dupe.IsAttachment;
1421 1764
1422 if (!userExposed) 1765 if (!userExposed)
1423 dupe.IsAttachment = true; 1766 dupe.IsAttachment = true;
1424 1767
@@ -1436,11 +1779,11 @@ namespace OpenSim.Region.Framework.Scenes
1436 dupe.m_rootPart.TrimPermissions(); 1779 dupe.m_rootPart.TrimPermissions();
1437 1780
1438 List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray()); 1781 List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
1439 1782
1440 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1783 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1441 { 1784 {
1442 return p1.LinkNum.CompareTo(p2.LinkNum); 1785 return p1.LinkNum.CompareTo(p2.LinkNum);
1443 } 1786 }
1444 ); 1787 );
1445 1788
1446 foreach (SceneObjectPart part in partList) 1789 foreach (SceneObjectPart part in partList)
@@ -1460,7 +1803,7 @@ namespace OpenSim.Region.Framework.Scenes
1460 if (part.PhysActor != null && userExposed) 1803 if (part.PhysActor != null && userExposed)
1461 { 1804 {
1462 PrimitiveBaseShape pbs = newPart.Shape; 1805 PrimitiveBaseShape pbs = newPart.Shape;
1463 1806
1464 newPart.PhysActor 1807 newPart.PhysActor
1465 = m_scene.PhysicsScene.AddPrimShape( 1808 = m_scene.PhysicsScene.AddPrimShape(
1466 string.Format("{0}/{1}", newPart.Name, newPart.UUID), 1809 string.Format("{0}/{1}", newPart.Name, newPart.UUID),
@@ -1470,11 +1813,11 @@ namespace OpenSim.Region.Framework.Scenes
1470 newPart.RotationOffset, 1813 newPart.RotationOffset,
1471 part.PhysActor.IsPhysical, 1814 part.PhysActor.IsPhysical,
1472 newPart.LocalId); 1815 newPart.LocalId);
1473 1816
1474 newPart.DoPhysicsPropertyUpdate(part.PhysActor.IsPhysical, true); 1817 newPart.DoPhysicsPropertyUpdate(part.PhysActor.IsPhysical, true);
1475 } 1818 }
1476 } 1819 }
1477 1820
1478 if (userExposed) 1821 if (userExposed)
1479 { 1822 {
1480 dupe.UpdateParentIDs(); 1823 dupe.UpdateParentIDs();
@@ -1589,6 +1932,7 @@ namespace OpenSim.Region.Framework.Scenes
1589 return Vector3.Zero; 1932 return Vector3.Zero;
1590 } 1933 }
1591 1934
1935 // This is used by both Double-Click Auto-Pilot and llMoveToTarget() in an attached object
1592 public void moveToTarget(Vector3 target, float tau) 1936 public void moveToTarget(Vector3 target, float tau)
1593 { 1937 {
1594 if (IsAttachment) 1938 if (IsAttachment)
@@ -1616,10 +1960,44 @@ namespace OpenSim.Region.Framework.Scenes
1616 RootPart.PhysActor.PIDActive = false; 1960 RootPart.PhysActor.PIDActive = false;
1617 } 1961 }
1618 1962
1963 public void rotLookAt(Quaternion target, float strength, float damping)
1964 {
1965 SceneObjectPart rootpart = m_rootPart;
1966 if (rootpart != null)
1967 {
1968 if (IsAttachment)
1969 {
1970 /*
1971 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
1972 if (avatar != null)
1973 {
1974 Rotate the Av?
1975 } */
1976 }
1977 else
1978 {
1979 if (rootpart.PhysActor != null)
1980 { // APID must be implemented in your physics system for this to function.
1981 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
1982 rootpart.PhysActor.APIDStrength = strength;
1983 rootpart.PhysActor.APIDDamping = damping;
1984 rootpart.PhysActor.APIDActive = true;
1985 }
1986 }
1987 }
1988 }
1989
1619 public void stopLookAt() 1990 public void stopLookAt()
1620 { 1991 {
1621 if (RootPart.PhysActor != null) 1992 SceneObjectPart rootpart = m_rootPart;
1622 RootPart.PhysActor.APIDActive = false; 1993 if (rootpart != null)
1994 {
1995 if (rootpart.PhysActor != null)
1996 { // APID must be implemented in your physics system for this to function.
1997 rootpart.PhysActor.APIDActive = false;
1998 }
1999 }
2000
1623 } 2001 }
1624 2002
1625 /// <summary> 2003 /// <summary>
@@ -1677,6 +2055,8 @@ namespace OpenSim.Region.Framework.Scenes
1677 public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) 2055 public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
1678 { 2056 {
1679 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2057 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
2058 newPart.SetParent(this);
2059
1680 AddPart(newPart); 2060 AddPart(newPart);
1681 2061
1682 SetPartAsNonRoot(newPart); 2062 SetPartAsNonRoot(newPart);
@@ -1823,11 +2203,11 @@ namespace OpenSim.Region.Framework.Scenes
1823 /// Immediately send a full update for this scene object. 2203 /// Immediately send a full update for this scene object.
1824 /// </summary> 2204 /// </summary>
1825 public void SendGroupFullUpdate() 2205 public void SendGroupFullUpdate()
1826 { 2206 {
1827 if (IsDeleted) 2207 if (IsDeleted)
1828 return; 2208 return;
1829 2209
1830// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); 2210// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
1831 2211
1832 RootPart.SendFullUpdateToAllClients(); 2212 RootPart.SendFullUpdateToAllClients();
1833 2213
@@ -1991,6 +2371,7 @@ namespace OpenSim.Region.Framework.Scenes
1991 Quaternion oldRootRotation = linkPart.RotationOffset; 2371 Quaternion oldRootRotation = linkPart.RotationOffset;
1992 2372
1993 linkPart.OffsetPosition = linkPart.GroupPosition - AbsolutePosition; 2373 linkPart.OffsetPosition = linkPart.GroupPosition - AbsolutePosition;
2374 linkPart.ParentID = m_rootPart.LocalId;
1994 linkPart.GroupPosition = AbsolutePosition; 2375 linkPart.GroupPosition = AbsolutePosition;
1995 Vector3 axPos = linkPart.OffsetPosition; 2376 Vector3 axPos = linkPart.OffsetPosition;
1996 2377
@@ -2023,12 +2404,15 @@ namespace OpenSim.Region.Framework.Scenes
2023 part.LinkNum += objectGroup.PrimCount; 2404 part.LinkNum += objectGroup.PrimCount;
2024 } 2405 }
2025 } 2406 }
2407 }
2026 2408
2027 linkPart.LinkNum = 2; 2409 linkPart.LinkNum = 2;
2028 2410
2029 linkPart.SetParent(this); 2411 linkPart.SetParent(this);
2030 linkPart.CreateSelected = true; 2412 linkPart.CreateSelected = true;
2031 2413
2414 lock (m_parts.SyncRoot)
2415 {
2032 //if (linkPart.PhysActor != null) 2416 //if (linkPart.PhysActor != null)
2033 //{ 2417 //{
2034 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2418 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
@@ -2186,6 +2570,7 @@ namespace OpenSim.Region.Framework.Scenes
2186 /// <param name="objectGroup"></param> 2570 /// <param name="objectGroup"></param>
2187 public virtual void DetachFromBackup() 2571 public virtual void DetachFromBackup()
2188 { 2572 {
2573 m_scene.SceneGraph.FireDetachFromBackup(this);
2189 if (m_isBackedUp && Scene != null) 2574 if (m_isBackedUp && Scene != null)
2190 m_scene.EventManager.OnBackup -= ProcessBackup; 2575 m_scene.EventManager.OnBackup -= ProcessBackup;
2191 2576
@@ -2204,7 +2589,8 @@ namespace OpenSim.Region.Framework.Scenes
2204 2589
2205 axPos *= parentRot; 2590 axPos *= parentRot;
2206 part.OffsetPosition = axPos; 2591 part.OffsetPosition = axPos;
2207 part.GroupPosition = oldGroupPosition + part.OffsetPosition; 2592 Vector3 newPos = oldGroupPosition + part.OffsetPosition;
2593 part.GroupPosition = newPos;
2208 part.OffsetPosition = Vector3.Zero; 2594 part.OffsetPosition = Vector3.Zero;
2209 part.RotationOffset = worldRot; 2595 part.RotationOffset = worldRot;
2210 2596
@@ -2215,7 +2601,7 @@ namespace OpenSim.Region.Framework.Scenes
2215 2601
2216 part.LinkNum = linkNum; 2602 part.LinkNum = linkNum;
2217 2603
2218 part.OffsetPosition = part.GroupPosition - AbsolutePosition; 2604 part.OffsetPosition = newPos - AbsolutePosition;
2219 2605
2220 Quaternion rootRotation = m_rootPart.RotationOffset; 2606 Quaternion rootRotation = m_rootPart.RotationOffset;
2221 2607
@@ -2225,7 +2611,7 @@ namespace OpenSim.Region.Framework.Scenes
2225 2611
2226 parentRot = m_rootPart.RotationOffset; 2612 parentRot = m_rootPart.RotationOffset;
2227 oldRot = part.RotationOffset; 2613 oldRot = part.RotationOffset;
2228 Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot; 2614 Quaternion newRot = Quaternion.Inverse(parentRot) * worldRot;
2229 part.RotationOffset = newRot; 2615 part.RotationOffset = newRot;
2230 } 2616 }
2231 2617
@@ -2472,8 +2858,12 @@ namespace OpenSim.Region.Framework.Scenes
2472 } 2858 }
2473 } 2859 }
2474 2860
2861 RootPart.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, SetVolumeDetect);
2475 for (int i = 0; i < parts.Length; i++) 2862 for (int i = 0; i < parts.Length; i++)
2476 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect); 2863 {
2864 if (parts[i] != RootPart)
2865 parts[i].UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, SetVolumeDetect);
2866 }
2477 } 2867 }
2478 } 2868 }
2479 2869
@@ -2486,6 +2876,17 @@ namespace OpenSim.Region.Framework.Scenes
2486 } 2876 }
2487 } 2877 }
2488 2878
2879
2880
2881 /// <summary>
2882 /// Gets the number of parts
2883 /// </summary>
2884 /// <returns></returns>
2885 public int GetPartCount()
2886 {
2887 return Parts.Count();
2888 }
2889
2489 /// <summary> 2890 /// <summary>
2490 /// Update the texture entry for this part 2891 /// Update the texture entry for this part
2491 /// </summary> 2892 /// </summary>
@@ -2542,7 +2943,6 @@ namespace OpenSim.Region.Framework.Scenes
2542 { 2943 {
2543// m_log.DebugFormat( 2944// m_log.DebugFormat(
2544// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale); 2945// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
2545
2546 RootPart.StoreUndoState(true); 2946 RootPart.StoreUndoState(true);
2547 2947
2548 scale.X = Math.Min(scale.X, Scene.m_maxNonphys); 2948 scale.X = Math.Min(scale.X, Scene.m_maxNonphys);
@@ -2643,7 +3043,6 @@ namespace OpenSim.Region.Framework.Scenes
2643 prevScale.X *= x; 3043 prevScale.X *= x;
2644 prevScale.Y *= y; 3044 prevScale.Y *= y;
2645 prevScale.Z *= z; 3045 prevScale.Z *= z;
2646
2647// RootPart.IgnoreUndoUpdate = true; 3046// RootPart.IgnoreUndoUpdate = true;
2648 RootPart.Resize(prevScale); 3047 RootPart.Resize(prevScale);
2649// RootPart.IgnoreUndoUpdate = false; 3048// RootPart.IgnoreUndoUpdate = false;
@@ -2674,7 +3073,9 @@ namespace OpenSim.Region.Framework.Scenes
2674 } 3073 }
2675 3074
2676// obPart.IgnoreUndoUpdate = false; 3075// obPart.IgnoreUndoUpdate = false;
2677// obPart.StoreUndoState(); 3076 HasGroupChanged = true;
3077 m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
3078 ScheduleGroupForTerseUpdate();
2678 } 3079 }
2679 3080
2680// m_log.DebugFormat( 3081// m_log.DebugFormat(
@@ -2734,9 +3135,9 @@ namespace OpenSim.Region.Framework.Scenes
2734 { 3135 {
2735 SceneObjectPart part = GetChildPart(localID); 3136 SceneObjectPart part = GetChildPart(localID);
2736 3137
2737// SceneObjectPart[] parts = m_parts.GetArray(); 3138 SceneObjectPart[] parts = m_parts.GetArray();
2738// for (int i = 0; i < parts.Length; i++) 3139 for (int i = 0; i < parts.Length; i++)
2739// parts[i].StoreUndoState(); 3140 parts[i].StoreUndoState();
2740 3141
2741 if (part != null) 3142 if (part != null)
2742 { 3143 {
@@ -2792,10 +3193,27 @@ namespace OpenSim.Region.Framework.Scenes
2792 obPart.OffsetPosition = obPart.OffsetPosition + diff; 3193 obPart.OffsetPosition = obPart.OffsetPosition + diff;
2793 } 3194 }
2794 3195
2795 AbsolutePosition = newPos; 3196 //We have to set undoing here because otherwise an undo state will be saved
3197 if (!m_rootPart.Undoing)
3198 {
3199 m_rootPart.Undoing = true;
3200 AbsolutePosition = newPos;
3201 m_rootPart.Undoing = false;
3202 }
3203 else
3204 {
3205 AbsolutePosition = newPos;
3206 }
2796 3207
2797 HasGroupChanged = true; 3208 HasGroupChanged = true;
2798 ScheduleGroupForTerseUpdate(); 3209 if (m_rootPart.Undoing)
3210 {
3211 ScheduleGroupForFullUpdate();
3212 }
3213 else
3214 {
3215 ScheduleGroupForTerseUpdate();
3216 }
2799 } 3217 }
2800 3218
2801 public void OffsetForNewRegion(Vector3 offset) 3219 public void OffsetForNewRegion(Vector3 offset)
@@ -2877,10 +3295,7 @@ namespace OpenSim.Region.Framework.Scenes
2877 public void UpdateSingleRotation(Quaternion rot, uint localID) 3295 public void UpdateSingleRotation(Quaternion rot, uint localID)
2878 { 3296 {
2879 SceneObjectPart part = GetChildPart(localID); 3297 SceneObjectPart part = GetChildPart(localID);
2880
2881 SceneObjectPart[] parts = m_parts.GetArray(); 3298 SceneObjectPart[] parts = m_parts.GetArray();
2882 for (int i = 0; i < parts.Length; i++)
2883 parts[i].StoreUndoState();
2884 3299
2885 if (part != null) 3300 if (part != null)
2886 { 3301 {
@@ -2918,7 +3333,16 @@ namespace OpenSim.Region.Framework.Scenes
2918 if (part.UUID == m_rootPart.UUID) 3333 if (part.UUID == m_rootPart.UUID)
2919 { 3334 {
2920 UpdateRootRotation(rot); 3335 UpdateRootRotation(rot);
2921 AbsolutePosition = pos; 3336 if (!m_rootPart.Undoing)
3337 {
3338 m_rootPart.Undoing = true;
3339 AbsolutePosition = pos;
3340 m_rootPart.Undoing = false;
3341 }
3342 else
3343 {
3344 AbsolutePosition = pos;
3345 }
2922 } 3346 }
2923 else 3347 else
2924 { 3348 {
@@ -2942,9 +3366,10 @@ namespace OpenSim.Region.Framework.Scenes
2942 3366
2943 Quaternion axRot = rot; 3367 Quaternion axRot = rot;
2944 Quaternion oldParentRot = m_rootPart.RotationOffset; 3368 Quaternion oldParentRot = m_rootPart.RotationOffset;
2945
2946 m_rootPart.StoreUndoState(); 3369 m_rootPart.StoreUndoState();
2947 m_rootPart.UpdateRotation(rot); 3370
3371 //Don't use UpdateRotation because it schedules an update prematurely
3372 m_rootPart.RotationOffset = rot;
2948 if (m_rootPart.PhysActor != null) 3373 if (m_rootPart.PhysActor != null)
2949 { 3374 {
2950 m_rootPart.PhysActor.Orientation = m_rootPart.RotationOffset; 3375 m_rootPart.PhysActor.Orientation = m_rootPart.RotationOffset;
@@ -2958,15 +3383,18 @@ namespace OpenSim.Region.Framework.Scenes
2958 if (prim.UUID != m_rootPart.UUID) 3383 if (prim.UUID != m_rootPart.UUID)
2959 { 3384 {
2960 prim.IgnoreUndoUpdate = true; 3385 prim.IgnoreUndoUpdate = true;
3386
3387 Quaternion NewRot = oldParentRot * prim.RotationOffset;
3388 NewRot = Quaternion.Inverse(axRot) * NewRot;
3389 prim.RotationOffset = NewRot;
3390
2961 Vector3 axPos = prim.OffsetPosition; 3391 Vector3 axPos = prim.OffsetPosition;
3392
2962 axPos *= oldParentRot; 3393 axPos *= oldParentRot;
2963 axPos *= Quaternion.Inverse(axRot); 3394 axPos *= Quaternion.Inverse(axRot);
2964 prim.OffsetPosition = axPos; 3395 prim.OffsetPosition = axPos;
2965 Quaternion primsRot = prim.RotationOffset; 3396
2966 Quaternion newRot = primsRot * oldParentRot; 3397 prim.IgnoreUndoUpdate = false;
2967 newRot *= Quaternion.Inverse(axRot);
2968 prim.RotationOffset = newRot;
2969 prim.ScheduleTerseUpdate();
2970 prim.IgnoreUndoUpdate = false; 3398 prim.IgnoreUndoUpdate = false;
2971 } 3399 }
2972 } 3400 }
@@ -2980,8 +3408,8 @@ namespace OpenSim.Region.Framework.Scenes
2980//// childpart.StoreUndoState(); 3408//// childpart.StoreUndoState();
2981// } 3409// }
2982// } 3410// }
2983 3411 HasGroupChanged = true;
2984 m_rootPart.ScheduleTerseUpdate(); 3412 ScheduleGroupForFullUpdate();
2985 3413
2986// m_log.DebugFormat( 3414// m_log.DebugFormat(
2987// "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}", 3415// "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}",
@@ -3209,7 +3637,6 @@ namespace OpenSim.Region.Framework.Scenes
3209 public float GetMass() 3637 public float GetMass()
3210 { 3638 {
3211 float retmass = 0f; 3639 float retmass = 0f;
3212
3213 SceneObjectPart[] parts = m_parts.GetArray(); 3640 SceneObjectPart[] parts = m_parts.GetArray();
3214 for (int i = 0; i < parts.Length; i++) 3641 for (int i = 0; i < parts.Length; i++)
3215 retmass += parts[i].GetMass(); 3642 retmass += parts[i].GetMass();
@@ -3303,6 +3730,14 @@ namespace OpenSim.Region.Framework.Scenes
3303 SetFromItemID(uuid); 3730 SetFromItemID(uuid);
3304 } 3731 }
3305 3732
3733 public void ResetOwnerChangeFlag()
3734 {
3735 ForEachPart(delegate(SceneObjectPart part)
3736 {
3737 part.ResetOwnerChangeFlag();
3738 });
3739 }
3740
3306 #endregion 3741 #endregion
3307 } 3742 }
3308} 3743}
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 6fa82b8..1a96f1b 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -62,7 +62,8 @@ namespace OpenSim.Region.Framework.Scenes
62 TELEPORT = 512, 62 TELEPORT = 512,
63 REGION_RESTART = 1024, 63 REGION_RESTART = 1024,
64 MEDIA = 2048, 64 MEDIA = 2048,
65 ANIMATION = 16384 65 ANIMATION = 16384,
66 POSITION = 32768
66 } 67 }
67 68
68 // I don't really know where to put this except here. 69 // I don't really know where to put this except here.
@@ -190,7 +191,15 @@ namespace OpenSim.Region.Framework.Scenes
190 191
191 public UUID FromFolderID; 192 public UUID FromFolderID;
192 193
193 194 // The following two are to hold the attachment data
195 // while an object is inworld
196 [XmlIgnore]
197 public byte AttachPoint = 0;
198
199 [XmlIgnore]
200 public Vector3 AttachOffset = Vector3.Zero;
201
202 [XmlIgnore]
194 public int STATUS_ROTATE_X; 203 public int STATUS_ROTATE_X;
195 204
196 205
@@ -272,6 +281,7 @@ namespace OpenSim.Region.Framework.Scenes
272 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 281 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
273 private Vector3 m_sitTargetPosition; 282 private Vector3 m_sitTargetPosition;
274 private string m_sitAnimation = "SIT"; 283 private string m_sitAnimation = "SIT";
284 private bool m_occupied; // KF if any av is sitting on this prim
275 private string m_text = String.Empty; 285 private string m_text = String.Empty;
276 private string m_touchName = String.Empty; 286 private string m_touchName = String.Empty;
277 private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5); 287 private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5);
@@ -315,6 +325,7 @@ namespace OpenSim.Region.Framework.Scenes
315 protected Vector3 m_lastAcceleration; 325 protected Vector3 m_lastAcceleration;
316 protected Vector3 m_lastAngularVelocity; 326 protected Vector3 m_lastAngularVelocity;
317 protected int m_lastTerseSent; 327 protected int m_lastTerseSent;
328 protected float m_buoyancy = 0.0f;
318 329
319 /// <summary> 330 /// <summary>
320 /// Stores media texture data 331 /// Stores media texture data
@@ -367,7 +378,7 @@ namespace OpenSim.Region.Framework.Scenes
367 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, 378 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
368 Quaternion rotationOffset, Vector3 offsetPosition) 379 Quaternion rotationOffset, Vector3 offsetPosition)
369 { 380 {
370 m_name = "Primitive"; 381 m_name = "Object";
371 382
372 Rezzed = DateTime.UtcNow; 383 Rezzed = DateTime.UtcNow;
373 _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed); 384 _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
@@ -422,7 +433,7 @@ namespace OpenSim.Region.Framework.Scenes
422 private uint _ownerMask = (uint)PermissionMask.All; 433 private uint _ownerMask = (uint)PermissionMask.All;
423 private uint _groupMask = (uint)PermissionMask.None; 434 private uint _groupMask = (uint)PermissionMask.None;
424 private uint _everyoneMask = (uint)PermissionMask.None; 435 private uint _everyoneMask = (uint)PermissionMask.None;
425 private uint _nextOwnerMask = (uint)PermissionMask.All; 436 private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
426 private PrimFlags _flags = PrimFlags.None; 437 private PrimFlags _flags = PrimFlags.None;
427 private DateTime m_expires; 438 private DateTime m_expires;
428 private DateTime m_rezzed; 439 private DateTime m_rezzed;
@@ -521,12 +532,16 @@ namespace OpenSim.Region.Framework.Scenes
521 } 532 }
522 533
523 /// <value> 534 /// <value>
524 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 535 /// Get the inventory list
525 /// </value> 536 /// </value>
526 public TaskInventoryDictionary TaskInventory 537 public TaskInventoryDictionary TaskInventory
527 { 538 {
528 get { return m_inventory.Items; } 539 get {
529 set { m_inventory.Items = value; } 540 return m_inventory.Items;
541 }
542 set {
543 m_inventory.Items = value;
544 }
530 } 545 }
531 546
532 /// <summary> 547 /// <summary>
@@ -667,14 +682,12 @@ namespace OpenSim.Region.Framework.Scenes
667 set { m_LoopSoundSlavePrims = value; } 682 set { m_LoopSoundSlavePrims = value; }
668 } 683 }
669 684
670
671 public Byte[] TextureAnimation 685 public Byte[] TextureAnimation
672 { 686 {
673 get { return m_TextureAnimation; } 687 get { return m_TextureAnimation; }
674 set { m_TextureAnimation = value; } 688 set { m_TextureAnimation = value; }
675 } 689 }
676 690
677
678 public Byte[] ParticleSystem 691 public Byte[] ParticleSystem
679 { 692 {
680 get { return m_particleSystem; } 693 get { return m_particleSystem; }
@@ -711,9 +724,11 @@ namespace OpenSim.Region.Framework.Scenes
711 { 724 {
712 // If this is a linkset, we don't want the physics engine mucking up our group position here. 725 // If this is a linkset, we don't want the physics engine mucking up our group position here.
713 PhysicsActor actor = PhysActor; 726 PhysicsActor actor = PhysActor;
714 if (actor != null && _parentID == 0) 727 if (_parentID == 0)
715 { 728 {
716 m_groupPosition = actor.Position; 729 if (actor != null)
730 m_groupPosition = actor.Position;
731 return m_groupPosition;
717 } 732 }
718 733
719 if (m_parentGroup.IsAttachment) 734 if (m_parentGroup.IsAttachment)
@@ -723,12 +738,14 @@ namespace OpenSim.Region.Framework.Scenes
723 return sp.AbsolutePosition; 738 return sp.AbsolutePosition;
724 } 739 }
725 740
741 // use root prim's group position. Physics may have updated it
742 if (ParentGroup.RootPart != this)
743 m_groupPosition = ParentGroup.RootPart.GroupPosition;
726 return m_groupPosition; 744 return m_groupPosition;
727 } 745 }
728 set 746 set
729 { 747 {
730 m_groupPosition = value; 748 m_groupPosition = value;
731
732 PhysicsActor actor = PhysActor; 749 PhysicsActor actor = PhysActor;
733 if (actor != null) 750 if (actor != null)
734 { 751 {
@@ -748,22 +765,13 @@ namespace OpenSim.Region.Framework.Scenes
748 765
749 // Tell the physics engines that this prim changed. 766 // Tell the physics engines that this prim changed.
750 m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); 767 m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
768
751 } 769 }
752 catch (Exception e) 770 catch (Exception e)
753 { 771 {
754 m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message); 772 m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message);
755 } 773 }
756 } 774 }
757
758 // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
759 if (m_sitTargetAvatar != UUID.Zero)
760 {
761 ScenePresence avatar;
762 if (m_parentGroup.Scene.TryGetScenePresence(m_sitTargetAvatar, out avatar))
763 {
764 avatar.ParentPosition = GetWorldPosition();
765 }
766 }
767 } 775 }
768 } 776 }
769 777
@@ -772,7 +780,7 @@ namespace OpenSim.Region.Framework.Scenes
772 get { return m_offsetPosition; } 780 get { return m_offsetPosition; }
773 set 781 set
774 { 782 {
775// StoreUndoState(); 783 Vector3 oldpos = m_offsetPosition;
776 m_offsetPosition = value; 784 m_offsetPosition = value;
777 785
778 if (ParentGroup != null && !ParentGroup.IsDeleted) 786 if (ParentGroup != null && !ParentGroup.IsDeleted)
@@ -787,7 +795,22 @@ namespace OpenSim.Region.Framework.Scenes
787 if (m_parentGroup.Scene != null) 795 if (m_parentGroup.Scene != null)
788 m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); 796 m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
789 } 797 }
798
799 if (!m_parentGroup.m_dupeInProgress)
800 {
801 List<ScenePresence> avs = ParentGroup.GetLinkedAvatars();
802 foreach (ScenePresence av in avs)
803 {
804 if (av.LinkedPrim == m_uuid)
805 {
806 Vector3 offset = (m_offsetPosition - oldpos);
807 av.AbsolutePosition += offset;
808 av.SendAvatarDataToAllAgents();
809 }
810 }
811 }
790 } 812 }
813 TriggerScriptChangedEvent(Changed.POSITION);
791 } 814 }
792 } 815 }
793 816
@@ -914,7 +937,16 @@ namespace OpenSim.Region.Framework.Scenes
914 /// <summary></summary> 937 /// <summary></summary>
915 public Vector3 Acceleration 938 public Vector3 Acceleration
916 { 939 {
917 get { return m_acceleration; } 940 get
941 {
942 PhysicsActor actor = PhysActor;
943 if (actor != null)
944 {
945 m_acceleration = actor.Acceleration;
946 }
947 return m_acceleration;
948 }
949
918 set { m_acceleration = value; } 950 set { m_acceleration = value; }
919 } 951 }
920 952
@@ -1245,6 +1277,13 @@ namespace OpenSim.Region.Framework.Scenes
1245 _flags = value; 1277 _flags = value;
1246 } 1278 }
1247 } 1279 }
1280
1281 [XmlIgnore]
1282 public bool IsOccupied // KF If an av is sittingon this prim
1283 {
1284 get { return m_occupied; }
1285 set { m_occupied = value; }
1286 }
1248 1287
1249 1288
1250 public UUID SitTargetAvatar 1289 public UUID SitTargetAvatar
@@ -1303,6 +1342,19 @@ namespace OpenSim.Region.Framework.Scenes
1303 set { m_collisionSoundVolume = value; } 1342 set { m_collisionSoundVolume = value; }
1304 } 1343 }
1305 1344
1345 public float Buoyancy
1346 {
1347 get { return m_buoyancy; }
1348 set
1349 {
1350 m_buoyancy = value;
1351 if (PhysActor != null)
1352 {
1353 PhysActor.Buoyancy = value;
1354 }
1355 }
1356 }
1357
1306 #endregion Public Properties with only Get 1358 #endregion Public Properties with only Get
1307 1359
1308 private uint ApplyMask(uint val, bool set, uint mask) 1360 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1672,6 +1724,9 @@ namespace OpenSim.Region.Framework.Scenes
1672 1724
1673 // Move afterwards ResetIDs as it clears the localID 1725 // Move afterwards ResetIDs as it clears the localID
1674 dupe.LocalId = localID; 1726 dupe.LocalId = localID;
1727 if(dupe.PhysActor != null)
1728 dupe.PhysActor.LocalID = localID;
1729
1675 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 1730 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1676 dupe._lastOwnerID = OwnerID; 1731 dupe._lastOwnerID = OwnerID;
1677 1732
@@ -2035,19 +2090,17 @@ namespace OpenSim.Region.Framework.Scenes
2035 public Vector3 GetWorldPosition() 2090 public Vector3 GetWorldPosition()
2036 { 2091 {
2037 Quaternion parentRot = ParentGroup.RootPart.RotationOffset; 2092 Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
2038
2039 Vector3 axPos = OffsetPosition; 2093 Vector3 axPos = OffsetPosition;
2040
2041 axPos *= parentRot; 2094 axPos *= parentRot;
2042 Vector3 translationOffsetPosition = axPos; 2095 Vector3 translationOffsetPosition = axPos;
2043 2096 if(_parentID == 0)
2044// m_log.DebugFormat("[SCENE OBJECT PART]: Found group pos {0} for part {1}", GroupPosition, Name); 2097 {
2045 2098 return GroupPosition;
2046 Vector3 worldPos = GroupPosition + translationOffsetPosition; 2099 }
2047 2100 else
2048// m_log.DebugFormat("[SCENE OBJECT PART]: Found world pos {0} for part {1}", worldPos, Name); 2101 {
2049 2102 return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position
2050 return worldPos; 2103 }
2051 } 2104 }
2052 2105
2053 /// <summary> 2106 /// <summary>
@@ -2687,17 +2740,18 @@ namespace OpenSim.Region.Framework.Scenes
2687 //Trys to fetch sound id from prim's inventory. 2740 //Trys to fetch sound id from prim's inventory.
2688 //Prim's inventory doesn't support non script items yet 2741 //Prim's inventory doesn't support non script items yet
2689 2742
2690 lock (TaskInventory) 2743 TaskInventory.LockItemsForRead(true);
2744
2745 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2691 { 2746 {
2692 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2747 if (item.Value.Name == sound)
2693 { 2748 {
2694 if (item.Value.Name == sound) 2749 soundID = item.Value.ItemID;
2695 { 2750 break;
2696 soundID = item.Value.ItemID;
2697 break;
2698 }
2699 } 2751 }
2700 } 2752 }
2753
2754 TaskInventory.LockItemsForRead(false);
2701 } 2755 }
2702 2756
2703 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp) 2757 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
@@ -2782,7 +2836,7 @@ namespace OpenSim.Region.Framework.Scenes
2782 2836
2783 public void RotLookAt(Quaternion target, float strength, float damping) 2837 public void RotLookAt(Quaternion target, float strength, float damping)
2784 { 2838 {
2785 rotLookAt(target, strength, damping); 2839 m_parentGroup.rotLookAt(target, strength, damping); // This calls method in SceneObjectGroup.
2786 } 2840 }
2787 2841
2788 public void rotLookAt(Quaternion target, float strength, float damping) 2842 public void rotLookAt(Quaternion target, float strength, float damping)
@@ -3027,8 +3081,8 @@ namespace OpenSim.Region.Framework.Scenes
3027 { 3081 {
3028 const float ROTATION_TOLERANCE = 0.01f; 3082 const float ROTATION_TOLERANCE = 0.01f;
3029 const float VELOCITY_TOLERANCE = 0.001f; 3083 const float VELOCITY_TOLERANCE = 0.001f;
3030 const float POSITION_TOLERANCE = 0.05f; 3084 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
3031 const int TIME_MS_TOLERANCE = 3000; 3085 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
3032 3086
3033 if (m_updateFlag == 1) 3087 if (m_updateFlag == 1)
3034 { 3088 {
@@ -3042,7 +3096,7 @@ namespace OpenSim.Region.Framework.Scenes
3042 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 3096 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
3043 { 3097 {
3044 AddTerseUpdateToAllAvatars(); 3098 AddTerseUpdateToAllAvatars();
3045 ClearUpdateSchedule(); 3099
3046 3100
3047 // This causes the Scene to 'poll' physical objects every couple of frames 3101 // This causes the Scene to 'poll' physical objects every couple of frames
3048 // bad, so it's been replaced by an event driven method. 3102 // bad, so it's been replaced by an event driven method.
@@ -3060,16 +3114,18 @@ namespace OpenSim.Region.Framework.Scenes
3060 m_lastAngularVelocity = AngularVelocity; 3114 m_lastAngularVelocity = AngularVelocity;
3061 m_lastTerseSent = Environment.TickCount; 3115 m_lastTerseSent = Environment.TickCount;
3062 } 3116 }
3117 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
3118 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
3063 } 3119 }
3064 else 3120 else
3065 { 3121 {
3066 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes 3122 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
3067 { 3123 {
3068 AddFullUpdateToAllAvatars(); 3124 AddFullUpdateToAllAvatars();
3069 ClearUpdateSchedule(); 3125 m_updateFlag = 0; //Same here
3070 } 3126 }
3071 } 3127 }
3072 ClearUpdateSchedule(); 3128 m_updateFlag = 0;
3073 } 3129 }
3074 3130
3075 /// <summary> 3131 /// <summary>
@@ -3097,17 +3153,16 @@ namespace OpenSim.Region.Framework.Scenes
3097 if (!UUID.TryParse(sound, out soundID)) 3153 if (!UUID.TryParse(sound, out soundID))
3098 { 3154 {
3099 // search sound file from inventory 3155 // search sound file from inventory
3100 lock (TaskInventory) 3156 TaskInventory.LockItemsForRead(true);
3157 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3101 { 3158 {
3102 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3159 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3103 { 3160 {
3104 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3161 soundID = item.Value.ItemID;
3105 { 3162 break;
3106 soundID = item.Value.ItemID;
3107 break;
3108 }
3109 } 3163 }
3110 } 3164 }
3165 TaskInventory.LockItemsForRead(false);
3111 } 3166 }
3112 3167
3113 if (soundID == UUID.Zero) 3168 if (soundID == UUID.Zero)
@@ -3518,7 +3573,7 @@ namespace OpenSim.Region.Framework.Scenes
3518 3573
3519 public void StopLookAt() 3574 public void StopLookAt()
3520 { 3575 {
3521 m_parentGroup.stopLookAt(); 3576 m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup.
3522 3577
3523 m_parentGroup.ScheduleGroupForTerseUpdate(); 3578 m_parentGroup.ScheduleGroupForTerseUpdate();
3524 } 3579 }
@@ -3569,45 +3624,45 @@ namespace OpenSim.Region.Framework.Scenes
3569 // TODO: May need to fix for group comparison 3624 // TODO: May need to fix for group comparison
3570 if (last.Compare(this)) 3625 if (last.Compare(this))
3571 { 3626 {
3572 // m_log.DebugFormat( 3627 // m_log.DebugFormat(
3573 // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}", 3628 // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
3574 // Name, LocalId, m_undo.Count); 3629 // Name, LocalId, m_undo.Count);
3575 3630
3576 return; 3631 return;
3577 } 3632 }
3578 } 3633 }
3579 } 3634 }
3580 3635
3581 // m_log.DebugFormat( 3636 // m_log.DebugFormat(
3582 // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}", 3637 // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
3583 // Name, LocalId, forGroup, m_undo.Count); 3638 // Name, LocalId, forGroup, m_undo.Count);
3584 3639
3585 if (m_parentGroup.GetSceneMaxUndo() > 0) 3640 if (m_parentGroup.GetSceneMaxUndo() > 0)
3586 { 3641 {
3587 UndoState nUndo = new UndoState(this, forGroup); 3642 UndoState nUndo = new UndoState(this, forGroup);
3588 3643
3589 m_undo.Push(nUndo); 3644 m_undo.Push(nUndo);
3590 3645
3591 if (m_redo.Count > 0) 3646 if (m_redo.Count > 0)
3592 m_redo.Clear(); 3647 m_redo.Clear();
3593 3648
3594 // m_log.DebugFormat( 3649 // m_log.DebugFormat(
3595 // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}", 3650 // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
3596 // Name, LocalId, forGroup, m_undo.Count); 3651 // Name, LocalId, forGroup, m_undo.Count);
3597 } 3652 }
3598 } 3653 }
3599 } 3654 }
3600 } 3655 }
3601// else 3656 // else
3602// { 3657 // {
3603// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId); 3658 // m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
3604// } 3659 // }
3605 } 3660 }
3606// else 3661 // else
3607// { 3662 // {
3608// m_log.DebugFormat( 3663 // m_log.DebugFormat(
3609// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId); 3664 // "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3610// } 3665 // }
3611 } 3666 }
3612 3667
3613 /// <summary> 3668 /// <summary>
@@ -4653,8 +4708,9 @@ namespace OpenSim.Region.Framework.Scenes
4653 { 4708 {
4654 m_shape.TextureEntry = textureEntry; 4709 m_shape.TextureEntry = textureEntry;
4655 TriggerScriptChangedEvent(Changed.TEXTURE); 4710 TriggerScriptChangedEvent(Changed.TEXTURE);
4656 4711 m_updateFlag = 1;
4657 ParentGroup.HasGroupChanged = true; 4712 ParentGroup.HasGroupChanged = true;
4713
4658 //This is madness.. 4714 //This is madness..
4659 //ParentGroup.ScheduleGroupForFullUpdate(); 4715 //ParentGroup.ScheduleGroupForFullUpdate();
4660 //This is sparta 4716 //This is sparta
@@ -4846,5 +4902,17 @@ namespace OpenSim.Region.Framework.Scenes
4846 Color color = Color; 4902 Color color = Color;
4847 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 4903 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4848 } 4904 }
4905
4906 public void ResetOwnerChangeFlag()
4907 {
4908 List<UUID> inv = Inventory.GetInventoryList();
4909
4910 foreach (UUID itemID in inv)
4911 {
4912 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
4913 item.OwnerChanged = false;
4914 Inventory.UpdateInventoryItem(item, false, false);
4915 }
4916 }
4849 } 4917 }
4850} 4918}
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 9446741..4edc220 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -48,6 +48,9 @@ namespace OpenSim.Region.Framework.Scenes
48 private string m_inventoryFileName = String.Empty; 48 private string m_inventoryFileName = String.Empty;
49 private byte[] m_inventoryFileData = new byte[0]; 49 private byte[] m_inventoryFileData = new byte[0];
50 private uint m_inventoryFileNameSerial = 0; 50 private uint m_inventoryFileNameSerial = 0;
51 private bool m_inventoryPrivileged = false;
52
53 private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>();
51 54
52 /// <value> 55 /// <value>
53 /// The part to which the inventory belongs. 56 /// The part to which the inventory belongs.
@@ -84,11 +87,14 @@ namespace OpenSim.Region.Framework.Scenes
84 /// </value> 87 /// </value>
85 protected internal TaskInventoryDictionary Items 88 protected internal TaskInventoryDictionary Items
86 { 89 {
87 get { return m_items; } 90 get {
91 return m_items;
92 }
88 set 93 set
89 { 94 {
90 m_items = value; 95 m_items = value;
91 m_inventorySerial++; 96 m_inventorySerial++;
97 QueryScriptStates();
92 } 98 }
93 } 99 }
94 100
@@ -123,38 +129,45 @@ namespace OpenSim.Region.Framework.Scenes
123 public void ResetInventoryIDs() 129 public void ResetInventoryIDs()
124 { 130 {
125 if (null == m_part) 131 if (null == m_part)
126 return; 132 m_items.LockItemsForWrite(true);
127 133
128 lock (m_items) 134 if (Items.Count == 0)
129 { 135 {
130 if (0 == m_items.Count) 136 m_items.LockItemsForWrite(false);
131 return; 137 return;
138 }
132 139
133 IList<TaskInventoryItem> items = GetInventoryItems(); 140 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
134 m_items.Clear(); 141 Items.Clear();
135 142
136 foreach (TaskInventoryItem item in items) 143 foreach (TaskInventoryItem item in items)
137 { 144 {
138 item.ResetIDs(m_part.UUID); 145 item.ResetIDs(m_part.UUID);
139 m_items.Add(item.ItemID, item); 146 Items.Add(item.ItemID, item);
140 }
141 } 147 }
148 m_items.LockItemsForWrite(false);
142 } 149 }
143 150
144 public void ResetObjectID() 151 public void ResetObjectID()
145 { 152 {
146 lock (Items) 153 m_items.LockItemsForWrite(true);
154
155 if (Items.Count == 0)
147 { 156 {
148 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 157 m_items.LockItemsForWrite(false);
149 Items.Clear(); 158 return;
150
151 foreach (TaskInventoryItem item in items)
152 {
153 item.ParentPartID = m_part.UUID;
154 item.ParentID = m_part.UUID;
155 Items.Add(item.ItemID, item);
156 }
157 } 159 }
160
161 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
162 Items.Clear();
163
164 foreach (TaskInventoryItem item in items)
165 {
166 item.ParentPartID = m_part.UUID;
167 item.ParentID = m_part.UUID;
168 Items.Add(item.ItemID, item);
169 }
170 m_items.LockItemsForWrite(false);
158 } 171 }
159 172
160 /// <summary> 173 /// <summary>
@@ -163,12 +176,11 @@ namespace OpenSim.Region.Framework.Scenes
163 /// <param name="ownerId"></param> 176 /// <param name="ownerId"></param>
164 public void ChangeInventoryOwner(UUID ownerId) 177 public void ChangeInventoryOwner(UUID ownerId)
165 { 178 {
166 lock (Items) 179 m_items.LockItemsForWrite(true);
180 if (0 == Items.Count)
167 { 181 {
168 if (0 == Items.Count) 182 m_items.LockItemsForWrite(false);
169 { 183 return;
170 return;
171 }
172 } 184 }
173 185
174 HasInventoryChanged = true; 186 HasInventoryChanged = true;
@@ -184,6 +196,7 @@ namespace OpenSim.Region.Framework.Scenes
184 item.PermsGranter = UUID.Zero; 196 item.PermsGranter = UUID.Zero;
185 item.OwnerChanged = true; 197 item.OwnerChanged = true;
186 } 198 }
199 m_items.LockItemsForWrite(false);
187 } 200 }
188 201
189 /// <summary> 202 /// <summary>
@@ -192,12 +205,11 @@ namespace OpenSim.Region.Framework.Scenes
192 /// <param name="groupID"></param> 205 /// <param name="groupID"></param>
193 public void ChangeInventoryGroup(UUID groupID) 206 public void ChangeInventoryGroup(UUID groupID)
194 { 207 {
195 lock (Items) 208 m_items.LockItemsForWrite(true);
209 if (0 == Items.Count)
196 { 210 {
197 if (0 == Items.Count) 211 m_items.LockItemsForWrite(false);
198 { 212 return;
199 return;
200 }
201 } 213 }
202 214
203 // Don't let this set the HasGroupChanged flag for attachments 215 // Don't let this set the HasGroupChanged flag for attachments
@@ -209,12 +221,45 @@ namespace OpenSim.Region.Framework.Scenes
209 m_part.ParentGroup.HasGroupChanged = true; 221 m_part.ParentGroup.HasGroupChanged = true;
210 } 222 }
211 223
212 List<TaskInventoryItem> items = GetInventoryItems(); 224 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
213 foreach (TaskInventoryItem item in items) 225 foreach (TaskInventoryItem item in items)
214 { 226 {
215 if (groupID != item.GroupID) 227 if (groupID != item.GroupID)
228 {
216 item.GroupID = groupID; 229 item.GroupID = groupID;
230 }
217 } 231 }
232 m_items.LockItemsForWrite(false);
233 }
234
235 private void QueryScriptStates()
236 {
237 if (m_part == null || m_part.ParentGroup == null)
238 return;
239
240 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
241 if (engines == null) // No engine at all
242 return;
243
244 Items.LockItemsForRead(true);
245 foreach (TaskInventoryItem item in Items.Values)
246 {
247 if (item.InvType == (int)InventoryType.LSL)
248 {
249 foreach (IScriptModule e in engines)
250 {
251 bool running;
252
253 if (e.HasScript(item.ItemID, out running))
254 {
255 item.ScriptRunning = running;
256 break;
257 }
258 }
259 }
260 }
261
262 Items.LockItemsForRead(false);
218 } 263 }
219 264
220 /// <summary> 265 /// <summary>
@@ -222,9 +267,14 @@ namespace OpenSim.Region.Framework.Scenes
222 /// </summary> 267 /// </summary>
223 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 268 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
224 { 269 {
225 List<TaskInventoryItem> scripts = GetInventoryScripts(); 270 Items.LockItemsForRead(true);
226 foreach (TaskInventoryItem item in scripts) 271 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
227 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 272 Items.LockItemsForRead(false);
273 foreach (TaskInventoryItem item in items)
274 {
275 if ((int)InventoryType.LSL == item.InvType)
276 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
277 }
228 } 278 }
229 279
230 public ArrayList GetScriptErrors(UUID itemID) 280 public ArrayList GetScriptErrors(UUID itemID)
@@ -257,9 +307,18 @@ namespace OpenSim.Region.Framework.Scenes
257 /// </param> 307 /// </param>
258 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 308 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
259 { 309 {
260 List<TaskInventoryItem> scripts = GetInventoryScripts(); 310 Items.LockItemsForRead(true);
261 foreach (TaskInventoryItem item in scripts) 311 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
262 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); 312 Items.LockItemsForRead(false);
313
314 foreach (TaskInventoryItem item in items)
315 {
316 if ((int)InventoryType.LSL == item.InvType)
317 {
318 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
319 m_part.RemoveScriptEvents(item.ItemID);
320 }
321 }
263 } 322 }
264 323
265 /// <summary> 324 /// <summary>
@@ -275,7 +334,10 @@ namespace OpenSim.Region.Framework.Scenes
275 // item.Name, item.ItemID, Name, UUID); 334 // item.Name, item.ItemID, Name, UUID);
276 335
277 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 336 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
337 {
338 StoreScriptError(item.ItemID, "no permission");
278 return; 339 return;
340 }
279 341
280 m_part.AddFlag(PrimFlags.Scripted); 342 m_part.AddFlag(PrimFlags.Scripted);
281 343
@@ -284,14 +346,13 @@ namespace OpenSim.Region.Framework.Scenes
284 if (stateSource == 2 && // Prim crossing 346 if (stateSource == 2 && // Prim crossing
285 m_part.ParentGroup.Scene.m_trustBinaries) 347 m_part.ParentGroup.Scene.m_trustBinaries)
286 { 348 {
287 lock (m_items) 349 m_items.LockItemsForWrite(true);
288 { 350 m_items[item.ItemID].PermsMask = 0;
289 m_items[item.ItemID].PermsMask = 0; 351 m_items[item.ItemID].PermsGranter = UUID.Zero;
290 m_items[item.ItemID].PermsGranter = UUID.Zero; 352 m_items.LockItemsForWrite(false);
291 }
292
293 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 353 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
294 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 354 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
355 StoreScriptErrors(item.ItemID, null);
295 m_part.ParentGroup.AddActiveScriptCount(1); 356 m_part.ParentGroup.AddActiveScriptCount(1);
296 m_part.ScheduleFullUpdate(); 357 m_part.ScheduleFullUpdate();
297 return; 358 return;
@@ -300,6 +361,8 @@ namespace OpenSim.Region.Framework.Scenes
300 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); 361 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
301 if (null == asset) 362 if (null == asset)
302 { 363 {
364 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
365 StoreScriptError(item.ItemID, msg);
303 m_log.ErrorFormat( 366 m_log.ErrorFormat(
304 "[PRIM INVENTORY]: " + 367 "[PRIM INVENTORY]: " +
305 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 368 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
@@ -311,15 +374,20 @@ namespace OpenSim.Region.Framework.Scenes
311 if (m_part.ParentGroup.m_savedScriptState != null) 374 if (m_part.ParentGroup.m_savedScriptState != null)
312 RestoreSavedScriptState(item.OldItemID, item.ItemID); 375 RestoreSavedScriptState(item.OldItemID, item.ItemID);
313 376
314 lock (m_items) 377 m_items.LockItemsForWrite(true);
315 { 378
316 m_items[item.ItemID].PermsMask = 0; 379 m_items[item.ItemID].PermsMask = 0;
317 m_items[item.ItemID].PermsGranter = UUID.Zero; 380 m_items[item.ItemID].PermsGranter = UUID.Zero;
318 } 381
382 m_items.LockItemsForWrite(false);
319 383
320 string script = Utils.BytesToString(asset.Data); 384 string script = Utils.BytesToString(asset.Data);
321 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 385 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
322 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 386 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
387 StoreScriptErrors(item.ItemID, null);
388 if (!item.ScriptRunning)
389 m_part.ParentGroup.Scene.EventManager.TriggerStopScript(
390 m_part.LocalId, item.ItemID);
323 m_part.ParentGroup.AddActiveScriptCount(1); 391 m_part.ParentGroup.AddActiveScriptCount(1);
324 m_part.ScheduleFullUpdate(); 392 m_part.ScheduleFullUpdate();
325 } 393 }
@@ -383,21 +451,145 @@ namespace OpenSim.Region.Framework.Scenes
383 451
384 /// <summary> 452 /// <summary>
385 /// Start a script which is in this prim's inventory. 453 /// Start a script which is in this prim's inventory.
454 /// Some processing may occur in the background, but this routine returns asap.
386 /// </summary> 455 /// </summary>
387 /// <param name="itemId"> 456 /// <param name="itemId">
388 /// A <see cref="UUID"/> 457 /// A <see cref="UUID"/>
389 /// </param> 458 /// </param>
390 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 459 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
391 { 460 {
392 TaskInventoryItem item = GetInventoryItem(itemId); 461 lock (m_scriptErrors)
393 if (item != null) 462 {
394 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 463 // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion
464 m_scriptErrors.Remove(itemId);
465 }
466 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
467 }
468
469 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
470 {
471 m_items.LockItemsForRead(true);
472 if (m_items.ContainsKey(itemId))
473 {
474 if (m_items.ContainsKey(itemId))
475 {
476 m_items.LockItemsForRead(false);
477 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
478 }
479 else
480 {
481 m_items.LockItemsForRead(false);
482 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
483 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
484 StoreScriptError(itemId, msg);
485 m_log.ErrorFormat(
486 "[PRIM INVENTORY]: " +
487 "Couldn't start script with ID {0} since it {1}", itemId, msg);
488 }
489 }
395 else 490 else
491 {
492 m_items.LockItemsForRead(false);
493 string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID);
494 StoreScriptError(itemId, msg);
396 m_log.ErrorFormat( 495 m_log.ErrorFormat(
397 "[PRIM INVENTORY]: " + 496 "[PRIM INVENTORY]: " +
398 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 497 "Couldn't start script with ID {0} since it {1}", itemId, msg);
399 itemId, m_part.Name, m_part.UUID, 498 }
400 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 499
500 }
501
502 /// <summary>
503 /// Start a script which is in this prim's inventory and return any compilation error messages.
504 /// </summary>
505 /// <param name="itemId">
506 /// A <see cref="UUID"/>
507 /// </param>
508 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
509 {
510 ArrayList errors;
511
512 // Indicate to CreateScriptInstanceInternal() we want it to
513 // post any compilation/loading error messages
514 lock (m_scriptErrors)
515 {
516 m_scriptErrors[itemId] = null;
517 }
518
519 // Perform compilation/loading
520 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
521
522 // Wait for and retrieve any errors
523 lock (m_scriptErrors)
524 {
525 while ((errors = m_scriptErrors[itemId]) == null)
526 {
527 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
528 {
529 m_log.ErrorFormat(
530 "[PRIM INVENTORY]: " +
531 "timedout waiting for script {0} errors", itemId);
532 errors = m_scriptErrors[itemId];
533 if (errors == null)
534 {
535 errors = new ArrayList(1);
536 errors.Add("timedout waiting for errors");
537 }
538 break;
539 }
540 }
541 m_scriptErrors.Remove(itemId);
542 }
543 return errors;
544 }
545
546 // Signal to CreateScriptInstanceEr() that compilation/loading is complete
547 private void StoreScriptErrors(UUID itemId, ArrayList errors)
548 {
549 lock (m_scriptErrors)
550 {
551 // If compilation/loading initiated via CreateScriptInstance(),
552 // it does not want the errors, so just get out
553 if (!m_scriptErrors.ContainsKey(itemId))
554 {
555 return;
556 }
557
558 // Initiated via CreateScriptInstanceEr(), if we know what the
559 // errors are, save them and wake CreateScriptInstanceEr().
560 if (errors != null)
561 {
562 m_scriptErrors[itemId] = errors;
563 System.Threading.Monitor.PulseAll(m_scriptErrors);
564 return;
565 }
566 }
567
568 // Initiated via CreateScriptInstanceEr() but we don't know what
569 // the errors are yet, so retrieve them from the script engine.
570 // This may involve some waiting internal to GetScriptErrors().
571 errors = GetScriptErrors(itemId);
572
573 // Get a default non-null value to indicate success.
574 if (errors == null)
575 {
576 errors = new ArrayList();
577 }
578
579 // Post to CreateScriptInstanceEr() and wake it up
580 lock (m_scriptErrors)
581 {
582 m_scriptErrors[itemId] = errors;
583 System.Threading.Monitor.PulseAll(m_scriptErrors);
584 }
585 }
586
587 // Like StoreScriptErrors(), but just posts a single string message
588 private void StoreScriptError(UUID itemId, string message)
589 {
590 ArrayList errors = new ArrayList(1);
591 errors.Add(message);
592 StoreScriptErrors(itemId, errors);
401 } 593 }
402 594
403 /// <summary> 595 /// <summary>
@@ -410,15 +602,7 @@ namespace OpenSim.Region.Framework.Scenes
410 /// </param> 602 /// </param>
411 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 603 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
412 { 604 {
413 bool scriptPresent = false; 605 if (m_items.ContainsKey(itemId))
414
415 lock (m_items)
416 {
417 if (m_items.ContainsKey(itemId))
418 scriptPresent = true;
419 }
420
421 if (scriptPresent)
422 { 606 {
423 if (!sceneObjectBeingDeleted) 607 if (!sceneObjectBeingDeleted)
424 m_part.RemoveScriptEvents(itemId); 608 m_part.RemoveScriptEvents(itemId);
@@ -443,14 +627,16 @@ namespace OpenSim.Region.Framework.Scenes
443 /// <returns></returns> 627 /// <returns></returns>
444 private bool InventoryContainsName(string name) 628 private bool InventoryContainsName(string name)
445 { 629 {
446 lock (m_items) 630 m_items.LockItemsForRead(true);
631 foreach (TaskInventoryItem item in m_items.Values)
447 { 632 {
448 foreach (TaskInventoryItem item in m_items.Values) 633 if (item.Name == name)
449 { 634 {
450 if (item.Name == name) 635 m_items.LockItemsForRead(false);
451 return true; 636 return true;
452 } 637 }
453 } 638 }
639 m_items.LockItemsForRead(false);
454 return false; 640 return false;
455 } 641 }
456 642
@@ -492,8 +678,9 @@ namespace OpenSim.Region.Framework.Scenes
492 /// <param name="item"></param> 678 /// <param name="item"></param>
493 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 679 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
494 { 680 {
495 List<TaskInventoryItem> il = GetInventoryItems(); 681 m_items.LockItemsForRead(true);
496 682 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
683 m_items.LockItemsForRead(false);
497 foreach (TaskInventoryItem i in il) 684 foreach (TaskInventoryItem i in il)
498 { 685 {
499 if (i.Name == item.Name) 686 if (i.Name == item.Name)
@@ -531,14 +718,14 @@ namespace OpenSim.Region.Framework.Scenes
531 item.Name = name; 718 item.Name = name;
532 item.GroupID = m_part.GroupID; 719 item.GroupID = m_part.GroupID;
533 720
534 lock (m_items) 721 m_items.LockItemsForWrite(true);
535 m_items.Add(item.ItemID, item); 722 m_items.Add(item.ItemID, item);
536 723 m_items.LockItemsForWrite(false);
537 if (allowedDrop) 724 if (allowedDrop)
538 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 725 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
539 else 726 else
540 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 727 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
541 728
542 m_inventorySerial++; 729 m_inventorySerial++;
543 //m_inventorySerial += 2; 730 //m_inventorySerial += 2;
544 HasInventoryChanged = true; 731 HasInventoryChanged = true;
@@ -554,15 +741,15 @@ namespace OpenSim.Region.Framework.Scenes
554 /// <param name="items"></param> 741 /// <param name="items"></param>
555 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 742 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
556 { 743 {
557 lock (m_items) 744 m_items.LockItemsForWrite(true);
745 foreach (TaskInventoryItem item in items)
558 { 746 {
559 foreach (TaskInventoryItem item in items) 747 m_items.Add(item.ItemID, item);
560 { 748// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
561 m_items.Add(item.ItemID, item);
562// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
563 }
564 m_inventorySerial++;
565 } 749 }
750 m_items.LockItemsForWrite(false);
751
752 m_inventorySerial++;
566 } 753 }
567 754
568 /// <summary> 755 /// <summary>
@@ -573,10 +760,9 @@ namespace OpenSim.Region.Framework.Scenes
573 public TaskInventoryItem GetInventoryItem(UUID itemId) 760 public TaskInventoryItem GetInventoryItem(UUID itemId)
574 { 761 {
575 TaskInventoryItem item; 762 TaskInventoryItem item;
576 763 m_items.LockItemsForRead(true);
577 lock (m_items) 764 m_items.TryGetValue(itemId, out item);
578 m_items.TryGetValue(itemId, out item); 765 m_items.LockItemsForRead(false);
579
580 return item; 766 return item;
581 } 767 }
582 768
@@ -592,15 +778,16 @@ namespace OpenSim.Region.Framework.Scenes
592 { 778 {
593 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(); 779 IList<TaskInventoryItem> items = new List<TaskInventoryItem>();
594 780
595 lock (m_items) 781 m_items.LockItemsForRead(true);
782
783 foreach (TaskInventoryItem item in m_items.Values)
596 { 784 {
597 foreach (TaskInventoryItem item in m_items.Values) 785 if (item.Name == name)
598 { 786 items.Add(item);
599 if (item.Name == name)
600 items.Add(item);
601 }
602 } 787 }
603 788
789 m_items.LockItemsForRead(false);
790
604 return items; 791 return items;
605 } 792 }
606 793
@@ -619,6 +806,9 @@ namespace OpenSim.Region.Framework.Scenes
619 string xmlData = Utils.BytesToString(rezAsset.Data); 806 string xmlData = Utils.BytesToString(rezAsset.Data);
620 SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); 807 SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
621 808
809 group.RootPart.AttachPoint = group.RootPart.Shape.State;
810 group.RootPart.AttachOffset = group.AbsolutePosition;
811
622 group.ResetIDs(); 812 group.ResetIDs();
623 813
624 SceneObjectPart rootPart = group.GetChildPart(group.UUID); 814 SceneObjectPart rootPart = group.GetChildPart(group.UUID);
@@ -693,8 +883,9 @@ namespace OpenSim.Region.Framework.Scenes
693 883
694 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) 884 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged)
695 { 885 {
696 TaskInventoryItem it = GetInventoryItem(item.ItemID); 886 m_items.LockItemsForWrite(true);
697 if (it != null) 887
888 if (m_items.ContainsKey(item.ItemID))
698 { 889 {
699// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); 890// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name);
700 891
@@ -707,14 +898,10 @@ namespace OpenSim.Region.Framework.Scenes
707 item.GroupID = m_part.GroupID; 898 item.GroupID = m_part.GroupID;
708 899
709 if (item.AssetID == UUID.Zero) 900 if (item.AssetID == UUID.Zero)
710 item.AssetID = it.AssetID; 901 item.AssetID = m_items[item.ItemID].AssetID;
711 902
712 lock (m_items) 903 m_items[item.ItemID] = item;
713 { 904 m_inventorySerial++;
714 m_items[item.ItemID] = item;
715 m_inventorySerial++;
716 }
717
718 if (fireScriptEvents) 905 if (fireScriptEvents)
719 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 906 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
720 907
@@ -723,7 +910,7 @@ namespace OpenSim.Region.Framework.Scenes
723 HasInventoryChanged = true; 910 HasInventoryChanged = true;
724 m_part.ParentGroup.HasGroupChanged = true; 911 m_part.ParentGroup.HasGroupChanged = true;
725 } 912 }
726 913 m_items.LockItemsForWrite(false);
727 return true; 914 return true;
728 } 915 }
729 else 916 else
@@ -734,8 +921,9 @@ namespace OpenSim.Region.Framework.Scenes
734 item.ItemID, m_part.Name, m_part.UUID, 921 item.ItemID, m_part.Name, m_part.UUID,
735 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 922 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
736 } 923 }
737 return false; 924 m_items.LockItemsForWrite(false);
738 925
926 return false;
739 } 927 }
740 928
741 /// <summary> 929 /// <summary>
@@ -746,43 +934,59 @@ namespace OpenSim.Region.Framework.Scenes
746 /// in this prim's inventory.</returns> 934 /// in this prim's inventory.</returns>
747 public int RemoveInventoryItem(UUID itemID) 935 public int RemoveInventoryItem(UUID itemID)
748 { 936 {
749 TaskInventoryItem item = GetInventoryItem(itemID); 937 m_items.LockItemsForRead(true);
750 if (item != null) 938
939 if (m_items.ContainsKey(itemID))
751 { 940 {
752 int type = m_items[itemID].InvType; 941 int type = m_items[itemID].InvType;
942 m_items.LockItemsForRead(false);
753 if (type == 10) // Script 943 if (type == 10) // Script
754 { 944 {
755 m_part.RemoveScriptEvents(itemID);
756 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 945 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
757 } 946 }
947 m_items.LockItemsForWrite(true);
758 m_items.Remove(itemID); 948 m_items.Remove(itemID);
949 m_items.LockItemsForWrite(false);
759 m_inventorySerial++; 950 m_inventorySerial++;
760 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 951 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
761 952
762 HasInventoryChanged = true; 953 HasInventoryChanged = true;
763 m_part.ParentGroup.HasGroupChanged = true; 954 m_part.ParentGroup.HasGroupChanged = true;
764 955
765 if (!ContainsScripts()) 956 int scriptcount = 0;
957 m_items.LockItemsForRead(true);
958 foreach (TaskInventoryItem item in m_items.Values)
959 {
960 if (item.Type == 10)
961 {
962 scriptcount++;
963 }
964 }
965 m_items.LockItemsForRead(false);
966
967
968 if (scriptcount <= 0)
969 {
766 m_part.RemFlag(PrimFlags.Scripted); 970 m_part.RemFlag(PrimFlags.Scripted);
971 }
767 972
768 m_part.ScheduleFullUpdate(); 973 m_part.ScheduleFullUpdate();
769 974
770 return type; 975 return type;
771
772 } 976 }
773 else 977 else
774 { 978 {
979 m_items.LockItemsForRead(false);
775 m_log.ErrorFormat( 980 m_log.ErrorFormat(
776 "[PRIM INVENTORY]: " + 981 "[PRIM INVENTORY]: " +
777 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 982 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
778 itemID, m_part.Name, m_part.UUID, 983 itemID, m_part.Name, m_part.UUID);
779 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
780 } 984 }
781 985
782 return -1; 986 return -1;
783 } 987 }
784 988
785 private bool CreateInventoryFile() 989 private bool CreateInventoryFileName()
786 { 990 {
787// m_log.DebugFormat( 991// m_log.DebugFormat(
788// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}", 992// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}",
@@ -791,116 +995,124 @@ namespace OpenSim.Region.Framework.Scenes
791 if (m_inventoryFileName == String.Empty || 995 if (m_inventoryFileName == String.Empty ||
792 m_inventoryFileNameSerial < m_inventorySerial) 996 m_inventoryFileNameSerial < m_inventorySerial)
793 { 997 {
794 // Something changed, we need to create a new file
795 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; 998 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp";
796 m_inventoryFileNameSerial = m_inventorySerial; 999 m_inventoryFileNameSerial = m_inventorySerial;
797 1000
798 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 1001 return true;
1002 }
1003
1004 return false;
1005 }
1006
1007 /// <summary>
1008 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
1009 /// </summary>
1010 /// <param name="xferManager"></param>
1011 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
1012 {
1013 bool changed = CreateInventoryFileName();
1014
1015 bool includeAssets = false;
1016 if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId))
1017 includeAssets = true;
1018
1019 if (m_inventoryPrivileged != includeAssets)
1020 changed = true;
1021
1022 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
1023
1024 Items.LockItemsForRead(true);
1025
1026 if (m_inventorySerial == 0) // No inventory
1027 {
1028 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1029 Items.LockItemsForRead(false);
1030 return;
1031 }
799 1032
800 lock (m_items) 1033 if (m_items.Count == 0) // No inventory
1034 {
1035 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1036 return;
1037 }
1038
1039 if (!changed)
1040 {
1041 if (m_inventoryFileData.Length > 2)
801 { 1042 {
802 foreach (TaskInventoryItem item in m_items.Values) 1043 xferManager.AddNewFile(m_inventoryFileName,
803 { 1044 m_inventoryFileData);
804// m_log.DebugFormat( 1045 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
805// "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}", 1046 Util.StringToBytes256(m_inventoryFileName));
806// item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId);
807 1047
808 UUID ownerID = item.OwnerID; 1048 Items.LockItemsForRead(false);
809 uint everyoneMask = 0; 1049 return;
810 uint baseMask = item.BasePermissions; 1050 }
811 uint ownerMask = item.CurrentPermissions; 1051 }
812 uint groupMask = item.GroupPermissions;
813 1052
814 invString.AddItemStart(); 1053 m_inventoryPrivileged = includeAssets;
815 invString.AddNameValueLine("item_id", item.ItemID.ToString());
816 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
817 1054
818 invString.AddPermissionsStart(); 1055 foreach (TaskInventoryItem item in m_items.Values)
1056 {
1057 UUID ownerID = item.OwnerID;
1058 uint everyoneMask = 0;
1059 uint baseMask = item.BasePermissions;
1060 uint ownerMask = item.CurrentPermissions;
1061 uint groupMask = item.GroupPermissions;
819 1062
820 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 1063 invString.AddItemStart();
821 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 1064 invString.AddNameValueLine("item_id", item.ItemID.ToString());
822 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); 1065 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
823 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
824 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
825 1066
826 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 1067 invString.AddPermissionsStart();
827 invString.AddNameValueLine("owner_id", ownerID.ToString());
828 1068
829 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 1069 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
1070 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
1071 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
1072 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
1073 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
830 1074
831 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 1075 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
832 invString.AddSectionEnd(); 1076 invString.AddNameValueLine("owner_id", ownerID.ToString());
833 1077
834 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 1078 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
835 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
836 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
837 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
838 1079
839 invString.AddSaleStart(); 1080 invString.AddNameValueLine("group_id", item.GroupID.ToString());
840 invString.AddNameValueLine("sale_type", "not"); 1081 invString.AddSectionEnd();
841 invString.AddNameValueLine("sale_price", "0");
842 invString.AddSectionEnd();
843 1082
844 invString.AddNameValueLine("name", item.Name + "|"); 1083 if (includeAssets)
845 invString.AddNameValueLine("desc", item.Description + "|"); 1084 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
1085 else
1086 invString.AddNameValueLine("asset_id", UUID.Zero.ToString());
1087 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
1088 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
1089 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
846 1090
847 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 1091 invString.AddSaleStart();
848 invString.AddSectionEnd(); 1092 invString.AddNameValueLine("sale_type", "not");
849 } 1093 invString.AddNameValueLine("sale_price", "0");
850 } 1094 invString.AddSectionEnd();
851 1095
852 m_inventoryFileData = Utils.StringToBytes(invString.BuildString); 1096 invString.AddNameValueLine("name", item.Name + "|");
1097 invString.AddNameValueLine("desc", item.Description + "|");
853 1098
854 return true; 1099 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
1100 invString.AddSectionEnd();
855 } 1101 }
856 1102
857 // No need to recreate, the existing file is fine 1103 Items.LockItemsForRead(false);
858 return false;
859 }
860 1104
861 /// <summary> 1105 m_inventoryFileData = Utils.StringToBytes(invString.BuildString);
862 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
863 /// </summary>
864 /// <param name="xferManager"></param>
865 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
866 {
867 lock (m_items)
868 {
869 // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing
870 // a new script if any previous deletion has left the prim inventory empty.
871 if (m_items.Count == 0) // No inventory
872 {
873// m_log.DebugFormat(
874// "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items",
875// m_part.Name, m_part.LocalId, m_part.UUID, client.Name);
876 1106
877 client.SendTaskInventory(m_part.UUID, 0, new byte[0]); 1107 if (m_inventoryFileData.Length > 2)
878 return; 1108 {
879 } 1109 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
880 1110 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
881 CreateInventoryFile(); 1111 Util.StringToBytes256(m_inventoryFileName));
882 1112 return;
883 // In principle, we should only do the rest if the inventory changed;
884 // by sending m_inventorySerial to the client, it ought to know
885 // that nothing changed and that it doesn't need to request the file.
886 // Unfortunately, it doesn't look like the client optimizes this;
887 // the client seems to always come back and request the Xfer,
888 // no matter what value m_inventorySerial has.
889 // FIXME: Could probably be > 0 here rather than > 2
890 if (m_inventoryFileData.Length > 2)
891 {
892 // Add the file for Xfer
893 // m_log.DebugFormat(
894 // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}",
895 // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId);
896
897 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
898 }
899
900 // Tell the client we're ready to Xfer the file
901 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
902 Util.StringToBytes256(m_inventoryFileName));
903 } 1113 }
1114
1115 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
904 } 1116 }
905 1117
906 /// <summary> 1118 /// <summary>
@@ -911,10 +1123,11 @@ namespace OpenSim.Region.Framework.Scenes
911 { 1123 {
912 if (HasInventoryChanged) 1124 if (HasInventoryChanged)
913 { 1125 {
914 HasInventoryChanged = false; 1126 Items.LockItemsForRead(true);
915 List<TaskInventoryItem> items = GetInventoryItems(); 1127 datastore.StorePrimInventory(m_part.UUID, Items.Values);
916 datastore.StorePrimInventory(m_part.UUID, items); 1128 Items.LockItemsForRead(false);
917 1129
1130 HasInventoryChanged = false;
918 } 1131 }
919 } 1132 }
920 1133
@@ -981,82 +1194,63 @@ namespace OpenSim.Region.Framework.Scenes
981 { 1194 {
982 uint mask=0x7fffffff; 1195 uint mask=0x7fffffff;
983 1196
984 lock (m_items) 1197 foreach (TaskInventoryItem item in m_items.Values)
985 { 1198 {
986 foreach (TaskInventoryItem item in m_items.Values) 1199 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
1200 mask &= ~((uint)PermissionMask.Copy >> 13);
1201 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1202 mask &= ~((uint)PermissionMask.Transfer >> 13);
1203 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1204 mask &= ~((uint)PermissionMask.Modify >> 13);
1205
1206 if (item.InvType == (int)InventoryType.Object)
987 { 1207 {
988 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1208 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
989 mask &= ~((uint)PermissionMask.Copy >> 13); 1209 mask &= ~((uint)PermissionMask.Copy >> 13);
990 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1210 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
991 mask &= ~((uint)PermissionMask.Transfer >> 13); 1211 mask &= ~((uint)PermissionMask.Transfer >> 13);
992 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1212 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
993 mask &= ~((uint)PermissionMask.Modify >> 13); 1213 mask &= ~((uint)PermissionMask.Modify >> 13);
994
995 if (item.InvType != (int)InventoryType.Object)
996 {
997 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
998 mask &= ~((uint)PermissionMask.Copy >> 13);
999 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1000 mask &= ~((uint)PermissionMask.Transfer >> 13);
1001 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1002 mask &= ~((uint)PermissionMask.Modify >> 13);
1003 }
1004 else
1005 {
1006 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1007 mask &= ~((uint)PermissionMask.Copy >> 13);
1008 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1009 mask &= ~((uint)PermissionMask.Transfer >> 13);
1010 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1011 mask &= ~((uint)PermissionMask.Modify >> 13);
1012 }
1013
1014 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1015 mask &= ~(uint)PermissionMask.Copy;
1016 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1017 mask &= ~(uint)PermissionMask.Transfer;
1018 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1019 mask &= ~(uint)PermissionMask.Modify;
1020 } 1214 }
1215
1216 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1217 mask &= ~(uint)PermissionMask.Copy;
1218 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1219 mask &= ~(uint)PermissionMask.Transfer;
1220 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1221 mask &= ~(uint)PermissionMask.Modify;
1021 } 1222 }
1022
1023 return mask; 1223 return mask;
1024 } 1224 }
1025 1225
1026 public void ApplyNextOwnerPermissions() 1226 public void ApplyNextOwnerPermissions()
1027 { 1227 {
1028 lock (m_items) 1228 foreach (TaskInventoryItem item in m_items.Values)
1029 { 1229 {
1030 foreach (TaskInventoryItem item in m_items.Values) 1230 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
1031 { 1231 {
1032 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1232 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1033 { 1233 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
1034 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1234 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1035 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 1235 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
1036 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1236 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1037 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 1237 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1038 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1039 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1040 }
1041 item.CurrentPermissions &= item.NextPermissions;
1042 item.BasePermissions &= item.NextPermissions;
1043 item.EveryonePermissions &= item.NextPermissions;
1044 item.OwnerChanged = true;
1045 item.PermsMask = 0;
1046 item.PermsGranter = UUID.Zero;
1047 } 1238 }
1239 item.OwnerChanged = true;
1240 item.CurrentPermissions &= item.NextPermissions;
1241 item.BasePermissions &= item.NextPermissions;
1242 item.EveryonePermissions &= item.NextPermissions;
1243 item.PermsMask = 0;
1244 item.PermsGranter = UUID.Zero;
1048 } 1245 }
1049 } 1246 }
1050 1247
1051 public void ApplyGodPermissions(uint perms) 1248 public void ApplyGodPermissions(uint perms)
1052 { 1249 {
1053 lock (m_items) 1250 foreach (TaskInventoryItem item in m_items.Values)
1054 { 1251 {
1055 foreach (TaskInventoryItem item in m_items.Values) 1252 item.CurrentPermissions = perms;
1056 { 1253 item.BasePermissions = perms;
1057 item.CurrentPermissions = perms;
1058 item.BasePermissions = perms;
1059 }
1060 } 1254 }
1061 1255
1062 m_inventorySerial++; 1256 m_inventorySerial++;
@@ -1069,17 +1263,13 @@ namespace OpenSim.Region.Framework.Scenes
1069 /// <returns></returns> 1263 /// <returns></returns>
1070 public bool ContainsScripts() 1264 public bool ContainsScripts()
1071 { 1265 {
1072 lock (m_items) 1266 foreach (TaskInventoryItem item in m_items.Values)
1073 { 1267 {
1074 foreach (TaskInventoryItem item in m_items.Values) 1268 if (item.InvType == (int)InventoryType.LSL)
1075 { 1269 {
1076 if (item.InvType == (int)InventoryType.LSL) 1270 return true;
1077 {
1078 return true;
1079 }
1080 } 1271 }
1081 } 1272 }
1082
1083 return false; 1273 return false;
1084 } 1274 }
1085 1275
@@ -1087,11 +1277,8 @@ namespace OpenSim.Region.Framework.Scenes
1087 { 1277 {
1088 List<UUID> ret = new List<UUID>(); 1278 List<UUID> ret = new List<UUID>();
1089 1279
1090 lock (m_items) 1280 foreach (TaskInventoryItem item in m_items.Values)
1091 { 1281 ret.Add(item.ItemID);
1092 foreach (TaskInventoryItem item in m_items.Values)
1093 ret.Add(item.ItemID);
1094 }
1095 1282
1096 return ret; 1283 return ret;
1097 } 1284 }
@@ -1122,6 +1309,11 @@ namespace OpenSim.Region.Framework.Scenes
1122 1309
1123 public Dictionary<UUID, string> GetScriptStates() 1310 public Dictionary<UUID, string> GetScriptStates()
1124 { 1311 {
1312 return GetScriptStates(false);
1313 }
1314
1315 public Dictionary<UUID, string> GetScriptStates(bool oldIDs)
1316 {
1125 Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); 1317 Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
1126 1318
1127 if (m_part.ParentGroup.Scene == null) // Group not in a scene 1319 if (m_part.ParentGroup.Scene == null) // Group not in a scene
@@ -1132,25 +1324,35 @@ namespace OpenSim.Region.Framework.Scenes
1132 if (engines == null) // No engine at all 1324 if (engines == null) // No engine at all
1133 return ret; 1325 return ret;
1134 1326
1135 List<TaskInventoryItem> scripts = GetInventoryScripts(); 1327 Items.LockItemsForRead(true);
1136 1328 foreach (TaskInventoryItem item in m_items.Values)
1137 foreach (TaskInventoryItem item in scripts)
1138 { 1329 {
1139 foreach (IScriptModule e in engines) 1330 if (item.InvType == (int)InventoryType.LSL)
1140 { 1331 {
1141 if (e != null) 1332 foreach (IScriptModule e in engines)
1142 { 1333 {
1143 string n = e.GetXMLState(item.ItemID); 1334 if (e != null)
1144 if (n != String.Empty)
1145 { 1335 {
1146 if (!ret.ContainsKey(item.ItemID)) 1336 string n = e.GetXMLState(item.ItemID);
1147 ret[item.ItemID] = n; 1337 if (n != String.Empty)
1148 break; 1338 {
1339 if (oldIDs)
1340 {
1341 if (!ret.ContainsKey(item.OldItemID))
1342 ret[item.OldItemID] = n;
1343 }
1344 else
1345 {
1346 if (!ret.ContainsKey(item.ItemID))
1347 ret[item.ItemID] = n;
1348 }
1349 break;
1350 }
1149 } 1351 }
1150 } 1352 }
1151 } 1353 }
1152 } 1354 }
1153 1355 Items.LockItemsForRead(false);
1154 return ret; 1356 return ret;
1155 } 1357 }
1156 1358
@@ -1160,21 +1362,27 @@ namespace OpenSim.Region.Framework.Scenes
1160 if (engines == null) 1362 if (engines == null)
1161 return; 1363 return;
1162 1364
1163 List<TaskInventoryItem> scripts = GetInventoryScripts();
1164 1365
1165 foreach (TaskInventoryItem item in scripts) 1366 Items.LockItemsForRead(true);
1367
1368 foreach (TaskInventoryItem item in m_items.Values)
1166 { 1369 {
1167 foreach (IScriptModule engine in engines) 1370 if (item.InvType == (int)InventoryType.LSL)
1168 { 1371 {
1169 if (engine != null) 1372 foreach (IScriptModule engine in engines)
1170 { 1373 {
1171 if (item.OwnerChanged) 1374 if (engine != null)
1172 engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER }); 1375 {
1173 item.OwnerChanged = false; 1376 if (item.OwnerChanged)
1174 engine.ResumeScript(item.ItemID); 1377 engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER });
1378 item.OwnerChanged = false;
1379 engine.ResumeScript(item.ItemID);
1380 }
1175 } 1381 }
1176 } 1382 }
1177 } 1383 }
1384
1385 Items.LockItemsForRead(false);
1178 } 1386 }
1179 } 1387 }
1180} 1388}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index f049b78..925a4f3 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Timers; 32using System.Timers;
@@ -72,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
72// { 73// {
73// m_log.Debug("[SCENE PRESENCE] Destructor called"); 74// m_log.Debug("[SCENE PRESENCE] Destructor called");
74// } 75// }
75 76
76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 78
78 public PresenceType PresenceType { get; private set; } 79 public PresenceType PresenceType { get; private set; }
@@ -89,7 +90,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 90 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 91 /// issue #1716
91 /// </summary> 92 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 93// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
94 // Value revised by KF 091121 by comparison with SL.
95 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 96
94 /// <summary> 97 /// <summary>
95 /// Movement updates for agents in neighboring regions are sent directly to clients. 98 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -100,16 +103,15 @@ namespace OpenSim.Region.Framework.Scenes
100 103
101 public UUID currentParcelUUID = UUID.Zero; 104 public UUID currentParcelUUID = UUID.Zero;
102 105
103 private ISceneViewer m_sceneViewer; 106 protected ScenePresenceAnimator m_animator;
104
105 /// <value> 107 /// <value>
106 /// The animator for this avatar 108 /// The animator for this avatar
107 /// </value> 109 /// </value>
108 public ScenePresenceAnimator Animator 110 public ScenePresenceAnimator Animator
109 { 111 {
110 get { return m_animator; } 112 get { return m_animator; }
113 private set { m_animator = value; }
111 } 114 }
112 protected ScenePresenceAnimator m_animator;
113 115
114 /// <summary> 116 /// <summary>
115 /// Attachments recorded on this avatar. 117 /// Attachments recorded on this avatar.
@@ -118,6 +120,7 @@ namespace OpenSim.Region.Framework.Scenes
118 /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is 120 /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is
119 /// necessary. 121 /// necessary.
120 /// </remarks> 122 /// </remarks>
123
121 protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); 124 protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
122 125
123 public Object AttachmentsSyncLock { get; private set; } 126 public Object AttachmentsSyncLock { get; private set; }
@@ -131,15 +134,21 @@ namespace OpenSim.Region.Framework.Scenes
131 public Vector3 lastKnownAllowedPosition; 134 public Vector3 lastKnownAllowedPosition;
132 public bool sentMessageAboutRestrictedParcelFlyingDown; 135 public bool sentMessageAboutRestrictedParcelFlyingDown;
133 public Vector4 CollisionPlane = Vector4.UnitW; 136 public Vector4 CollisionPlane = Vector4.UnitW;
134 137
138 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
139 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
135 private Vector3 m_lastPosition; 140 private Vector3 m_lastPosition;
141 private Vector3 m_lastWorldPosition;
136 private Quaternion m_lastRotation; 142 private Quaternion m_lastRotation;
137 private Vector3 m_lastVelocity; 143 private Vector3 m_lastVelocity;
138 //private int m_lastTerseSent; 144 //private int m_lastTerseSent;
139 145
140 private bool m_updateflag;
141 private byte m_movementflag;
142 private Vector3? m_forceToApply; 146 private Vector3? m_forceToApply;
147 private int m_userFlags;
148 public int UserFlags
149 {
150 get { return m_userFlags; }
151 }
143 private TeleportFlags m_teleportFlags; 152 private TeleportFlags m_teleportFlags;
144 public TeleportFlags TeleportFlags 153 public TeleportFlags TeleportFlags
145 { 154 {
@@ -159,24 +168,13 @@ namespace OpenSim.Region.Framework.Scenes
159 168
160 private float m_sitAvatarHeight = 2.0f; 169 private float m_sitAvatarHeight = 2.0f;
161 170
162 private int m_godLevel;
163 private int m_userLevel;
164
165 private bool m_invulnerable = true;
166
167 private Vector3 m_lastChildAgentUpdatePosition; 171 private Vector3 m_lastChildAgentUpdatePosition;
168 private Vector3 m_lastChildAgentUpdateCamPosition; 172 private Vector3 m_lastChildAgentUpdateCamPosition;
169 173
170 private int m_perfMonMS; 174 private int m_perfMonMS;
171 175
172 private bool m_setAlwaysRun; 176 private bool m_flyingOld; // add for fly velocity control
173 177 public bool m_wasFlying; // add for fly velocity control
174 private bool m_forceFly;
175 private bool m_flyDisabled;
176
177 private float m_speedModifier = 1.0f;
178
179 private Quaternion m_bodyRot = Quaternion.Identity;
180 178
181 private const int LAND_VELOCITYMAG_MAX = 12; 179 private const int LAND_VELOCITYMAG_MAX = 12;
182 180
@@ -188,24 +186,15 @@ namespace OpenSim.Region.Framework.Scenes
188 186
189 protected ulong crossingFromRegion; 187 protected ulong crossingFromRegion;
190 188
191 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 189 private readonly Vector3[] Dir_Vectors = new Vector3[11];
190 private bool m_isNudging = false;
192 191
193 // Position of agent's camera in world (region cordinates)
194 protected Vector3 m_CameraCenter;
195 protected Vector3 m_lastCameraCenter;
196 192
197 protected Timer m_reprioritization_timer; 193 protected Timer m_reprioritization_timer;
198 protected bool m_reprioritizing; 194 protected bool m_reprioritizing;
199 protected bool m_reprioritization_called; 195 protected bool m_reprioritization_called;
200 196
201 // Use these three vectors to figure out what the agent is looking at
202 // Convert it to a Matrix and/or Quaternion
203 protected Vector3 m_CameraAtAxis;
204 protected Vector3 m_CameraLeftAxis;
205 protected Vector3 m_CameraUpAxis;
206 private AgentManager.ControlFlags m_AgentControlFlags;
207 private Quaternion m_headrotation = Quaternion.Identity; 197 private Quaternion m_headrotation = Quaternion.Identity;
208 private byte m_state;
209 198
210 //Reuse the Vector3 instead of creating a new one on the UpdateMovement method 199 //Reuse the Vector3 instead of creating a new one on the UpdateMovement method
211// private Vector3 movementvector; 200// private Vector3 movementvector;
@@ -213,12 +202,14 @@ namespace OpenSim.Region.Framework.Scenes
213 private bool m_autopilotMoving; 202 private bool m_autopilotMoving;
214 private Vector3 m_autoPilotTarget; 203 private Vector3 m_autoPilotTarget;
215 private bool m_sitAtAutoTarget; 204 private bool m_sitAtAutoTarget;
205 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
216 206
217 private string m_nextSitAnimation = String.Empty; 207 private string m_nextSitAnimation = String.Empty;
218 208
219 //PauPaw:Proper PID Controler for autopilot************ 209 //PauPaw:Proper PID Controler for autopilot************
220 public bool MovingToTarget { get; private set; } 210 public bool MovingToTarget { get; private set; }
221 public Vector3 MoveToPositionTarget { get; private set; } 211 public Vector3 MoveToPositionTarget { get; private set; }
212 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
222 213
223 /// <summary> 214 /// <summary>
224 /// Controls whether an avatar automatically moving to a target will land when it gets there (if flying). 215 /// Controls whether an avatar automatically moving to a target will land when it gets there (if flying).
@@ -228,17 +219,31 @@ namespace OpenSim.Region.Framework.Scenes
228 private bool m_followCamAuto; 219 private bool m_followCamAuto;
229 220
230 private int m_movementUpdateCount; 221 private int m_movementUpdateCount;
222 private int m_lastColCount = -1; //KF: Look for Collision chnages
223 private int m_updateCount = 0; //KF: Update Anims for a while
224 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
231 private const int NumMovementsBetweenRayCast = 5; 225 private const int NumMovementsBetweenRayCast = 5;
226 private List<uint> m_lastColliders = new List<uint>();
227
228 private object m_syncRoot = new Object();
232 229
233 private bool CameraConstraintActive; 230 private bool CameraConstraintActive;
234 //private int m_moveToPositionStateStatus; 231 //private int m_moveToPositionStateStatus;
235 //***************************************************** 232 //*****************************************************
236 233
237 // Agent's Draw distance.
238 protected float m_DrawDistance;
239
240 protected AvatarAppearance m_appearance; 234 protected AvatarAppearance m_appearance;
241 235
236 public AvatarAppearance Appearance
237 {
238 get { return m_appearance; }
239 set
240 {
241 m_appearance = value;
242// m_log.DebugFormat("[SCENE PRESENCE]: Set appearance for {0} to {1}", Name, value);
243 }
244 }
245
246
242 // neighbouring regions we have enabled a child agent in 247 // neighbouring regions we have enabled a child agent in
243 // holds the seed cap for the child agent in that region 248 // holds the seed cap for the child agent in that region
244 private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>(); 249 private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>();
@@ -250,6 +255,7 @@ namespace OpenSim.Region.Framework.Scenes
250 public List<string> InTransitScriptStates 255 public List<string> InTransitScriptStates
251 { 256 {
252 get { return m_InTransitScriptStates; } 257 get { return m_InTransitScriptStates; }
258 private set { m_InTransitScriptStates = value; }
253 } 259 }
254 private List<string> m_InTransitScriptStates = new List<string>(); 260 private List<string> m_InTransitScriptStates = new List<string>();
255 261
@@ -265,7 +271,9 @@ namespace OpenSim.Region.Framework.Scenes
265 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 271 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
266 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 272 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
267 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 273 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
268 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 274 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
275 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
276 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
269 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 277 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
270 } 278 }
271 279
@@ -278,8 +286,6 @@ namespace OpenSim.Region.Framework.Scenes
278 string m_callbackURI; 286 string m_callbackURI;
279 UUID m_originRegionID; 287 UUID m_originRegionID;
280 288
281 ulong m_rootRegionHandle;
282
283 /// <value> 289 /// <value>
284 /// Script engines present in the scene 290 /// Script engines present in the scene
285 /// </value> 291 /// </value>
@@ -287,6 +293,8 @@ namespace OpenSim.Region.Framework.Scenes
287 293
288 #region Properties 294 #region Properties
289 295
296 protected PhysicsActor m_physicsActor;
297
290 /// <summary> 298 /// <summary>
291 /// Physical scene representation of this Avatar. 299 /// Physical scene representation of this Avatar.
292 /// </summary> 300 /// </summary>
@@ -296,69 +304,102 @@ namespace OpenSim.Region.Framework.Scenes
296 get { return m_physicsActor; } 304 get { return m_physicsActor; }
297 } 305 }
298 306
307 private byte m_movementflag;
308
299 public byte MovementFlag 309 public byte MovementFlag
300 { 310 {
301 set { m_movementflag = value; } 311 set { m_movementflag = value; }
302 get { return m_movementflag; } 312 get { return m_movementflag; }
303 } 313 }
304 314
315 private bool m_updateflag;
316
305 public bool Updated 317 public bool Updated
306 { 318 {
307 set { m_updateflag = value; } 319 set { m_updateflag = value; }
308 get { return m_updateflag; } 320 get { return m_updateflag; }
309 } 321 }
310 322
323 private bool m_invulnerable = true;
324
311 public bool Invulnerable 325 public bool Invulnerable
312 { 326 {
313 set { m_invulnerable = value; } 327 set { m_invulnerable = value; }
314 get { return m_invulnerable; } 328 get { return m_invulnerable; }
315 } 329 }
316 330
331 private int m_userLevel;
332
317 public int UserLevel 333 public int UserLevel
318 { 334 {
319 get { return m_userLevel; } 335 get { return m_userLevel; }
336 private set { m_userLevel = value; }
320 } 337 }
321 338
339 private int m_godLevel;
340
322 public int GodLevel 341 public int GodLevel
323 { 342 {
324 get { return m_godLevel; } 343 get { return m_godLevel; }
344 private set { m_godLevel = value; }
325 } 345 }
326 346
347 private ulong m_rootRegionHandle;
348
327 public ulong RegionHandle 349 public ulong RegionHandle
328 { 350 {
329 get { return m_rootRegionHandle; } 351 get { return m_rootRegionHandle; }
352 private set { m_rootRegionHandle = value; }
330 } 353 }
331 354
355 #region Client Camera
356 // Position of agent's camera in world (region cordinates)
357 protected Vector3 m_lastCameraPosition;
358
359 protected Vector3 m_CameraPosition;
360
332 public Vector3 CameraPosition 361 public Vector3 CameraPosition
333 { 362 {
334 get { return m_CameraCenter; } 363 get { return m_CameraPosition; }
364 private set { m_CameraPosition = value; }
335 } 365 }
336 366
337 public Quaternion CameraRotation 367 public Quaternion CameraRotation
338 { 368 {
339 get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } 369 get { return Util.Axes2Rot(CameraAtAxis, CameraLeftAxis, CameraUpAxis); }
340 } 370 }
341 371
372 // Use these three vectors to figure out what the agent is looking at
373 // Convert it to a Matrix and/or Quaternion
374 //
375 protected Vector3 m_CameraAtAxis;
376 protected Vector3 m_CameraLeftAxis;
377 protected Vector3 m_CameraUpAxis;
378
342 public Vector3 CameraAtAxis 379 public Vector3 CameraAtAxis
343 { 380 {
344 get { return m_CameraAtAxis; } 381 get { return m_CameraAtAxis; }
382 private set { m_CameraAtAxis = value; }
345 } 383 }
346 384
385
347 public Vector3 CameraLeftAxis 386 public Vector3 CameraLeftAxis
348 { 387 {
349 get { return m_CameraLeftAxis; } 388 get { return m_CameraLeftAxis; }
389 private set { m_CameraLeftAxis = value; }
350 } 390 }
351 391
352 public Vector3 CameraUpAxis 392 public Vector3 CameraUpAxis
353 { 393 {
354 get { return m_CameraUpAxis; } 394 get { return m_CameraUpAxis; }
395 private set { m_CameraUpAxis = value; }
355 } 396 }
356 397
357 public Vector3 Lookat 398 public Vector3 Lookat
358 { 399 {
359 get 400 get
360 { 401 {
361 Vector3 a = new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0); 402 Vector3 a = new Vector3(CameraAtAxis.X, CameraAtAxis.Y, 0);
362 403
363 if (a == Vector3.Zero) 404 if (a == Vector3.Zero)
364 return a; 405 return a;
@@ -366,20 +407,10 @@ namespace OpenSim.Region.Framework.Scenes
366 return Util.GetNormalizedVector(a); 407 return Util.GetNormalizedVector(a);
367 } 408 }
368 } 409 }
410 #endregion
369 411
370 private readonly string m_firstname; 412 public readonly string Firstname;
371 413 public readonly string Lastname;
372 public string Firstname
373 {
374 get { return m_firstname; }
375 }
376
377 private readonly string m_lastname;
378
379 public string Lastname
380 {
381 get { return m_lastname; }
382 }
383 414
384 private string m_grouptitle; 415 private string m_grouptitle;
385 416
@@ -389,9 +420,13 @@ namespace OpenSim.Region.Framework.Scenes
389 set { m_grouptitle = value; } 420 set { m_grouptitle = value; }
390 } 421 }
391 422
423 // Agent's Draw distance.
424 protected float m_DrawDistance;
425
392 public float DrawDistance 426 public float DrawDistance
393 { 427 {
394 get { return m_DrawDistance; } 428 get { return m_DrawDistance; }
429 private set { m_DrawDistance = value; }
395 } 430 }
396 431
397 protected bool m_allowMovement = true; 432 protected bool m_allowMovement = true;
@@ -402,6 +437,8 @@ namespace OpenSim.Region.Framework.Scenes
402 set { m_allowMovement = value; } 437 set { m_allowMovement = value; }
403 } 438 }
404 439
440 private bool m_setAlwaysRun;
441
405 public bool SetAlwaysRun 442 public bool SetAlwaysRun
406 { 443 {
407 get 444 get
@@ -425,12 +462,16 @@ namespace OpenSim.Region.Framework.Scenes
425 } 462 }
426 } 463 }
427 464
465 private byte m_state;
466
428 public byte State 467 public byte State
429 { 468 {
430 get { return m_state; } 469 get { return m_state; }
431 set { m_state = value; } 470 set { m_state = value; }
432 } 471 }
433 472
473 private AgentManager.ControlFlags m_AgentControlFlags;
474
434 public uint AgentControlFlags 475 public uint AgentControlFlags
435 { 476 {
436 get { return (uint)m_AgentControlFlags; } 477 get { return (uint)m_AgentControlFlags; }
@@ -442,11 +483,10 @@ namespace OpenSim.Region.Framework.Scenes
442 /// </summary> 483 /// </summary>
443 private IClientAPI m_controllingClient; 484 private IClientAPI m_controllingClient;
444 485
445 protected PhysicsActor m_physicsActor;
446
447 public IClientAPI ControllingClient 486 public IClientAPI ControllingClient
448 { 487 {
449 get { return m_controllingClient; } 488 get { return m_controllingClient; }
489 private set { m_controllingClient = value; }
450 } 490 }
451 491
452 public IClientCore ClientView 492 public IClientCore ClientView
@@ -455,6 +495,7 @@ namespace OpenSim.Region.Framework.Scenes
455 } 495 }
456 496
457 protected Vector3 m_parentPosition; 497 protected Vector3 m_parentPosition;
498
458 public Vector3 ParentPosition 499 public Vector3 ParentPosition
459 { 500 {
460 get { return m_parentPosition; } 501 get { return m_parentPosition; }
@@ -469,8 +510,9 @@ namespace OpenSim.Region.Framework.Scenes
469 get 510 get
470 { 511 {
471 PhysicsActor actor = m_physicsActor; 512 PhysicsActor actor = m_physicsActor;
472 if (actor != null) 513// if (actor != null)
473 { 514 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
515 {
474 m_pos = actor.Position; 516 m_pos = actor.Position;
475 517
476// m_log.DebugFormat( 518// m_log.DebugFormat(
@@ -484,7 +526,7 @@ namespace OpenSim.Region.Framework.Scenes
484 // the avatar is seated, this value will also 526 // the avatar is seated, this value will also
485 // be used as the location to unsit to. 527 // be used as the location to unsit to.
486 // 528 //
487 // If m_parentID is not 0, assume we are a seated avatar 529 // If ParentID is not 0, assume we are a seated avatar
488 // and we should return the position based on the sittarget 530 // and we should return the position based on the sittarget
489 // offset and rotation of the prim we are seated on. 531 // offset and rotation of the prim we are seated on.
490 // 532 //
@@ -492,16 +534,16 @@ namespace OpenSim.Region.Framework.Scenes
492 // in the sim unless the avatar is on a sit target. While 534 // in the sim unless the avatar is on a sit target. While
493 // on a sit target, m_pos will contain the desired offset 535 // on a sit target, m_pos will contain the desired offset
494 // without the parent rotation applied. 536 // without the parent rotation applied.
495 if (m_parentID != 0) 537 if (ParentID != 0)
496 { 538 {
497 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 539 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentID);
498 if (part != null) 540 if (part != null)
499 { 541 {
500 return m_parentPosition + (m_pos * part.GetWorldRotation()); 542 return part.AbsolutePosition + (m_pos * part.GetWorldRotation());
501 } 543 }
502 else 544 else
503 { 545 {
504 return m_parentPosition + m_pos; 546 return ParentPosition + m_pos;
505 } 547 }
506 } 548 }
507 } 549 }
@@ -510,13 +552,12 @@ namespace OpenSim.Region.Framework.Scenes
510 } 552 }
511 set 553 set
512 { 554 {
513 PhysicsActor actor = m_physicsActor; 555 if (PhysicsActor != null)
514 if (actor != null)
515 { 556 {
516 try 557 try
517 { 558 {
518 lock (m_scene.SyncRoot) 559 lock (m_scene.SyncRoot)
519 m_physicsActor.Position = value; 560 PhysicsActor.Position = value;
520 } 561 }
521 catch (Exception e) 562 catch (Exception e)
522 { 563 {
@@ -524,7 +565,9 @@ namespace OpenSim.Region.Framework.Scenes
524 } 565 }
525 } 566 }
526 567
527 m_pos = value; 568// Changed this to update unconditionally to make npose work
569// if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
570 m_pos = value;
528 m_parentPosition = Vector3.Zero; 571 m_parentPosition = Vector3.Zero;
529 572
530// m_log.DebugFormat( 573// m_log.DebugFormat(
@@ -549,10 +592,9 @@ namespace OpenSim.Region.Framework.Scenes
549 { 592 {
550 get 593 get
551 { 594 {
552 PhysicsActor actor = m_physicsActor; 595 if (PhysicsActor != null)
553 if (actor != null)
554 { 596 {
555 m_velocity = actor.Velocity; 597 m_velocity = PhysicsActor.Velocity;
556 598
557// m_log.DebugFormat( 599// m_log.DebugFormat(
558// "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!", 600// "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!",
@@ -563,13 +605,12 @@ namespace OpenSim.Region.Framework.Scenes
563 } 605 }
564 set 606 set
565 { 607 {
566 PhysicsActor actor = m_physicsActor; 608 if (PhysicsActor != null)
567 if (actor != null)
568 { 609 {
569 try 610 try
570 { 611 {
571 lock (m_scene.SyncRoot) 612 lock (m_scene.SyncRoot)
572 actor.Velocity = value; 613 PhysicsActor.Velocity = value;
573 } 614 }
574 catch (Exception e) 615 catch (Exception e)
575 { 616 {
@@ -585,13 +626,39 @@ namespace OpenSim.Region.Framework.Scenes
585 } 626 }
586 } 627 }
587 628
629 public Quaternion OffsetRotation
630 {
631 get { return m_offsetRotation; }
632 set { m_offsetRotation = value; }
633 }
634 private Quaternion m_bodyRot = Quaternion.Identity;
635
588 public Quaternion Rotation 636 public Quaternion Rotation
589 { 637 {
590 get { return m_bodyRot; } 638 get {
591 set 639 if (m_parentID != 0)
592 { 640 {
641 if (m_offsetRotation != null)
642 {
643 return m_offsetRotation;
644 }
645 else
646 {
647 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
648 }
649
650 }
651 else
652 {
653 return m_bodyRot;
654 }
655 }
656 set {
593 m_bodyRot = value; 657 m_bodyRot = value;
594// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); 658 if (m_parentID != 0)
659 {
660 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
661 }
595 } 662 }
596 } 663 }
597 664
@@ -611,11 +678,21 @@ namespace OpenSim.Region.Framework.Scenes
611 678
612 private uint m_parentID; 679 private uint m_parentID;
613 680
681
682 private UUID m_linkedPrim;
683
614 public uint ParentID 684 public uint ParentID
615 { 685 {
616 get { return m_parentID; } 686 get { return m_parentID; }
617 set { m_parentID = value; } 687 set { m_parentID = value; }
618 } 688 }
689
690 public UUID LinkedPrim
691 {
692 get { return m_linkedPrim; }
693 set { m_linkedPrim = value; }
694 }
695
619 public float Health 696 public float Health
620 { 697 {
621 get { return m_health; } 698 get { return m_health; }
@@ -645,9 +722,12 @@ namespace OpenSim.Region.Framework.Scenes
645 } 722 }
646 } 723 }
647 724
725 private ISceneViewer m_sceneViewer;
726
648 public ISceneViewer SceneViewer 727 public ISceneViewer SceneViewer
649 { 728 {
650 get { return m_sceneViewer; } 729 get { return m_sceneViewer; }
730 private set { m_sceneViewer = value; }
651 } 731 }
652 732
653 public void AdjustKnownSeeds() 733 public void AdjustKnownSeeds()
@@ -694,28 +774,44 @@ namespace OpenSim.Region.Framework.Scenes
694 } 774 }
695 } 775 }
696 776
697 private bool m_inTransit;
698 private bool m_mouseLook; 777 private bool m_mouseLook;
699 private bool m_leftButtonDown; 778 private bool m_leftButtonDown;
700 779
780 private bool m_inTransit;
781
701 public bool IsInTransit 782 public bool IsInTransit
702 { 783 {
703 get { return m_inTransit; } 784 get { return m_inTransit; }
704 set { m_inTransit = value; } 785 set {
786 if(value)
787 {
788 if ((PhysicsActor != null) && PhysicsActor.Flying)
789 m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY;
790 else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
791 m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY;
792 }
793 m_inTransit = value;
794 }
705 } 795 }
706 796
797 private float m_speedModifier = 1.0f;
798
707 public float SpeedModifier 799 public float SpeedModifier
708 { 800 {
709 get { return m_speedModifier; } 801 get { return m_speedModifier; }
710 set { m_speedModifier = value; } 802 set { m_speedModifier = value; }
711 } 803 }
712 804
805 private bool m_forceFly;
806
713 public bool ForceFly 807 public bool ForceFly
714 { 808 {
715 get { return m_forceFly; } 809 get { return m_forceFly; }
716 set { m_forceFly = value; } 810 set { m_forceFly = value; }
717 } 811 }
718 812
813 private bool m_flyDisabled;
814
719 public bool FlyDisabled 815 public bool FlyDisabled
720 { 816 {
721 get { return m_flyDisabled; } 817 get { return m_flyDisabled; }
@@ -737,42 +833,40 @@ namespace OpenSim.Region.Framework.Scenes
737 AttachmentsSyncLock = new Object(); 833 AttachmentsSyncLock = new Object();
738 834
739 m_sendCourseLocationsMethod = SendCoarseLocationsDefault; 835 m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
740 m_sceneViewer = new SceneViewer(this); 836 SceneViewer = new SceneViewer(this);
741 m_animator = new ScenePresenceAnimator(this); 837 Animator = new ScenePresenceAnimator(this);
742 PresenceType = type; 838 PresenceType = type;
743 m_DrawDistance = world.DefaultDrawDistance; 839 DrawDistance = world.DefaultDrawDistance;
744 m_rootRegionHandle = world.RegionInfo.RegionHandle; 840 RegionHandle = world.RegionInfo.RegionHandle;
745 m_controllingClient = client; 841 ControllingClient = client;
746 m_firstname = m_controllingClient.FirstName; 842 Firstname = ControllingClient.FirstName;
747 m_lastname = m_controllingClient.LastName; 843 Lastname = ControllingClient.LastName;
748 m_name = String.Format("{0} {1}", m_firstname, m_lastname); 844 m_name = String.Format("{0} {1}", Firstname, Lastname);
749 m_scene = world; 845 m_scene = world;
750 m_uuid = client.AgentId; 846 m_uuid = client.AgentId;
751 m_localId = m_scene.AllocateLocalId(); 847 m_localId = m_scene.AllocateLocalId();
752 848
753 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); 849 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
850 m_userFlags = account.UserFlags;
754 851
755 if (account != null) 852 if (account != null)
756 m_userLevel = account.UserLevel; 853 UserLevel = account.UserLevel;
757 854
758 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 855 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
759 if (gm != null) 856 if (gm != null)
760 m_grouptitle = gm.GetGroupTitle(m_uuid); 857 Grouptitle = gm.GetGroupTitle(m_uuid);
761 858
762 m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); 859 m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>();
763 860
764 AbsolutePosition = posLastSignificantMove = m_CameraCenter = 861 AbsolutePosition = posLastSignificantMove = CameraPosition =
765 m_lastCameraCenter = m_controllingClient.StartPos; 862 m_lastCameraPosition = ControllingClient.StartPos;
766 863
767 m_reprioritization_timer = new Timer(world.ReprioritizationInterval); 864 m_reprioritization_timer = new Timer(world.ReprioritizationInterval);
768 m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize); 865 m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize);
769 m_reprioritization_timer.AutoReset = false; 866 m_reprioritization_timer.AutoReset = false;
770 867
771 AdjustKnownSeeds(); 868 AdjustKnownSeeds();
772
773 // TODO: I think, this won't send anything, as we are still a child here...
774 Animator.TrySetMovementAnimation("STAND"); 869 Animator.TrySetMovementAnimation("STAND");
775
776 // we created a new ScenePresence (a new child agent) in a fresh region. 870 // we created a new ScenePresence (a new child agent) in a fresh region.
777 // Request info about all the (root) agents in this region 871 // Request info about all the (root) agents in this region
778 // Note: This won't send data *to* other clients in that region (children don't send) 872 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -785,21 +879,21 @@ namespace OpenSim.Region.Framework.Scenes
785 RegisterToEvents(); 879 RegisterToEvents();
786 SetDirectionVectors(); 880 SetDirectionVectors();
787 881
788 m_appearance = appearance; 882 Appearance = appearance;
789 } 883 }
790 884
791 public void RegisterToEvents() 885 public void RegisterToEvents()
792 { 886 {
793 m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; 887 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
794 //m_controllingClient.OnCompleteMovementToRegion += SendInitialData; 888 //ControllingClient.OnCompleteMovementToRegion += SendInitialData;
795 m_controllingClient.OnAgentUpdate += HandleAgentUpdate; 889 ControllingClient.OnAgentUpdate += HandleAgentUpdate;
796 m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit; 890 ControllingClient.OnAgentRequestSit += HandleAgentRequestSit;
797 m_controllingClient.OnAgentSit += HandleAgentSit; 891 ControllingClient.OnAgentSit += HandleAgentSit;
798 m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 892 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
799 m_controllingClient.OnStartAnim += HandleStartAnim; 893 ControllingClient.OnStartAnim += HandleStartAnim;
800 m_controllingClient.OnStopAnim += HandleStopAnim; 894 ControllingClient.OnStopAnim += HandleStopAnim;
801 m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; 895 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
802 m_controllingClient.OnAutoPilotGo += MoveToTarget; 896 ControllingClient.OnAutoPilotGo += MoveToTarget;
803 897
804 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 898 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
805 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 899 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -813,25 +907,47 @@ namespace OpenSim.Region.Framework.Scenes
813 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 907 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
814 Dir_Vectors[4] = Vector3.UnitZ; //UP 908 Dir_Vectors[4] = Vector3.UnitZ; //UP
815 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 909 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
816 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 910 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
817 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 911 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
818 Dir_Vectors[7] = -Vector3.UnitX; //BACK 912 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
913 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
914 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
819 } 915 }
820 916
821 private Vector3[] GetWalkDirectionVectors() 917 private Vector3[] GetWalkDirectionVectors()
822 { 918 {
823 Vector3[] vector = new Vector3[9]; 919 Vector3[] vector = new Vector3[11];
824 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 920 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
825 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 921 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
826 vector[2] = Vector3.UnitY; //LEFT 922 vector[2] = Vector3.UnitY; //LEFT
827 vector[3] = -Vector3.UnitY; //RIGHT 923 vector[3] = -Vector3.UnitY; //RIGHT
828 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 924 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
829 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 925 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
830 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 926 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
831 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 927 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
832 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 928 vector[8] = Vector3.UnitY; //LEFT_NUDGE
929 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
930 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
833 return vector; 931 return vector;
834 } 932 }
933
934 private bool[] GetDirectionIsNudge()
935 {
936 bool[] isNudge = new bool[11];
937 isNudge[0] = false; //FORWARD
938 isNudge[1] = false; //BACK
939 isNudge[2] = false; //LEFT
940 isNudge[3] = false; //RIGHT
941 isNudge[4] = false; //UP
942 isNudge[5] = false; //DOWN
943 isNudge[6] = true; //FORWARD_NUDGE
944 isNudge[7] = true; //BACK_NUDGE
945 isNudge[8] = true; //LEFT_NUDGE
946 isNudge[9] = true; //RIGHT_NUDGE
947 isNudge[10] = true; //DOWN_Nudge
948 return isNudge;
949 }
950
835 951
836 #endregion 952 #endregion
837 953
@@ -848,6 +964,8 @@ namespace OpenSim.Region.Framework.Scenes
848 public void SendPrimUpdates() 964 public void SendPrimUpdates()
849 { 965 {
850 m_sceneViewer.SendPrimUpdates(); 966 m_sceneViewer.SendPrimUpdates();
967
968 SceneViewer.SendPrimUpdates();
851 } 969 }
852 970
853 #region Status Methods 971 #region Status Methods
@@ -865,21 +983,21 @@ namespace OpenSim.Region.Framework.Scenes
865 983
866 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); 984 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
867 985
868 bool wasChild = m_isChildAgent; 986 bool wasChild = IsChildAgent;
869 m_isChildAgent = false; 987 IsChildAgent = false;
870 988
871 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 989 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
872 if (gm != null) 990 if (gm != null)
873 m_grouptitle = gm.GetGroupTitle(m_uuid); 991 Grouptitle = gm.GetGroupTitle(m_uuid);
874 992
875 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; 993 RegionHandle = m_scene.RegionInfo.RegionHandle;
876 994
877 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 995 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
878 996
879 // Moved this from SendInitialData to ensure that m_appearance is initialized 997 // Moved this from SendInitialData to ensure that Appearance is initialized
880 // before the inventory is processed in MakeRootAgent. This fixes a race condition 998 // before the inventory is processed in MakeRootAgent. This fixes a race condition
881 // related to the handling of attachments 999 // related to the handling of attachments
882 //m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); 1000 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
883 if (m_scene.TestBorderCross(pos, Cardinals.E)) 1001 if (m_scene.TestBorderCross(pos, Cardinals.E))
884 { 1002 {
885 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 1003 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
@@ -892,6 +1010,62 @@ namespace OpenSim.Region.Framework.Scenes
892 pos.Y = crossedBorder.BorderLine.Z - 1; 1010 pos.Y = crossedBorder.BorderLine.Z - 1;
893 } 1011 }
894 1012
1013 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
1014 if (land != null)
1015 {
1016 // If we come in via login, landmark or map, we want to
1017 // honor landing points. If we come in via Lure, we want
1018 // to ignore them.
1019 if ((m_teleportFlags & (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID)) == (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID) ||
1020 (m_teleportFlags & TeleportFlags.ViaLandmark) != 0 ||
1021 (m_teleportFlags & TeleportFlags.ViaLocation) != 0)
1022 {
1023 // Don't restrict gods, estate managers, or land owners to
1024 // the TP point. This behaviour mimics agni.
1025 if (land.LandData.LandingType == (byte)LandingType.LandingPoint &&
1026 land.LandData.UserLocation != Vector3.Zero &&
1027 GodLevel < 200 &&
1028 ((land.LandData.OwnerID != m_uuid &&
1029 (!m_scene.Permissions.IsGod(m_uuid)) &&
1030 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid))) || (m_teleportFlags & TeleportFlags.ViaLocation) != 0))
1031 {
1032 pos = land.LandData.UserLocation;
1033 }
1034 }
1035
1036 land.SendLandUpdateToClient(ControllingClient);
1037 }
1038
1039 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
1040 {
1041 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
1042
1043 if (pos.X < 0)
1044 {
1045 emergencyPos.X = (int)Constants.RegionSize + pos.X;
1046 if (!(pos.Y < 0))
1047 emergencyPos.Y = pos.Y;
1048 if (!(pos.Z < 0))
1049 emergencyPos.Z = pos.Z;
1050 }
1051 if (pos.Y < 0)
1052 {
1053 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
1054 if (!(pos.X < 0))
1055 emergencyPos.X = pos.X;
1056 if (!(pos.Z < 0))
1057 emergencyPos.Z = pos.Z;
1058 }
1059 if (pos.Z < 0)
1060 {
1061 emergencyPos.Z = 128;
1062 if (!(pos.Y < 0))
1063 emergencyPos.Y = pos.Y;
1064 if (!(pos.X < 0))
1065 emergencyPos.X = pos.X;
1066 }
1067 }
1068
895 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 1069 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
896 { 1070 {
897 m_log.WarnFormat( 1071 m_log.WarnFormat(
@@ -904,8 +1078,8 @@ namespace OpenSim.Region.Framework.Scenes
904 } 1078 }
905 1079
906 float localAVHeight = 1.56f; 1080 float localAVHeight = 1.56f;
907 if (m_appearance.AvatarHeight > 0) 1081 if (Appearance.AvatarHeight > 0)
908 localAVHeight = m_appearance.AvatarHeight; 1082 localAVHeight = Appearance.AvatarHeight;
909 1083
910 float posZLimit = 0; 1084 float posZLimit = 0;
911 1085
@@ -921,13 +1095,13 @@ namespace OpenSim.Region.Framework.Scenes
921 1095
922 AddToPhysicalScene(isFlying); 1096 AddToPhysicalScene(isFlying);
923 1097
924 if (m_forceFly) 1098 if (ForceFly)
925 { 1099 {
926 m_physicsActor.Flying = true; 1100 PhysicsActor.Flying = true;
927 } 1101 }
928 else if (m_flyDisabled) 1102 else if (FlyDisabled)
929 { 1103 {
930 m_physicsActor.Flying = false; 1104 PhysicsActor.Flying = false;
931 } 1105 }
932 1106
933 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1107 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
@@ -965,7 +1139,7 @@ namespace OpenSim.Region.Framework.Scenes
965 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1139 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
966 // stall on the border crossing since the existing child agent will still have the last movement 1140 // stall on the border crossing since the existing child agent will still have the last movement
967 // recorded, which stops the input from being processed. 1141 // recorded, which stops the input from being processed.
968 m_movementflag = 0; 1142 MovementFlag = 0;
969 1143
970 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1144 m_scene.EventManager.TriggerOnMakeRootAgent(this);
971 } 1145 }
@@ -995,12 +1169,12 @@ namespace OpenSim.Region.Framework.Scenes
995 { 1169 {
996 // Reset these so that teleporting in and walking out isn't seen 1170 // Reset these so that teleporting in and walking out isn't seen
997 // as teleporting back 1171 // as teleporting back
998 m_teleportFlags = TeleportFlags.Default; 1172 TeleportFlags = TeleportFlags.Default;
999 1173
1000 // It looks like m_animator is set to null somewhere, and MakeChild 1174 // It looks like Animator is set to null somewhere, and MakeChild
1001 // is called after that. Probably in aborted teleports. 1175 // is called after that. Probably in aborted teleports.
1002 if (m_animator == null) 1176 if (Animator == null)
1003 m_animator = new ScenePresenceAnimator(this); 1177 Animator = new ScenePresenceAnimator(this);
1004 else 1178 else
1005 Animator.ResetAnimations(); 1179 Animator.ResetAnimations();
1006 1180
@@ -1012,11 +1186,11 @@ namespace OpenSim.Region.Framework.Scenes
1012 // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated. 1186 // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated.
1013 //Velocity = new Vector3(0, 0, 0); 1187 //Velocity = new Vector3(0, 0, 0);
1014 1188
1015 m_isChildAgent = true; 1189 IsChildAgent = true;
1016 m_scene.SwapRootAgentCount(true); 1190 m_scene.SwapRootAgentCount(true);
1017 RemoveFromPhysicalScene(); 1191 RemoveFromPhysicalScene();
1018 1192
1019 // FIXME: Set m_rootRegionHandle to the region handle of the scene this agent is moving into 1193 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
1020 1194
1021 m_scene.EventManager.TriggerOnMakeChildAgent(this); 1195 m_scene.EventManager.TriggerOnMakeChildAgent(this);
1022 } 1196 }
@@ -1024,16 +1198,21 @@ namespace OpenSim.Region.Framework.Scenes
1024 /// <summary> 1198 /// <summary>
1025 /// Removes physics plugin scene representation of this agent if it exists. 1199 /// Removes physics plugin scene representation of this agent if it exists.
1026 /// </summary> 1200 /// </summary>
1027 private void RemoveFromPhysicalScene() 1201 public void RemoveFromPhysicalScene()
1028 { 1202 {
1029 if (PhysicsActor != null) 1203 if (PhysicsActor != null)
1030 { 1204 {
1031 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1205 try
1032 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; 1206 {
1033 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); 1207 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
1034 m_physicsActor.UnSubscribeEvents(); 1208 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
1035 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1209 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1036 PhysicsActor = null; 1210 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1211 m_physicsActor.UnSubscribeEvents();
1212 PhysicsActor = null;
1213 }
1214 catch
1215 { }
1037 } 1216 }
1038 } 1217 }
1039 1218
@@ -1044,24 +1223,27 @@ namespace OpenSim.Region.Framework.Scenes
1044 public void Teleport(Vector3 pos) 1223 public void Teleport(Vector3 pos)
1045 { 1224 {
1046 bool isFlying = false; 1225 bool isFlying = false;
1047 if (m_physicsActor != null) 1226 if (PhysicsActor != null)
1048 isFlying = m_physicsActor.Flying; 1227 isFlying = PhysicsActor.Flying;
1049 1228
1050 RemoveFromPhysicalScene(); 1229 RemoveFromPhysicalScene();
1051 Velocity = Vector3.Zero; 1230 Velocity = Vector3.Zero;
1231 CheckLandingPoint(ref pos);
1052 AbsolutePosition = pos; 1232 AbsolutePosition = pos;
1053 AddToPhysicalScene(isFlying); 1233 AddToPhysicalScene(isFlying);
1054 1234
1055 SendTerseUpdateToAllClients(); 1235 SendTerseUpdateToAllClients();
1236
1056 } 1237 }
1057 1238
1058 public void TeleportWithMomentum(Vector3 pos) 1239 public void TeleportWithMomentum(Vector3 pos)
1059 { 1240 {
1060 bool isFlying = false; 1241 bool isFlying = false;
1061 if (m_physicsActor != null) 1242 if (PhysicsActor != null)
1062 isFlying = m_physicsActor.Flying; 1243 isFlying = PhysicsActor.Flying;
1063 1244
1064 RemoveFromPhysicalScene(); 1245 RemoveFromPhysicalScene();
1246 CheckLandingPoint(ref pos);
1065 AbsolutePosition = pos; 1247 AbsolutePosition = pos;
1066 AddToPhysicalScene(isFlying); 1248 AddToPhysicalScene(isFlying);
1067 1249
@@ -1174,11 +1356,11 @@ namespace OpenSim.Region.Framework.Scenes
1174 1356
1175 //m_log.DebugFormat("[SCENE PRESENCE] Completed movement"); 1357 //m_log.DebugFormat("[SCENE PRESENCE] Completed movement");
1176 1358
1177 m_controllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look); 1359 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look);
1178 SendInitialData(); 1360 SendInitialData();
1179 1361
1180 // Create child agents in neighbouring regions 1362 // Create child agents in neighbouring regions
1181 if (openChildAgents && !m_isChildAgent) 1363 if (openChildAgents && !IsChildAgent)
1182 { 1364 {
1183 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1365 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1184 if (m_agentTransfer != null) 1366 if (m_agentTransfer != null)
@@ -1222,7 +1404,7 @@ namespace OpenSim.Region.Framework.Scenes
1222 { 1404 {
1223 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1405 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1224 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1406 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
1225 !m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1407 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1226 { 1408 {
1227 if (CameraConstraintActive) 1409 if (CameraConstraintActive)
1228 { 1410 {
@@ -1237,13 +1419,14 @@ namespace OpenSim.Region.Framework.Scenes
1237 /// <summary> 1419 /// <summary>
1238 /// This is the event handler for client movement. If a client is moving, this event is triggering. 1420 /// This is the event handler for client movement. If a client is moving, this event is triggering.
1239 /// </summary> 1421 /// </summary>
1422 /// <summary>
1423 /// This is the event handler for client movement. If a client is moving, this event is triggering.
1424 /// </summary>
1240 public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) 1425 public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
1241 { 1426 {
1242// m_log.DebugFormat( 1427 // m_log.DebugFormat("[SCENE PRESENCE]: Received agent update from {0}", remoteClient.Name);
1243// "[SCENE PRESENCE]: In {0} received agent update from {1}",
1244// Scene.RegionInfo.RegionName, remoteClient.Name);
1245 1428
1246 //if (m_isChildAgent) 1429 //if (IsChildAgent)
1247 //{ 1430 //{
1248 // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); 1431 // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent");
1249 // return; 1432 // return;
@@ -1287,28 +1470,28 @@ namespace OpenSim.Region.Framework.Scenes
1287 1470
1288 // Camera location in world. We'll need to raytrace 1471 // Camera location in world. We'll need to raytrace
1289 // from this location from time to time. 1472 // from this location from time to time.
1290 m_CameraCenter = agentData.CameraCenter; 1473 CameraPosition = agentData.CameraCenter;
1291 if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance) 1474 if (Vector3.Distance(m_lastCameraPosition, CameraPosition) >= Scene.RootReprioritizationDistance)
1292 { 1475 {
1293 ReprioritizeUpdates(); 1476 ReprioritizeUpdates();
1294 m_lastCameraCenter = m_CameraCenter; 1477 m_lastCameraPosition = CameraPosition;
1295 } 1478 }
1296 1479
1297 // Use these three vectors to figure out what the agent is looking at 1480 // Use these three vectors to figure out what the agent is looking at
1298 // Convert it to a Matrix and/or Quaternion 1481 // Convert it to a Matrix and/or Quaternion
1299 m_CameraAtAxis = agentData.CameraAtAxis; 1482 CameraAtAxis = agentData.CameraAtAxis;
1300 m_CameraLeftAxis = agentData.CameraLeftAxis; 1483 CameraLeftAxis = agentData.CameraLeftAxis;
1301 m_CameraUpAxis = agentData.CameraUpAxis; 1484 m_CameraUpAxis = agentData.CameraUpAxis;
1302 1485
1303 // The Agent's Draw distance setting 1486 // The Agent's Draw distance setting
1304 // When we get to the point of re-computing neighbors everytime this 1487 // When we get to the point of re-computing neighbors everytime this
1305 // changes, then start using the agent's drawdistance rather than the 1488 // changes, then start using the agent's drawdistance rather than the
1306 // region's draw distance. 1489 // region's draw distance.
1307 // m_DrawDistance = agentData.Far; 1490 // DrawDistance = agentData.Far;
1308 m_DrawDistance = Scene.DefaultDrawDistance; 1491 DrawDistance = Scene.DefaultDrawDistance;
1309 1492
1310 // Check if Client has camera in 'follow cam' or 'build' mode. 1493 // Check if Client has camera in 'follow cam' or 'build' mode.
1311 Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); 1494 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
1312 1495
1313 m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) 1496 m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f)
1314 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; 1497 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
@@ -1330,7 +1513,7 @@ namespace OpenSim.Region.Framework.Scenes
1330 if (m_followCamAuto) 1513 if (m_followCamAuto)
1331 { 1514 {
1332 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1515 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
1333 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1516 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
1334 } 1517 }
1335 } 1518 }
1336 1519
@@ -1359,7 +1542,7 @@ namespace OpenSim.Region.Framework.Scenes
1359 // Here's where you get them. 1542 // Here's where you get them.
1360 m_AgentControlFlags = flags; 1543 m_AgentControlFlags = flags;
1361 m_headrotation = agentData.HeadRotation; 1544 m_headrotation = agentData.HeadRotation;
1362 m_state = agentData.State; 1545 State = agentData.State;
1363 1546
1364 PhysicsActor actor = PhysicsActor; 1547 PhysicsActor actor = PhysicsActor;
1365 if (actor == null) 1548 if (actor == null)
@@ -1367,12 +1550,12 @@ namespace OpenSim.Region.Framework.Scenes
1367 return; 1550 return;
1368 } 1551 }
1369 1552
1370 if (m_allowMovement && !SitGround) 1553 if (AllowMovement && !SitGround)
1371 { 1554 {
1372 Quaternion bodyRotation = agentData.BodyRotation; 1555 Quaternion bodyRotation = agentData.BodyRotation;
1373 bool update_rotation = false; 1556 bool update_rotation = false;
1374 1557
1375 if (bodyRotation != m_bodyRot) 1558 if (bodyRotation != Rotation)
1376 { 1559 {
1377 Rotation = bodyRotation; 1560 Rotation = bodyRotation;
1378 update_rotation = true; 1561 update_rotation = true;
@@ -1392,9 +1575,9 @@ namespace OpenSim.Region.Framework.Scenes
1392 1575
1393 bool oldflying = PhysicsActor.Flying; 1576 bool oldflying = PhysicsActor.Flying;
1394 1577
1395 if (m_forceFly) 1578 if (ForceFly)
1396 actor.Flying = true; 1579 actor.Flying = true;
1397 else if (m_flyDisabled) 1580 else if (FlyDisabled)
1398 actor.Flying = false; 1581 actor.Flying = false;
1399 else 1582 else
1400 actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1583 actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
@@ -1402,7 +1585,7 @@ namespace OpenSim.Region.Framework.Scenes
1402 if (actor.Flying != oldflying) 1585 if (actor.Flying != oldflying)
1403 update_movementflag = true; 1586 update_movementflag = true;
1404 1587
1405 if (m_parentID == 0) 1588 if (ParentID == 0)
1406 { 1589 {
1407 bool bAllowUpdateMoveToPosition = false; 1590 bool bAllowUpdateMoveToPosition = false;
1408 1591
@@ -1410,12 +1593,12 @@ namespace OpenSim.Region.Framework.Scenes
1410 1593
1411 // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying 1594 // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying
1412 // this prevents 'jumping' in inappropriate situations. 1595 // this prevents 'jumping' in inappropriate situations.
1413 if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying)) 1596 if ((m_mouseLook && !PhysicsActor.Flying) || (m_leftButtonDown && !PhysicsActor.Flying))
1414 dirVectors = GetWalkDirectionVectors(); 1597 dirVectors = GetWalkDirectionVectors();
1415 else 1598 else
1416 dirVectors = Dir_Vectors; 1599 dirVectors = Dir_Vectors;
1417 1600
1418 // The fact that m_movementflag is a byte needs to be fixed 1601 // The fact that MovementFlag is a byte needs to be fixed
1419 // it really should be a uint 1602 // it really should be a uint
1420 // A DIR_CONTROL_FLAG occurs when the user is trying to move in a particular direction. 1603 // A DIR_CONTROL_FLAG occurs when the user is trying to move in a particular direction.
1421 uint nudgehack = 250; 1604 uint nudgehack = 250;
@@ -1435,32 +1618,32 @@ namespace OpenSim.Region.Framework.Scenes
1435 // Why did I get this? 1618 // Why did I get this?
1436 } 1619 }
1437 1620
1438 if ((m_movementflag & (byte)(uint)DCF) == 0) 1621 if ((MovementFlag & (byte)(uint)DCF) == 0)
1439 { 1622 {
1440 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) 1623 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACK_NUDGE)
1441 { 1624 {
1442 m_movementflag |= (byte)nudgehack; 1625 MovementFlag |= (byte)nudgehack;
1443 } 1626 }
1444 1627
1445// m_log.DebugFormat("[SCENE PRESENCE]: Updating m_movementflag for {0} with {1}", Name, DCF); 1628// m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF);
1446 m_movementflag += (byte)(uint)DCF; 1629 MovementFlag += (byte)(uint)DCF;
1447 update_movementflag = true; 1630 update_movementflag = true;
1448 } 1631 }
1449 } 1632 }
1450 else 1633 else
1451 { 1634 {
1452 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1635 if ((m_movementflag & (byte)(uint)DCF) != 0 ||
1453 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) 1636 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACK_NUDGE)
1454 && ((m_movementflag & (byte)nudgehack) == nudgehack)) 1637 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1455 ) // This or is for Nudge forward 1638 ) // This or is for Nudge forward
1456 { 1639 {
1457// m_log.DebugFormat("[SCENE PRESENCE]: Updating m_movementflag for {0} with lack of {1}", Name, DCF); 1640 // m_log.DebugFormat("[SCENE PRESENCE]: Updating m_movementflag for {0} with lack of {1}", Name, DCF);
1458 m_movementflag -= ((byte)(uint)DCF); 1641 m_movementflag -= ((byte)(uint)DCF);
1459 update_movementflag = true; 1642 update_movementflag = true;
1460 1643
1461 /* 1644 /*
1462 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) 1645 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1463 && ((m_movementflag & (byte)nudgehack) == nudgehack)) 1646 && ((MovementFlag & (byte)nudgehack) == nudgehack))
1464 { 1647 {
1465 m_log.Debug("Removed Hack flag"); 1648 m_log.Debug("Removed Hack flag");
1466 } 1649 }
@@ -1495,7 +1678,7 @@ namespace OpenSim.Region.Framework.Scenes
1495 // with something with the down arrow pressed. 1678 // with something with the down arrow pressed.
1496 1679
1497 // Only do this if we're flying 1680 // Only do this if we're flying
1498 if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) 1681 if (PhysicsActor != null && PhysicsActor.Flying && !ForceFly)
1499 { 1682 {
1500 // Landing detection code 1683 // Landing detection code
1501 1684
@@ -1503,10 +1686,7 @@ namespace OpenSim.Region.Framework.Scenes
1503 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || 1686 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
1504 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 1687 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
1505 1688
1506 // Are the collision requirements fulfilled? 1689 if (PhysicsActor.Flying && PhysicsActor.IsColliding && controlland)
1507 bool colliding = (m_physicsActor.IsColliding == true);
1508
1509 if (m_physicsActor.Flying && colliding && controlland)
1510 { 1690 {
1511 // nesting this check because LengthSquared() is expensive and we don't 1691 // nesting this check because LengthSquared() is expensive and we don't
1512 // want to do it every step when flying. 1692 // want to do it every step when flying.
@@ -1519,23 +1699,23 @@ namespace OpenSim.Region.Framework.Scenes
1519 // which occurs later in the main scene loop 1699 // which occurs later in the main scene loop
1520 if (update_movementflag || (update_rotation && DCFlagKeyPressed)) 1700 if (update_movementflag || (update_rotation && DCFlagKeyPressed))
1521 { 1701 {
1522// m_log.DebugFormat( 1702 // m_log.DebugFormat(
1523// "[SCENE PRESENCE]: In {0} adding velocity of {1} to {2}, umf = {3}, ur = {4}", 1703 // "[SCENE PRESENCE]: In {0} adding velocity of {1} to {2}, umf = {3}, ur = {4}",
1524// m_scene.RegionInfo.RegionName, agent_control_v3, Name, update_movementflag, update_rotation); 1704 // m_scene.RegionInfo.RegionName, agent_control_v3, Name, update_movementflag, update_rotation);
1525 1705
1526 AddNewMovement(agent_control_v3); 1706 AddNewMovement(agent_control_v3);
1527 } 1707 }
1528// else 1708 // else
1529// { 1709 // {
1530// if (!update_movementflag) 1710 // if (!update_movementflag)
1531// { 1711 // {
1532// m_log.DebugFormat( 1712 // m_log.DebugFormat(
1533// "[SCENE PRESENCE]: In {0} ignoring requested update of {1} for {2} as update_movementflag = false", 1713 // "[SCENE PRESENCE]: In {0} ignoring requested update of {1} for {2} as update_movementflag = false",
1534// m_scene.RegionInfo.RegionName, agent_control_v3, Name); 1714 // m_scene.RegionInfo.RegionName, agent_control_v3, Name);
1535// } 1715 // }
1536// } 1716 // }
1537 1717
1538 if (update_movementflag && m_parentID == 0) 1718 if (update_movementflag && ParentID == 0)
1539 Animator.UpdateMovementAnimations(); 1719 Animator.UpdateMovementAnimations();
1540 } 1720 }
1541 1721
@@ -1555,20 +1735,20 @@ namespace OpenSim.Region.Framework.Scenes
1555 /// <returns>True if movement has been updated in some way. False otherwise.</returns> 1735 /// <returns>True if movement has been updated in some way. False otherwise.</returns>
1556 public bool HandleMoveToTargetUpdate(ref Vector3 agent_control_v3) 1736 public bool HandleMoveToTargetUpdate(ref Vector3 agent_control_v3)
1557 { 1737 {
1558// m_log.DebugFormat("[SCENE PRESENCE]: Called HandleMoveToTargetUpdate() for {0}", Name); 1738 // m_log.DebugFormat("[SCENE PRESENCE]: Called HandleMoveToTargetUpdate() for {0}", Name);
1559 1739
1560 bool updated = false; 1740 bool updated = false;
1561 1741
1562// m_log.DebugFormat( 1742 // m_log.DebugFormat(
1563// "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}", 1743 // "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}",
1564// allowUpdate, m_moveToPositionInProgress, m_autopilotMoving); 1744 // allowUpdate, m_moveToPositionInProgress, m_autopilotMoving);
1565 1745
1566 if (!m_autopilotMoving) 1746 if (!m_autopilotMoving)
1567 { 1747 {
1568 double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, MoveToPositionTarget); 1748 double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, MoveToPositionTarget);
1569// m_log.DebugFormat( 1749 // m_log.DebugFormat(
1570// "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}", 1750 // "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}",
1571// Name, AbsolutePosition, MoveToPositionTarget, distanceToTarget); 1751 // Name, AbsolutePosition, MoveToPositionTarget, distanceToTarget);
1572 1752
1573 // Check the error term of the current position in relation to the target position 1753 // Check the error term of the current position in relation to the target position
1574 if (distanceToTarget <= 1) 1754 if (distanceToTarget <= 1)
@@ -1591,7 +1771,7 @@ namespace OpenSim.Region.Framework.Scenes
1591 (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords 1771 (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords
1592 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(Rotation)); // change to avatar coords 1772 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(Rotation)); // change to avatar coords
1593 // Ignore z component of vector 1773 // Ignore z component of vector
1594// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1774 // Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1595 LocalVectorToTarget3D.Normalize(); 1775 LocalVectorToTarget3D.Normalize();
1596 1776
1597 // update avatar movement flags. the avatar coordinate system is as follows: 1777 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1617,26 +1797,26 @@ namespace OpenSim.Region.Framework.Scenes
1617 // one of left/right/back/forward. 1797 // one of left/right/back/forward.
1618 if (LocalVectorToTarget3D.X < 0) //MoveBack 1798 if (LocalVectorToTarget3D.X < 0) //MoveBack
1619 { 1799 {
1620 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; 1800 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
1621 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; 1801 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
1622 updated = true; 1802 updated = true;
1623 } 1803 }
1624 else if (LocalVectorToTarget3D.X > 0) //Move Forward 1804 else if (LocalVectorToTarget3D.X > 0) //Move Forward
1625 { 1805 {
1626 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; 1806 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
1627 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; 1807 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
1628 updated = true; 1808 updated = true;
1629 } 1809 }
1630 1810
1631 if (LocalVectorToTarget3D.Y > 0) //MoveLeft 1811 if (LocalVectorToTarget3D.Y > 0) //MoveLeft
1632 { 1812 {
1633 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; 1813 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
1634 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; 1814 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
1635 updated = true; 1815 updated = true;
1636 } 1816 }
1637 else if (LocalVectorToTarget3D.Y < 0) //MoveRight 1817 else if (LocalVectorToTarget3D.Y < 0) //MoveRight
1638 { 1818 {
1639 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; 1819 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
1640 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; 1820 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
1641 updated = true; 1821 updated = true;
1642 } 1822 }
@@ -1645,21 +1825,21 @@ namespace OpenSim.Region.Framework.Scenes
1645 { 1825 {
1646 // Don't set these flags for up or down - doing so will make the avatar crouch or 1826 // Don't set these flags for up or down - doing so will make the avatar crouch or
1647 // keep trying to jump even if walking along level ground 1827 // keep trying to jump even if walking along level ground
1648 //m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; 1828 //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP;
1649 //AgentControlFlags 1829 //AgentControlFlags
1650 //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; 1830 //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP;
1651 updated = true; 1831 updated = true;
1652 } 1832 }
1653 else if (LocalVectorToTarget3D.Z < 0) //Down 1833 else if (LocalVectorToTarget3D.Z < 0) //Down
1654 { 1834 {
1655 //m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; 1835 //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN;
1656 //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; 1836 //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN;
1657 updated = true; 1837 updated = true;
1658 } 1838 }
1659 1839
1660// m_log.DebugFormat( 1840 // m_log.DebugFormat(
1661// "[SCENE PRESENCE]: HandleMoveToTargetUpdate adding {0} to move vector {1} for {2}", 1841 // "[SCENE PRESENCE]: HandleMoveToTargetUpdate adding {0} to move vector {1} for {2}",
1662// LocalVectorToTarget3D, agent_control_v3, Name); 1842 // LocalVectorToTarget3D, agent_control_v3, Name);
1663 1843
1664 agent_control_v3 += LocalVectorToTarget3D; 1844 agent_control_v3 += LocalVectorToTarget3D;
1665 } 1845 }
@@ -1780,7 +1960,7 @@ namespace OpenSim.Region.Framework.Scenes
1780 Velocity = Vector3.Zero; 1960 Velocity = Vector3.Zero;
1781 SendAvatarDataToAllAgents(); 1961 SendAvatarDataToAllAgents();
1782 1962
1783 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1963 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1784 } 1964 }
1785 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1965 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1786 m_requestedSitTargetUUID = UUID.Zero; 1966 m_requestedSitTargetUUID = UUID.Zero;
@@ -1815,49 +1995,84 @@ namespace OpenSim.Region.Framework.Scenes
1815 { 1995 {
1816 SitGround = false; 1996 SitGround = false;
1817 1997
1818 if (m_parentID != 0) 1998 if (ParentID != 0)
1819 { 1999 {
1820 m_log.Debug("StandupCode Executed"); 2000 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1821 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1822 if (part != null) 2001 if (part != null)
1823 { 2002 {
2003 part.TaskInventory.LockItemsForRead(true);
1824 TaskInventoryDictionary taskIDict = part.TaskInventory; 2004 TaskInventoryDictionary taskIDict = part.TaskInventory;
1825 if (taskIDict != null) 2005 if (taskIDict != null)
1826 { 2006 {
1827 lock (taskIDict) 2007 foreach (UUID taskID in taskIDict.Keys)
1828 { 2008 {
1829 foreach (UUID taskID in taskIDict.Keys) 2009 UnRegisterControlEventsToScript(LocalId, taskID);
1830 { 2010 taskIDict[taskID].PermsMask &= ~(
1831 UnRegisterControlEventsToScript(LocalId, taskID); 2011 2048 | //PERMISSION_CONTROL_CAMERA
1832 taskIDict[taskID].PermsMask &= ~( 2012 4); // PERMISSION_TAKE_CONTROLS
1833 2048 | //PERMISSION_CONTROL_CAMERA
1834 4); // PERMISSION_TAKE_CONTROLS
1835 }
1836 } 2013 }
1837
1838 } 2014 }
2015 part.TaskInventory.LockItemsForRead(false);
1839 // Reset sit target. 2016 // Reset sit target.
1840 if (part.GetAvatarOnSitTarget() == UUID) 2017 if (part.GetAvatarOnSitTarget() == UUID)
1841 part.SitTargetAvatar = UUID.Zero; 2018 part.SitTargetAvatar = UUID.Zero;
1842 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2019 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1843 2020
1844 m_parentPosition = part.GetWorldPosition(); 2021 ParentPosition = part.GetWorldPosition();
1845 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2022 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1846 } 2023 }
2024 // part.GetWorldRotation() is the rotation of the object being sat on
2025 // Rotation is the sittiing Av's rotation
2026
2027 Quaternion partRot;
2028// if (part.LinkNum == 1)
2029// { // Root prim of linkset
2030// partRot = part.ParentGroup.RootPart.RotationOffset;
2031// }
2032// else
2033// { // single or child prim
2034
2035// }
2036 if (part == null) //CW: Part may be gone. llDie() for example.
2037 {
2038 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
2039 }
2040 else
2041 {
2042 partRot = part.GetWorldRotation();
2043 }
1847 2044
2045 Quaternion partIRot = Quaternion.Inverse(partRot);
2046
2047 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
2048 Vector3 avStandUp = new Vector3(0.3f, 0f, 0f) * avatarRot; // 0.3M infront of av
2049
2050
1848 if (m_physicsActor == null) 2051 if (m_physicsActor == null)
1849 { 2052 {
1850 AddToPhysicalScene(false); 2053 AddToPhysicalScene(false);
1851 } 2054 }
1852 2055 //CW: If the part isn't null then we can set the current position
1853 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 2056 if (part != null)
1854 m_parentPosition = Vector3.Zero; 2057 {
1855 2058 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1856 m_parentID = 0; 2059 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
2060 part.IsOccupied = false;
2061 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
2062 }
2063 else
2064 {
2065 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
2066 AbsolutePosition = m_lastWorldPosition;
2067 }
2068
2069 m_parentPosition = Vector3.Zero;
2070 m_parentID = 0;
2071 m_linkedPrim = UUID.Zero;
2072 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1857 SendAvatarDataToAllAgents(); 2073 SendAvatarDataToAllAgents();
1858 m_requestedSitTargetID = 0; 2074 m_requestedSitTargetID = 0;
1859 } 2075 }
1860
1861 Animator.TrySetMovementAnimation("STAND"); 2076 Animator.TrySetMovementAnimation("STAND");
1862 } 2077 }
1863 2078
@@ -1888,13 +2103,9 @@ namespace OpenSim.Region.Framework.Scenes
1888 Vector3 avSitOffSet = part.SitTargetPosition; 2103 Vector3 avSitOffSet = part.SitTargetPosition;
1889 Quaternion avSitOrientation = part.SitTargetOrientation; 2104 Quaternion avSitOrientation = part.SitTargetOrientation;
1890 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 2105 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1891 2106 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1892 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 2107 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1893 bool SitTargetisSet = 2108 if (SitTargetisSet && !SitTargetOccupied)
1894 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1895 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1896
1897 if (SitTargetisSet && SitTargetUnOccupied)
1898 { 2109 {
1899 //switch the target to this prim 2110 //switch the target to this prim
1900 return part; 2111 return part;
@@ -1908,85 +2119,168 @@ namespace OpenSim.Region.Framework.Scenes
1908 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 2119 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1909 { 2120 {
1910 bool autopilot = true; 2121 bool autopilot = true;
2122 Vector3 autopilotTarget = new Vector3();
2123 Quaternion sitOrientation = Quaternion.Identity;
1911 Vector3 pos = new Vector3(); 2124 Vector3 pos = new Vector3();
1912 Quaternion sitOrientation = pSitOrientation;
1913 Vector3 cameraEyeOffset = Vector3.Zero; 2125 Vector3 cameraEyeOffset = Vector3.Zero;
1914 Vector3 cameraAtOffset = Vector3.Zero; 2126 Vector3 cameraAtOffset = Vector3.Zero;
1915 bool forceMouselook = false; 2127 bool forceMouselook = false;
1916 2128
1917 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 2129 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1918 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 2130 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1919 if (part != null) 2131 if (part == null) return;
2132
2133 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
2134 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
2135
2136 // part is the prim to sit on
2137 // offset is the world-ref vector distance from that prim center to the click-spot
2138 // UUID is the UUID of the Avatar doing the clicking
2139
2140 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
2141
2142 // Is a sit target available?
2143 Vector3 avSitOffSet = part.SitTargetPosition;
2144 Quaternion avSitOrientation = part.SitTargetOrientation;
2145
2146 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
2147 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
2148 Quaternion partRot;
2149// if (part.LinkNum == 1)
2150// { // Root prim of linkset
2151// partRot = part.ParentGroup.RootPart.RotationOffset;
2152// }
2153// else
2154// { // single or child prim
2155 partRot = part.GetWorldRotation();
2156// }
2157 Quaternion partIRot = Quaternion.Inverse(partRot);
2158//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
2159 // Sit analysis rewritten by KF 091125
2160 if (SitTargetisSet) // scipted sit
1920 { 2161 {
1921 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 2162 if (!part.IsOccupied)
1922 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 2163 {
1923 2164//Console.WriteLine("Scripted, unoccupied");
1924 // Is a sit target available? 2165 part.SitTargetAvatar = UUID; // set that Av will be on it
1925 Vector3 avSitOffSet = part.SitTargetPosition; 2166 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1926 Quaternion avSitOrientation = part.SitTargetOrientation; 2167
1927 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 2168 Quaternion nrot = avSitOrientation;
1928 2169 if (!part.IsRoot)
1929 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero));
1930 bool SitTargetisSet =
1931 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f &&
1932 (
1933 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion
1934 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point
1935 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion
1936 )
1937 ));
1938
1939 if (SitTargetisSet && SitTargetUnOccupied)
1940 {
1941 part.SitTargetAvatar = UUID;
1942 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z);
1943 sitOrientation = avSitOrientation;
1944 autopilot = false;
1945 }
1946 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1947
1948 pos = part.AbsolutePosition + offset;
1949 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1)
1950 //{
1951 // offset = pos;
1952 //autopilot = false;
1953 //}
1954 if (m_physicsActor != null)
1955 {
1956 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1957 // We can remove the physicsActor until they stand up.
1958 m_sitAvatarHeight = m_physicsActor.Size.Z;
1959
1960 if (autopilot)
1961 { 2170 {
1962 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 2171 nrot = part.RotationOffset * avSitOrientation;
1963 {
1964 autopilot = false;
1965
1966 RemoveFromPhysicalScene();
1967 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1968 }
1969 } 2172 }
1970 else 2173 sitOrientation = nrot; // Change rotatione to the scripted one
2174 OffsetRotation = nrot;
2175 autopilot = false; // Jump direct to scripted llSitPos()
2176 }
2177 else
2178 {
2179//Console.WriteLine("Scripted, occupied");
2180 return;
2181 }
2182 }
2183 else // Not Scripted
2184 {
2185 if ( (Math.Abs(offset.X) > 0.1f) || (Math.Abs(offset.Y) > 0.1f) ) // Changed 0.5M to 0.1M as they want to be able to sit close together
2186 {
2187 // large prim & offset, ignore if other Avs sitting
2188// offset.Z -= 0.05f;
2189 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
2190 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
2191
2192//Console.WriteLine(" offset ={0}", offset);
2193//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
2194//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
2195
2196 }
2197 else // small offset
2198 {
2199//Console.WriteLine("Small offset");
2200 if (!part.IsOccupied)
2201 {
2202 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
2203 autopilotTarget = part.AbsolutePosition;
2204//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
2205 }
2206 else return; // occupied small
2207 } // end large/small
2208 } // end Scripted/not
2209
2210 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2211
2212 cameraAtOffset = part.GetCameraAtOffset();
2213 cameraEyeOffset = part.GetCameraEyeOffset();
2214 forceMouselook = part.GetForceMouselook();
2215 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2216 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2217
2218 if (m_physicsActor != null)
2219 {
2220 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2221 // We can remove the physicsActor until they stand up.
2222 m_sitAvatarHeight = m_physicsActor.Size.Z;
2223 if (autopilot)
2224 { // its not a scripted sit
2225// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2226 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) )
1971 { 2227 {
2228 autopilot = false; // close enough
2229 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2230 Not using the part's position because returning the AV to the last known standing
2231 position is likely to be more friendly, isn't it? */
1972 RemoveFromPhysicalScene(); 2232 RemoveFromPhysicalScene();
1973 } 2233 Velocity = Vector3.Zero;
2234 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2235 } // else the autopilot will get us close
2236 }
2237 else
2238 { // its a scripted sit
2239 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2240 I *am* using the part's position this time because we have no real idea how far away
2241 the avatar is from the sit target. */
2242 RemoveFromPhysicalScene();
2243 Velocity = Vector3.Zero;
1974 } 2244 }
1975
1976 cameraAtOffset = part.GetCameraAtOffset();
1977 cameraEyeOffset = part.GetCameraEyeOffset();
1978 forceMouselook = part.GetForceMouselook();
1979 } 2245 }
1980 2246 else return; // physactor is null!
1981 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2247
1982 m_requestedSitTargetUUID = targetID; 2248 Vector3 offsetr; // = offset * partIRot;
2249 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2250 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2251 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2252 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2253 //offsetr = offset * partIRot;
2254//
2255 // }
2256 // else
2257 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2258 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2259 // (offset * partRot);
2260 // }
2261
2262//Console.WriteLine(" ");
2263//Console.WriteLine("link number ={0}", part.LinkNum);
2264//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2265//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2266//Console.WriteLine("Click offst ={0}", offset);
2267//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2268//Console.WriteLine("offsetr ={0}", offsetr);
2269//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2270//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2271
2272 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2273 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2274
2275 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1983 // This calls HandleAgentSit twice, once from here, and the client calls 2276 // This calls HandleAgentSit twice, once from here, and the client calls
1984 // HandleAgentSit itself after it gets to the location 2277 // HandleAgentSit itself after it gets to the location
1985 // It doesn't get to the location until we've moved them there though 2278 // It doesn't get to the location until we've moved them there though
1986 // which happens in HandleAgentSit :P 2279 // which happens in HandleAgentSit :P
1987 m_autopilotMoving = autopilot; 2280 m_autopilotMoving = autopilot;
1988 m_autoPilotTarget = pos; 2281 m_autoPilotTarget = autopilotTarget;
1989 m_sitAtAutoTarget = autopilot; 2282 m_sitAtAutoTarget = autopilot;
2283 m_initialSitTarget = autopilotTarget;
1990 if (!autopilot) 2284 if (!autopilot)
1991 HandleAgentSit(remoteClient, UUID); 2285 HandleAgentSit(remoteClient, UUID);
1992 } 2286 }
@@ -1994,7 +2288,7 @@ namespace OpenSim.Region.Framework.Scenes
1994 // public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) 2288 // public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation)
1995 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2289 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
1996 { 2290 {
1997 if (m_parentID != 0) 2291 if (ParentID != 0)
1998 { 2292 {
1999 StandUp(); 2293 StandUp();
2000 } 2294 }
@@ -2251,47 +2545,131 @@ namespace OpenSim.Region.Framework.Scenes
2251 { 2545 {
2252 if (part != null) 2546 if (part != null)
2253 { 2547 {
2548//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2254 if (part.GetAvatarOnSitTarget() == UUID) 2549 if (part.GetAvatarOnSitTarget() == UUID)
2255 { 2550 {
2551//Console.WriteLine("Scripted Sit");
2552 // Scripted sit
2256 Vector3 sitTargetPos = part.SitTargetPosition; 2553 Vector3 sitTargetPos = part.SitTargetPosition;
2257 Quaternion sitTargetOrient = part.SitTargetOrientation; 2554 Quaternion sitTargetOrient = part.SitTargetOrientation;
2258
2259 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2260 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2261
2262 //Quaternion result = (sitTargetOrient * vq) * nq;
2263
2264 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2555 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2265 m_pos += SIT_TARGET_ADJUSTMENT; 2556 m_pos += SIT_TARGET_ADJUSTMENT;
2557 if (!part.IsRoot)
2558 {
2559 m_pos *= part.RotationOffset;
2560 }
2266 m_bodyRot = sitTargetOrient; 2561 m_bodyRot = sitTargetOrient;
2267 //Rotation = sitTargetOrient;
2268 m_parentPosition = part.AbsolutePosition; 2562 m_parentPosition = part.AbsolutePosition;
2269 2563 part.IsOccupied = true;
2270 //SendTerseUpdateToAllClients(); 2564 part.ParentGroup.AddAvatar(agentID);
2271 } 2565 }
2272 else 2566 else
2273 { 2567 {
2274 m_pos -= part.AbsolutePosition; 2568 // if m_avUnscriptedSitPos is zero then Av sits above center
2569 // Else Av sits at m_avUnscriptedSitPos
2570
2571 // Non-scripted sit by Kitto Flora 21Nov09
2572 // Calculate angle of line from prim to Av
2573 Quaternion partIRot;
2574// if (part.LinkNum == 1)
2575// { // Root prim of linkset
2576// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2577// }
2578// else
2579// { // single or child prim
2580 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2581// }
2582 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2583 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2584 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2585 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2586 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2587 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2588 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2589 // Av sits at world euler <0,0, z>, translated by part rotation
2590 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2591
2275 m_parentPosition = part.AbsolutePosition; 2592 m_parentPosition = part.AbsolutePosition;
2276 } 2593 part.IsOccupied = true;
2594 part.ParentGroup.AddAvatar(agentID);
2595 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2596 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2597 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2598 m_avUnscriptedSitPos; // adds click offset, if any
2599 //Set up raytrace to find top surface of prim
2600 Vector3 size = part.Scale;
2601 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2602 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2603 Vector3 down = new Vector3(0f, 0f, -1f);
2604//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2605 m_scene.PhysicsScene.RaycastWorld(
2606 start, // Vector3 position,
2607 down, // Vector3 direction,
2608 mag, // float length,
2609 SitAltitudeCallback); // retMethod
2610 } // end scripted/not
2277 } 2611 }
2278 else 2612 else // no Av
2279 { 2613 {
2280 return; 2614 return;
2281 } 2615 }
2282 } 2616 }
2283 m_parentID = m_requestedSitTargetID; 2617 ParentID = m_requestedSitTargetID;
2284 2618
2619 //We want our offsets to reference the root prim, not the child we may have sat on
2620 if (!part.IsRoot)
2621 {
2622 m_parentID = part.ParentGroup.RootPart.LocalId;
2623 m_pos += part.OffsetPosition;
2624 }
2625 else
2626 {
2627 m_parentID = m_requestedSitTargetID;
2628 }
2629
2630 m_linkedPrim = part.UUID;
2631 if (part.GetAvatarOnSitTarget() != UUID)
2632 {
2633 m_offsetRotation = m_offsetRotation / part.RotationOffset;
2634 }
2285 Velocity = Vector3.Zero; 2635 Velocity = Vector3.Zero;
2286 RemoveFromPhysicalScene(); 2636 RemoveFromPhysicalScene();
2287
2288 Animator.TrySetMovementAnimation(sitAnimation); 2637 Animator.TrySetMovementAnimation(sitAnimation);
2289 SendAvatarDataToAllAgents(); 2638 SendAvatarDataToAllAgents();
2290 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2291 // So we're also sending a terse update (which has avatar rotation)
2292 // [Update] We do now.
2293 //SendTerseUpdateToAllClients(); 2639 //SendTerseUpdateToAllClients();
2294 } 2640 }
2641
2642 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2643 {
2644 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2645 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2646 if(hitYN)
2647 {
2648 // m_pos = Av offset from prim center to make look like on center
2649 // m_parentPosition = Actual center pos of prim
2650 // collisionPoint = spot on prim where we want to sit
2651 // collisionPoint.Z = global sit surface height
2652 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2653 Quaternion partIRot;
2654// if (part.LinkNum == 1)
2655/// { // Root prim of linkset
2656// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2657// }
2658// else
2659// { // single or child prim
2660 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2661// }
2662 if (m_initialSitTarget != null)
2663 {
2664 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2665 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2666 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2667 m_pos += offset;
2668 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2669 }
2670
2671 }
2672 } // End SitAltitudeCallback KF.
2295 2673
2296 /// <summary> 2674 /// <summary>
2297 /// Event handler for the 'Always run' setting on the client 2675 /// Event handler for the 'Always run' setting on the client
@@ -2299,11 +2677,7 @@ namespace OpenSim.Region.Framework.Scenes
2299 /// </summary> 2677 /// </summary>
2300 public void HandleSetAlwaysRun(IClientAPI remoteClient, bool pSetAlwaysRun) 2678 public void HandleSetAlwaysRun(IClientAPI remoteClient, bool pSetAlwaysRun)
2301 { 2679 {
2302 m_setAlwaysRun = pSetAlwaysRun; 2680 SetAlwaysRun = pSetAlwaysRun;
2303 if (PhysicsActor != null)
2304 {
2305 PhysicsActor.SetAlwaysRun = pSetAlwaysRun;
2306 }
2307 } 2681 }
2308 2682
2309 public void HandleStartAnim(IClientAPI remoteClient, UUID animID) 2683 public void HandleStartAnim(IClientAPI remoteClient, UUID animID)
@@ -2325,27 +2699,25 @@ namespace OpenSim.Region.Framework.Scenes
2325 Vector3 direc = vec * Rotation; 2699 Vector3 direc = vec * Rotation;
2326 direc.Normalize(); 2700 direc.Normalize();
2327 2701
2328 direc *= 0.03f * 128f * m_speedModifier; 2702 direc *= 0.03f * 128f * SpeedModifier;
2329 2703
2330 PhysicsActor actor = m_physicsActor; 2704 if (PhysicsActor != null)
2331 if (actor != null)
2332 { 2705 {
2333 if (actor.Flying) 2706 if (PhysicsActor.Flying)
2334 { 2707 {
2335 direc *= 4.0f; 2708 direc *= 4.0f;
2336 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2709 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2337 //bool colliding = (m_physicsActor.IsColliding==true);
2338 //if (controlland) 2710 //if (controlland)
2339 // m_log.Info("[AGENT]: landCommand"); 2711 // m_log.Info("[AGENT]: landCommand");
2340 //if (colliding) 2712 //if (PhysicsActor.IsColliding)
2341 // m_log.Info("[AGENT]: colliding"); 2713 // m_log.Info("[AGENT]: colliding");
2342 //if (m_physicsActor.Flying && colliding && controlland) 2714 //if (PhysicsActor.Flying && PhysicsActor.IsColliding && controlland)
2343 //{ 2715 //{
2344 // StopFlying(); 2716 // StopFlying();
2345 // m_log.Info("[AGENT]: Stop FLying"); 2717 // m_log.Info("[AGENT]: Stop Flying");
2346 //} 2718 //}
2347 } 2719 }
2348 else if (!actor.Flying && actor.IsColliding) 2720 else if (!PhysicsActor.Flying && PhysicsActor.IsColliding)
2349 { 2721 {
2350 if (direc.Z > 2.0f) 2722 if (direc.Z > 2.0f)
2351 { 2723 {
@@ -2378,16 +2750,14 @@ namespace OpenSim.Region.Framework.Scenes
2378 if (!sendingPrims) 2750 if (!sendingPrims)
2379 Util.FireAndForget(delegate { sendingPrims = true; SendPrimUpdates(); sendingPrims = false; }); 2751 Util.FireAndForget(delegate { sendingPrims = true; SendPrimUpdates(); sendingPrims = false; });
2380 2752
2381 if (m_isChildAgent == false) 2753 if (IsChildAgent == false)
2382 { 2754 {
2383// PhysicsActor actor = m_physicsActor;
2384
2385 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2755 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2386 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2756 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2387 // storing a requested force instead of an actual traveling velocity 2757 // storing a requested force instead of an actual traveling velocity
2388 2758
2389 // Throw away duplicate or insignificant updates 2759 // Throw away duplicate or insignificant updates
2390 if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || 2760 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2391 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 2761 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2392 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) 2762 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2393 //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2763 //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
@@ -2396,17 +2766,20 @@ namespace OpenSim.Region.Framework.Scenes
2396 2766
2397 // Update the "last" values 2767 // Update the "last" values
2398 m_lastPosition = m_pos; 2768 m_lastPosition = m_pos;
2399 m_lastRotation = m_bodyRot; 2769 m_lastRotation = Rotation;
2400 m_lastVelocity = Velocity; 2770 m_lastVelocity = Velocity;
2401 //m_lastTerseSent = Environment.TickCount; 2771 //m_lastTerseSent = Environment.TickCount;
2402 } 2772 }
2403 2773
2404 // followed suggestion from mic bowman. reversed the two lines below. 2774 // followed suggestion from mic bowman. reversed the two lines below.
2405 if (m_parentID == 0 && m_physicsActor != null || m_parentID != 0) // Check that we have a physics actor or we're sitting on something 2775 if (ParentID == 0 && PhysicsActor != null || ParentID != 0) // Check that we have a physics actor or we're sitting on something
2406 CheckForBorderCrossing(); 2776 CheckForBorderCrossing();
2407 2777
2408 CheckForSignificantMovement(); // sends update to the modules. 2778 CheckForSignificantMovement(); // sends update to the modules.
2409 } 2779 }
2780
2781 //Sending prim updates AFTER the avatar terse updates are sent
2782 SendPrimUpdates();
2410 } 2783 }
2411 2784
2412 #endregion 2785 #endregion
@@ -2425,9 +2798,9 @@ namespace OpenSim.Region.Framework.Scenes
2425 if (remoteClient.IsActive) 2798 if (remoteClient.IsActive)
2426 { 2799 {
2427 Vector3 pos = m_pos; 2800 Vector3 pos = m_pos;
2428 pos.Z += m_appearance.HipOffset; 2801 pos.Z += Appearance.HipOffset;
2429 2802
2430 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity); 2803 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity);
2431 2804
2432 remoteClient.SendPrimUpdate( 2805 remoteClient.SendPrimUpdate(
2433 this, 2806 this,
@@ -2499,7 +2872,7 @@ namespace OpenSim.Region.Framework.Scenes
2499 2872
2500 public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List<Vector3> coarseLocations, List<UUID> avatarUUIDs) 2873 public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
2501 { 2874 {
2502 m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations); 2875 ControllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations);
2503 } 2876 }
2504 2877
2505 /// <summary> 2878 /// <summary>
@@ -2509,21 +2882,21 @@ namespace OpenSim.Region.Framework.Scenes
2509 private void SendInitialData() 2882 private void SendInitialData()
2510 { 2883 {
2511 //m_log.DebugFormat("[SCENE PRESENCE] SendInitialData: {0} ({1})", Name, UUID); 2884 //m_log.DebugFormat("[SCENE PRESENCE] SendInitialData: {0} ({1})", Name, UUID);
2512 // Moved this into CompleteMovement to ensure that m_appearance is initialized before 2885 // Moved this into CompleteMovement to ensure that Appearance is initialized before
2513 // the inventory arrives 2886 // the inventory arrives
2514 // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); 2887 // m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
2515 2888
2516 bool cachedappearance = false; 2889 bool cachedappearance = false;
2517 2890
2518 // We have an appearance but we may not have the baked textures. Check the asset cache 2891 // We have an appearance but we may not have the baked textures. Check the asset cache
2519 // to see if all the baked textures are already here. 2892 // to see if all the baked textures are already here.
2520 if (m_scene.AvatarFactory != null) 2893 if (m_scene.AvatarFactory != null)
2521 cachedappearance = m_scene.AvatarFactory.ValidateBakedTextureCache(m_controllingClient); 2894 cachedappearance = m_scene.AvatarFactory.ValidateBakedTextureCache(ControllingClient);
2522 2895
2523 // If we aren't using a cached appearance, then clear out the baked textures 2896 // If we aren't using a cached appearance, then clear out the baked textures
2524 if (!cachedappearance) 2897 if (!cachedappearance)
2525 { 2898 {
2526 m_appearance.ResetAppearance(); 2899 Appearance.ResetAppearance();
2527 if (m_scene.AvatarFactory != null) 2900 if (m_scene.AvatarFactory != null)
2528 m_scene.AvatarFactory.QueueAppearanceSave(UUID); 2901 m_scene.AvatarFactory.QueueAppearanceSave(UUID);
2529 } 2902 }
@@ -2671,17 +3044,7 @@ namespace OpenSim.Region.Framework.Scenes
2671// "[SCENE PRESENCE] Send appearance from {0} {1} to {2} {3}", Name, m_uuid, avatar.Name, avatar.UUID); 3044// "[SCENE PRESENCE] Send appearance from {0} {1} to {2} {3}", Name, m_uuid, avatar.Name, avatar.UUID);
2672 3045
2673 avatar.ControllingClient.SendAppearance( 3046 avatar.ControllingClient.SendAppearance(
2674 UUID, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); 3047 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
2675 }
2676
2677 public AvatarAppearance Appearance
2678 {
2679 get { return m_appearance; }
2680 set
2681 {
2682 m_appearance = value;
2683// m_log.DebugFormat("[SCENE PRESENCE]: Set appearance for {0} to {1}", Name, value);
2684 }
2685 } 3048 }
2686 3049
2687 #endregion 3050 #endregion
@@ -2709,14 +3072,13 @@ namespace OpenSim.Region.Framework.Scenes
2709 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); 3072 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
2710 cadu.ActiveGroupID = UUID.Zero.Guid; 3073 cadu.ActiveGroupID = UUID.Zero.Guid;
2711 cadu.AgentID = UUID.Guid; 3074 cadu.AgentID = UUID.Guid;
2712 cadu.alwaysrun = m_setAlwaysRun; 3075 cadu.alwaysrun = SetAlwaysRun;
2713 cadu.AVHeight = m_appearance.AvatarHeight; 3076 cadu.AVHeight = Appearance.AvatarHeight;
2714 Vector3 tempCameraCenter = m_CameraCenter; 3077 cadu.cameraPosition = CameraPosition;
2715 cadu.cameraPosition = tempCameraCenter; 3078 cadu.drawdistance = DrawDistance;
2716 cadu.drawdistance = m_DrawDistance;
2717 cadu.GroupAccess = 0; 3079 cadu.GroupAccess = 0;
2718 cadu.Position = AbsolutePosition; 3080 cadu.Position = AbsolutePosition;
2719 cadu.regionHandle = m_rootRegionHandle; 3081 cadu.regionHandle = RegionHandle;
2720 3082
2721 // Throttles 3083 // Throttles
2722 float multiplier = 1; 3084 float multiplier = 1;
@@ -2822,7 +3184,7 @@ namespace OpenSim.Region.Framework.Scenes
2822 { 3184 {
2823 if (m_requestedSitTargetUUID == UUID.Zero) 3185 if (m_requestedSitTargetUUID == UUID.Zero)
2824 { 3186 {
2825 bool isFlying = m_physicsActor.Flying; 3187 bool isFlying = PhysicsActor.Flying;
2826 RemoveFromPhysicalScene(); 3188 RemoveFromPhysicalScene();
2827 3189
2828 Vector3 pos = AbsolutePosition; 3190 Vector3 pos = AbsolutePosition;
@@ -2847,7 +3209,7 @@ namespace OpenSim.Region.Framework.Scenes
2847 { 3209 {
2848 if (m_requestedSitTargetUUID == UUID.Zero) 3210 if (m_requestedSitTargetUUID == UUID.Zero)
2849 { 3211 {
2850 bool isFlying = m_physicsActor.Flying; 3212 bool isFlying = PhysicsActor.Flying;
2851 RemoveFromPhysicalScene(); 3213 RemoveFromPhysicalScene();
2852 3214
2853 Vector3 pos = AbsolutePosition; 3215 Vector3 pos = AbsolutePosition;
@@ -2937,7 +3299,7 @@ namespace OpenSim.Region.Framework.Scenes
2937 { 3299 {
2938 try 3300 try
2939 { 3301 {
2940 return m_scene.CrossAgentToNewRegion(this, m_physicsActor.Flying); 3302 return m_scene.CrossAgentToNewRegion(this, PhysicsActor.Flying);
2941 } 3303 }
2942 catch 3304 catch
2943 { 3305 {
@@ -2945,19 +3307,9 @@ namespace OpenSim.Region.Framework.Scenes
2945 } 3307 }
2946 } 3308 }
2947 3309
2948 public void InTransit()
2949 {
2950 m_inTransit = true;
2951
2952 if ((m_physicsActor != null) && m_physicsActor.Flying)
2953 m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY;
2954 else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
2955 m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY;
2956 }
2957
2958 public void NotInTransit() 3310 public void NotInTransit()
2959 { 3311 {
2960 m_inTransit = false; 3312 IsInTransit = false;
2961 } 3313 }
2962 3314
2963 public void RestoreInCurrentScene() 3315 public void RestoreInCurrentScene()
@@ -3013,7 +3365,7 @@ namespace OpenSim.Region.Framework.Scenes
3013 if (byebyeRegions.Count > 0) 3365 if (byebyeRegions.Count > 0)
3014 { 3366 {
3015 m_log.Debug("[SCENE PRESENCE]: Closing " + byebyeRegions.Count + " child agents"); 3367 m_log.Debug("[SCENE PRESENCE]: Closing " + byebyeRegions.Count + " child agents");
3016 m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions); 3368 m_scene.SceneGridService.SendCloseChildAgentConnections(ControllingClient.AgentId, byebyeRegions);
3017 } 3369 }
3018 3370
3019 foreach (ulong handle in byebyeRegions) 3371 foreach (ulong handle in byebyeRegions)
@@ -3039,17 +3391,17 @@ namespace OpenSim.Region.Framework.Scenes
3039 if (account != null) 3391 if (account != null)
3040 { 3392 {
3041 if (account.UserLevel > 0) 3393 if (account.UserLevel > 0)
3042 m_godLevel = account.UserLevel; 3394 GodLevel = account.UserLevel;
3043 else 3395 else
3044 m_godLevel = 200; 3396 GodLevel = 200;
3045 } 3397 }
3046 } 3398 }
3047 else 3399 else
3048 { 3400 {
3049 m_godLevel = 0; 3401 GodLevel = 0;
3050 } 3402 }
3051 3403
3052 ControllingClient.SendAdminResponse(token, (uint)m_godLevel); 3404 ControllingClient.SendAdminResponse(token, (uint)GodLevel);
3053 } 3405 }
3054 3406
3055 #region Child Agent Updates 3407 #region Child Agent Updates
@@ -3081,8 +3433,8 @@ namespace OpenSim.Region.Framework.Scenes
3081 // When we get to the point of re-computing neighbors everytime this 3433 // When we get to the point of re-computing neighbors everytime this
3082 // changes, then start using the agent's drawdistance rather than the 3434 // changes, then start using the agent's drawdistance rather than the
3083 // region's draw distance. 3435 // region's draw distance.
3084 // m_DrawDistance = cAgentData.Far; 3436 // DrawDistance = cAgentData.Far;
3085 m_DrawDistance = Scene.DefaultDrawDistance; 3437 DrawDistance = Scene.DefaultDrawDistance;
3086 3438
3087 if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!! 3439 if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!!
3088 m_pos = cAgentData.Position + offset; 3440 m_pos = cAgentData.Position + offset;
@@ -3093,7 +3445,7 @@ namespace OpenSim.Region.Framework.Scenes
3093 ReprioritizeUpdates(); 3445 ReprioritizeUpdates();
3094 } 3446 }
3095 3447
3096 m_CameraCenter = cAgentData.Center + offset; 3448 CameraPosition = cAgentData.Center + offset;
3097 3449
3098 //SetHeight(cAgentData.AVHeight); 3450 //SetHeight(cAgentData.AVHeight);
3099 3451
@@ -3101,7 +3453,7 @@ namespace OpenSim.Region.Framework.Scenes
3101 ControllingClient.SetChildAgentThrottle(cAgentData.Throttles); 3453 ControllingClient.SetChildAgentThrottle(cAgentData.Throttles);
3102 3454
3103 //cAgentData.AVHeight; 3455 //cAgentData.AVHeight;
3104 m_rootRegionHandle = cAgentData.RegionHandle; 3456 RegionHandle = cAgentData.RegionHandle;
3105 //m_velocity = cAgentData.Velocity; 3457 //m_velocity = cAgentData.Velocity;
3106 } 3458 }
3107 3459
@@ -3114,12 +3466,12 @@ namespace OpenSim.Region.Framework.Scenes
3114 3466
3115 cAgent.Position = AbsolutePosition; 3467 cAgent.Position = AbsolutePosition;
3116 cAgent.Velocity = m_velocity; 3468 cAgent.Velocity = m_velocity;
3117 cAgent.Center = m_CameraCenter; 3469 cAgent.Center = CameraPosition;
3118 cAgent.AtAxis = m_CameraAtAxis; 3470 cAgent.AtAxis = CameraAtAxis;
3119 cAgent.LeftAxis = m_CameraLeftAxis; 3471 cAgent.LeftAxis = CameraLeftAxis;
3120 cAgent.UpAxis = m_CameraUpAxis; 3472 cAgent.UpAxis = m_CameraUpAxis;
3121 3473
3122 cAgent.Far = m_DrawDistance; 3474 cAgent.Far = DrawDistance;
3123 3475
3124 // Throttles 3476 // Throttles
3125 float multiplier = 1; 3477 float multiplier = 1;
@@ -3134,17 +3486,17 @@ namespace OpenSim.Region.Framework.Scenes
3134 cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier); 3486 cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier);
3135 3487
3136 cAgent.HeadRotation = m_headrotation; 3488 cAgent.HeadRotation = m_headrotation;
3137 cAgent.BodyRotation = m_bodyRot; 3489 cAgent.BodyRotation = Rotation;
3138 cAgent.ControlFlags = (uint)m_AgentControlFlags; 3490 cAgent.ControlFlags = (uint)m_AgentControlFlags;
3139 3491
3140 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3492 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3141 cAgent.GodLevel = (byte)m_godLevel; 3493 cAgent.GodLevel = (byte)GodLevel;
3142 else 3494 else
3143 cAgent.GodLevel = (byte) 0; 3495 cAgent.GodLevel = (byte) 0;
3144 3496
3145 cAgent.AlwaysRun = m_setAlwaysRun; 3497 cAgent.AlwaysRun = SetAlwaysRun;
3146 3498
3147 cAgent.Appearance = new AvatarAppearance(m_appearance); 3499 cAgent.Appearance = new AvatarAppearance(Appearance);
3148 3500
3149 lock (scriptedcontrols) 3501 lock (scriptedcontrols)
3150 { 3502 {
@@ -3173,7 +3525,7 @@ namespace OpenSim.Region.Framework.Scenes
3173 cAgent.AttachmentObjects = new List<ISceneObject>(); 3525 cAgent.AttachmentObjects = new List<ISceneObject>();
3174 cAgent.AttachmentObjectStates = new List<string>(); 3526 cAgent.AttachmentObjectStates = new List<string>();
3175 // IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>(); 3527 // IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
3176 m_InTransitScriptStates.Clear(); 3528 InTransitScriptStates.Clear();
3177 3529
3178 foreach (SceneObjectGroup sog in m_attachments) 3530 foreach (SceneObjectGroup sog in m_attachments)
3179 { 3531 {
@@ -3186,7 +3538,7 @@ namespace OpenSim.Region.Framework.Scenes
3186 cAgent.AttachmentObjects.Add(clone); 3538 cAgent.AttachmentObjects.Add(clone);
3187 string state = sog.GetStateSnapshot(); 3539 string state = sog.GetStateSnapshot();
3188 cAgent.AttachmentObjectStates.Add(state); 3540 cAgent.AttachmentObjectStates.Add(state);
3189 m_InTransitScriptStates.Add(state); 3541 InTransitScriptStates.Add(state);
3190 // Let's remove the scripts of the original object here 3542 // Let's remove the scripts of the original object here
3191 sog.RemoveScriptInstances(true); 3543 sog.RemoveScriptInstances(true);
3192 } 3544 }
@@ -3201,33 +3553,34 @@ namespace OpenSim.Region.Framework.Scenes
3201 m_callbackURI = cAgent.CallbackURI; 3553 m_callbackURI = cAgent.CallbackURI;
3202 3554
3203 m_pos = cAgent.Position; 3555 m_pos = cAgent.Position;
3556
3204 m_velocity = cAgent.Velocity; 3557 m_velocity = cAgent.Velocity;
3205 m_CameraCenter = cAgent.Center; 3558 CameraPosition = cAgent.Center;
3206 m_CameraAtAxis = cAgent.AtAxis; 3559 CameraAtAxis = cAgent.AtAxis;
3207 m_CameraLeftAxis = cAgent.LeftAxis; 3560 CameraLeftAxis = cAgent.LeftAxis;
3208 m_CameraUpAxis = cAgent.UpAxis; 3561 m_CameraUpAxis = cAgent.UpAxis;
3209 3562
3210 // When we get to the point of re-computing neighbors everytime this 3563 // When we get to the point of re-computing neighbors everytime this
3211 // changes, then start using the agent's drawdistance rather than the 3564 // changes, then start using the agent's drawdistance rather than the
3212 // region's draw distance. 3565 // region's draw distance.
3213 // m_DrawDistance = cAgent.Far; 3566 // DrawDistance = cAgent.Far;
3214 m_DrawDistance = Scene.DefaultDrawDistance; 3567 DrawDistance = Scene.DefaultDrawDistance;
3215 3568
3216 if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0) 3569 if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0)
3217 ControllingClient.SetChildAgentThrottle(cAgent.Throttles); 3570 ControllingClient.SetChildAgentThrottle(cAgent.Throttles);
3218 3571
3219 m_headrotation = cAgent.HeadRotation; 3572 m_headrotation = cAgent.HeadRotation;
3220 m_bodyRot = cAgent.BodyRotation; 3573 Rotation = cAgent.BodyRotation;
3221 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; 3574 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags;
3222 3575
3223 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3576 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3224 m_godLevel = cAgent.GodLevel; 3577 GodLevel = cAgent.GodLevel;
3225 m_setAlwaysRun = cAgent.AlwaysRun; 3578 SetAlwaysRun = cAgent.AlwaysRun;
3226 3579
3227 m_appearance = new AvatarAppearance(cAgent.Appearance); 3580 Appearance = new AvatarAppearance(cAgent.Appearance);
3228 if (m_physicsActor != null) 3581 if (PhysicsActor != null)
3229 { 3582 {
3230 bool isFlying = m_physicsActor.Flying; 3583 bool isFlying = PhysicsActor.Flying;
3231 RemoveFromPhysicalScene(); 3584 RemoveFromPhysicalScene();
3232 AddToPhysicalScene(isFlying); 3585 AddToPhysicalScene(isFlying);
3233 } 3586 }
@@ -3293,7 +3646,7 @@ namespace OpenSim.Region.Framework.Scenes
3293 { 3646 {
3294 Vector3 force = m_forceToApply.Value; 3647 Vector3 force = m_forceToApply.Value;
3295 3648
3296 m_updateflag = true; 3649 Updated = true;
3297 3650
3298 Velocity = force; 3651 Velocity = force;
3299 3652
@@ -3310,30 +3663,30 @@ namespace OpenSim.Region.Framework.Scenes
3310// "[SCENE PRESENCE]: Adding physics actor for {0}, ifFlying = {1} in {2}", 3663// "[SCENE PRESENCE]: Adding physics actor for {0}, ifFlying = {1} in {2}",
3311// Name, isFlying, Scene.RegionInfo.RegionName); 3664// Name, isFlying, Scene.RegionInfo.RegionName);
3312 3665
3313 if (m_appearance.AvatarHeight == 0) 3666 if (Appearance.AvatarHeight == 0)
3314 m_appearance.SetHeight(); 3667 Appearance.SetHeight();
3315 3668
3316 PhysicsScene scene = m_scene.PhysicsScene; 3669 PhysicsScene scene = m_scene.PhysicsScene;
3317 3670
3318 Vector3 pVec = AbsolutePosition; 3671 Vector3 pVec = AbsolutePosition;
3319 3672
3320 // Old bug where the height was in centimeters instead of meters 3673 // Old bug where the height was in centimeters instead of meters
3321 m_physicsActor = scene.AddAvatar(LocalId, Firstname + "." + Lastname, pVec, 3674 PhysicsActor = scene.AddAvatar(LocalId, Firstname + "." + Lastname, pVec,
3322 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying); 3675 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying);
3323 3676
3324 scene.AddPhysicsActorTaint(m_physicsActor); 3677 scene.AddPhysicsActorTaint(PhysicsActor);
3325 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3678 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3326 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3679 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3327 m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3680 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3328 m_physicsActor.SubscribeEvents(500); 3681 PhysicsActor.SubscribeEvents(500);
3329 m_physicsActor.LocalID = LocalId; 3682 PhysicsActor.LocalID = LocalId;
3330 3683
3331 SetHeight(m_appearance.AvatarHeight); 3684 SetHeight(Appearance.AvatarHeight);
3332 } 3685 }
3333 3686
3334 private void OutOfBoundsCall(Vector3 pos) 3687 private void OutOfBoundsCall(Vector3 pos)
3335 { 3688 {
3336 //bool flying = m_physicsActor.Flying; 3689 //bool flying = PhysicsActor.Flying;
3337 //RemoveFromPhysicalScene(); 3690 //RemoveFromPhysicalScene();
3338 3691
3339 //AddToPhysicalScene(flying); 3692 //AddToPhysicalScene(flying);
@@ -3348,16 +3701,28 @@ namespace OpenSim.Region.Framework.Scenes
3348 return; 3701 return;
3349 3702
3350 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3703 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
3351 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents( 3704 // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents(
3352 // as of this comment the interval is set in AddToPhysicalScene 3705 // as of this comment the interval is set in AddToPhysicalScene
3353 if (Animator != null) 3706 if (Animator!=null)
3354 Animator.UpdateMovementAnimations(); 3707 {
3708 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3709 { // else its will lock out other animation changes, like ground sit.
3710 Animator.UpdateMovementAnimations();
3711 m_updateCount--;
3712 }
3713 }
3355 3714
3356 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3715 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3357 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3716 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3358 3717
3359 CollisionPlane = Vector4.UnitW; 3718 CollisionPlane = Vector4.UnitW;
3360 3719
3720 if (m_lastColCount != coldata.Count)
3721 {
3722 m_updateCount = UPDATE_COUNT;
3723 m_lastColCount = coldata.Count;
3724 }
3725
3361 if (coldata.Count != 0 && Animator != null) 3726 if (coldata.Count != 0 && Animator != null)
3362 { 3727 {
3363 switch (Animator.CurrentMovementAnimation) 3728 switch (Animator.CurrentMovementAnimation)
@@ -3387,7 +3752,149 @@ namespace OpenSim.Region.Framework.Scenes
3387 } 3752 }
3388 } 3753 }
3389 3754
3390 if (m_invulnerable) 3755 List<uint> thisHitColliders = new List<uint>();
3756 List<uint> endedColliders = new List<uint>();
3757 List<uint> startedColliders = new List<uint>();
3758
3759 foreach (uint localid in coldata.Keys)
3760 {
3761 thisHitColliders.Add(localid);
3762 if (!m_lastColliders.Contains(localid))
3763 {
3764 startedColliders.Add(localid);
3765 }
3766 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3767 }
3768
3769 // calculate things that ended colliding
3770 foreach (uint localID in m_lastColliders)
3771 {
3772 if (!thisHitColliders.Contains(localID))
3773 {
3774 endedColliders.Add(localID);
3775 }
3776 }
3777 //add the items that started colliding this time to the last colliders list.
3778 foreach (uint localID in startedColliders)
3779 {
3780 m_lastColliders.Add(localID);
3781 }
3782 // remove things that ended colliding from the last colliders list
3783 foreach (uint localID in endedColliders)
3784 {
3785 m_lastColliders.Remove(localID);
3786 }
3787
3788 // do event notification
3789 if (startedColliders.Count > 0)
3790 {
3791 ColliderArgs StartCollidingMessage = new ColliderArgs();
3792 List<DetectedObject> colliding = new List<DetectedObject>();
3793 foreach (uint localId in startedColliders)
3794 {
3795 if (localId == 0)
3796 continue;
3797
3798 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3799 string data = "";
3800 if (obj != null)
3801 {
3802 DetectedObject detobj = new DetectedObject();
3803 detobj.keyUUID = obj.UUID;
3804 detobj.nameStr = obj.Name;
3805 detobj.ownerUUID = obj.OwnerID;
3806 detobj.posVector = obj.AbsolutePosition;
3807 detobj.rotQuat = obj.GetWorldRotation();
3808 detobj.velVector = obj.Velocity;
3809 detobj.colliderType = 0;
3810 detobj.groupUUID = obj.GroupID;
3811 colliding.Add(detobj);
3812 }
3813 }
3814
3815 if (colliding.Count > 0)
3816 {
3817 StartCollidingMessage.Colliders = colliding;
3818
3819 foreach (SceneObjectGroup att in GetAttachments())
3820 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3821 }
3822 }
3823
3824 if (endedColliders.Count > 0)
3825 {
3826 ColliderArgs EndCollidingMessage = new ColliderArgs();
3827 List<DetectedObject> colliding = new List<DetectedObject>();
3828 foreach (uint localId in endedColliders)
3829 {
3830 if (localId == 0)
3831 continue;
3832
3833 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3834 string data = "";
3835 if (obj != null)
3836 {
3837 DetectedObject detobj = new DetectedObject();
3838 detobj.keyUUID = obj.UUID;
3839 detobj.nameStr = obj.Name;
3840 detobj.ownerUUID = obj.OwnerID;
3841 detobj.posVector = obj.AbsolutePosition;
3842 detobj.rotQuat = obj.GetWorldRotation();
3843 detobj.velVector = obj.Velocity;
3844 detobj.colliderType = 0;
3845 detobj.groupUUID = obj.GroupID;
3846 colliding.Add(detobj);
3847 }
3848 }
3849
3850 if (colliding.Count > 0)
3851 {
3852 EndCollidingMessage.Colliders = colliding;
3853
3854 foreach (SceneObjectGroup att in GetAttachments())
3855 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3856 }
3857 }
3858
3859 if (thisHitColliders.Count > 0)
3860 {
3861 ColliderArgs CollidingMessage = new ColliderArgs();
3862 List<DetectedObject> colliding = new List<DetectedObject>();
3863 foreach (uint localId in thisHitColliders)
3864 {
3865 if (localId == 0)
3866 continue;
3867
3868 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3869 string data = "";
3870 if (obj != null)
3871 {
3872 DetectedObject detobj = new DetectedObject();
3873 detobj.keyUUID = obj.UUID;
3874 detobj.nameStr = obj.Name;
3875 detobj.ownerUUID = obj.OwnerID;
3876 detobj.posVector = obj.AbsolutePosition;
3877 detobj.rotQuat = obj.GetWorldRotation();
3878 detobj.velVector = obj.Velocity;
3879 detobj.colliderType = 0;
3880 detobj.groupUUID = obj.GroupID;
3881 colliding.Add(detobj);
3882 }
3883 }
3884
3885 if (colliding.Count > 0)
3886 {
3887 CollidingMessage.Colliders = colliding;
3888
3889 lock (m_attachments)
3890 {
3891 foreach (SceneObjectGroup att in m_attachments)
3892 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3893 }
3894 }
3895 }
3896
3897 if (Invulnerable)
3391 return; 3898 return;
3392 3899
3393 float starthealth = Health; 3900 float starthealth = Health;
@@ -3412,13 +3919,13 @@ namespace OpenSim.Region.Framework.Scenes
3412 //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString()); 3919 //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString());
3413 } 3920 }
3414 //Health = 100; 3921 //Health = 100;
3415 if (!m_invulnerable) 3922 if (!Invulnerable)
3416 { 3923 {
3417 if (starthealth != Health) 3924 if (starthealth != Health)
3418 { 3925 {
3419 ControllingClient.SendHealth(Health); 3926 ControllingClient.SendHealth(Health);
3420 } 3927 }
3421 if (m_health <= 0) 3928 if (Health <= 0)
3422 m_scene.EventManager.TriggerAvatarKill(killerObj, this); 3929 m_scene.EventManager.TriggerAvatarKill(killerObj, this);
3423 } 3930 }
3424 } 3931 }
@@ -3449,17 +3956,21 @@ namespace OpenSim.Region.Framework.Scenes
3449 // unsetting the elapsed callback should be enough to allow for cleanup however. 3956 // unsetting the elapsed callback should be enough to allow for cleanup however.
3450 // m_reprioritizationTimer.Dispose(); 3957 // m_reprioritizationTimer.Dispose();
3451 3958
3452 m_sceneViewer.Close(); 3959 SceneViewer.Close();
3453 3960
3454 RemoveFromPhysicalScene(); 3961 RemoveFromPhysicalScene();
3455 m_animator.Close(); 3962 Animator.Close();
3456 m_animator = null; 3963 Animator = null;
3457 } 3964 }
3458 3965
3459 public void AddAttachment(SceneObjectGroup gobj) 3966 public void AddAttachment(SceneObjectGroup gobj)
3460 { 3967 {
3461 lock (m_attachments) 3968 lock (m_attachments)
3462 { 3969 {
3970 // This may be true when the attachment comes back
3971 // from serialization after login. Clear it.
3972 gobj.IsDeleted = false;
3973
3463 m_attachments.Add(gobj); 3974 m_attachments.Add(gobj);
3464 } 3975 }
3465 } 3976 }
@@ -3815,7 +4326,7 @@ namespace OpenSim.Region.Framework.Scenes
3815 4326
3816 private void Reprioritize(object sender, ElapsedEventArgs e) 4327 private void Reprioritize(object sender, ElapsedEventArgs e)
3817 { 4328 {
3818 m_controllingClient.ReprioritizeUpdates(); 4329 ControllingClient.ReprioritizeUpdates();
3819 4330
3820 lock (m_reprioritization_timer) 4331 lock (m_reprioritization_timer)
3821 { 4332 {
@@ -3823,5 +4334,39 @@ namespace OpenSim.Region.Framework.Scenes
3823 m_reprioritization_called = false; 4334 m_reprioritization_called = false;
3824 } 4335 }
3825 } 4336 }
4337
4338 private Vector3 Quat2Euler(Quaternion rot){
4339 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4340 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4341 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4342 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4343 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4344 return(new Vector3(x,y,z));
4345 }
4346
4347 private void CheckLandingPoint(ref Vector3 pos)
4348 {
4349 // Never constrain lures
4350 if ((TeleportFlags & TeleportFlags.ViaLure) != 0)
4351 return;
4352
4353 if (m_scene.RegionInfo.EstateSettings.AllowDirectTeleport)
4354 return;
4355
4356 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
4357
4358 if (land.LandData.LandingType == (byte)LandingType.LandingPoint &&
4359 land.LandData.UserLocation != Vector3.Zero &&
4360 land.LandData.OwnerID != m_uuid &&
4361 (!m_scene.Permissions.IsGod(m_uuid)) &&
4362 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)))
4363 {
4364 float curr = Vector3.Distance(AbsolutePosition, pos);
4365 if (Vector3.Distance(land.LandData.UserLocation, pos) < curr)
4366 pos = land.LandData.UserLocation;
4367 else
4368 ControllingClient.SendAlertMessage("Can't teleport closer to destination");
4369 }
4370 }
3826 } 4371 }
3827} 4372}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index 50e1e39..8a0d288 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -126,7 +126,7 @@ namespace OpenSim.Region.Framework.Scenes
126 g.ScheduleFullUpdateToAvatar(m_presence); 126 g.ScheduleFullUpdateToAvatar(m_presence);
127 } 127 }
128 128
129 while (m_partsUpdateQueue.Count > 0) 129 while (m_partsUpdateQueue != null && m_partsUpdateQueue.Count != null && m_partsUpdateQueue.Count > 0)
130 { 130 {
131 SceneObjectPart part = m_partsUpdateQueue.Dequeue(); 131 SceneObjectPart part = m_partsUpdateQueue.Dequeue();
132 132
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
index e06a222..11dad6c 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -346,6 +346,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
346 m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2); 346 m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
347 m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3); 347 m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
348 m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4); 348 m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
349
350 m_SOPXmlProcessors.Add("Buoyancy", ProcessBuoyancy);
349 #endregion 351 #endregion
350 352
351 #region TaskInventoryXmlProcessors initialization 353 #region TaskInventoryXmlProcessors initialization
@@ -735,6 +737,11 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
735 obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty); 737 obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
736 } 738 }
737 739
740 private static void ProcessBuoyancy(SceneObjectPart obj, XmlTextReader reader)
741 {
742 obj.Buoyancy = (int)reader.ReadElementContentAsFloat("Buoyancy", String.Empty);
743 }
744
738 #endregion 745 #endregion
739 746
740 #region TaskInventoryXmlProcessors 747 #region TaskInventoryXmlProcessors
@@ -1219,6 +1226,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1219 writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString()); 1226 writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
1220 writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString()); 1227 writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
1221 1228
1229 writer.WriteElementString("Buoyancy", sop.Buoyancy.ToString());
1230
1222 writer.WriteEndElement(); 1231 writer.WriteEndElement();
1223 } 1232 }
1224 1233
@@ -1503,12 +1512,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1503 { 1512 {
1504 TaskInventoryDictionary tinv = new TaskInventoryDictionary(); 1513 TaskInventoryDictionary tinv = new TaskInventoryDictionary();
1505 1514
1506 if (reader.IsEmptyElement)
1507 {
1508 reader.Read();
1509 return tinv;
1510 }
1511
1512 reader.ReadStartElement(name, String.Empty); 1515 reader.ReadStartElement(name, String.Empty);
1513 1516
1514 while (reader.Name == "TaskInventoryItem") 1517 while (reader.Name == "TaskInventoryItem")
@@ -1551,12 +1554,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1551 1554
1552 PrimitiveBaseShape shape = new PrimitiveBaseShape(); 1555 PrimitiveBaseShape shape = new PrimitiveBaseShape();
1553 1556
1554 if (reader.IsEmptyElement)
1555 {
1556 reader.Read();
1557 return shape;
1558 }
1559
1560 reader.ReadStartElement(name, String.Empty); // Shape 1557 reader.ReadStartElement(name, String.Empty); // Shape
1561 1558
1562 string nodeName = string.Empty; 1559 string nodeName = string.Empty;
@@ -1596,4 +1593,4 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1596 1593
1597 #endregion 1594 #endregion
1598 } 1595 }
1599} 1596} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/UndoState.cs b/OpenSim/Region/Framework/Scenes/UndoState.cs
index d34d8e5..0a30f4b 100644
--- a/OpenSim/Region/Framework/Scenes/UndoState.cs
+++ b/OpenSim/Region/Framework/Scenes/UndoState.cs
@@ -30,12 +30,27 @@ using System.Reflection;
30using log4net; 30using log4net;
31using OpenMetaverse; 31using OpenMetaverse;
32using OpenSim.Region.Framework.Interfaces; 32using OpenSim.Region.Framework.Interfaces;
33using System;
33 34
34namespace OpenSim.Region.Framework.Scenes 35namespace OpenSim.Region.Framework.Scenes
35{ 36{
37 [Flags]
38 public enum UndoType
39 {
40 STATE_PRIM_POSITION = 1,
41 STATE_PRIM_ROTATION = 2,
42 STATE_PRIM_SCALE = 4,
43 STATE_PRIM_ALL = 7,
44 STATE_GROUP_POSITION = 8,
45 STATE_GROUP_ROTATION = 16,
46 STATE_GROUP_SCALE = 32,
47 STATE_GROUP_ALL = 56,
48 STATE_ALL = 63
49 }
50
36 public class UndoState 51 public class UndoState
37 { 52 {
38// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 53 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39 54
40 public Vector3 Position = Vector3.Zero; 55 public Vector3 Position = Vector3.Zero;
41 public Vector3 Scale = Vector3.Zero; 56 public Vector3 Scale = Vector3.Zero;
@@ -57,37 +72,37 @@ namespace OpenSim.Region.Framework.Scenes
57 { 72 {
58 ForGroup = forGroup; 73 ForGroup = forGroup;
59 74
60// if (ForGroup) 75 // if (ForGroup)
61 Position = part.ParentGroup.AbsolutePosition; 76 Position = part.ParentGroup.AbsolutePosition;
62// else 77 // else
63// Position = part.OffsetPosition; 78 // Position = part.OffsetPosition;
64 79
65// m_log.DebugFormat( 80 // m_log.DebugFormat(
66// "[UNDO STATE]: Storing undo position {0} for root part", Position); 81 // "[UNDO STATE]: Storing undo position {0} for root part", Position);
67 82
68 Rotation = part.RotationOffset; 83 Rotation = part.RotationOffset;
69 84
70// m_log.DebugFormat( 85 // m_log.DebugFormat(
71// "[UNDO STATE]: Storing undo rotation {0} for root part", Rotation); 86 // "[UNDO STATE]: Storing undo rotation {0} for root part", Rotation);
72 87
73 Scale = part.Shape.Scale; 88 Scale = part.Shape.Scale;
74 89
75// m_log.DebugFormat( 90 // m_log.DebugFormat(
76// "[UNDO STATE]: Storing undo scale {0} for root part", Scale); 91 // "[UNDO STATE]: Storing undo scale {0} for root part", Scale);
77 } 92 }
78 else 93 else
79 { 94 {
80 Position = part.OffsetPosition; 95 Position = part.OffsetPosition;
81// m_log.DebugFormat( 96 // m_log.DebugFormat(
82// "[UNDO STATE]: Storing undo position {0} for child part", Position); 97 // "[UNDO STATE]: Storing undo position {0} for child part", Position);
83 98
84 Rotation = part.RotationOffset; 99 Rotation = part.RotationOffset;
85// m_log.DebugFormat( 100 // m_log.DebugFormat(
86// "[UNDO STATE]: Storing undo rotation {0} for child part", Rotation); 101 // "[UNDO STATE]: Storing undo rotation {0} for child part", Rotation);
87 102
88 Scale = part.Shape.Scale; 103 Scale = part.Shape.Scale;
89// m_log.DebugFormat( 104 // m_log.DebugFormat(
90// "[UNDO STATE]: Storing undo scale {0} for child part", Scale); 105 // "[UNDO STATE]: Storing undo scale {0} for child part", Scale);
91 } 106 }
92 } 107 }
93 108
@@ -121,9 +136,9 @@ namespace OpenSim.Region.Framework.Scenes
121 136
122 if (part.ParentID == 0) 137 if (part.ParentID == 0)
123 { 138 {
124// m_log.DebugFormat( 139 // m_log.DebugFormat(
125// "[UNDO STATE]: Undoing position to {0} for root part {1} {2}", 140 // "[UNDO STATE]: Undoing position to {0} for root part {1} {2}",
126// Position, part.Name, part.LocalId); 141 // Position, part.Name, part.LocalId);
127 142
128 if (Position != Vector3.Zero) 143 if (Position != Vector3.Zero)
129 { 144 {
@@ -133,9 +148,9 @@ namespace OpenSim.Region.Framework.Scenes
133 part.ParentGroup.UpdateRootPosition(Position); 148 part.ParentGroup.UpdateRootPosition(Position);
134 } 149 }
135 150
136// m_log.DebugFormat( 151 // m_log.DebugFormat(
137// "[UNDO STATE]: Undoing rotation {0} to {1} for root part {2} {3}", 152 // "[UNDO STATE]: Undoing rotation {0} to {1} for root part {2} {3}",
138// part.RotationOffset, Rotation, part.Name, part.LocalId); 153 // part.RotationOffset, Rotation, part.Name, part.LocalId);
139 154
140 if (ForGroup) 155 if (ForGroup)
141 part.UpdateRotation(Rotation); 156 part.UpdateRotation(Rotation);
@@ -144,9 +159,9 @@ namespace OpenSim.Region.Framework.Scenes
144 159
145 if (Scale != Vector3.Zero) 160 if (Scale != Vector3.Zero)
146 { 161 {
147// m_log.DebugFormat( 162 // m_log.DebugFormat(
148// "[UNDO STATE]: Undoing scale {0} to {1} for root part {2} {3}", 163 // "[UNDO STATE]: Undoing scale {0} to {1} for root part {2} {3}",
149// part.Shape.Scale, Scale, part.Name, part.LocalId); 164 // part.Shape.Scale, Scale, part.Name, part.LocalId);
150 165
151 if (ForGroup) 166 if (ForGroup)
152 part.ParentGroup.GroupResize(Scale); 167 part.ParentGroup.GroupResize(Scale);
@@ -160,24 +175,24 @@ namespace OpenSim.Region.Framework.Scenes
160 { 175 {
161 if (Position != Vector3.Zero) 176 if (Position != Vector3.Zero)
162 { 177 {
163// m_log.DebugFormat( 178 // m_log.DebugFormat(
164// "[UNDO STATE]: Undoing position {0} to {1} for child part {2} {3}", 179 // "[UNDO STATE]: Undoing position {0} to {1} for child part {2} {3}",
165// part.OffsetPosition, Position, part.Name, part.LocalId); 180 // part.OffsetPosition, Position, part.Name, part.LocalId);
166 181
167 part.OffsetPosition = Position; 182 part.OffsetPosition = Position;
168 } 183 }
169 184
170// m_log.DebugFormat( 185 // m_log.DebugFormat(
171// "[UNDO STATE]: Undoing rotation {0} to {1} for child part {2} {3}", 186 // "[UNDO STATE]: Undoing rotation {0} to {1} for child part {2} {3}",
172// part.RotationOffset, Rotation, part.Name, part.LocalId); 187 // part.RotationOffset, Rotation, part.Name, part.LocalId);
173 188
174 part.UpdateRotation(Rotation); 189 part.UpdateRotation(Rotation);
175 190
176 if (Scale != Vector3.Zero) 191 if (Scale != Vector3.Zero)
177 { 192 {
178// m_log.DebugFormat( 193 // m_log.DebugFormat(
179// "[UNDO STATE]: Undoing scale {0} to {1} for child part {2} {3}", 194 // "[UNDO STATE]: Undoing scale {0} to {1} for child part {2} {3}",
180// part.Shape.Scale, Scale, part.Name, part.LocalId); 195 // part.Shape.Scale, Scale, part.Name, part.LocalId);
181 196
182 part.Resize(Scale); 197 part.Resize(Scale);
183 } 198 }
@@ -249,4 +264,4 @@ namespace OpenSim.Region.Framework.Scenes
249 m_terrainModule.UndoTerrain(m_terrainChannel); 264 m_terrainModule.UndoTerrain(m_terrainChannel);
250 } 265 }
251 } 266 }
252} \ No newline at end of file 267}
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
index 3acdaf8..8d41f00 100644
--- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
+++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
@@ -87,10 +87,6 @@ namespace OpenSim.Region.Framework.Scenes
87 /// <param name="assetUuids">The assets gathered</param> 87 /// <param name="assetUuids">The assets gathered</param>
88 public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary<UUID, AssetType> assetUuids) 88 public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary<UUID, AssetType> assetUuids)
89 { 89 {
90 // avoid infinite loops
91 if (assetUuids.ContainsKey(assetUuid))
92 return;
93
94 try 90 try
95 { 91 {
96 assetUuids[assetUuid] = assetType; 92 assetUuids[assetUuid] = assetType;