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.cs868
1 files changed, 636 insertions, 232 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 11b63b7..a5ef2b7 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -156,8 +156,8 @@ namespace OpenSim.Region.Framework.Scenes
156 // TODO: need to figure out how allow client agents but deny 156 // TODO: need to figure out how allow client agents but deny
157 // root agents when ACL denies access to root agent 157 // root agents when ACL denies access to root agent
158 public bool m_strictAccessControl = true; 158 public bool m_strictAccessControl = true;
159 159 public bool m_seeIntoBannedRegion = false;
160 public int MaxUndoCount { get; set; } 160 public int MaxUndoCount = 5;
161 161
162 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 162 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
163 public bool LoginLock = false; 163 public bool LoginLock = false;
@@ -173,11 +173,13 @@ namespace OpenSim.Region.Framework.Scenes
173 173
174 protected int m_splitRegionID; 174 protected int m_splitRegionID;
175 protected Timer m_restartWaitTimer = new Timer(); 175 protected Timer m_restartWaitTimer = new Timer();
176 protected Timer m_timerWatchdog = new Timer();
176 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 177 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
177 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 178 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
178 protected string m_simulatorVersion = "OpenSimulator Server"; 179 protected string m_simulatorVersion = "OpenSimulator Server";
179 protected AgentCircuitManager m_authenticateHandler; 180 protected AgentCircuitManager m_authenticateHandler;
180 protected SceneCommunicationService m_sceneGridService; 181 protected SceneCommunicationService m_sceneGridService;
182 protected ISnmpModule m_snmpService = null;
181 183
182 protected ISimulationDataService m_SimulationDataService; 184 protected ISimulationDataService m_SimulationDataService;
183 protected IEstateDataService m_EstateDataService; 185 protected IEstateDataService m_EstateDataService;
@@ -240,8 +242,8 @@ namespace OpenSim.Region.Framework.Scenes
240 private int m_update_presences = 1; // Update scene presence movements 242 private int m_update_presences = 1; // Update scene presence movements
241 private int m_update_events = 1; 243 private int m_update_events = 1;
242 private int m_update_backup = 200; 244 private int m_update_backup = 200;
243 private int m_update_terrain = 50; 245 private int m_update_terrain = 1000;
244// private int m_update_land = 1; 246 private int m_update_land = 10;
245 private int m_update_coarse_locations = 50; 247 private int m_update_coarse_locations = 50;
246 248
247 private int agentMS; 249 private int agentMS;
@@ -254,13 +256,13 @@ namespace OpenSim.Region.Framework.Scenes
254 private int backupMS; 256 private int backupMS;
255 private int terrainMS; 257 private int terrainMS;
256 private int landMS; 258 private int landMS;
257 private int spareMS;
258 259
259 /// <summary> 260 /// <summary>
260 /// Tick at which the last frame was processed. 261 /// Tick at which the last frame was processed.
261 /// </summary> 262 /// </summary>
262 private int m_lastFrameTick; 263 private int m_lastFrameTick;
263 264
265 public bool CombineRegions = false;
264 /// <summary> 266 /// <summary>
265 /// Tick at which the last maintenance run occurred. 267 /// Tick at which the last maintenance run occurred.
266 /// </summary> 268 /// </summary>
@@ -291,6 +293,11 @@ namespace OpenSim.Region.Framework.Scenes
291 /// </summary> 293 /// </summary>
292 private int m_LastLogin; 294 private int m_LastLogin;
293 295
296 private int m_lastIncoming;
297 private int m_lastOutgoing;
298 private int m_hbRestarts = 0;
299
300
294 /// <summary> 301 /// <summary>
295 /// Thread that runs the scene loop. 302 /// Thread that runs the scene loop.
296 /// </summary> 303 /// </summary>
@@ -331,7 +338,7 @@ namespace OpenSim.Region.Framework.Scenes
331 private volatile bool m_active; 338 private volatile bool m_active;
332 339
333// private int m_lastUpdate; 340// private int m_lastUpdate;
334// private bool m_firstHeartbeat = true; 341 private bool m_firstHeartbeat = true;
335 342
336 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time; 343 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
337 private bool m_reprioritizationEnabled = true; 344 private bool m_reprioritizationEnabled = true;
@@ -376,6 +383,19 @@ namespace OpenSim.Region.Framework.Scenes
376 get { return m_sceneGridService; } 383 get { return m_sceneGridService; }
377 } 384 }
378 385
386 public ISnmpModule SnmpService
387 {
388 get
389 {
390 if (m_snmpService == null)
391 {
392 m_snmpService = RequestModuleInterface<ISnmpModule>();
393 }
394
395 return m_snmpService;
396 }
397 }
398
379 public ISimulationDataService SimulationDataService 399 public ISimulationDataService SimulationDataService
380 { 400 {
381 get 401 get
@@ -674,6 +694,8 @@ namespace OpenSim.Region.Framework.Scenes
674 m_SimulationDataService = simDataService; 694 m_SimulationDataService = simDataService;
675 m_EstateDataService = estateDataService; 695 m_EstateDataService = estateDataService;
676 m_regionHandle = RegionInfo.RegionHandle; 696 m_regionHandle = RegionInfo.RegionHandle;
697 m_lastIncoming = 0;
698 m_lastOutgoing = 0;
677 699
678 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 700 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
679 m_asyncSceneObjectDeleter.Enabled = true; 701 m_asyncSceneObjectDeleter.Enabled = true;
@@ -761,132 +783,141 @@ namespace OpenSim.Region.Framework.Scenes
761 783
762 // Region config overrides global config 784 // Region config overrides global config
763 // 785 //
764 if (m_config.Configs["Startup"] != null) 786 try
765 { 787 {
766 IConfig startupConfig = m_config.Configs["Startup"]; 788 if (m_config.Configs["Startup"] != null)
767
768 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
769
770 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance);
771 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
772 if (!m_useBackup)
773 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
774
775 //Animation states
776 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
777
778 MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20);
779
780 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims);
781 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims);
782
783 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
784 if (RegionInfo.NonphysPrimMin > 0)
785 { 789 {
786 m_minNonphys = RegionInfo.NonphysPrimMin; 790 IConfig startupConfig = m_config.Configs["Startup"];
787 }
788 791
789 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 792 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
790 if (RegionInfo.NonphysPrimMax > 0)
791 {
792 m_maxNonphys = RegionInfo.NonphysPrimMax;
793 }
794 793
795 m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys); 794 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
796 if (RegionInfo.PhysPrimMin > 0) 795 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
797 { 796 if (!m_useBackup)
798 m_minPhys = RegionInfo.PhysPrimMin; 797 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
799 } 798
799 //Animation states
800 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
800 801
801 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 802 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
802 if (RegionInfo.PhysPrimMax > 0) 803 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
803 {
804 m_maxPhys = RegionInfo.PhysPrimMax;
805 }
806 804
807 // Here, if clamping is requested in either global or 805 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
808 // local config, it will be used 806 if (RegionInfo.NonphysPrimMin > 0)
809 // 807 {
810 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize); 808 m_minNonphys = RegionInfo.NonphysPrimMin;
811 if (RegionInfo.ClampPrimSize) 809 }
812 {
813 m_clampPrimSize = true;
814 }
815 810
816 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); 811 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
817 if (RegionInfo.LinksetCapacity > 0) 812 if (RegionInfo.NonphysPrimMax > 0)
818 { 813 {
819 m_linksetCapacity = RegionInfo.LinksetCapacity; 814 m_maxNonphys = RegionInfo.NonphysPrimMax;
820 } 815 }
821 816
822 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete); 817 m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys);
823 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 818 if (RegionInfo.PhysPrimMin > 0)
824 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 819 {
825 m_dontPersistBefore = 820 m_minPhys = RegionInfo.PhysPrimMin;
826 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE); 821 }
827 m_dontPersistBefore *= 10000000;
828 m_persistAfter =
829 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
830 m_persistAfter *= 10000000;
831 822
832 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 823 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
833 824
834 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest"); 825 if (RegionInfo.PhysPrimMax > 0)
835 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false); 826 {
827 m_maxPhys = RegionInfo.PhysPrimMax;
828 }
836 829
837 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 830 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity);
831 if (RegionInfo.LinksetCapacity > 0)
832 {
833 m_linksetCapacity = RegionInfo.LinksetCapacity;
834 }
838 835
839 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 836 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
840 if (m_generateMaptiles) 837 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
841 { 838
842 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0); 839 // Here, if clamping is requested in either global or
843 if (maptileRefresh != 0) 840 // local config, it will be used
841 //
842 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
843 if (RegionInfo.ClampPrimSize)
844 { 844 {
845 m_mapGenerationTimer.Interval = maptileRefresh * 1000; 845 m_clampPrimSize = true;
846 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
847 m_mapGenerationTimer.AutoReset = true;
848 m_mapGenerationTimer.Start();
849 } 846 }
850 }
851 else
852 {
853 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
854 UUID tileID;
855 847
856 if (UUID.TryParse(tile, out tileID)) 848 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
849 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
850 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
851 m_dontPersistBefore =
852 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE);
853 m_dontPersistBefore *= 10000000;
854 m_persistAfter =
855 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
856 m_persistAfter *= 10000000;
857
858 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
859 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
860
861 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
862 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
863 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
864
865 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
866 if (m_generateMaptiles)
857 { 867 {
858 RegionInfo.RegionSettings.TerrainImageID = tileID; 868 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0);
869 if (maptileRefresh != 0)
870 {
871 m_mapGenerationTimer.Interval = maptileRefresh * 1000;
872 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
873 m_mapGenerationTimer.AutoReset = true;
874 m_mapGenerationTimer.Start();
875 }
859 } 876 }
860 } 877 else
878 {
879 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
880 UUID tileID;
861 881
862 string grant = startupConfig.GetString("AllowedClients", String.Empty); 882 if (UUID.TryParse(tile, out tileID))
863 if (grant.Length > 0) 883 {
864 { 884 RegionInfo.RegionSettings.TerrainImageID = tileID;
865 foreach (string viewer in grant.Split('|')) 885 }
886 }
887
888 string grant = startupConfig.GetString("AllowedClients", String.Empty);
889 if (grant.Length > 0)
866 { 890 {
867 m_AllowedViewers.Add(viewer.Trim().ToLower()); 891 foreach (string viewer in grant.Split(','))
892 {
893 m_AllowedViewers.Add(viewer.Trim().ToLower());
894 }
868 } 895 }
869 }
870 896
871 grant = startupConfig.GetString("BannedClients", String.Empty); 897 grant = startupConfig.GetString("BannedClients", String.Empty);
872 if (grant.Length > 0) 898 if (grant.Length > 0)
873 {
874 foreach (string viewer in grant.Split('|'))
875 { 899 {
876 m_BannedViewers.Add(viewer.Trim().ToLower()); 900 foreach (string viewer in grant.Split(','))
901 {
902 m_BannedViewers.Add(viewer.Trim().ToLower());
903 }
877 } 904 }
878 }
879 905
880 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime); 906 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime);
881 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup); 907 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup);
882 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations); 908 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations);
883 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement); 909 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement);
884 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events); 910 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events);
885 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects); 911 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
886 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics); 912 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
887 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences); 913 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
888 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain); 914 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
889 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning); 915 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
916 }
917 }
918 catch (Exception e)
919 {
920 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
890 } 921 }
891 922
892 // FIXME: Ultimately this should be in a module. 923 // FIXME: Ultimately this should be in a module.
@@ -931,6 +962,8 @@ namespace OpenSim.Region.Framework.Scenes
931 StatsReporter = new SimStatsReporter(this); 962 StatsReporter = new SimStatsReporter(this);
932 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 963 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
933 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 964 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
965
966 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
934 } 967 }
935 968
936 public Scene(RegionInfo regInfo) : base(regInfo) 969 public Scene(RegionInfo regInfo) : base(regInfo)
@@ -1299,9 +1332,11 @@ namespace OpenSim.Region.Framework.Scenes
1299 // Stop all client threads. 1332 // Stop all client threads.
1300 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); }); 1333 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); });
1301 1334
1302 m_log.Debug("[SCENE]: Persisting changed objects"); 1335 m_log.Debug("[SCENE]: TriggerSceneShuttingDown");
1303 EventManager.TriggerSceneShuttingDown(this); 1336 EventManager.TriggerSceneShuttingDown(this);
1304 1337
1338 m_log.Debug("[SCENE]: Persisting changed objects");
1339
1305 EntityBase[] entities = GetEntities(); 1340 EntityBase[] entities = GetEntities();
1306 foreach (EntityBase entity in entities) 1341 foreach (EntityBase entity in entities)
1307 { 1342 {
@@ -1311,6 +1346,7 @@ namespace OpenSim.Region.Framework.Scenes
1311 } 1346 }
1312 } 1347 }
1313 1348
1349 m_log.Debug("[SCENE]: Graph close");
1314 m_sceneGraph.Close(); 1350 m_sceneGraph.Close();
1315 1351
1316 if (!GridService.DeregisterRegion(RegionInfo.RegionID)) 1352 if (!GridService.DeregisterRegion(RegionInfo.RegionID))
@@ -1323,6 +1359,7 @@ namespace OpenSim.Region.Framework.Scenes
1323 // attempt to reference a null or disposed physics scene. 1359 // attempt to reference a null or disposed physics scene.
1324 if (PhysicsScene != null) 1360 if (PhysicsScene != null)
1325 { 1361 {
1362 m_log.Debug("[SCENE]: Dispose Physics");
1326 PhysicsScene phys = PhysicsScene; 1363 PhysicsScene phys = PhysicsScene;
1327 // remove the physics engine from both Scene and SceneGraph 1364 // remove the physics engine from both Scene and SceneGraph
1328 PhysicsScene = null; 1365 PhysicsScene = null;
@@ -1345,11 +1382,29 @@ namespace OpenSim.Region.Framework.Scenes
1345 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1382 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1346 if (m_heartbeatThread != null) 1383 if (m_heartbeatThread != null)
1347 { 1384 {
1385 m_hbRestarts++;
1386 if(m_hbRestarts > 10)
1387 Environment.Exit(1);
1388 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1389
1390//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1391//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1392//proc.EnableRaisingEvents=false;
1393//proc.StartInfo.FileName = "/bin/kill";
1394//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1395//proc.Start();
1396//proc.WaitForExit();
1397//Thread.Sleep(1000);
1398//Environment.Exit(1);
1348 m_heartbeatThread.Abort(); 1399 m_heartbeatThread.Abort();
1400 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1349 m_heartbeatThread = null; 1401 m_heartbeatThread = null;
1350 } 1402 }
1351// m_lastUpdate = Util.EnvironmentTickCount(); 1403// m_lastUpdate = Util.EnvironmentTickCount();
1352 1404
1405// m_sceneGraph.PreparePhysicsSimulation();
1406
1407
1353 m_heartbeatThread 1408 m_heartbeatThread
1354 = Watchdog.StartThread( 1409 = Watchdog.StartThread(
1355 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false); 1410 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false);
@@ -1492,16 +1547,20 @@ namespace OpenSim.Region.Framework.Scenes
1492 endFrame = Frame + frames; 1547 endFrame = Frame + frames;
1493 1548
1494 float physicsFPS = 0f; 1549 float physicsFPS = 0f;
1495 int previousFrameTick, tmpMS; 1550 int tmpMS;
1496 int maintc = Util.EnvironmentTickCount(); 1551 int previousFrameTick;
1552 int maintc;
1553 int sleepMS;
1554 int framestart;
1497 1555
1498 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) 1556 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
1499 { 1557 {
1558 framestart = Util.EnvironmentTickCount();
1500 ++Frame; 1559 ++Frame;
1501 1560
1502// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1561// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1503 1562
1504 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1563 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1505 1564
1506 try 1565 try
1507 { 1566 {
@@ -1553,6 +1612,7 @@ namespace OpenSim.Region.Framework.Scenes
1553 m_sceneGraph.UpdatePresences(); 1612 m_sceneGraph.UpdatePresences();
1554 1613
1555 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1614 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1615
1556 1616
1557 // Delete temp-on-rez stuff 1617 // Delete temp-on-rez stuff
1558 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1618 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
@@ -1634,34 +1694,37 @@ namespace OpenSim.Region.Framework.Scenes
1634 1694
1635 Watchdog.UpdateThread(); 1695 Watchdog.UpdateThread();
1636 1696
1697 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1698
1699 StatsReporter.AddPhysicsFPS(physicsFPS);
1700 StatsReporter.AddTimeDilation(TimeDilation);
1701 StatsReporter.AddFPS(1);
1702
1703 StatsReporter.addAgentMS(agentMS);
1704 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1705 StatsReporter.addOtherMS(otherMS);
1706 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1707
1637 previousFrameTick = m_lastFrameTick; 1708 previousFrameTick = m_lastFrameTick;
1638 m_lastFrameTick = Util.EnvironmentTickCount(); 1709 m_lastFrameTick = Util.EnvironmentTickCount();
1639 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1710 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
1640 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1711 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1641 1712
1713 m_firstHeartbeat = false;
1714
1715 sleepMS = Util.EnvironmentTickCount();
1716
1642 if (tmpMS > 0) 1717 if (tmpMS > 0)
1643 {
1644 Thread.Sleep(tmpMS); 1718 Thread.Sleep(tmpMS);
1645 spareMS += tmpMS;
1646 }
1647 1719
1648 frameMS = Util.EnvironmentTickCountSubtract(maintc); 1720 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1649 maintc = Util.EnvironmentTickCount(); 1721 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1650 1722 StatsReporter.addSleepMS(sleepMS);
1651 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; 1723 StatsReporter.addFrameMS(frameMS);
1652 1724
1653 // if (Frame%m_update_avatars == 0) 1725 // if (Frame%m_update_avatars == 0)
1654 // UpdateInWorldTime(); 1726 // UpdateInWorldTime();
1655 StatsReporter.AddPhysicsFPS(physicsFPS);
1656 StatsReporter.AddTimeDilation(TimeDilation);
1657 StatsReporter.AddFPS(1);
1658 1727
1659 StatsReporter.addFrameMS(frameMS);
1660 StatsReporter.addAgentMS(agentMS);
1661 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1662 StatsReporter.addOtherMS(otherMS);
1663 StatsReporter.AddSpareMS(spareMS);
1664 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1665 1728
1666 // Optionally warn if a frame takes double the amount of time that it should. 1729 // Optionally warn if a frame takes double the amount of time that it should.
1667 if (DebugUpdates 1730 if (DebugUpdates
@@ -1779,7 +1842,7 @@ namespace OpenSim.Region.Framework.Scenes
1779 msg.fromAgentName = "Server"; 1842 msg.fromAgentName = "Server";
1780 msg.dialog = (byte)19; // Object msg 1843 msg.dialog = (byte)19; // Object msg
1781 msg.fromGroup = false; 1844 msg.fromGroup = false;
1782 msg.offline = (byte)0; 1845 msg.offline = (byte)1;
1783 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1846 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1784 msg.Position = Vector3.Zero; 1847 msg.Position = Vector3.Zero;
1785 msg.RegionID = RegionInfo.RegionID.Guid; 1848 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -2001,6 +2064,19 @@ namespace OpenSim.Region.Framework.Scenes
2001 EventManager.TriggerPrimsLoaded(this); 2064 EventManager.TriggerPrimsLoaded(this);
2002 } 2065 }
2003 2066
2067 public bool SuportsRayCastFiltered()
2068 {
2069 if (PhysicsScene == null)
2070 return false;
2071 return PhysicsScene.SuportsRaycastWorldFiltered();
2072 }
2073
2074 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2075 {
2076 if (PhysicsScene == null)
2077 return null;
2078 return PhysicsScene.RaycastWorld(position, direction, length, Count,filter);
2079 }
2004 2080
2005 /// <summary> 2081 /// <summary>
2006 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed. 2082 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
@@ -2017,14 +2093,24 @@ namespace OpenSim.Region.Framework.Scenes
2017 /// <returns></returns> 2093 /// <returns></returns>
2018 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2094 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
2019 { 2095 {
2096
2097 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2098 Vector3 wpos = Vector3.Zero;
2099 // Check for water surface intersection from above
2100 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2101 {
2102 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2103 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2104 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2105 wpos.Z = wheight;
2106 }
2107
2020 Vector3 pos = Vector3.Zero; 2108 Vector3 pos = Vector3.Zero;
2021 if (RayEndIsIntersection == (byte)1) 2109 if (RayEndIsIntersection == (byte)1)
2022 { 2110 {
2023 pos = RayEnd; 2111 pos = RayEnd;
2024 return pos;
2025 } 2112 }
2026 2113 else if (RayTargetID != UUID.Zero)
2027 if (RayTargetID != UUID.Zero)
2028 { 2114 {
2029 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2115 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
2030 2116
@@ -2046,7 +2132,7 @@ namespace OpenSim.Region.Framework.Scenes
2046 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 2132 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
2047 2133
2048 // Un-comment out the following line to Get Raytrace results printed to the console. 2134 // Un-comment out the following line to Get Raytrace results printed to the console.
2049 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 2135 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
2050 float ScaleOffset = 0.5f; 2136 float ScaleOffset = 0.5f;
2051 2137
2052 // If we hit something 2138 // If we hit something
@@ -2069,13 +2155,10 @@ namespace OpenSim.Region.Framework.Scenes
2069 //pos.Z -= 0.25F; 2155 //pos.Z -= 0.25F;
2070 2156
2071 } 2157 }
2072
2073 return pos;
2074 } 2158 }
2075 else 2159 else
2076 { 2160 {
2077 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2161 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2078
2079 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2162 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2080 2163
2081 // Un-comment the following line to print the raytrace results to the console. 2164 // Un-comment the following line to print the raytrace results to the console.
@@ -2084,13 +2167,12 @@ namespace OpenSim.Region.Framework.Scenes
2084 if (ei.HitTF) 2167 if (ei.HitTF)
2085 { 2168 {
2086 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2169 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2087 } else 2170 }
2171 else
2088 { 2172 {
2089 // fall back to our stupid functionality 2173 // fall back to our stupid functionality
2090 pos = RayEnd; 2174 pos = RayEnd;
2091 } 2175 }
2092
2093 return pos;
2094 } 2176 }
2095 } 2177 }
2096 else 2178 else
@@ -2101,8 +2183,12 @@ namespace OpenSim.Region.Framework.Scenes
2101 //increase height so its above the ground. 2183 //increase height so its above the ground.
2102 //should be getting the normal of the ground at the rez point and using that? 2184 //should be getting the normal of the ground at the rez point and using that?
2103 pos.Z += scale.Z / 2f; 2185 pos.Z += scale.Z / 2f;
2104 return pos; 2186// return pos;
2105 } 2187 }
2188
2189 // check against posible water intercept
2190 if (wpos.Z > pos.Z) pos = wpos;
2191 return pos;
2106 } 2192 }
2107 2193
2108 2194
@@ -2193,12 +2279,12 @@ namespace OpenSim.Region.Framework.Scenes
2193 { 2279 {
2194 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates)) 2280 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates))
2195 { 2281 {
2282 sceneObject.IsDeleted = false;
2196 EventManager.TriggerObjectAddedToScene(sceneObject); 2283 EventManager.TriggerObjectAddedToScene(sceneObject);
2197 return true; 2284 return true;
2198 } 2285 }
2199 2286
2200 return false; 2287 return false;
2201
2202 } 2288 }
2203 2289
2204 /// <summary> 2290 /// <summary>
@@ -2290,6 +2376,15 @@ namespace OpenSim.Region.Framework.Scenes
2290 /// </summary> 2376 /// </summary>
2291 public void DeleteAllSceneObjects() 2377 public void DeleteAllSceneObjects()
2292 { 2378 {
2379 DeleteAllSceneObjects(false);
2380 }
2381
2382 /// <summary>
2383 /// Delete every object from the scene. This does not include attachments worn by avatars.
2384 /// </summary>
2385 public void DeleteAllSceneObjects(bool exceptNoCopy)
2386 {
2387 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2293 lock (Entities) 2388 lock (Entities)
2294 { 2389 {
2295 EntityBase[] entities = Entities.GetEntities(); 2390 EntityBase[] entities = Entities.GetEntities();
@@ -2298,11 +2393,24 @@ namespace OpenSim.Region.Framework.Scenes
2298 if (e is SceneObjectGroup) 2393 if (e is SceneObjectGroup)
2299 { 2394 {
2300 SceneObjectGroup sog = (SceneObjectGroup)e; 2395 SceneObjectGroup sog = (SceneObjectGroup)e;
2301 if (!sog.IsAttachment) 2396 if (sog != null && !sog.IsAttachment)
2302 DeleteSceneObject((SceneObjectGroup)e, false); 2397 {
2398 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2399 {
2400 DeleteSceneObject((SceneObjectGroup)e, false);
2401 }
2402 else
2403 {
2404 toReturn.Add((SceneObjectGroup)e);
2405 }
2406 }
2303 } 2407 }
2304 } 2408 }
2305 } 2409 }
2410 if (toReturn.Count > 0)
2411 {
2412 returnObjects(toReturn.ToArray(), UUID.Zero);
2413 }
2306 } 2414 }
2307 2415
2308 /// <summary> 2416 /// <summary>
@@ -2337,6 +2445,12 @@ namespace OpenSim.Region.Framework.Scenes
2337 2445
2338 foreach (SceneObjectPart part in partList) 2446 foreach (SceneObjectPart part in partList)
2339 { 2447 {
2448 if (part.KeyframeMotion != null)
2449 {
2450 part.KeyframeMotion.Delete();
2451 part.KeyframeMotion = null;
2452 }
2453
2340 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0)) 2454 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
2341 { 2455 {
2342 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? 2456 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
@@ -2354,6 +2468,8 @@ namespace OpenSim.Region.Framework.Scenes
2354 } 2468 }
2355 2469
2356 group.DeleteGroupFromScene(silent); 2470 group.DeleteGroupFromScene(silent);
2471 if (!silent)
2472 SendKillObject(new List<uint>() { group.LocalId });
2357 2473
2358// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2474// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2359 } 2475 }
@@ -2644,7 +2760,7 @@ namespace OpenSim.Region.Framework.Scenes
2644 // If the user is banned, we won't let any of their objects 2760 // If the user is banned, we won't let any of their objects
2645 // enter. Period. 2761 // enter. Period.
2646 // 2762 //
2647 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID)) 2763 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
2648 { 2764 {
2649 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID); 2765 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
2650 return false; 2766 return false;
@@ -2652,6 +2768,8 @@ namespace OpenSim.Region.Framework.Scenes
2652 2768
2653 if (newPosition != Vector3.Zero) 2769 if (newPosition != Vector3.Zero)
2654 newObject.RootPart.GroupPosition = newPosition; 2770 newObject.RootPart.GroupPosition = newPosition;
2771 if (newObject.RootPart.KeyframeMotion != null)
2772 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2655 2773
2656 if (!AddSceneObject(newObject)) 2774 if (!AddSceneObject(newObject))
2657 { 2775 {
@@ -2696,6 +2814,23 @@ namespace OpenSim.Region.Framework.Scenes
2696 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2814 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2697 public bool AddSceneObject(SceneObjectGroup sceneObject) 2815 public bool AddSceneObject(SceneObjectGroup sceneObject)
2698 { 2816 {
2817 if (sceneObject.OwnerID == UUID.Zero)
2818 {
2819 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2820 return false;
2821 }
2822
2823 // If the user is banned, we won't let any of their objects
2824 // enter. Period.
2825 //
2826 int flags = GetUserFlags(sceneObject.OwnerID);
2827 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2828 {
2829 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2830
2831 return false;
2832 }
2833
2699 // Force allocation of new LocalId 2834 // Force allocation of new LocalId
2700 // 2835 //
2701 SceneObjectPart[] parts = sceneObject.Parts; 2836 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2729,16 +2864,27 @@ namespace OpenSim.Region.Framework.Scenes
2729 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2864 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2730 2865
2731 if (AttachmentsModule != null) 2866 if (AttachmentsModule != null)
2732 AttachmentsModule.AttachObject(sp, grp, 0, false, false); 2867 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false);
2733 } 2868 }
2734 else 2869 else
2735 { 2870 {
2871 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2736 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2872 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2737 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2873 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2738 } 2874 }
2875 if (sceneObject.OwnerID == UUID.Zero)
2876 {
2877 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2878 return false;
2879 }
2739 } 2880 }
2740 else 2881 else
2741 { 2882 {
2883 if (sceneObject.OwnerID == UUID.Zero)
2884 {
2885 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2886 return false;
2887 }
2742 AddRestoredSceneObject(sceneObject, true, false); 2888 AddRestoredSceneObject(sceneObject, true, false);
2743 } 2889 }
2744 2890
@@ -2755,6 +2901,24 @@ namespace OpenSim.Region.Framework.Scenes
2755 return 2; // StateSource.PrimCrossing 2901 return 2; // StateSource.PrimCrossing
2756 } 2902 }
2757 2903
2904 public int GetUserFlags(UUID user)
2905 {
2906 //Unfortunately the SP approach means that the value is cached until region is restarted
2907 /*
2908 ScenePresence sp;
2909 if (TryGetScenePresence(user, out sp))
2910 {
2911 return sp.UserFlags;
2912 }
2913 else
2914 {
2915 */
2916 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2917 if (uac == null)
2918 return 0;
2919 return uac.UserFlags;
2920 //}
2921 }
2758 #endregion 2922 #endregion
2759 2923
2760 #region Add/Remove Avatar Methods 2924 #region Add/Remove Avatar Methods
@@ -2787,7 +2951,7 @@ namespace OpenSim.Region.Framework.Scenes
2787 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2951 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2788 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2952 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2789 2953
2790 // CheckHeartbeat(); 2954 CheckHeartbeat();
2791 2955
2792 sp = GetScenePresence(client.AgentId); 2956 sp = GetScenePresence(client.AgentId);
2793 2957
@@ -2818,6 +2982,7 @@ namespace OpenSim.Region.Framework.Scenes
2818 // start the scripts again (since this is done in RezAttachments()). 2982 // start the scripts again (since this is done in RezAttachments()).
2819 // XXX: This is convoluted. 2983 // XXX: This is convoluted.
2820 sp.IsChildAgent = false; 2984 sp.IsChildAgent = false;
2985 sp.IsLoggingIn = true;
2821 2986
2822 if (AttachmentsModule != null) 2987 if (AttachmentsModule != null)
2823 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); }); 2988 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); });
@@ -2931,19 +3096,14 @@ namespace OpenSim.Region.Framework.Scenes
2931 // and the scene presence and the client, if they exist 3096 // and the scene presence and the client, if they exist
2932 try 3097 try
2933 { 3098 {
2934 // We need to wait for the client to make UDP contact first. 3099 ScenePresence sp = GetScenePresence(agentID);
2935 // It's the UDP contact that creates the scene presence 3100
2936 ScenePresence sp = WaitGetScenePresence(agentID);
2937 if (sp != null) 3101 if (sp != null)
2938 { 3102 {
2939 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3103 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2940
2941 sp.ControllingClient.Close(); 3104 sp.ControllingClient.Close();
2942 } 3105 }
2943 else 3106
2944 {
2945 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2946 }
2947 // BANG! SLASH! 3107 // BANG! SLASH!
2948 m_authenticateHandler.RemoveCircuit(agentID); 3108 m_authenticateHandler.RemoveCircuit(agentID);
2949 3109
@@ -2988,6 +3148,8 @@ namespace OpenSim.Region.Framework.Scenes
2988 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3148 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2989 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3149 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2990 3150
3151 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3152
2991 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3153 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2992 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3154 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2993 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3155 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -3044,6 +3206,7 @@ namespace OpenSim.Region.Framework.Scenes
3044 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3206 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
3045 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3207 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
3046 client.OnCopyInventoryItem += CopyInventoryItem; 3208 client.OnCopyInventoryItem += CopyInventoryItem;
3209 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
3047 client.OnMoveInventoryItem += MoveInventoryItem; 3210 client.OnMoveInventoryItem += MoveInventoryItem;
3048 client.OnRemoveInventoryItem += RemoveInventoryItem; 3211 client.OnRemoveInventoryItem += RemoveInventoryItem;
3049 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3212 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3115,6 +3278,8 @@ namespace OpenSim.Region.Framework.Scenes
3115 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3278 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3116 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3279 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3117 3280
3281 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3282
3118 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3283 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3119 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3284 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3120 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3285 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3217,7 +3382,7 @@ namespace OpenSim.Region.Framework.Scenes
3217 /// </summary> 3382 /// </summary>
3218 /// <param name="agentId">The avatar's Unique ID</param> 3383 /// <param name="agentId">The avatar's Unique ID</param>
3219 /// <param name="client">The IClientAPI for the client</param> 3384 /// <param name="client">The IClientAPI for the client</param>
3220 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3385 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3221 { 3386 {
3222 if (EntityTransferModule != null) 3387 if (EntityTransferModule != null)
3223 { 3388 {
@@ -3228,6 +3393,7 @@ namespace OpenSim.Region.Framework.Scenes
3228 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3393 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3229 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3394 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3230 } 3395 }
3396 return false;
3231 } 3397 }
3232 3398
3233 /// <summary> 3399 /// <summary>
@@ -3337,6 +3503,16 @@ namespace OpenSim.Region.Framework.Scenes
3337 /// <param name="flags"></param> 3503 /// <param name="flags"></param>
3338 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3504 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3339 { 3505 {
3506 //Add half the avatar's height so that the user doesn't fall through prims
3507 ScenePresence presence;
3508 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3509 {
3510 if (presence.Appearance != null)
3511 {
3512 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3513 }
3514 }
3515
3340 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3516 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3341 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3517 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3342 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3518 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3474,6 +3650,7 @@ namespace OpenSim.Region.Framework.Scenes
3474 // It's possible for child agents to have transactions if changes are being made cross-border. 3650 // It's possible for child agents to have transactions if changes are being made cross-border.
3475 if (AgentTransactionsModule != null) 3651 if (AgentTransactionsModule != null)
3476 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 3652 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3653 m_log.Debug("[Scene] The avatar has left the building");
3477 } 3654 }
3478 catch (Exception e) 3655 catch (Exception e)
3479 { 3656 {
@@ -3666,38 +3843,39 @@ namespace OpenSim.Region.Framework.Scenes
3666 agent.firstname, agent.lastname, agent.Viewer); 3843 agent.firstname, agent.lastname, agent.Viewer);
3667 reason = "Access denied, your viewer is banned by the region owner"; 3844 reason = "Access denied, your viewer is banned by the region owner";
3668 return false; 3845 return false;
3669 } 3846 }
3847
3848
3849 ScenePresence sp = GetScenePresence(agent.AgentID);
3670 3850
3671 ILandObject land; 3851 if (sp != null && !sp.IsChildAgent)
3852 {
3853 // We have a zombie from a crashed session.
3854 // Or the same user is trying to be root twice here, won't work.
3855 // Kill it.
3856 m_log.WarnFormat(
3857 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3858 sp.Name, sp.UUID, RegionInfo.RegionName);
3859
3860 sp.ControllingClient.Close(true, true);
3861 sp = null;
3862 }
3672 3863
3673 lock (agent) 3864 lock (agent)
3674 { 3865 {
3675 ScenePresence sp = GetScenePresence(agent.AgentID);
3676
3677 if (sp != null && !sp.IsChildAgent)
3678 {
3679 // We have a zombie from a crashed session.
3680 // Or the same user is trying to be root twice here, won't work.
3681 // Kill it.
3682 m_log.WarnFormat(
3683 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3684 sp.Name, sp.UUID, RegionInfo.RegionName);
3685
3686 sp.ControllingClient.Close(true);
3687 sp = null;
3688 }
3689
3690 land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3691
3692 //On login test land permisions 3866 //On login test land permisions
3693 if (vialogin) 3867 if (vialogin)
3694 { 3868 {
3695 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3869 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3870 if (cache != null)
3871 cache.Remove(agent.firstname + " " + agent.lastname);
3872 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3696 { 3873 {
3874 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3697 return false; 3875 return false;
3698 } 3876 }
3699 } 3877 }
3700 3878
3701 if (sp == null) // We don't have an [child] agent here already 3879 if (sp == null) // We don't have an [child] agent here already
3702 { 3880 {
3703 if (requirePresenceLookup) 3881 if (requirePresenceLookup)
@@ -3706,34 +3884,36 @@ namespace OpenSim.Region.Framework.Scenes
3706 { 3884 {
3707 if (!VerifyUserPresence(agent, out reason)) 3885 if (!VerifyUserPresence(agent, out reason))
3708 return false; 3886 return false;
3709 } 3887 } catch (Exception e)
3710 catch (Exception e)
3711 { 3888 {
3712 m_log.ErrorFormat( 3889 m_log.ErrorFormat(
3713 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace); 3890 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace);
3714
3715 return false; 3891 return false;
3716 } 3892 }
3717 } 3893 }
3718 3894
3719 try 3895 try
3720 { 3896 {
3721 if (!AuthorizeUser(agent, out reason)) 3897 // Always check estate if this is a login. Always
3722 return false; 3898 // check if banned regions are to be blacked out.
3899 if (vialogin || (!m_seeIntoBannedRegion))
3900 {
3901 if (!AuthorizeUser(agent, out reason))
3902 return false;
3903 }
3723 } 3904 }
3724 catch (Exception e) 3905 catch (Exception e)
3725 { 3906 {
3726 m_log.ErrorFormat( 3907 m_log.ErrorFormat(
3727 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3908 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
3728
3729 return false; 3909 return false;
3730 } 3910 }
3731 3911
3732 m_log.InfoFormat( 3912 m_log.InfoFormat(
3733 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})", 3913 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})",
3734 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname, 3914 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
3735 agent.AgentID, agent.circuitcode); 3915 agent.AgentID, agent.circuitcode);
3736 3916
3737 if (CapsModule != null) 3917 if (CapsModule != null)
3738 { 3918 {
3739 CapsModule.SetAgentCapsSeeds(agent); 3919 CapsModule.SetAgentCapsSeeds(agent);
@@ -3745,15 +3925,15 @@ namespace OpenSim.Region.Framework.Scenes
3745 // Let the SP know how we got here. This has a lot of interesting 3925 // Let the SP know how we got here. This has a lot of interesting
3746 // uses down the line. 3926 // uses down the line.
3747 sp.TeleportFlags = (TPFlags)teleportFlags; 3927 sp.TeleportFlags = (TPFlags)teleportFlags;
3748 3928
3749 if (sp.IsChildAgent) 3929 if (sp.IsChildAgent)
3750 { 3930 {
3751 m_log.DebugFormat( 3931 m_log.DebugFormat(
3752 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}", 3932 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
3753 agent.AgentID, RegionInfo.RegionName); 3933 agent.AgentID, RegionInfo.RegionName);
3754 3934
3755 sp.AdjustKnownSeeds(); 3935 sp.AdjustKnownSeeds();
3756 3936
3757 if (CapsModule != null) 3937 if (CapsModule != null)
3758 CapsModule.SetAgentCapsSeeds(agent); 3938 CapsModule.SetAgentCapsSeeds(agent);
3759 } 3939 }
@@ -3855,6 +4035,8 @@ namespace OpenSim.Region.Framework.Scenes
3855 } 4035 }
3856 4036
3857 // Honor parcel landing type and position. 4037 // Honor parcel landing type and position.
4038 /*
4039 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3858 if (land != null) 4040 if (land != null)
3859 { 4041 {
3860 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 4042 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3862,25 +4044,43 @@ namespace OpenSim.Region.Framework.Scenes
3862 agent.startpos = land.LandData.UserLocation; 4044 agent.startpos = land.LandData.UserLocation;
3863 } 4045 }
3864 } 4046 }
4047 */// This is now handled properly in ScenePresence.MakeRootAgent
3865 } 4048 }
3866 4049
3867 return true; 4050 return true;
3868 } 4051 }
3869 4052
3870 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 4053 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3871 { 4054 {
3872 bool banned = land.IsBannedFromLand(agent.AgentID); 4055 if (posX < 0)
3873 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 4056 posX = 0;
4057 else if (posX >= 256)
4058 posX = 255.999f;
4059 if (posY < 0)
4060 posY = 0;
4061 else if (posY >= 256)
4062 posY = 255.999f;
4063
4064 reason = String.Empty;
4065 if (Permissions.IsGod(agentID))
4066 return true;
4067
4068 ILandObject land = LandChannel.GetLandObject(posX, posY);
4069 if (land == null)
4070 return false;
4071
4072 bool banned = land.IsBannedFromLand(agentID);
4073 bool restricted = land.IsRestrictedFromLand(agentID);
3874 4074
3875 if (banned || restricted) 4075 if (banned || restricted)
3876 { 4076 {
3877 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 4077 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3878 if (nearestParcel != null) 4078 if (nearestParcel != null)
3879 { 4079 {
3880 //Move agent to nearest allowed 4080 //Move agent to nearest allowed
3881 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 4081 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3882 agent.startpos.X = newPosition.X; 4082 posX = newPosition.X;
3883 agent.startpos.Y = newPosition.Y; 4083 posY = newPosition.Y;
3884 } 4084 }
3885 else 4085 else
3886 { 4086 {
@@ -3942,7 +4142,7 @@ namespace OpenSim.Region.Framework.Scenes
3942 4142
3943 if (!m_strictAccessControl) return true; 4143 if (!m_strictAccessControl) return true;
3944 if (Permissions.IsGod(agent.AgentID)) return true; 4144 if (Permissions.IsGod(agent.AgentID)) return true;
3945 4145
3946 if (AuthorizationService != null) 4146 if (AuthorizationService != null)
3947 { 4147 {
3948 if (!AuthorizationService.IsAuthorizedForRegion( 4148 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3957,7 +4157,7 @@ namespace OpenSim.Region.Framework.Scenes
3957 4157
3958 if (RegionInfo.EstateSettings != null) 4158 if (RegionInfo.EstateSettings != null)
3959 { 4159 {
3960 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4160 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, 0))
3961 { 4161 {
3962 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4162 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3963 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4163 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4147,6 +4347,15 @@ namespace OpenSim.Region.Framework.Scenes
4147 4347
4148 // XPTO: if this agent is not allowed here as root, always return false 4348 // XPTO: if this agent is not allowed here as root, always return false
4149 4349
4350 // We have to wait until the viewer contacts this region after receiving EAC.
4351 // That calls AddNewClient, which finally creates the ScenePresence
4352 int flags = GetUserFlags(cAgentData.AgentID);
4353 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4354 {
4355 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4356 return false;
4357 }
4358
4150 // TODO: This check should probably be in QueryAccess(). 4359 // TODO: This check should probably be in QueryAccess().
4151 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4360 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4152 if (nearestParcel == null) 4361 if (nearestParcel == null)
@@ -4211,7 +4420,7 @@ namespace OpenSim.Region.Framework.Scenes
4211 /// <param name='agentID'></param> 4420 /// <param name='agentID'></param>
4212 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4421 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4213 { 4422 {
4214 int ntimes = 10; 4423 int ntimes = 30;
4215 ScenePresence sp = null; 4424 ScenePresence sp = null;
4216 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4425 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4217 Thread.Sleep(1000); 4426 Thread.Sleep(1000);
@@ -4241,6 +4450,16 @@ namespace OpenSim.Region.Framework.Scenes
4241 return false; 4450 return false;
4242 } 4451 }
4243 4452
4453 public bool IncomingCloseAgent(UUID agentID)
4454 {
4455 return IncomingCloseAgent(agentID, false);
4456 }
4457
4458 public bool IncomingCloseChildAgent(UUID agentID)
4459 {
4460 return IncomingCloseAgent(agentID, true);
4461 }
4462
4244 /// <summary> 4463 /// <summary>
4245 /// Tell a single agent to disconnect from the region. 4464 /// Tell a single agent to disconnect from the region.
4246 /// </summary> 4465 /// </summary>
@@ -4256,7 +4475,7 @@ namespace OpenSim.Region.Framework.Scenes
4256 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4475 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4257 if (presence != null) 4476 if (presence != null)
4258 { 4477 {
4259 presence.ControllingClient.Close(force); 4478 presence.ControllingClient.Close(force, force);
4260 return true; 4479 return true;
4261 } 4480 }
4262 4481
@@ -4916,35 +5135,81 @@ namespace OpenSim.Region.Framework.Scenes
4916 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5135 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
4917 } 5136 }
4918 5137
4919 public int GetHealth() 5138 public int GetHealth(out int flags, out string message)
4920 { 5139 {
4921 // Returns: 5140 // Returns:
4922 // 1 = sim is up and accepting http requests. The heartbeat has 5141 // 1 = sim is up and accepting http requests. The heartbeat has
4923 // stopped and the sim is probably locked up, but a remote 5142 // stopped and the sim is probably locked up, but a remote
4924 // admin restart may succeed 5143 // admin restart may succeed
4925 // 5144 //
4926 // 2 = Sim is up and the heartbeat is running. The sim is likely 5145 // 2 = Sim is up and the heartbeat is running. The sim is likely
4927 // usable for people within and logins _may_ work 5146 // usable for people within
5147 //
5148 // 3 = Sim is up and one packet thread is running. Sim is
5149 // unstable and will not accept new logins
4928 // 5150 //
4929 // 3 = We have seen a new user enter within the past 4 minutes 5151 // 4 = Sim is up and both packet threads are running. Sim is
5152 // likely usable
5153 //
5154 // 5 = We have seen a new user enter within the past 4 minutes
4930 // which can be seen as positive confirmation of sim health 5155 // which can be seen as positive confirmation of sim health
4931 // 5156 //
5157
5158 flags = 0;
5159 message = String.Empty;
5160
5161 CheckHeartbeat();
5162
5163 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5164 {
5165 // We're still starting
5166 // 0 means "in startup", it can't happen another way, since
5167 // to get here, we must be able to accept http connections
5168 return 0;
5169 }
5170
4932 int health=1; // Start at 1, means we're up 5171 int health=1; // Start at 1, means we're up
4933 5172
4934 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5173 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4935 health += 1; 5174 {
5175 health+=1;
5176 flags |= 1;
5177 }
5178
5179 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5180 {
5181 health+=1;
5182 flags |= 2;
5183 }
5184
5185 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5186 {
5187 health+=1;
5188 flags |= 4;
5189 }
4936 else 5190 else
5191 {
5192int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5193System.Diagnostics.Process proc = new System.Diagnostics.Process();
5194proc.EnableRaisingEvents=false;
5195proc.StartInfo.FileName = "/bin/kill";
5196proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5197proc.Start();
5198proc.WaitForExit();
5199Thread.Sleep(1000);
5200Environment.Exit(1);
5201 }
5202
5203 if (flags != 7)
4937 return health; 5204 return health;
4938 5205
4939 // A login in the last 4 mins? We can't be doing too badly 5206 // A login in the last 4 mins? We can't be doing too badly
4940 // 5207 //
4941 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5208 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4942 health++; 5209 health++;
4943 else 5210 else
4944 return health; 5211 return health;
4945 5212
4946// CheckHeartbeat();
4947
4948 return health; 5213 return health;
4949 } 5214 }
4950 5215
@@ -5032,7 +5297,7 @@ namespace OpenSim.Region.Framework.Scenes
5032 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 5297 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
5033 if (wasUsingPhysics) 5298 if (wasUsingPhysics)
5034 { 5299 {
5035 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 5300 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
5036 } 5301 }
5037 } 5302 }
5038 5303
@@ -5131,14 +5396,14 @@ namespace OpenSim.Region.Framework.Scenes
5131 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5396 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5132 } 5397 }
5133 5398
5134// private void CheckHeartbeat() 5399 private void CheckHeartbeat()
5135// { 5400 {
5136// if (m_firstHeartbeat) 5401 if (m_firstHeartbeat)
5137// return; 5402 return;
5138// 5403
5139// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5404 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5140// StartTimer(); 5405 Start();
5141// } 5406 }
5142 5407
5143 public override ISceneObject DeserializeObject(string representation) 5408 public override ISceneObject DeserializeObject(string representation)
5144 { 5409 {
@@ -5150,9 +5415,14 @@ namespace OpenSim.Region.Framework.Scenes
5150 get { return m_allowScriptCrossings; } 5415 get { return m_allowScriptCrossings; }
5151 } 5416 }
5152 5417
5153 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5418 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5154 { 5419 {
5155 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5420 return GetNearestAllowedPosition(avatar, null);
5421 }
5422
5423 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5424 {
5425 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
5156 5426
5157 if (nearestParcel != null) 5427 if (nearestParcel != null)
5158 { 5428 {
@@ -5161,10 +5431,7 @@ namespace OpenSim.Region.Framework.Scenes
5161 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5431 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5162 if (nearestPoint != null) 5432 if (nearestPoint != null)
5163 { 5433 {
5164// m_log.DebugFormat( 5434 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
5165// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
5166// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
5167
5168 return nearestPoint.Value; 5435 return nearestPoint.Value;
5169 } 5436 }
5170 5437
@@ -5174,17 +5441,20 @@ namespace OpenSim.Region.Framework.Scenes
5174 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5441 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5175 if (nearestPoint != null) 5442 if (nearestPoint != null)
5176 { 5443 {
5177// m_log.DebugFormat( 5444 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
5178// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
5179
5180 return nearestPoint.Value; 5445 return nearestPoint.Value;
5181 } 5446 }
5182 5447
5183 //Ultimate backup if we have no idea where they are 5448 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
5184// m_log.DebugFormat( 5449 if (dest != excludeParcel)
5185// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5450 {
5451 // Ultimate backup if we have no idea where they are and
5452 // the last allowed position was in another parcel
5453 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5454 return avatar.lastKnownAllowedPosition;
5455 }
5186 5456
5187 return avatar.lastKnownAllowedPosition; 5457 // else fall through to region edge
5188 } 5458 }
5189 5459
5190 //Go to the edge, this happens in teleporting to a region with no available parcels 5460 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -5218,13 +5488,18 @@ namespace OpenSim.Region.Framework.Scenes
5218 5488
5219 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5489 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5220 { 5490 {
5491 return GetNearestAllowedParcel(avatarId, x, y, null);
5492 }
5493
5494 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5495 {
5221 List<ILandObject> all = AllParcels(); 5496 List<ILandObject> all = AllParcels();
5222 float minParcelDistance = float.MaxValue; 5497 float minParcelDistance = float.MaxValue;
5223 ILandObject nearestParcel = null; 5498 ILandObject nearestParcel = null;
5224 5499
5225 foreach (var parcel in all) 5500 foreach (var parcel in all)
5226 { 5501 {
5227 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5502 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
5228 { 5503 {
5229 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5504 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5230 if (parcelDistance < minParcelDistance) 5505 if (parcelDistance < minParcelDistance)
@@ -5440,7 +5715,55 @@ namespace OpenSim.Region.Framework.Scenes
5440 mapModule.GenerateMaptile(); 5715 mapModule.GenerateMaptile();
5441 } 5716 }
5442 5717
5443 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5718// public void CleanDroppedAttachments()
5719// {
5720// List<SceneObjectGroup> objectsToDelete =
5721// new List<SceneObjectGroup>();
5722//
5723// lock (m_cleaningAttachments)
5724// {
5725// ForEachSOG(delegate (SceneObjectGroup grp)
5726// {
5727// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5728// {
5729// UUID agentID = grp.OwnerID;
5730// if (agentID == UUID.Zero)
5731// {
5732// objectsToDelete.Add(grp);
5733// return;
5734// }
5735//
5736// ScenePresence sp = GetScenePresence(agentID);
5737// if (sp == null)
5738// {
5739// objectsToDelete.Add(grp);
5740// return;
5741// }
5742// }
5743// });
5744// }
5745//
5746// foreach (SceneObjectGroup grp in objectsToDelete)
5747// {
5748// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5749// DeleteSceneObject(grp, true);
5750// }
5751// }
5752
5753 public void ThreadAlive(int threadCode)
5754 {
5755 switch(threadCode)
5756 {
5757 case 1: // Incoming
5758 m_lastIncoming = Util.EnvironmentTickCount();
5759 break;
5760 case 2: // Incoming
5761 m_lastOutgoing = Util.EnvironmentTickCount();
5762 break;
5763 }
5764 }
5765
5766 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5444 { 5767 {
5445 RegenerateMaptile(); 5768 RegenerateMaptile();
5446 5769
@@ -5468,6 +5791,8 @@ namespace OpenSim.Region.Framework.Scenes
5468 /// <returns></returns> 5791 /// <returns></returns>
5469 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5792 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5470 { 5793 {
5794 reason = "You are banned from the region";
5795
5471 if (EntityTransferModule.IsInTransit(agentID)) 5796 if (EntityTransferModule.IsInTransit(agentID))
5472 { 5797 {
5473 reason = "Agent is still in transit from this region"; 5798 reason = "Agent is still in transit from this region";
@@ -5479,6 +5804,12 @@ namespace OpenSim.Region.Framework.Scenes
5479 return false; 5804 return false;
5480 } 5805 }
5481 5806
5807 if (Permissions.IsGod(agentID))
5808 {
5809 reason = String.Empty;
5810 return true;
5811 }
5812
5482 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5813 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5483 // However, the long term fix is to make sure root agent count is always accurate. 5814 // However, the long term fix is to make sure root agent count is always accurate.
5484 m_sceneGraph.RecalculateStats(); 5815 m_sceneGraph.RecalculateStats();
@@ -5499,6 +5830,41 @@ namespace OpenSim.Region.Framework.Scenes
5499 } 5830 }
5500 } 5831 }
5501 5832
5833 ScenePresence presence = GetScenePresence(agentID);
5834 IClientAPI client = null;
5835 AgentCircuitData aCircuit = null;
5836
5837 if (presence != null)
5838 {
5839 client = presence.ControllingClient;
5840 if (client != null)
5841 aCircuit = client.RequestClientInfo();
5842 }
5843
5844 // We may be called before there is a presence or a client.
5845 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5846 if (client == null)
5847 {
5848 aCircuit = new AgentCircuitData();
5849 aCircuit.AgentID = agentID;
5850 aCircuit.firstname = String.Empty;
5851 aCircuit.lastname = String.Empty;
5852 }
5853
5854 try
5855 {
5856 if (!AuthorizeUser(aCircuit, out reason))
5857 {
5858 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5859 return false;
5860 }
5861 }
5862 catch (Exception e)
5863 {
5864 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5865 return false;
5866 }
5867
5502 if (position == Vector3.Zero) // Teleport 5868 if (position == Vector3.Zero) // Teleport
5503 { 5869 {
5504 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5870 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5527,13 +5893,46 @@ namespace OpenSim.Region.Framework.Scenes
5527 } 5893 }
5528 } 5894 }
5529 } 5895 }
5896
5897 float posX = 128.0f;
5898 float posY = 128.0f;
5899
5900 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5901 {
5902 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5903 return false;
5904 }
5905 }
5906 else // Walking
5907 {
5908 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5909 if (land == null)
5910 return false;
5911
5912 bool banned = land.IsBannedFromLand(agentID);
5913 bool restricted = land.IsRestrictedFromLand(agentID);
5914
5915 if (banned || restricted)
5916 return false;
5530 } 5917 }
5531 5918
5532 reason = String.Empty; 5919 reason = String.Empty;
5533 return true; 5920 return true;
5534 } 5921 }
5535 5922
5536 /// <summary> 5923 public void StartTimerWatchdog()
5924 {
5925 m_timerWatchdog.Interval = 1000;
5926 m_timerWatchdog.Elapsed += TimerWatchdog;
5927 m_timerWatchdog.AutoReset = true;
5928 m_timerWatchdog.Start();
5929 }
5930
5931 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5932 {
5933 CheckHeartbeat();
5934 }
5935
5537 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5936 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5538 /// autopilot that moves an avatar to a sit target!. 5937 /// autopilot that moves an avatar to a sit target!.
5539 /// </summary> 5938 /// </summary>
@@ -5612,6 +6011,11 @@ namespace OpenSim.Region.Framework.Scenes
5612 return m_SpawnPoint - 1; 6011 return m_SpawnPoint - 1;
5613 } 6012 }
5614 6013
6014 private void HandleGcCollect(string module, string[] args)
6015 {
6016 GC.Collect();
6017 }
6018
5615 /// <summary> 6019 /// <summary>
5616 /// Wrappers to get physics modules retrieve assets. 6020 /// Wrappers to get physics modules retrieve assets.
5617 /// </summary> 6021 /// </summary>