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.cs446
1 files changed, 360 insertions, 86 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 29a54e8..b288c8a 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;
@@ -170,7 +173,7 @@ namespace OpenSim.Region.Framework.Scenes
170 private int m_update_events = 1; 173 private int m_update_events = 1;
171 private int m_update_backup = 200; 174 private int m_update_backup = 200;
172 private int m_update_terrain = 50; 175 private int m_update_terrain = 50;
173// private int m_update_land = 1; 176 private int m_update_land = 10;
174 private int m_update_coarse_locations = 50; 177 private int m_update_coarse_locations = 50;
175 178
176 private int frameMS; 179 private int frameMS;
@@ -184,14 +187,17 @@ namespace OpenSim.Region.Framework.Scenes
184 private int landMS; 187 private int landMS;
185 private int lastCompletedFrame; 188 private int lastCompletedFrame;
186 189
190 public bool CombineRegions = false;
187 private bool m_physics_enabled = true; 191 private bool m_physics_enabled = true;
188 private bool m_scripts_enabled = true; 192 private bool m_scripts_enabled = true;
189 private string m_defaultScriptEngine; 193 private string m_defaultScriptEngine;
190 private int m_LastLogin; 194 private int m_LastLogin;
191 private Thread HeartbeatThread; 195 private Thread HeartbeatThread = null;
192 private volatile bool shuttingdown; 196 private volatile bool shuttingdown;
193 197
194 private int m_lastUpdate; 198 private int m_lastUpdate;
199 private int m_lastIncoming;
200 private int m_lastOutgoing;
195 private bool m_firstHeartbeat = true; 201 private bool m_firstHeartbeat = true;
196 202
197 private object m_deleting_scene_object = new object(); 203 private object m_deleting_scene_object = new object();
@@ -244,6 +250,19 @@ namespace OpenSim.Region.Framework.Scenes
244 get { return m_sceneGridService; } 250 get { return m_sceneGridService; }
245 } 251 }
246 252
253 public ISnmpModule SnmpService
254 {
255 get
256 {
257 if (m_snmpService == null)
258 {
259 m_snmpService = RequestModuleInterface<ISnmpModule>();
260 }
261
262 return m_snmpService;
263 }
264 }
265
247 public ISimulationDataService SimulationDataService 266 public ISimulationDataService SimulationDataService
248 { 267 {
249 get 268 get
@@ -572,7 +591,10 @@ namespace OpenSim.Region.Framework.Scenes
572 m_regInfo = regInfo; 591 m_regInfo = regInfo;
573 m_regionHandle = m_regInfo.RegionHandle; 592 m_regionHandle = m_regInfo.RegionHandle;
574 m_regionName = m_regInfo.RegionName; 593 m_regionName = m_regInfo.RegionName;
594 m_datastore = m_regInfo.DataStore;
575 m_lastUpdate = Util.EnvironmentTickCount(); 595 m_lastUpdate = Util.EnvironmentTickCount();
596 m_lastIncoming = 0;
597 m_lastOutgoing = 0;
576 598
577 m_physicalPrim = physicalPrim; 599 m_physicalPrim = physicalPrim;
578 m_seeIntoRegionFromNeighbor = SeeIntoRegionFromNeighbor; 600 m_seeIntoRegionFromNeighbor = SeeIntoRegionFromNeighbor;
@@ -704,9 +726,10 @@ namespace OpenSim.Region.Framework.Scenes
704 //Animation states 726 //Animation states
705 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 727 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
706 // TODO: Change default to true once the feature is supported 728 // TODO: Change default to true once the feature is supported
707 m_usePreJump = startupConfig.GetBoolean("enableprejump", false); 729 m_usePreJump = startupConfig.GetBoolean("enableprejump", true);
708
709 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 730 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
731
732 m_log.DebugFormat("[SCENE]: prejump is {0}", m_usePreJump ? "ON" : "OFF");
710 if (RegionInfo.NonphysPrimMax > 0) 733 if (RegionInfo.NonphysPrimMax > 0)
711 { 734 {
712 m_maxNonphys = RegionInfo.NonphysPrimMax; 735 m_maxNonphys = RegionInfo.NonphysPrimMax;
@@ -738,6 +761,7 @@ namespace OpenSim.Region.Framework.Scenes
738 m_persistAfter *= 10000000; 761 m_persistAfter *= 10000000;
739 762
740 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 763 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
764 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
741 765
742 IConfig packetConfig = m_config.Configs["PacketPool"]; 766 IConfig packetConfig = m_config.Configs["PacketPool"];
743 if (packetConfig != null) 767 if (packetConfig != null)
@@ -747,6 +771,8 @@ namespace OpenSim.Region.Framework.Scenes
747 } 771 }
748 772
749 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 773 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
774 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
775 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
750 776
751 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 777 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
752 if (m_generateMaptiles) 778 if (m_generateMaptiles)
@@ -771,9 +797,9 @@ namespace OpenSim.Region.Framework.Scenes
771 } 797 }
772 } 798 }
773 } 799 }
774 catch 800 catch (Exception e)
775 { 801 {
776 m_log.Warn("[SCENE]: Failed to load StartupConfig"); 802 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
777 } 803 }
778 804
779 #endregion Region Config 805 #endregion Region Config
@@ -1150,7 +1176,9 @@ namespace OpenSim.Region.Framework.Scenes
1150 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1176 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1151 if (HeartbeatThread != null) 1177 if (HeartbeatThread != null)
1152 { 1178 {
1179 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1153 HeartbeatThread.Abort(); 1180 HeartbeatThread.Abort();
1181 Watchdog.RemoveThread(HeartbeatThread.ManagedThreadId);
1154 HeartbeatThread = null; 1182 HeartbeatThread = null;
1155 } 1183 }
1156 m_lastUpdate = Util.EnvironmentTickCount(); 1184 m_lastUpdate = Util.EnvironmentTickCount();
@@ -1193,9 +1221,6 @@ namespace OpenSim.Region.Framework.Scenes
1193 { 1221 {
1194 while (!shuttingdown) 1222 while (!shuttingdown)
1195 Update(); 1223 Update();
1196
1197 m_lastUpdate = Util.EnvironmentTickCount();
1198 m_firstHeartbeat = false;
1199 } 1224 }
1200 catch (ThreadAbortException) 1225 catch (ThreadAbortException)
1201 { 1226 {
@@ -1285,6 +1310,13 @@ namespace OpenSim.Region.Framework.Scenes
1285 eventMS = Util.EnvironmentTickCountSubtract(evMS); ; 1310 eventMS = Util.EnvironmentTickCountSubtract(evMS); ;
1286 } 1311 }
1287 1312
1313 // if (Frame % m_update_land == 0)
1314 // {
1315 // int ldMS = Util.EnvironmentTickCount();
1316 // UpdateLand();
1317 // landMS = Util.EnvironmentTickCountSubtract(ldMS);
1318 // }
1319
1288 if (Frame % m_update_backup == 0) 1320 if (Frame % m_update_backup == 0)
1289 { 1321 {
1290 int backMS = Util.EnvironmentTickCount(); 1322 int backMS = Util.EnvironmentTickCount();
@@ -1385,12 +1417,16 @@ namespace OpenSim.Region.Framework.Scenes
1385 maintc = Util.EnvironmentTickCountSubtract(maintc); 1417 maintc = Util.EnvironmentTickCountSubtract(maintc);
1386 maintc = (int)(m_timespan * 1000) - maintc; 1418 maintc = (int)(m_timespan * 1000) - maintc;
1387 1419
1420
1421 m_lastUpdate = Util.EnvironmentTickCount();
1422 m_firstHeartbeat = false;
1423
1388 if (maintc > 0) 1424 if (maintc > 0)
1389 Thread.Sleep(maintc); 1425 Thread.Sleep(maintc);
1390 1426
1391 // Tell the watchdog that this thread is still alive 1427 // Tell the watchdog that this thread is still alive
1392 Watchdog.UpdateThread(); 1428 Watchdog.UpdateThread();
1393 } 1429 }
1394 1430
1395 public void AddGroupTarget(SceneObjectGroup grp) 1431 public void AddGroupTarget(SceneObjectGroup grp)
1396 { 1432 {
@@ -1406,9 +1442,9 @@ namespace OpenSim.Region.Framework.Scenes
1406 1442
1407 private void CheckAtTargets() 1443 private void CheckAtTargets()
1408 { 1444 {
1409 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1445 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1410 lock (m_groupsWithTargets) 1446 lock (m_groupsWithTargets)
1411 objs = m_groupsWithTargets.Values; 1447 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1412 1448
1413 foreach (SceneObjectGroup entry in objs) 1449 foreach (SceneObjectGroup entry in objs)
1414 entry.checkAtTargets(); 1450 entry.checkAtTargets();
@@ -1728,14 +1764,24 @@ namespace OpenSim.Region.Framework.Scenes
1728 /// <returns></returns> 1764 /// <returns></returns>
1729 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1765 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1730 { 1766 {
1767
1768 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1769 Vector3 wpos = Vector3.Zero;
1770 // Check for water surface intersection from above
1771 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1772 {
1773 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1774 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1775 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1776 wpos.Z = wheight;
1777 }
1778
1731 Vector3 pos = Vector3.Zero; 1779 Vector3 pos = Vector3.Zero;
1732 if (RayEndIsIntersection == (byte)1) 1780 if (RayEndIsIntersection == (byte)1)
1733 { 1781 {
1734 pos = RayEnd; 1782 pos = RayEnd;
1735 return pos;
1736 } 1783 }
1737 1784 else if (RayTargetID != UUID.Zero)
1738 if (RayTargetID != UUID.Zero)
1739 { 1785 {
1740 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1786 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1741 1787
@@ -1757,7 +1803,7 @@ namespace OpenSim.Region.Framework.Scenes
1757 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1803 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1758 1804
1759 // Un-comment out the following line to Get Raytrace results printed to the console. 1805 // Un-comment out the following line to Get Raytrace results printed to the console.
1760 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1806 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1761 float ScaleOffset = 0.5f; 1807 float ScaleOffset = 0.5f;
1762 1808
1763 // If we hit something 1809 // If we hit something
@@ -1780,13 +1826,10 @@ namespace OpenSim.Region.Framework.Scenes
1780 //pos.Z -= 0.25F; 1826 //pos.Z -= 0.25F;
1781 1827
1782 } 1828 }
1783
1784 return pos;
1785 } 1829 }
1786 else 1830 else
1787 { 1831 {
1788 // We don't have a target here, so we're going to raytrace all the objects in the scene. 1832 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1789
1790 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 1833 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1791 1834
1792 // Un-comment the following line to print the raytrace results to the console. 1835 // Un-comment the following line to print the raytrace results to the console.
@@ -1795,13 +1838,12 @@ namespace OpenSim.Region.Framework.Scenes
1795 if (ei.HitTF) 1838 if (ei.HitTF)
1796 { 1839 {
1797 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 1840 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1798 } else 1841 }
1842 else
1799 { 1843 {
1800 // fall back to our stupid functionality 1844 // fall back to our stupid functionality
1801 pos = RayEnd; 1845 pos = RayEnd;
1802 } 1846 }
1803
1804 return pos;
1805 } 1847 }
1806 } 1848 }
1807 else 1849 else
@@ -1812,8 +1854,12 @@ namespace OpenSim.Region.Framework.Scenes
1812 //increase height so its above the ground. 1854 //increase height so its above the ground.
1813 //should be getting the normal of the ground at the rez point and using that? 1855 //should be getting the normal of the ground at the rez point and using that?
1814 pos.Z += scale.Z / 2f; 1856 pos.Z += scale.Z / 2f;
1815 return pos; 1857// return pos;
1816 } 1858 }
1859
1860 // check against posible water intercept
1861 if (wpos.Z > pos.Z) pos = wpos;
1862 return pos;
1817 } 1863 }
1818 1864
1819 1865
@@ -1897,7 +1943,10 @@ namespace OpenSim.Region.Framework.Scenes
1897 public bool AddRestoredSceneObject( 1943 public bool AddRestoredSceneObject(
1898 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 1944 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
1899 { 1945 {
1900 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 1946 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
1947 if (result)
1948 sceneObject.IsDeleted = false;
1949 return result;
1901 } 1950 }
1902 1951
1903 /// <summary> 1952 /// <summary>
@@ -1987,6 +2036,15 @@ namespace OpenSim.Region.Framework.Scenes
1987 /// </summary> 2036 /// </summary>
1988 public void DeleteAllSceneObjects() 2037 public void DeleteAllSceneObjects()
1989 { 2038 {
2039 DeleteAllSceneObjects(false);
2040 }
2041
2042 /// <summary>
2043 /// Delete every object from the scene. This does not include attachments worn by avatars.
2044 /// </summary>
2045 public void DeleteAllSceneObjects(bool exceptNoCopy)
2046 {
2047 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
1990 lock (Entities) 2048 lock (Entities)
1991 { 2049 {
1992 EntityBase[] entities = Entities.GetEntities(); 2050 EntityBase[] entities = Entities.GetEntities();
@@ -1995,11 +2053,24 @@ namespace OpenSim.Region.Framework.Scenes
1995 if (e is SceneObjectGroup) 2053 if (e is SceneObjectGroup)
1996 { 2054 {
1997 SceneObjectGroup sog = (SceneObjectGroup)e; 2055 SceneObjectGroup sog = (SceneObjectGroup)e;
1998 if (!sog.IsAttachment) 2056 if (sog != null && !sog.IsAttachment)
1999 DeleteSceneObject((SceneObjectGroup)e, false); 2057 {
2058 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2059 {
2060 DeleteSceneObject((SceneObjectGroup)e, false);
2061 }
2062 else
2063 {
2064 toReturn.Add((SceneObjectGroup)e);
2065 }
2066 }
2000 } 2067 }
2001 } 2068 }
2002 } 2069 }
2070 if (toReturn.Count > 0)
2071 {
2072 returnObjects(toReturn.ToArray(), UUID.Zero);
2073 }
2003 } 2074 }
2004 2075
2005 /// <summary> 2076 /// <summary>
@@ -2048,6 +2119,8 @@ namespace OpenSim.Region.Framework.Scenes
2048 } 2119 }
2049 2120
2050 group.DeleteGroupFromScene(silent); 2121 group.DeleteGroupFromScene(silent);
2122 if (!silent)
2123 SendKillObject(new List<uint>() { group.LocalId });
2051 2124
2052// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2125// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2053 } 2126 }
@@ -2402,10 +2475,17 @@ namespace OpenSim.Region.Framework.Scenes
2402 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2475 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2403 public bool AddSceneObject(SceneObjectGroup sceneObject) 2476 public bool AddSceneObject(SceneObjectGroup sceneObject)
2404 { 2477 {
2478 if (sceneObject.OwnerID == UUID.Zero)
2479 {
2480 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2481 return false;
2482 }
2483
2405 // If the user is banned, we won't let any of their objects 2484 // If the user is banned, we won't let any of their objects
2406 // enter. Period. 2485 // enter. Period.
2407 // 2486 //
2408 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2487 int flags = GetUserFlags(sceneObject.OwnerID);
2488 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2409 { 2489 {
2410 m_log.Info("[INTERREGION]: Denied prim crossing for " + 2490 m_log.Info("[INTERREGION]: Denied prim crossing for " +
2411 "banned avatar"); 2491 "banned avatar");
@@ -2452,12 +2532,23 @@ namespace OpenSim.Region.Framework.Scenes
2452 } 2532 }
2453 else 2533 else
2454 { 2534 {
2535 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2455 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2536 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2456 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2537 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2457 } 2538 }
2539 if (sceneObject.OwnerID == UUID.Zero)
2540 {
2541 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2542 return false;
2543 }
2458 } 2544 }
2459 else 2545 else
2460 { 2546 {
2547 if (sceneObject.OwnerID == UUID.Zero)
2548 {
2549 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2550 return false;
2551 }
2461 AddRestoredSceneObject(sceneObject, true, false); 2552 AddRestoredSceneObject(sceneObject, true, false);
2462 2553
2463 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2554 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2487,6 +2578,24 @@ namespace OpenSim.Region.Framework.Scenes
2487 return 2; // StateSource.PrimCrossing 2578 return 2; // StateSource.PrimCrossing
2488 } 2579 }
2489 2580
2581 public int GetUserFlags(UUID user)
2582 {
2583 //Unfortunately the SP approach means that the value is cached until region is restarted
2584 /*
2585 ScenePresence sp;
2586 if (TryGetScenePresence(user, out sp))
2587 {
2588 return sp.UserFlags;
2589 }
2590 else
2591 {
2592 */
2593 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2594 if (uac == null)
2595 return 0;
2596 return uac.UserFlags;
2597 //}
2598 }
2490 #endregion 2599 #endregion
2491 2600
2492 #region Add/Remove Avatar Methods 2601 #region Add/Remove Avatar Methods
@@ -2508,6 +2617,7 @@ namespace OpenSim.Region.Framework.Scenes
2508 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2617 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2509 2618
2510 CheckHeartbeat(); 2619 CheckHeartbeat();
2620 ScenePresence presence;
2511 2621
2512 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here 2622 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here
2513 { 2623 {
@@ -2541,7 +2651,14 @@ namespace OpenSim.Region.Framework.Scenes
2541 2651
2542 EventManager.TriggerOnNewClient(client); 2652 EventManager.TriggerOnNewClient(client);
2543 if (vialogin) 2653 if (vialogin)
2654 {
2544 EventManager.TriggerOnClientLogin(client); 2655 EventManager.TriggerOnClientLogin(client);
2656
2657 // Send initial parcel data
2658 Vector3 pos = createdSp.AbsolutePosition;
2659 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2660 land.SendLandUpdateToClient(client);
2661 }
2545 } 2662 }
2546 } 2663 }
2547 2664
@@ -2630,19 +2747,12 @@ namespace OpenSim.Region.Framework.Scenes
2630 // and the scene presence and the client, if they exist 2747 // and the scene presence and the client, if they exist
2631 try 2748 try
2632 { 2749 {
2633 // We need to wait for the client to make UDP contact first. 2750 ScenePresence sp = GetScenePresence(agentID);
2634 // It's the UDP contact that creates the scene presence 2751 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2635 ScenePresence sp = WaitGetScenePresence(agentID); 2752
2636 if (sp != null) 2753 if (sp != null)
2637 {
2638 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2639
2640 sp.ControllingClient.Close(); 2754 sp.ControllingClient.Close();
2641 } 2755
2642 else
2643 {
2644 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2645 }
2646 // BANG! SLASH! 2756 // BANG! SLASH!
2647 m_authenticateHandler.RemoveCircuit(agentID); 2757 m_authenticateHandler.RemoveCircuit(agentID);
2648 2758
@@ -2742,6 +2852,7 @@ namespace OpenSim.Region.Framework.Scenes
2742 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 2852 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2743 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 2853 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2744 client.OnCopyInventoryItem += CopyInventoryItem; 2854 client.OnCopyInventoryItem += CopyInventoryItem;
2855 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2745 client.OnMoveInventoryItem += MoveInventoryItem; 2856 client.OnMoveInventoryItem += MoveInventoryItem;
2746 client.OnRemoveInventoryItem += RemoveInventoryItem; 2857 client.OnRemoveInventoryItem += RemoveInventoryItem;
2747 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 2858 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2919,15 +3030,16 @@ namespace OpenSim.Region.Framework.Scenes
2919 /// </summary> 3030 /// </summary>
2920 /// <param name="agentId">The avatar's Unique ID</param> 3031 /// <param name="agentId">The avatar's Unique ID</param>
2921 /// <param name="client">The IClientAPI for the client</param> 3032 /// <param name="client">The IClientAPI for the client</param>
2922 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3033 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
2923 { 3034 {
2924 if (m_teleportModule != null) 3035 if (m_teleportModule != null)
2925 m_teleportModule.TeleportHome(agentId, client); 3036 return m_teleportModule.TeleportHome(agentId, client);
2926 else 3037 else
2927 { 3038 {
2928 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3039 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
2929 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3040 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
2930 } 3041 }
3042 return false;
2931 } 3043 }
2932 3044
2933 /// <summary> 3045 /// <summary>
@@ -3019,6 +3131,16 @@ namespace OpenSim.Region.Framework.Scenes
3019 /// <param name="flags"></param> 3131 /// <param name="flags"></param>
3020 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3132 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3021 { 3133 {
3134 //Add half the avatar's height so that the user doesn't fall through prims
3135 ScenePresence presence;
3136 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3137 {
3138 if (presence.Appearance != null)
3139 {
3140 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3141 }
3142 }
3143
3022 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3144 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3023 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3145 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3024 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3146 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3093,8 +3215,9 @@ namespace OpenSim.Region.Framework.Scenes
3093 regions.Remove(RegionInfo.RegionHandle); 3215 regions.Remove(RegionInfo.RegionHandle);
3094 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3216 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3095 } 3217 }
3096 3218 m_log.Debug("[Scene] Beginning ClientClosed");
3097 m_eventManager.TriggerClientClosed(agentID, this); 3219 m_eventManager.TriggerClientClosed(agentID, this);
3220 m_log.Debug("[Scene] Finished ClientClosed");
3098 } 3221 }
3099 catch (NullReferenceException) 3222 catch (NullReferenceException)
3100 { 3223 {
@@ -3102,7 +3225,12 @@ namespace OpenSim.Region.Framework.Scenes
3102 // Avatar is already disposed :/ 3225 // Avatar is already disposed :/
3103 } 3226 }
3104 3227
3228 m_log.Debug("[Scene] Beginning OnRemovePresence");
3105 m_eventManager.TriggerOnRemovePresence(agentID); 3229 m_eventManager.TriggerOnRemovePresence(agentID);
3230 m_log.Debug("[Scene] Finished OnRemovePresence");
3231
3232 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3233 AttachmentsModule.SaveChangedAttachments(avatar);
3106 3234
3107 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc) 3235 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3108 AttachmentsModule.SaveChangedAttachments(avatar); 3236 AttachmentsModule.SaveChangedAttachments(avatar);
@@ -3111,7 +3239,7 @@ namespace OpenSim.Region.Framework.Scenes
3111 delegate(IClientAPI client) 3239 delegate(IClientAPI client)
3112 { 3240 {
3113 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway 3241 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway
3114 try { client.SendKillObject(avatar.RegionHandle, avatar.LocalId); } 3242 try { client.SendKillObject(avatar.RegionHandle, new List<uint>() { avatar.LocalId}); }
3115 catch (NullReferenceException) { } 3243 catch (NullReferenceException) { }
3116 }); 3244 });
3117 3245
@@ -3122,8 +3250,11 @@ namespace OpenSim.Region.Framework.Scenes
3122 } 3250 }
3123 3251
3124 // Remove the avatar from the scene 3252 // Remove the avatar from the scene
3253 m_log.Debug("[Scene] Begin RemoveScenePresence");
3125 m_sceneGraph.RemoveScenePresence(agentID); 3254 m_sceneGraph.RemoveScenePresence(agentID);
3255 m_log.Debug("[Scene] Finished RemoveScenePresence. Removing the client manager");
3126 m_clientManager.Remove(agentID); 3256 m_clientManager.Remove(agentID);
3257 m_log.Debug("[Scene] Removed the client manager. Firing avatar.close");
3127 3258
3128 try 3259 try
3129 { 3260 {
@@ -3137,9 +3268,10 @@ namespace OpenSim.Region.Framework.Scenes
3137 { 3268 {
3138 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3269 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3139 } 3270 }
3140 3271 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3141 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3272 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3142// CleanDroppedAttachments(); 3273// CleanDroppedAttachments();
3274 m_log.Debug("[Scene] The avatar has left the building");
3143 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3275 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3144 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3276 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3145 } 3277 }
@@ -3170,19 +3302,24 @@ namespace OpenSim.Region.Framework.Scenes
3170 3302
3171 #region Entities 3303 #region Entities
3172 3304
3173 public void SendKillObject(uint localID) 3305 public void SendKillObject(List<uint> localIDs)
3174 { 3306 {
3175 SceneObjectPart part = GetSceneObjectPart(localID); 3307 List<uint> deleteIDs = new List<uint>();
3176 if (part != null) // It is a prim 3308
3309 foreach (uint localID in localIDs)
3177 { 3310 {
3178 if (!part.ParentGroup.IsDeleted) // Valid 3311 SceneObjectPart part = GetSceneObjectPart(localID);
3312 if (part != null) // It is a prim
3179 { 3313 {
3180 if (part.ParentGroup.RootPart != part) // Child part 3314 if (part.ParentGroup != null && !part.ParentGroup.IsDeleted) // Valid
3181 return; 3315 {
3316 if (part.ParentGroup.RootPart != part) // Child part
3317 continue;
3318 }
3182 } 3319 }
3320 deleteIDs.Add(localID);
3183 } 3321 }
3184 3322 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, deleteIDs); });
3185 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); });
3186 } 3323 }
3187 3324
3188 #endregion 3325 #endregion
@@ -3200,7 +3337,6 @@ namespace OpenSim.Region.Framework.Scenes
3200 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate; 3337 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3201 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar; 3338 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar;
3202 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3339 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3203 m_sceneGridService.KiPrimitive += SendKillObject;
3204 m_sceneGridService.OnGetLandData += GetLandData; 3340 m_sceneGridService.OnGetLandData += GetLandData;
3205 } 3341 }
3206 3342
@@ -3209,7 +3345,6 @@ namespace OpenSim.Region.Framework.Scenes
3209 /// </summary> 3345 /// </summary>
3210 public void UnRegisterRegionWithComms() 3346 public void UnRegisterRegionWithComms()
3211 { 3347 {
3212 m_sceneGridService.KiPrimitive -= SendKillObject;
3213 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid; 3348 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid;
3214 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar; 3349 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar;
3215 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate; 3350 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
@@ -3289,13 +3424,16 @@ namespace OpenSim.Region.Framework.Scenes
3289 sp = null; 3424 sp = null;
3290 } 3425 }
3291 3426
3292 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3293 3427
3294 //On login test land permisions 3428 //On login test land permisions
3295 if (vialogin) 3429 if (vialogin)
3296 { 3430 {
3297 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3431 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3432 if (cache != null)
3433 cache.Remove(agent.firstname + " " + agent.lastname);
3434 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3298 { 3435 {
3436 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3299 return false; 3437 return false;
3300 } 3438 }
3301 } 3439 }
@@ -3318,8 +3456,13 @@ namespace OpenSim.Region.Framework.Scenes
3318 3456
3319 try 3457 try
3320 { 3458 {
3321 if (!AuthorizeUser(agent, out reason)) 3459 // Always check estate if this is a login. Always
3322 return false; 3460 // check if banned regions are to be blacked out.
3461 if (vialogin || (!m_seeIntoBannedRegion))
3462 {
3463 if (!AuthorizeUser(agent, out reason))
3464 return false;
3465 }
3323 } 3466 }
3324 catch (Exception e) 3467 catch (Exception e)
3325 { 3468 {
@@ -3421,6 +3564,8 @@ namespace OpenSim.Region.Framework.Scenes
3421 } 3564 }
3422 } 3565 }
3423 // Honor parcel landing type and position. 3566 // Honor parcel landing type and position.
3567 /*
3568 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3424 if (land != null) 3569 if (land != null)
3425 { 3570 {
3426 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3571 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3428,26 +3573,34 @@ namespace OpenSim.Region.Framework.Scenes
3428 agent.startpos = land.LandData.UserLocation; 3573 agent.startpos = land.LandData.UserLocation;
3429 } 3574 }
3430 } 3575 }
3576 */// This is now handled properly in ScenePresence.MakeRootAgent
3431 } 3577 }
3432 3578
3433 return true; 3579 return true;
3434 } 3580 }
3435 3581
3436 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3582 private bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3437 { 3583 {
3438 3584 reason = String.Empty;
3439 bool banned = land.IsBannedFromLand(agent.AgentID); 3585 if (Permissions.IsGod(agentID))
3440 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3586 return true;
3587
3588 ILandObject land = LandChannel.GetLandObject(posX, posY);
3589 if (land == null)
3590 return false;
3591
3592 bool banned = land.IsBannedFromLand(agentID);
3593 bool restricted = land.IsRestrictedFromLand(agentID);
3441 3594
3442 if (banned || restricted) 3595 if (banned || restricted)
3443 { 3596 {
3444 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3597 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3445 if (nearestParcel != null) 3598 if (nearestParcel != null)
3446 { 3599 {
3447 //Move agent to nearest allowed 3600 //Move agent to nearest allowed
3448 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3601 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3449 agent.startpos.X = newPosition.X; 3602 posX = newPosition.X;
3450 agent.startpos.Y = newPosition.Y; 3603 posY = newPosition.Y;
3451 } 3604 }
3452 else 3605 else
3453 { 3606 {
@@ -3509,7 +3662,7 @@ namespace OpenSim.Region.Framework.Scenes
3509 3662
3510 if (!m_strictAccessControl) return true; 3663 if (!m_strictAccessControl) return true;
3511 if (Permissions.IsGod(agent.AgentID)) return true; 3664 if (Permissions.IsGod(agent.AgentID)) return true;
3512 3665
3513 if (AuthorizationService != null) 3666 if (AuthorizationService != null)
3514 { 3667 {
3515 if (!AuthorizationService.IsAuthorizedForRegion( 3668 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3517,14 +3670,14 @@ namespace OpenSim.Region.Framework.Scenes
3517 { 3670 {
3518 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region", 3671 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region",
3519 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3672 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
3520 3673
3521 return false; 3674 return false;
3522 } 3675 }
3523 } 3676 }
3524 3677
3525 if (m_regInfo.EstateSettings != null) 3678 if (m_regInfo.EstateSettings != null)
3526 { 3679 {
3527 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3680 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3528 { 3681 {
3529 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3682 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3530 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3683 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3714,6 +3867,13 @@ namespace OpenSim.Region.Framework.Scenes
3714 3867
3715 // We have to wait until the viewer contacts this region after receiving EAC. 3868 // We have to wait until the viewer contacts this region after receiving EAC.
3716 // That calls AddNewClient, which finally creates the ScenePresence 3869 // That calls AddNewClient, which finally creates the ScenePresence
3870 int flags = GetUserFlags(cAgentData.AgentID);
3871 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
3872 {
3873 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
3874 return false;
3875 }
3876
3717 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 3877 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3718 if (nearestParcel == null) 3878 if (nearestParcel == null)
3719 { 3879 {
@@ -3729,7 +3889,6 @@ namespace OpenSim.Region.Framework.Scenes
3729 return false; 3889 return false;
3730 } 3890 }
3731 3891
3732
3733 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID); 3892 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID);
3734 3893
3735 if (childAgentUpdate != null) 3894 if (childAgentUpdate != null)
@@ -3796,12 +3955,22 @@ namespace OpenSim.Region.Framework.Scenes
3796 return false; 3955 return false;
3797 } 3956 }
3798 3957
3958 public bool IncomingCloseAgent(UUID agentID)
3959 {
3960 return IncomingCloseAgent(agentID, false);
3961 }
3962
3963 public bool IncomingCloseChildAgent(UUID agentID)
3964 {
3965 return IncomingCloseAgent(agentID, true);
3966 }
3967
3799 /// <summary> 3968 /// <summary>
3800 /// Tell a single agent to disconnect from the region. 3969 /// Tell a single agent to disconnect from the region.
3801 /// </summary> 3970 /// </summary>
3802 /// <param name="regionHandle"></param>
3803 /// <param name="agentID"></param> 3971 /// <param name="agentID"></param>
3804 public bool IncomingCloseAgent(UUID agentID) 3972 /// <param name="childOnly"></param>
3973 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
3805 { 3974 {
3806 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 3975 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
3807 3976
@@ -3813,7 +3982,7 @@ namespace OpenSim.Region.Framework.Scenes
3813 { 3982 {
3814 m_sceneGraph.removeUserCount(false); 3983 m_sceneGraph.removeUserCount(false);
3815 } 3984 }
3816 else 3985 else if (!childOnly)
3817 { 3986 {
3818 m_sceneGraph.removeUserCount(true); 3987 m_sceneGraph.removeUserCount(true);
3819 } 3988 }
@@ -3829,9 +3998,12 @@ namespace OpenSim.Region.Framework.Scenes
3829 } 3998 }
3830 else 3999 else
3831 presence.ControllingClient.SendShutdownConnectionNotice(); 4000 presence.ControllingClient.SendShutdownConnectionNotice();
4001 presence.ControllingClient.Close(false);
4002 }
4003 else if (!childOnly)
4004 {
4005 presence.ControllingClient.Close(true);
3832 } 4006 }
3833
3834 presence.ControllingClient.Close();
3835 return true; 4007 return true;
3836 } 4008 }
3837 4009
@@ -4446,34 +4618,66 @@ namespace OpenSim.Region.Framework.Scenes
4446 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4618 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4447 } 4619 }
4448 4620
4449 public int GetHealth() 4621 public int GetHealth(out int flags, out string message)
4450 { 4622 {
4451 // Returns: 4623 // Returns:
4452 // 1 = sim is up and accepting http requests. The heartbeat has 4624 // 1 = sim is up and accepting http requests. The heartbeat has
4453 // stopped and the sim is probably locked up, but a remote 4625 // stopped and the sim is probably locked up, but a remote
4454 // admin restart may succeed 4626 // admin restart may succeed
4455 // 4627 //
4456 // 2 = Sim is up and the heartbeat is running. The sim is likely 4628 // 2 = Sim is up and the heartbeat is running. The sim is likely
4457 // usable for people within and logins _may_ work 4629 // usable for people within
4630 //
4631 // 3 = Sim is up and one packet thread is running. Sim is
4632 // unstable and will not accept new logins
4633 //
4634 // 4 = Sim is up and both packet threads are running. Sim is
4635 // likely usable
4458 // 4636 //
4459 // 3 = We have seen a new user enter within the past 4 minutes 4637 // 5 = We have seen a new user enter within the past 4 minutes
4460 // which can be seen as positive confirmation of sim health 4638 // which can be seen as positive confirmation of sim health
4461 // 4639 //
4640
4641 flags = 0;
4642 message = String.Empty;
4643
4644 CheckHeartbeat();
4645
4646 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4647 {
4648 // We're still starting
4649 // 0 means "in startup", it can't happen another way, since
4650 // to get here, we must be able to accept http connections
4651 return 0;
4652 }
4653
4462 int health=1; // Start at 1, means we're up 4654 int health=1; // Start at 1, means we're up
4463 4655
4464 if ((Util.EnvironmentTickCountSubtract(m_lastUpdate)) < 1000) 4656 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) < 1000)
4657 {
4465 health+=1; 4658 health+=1;
4466 else 4659 flags |= 1;
4660 }
4661
4662 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4663 {
4664 health+=1;
4665 flags |= 2;
4666 }
4667
4668 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4669 {
4670 health+=1;
4671 flags |= 4;
4672 }
4673
4674 if (flags != 7)
4467 return health; 4675 return health;
4468 4676
4469 // A login in the last 4 mins? We can't be doing too badly 4677 // A login in the last 4 mins? We can't be doing too badly
4470 // 4678 //
4471 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4679 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4472 health++; 4680 health++;
4473 else
4474 return health;
4475
4476 CheckHeartbeat();
4477 4681
4478 return health; 4682 return health;
4479 } 4683 }
@@ -4666,7 +4870,7 @@ namespace OpenSim.Region.Framework.Scenes
4666 if (m_firstHeartbeat) 4870 if (m_firstHeartbeat)
4667 return; 4871 return;
4668 4872
4669 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4873 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 5000)
4670 StartTimer(); 4874 StartTimer();
4671 } 4875 }
4672 4876
@@ -5115,6 +5319,19 @@ namespace OpenSim.Region.Framework.Scenes
5115// } 5319// }
5116// } 5320// }
5117 5321
5322 public void ThreadAlive(int threadCode)
5323 {
5324 switch(threadCode)
5325 {
5326 case 1: // Incoming
5327 m_lastIncoming = Util.EnvironmentTickCount();
5328 break;
5329 case 2: // Incoming
5330 m_lastOutgoing = Util.EnvironmentTickCount();
5331 break;
5332 }
5333 }
5334
5118 // This method is called across the simulation connector to 5335 // This method is called across the simulation connector to
5119 // determine if a given agent is allowed in this region 5336 // determine if a given agent is allowed in this region
5120 // AS A ROOT AGENT. Returning false here will prevent them 5337 // AS A ROOT AGENT. Returning false here will prevent them
@@ -5123,6 +5340,14 @@ namespace OpenSim.Region.Framework.Scenes
5123 // child agent creation, thereby emulating the SL behavior. 5340 // child agent creation, thereby emulating the SL behavior.
5124 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5341 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5125 { 5342 {
5343 reason = "You are banned from the region";
5344
5345 if (Permissions.IsGod(agentID))
5346 {
5347 reason = String.Empty;
5348 return true;
5349 }
5350
5126 int num = m_sceneGraph.GetNumberOfScenePresences(); 5351 int num = m_sceneGraph.GetNumberOfScenePresences();
5127 5352
5128 if (num >= RegionInfo.RegionSettings.AgentLimit) 5353 if (num >= RegionInfo.RegionSettings.AgentLimit)
@@ -5134,11 +5359,60 @@ namespace OpenSim.Region.Framework.Scenes
5134 } 5359 }
5135 } 5360 }
5136 5361
5362 try
5363 {
5364 if (!AuthorizeUser(GetScenePresence(agentID).ControllingClient.RequestClientInfo(), out reason))
5365 {
5366 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5367 return false;
5368 }
5369 }
5370 catch
5371 {
5372 return false;
5373 }
5374
5375 if (position == Vector3.Zero) // Teleport
5376 {
5377 float posX = 128.0f;
5378 float posY = 128.0f;
5379
5380 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5381 {
5382 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5383 return false;
5384 }
5385 }
5386 else // Walking
5387 {
5388 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5389 if (land == null)
5390 return false;
5391
5392 bool banned = land.IsBannedFromLand(agentID);
5393 bool restricted = land.IsRestrictedFromLand(agentID);
5394
5395 if (banned || restricted)
5396 return false;
5397 }
5398
5137 reason = String.Empty; 5399 reason = String.Empty;
5138 return true; 5400 return true;
5139 } 5401 }
5140 5402
5141 /// <summary> 5403 public void StartTimerWatchdog()
5404 {
5405 m_timerWatchdog.Interval = 1000;
5406 m_timerWatchdog.Elapsed += TimerWatchdog;
5407 m_timerWatchdog.AutoReset = true;
5408 m_timerWatchdog.Start();
5409 }
5410
5411 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5412 {
5413 CheckHeartbeat();
5414 }
5415
5142 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5416 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5143 /// autopilot that moves an avatar to a sit target!. 5417 /// autopilot that moves an avatar to a sit target!.
5144 /// </summary> 5418 /// </summary>