aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Scene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs502
1 files changed, 417 insertions, 85 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 1e111e5..5d4ddea 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -95,6 +95,7 @@ namespace OpenSim.Region.Framework.Scenes
95 // TODO: need to figure out how allow client agents but deny 95 // TODO: need to figure out how allow client agents but deny
96 // root agents when ACL denies access to root agent 96 // root agents when ACL denies access to root agent
97 public bool m_strictAccessControl = true; 97 public bool m_strictAccessControl = true;
98 public bool m_seeIntoBannedRegion = false;
98 public int MaxUndoCount = 5; 99 public int MaxUndoCount = 5;
99 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 100 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
100 public bool LoginLock = false; 101 public bool LoginLock = false;
@@ -110,12 +111,14 @@ namespace OpenSim.Region.Framework.Scenes
110 111
111 protected int m_splitRegionID; 112 protected int m_splitRegionID;
112 protected Timer m_restartWaitTimer = new Timer(); 113 protected Timer m_restartWaitTimer = new Timer();
114 protected Timer m_timerWatchdog = new Timer();
113 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 115 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
114 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 116 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
115 protected string m_simulatorVersion = "OpenSimulator Server"; 117 protected string m_simulatorVersion = "OpenSimulator Server";
116 protected ModuleLoader m_moduleLoader; 118 protected ModuleLoader m_moduleLoader;
117 protected AgentCircuitManager m_authenticateHandler; 119 protected AgentCircuitManager m_authenticateHandler;
118 protected SceneCommunicationService m_sceneGridService; 120 protected SceneCommunicationService m_sceneGridService;
121 protected ISnmpModule m_snmpService = null;
119 122
120 protected ISimulationDataService m_SimulationDataService; 123 protected ISimulationDataService m_SimulationDataService;
121 protected IEstateDataService m_EstateDataService; 124 protected IEstateDataService m_EstateDataService;
@@ -167,7 +170,7 @@ namespace OpenSim.Region.Framework.Scenes
167 private int m_update_events = 1; 170 private int m_update_events = 1;
168 private int m_update_backup = 200; 171 private int m_update_backup = 200;
169 private int m_update_terrain = 50; 172 private int m_update_terrain = 50;
170// private int m_update_land = 1; 173 private int m_update_land = 10;
171 private int m_update_coarse_locations = 50; 174 private int m_update_coarse_locations = 50;
172 175
173 private int agentMS; 176 private int agentMS;
@@ -182,6 +185,7 @@ namespace OpenSim.Region.Framework.Scenes
182 private int landMS; 185 private int landMS;
183 private int lastCompletedFrame; 186 private int lastCompletedFrame;
184 187
188 public bool CombineRegions = false;
185 /// <summary> 189 /// <summary>
186 /// Signals whether temporary objects are currently being cleaned up. Needed because this is launched 190 /// Signals whether temporary objects are currently being cleaned up. Needed because this is launched
187 /// asynchronously from the update loop. 191 /// asynchronously from the update loop.
@@ -204,10 +208,12 @@ namespace OpenSim.Region.Framework.Scenes
204 private bool m_scripts_enabled = true; 208 private bool m_scripts_enabled = true;
205 private string m_defaultScriptEngine; 209 private string m_defaultScriptEngine;
206 private int m_LastLogin; 210 private int m_LastLogin;
207 private Thread HeartbeatThread; 211 private Thread HeartbeatThread = null;
208 private volatile bool shuttingdown; 212 private volatile bool shuttingdown;
209 213
210 private int m_lastUpdate; 214 private int m_lastUpdate;
215 private int m_lastIncoming;
216 private int m_lastOutgoing;
211 private bool m_firstHeartbeat = true; 217 private bool m_firstHeartbeat = true;
212 218
213 private object m_deleting_scene_object = new object(); 219 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
@@ -536,6 +555,9 @@ namespace OpenSim.Region.Framework.Scenes
536 m_EstateDataService = estateDataService; 555 m_EstateDataService = estateDataService;
537 m_regionHandle = m_regInfo.RegionHandle; 556 m_regionHandle = m_regInfo.RegionHandle;
538 m_regionName = m_regInfo.RegionName; 557 m_regionName = m_regInfo.RegionName;
558 m_lastUpdate = Util.EnvironmentTickCount();
559 m_lastIncoming = 0;
560 m_lastOutgoing = 0;
539 561
540 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 562 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
541 m_asyncSceneObjectDeleter.Enabled = true; 563 m_asyncSceneObjectDeleter.Enabled = true;
@@ -652,6 +674,8 @@ namespace OpenSim.Region.Framework.Scenes
652 m_physicalPrim = startupConfig.GetBoolean("physical_prim", true); 674 m_physicalPrim = startupConfig.GetBoolean("physical_prim", true);
653 675
654 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 676 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
677
678 m_log.DebugFormat("[SCENE]: prejump is {0}", m_usePreJump ? "ON" : "OFF");
655 if (RegionInfo.NonphysPrimMax > 0) 679 if (RegionInfo.NonphysPrimMax > 0)
656 { 680 {
657 m_maxNonphys = RegionInfo.NonphysPrimMax; 681 m_maxNonphys = RegionInfo.NonphysPrimMax;
@@ -683,6 +707,7 @@ namespace OpenSim.Region.Framework.Scenes
683 m_persistAfter *= 10000000; 707 m_persistAfter *= 10000000;
684 708
685 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 709 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
710 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
686 711
687 IConfig packetConfig = m_config.Configs["PacketPool"]; 712 IConfig packetConfig = m_config.Configs["PacketPool"];
688 if (packetConfig != null) 713 if (packetConfig != null)
@@ -692,6 +717,8 @@ namespace OpenSim.Region.Framework.Scenes
692 } 717 }
693 718
694 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 719 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
720 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
721 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
695 722
696 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 723 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
697 if (m_generateMaptiles) 724 if (m_generateMaptiles)
@@ -727,9 +754,9 @@ namespace OpenSim.Region.Framework.Scenes
727 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain); 754 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
728 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning); 755 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
729 } 756 }
730 catch 757 catch (Exception e)
731 { 758 {
732 m_log.Warn("[SCENE]: Failed to load StartupConfig"); 759 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
733 } 760 }
734 761
735 #endregion Region Config 762 #endregion Region Config
@@ -1140,7 +1167,9 @@ namespace OpenSim.Region.Framework.Scenes
1140 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1167 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1141 if (HeartbeatThread != null) 1168 if (HeartbeatThread != null)
1142 { 1169 {
1170 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1143 HeartbeatThread.Abort(); 1171 HeartbeatThread.Abort();
1172 Watchdog.AbortThread(HeartbeatThread.ManagedThreadId);
1144 HeartbeatThread = null; 1173 HeartbeatThread = null;
1145 } 1174 }
1146 m_lastUpdate = Util.EnvironmentTickCount(); 1175 m_lastUpdate = Util.EnvironmentTickCount();
@@ -1183,9 +1212,6 @@ namespace OpenSim.Region.Framework.Scenes
1183 { 1212 {
1184 while (!shuttingdown) 1213 while (!shuttingdown)
1185 Update(); 1214 Update();
1186
1187 m_lastUpdate = Util.EnvironmentTickCount();
1188 m_firstHeartbeat = false;
1189 } 1215 }
1190 catch (ThreadAbortException) 1216 catch (ThreadAbortException)
1191 { 1217 {
@@ -1283,6 +1309,13 @@ namespace OpenSim.Region.Framework.Scenes
1283 eventMS = Util.EnvironmentTickCountSubtract(evMS); ; 1309 eventMS = Util.EnvironmentTickCountSubtract(evMS); ;
1284 } 1310 }
1285 1311
1312 // if (Frame % m_update_land == 0)
1313 // {
1314 // int ldMS = Util.EnvironmentTickCount();
1315 // UpdateLand();
1316 // landMS = Util.EnvironmentTickCountSubtract(ldMS);
1317 // }
1318
1286 if (Frame % m_update_backup == 0) 1319 if (Frame % m_update_backup == 0)
1287 { 1320 {
1288 int backMS = Util.EnvironmentTickCount(); 1321 int backMS = Util.EnvironmentTickCount();
@@ -1384,12 +1417,16 @@ namespace OpenSim.Region.Framework.Scenes
1384 maintc = Util.EnvironmentTickCountSubtract(maintc); 1417 maintc = Util.EnvironmentTickCountSubtract(maintc);
1385 maintc = (int)(MinFrameTime * 1000) - maintc; 1418 maintc = (int)(MinFrameTime * 1000) - maintc;
1386 1419
1420
1421 m_lastUpdate = Util.EnvironmentTickCount();
1422 m_firstHeartbeat = false;
1423
1387 if (maintc > 0) 1424 if (maintc > 0)
1388 Thread.Sleep(maintc); 1425 Thread.Sleep(maintc);
1389 1426
1390 // Tell the watchdog that this thread is still alive 1427 // Tell the watchdog that this thread is still alive
1391 Watchdog.UpdateThread(); 1428 Watchdog.UpdateThread();
1392 } 1429 }
1393 1430
1394 public void AddGroupTarget(SceneObjectGroup grp) 1431 public void AddGroupTarget(SceneObjectGroup grp)
1395 { 1432 {
@@ -1405,9 +1442,9 @@ namespace OpenSim.Region.Framework.Scenes
1405 1442
1406 private void CheckAtTargets() 1443 private void CheckAtTargets()
1407 { 1444 {
1408 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1445 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1409 lock (m_groupsWithTargets) 1446 lock (m_groupsWithTargets)
1410 objs = m_groupsWithTargets.Values; 1447 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1411 1448
1412 foreach (SceneObjectGroup entry in objs) 1449 foreach (SceneObjectGroup entry in objs)
1413 entry.checkAtTargets(); 1450 entry.checkAtTargets();
@@ -1489,7 +1526,7 @@ namespace OpenSim.Region.Framework.Scenes
1489 msg.fromAgentName = "Server"; 1526 msg.fromAgentName = "Server";
1490 msg.dialog = (byte)19; // Object msg 1527 msg.dialog = (byte)19; // Object msg
1491 msg.fromGroup = false; 1528 msg.fromGroup = false;
1492 msg.offline = (byte)0; 1529 msg.offline = (byte)1;
1493 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1530 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1494 msg.Position = Vector3.Zero; 1531 msg.Position = Vector3.Zero;
1495 msg.RegionID = RegionInfo.RegionID.Guid; 1532 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1724,14 +1761,24 @@ namespace OpenSim.Region.Framework.Scenes
1724 /// <returns></returns> 1761 /// <returns></returns>
1725 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1762 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1726 { 1763 {
1764
1765 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1766 Vector3 wpos = Vector3.Zero;
1767 // Check for water surface intersection from above
1768 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1769 {
1770 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1771 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1772 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1773 wpos.Z = wheight;
1774 }
1775
1727 Vector3 pos = Vector3.Zero; 1776 Vector3 pos = Vector3.Zero;
1728 if (RayEndIsIntersection == (byte)1) 1777 if (RayEndIsIntersection == (byte)1)
1729 { 1778 {
1730 pos = RayEnd; 1779 pos = RayEnd;
1731 return pos;
1732 } 1780 }
1733 1781 else if (RayTargetID != UUID.Zero)
1734 if (RayTargetID != UUID.Zero)
1735 { 1782 {
1736 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1783 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1737 1784
@@ -1753,7 +1800,7 @@ namespace OpenSim.Region.Framework.Scenes
1753 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1800 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1754 1801
1755 // Un-comment out the following line to Get Raytrace results printed to the console. 1802 // Un-comment out the following line to Get Raytrace results printed to the console.
1756 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1803 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1757 float ScaleOffset = 0.5f; 1804 float ScaleOffset = 0.5f;
1758 1805
1759 // If we hit something 1806 // If we hit something
@@ -1776,13 +1823,10 @@ namespace OpenSim.Region.Framework.Scenes
1776 //pos.Z -= 0.25F; 1823 //pos.Z -= 0.25F;
1777 1824
1778 } 1825 }
1779
1780 return pos;
1781 } 1826 }
1782 else 1827 else
1783 { 1828 {
1784 // We don't have a target here, so we're going to raytrace all the objects in the scene. 1829 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1785
1786 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 1830 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1787 1831
1788 // Un-comment the following line to print the raytrace results to the console. 1832 // Un-comment the following line to print the raytrace results to the console.
@@ -1791,13 +1835,12 @@ namespace OpenSim.Region.Framework.Scenes
1791 if (ei.HitTF) 1835 if (ei.HitTF)
1792 { 1836 {
1793 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 1837 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1794 } else 1838 }
1839 else
1795 { 1840 {
1796 // fall back to our stupid functionality 1841 // fall back to our stupid functionality
1797 pos = RayEnd; 1842 pos = RayEnd;
1798 } 1843 }
1799
1800 return pos;
1801 } 1844 }
1802 } 1845 }
1803 else 1846 else
@@ -1808,8 +1851,12 @@ namespace OpenSim.Region.Framework.Scenes
1808 //increase height so its above the ground. 1851 //increase height so its above the ground.
1809 //should be getting the normal of the ground at the rez point and using that? 1852 //should be getting the normal of the ground at the rez point and using that?
1810 pos.Z += scale.Z / 2f; 1853 pos.Z += scale.Z / 2f;
1811 return pos; 1854// return pos;
1812 } 1855 }
1856
1857 // check against posible water intercept
1858 if (wpos.Z > pos.Z) pos = wpos;
1859 return pos;
1813 } 1860 }
1814 1861
1815 1862
@@ -1893,7 +1940,10 @@ namespace OpenSim.Region.Framework.Scenes
1893 public bool AddRestoredSceneObject( 1940 public bool AddRestoredSceneObject(
1894 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 1941 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
1895 { 1942 {
1896 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 1943 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
1944 if (result)
1945 sceneObject.IsDeleted = false;
1946 return result;
1897 } 1947 }
1898 1948
1899 /// <summary> 1949 /// <summary>
@@ -1983,6 +2033,15 @@ namespace OpenSim.Region.Framework.Scenes
1983 /// </summary> 2033 /// </summary>
1984 public void DeleteAllSceneObjects() 2034 public void DeleteAllSceneObjects()
1985 { 2035 {
2036 DeleteAllSceneObjects(false);
2037 }
2038
2039 /// <summary>
2040 /// Delete every object from the scene. This does not include attachments worn by avatars.
2041 /// </summary>
2042 public void DeleteAllSceneObjects(bool exceptNoCopy)
2043 {
2044 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
1986 lock (Entities) 2045 lock (Entities)
1987 { 2046 {
1988 EntityBase[] entities = Entities.GetEntities(); 2047 EntityBase[] entities = Entities.GetEntities();
@@ -1991,11 +2050,24 @@ namespace OpenSim.Region.Framework.Scenes
1991 if (e is SceneObjectGroup) 2050 if (e is SceneObjectGroup)
1992 { 2051 {
1993 SceneObjectGroup sog = (SceneObjectGroup)e; 2052 SceneObjectGroup sog = (SceneObjectGroup)e;
1994 if (!sog.IsAttachment) 2053 if (sog != null && !sog.IsAttachment)
1995 DeleteSceneObject((SceneObjectGroup)e, false); 2054 {
2055 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2056 {
2057 DeleteSceneObject((SceneObjectGroup)e, false);
2058 }
2059 else
2060 {
2061 toReturn.Add((SceneObjectGroup)e);
2062 }
2063 }
1996 } 2064 }
1997 } 2065 }
1998 } 2066 }
2067 if (toReturn.Count > 0)
2068 {
2069 returnObjects(toReturn.ToArray(), UUID.Zero);
2070 }
1999 } 2071 }
2000 2072
2001 /// <summary> 2073 /// <summary>
@@ -2043,6 +2115,8 @@ namespace OpenSim.Region.Framework.Scenes
2043 } 2115 }
2044 2116
2045 group.DeleteGroupFromScene(silent); 2117 group.DeleteGroupFromScene(silent);
2118 if (!silent)
2119 SendKillObject(new List<uint>() { group.LocalId });
2046 2120
2047// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2121// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2048 } 2122 }
@@ -2397,10 +2471,17 @@ namespace OpenSim.Region.Framework.Scenes
2397 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2471 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2398 public bool AddSceneObject(SceneObjectGroup sceneObject) 2472 public bool AddSceneObject(SceneObjectGroup sceneObject)
2399 { 2473 {
2474 if (sceneObject.OwnerID == UUID.Zero)
2475 {
2476 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2477 return false;
2478 }
2479
2400 // If the user is banned, we won't let any of their objects 2480 // If the user is banned, we won't let any of their objects
2401 // enter. Period. 2481 // enter. Period.
2402 // 2482 //
2403 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2483 int flags = GetUserFlags(sceneObject.OwnerID);
2484 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2404 { 2485 {
2405 m_log.Info("[INTERREGION]: Denied prim crossing for " + 2486 m_log.Info("[INTERREGION]: Denied prim crossing for " +
2406 "banned avatar"); 2487 "banned avatar");
@@ -2447,12 +2528,23 @@ namespace OpenSim.Region.Framework.Scenes
2447 } 2528 }
2448 else 2529 else
2449 { 2530 {
2531 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2450 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2532 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2451 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2533 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2452 } 2534 }
2535 if (sceneObject.OwnerID == UUID.Zero)
2536 {
2537 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2538 return false;
2539 }
2453 } 2540 }
2454 else 2541 else
2455 { 2542 {
2543 if (sceneObject.OwnerID == UUID.Zero)
2544 {
2545 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2546 return false;
2547 }
2456 AddRestoredSceneObject(sceneObject, true, false); 2548 AddRestoredSceneObject(sceneObject, true, false);
2457 2549
2458 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2550 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2482,6 +2574,24 @@ namespace OpenSim.Region.Framework.Scenes
2482 return 2; // StateSource.PrimCrossing 2574 return 2; // StateSource.PrimCrossing
2483 } 2575 }
2484 2576
2577 public int GetUserFlags(UUID user)
2578 {
2579 //Unfortunately the SP approach means that the value is cached until region is restarted
2580 /*
2581 ScenePresence sp;
2582 if (TryGetScenePresence(user, out sp))
2583 {
2584 return sp.UserFlags;
2585 }
2586 else
2587 {
2588 */
2589 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2590 if (uac == null)
2591 return 0;
2592 return uac.UserFlags;
2593 //}
2594 }
2485 #endregion 2595 #endregion
2486 2596
2487 #region Add/Remove Avatar Methods 2597 #region Add/Remove Avatar Methods
@@ -2503,6 +2613,7 @@ namespace OpenSim.Region.Framework.Scenes
2503 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2613 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2504 2614
2505 CheckHeartbeat(); 2615 CheckHeartbeat();
2616 ScenePresence presence;
2506 2617
2507 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here 2618 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here
2508 { 2619 {
@@ -2538,7 +2649,14 @@ namespace OpenSim.Region.Framework.Scenes
2538 2649
2539 EventManager.TriggerOnNewClient(client); 2650 EventManager.TriggerOnNewClient(client);
2540 if (vialogin) 2651 if (vialogin)
2652 {
2541 EventManager.TriggerOnClientLogin(client); 2653 EventManager.TriggerOnClientLogin(client);
2654
2655 // Send initial parcel data
2656 Vector3 pos = createdSp.AbsolutePosition;
2657 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2658 land.SendLandUpdateToClient(client);
2659 }
2542 } 2660 }
2543 } 2661 }
2544 2662
@@ -2627,19 +2745,12 @@ namespace OpenSim.Region.Framework.Scenes
2627 // and the scene presence and the client, if they exist 2745 // and the scene presence and the client, if they exist
2628 try 2746 try
2629 { 2747 {
2630 // We need to wait for the client to make UDP contact first. 2748 ScenePresence sp = GetScenePresence(agentID);
2631 // It's the UDP contact that creates the scene presence 2749 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2632 ScenePresence sp = WaitGetScenePresence(agentID); 2750
2633 if (sp != null) 2751 if (sp != null)
2634 {
2635 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2636
2637 sp.ControllingClient.Close(); 2752 sp.ControllingClient.Close();
2638 } 2753
2639 else
2640 {
2641 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2642 }
2643 // BANG! SLASH! 2754 // BANG! SLASH!
2644 m_authenticateHandler.RemoveCircuit(agentID); 2755 m_authenticateHandler.RemoveCircuit(agentID);
2645 2756
@@ -2739,6 +2850,7 @@ namespace OpenSim.Region.Framework.Scenes
2739 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 2850 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2740 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 2851 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2741 client.OnCopyInventoryItem += CopyInventoryItem; 2852 client.OnCopyInventoryItem += CopyInventoryItem;
2853 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2742 client.OnMoveInventoryItem += MoveInventoryItem; 2854 client.OnMoveInventoryItem += MoveInventoryItem;
2743 client.OnRemoveInventoryItem += RemoveInventoryItem; 2855 client.OnRemoveInventoryItem += RemoveInventoryItem;
2744 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 2856 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2916,15 +3028,16 @@ namespace OpenSim.Region.Framework.Scenes
2916 /// </summary> 3028 /// </summary>
2917 /// <param name="agentId">The avatar's Unique ID</param> 3029 /// <param name="agentId">The avatar's Unique ID</param>
2918 /// <param name="client">The IClientAPI for the client</param> 3030 /// <param name="client">The IClientAPI for the client</param>
2919 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3031 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
2920 { 3032 {
2921 if (m_teleportModule != null) 3033 if (m_teleportModule != null)
2922 m_teleportModule.TeleportHome(agentId, client); 3034 return m_teleportModule.TeleportHome(agentId, client);
2923 else 3035 else
2924 { 3036 {
2925 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3037 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
2926 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3038 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
2927 } 3039 }
3040 return false;
2928 } 3041 }
2929 3042
2930 /// <summary> 3043 /// <summary>
@@ -3016,6 +3129,16 @@ namespace OpenSim.Region.Framework.Scenes
3016 /// <param name="flags"></param> 3129 /// <param name="flags"></param>
3017 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3130 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3018 { 3131 {
3132 //Add half the avatar's height so that the user doesn't fall through prims
3133 ScenePresence presence;
3134 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3135 {
3136 if (presence.Appearance != null)
3137 {
3138 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3139 }
3140 }
3141
3019 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3142 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3020 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3143 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3021 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3144 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3084,8 +3207,9 @@ namespace OpenSim.Region.Framework.Scenes
3084 regions.Remove(RegionInfo.RegionHandle); 3207 regions.Remove(RegionInfo.RegionHandle);
3085 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3208 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3086 } 3209 }
3087 3210 m_log.Debug("[Scene] Beginning ClientClosed");
3088 m_eventManager.TriggerClientClosed(agentID, this); 3211 m_eventManager.TriggerClientClosed(agentID, this);
3212 m_log.Debug("[Scene] Finished ClientClosed");
3089 } 3213 }
3090 catch (NullReferenceException) 3214 catch (NullReferenceException)
3091 { 3215 {
@@ -3093,7 +3217,12 @@ namespace OpenSim.Region.Framework.Scenes
3093 // Avatar is already disposed :/ 3217 // Avatar is already disposed :/
3094 } 3218 }
3095 3219
3220 m_log.Debug("[Scene] Beginning OnRemovePresence");
3096 m_eventManager.TriggerOnRemovePresence(agentID); 3221 m_eventManager.TriggerOnRemovePresence(agentID);
3222 m_log.Debug("[Scene] Finished OnRemovePresence");
3223
3224 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3225 AttachmentsModule.SaveChangedAttachments(avatar);
3097 3226
3098 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc) 3227 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3099 AttachmentsModule.SaveChangedAttachments(avatar); 3228 AttachmentsModule.SaveChangedAttachments(avatar);
@@ -3102,7 +3231,7 @@ namespace OpenSim.Region.Framework.Scenes
3102 delegate(IClientAPI client) 3231 delegate(IClientAPI client)
3103 { 3232 {
3104 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway 3233 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway
3105 try { client.SendKillObject(avatar.RegionHandle, avatar.LocalId); } 3234 try { client.SendKillObject(avatar.RegionHandle, new List<uint>() { avatar.LocalId}); }
3106 catch (NullReferenceException) { } 3235 catch (NullReferenceException) { }
3107 }); 3236 });
3108 3237
@@ -3113,8 +3242,11 @@ namespace OpenSim.Region.Framework.Scenes
3113 } 3242 }
3114 3243
3115 // Remove the avatar from the scene 3244 // Remove the avatar from the scene
3245 m_log.Debug("[Scene] Begin RemoveScenePresence");
3116 m_sceneGraph.RemoveScenePresence(agentID); 3246 m_sceneGraph.RemoveScenePresence(agentID);
3247 m_log.Debug("[Scene] Finished RemoveScenePresence. Removing the client manager");
3117 m_clientManager.Remove(agentID); 3248 m_clientManager.Remove(agentID);
3249 m_log.Debug("[Scene] Removed the client manager. Firing avatar.close");
3118 3250
3119 try 3251 try
3120 { 3252 {
@@ -3128,9 +3260,10 @@ namespace OpenSim.Region.Framework.Scenes
3128 { 3260 {
3129 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3261 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3130 } 3262 }
3131 3263 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3132 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3264 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3133// CleanDroppedAttachments(); 3265// CleanDroppedAttachments();
3266 m_log.Debug("[Scene] The avatar has left the building");
3134 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3267 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3135 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3268 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3136 } 3269 }
@@ -3161,19 +3294,24 @@ namespace OpenSim.Region.Framework.Scenes
3161 3294
3162 #region Entities 3295 #region Entities
3163 3296
3164 public void SendKillObject(uint localID) 3297 public void SendKillObject(List<uint> localIDs)
3165 { 3298 {
3166 SceneObjectPart part = GetSceneObjectPart(localID); 3299 List<uint> deleteIDs = new List<uint>();
3167 if (part != null) // It is a prim 3300
3301 foreach (uint localID in localIDs)
3168 { 3302 {
3169 if (!part.ParentGroup.IsDeleted) // Valid 3303 SceneObjectPart part = GetSceneObjectPart(localID);
3304 if (part != null) // It is a prim
3170 { 3305 {
3171 if (part.ParentGroup.RootPart != part) // Child part 3306 if (part.ParentGroup != null && !part.ParentGroup.IsDeleted) // Valid
3172 return; 3307 {
3308 if (part.ParentGroup.RootPart != part) // Child part
3309 continue;
3310 }
3173 } 3311 }
3312 deleteIDs.Add(localID);
3174 } 3313 }
3175 3314 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, deleteIDs); });
3176 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); });
3177 } 3315 }
3178 3316
3179 #endregion 3317 #endregion
@@ -3191,7 +3329,6 @@ namespace OpenSim.Region.Framework.Scenes
3191 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate; 3329 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3192 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar; 3330 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar;
3193 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3331 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3194 m_sceneGridService.KiPrimitive += SendKillObject;
3195 m_sceneGridService.OnGetLandData += GetLandData; 3332 m_sceneGridService.OnGetLandData += GetLandData;
3196 } 3333 }
3197 3334
@@ -3200,7 +3337,6 @@ namespace OpenSim.Region.Framework.Scenes
3200 /// </summary> 3337 /// </summary>
3201 public void UnRegisterRegionWithComms() 3338 public void UnRegisterRegionWithComms()
3202 { 3339 {
3203 m_sceneGridService.KiPrimitive -= SendKillObject;
3204 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid; 3340 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid;
3205 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar; 3341 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar;
3206 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate; 3342 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
@@ -3280,13 +3416,16 @@ namespace OpenSim.Region.Framework.Scenes
3280 sp = null; 3416 sp = null;
3281 } 3417 }
3282 3418
3283 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3284 3419
3285 //On login test land permisions 3420 //On login test land permisions
3286 if (vialogin) 3421 if (vialogin)
3287 { 3422 {
3288 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3423 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3424 if (cache != null)
3425 cache.Remove(agent.firstname + " " + agent.lastname);
3426 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3289 { 3427 {
3428 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3290 return false; 3429 return false;
3291 } 3430 }
3292 } 3431 }
@@ -3309,8 +3448,13 @@ namespace OpenSim.Region.Framework.Scenes
3309 3448
3310 try 3449 try
3311 { 3450 {
3312 if (!AuthorizeUser(agent, out reason)) 3451 // Always check estate if this is a login. Always
3313 return false; 3452 // check if banned regions are to be blacked out.
3453 if (vialogin || (!m_seeIntoBannedRegion))
3454 {
3455 if (!AuthorizeUser(agent, out reason))
3456 return false;
3457 }
3314 } 3458 }
3315 catch (Exception e) 3459 catch (Exception e)
3316 { 3460 {
@@ -3412,6 +3556,8 @@ namespace OpenSim.Region.Framework.Scenes
3412 } 3556 }
3413 } 3557 }
3414 // Honor parcel landing type and position. 3558 // Honor parcel landing type and position.
3559 /*
3560 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3415 if (land != null) 3561 if (land != null)
3416 { 3562 {
3417 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3563 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3419,26 +3565,34 @@ namespace OpenSim.Region.Framework.Scenes
3419 agent.startpos = land.LandData.UserLocation; 3565 agent.startpos = land.LandData.UserLocation;
3420 } 3566 }
3421 } 3567 }
3568 */// This is now handled properly in ScenePresence.MakeRootAgent
3422 } 3569 }
3423 3570
3424 return true; 3571 return true;
3425 } 3572 }
3426 3573
3427 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3574 private bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3428 { 3575 {
3429 3576 reason = String.Empty;
3430 bool banned = land.IsBannedFromLand(agent.AgentID); 3577 if (Permissions.IsGod(agentID))
3431 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3578 return true;
3579
3580 ILandObject land = LandChannel.GetLandObject(posX, posY);
3581 if (land == null)
3582 return false;
3583
3584 bool banned = land.IsBannedFromLand(agentID);
3585 bool restricted = land.IsRestrictedFromLand(agentID);
3432 3586
3433 if (banned || restricted) 3587 if (banned || restricted)
3434 { 3588 {
3435 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3589 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3436 if (nearestParcel != null) 3590 if (nearestParcel != null)
3437 { 3591 {
3438 //Move agent to nearest allowed 3592 //Move agent to nearest allowed
3439 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3593 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3440 agent.startpos.X = newPosition.X; 3594 posX = newPosition.X;
3441 agent.startpos.Y = newPosition.Y; 3595 posY = newPosition.Y;
3442 } 3596 }
3443 else 3597 else
3444 { 3598 {
@@ -3500,7 +3654,7 @@ namespace OpenSim.Region.Framework.Scenes
3500 3654
3501 if (!m_strictAccessControl) return true; 3655 if (!m_strictAccessControl) return true;
3502 if (Permissions.IsGod(agent.AgentID)) return true; 3656 if (Permissions.IsGod(agent.AgentID)) return true;
3503 3657
3504 if (AuthorizationService != null) 3658 if (AuthorizationService != null)
3505 { 3659 {
3506 if (!AuthorizationService.IsAuthorizedForRegion( 3660 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3508,14 +3662,14 @@ namespace OpenSim.Region.Framework.Scenes
3508 { 3662 {
3509 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region", 3663 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region",
3510 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3664 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
3511 3665
3512 return false; 3666 return false;
3513 } 3667 }
3514 } 3668 }
3515 3669
3516 if (m_regInfo.EstateSettings != null) 3670 if (m_regInfo.EstateSettings != null)
3517 { 3671 {
3518 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3672 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3519 { 3673 {
3520 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3674 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3521 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3675 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3705,6 +3859,13 @@ namespace OpenSim.Region.Framework.Scenes
3705 3859
3706 // We have to wait until the viewer contacts this region after receiving EAC. 3860 // We have to wait until the viewer contacts this region after receiving EAC.
3707 // That calls AddNewClient, which finally creates the ScenePresence 3861 // That calls AddNewClient, which finally creates the ScenePresence
3862 int flags = GetUserFlags(cAgentData.AgentID);
3863 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
3864 {
3865 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
3866 return false;
3867 }
3868
3708 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 3869 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3709 if (nearestParcel == null) 3870 if (nearestParcel == null)
3710 { 3871 {
@@ -3720,7 +3881,6 @@ namespace OpenSim.Region.Framework.Scenes
3720 return false; 3881 return false;
3721 } 3882 }
3722 3883
3723
3724 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID); 3884 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID);
3725 3885
3726 if (childAgentUpdate != null) 3886 if (childAgentUpdate != null)
@@ -3787,12 +3947,22 @@ namespace OpenSim.Region.Framework.Scenes
3787 return false; 3947 return false;
3788 } 3948 }
3789 3949
3950 public bool IncomingCloseAgent(UUID agentID)
3951 {
3952 return IncomingCloseAgent(agentID, false);
3953 }
3954
3955 public bool IncomingCloseChildAgent(UUID agentID)
3956 {
3957 return IncomingCloseAgent(agentID, true);
3958 }
3959
3790 /// <summary> 3960 /// <summary>
3791 /// Tell a single agent to disconnect from the region. 3961 /// Tell a single agent to disconnect from the region.
3792 /// </summary> 3962 /// </summary>
3793 /// <param name="regionHandle"></param>
3794 /// <param name="agentID"></param> 3963 /// <param name="agentID"></param>
3795 public bool IncomingCloseAgent(UUID agentID) 3964 /// <param name="childOnly"></param>
3965 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
3796 { 3966 {
3797 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 3967 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
3798 3968
@@ -3804,7 +3974,7 @@ namespace OpenSim.Region.Framework.Scenes
3804 { 3974 {
3805 m_sceneGraph.removeUserCount(false); 3975 m_sceneGraph.removeUserCount(false);
3806 } 3976 }
3807 else 3977 else if (!childOnly)
3808 { 3978 {
3809 m_sceneGraph.removeUserCount(true); 3979 m_sceneGraph.removeUserCount(true);
3810 } 3980 }
@@ -3820,9 +3990,12 @@ namespace OpenSim.Region.Framework.Scenes
3820 } 3990 }
3821 else 3991 else
3822 presence.ControllingClient.SendShutdownConnectionNotice(); 3992 presence.ControllingClient.SendShutdownConnectionNotice();
3993 presence.ControllingClient.Close(false);
3994 }
3995 else if (!childOnly)
3996 {
3997 presence.ControllingClient.Close(true);
3823 } 3998 }
3824
3825 presence.ControllingClient.Close();
3826 return true; 3999 return true;
3827 } 4000 }
3828 4001
@@ -4417,34 +4590,66 @@ namespace OpenSim.Region.Framework.Scenes
4417 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4590 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4418 } 4591 }
4419 4592
4420 public int GetHealth() 4593 public int GetHealth(out int flags, out string message)
4421 { 4594 {
4422 // Returns: 4595 // Returns:
4423 // 1 = sim is up and accepting http requests. The heartbeat has 4596 // 1 = sim is up and accepting http requests. The heartbeat has
4424 // stopped and the sim is probably locked up, but a remote 4597 // stopped and the sim is probably locked up, but a remote
4425 // admin restart may succeed 4598 // admin restart may succeed
4426 // 4599 //
4427 // 2 = Sim is up and the heartbeat is running. The sim is likely 4600 // 2 = Sim is up and the heartbeat is running. The sim is likely
4428 // usable for people within and logins _may_ work 4601 // usable for people within
4429 // 4602 //
4430 // 3 = We have seen a new user enter within the past 4 minutes 4603 // 3 = Sim is up and one packet thread is running. Sim is
4604 // unstable and will not accept new logins
4605 //
4606 // 4 = Sim is up and both packet threads are running. Sim is
4607 // likely usable
4608 //
4609 // 5 = We have seen a new user enter within the past 4 minutes
4431 // which can be seen as positive confirmation of sim health 4610 // which can be seen as positive confirmation of sim health
4432 // 4611 //
4612
4613 flags = 0;
4614 message = String.Empty;
4615
4616 CheckHeartbeat();
4617
4618 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4619 {
4620 // We're still starting
4621 // 0 means "in startup", it can't happen another way, since
4622 // to get here, we must be able to accept http connections
4623 return 0;
4624 }
4625
4433 int health=1; // Start at 1, means we're up 4626 int health=1; // Start at 1, means we're up
4434 4627
4435 if ((Util.EnvironmentTickCountSubtract(m_lastUpdate)) < 1000) 4628 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) < 1000)
4629 {
4436 health+=1; 4630 health+=1;
4437 else 4631 flags |= 1;
4632 }
4633
4634 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4635 {
4636 health+=1;
4637 flags |= 2;
4638 }
4639
4640 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4641 {
4642 health+=1;
4643 flags |= 4;
4644 }
4645
4646 if (flags != 7)
4438 return health; 4647 return health;
4439 4648
4440 // A login in the last 4 mins? We can't be doing too badly 4649 // A login in the last 4 mins? We can't be doing too badly
4441 // 4650 //
4442 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4651 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4443 health++; 4652 health++;
4444 else
4445 return health;
4446
4447 CheckHeartbeat();
4448 4653
4449 return health; 4654 return health;
4450 } 4655 }
@@ -4637,7 +4842,7 @@ namespace OpenSim.Region.Framework.Scenes
4637 if (m_firstHeartbeat) 4842 if (m_firstHeartbeat)
4638 return; 4843 return;
4639 4844
4640 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4845 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 5000)
4641 StartTimer(); 4846 StartTimer();
4642 } 4847 }
4643 4848
@@ -5051,6 +5256,54 @@ namespace OpenSim.Region.Framework.Scenes
5051 } 5256 }
5052 } 5257 }
5053 5258
5259// public void CleanDroppedAttachments()
5260// {
5261// List<SceneObjectGroup> objectsToDelete =
5262// new List<SceneObjectGroup>();
5263//
5264// lock (m_cleaningAttachments)
5265// {
5266// ForEachSOG(delegate (SceneObjectGroup grp)
5267// {
5268// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5269// {
5270// UUID agentID = grp.OwnerID;
5271// if (agentID == UUID.Zero)
5272// {
5273// objectsToDelete.Add(grp);
5274// return;
5275// }
5276//
5277// ScenePresence sp = GetScenePresence(agentID);
5278// if (sp == null)
5279// {
5280// objectsToDelete.Add(grp);
5281// return;
5282// }
5283// }
5284// });
5285// }
5286//
5287// foreach (SceneObjectGroup grp in objectsToDelete)
5288// {
5289// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5290// DeleteSceneObject(grp, true);
5291// }
5292// }
5293
5294 public void ThreadAlive(int threadCode)
5295 {
5296 switch(threadCode)
5297 {
5298 case 1: // Incoming
5299 m_lastIncoming = Util.EnvironmentTickCount();
5300 break;
5301 case 2: // Incoming
5302 m_lastOutgoing = Util.EnvironmentTickCount();
5303 break;
5304 }
5305 }
5306
5054 // This method is called across the simulation connector to 5307 // This method is called across the simulation connector to
5055 // determine if a given agent is allowed in this region 5308 // determine if a given agent is allowed in this region
5056 // AS A ROOT AGENT. Returning false here will prevent them 5309 // AS A ROOT AGENT. Returning false here will prevent them
@@ -5059,6 +5312,14 @@ namespace OpenSim.Region.Framework.Scenes
5059 // child agent creation, thereby emulating the SL behavior. 5312 // child agent creation, thereby emulating the SL behavior.
5060 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5313 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5061 { 5314 {
5315 reason = "You are banned from the region";
5316
5317 if (Permissions.IsGod(agentID))
5318 {
5319 reason = String.Empty;
5320 return true;
5321 }
5322
5062 int num = m_sceneGraph.GetNumberOfScenePresences(); 5323 int num = m_sceneGraph.GetNumberOfScenePresences();
5063 5324
5064 if (num >= RegionInfo.RegionSettings.AgentLimit) 5325 if (num >= RegionInfo.RegionSettings.AgentLimit)
@@ -5070,11 +5331,82 @@ namespace OpenSim.Region.Framework.Scenes
5070 } 5331 }
5071 } 5332 }
5072 5333
5334 ScenePresence presence = GetScenePresence(agentID);
5335 IClientAPI client = null;
5336 AgentCircuitData aCircuit = null;
5337
5338 if (presence != null)
5339 {
5340 client = presence.ControllingClient;
5341 if (client != null)
5342 aCircuit = client.RequestClientInfo();
5343 }
5344
5345 // We may be called before there is a presence or a client.
5346 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5347 if (client == null)
5348 {
5349 aCircuit = new AgentCircuitData();
5350 aCircuit.AgentID = agentID;
5351 aCircuit.firstname = String.Empty;
5352 aCircuit.lastname = String.Empty;
5353 }
5354
5355 try
5356 {
5357 if (!AuthorizeUser(aCircuit, out reason))
5358 {
5359 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5360 return false;
5361 }
5362 }
5363 catch (Exception e)
5364 {
5365 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5366 return false;
5367 }
5368
5369 if (position == Vector3.Zero) // Teleport
5370 {
5371 float posX = 128.0f;
5372 float posY = 128.0f;
5373
5374 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5375 {
5376 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5377 return false;
5378 }
5379 }
5380 else // Walking
5381 {
5382 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5383 if (land == null)
5384 return false;
5385
5386 bool banned = land.IsBannedFromLand(agentID);
5387 bool restricted = land.IsRestrictedFromLand(agentID);
5388
5389 if (banned || restricted)
5390 return false;
5391 }
5392
5073 reason = String.Empty; 5393 reason = String.Empty;
5074 return true; 5394 return true;
5075 } 5395 }
5076 5396
5077 /// <summary> 5397 public void StartTimerWatchdog()
5398 {
5399 m_timerWatchdog.Interval = 1000;
5400 m_timerWatchdog.Elapsed += TimerWatchdog;
5401 m_timerWatchdog.AutoReset = true;
5402 m_timerWatchdog.Start();
5403 }
5404
5405 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5406 {
5407 CheckHeartbeat();
5408 }
5409
5078 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5410 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5079 /// autopilot that moves an avatar to a sit target!. 5411 /// autopilot that moves an avatar to a sit target!.
5080 /// </summary> 5412 /// </summary>