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 5778176..6ca7ef2 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -226,8 +226,8 @@ namespace OpenSim.Region.Framework.Scenes
226 // TODO: need to figure out how allow client agents but deny 226 // TODO: need to figure out how allow client agents but deny
227 // root agents when ACL denies access to root agent 227 // root agents when ACL denies access to root agent
228 public bool m_strictAccessControl = true; 228 public bool m_strictAccessControl = true;
229 229 public bool m_seeIntoBannedRegion = false;
230 public int MaxUndoCount { get; set; } 230 public int MaxUndoCount = 5;
231 231
232 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet; 232 // Using this for RegionReady module to prevent LoginsDisabled from changing under our feet;
233 public bool LoginLock = false; 233 public bool LoginLock = false;
@@ -243,11 +243,13 @@ namespace OpenSim.Region.Framework.Scenes
243 243
244 protected int m_splitRegionID; 244 protected int m_splitRegionID;
245 protected Timer m_restartWaitTimer = new Timer(); 245 protected Timer m_restartWaitTimer = new Timer();
246 protected Timer m_timerWatchdog = new Timer();
246 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 247 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
247 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 248 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
248 protected string m_simulatorVersion = "OpenSimulator Server"; 249 protected string m_simulatorVersion = "OpenSimulator Server";
249 protected AgentCircuitManager m_authenticateHandler; 250 protected AgentCircuitManager m_authenticateHandler;
250 protected SceneCommunicationService m_sceneGridService; 251 protected SceneCommunicationService m_sceneGridService;
252 protected ISnmpModule m_snmpService = null;
251 253
252 protected ISimulationDataService m_SimulationDataService; 254 protected ISimulationDataService m_SimulationDataService;
253 protected IEstateDataService m_EstateDataService; 255 protected IEstateDataService m_EstateDataService;
@@ -310,8 +312,8 @@ namespace OpenSim.Region.Framework.Scenes
310 private int m_update_presences = 1; // Update scene presence movements 312 private int m_update_presences = 1; // Update scene presence movements
311 private int m_update_events = 1; 313 private int m_update_events = 1;
312 private int m_update_backup = 200; 314 private int m_update_backup = 200;
313 private int m_update_terrain = 50; 315 private int m_update_terrain = 1000;
314// private int m_update_land = 1; 316 private int m_update_land = 10;
315 private int m_update_coarse_locations = 50; 317 private int m_update_coarse_locations = 50;
316 318
317 private int agentMS; 319 private int agentMS;
@@ -324,13 +326,13 @@ namespace OpenSim.Region.Framework.Scenes
324 private int backupMS; 326 private int backupMS;
325 private int terrainMS; 327 private int terrainMS;
326 private int landMS; 328 private int landMS;
327 private int spareMS;
328 329
329 /// <summary> 330 /// <summary>
330 /// Tick at which the last frame was processed. 331 /// Tick at which the last frame was processed.
331 /// </summary> 332 /// </summary>
332 private int m_lastFrameTick; 333 private int m_lastFrameTick;
333 334
335 public bool CombineRegions = false;
334 /// <summary> 336 /// <summary>
335 /// Tick at which the last maintenance run occurred. 337 /// Tick at which the last maintenance run occurred.
336 /// </summary> 338 /// </summary>
@@ -359,6 +361,11 @@ namespace OpenSim.Region.Framework.Scenes
359 /// </summary> 361 /// </summary>
360 private int m_LastLogin; 362 private int m_LastLogin;
361 363
364 private int m_lastIncoming;
365 private int m_lastOutgoing;
366 private int m_hbRestarts = 0;
367
368
362 /// <summary> 369 /// <summary>
363 /// Thread that runs the scene loop. 370 /// Thread that runs the scene loop.
364 /// </summary> 371 /// </summary>
@@ -399,7 +406,7 @@ namespace OpenSim.Region.Framework.Scenes
399 private volatile bool m_active; 406 private volatile bool m_active;
400 407
401// private int m_lastUpdate; 408// private int m_lastUpdate;
402// private bool m_firstHeartbeat = true; 409 private bool m_firstHeartbeat = true;
403 410
404 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time; 411 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
405 private bool m_reprioritizationEnabled = true; 412 private bool m_reprioritizationEnabled = true;
@@ -443,6 +450,19 @@ namespace OpenSim.Region.Framework.Scenes
443 get { return m_sceneGridService; } 450 get { return m_sceneGridService; }
444 } 451 }
445 452
453 public ISnmpModule SnmpService
454 {
455 get
456 {
457 if (m_snmpService == null)
458 {
459 m_snmpService = RequestModuleInterface<ISnmpModule>();
460 }
461
462 return m_snmpService;
463 }
464 }
465
446 public ISimulationDataService SimulationDataService 466 public ISimulationDataService SimulationDataService
447 { 467 {
448 get 468 get
@@ -736,6 +756,8 @@ namespace OpenSim.Region.Framework.Scenes
736 m_SimulationDataService = simDataService; 756 m_SimulationDataService = simDataService;
737 m_EstateDataService = estateDataService; 757 m_EstateDataService = estateDataService;
738 m_regionHandle = RegionInfo.RegionHandle; 758 m_regionHandle = RegionInfo.RegionHandle;
759 m_lastIncoming = 0;
760 m_lastOutgoing = 0;
739 761
740 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 762 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
741 m_asyncSceneObjectDeleter.Enabled = true; 763 m_asyncSceneObjectDeleter.Enabled = true;
@@ -825,132 +847,141 @@ namespace OpenSim.Region.Framework.Scenes
825 847
826 // Region config overrides global config 848 // Region config overrides global config
827 // 849 //
828 if (m_config.Configs["Startup"] != null) 850 try
829 { 851 {
830 IConfig startupConfig = m_config.Configs["Startup"]; 852 if (m_config.Configs["Startup"] != null)
831
832 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
833
834 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance);
835 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup);
836 if (!UseBackup)
837 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
838
839 //Animation states
840 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
841
842 MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20);
843
844 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims);
845 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims);
846
847 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
848 if (RegionInfo.NonphysPrimMin > 0)
849 { 853 {
850 m_minNonphys = RegionInfo.NonphysPrimMin; 854 IConfig startupConfig = m_config.Configs["Startup"];
851 }
852 855
853 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 856 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
854 if (RegionInfo.NonphysPrimMax > 0)
855 {
856 m_maxNonphys = RegionInfo.NonphysPrimMax;
857 }
858 857
859 m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys); 858 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
860 if (RegionInfo.PhysPrimMin > 0) 859 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup);
861 { 860 if (!UseBackup)
862 m_minPhys = RegionInfo.PhysPrimMin; 861 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
863 } 862
863 //Animation states
864 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
864 865
865 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 866 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
866 if (RegionInfo.PhysPrimMax > 0) 867 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
867 {
868 m_maxPhys = RegionInfo.PhysPrimMax;
869 }
870 868
871 // Here, if clamping is requested in either global or 869 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
872 // local config, it will be used 870 if (RegionInfo.NonphysPrimMin > 0)
873 // 871 {
874 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize); 872 m_minNonphys = RegionInfo.NonphysPrimMin;
875 if (RegionInfo.ClampPrimSize) 873 }
876 {
877 m_clampPrimSize = true;
878 }
879 874
880 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); 875 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
881 if (RegionInfo.LinksetCapacity > 0) 876 if (RegionInfo.NonphysPrimMax > 0)
882 { 877 {
883 m_linksetCapacity = RegionInfo.LinksetCapacity; 878 m_maxNonphys = RegionInfo.NonphysPrimMax;
884 } 879 }
885 880
886 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete); 881 m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys);
887 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 882 if (RegionInfo.PhysPrimMin > 0)
888 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 883 {
889 m_dontPersistBefore = 884 m_minPhys = RegionInfo.PhysPrimMin;
890 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE); 885 }
891 m_dontPersistBefore *= 10000000;
892 m_persistAfter =
893 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
894 m_persistAfter *= 10000000;
895 886
896 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 887 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
897 888
898 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest"); 889 if (RegionInfo.PhysPrimMax > 0)
899 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false); 890 {
891 m_maxPhys = RegionInfo.PhysPrimMax;
892 }
900 893
901 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 894 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity);
895 if (RegionInfo.LinksetCapacity > 0)
896 {
897 m_linksetCapacity = RegionInfo.LinksetCapacity;
898 }
902 899
903 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 900 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
904 if (m_generateMaptiles) 901 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
905 { 902
906 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0); 903 // Here, if clamping is requested in either global or
907 if (maptileRefresh != 0) 904 // local config, it will be used
905 //
906 m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize);
907 if (RegionInfo.ClampPrimSize)
908 { 908 {
909 m_mapGenerationTimer.Interval = maptileRefresh * 1000; 909 m_clampPrimSize = true;
910 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
911 m_mapGenerationTimer.AutoReset = true;
912 m_mapGenerationTimer.Start();
913 } 910 }
914 }
915 else
916 {
917 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
918 UUID tileID;
919 911
920 if (UUID.TryParse(tile, out tileID)) 912 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
913 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
914 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
915 m_dontPersistBefore =
916 startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE);
917 m_dontPersistBefore *= 10000000;
918 m_persistAfter =
919 startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE);
920 m_persistAfter *= 10000000;
921
922 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
923 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
924
925 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
926 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
927 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
928
929 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
930 if (m_generateMaptiles)
921 { 931 {
922 RegionInfo.RegionSettings.TerrainImageID = tileID; 932 int maptileRefresh = startupConfig.GetInt("MaptileRefresh", 0);
933 if (maptileRefresh != 0)
934 {
935 m_mapGenerationTimer.Interval = maptileRefresh * 1000;
936 m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister;
937 m_mapGenerationTimer.AutoReset = true;
938 m_mapGenerationTimer.Start();
939 }
923 } 940 }
924 } 941 else
942 {
943 string tile = startupConfig.GetString("MaptileStaticUUID", UUID.Zero.ToString());
944 UUID tileID;
925 945
926 string grant = startupConfig.GetString("AllowedClients", String.Empty); 946 if (UUID.TryParse(tile, out tileID))
927 if (grant.Length > 0) 947 {
928 { 948 RegionInfo.RegionSettings.TerrainImageID = tileID;
929 foreach (string viewer in grant.Split('|')) 949 }
950 }
951
952 string grant = startupConfig.GetString("AllowedClients", String.Empty);
953 if (grant.Length > 0)
930 { 954 {
931 m_AllowedViewers.Add(viewer.Trim().ToLower()); 955 foreach (string viewer in grant.Split(','))
956 {
957 m_AllowedViewers.Add(viewer.Trim().ToLower());
958 }
932 } 959 }
933 }
934 960
935 grant = startupConfig.GetString("BannedClients", String.Empty); 961 grant = startupConfig.GetString("BannedClients", String.Empty);
936 if (grant.Length > 0) 962 if (grant.Length > 0)
937 {
938 foreach (string viewer in grant.Split('|'))
939 { 963 {
940 m_BannedViewers.Add(viewer.Trim().ToLower()); 964 foreach (string viewer in grant.Split(','))
965 {
966 m_BannedViewers.Add(viewer.Trim().ToLower());
967 }
941 } 968 }
942 }
943 969
944 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime); 970 MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime);
945 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup); 971 m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup);
946 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations); 972 m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations);
947 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement); 973 m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement);
948 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events); 974 m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events);
949 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects); 975 m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects);
950 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics); 976 m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics);
951 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences); 977 m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences);
952 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain); 978 m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain);
953 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning); 979 m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning);
980 }
981 }
982 catch (Exception e)
983 {
984 m_log.Error("[SCENE]: Failed to load StartupConfig: " + e.ToString());
954 } 985 }
955 986
956 // FIXME: Ultimately this should be in a module. 987 // FIXME: Ultimately this should be in a module.
@@ -995,6 +1026,8 @@ namespace OpenSim.Region.Framework.Scenes
995 StatsReporter = new SimStatsReporter(this); 1026 StatsReporter = new SimStatsReporter(this);
996 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 1027 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
997 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 1028 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
1029
1030 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
998 } 1031 }
999 1032
1000 public Scene(RegionInfo regInfo) : base(regInfo) 1033 public Scene(RegionInfo regInfo) : base(regInfo)
@@ -1290,8 +1323,11 @@ namespace OpenSim.Region.Framework.Scenes
1290 // Stop all client threads. 1323 // Stop all client threads.
1291 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); }); 1324 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); });
1292 1325
1293 m_log.Debug("[SCENE]: Persisting changed objects"); 1326 m_log.Debug("[SCENE]: TriggerSceneShuttingDown");
1294 EventManager.TriggerSceneShuttingDown(this); 1327 EventManager.TriggerSceneShuttingDown(this);
1328
1329 m_log.Debug("[SCENE]: Persisting changed objects");
1330
1295 Backup(false); 1331 Backup(false);
1296 m_sceneGraph.Close(); 1332 m_sceneGraph.Close();
1297 1333
@@ -1305,6 +1341,7 @@ namespace OpenSim.Region.Framework.Scenes
1305 // attempt to reference a null or disposed physics scene. 1341 // attempt to reference a null or disposed physics scene.
1306 if (PhysicsScene != null) 1342 if (PhysicsScene != null)
1307 { 1343 {
1344 m_log.Debug("[SCENE]: Dispose Physics");
1308 PhysicsScene phys = PhysicsScene; 1345 PhysicsScene phys = PhysicsScene;
1309 // remove the physics engine from both Scene and SceneGraph 1346 // remove the physics engine from both Scene and SceneGraph
1310 PhysicsScene = null; 1347 PhysicsScene = null;
@@ -1327,11 +1364,29 @@ namespace OpenSim.Region.Framework.Scenes
1327 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1364 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1328 if (m_heartbeatThread != null) 1365 if (m_heartbeatThread != null)
1329 { 1366 {
1367 m_hbRestarts++;
1368 if(m_hbRestarts > 10)
1369 Environment.Exit(1);
1370 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1371
1372//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1373//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1374//proc.EnableRaisingEvents=false;
1375//proc.StartInfo.FileName = "/bin/kill";
1376//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1377//proc.Start();
1378//proc.WaitForExit();
1379//Thread.Sleep(1000);
1380//Environment.Exit(1);
1330 m_heartbeatThread.Abort(); 1381 m_heartbeatThread.Abort();
1382 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1331 m_heartbeatThread = null; 1383 m_heartbeatThread = null;
1332 } 1384 }
1333// m_lastUpdate = Util.EnvironmentTickCount(); 1385// m_lastUpdate = Util.EnvironmentTickCount();
1334 1386
1387// m_sceneGraph.PreparePhysicsSimulation();
1388
1389
1335 m_heartbeatThread 1390 m_heartbeatThread
1336 = Watchdog.StartThread( 1391 = Watchdog.StartThread(
1337 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false); 1392 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false);
@@ -1474,16 +1529,20 @@ namespace OpenSim.Region.Framework.Scenes
1474 endFrame = Frame + frames; 1529 endFrame = Frame + frames;
1475 1530
1476 float physicsFPS = 0f; 1531 float physicsFPS = 0f;
1477 int previousFrameTick, tmpMS; 1532 int tmpMS;
1478 int maintc = Util.EnvironmentTickCount(); 1533 int previousFrameTick;
1534 int maintc;
1535 int sleepMS;
1536 int framestart;
1479 1537
1480 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) 1538 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
1481 { 1539 {
1540 framestart = Util.EnvironmentTickCount();
1482 ++Frame; 1541 ++Frame;
1483 1542
1484// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1543// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1485 1544
1486 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1545 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1487 1546
1488 try 1547 try
1489 { 1548 {
@@ -1535,6 +1594,7 @@ namespace OpenSim.Region.Framework.Scenes
1535 m_sceneGraph.UpdatePresences(); 1594 m_sceneGraph.UpdatePresences();
1536 1595
1537 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1596 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1597
1538 1598
1539 // Delete temp-on-rez stuff 1599 // Delete temp-on-rez stuff
1540 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1600 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
@@ -1616,34 +1676,37 @@ namespace OpenSim.Region.Framework.Scenes
1616 1676
1617 Watchdog.UpdateThread(); 1677 Watchdog.UpdateThread();
1618 1678
1679 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1680
1681 StatsReporter.AddPhysicsFPS(physicsFPS);
1682 StatsReporter.AddTimeDilation(TimeDilation);
1683 StatsReporter.AddFPS(1);
1684
1685 StatsReporter.addAgentMS(agentMS);
1686 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1687 StatsReporter.addOtherMS(otherMS);
1688 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1689
1619 previousFrameTick = m_lastFrameTick; 1690 previousFrameTick = m_lastFrameTick;
1620 m_lastFrameTick = Util.EnvironmentTickCount(); 1691 m_lastFrameTick = Util.EnvironmentTickCount();
1621 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1692 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
1622 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1693 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1623 1694
1695 m_firstHeartbeat = false;
1696
1697 sleepMS = Util.EnvironmentTickCount();
1698
1624 if (tmpMS > 0) 1699 if (tmpMS > 0)
1625 {
1626 Thread.Sleep(tmpMS); 1700 Thread.Sleep(tmpMS);
1627 spareMS += tmpMS;
1628 }
1629
1630 frameMS = Util.EnvironmentTickCountSubtract(maintc);
1631 maintc = Util.EnvironmentTickCount();
1632 1701
1633 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; 1702 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1703 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1704 StatsReporter.addSleepMS(sleepMS);
1705 StatsReporter.addFrameMS(frameMS);
1634 1706
1635 // if (Frame%m_update_avatars == 0) 1707 // if (Frame%m_update_avatars == 0)
1636 // UpdateInWorldTime(); 1708 // UpdateInWorldTime();
1637 StatsReporter.AddPhysicsFPS(physicsFPS);
1638 StatsReporter.AddTimeDilation(TimeDilation);
1639 StatsReporter.AddFPS(1);
1640 1709
1641 StatsReporter.addFrameMS(frameMS);
1642 StatsReporter.addAgentMS(agentMS);
1643 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1644 StatsReporter.addOtherMS(otherMS);
1645 StatsReporter.AddSpareMS(spareMS);
1646 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1647 1710
1648 // Optionally warn if a frame takes double the amount of time that it should. 1711 // Optionally warn if a frame takes double the amount of time that it should.
1649 if (DebugUpdates 1712 if (DebugUpdates
@@ -1761,7 +1824,7 @@ namespace OpenSim.Region.Framework.Scenes
1761 msg.fromAgentName = "Server"; 1824 msg.fromAgentName = "Server";
1762 msg.dialog = (byte)19; // Object msg 1825 msg.dialog = (byte)19; // Object msg
1763 msg.fromGroup = false; 1826 msg.fromGroup = false;
1764 msg.offline = (byte)0; 1827 msg.offline = (byte)1;
1765 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1828 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1766 msg.Position = Vector3.Zero; 1829 msg.Position = Vector3.Zero;
1767 msg.RegionID = RegionInfo.RegionID.Guid; 1830 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1983,6 +2046,19 @@ namespace OpenSim.Region.Framework.Scenes
1983 EventManager.TriggerPrimsLoaded(this); 2046 EventManager.TriggerPrimsLoaded(this);
1984 } 2047 }
1985 2048
2049 public bool SuportsRayCastFiltered()
2050 {
2051 if (PhysicsScene == null)
2052 return false;
2053 return PhysicsScene.SuportsRaycastWorldFiltered();
2054 }
2055
2056 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2057 {
2058 if (PhysicsScene == null)
2059 return null;
2060 return PhysicsScene.RaycastWorld(position, direction, length, Count,filter);
2061 }
1986 2062
1987 /// <summary> 2063 /// <summary>
1988 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed. 2064 /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
@@ -1999,14 +2075,24 @@ namespace OpenSim.Region.Framework.Scenes
1999 /// <returns></returns> 2075 /// <returns></returns>
2000 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2076 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
2001 { 2077 {
2078
2079 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2080 Vector3 wpos = Vector3.Zero;
2081 // Check for water surface intersection from above
2082 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2083 {
2084 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2085 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2086 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2087 wpos.Z = wheight;
2088 }
2089
2002 Vector3 pos = Vector3.Zero; 2090 Vector3 pos = Vector3.Zero;
2003 if (RayEndIsIntersection == (byte)1) 2091 if (RayEndIsIntersection == (byte)1)
2004 { 2092 {
2005 pos = RayEnd; 2093 pos = RayEnd;
2006 return pos;
2007 } 2094 }
2008 2095 else if (RayTargetID != UUID.Zero)
2009 if (RayTargetID != UUID.Zero)
2010 { 2096 {
2011 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2097 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
2012 2098
@@ -2028,7 +2114,7 @@ namespace OpenSim.Region.Framework.Scenes
2028 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 2114 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
2029 2115
2030 // Un-comment out the following line to Get Raytrace results printed to the console. 2116 // Un-comment out the following line to Get Raytrace results printed to the console.
2031 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 2117 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
2032 float ScaleOffset = 0.5f; 2118 float ScaleOffset = 0.5f;
2033 2119
2034 // If we hit something 2120 // If we hit something
@@ -2051,13 +2137,10 @@ namespace OpenSim.Region.Framework.Scenes
2051 //pos.Z -= 0.25F; 2137 //pos.Z -= 0.25F;
2052 2138
2053 } 2139 }
2054
2055 return pos;
2056 } 2140 }
2057 else 2141 else
2058 { 2142 {
2059 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2143 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2060
2061 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2144 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2062 2145
2063 // Un-comment the following line to print the raytrace results to the console. 2146 // Un-comment the following line to print the raytrace results to the console.
@@ -2066,13 +2149,12 @@ namespace OpenSim.Region.Framework.Scenes
2066 if (ei.HitTF) 2149 if (ei.HitTF)
2067 { 2150 {
2068 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2151 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2069 } else 2152 }
2153 else
2070 { 2154 {
2071 // fall back to our stupid functionality 2155 // fall back to our stupid functionality
2072 pos = RayEnd; 2156 pos = RayEnd;
2073 } 2157 }
2074
2075 return pos;
2076 } 2158 }
2077 } 2159 }
2078 else 2160 else
@@ -2083,8 +2165,12 @@ namespace OpenSim.Region.Framework.Scenes
2083 //increase height so its above the ground. 2165 //increase height so its above the ground.
2084 //should be getting the normal of the ground at the rez point and using that? 2166 //should be getting the normal of the ground at the rez point and using that?
2085 pos.Z += scale.Z / 2f; 2167 pos.Z += scale.Z / 2f;
2086 return pos; 2168// return pos;
2087 } 2169 }
2170
2171 // check against posible water intercept
2172 if (wpos.Z > pos.Z) pos = wpos;
2173 return pos;
2088 } 2174 }
2089 2175
2090 2176
@@ -2175,12 +2261,12 @@ namespace OpenSim.Region.Framework.Scenes
2175 { 2261 {
2176 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates)) 2262 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates))
2177 { 2263 {
2264 sceneObject.IsDeleted = false;
2178 EventManager.TriggerObjectAddedToScene(sceneObject); 2265 EventManager.TriggerObjectAddedToScene(sceneObject);
2179 return true; 2266 return true;
2180 } 2267 }
2181 2268
2182 return false; 2269 return false;
2183
2184 } 2270 }
2185 2271
2186 /// <summary> 2272 /// <summary>
@@ -2272,6 +2358,15 @@ namespace OpenSim.Region.Framework.Scenes
2272 /// </summary> 2358 /// </summary>
2273 public void DeleteAllSceneObjects() 2359 public void DeleteAllSceneObjects()
2274 { 2360 {
2361 DeleteAllSceneObjects(false);
2362 }
2363
2364 /// <summary>
2365 /// Delete every object from the scene. This does not include attachments worn by avatars.
2366 /// </summary>
2367 public void DeleteAllSceneObjects(bool exceptNoCopy)
2368 {
2369 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2275 lock (Entities) 2370 lock (Entities)
2276 { 2371 {
2277 EntityBase[] entities = Entities.GetEntities(); 2372 EntityBase[] entities = Entities.GetEntities();
@@ -2280,11 +2375,24 @@ namespace OpenSim.Region.Framework.Scenes
2280 if (e is SceneObjectGroup) 2375 if (e is SceneObjectGroup)
2281 { 2376 {
2282 SceneObjectGroup sog = (SceneObjectGroup)e; 2377 SceneObjectGroup sog = (SceneObjectGroup)e;
2283 if (!sog.IsAttachment) 2378 if (sog != null && !sog.IsAttachment)
2284 DeleteSceneObject((SceneObjectGroup)e, false); 2379 {
2380 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2381 {
2382 DeleteSceneObject((SceneObjectGroup)e, false);
2383 }
2384 else
2385 {
2386 toReturn.Add((SceneObjectGroup)e);
2387 }
2388 }
2285 } 2389 }
2286 } 2390 }
2287 } 2391 }
2392 if (toReturn.Count > 0)
2393 {
2394 returnObjects(toReturn.ToArray(), UUID.Zero);
2395 }
2288 } 2396 }
2289 2397
2290 /// <summary> 2398 /// <summary>
@@ -2319,6 +2427,12 @@ namespace OpenSim.Region.Framework.Scenes
2319 2427
2320 foreach (SceneObjectPart part in partList) 2428 foreach (SceneObjectPart part in partList)
2321 { 2429 {
2430 if (part.KeyframeMotion != null)
2431 {
2432 part.KeyframeMotion.Delete();
2433 part.KeyframeMotion = null;
2434 }
2435
2322 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0)) 2436 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
2323 { 2437 {
2324 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? 2438 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
@@ -2336,6 +2450,8 @@ namespace OpenSim.Region.Framework.Scenes
2336 } 2450 }
2337 2451
2338 group.DeleteGroupFromScene(silent); 2452 group.DeleteGroupFromScene(silent);
2453 if (!silent)
2454 SendKillObject(new List<uint>() { group.LocalId });
2339 2455
2340// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2456// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2341 } 2457 }
@@ -2626,7 +2742,7 @@ namespace OpenSim.Region.Framework.Scenes
2626 // If the user is banned, we won't let any of their objects 2742 // If the user is banned, we won't let any of their objects
2627 // enter. Period. 2743 // enter. Period.
2628 // 2744 //
2629 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID)) 2745 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
2630 { 2746 {
2631 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID); 2747 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
2632 return false; 2748 return false;
@@ -2634,6 +2750,8 @@ namespace OpenSim.Region.Framework.Scenes
2634 2750
2635 if (newPosition != Vector3.Zero) 2751 if (newPosition != Vector3.Zero)
2636 newObject.RootPart.GroupPosition = newPosition; 2752 newObject.RootPart.GroupPosition = newPosition;
2753 if (newObject.RootPart.KeyframeMotion != null)
2754 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2637 2755
2638 if (!AddSceneObject(newObject)) 2756 if (!AddSceneObject(newObject))
2639 { 2757 {
@@ -2678,6 +2796,23 @@ namespace OpenSim.Region.Framework.Scenes
2678 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2796 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2679 public bool AddSceneObject(SceneObjectGroup sceneObject) 2797 public bool AddSceneObject(SceneObjectGroup sceneObject)
2680 { 2798 {
2799 if (sceneObject.OwnerID == UUID.Zero)
2800 {
2801 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2802 return false;
2803 }
2804
2805 // If the user is banned, we won't let any of their objects
2806 // enter. Period.
2807 //
2808 int flags = GetUserFlags(sceneObject.OwnerID);
2809 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2810 {
2811 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2812
2813 return false;
2814 }
2815
2681 // Force allocation of new LocalId 2816 // Force allocation of new LocalId
2682 // 2817 //
2683 SceneObjectPart[] parts = sceneObject.Parts; 2818 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2711,16 +2846,27 @@ namespace OpenSim.Region.Framework.Scenes
2711 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2846 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2712 2847
2713 if (AttachmentsModule != null) 2848 if (AttachmentsModule != null)
2714 AttachmentsModule.AttachObject(sp, grp, 0, false, false); 2849 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false);
2715 } 2850 }
2716 else 2851 else
2717 { 2852 {
2853 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2718 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2854 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2719 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2855 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2720 } 2856 }
2857 if (sceneObject.OwnerID == UUID.Zero)
2858 {
2859 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2860 return false;
2861 }
2721 } 2862 }
2722 else 2863 else
2723 { 2864 {
2865 if (sceneObject.OwnerID == UUID.Zero)
2866 {
2867 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2868 return false;
2869 }
2724 AddRestoredSceneObject(sceneObject, true, false); 2870 AddRestoredSceneObject(sceneObject, true, false);
2725 } 2871 }
2726 2872
@@ -2737,6 +2883,24 @@ namespace OpenSim.Region.Framework.Scenes
2737 return 2; // StateSource.PrimCrossing 2883 return 2; // StateSource.PrimCrossing
2738 } 2884 }
2739 2885
2886 public int GetUserFlags(UUID user)
2887 {
2888 //Unfortunately the SP approach means that the value is cached until region is restarted
2889 /*
2890 ScenePresence sp;
2891 if (TryGetScenePresence(user, out sp))
2892 {
2893 return sp.UserFlags;
2894 }
2895 else
2896 {
2897 */
2898 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2899 if (uac == null)
2900 return 0;
2901 return uac.UserFlags;
2902 //}
2903 }
2740 #endregion 2904 #endregion
2741 2905
2742 #region Add/Remove Avatar Methods 2906 #region Add/Remove Avatar Methods
@@ -2769,7 +2933,7 @@ namespace OpenSim.Region.Framework.Scenes
2769 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2933 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2770 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2934 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2771 2935
2772 // CheckHeartbeat(); 2936 CheckHeartbeat();
2773 2937
2774 sp = GetScenePresence(client.AgentId); 2938 sp = GetScenePresence(client.AgentId);
2775 2939
@@ -2800,6 +2964,7 @@ namespace OpenSim.Region.Framework.Scenes
2800 // start the scripts again (since this is done in RezAttachments()). 2964 // start the scripts again (since this is done in RezAttachments()).
2801 // XXX: This is convoluted. 2965 // XXX: This is convoluted.
2802 sp.IsChildAgent = false; 2966 sp.IsChildAgent = false;
2967 sp.IsLoggingIn = true;
2803 2968
2804 if (AttachmentsModule != null) 2969 if (AttachmentsModule != null)
2805 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); }); 2970 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); });
@@ -2913,19 +3078,14 @@ namespace OpenSim.Region.Framework.Scenes
2913 // and the scene presence and the client, if they exist 3078 // and the scene presence and the client, if they exist
2914 try 3079 try
2915 { 3080 {
2916 // We need to wait for the client to make UDP contact first. 3081 ScenePresence sp = GetScenePresence(agentID);
2917 // It's the UDP contact that creates the scene presence 3082
2918 ScenePresence sp = WaitGetScenePresence(agentID);
2919 if (sp != null) 3083 if (sp != null)
2920 { 3084 {
2921 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3085 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2922
2923 sp.ControllingClient.Close(); 3086 sp.ControllingClient.Close();
2924 } 3087 }
2925 else 3088
2926 {
2927 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2928 }
2929 // BANG! SLASH! 3089 // BANG! SLASH!
2930 m_authenticateHandler.RemoveCircuit(agentID); 3090 m_authenticateHandler.RemoveCircuit(agentID);
2931 3091
@@ -2970,6 +3130,8 @@ namespace OpenSim.Region.Framework.Scenes
2970 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3130 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2971 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3131 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2972 3132
3133 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3134
2973 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3135 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2974 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3136 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2975 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3137 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -3026,6 +3188,7 @@ namespace OpenSim.Region.Framework.Scenes
3026 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3188 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
3027 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3189 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
3028 client.OnCopyInventoryItem += CopyInventoryItem; 3190 client.OnCopyInventoryItem += CopyInventoryItem;
3191 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
3029 client.OnMoveInventoryItem += MoveInventoryItem; 3192 client.OnMoveInventoryItem += MoveInventoryItem;
3030 client.OnRemoveInventoryItem += RemoveInventoryItem; 3193 client.OnRemoveInventoryItem += RemoveInventoryItem;
3031 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3194 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3097,6 +3260,8 @@ namespace OpenSim.Region.Framework.Scenes
3097 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3260 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3098 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3261 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3099 3262
3263 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3264
3100 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3265 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3101 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3266 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3102 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3267 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3199,7 +3364,7 @@ namespace OpenSim.Region.Framework.Scenes
3199 /// </summary> 3364 /// </summary>
3200 /// <param name="agentId">The avatar's Unique ID</param> 3365 /// <param name="agentId">The avatar's Unique ID</param>
3201 /// <param name="client">The IClientAPI for the client</param> 3366 /// <param name="client">The IClientAPI for the client</param>
3202 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3367 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3203 { 3368 {
3204 if (EntityTransferModule != null) 3369 if (EntityTransferModule != null)
3205 { 3370 {
@@ -3210,6 +3375,7 @@ namespace OpenSim.Region.Framework.Scenes
3210 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3375 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3211 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3376 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3212 } 3377 }
3378 return false;
3213 } 3379 }
3214 3380
3215 /// <summary> 3381 /// <summary>
@@ -3319,6 +3485,16 @@ namespace OpenSim.Region.Framework.Scenes
3319 /// <param name="flags"></param> 3485 /// <param name="flags"></param>
3320 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3486 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3321 { 3487 {
3488 //Add half the avatar's height so that the user doesn't fall through prims
3489 ScenePresence presence;
3490 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3491 {
3492 if (presence.Appearance != null)
3493 {
3494 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3495 }
3496 }
3497
3322 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3498 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3323 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3499 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3324 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3500 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3456,6 +3632,7 @@ namespace OpenSim.Region.Framework.Scenes
3456 // It's possible for child agents to have transactions if changes are being made cross-border. 3632 // It's possible for child agents to have transactions if changes are being made cross-border.
3457 if (AgentTransactionsModule != null) 3633 if (AgentTransactionsModule != null)
3458 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 3634 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3635 m_log.Debug("[Scene] The avatar has left the building");
3459 } 3636 }
3460 catch (Exception e) 3637 catch (Exception e)
3461 { 3638 {
@@ -3648,38 +3825,39 @@ namespace OpenSim.Region.Framework.Scenes
3648 agent.firstname, agent.lastname, agent.Viewer); 3825 agent.firstname, agent.lastname, agent.Viewer);
3649 reason = "Access denied, your viewer is banned by the region owner"; 3826 reason = "Access denied, your viewer is banned by the region owner";
3650 return false; 3827 return false;
3651 } 3828 }
3829
3652 3830
3653 ILandObject land; 3831 ScenePresence sp = GetScenePresence(agent.AgentID);
3832
3833 if (sp != null && !sp.IsChildAgent)
3834 {
3835 // We have a zombie from a crashed session.
3836 // Or the same user is trying to be root twice here, won't work.
3837 // Kill it.
3838 m_log.WarnFormat(
3839 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3840 sp.Name, sp.UUID, RegionInfo.RegionName);
3841
3842 sp.ControllingClient.Close(true, true);
3843 sp = null;
3844 }
3654 3845
3655 lock (agent) 3846 lock (agent)
3656 { 3847 {
3657 ScenePresence sp = GetScenePresence(agent.AgentID);
3658
3659 if (sp != null && !sp.IsChildAgent)
3660 {
3661 // We have a zombie from a crashed session.
3662 // Or the same user is trying to be root twice here, won't work.
3663 // Kill it.
3664 m_log.WarnFormat(
3665 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3666 sp.Name, sp.UUID, RegionInfo.RegionName);
3667
3668 sp.ControllingClient.Close(true);
3669 sp = null;
3670 }
3671
3672 land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3673
3674 //On login test land permisions 3848 //On login test land permisions
3675 if (vialogin) 3849 if (vialogin)
3676 { 3850 {
3677 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3851 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3852 if (cache != null)
3853 cache.Remove(agent.firstname + " " + agent.lastname);
3854 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3678 { 3855 {
3856 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3679 return false; 3857 return false;
3680 } 3858 }
3681 } 3859 }
3682 3860
3683 if (sp == null) // We don't have an [child] agent here already 3861 if (sp == null) // We don't have an [child] agent here already
3684 { 3862 {
3685 if (requirePresenceLookup) 3863 if (requirePresenceLookup)
@@ -3688,34 +3866,36 @@ namespace OpenSim.Region.Framework.Scenes
3688 { 3866 {
3689 if (!VerifyUserPresence(agent, out reason)) 3867 if (!VerifyUserPresence(agent, out reason))
3690 return false; 3868 return false;
3691 } 3869 } catch (Exception e)
3692 catch (Exception e)
3693 { 3870 {
3694 m_log.ErrorFormat( 3871 m_log.ErrorFormat(
3695 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace); 3872 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace);
3696
3697 return false; 3873 return false;
3698 } 3874 }
3699 } 3875 }
3700 3876
3701 try 3877 try
3702 { 3878 {
3703 if (!AuthorizeUser(agent, out reason)) 3879 // Always check estate if this is a login. Always
3704 return false; 3880 // check if banned regions are to be blacked out.
3881 if (vialogin || (!m_seeIntoBannedRegion))
3882 {
3883 if (!AuthorizeUser(agent, out reason))
3884 return false;
3885 }
3705 } 3886 }
3706 catch (Exception e) 3887 catch (Exception e)
3707 { 3888 {
3708 m_log.ErrorFormat( 3889 m_log.ErrorFormat(
3709 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3890 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
3710
3711 return false; 3891 return false;
3712 } 3892 }
3713 3893
3714 m_log.InfoFormat( 3894 m_log.InfoFormat(
3715 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})", 3895 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})",
3716 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname, 3896 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
3717 agent.AgentID, agent.circuitcode); 3897 agent.AgentID, agent.circuitcode);
3718 3898
3719 if (CapsModule != null) 3899 if (CapsModule != null)
3720 { 3900 {
3721 CapsModule.SetAgentCapsSeeds(agent); 3901 CapsModule.SetAgentCapsSeeds(agent);
@@ -3727,15 +3907,15 @@ namespace OpenSim.Region.Framework.Scenes
3727 // Let the SP know how we got here. This has a lot of interesting 3907 // Let the SP know how we got here. This has a lot of interesting
3728 // uses down the line. 3908 // uses down the line.
3729 sp.TeleportFlags = (TPFlags)teleportFlags; 3909 sp.TeleportFlags = (TPFlags)teleportFlags;
3730 3910
3731 if (sp.IsChildAgent) 3911 if (sp.IsChildAgent)
3732 { 3912 {
3733 m_log.DebugFormat( 3913 m_log.DebugFormat(
3734 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}", 3914 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
3735 agent.AgentID, RegionInfo.RegionName); 3915 agent.AgentID, RegionInfo.RegionName);
3736 3916
3737 sp.AdjustKnownSeeds(); 3917 sp.AdjustKnownSeeds();
3738 3918
3739 if (CapsModule != null) 3919 if (CapsModule != null)
3740 CapsModule.SetAgentCapsSeeds(agent); 3920 CapsModule.SetAgentCapsSeeds(agent);
3741 } 3921 }
@@ -3837,6 +4017,8 @@ namespace OpenSim.Region.Framework.Scenes
3837 } 4017 }
3838 4018
3839 // Honor parcel landing type and position. 4019 // Honor parcel landing type and position.
4020 /*
4021 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3840 if (land != null) 4022 if (land != null)
3841 { 4023 {
3842 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 4024 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3844,25 +4026,43 @@ namespace OpenSim.Region.Framework.Scenes
3844 agent.startpos = land.LandData.UserLocation; 4026 agent.startpos = land.LandData.UserLocation;
3845 } 4027 }
3846 } 4028 }
4029 */// This is now handled properly in ScenePresence.MakeRootAgent
3847 } 4030 }
3848 4031
3849 return true; 4032 return true;
3850 } 4033 }
3851 4034
3852 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 4035 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3853 { 4036 {
3854 bool banned = land.IsBannedFromLand(agent.AgentID); 4037 if (posX < 0)
3855 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 4038 posX = 0;
4039 else if (posX >= 256)
4040 posX = 255.999f;
4041 if (posY < 0)
4042 posY = 0;
4043 else if (posY >= 256)
4044 posY = 255.999f;
4045
4046 reason = String.Empty;
4047 if (Permissions.IsGod(agentID))
4048 return true;
4049
4050 ILandObject land = LandChannel.GetLandObject(posX, posY);
4051 if (land == null)
4052 return false;
4053
4054 bool banned = land.IsBannedFromLand(agentID);
4055 bool restricted = land.IsRestrictedFromLand(agentID);
3856 4056
3857 if (banned || restricted) 4057 if (banned || restricted)
3858 { 4058 {
3859 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 4059 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3860 if (nearestParcel != null) 4060 if (nearestParcel != null)
3861 { 4061 {
3862 //Move agent to nearest allowed 4062 //Move agent to nearest allowed
3863 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 4063 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3864 agent.startpos.X = newPosition.X; 4064 posX = newPosition.X;
3865 agent.startpos.Y = newPosition.Y; 4065 posY = newPosition.Y;
3866 } 4066 }
3867 else 4067 else
3868 { 4068 {
@@ -3924,7 +4124,7 @@ namespace OpenSim.Region.Framework.Scenes
3924 4124
3925 if (!m_strictAccessControl) return true; 4125 if (!m_strictAccessControl) return true;
3926 if (Permissions.IsGod(agent.AgentID)) return true; 4126 if (Permissions.IsGod(agent.AgentID)) return true;
3927 4127
3928 if (AuthorizationService != null) 4128 if (AuthorizationService != null)
3929 { 4129 {
3930 if (!AuthorizationService.IsAuthorizedForRegion( 4130 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3939,7 +4139,7 @@ namespace OpenSim.Region.Framework.Scenes
3939 4139
3940 if (RegionInfo.EstateSettings != null) 4140 if (RegionInfo.EstateSettings != null)
3941 { 4141 {
3942 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4142 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, 0))
3943 { 4143 {
3944 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4144 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3945 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4145 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4129,6 +4329,15 @@ namespace OpenSim.Region.Framework.Scenes
4129 4329
4130 // XPTO: if this agent is not allowed here as root, always return false 4330 // XPTO: if this agent is not allowed here as root, always return false
4131 4331
4332 // We have to wait until the viewer contacts this region after receiving EAC.
4333 // That calls AddNewClient, which finally creates the ScenePresence
4334 int flags = GetUserFlags(cAgentData.AgentID);
4335 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4336 {
4337 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4338 return false;
4339 }
4340
4132 // TODO: This check should probably be in QueryAccess(). 4341 // TODO: This check should probably be in QueryAccess().
4133 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4342 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4134 if (nearestParcel == null) 4343 if (nearestParcel == null)
@@ -4193,7 +4402,7 @@ namespace OpenSim.Region.Framework.Scenes
4193 /// <param name='agentID'></param> 4402 /// <param name='agentID'></param>
4194 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4403 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4195 { 4404 {
4196 int ntimes = 10; 4405 int ntimes = 30;
4197 ScenePresence sp = null; 4406 ScenePresence sp = null;
4198 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4407 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4199 Thread.Sleep(1000); 4408 Thread.Sleep(1000);
@@ -4223,6 +4432,16 @@ namespace OpenSim.Region.Framework.Scenes
4223 return false; 4432 return false;
4224 } 4433 }
4225 4434
4435 public bool IncomingCloseAgent(UUID agentID)
4436 {
4437 return IncomingCloseAgent(agentID, false);
4438 }
4439
4440 public bool IncomingCloseChildAgent(UUID agentID)
4441 {
4442 return IncomingCloseAgent(agentID, true);
4443 }
4444
4226 /// <summary> 4445 /// <summary>
4227 /// Tell a single agent to disconnect from the region. 4446 /// Tell a single agent to disconnect from the region.
4228 /// </summary> 4447 /// </summary>
@@ -4238,7 +4457,7 @@ namespace OpenSim.Region.Framework.Scenes
4238 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4457 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4239 if (presence != null) 4458 if (presence != null)
4240 { 4459 {
4241 presence.ControllingClient.Close(force); 4460 presence.ControllingClient.Close(force, force);
4242 return true; 4461 return true;
4243 } 4462 }
4244 4463
@@ -4898,35 +5117,81 @@ namespace OpenSim.Region.Framework.Scenes
4898 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5117 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
4899 } 5118 }
4900 5119
4901 public int GetHealth() 5120 public int GetHealth(out int flags, out string message)
4902 { 5121 {
4903 // Returns: 5122 // Returns:
4904 // 1 = sim is up and accepting http requests. The heartbeat has 5123 // 1 = sim is up and accepting http requests. The heartbeat has
4905 // stopped and the sim is probably locked up, but a remote 5124 // stopped and the sim is probably locked up, but a remote
4906 // admin restart may succeed 5125 // admin restart may succeed
4907 // 5126 //
4908 // 2 = Sim is up and the heartbeat is running. The sim is likely 5127 // 2 = Sim is up and the heartbeat is running. The sim is likely
4909 // usable for people within and logins _may_ work 5128 // usable for people within
5129 //
5130 // 3 = Sim is up and one packet thread is running. Sim is
5131 // unstable and will not accept new logins
4910 // 5132 //
4911 // 3 = We have seen a new user enter within the past 4 minutes 5133 // 4 = Sim is up and both packet threads are running. Sim is
5134 // likely usable
5135 //
5136 // 5 = We have seen a new user enter within the past 4 minutes
4912 // which can be seen as positive confirmation of sim health 5137 // which can be seen as positive confirmation of sim health
4913 // 5138 //
5139
5140 flags = 0;
5141 message = String.Empty;
5142
5143 CheckHeartbeat();
5144
5145 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5146 {
5147 // We're still starting
5148 // 0 means "in startup", it can't happen another way, since
5149 // to get here, we must be able to accept http connections
5150 return 0;
5151 }
5152
4914 int health=1; // Start at 1, means we're up 5153 int health=1; // Start at 1, means we're up
4915 5154
4916 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5155 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4917 health += 1; 5156 {
5157 health+=1;
5158 flags |= 1;
5159 }
5160
5161 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5162 {
5163 health+=1;
5164 flags |= 2;
5165 }
5166
5167 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5168 {
5169 health+=1;
5170 flags |= 4;
5171 }
4918 else 5172 else
5173 {
5174int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5175System.Diagnostics.Process proc = new System.Diagnostics.Process();
5176proc.EnableRaisingEvents=false;
5177proc.StartInfo.FileName = "/bin/kill";
5178proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5179proc.Start();
5180proc.WaitForExit();
5181Thread.Sleep(1000);
5182Environment.Exit(1);
5183 }
5184
5185 if (flags != 7)
4919 return health; 5186 return health;
4920 5187
4921 // A login in the last 4 mins? We can't be doing too badly 5188 // A login in the last 4 mins? We can't be doing too badly
4922 // 5189 //
4923 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5190 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4924 health++; 5191 health++;
4925 else 5192 else
4926 return health; 5193 return health;
4927 5194
4928// CheckHeartbeat();
4929
4930 return health; 5195 return health;
4931 } 5196 }
4932 5197
@@ -5014,7 +5279,7 @@ namespace OpenSim.Region.Framework.Scenes
5014 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 5279 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
5015 if (wasUsingPhysics) 5280 if (wasUsingPhysics)
5016 { 5281 {
5017 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 5282 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
5018 } 5283 }
5019 } 5284 }
5020 5285
@@ -5113,14 +5378,14 @@ namespace OpenSim.Region.Framework.Scenes
5113 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5378 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5114 } 5379 }
5115 5380
5116// private void CheckHeartbeat() 5381 private void CheckHeartbeat()
5117// { 5382 {
5118// if (m_firstHeartbeat) 5383 if (m_firstHeartbeat)
5119// return; 5384 return;
5120// 5385
5121// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5386 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5122// StartTimer(); 5387 Start();
5123// } 5388 }
5124 5389
5125 public override ISceneObject DeserializeObject(string representation) 5390 public override ISceneObject DeserializeObject(string representation)
5126 { 5391 {
@@ -5132,9 +5397,14 @@ namespace OpenSim.Region.Framework.Scenes
5132 get { return m_allowScriptCrossings; } 5397 get { return m_allowScriptCrossings; }
5133 } 5398 }
5134 5399
5135 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5400 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5136 { 5401 {
5137 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5402 return GetNearestAllowedPosition(avatar, null);
5403 }
5404
5405 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5406 {
5407 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
5138 5408
5139 if (nearestParcel != null) 5409 if (nearestParcel != null)
5140 { 5410 {
@@ -5143,10 +5413,7 @@ namespace OpenSim.Region.Framework.Scenes
5143 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5413 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5144 if (nearestPoint != null) 5414 if (nearestPoint != null)
5145 { 5415 {
5146// m_log.DebugFormat( 5416 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
5147// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
5148// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
5149
5150 return nearestPoint.Value; 5417 return nearestPoint.Value;
5151 } 5418 }
5152 5419
@@ -5156,17 +5423,20 @@ namespace OpenSim.Region.Framework.Scenes
5156 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5423 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5157 if (nearestPoint != null) 5424 if (nearestPoint != null)
5158 { 5425 {
5159// m_log.DebugFormat( 5426 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
5160// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
5161
5162 return nearestPoint.Value; 5427 return nearestPoint.Value;
5163 } 5428 }
5164 5429
5165 //Ultimate backup if we have no idea where they are 5430 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
5166// m_log.DebugFormat( 5431 if (dest != excludeParcel)
5167// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5432 {
5433 // Ultimate backup if we have no idea where they are and
5434 // the last allowed position was in another parcel
5435 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5436 return avatar.lastKnownAllowedPosition;
5437 }
5168 5438
5169 return avatar.lastKnownAllowedPosition; 5439 // else fall through to region edge
5170 } 5440 }
5171 5441
5172 //Go to the edge, this happens in teleporting to a region with no available parcels 5442 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -5200,13 +5470,18 @@ namespace OpenSim.Region.Framework.Scenes
5200 5470
5201 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5471 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5202 { 5472 {
5473 return GetNearestAllowedParcel(avatarId, x, y, null);
5474 }
5475
5476 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5477 {
5203 List<ILandObject> all = AllParcels(); 5478 List<ILandObject> all = AllParcels();
5204 float minParcelDistance = float.MaxValue; 5479 float minParcelDistance = float.MaxValue;
5205 ILandObject nearestParcel = null; 5480 ILandObject nearestParcel = null;
5206 5481
5207 foreach (var parcel in all) 5482 foreach (var parcel in all)
5208 { 5483 {
5209 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5484 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
5210 { 5485 {
5211 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5486 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5212 if (parcelDistance < minParcelDistance) 5487 if (parcelDistance < minParcelDistance)
@@ -5422,7 +5697,55 @@ namespace OpenSim.Region.Framework.Scenes
5422 mapModule.GenerateMaptile(); 5697 mapModule.GenerateMaptile();
5423 } 5698 }
5424 5699
5425 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5700// public void CleanDroppedAttachments()
5701// {
5702// List<SceneObjectGroup> objectsToDelete =
5703// new List<SceneObjectGroup>();
5704//
5705// lock (m_cleaningAttachments)
5706// {
5707// ForEachSOG(delegate (SceneObjectGroup grp)
5708// {
5709// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5710// {
5711// UUID agentID = grp.OwnerID;
5712// if (agentID == UUID.Zero)
5713// {
5714// objectsToDelete.Add(grp);
5715// return;
5716// }
5717//
5718// ScenePresence sp = GetScenePresence(agentID);
5719// if (sp == null)
5720// {
5721// objectsToDelete.Add(grp);
5722// return;
5723// }
5724// }
5725// });
5726// }
5727//
5728// foreach (SceneObjectGroup grp in objectsToDelete)
5729// {
5730// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5731// DeleteSceneObject(grp, true);
5732// }
5733// }
5734
5735 public void ThreadAlive(int threadCode)
5736 {
5737 switch(threadCode)
5738 {
5739 case 1: // Incoming
5740 m_lastIncoming = Util.EnvironmentTickCount();
5741 break;
5742 case 2: // Incoming
5743 m_lastOutgoing = Util.EnvironmentTickCount();
5744 break;
5745 }
5746 }
5747
5748 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5426 { 5749 {
5427 RegenerateMaptile(); 5750 RegenerateMaptile();
5428 5751
@@ -5450,6 +5773,8 @@ namespace OpenSim.Region.Framework.Scenes
5450 /// <returns></returns> 5773 /// <returns></returns>
5451 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5774 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5452 { 5775 {
5776 reason = "You are banned from the region";
5777
5453 if (EntityTransferModule.IsInTransit(agentID)) 5778 if (EntityTransferModule.IsInTransit(agentID))
5454 { 5779 {
5455 reason = "Agent is still in transit from this region"; 5780 reason = "Agent is still in transit from this region";
@@ -5461,6 +5786,12 @@ namespace OpenSim.Region.Framework.Scenes
5461 return false; 5786 return false;
5462 } 5787 }
5463 5788
5789 if (Permissions.IsGod(agentID))
5790 {
5791 reason = String.Empty;
5792 return true;
5793 }
5794
5464 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5795 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5465 // However, the long term fix is to make sure root agent count is always accurate. 5796 // However, the long term fix is to make sure root agent count is always accurate.
5466 m_sceneGraph.RecalculateStats(); 5797 m_sceneGraph.RecalculateStats();
@@ -5481,6 +5812,41 @@ namespace OpenSim.Region.Framework.Scenes
5481 } 5812 }
5482 } 5813 }
5483 5814
5815 ScenePresence presence = GetScenePresence(agentID);
5816 IClientAPI client = null;
5817 AgentCircuitData aCircuit = null;
5818
5819 if (presence != null)
5820 {
5821 client = presence.ControllingClient;
5822 if (client != null)
5823 aCircuit = client.RequestClientInfo();
5824 }
5825
5826 // We may be called before there is a presence or a client.
5827 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5828 if (client == null)
5829 {
5830 aCircuit = new AgentCircuitData();
5831 aCircuit.AgentID = agentID;
5832 aCircuit.firstname = String.Empty;
5833 aCircuit.lastname = String.Empty;
5834 }
5835
5836 try
5837 {
5838 if (!AuthorizeUser(aCircuit, out reason))
5839 {
5840 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5841 return false;
5842 }
5843 }
5844 catch (Exception e)
5845 {
5846 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5847 return false;
5848 }
5849
5484 if (position == Vector3.Zero) // Teleport 5850 if (position == Vector3.Zero) // Teleport
5485 { 5851 {
5486 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5852 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5509,13 +5875,46 @@ namespace OpenSim.Region.Framework.Scenes
5509 } 5875 }
5510 } 5876 }
5511 } 5877 }
5878
5879 float posX = 128.0f;
5880 float posY = 128.0f;
5881
5882 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5883 {
5884 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5885 return false;
5886 }
5887 }
5888 else // Walking
5889 {
5890 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5891 if (land == null)
5892 return false;
5893
5894 bool banned = land.IsBannedFromLand(agentID);
5895 bool restricted = land.IsRestrictedFromLand(agentID);
5896
5897 if (banned || restricted)
5898 return false;
5512 } 5899 }
5513 5900
5514 reason = String.Empty; 5901 reason = String.Empty;
5515 return true; 5902 return true;
5516 } 5903 }
5517 5904
5518 /// <summary> 5905 public void StartTimerWatchdog()
5906 {
5907 m_timerWatchdog.Interval = 1000;
5908 m_timerWatchdog.Elapsed += TimerWatchdog;
5909 m_timerWatchdog.AutoReset = true;
5910 m_timerWatchdog.Start();
5911 }
5912
5913 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5914 {
5915 CheckHeartbeat();
5916 }
5917
5519 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5918 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5520 /// autopilot that moves an avatar to a sit target!. 5919 /// autopilot that moves an avatar to a sit target!.
5521 /// </summary> 5920 /// </summary>
@@ -5594,6 +5993,11 @@ namespace OpenSim.Region.Framework.Scenes
5594 return m_SpawnPoint - 1; 5993 return m_SpawnPoint - 1;
5595 } 5994 }
5596 5995
5996 private void HandleGcCollect(string module, string[] args)
5997 {
5998 GC.Collect();
5999 }
6000
5597 /// <summary> 6001 /// <summary>
5598 /// Wrappers to get physics modules retrieve assets. 6002 /// Wrappers to get physics modules retrieve assets.
5599 /// </summary> 6003 /// </summary>