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 e43185d..b2f5279 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -97,6 +97,7 @@ namespace OpenSim.Region.Framework.Scenes
97 // TODO: need to figure out how allow client agents but deny 97 // TODO: need to figure out how allow client agents but deny
98 // root agents when ACL denies access to root agent 98 // root agents when ACL denies access to root agent
99 public bool m_strictAccessControl = true; 99 public bool m_strictAccessControl = true;
100 public bool m_seeIntoBannedRegion = false;
100 public int MaxUndoCount = 5; 101 public int MaxUndoCount = 5;
101 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 102 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
102 public bool LoginLock = false; 103 public bool LoginLock = false;
@@ -112,12 +113,14 @@ namespace OpenSim.Region.Framework.Scenes
112 113
113 protected int m_splitRegionID; 114 protected int m_splitRegionID;
114 protected Timer m_restartWaitTimer = new Timer(); 115 protected Timer m_restartWaitTimer = new Timer();
116 protected Timer m_timerWatchdog = new Timer();
115 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 117 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
116 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 118 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
117 protected string m_simulatorVersion = "OpenSimulator Server"; 119 protected string m_simulatorVersion = "OpenSimulator Server";
118 protected ModuleLoader m_moduleLoader; 120 protected ModuleLoader m_moduleLoader;
119 protected AgentCircuitManager m_authenticateHandler; 121 protected AgentCircuitManager m_authenticateHandler;
120 protected SceneCommunicationService m_sceneGridService; 122 protected SceneCommunicationService m_sceneGridService;
123 protected ISnmpModule m_snmpService = null;
121 124
122 protected ISimulationDataService m_SimulationDataService; 125 protected ISimulationDataService m_SimulationDataService;
123 protected IEstateDataService m_EstateDataService; 126 protected IEstateDataService m_EstateDataService;
@@ -169,7 +172,7 @@ namespace OpenSim.Region.Framework.Scenes
169 private int m_update_events = 1; 172 private int m_update_events = 1;
170 private int m_update_backup = 200; 173 private int m_update_backup = 200;
171 private int m_update_terrain = 50; 174 private int m_update_terrain = 50;
172// private int m_update_land = 1; 175 private int m_update_land = 10;
173 private int m_update_coarse_locations = 50; 176 private int m_update_coarse_locations = 50;
174 177
175 private int agentMS; 178 private int agentMS;
@@ -184,6 +187,7 @@ 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 /// <summary> 191 /// <summary>
188 /// Signals whether temporary objects are currently being cleaned up. Needed because this is launched 192 /// Signals whether temporary objects are currently being cleaned up. Needed because this is launched
189 /// asynchronously from the update loop. 193 /// asynchronously from the update loop.
@@ -206,10 +210,12 @@ namespace OpenSim.Region.Framework.Scenes
206 private bool m_scripts_enabled = true; 210 private bool m_scripts_enabled = true;
207 private string m_defaultScriptEngine; 211 private string m_defaultScriptEngine;
208 private int m_LastLogin; 212 private int m_LastLogin;
209 private Thread HeartbeatThread; 213 private Thread HeartbeatThread = null;
210 private volatile bool shuttingdown; 214 private volatile bool shuttingdown;
211 215
212 private int m_lastUpdate; 216 private int m_lastUpdate;
217 private int m_lastIncoming;
218 private int m_lastOutgoing;
213 private bool m_firstHeartbeat = true; 219 private bool m_firstHeartbeat = true;
214 220
215 private object m_deleting_scene_object = new object(); 221 private object m_deleting_scene_object = new object();
@@ -257,6 +263,19 @@ namespace OpenSim.Region.Framework.Scenes
257 get { return m_sceneGridService; } 263 get { return m_sceneGridService; }
258 } 264 }
259 265
266 public ISnmpModule SnmpService
267 {
268 get
269 {
270 if (m_snmpService == null)
271 {
272 m_snmpService = RequestModuleInterface<ISnmpModule>();
273 }
274
275 return m_snmpService;
276 }
277 }
278
260 public ISimulationDataService SimulationDataService 279 public ISimulationDataService SimulationDataService
261 { 280 {
262 get 281 get
@@ -549,6 +568,9 @@ namespace OpenSim.Region.Framework.Scenes
549 m_EstateDataService = estateDataService; 568 m_EstateDataService = estateDataService;
550 m_regionHandle = m_regInfo.RegionHandle; 569 m_regionHandle = m_regInfo.RegionHandle;
551 m_regionName = m_regInfo.RegionName; 570 m_regionName = m_regInfo.RegionName;
571 m_lastUpdate = Util.EnvironmentTickCount();
572 m_lastIncoming = 0;
573 m_lastOutgoing = 0;
552 574
553 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 575 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
554 m_asyncSceneObjectDeleter.Enabled = true; 576 m_asyncSceneObjectDeleter.Enabled = true;
@@ -670,11 +692,13 @@ namespace OpenSim.Region.Framework.Scenes
670 //Animation states 692 //Animation states
671 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 693 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
672 // TODO: Change default to true once the feature is supported 694 // TODO: Change default to true once the feature is supported
673 m_usePreJump = startupConfig.GetBoolean("enableprejump", false); 695 m_usePreJump = startupConfig.GetBoolean("enableprejump", true);
674 696
675 m_physicalPrim = startupConfig.GetBoolean("physical_prim", true); 697 m_physicalPrim = startupConfig.GetBoolean("physical_prim", true);
676 698
677 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 699 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
700
701 m_log.DebugFormat("[SCENE]: prejump is {0}", m_usePreJump ? "ON" : "OFF");
678 if (RegionInfo.NonphysPrimMax > 0) 702 if (RegionInfo.NonphysPrimMax > 0)
679 { 703 {
680 m_maxNonphys = RegionInfo.NonphysPrimMax; 704 m_maxNonphys = RegionInfo.NonphysPrimMax;
@@ -707,6 +731,7 @@ namespace OpenSim.Region.Framework.Scenes
707 m_persistAfter *= 10000000; 731 m_persistAfter *= 10000000;
708 732
709 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 733 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
734 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
710 735
711 IConfig packetConfig = m_config.Configs["PacketPool"]; 736 IConfig packetConfig = m_config.Configs["PacketPool"];
712 if (packetConfig != null) 737 if (packetConfig != null)
@@ -716,6 +741,8 @@ namespace OpenSim.Region.Framework.Scenes
716 } 741 }
717 742
718 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 743 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
744 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
745 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
719 746
720 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 747 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
721 if (m_generateMaptiles) 748 if (m_generateMaptiles)
@@ -751,9 +778,9 @@ namespace OpenSim.Region.Framework.Scenes
751 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain); 778 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
752 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning); 779 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
753 } 780 }
754 catch 781 catch (Exception e)
755 { 782 {
756 m_log.Warn("[SCENE]: Failed to load StartupConfig"); 783 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
757 } 784 }
758 785
759 #endregion Region Config 786 #endregion Region Config
@@ -1174,7 +1201,9 @@ namespace OpenSim.Region.Framework.Scenes
1174 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1201 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1175 if (HeartbeatThread != null) 1202 if (HeartbeatThread != null)
1176 { 1203 {
1204 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1177 HeartbeatThread.Abort(); 1205 HeartbeatThread.Abort();
1206 Watchdog.AbortThread(HeartbeatThread.ManagedThreadId);
1178 HeartbeatThread = null; 1207 HeartbeatThread = null;
1179 } 1208 }
1180 m_lastUpdate = Util.EnvironmentTickCount(); 1209 m_lastUpdate = Util.EnvironmentTickCount();
@@ -1217,9 +1246,6 @@ namespace OpenSim.Region.Framework.Scenes
1217 { 1246 {
1218 while (!shuttingdown) 1247 while (!shuttingdown)
1219 Update(); 1248 Update();
1220
1221 m_lastUpdate = Util.EnvironmentTickCount();
1222 m_firstHeartbeat = false;
1223 } 1249 }
1224 catch (ThreadAbortException) 1250 catch (ThreadAbortException)
1225 { 1251 {
@@ -1319,6 +1345,13 @@ namespace OpenSim.Region.Framework.Scenes
1319 eventMS = Util.EnvironmentTickCountSubtract(evMS); ; 1345 eventMS = Util.EnvironmentTickCountSubtract(evMS); ;
1320 } 1346 }
1321 1347
1348 // if (Frame % m_update_land == 0)
1349 // {
1350 // int ldMS = Util.EnvironmentTickCount();
1351 // UpdateLand();
1352 // landMS = Util.EnvironmentTickCountSubtract(ldMS);
1353 // }
1354
1322 if (Frame % m_update_backup == 0) 1355 if (Frame % m_update_backup == 0)
1323 { 1356 {
1324 int backMS = Util.EnvironmentTickCount(); 1357 int backMS = Util.EnvironmentTickCount();
@@ -1420,12 +1453,16 @@ namespace OpenSim.Region.Framework.Scenes
1420 maintc = Util.EnvironmentTickCountSubtract(maintc); 1453 maintc = Util.EnvironmentTickCountSubtract(maintc);
1421 maintc = (int)(MinFrameTime * 1000) - maintc; 1454 maintc = (int)(MinFrameTime * 1000) - maintc;
1422 1455
1456
1457 m_lastUpdate = Util.EnvironmentTickCount();
1458 m_firstHeartbeat = false;
1459
1423 if (maintc > 0) 1460 if (maintc > 0)
1424 Thread.Sleep(maintc); 1461 Thread.Sleep(maintc);
1425 1462
1426 // Tell the watchdog that this thread is still alive 1463 // Tell the watchdog that this thread is still alive
1427 Watchdog.UpdateThread(); 1464 Watchdog.UpdateThread();
1428 } 1465 }
1429 1466
1430 public void AddGroupTarget(SceneObjectGroup grp) 1467 public void AddGroupTarget(SceneObjectGroup grp)
1431 { 1468 {
@@ -1441,9 +1478,9 @@ namespace OpenSim.Region.Framework.Scenes
1441 1478
1442 private void CheckAtTargets() 1479 private void CheckAtTargets()
1443 { 1480 {
1444 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1481 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1445 lock (m_groupsWithTargets) 1482 lock (m_groupsWithTargets)
1446 objs = m_groupsWithTargets.Values; 1483 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1447 1484
1448 foreach (SceneObjectGroup entry in objs) 1485 foreach (SceneObjectGroup entry in objs)
1449 entry.checkAtTargets(); 1486 entry.checkAtTargets();
@@ -1763,14 +1800,24 @@ namespace OpenSim.Region.Framework.Scenes
1763 /// <returns></returns> 1800 /// <returns></returns>
1764 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1801 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1765 { 1802 {
1803
1804 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1805 Vector3 wpos = Vector3.Zero;
1806 // Check for water surface intersection from above
1807 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1808 {
1809 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1810 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1811 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1812 wpos.Z = wheight;
1813 }
1814
1766 Vector3 pos = Vector3.Zero; 1815 Vector3 pos = Vector3.Zero;
1767 if (RayEndIsIntersection == (byte)1) 1816 if (RayEndIsIntersection == (byte)1)
1768 { 1817 {
1769 pos = RayEnd; 1818 pos = RayEnd;
1770 return pos;
1771 } 1819 }
1772 1820 else if (RayTargetID != UUID.Zero)
1773 if (RayTargetID != UUID.Zero)
1774 { 1821 {
1775 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1822 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1776 1823
@@ -1792,7 +1839,7 @@ namespace OpenSim.Region.Framework.Scenes
1792 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1839 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1793 1840
1794 // Un-comment out the following line to Get Raytrace results printed to the console. 1841 // Un-comment out the following line to Get Raytrace results printed to the console.
1795 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1842 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1796 float ScaleOffset = 0.5f; 1843 float ScaleOffset = 0.5f;
1797 1844
1798 // If we hit something 1845 // If we hit something
@@ -1815,13 +1862,10 @@ namespace OpenSim.Region.Framework.Scenes
1815 //pos.Z -= 0.25F; 1862 //pos.Z -= 0.25F;
1816 1863
1817 } 1864 }
1818
1819 return pos;
1820 } 1865 }
1821 else 1866 else
1822 { 1867 {
1823 // We don't have a target here, so we're going to raytrace all the objects in the scene. 1868 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1824
1825 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 1869 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1826 1870
1827 // Un-comment the following line to print the raytrace results to the console. 1871 // Un-comment the following line to print the raytrace results to the console.
@@ -1830,13 +1874,12 @@ namespace OpenSim.Region.Framework.Scenes
1830 if (ei.HitTF) 1874 if (ei.HitTF)
1831 { 1875 {
1832 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 1876 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1833 } else 1877 }
1878 else
1834 { 1879 {
1835 // fall back to our stupid functionality 1880 // fall back to our stupid functionality
1836 pos = RayEnd; 1881 pos = RayEnd;
1837 } 1882 }
1838
1839 return pos;
1840 } 1883 }
1841 } 1884 }
1842 else 1885 else
@@ -1847,8 +1890,12 @@ namespace OpenSim.Region.Framework.Scenes
1847 //increase height so its above the ground. 1890 //increase height so its above the ground.
1848 //should be getting the normal of the ground at the rez point and using that? 1891 //should be getting the normal of the ground at the rez point and using that?
1849 pos.Z += scale.Z / 2f; 1892 pos.Z += scale.Z / 2f;
1850 return pos; 1893// return pos;
1851 } 1894 }
1895
1896 // check against posible water intercept
1897 if (wpos.Z > pos.Z) pos = wpos;
1898 return pos;
1852 } 1899 }
1853 1900
1854 1901
@@ -1932,7 +1979,10 @@ namespace OpenSim.Region.Framework.Scenes
1932 public bool AddRestoredSceneObject( 1979 public bool AddRestoredSceneObject(
1933 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 1980 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
1934 { 1981 {
1935 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 1982 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
1983 if (result)
1984 sceneObject.IsDeleted = false;
1985 return result;
1936 } 1986 }
1937 1987
1938 /// <summary> 1988 /// <summary>
@@ -2022,6 +2072,15 @@ namespace OpenSim.Region.Framework.Scenes
2022 /// </summary> 2072 /// </summary>
2023 public void DeleteAllSceneObjects() 2073 public void DeleteAllSceneObjects()
2024 { 2074 {
2075 DeleteAllSceneObjects(false);
2076 }
2077
2078 /// <summary>
2079 /// Delete every object from the scene. This does not include attachments worn by avatars.
2080 /// </summary>
2081 public void DeleteAllSceneObjects(bool exceptNoCopy)
2082 {
2083 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2025 lock (Entities) 2084 lock (Entities)
2026 { 2085 {
2027 EntityBase[] entities = Entities.GetEntities(); 2086 EntityBase[] entities = Entities.GetEntities();
@@ -2030,11 +2089,24 @@ namespace OpenSim.Region.Framework.Scenes
2030 if (e is SceneObjectGroup) 2089 if (e is SceneObjectGroup)
2031 { 2090 {
2032 SceneObjectGroup sog = (SceneObjectGroup)e; 2091 SceneObjectGroup sog = (SceneObjectGroup)e;
2033 if (!sog.IsAttachment) 2092 if (sog != null && !sog.IsAttachment)
2034 DeleteSceneObject((SceneObjectGroup)e, false); 2093 {
2094 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2095 {
2096 DeleteSceneObject((SceneObjectGroup)e, false);
2097 }
2098 else
2099 {
2100 toReturn.Add((SceneObjectGroup)e);
2101 }
2102 }
2035 } 2103 }
2036 } 2104 }
2037 } 2105 }
2106 if (toReturn.Count > 0)
2107 {
2108 returnObjects(toReturn.ToArray(), UUID.Zero);
2109 }
2038 } 2110 }
2039 2111
2040 /// <summary> 2112 /// <summary>
@@ -2082,6 +2154,8 @@ namespace OpenSim.Region.Framework.Scenes
2082 } 2154 }
2083 2155
2084 group.DeleteGroupFromScene(silent); 2156 group.DeleteGroupFromScene(silent);
2157 if (!silent)
2158 SendKillObject(new List<uint>() { group.LocalId });
2085 2159
2086// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2160// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2087 } 2161 }
@@ -2436,10 +2510,17 @@ namespace OpenSim.Region.Framework.Scenes
2436 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2510 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2437 public bool AddSceneObject(SceneObjectGroup sceneObject) 2511 public bool AddSceneObject(SceneObjectGroup sceneObject)
2438 { 2512 {
2513 if (sceneObject.OwnerID == UUID.Zero)
2514 {
2515 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2516 return false;
2517 }
2518
2439 // If the user is banned, we won't let any of their objects 2519 // If the user is banned, we won't let any of their objects
2440 // enter. Period. 2520 // enter. Period.
2441 // 2521 //
2442 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2522 int flags = GetUserFlags(sceneObject.OwnerID);
2523 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2443 { 2524 {
2444 m_log.Info("[INTERREGION]: Denied prim crossing for " + 2525 m_log.Info("[INTERREGION]: Denied prim crossing for " +
2445 "banned avatar"); 2526 "banned avatar");
@@ -2486,12 +2567,23 @@ namespace OpenSim.Region.Framework.Scenes
2486 } 2567 }
2487 else 2568 else
2488 { 2569 {
2570 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2489 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2571 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2490 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2572 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2491 } 2573 }
2574 if (sceneObject.OwnerID == UUID.Zero)
2575 {
2576 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2577 return false;
2578 }
2492 } 2579 }
2493 else 2580 else
2494 { 2581 {
2582 if (sceneObject.OwnerID == UUID.Zero)
2583 {
2584 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2585 return false;
2586 }
2495 AddRestoredSceneObject(sceneObject, true, false); 2587 AddRestoredSceneObject(sceneObject, true, false);
2496 2588
2497 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2589 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2521,6 +2613,24 @@ namespace OpenSim.Region.Framework.Scenes
2521 return 2; // StateSource.PrimCrossing 2613 return 2; // StateSource.PrimCrossing
2522 } 2614 }
2523 2615
2616 public int GetUserFlags(UUID user)
2617 {
2618 //Unfortunately the SP approach means that the value is cached until region is restarted
2619 /*
2620 ScenePresence sp;
2621 if (TryGetScenePresence(user, out sp))
2622 {
2623 return sp.UserFlags;
2624 }
2625 else
2626 {
2627 */
2628 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2629 if (uac == null)
2630 return 0;
2631 return uac.UserFlags;
2632 //}
2633 }
2524 #endregion 2634 #endregion
2525 2635
2526 #region Add/Remove Avatar Methods 2636 #region Add/Remove Avatar Methods
@@ -2542,6 +2652,7 @@ namespace OpenSim.Region.Framework.Scenes
2542 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2652 (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2543 2653
2544 CheckHeartbeat(); 2654 CheckHeartbeat();
2655 ScenePresence presence;
2545 2656
2546 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here 2657 if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here
2547 { 2658 {
@@ -2577,7 +2688,14 @@ namespace OpenSim.Region.Framework.Scenes
2577 2688
2578 EventManager.TriggerOnNewClient(client); 2689 EventManager.TriggerOnNewClient(client);
2579 if (vialogin) 2690 if (vialogin)
2691 {
2580 EventManager.TriggerOnClientLogin(client); 2692 EventManager.TriggerOnClientLogin(client);
2693
2694 // Send initial parcel data
2695 Vector3 pos = createdSp.AbsolutePosition;
2696 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2697 land.SendLandUpdateToClient(client);
2698 }
2581 } 2699 }
2582 } 2700 }
2583 2701
@@ -2666,19 +2784,12 @@ namespace OpenSim.Region.Framework.Scenes
2666 // and the scene presence and the client, if they exist 2784 // and the scene presence and the client, if they exist
2667 try 2785 try
2668 { 2786 {
2669 // We need to wait for the client to make UDP contact first. 2787 ScenePresence sp = GetScenePresence(agentID);
2670 // It's the UDP contact that creates the scene presence 2788 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2671 ScenePresence sp = WaitGetScenePresence(agentID); 2789
2672 if (sp != null) 2790 if (sp != null)
2673 {
2674 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2675
2676 sp.ControllingClient.Close(); 2791 sp.ControllingClient.Close();
2677 } 2792
2678 else
2679 {
2680 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2681 }
2682 // BANG! SLASH! 2793 // BANG! SLASH!
2683 m_authenticateHandler.RemoveCircuit(agentID); 2794 m_authenticateHandler.RemoveCircuit(agentID);
2684 2795
@@ -2778,6 +2889,7 @@ namespace OpenSim.Region.Framework.Scenes
2778 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 2889 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2779 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 2890 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2780 client.OnCopyInventoryItem += CopyInventoryItem; 2891 client.OnCopyInventoryItem += CopyInventoryItem;
2892 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2781 client.OnMoveInventoryItem += MoveInventoryItem; 2893 client.OnMoveInventoryItem += MoveInventoryItem;
2782 client.OnRemoveInventoryItem += RemoveInventoryItem; 2894 client.OnRemoveInventoryItem += RemoveInventoryItem;
2783 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 2895 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2955,15 +3067,16 @@ namespace OpenSim.Region.Framework.Scenes
2955 /// </summary> 3067 /// </summary>
2956 /// <param name="agentId">The avatar's Unique ID</param> 3068 /// <param name="agentId">The avatar's Unique ID</param>
2957 /// <param name="client">The IClientAPI for the client</param> 3069 /// <param name="client">The IClientAPI for the client</param>
2958 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3070 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
2959 { 3071 {
2960 if (m_teleportModule != null) 3072 if (m_teleportModule != null)
2961 m_teleportModule.TeleportHome(agentId, client); 3073 return m_teleportModule.TeleportHome(agentId, client);
2962 else 3074 else
2963 { 3075 {
2964 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3076 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
2965 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3077 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
2966 } 3078 }
3079 return false;
2967 } 3080 }
2968 3081
2969 /// <summary> 3082 /// <summary>
@@ -3055,6 +3168,16 @@ namespace OpenSim.Region.Framework.Scenes
3055 /// <param name="flags"></param> 3168 /// <param name="flags"></param>
3056 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3169 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3057 { 3170 {
3171 //Add half the avatar's height so that the user doesn't fall through prims
3172 ScenePresence presence;
3173 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3174 {
3175 if (presence.Appearance != null)
3176 {
3177 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3178 }
3179 }
3180
3058 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3181 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3059 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3182 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3060 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3183 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3123,8 +3246,9 @@ namespace OpenSim.Region.Framework.Scenes
3123 regions.Remove(RegionInfo.RegionHandle); 3246 regions.Remove(RegionInfo.RegionHandle);
3124 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3247 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3125 } 3248 }
3126 3249 m_log.Debug("[Scene] Beginning ClientClosed");
3127 m_eventManager.TriggerClientClosed(agentID, this); 3250 m_eventManager.TriggerClientClosed(agentID, this);
3251 m_log.Debug("[Scene] Finished ClientClosed");
3128 } 3252 }
3129 catch (NullReferenceException) 3253 catch (NullReferenceException)
3130 { 3254 {
@@ -3132,7 +3256,12 @@ namespace OpenSim.Region.Framework.Scenes
3132 // Avatar is already disposed :/ 3256 // Avatar is already disposed :/
3133 } 3257 }
3134 3258
3259 m_log.Debug("[Scene] Beginning OnRemovePresence");
3135 m_eventManager.TriggerOnRemovePresence(agentID); 3260 m_eventManager.TriggerOnRemovePresence(agentID);
3261 m_log.Debug("[Scene] Finished OnRemovePresence");
3262
3263 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3264 AttachmentsModule.SaveChangedAttachments(avatar);
3136 3265
3137 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc) 3266 if (AttachmentsModule != null && !avatar.IsChildAgent && avatar.PresenceType != PresenceType.Npc)
3138 AttachmentsModule.SaveChangedAttachments(avatar); 3267 AttachmentsModule.SaveChangedAttachments(avatar);
@@ -3141,7 +3270,7 @@ namespace OpenSim.Region.Framework.Scenes
3141 delegate(IClientAPI client) 3270 delegate(IClientAPI client)
3142 { 3271 {
3143 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway 3272 //We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway
3144 try { client.SendKillObject(avatar.RegionHandle, avatar.LocalId); } 3273 try { client.SendKillObject(avatar.RegionHandle, new List<uint>() { avatar.LocalId}); }
3145 catch (NullReferenceException) { } 3274 catch (NullReferenceException) { }
3146 }); 3275 });
3147 3276
@@ -3152,8 +3281,11 @@ namespace OpenSim.Region.Framework.Scenes
3152 } 3281 }
3153 3282
3154 // Remove the avatar from the scene 3283 // Remove the avatar from the scene
3284 m_log.Debug("[Scene] Begin RemoveScenePresence");
3155 m_sceneGraph.RemoveScenePresence(agentID); 3285 m_sceneGraph.RemoveScenePresence(agentID);
3286 m_log.Debug("[Scene] Finished RemoveScenePresence. Removing the client manager");
3156 m_clientManager.Remove(agentID); 3287 m_clientManager.Remove(agentID);
3288 m_log.Debug("[Scene] Removed the client manager. Firing avatar.close");
3157 3289
3158 try 3290 try
3159 { 3291 {
@@ -3167,9 +3299,10 @@ namespace OpenSim.Region.Framework.Scenes
3167 { 3299 {
3168 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3300 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3169 } 3301 }
3170 3302 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3171 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3303 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3172// CleanDroppedAttachments(); 3304// CleanDroppedAttachments();
3305 m_log.Debug("[Scene] The avatar has left the building");
3173 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3306 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3174 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3307 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3175 } 3308 }
@@ -3200,19 +3333,24 @@ namespace OpenSim.Region.Framework.Scenes
3200 3333
3201 #region Entities 3334 #region Entities
3202 3335
3203 public void SendKillObject(uint localID) 3336 public void SendKillObject(List<uint> localIDs)
3204 { 3337 {
3205 SceneObjectPart part = GetSceneObjectPart(localID); 3338 List<uint> deleteIDs = new List<uint>();
3206 if (part != null) // It is a prim 3339
3340 foreach (uint localID in localIDs)
3207 { 3341 {
3208 if (!part.ParentGroup.IsDeleted) // Valid 3342 SceneObjectPart part = GetSceneObjectPart(localID);
3343 if (part != null) // It is a prim
3209 { 3344 {
3210 if (part.ParentGroup.RootPart != part) // Child part 3345 if (part.ParentGroup != null && !part.ParentGroup.IsDeleted) // Valid
3211 return; 3346 {
3347 if (part.ParentGroup.RootPart != part) // Child part
3348 continue;
3349 }
3212 } 3350 }
3351 deleteIDs.Add(localID);
3213 } 3352 }
3214 3353 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, deleteIDs); });
3215 ForEachClient(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); });
3216 } 3354 }
3217 3355
3218 #endregion 3356 #endregion
@@ -3230,7 +3368,6 @@ namespace OpenSim.Region.Framework.Scenes
3230 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate; 3368 //m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3231 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar; 3369 //m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar;
3232 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3370 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3233 m_sceneGridService.KiPrimitive += SendKillObject;
3234 m_sceneGridService.OnGetLandData += GetLandData; 3371 m_sceneGridService.OnGetLandData += GetLandData;
3235 } 3372 }
3236 3373
@@ -3239,7 +3376,6 @@ namespace OpenSim.Region.Framework.Scenes
3239 /// </summary> 3376 /// </summary>
3240 public void UnRegisterRegionWithComms() 3377 public void UnRegisterRegionWithComms()
3241 { 3378 {
3242 m_sceneGridService.KiPrimitive -= SendKillObject;
3243 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid; 3379 m_sceneGridService.OnLogOffUser -= HandleLogOffUserFromGrid;
3244 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar; 3380 //m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar;
3245 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate; 3381 //m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
@@ -3319,13 +3455,16 @@ namespace OpenSim.Region.Framework.Scenes
3319 sp = null; 3455 sp = null;
3320 } 3456 }
3321 3457
3322 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3323 3458
3324 //On login test land permisions 3459 //On login test land permisions
3325 if (vialogin) 3460 if (vialogin)
3326 { 3461 {
3327 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3462 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3463 if (cache != null)
3464 cache.Remove(agent.firstname + " " + agent.lastname);
3465 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3328 { 3466 {
3467 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3329 return false; 3468 return false;
3330 } 3469 }
3331 } 3470 }
@@ -3348,8 +3487,13 @@ namespace OpenSim.Region.Framework.Scenes
3348 3487
3349 try 3488 try
3350 { 3489 {
3351 if (!AuthorizeUser(agent, out reason)) 3490 // Always check estate if this is a login. Always
3352 return false; 3491 // check if banned regions are to be blacked out.
3492 if (vialogin || (!m_seeIntoBannedRegion))
3493 {
3494 if (!AuthorizeUser(agent, out reason))
3495 return false;
3496 }
3353 } 3497 }
3354 catch (Exception e) 3498 catch (Exception e)
3355 { 3499 {
@@ -3451,6 +3595,8 @@ namespace OpenSim.Region.Framework.Scenes
3451 } 3595 }
3452 } 3596 }
3453 // Honor parcel landing type and position. 3597 // Honor parcel landing type and position.
3598 /*
3599 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3454 if (land != null) 3600 if (land != null)
3455 { 3601 {
3456 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3602 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3458,26 +3604,34 @@ namespace OpenSim.Region.Framework.Scenes
3458 agent.startpos = land.LandData.UserLocation; 3604 agent.startpos = land.LandData.UserLocation;
3459 } 3605 }
3460 } 3606 }
3607 */// This is now handled properly in ScenePresence.MakeRootAgent
3461 } 3608 }
3462 3609
3463 return true; 3610 return true;
3464 } 3611 }
3465 3612
3466 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3613 private bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3467 { 3614 {
3468 3615 reason = String.Empty;
3469 bool banned = land.IsBannedFromLand(agent.AgentID); 3616 if (Permissions.IsGod(agentID))
3470 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3617 return true;
3618
3619 ILandObject land = LandChannel.GetLandObject(posX, posY);
3620 if (land == null)
3621 return false;
3622
3623 bool banned = land.IsBannedFromLand(agentID);
3624 bool restricted = land.IsRestrictedFromLand(agentID);
3471 3625
3472 if (banned || restricted) 3626 if (banned || restricted)
3473 { 3627 {
3474 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3628 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3475 if (nearestParcel != null) 3629 if (nearestParcel != null)
3476 { 3630 {
3477 //Move agent to nearest allowed 3631 //Move agent to nearest allowed
3478 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3632 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3479 agent.startpos.X = newPosition.X; 3633 posX = newPosition.X;
3480 agent.startpos.Y = newPosition.Y; 3634 posY = newPosition.Y;
3481 } 3635 }
3482 else 3636 else
3483 { 3637 {
@@ -3539,7 +3693,7 @@ namespace OpenSim.Region.Framework.Scenes
3539 3693
3540 if (!m_strictAccessControl) return true; 3694 if (!m_strictAccessControl) return true;
3541 if (Permissions.IsGod(agent.AgentID)) return true; 3695 if (Permissions.IsGod(agent.AgentID)) return true;
3542 3696
3543 if (AuthorizationService != null) 3697 if (AuthorizationService != null)
3544 { 3698 {
3545 if (!AuthorizationService.IsAuthorizedForRegion( 3699 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3547,14 +3701,14 @@ namespace OpenSim.Region.Framework.Scenes
3547 { 3701 {
3548 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region", 3702 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access to the region",
3549 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3703 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
3550 3704
3551 return false; 3705 return false;
3552 } 3706 }
3553 } 3707 }
3554 3708
3555 if (m_regInfo.EstateSettings != null) 3709 if (m_regInfo.EstateSettings != null)
3556 { 3710 {
3557 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3711 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3558 { 3712 {
3559 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3713 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3560 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3714 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3744,6 +3898,13 @@ namespace OpenSim.Region.Framework.Scenes
3744 3898
3745 // We have to wait until the viewer contacts this region after receiving EAC. 3899 // We have to wait until the viewer contacts this region after receiving EAC.
3746 // That calls AddNewClient, which finally creates the ScenePresence 3900 // That calls AddNewClient, which finally creates the ScenePresence
3901 int flags = GetUserFlags(cAgentData.AgentID);
3902 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
3903 {
3904 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
3905 return false;
3906 }
3907
3747 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 3908 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3748 if (nearestParcel == null) 3909 if (nearestParcel == null)
3749 { 3910 {
@@ -3759,7 +3920,6 @@ namespace OpenSim.Region.Framework.Scenes
3759 return false; 3920 return false;
3760 } 3921 }
3761 3922
3762
3763 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID); 3923 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID);
3764 3924
3765 if (childAgentUpdate != null) 3925 if (childAgentUpdate != null)
@@ -3826,12 +3986,22 @@ namespace OpenSim.Region.Framework.Scenes
3826 return false; 3986 return false;
3827 } 3987 }
3828 3988
3989 public bool IncomingCloseAgent(UUID agentID)
3990 {
3991 return IncomingCloseAgent(agentID, false);
3992 }
3993
3994 public bool IncomingCloseChildAgent(UUID agentID)
3995 {
3996 return IncomingCloseAgent(agentID, true);
3997 }
3998
3829 /// <summary> 3999 /// <summary>
3830 /// Tell a single agent to disconnect from the region. 4000 /// Tell a single agent to disconnect from the region.
3831 /// </summary> 4001 /// </summary>
3832 /// <param name="regionHandle"></param>
3833 /// <param name="agentID"></param> 4002 /// <param name="agentID"></param>
3834 public bool IncomingCloseAgent(UUID agentID) 4003 /// <param name="childOnly"></param>
4004 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
3835 { 4005 {
3836 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 4006 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
3837 4007
@@ -3843,7 +4013,7 @@ namespace OpenSim.Region.Framework.Scenes
3843 { 4013 {
3844 m_sceneGraph.removeUserCount(false); 4014 m_sceneGraph.removeUserCount(false);
3845 } 4015 }
3846 else 4016 else if (!childOnly)
3847 { 4017 {
3848 m_sceneGraph.removeUserCount(true); 4018 m_sceneGraph.removeUserCount(true);
3849 } 4019 }
@@ -3859,9 +4029,12 @@ namespace OpenSim.Region.Framework.Scenes
3859 } 4029 }
3860 else 4030 else
3861 presence.ControllingClient.SendShutdownConnectionNotice(); 4031 presence.ControllingClient.SendShutdownConnectionNotice();
4032 presence.ControllingClient.Close(false);
4033 }
4034 else if (!childOnly)
4035 {
4036 presence.ControllingClient.Close(true);
3862 } 4037 }
3863
3864 presence.ControllingClient.Close();
3865 return true; 4038 return true;
3866 } 4039 }
3867 4040
@@ -4476,34 +4649,66 @@ namespace OpenSim.Region.Framework.Scenes
4476 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4649 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4477 } 4650 }
4478 4651
4479 public int GetHealth() 4652 public int GetHealth(out int flags, out string message)
4480 { 4653 {
4481 // Returns: 4654 // Returns:
4482 // 1 = sim is up and accepting http requests. The heartbeat has 4655 // 1 = sim is up and accepting http requests. The heartbeat has
4483 // stopped and the sim is probably locked up, but a remote 4656 // stopped and the sim is probably locked up, but a remote
4484 // admin restart may succeed 4657 // admin restart may succeed
4485 // 4658 //
4486 // 2 = Sim is up and the heartbeat is running. The sim is likely 4659 // 2 = Sim is up and the heartbeat is running. The sim is likely
4487 // usable for people within and logins _may_ work 4660 // usable for people within
4488 // 4661 //
4489 // 3 = We have seen a new user enter within the past 4 minutes 4662 // 3 = Sim is up and one packet thread is running. Sim is
4663 // unstable and will not accept new logins
4664 //
4665 // 4 = Sim is up and both packet threads are running. Sim is
4666 // likely usable
4667 //
4668 // 5 = We have seen a new user enter within the past 4 minutes
4490 // which can be seen as positive confirmation of sim health 4669 // which can be seen as positive confirmation of sim health
4491 // 4670 //
4671
4672 flags = 0;
4673 message = String.Empty;
4674
4675 CheckHeartbeat();
4676
4677 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4678 {
4679 // We're still starting
4680 // 0 means "in startup", it can't happen another way, since
4681 // to get here, we must be able to accept http connections
4682 return 0;
4683 }
4684
4492 int health=1; // Start at 1, means we're up 4685 int health=1; // Start at 1, means we're up
4493 4686
4494 if ((Util.EnvironmentTickCountSubtract(m_lastUpdate)) < 1000) 4687 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) < 1000)
4688 {
4495 health+=1; 4689 health+=1;
4496 else 4690 flags |= 1;
4691 }
4692
4693 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4694 {
4695 health+=1;
4696 flags |= 2;
4697 }
4698
4699 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4700 {
4701 health+=1;
4702 flags |= 4;
4703 }
4704
4705 if (flags != 7)
4497 return health; 4706 return health;
4498 4707
4499 // A login in the last 4 mins? We can't be doing too badly 4708 // A login in the last 4 mins? We can't be doing too badly
4500 // 4709 //
4501 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4710 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4502 health++; 4711 health++;
4503 else
4504 return health;
4505
4506 CheckHeartbeat();
4507 4712
4508 return health; 4713 return health;
4509 } 4714 }
@@ -4696,7 +4901,7 @@ namespace OpenSim.Region.Framework.Scenes
4696 if (m_firstHeartbeat) 4901 if (m_firstHeartbeat)
4697 return; 4902 return;
4698 4903
4699 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4904 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 5000)
4700 StartTimer(); 4905 StartTimer();
4701 } 4906 }
4702 4907
@@ -5110,6 +5315,54 @@ namespace OpenSim.Region.Framework.Scenes
5110 } 5315 }
5111 } 5316 }
5112 5317
5318// public void CleanDroppedAttachments()
5319// {
5320// List<SceneObjectGroup> objectsToDelete =
5321// new List<SceneObjectGroup>();
5322//
5323// lock (m_cleaningAttachments)
5324// {
5325// ForEachSOG(delegate (SceneObjectGroup grp)
5326// {
5327// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5328// {
5329// UUID agentID = grp.OwnerID;
5330// if (agentID == UUID.Zero)
5331// {
5332// objectsToDelete.Add(grp);
5333// return;
5334// }
5335//
5336// ScenePresence sp = GetScenePresence(agentID);
5337// if (sp == null)
5338// {
5339// objectsToDelete.Add(grp);
5340// return;
5341// }
5342// }
5343// });
5344// }
5345//
5346// foreach (SceneObjectGroup grp in objectsToDelete)
5347// {
5348// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5349// DeleteSceneObject(grp, true);
5350// }
5351// }
5352
5353 public void ThreadAlive(int threadCode)
5354 {
5355 switch(threadCode)
5356 {
5357 case 1: // Incoming
5358 m_lastIncoming = Util.EnvironmentTickCount();
5359 break;
5360 case 2: // Incoming
5361 m_lastOutgoing = Util.EnvironmentTickCount();
5362 break;
5363 }
5364 }
5365
5113 // This method is called across the simulation connector to 5366 // This method is called across the simulation connector to
5114 // determine if a given agent is allowed in this region 5367 // determine if a given agent is allowed in this region
5115 // AS A ROOT AGENT. Returning false here will prevent them 5368 // AS A ROOT AGENT. Returning false here will prevent them
@@ -5118,6 +5371,14 @@ namespace OpenSim.Region.Framework.Scenes
5118 // child agent creation, thereby emulating the SL behavior. 5371 // child agent creation, thereby emulating the SL behavior.
5119 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5372 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5120 { 5373 {
5374 reason = "You are banned from the region";
5375
5376 if (Permissions.IsGod(agentID))
5377 {
5378 reason = String.Empty;
5379 return true;
5380 }
5381
5121 int num = m_sceneGraph.GetNumberOfScenePresences(); 5382 int num = m_sceneGraph.GetNumberOfScenePresences();
5122 5383
5123 if (num >= RegionInfo.RegionSettings.AgentLimit) 5384 if (num >= RegionInfo.RegionSettings.AgentLimit)
@@ -5129,11 +5390,82 @@ namespace OpenSim.Region.Framework.Scenes
5129 } 5390 }
5130 } 5391 }
5131 5392
5393 ScenePresence presence = GetScenePresence(agentID);
5394 IClientAPI client = null;
5395 AgentCircuitData aCircuit = null;
5396
5397 if (presence != null)
5398 {
5399 client = presence.ControllingClient;
5400 if (client != null)
5401 aCircuit = client.RequestClientInfo();
5402 }
5403
5404 // We may be called before there is a presence or a client.
5405 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5406 if (client == null)
5407 {
5408 aCircuit = new AgentCircuitData();
5409 aCircuit.AgentID = agentID;
5410 aCircuit.firstname = String.Empty;
5411 aCircuit.lastname = String.Empty;
5412 }
5413
5414 try
5415 {
5416 if (!AuthorizeUser(aCircuit, out reason))
5417 {
5418 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5419 return false;
5420 }
5421 }
5422 catch (Exception e)
5423 {
5424 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5425 return false;
5426 }
5427
5428 if (position == Vector3.Zero) // Teleport
5429 {
5430 float posX = 128.0f;
5431 float posY = 128.0f;
5432
5433 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5434 {
5435 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5436 return false;
5437 }
5438 }
5439 else // Walking
5440 {
5441 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5442 if (land == null)
5443 return false;
5444
5445 bool banned = land.IsBannedFromLand(agentID);
5446 bool restricted = land.IsRestrictedFromLand(agentID);
5447
5448 if (banned || restricted)
5449 return false;
5450 }
5451
5132 reason = String.Empty; 5452 reason = String.Empty;
5133 return true; 5453 return true;
5134 } 5454 }
5135 5455
5136 /// <summary> 5456 public void StartTimerWatchdog()
5457 {
5458 m_timerWatchdog.Interval = 1000;
5459 m_timerWatchdog.Elapsed += TimerWatchdog;
5460 m_timerWatchdog.AutoReset = true;
5461 m_timerWatchdog.Start();
5462 }
5463
5464 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5465 {
5466 CheckHeartbeat();
5467 }
5468
5137 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5469 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5138 /// autopilot that moves an avatar to a sit target!. 5470 /// autopilot that moves an avatar to a sit target!.
5139 /// </summary> 5471 /// </summary>