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.cs695
1 files changed, 534 insertions, 161 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 7afde38..3095382 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.");
@@ -3321,6 +3474,7 @@ namespace OpenSim.Region.Framework.Scenes
3321 avatar.Close(); 3474 avatar.Close();
3322 3475
3323 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3476 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3477 m_log.Debug("[Scene] The avatar has left the building");
3324 } 3478 }
3325 catch (Exception e) 3479 catch (Exception e)
3326 { 3480 {
@@ -3471,13 +3625,16 @@ namespace OpenSim.Region.Framework.Scenes
3471 sp = null; 3625 sp = null;
3472 } 3626 }
3473 3627
3474 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3475 3628
3476 //On login test land permisions 3629 //On login test land permisions
3477 if (vialogin) 3630 if (vialogin)
3478 { 3631 {
3479 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3632 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3633 if (cache != null)
3634 cache.Remove(agent.firstname + " " + agent.lastname);
3635 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3480 { 3636 {
3637 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3481 return false; 3638 return false;
3482 } 3639 }
3483 } 3640 }
@@ -3500,9 +3657,15 @@ namespace OpenSim.Region.Framework.Scenes
3500 3657
3501 try 3658 try
3502 { 3659 {
3503 if (!AuthorizeUser(agent, out reason)) 3660 // Always check estate if this is a login. Always
3504 return false; 3661 // check if banned regions are to be blacked out.
3505 } catch (Exception e) 3662 if (vialogin || (!m_seeIntoBannedRegion))
3663 {
3664 if (!AuthorizeUser(agent, out reason))
3665 return false;
3666 }
3667 }
3668 catch (Exception e)
3506 { 3669 {
3507 m_log.ErrorFormat( 3670 m_log.ErrorFormat(
3508 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3671 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
@@ -3633,6 +3796,8 @@ namespace OpenSim.Region.Framework.Scenes
3633 } 3796 }
3634 3797
3635 // Honor parcel landing type and position. 3798 // Honor parcel landing type and position.
3799 /*
3800 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3636 if (land != null) 3801 if (land != null)
3637 { 3802 {
3638 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3803 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3640,25 +3805,34 @@ namespace OpenSim.Region.Framework.Scenes
3640 agent.startpos = land.LandData.UserLocation; 3805 agent.startpos = land.LandData.UserLocation;
3641 } 3806 }
3642 } 3807 }
3808 */// This is now handled properly in ScenePresence.MakeRootAgent
3643 } 3809 }
3644 3810
3645 return true; 3811 return true;
3646 } 3812 }
3647 3813
3648 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3814 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3649 { 3815 {
3650 bool banned = land.IsBannedFromLand(agent.AgentID); 3816 reason = String.Empty;
3651 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3817 if (Permissions.IsGod(agentID))
3818 return true;
3819
3820 ILandObject land = LandChannel.GetLandObject(posX, posY);
3821 if (land == null)
3822 return false;
3823
3824 bool banned = land.IsBannedFromLand(agentID);
3825 bool restricted = land.IsRestrictedFromLand(agentID);
3652 3826
3653 if (banned || restricted) 3827 if (banned || restricted)
3654 { 3828 {
3655 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3829 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3656 if (nearestParcel != null) 3830 if (nearestParcel != null)
3657 { 3831 {
3658 //Move agent to nearest allowed 3832 //Move agent to nearest allowed
3659 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3833 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3660 agent.startpos.X = newPosition.X; 3834 posX = newPosition.X;
3661 agent.startpos.Y = newPosition.Y; 3835 posY = newPosition.Y;
3662 } 3836 }
3663 else 3837 else
3664 { 3838 {
@@ -3720,7 +3894,7 @@ namespace OpenSim.Region.Framework.Scenes
3720 3894
3721 if (!m_strictAccessControl) return true; 3895 if (!m_strictAccessControl) return true;
3722 if (Permissions.IsGod(agent.AgentID)) return true; 3896 if (Permissions.IsGod(agent.AgentID)) return true;
3723 3897
3724 if (AuthorizationService != null) 3898 if (AuthorizationService != null)
3725 { 3899 {
3726 if (!AuthorizationService.IsAuthorizedForRegion( 3900 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3735,7 +3909,7 @@ namespace OpenSim.Region.Framework.Scenes
3735 3909
3736 if (m_regInfo.EstateSettings != null) 3910 if (m_regInfo.EstateSettings != null)
3737 { 3911 {
3738 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3912 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3739 { 3913 {
3740 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3914 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3741 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3915 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3925,6 +4099,15 @@ namespace OpenSim.Region.Framework.Scenes
3925 4099
3926 // XPTO: if this agent is not allowed here as root, always return false 4100 // XPTO: if this agent is not allowed here as root, always return false
3927 4101
4102 // We have to wait until the viewer contacts this region after receiving EAC.
4103 // That calls AddNewClient, which finally creates the ScenePresence
4104 int flags = GetUserFlags(cAgentData.AgentID);
4105 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4106 {
4107 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4108 return false;
4109 }
4110
3928 // TODO: This check should probably be in QueryAccess(). 4111 // TODO: This check should probably be in QueryAccess().
3929 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4112 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3930 if (nearestParcel == null) 4113 if (nearestParcel == null)
@@ -4018,12 +4201,22 @@ namespace OpenSim.Region.Framework.Scenes
4018 return false; 4201 return false;
4019 } 4202 }
4020 4203
4204 public bool IncomingCloseAgent(UUID agentID)
4205 {
4206 return IncomingCloseAgent(agentID, false);
4207 }
4208
4209 public bool IncomingCloseChildAgent(UUID agentID)
4210 {
4211 return IncomingCloseAgent(agentID, true);
4212 }
4213
4021 /// <summary> 4214 /// <summary>
4022 /// Tell a single agent to disconnect from the region. 4215 /// Tell a single agent to disconnect from the region.
4023 /// </summary> 4216 /// </summary>
4024 /// <param name="regionHandle"></param>
4025 /// <param name="agentID"></param> 4217 /// <param name="agentID"></param>
4026 public bool IncomingCloseAgent(UUID agentID) 4218 /// <param name="childOnly"></param>
4219 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
4027 { 4220 {
4028 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 4221 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
4029 4222
@@ -4616,35 +4809,81 @@ namespace OpenSim.Region.Framework.Scenes
4616 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4809 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4617 } 4810 }
4618 4811
4619 public int GetHealth() 4812 public int GetHealth(out int flags, out string message)
4620 { 4813 {
4621 // Returns: 4814 // Returns:
4622 // 1 = sim is up and accepting http requests. The heartbeat has 4815 // 1 = sim is up and accepting http requests. The heartbeat has
4623 // stopped and the sim is probably locked up, but a remote 4816 // stopped and the sim is probably locked up, but a remote
4624 // admin restart may succeed 4817 // admin restart may succeed
4625 // 4818 //
4626 // 2 = Sim is up and the heartbeat is running. The sim is likely 4819 // 2 = Sim is up and the heartbeat is running. The sim is likely
4627 // usable for people within and logins _may_ work 4820 // usable for people within
4821 //
4822 // 3 = Sim is up and one packet thread is running. Sim is
4823 // unstable and will not accept new logins
4628 // 4824 //
4629 // 3 = We have seen a new user enter within the past 4 minutes 4825 // 4 = Sim is up and both packet threads are running. Sim is
4826 // likely usable
4827 //
4828 // 5 = We have seen a new user enter within the past 4 minutes
4630 // which can be seen as positive confirmation of sim health 4829 // which can be seen as positive confirmation of sim health
4631 // 4830 //
4831
4832 flags = 0;
4833 message = String.Empty;
4834
4835 CheckHeartbeat();
4836
4837 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4838 {
4839 // We're still starting
4840 // 0 means "in startup", it can't happen another way, since
4841 // to get here, we must be able to accept http connections
4842 return 0;
4843 }
4844
4632 int health=1; // Start at 1, means we're up 4845 int health=1; // Start at 1, means we're up
4633 4846
4634 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 4847 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4635 health += 1; 4848 {
4849 health+=1;
4850 flags |= 1;
4851 }
4852
4853 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4854 {
4855 health+=1;
4856 flags |= 2;
4857 }
4858
4859 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4860 {
4861 health+=1;
4862 flags |= 4;
4863 }
4636 else 4864 else
4865 {
4866int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
4867System.Diagnostics.Process proc = new System.Diagnostics.Process();
4868proc.EnableRaisingEvents=false;
4869proc.StartInfo.FileName = "/bin/kill";
4870proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
4871proc.Start();
4872proc.WaitForExit();
4873Thread.Sleep(1000);
4874Environment.Exit(1);
4875 }
4876
4877 if (flags != 7)
4637 return health; 4878 return health;
4638 4879
4639 // A login in the last 4 mins? We can't be doing too badly 4880 // A login in the last 4 mins? We can't be doing too badly
4640 // 4881 //
4641 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4882 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4642 health++; 4883 health++;
4643 else 4884 else
4644 return health; 4885 return health;
4645 4886
4646// CheckHeartbeat();
4647
4648 return health; 4887 return health;
4649 } 4888 }
4650 4889
@@ -4732,7 +4971,7 @@ namespace OpenSim.Region.Framework.Scenes
4732 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 4971 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
4733 if (wasUsingPhysics) 4972 if (wasUsingPhysics)
4734 { 4973 {
4735 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 4974 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
4736 } 4975 }
4737 } 4976 }
4738 4977
@@ -4831,14 +5070,14 @@ namespace OpenSim.Region.Framework.Scenes
4831 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5070 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
4832 } 5071 }
4833 5072
4834// private void CheckHeartbeat() 5073 private void CheckHeartbeat()
4835// { 5074 {
4836// if (m_firstHeartbeat) 5075 if (m_firstHeartbeat)
4837// return; 5076 return;
4838// 5077
4839// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5078 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
4840// StartTimer(); 5079 Start();
4841// } 5080 }
4842 5081
4843 public override ISceneObject DeserializeObject(string representation) 5082 public override ISceneObject DeserializeObject(string representation)
4844 { 5083 {
@@ -4850,9 +5089,14 @@ namespace OpenSim.Region.Framework.Scenes
4850 get { return m_allowScriptCrossings; } 5089 get { return m_allowScriptCrossings; }
4851 } 5090 }
4852 5091
4853 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5092 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5093 {
5094 return GetNearestAllowedPosition(avatar, null);
5095 }
5096
5097 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
4854 { 5098 {
4855 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5099 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
4856 5100
4857 if (nearestParcel != null) 5101 if (nearestParcel != null)
4858 { 5102 {
@@ -4861,10 +5105,7 @@ namespace OpenSim.Region.Framework.Scenes
4861 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5105 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4862 if (nearestPoint != null) 5106 if (nearestPoint != null)
4863 { 5107 {
4864// m_log.DebugFormat( 5108 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4865// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
4866// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
4867
4868 return nearestPoint.Value; 5109 return nearestPoint.Value;
4869 } 5110 }
4870 5111
@@ -4874,17 +5115,20 @@ namespace OpenSim.Region.Framework.Scenes
4874 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5115 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4875 if (nearestPoint != null) 5116 if (nearestPoint != null)
4876 { 5117 {
4877// m_log.DebugFormat( 5118 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4878// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
4879
4880 return nearestPoint.Value; 5119 return nearestPoint.Value;
4881 } 5120 }
4882 5121
4883 //Ultimate backup if we have no idea where they are 5122 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
4884// m_log.DebugFormat( 5123 if (dest != excludeParcel)
4885// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5124 {
5125 // Ultimate backup if we have no idea where they are and
5126 // the last allowed position was in another parcel
5127 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5128 return avatar.lastKnownAllowedPosition;
5129 }
4886 5130
4887 return avatar.lastKnownAllowedPosition; 5131 // else fall through to region edge
4888 } 5132 }
4889 5133
4890 //Go to the edge, this happens in teleporting to a region with no available parcels 5134 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -4918,13 +5162,18 @@ namespace OpenSim.Region.Framework.Scenes
4918 5162
4919 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5163 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
4920 { 5164 {
5165 return GetNearestAllowedParcel(avatarId, x, y, null);
5166 }
5167
5168 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5169 {
4921 List<ILandObject> all = AllParcels(); 5170 List<ILandObject> all = AllParcels();
4922 float minParcelDistance = float.MaxValue; 5171 float minParcelDistance = float.MaxValue;
4923 ILandObject nearestParcel = null; 5172 ILandObject nearestParcel = null;
4924 5173
4925 foreach (var parcel in all) 5174 foreach (var parcel in all)
4926 { 5175 {
4927 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5176 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
4928 { 5177 {
4929 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5178 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
4930 if (parcelDistance < minParcelDistance) 5179 if (parcelDistance < minParcelDistance)
@@ -5166,7 +5415,55 @@ namespace OpenSim.Region.Framework.Scenes
5166 mapModule.GenerateMaptile(); 5415 mapModule.GenerateMaptile();
5167 } 5416 }
5168 5417
5169 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5418// public void CleanDroppedAttachments()
5419// {
5420// List<SceneObjectGroup> objectsToDelete =
5421// new List<SceneObjectGroup>();
5422//
5423// lock (m_cleaningAttachments)
5424// {
5425// ForEachSOG(delegate (SceneObjectGroup grp)
5426// {
5427// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5428// {
5429// UUID agentID = grp.OwnerID;
5430// if (agentID == UUID.Zero)
5431// {
5432// objectsToDelete.Add(grp);
5433// return;
5434// }
5435//
5436// ScenePresence sp = GetScenePresence(agentID);
5437// if (sp == null)
5438// {
5439// objectsToDelete.Add(grp);
5440// return;
5441// }
5442// }
5443// });
5444// }
5445//
5446// foreach (SceneObjectGroup grp in objectsToDelete)
5447// {
5448// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5449// DeleteSceneObject(grp, true);
5450// }
5451// }
5452
5453 public void ThreadAlive(int threadCode)
5454 {
5455 switch(threadCode)
5456 {
5457 case 1: // Incoming
5458 m_lastIncoming = Util.EnvironmentTickCount();
5459 break;
5460 case 2: // Incoming
5461 m_lastOutgoing = Util.EnvironmentTickCount();
5462 break;
5463 }
5464 }
5465
5466 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5170 { 5467 {
5171 RegenerateMaptile(); 5468 RegenerateMaptile();
5172 5469
@@ -5194,6 +5491,8 @@ namespace OpenSim.Region.Framework.Scenes
5194 /// <returns></returns> 5491 /// <returns></returns>
5195 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5492 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5196 { 5493 {
5494 reason = "You are banned from the region";
5495
5197 if (EntityTransferModule.IsInTransit(agentID)) 5496 if (EntityTransferModule.IsInTransit(agentID))
5198 { 5497 {
5199 reason = "Agent is still in transit from this region"; 5498 reason = "Agent is still in transit from this region";
@@ -5205,6 +5504,12 @@ namespace OpenSim.Region.Framework.Scenes
5205 return false; 5504 return false;
5206 } 5505 }
5207 5506
5507 if (Permissions.IsGod(agentID))
5508 {
5509 reason = String.Empty;
5510 return true;
5511 }
5512
5208 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5513 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5209 // However, the long term fix is to make sure root agent count is always accurate. 5514 // However, the long term fix is to make sure root agent count is always accurate.
5210 m_sceneGraph.RecalculateStats(); 5515 m_sceneGraph.RecalculateStats();
@@ -5225,6 +5530,41 @@ namespace OpenSim.Region.Framework.Scenes
5225 } 5530 }
5226 } 5531 }
5227 5532
5533 ScenePresence presence = GetScenePresence(agentID);
5534 IClientAPI client = null;
5535 AgentCircuitData aCircuit = null;
5536
5537 if (presence != null)
5538 {
5539 client = presence.ControllingClient;
5540 if (client != null)
5541 aCircuit = client.RequestClientInfo();
5542 }
5543
5544 // We may be called before there is a presence or a client.
5545 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5546 if (client == null)
5547 {
5548 aCircuit = new AgentCircuitData();
5549 aCircuit.AgentID = agentID;
5550 aCircuit.firstname = String.Empty;
5551 aCircuit.lastname = String.Empty;
5552 }
5553
5554 try
5555 {
5556 if (!AuthorizeUser(aCircuit, out reason))
5557 {
5558 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5559 return false;
5560 }
5561 }
5562 catch (Exception e)
5563 {
5564 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5565 return false;
5566 }
5567
5228 if (position == Vector3.Zero) // Teleport 5568 if (position == Vector3.Zero) // Teleport
5229 { 5569 {
5230 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5570 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5253,13 +5593,46 @@ namespace OpenSim.Region.Framework.Scenes
5253 } 5593 }
5254 } 5594 }
5255 } 5595 }
5596
5597 float posX = 128.0f;
5598 float posY = 128.0f;
5599
5600 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5601 {
5602 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5603 return false;
5604 }
5605 }
5606 else // Walking
5607 {
5608 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5609 if (land == null)
5610 return false;
5611
5612 bool banned = land.IsBannedFromLand(agentID);
5613 bool restricted = land.IsRestrictedFromLand(agentID);
5614
5615 if (banned || restricted)
5616 return false;
5256 } 5617 }
5257 5618
5258 reason = String.Empty; 5619 reason = String.Empty;
5259 return true; 5620 return true;
5260 } 5621 }
5261 5622
5262 /// <summary> 5623 public void StartTimerWatchdog()
5624 {
5625 m_timerWatchdog.Interval = 1000;
5626 m_timerWatchdog.Elapsed += TimerWatchdog;
5627 m_timerWatchdog.AutoReset = true;
5628 m_timerWatchdog.Start();
5629 }
5630
5631 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5632 {
5633 CheckHeartbeat();
5634 }
5635
5263 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5636 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5264 /// autopilot that moves an avatar to a sit target!. 5637 /// autopilot that moves an avatar to a sit target!.
5265 /// </summary> 5638 /// </summary>