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.cs702
1 files changed, 538 insertions, 164 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 17503b1..a77f26b 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -124,6 +124,7 @@ namespace OpenSim.Region.Framework.Scenes
124 // TODO: need to figure out how allow client agents but deny 124 // TODO: need to figure out how allow client agents but deny
125 // root agents when ACL denies access to root agent 125 // root agents when ACL denies access to root agent
126 public bool m_strictAccessControl = true; 126 public bool m_strictAccessControl = true;
127 public bool m_seeIntoBannedRegion = false;
127 public int MaxUndoCount = 5; 128 public int MaxUndoCount = 5;
128 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 129 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
129 public bool LoginLock = false; 130 public bool LoginLock = false;
@@ -139,12 +140,14 @@ namespace OpenSim.Region.Framework.Scenes
139 140
140 protected int m_splitRegionID; 141 protected int m_splitRegionID;
141 protected Timer m_restartWaitTimer = new Timer(); 142 protected Timer m_restartWaitTimer = new Timer();
143 protected Timer m_timerWatchdog = new Timer();
142 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 144 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
143 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 145 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
144 protected string m_simulatorVersion = "OpenSimulator Server"; 146 protected string m_simulatorVersion = "OpenSimulator Server";
145 protected ModuleLoader m_moduleLoader; 147 protected ModuleLoader m_moduleLoader;
146 protected AgentCircuitManager m_authenticateHandler; 148 protected AgentCircuitManager m_authenticateHandler;
147 protected SceneCommunicationService m_sceneGridService; 149 protected SceneCommunicationService m_sceneGridService;
150 protected ISnmpModule m_snmpService = null;
148 151
149 protected ISimulationDataService m_SimulationDataService; 152 protected ISimulationDataService m_SimulationDataService;
150 protected IEstateDataService m_EstateDataService; 153 protected IEstateDataService m_EstateDataService;
@@ -206,7 +209,7 @@ namespace OpenSim.Region.Framework.Scenes
206 private int m_update_events = 1; 209 private int m_update_events = 1;
207 private int m_update_backup = 200; 210 private int m_update_backup = 200;
208 private int m_update_terrain = 50; 211 private int m_update_terrain = 50;
209// private int m_update_land = 1; 212 private int m_update_land = 10;
210 private int m_update_coarse_locations = 50; 213 private int m_update_coarse_locations = 50;
211 214
212 private int agentMS; 215 private int agentMS;
@@ -226,6 +229,7 @@ namespace OpenSim.Region.Framework.Scenes
226 /// </summary> 229 /// </summary>
227 private int m_lastFrameTick; 230 private int m_lastFrameTick;
228 231
232 public bool CombineRegions = false;
229 /// <summary> 233 /// <summary>
230 /// Tick at which the last maintenance run occurred. 234 /// Tick at which the last maintenance run occurred.
231 /// </summary> 235 /// </summary>
@@ -256,6 +260,11 @@ namespace OpenSim.Region.Framework.Scenes
256 /// </summary> 260 /// </summary>
257 private int m_LastLogin; 261 private int m_LastLogin;
258 262
263 private int m_lastIncoming;
264 private int m_lastOutgoing;
265 private int m_hbRestarts = 0;
266
267
259 /// <summary> 268 /// <summary>
260 /// Thread that runs the scene loop. 269 /// Thread that runs the scene loop.
261 /// </summary> 270 /// </summary>
@@ -271,7 +280,7 @@ namespace OpenSim.Region.Framework.Scenes
271 private volatile bool m_shuttingDown; 280 private volatile bool m_shuttingDown;
272 281
273// private int m_lastUpdate; 282// private int m_lastUpdate;
274// private bool m_firstHeartbeat = true; 283 private bool m_firstHeartbeat = true;
275 284
276 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time; 285 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
277 private bool m_reprioritizationEnabled = true; 286 private bool m_reprioritizationEnabled = true;
@@ -316,6 +325,19 @@ namespace OpenSim.Region.Framework.Scenes
316 get { return m_sceneGridService; } 325 get { return m_sceneGridService; }
317 } 326 }
318 327
328 public ISnmpModule SnmpService
329 {
330 get
331 {
332 if (m_snmpService == null)
333 {
334 m_snmpService = RequestModuleInterface<ISnmpModule>();
335 }
336
337 return m_snmpService;
338 }
339 }
340
319 public ISimulationDataService SimulationDataService 341 public ISimulationDataService SimulationDataService
320 { 342 {
321 get 343 get
@@ -615,6 +637,8 @@ namespace OpenSim.Region.Framework.Scenes
615 m_EstateDataService = estateDataService; 637 m_EstateDataService = estateDataService;
616 m_regionHandle = m_regInfo.RegionHandle; 638 m_regionHandle = m_regInfo.RegionHandle;
617 m_regionName = m_regInfo.RegionName; 639 m_regionName = m_regInfo.RegionName;
640 m_lastIncoming = 0;
641 m_lastOutgoing = 0;
618 642
619 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 643 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
620 m_asyncSceneObjectDeleter.Enabled = true; 644 m_asyncSceneObjectDeleter.Enabled = true;
@@ -695,102 +719,111 @@ namespace OpenSim.Region.Framework.Scenes
695 719
696 // Region config overrides global config 720 // Region config overrides global config
697 // 721 //
698 if (m_config.Configs["Startup"] != null) 722 try
699 { 723 {
700 IConfig startupConfig = m_config.Configs["Startup"]; 724 if (m_config.Configs["Startup"] != null)
701
702 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance);
703 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
704 if (!m_useBackup)
705 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
706
707 //Animation states
708 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
709
710 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims);
711 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims);
712
713 m_maxNonphys = startupConfig.GetFloat("NonphysicalPrimMax", m_maxNonphys);
714 if (RegionInfo.NonphysPrimMax > 0)
715 { 725 {
716 m_maxNonphys = RegionInfo.NonphysPrimMax; 726 IConfig startupConfig = m_config.Configs["Startup"];
717 }
718
719 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
720 727
721 if (RegionInfo.PhysPrimMax > 0) 728 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
722 { 729 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
723 m_maxPhys = RegionInfo.PhysPrimMax; 730 if (!m_useBackup)
724 } 731 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
732
733 //Animation states
734 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
725 735
726 // Here, if clamping is requested in either global or 736 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
727 // local config, it will be used 737 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
728 //
729 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
730 if (RegionInfo.ClampPrimSize)
731 {
732 m_clampPrimSize = true;
733 }
734 738
735 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete); 739 m_maxNonphys = startupConfig.GetFloat("NonphysicalPrimMax", m_maxNonphys);
736 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 740 if (RegionInfo.NonphysPrimMax > 0)
737 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 741 {
738 m_dontPersistBefore = 742 m_maxNonphys = RegionInfo.NonphysPrimMax;
739 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE); 743 }
740 m_dontPersistBefore *= 10000000;
741 m_persistAfter =
742 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
743 m_persistAfter *= 10000000;
744 744
745 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 745 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
746 746
747 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest"); 747 if (RegionInfo.PhysPrimMax > 0)
748 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false); 748 {
749 m_maxPhys = RegionInfo.PhysPrimMax;
750 }
749 751
750 IConfig packetConfig = m_config.Configs["PacketPool"]; 752 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
751 if (packetConfig != null) 753 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
752 {
753 PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true);
754 PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true);
755 }
756 754
757 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 755 // Here, if clamping is requested in either global or
756 // local config, it will be used
757 //
758 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
759 if (RegionInfo.ClampPrimSize)
760 {
761 m_clampPrimSize = true;
762 }
758 763
759 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 764 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
760 if (m_generateMaptiles) 765 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
761 { 766 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
762 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0); 767 m_dontPersistBefore =
763 if (maptileRefresh != 0) 768 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE);
769 m_dontPersistBefore *= 10000000;
770 m_persistAfter =
771 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
772 m_persistAfter *= 10000000;
773
774 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
775 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
776
777 IConfig packetConfig = m_config.Configs["PacketPool"];
778 if (packetConfig != null)
764 { 779 {
765 m_mapGenerationTimer.Interval = maptileRefresh * 1000; 780 PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true);
766 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister; 781 PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true);
767 m_mapGenerationTimer.AutoReset = true;
768 m_mapGenerationTimer.Start();
769 } 782 }
770 }
771 else
772 {
773 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
774 UUID tileID;
775 783
776 if (UUID.TryParse(tile, out tileID)) 784 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
785 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
786 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
787
788 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
789 if (m_generateMaptiles)
777 { 790 {
778 RegionInfo.RegionSettings.TerrainImageID = tileID; 791 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0);
792 if (maptileRefresh != 0)
793 {
794 m_mapGenerationTimer.Interval = maptileRefresh * 1000;
795 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
796 m_mapGenerationTimer.AutoReset = true;
797 m_mapGenerationTimer.Start();
798 }
779 } 799 }
780 } 800 else
801 {
802 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
803 UUID tileID;
781 804
782 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime); 805 if (UUID.TryParse(tile, out tileID))
783 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup); 806 {
784 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations); 807 RegionInfo.RegionSettings.TerrainImageID = tileID;
785 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement); 808 }
786 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events); 809 }
787 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
788 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
789 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
790 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
791 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
792 810
793 SendPeriodicAppearanceUpdates = startupConfig.GetBoolean("SendPeriodicAppearanceUpdates", SendPeriodicAppearanceUpdates); 811 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime);
812 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup);
813 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations);
814 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement);
815 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events);
816 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
817 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
818 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
819 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
820 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
821 SendPeriodicAppearanceUpdates = startupConfig.GetBoolean("SendPeriodicAppearanceUpdates", SendPeriodicAppearanceUpdates);
822 }
823 }
824 catch (Exception e)
825 {
826 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
794 } 827 }
795 828
796 #endregion Region Config 829 #endregion Region Config
@@ -1217,7 +1250,22 @@ namespace OpenSim.Region.Framework.Scenes
1217 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1250 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1218 if (m_heartbeatThread != null) 1251 if (m_heartbeatThread != null)
1219 { 1252 {
1253 m_hbRestarts++;
1254 if(m_hbRestarts > 10)
1255 Environment.Exit(1);
1256 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1257
1258//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1259//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1260//proc.EnableRaisingEvents=false;
1261//proc.StartInfo.FileName = "/bin/kill";
1262//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1263//proc.Start();
1264//proc.WaitForExit();
1265//Thread.Sleep(1000);
1266//Environment.Exit(1);
1220 m_heartbeatThread.Abort(); 1267 m_heartbeatThread.Abort();
1268 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1221 m_heartbeatThread = null; 1269 m_heartbeatThread = null;
1222 } 1270 }
1223// m_lastUpdate = Util.EnvironmentTickCount(); 1271// m_lastUpdate = Util.EnvironmentTickCount();
@@ -1507,6 +1555,8 @@ namespace OpenSim.Region.Framework.Scenes
1507 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1555 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc);
1508 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1556 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1509 1557
1558 m_firstHeartbeat = false;
1559
1510 if (tmpMS > 0) 1560 if (tmpMS > 0)
1511 { 1561 {
1512 Thread.Sleep(tmpMS); 1562 Thread.Sleep(tmpMS);
@@ -1557,9 +1607,9 @@ namespace OpenSim.Region.Framework.Scenes
1557 1607
1558 private void CheckAtTargets() 1608 private void CheckAtTargets()
1559 { 1609 {
1560 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1610 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1561 lock (m_groupsWithTargets) 1611 lock (m_groupsWithTargets)
1562 objs = m_groupsWithTargets.Values; 1612 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1563 1613
1564 foreach (SceneObjectGroup entry in objs) 1614 foreach (SceneObjectGroup entry in objs)
1565 entry.checkAtTargets(); 1615 entry.checkAtTargets();
@@ -1640,7 +1690,7 @@ namespace OpenSim.Region.Framework.Scenes
1640 msg.fromAgentName = "Server"; 1690 msg.fromAgentName = "Server";
1641 msg.dialog = (byte)19; // Object msg 1691 msg.dialog = (byte)19; // Object msg
1642 msg.fromGroup = false; 1692 msg.fromGroup = false;
1643 msg.offline = (byte)0; 1693 msg.offline = (byte)1;
1644 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1694 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1645 msg.Position = Vector3.Zero; 1695 msg.Position = Vector3.Zero;
1646 msg.RegionID = RegionInfo.RegionID.Guid; 1696 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1862,6 +1912,19 @@ namespace OpenSim.Region.Framework.Scenes
1862 EventManager.TriggerPrimsLoaded(this); 1912 EventManager.TriggerPrimsLoaded(this);
1863 } 1913 }
1864 1914
1915 public bool SuportsRayCastFiltered()
1916 {
1917 if (PhysicsScene == null)
1918 return false;
1919 return PhysicsScene.SuportsRaycastWorldFiltered();
1920 }
1921
1922 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
1923 {
1924 if (PhysicsScene == null)
1925 return null;
1926 return PhysicsScene.RaycastWorld(position, direction, length, Count,filter);
1927 }
1865 1928
1866 /// <summary> 1929 /// <summary>
1867 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed. 1930 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
@@ -1878,14 +1941,24 @@ namespace OpenSim.Region.Framework.Scenes
1878 /// <returns></returns> 1941 /// <returns></returns>
1879 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1942 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1880 { 1943 {
1944
1945 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1946 Vector3 wpos = Vector3.Zero;
1947 // Check for water surface intersection from above
1948 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1949 {
1950 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1951 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1952 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1953 wpos.Z = wheight;
1954 }
1955
1881 Vector3 pos = Vector3.Zero; 1956 Vector3 pos = Vector3.Zero;
1882 if (RayEndIsIntersection == (byte)1) 1957 if (RayEndIsIntersection == (byte)1)
1883 { 1958 {
1884 pos = RayEnd; 1959 pos = RayEnd;
1885 return pos;
1886 } 1960 }
1887 1961 else if (RayTargetID != UUID.Zero)
1888 if (RayTargetID != UUID.Zero)
1889 { 1962 {
1890 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1963 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1891 1964
@@ -1907,7 +1980,7 @@ namespace OpenSim.Region.Framework.Scenes
1907 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1980 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1908 1981
1909 // Un-comment out the following line to Get Raytrace results printed to the console. 1982 // Un-comment out the following line to Get Raytrace results printed to the console.
1910 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1983 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1911 float ScaleOffset = 0.5f; 1984 float ScaleOffset = 0.5f;
1912 1985
1913 // If we hit something 1986 // If we hit something
@@ -1930,13 +2003,10 @@ namespace OpenSim.Region.Framework.Scenes
1930 //pos.Z -= 0.25F; 2003 //pos.Z -= 0.25F;
1931 2004
1932 } 2005 }
1933
1934 return pos;
1935 } 2006 }
1936 else 2007 else
1937 { 2008 {
1938 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2009 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1939
1940 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2010 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1941 2011
1942 // Un-comment the following line to print the raytrace results to the console. 2012 // Un-comment the following line to print the raytrace results to the console.
@@ -1945,13 +2015,12 @@ namespace OpenSim.Region.Framework.Scenes
1945 if (ei.HitTF) 2015 if (ei.HitTF)
1946 { 2016 {
1947 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2017 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1948 } else 2018 }
2019 else
1949 { 2020 {
1950 // fall back to our stupid functionality 2021 // fall back to our stupid functionality
1951 pos = RayEnd; 2022 pos = RayEnd;
1952 } 2023 }
1953
1954 return pos;
1955 } 2024 }
1956 } 2025 }
1957 else 2026 else
@@ -1962,8 +2031,12 @@ namespace OpenSim.Region.Framework.Scenes
1962 //increase height so its above the ground. 2031 //increase height so its above the ground.
1963 //should be getting the normal of the ground at the rez point and using that? 2032 //should be getting the normal of the ground at the rez point and using that?
1964 pos.Z += scale.Z / 2f; 2033 pos.Z += scale.Z / 2f;
1965 return pos; 2034// return pos;
1966 } 2035 }
2036
2037 // check against posible water intercept
2038 if (wpos.Z > pos.Z) pos = wpos;
2039 return pos;
1967 } 2040 }
1968 2041
1969 2042
@@ -2053,7 +2126,10 @@ namespace OpenSim.Region.Framework.Scenes
2053 public bool AddRestoredSceneObject( 2126 public bool AddRestoredSceneObject(
2054 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 2127 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
2055 { 2128 {
2056 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 2129 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
2130 if (result)
2131 sceneObject.IsDeleted = false;
2132 return result;
2057 } 2133 }
2058 2134
2059 /// <summary> 2135 /// <summary>
@@ -2145,6 +2221,15 @@ namespace OpenSim.Region.Framework.Scenes
2145 /// </summary> 2221 /// </summary>
2146 public void DeleteAllSceneObjects() 2222 public void DeleteAllSceneObjects()
2147 { 2223 {
2224 DeleteAllSceneObjects(false);
2225 }
2226
2227 /// <summary>
2228 /// Delete every object from the scene. This does not include attachments worn by avatars.
2229 /// </summary>
2230 public void DeleteAllSceneObjects(bool exceptNoCopy)
2231 {
2232 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2148 lock (Entities) 2233 lock (Entities)
2149 { 2234 {
2150 EntityBase[] entities = Entities.GetEntities(); 2235 EntityBase[] entities = Entities.GetEntities();
@@ -2153,11 +2238,24 @@ namespace OpenSim.Region.Framework.Scenes
2153 if (e is SceneObjectGroup) 2238 if (e is SceneObjectGroup)
2154 { 2239 {
2155 SceneObjectGroup sog = (SceneObjectGroup)e; 2240 SceneObjectGroup sog = (SceneObjectGroup)e;
2156 if (!sog.IsAttachment) 2241 if (sog != null && !sog.IsAttachment)
2157 DeleteSceneObject((SceneObjectGroup)e, false); 2242 {
2243 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2244 {
2245 DeleteSceneObject((SceneObjectGroup)e, false);
2246 }
2247 else
2248 {
2249 toReturn.Add((SceneObjectGroup)e);
2250 }
2251 }
2158 } 2252 }
2159 } 2253 }
2160 } 2254 }
2255 if (toReturn.Count > 0)
2256 {
2257 returnObjects(toReturn.ToArray(), UUID.Zero);
2258 }
2161 } 2259 }
2162 2260
2163 /// <summary> 2261 /// <summary>
@@ -2192,6 +2290,8 @@ namespace OpenSim.Region.Framework.Scenes
2192 } 2290 }
2193 2291
2194 group.DeleteGroupFromScene(silent); 2292 group.DeleteGroupFromScene(silent);
2293 if (!silent)
2294 SendKillObject(new List<uint>() { group.LocalId });
2195 2295
2196// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2296// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2197 } 2297 }
@@ -2481,6 +2581,8 @@ namespace OpenSim.Region.Framework.Scenes
2481 2581
2482 if (newPosition != Vector3.Zero) 2582 if (newPosition != Vector3.Zero)
2483 newObject.RootPart.GroupPosition = newPosition; 2583 newObject.RootPart.GroupPosition = newPosition;
2584 if (newObject.RootPart.KeyframeMotion != null)
2585 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2484 2586
2485 if (!AddSceneObject(newObject)) 2587 if (!AddSceneObject(newObject))
2486 { 2588 {
@@ -2549,10 +2651,17 @@ namespace OpenSim.Region.Framework.Scenes
2549 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2651 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2550 public bool AddSceneObject(SceneObjectGroup sceneObject) 2652 public bool AddSceneObject(SceneObjectGroup sceneObject)
2551 { 2653 {
2654 if (sceneObject.OwnerID == UUID.Zero)
2655 {
2656 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2657 return false;
2658 }
2659
2552 // If the user is banned, we won't let any of their objects 2660 // If the user is banned, we won't let any of their objects
2553 // enter. Period. 2661 // enter. Period.
2554 // 2662 //
2555 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2663 int flags = GetUserFlags(sceneObject.OwnerID);
2664 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2556 { 2665 {
2557 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID); 2666 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2558 2667
@@ -2594,16 +2703,27 @@ namespace OpenSim.Region.Framework.Scenes
2594 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2703 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2595 2704
2596 if (AttachmentsModule != null) 2705 if (AttachmentsModule != null)
2597 AttachmentsModule.AttachObject(sp, grp, 0, false); 2706 AttachmentsModule.AttachObject(sp, grp, 0, false, false);
2598 } 2707 }
2599 else 2708 else
2600 { 2709 {
2710 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2601 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2711 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2602 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2712 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2603 } 2713 }
2714 if (sceneObject.OwnerID == UUID.Zero)
2715 {
2716 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2717 return false;
2718 }
2604 } 2719 }
2605 else 2720 else
2606 { 2721 {
2722 if (sceneObject.OwnerID == UUID.Zero)
2723 {
2724 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2725 return false;
2726 }
2607 AddRestoredSceneObject(sceneObject, true, false); 2727 AddRestoredSceneObject(sceneObject, true, false);
2608 2728
2609 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2729 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2632,6 +2752,24 @@ namespace OpenSim.Region.Framework.Scenes
2632 return 2; // StateSource.PrimCrossing 2752 return 2; // StateSource.PrimCrossing
2633 } 2753 }
2634 2754
2755 public int GetUserFlags(UUID user)
2756 {
2757 //Unfortunately the SP approach means that the value is cached until region is restarted
2758 /*
2759 ScenePresence sp;
2760 if (TryGetScenePresence(user, out sp))
2761 {
2762 return sp.UserFlags;
2763 }
2764 else
2765 {
2766 */
2767 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2768 if (uac == null)
2769 return 0;
2770 return uac.UserFlags;
2771 //}
2772 }
2635 #endregion 2773 #endregion
2636 2774
2637 #region Add/Remove Avatar Methods 2775 #region Add/Remove Avatar Methods
@@ -2645,7 +2783,7 @@ namespace OpenSim.Region.Framework.Scenes
2645 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2783 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2646 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2784 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2647 2785
2648// CheckHeartbeat(); 2786 CheckHeartbeat();
2649 2787
2650 ScenePresence sp = GetScenePresence(client.AgentId); 2788 ScenePresence sp = GetScenePresence(client.AgentId);
2651 2789
@@ -2699,7 +2837,13 @@ namespace OpenSim.Region.Framework.Scenes
2699 2837
2700 EventManager.TriggerOnNewClient(client); 2838 EventManager.TriggerOnNewClient(client);
2701 if (vialogin) 2839 if (vialogin)
2840 {
2702 EventManager.TriggerOnClientLogin(client); 2841 EventManager.TriggerOnClientLogin(client);
2842 // Send initial parcel data
2843 Vector3 pos = sp.AbsolutePosition;
2844 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2845 land.SendLandUpdateToClient(client);
2846 }
2703 2847
2704 return sp; 2848 return sp;
2705 } 2849 }
@@ -2789,19 +2933,12 @@ namespace OpenSim.Region.Framework.Scenes
2789 // and the scene presence and the client, if they exist 2933 // and the scene presence and the client, if they exist
2790 try 2934 try
2791 { 2935 {
2792 // We need to wait for the client to make UDP contact first. 2936 ScenePresence sp = GetScenePresence(agentID);
2793 // It's the UDP contact that creates the scene presence 2937 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2794 ScenePresence sp = WaitGetScenePresence(agentID); 2938
2795 if (sp != null) 2939 if (sp != null)
2796 {
2797 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2798
2799 sp.ControllingClient.Close(); 2940 sp.ControllingClient.Close();
2800 } 2941
2801 else
2802 {
2803 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2804 }
2805 // BANG! SLASH! 2942 // BANG! SLASH!
2806 m_authenticateHandler.RemoveCircuit(agentID); 2943 m_authenticateHandler.RemoveCircuit(agentID);
2807 2944
@@ -2846,6 +2983,8 @@ namespace OpenSim.Region.Framework.Scenes
2846 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 2983 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2847 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 2984 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2848 2985
2986 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
2987
2849 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 2988 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2850 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 2989 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2851 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 2990 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -2902,6 +3041,7 @@ namespace OpenSim.Region.Framework.Scenes
2902 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3041 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2903 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3042 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2904 client.OnCopyInventoryItem += CopyInventoryItem; 3043 client.OnCopyInventoryItem += CopyInventoryItem;
3044 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2905 client.OnMoveInventoryItem += MoveInventoryItem; 3045 client.OnMoveInventoryItem += MoveInventoryItem;
2906 client.OnRemoveInventoryItem += RemoveInventoryItem; 3046 client.OnRemoveInventoryItem += RemoveInventoryItem;
2907 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3047 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2973,6 +3113,8 @@ namespace OpenSim.Region.Framework.Scenes
2973 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3113 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
2974 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3114 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
2975 3115
3116 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3117
2976 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3118 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
2977 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3119 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
2978 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3120 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3075,7 +3217,7 @@ namespace OpenSim.Region.Framework.Scenes
3075 /// </summary> 3217 /// </summary>
3076 /// <param name="agentId">The avatar's Unique ID</param> 3218 /// <param name="agentId">The avatar's Unique ID</param>
3077 /// <param name="client">The IClientAPI for the client</param> 3219 /// <param name="client">The IClientAPI for the client</param>
3078 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3220 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3079 { 3221 {
3080 if (EntityTransferModule != null) 3222 if (EntityTransferModule != null)
3081 { 3223 {
@@ -3086,6 +3228,7 @@ namespace OpenSim.Region.Framework.Scenes
3086 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3228 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3087 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3229 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3088 } 3230 }
3231 return false;
3089 } 3232 }
3090 3233
3091 /// <summary> 3234 /// <summary>
@@ -3195,6 +3338,16 @@ namespace OpenSim.Region.Framework.Scenes
3195 /// <param name="flags"></param> 3338 /// <param name="flags"></param>
3196 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3339 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3197 { 3340 {
3341 //Add half the avatar's height so that the user doesn't fall through prims
3342 ScenePresence presence;
3343 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3344 {
3345 if (presence.Appearance != null)
3346 {
3347 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3348 }
3349 }
3350
3198 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3351 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3199 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3352 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3200 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3353 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3279,8 +3432,9 @@ namespace OpenSim.Region.Framework.Scenes
3279 regions.Remove(RegionInfo.RegionHandle); 3432 regions.Remove(RegionInfo.RegionHandle);
3280 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3433 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3281 } 3434 }
3282 3435 m_log.Debug("[Scene] Beginning ClientClosed");
3283 m_eventManager.TriggerClientClosed(agentID, this); 3436 m_eventManager.TriggerClientClosed(agentID, this);
3437 m_log.Debug("[Scene] Finished ClientClosed");
3284 } 3438 }
3285 catch (NullReferenceException) 3439 catch (NullReferenceException)
3286 { 3440 {
@@ -3343,9 +3497,10 @@ namespace OpenSim.Region.Framework.Scenes
3343 { 3497 {
3344 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace); 3498 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace);
3345 } 3499 }
3346 3500 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3347 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3501 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3348// CleanDroppedAttachments(); 3502// CleanDroppedAttachments();
3503 m_log.Debug("[Scene] The avatar has left the building");
3349 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3504 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3350 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3505 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3351 } 3506 }
@@ -3480,13 +3635,16 @@ namespace OpenSim.Region.Framework.Scenes
3480 sp = null; 3635 sp = null;
3481 } 3636 }
3482 3637
3483 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3484 3638
3485 //On login test land permisions 3639 //On login test land permisions
3486 if (vialogin) 3640 if (vialogin)
3487 { 3641 {
3488 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3642 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3643 if (cache != null)
3644 cache.Remove(agent.firstname + " " + agent.lastname);
3645 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3489 { 3646 {
3647 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3490 return false; 3648 return false;
3491 } 3649 }
3492 } 3650 }
@@ -3509,9 +3667,15 @@ namespace OpenSim.Region.Framework.Scenes
3509 3667
3510 try 3668 try
3511 { 3669 {
3512 if (!AuthorizeUser(agent, out reason)) 3670 // Always check estate if this is a login. Always
3513 return false; 3671 // check if banned regions are to be blacked out.
3514 } catch (Exception e) 3672 if (vialogin || (!m_seeIntoBannedRegion))
3673 {
3674 if (!AuthorizeUser(agent, out reason))
3675 return false;
3676 }
3677 }
3678 catch (Exception e)
3515 { 3679 {
3516 m_log.ErrorFormat( 3680 m_log.ErrorFormat(
3517 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3681 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
@@ -3642,6 +3806,8 @@ namespace OpenSim.Region.Framework.Scenes
3642 } 3806 }
3643 3807
3644 // Honor parcel landing type and position. 3808 // Honor parcel landing type and position.
3809 /*
3810 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3645 if (land != null) 3811 if (land != null)
3646 { 3812 {
3647 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3813 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3649,25 +3815,34 @@ namespace OpenSim.Region.Framework.Scenes
3649 agent.startpos = land.LandData.UserLocation; 3815 agent.startpos = land.LandData.UserLocation;
3650 } 3816 }
3651 } 3817 }
3818 */// This is now handled properly in ScenePresence.MakeRootAgent
3652 } 3819 }
3653 3820
3654 return true; 3821 return true;
3655 } 3822 }
3656 3823
3657 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3824 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3658 { 3825 {
3659 bool banned = land.IsBannedFromLand(agent.AgentID); 3826 reason = String.Empty;
3660 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3827 if (Permissions.IsGod(agentID))
3828 return true;
3829
3830 ILandObject land = LandChannel.GetLandObject(posX, posY);
3831 if (land == null)
3832 return false;
3833
3834 bool banned = land.IsBannedFromLand(agentID);
3835 bool restricted = land.IsRestrictedFromLand(agentID);
3661 3836
3662 if (banned || restricted) 3837 if (banned || restricted)
3663 { 3838 {
3664 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3839 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3665 if (nearestParcel != null) 3840 if (nearestParcel != null)
3666 { 3841 {
3667 //Move agent to nearest allowed 3842 //Move agent to nearest allowed
3668 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3843 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3669 agent.startpos.X = newPosition.X; 3844 posX = newPosition.X;
3670 agent.startpos.Y = newPosition.Y; 3845 posY = newPosition.Y;
3671 } 3846 }
3672 else 3847 else
3673 { 3848 {
@@ -3729,7 +3904,7 @@ namespace OpenSim.Region.Framework.Scenes
3729 3904
3730 if (!m_strictAccessControl) return true; 3905 if (!m_strictAccessControl) return true;
3731 if (Permissions.IsGod(agent.AgentID)) return true; 3906 if (Permissions.IsGod(agent.AgentID)) return true;
3732 3907
3733 if (AuthorizationService != null) 3908 if (AuthorizationService != null)
3734 { 3909 {
3735 if (!AuthorizationService.IsAuthorizedForRegion( 3910 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3744,7 +3919,7 @@ namespace OpenSim.Region.Framework.Scenes
3744 3919
3745 if (m_regInfo.EstateSettings != null) 3920 if (m_regInfo.EstateSettings != null)
3746 { 3921 {
3747 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3922 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3748 { 3923 {
3749 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3924 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3750 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3925 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3934,6 +4109,15 @@ namespace OpenSim.Region.Framework.Scenes
3934 4109
3935 // XPTO: if this agent is not allowed here as root, always return false 4110 // XPTO: if this agent is not allowed here as root, always return false
3936 4111
4112 // We have to wait until the viewer contacts this region after receiving EAC.
4113 // That calls AddNewClient, which finally creates the ScenePresence
4114 int flags = GetUserFlags(cAgentData.AgentID);
4115 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4116 {
4117 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4118 return false;
4119 }
4120
3937 // TODO: This check should probably be in QueryAccess(). 4121 // TODO: This check should probably be in QueryAccess().
3938 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4122 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3939 if (nearestParcel == null) 4123 if (nearestParcel == null)
@@ -4027,12 +4211,22 @@ namespace OpenSim.Region.Framework.Scenes
4027 return false; 4211 return false;
4028 } 4212 }
4029 4213
4214 public bool IncomingCloseAgent(UUID agentID)
4215 {
4216 return IncomingCloseAgent(agentID, false);
4217 }
4218
4219 public bool IncomingCloseChildAgent(UUID agentID)
4220 {
4221 return IncomingCloseAgent(agentID, true);
4222 }
4223
4030 /// <summary> 4224 /// <summary>
4031 /// Tell a single agent to disconnect from the region. 4225 /// Tell a single agent to disconnect from the region.
4032 /// </summary> 4226 /// </summary>
4033 /// <param name="regionHandle"></param>
4034 /// <param name="agentID"></param> 4227 /// <param name="agentID"></param>
4035 public bool IncomingCloseAgent(UUID agentID) 4228 /// <param name="childOnly"></param>
4229 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
4036 { 4230 {
4037 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 4231 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
4038 4232
@@ -4044,7 +4238,7 @@ namespace OpenSim.Region.Framework.Scenes
4044 { 4238 {
4045 m_sceneGraph.removeUserCount(false); 4239 m_sceneGraph.removeUserCount(false);
4046 } 4240 }
4047 else 4241 else if (!childOnly)
4048 { 4242 {
4049 m_sceneGraph.removeUserCount(true); 4243 m_sceneGraph.removeUserCount(true);
4050 } 4244 }
@@ -4635,35 +4829,81 @@ namespace OpenSim.Region.Framework.Scenes
4635 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4829 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4636 } 4830 }
4637 4831
4638 public int GetHealth() 4832 public int GetHealth(out int flags, out string message)
4639 { 4833 {
4640 // Returns: 4834 // Returns:
4641 // 1 = sim is up and accepting http requests. The heartbeat has 4835 // 1 = sim is up and accepting http requests. The heartbeat has
4642 // stopped and the sim is probably locked up, but a remote 4836 // stopped and the sim is probably locked up, but a remote
4643 // admin restart may succeed 4837 // admin restart may succeed
4644 // 4838 //
4645 // 2 = Sim is up and the heartbeat is running. The sim is likely 4839 // 2 = Sim is up and the heartbeat is running. The sim is likely
4646 // usable for people within and logins _may_ work 4840 // usable for people within
4841 //
4842 // 3 = Sim is up and one packet thread is running. Sim is
4843 // unstable and will not accept new logins
4647 // 4844 //
4648 // 3 = We have seen a new user enter within the past 4 minutes 4845 // 4 = Sim is up and both packet threads are running. Sim is
4846 // likely usable
4847 //
4848 // 5 = We have seen a new user enter within the past 4 minutes
4649 // which can be seen as positive confirmation of sim health 4849 // which can be seen as positive confirmation of sim health
4650 // 4850 //
4851
4852 flags = 0;
4853 message = String.Empty;
4854
4855 CheckHeartbeat();
4856
4857 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4858 {
4859 // We're still starting
4860 // 0 means "in startup", it can't happen another way, since
4861 // to get here, we must be able to accept http connections
4862 return 0;
4863 }
4864
4651 int health=1; // Start at 1, means we're up 4865 int health=1; // Start at 1, means we're up
4652 4866
4653 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 4867 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4654 health += 1; 4868 {
4869 health+=1;
4870 flags |= 1;
4871 }
4872
4873 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4874 {
4875 health+=1;
4876 flags |= 2;
4877 }
4878
4879 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4880 {
4881 health+=1;
4882 flags |= 4;
4883 }
4655 else 4884 else
4885 {
4886int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
4887System.Diagnostics.Process proc = new System.Diagnostics.Process();
4888proc.EnableRaisingEvents=false;
4889proc.StartInfo.FileName = "/bin/kill";
4890proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
4891proc.Start();
4892proc.WaitForExit();
4893Thread.Sleep(1000);
4894Environment.Exit(1);
4895 }
4896
4897 if (flags != 7)
4656 return health; 4898 return health;
4657 4899
4658 // A login in the last 4 mins? We can't be doing too badly 4900 // A login in the last 4 mins? We can't be doing too badly
4659 // 4901 //
4660 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4902 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4661 health++; 4903 health++;
4662 else 4904 else
4663 return health; 4905 return health;
4664 4906
4665// CheckHeartbeat();
4666
4667 return health; 4907 return health;
4668 } 4908 }
4669 4909
@@ -4751,7 +4991,7 @@ namespace OpenSim.Region.Framework.Scenes
4751 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 4991 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
4752 if (wasUsingPhysics) 4992 if (wasUsingPhysics)
4753 { 4993 {
4754 jointProxyObject.UpdatePrimFlags(false, false, true, false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock 4994 jointProxyObject.UpdatePrimFlags(false, false, true, false,false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock
4755 } 4995 }
4756 } 4996 }
4757 4997
@@ -4850,14 +5090,14 @@ namespace OpenSim.Region.Framework.Scenes
4850 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5090 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
4851 } 5091 }
4852 5092
4853// private void CheckHeartbeat() 5093 private void CheckHeartbeat()
4854// { 5094 {
4855// if (m_firstHeartbeat) 5095 if (m_firstHeartbeat)
4856// return; 5096 return;
4857// 5097
4858// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5098 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
4859// StartTimer(); 5099 Start();
4860// } 5100 }
4861 5101
4862 public override ISceneObject DeserializeObject(string representation) 5102 public override ISceneObject DeserializeObject(string representation)
4863 { 5103 {
@@ -4869,9 +5109,14 @@ namespace OpenSim.Region.Framework.Scenes
4869 get { return m_allowScriptCrossings; } 5109 get { return m_allowScriptCrossings; }
4870 } 5110 }
4871 5111
4872 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5112 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5113 {
5114 return GetNearestAllowedPosition(avatar, null);
5115 }
5116
5117 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
4873 { 5118 {
4874 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5119 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
4875 5120
4876 if (nearestParcel != null) 5121 if (nearestParcel != null)
4877 { 5122 {
@@ -4880,10 +5125,7 @@ namespace OpenSim.Region.Framework.Scenes
4880 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5125 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4881 if (nearestPoint != null) 5126 if (nearestPoint != null)
4882 { 5127 {
4883// m_log.DebugFormat( 5128 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4884// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
4885// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
4886
4887 return nearestPoint.Value; 5129 return nearestPoint.Value;
4888 } 5130 }
4889 5131
@@ -4893,17 +5135,20 @@ namespace OpenSim.Region.Framework.Scenes
4893 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5135 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4894 if (nearestPoint != null) 5136 if (nearestPoint != null)
4895 { 5137 {
4896// m_log.DebugFormat( 5138 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4897// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
4898
4899 return nearestPoint.Value; 5139 return nearestPoint.Value;
4900 } 5140 }
4901 5141
4902 //Ultimate backup if we have no idea where they are 5142 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
4903// m_log.DebugFormat( 5143 if (dest != excludeParcel)
4904// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5144 {
5145 // Ultimate backup if we have no idea where they are and
5146 // the last allowed position was in another parcel
5147 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5148 return avatar.lastKnownAllowedPosition;
5149 }
4905 5150
4906 return avatar.lastKnownAllowedPosition; 5151 // else fall through to region edge
4907 } 5152 }
4908 5153
4909 //Go to the edge, this happens in teleporting to a region with no available parcels 5154 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -4937,13 +5182,18 @@ namespace OpenSim.Region.Framework.Scenes
4937 5182
4938 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5183 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
4939 { 5184 {
5185 return GetNearestAllowedParcel(avatarId, x, y, null);
5186 }
5187
5188 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5189 {
4940 List<ILandObject> all = AllParcels(); 5190 List<ILandObject> all = AllParcels();
4941 float minParcelDistance = float.MaxValue; 5191 float minParcelDistance = float.MaxValue;
4942 ILandObject nearestParcel = null; 5192 ILandObject nearestParcel = null;
4943 5193
4944 foreach (var parcel in all) 5194 foreach (var parcel in all)
4945 { 5195 {
4946 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5196 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
4947 { 5197 {
4948 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5198 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
4949 if (parcelDistance < minParcelDistance) 5199 if (parcelDistance < minParcelDistance)
@@ -5185,7 +5435,55 @@ namespace OpenSim.Region.Framework.Scenes
5185 mapModule.GenerateMaptile(); 5435 mapModule.GenerateMaptile();
5186 } 5436 }
5187 5437
5188 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5438// public void CleanDroppedAttachments()
5439// {
5440// List<SceneObjectGroup> objectsToDelete =
5441// new List<SceneObjectGroup>();
5442//
5443// lock (m_cleaningAttachments)
5444// {
5445// ForEachSOG(delegate (SceneObjectGroup grp)
5446// {
5447// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5448// {
5449// UUID agentID = grp.OwnerID;
5450// if (agentID == UUID.Zero)
5451// {
5452// objectsToDelete.Add(grp);
5453// return;
5454// }
5455//
5456// ScenePresence sp = GetScenePresence(agentID);
5457// if (sp == null)
5458// {
5459// objectsToDelete.Add(grp);
5460// return;
5461// }
5462// }
5463// });
5464// }
5465//
5466// foreach (SceneObjectGroup grp in objectsToDelete)
5467// {
5468// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5469// DeleteSceneObject(grp, true);
5470// }
5471// }
5472
5473 public void ThreadAlive(int threadCode)
5474 {
5475 switch(threadCode)
5476 {
5477 case 1: // Incoming
5478 m_lastIncoming = Util.EnvironmentTickCount();
5479 break;
5480 case 2: // Incoming
5481 m_lastOutgoing = Util.EnvironmentTickCount();
5482 break;
5483 }
5484 }
5485
5486 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5189 { 5487 {
5190 RegenerateMaptile(); 5488 RegenerateMaptile();
5191 5489
@@ -5213,6 +5511,8 @@ namespace OpenSim.Region.Framework.Scenes
5213 /// <returns></returns> 5511 /// <returns></returns>
5214 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5512 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5215 { 5513 {
5514 reason = "You are banned from the region";
5515
5216 if (EntityTransferModule.IsInTransit(agentID)) 5516 if (EntityTransferModule.IsInTransit(agentID))
5217 { 5517 {
5218 reason = "Agent is still in transit from this region"; 5518 reason = "Agent is still in transit from this region";
@@ -5224,6 +5524,12 @@ namespace OpenSim.Region.Framework.Scenes
5224 return false; 5524 return false;
5225 } 5525 }
5226 5526
5527 if (Permissions.IsGod(agentID))
5528 {
5529 reason = String.Empty;
5530 return true;
5531 }
5532
5227 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5533 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5228 // However, the long term fix is to make sure root agent count is always accurate. 5534 // However, the long term fix is to make sure root agent count is always accurate.
5229 m_sceneGraph.RecalculateStats(); 5535 m_sceneGraph.RecalculateStats();
@@ -5244,6 +5550,41 @@ namespace OpenSim.Region.Framework.Scenes
5244 } 5550 }
5245 } 5551 }
5246 5552
5553 ScenePresence presence = GetScenePresence(agentID);
5554 IClientAPI client = null;
5555 AgentCircuitData aCircuit = null;
5556
5557 if (presence != null)
5558 {
5559 client = presence.ControllingClient;
5560 if (client != null)
5561 aCircuit = client.RequestClientInfo();
5562 }
5563
5564 // We may be called before there is a presence or a client.
5565 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5566 if (client == null)
5567 {
5568 aCircuit = new AgentCircuitData();
5569 aCircuit.AgentID = agentID;
5570 aCircuit.firstname = String.Empty;
5571 aCircuit.lastname = String.Empty;
5572 }
5573
5574 try
5575 {
5576 if (!AuthorizeUser(aCircuit, out reason))
5577 {
5578 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5579 return false;
5580 }
5581 }
5582 catch (Exception e)
5583 {
5584 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5585 return false;
5586 }
5587
5247 if (position == Vector3.Zero) // Teleport 5588 if (position == Vector3.Zero) // Teleport
5248 { 5589 {
5249 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5590 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5272,13 +5613,46 @@ namespace OpenSim.Region.Framework.Scenes
5272 } 5613 }
5273 } 5614 }
5274 } 5615 }
5616
5617 float posX = 128.0f;
5618 float posY = 128.0f;
5619
5620 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5621 {
5622 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5623 return false;
5624 }
5625 }
5626 else // Walking
5627 {
5628 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5629 if (land == null)
5630 return false;
5631
5632 bool banned = land.IsBannedFromLand(agentID);
5633 bool restricted = land.IsRestrictedFromLand(agentID);
5634
5635 if (banned || restricted)
5636 return false;
5275 } 5637 }
5276 5638
5277 reason = String.Empty; 5639 reason = String.Empty;
5278 return true; 5640 return true;
5279 } 5641 }
5280 5642
5281 /// <summary> 5643 public void StartTimerWatchdog()
5644 {
5645 m_timerWatchdog.Interval = 1000;
5646 m_timerWatchdog.Elapsed += TimerWatchdog;
5647 m_timerWatchdog.AutoReset = true;
5648 m_timerWatchdog.Start();
5649 }
5650
5651 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5652 {
5653 CheckHeartbeat();
5654 }
5655
5282 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5656 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5283 /// autopilot that moves an avatar to a sit target!. 5657 /// autopilot that moves an avatar to a sit target!.
5284 /// </summary> 5658 /// </summary>