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.cs836
1 files changed, 624 insertions, 212 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 872c061..129bf09 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -151,8 +151,8 @@ namespace OpenSim.Region.Framework.Scenes
151 // TODO: need to figure out how allow client agents but deny 151 // TODO: need to figure out how allow client agents but deny
152 // root agents when ACL denies access to root agent 152 // root agents when ACL denies access to root agent
153 public bool m_strictAccessControl = true; 153 public bool m_strictAccessControl = true;
154 154 public bool m_seeIntoBannedRegion = false;
155 public int MaxUndoCount { get; set; } 155 public int MaxUndoCount = 5;
156 156
157 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 157 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
158 public bool LoginLock = false; 158 public bool LoginLock = false;
@@ -168,12 +168,14 @@ namespace OpenSim.Region.Framework.Scenes
168 168
169 protected int m_splitRegionID; 169 protected int m_splitRegionID;
170 protected Timer m_restartWaitTimer = new Timer(); 170 protected Timer m_restartWaitTimer = new Timer();
171 protected Timer m_timerWatchdog = new Timer();
171 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 172 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
172 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 173 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
173 protected string m_simulatorVersion = "OpenSimulator Server"; 174 protected string m_simulatorVersion = "OpenSimulator Server";
174 protected ModuleLoader m_moduleLoader; 175 protected ModuleLoader m_moduleLoader;
175 protected AgentCircuitManager m_authenticateHandler; 176 protected AgentCircuitManager m_authenticateHandler;
176 protected SceneCommunicationService m_sceneGridService; 177 protected SceneCommunicationService m_sceneGridService;
178 protected ISnmpModule m_snmpService = null;
177 179
178 protected ISimulationDataService m_SimulationDataService; 180 protected ISimulationDataService m_SimulationDataService;
179 protected IEstateDataService m_EstateDataService; 181 protected IEstateDataService m_EstateDataService;
@@ -236,8 +238,8 @@ namespace OpenSim.Region.Framework.Scenes
236 private int m_update_presences = 1; // Update scene presence movements 238 private int m_update_presences = 1; // Update scene presence movements
237 private int m_update_events = 1; 239 private int m_update_events = 1;
238 private int m_update_backup = 200; 240 private int m_update_backup = 200;
239 private int m_update_terrain = 50; 241 private int m_update_terrain = 1000;
240// private int m_update_land = 1; 242 private int m_update_land = 10;
241 private int m_update_coarse_locations = 50; 243 private int m_update_coarse_locations = 50;
242 244
243 private int agentMS; 245 private int agentMS;
@@ -250,13 +252,13 @@ namespace OpenSim.Region.Framework.Scenes
250 private int backupMS; 252 private int backupMS;
251 private int terrainMS; 253 private int terrainMS;
252 private int landMS; 254 private int landMS;
253 private int spareMS;
254 255
255 /// <summary> 256 /// <summary>
256 /// Tick at which the last frame was processed. 257 /// Tick at which the last frame was processed.
257 /// </summary> 258 /// </summary>
258 private int m_lastFrameTick; 259 private int m_lastFrameTick;
259 260
261 public bool CombineRegions = false;
260 /// <summary> 262 /// <summary>
261 /// Tick at which the last maintenance run occurred. 263 /// Tick at which the last maintenance run occurred.
262 /// </summary> 264 /// </summary>
@@ -287,6 +289,11 @@ namespace OpenSim.Region.Framework.Scenes
287 /// </summary> 289 /// </summary>
288 private int m_LastLogin; 290 private int m_LastLogin;
289 291
292 private int m_lastIncoming;
293 private int m_lastOutgoing;
294 private int m_hbRestarts = 0;
295
296
290 /// <summary> 297 /// <summary>
291 /// Thread that runs the scene loop. 298 /// Thread that runs the scene loop.
292 /// </summary> 299 /// </summary>
@@ -302,7 +309,7 @@ namespace OpenSim.Region.Framework.Scenes
302 private volatile bool m_shuttingDown; 309 private volatile bool m_shuttingDown;
303 310
304// private int m_lastUpdate; 311// private int m_lastUpdate;
305// private bool m_firstHeartbeat = true; 312 private bool m_firstHeartbeat = true;
306 313
307 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time; 314 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
308 private bool m_reprioritizationEnabled = true; 315 private bool m_reprioritizationEnabled = true;
@@ -347,6 +354,19 @@ namespace OpenSim.Region.Framework.Scenes
347 get { return m_sceneGridService; } 354 get { return m_sceneGridService; }
348 } 355 }
349 356
357 public ISnmpModule SnmpService
358 {
359 get
360 {
361 if (m_snmpService == null)
362 {
363 m_snmpService = RequestModuleInterface<ISnmpModule>();
364 }
365
366 return m_snmpService;
367 }
368 }
369
350 public ISimulationDataService SimulationDataService 370 public ISimulationDataService SimulationDataService
351 { 371 {
352 get 372 get
@@ -646,6 +666,8 @@ namespace OpenSim.Region.Framework.Scenes
646 m_SimulationDataService = simDataService; 666 m_SimulationDataService = simDataService;
647 m_EstateDataService = estateDataService; 667 m_EstateDataService = estateDataService;
648 m_regionHandle = RegionInfo.RegionHandle; 668 m_regionHandle = RegionInfo.RegionHandle;
669 m_lastIncoming = 0;
670 m_lastOutgoing = 0;
649 671
650 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 672 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
651 m_asyncSceneObjectDeleter.Enabled = true; 673 m_asyncSceneObjectDeleter.Enabled = true;
@@ -728,137 +750,148 @@ namespace OpenSim.Region.Framework.Scenes
728 750
729 // Region config overrides global config 751 // Region config overrides global config
730 // 752 //
731 if (m_config.Configs["Startup"] != null) 753 try
732 { 754 {
733 IConfig startupConfig = m_config.Configs["Startup"]; 755 if (m_config.Configs["Startup"] != null)
734 756 {
735 StartDisabled = startupConfig.GetBoolean("StartDisabled", false); 757 IConfig startupConfig = m_config.Configs["Startup"];
736 758
737 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance); 759 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
738 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
739 if (!m_useBackup)
740 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
741
742 //Animation states
743 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
744 760
745 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims); 761 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
746 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims); 762 m_useBackup = startupConfig.GetBoolean("UseSceneBackup", m_useBackup);
763 if (!m_useBackup)
764 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
765
766 //Animation states
767 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
747 768
748 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys); 769 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
749 if (RegionInfo.NonphysPrimMin > 0) 770 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
750 {
751 m_minNonphys = RegionInfo.NonphysPrimMin;
752 }
753 771
754 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 772 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
755 if (RegionInfo.NonphysPrimMax > 0) 773 if (RegionInfo.NonphysPrimMin > 0)
756 { 774 {
757 m_maxNonphys = RegionInfo.NonphysPrimMax; 775 m_minNonphys = RegionInfo.NonphysPrimMin;
758 } 776 }
759 777
760 m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys); 778 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
761 if (RegionInfo.PhysPrimMin > 0) 779 if (RegionInfo.NonphysPrimMax > 0)
762 { 780 {
763 m_minPhys = RegionInfo.PhysPrimMin; 781 m_maxNonphys = RegionInfo.NonphysPrimMax;
764 } 782 }
765 783
766 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 784 m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys);
767 if (RegionInfo.PhysPrimMax > 0) 785 if (RegionInfo.PhysPrimMin > 0)
768 { 786 {
769 m_maxPhys = RegionInfo.PhysPrimMax; 787 m_minPhys = RegionInfo.PhysPrimMin;
770 } 788 }
771 789
772 // Here, if clamping is requested in either global or 790 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
773 // local config, it will be used
774 //
775 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
776 if (RegionInfo.ClampPrimSize)
777 {
778 m_clampPrimSize = true;
779 }
780 791
781 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); 792 if (RegionInfo.PhysPrimMax > 0)
782 if (RegionInfo.LinksetCapacity > 0) 793 {
783 { 794 m_maxPhys = RegionInfo.PhysPrimMax;
784 m_linksetCapacity = RegionInfo.LinksetCapacity; 795 }
785 }
786 796
787 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete); 797 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity);
788 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 798 if (RegionInfo.LinksetCapacity > 0)
789 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 799 {
790 m_dontPersistBefore = 800 m_linksetCapacity = RegionInfo.LinksetCapacity;
791 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE); 801 }
792 m_dontPersistBefore *= 10000000;
793 m_persistAfter =
794 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
795 m_persistAfter *= 10000000;
796 802
797 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 803 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
804 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
798 805
799 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest"); 806 // Here, if clamping is requested in either global or
800 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false); 807 // local config, it will be used
808 //
809 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
810 if (RegionInfo.ClampPrimSize)
811 {
812 m_clampPrimSize = true;
813 }
801 814
802 IConfig packetConfig = m_config.Configs["PacketPool"]; 815 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
803 if (packetConfig != null) 816 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
804 { 817 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
805 PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true); 818 m_dontPersistBefore =
806 PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true); 819 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE);
807 } 820 m_dontPersistBefore *= 10000000;
821 m_persistAfter =
822 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
823 m_persistAfter *= 10000000;
824
825 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
826 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
827
828 IConfig packetConfig = m_config.Configs["PacketPool"];
829 if (packetConfig != null)
830 {
831 PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true);
832 PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true);
833 }
808 834
809 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 835 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
836 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
837 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
810 838
811 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 839 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
812 if (m_generateMaptiles) 840 if (m_generateMaptiles)
813 {
814 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0);
815 if (maptileRefresh != 0)
816 { 841 {
817 m_mapGenerationTimer.Interval = maptileRefresh * 1000; 842 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0);
818 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister; 843 if (maptileRefresh != 0)
819 m_mapGenerationTimer.AutoReset = true; 844 {
820 m_mapGenerationTimer.Start(); 845 m_mapGenerationTimer.Interval = maptileRefresh * 1000;
846 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
847 m_mapGenerationTimer.AutoReset = true;
848 m_mapGenerationTimer.Start();
849 }
821 } 850 }
822 } 851 else
823 else
824 {
825 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
826 UUID tileID;
827
828 if (UUID.TryParse(tile, out tileID))
829 { 852 {
830 RegionInfo.RegionSettings.TerrainImageID = tileID; 853 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
854 UUID tileID;
855
856 if (UUID.TryParse(tile, out tileID))
857 {
858 RegionInfo.RegionSettings.TerrainImageID = tileID;
859 }
831 } 860 }
832 }
833 861
834 string grant = startupConfig.GetString("AllowedClients", String.Empty); 862 string grant = startupConfig.GetString("AllowedClients", String.Empty);
835 if (grant.Length > 0) 863 if (grant.Length > 0)
836 {
837 foreach (string viewer in grant.Split('|'))
838 { 864 {
839 m_AllowedViewers.Add(viewer.Trim().ToLower()); 865 foreach (string viewer in grant.Split(','))
866 {
867 m_AllowedViewers.Add(viewer.Trim().ToLower());
868 }
840 } 869 }
841 }
842 870
843 grant = startupConfig.GetString("BannedClients", String.Empty); 871 grant = startupConfig.GetString("BannedClients", String.Empty);
844 if (grant.Length > 0) 872 if (grant.Length > 0)
845 {
846 foreach (string viewer in grant.Split('|'))
847 { 873 {
848 m_BannedViewers.Add(viewer.Trim().ToLower()); 874 foreach (string viewer in grant.Split(','))
875 {
876 m_BannedViewers.Add(viewer.Trim().ToLower());
877 }
849 } 878 }
850 }
851 879
852 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime); 880 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime);
853 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup); 881 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup);
854 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations); 882 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations);
855 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement); 883 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement);
856 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events); 884 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events);
857 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects); 885 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
858 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics); 886 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
859 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences); 887 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
860 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain); 888 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
861 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning); 889 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
890 }
891 }
892 catch (Exception e)
893 {
894 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
862 } 895 }
863 896
864 // FIXME: Ultimately this should be in a module. 897 // FIXME: Ultimately this should be in a module.
@@ -903,6 +936,8 @@ namespace OpenSim.Region.Framework.Scenes
903 StatsReporter = new SimStatsReporter(this); 936 StatsReporter = new SimStatsReporter(this);
904 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 937 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
905 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 938 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
939
940 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
906 } 941 }
907 942
908 public Scene(RegionInfo regInfo) : base(regInfo) 943 public Scene(RegionInfo regInfo) : base(regInfo)
@@ -932,9 +967,6 @@ namespace OpenSim.Region.Framework.Scenes
932 WestBorders.Add(westBorder); 967 WestBorders.Add(westBorder);
933 BordersLocked = false; 968 BordersLocked = false;
934 969
935 // TODO: At some point this should be made configurable.
936 MaxUndoCount = 5;
937
938 m_eventManager = new EventManager(); 970 m_eventManager = new EventManager();
939 971
940 m_permissions = new ScenePermissions(this); 972 m_permissions = new ScenePermissions(this);
@@ -1308,7 +1340,22 @@ namespace OpenSim.Region.Framework.Scenes
1308 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1340 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1309 if (m_heartbeatThread != null) 1341 if (m_heartbeatThread != null)
1310 { 1342 {
1343 m_hbRestarts++;
1344 if(m_hbRestarts > 10)
1345 Environment.Exit(1);
1346 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1347
1348//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1349//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1350//proc.EnableRaisingEvents=false;
1351//proc.StartInfo.FileName = "/bin/kill";
1352//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1353//proc.Start();
1354//proc.WaitForExit();
1355//Thread.Sleep(1000);
1356//Environment.Exit(1);
1311 m_heartbeatThread.Abort(); 1357 m_heartbeatThread.Abort();
1358 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1312 m_heartbeatThread = null; 1359 m_heartbeatThread = null;
1313 } 1360 }
1314// m_lastUpdate = Util.EnvironmentTickCount(); 1361// m_lastUpdate = Util.EnvironmentTickCount();
@@ -1455,16 +1502,20 @@ namespace OpenSim.Region.Framework.Scenes
1455 endFrame = Frame + frames; 1502 endFrame = Frame + frames;
1456 1503
1457 float physicsFPS = 0f; 1504 float physicsFPS = 0f;
1458 int previousFrameTick, tmpMS; 1505 int tmpMS;
1459 int maintc = Util.EnvironmentTickCount(); 1506 int previousFrameTick;
1507 int maintc;
1508 int sleepMS;
1509 int framestart;
1460 1510
1461 while (!m_shuttingDown && (endFrame == null || Frame < endFrame)) 1511 while (!m_shuttingDown && (endFrame == null || Frame < endFrame))
1462 { 1512 {
1513 framestart = Util.EnvironmentTickCount();
1463 ++Frame; 1514 ++Frame;
1464 1515
1465// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1516// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1466 1517
1467 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1518 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1468 1519
1469 try 1520 try
1470 { 1521 {
@@ -1516,6 +1567,7 @@ namespace OpenSim.Region.Framework.Scenes
1516 m_sceneGraph.UpdatePresences(); 1567 m_sceneGraph.UpdatePresences();
1517 1568
1518 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1569 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1570
1519 1571
1520 // Delete temp-on-rez stuff 1572 // Delete temp-on-rez stuff
1521 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1573 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
@@ -1597,34 +1649,37 @@ namespace OpenSim.Region.Framework.Scenes
1597 1649
1598 Watchdog.UpdateThread(); 1650 Watchdog.UpdateThread();
1599 1651
1652 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1653
1654 StatsReporter.AddPhysicsFPS(physicsFPS);
1655 StatsReporter.AddTimeDilation(TimeDilation);
1656 StatsReporter.AddFPS(1);
1657
1658 StatsReporter.addAgentMS(agentMS);
1659 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1660 StatsReporter.addOtherMS(otherMS);
1661 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1662
1600 previousFrameTick = m_lastFrameTick; 1663 previousFrameTick = m_lastFrameTick;
1601 m_lastFrameTick = Util.EnvironmentTickCount(); 1664 m_lastFrameTick = Util.EnvironmentTickCount();
1602 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1665 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
1603 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1666 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1604 1667
1668 m_firstHeartbeat = false;
1669
1670 sleepMS = Util.EnvironmentTickCount();
1671
1605 if (tmpMS > 0) 1672 if (tmpMS > 0)
1606 {
1607 Thread.Sleep(tmpMS); 1673 Thread.Sleep(tmpMS);
1608 spareMS += tmpMS;
1609 }
1610
1611 frameMS = Util.EnvironmentTickCountSubtract(maintc);
1612 maintc = Util.EnvironmentTickCount();
1613 1674
1614 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; 1675 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1676 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1677 StatsReporter.addSleepMS(sleepMS);
1678 StatsReporter.addFrameMS(frameMS);
1615 1679
1616 // if (Frame%m_update_avatars == 0) 1680 // if (Frame%m_update_avatars == 0)
1617 // UpdateInWorldTime(); 1681 // UpdateInWorldTime();
1618 StatsReporter.AddPhysicsFPS(physicsFPS);
1619 StatsReporter.AddTimeDilation(TimeDilation);
1620 StatsReporter.AddFPS(1);
1621 1682
1622 StatsReporter.addFrameMS(frameMS);
1623 StatsReporter.addAgentMS(agentMS);
1624 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1625 StatsReporter.addOtherMS(otherMS);
1626 StatsReporter.AddSpareMS(spareMS);
1627 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1628 1683
1629 // Optionally warn if a frame takes double the amount of time that it should. 1684 // Optionally warn if a frame takes double the amount of time that it should.
1630 if (DebugUpdates 1685 if (DebugUpdates
@@ -1652,9 +1707,9 @@ namespace OpenSim.Region.Framework.Scenes
1652 1707
1653 private void CheckAtTargets() 1708 private void CheckAtTargets()
1654 { 1709 {
1655 Dictionary<UUID, SceneObjectGroup>.ValueCollection objs; 1710 List<SceneObjectGroup> objs = new List<SceneObjectGroup>();
1656 lock (m_groupsWithTargets) 1711 lock (m_groupsWithTargets)
1657 objs = m_groupsWithTargets.Values; 1712 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values);
1658 1713
1659 foreach (SceneObjectGroup entry in objs) 1714 foreach (SceneObjectGroup entry in objs)
1660 entry.checkAtTargets(); 1715 entry.checkAtTargets();
@@ -1735,7 +1790,7 @@ namespace OpenSim.Region.Framework.Scenes
1735 msg.fromAgentName = "Server"; 1790 msg.fromAgentName = "Server";
1736 msg.dialog = (byte)19; // Object msg 1791 msg.dialog = (byte)19; // Object msg
1737 msg.fromGroup = false; 1792 msg.fromGroup = false;
1738 msg.offline = (byte)0; 1793 msg.offline = (byte)1;
1739 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1794 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1740 msg.Position = Vector3.Zero; 1795 msg.Position = Vector3.Zero;
1741 msg.RegionID = RegionInfo.RegionID.Guid; 1796 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1957,6 +2012,19 @@ namespace OpenSim.Region.Framework.Scenes
1957 EventManager.TriggerPrimsLoaded(this); 2012 EventManager.TriggerPrimsLoaded(this);
1958 } 2013 }
1959 2014
2015 public bool SuportsRayCastFiltered()
2016 {
2017 if (PhysicsScene == null)
2018 return false;
2019 return PhysicsScene.SuportsRaycastWorldFiltered();
2020 }
2021
2022 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2023 {
2024 if (PhysicsScene == null)
2025 return null;
2026 return PhysicsScene.RaycastWorld(position, direction, length, Count,filter);
2027 }
1960 2028
1961 /// <summary> 2029 /// <summary>
1962 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed. 2030 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
@@ -1973,14 +2041,24 @@ namespace OpenSim.Region.Framework.Scenes
1973 /// <returns></returns> 2041 /// <returns></returns>
1974 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2042 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
1975 { 2043 {
2044
2045 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2046 Vector3 wpos = Vector3.Zero;
2047 // Check for water surface intersection from above
2048 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2049 {
2050 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2051 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2052 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2053 wpos.Z = wheight;
2054 }
2055
1976 Vector3 pos = Vector3.Zero; 2056 Vector3 pos = Vector3.Zero;
1977 if (RayEndIsIntersection == (byte)1) 2057 if (RayEndIsIntersection == (byte)1)
1978 { 2058 {
1979 pos = RayEnd; 2059 pos = RayEnd;
1980 return pos;
1981 } 2060 }
1982 2061 else if (RayTargetID != UUID.Zero)
1983 if (RayTargetID != UUID.Zero)
1984 { 2062 {
1985 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2063 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
1986 2064
@@ -2002,7 +2080,7 @@ namespace OpenSim.Region.Framework.Scenes
2002 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 2080 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
2003 2081
2004 // Un-comment out the following line to Get Raytrace results printed to the console. 2082 // Un-comment out the following line to Get Raytrace results printed to the console.
2005 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 2083 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
2006 float ScaleOffset = 0.5f; 2084 float ScaleOffset = 0.5f;
2007 2085
2008 // If we hit something 2086 // If we hit something
@@ -2025,13 +2103,10 @@ namespace OpenSim.Region.Framework.Scenes
2025 //pos.Z -= 0.25F; 2103 //pos.Z -= 0.25F;
2026 2104
2027 } 2105 }
2028
2029 return pos;
2030 } 2106 }
2031 else 2107 else
2032 { 2108 {
2033 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2109 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2034
2035 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2110 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2036 2111
2037 // Un-comment the following line to print the raytrace results to the console. 2112 // Un-comment the following line to print the raytrace results to the console.
@@ -2040,13 +2115,12 @@ namespace OpenSim.Region.Framework.Scenes
2040 if (ei.HitTF) 2115 if (ei.HitTF)
2041 { 2116 {
2042 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2117 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2043 } else 2118 }
2119 else
2044 { 2120 {
2045 // fall back to our stupid functionality 2121 // fall back to our stupid functionality
2046 pos = RayEnd; 2122 pos = RayEnd;
2047 } 2123 }
2048
2049 return pos;
2050 } 2124 }
2051 } 2125 }
2052 else 2126 else
@@ -2057,8 +2131,12 @@ namespace OpenSim.Region.Framework.Scenes
2057 //increase height so its above the ground. 2131 //increase height so its above the ground.
2058 //should be getting the normal of the ground at the rez point and using that? 2132 //should be getting the normal of the ground at the rez point and using that?
2059 pos.Z += scale.Z / 2f; 2133 pos.Z += scale.Z / 2f;
2060 return pos; 2134// return pos;
2061 } 2135 }
2136
2137 // check against posible water intercept
2138 if (wpos.Z > pos.Z) pos = wpos;
2139 return pos;
2062 } 2140 }
2063 2141
2064 2142
@@ -2147,7 +2225,10 @@ namespace OpenSim.Region.Framework.Scenes
2147 public bool AddRestoredSceneObject( 2225 public bool AddRestoredSceneObject(
2148 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 2226 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
2149 { 2227 {
2150 return m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates); 2228 bool result = m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates);
2229 if (result)
2230 sceneObject.IsDeleted = false;
2231 return result;
2151 } 2232 }
2152 2233
2153 /// <summary> 2234 /// <summary>
@@ -2239,6 +2320,15 @@ namespace OpenSim.Region.Framework.Scenes
2239 /// </summary> 2320 /// </summary>
2240 public void DeleteAllSceneObjects() 2321 public void DeleteAllSceneObjects()
2241 { 2322 {
2323 DeleteAllSceneObjects(false);
2324 }
2325
2326 /// <summary>
2327 /// Delete every object from the scene. This does not include attachments worn by avatars.
2328 /// </summary>
2329 public void DeleteAllSceneObjects(bool exceptNoCopy)
2330 {
2331 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2242 lock (Entities) 2332 lock (Entities)
2243 { 2333 {
2244 EntityBase[] entities = Entities.GetEntities(); 2334 EntityBase[] entities = Entities.GetEntities();
@@ -2247,11 +2337,24 @@ namespace OpenSim.Region.Framework.Scenes
2247 if (e is SceneObjectGroup) 2337 if (e is SceneObjectGroup)
2248 { 2338 {
2249 SceneObjectGroup sog = (SceneObjectGroup)e; 2339 SceneObjectGroup sog = (SceneObjectGroup)e;
2250 if (!sog.IsAttachment) 2340 if (sog != null && !sog.IsAttachment)
2251 DeleteSceneObject((SceneObjectGroup)e, false); 2341 {
2342 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2343 {
2344 DeleteSceneObject((SceneObjectGroup)e, false);
2345 }
2346 else
2347 {
2348 toReturn.Add((SceneObjectGroup)e);
2349 }
2350 }
2252 } 2351 }
2253 } 2352 }
2254 } 2353 }
2354 if (toReturn.Count > 0)
2355 {
2356 returnObjects(toReturn.ToArray(), UUID.Zero);
2357 }
2255 } 2358 }
2256 2359
2257 /// <summary> 2360 /// <summary>
@@ -2286,6 +2389,12 @@ namespace OpenSim.Region.Framework.Scenes
2286 2389
2287 foreach (SceneObjectPart part in partList) 2390 foreach (SceneObjectPart part in partList)
2288 { 2391 {
2392 if (part.KeyframeMotion != null)
2393 {
2394 part.KeyframeMotion.Delete();
2395 part.KeyframeMotion = null;
2396 }
2397
2289 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0)) 2398 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
2290 { 2399 {
2291 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? 2400 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
@@ -2303,6 +2412,8 @@ namespace OpenSim.Region.Framework.Scenes
2303 } 2412 }
2304 2413
2305 group.DeleteGroupFromScene(silent); 2414 group.DeleteGroupFromScene(silent);
2415 if (!silent)
2416 SendKillObject(new List<uint>() { group.LocalId });
2306 2417
2307// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2418// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2308 } 2419 }
@@ -2593,7 +2704,7 @@ namespace OpenSim.Region.Framework.Scenes
2593 // If the user is banned, we won't let any of their objects 2704 // If the user is banned, we won't let any of their objects
2594 // enter. Period. 2705 // enter. Period.
2595 // 2706 //
2596 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID)) 2707 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
2597 { 2708 {
2598 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID); 2709 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
2599 return false; 2710 return false;
@@ -2601,6 +2712,8 @@ namespace OpenSim.Region.Framework.Scenes
2601 2712
2602 if (newPosition != Vector3.Zero) 2713 if (newPosition != Vector3.Zero)
2603 newObject.RootPart.GroupPosition = newPosition; 2714 newObject.RootPart.GroupPosition = newPosition;
2715 if (newObject.RootPart.KeyframeMotion != null)
2716 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2604 2717
2605 if (!AddSceneObject(newObject)) 2718 if (!AddSceneObject(newObject))
2606 { 2719 {
@@ -2645,6 +2758,23 @@ namespace OpenSim.Region.Framework.Scenes
2645 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2758 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2646 public bool AddSceneObject(SceneObjectGroup sceneObject) 2759 public bool AddSceneObject(SceneObjectGroup sceneObject)
2647 { 2760 {
2761 if (sceneObject.OwnerID == UUID.Zero)
2762 {
2763 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2764 return false;
2765 }
2766
2767 // If the user is banned, we won't let any of their objects
2768 // enter. Period.
2769 //
2770 int flags = GetUserFlags(sceneObject.OwnerID);
2771 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2772 {
2773 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2774
2775 return false;
2776 }
2777
2648 // Force allocation of new LocalId 2778 // Force allocation of new LocalId
2649 // 2779 //
2650 SceneObjectPart[] parts = sceneObject.Parts; 2780 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2678,16 +2808,27 @@ namespace OpenSim.Region.Framework.Scenes
2678 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2808 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2679 2809
2680 if (AttachmentsModule != null) 2810 if (AttachmentsModule != null)
2681 AttachmentsModule.AttachObject(sp, grp, 0, false, false); 2811 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false);
2682 } 2812 }
2683 else 2813 else
2684 { 2814 {
2815 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2685 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2816 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2686 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2817 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2687 } 2818 }
2819 if (sceneObject.OwnerID == UUID.Zero)
2820 {
2821 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2822 return false;
2823 }
2688 } 2824 }
2689 else 2825 else
2690 { 2826 {
2827 if (sceneObject.OwnerID == UUID.Zero)
2828 {
2829 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2830 return false;
2831 }
2691 AddRestoredSceneObject(sceneObject, true, false); 2832 AddRestoredSceneObject(sceneObject, true, false);
2692 } 2833 }
2693 2834
@@ -2704,6 +2845,24 @@ namespace OpenSim.Region.Framework.Scenes
2704 return 2; // StateSource.PrimCrossing 2845 return 2; // StateSource.PrimCrossing
2705 } 2846 }
2706 2847
2848 public int GetUserFlags(UUID user)
2849 {
2850 //Unfortunately the SP approach means that the value is cached until region is restarted
2851 /*
2852 ScenePresence sp;
2853 if (TryGetScenePresence(user, out sp))
2854 {
2855 return sp.UserFlags;
2856 }
2857 else
2858 {
2859 */
2860 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2861 if (uac == null)
2862 return 0;
2863 return uac.UserFlags;
2864 //}
2865 }
2707 #endregion 2866 #endregion
2708 2867
2709 #region Add/Remove Avatar Methods 2868 #region Add/Remove Avatar Methods
@@ -2717,7 +2876,7 @@ namespace OpenSim.Region.Framework.Scenes
2717 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2876 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2718 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2877 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2719 2878
2720// CheckHeartbeat(); 2879 CheckHeartbeat();
2721 2880
2722 ScenePresence sp = GetScenePresence(client.AgentId); 2881 ScenePresence sp = GetScenePresence(client.AgentId);
2723 2882
@@ -2771,7 +2930,15 @@ namespace OpenSim.Region.Framework.Scenes
2771 2930
2772 EventManager.TriggerOnNewClient(client); 2931 EventManager.TriggerOnNewClient(client);
2773 if (vialogin) 2932 if (vialogin)
2933 {
2774 EventManager.TriggerOnClientLogin(client); 2934 EventManager.TriggerOnClientLogin(client);
2935 // Send initial parcel data
2936/* this is done on TriggerOnNewClient by landmanegement respective event handler
2937 Vector3 pos = sp.AbsolutePosition;
2938 ILandObject land = LandChannel.GetLandObject(pos.X, pos.Y);
2939 land.SendLandUpdateToClient(client);
2940*/
2941 }
2775 2942
2776 return sp; 2943 return sp;
2777 } 2944 }
@@ -2860,19 +3027,14 @@ namespace OpenSim.Region.Framework.Scenes
2860 // and the scene presence and the client, if they exist 3027 // and the scene presence and the client, if they exist
2861 try 3028 try
2862 { 3029 {
2863 // We need to wait for the client to make UDP contact first. 3030 ScenePresence sp = GetScenePresence(agentID);
2864 // It's the UDP contact that creates the scene presence 3031
2865 ScenePresence sp = WaitGetScenePresence(agentID);
2866 if (sp != null) 3032 if (sp != null)
2867 { 3033 {
2868 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3034 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2869
2870 sp.ControllingClient.Close(); 3035 sp.ControllingClient.Close();
2871 } 3036 }
2872 else 3037
2873 {
2874 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2875 }
2876 // BANG! SLASH! 3038 // BANG! SLASH!
2877 m_authenticateHandler.RemoveCircuit(agentID); 3039 m_authenticateHandler.RemoveCircuit(agentID);
2878 3040
@@ -2917,6 +3079,8 @@ namespace OpenSim.Region.Framework.Scenes
2917 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3079 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2918 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3080 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2919 3081
3082 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3083
2920 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3084 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2921 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3085 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2922 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3086 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -2973,6 +3137,7 @@ namespace OpenSim.Region.Framework.Scenes
2973 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3137 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
2974 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3138 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
2975 client.OnCopyInventoryItem += CopyInventoryItem; 3139 client.OnCopyInventoryItem += CopyInventoryItem;
3140 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
2976 client.OnMoveInventoryItem += MoveInventoryItem; 3141 client.OnMoveInventoryItem += MoveInventoryItem;
2977 client.OnRemoveInventoryItem += RemoveInventoryItem; 3142 client.OnRemoveInventoryItem += RemoveInventoryItem;
2978 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3143 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3044,6 +3209,8 @@ namespace OpenSim.Region.Framework.Scenes
3044 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3209 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3045 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3210 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3046 3211
3212 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3213
3047 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3214 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3048 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3215 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3049 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3216 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3146,7 +3313,7 @@ namespace OpenSim.Region.Framework.Scenes
3146 /// </summary> 3313 /// </summary>
3147 /// <param name="agentId">The avatar's Unique ID</param> 3314 /// <param name="agentId">The avatar's Unique ID</param>
3148 /// <param name="client">The IClientAPI for the client</param> 3315 /// <param name="client">The IClientAPI for the client</param>
3149 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3316 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3150 { 3317 {
3151 if (EntityTransferModule != null) 3318 if (EntityTransferModule != null)
3152 { 3319 {
@@ -3157,6 +3324,7 @@ namespace OpenSim.Region.Framework.Scenes
3157 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3324 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3158 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3325 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3159 } 3326 }
3327 return false;
3160 } 3328 }
3161 3329
3162 /// <summary> 3330 /// <summary>
@@ -3266,6 +3434,16 @@ namespace OpenSim.Region.Framework.Scenes
3266 /// <param name="flags"></param> 3434 /// <param name="flags"></param>
3267 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3435 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3268 { 3436 {
3437 //Add half the avatar's height so that the user doesn't fall through prims
3438 ScenePresence presence;
3439 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3440 {
3441 if (presence.Appearance != null)
3442 {
3443 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3444 }
3445 }
3446
3269 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3447 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3270 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3448 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3271 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3449 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3382,6 +3560,7 @@ namespace OpenSim.Region.Framework.Scenes
3382 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 3560 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3383 3561
3384 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3562 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3563 m_log.Debug("[Scene] The avatar has left the building");
3385 } 3564 }
3386 catch (Exception e) 3565 catch (Exception e)
3387 { 3566 {
@@ -3579,17 +3758,20 @@ namespace OpenSim.Region.Framework.Scenes
3579 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.", 3758 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3580 sp.Name, sp.UUID, RegionInfo.RegionName); 3759 sp.Name, sp.UUID, RegionInfo.RegionName);
3581 3760
3582 sp.ControllingClient.Close(true); 3761 sp.ControllingClient.Close(true, true);
3583 sp = null; 3762 sp = null;
3584 } 3763 }
3585 3764
3586 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3587 3765
3588 //On login test land permisions 3766 //On login test land permisions
3589 if (vialogin) 3767 if (vialogin)
3590 { 3768 {
3591 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3769 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3770 if (cache != null)
3771 cache.Remove(agent.firstname + " " + agent.lastname);
3772 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3592 { 3773 {
3774 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3593 return false; 3775 return false;
3594 } 3776 }
3595 } 3777 }
@@ -3612,9 +3794,15 @@ namespace OpenSim.Region.Framework.Scenes
3612 3794
3613 try 3795 try
3614 { 3796 {
3615 if (!AuthorizeUser(agent, out reason)) 3797 // Always check estate if this is a login. Always
3616 return false; 3798 // check if banned regions are to be blacked out.
3617 } catch (Exception e) 3799 if (vialogin || (!m_seeIntoBannedRegion))
3800 {
3801 if (!AuthorizeUser(agent, out reason))
3802 return false;
3803 }
3804 }
3805 catch (Exception e)
3618 { 3806 {
3619 m_log.ErrorFormat( 3807 m_log.ErrorFormat(
3620 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3808 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
@@ -3745,6 +3933,8 @@ namespace OpenSim.Region.Framework.Scenes
3745 } 3933 }
3746 3934
3747 // Honor parcel landing type and position. 3935 // Honor parcel landing type and position.
3936 /*
3937 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3748 if (land != null) 3938 if (land != null)
3749 { 3939 {
3750 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3940 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3752,25 +3942,43 @@ namespace OpenSim.Region.Framework.Scenes
3752 agent.startpos = land.LandData.UserLocation; 3942 agent.startpos = land.LandData.UserLocation;
3753 } 3943 }
3754 } 3944 }
3945 */// This is now handled properly in ScenePresence.MakeRootAgent
3755 } 3946 }
3756 3947
3757 return true; 3948 return true;
3758 } 3949 }
3759 3950
3760 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 3951 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3761 { 3952 {
3762 bool banned = land.IsBannedFromLand(agent.AgentID); 3953 if (posX < 0)
3763 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 3954 posX = 0;
3955 else if (posX >= 256)
3956 posX = 255.999f;
3957 if (posY < 0)
3958 posY = 0;
3959 else if (posY >= 256)
3960 posY = 255.999f;
3961
3962 reason = String.Empty;
3963 if (Permissions.IsGod(agentID))
3964 return true;
3965
3966 ILandObject land = LandChannel.GetLandObject(posX, posY);
3967 if (land == null)
3968 return false;
3969
3970 bool banned = land.IsBannedFromLand(agentID);
3971 bool restricted = land.IsRestrictedFromLand(agentID);
3764 3972
3765 if (banned || restricted) 3973 if (banned || restricted)
3766 { 3974 {
3767 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 3975 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3768 if (nearestParcel != null) 3976 if (nearestParcel != null)
3769 { 3977 {
3770 //Move agent to nearest allowed 3978 //Move agent to nearest allowed
3771 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 3979 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3772 agent.startpos.X = newPosition.X; 3980 posX = newPosition.X;
3773 agent.startpos.Y = newPosition.Y; 3981 posY = newPosition.Y;
3774 } 3982 }
3775 else 3983 else
3776 { 3984 {
@@ -3832,7 +4040,7 @@ namespace OpenSim.Region.Framework.Scenes
3832 4040
3833 if (!m_strictAccessControl) return true; 4041 if (!m_strictAccessControl) return true;
3834 if (Permissions.IsGod(agent.AgentID)) return true; 4042 if (Permissions.IsGod(agent.AgentID)) return true;
3835 4043
3836 if (AuthorizationService != null) 4044 if (AuthorizationService != null)
3837 { 4045 {
3838 if (!AuthorizationService.IsAuthorizedForRegion( 4046 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3847,7 +4055,7 @@ namespace OpenSim.Region.Framework.Scenes
3847 4055
3848 if (RegionInfo.EstateSettings != null) 4056 if (RegionInfo.EstateSettings != null)
3849 { 4057 {
3850 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4058 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, 0))
3851 { 4059 {
3852 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4060 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3853 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4061 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4037,6 +4245,15 @@ namespace OpenSim.Region.Framework.Scenes
4037 4245
4038 // XPTO: if this agent is not allowed here as root, always return false 4246 // XPTO: if this agent is not allowed here as root, always return false
4039 4247
4248 // We have to wait until the viewer contacts this region after receiving EAC.
4249 // That calls AddNewClient, which finally creates the ScenePresence
4250 int flags = GetUserFlags(cAgentData.AgentID);
4251 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4252 {
4253 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4254 return false;
4255 }
4256
4040 // TODO: This check should probably be in QueryAccess(). 4257 // TODO: This check should probably be in QueryAccess().
4041 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4258 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4042 if (nearestParcel == null) 4259 if (nearestParcel == null)
@@ -4100,7 +4317,7 @@ namespace OpenSim.Region.Framework.Scenes
4100 /// <param name='agentID'></param> 4317 /// <param name='agentID'></param>
4101 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4318 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4102 { 4319 {
4103 int ntimes = 10; 4320 int ntimes = 30;
4104 ScenePresence sp = null; 4321 ScenePresence sp = null;
4105 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4322 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4106 Thread.Sleep(1000); 4323 Thread.Sleep(1000);
@@ -4130,6 +4347,16 @@ namespace OpenSim.Region.Framework.Scenes
4130 return false; 4347 return false;
4131 } 4348 }
4132 4349
4350 public bool IncomingCloseAgent(UUID agentID)
4351 {
4352 return IncomingCloseAgent(agentID, false);
4353 }
4354
4355 public bool IncomingCloseChildAgent(UUID agentID)
4356 {
4357 return IncomingCloseAgent(agentID, true);
4358 }
4359
4133 /// <summary> 4360 /// <summary>
4134 /// Tell a single agent to disconnect from the region. 4361 /// Tell a single agent to disconnect from the region.
4135 /// </summary> 4362 /// </summary>
@@ -4145,7 +4372,7 @@ namespace OpenSim.Region.Framework.Scenes
4145 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4372 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4146 if (presence != null) 4373 if (presence != null)
4147 { 4374 {
4148 presence.ControllingClient.Close(force); 4375 presence.ControllingClient.Close(true, force);
4149 return true; 4376 return true;
4150 } 4377 }
4151 4378
@@ -4793,35 +5020,81 @@ namespace OpenSim.Region.Framework.Scenes
4793 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5020 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
4794 } 5021 }
4795 5022
4796 public int GetHealth() 5023 public int GetHealth(out int flags, out string message)
4797 { 5024 {
4798 // Returns: 5025 // Returns:
4799 // 1 = sim is up and accepting http requests. The heartbeat has 5026 // 1 = sim is up and accepting http requests. The heartbeat has
4800 // stopped and the sim is probably locked up, but a remote 5027 // stopped and the sim is probably locked up, but a remote
4801 // admin restart may succeed 5028 // admin restart may succeed
4802 // 5029 //
4803 // 2 = Sim is up and the heartbeat is running. The sim is likely 5030 // 2 = Sim is up and the heartbeat is running. The sim is likely
4804 // usable for people within and logins _may_ work 5031 // usable for people within
5032 //
5033 // 3 = Sim is up and one packet thread is running. Sim is
5034 // unstable and will not accept new logins
4805 // 5035 //
4806 // 3 = We have seen a new user enter within the past 4 minutes 5036 // 4 = Sim is up and both packet threads are running. Sim is
5037 // likely usable
5038 //
5039 // 5 = We have seen a new user enter within the past 4 minutes
4807 // which can be seen as positive confirmation of sim health 5040 // which can be seen as positive confirmation of sim health
4808 // 5041 //
5042
5043 flags = 0;
5044 message = String.Empty;
5045
5046 CheckHeartbeat();
5047
5048 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5049 {
5050 // We're still starting
5051 // 0 means "in startup", it can't happen another way, since
5052 // to get here, we must be able to accept http connections
5053 return 0;
5054 }
5055
4809 int health=1; // Start at 1, means we're up 5056 int health=1; // Start at 1, means we're up
4810 5057
4811 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5058 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4812 health += 1; 5059 {
5060 health+=1;
5061 flags |= 1;
5062 }
5063
5064 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5065 {
5066 health+=1;
5067 flags |= 2;
5068 }
5069
5070 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5071 {
5072 health+=1;
5073 flags |= 4;
5074 }
4813 else 5075 else
5076 {
5077int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5078System.Diagnostics.Process proc = new System.Diagnostics.Process();
5079proc.EnableRaisingEvents=false;
5080proc.StartInfo.FileName = "/bin/kill";
5081proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5082proc.Start();
5083proc.WaitForExit();
5084Thread.Sleep(1000);
5085Environment.Exit(1);
5086 }
5087
5088 if (flags != 7)
4814 return health; 5089 return health;
4815 5090
4816 // A login in the last 4 mins? We can't be doing too badly 5091 // A login in the last 4 mins? We can't be doing too badly
4817 // 5092 //
4818 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5093 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4819 health++; 5094 health++;
4820 else 5095 else
4821 return health; 5096 return health;
4822 5097
4823// CheckHeartbeat();
4824
4825 return health; 5098 return health;
4826 } 5099 }
4827 5100
@@ -4909,7 +5182,7 @@ namespace OpenSim.Region.Framework.Scenes
4909 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 5182 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
4910 if (wasUsingPhysics) 5183 if (wasUsingPhysics)
4911 { 5184 {
4912 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 5185 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
4913 } 5186 }
4914 } 5187 }
4915 5188
@@ -5008,14 +5281,14 @@ namespace OpenSim.Region.Framework.Scenes
5008 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5281 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5009 } 5282 }
5010 5283
5011// private void CheckHeartbeat() 5284 private void CheckHeartbeat()
5012// { 5285 {
5013// if (m_firstHeartbeat) 5286 if (m_firstHeartbeat)
5014// return; 5287 return;
5015// 5288
5016// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5289 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5017// StartTimer(); 5290 Start();
5018// } 5291 }
5019 5292
5020 public override ISceneObject DeserializeObject(string representation) 5293 public override ISceneObject DeserializeObject(string representation)
5021 { 5294 {
@@ -5027,9 +5300,14 @@ namespace OpenSim.Region.Framework.Scenes
5027 get { return m_allowScriptCrossings; } 5300 get { return m_allowScriptCrossings; }
5028 } 5301 }
5029 5302
5030 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5303 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5031 { 5304 {
5032 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5305 return GetNearestAllowedPosition(avatar, null);
5306 }
5307
5308 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5309 {
5310 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
5033 5311
5034 if (nearestParcel != null) 5312 if (nearestParcel != null)
5035 { 5313 {
@@ -5038,10 +5316,7 @@ namespace OpenSim.Region.Framework.Scenes
5038 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5316 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5039 if (nearestPoint != null) 5317 if (nearestPoint != null)
5040 { 5318 {
5041// m_log.DebugFormat( 5319 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
5042// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
5043// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
5044
5045 return nearestPoint.Value; 5320 return nearestPoint.Value;
5046 } 5321 }
5047 5322
@@ -5051,17 +5326,20 @@ namespace OpenSim.Region.Framework.Scenes
5051 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5326 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5052 if (nearestPoint != null) 5327 if (nearestPoint != null)
5053 { 5328 {
5054// m_log.DebugFormat( 5329 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
5055// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
5056
5057 return nearestPoint.Value; 5330 return nearestPoint.Value;
5058 } 5331 }
5059 5332
5060 //Ultimate backup if we have no idea where they are 5333 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
5061// m_log.DebugFormat( 5334 if (dest != excludeParcel)
5062// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5335 {
5336 // Ultimate backup if we have no idea where they are and
5337 // the last allowed position was in another parcel
5338 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5339 return avatar.lastKnownAllowedPosition;
5340 }
5063 5341
5064 return avatar.lastKnownAllowedPosition; 5342 // else fall through to region edge
5065 } 5343 }
5066 5344
5067 //Go to the edge, this happens in teleporting to a region with no available parcels 5345 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -5095,13 +5373,18 @@ namespace OpenSim.Region.Framework.Scenes
5095 5373
5096 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5374 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5097 { 5375 {
5376 return GetNearestAllowedParcel(avatarId, x, y, null);
5377 }
5378
5379 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5380 {
5098 List<ILandObject> all = AllParcels(); 5381 List<ILandObject> all = AllParcels();
5099 float minParcelDistance = float.MaxValue; 5382 float minParcelDistance = float.MaxValue;
5100 ILandObject nearestParcel = null; 5383 ILandObject nearestParcel = null;
5101 5384
5102 foreach (var parcel in all) 5385 foreach (var parcel in all)
5103 { 5386 {
5104 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5387 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
5105 { 5388 {
5106 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5389 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5107 if (parcelDistance < minParcelDistance) 5390 if (parcelDistance < minParcelDistance)
@@ -5343,7 +5626,55 @@ namespace OpenSim.Region.Framework.Scenes
5343 mapModule.GenerateMaptile(); 5626 mapModule.GenerateMaptile();
5344 } 5627 }
5345 5628
5346 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5629// public void CleanDroppedAttachments()
5630// {
5631// List<SceneObjectGroup> objectsToDelete =
5632// new List<SceneObjectGroup>();
5633//
5634// lock (m_cleaningAttachments)
5635// {
5636// ForEachSOG(delegate (SceneObjectGroup grp)
5637// {
5638// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5639// {
5640// UUID agentID = grp.OwnerID;
5641// if (agentID == UUID.Zero)
5642// {
5643// objectsToDelete.Add(grp);
5644// return;
5645// }
5646//
5647// ScenePresence sp = GetScenePresence(agentID);
5648// if (sp == null)
5649// {
5650// objectsToDelete.Add(grp);
5651// return;
5652// }
5653// }
5654// });
5655// }
5656//
5657// foreach (SceneObjectGroup grp in objectsToDelete)
5658// {
5659// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5660// DeleteSceneObject(grp, true);
5661// }
5662// }
5663
5664 public void ThreadAlive(int threadCode)
5665 {
5666 switch(threadCode)
5667 {
5668 case 1: // Incoming
5669 m_lastIncoming = Util.EnvironmentTickCount();
5670 break;
5671 case 2: // Incoming
5672 m_lastOutgoing = Util.EnvironmentTickCount();
5673 break;
5674 }
5675 }
5676
5677 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5347 { 5678 {
5348 RegenerateMaptile(); 5679 RegenerateMaptile();
5349 5680
@@ -5371,6 +5702,8 @@ namespace OpenSim.Region.Framework.Scenes
5371 /// <returns></returns> 5702 /// <returns></returns>
5372 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5703 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5373 { 5704 {
5705 reason = "You are banned from the region";
5706
5374 if (EntityTransferModule.IsInTransit(agentID)) 5707 if (EntityTransferModule.IsInTransit(agentID))
5375 { 5708 {
5376 reason = "Agent is still in transit from this region"; 5709 reason = "Agent is still in transit from this region";
@@ -5382,6 +5715,12 @@ namespace OpenSim.Region.Framework.Scenes
5382 return false; 5715 return false;
5383 } 5716 }
5384 5717
5718 if (Permissions.IsGod(agentID))
5719 {
5720 reason = String.Empty;
5721 return true;
5722 }
5723
5385 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5724 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5386 // However, the long term fix is to make sure root agent count is always accurate. 5725 // However, the long term fix is to make sure root agent count is always accurate.
5387 m_sceneGraph.RecalculateStats(); 5726 m_sceneGraph.RecalculateStats();
@@ -5402,6 +5741,41 @@ namespace OpenSim.Region.Framework.Scenes
5402 } 5741 }
5403 } 5742 }
5404 5743
5744 ScenePresence presence = GetScenePresence(agentID);
5745 IClientAPI client = null;
5746 AgentCircuitData aCircuit = null;
5747
5748 if (presence != null)
5749 {
5750 client = presence.ControllingClient;
5751 if (client != null)
5752 aCircuit = client.RequestClientInfo();
5753 }
5754
5755 // We may be called before there is a presence or a client.
5756 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5757 if (client == null)
5758 {
5759 aCircuit = new AgentCircuitData();
5760 aCircuit.AgentID = agentID;
5761 aCircuit.firstname = String.Empty;
5762 aCircuit.lastname = String.Empty;
5763 }
5764
5765 try
5766 {
5767 if (!AuthorizeUser(aCircuit, out reason))
5768 {
5769 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5770 return false;
5771 }
5772 }
5773 catch (Exception e)
5774 {
5775 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5776 return false;
5777 }
5778
5405 if (position == Vector3.Zero) // Teleport 5779 if (position == Vector3.Zero) // Teleport
5406 { 5780 {
5407 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5781 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5430,13 +5804,46 @@ namespace OpenSim.Region.Framework.Scenes
5430 } 5804 }
5431 } 5805 }
5432 } 5806 }
5807
5808 float posX = 128.0f;
5809 float posY = 128.0f;
5810
5811 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5812 {
5813 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5814 return false;
5815 }
5816 }
5817 else // Walking
5818 {
5819 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5820 if (land == null)
5821 return false;
5822
5823 bool banned = land.IsBannedFromLand(agentID);
5824 bool restricted = land.IsRestrictedFromLand(agentID);
5825
5826 if (banned || restricted)
5827 return false;
5433 } 5828 }
5434 5829
5435 reason = String.Empty; 5830 reason = String.Empty;
5436 return true; 5831 return true;
5437 } 5832 }
5438 5833
5439 /// <summary> 5834 public void StartTimerWatchdog()
5835 {
5836 m_timerWatchdog.Interval = 1000;
5837 m_timerWatchdog.Elapsed += TimerWatchdog;
5838 m_timerWatchdog.AutoReset = true;
5839 m_timerWatchdog.Start();
5840 }
5841
5842 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5843 {
5844 CheckHeartbeat();
5845 }
5846
5440 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5847 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5441 /// autopilot that moves an avatar to a sit target!. 5848 /// autopilot that moves an avatar to a sit target!.
5442 /// </summary> 5849 /// </summary>
@@ -5515,6 +5922,11 @@ namespace OpenSim.Region.Framework.Scenes
5515 return m_SpawnPoint - 1; 5922 return m_SpawnPoint - 1;
5516 } 5923 }
5517 5924
5925 private void HandleGcCollect(string module, string[] args)
5926 {
5927 GC.Collect();
5928 }
5929
5518 // Wrappers to get physics modules retrieve assets. Has to be done this way 5930 // Wrappers to get physics modules retrieve assets. Has to be done this way
5519 // because we can't assign the asset service to physics directly - at the 5931 // because we can't assign the asset service to physics directly - at the
5520 // time physics are instantiated it's not registered but it will be by 5932 // time physics are instantiated it's not registered but it will be by