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.cs707
1 files changed, 552 insertions, 155 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 9b17b7f..1a1c3d2 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>
@@ -350,7 +352,7 @@ namespace OpenSim.Region.Framework.Scenes
350 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing 352 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing
351 private volatile bool m_backingup; 353 private volatile bool m_backingup;
352 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); 354 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>();
353 private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>(); 355 private Dictionary<UUID, int> m_groupsWithTargets = new Dictionary<UUID, int>();
354 356
355 private string m_defaultScriptEngine; 357 private string m_defaultScriptEngine;
356 358
@@ -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
@@ -735,6 +755,8 @@ namespace OpenSim.Region.Framework.Scenes
735 m_SimulationDataService = simDataService; 755 m_SimulationDataService = simDataService;
736 m_EstateDataService = estateDataService; 756 m_EstateDataService = estateDataService;
737 m_regionHandle = RegionInfo.RegionHandle; 757 m_regionHandle = RegionInfo.RegionHandle;
758 m_lastIncoming = 0;
759 m_lastOutgoing = 0;
738 760
739 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 761 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
740 m_asyncSceneObjectDeleter.Enabled = true; 762 m_asyncSceneObjectDeleter.Enabled = true;
@@ -828,7 +850,7 @@ namespace OpenSim.Region.Framework.Scenes
828 850
829 StartDisabled = startupConfig.GetBoolean("StartDisabled", false); 851 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
830 852
831 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance); 853 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
832 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup); 854 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup);
833 if (!UseBackup) 855 if (!UseBackup)
834 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName); 856 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
@@ -836,10 +858,8 @@ namespace OpenSim.Region.Framework.Scenes
836 //Animation states 858 //Animation states
837 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 859 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
838 860
839 MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20); 861 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
840 862 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
841 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims);
842 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims);
843 863
844 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys); 864 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
845 if (RegionInfo.NonphysPrimMin > 0) 865 if (RegionInfo.NonphysPrimMin > 0)
@@ -860,11 +880,21 @@ namespace OpenSim.Region.Framework.Scenes
860 } 880 }
861 881
862 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 882 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
883
863 if (RegionInfo.PhysPrimMax > 0) 884 if (RegionInfo.PhysPrimMax > 0)
864 { 885 {
865 m_maxPhys = RegionInfo.PhysPrimMax; 886 m_maxPhys = RegionInfo.PhysPrimMax;
866 } 887 }
867 888
889 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity);
890 if (RegionInfo.LinksetCapacity > 0)
891 {
892 m_linksetCapacity = RegionInfo.LinksetCapacity;
893 }
894
895 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
896 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
897
868 // Here, if clamping is requested in either global or 898 // Here, if clamping is requested in either global or
869 // local config, it will be used 899 // local config, it will be used
870 // 900 //
@@ -874,13 +904,7 @@ namespace OpenSim.Region.Framework.Scenes
874 m_clampPrimSize = true; 904 m_clampPrimSize = true;
875 } 905 }
876 906
877 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); 907 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
878 if (RegionInfo.LinksetCapacity > 0)
879 {
880 m_linksetCapacity = RegionInfo.LinksetCapacity;
881 }
882
883 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete);
884 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 908 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
885 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 909 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
886 m_dontPersistBefore = 910 m_dontPersistBefore =
@@ -891,11 +915,11 @@ namespace OpenSim.Region.Framework.Scenes
891 m_persistAfter *= 10000000; 915 m_persistAfter *= 10000000;
892 916
893 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 917 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
894 918 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
895 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
896 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
897 919
898 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 920 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
921 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
922 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
899 923
900 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 924 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
901 if (m_generateMaptiles) 925 if (m_generateMaptiles)
@@ -928,7 +952,7 @@ namespace OpenSim.Region.Framework.Scenes
928 string grant = startupConfig.GetString("AllowedClients", String.Empty); 952 string grant = startupConfig.GetString("AllowedClients", String.Empty);
929 if (grant.Length > 0) 953 if (grant.Length > 0)
930 { 954 {
931 foreach (string viewer in grant.Split('|')) 955 foreach (string viewer in grant.Split(','))
932 { 956 {
933 m_AllowedViewers.Add(viewer.Trim().ToLower()); 957 m_AllowedViewers.Add(viewer.Trim().ToLower());
934 } 958 }
@@ -937,7 +961,7 @@ namespace OpenSim.Region.Framework.Scenes
937 grant = startupConfig.GetString("BannedClients", String.Empty); 961 grant = startupConfig.GetString("BannedClients", String.Empty);
938 if (grant.Length > 0) 962 if (grant.Length > 0)
939 { 963 {
940 foreach (string viewer in grant.Split('|')) 964 foreach (string viewer in grant.Split(','))
941 { 965 {
942 m_BannedViewers.Add(viewer.Trim().ToLower()); 966 m_BannedViewers.Add(viewer.Trim().ToLower());
943 } 967 }
@@ -997,6 +1021,8 @@ namespace OpenSim.Region.Framework.Scenes
997 StatsReporter = new SimStatsReporter(this); 1021 StatsReporter = new SimStatsReporter(this);
998 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 1022 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
999 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 1023 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
1024
1025 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
1000 } 1026 }
1001 1027
1002 public Scene(RegionInfo regInfo) : base(regInfo) 1028 public Scene(RegionInfo regInfo) : base(regInfo)
@@ -1292,8 +1318,11 @@ namespace OpenSim.Region.Framework.Scenes
1292 // Stop all client threads. 1318 // Stop all client threads.
1293 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); }); 1319 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); });
1294 1320
1295 m_log.Debug("[SCENE]: Persisting changed objects"); 1321 m_log.Debug("[SCENE]: TriggerSceneShuttingDown");
1296 EventManager.TriggerSceneShuttingDown(this); 1322 EventManager.TriggerSceneShuttingDown(this);
1323
1324 m_log.Debug("[SCENE]: Persisting changed objects");
1325
1297 Backup(false); 1326 Backup(false);
1298 m_sceneGraph.Close(); 1327 m_sceneGraph.Close();
1299 1328
@@ -1307,6 +1336,7 @@ namespace OpenSim.Region.Framework.Scenes
1307 // attempt to reference a null or disposed physics scene. 1336 // attempt to reference a null or disposed physics scene.
1308 if (PhysicsScene != null) 1337 if (PhysicsScene != null)
1309 { 1338 {
1339 m_log.Debug("[SCENE]: Dispose Physics");
1310 PhysicsScene phys = PhysicsScene; 1340 PhysicsScene phys = PhysicsScene;
1311 // remove the physics engine from both Scene and SceneGraph 1341 // remove the physics engine from both Scene and SceneGraph
1312 PhysicsScene = null; 1342 PhysicsScene = null;
@@ -1329,11 +1359,29 @@ namespace OpenSim.Region.Framework.Scenes
1329 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1359 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1330 if (m_heartbeatThread != null) 1360 if (m_heartbeatThread != null)
1331 { 1361 {
1362 m_hbRestarts++;
1363 if(m_hbRestarts > 10)
1364 Environment.Exit(1);
1365 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1366
1367//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1368//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1369//proc.EnableRaisingEvents=false;
1370//proc.StartInfo.FileName = "/bin/kill";
1371//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1372//proc.Start();
1373//proc.WaitForExit();
1374//Thread.Sleep(1000);
1375//Environment.Exit(1);
1332 m_heartbeatThread.Abort(); 1376 m_heartbeatThread.Abort();
1377 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1333 m_heartbeatThread = null; 1378 m_heartbeatThread = null;
1334 } 1379 }
1335// m_lastUpdate = Util.EnvironmentTickCount(); 1380// m_lastUpdate = Util.EnvironmentTickCount();
1336 1381
1382// m_sceneGraph.PreparePhysicsSimulation();
1383
1384
1337 m_heartbeatThread 1385 m_heartbeatThread
1338 = Watchdog.StartThread( 1386 = Watchdog.StartThread(
1339 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false); 1387 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false);
@@ -1476,16 +1524,20 @@ namespace OpenSim.Region.Framework.Scenes
1476 endFrame = Frame + frames; 1524 endFrame = Frame + frames;
1477 1525
1478 float physicsFPS = 0f; 1526 float physicsFPS = 0f;
1479 int previousFrameTick, tmpMS; 1527 int tmpMS;
1480 int maintc = Util.EnvironmentTickCount(); 1528 int previousFrameTick;
1529 int maintc;
1530 int sleepMS;
1531 int framestart;
1481 1532
1482 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) 1533 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
1483 { 1534 {
1535 framestart = Util.EnvironmentTickCount();
1484 ++Frame; 1536 ++Frame;
1485 1537
1486// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1538// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1487 1539
1488 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1540 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1489 1541
1490 try 1542 try
1491 { 1543 {
@@ -1537,6 +1589,7 @@ namespace OpenSim.Region.Framework.Scenes
1537 m_sceneGraph.UpdatePresences(); 1589 m_sceneGraph.UpdatePresences();
1538 1590
1539 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1591 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1592
1540 1593
1541 // Delete temp-on-rez stuff 1594 // Delete temp-on-rez stuff
1542 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1595 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
@@ -1618,34 +1671,37 @@ namespace OpenSim.Region.Framework.Scenes
1618 1671
1619 Watchdog.UpdateThread(); 1672 Watchdog.UpdateThread();
1620 1673
1674 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1675
1676 StatsReporter.AddPhysicsFPS(physicsFPS);
1677 StatsReporter.AddTimeDilation(TimeDilation);
1678 StatsReporter.AddFPS(1);
1679
1680 StatsReporter.addAgentMS(agentMS);
1681 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1682 StatsReporter.addOtherMS(otherMS);
1683 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1684
1621 previousFrameTick = m_lastFrameTick; 1685 previousFrameTick = m_lastFrameTick;
1622 m_lastFrameTick = Util.EnvironmentTickCount(); 1686 m_lastFrameTick = Util.EnvironmentTickCount();
1623 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1687 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
1624 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1688 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1625 1689
1690 m_firstHeartbeat = false;
1691
1692 sleepMS = Util.EnvironmentTickCount();
1693
1626 if (tmpMS > 0) 1694 if (tmpMS > 0)
1627 {
1628 Thread.Sleep(tmpMS); 1695 Thread.Sleep(tmpMS);
1629 spareMS += tmpMS;
1630 }
1631
1632 frameMS = Util.EnvironmentTickCountSubtract(maintc);
1633 maintc = Util.EnvironmentTickCount();
1634 1696
1635 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; 1697 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1698 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1699 StatsReporter.addSleepMS(sleepMS);
1700 StatsReporter.addFrameMS(frameMS);
1636 1701
1637 // if (Frame%m_update_avatars == 0) 1702 // if (Frame%m_update_avatars == 0)
1638 // UpdateInWorldTime(); 1703 // UpdateInWorldTime();
1639 StatsReporter.AddPhysicsFPS(physicsFPS);
1640 StatsReporter.AddTimeDilation(TimeDilation);
1641 StatsReporter.AddFPS(1);
1642 1704
1643 StatsReporter.addFrameMS(frameMS);
1644 StatsReporter.addAgentMS(agentMS);
1645 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1646 StatsReporter.addOtherMS(otherMS);
1647 StatsReporter.AddSpareMS(spareMS);
1648 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1649 1705
1650 // Optionally warn if a frame takes double the amount of time that it should. 1706 // Optionally warn if a frame takes double the amount of time that it should.
1651 if (DebugUpdates 1707 if (DebugUpdates
@@ -1662,7 +1718,7 @@ namespace OpenSim.Region.Framework.Scenes
1662 public void AddGroupTarget(SceneObjectGroup grp) 1718 public void AddGroupTarget(SceneObjectGroup grp)
1663 { 1719 {
1664 lock (m_groupsWithTargets) 1720 lock (m_groupsWithTargets)
1665 m_groupsWithTargets[grp.UUID] = grp; 1721 m_groupsWithTargets[grp.UUID] = 0;
1666 } 1722 }
1667 1723
1668 public void RemoveGroupTarget(SceneObjectGroup grp) 1724 public void RemoveGroupTarget(SceneObjectGroup grp)
@@ -1673,18 +1729,24 @@ namespace OpenSim.Region.Framework.Scenes
1673 1729
1674 private void CheckAtTargets() 1730 private void CheckAtTargets()
1675 { 1731 {
1676 List<SceneObjectGroup> objs = null; 1732 List<UUID> objs = null;
1677 1733
1678 lock (m_groupsWithTargets) 1734 lock (m_groupsWithTargets)
1679 { 1735 {
1680 if (m_groupsWithTargets.Count != 0) 1736 if (m_groupsWithTargets.Count != 0)
1681 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values); 1737 objs = new List<UUID>(m_groupsWithTargets.Keys);
1682 } 1738 }
1683 1739
1684 if (objs != null) 1740 if (objs != null)
1685 { 1741 {
1686 foreach (SceneObjectGroup entry in objs) 1742 foreach (UUID entry in objs)
1687 entry.checkAtTargets(); 1743 {
1744 SceneObjectGroup grp = GetSceneObjectGroup(entry);
1745 if (grp == null)
1746 m_groupsWithTargets.Remove(entry);
1747 else
1748 grp.checkAtTargets();
1749 }
1688 } 1750 }
1689 } 1751 }
1690 1752
@@ -1763,7 +1825,7 @@ namespace OpenSim.Region.Framework.Scenes
1763 msg.fromAgentName = "Server"; 1825 msg.fromAgentName = "Server";
1764 msg.dialog = (byte)19; // Object msg 1826 msg.dialog = (byte)19; // Object msg
1765 msg.fromGroup = false; 1827 msg.fromGroup = false;
1766 msg.offline = (byte)0; 1828 msg.offline = (byte)1;
1767 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1829 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1768 msg.Position = Vector3.Zero; 1830 msg.Position = Vector3.Zero;
1769 msg.RegionID = RegionInfo.RegionID.Guid; 1831 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1992,7 +2054,7 @@ namespace OpenSim.Region.Framework.Scenes
1992 return PhysicsScene.SupportsRaycastWorldFiltered(); 2054 return PhysicsScene.SupportsRaycastWorldFiltered();
1993 } 2055 }
1994 2056
1995 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) 2057 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
1996 { 2058 {
1997 if (PhysicsScene == null) 2059 if (PhysicsScene == null)
1998 return null; 2060 return null;
@@ -2014,14 +2076,24 @@ namespace OpenSim.Region.Framework.Scenes
2014 /// <returns></returns> 2076 /// <returns></returns>
2015 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2077 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
2016 { 2078 {
2079
2080 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2081 Vector3 wpos = Vector3.Zero;
2082 // Check for water surface intersection from above
2083 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2084 {
2085 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2086 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2087 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2088 wpos.Z = wheight;
2089 }
2090
2017 Vector3 pos = Vector3.Zero; 2091 Vector3 pos = Vector3.Zero;
2018 if (RayEndIsIntersection == (byte)1) 2092 if (RayEndIsIntersection == (byte)1)
2019 { 2093 {
2020 pos = RayEnd; 2094 pos = RayEnd;
2021 return pos;
2022 } 2095 }
2023 2096 else if (RayTargetID != UUID.Zero)
2024 if (RayTargetID != UUID.Zero)
2025 { 2097 {
2026 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2098 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
2027 2099
@@ -2043,7 +2115,7 @@ namespace OpenSim.Region.Framework.Scenes
2043 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 2115 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
2044 2116
2045 // Un-comment out the following line to Get Raytrace results printed to the console. 2117 // Un-comment out the following line to Get Raytrace results printed to the console.
2046 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 2118 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
2047 float ScaleOffset = 0.5f; 2119 float ScaleOffset = 0.5f;
2048 2120
2049 // If we hit something 2121 // If we hit something
@@ -2066,13 +2138,10 @@ namespace OpenSim.Region.Framework.Scenes
2066 //pos.Z -= 0.25F; 2138 //pos.Z -= 0.25F;
2067 2139
2068 } 2140 }
2069
2070 return pos;
2071 } 2141 }
2072 else 2142 else
2073 { 2143 {
2074 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2144 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2075
2076 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2145 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2077 2146
2078 // Un-comment the following line to print the raytrace results to the console. 2147 // Un-comment the following line to print the raytrace results to the console.
@@ -2081,13 +2150,12 @@ namespace OpenSim.Region.Framework.Scenes
2081 if (ei.HitTF) 2150 if (ei.HitTF)
2082 { 2151 {
2083 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2152 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2084 } else 2153 }
2154 else
2085 { 2155 {
2086 // fall back to our stupid functionality 2156 // fall back to our stupid functionality
2087 pos = RayEnd; 2157 pos = RayEnd;
2088 } 2158 }
2089
2090 return pos;
2091 } 2159 }
2092 } 2160 }
2093 else 2161 else
@@ -2098,8 +2166,12 @@ namespace OpenSim.Region.Framework.Scenes
2098 //increase height so its above the ground. 2166 //increase height so its above the ground.
2099 //should be getting the normal of the ground at the rez point and using that? 2167 //should be getting the normal of the ground at the rez point and using that?
2100 pos.Z += scale.Z / 2f; 2168 pos.Z += scale.Z / 2f;
2101 return pos; 2169// return pos;
2102 } 2170 }
2171
2172 // check against posible water intercept
2173 if (wpos.Z > pos.Z) pos = wpos;
2174 return pos;
2103 } 2175 }
2104 2176
2105 2177
@@ -2190,12 +2262,12 @@ namespace OpenSim.Region.Framework.Scenes
2190 { 2262 {
2191 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates)) 2263 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates))
2192 { 2264 {
2265 sceneObject.IsDeleted = false;
2193 EventManager.TriggerObjectAddedToScene(sceneObject); 2266 EventManager.TriggerObjectAddedToScene(sceneObject);
2194 return true; 2267 return true;
2195 } 2268 }
2196 2269
2197 return false; 2270 return false;
2198
2199 } 2271 }
2200 2272
2201 /// <summary> 2273 /// <summary>
@@ -2287,6 +2359,15 @@ namespace OpenSim.Region.Framework.Scenes
2287 /// </summary> 2359 /// </summary>
2288 public void DeleteAllSceneObjects() 2360 public void DeleteAllSceneObjects()
2289 { 2361 {
2362 DeleteAllSceneObjects(false);
2363 }
2364
2365 /// <summary>
2366 /// Delete every object from the scene. This does not include attachments worn by avatars.
2367 /// </summary>
2368 public void DeleteAllSceneObjects(bool exceptNoCopy)
2369 {
2370 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2290 lock (Entities) 2371 lock (Entities)
2291 { 2372 {
2292 EntityBase[] entities = Entities.GetEntities(); 2373 EntityBase[] entities = Entities.GetEntities();
@@ -2295,11 +2376,24 @@ namespace OpenSim.Region.Framework.Scenes
2295 if (e is SceneObjectGroup) 2376 if (e is SceneObjectGroup)
2296 { 2377 {
2297 SceneObjectGroup sog = (SceneObjectGroup)e; 2378 SceneObjectGroup sog = (SceneObjectGroup)e;
2298 if (!sog.IsAttachment) 2379 if (sog != null && !sog.IsAttachment)
2299 DeleteSceneObject((SceneObjectGroup)e, false); 2380 {
2381 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2382 {
2383 DeleteSceneObject((SceneObjectGroup)e, false);
2384 }
2385 else
2386 {
2387 toReturn.Add((SceneObjectGroup)e);
2388 }
2389 }
2300 } 2390 }
2301 } 2391 }
2302 } 2392 }
2393 if (toReturn.Count > 0)
2394 {
2395 returnObjects(toReturn.ToArray(), UUID.Zero);
2396 }
2303 } 2397 }
2304 2398
2305 /// <summary> 2399 /// <summary>
@@ -2334,6 +2428,12 @@ namespace OpenSim.Region.Framework.Scenes
2334 2428
2335 foreach (SceneObjectPart part in partList) 2429 foreach (SceneObjectPart part in partList)
2336 { 2430 {
2431 if (part.KeyframeMotion != null)
2432 {
2433 part.KeyframeMotion.Delete();
2434 part.KeyframeMotion = null;
2435 }
2436
2337 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0)) 2437 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
2338 { 2438 {
2339 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? 2439 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
@@ -2351,6 +2451,8 @@ namespace OpenSim.Region.Framework.Scenes
2351 } 2451 }
2352 2452
2353 group.DeleteGroupFromScene(silent); 2453 group.DeleteGroupFromScene(silent);
2454 if (!silent)
2455 SendKillObject(new List<uint>() { group.LocalId });
2354 2456
2355// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2457// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2356 } 2458 }
@@ -2641,7 +2743,7 @@ namespace OpenSim.Region.Framework.Scenes
2641 // If the user is banned, we won't let any of their objects 2743 // If the user is banned, we won't let any of their objects
2642 // enter. Period. 2744 // enter. Period.
2643 // 2745 //
2644 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID)) 2746 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
2645 { 2747 {
2646 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID); 2748 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
2647 return false; 2749 return false;
@@ -2649,6 +2751,8 @@ namespace OpenSim.Region.Framework.Scenes
2649 2751
2650 if (newPosition != Vector3.Zero) 2752 if (newPosition != Vector3.Zero)
2651 newObject.RootPart.GroupPosition = newPosition; 2753 newObject.RootPart.GroupPosition = newPosition;
2754 if (newObject.RootPart.KeyframeMotion != null)
2755 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2652 2756
2653 if (!AddSceneObject(newObject)) 2757 if (!AddSceneObject(newObject))
2654 { 2758 {
@@ -2693,6 +2797,23 @@ namespace OpenSim.Region.Framework.Scenes
2693 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2797 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2694 public bool AddSceneObject(SceneObjectGroup sceneObject) 2798 public bool AddSceneObject(SceneObjectGroup sceneObject)
2695 { 2799 {
2800 if (sceneObject.OwnerID == UUID.Zero)
2801 {
2802 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2803 return false;
2804 }
2805
2806 // If the user is banned, we won't let any of their objects
2807 // enter. Period.
2808 //
2809 int flags = GetUserFlags(sceneObject.OwnerID);
2810 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2811 {
2812 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2813
2814 return false;
2815 }
2816
2696 // Force allocation of new LocalId 2817 // Force allocation of new LocalId
2697 // 2818 //
2698 SceneObjectPart[] parts = sceneObject.Parts; 2819 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2726,16 +2847,27 @@ namespace OpenSim.Region.Framework.Scenes
2726 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2847 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2727 2848
2728 if (AttachmentsModule != null) 2849 if (AttachmentsModule != null)
2729 AttachmentsModule.AttachObject(sp, grp, 0, false, false); 2850 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false);
2730 } 2851 }
2731 else 2852 else
2732 { 2853 {
2854 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2733 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2855 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2734 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2856 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2735 } 2857 }
2858 if (sceneObject.OwnerID == UUID.Zero)
2859 {
2860 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2861 return false;
2862 }
2736 } 2863 }
2737 else 2864 else
2738 { 2865 {
2866 if (sceneObject.OwnerID == UUID.Zero)
2867 {
2868 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2869 return false;
2870 }
2739 AddRestoredSceneObject(sceneObject, true, false); 2871 AddRestoredSceneObject(sceneObject, true, false);
2740 } 2872 }
2741 2873
@@ -2752,6 +2884,24 @@ namespace OpenSim.Region.Framework.Scenes
2752 return 2; // StateSource.PrimCrossing 2884 return 2; // StateSource.PrimCrossing
2753 } 2885 }
2754 2886
2887 public int GetUserFlags(UUID user)
2888 {
2889 //Unfortunately the SP approach means that the value is cached until region is restarted
2890 /*
2891 ScenePresence sp;
2892 if (TryGetScenePresence(user, out sp))
2893 {
2894 return sp.UserFlags;
2895 }
2896 else
2897 {
2898 */
2899 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2900 if (uac == null)
2901 return 0;
2902 return uac.UserFlags;
2903 //}
2904 }
2755 #endregion 2905 #endregion
2756 2906
2757 #region Add/Remove Avatar Methods 2907 #region Add/Remove Avatar Methods
@@ -2784,7 +2934,7 @@ namespace OpenSim.Region.Framework.Scenes
2784 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2934 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2785 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2935 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2786 2936
2787 // CheckHeartbeat(); 2937 CheckHeartbeat();
2788 2938
2789 sp = GetScenePresence(client.AgentId); 2939 sp = GetScenePresence(client.AgentId);
2790 2940
@@ -2802,6 +2952,13 @@ namespace OpenSim.Region.Framework.Scenes
2802 SubscribeToClientEvents(client); 2952 SubscribeToClientEvents(client);
2803 2953
2804 sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type); 2954 sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type);
2955 InventoryFolderBase cof = InventoryService.GetFolderForType(client.AgentId, (AssetType)46);
2956 if (cof == null)
2957 sp.COF = UUID.Zero;
2958 else
2959 sp.COF = cof.ID;
2960
2961 m_log.DebugFormat("[SCENE]: COF for {0} is {1}", client.AgentId, sp.COF);
2805 m_eventManager.TriggerOnNewPresence(sp); 2962 m_eventManager.TriggerOnNewPresence(sp);
2806 2963
2807 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags; 2964 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags;
@@ -2815,6 +2972,7 @@ namespace OpenSim.Region.Framework.Scenes
2815 // start the scripts again (since this is done in RezAttachments()). 2972 // start the scripts again (since this is done in RezAttachments()).
2816 // XXX: This is convoluted. 2973 // XXX: This is convoluted.
2817 sp.IsChildAgent = false; 2974 sp.IsChildAgent = false;
2975 sp.IsLoggingIn = true;
2818 2976
2819 if (AttachmentsModule != null) 2977 if (AttachmentsModule != null)
2820 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); }); 2978 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); });
@@ -2928,19 +3086,14 @@ namespace OpenSim.Region.Framework.Scenes
2928 // and the scene presence and the client, if they exist 3086 // and the scene presence and the client, if they exist
2929 try 3087 try
2930 { 3088 {
2931 // We need to wait for the client to make UDP contact first. 3089 ScenePresence sp = GetScenePresence(agentID);
2932 // It's the UDP contact that creates the scene presence 3090
2933 ScenePresence sp = WaitGetScenePresence(agentID);
2934 if (sp != null) 3091 if (sp != null)
2935 { 3092 {
2936 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3093 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2937
2938 sp.ControllingClient.Close(); 3094 sp.ControllingClient.Close();
2939 } 3095 }
2940 else 3096
2941 {
2942 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2943 }
2944 // BANG! SLASH! 3097 // BANG! SLASH!
2945 m_authenticateHandler.RemoveCircuit(agentID); 3098 m_authenticateHandler.RemoveCircuit(agentID);
2946 3099
@@ -2985,6 +3138,8 @@ namespace OpenSim.Region.Framework.Scenes
2985 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3138 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2986 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3139 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2987 3140
3141 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3142
2988 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3143 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2989 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3144 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2990 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3145 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -3041,6 +3196,7 @@ namespace OpenSim.Region.Framework.Scenes
3041 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3196 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
3042 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3197 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
3043 client.OnCopyInventoryItem += CopyInventoryItem; 3198 client.OnCopyInventoryItem += CopyInventoryItem;
3199 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
3044 client.OnMoveInventoryItem += MoveInventoryItem; 3200 client.OnMoveInventoryItem += MoveInventoryItem;
3045 client.OnRemoveInventoryItem += RemoveInventoryItem; 3201 client.OnRemoveInventoryItem += RemoveInventoryItem;
3046 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3202 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3112,6 +3268,8 @@ namespace OpenSim.Region.Framework.Scenes
3112 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3268 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3113 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3269 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3114 3270
3271 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3272
3115 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3273 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3116 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3274 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3117 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3275 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3214,7 +3372,7 @@ namespace OpenSim.Region.Framework.Scenes
3214 /// </summary> 3372 /// </summary>
3215 /// <param name="agentId">The avatar's Unique ID</param> 3373 /// <param name="agentId">The avatar's Unique ID</param>
3216 /// <param name="client">The IClientAPI for the client</param> 3374 /// <param name="client">The IClientAPI for the client</param>
3217 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3375 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3218 { 3376 {
3219 if (EntityTransferModule != null) 3377 if (EntityTransferModule != null)
3220 { 3378 {
@@ -3225,6 +3383,7 @@ namespace OpenSim.Region.Framework.Scenes
3225 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3383 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3226 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3384 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3227 } 3385 }
3386 return false;
3228 } 3387 }
3229 3388
3230 /// <summary> 3389 /// <summary>
@@ -3334,6 +3493,16 @@ namespace OpenSim.Region.Framework.Scenes
3334 /// <param name="flags"></param> 3493 /// <param name="flags"></param>
3335 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3494 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3336 { 3495 {
3496 //Add half the avatar's height so that the user doesn't fall through prims
3497 ScenePresence presence;
3498 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3499 {
3500 if (presence.Appearance != null)
3501 {
3502 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3503 }
3504 }
3505
3337 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3506 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3338 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3507 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3339 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3508 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3471,6 +3640,7 @@ namespace OpenSim.Region.Framework.Scenes
3471 // It's possible for child agents to have transactions if changes are being made cross-border. 3640 // It's possible for child agents to have transactions if changes are being made cross-border.
3472 if (AgentTransactionsModule != null) 3641 if (AgentTransactionsModule != null)
3473 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 3642 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3643 m_log.Debug("[Scene] The avatar has left the building");
3474 } 3644 }
3475 catch (Exception e) 3645 catch (Exception e)
3476 { 3646 {
@@ -3663,38 +3833,39 @@ namespace OpenSim.Region.Framework.Scenes
3663 agent.firstname, agent.lastname, agent.Viewer); 3833 agent.firstname, agent.lastname, agent.Viewer);
3664 reason = "Access denied, your viewer is banned by the region owner"; 3834 reason = "Access denied, your viewer is banned by the region owner";
3665 return false; 3835 return false;
3666 } 3836 }
3837
3838
3839 ScenePresence sp = GetScenePresence(agent.AgentID);
3667 3840
3668 ILandObject land; 3841 if (sp != null && !sp.IsChildAgent)
3842 {
3843 // We have a zombie from a crashed session.
3844 // Or the same user is trying to be root twice here, won't work.
3845 // Kill it.
3846 m_log.WarnFormat(
3847 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3848 sp.Name, sp.UUID, RegionInfo.RegionName);
3849
3850 sp.ControllingClient.Close(true, true);
3851 sp = null;
3852 }
3669 3853
3670 lock (agent) 3854 lock (agent)
3671 { 3855 {
3672 ScenePresence sp = GetScenePresence(agent.AgentID);
3673
3674 if (sp != null && !sp.IsChildAgent)
3675 {
3676 // We have a zombie from a crashed session.
3677 // Or the same user is trying to be root twice here, won't work.
3678 // Kill it.
3679 m_log.WarnFormat(
3680 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3681 sp.Name, sp.UUID, RegionInfo.RegionName);
3682
3683 sp.ControllingClient.Close(true);
3684 sp = null;
3685 }
3686
3687 land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3688
3689 //On login test land permisions 3856 //On login test land permisions
3690 if (vialogin) 3857 if (vialogin)
3691 { 3858 {
3692 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3859 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3860 if (cache != null)
3861 cache.Remove(agent.firstname + " " + agent.lastname);
3862 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3693 { 3863 {
3864 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3694 return false; 3865 return false;
3695 } 3866 }
3696 } 3867 }
3697 3868
3698 if (sp == null) // We don't have an [child] agent here already 3869 if (sp == null) // We don't have an [child] agent here already
3699 { 3870 {
3700 if (requirePresenceLookup) 3871 if (requirePresenceLookup)
@@ -3703,34 +3874,36 @@ namespace OpenSim.Region.Framework.Scenes
3703 { 3874 {
3704 if (!VerifyUserPresence(agent, out reason)) 3875 if (!VerifyUserPresence(agent, out reason))
3705 return false; 3876 return false;
3706 } 3877 } catch (Exception e)
3707 catch (Exception e)
3708 { 3878 {
3709 m_log.ErrorFormat( 3879 m_log.ErrorFormat(
3710 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace); 3880 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace);
3711
3712 return false; 3881 return false;
3713 } 3882 }
3714 } 3883 }
3715 3884
3716 try 3885 try
3717 { 3886 {
3718 if (!AuthorizeUser(agent, out reason)) 3887 // Always check estate if this is a login. Always
3719 return false; 3888 // check if banned regions are to be blacked out.
3889 if (vialogin || (!m_seeIntoBannedRegion))
3890 {
3891 if (!AuthorizeUser(agent, out reason))
3892 return false;
3893 }
3720 } 3894 }
3721 catch (Exception e) 3895 catch (Exception e)
3722 { 3896 {
3723 m_log.ErrorFormat( 3897 m_log.ErrorFormat(
3724 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3898 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
3725
3726 return false; 3899 return false;
3727 } 3900 }
3728 3901
3729 m_log.InfoFormat( 3902 m_log.InfoFormat(
3730 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})", 3903 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})",
3731 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname, 3904 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
3732 agent.AgentID, agent.circuitcode); 3905 agent.AgentID, agent.circuitcode);
3733 3906
3734 if (CapsModule != null) 3907 if (CapsModule != null)
3735 { 3908 {
3736 CapsModule.SetAgentCapsSeeds(agent); 3909 CapsModule.SetAgentCapsSeeds(agent);
@@ -3742,15 +3915,15 @@ namespace OpenSim.Region.Framework.Scenes
3742 // Let the SP know how we got here. This has a lot of interesting 3915 // Let the SP know how we got here. This has a lot of interesting
3743 // uses down the line. 3916 // uses down the line.
3744 sp.TeleportFlags = (TPFlags)teleportFlags; 3917 sp.TeleportFlags = (TPFlags)teleportFlags;
3745 3918
3746 if (sp.IsChildAgent) 3919 if (sp.IsChildAgent)
3747 { 3920 {
3748 m_log.DebugFormat( 3921 m_log.DebugFormat(
3749 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}", 3922 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
3750 agent.AgentID, RegionInfo.RegionName); 3923 agent.AgentID, RegionInfo.RegionName);
3751 3924
3752 sp.AdjustKnownSeeds(); 3925 sp.AdjustKnownSeeds();
3753 3926
3754 if (CapsModule != null) 3927 if (CapsModule != null)
3755 CapsModule.SetAgentCapsSeeds(agent); 3928 CapsModule.SetAgentCapsSeeds(agent);
3756 } 3929 }
@@ -3852,6 +4025,8 @@ namespace OpenSim.Region.Framework.Scenes
3852 } 4025 }
3853 4026
3854 // Honor parcel landing type and position. 4027 // Honor parcel landing type and position.
4028 /*
4029 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3855 if (land != null) 4030 if (land != null)
3856 { 4031 {
3857 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 4032 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3859,25 +4034,43 @@ namespace OpenSim.Region.Framework.Scenes
3859 agent.startpos = land.LandData.UserLocation; 4034 agent.startpos = land.LandData.UserLocation;
3860 } 4035 }
3861 } 4036 }
4037 */// This is now handled properly in ScenePresence.MakeRootAgent
3862 } 4038 }
3863 4039
3864 return true; 4040 return true;
3865 } 4041 }
3866 4042
3867 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 4043 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3868 { 4044 {
3869 bool banned = land.IsBannedFromLand(agent.AgentID); 4045 if (posX < 0)
3870 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 4046 posX = 0;
4047 else if (posX >= 256)
4048 posX = 255.999f;
4049 if (posY < 0)
4050 posY = 0;
4051 else if (posY >= 256)
4052 posY = 255.999f;
4053
4054 reason = String.Empty;
4055 if (Permissions.IsGod(agentID))
4056 return true;
4057
4058 ILandObject land = LandChannel.GetLandObject(posX, posY);
4059 if (land == null)
4060 return false;
4061
4062 bool banned = land.IsBannedFromLand(agentID);
4063 bool restricted = land.IsRestrictedFromLand(agentID);
3871 4064
3872 if (banned || restricted) 4065 if (banned || restricted)
3873 { 4066 {
3874 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 4067 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3875 if (nearestParcel != null) 4068 if (nearestParcel != null)
3876 { 4069 {
3877 //Move agent to nearest allowed 4070 //Move agent to nearest allowed
3878 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 4071 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3879 agent.startpos.X = newPosition.X; 4072 posX = newPosition.X;
3880 agent.startpos.Y = newPosition.Y; 4073 posY = newPosition.Y;
3881 } 4074 }
3882 else 4075 else
3883 { 4076 {
@@ -3939,7 +4132,7 @@ namespace OpenSim.Region.Framework.Scenes
3939 4132
3940 if (!m_strictAccessControl) return true; 4133 if (!m_strictAccessControl) return true;
3941 if (Permissions.IsGod(agent.AgentID)) return true; 4134 if (Permissions.IsGod(agent.AgentID)) return true;
3942 4135
3943 if (AuthorizationService != null) 4136 if (AuthorizationService != null)
3944 { 4137 {
3945 if (!AuthorizationService.IsAuthorizedForRegion( 4138 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3954,7 +4147,7 @@ namespace OpenSim.Region.Framework.Scenes
3954 4147
3955 if (RegionInfo.EstateSettings != null) 4148 if (RegionInfo.EstateSettings != null)
3956 { 4149 {
3957 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4150 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, 0))
3958 { 4151 {
3959 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4152 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3960 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4153 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4144,6 +4337,15 @@ namespace OpenSim.Region.Framework.Scenes
4144 4337
4145 // XPTO: if this agent is not allowed here as root, always return false 4338 // XPTO: if this agent is not allowed here as root, always return false
4146 4339
4340 // We have to wait until the viewer contacts this region after receiving EAC.
4341 // That calls AddNewClient, which finally creates the ScenePresence
4342 int flags = GetUserFlags(cAgentData.AgentID);
4343 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4344 {
4345 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4346 return false;
4347 }
4348
4147 // TODO: This check should probably be in QueryAccess(). 4349 // TODO: This check should probably be in QueryAccess().
4148 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4350 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4149 if (nearestParcel == null) 4351 if (nearestParcel == null)
@@ -4208,7 +4410,7 @@ namespace OpenSim.Region.Framework.Scenes
4208 /// <param name='agentID'></param> 4410 /// <param name='agentID'></param>
4209 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4411 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4210 { 4412 {
4211 int ntimes = 10; 4413 int ntimes = 30;
4212 ScenePresence sp = null; 4414 ScenePresence sp = null;
4213 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4415 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4214 Thread.Sleep(1000); 4416 Thread.Sleep(1000);
@@ -4238,6 +4440,16 @@ namespace OpenSim.Region.Framework.Scenes
4238 return false; 4440 return false;
4239 } 4441 }
4240 4442
4443 public bool IncomingCloseAgent(UUID agentID)
4444 {
4445 return IncomingCloseAgent(agentID, false);
4446 }
4447
4448 public bool IncomingCloseChildAgent(UUID agentID)
4449 {
4450 return IncomingCloseAgent(agentID, true);
4451 }
4452
4241 /// <summary> 4453 /// <summary>
4242 /// Tell a single agent to disconnect from the region. 4454 /// Tell a single agent to disconnect from the region.
4243 /// </summary> 4455 /// </summary>
@@ -4253,7 +4465,7 @@ namespace OpenSim.Region.Framework.Scenes
4253 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4465 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4254 if (presence != null) 4466 if (presence != null)
4255 { 4467 {
4256 presence.ControllingClient.Close(force); 4468 presence.ControllingClient.Close(force, force);
4257 return true; 4469 return true;
4258 } 4470 }
4259 4471
@@ -4886,7 +5098,7 @@ namespace OpenSim.Region.Framework.Scenes
4886 { 5098 {
4887 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 5099 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
4888 { 5100 {
4889 if (grp.RootPart.Expires <= DateTime.Now) 5101 if (grp.GetSittingAvatarsCount() == 0 && grp.RootPart.Expires <= DateTime.Now)
4890 DeleteSceneObject(grp, false); 5102 DeleteSceneObject(grp, false);
4891 } 5103 }
4892 } 5104 }
@@ -4900,35 +5112,81 @@ namespace OpenSim.Region.Framework.Scenes
4900 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5112 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
4901 } 5113 }
4902 5114
4903 public int GetHealth() 5115 public int GetHealth(out int flags, out string message)
4904 { 5116 {
4905 // Returns: 5117 // Returns:
4906 // 1 = sim is up and accepting http requests. The heartbeat has 5118 // 1 = sim is up and accepting http requests. The heartbeat has
4907 // stopped and the sim is probably locked up, but a remote 5119 // stopped and the sim is probably locked up, but a remote
4908 // admin restart may succeed 5120 // admin restart may succeed
4909 // 5121 //
4910 // 2 = Sim is up and the heartbeat is running. The sim is likely 5122 // 2 = Sim is up and the heartbeat is running. The sim is likely
4911 // usable for people within and logins _may_ work 5123 // usable for people within
5124 //
5125 // 3 = Sim is up and one packet thread is running. Sim is
5126 // unstable and will not accept new logins
4912 // 5127 //
4913 // 3 = We have seen a new user enter within the past 4 minutes 5128 // 4 = Sim is up and both packet threads are running. Sim is
5129 // likely usable
5130 //
5131 // 5 = We have seen a new user enter within the past 4 minutes
4914 // which can be seen as positive confirmation of sim health 5132 // which can be seen as positive confirmation of sim health
4915 // 5133 //
5134
5135 flags = 0;
5136 message = String.Empty;
5137
5138 CheckHeartbeat();
5139
5140 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5141 {
5142 // We're still starting
5143 // 0 means "in startup", it can't happen another way, since
5144 // to get here, we must be able to accept http connections
5145 return 0;
5146 }
5147
4916 int health=1; // Start at 1, means we're up 5148 int health=1; // Start at 1, means we're up
4917 5149
4918 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5150 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4919 health += 1; 5151 {
5152 health+=1;
5153 flags |= 1;
5154 }
5155
5156 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5157 {
5158 health+=1;
5159 flags |= 2;
5160 }
5161
5162 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5163 {
5164 health+=1;
5165 flags |= 4;
5166 }
4920 else 5167 else
5168 {
5169int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5170System.Diagnostics.Process proc = new System.Diagnostics.Process();
5171proc.EnableRaisingEvents=false;
5172proc.StartInfo.FileName = "/bin/kill";
5173proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5174proc.Start();
5175proc.WaitForExit();
5176Thread.Sleep(1000);
5177Environment.Exit(1);
5178 }
5179
5180 if (flags != 7)
4921 return health; 5181 return health;
4922 5182
4923 // A login in the last 4 mins? We can't be doing too badly 5183 // A login in the last 4 mins? We can't be doing too badly
4924 // 5184 //
4925 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5185 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4926 health++; 5186 health++;
4927 else 5187 else
4928 return health; 5188 return health;
4929 5189
4930// CheckHeartbeat();
4931
4932 return health; 5190 return health;
4933 } 5191 }
4934 5192
@@ -5016,7 +5274,7 @@ namespace OpenSim.Region.Framework.Scenes
5016 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 5274 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
5017 if (wasUsingPhysics) 5275 if (wasUsingPhysics)
5018 { 5276 {
5019 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 5277 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
5020 } 5278 }
5021 } 5279 }
5022 5280
@@ -5115,14 +5373,14 @@ namespace OpenSim.Region.Framework.Scenes
5115 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5373 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5116 } 5374 }
5117 5375
5118// private void CheckHeartbeat() 5376 private void CheckHeartbeat()
5119// { 5377 {
5120// if (m_firstHeartbeat) 5378 if (m_firstHeartbeat)
5121// return; 5379 return;
5122// 5380
5123// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5381 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5124// StartTimer(); 5382 Start();
5125// } 5383 }
5126 5384
5127 public override ISceneObject DeserializeObject(string representation) 5385 public override ISceneObject DeserializeObject(string representation)
5128 { 5386 {
@@ -5134,9 +5392,14 @@ namespace OpenSim.Region.Framework.Scenes
5134 get { return m_allowScriptCrossings; } 5392 get { return m_allowScriptCrossings; }
5135 } 5393 }
5136 5394
5137 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5395 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5396 {
5397 return GetNearestAllowedPosition(avatar, null);
5398 }
5399
5400 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5138 { 5401 {
5139 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5402 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
5140 5403
5141 if (nearestParcel != null) 5404 if (nearestParcel != null)
5142 { 5405 {
@@ -5145,10 +5408,7 @@ namespace OpenSim.Region.Framework.Scenes
5145 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5408 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5146 if (nearestPoint != null) 5409 if (nearestPoint != null)
5147 { 5410 {
5148// m_log.DebugFormat( 5411 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
5149// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
5150// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
5151
5152 return nearestPoint.Value; 5412 return nearestPoint.Value;
5153 } 5413 }
5154 5414
@@ -5158,17 +5418,20 @@ namespace OpenSim.Region.Framework.Scenes
5158 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5418 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5159 if (nearestPoint != null) 5419 if (nearestPoint != null)
5160 { 5420 {
5161// m_log.DebugFormat( 5421 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
5162// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
5163
5164 return nearestPoint.Value; 5422 return nearestPoint.Value;
5165 } 5423 }
5166 5424
5167 //Ultimate backup if we have no idea where they are 5425 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
5168// m_log.DebugFormat( 5426 if (dest != excludeParcel)
5169// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5427 {
5428 // Ultimate backup if we have no idea where they are and
5429 // the last allowed position was in another parcel
5430 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5431 return avatar.lastKnownAllowedPosition;
5432 }
5170 5433
5171 return avatar.lastKnownAllowedPosition; 5434 // else fall through to region edge
5172 } 5435 }
5173 5436
5174 //Go to the edge, this happens in teleporting to a region with no available parcels 5437 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -5202,13 +5465,18 @@ namespace OpenSim.Region.Framework.Scenes
5202 5465
5203 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5466 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5204 { 5467 {
5468 return GetNearestAllowedParcel(avatarId, x, y, null);
5469 }
5470
5471 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5472 {
5205 List<ILandObject> all = AllParcels(); 5473 List<ILandObject> all = AllParcels();
5206 float minParcelDistance = float.MaxValue; 5474 float minParcelDistance = float.MaxValue;
5207 ILandObject nearestParcel = null; 5475 ILandObject nearestParcel = null;
5208 5476
5209 foreach (var parcel in all) 5477 foreach (var parcel in all)
5210 { 5478 {
5211 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5479 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
5212 { 5480 {
5213 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5481 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5214 if (parcelDistance < minParcelDistance) 5482 if (parcelDistance < minParcelDistance)
@@ -5424,7 +5692,55 @@ namespace OpenSim.Region.Framework.Scenes
5424 mapModule.GenerateMaptile(); 5692 mapModule.GenerateMaptile();
5425 } 5693 }
5426 5694
5427 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5695// public void CleanDroppedAttachments()
5696// {
5697// List<SceneObjectGroup> objectsToDelete =
5698// new List<SceneObjectGroup>();
5699//
5700// lock (m_cleaningAttachments)
5701// {
5702// ForEachSOG(delegate (SceneObjectGroup grp)
5703// {
5704// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5705// {
5706// UUID agentID = grp.OwnerID;
5707// if (agentID == UUID.Zero)
5708// {
5709// objectsToDelete.Add(grp);
5710// return;
5711// }
5712//
5713// ScenePresence sp = GetScenePresence(agentID);
5714// if (sp == null)
5715// {
5716// objectsToDelete.Add(grp);
5717// return;
5718// }
5719// }
5720// });
5721// }
5722//
5723// foreach (SceneObjectGroup grp in objectsToDelete)
5724// {
5725// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5726// DeleteSceneObject(grp, true);
5727// }
5728// }
5729
5730 public void ThreadAlive(int threadCode)
5731 {
5732 switch(threadCode)
5733 {
5734 case 1: // Incoming
5735 m_lastIncoming = Util.EnvironmentTickCount();
5736 break;
5737 case 2: // Incoming
5738 m_lastOutgoing = Util.EnvironmentTickCount();
5739 break;
5740 }
5741 }
5742
5743 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5428 { 5744 {
5429 RegenerateMaptile(); 5745 RegenerateMaptile();
5430 5746
@@ -5452,6 +5768,8 @@ namespace OpenSim.Region.Framework.Scenes
5452 /// <returns></returns> 5768 /// <returns></returns>
5453 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5769 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5454 { 5770 {
5771 reason = "You are banned from the region";
5772
5455 if (EntityTransferModule.IsInTransit(agentID)) 5773 if (EntityTransferModule.IsInTransit(agentID))
5456 { 5774 {
5457 reason = "Agent is still in transit from this region"; 5775 reason = "Agent is still in transit from this region";
@@ -5463,6 +5781,12 @@ namespace OpenSim.Region.Framework.Scenes
5463 return false; 5781 return false;
5464 } 5782 }
5465 5783
5784 if (Permissions.IsGod(agentID))
5785 {
5786 reason = String.Empty;
5787 return true;
5788 }
5789
5466 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5790 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5467 // However, the long term fix is to make sure root agent count is always accurate. 5791 // However, the long term fix is to make sure root agent count is always accurate.
5468 m_sceneGraph.RecalculateStats(); 5792 m_sceneGraph.RecalculateStats();
@@ -5483,6 +5807,41 @@ namespace OpenSim.Region.Framework.Scenes
5483 } 5807 }
5484 } 5808 }
5485 5809
5810 ScenePresence presence = GetScenePresence(agentID);
5811 IClientAPI client = null;
5812 AgentCircuitData aCircuit = null;
5813
5814 if (presence != null)
5815 {
5816 client = presence.ControllingClient;
5817 if (client != null)
5818 aCircuit = client.RequestClientInfo();
5819 }
5820
5821 // We may be called before there is a presence or a client.
5822 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5823 if (client == null)
5824 {
5825 aCircuit = new AgentCircuitData();
5826 aCircuit.AgentID = agentID;
5827 aCircuit.firstname = String.Empty;
5828 aCircuit.lastname = String.Empty;
5829 }
5830
5831 try
5832 {
5833 if (!AuthorizeUser(aCircuit, out reason))
5834 {
5835 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5836 return false;
5837 }
5838 }
5839 catch (Exception e)
5840 {
5841 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5842 return false;
5843 }
5844
5486 if (position == Vector3.Zero) // Teleport 5845 if (position == Vector3.Zero) // Teleport
5487 { 5846 {
5488 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5847 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5516,13 +5875,46 @@ namespace OpenSim.Region.Framework.Scenes
5516 } 5875 }
5517 } 5876 }
5518 } 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;
5519 } 5899 }
5520 5900
5521 reason = String.Empty; 5901 reason = String.Empty;
5522 return true; 5902 return true;
5523 } 5903 }
5524 5904
5525 /// <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
5526 /// 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
5527 /// autopilot that moves an avatar to a sit target!. 5919 /// autopilot that moves an avatar to a sit target!.
5528 /// </summary> 5920 /// </summary>
@@ -5601,6 +5993,11 @@ namespace OpenSim.Region.Framework.Scenes
5601 return m_SpawnPoint - 1; 5993 return m_SpawnPoint - 1;
5602 } 5994 }
5603 5995
5996 private void HandleGcCollect(string module, string[] args)
5997 {
5998 GC.Collect();
5999 }
6000
5604 /// <summary> 6001 /// <summary>
5605 /// Wrappers to get physics modules retrieve assets. 6002 /// Wrappers to get physics modules retrieve assets.
5606 /// </summary> 6003 /// </summary>