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.cs697
1 files changed, 535 insertions, 162 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index a87dfb7..85b1242 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -118,6 +118,7 @@ namespace OpenSim.Region.Framework.Scenes
118 // TODO: need to figure out how allow client agents but deny 118 // TODO: need to figure out how allow client agents but deny
119 // root agents when ACL denies access to root agent 119 // root agents when ACL denies access to root agent
120 public bool m_strictAccessControl = true; 120 public bool m_strictAccessControl = true;
121 public bool m_seeIntoBannedRegion = false;
121 public int MaxUndoCount = 5; 122 public int MaxUndoCount = 5;
122 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 123 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
123 public bool LoginLock = false; 124 public bool LoginLock = false;
@@ -133,12 +134,14 @@ namespace OpenSim.Region.Framework.Scenes
133 134
134 protected int m_splitRegionID; 135 protected int m_splitRegionID;
135 protected Timer m_restartWaitTimer = new Timer(); 136 protected Timer m_restartWaitTimer = new Timer();
137 protected Timer m_timerWatchdog = new Timer();
136 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 138 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
137 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 139 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
138 protected string m_simulatorVersion = "OpenSimulator Server"; 140 protected string m_simulatorVersion = "OpenSimulator Server";
139 protected ModuleLoader m_moduleLoader; 141 protected ModuleLoader m_moduleLoader;
140 protected AgentCircuitManager m_authenticateHandler; 142 protected AgentCircuitManager m_authenticateHandler;
141 protected SceneCommunicationService m_sceneGridService; 143 protected SceneCommunicationService m_sceneGridService;
144 protected ISnmpModule m_snmpService = null;
142 145
143 protected ISimulationDataService m_SimulationDataService; 146 protected ISimulationDataService m_SimulationDataService;
144 protected IEstateDataService m_EstateDataService; 147 protected IEstateDataService m_EstateDataService;
@@ -201,7 +204,7 @@ namespace OpenSim.Region.Framework.Scenes
201 private int m_update_events = 1; 204 private int m_update_events = 1;
202 private int m_update_backup = 200; 205 private int m_update_backup = 200;
203 private int m_update_terrain = 50; 206 private int m_update_terrain = 50;
204// private int m_update_land = 1; 207 private int m_update_land = 10;
205 private int m_update_coarse_locations = 50; 208 private int m_update_coarse_locations = 50;
206 209
207 private int agentMS; 210 private int agentMS;
@@ -220,6 +223,7 @@ namespace OpenSim.Region.Framework.Scenes
220 /// </summary> 223 /// </summary>
221 private int m_lastFrameTick; 224 private int m_lastFrameTick;
222 225
226 public bool CombineRegions = false;
223 /// <summary> 227 /// <summary>
224 /// Tick at which the last maintenance run occurred. 228 /// Tick at which the last maintenance run occurred.
225 /// </summary> 229 /// </summary>
@@ -250,6 +254,11 @@ namespace OpenSim.Region.Framework.Scenes
250 /// </summary> 254 /// </summary>
251 private int m_LastLogin; 255 private int m_LastLogin;
252 256
257 private int m_lastIncoming;
258 private int m_lastOutgoing;
259 private int m_hbRestarts = 0;
260
261
253 /// <summary> 262 /// <summary>
254 /// Thread that runs the scene loop. 263 /// Thread that runs the scene loop.
255 /// </summary> 264 /// </summary>
@@ -265,7 +274,7 @@ namespace OpenSim.Region.Framework.Scenes
265 private volatile bool m_shuttingDown; 274 private volatile bool m_shuttingDown;
266 275
267// private int m_lastUpdate; 276// private int m_lastUpdate;
268// private bool m_firstHeartbeat = true; 277 private bool m_firstHeartbeat = true;
269 278
270 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time; 279 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
271 private bool m_reprioritizationEnabled = true; 280 private bool m_reprioritizationEnabled = true;
@@ -310,6 +319,19 @@ namespace OpenSim.Region.Framework.Scenes
310 get { return m_sceneGridService; } 319 get { return m_sceneGridService; }
311 } 320 }
312 321
322 public ISnmpModule SnmpService
323 {
324 get
325 {
326 if (m_snmpService == null)
327 {
328 m_snmpService = RequestModuleInterface<ISnmpModule>();
329 }
330
331 return m_snmpService;
332 }
333 }
334
313 public ISimulationDataService SimulationDataService 335 public ISimulationDataService SimulationDataService
314 { 336 {
315 get 337 get
@@ -592,6 +614,8 @@ namespace OpenSim.Region.Framework.Scenes
592 m_EstateDataService = estateDataService; 614 m_EstateDataService = estateDataService;
593 m_regionHandle = m_regInfo.RegionHandle; 615 m_regionHandle = m_regInfo.RegionHandle;
594 m_regionName = m_regInfo.RegionName; 616 m_regionName = m_regInfo.RegionName;
617 m_lastIncoming = 0;
618 m_lastOutgoing = 0;
595 619
596 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 620 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
597 m_asyncSceneObjectDeleter.Enabled = true; 621 m_asyncSceneObjectDeleter.Enabled = true;
@@ -672,98 +696,107 @@ namespace OpenSim.Region.Framework.Scenes
672 696
673 // Region config overrides global config 697 // Region config overrides global config
674 // 698 //
675 if (m_config.Configs["Startup"] != null) 699 try
676 { 700 {
677 IConfig startupConfig = m_config.Configs["Startup"]; 701 if (m_config.Configs["Startup"] != null)
678
679 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
680 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
681 if (!m_useBackup)
682 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
683
684 //Animation states
685 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
686
687 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims);
688 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims);
689
690 m_maxNonphys = startupConfig.GetFloat("NonphysicalPrimMax", m_maxNonphys);
691 if (RegionInfo.NonphysPrimMax > 0)
692 { 702 {
693 m_maxNonphys = RegionInfo.NonphysPrimMax; 703 IConfig startupConfig = m_config.Configs["Startup"];
694 }
695 704
696 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 705 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
706 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
707 if (!m_useBackup)
708 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
709
710 //Animation states
711 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
697 712
698 if (RegionInfo.PhysPrimMax > 0) 713 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
699 { 714 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
700 m_maxPhys = RegionInfo.PhysPrimMax;
701 }
702 715
703 // Here, if clamping is requested in either global or 716 m_maxNonphys = startupConfig.GetFloat("NonphysicalPrimMax", m_maxNonphys);
704 // local config, it will be used 717 if (RegionInfo.NonphysPrimMax > 0)
705 // 718 {
706 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize); 719 m_maxNonphys = RegionInfo.NonphysPrimMax;
707 if (RegionInfo.ClampPrimSize) 720 }
708 {
709 m_clampPrimSize = true;
710 }
711 721
712 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 722 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
713 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
714 m_dontPersistBefore =
715 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE);
716 m_dontPersistBefore *= 10000000;
717 m_persistAfter =
718 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
719 m_persistAfter *= 10000000;
720 723
721 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 724 if (RegionInfo.PhysPrimMax > 0)
725 {
726 m_maxPhys = RegionInfo.PhysPrimMax;
727 }
722 728
723 IConfig packetConfig = m_config.Configs["PacketPool"]; 729 // Here, if clamping is requested in either global or
724 if (packetConfig != null) 730 // local config, it will be used
725 { 731 //
726 PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true); 732 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
727 PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true); 733 if (RegionInfo.ClampPrimSize)
728 } 734 {
735 m_clampPrimSize = true;
736 }
729 737
730 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 738 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
739 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
740 m_dontPersistBefore =
741 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE);
742 m_dontPersistBefore *= 10000000;
743 m_persistAfter =
744 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
745 m_persistAfter *= 10000000;
731 746
732 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 747 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
733 if (m_generateMaptiles) 748 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
734 { 749
735 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0); 750 IConfig packetConfig = m_config.Configs["PacketPool"];
736 if (maptileRefresh != 0) 751 if (packetConfig != null)
737 { 752 {
738 m_mapGenerationTimer.Interval = maptileRefresh * 1000; 753 PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true);
739 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister; 754 PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true);
740 m_mapGenerationTimer.AutoReset = true;
741 m_mapGenerationTimer.Start();
742 } 755 }
743 }
744 else
745 {
746 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
747 UUID tileID;
748 756
749 if (UUID.TryParse(tile, out tileID)) 757 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
758 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
759 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
760
761 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
762 if (m_generateMaptiles)
750 { 763 {
751 RegionInfo.RegionSettings.TerrainImageID = tileID; 764 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0);
765 if (maptileRefresh != 0)
766 {
767 m_mapGenerationTimer.Interval = maptileRefresh * 1000;
768 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
769 m_mapGenerationTimer.AutoReset = true;
770 m_mapGenerationTimer.Start();
771 }
752 } 772 }
753 } 773 else
774 {
775 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
776 UUID tileID;
754 777
755 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime); 778 if (UUID.TryParse(tile, out tileID))
756 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup); 779 {
757 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations); 780 RegionInfo.RegionSettings.TerrainImageID = tileID;
758 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement); 781 }
759 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events); 782 }
760 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
761 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
762 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
763 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
764 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
765 783
766 SendPeriodicAppearanceUpdates = startupConfig.GetBoolean("SendPeriodicAppearanceUpdates", SendPeriodicAppearanceUpdates); 784 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime);
785 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup);
786 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations);
787 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement);
788 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events);
789 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
790 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
791 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
792 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
793 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
794 SendPeriodicAppearanceUpdates = startupConfig.GetBoolean("SendPeriodicAppearanceUpdates", SendPeriodicAppearanceUpdates);
795 }
796 }
797 catch (Exception e)
798 {
799 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
767 } 800 }
768 801
769 #endregion Region Config 802 #endregion Region Config
@@ -1190,7 +1223,22 @@ namespace OpenSim.Region.Framework.Scenes
1190 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1223 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1191 if (m_heartbeatThread != null) 1224 if (m_heartbeatThread != null)
1192 { 1225 {
1226 m_hbRestarts++;
1227 if(m_hbRestarts > 10)
1228 Environment.Exit(1);
1229 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1230
1231//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1232//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1233//proc.EnableRaisingEvents=false;
1234//proc.StartInfo.FileName = "/bin/kill";
1235//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1236//proc.Start();
1237//proc.WaitForExit();
1238//Thread.Sleep(1000);
1239//Environment.Exit(1);
1193 m_heartbeatThread.Abort(); 1240 m_heartbeatThread.Abort();
1241 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1194 m_heartbeatThread = null; 1242 m_heartbeatThread = null;
1195 } 1243 }
1196// m_lastUpdate = Util.EnvironmentTickCount(); 1244// m_lastUpdate = Util.EnvironmentTickCount();
@@ -1503,6 +1551,8 @@ namespace OpenSim.Region.Framework.Scenes
1503 maintc = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1551 maintc = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc);
1504 maintc = (int)(MinFrameTime * 1000) - maintc; 1552 maintc = (int)(MinFrameTime * 1000) - maintc;
1505 1553
1554 m_firstHeartbeat = false;
1555
1506 if (maintc > 0) 1556 if (maintc > 0)
1507 Thread.Sleep(maintc); 1557 Thread.Sleep(maintc);
1508 1558
@@ -1532,9 +1582,9 @@ namespace OpenSim.Region.Framework.Scenes
1532 1582
1533 private void CheckAtTargets() 1583 private void CheckAtTargets()
1534 { 1584 {
1535 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1585 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1536 lock (m_groupsWithTargets) 1586 lock (m_groupsWithTargets)
1537 objs = m_groupsWithTargets.Values; 1587 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1538 1588
1539 foreach (SceneObjectGroup entry in objs) 1589 foreach (SceneObjectGroup entry in objs)
1540 entry.checkAtTargets(); 1590 entry.checkAtTargets();
@@ -1615,7 +1665,7 @@ namespace OpenSim.Region.Framework.Scenes
1615 msg.fromAgentName = "Server"; 1665 msg.fromAgentName = "Server";
1616 msg.dialog = (byte)19; // Object msg 1666 msg.dialog = (byte)19; // Object msg
1617 msg.fromGroup = false; 1667 msg.fromGroup = false;
1618 msg.offline = (byte)0; 1668 msg.offline = (byte)1;
1619 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1669 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1620 msg.Position = Vector3.Zero; 1670 msg.Position = Vector3.Zero;
1621 msg.RegionID = RegionInfo.RegionID.Guid; 1671 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1837,6 +1887,19 @@ namespace OpenSim.Region.Framework.Scenes
1837 EventManager.TriggerPrimsLoaded(this); 1887 EventManager.TriggerPrimsLoaded(this);
1838 } 1888 }
1839 1889
1890 public bool SuportsRayCastFiltered()
1891 {
1892 if (PhysicsScene == null)
1893 return false;
1894 return PhysicsScene.SuportsRaycastWorldFiltered();
1895 }
1896
1897 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
1898 {
1899 if (PhysicsScene == null)
1900 return null;
1901 return PhysicsScene.RaycastWorld(position, direction, length, Count,filter);
1902 }
1840 1903
1841 /// <summary> 1904 /// <summary>
1842 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed. 1905 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
@@ -1853,14 +1916,24 @@ namespace OpenSim.Region.Framework.Scenes
1853 /// <returns></returns> 1916 /// <returns></returns>
1854 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1917 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1855 { 1918 {
1919
1920 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1921 Vector3 wpos = Vector3.Zero;
1922 // Check for water surface intersection from above
1923 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1924 {
1925 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1926 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1927 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1928 wpos.Z = wheight;
1929 }
1930
1856 Vector3 pos = Vector3.Zero; 1931 Vector3 pos = Vector3.Zero;
1857 if (RayEndIsIntersection == (byte)1) 1932 if (RayEndIsIntersection == (byte)1)
1858 { 1933 {
1859 pos = RayEnd; 1934 pos = RayEnd;
1860 return pos;
1861 } 1935 }
1862 1936 else if (RayTargetID != UUID.Zero)
1863 if (RayTargetID != UUID.Zero)
1864 { 1937 {
1865 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1938 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1866 1939
@@ -1882,7 +1955,7 @@ namespace OpenSim.Region.Framework.Scenes
1882 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1955 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1883 1956
1884 // Un-comment out the following line to Get Raytrace results printed to the console. 1957 // Un-comment out the following line to Get Raytrace results printed to the console.
1885 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1958 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1886 float ScaleOffset = 0.5f; 1959 float ScaleOffset = 0.5f;
1887 1960
1888 // If we hit something 1961 // If we hit something
@@ -1905,13 +1978,10 @@ namespace OpenSim.Region.Framework.Scenes
1905 //pos.Z -= 0.25F; 1978 //pos.Z -= 0.25F;
1906 1979
1907 } 1980 }
1908
1909 return pos;
1910 } 1981 }
1911 else 1982 else
1912 { 1983 {
1913 // We don't have a target here, so we're going to raytrace all the objects in the scene. 1984 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1914
1915 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 1985 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1916 1986
1917 // Un-comment the following line to print the raytrace results to the console. 1987 // Un-comment the following line to print the raytrace results to the console.
@@ -1920,13 +1990,12 @@ namespace OpenSim.Region.Framework.Scenes
1920 if (ei.HitTF) 1990 if (ei.HitTF)
1921 { 1991 {
1922 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 1992 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1923 } else 1993 }
1994 else
1924 { 1995 {
1925 // fall back to our stupid functionality 1996 // fall back to our stupid functionality
1926 pos = RayEnd; 1997 pos = RayEnd;
1927 } 1998 }
1928
1929 return pos;
1930 } 1999 }
1931 } 2000 }
1932 else 2001 else
@@ -1937,8 +2006,12 @@ namespace OpenSim.Region.Framework.Scenes
1937 //increase height so its above the ground. 2006 //increase height so its above the ground.
1938 //should be getting the normal of the ground at the rez point and using that? 2007 //should be getting the normal of the ground at the rez point and using that?
1939 pos.Z += scale.Z / 2f; 2008 pos.Z += scale.Z / 2f;
1940 return pos; 2009// return pos;
1941 } 2010 }
2011
2012 // check against posible water intercept
2013 if (wpos.Z > pos.Z) pos = wpos;
2014 return pos;
1942 } 2015 }
1943 2016
1944 2017
@@ -2028,7 +2101,10 @@ namespace OpenSim.Region.Framework.Scenes
2028 public bool AddRestoredSceneObject( 2101 public bool AddRestoredSceneObject(
2029 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 2102 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
2030 { 2103 {
2031 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 2104 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
2105 if (result)
2106 sceneObject.IsDeleted = false;
2107 return result;
2032 } 2108 }
2033 2109
2034 /// <summary> 2110 /// <summary>
@@ -2120,6 +2196,15 @@ namespace OpenSim.Region.Framework.Scenes
2120 /// </summary> 2196 /// </summary>
2121 public void DeleteAllSceneObjects() 2197 public void DeleteAllSceneObjects()
2122 { 2198 {
2199 DeleteAllSceneObjects(false);
2200 }
2201
2202 /// <summary>
2203 /// Delete every object from the scene. This does not include attachments worn by avatars.
2204 /// </summary>
2205 public void DeleteAllSceneObjects(bool exceptNoCopy)
2206 {
2207 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2123 lock (Entities) 2208 lock (Entities)
2124 { 2209 {
2125 EntityBase[] entities = Entities.GetEntities(); 2210 EntityBase[] entities = Entities.GetEntities();
@@ -2128,11 +2213,24 @@ namespace OpenSim.Region.Framework.Scenes
2128 if (e is SceneObjectGroup) 2213 if (e is SceneObjectGroup)
2129 { 2214 {
2130 SceneObjectGroup sog = (SceneObjectGroup)e; 2215 SceneObjectGroup sog = (SceneObjectGroup)e;
2131 if (!sog.IsAttachment) 2216 if (sog != null && !sog.IsAttachment)
2132 DeleteSceneObject((SceneObjectGroup)e, false); 2217 {
2218 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2219 {
2220 DeleteSceneObject((SceneObjectGroup)e, false);
2221 }
2222 else
2223 {
2224 toReturn.Add((SceneObjectGroup)e);
2225 }
2226 }
2133 } 2227 }
2134 } 2228 }
2135 } 2229 }
2230 if (toReturn.Count > 0)
2231 {
2232 returnObjects(toReturn.ToArray(), UUID.Zero);
2233 }
2136 } 2234 }
2137 2235
2138 /// <summary> 2236 /// <summary>
@@ -2167,6 +2265,8 @@ namespace OpenSim.Region.Framework.Scenes
2167 } 2265 }
2168 2266
2169 group.DeleteGroupFromScene(silent); 2267 group.DeleteGroupFromScene(silent);
2268 if (!silent)
2269 SendKillObject(new List<uint>() { group.LocalId });
2170 2270
2171// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2271// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2172 } 2272 }
@@ -2456,6 +2556,8 @@ namespace OpenSim.Region.Framework.Scenes
2456 2556
2457 if (newPosition != Vector3.Zero) 2557 if (newPosition != Vector3.Zero)
2458 newObject.RootPart.GroupPosition = newPosition; 2558 newObject.RootPart.GroupPosition = newPosition;
2559 if (newObject.RootPart.KeyframeMotion != null)
2560 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2459 2561
2460 if (!AddSceneObject(newObject)) 2562 if (!AddSceneObject(newObject))
2461 { 2563 {
@@ -2524,10 +2626,17 @@ namespace OpenSim.Region.Framework.Scenes
2524 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2626 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2525 public bool AddSceneObject(SceneObjectGroup sceneObject) 2627 public bool AddSceneObject(SceneObjectGroup sceneObject)
2526 { 2628 {
2629 if (sceneObject.OwnerID == UUID.Zero)
2630 {
2631 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2632 return false;
2633 }
2634
2527 // If the user is banned, we won't let any of their objects 2635 // If the user is banned, we won't let any of their objects
2528 // enter. Period. 2636 // enter. Period.
2529 // 2637 //
2530 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2638 int flags = GetUserFlags(sceneObject.OwnerID);
2639 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2531 { 2640 {
2532 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID); 2641 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2533 2642
@@ -2573,12 +2682,23 @@ namespace OpenSim.Region.Framework.Scenes
2573 } 2682 }
2574 else 2683 else
2575 { 2684 {
2685 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2576 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2686 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2577 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2687 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2578 } 2688 }
2689 if (sceneObject.OwnerID == UUID.Zero)
2690 {
2691 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2692 return false;
2693 }
2579 } 2694 }
2580 else 2695 else
2581 { 2696 {
2697 if (sceneObject.OwnerID == UUID.Zero)
2698 {
2699 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2700 return false;
2701 }
2582 AddRestoredSceneObject(sceneObject, true, false); 2702 AddRestoredSceneObject(sceneObject, true, false);
2583 2703
2584 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2704 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2607,6 +2727,24 @@ namespace OpenSim.Region.Framework.Scenes
2607 return 2; // StateSource.PrimCrossing 2727 return 2; // StateSource.PrimCrossing
2608 } 2728 }
2609 2729
2730 public int GetUserFlags(UUID user)
2731 {
2732 //Unfortunately the SP approach means that the value is cached until region is restarted
2733 /*
2734 ScenePresence sp;
2735 if (TryGetScenePresence(user, out sp))
2736 {
2737 return sp.UserFlags;
2738 }
2739 else
2740 {
2741 */
2742 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2743 if (uac == null)
2744 return 0;
2745 return uac.UserFlags;
2746 //}
2747 }
2610 #endregion 2748 #endregion
2611 2749
2612 #region Add/Remove Avatar Methods 2750 #region Add/Remove Avatar Methods
@@ -2620,7 +2758,7 @@ namespace OpenSim.Region.Framework.Scenes
2620 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2758 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2621 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2759 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2622 2760
2623// CheckHeartbeat(); 2761 CheckHeartbeat();
2624 2762
2625 ScenePresence sp = GetScenePresence(client.AgentId); 2763 ScenePresence sp = GetScenePresence(client.AgentId);
2626 2764
@@ -2673,7 +2811,13 @@ namespace OpenSim.Region.Framework.Scenes
2673 2811
2674 EventManager.TriggerOnNewClient(client); 2812 EventManager.TriggerOnNewClient(client);
2675 if (vialogin) 2813 if (vialogin)
2814 {
2676 EventManager.TriggerOnClientLogin(client); 2815 EventManager.TriggerOnClientLogin(client);
2816 // Send initial parcel data
2817 Vector3 pos = sp.AbsolutePosition;
2818 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2819 land.SendLandUpdateToClient(client);
2820 }
2677 2821
2678 return sp; 2822 return sp;
2679 } 2823 }
@@ -2763,19 +2907,12 @@ namespace OpenSim.Region.Framework.Scenes
2763 // and the scene presence and the client, if they exist 2907 // and the scene presence and the client, if they exist
2764 try 2908 try
2765 { 2909 {
2766 // We need to wait for the client to make UDP contact first. 2910 ScenePresence sp = GetScenePresence(agentID);
2767 // It's the UDP contact that creates the scene presence 2911 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2768 ScenePresence sp = WaitGetScenePresence(agentID); 2912
2769 if (sp != null) 2913 if (sp != null)
2770 {
2771 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2772
2773 sp.ControllingClient.Close(); 2914 sp.ControllingClient.Close();
2774 } 2915
2775 else
2776 {
2777 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2778 }
2779 // BANG! SLASH! 2916 // BANG! SLASH!
2780 m_authenticateHandler.RemoveCircuit(agentID); 2917 m_authenticateHandler.RemoveCircuit(agentID);
2781 2918
@@ -2820,6 +2957,8 @@ namespace OpenSim.Region.Framework.Scenes
2820 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 2957 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2821 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 2958 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2822 2959
2960 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
2961
2823 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 2962 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2824 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 2963 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2825 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 2964 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -2876,6 +3015,7 @@ namespace OpenSim.Region.Framework.Scenes
2876 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3015 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2877 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3016 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2878 client.OnCopyInventoryItem += CopyInventoryItem; 3017 client.OnCopyInventoryItem += CopyInventoryItem;
3018 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2879 client.OnMoveInventoryItem += MoveInventoryItem; 3019 client.OnMoveInventoryItem += MoveInventoryItem;
2880 client.OnRemoveInventoryItem += RemoveInventoryItem; 3020 client.OnRemoveInventoryItem += RemoveInventoryItem;
2881 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3021 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2947,6 +3087,8 @@ namespace OpenSim.Region.Framework.Scenes
2947 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3087 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
2948 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3088 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
2949 3089
3090 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3091
2950 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3092 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
2951 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3093 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
2952 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3094 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3049,15 +3191,16 @@ namespace OpenSim.Region.Framework.Scenes
3049 /// </summary> 3191 /// </summary>
3050 /// <param name="agentId">The avatar's Unique ID</param> 3192 /// <param name="agentId">The avatar's Unique ID</param>
3051 /// <param name="client">The IClientAPI for the client</param> 3193 /// <param name="client">The IClientAPI for the client</param>
3052 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3194 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3053 { 3195 {
3054 if (m_teleportModule != null) 3196 if (m_teleportModule != null)
3055 m_teleportModule.TeleportHome(agentId, client); 3197 return m_teleportModule.TeleportHome(agentId, client);
3056 else 3198 else
3057 { 3199 {
3058 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3200 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3059 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3201 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3060 } 3202 }
3203 return false;
3061 } 3204 }
3062 3205
3063 /// <summary> 3206 /// <summary>
@@ -3167,6 +3310,16 @@ namespace OpenSim.Region.Framework.Scenes
3167 /// <param name="flags"></param> 3310 /// <param name="flags"></param>
3168 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3311 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3169 { 3312 {
3313 //Add half the avatar's height so that the user doesn't fall through prims
3314 ScenePresence presence;
3315 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3316 {
3317 if (presence.Appearance != null)
3318 {
3319 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3320 }
3321 }
3322
3170 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3323 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3171 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3324 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3172 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3325 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3235,8 +3388,9 @@ namespace OpenSim.Region.Framework.Scenes
3235 regions.Remove(RegionInfo.RegionHandle); 3388 regions.Remove(RegionInfo.RegionHandle);
3236 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3389 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3237 } 3390 }
3238 3391 m_log.Debug("[Scene] Beginning ClientClosed");
3239 m_eventManager.TriggerClientClosed(agentID, this); 3392 m_eventManager.TriggerClientClosed(agentID, this);
3393 m_log.Debug("[Scene] Finished ClientClosed");
3240 } 3394 }
3241 catch (NullReferenceException) 3395 catch (NullReferenceException)
3242 { 3396 {
@@ -3298,9 +3452,10 @@ namespace OpenSim.Region.Framework.Scenes
3298 { 3452 {
3299 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace); 3453 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace);
3300 } 3454 }
3301 3455 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3302 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3456 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3303// CleanDroppedAttachments(); 3457// CleanDroppedAttachments();
3458 m_log.Debug("[Scene] The avatar has left the building");
3304 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3459 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3305 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3460 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3306 } 3461 }
@@ -3422,13 +3577,16 @@ namespace OpenSim.Region.Framework.Scenes
3422 sp = null; 3577 sp = null;
3423 } 3578 }
3424 3579
3425 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3426 3580
3427 //On login test land permisions 3581 //On login test land permisions
3428 if (vialogin) 3582 if (vialogin)
3429 { 3583 {
3430 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3584 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3585 if (cache != null)
3586 cache.Remove(agent.firstname + " " + agent.lastname);
3587 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3431 { 3588 {
3589 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3432 return false; 3590 return false;
3433 } 3591 }
3434 } 3592 }
@@ -3452,8 +3610,13 @@ namespace OpenSim.Region.Framework.Scenes
3452 3610
3453 try 3611 try
3454 { 3612 {
3455 if (!AuthorizeUser(agent, out reason)) 3613 // Always check estate if this is a login. Always
3456 return false; 3614 // check if banned regions are to be blacked out.
3615 if (vialogin || (!m_seeIntoBannedRegion))
3616 {
3617 if (!AuthorizeUser(agent, out reason))
3618 return false;
3619 }
3457 } 3620 }
3458 catch (Exception e) 3621 catch (Exception e)
3459 { 3622 {
@@ -3579,6 +3742,8 @@ namespace OpenSim.Region.Framework.Scenes
3579 } 3742 }
3580 3743
3581 // Honor parcel landing type and position. 3744 // Honor parcel landing type and position.
3745 /*
3746 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3582 if (land != null) 3747 if (land != null)
3583 { 3748 {
3584 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3749 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3586,26 +3751,34 @@ namespace OpenSim.Region.Framework.Scenes
3586 agent.startpos = land.LandData.UserLocation; 3751 agent.startpos = land.LandData.UserLocation;
3587 } 3752 }
3588 } 3753 }
3754 */// This is now handled properly in ScenePresence.MakeRootAgent
3589 } 3755 }
3590 3756
3591 return true; 3757 return true;
3592 } 3758 }
3593 3759
3594 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3760 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3595 { 3761 {
3596 3762 reason = String.Empty;
3597 bool banned = land.IsBannedFromLand(agent.AgentID); 3763 if (Permissions.IsGod(agentID))
3598 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3764 return true;
3765
3766 ILandObject land = LandChannel.GetLandObject(posX, posY);
3767 if (land == null)
3768 return false;
3769
3770 bool banned = land.IsBannedFromLand(agentID);
3771 bool restricted = land.IsRestrictedFromLand(agentID);
3599 3772
3600 if (banned || restricted) 3773 if (banned || restricted)
3601 { 3774 {
3602 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3775 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3603 if (nearestParcel != null) 3776 if (nearestParcel != null)
3604 { 3777 {
3605 //Move agent to nearest allowed 3778 //Move agent to nearest allowed
3606 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3779 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3607 agent.startpos.X = newPosition.X; 3780 posX = newPosition.X;
3608 agent.startpos.Y = newPosition.Y; 3781 posY = newPosition.Y;
3609 } 3782 }
3610 else 3783 else
3611 { 3784 {
@@ -3667,7 +3840,7 @@ namespace OpenSim.Region.Framework.Scenes
3667 3840
3668 if (!m_strictAccessControl) return true; 3841 if (!m_strictAccessControl) return true;
3669 if (Permissions.IsGod(agent.AgentID)) return true; 3842 if (Permissions.IsGod(agent.AgentID)) return true;
3670 3843
3671 if (AuthorizationService != null) 3844 if (AuthorizationService != null)
3672 { 3845 {
3673 if (!AuthorizationService.IsAuthorizedForRegion( 3846 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3682,7 +3855,7 @@ namespace OpenSim.Region.Framework.Scenes
3682 3855
3683 if (m_regInfo.EstateSettings != null) 3856 if (m_regInfo.EstateSettings != null)
3684 { 3857 {
3685 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3858 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3686 { 3859 {
3687 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3860 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3688 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3861 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3874,6 +4047,13 @@ namespace OpenSim.Region.Framework.Scenes
3874 4047
3875 // We have to wait until the viewer contacts this region after receiving EAC. 4048 // We have to wait until the viewer contacts this region after receiving EAC.
3876 // That calls AddNewClient, which finally creates the ScenePresence 4049 // That calls AddNewClient, which finally creates the ScenePresence
4050 int flags = GetUserFlags(cAgentData.AgentID);
4051 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4052 {
4053 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4054 return false;
4055 }
4056
3877 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4057 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3878 if (nearestParcel == null) 4058 if (nearestParcel == null)
3879 { 4059 {
@@ -3955,12 +4135,22 @@ namespace OpenSim.Region.Framework.Scenes
3955 return false; 4135 return false;
3956 } 4136 }
3957 4137
4138 public bool IncomingCloseAgent(UUID agentID)
4139 {
4140 return IncomingCloseAgent(agentID, false);
4141 }
4142
4143 public bool IncomingCloseChildAgent(UUID agentID)
4144 {
4145 return IncomingCloseAgent(agentID, true);
4146 }
4147
3958 /// <summary> 4148 /// <summary>
3959 /// Tell a single agent to disconnect from the region. 4149 /// Tell a single agent to disconnect from the region.
3960 /// </summary> 4150 /// </summary>
3961 /// <param name="regionHandle"></param>
3962 /// <param name="agentID"></param> 4151 /// <param name="agentID"></param>
3963 public bool IncomingCloseAgent(UUID agentID) 4152 /// <param name="childOnly"></param>
4153 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
3964 { 4154 {
3965 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 4155 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
3966 4156
@@ -3972,7 +4162,7 @@ namespace OpenSim.Region.Framework.Scenes
3972 { 4162 {
3973 m_sceneGraph.removeUserCount(false); 4163 m_sceneGraph.removeUserCount(false);
3974 } 4164 }
3975 else 4165 else if (!childOnly)
3976 { 4166 {
3977 m_sceneGraph.removeUserCount(true); 4167 m_sceneGraph.removeUserCount(true);
3978 } 4168 }
@@ -3988,9 +4178,12 @@ namespace OpenSim.Region.Framework.Scenes
3988 } 4178 }
3989 else 4179 else
3990 presence.ControllingClient.SendShutdownConnectionNotice(); 4180 presence.ControllingClient.SendShutdownConnectionNotice();
4181 presence.ControllingClient.Close(false);
4182 }
4183 else if (!childOnly)
4184 {
4185 presence.ControllingClient.Close(true);
3991 } 4186 }
3992
3993 presence.ControllingClient.Close();
3994 return true; 4187 return true;
3995 } 4188 }
3996 4189
@@ -4572,35 +4765,81 @@ namespace OpenSim.Region.Framework.Scenes
4572 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4765 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4573 } 4766 }
4574 4767
4575 public int GetHealth() 4768 public int GetHealth(out int flags, out string message)
4576 { 4769 {
4577 // Returns: 4770 // Returns:
4578 // 1 = sim is up and accepting http requests. The heartbeat has 4771 // 1 = sim is up and accepting http requests. The heartbeat has
4579 // stopped and the sim is probably locked up, but a remote 4772 // stopped and the sim is probably locked up, but a remote
4580 // admin restart may succeed 4773 // admin restart may succeed
4581 // 4774 //
4582 // 2 = Sim is up and the heartbeat is running. The sim is likely 4775 // 2 = Sim is up and the heartbeat is running. The sim is likely
4583 // usable for people within and logins _may_ work 4776 // usable for people within
4777 //
4778 // 3 = Sim is up and one packet thread is running. Sim is
4779 // unstable and will not accept new logins
4780 //
4781 // 4 = Sim is up and both packet threads are running. Sim is
4782 // likely usable
4584 // 4783 //
4585 // 3 = We have seen a new user enter within the past 4 minutes 4784 // 5 = We have seen a new user enter within the past 4 minutes
4586 // which can be seen as positive confirmation of sim health 4785 // which can be seen as positive confirmation of sim health
4587 // 4786 //
4787
4788 flags = 0;
4789 message = String.Empty;
4790
4791 CheckHeartbeat();
4792
4793 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4794 {
4795 // We're still starting
4796 // 0 means "in startup", it can't happen another way, since
4797 // to get here, we must be able to accept http connections
4798 return 0;
4799 }
4800
4588 int health=1; // Start at 1, means we're up 4801 int health=1; // Start at 1, means we're up
4589 4802
4590 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 4803 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4591 health += 1; 4804 {
4805 health+=1;
4806 flags |= 1;
4807 }
4808
4809 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4810 {
4811 health+=1;
4812 flags |= 2;
4813 }
4814
4815 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4816 {
4817 health+=1;
4818 flags |= 4;
4819 }
4592 else 4820 else
4821 {
4822int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
4823System.Diagnostics.Process proc = new System.Diagnostics.Process();
4824proc.EnableRaisingEvents=false;
4825proc.StartInfo.FileName = "/bin/kill";
4826proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
4827proc.Start();
4828proc.WaitForExit();
4829Thread.Sleep(1000);
4830Environment.Exit(1);
4831 }
4832
4833 if (flags != 7)
4593 return health; 4834 return health;
4594 4835
4595 // A login in the last 4 mins? We can't be doing too badly 4836 // A login in the last 4 mins? We can't be doing too badly
4596 // 4837 //
4597 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4838 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4598 health++; 4839 health++;
4599 else 4840 else
4600 return health; 4841 return health;
4601 4842
4602// CheckHeartbeat();
4603
4604 return health; 4843 return health;
4605 } 4844 }
4606 4845
@@ -4688,7 +4927,7 @@ namespace OpenSim.Region.Framework.Scenes
4688 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 4927 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
4689 if (wasUsingPhysics) 4928 if (wasUsingPhysics)
4690 { 4929 {
4691 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 4930 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
4692 } 4931 }
4693 } 4932 }
4694 4933
@@ -4787,14 +5026,14 @@ namespace OpenSim.Region.Framework.Scenes
4787 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5026 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
4788 } 5027 }
4789 5028
4790// private void CheckHeartbeat() 5029 private void CheckHeartbeat()
4791// { 5030 {
4792// if (m_firstHeartbeat) 5031 if (m_firstHeartbeat)
4793// return; 5032 return;
4794// 5033
4795// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5034 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
4796// StartTimer(); 5035 Start();
4797// } 5036 }
4798 5037
4799 public override ISceneObject DeserializeObject(string representation) 5038 public override ISceneObject DeserializeObject(string representation)
4800 { 5039 {
@@ -4806,9 +5045,14 @@ namespace OpenSim.Region.Framework.Scenes
4806 get { return m_allowScriptCrossings; } 5045 get { return m_allowScriptCrossings; }
4807 } 5046 }
4808 5047
4809 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5048 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
4810 { 5049 {
4811 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5050 return GetNearestAllowedPosition(avatar, null);
5051 }
5052
5053 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5054 {
5055 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
4812 5056
4813 if (nearestParcel != null) 5057 if (nearestParcel != null)
4814 { 5058 {
@@ -4817,10 +5061,7 @@ namespace OpenSim.Region.Framework.Scenes
4817 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5061 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4818 if (nearestPoint != null) 5062 if (nearestPoint != null)
4819 { 5063 {
4820// m_log.DebugFormat( 5064 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4821// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
4822// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
4823
4824 return nearestPoint.Value; 5065 return nearestPoint.Value;
4825 } 5066 }
4826 5067
@@ -4830,17 +5071,20 @@ namespace OpenSim.Region.Framework.Scenes
4830 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5071 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4831 if (nearestPoint != null) 5072 if (nearestPoint != null)
4832 { 5073 {
4833// m_log.DebugFormat( 5074 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4834// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
4835
4836 return nearestPoint.Value; 5075 return nearestPoint.Value;
4837 } 5076 }
4838 5077
4839 //Ultimate backup if we have no idea where they are 5078 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
4840// m_log.DebugFormat( 5079 if (dest != excludeParcel)
4841// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5080 {
5081 // Ultimate backup if we have no idea where they are and
5082 // the last allowed position was in another parcel
5083 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5084 return avatar.lastKnownAllowedPosition;
5085 }
4842 5086
4843 return avatar.lastKnownAllowedPosition; 5087 // else fall through to region edge
4844 } 5088 }
4845 5089
4846 //Go to the edge, this happens in teleporting to a region with no available parcels 5090 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -4874,13 +5118,18 @@ namespace OpenSim.Region.Framework.Scenes
4874 5118
4875 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5119 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
4876 { 5120 {
5121 return GetNearestAllowedParcel(avatarId, x, y, null);
5122 }
5123
5124 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5125 {
4877 List<ILandObject> all = AllParcels(); 5126 List<ILandObject> all = AllParcels();
4878 float minParcelDistance = float.MaxValue; 5127 float minParcelDistance = float.MaxValue;
4879 ILandObject nearestParcel = null; 5128 ILandObject nearestParcel = null;
4880 5129
4881 foreach (var parcel in all) 5130 foreach (var parcel in all)
4882 { 5131 {
4883 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5132 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
4884 { 5133 {
4885 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5134 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
4886 if (parcelDistance < minParcelDistance) 5135 if (parcelDistance < minParcelDistance)
@@ -5122,7 +5371,55 @@ namespace OpenSim.Region.Framework.Scenes
5122 mapModule.GenerateMaptile(); 5371 mapModule.GenerateMaptile();
5123 } 5372 }
5124 5373
5125 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5374// public void CleanDroppedAttachments()
5375// {
5376// List<SceneObjectGroup> objectsToDelete =
5377// new List<SceneObjectGroup>();
5378//
5379// lock (m_cleaningAttachments)
5380// {
5381// ForEachSOG(delegate (SceneObjectGroup grp)
5382// {
5383// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5384// {
5385// UUID agentID = grp.OwnerID;
5386// if (agentID == UUID.Zero)
5387// {
5388// objectsToDelete.Add(grp);
5389// return;
5390// }
5391//
5392// ScenePresence sp = GetScenePresence(agentID);
5393// if (sp == null)
5394// {
5395// objectsToDelete.Add(grp);
5396// return;
5397// }
5398// }
5399// });
5400// }
5401//
5402// foreach (SceneObjectGroup grp in objectsToDelete)
5403// {
5404// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5405// DeleteSceneObject(grp, true);
5406// }
5407// }
5408
5409 public void ThreadAlive(int threadCode)
5410 {
5411 switch(threadCode)
5412 {
5413 case 1: // Incoming
5414 m_lastIncoming = Util.EnvironmentTickCount();
5415 break;
5416 case 2: // Incoming
5417 m_lastOutgoing = Util.EnvironmentTickCount();
5418 break;
5419 }
5420 }
5421
5422 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5126 { 5423 {
5127 RegenerateMaptile(); 5424 RegenerateMaptile();
5128 5425
@@ -5141,6 +5438,14 @@ namespace OpenSim.Region.Framework.Scenes
5141 // child agent creation, thereby emulating the SL behavior. 5438 // child agent creation, thereby emulating the SL behavior.
5142 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5439 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5143 { 5440 {
5441 reason = "You are banned from the region";
5442
5443 if (Permissions.IsGod(agentID))
5444 {
5445 reason = String.Empty;
5446 return true;
5447 }
5448
5144 int num = m_sceneGraph.GetNumberOfScenePresences(); 5449 int num = m_sceneGraph.GetNumberOfScenePresences();
5145 5450
5146 if (num >= RegionInfo.RegionSettings.AgentLimit) 5451 if (num >= RegionInfo.RegionSettings.AgentLimit)
@@ -5152,6 +5457,41 @@ namespace OpenSim.Region.Framework.Scenes
5152 } 5457 }
5153 } 5458 }
5154 5459
5460 ScenePresence presence = GetScenePresence(agentID);
5461 IClientAPI client = null;
5462 AgentCircuitData aCircuit = null;
5463
5464 if (presence != null)
5465 {
5466 client = presence.ControllingClient;
5467 if (client != null)
5468 aCircuit = client.RequestClientInfo();
5469 }
5470
5471 // We may be called before there is a presence or a client.
5472 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5473 if (client == null)
5474 {
5475 aCircuit = new AgentCircuitData();
5476 aCircuit.AgentID = agentID;
5477 aCircuit.firstname = String.Empty;
5478 aCircuit.lastname = String.Empty;
5479 }
5480
5481 try
5482 {
5483 if (!AuthorizeUser(aCircuit, out reason))
5484 {
5485 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5486 return false;
5487 }
5488 }
5489 catch (Exception e)
5490 {
5491 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5492 return false;
5493 }
5494
5155 if (position == Vector3.Zero) // Teleport 5495 if (position == Vector3.Zero) // Teleport
5156 { 5496 {
5157 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5497 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5180,13 +5520,46 @@ namespace OpenSim.Region.Framework.Scenes
5180 } 5520 }
5181 } 5521 }
5182 } 5522 }
5523
5524 float posX = 128.0f;
5525 float posY = 128.0f;
5526
5527 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5528 {
5529 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5530 return false;
5531 }
5532 }
5533 else // Walking
5534 {
5535 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5536 if (land == null)
5537 return false;
5538
5539 bool banned = land.IsBannedFromLand(agentID);
5540 bool restricted = land.IsRestrictedFromLand(agentID);
5541
5542 if (banned || restricted)
5543 return false;
5183 } 5544 }
5184 5545
5185 reason = String.Empty; 5546 reason = String.Empty;
5186 return true; 5547 return true;
5187 } 5548 }
5188 5549
5189 /// <summary> 5550 public void StartTimerWatchdog()
5551 {
5552 m_timerWatchdog.Interval = 1000;
5553 m_timerWatchdog.Elapsed += TimerWatchdog;
5554 m_timerWatchdog.AutoReset = true;
5555 m_timerWatchdog.Start();
5556 }
5557
5558 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5559 {
5560 CheckHeartbeat();
5561 }
5562
5190 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5563 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5191 /// autopilot that moves an avatar to a sit target!. 5564 /// autopilot that moves an avatar to a sit target!.
5192 /// </summary> 5565 /// </summary>