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.cs684
1 files changed, 522 insertions, 162 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 29825a2..df37b98 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", true);
688 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
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
@@ -1194,7 +1227,22 @@ namespace OpenSim.Region.Framework.Scenes
1194 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1227 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1195 if (m_heartbeatThread != null) 1228 if (m_heartbeatThread != null)
1196 { 1229 {
1230 m_hbRestarts++;
1231 if(m_hbRestarts > 10)
1232 Environment.Exit(1);
1233 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1234
1235//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1236//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1237//proc.EnableRaisingEvents=false;
1238//proc.StartInfo.FileName = "/bin/kill";
1239//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1240//proc.Start();
1241//proc.WaitForExit();
1242//Thread.Sleep(1000);
1243//Environment.Exit(1);
1197 m_heartbeatThread.Abort(); 1244 m_heartbeatThread.Abort();
1245 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1198 m_heartbeatThread = null; 1246 m_heartbeatThread = null;
1199 } 1247 }
1200// m_lastUpdate = Util.EnvironmentTickCount(); 1248// m_lastUpdate = Util.EnvironmentTickCount();
@@ -1507,6 +1555,8 @@ namespace OpenSim.Region.Framework.Scenes
1507 maintc = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1555 maintc = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc);
1508 maintc = (int)(MinFrameTime * 1000) - maintc; 1556 maintc = (int)(MinFrameTime * 1000) - maintc;
1509 1557
1558 m_firstHeartbeat = false;
1559
1510 if (maintc > 0) 1560 if (maintc > 0)
1511 Thread.Sleep(maintc); 1561 Thread.Sleep(maintc);
1512 1562
@@ -1536,9 +1586,9 @@ namespace OpenSim.Region.Framework.Scenes
1536 1586
1537 private void CheckAtTargets() 1587 private void CheckAtTargets()
1538 { 1588 {
1539 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1589 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1540 lock (m_groupsWithTargets) 1590 lock (m_groupsWithTargets)
1541 objs = m_groupsWithTargets.Values; 1591 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1542 1592
1543 foreach (SceneObjectGroup entry in objs) 1593 foreach (SceneObjectGroup entry in objs)
1544 entry.checkAtTargets(); 1594 entry.checkAtTargets();
@@ -1619,7 +1669,7 @@ namespace OpenSim.Region.Framework.Scenes
1619 msg.fromAgentName = "Server"; 1669 msg.fromAgentName = "Server";
1620 msg.dialog = (byte)19; // Object msg 1670 msg.dialog = (byte)19; // Object msg
1621 msg.fromGroup = false; 1671 msg.fromGroup = false;
1622 msg.offline = (byte)0; 1672 msg.offline = (byte)1;
1623 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1673 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1624 msg.Position = Vector3.Zero; 1674 msg.Position = Vector3.Zero;
1625 msg.RegionID = RegionInfo.RegionID.Guid; 1675 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1857,14 +1907,24 @@ namespace OpenSim.Region.Framework.Scenes
1857 /// <returns></returns> 1907 /// <returns></returns>
1858 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 1908 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1859 { 1909 {
1910
1911 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
1912 Vector3 wpos = Vector3.Zero;
1913 // Check for water surface intersection from above
1914 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
1915 {
1916 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
1917 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
1918 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
1919 wpos.Z = wheight;
1920 }
1921
1860 Vector3 pos = Vector3.Zero; 1922 Vector3 pos = Vector3.Zero;
1861 if (RayEndIsIntersection == (byte)1) 1923 if (RayEndIsIntersection == (byte)1)
1862 { 1924 {
1863 pos = RayEnd; 1925 pos = RayEnd;
1864 return pos;
1865 } 1926 }
1866 1927 else if (RayTargetID != UUID.Zero)
1867 if (RayTargetID != UUID.Zero)
1868 { 1928 {
1869 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 1929 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1870 1930
@@ -1886,7 +1946,7 @@ namespace OpenSim.Region.Framework.Scenes
1886 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 1946 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
1887 1947
1888 // Un-comment out the following line to Get Raytrace results printed to the console. 1948 // Un-comment out the following line to Get Raytrace results printed to the console.
1889 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 1949 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
1890 float ScaleOffset = 0.5f; 1950 float ScaleOffset = 0.5f;
1891 1951
1892 // If we hit something 1952 // If we hit something
@@ -1909,13 +1969,10 @@ namespace OpenSim.Region.Framework.Scenes
1909 //pos.Z -= 0.25F; 1969 //pos.Z -= 0.25F;
1910 1970
1911 } 1971 }
1912
1913 return pos;
1914 } 1972 }
1915 else 1973 else
1916 { 1974 {
1917 // We don't have a target here, so we're going to raytrace all the objects in the scene. 1975 // We don't have a target here, so we're going to raytrace all the objects in the scene.
1918
1919 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 1976 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
1920 1977
1921 // Un-comment the following line to print the raytrace results to the console. 1978 // Un-comment the following line to print the raytrace results to the console.
@@ -1924,13 +1981,12 @@ namespace OpenSim.Region.Framework.Scenes
1924 if (ei.HitTF) 1981 if (ei.HitTF)
1925 { 1982 {
1926 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 1983 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
1927 } else 1984 }
1985 else
1928 { 1986 {
1929 // fall back to our stupid functionality 1987 // fall back to our stupid functionality
1930 pos = RayEnd; 1988 pos = RayEnd;
1931 } 1989 }
1932
1933 return pos;
1934 } 1990 }
1935 } 1991 }
1936 else 1992 else
@@ -1941,8 +1997,12 @@ namespace OpenSim.Region.Framework.Scenes
1941 //increase height so its above the ground. 1997 //increase height so its above the ground.
1942 //should be getting the normal of the ground at the rez point and using that? 1998 //should be getting the normal of the ground at the rez point and using that?
1943 pos.Z += scale.Z / 2f; 1999 pos.Z += scale.Z / 2f;
1944 return pos; 2000// return pos;
1945 } 2001 }
2002
2003 // check against posible water intercept
2004 if (wpos.Z > pos.Z) pos = wpos;
2005 return pos;
1946 } 2006 }
1947 2007
1948 2008
@@ -2032,7 +2092,10 @@ namespace OpenSim.Region.Framework.Scenes
2032 public bool AddRestoredSceneObject( 2092 public bool AddRestoredSceneObject(
2033 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 2093 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
2034 { 2094 {
2035 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 2095 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
2096 if (result)
2097 sceneObject.IsDeleted = false;
2098 return result;
2036 } 2099 }
2037 2100
2038 /// <summary> 2101 /// <summary>
@@ -2124,6 +2187,15 @@ namespace OpenSim.Region.Framework.Scenes
2124 /// </summary> 2187 /// </summary>
2125 public void DeleteAllSceneObjects() 2188 public void DeleteAllSceneObjects()
2126 { 2189 {
2190 DeleteAllSceneObjects(false);
2191 }
2192
2193 /// <summary>
2194 /// Delete every object from the scene. This does not include attachments worn by avatars.
2195 /// </summary>
2196 public void DeleteAllSceneObjects(bool exceptNoCopy)
2197 {
2198 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2127 lock (Entities) 2199 lock (Entities)
2128 { 2200 {
2129 EntityBase[] entities = Entities.GetEntities(); 2201 EntityBase[] entities = Entities.GetEntities();
@@ -2132,11 +2204,24 @@ namespace OpenSim.Region.Framework.Scenes
2132 if (e is SceneObjectGroup) 2204 if (e is SceneObjectGroup)
2133 { 2205 {
2134 SceneObjectGroup sog = (SceneObjectGroup)e; 2206 SceneObjectGroup sog = (SceneObjectGroup)e;
2135 if (!sog.IsAttachment) 2207 if (sog != null && !sog.IsAttachment)
2136 DeleteSceneObject((SceneObjectGroup)e, false); 2208 {
2209 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2210 {
2211 DeleteSceneObject((SceneObjectGroup)e, false);
2212 }
2213 else
2214 {
2215 toReturn.Add((SceneObjectGroup)e);
2216 }
2217 }
2137 } 2218 }
2138 } 2219 }
2139 } 2220 }
2221 if (toReturn.Count > 0)
2222 {
2223 returnObjects(toReturn.ToArray(), UUID.Zero);
2224 }
2140 } 2225 }
2141 2226
2142 /// <summary> 2227 /// <summary>
@@ -2177,6 +2262,8 @@ namespace OpenSim.Region.Framework.Scenes
2177 } 2262 }
2178 2263
2179 group.DeleteGroupFromScene(silent); 2264 group.DeleteGroupFromScene(silent);
2265 if (!silent)
2266 SendKillObject(new List<uint>() { group.LocalId });
2180 2267
2181// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2268// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2182 } 2269 }
@@ -2466,6 +2553,8 @@ namespace OpenSim.Region.Framework.Scenes
2466 2553
2467 if (newPosition != Vector3.Zero) 2554 if (newPosition != Vector3.Zero)
2468 newObject.RootPart.GroupPosition = newPosition; 2555 newObject.RootPart.GroupPosition = newPosition;
2556 if (newObject.RootPart.KeyframeMotion != null)
2557 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2469 2558
2470 if (!AddSceneObject(newObject)) 2559 if (!AddSceneObject(newObject))
2471 { 2560 {
@@ -2534,10 +2623,17 @@ namespace OpenSim.Region.Framework.Scenes
2534 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2623 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2535 public bool AddSceneObject(SceneObjectGroup sceneObject) 2624 public bool AddSceneObject(SceneObjectGroup sceneObject)
2536 { 2625 {
2626 if (sceneObject.OwnerID == UUID.Zero)
2627 {
2628 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2629 return false;
2630 }
2631
2537 // If the user is banned, we won't let any of their objects 2632 // If the user is banned, we won't let any of their objects
2538 // enter. Period. 2633 // enter. Period.
2539 // 2634 //
2540 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID)) 2635 int flags = GetUserFlags(sceneObject.OwnerID);
2636 if (m_regInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2541 { 2637 {
2542 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID); 2638 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2543 2639
@@ -2583,12 +2679,23 @@ namespace OpenSim.Region.Framework.Scenes
2583 } 2679 }
2584 else 2680 else
2585 { 2681 {
2682 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2586 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2683 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2587 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2684 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2588 } 2685 }
2686 if (sceneObject.OwnerID == UUID.Zero)
2687 {
2688 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2689 return false;
2690 }
2589 } 2691 }
2590 else 2692 else
2591 { 2693 {
2694 if (sceneObject.OwnerID == UUID.Zero)
2695 {
2696 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2697 return false;
2698 }
2592 AddRestoredSceneObject(sceneObject, true, false); 2699 AddRestoredSceneObject(sceneObject, true, false);
2593 2700
2594 if (!Permissions.CanObjectEntry(sceneObject.UUID, 2701 if (!Permissions.CanObjectEntry(sceneObject.UUID,
@@ -2617,6 +2724,24 @@ namespace OpenSim.Region.Framework.Scenes
2617 return 2; // StateSource.PrimCrossing 2724 return 2; // StateSource.PrimCrossing
2618 } 2725 }
2619 2726
2727 public int GetUserFlags(UUID user)
2728 {
2729 //Unfortunately the SP approach means that the value is cached until region is restarted
2730 /*
2731 ScenePresence sp;
2732 if (TryGetScenePresence(user, out sp))
2733 {
2734 return sp.UserFlags;
2735 }
2736 else
2737 {
2738 */
2739 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2740 if (uac == null)
2741 return 0;
2742 return uac.UserFlags;
2743 //}
2744 }
2620 #endregion 2745 #endregion
2621 2746
2622 #region Add/Remove Avatar Methods 2747 #region Add/Remove Avatar Methods
@@ -2630,7 +2755,7 @@ namespace OpenSim.Region.Framework.Scenes
2630 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2755 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2631 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2756 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2632 2757
2633// CheckHeartbeat(); 2758 CheckHeartbeat();
2634 2759
2635 ScenePresence sp = GetScenePresence(client.AgentId); 2760 ScenePresence sp = GetScenePresence(client.AgentId);
2636 2761
@@ -2683,7 +2808,13 @@ namespace OpenSim.Region.Framework.Scenes
2683 2808
2684 EventManager.TriggerOnNewClient(client); 2809 EventManager.TriggerOnNewClient(client);
2685 if (vialogin) 2810 if (vialogin)
2811 {
2686 EventManager.TriggerOnClientLogin(client); 2812 EventManager.TriggerOnClientLogin(client);
2813 // Send initial parcel data
2814 Vector3 pos = sp.AbsolutePosition;
2815 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2816 land.SendLandUpdateToClient(client);
2817 }
2687 2818
2688 return sp; 2819 return sp;
2689 } 2820 }
@@ -2773,19 +2904,12 @@ namespace OpenSim.Region.Framework.Scenes
2773 // and the scene presence and the client, if they exist 2904 // and the scene presence and the client, if they exist
2774 try 2905 try
2775 { 2906 {
2776 // We need to wait for the client to make UDP contact first. 2907 ScenePresence sp = GetScenePresence(agentID);
2777 // It's the UDP contact that creates the scene presence 2908 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2778 ScenePresence sp = WaitGetScenePresence(agentID); 2909
2779 if (sp != null) 2910 if (sp != null)
2780 {
2781 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2782
2783 sp.ControllingClient.Close(); 2911 sp.ControllingClient.Close();
2784 } 2912
2785 else
2786 {
2787 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2788 }
2789 // BANG! SLASH! 2913 // BANG! SLASH!
2790 m_authenticateHandler.RemoveCircuit(agentID); 2914 m_authenticateHandler.RemoveCircuit(agentID);
2791 2915
@@ -2830,6 +2954,8 @@ namespace OpenSim.Region.Framework.Scenes
2830 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 2954 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2831 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 2955 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2832 2956
2957 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
2958
2833 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 2959 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2834 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 2960 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2835 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 2961 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -2886,6 +3012,7 @@ namespace OpenSim.Region.Framework.Scenes
2886 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3012 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2887 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3013 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2888 client.OnCopyInventoryItem += CopyInventoryItem; 3014 client.OnCopyInventoryItem += CopyInventoryItem;
3015 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2889 client.OnMoveInventoryItem += MoveInventoryItem; 3016 client.OnMoveInventoryItem += MoveInventoryItem;
2890 client.OnRemoveInventoryItem += RemoveInventoryItem; 3017 client.OnRemoveInventoryItem += RemoveInventoryItem;
2891 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3018 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -2957,6 +3084,8 @@ namespace OpenSim.Region.Framework.Scenes
2957 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3084 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
2958 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3085 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
2959 3086
3087 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3088
2960 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3089 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
2961 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3090 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
2962 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3091 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3059,15 +3188,16 @@ namespace OpenSim.Region.Framework.Scenes
3059 /// </summary> 3188 /// </summary>
3060 /// <param name="agentId">The avatar's Unique ID</param> 3189 /// <param name="agentId">The avatar's Unique ID</param>
3061 /// <param name="client">The IClientAPI for the client</param> 3190 /// <param name="client">The IClientAPI for the client</param>
3062 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3191 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3063 { 3192 {
3064 if (m_teleportModule != null) 3193 if (m_teleportModule != null)
3065 m_teleportModule.TeleportHome(agentId, client); 3194 return m_teleportModule.TeleportHome(agentId, client);
3066 else 3195 else
3067 { 3196 {
3068 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3197 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3069 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3198 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3070 } 3199 }
3200 return false;
3071 } 3201 }
3072 3202
3073 /// <summary> 3203 /// <summary>
@@ -3177,6 +3307,16 @@ namespace OpenSim.Region.Framework.Scenes
3177 /// <param name="flags"></param> 3307 /// <param name="flags"></param>
3178 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3308 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3179 { 3309 {
3310 //Add half the avatar's height so that the user doesn't fall through prims
3311 ScenePresence presence;
3312 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3313 {
3314 if (presence.Appearance != null)
3315 {
3316 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3317 }
3318 }
3319
3180 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3320 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3181 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3321 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3182 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3322 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3245,8 +3385,9 @@ namespace OpenSim.Region.Framework.Scenes
3245 regions.Remove(RegionInfo.RegionHandle); 3385 regions.Remove(RegionInfo.RegionHandle);
3246 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions); 3386 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3247 } 3387 }
3248 3388 m_log.Debug("[Scene] Beginning ClientClosed");
3249 m_eventManager.TriggerClientClosed(agentID, this); 3389 m_eventManager.TriggerClientClosed(agentID, this);
3390 m_log.Debug("[Scene] Finished ClientClosed");
3250 } 3391 }
3251 catch (NullReferenceException) 3392 catch (NullReferenceException)
3252 { 3393 {
@@ -3308,9 +3449,10 @@ namespace OpenSim.Region.Framework.Scenes
3308 { 3449 {
3309 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace); 3450 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace);
3310 } 3451 }
3311 3452 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3312 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3453 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3313// CleanDroppedAttachments(); 3454// CleanDroppedAttachments();
3455 m_log.Debug("[Scene] The avatar has left the building");
3314 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3456 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3315 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true)); 3457 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3316 } 3458 }
@@ -3432,13 +3574,16 @@ namespace OpenSim.Region.Framework.Scenes
3432 sp = null; 3574 sp = null;
3433 } 3575 }
3434 3576
3435 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3436 3577
3437 //On login test land permisions 3578 //On login test land permisions
3438 if (vialogin) 3579 if (vialogin)
3439 { 3580 {
3440 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3581 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3582 if (cache != null)
3583 cache.Remove(agent.firstname + " " + agent.lastname);
3584 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3441 { 3585 {
3586 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3442 return false; 3587 return false;
3443 } 3588 }
3444 } 3589 }
@@ -3462,8 +3607,13 @@ namespace OpenSim.Region.Framework.Scenes
3462 3607
3463 try 3608 try
3464 { 3609 {
3465 if (!AuthorizeUser(agent, out reason)) 3610 // Always check estate if this is a login. Always
3466 return false; 3611 // check if banned regions are to be blacked out.
3612 if (vialogin || (!m_seeIntoBannedRegion))
3613 {
3614 if (!AuthorizeUser(agent, out reason))
3615 return false;
3616 }
3467 } 3617 }
3468 catch (Exception e) 3618 catch (Exception e)
3469 { 3619 {
@@ -3589,6 +3739,8 @@ namespace OpenSim.Region.Framework.Scenes
3589 } 3739 }
3590 3740
3591 // Honor parcel landing type and position. 3741 // Honor parcel landing type and position.
3742 /*
3743 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3592 if (land != null) 3744 if (land != null)
3593 { 3745 {
3594 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3746 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3596,26 +3748,34 @@ namespace OpenSim.Region.Framework.Scenes
3596 agent.startpos = land.LandData.UserLocation; 3748 agent.startpos = land.LandData.UserLocation;
3597 } 3749 }
3598 } 3750 }
3751 */// This is now handled properly in ScenePresence.MakeRootAgent
3599 } 3752 }
3600 3753
3601 return true; 3754 return true;
3602 } 3755 }
3603 3756
3604 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3757 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3605 { 3758 {
3606 3759 reason = String.Empty;
3607 bool banned = land.IsBannedFromLand(agent.AgentID); 3760 if (Permissions.IsGod(agentID))
3608 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3761 return true;
3762
3763 ILandObject land = LandChannel.GetLandObject(posX, posY);
3764 if (land == null)
3765 return false;
3766
3767 bool banned = land.IsBannedFromLand(agentID);
3768 bool restricted = land.IsRestrictedFromLand(agentID);
3609 3769
3610 if (banned || restricted) 3770 if (banned || restricted)
3611 { 3771 {
3612 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3772 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3613 if (nearestParcel != null) 3773 if (nearestParcel != null)
3614 { 3774 {
3615 //Move agent to nearest allowed 3775 //Move agent to nearest allowed
3616 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3776 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3617 agent.startpos.X = newPosition.X; 3777 posX = newPosition.X;
3618 agent.startpos.Y = newPosition.Y; 3778 posY = newPosition.Y;
3619 } 3779 }
3620 else 3780 else
3621 { 3781 {
@@ -3677,7 +3837,7 @@ namespace OpenSim.Region.Framework.Scenes
3677 3837
3678 if (!m_strictAccessControl) return true; 3838 if (!m_strictAccessControl) return true;
3679 if (Permissions.IsGod(agent.AgentID)) return true; 3839 if (Permissions.IsGod(agent.AgentID)) return true;
3680 3840
3681 if (AuthorizationService != null) 3841 if (AuthorizationService != null)
3682 { 3842 {
3683 if (!AuthorizationService.IsAuthorizedForRegion( 3843 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3692,7 +3852,7 @@ namespace OpenSim.Region.Framework.Scenes
3692 3852
3693 if (m_regInfo.EstateSettings != null) 3853 if (m_regInfo.EstateSettings != null)
3694 { 3854 {
3695 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID)) 3855 if (m_regInfo.EstateSettings.IsBanned(agent.AgentID,0))
3696 { 3856 {
3697 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 3857 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3698 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 3858 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -3884,6 +4044,13 @@ namespace OpenSim.Region.Framework.Scenes
3884 4044
3885 // We have to wait until the viewer contacts this region after receiving EAC. 4045 // We have to wait until the viewer contacts this region after receiving EAC.
3886 // That calls AddNewClient, which finally creates the ScenePresence 4046 // That calls AddNewClient, which finally creates the ScenePresence
4047 int flags = GetUserFlags(cAgentData.AgentID);
4048 if (m_regInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4049 {
4050 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4051 return false;
4052 }
4053
3887 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4054 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
3888 if (nearestParcel == null) 4055 if (nearestParcel == null)
3889 { 4056 {
@@ -3965,12 +4132,22 @@ namespace OpenSim.Region.Framework.Scenes
3965 return false; 4132 return false;
3966 } 4133 }
3967 4134
4135 public bool IncomingCloseAgent(UUID agentID)
4136 {
4137 return IncomingCloseAgent(agentID, false);
4138 }
4139
4140 public bool IncomingCloseChildAgent(UUID agentID)
4141 {
4142 return IncomingCloseAgent(agentID, true);
4143 }
4144
3968 /// <summary> 4145 /// <summary>
3969 /// Tell a single agent to disconnect from the region. 4146 /// Tell a single agent to disconnect from the region.
3970 /// </summary> 4147 /// </summary>
3971 /// <param name="regionHandle"></param>
3972 /// <param name="agentID"></param> 4148 /// <param name="agentID"></param>
3973 public bool IncomingCloseAgent(UUID agentID) 4149 /// <param name="childOnly"></param>
4150 public bool IncomingCloseAgent(UUID agentID, bool childOnly)
3974 { 4151 {
3975 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); 4152 //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID);
3976 4153
@@ -3982,7 +4159,7 @@ namespace OpenSim.Region.Framework.Scenes
3982 { 4159 {
3983 m_sceneGraph.removeUserCount(false); 4160 m_sceneGraph.removeUserCount(false);
3984 } 4161 }
3985 else 4162 else if (!childOnly)
3986 { 4163 {
3987 m_sceneGraph.removeUserCount(true); 4164 m_sceneGraph.removeUserCount(true);
3988 } 4165 }
@@ -3998,9 +4175,12 @@ namespace OpenSim.Region.Framework.Scenes
3998 } 4175 }
3999 else 4176 else
4000 presence.ControllingClient.SendShutdownConnectionNotice(); 4177 presence.ControllingClient.SendShutdownConnectionNotice();
4178 presence.ControllingClient.Close(false);
4179 }
4180 else if (!childOnly)
4181 {
4182 presence.ControllingClient.Close(true);
4001 } 4183 }
4002
4003 presence.ControllingClient.Close();
4004 return true; 4184 return true;
4005 } 4185 }
4006 4186
@@ -4582,35 +4762,81 @@ namespace OpenSim.Region.Framework.Scenes
4582 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID); 4762 SimulationDataService.RemoveObject(uuid, m_regInfo.RegionID);
4583 } 4763 }
4584 4764
4585 public int GetHealth() 4765 public int GetHealth(out int flags, out string message)
4586 { 4766 {
4587 // Returns: 4767 // Returns:
4588 // 1 = sim is up and accepting http requests. The heartbeat has 4768 // 1 = sim is up and accepting http requests. The heartbeat has
4589 // stopped and the sim is probably locked up, but a remote 4769 // stopped and the sim is probably locked up, but a remote
4590 // admin restart may succeed 4770 // admin restart may succeed
4591 // 4771 //
4592 // 2 = Sim is up and the heartbeat is running. The sim is likely 4772 // 2 = Sim is up and the heartbeat is running. The sim is likely
4593 // usable for people within and logins _may_ work 4773 // usable for people within
4774 //
4775 // 3 = Sim is up and one packet thread is running. Sim is
4776 // unstable and will not accept new logins
4594 // 4777 //
4595 // 3 = We have seen a new user enter within the past 4 minutes 4778 // 4 = Sim is up and both packet threads are running. Sim is
4779 // likely usable
4780 //
4781 // 5 = We have seen a new user enter within the past 4 minutes
4596 // which can be seen as positive confirmation of sim health 4782 // which can be seen as positive confirmation of sim health
4597 // 4783 //
4784
4785 flags = 0;
4786 message = String.Empty;
4787
4788 CheckHeartbeat();
4789
4790 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
4791 {
4792 // We're still starting
4793 // 0 means "in startup", it can't happen another way, since
4794 // to get here, we must be able to accept http connections
4795 return 0;
4796 }
4797
4598 int health=1; // Start at 1, means we're up 4798 int health=1; // Start at 1, means we're up
4599 4799
4600 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 4800 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4601 health += 1; 4801 {
4802 health+=1;
4803 flags |= 1;
4804 }
4805
4806 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
4807 {
4808 health+=1;
4809 flags |= 2;
4810 }
4811
4812 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
4813 {
4814 health+=1;
4815 flags |= 4;
4816 }
4602 else 4817 else
4818 {
4819int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
4820System.Diagnostics.Process proc = new System.Diagnostics.Process();
4821proc.EnableRaisingEvents=false;
4822proc.StartInfo.FileName = "/bin/kill";
4823proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
4824proc.Start();
4825proc.WaitForExit();
4826Thread.Sleep(1000);
4827Environment.Exit(1);
4828 }
4829
4830 if (flags != 7)
4603 return health; 4831 return health;
4604 4832
4605 // A login in the last 4 mins? We can't be doing too badly 4833 // A login in the last 4 mins? We can't be doing too badly
4606 // 4834 //
4607 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 4835 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4608 health++; 4836 health++;
4609 else 4837 else
4610 return health; 4838 return health;
4611 4839
4612// CheckHeartbeat();
4613
4614 return health; 4840 return health;
4615 } 4841 }
4616 4842
@@ -4698,7 +4924,7 @@ namespace OpenSim.Region.Framework.Scenes
4698 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 4924 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
4699 if (wasUsingPhysics) 4925 if (wasUsingPhysics)
4700 { 4926 {
4701 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 4927 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
4702 } 4928 }
4703 } 4929 }
4704 4930
@@ -4797,14 +5023,14 @@ namespace OpenSim.Region.Framework.Scenes
4797 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5023 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
4798 } 5024 }
4799 5025
4800// private void CheckHeartbeat() 5026 private void CheckHeartbeat()
4801// { 5027 {
4802// if (m_firstHeartbeat) 5028 if (m_firstHeartbeat)
4803// return; 5029 return;
4804// 5030
4805// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5031 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
4806// StartTimer(); 5032 Start();
4807// } 5033 }
4808 5034
4809 public override ISceneObject DeserializeObject(string representation) 5035 public override ISceneObject DeserializeObject(string representation)
4810 { 5036 {
@@ -4816,9 +5042,14 @@ namespace OpenSim.Region.Framework.Scenes
4816 get { return m_allowScriptCrossings; } 5042 get { return m_allowScriptCrossings; }
4817 } 5043 }
4818 5044
4819 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5045 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5046 {
5047 return GetNearestAllowedPosition(avatar, null);
5048 }
5049
5050 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
4820 { 5051 {
4821 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5052 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
4822 5053
4823 if (nearestParcel != null) 5054 if (nearestParcel != null)
4824 { 5055 {
@@ -4827,10 +5058,7 @@ namespace OpenSim.Region.Framework.Scenes
4827 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5058 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4828 if (nearestPoint != null) 5059 if (nearestPoint != null)
4829 { 5060 {
4830// m_log.DebugFormat( 5061 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4831// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
4832// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
4833
4834 return nearestPoint.Value; 5062 return nearestPoint.Value;
4835 } 5063 }
4836 5064
@@ -4840,17 +5068,20 @@ namespace OpenSim.Region.Framework.Scenes
4840 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5068 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4841 if (nearestPoint != null) 5069 if (nearestPoint != null)
4842 { 5070 {
4843// m_log.DebugFormat( 5071 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4844// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
4845
4846 return nearestPoint.Value; 5072 return nearestPoint.Value;
4847 } 5073 }
4848 5074
4849 //Ultimate backup if we have no idea where they are 5075 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
4850// m_log.DebugFormat( 5076 if (dest != excludeParcel)
4851// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5077 {
5078 // Ultimate backup if we have no idea where they are and
5079 // the last allowed position was in another parcel
5080 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5081 return avatar.lastKnownAllowedPosition;
5082 }
4852 5083
4853 return avatar.lastKnownAllowedPosition; 5084 // else fall through to region edge
4854 } 5085 }
4855 5086
4856 //Go to the edge, this happens in teleporting to a region with no available parcels 5087 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -4884,13 +5115,18 @@ namespace OpenSim.Region.Framework.Scenes
4884 5115
4885 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5116 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
4886 { 5117 {
5118 return GetNearestAllowedParcel(avatarId, x, y, null);
5119 }
5120
5121 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5122 {
4887 List<ILandObject> all = AllParcels(); 5123 List<ILandObject> all = AllParcels();
4888 float minParcelDistance = float.MaxValue; 5124 float minParcelDistance = float.MaxValue;
4889 ILandObject nearestParcel = null; 5125 ILandObject nearestParcel = null;
4890 5126
4891 foreach (var parcel in all) 5127 foreach (var parcel in all)
4892 { 5128 {
4893 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5129 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
4894 { 5130 {
4895 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5131 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
4896 if (parcelDistance < minParcelDistance) 5132 if (parcelDistance < minParcelDistance)
@@ -5132,7 +5368,55 @@ namespace OpenSim.Region.Framework.Scenes
5132 mapModule.GenerateMaptile(); 5368 mapModule.GenerateMaptile();
5133 } 5369 }
5134 5370
5135 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5371// public void CleanDroppedAttachments()
5372// {
5373// List<SceneObjectGroup> objectsToDelete =
5374// new List<SceneObjectGroup>();
5375//
5376// lock (m_cleaningAttachments)
5377// {
5378// ForEachSOG(delegate (SceneObjectGroup grp)
5379// {
5380// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5381// {
5382// UUID agentID = grp.OwnerID;
5383// if (agentID == UUID.Zero)
5384// {
5385// objectsToDelete.Add(grp);
5386// return;
5387// }
5388//
5389// ScenePresence sp = GetScenePresence(agentID);
5390// if (sp == null)
5391// {
5392// objectsToDelete.Add(grp);
5393// return;
5394// }
5395// }
5396// });
5397// }
5398//
5399// foreach (SceneObjectGroup grp in objectsToDelete)
5400// {
5401// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5402// DeleteSceneObject(grp, true);
5403// }
5404// }
5405
5406 public void ThreadAlive(int threadCode)
5407 {
5408 switch(threadCode)
5409 {
5410 case 1: // Incoming
5411 m_lastIncoming = Util.EnvironmentTickCount();
5412 break;
5413 case 2: // Incoming
5414 m_lastOutgoing = Util.EnvironmentTickCount();
5415 break;
5416 }
5417 }
5418
5419 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5136 { 5420 {
5137 RegenerateMaptile(); 5421 RegenerateMaptile();
5138 5422
@@ -5151,6 +5435,14 @@ namespace OpenSim.Region.Framework.Scenes
5151 // child agent creation, thereby emulating the SL behavior. 5435 // child agent creation, thereby emulating the SL behavior.
5152 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5436 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5153 { 5437 {
5438 reason = "You are banned from the region";
5439
5440 if (Permissions.IsGod(agentID))
5441 {
5442 reason = String.Empty;
5443 return true;
5444 }
5445
5154 int num = m_sceneGraph.GetNumberOfScenePresences(); 5446 int num = m_sceneGraph.GetNumberOfScenePresences();
5155 5447
5156 if (num >= RegionInfo.RegionSettings.AgentLimit) 5448 if (num >= RegionInfo.RegionSettings.AgentLimit)
@@ -5162,6 +5454,41 @@ namespace OpenSim.Region.Framework.Scenes
5162 } 5454 }
5163 } 5455 }
5164 5456
5457 ScenePresence presence = GetScenePresence(agentID);
5458 IClientAPI client = null;
5459 AgentCircuitData aCircuit = null;
5460
5461 if (presence != null)
5462 {
5463 client = presence.ControllingClient;
5464 if (client != null)
5465 aCircuit = client.RequestClientInfo();
5466 }
5467
5468 // We may be called before there is a presence or a client.
5469 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5470 if (client == null)
5471 {
5472 aCircuit = new AgentCircuitData();
5473 aCircuit.AgentID = agentID;
5474 aCircuit.firstname = String.Empty;
5475 aCircuit.lastname = String.Empty;
5476 }
5477
5478 try
5479 {
5480 if (!AuthorizeUser(aCircuit, out reason))
5481 {
5482 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5483 return false;
5484 }
5485 }
5486 catch (Exception e)
5487 {
5488 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5489 return false;
5490 }
5491
5165 if (position == Vector3.Zero) // Teleport 5492 if (position == Vector3.Zero) // Teleport
5166 { 5493 {
5167 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5494 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5190,13 +5517,46 @@ namespace OpenSim.Region.Framework.Scenes
5190 } 5517 }
5191 } 5518 }
5192 } 5519 }
5520
5521 float posX = 128.0f;
5522 float posY = 128.0f;
5523
5524 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5525 {
5526 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5527 return false;
5528 }
5529 }
5530 else // Walking
5531 {
5532 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5533 if (land == null)
5534 return false;
5535
5536 bool banned = land.IsBannedFromLand(agentID);
5537 bool restricted = land.IsRestrictedFromLand(agentID);
5538
5539 if (banned || restricted)
5540 return false;
5193 } 5541 }
5194 5542
5195 reason = String.Empty; 5543 reason = String.Empty;
5196 return true; 5544 return true;
5197 } 5545 }
5198 5546
5199 /// <summary> 5547 public void StartTimerWatchdog()
5548 {
5549 m_timerWatchdog.Interval = 1000;
5550 m_timerWatchdog.Elapsed += TimerWatchdog;
5551 m_timerWatchdog.AutoReset = true;
5552 m_timerWatchdog.Start();
5553 }
5554
5555 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5556 {
5557 CheckHeartbeat();
5558 }
5559
5200 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5560 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5201 /// autopilot that moves an avatar to a sit target!. 5561 /// autopilot that moves an avatar to a sit target!.
5202 /// </summary> 5562 /// </summary>