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.cs700
1 files changed, 545 insertions, 155 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index f8d84e3..6d50c13 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
@@ -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;
@@ -831,7 +853,7 @@ namespace OpenSim.Region.Framework.Scenes
831 853
832 StartDisabled = startupConfig.GetBoolean("StartDisabled", false); 854 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
833 855
834 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance); 856 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance",m_defaultDrawDistance);
835 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup); 857 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup);
836 if (!UseBackup) 858 if (!UseBackup)
837 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName); 859 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
@@ -839,10 +861,8 @@ namespace OpenSim.Region.Framework.Scenes
839 //Animation states 861 //Animation states
840 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 862 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
841 863
842 MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20); 864 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
843 865 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
844 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims);
845 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims);
846 866
847 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys); 867 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
848 if (RegionInfo.NonphysPrimMin > 0) 868 if (RegionInfo.NonphysPrimMin > 0)
@@ -863,11 +883,21 @@ namespace OpenSim.Region.Framework.Scenes
863 } 883 }
864 884
865 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 885 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
886
866 if (RegionInfo.PhysPrimMax > 0) 887 if (RegionInfo.PhysPrimMax > 0)
867 { 888 {
868 m_maxPhys = RegionInfo.PhysPrimMax; 889 m_maxPhys = RegionInfo.PhysPrimMax;
869 } 890 }
870 891
892 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity);
893 if (RegionInfo.LinksetCapacity > 0)
894 {
895 m_linksetCapacity = RegionInfo.LinksetCapacity;
896 }
897
898 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
899 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
900
871 // Here, if clamping is requested in either global or 901 // Here, if clamping is requested in either global or
872 // local config, it will be used 902 // local config, it will be used
873 // 903 //
@@ -877,13 +907,7 @@ namespace OpenSim.Region.Framework.Scenes
877 m_clampPrimSize = true; 907 m_clampPrimSize = true;
878 } 908 }
879 909
880 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); 910 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
881 if (RegionInfo.LinksetCapacity > 0)
882 {
883 m_linksetCapacity = RegionInfo.LinksetCapacity;
884 }
885
886 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete);
887 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 911 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
888 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 912 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
889 m_dontPersistBefore = 913 m_dontPersistBefore =
@@ -894,11 +918,11 @@ namespace OpenSim.Region.Framework.Scenes
894 m_persistAfter *= 10000000; 918 m_persistAfter *= 10000000;
895 919
896 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 920 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
897 921 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
898 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
899 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
900 922
901 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 923 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
924 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
925 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
902 926
903 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true); 927 m_generateMaptiles = startupConfig.GetBoolean("GenerateMaptiles", true);
904 if (m_generateMaptiles) 928 if (m_generateMaptiles)
@@ -931,7 +955,7 @@ namespace OpenSim.Region.Framework.Scenes
931 string grant = startupConfig.GetString("AllowedClients", String.Empty); 955 string grant = startupConfig.GetString("AllowedClients", String.Empty);
932 if (grant.Length > 0) 956 if (grant.Length > 0)
933 { 957 {
934 foreach (string viewer in grant.Split('|')) 958 foreach (string viewer in grant.Split(','))
935 { 959 {
936 m_AllowedViewers.Add(viewer.Trim().ToLower()); 960 m_AllowedViewers.Add(viewer.Trim().ToLower());
937 } 961 }
@@ -940,7 +964,7 @@ namespace OpenSim.Region.Framework.Scenes
940 grant = startupConfig.GetString("BannedClients", String.Empty); 964 grant = startupConfig.GetString("BannedClients", String.Empty);
941 if (grant.Length > 0) 965 if (grant.Length > 0)
942 { 966 {
943 foreach (string viewer in grant.Split('|')) 967 foreach (string viewer in grant.Split(','))
944 { 968 {
945 m_BannedViewers.Add(viewer.Trim().ToLower()); 969 m_BannedViewers.Add(viewer.Trim().ToLower());
946 } 970 }
@@ -1000,6 +1024,8 @@ namespace OpenSim.Region.Framework.Scenes
1000 StatsReporter = new SimStatsReporter(this); 1024 StatsReporter = new SimStatsReporter(this);
1001 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 1025 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
1002 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 1026 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
1027
1028 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
1003 } 1029 }
1004 1030
1005 public Scene(RegionInfo regInfo) : base(regInfo) 1031 public Scene(RegionInfo regInfo) : base(regInfo)
@@ -1295,8 +1321,11 @@ namespace OpenSim.Region.Framework.Scenes
1295 // Stop all client threads. 1321 // Stop all client threads.
1296 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); }); 1322 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); });
1297 1323
1298 m_log.Debug("[SCENE]: Persisting changed objects"); 1324 m_log.Debug("[SCENE]: TriggerSceneShuttingDown");
1299 EventManager.TriggerSceneShuttingDown(this); 1325 EventManager.TriggerSceneShuttingDown(this);
1326
1327 m_log.Debug("[SCENE]: Persisting changed objects");
1328
1300 Backup(false); 1329 Backup(false);
1301 m_sceneGraph.Close(); 1330 m_sceneGraph.Close();
1302 1331
@@ -1310,6 +1339,7 @@ namespace OpenSim.Region.Framework.Scenes
1310 // attempt to reference a null or disposed physics scene. 1339 // attempt to reference a null or disposed physics scene.
1311 if (PhysicsScene != null) 1340 if (PhysicsScene != null)
1312 { 1341 {
1342 m_log.Debug("[SCENE]: Dispose Physics");
1313 PhysicsScene phys = PhysicsScene; 1343 PhysicsScene phys = PhysicsScene;
1314 // remove the physics engine from both Scene and SceneGraph 1344 // remove the physics engine from both Scene and SceneGraph
1315 PhysicsScene = null; 1345 PhysicsScene = null;
@@ -1332,11 +1362,29 @@ namespace OpenSim.Region.Framework.Scenes
1332 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1362 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1333 if (m_heartbeatThread != null) 1363 if (m_heartbeatThread != null)
1334 { 1364 {
1365 m_hbRestarts++;
1366 if(m_hbRestarts > 10)
1367 Environment.Exit(1);
1368 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1369
1370//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1371//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1372//proc.EnableRaisingEvents=false;
1373//proc.StartInfo.FileName = "/bin/kill";
1374//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1375//proc.Start();
1376//proc.WaitForExit();
1377//Thread.Sleep(1000);
1378//Environment.Exit(1);
1335 m_heartbeatThread.Abort(); 1379 m_heartbeatThread.Abort();
1380 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1336 m_heartbeatThread = null; 1381 m_heartbeatThread = null;
1337 } 1382 }
1338// m_lastUpdate = Util.EnvironmentTickCount(); 1383// m_lastUpdate = Util.EnvironmentTickCount();
1339 1384
1385// m_sceneGraph.PreparePhysicsSimulation();
1386
1387
1340 m_heartbeatThread 1388 m_heartbeatThread
1341 = Watchdog.StartThread( 1389 = Watchdog.StartThread(
1342 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false); 1390 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false);
@@ -1479,16 +1527,20 @@ namespace OpenSim.Region.Framework.Scenes
1479 endFrame = Frame + frames; 1527 endFrame = Frame + frames;
1480 1528
1481 float physicsFPS = 0f; 1529 float physicsFPS = 0f;
1482 int previousFrameTick, tmpMS; 1530 int tmpMS;
1483 int maintc = Util.EnvironmentTickCount(); 1531 int previousFrameTick;
1532 int maintc;
1533 int sleepMS;
1534 int framestart;
1484 1535
1485 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) 1536 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
1486 { 1537 {
1538 framestart = Util.EnvironmentTickCount();
1487 ++Frame; 1539 ++Frame;
1488 1540
1489// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1541// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1490 1542
1491 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1543 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1492 1544
1493 try 1545 try
1494 { 1546 {
@@ -1540,6 +1592,7 @@ namespace OpenSim.Region.Framework.Scenes
1540 m_sceneGraph.UpdatePresences(); 1592 m_sceneGraph.UpdatePresences();
1541 1593
1542 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1594 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1595
1543 1596
1544 // Delete temp-on-rez stuff 1597 // Delete temp-on-rez stuff
1545 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1598 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
@@ -1621,34 +1674,37 @@ namespace OpenSim.Region.Framework.Scenes
1621 1674
1622 Watchdog.UpdateThread(); 1675 Watchdog.UpdateThread();
1623 1676
1677 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1678
1679 StatsReporter.AddPhysicsFPS(physicsFPS);
1680 StatsReporter.AddTimeDilation(TimeDilation);
1681 StatsReporter.AddFPS(1);
1682
1683 StatsReporter.addAgentMS(agentMS);
1684 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1685 StatsReporter.addOtherMS(otherMS);
1686 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1687
1624 previousFrameTick = m_lastFrameTick; 1688 previousFrameTick = m_lastFrameTick;
1625 m_lastFrameTick = Util.EnvironmentTickCount(); 1689 m_lastFrameTick = Util.EnvironmentTickCount();
1626 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1690 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
1627 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1691 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1628 1692
1693 m_firstHeartbeat = false;
1694
1695 sleepMS = Util.EnvironmentTickCount();
1696
1629 if (tmpMS > 0) 1697 if (tmpMS > 0)
1630 {
1631 Thread.Sleep(tmpMS); 1698 Thread.Sleep(tmpMS);
1632 spareMS += tmpMS;
1633 }
1634
1635 frameMS = Util.EnvironmentTickCountSubtract(maintc);
1636 maintc = Util.EnvironmentTickCount();
1637 1699
1638 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; 1700 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1701 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1702 StatsReporter.addSleepMS(sleepMS);
1703 StatsReporter.addFrameMS(frameMS);
1639 1704
1640 // if (Frame%m_update_avatars == 0) 1705 // if (Frame%m_update_avatars == 0)
1641 // UpdateInWorldTime(); 1706 // UpdateInWorldTime();
1642 StatsReporter.AddPhysicsFPS(physicsFPS);
1643 StatsReporter.AddTimeDilation(TimeDilation);
1644 StatsReporter.AddFPS(1);
1645 1707
1646 StatsReporter.addFrameMS(frameMS);
1647 StatsReporter.addAgentMS(agentMS);
1648 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1649 StatsReporter.addOtherMS(otherMS);
1650 StatsReporter.AddSpareMS(spareMS);
1651 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1652 1708
1653 // Optionally warn if a frame takes double the amount of time that it should. 1709 // Optionally warn if a frame takes double the amount of time that it should.
1654 if (DebugUpdates 1710 if (DebugUpdates
@@ -1665,7 +1721,7 @@ namespace OpenSim.Region.Framework.Scenes
1665 public void AddGroupTarget(SceneObjectGroup grp) 1721 public void AddGroupTarget(SceneObjectGroup grp)
1666 { 1722 {
1667 lock (m_groupsWithTargets) 1723 lock (m_groupsWithTargets)
1668 m_groupsWithTargets[grp.UUID] = grp; 1724 m_groupsWithTargets[grp.UUID] = 0;
1669 } 1725 }
1670 1726
1671 public void RemoveGroupTarget(SceneObjectGroup grp) 1727 public void RemoveGroupTarget(SceneObjectGroup grp)
@@ -1676,18 +1732,24 @@ namespace OpenSim.Region.Framework.Scenes
1676 1732
1677 private void CheckAtTargets() 1733 private void CheckAtTargets()
1678 { 1734 {
1679 List<SceneObjectGroup> objs = null; 1735 List<UUID> objs = null;
1680 1736
1681 lock (m_groupsWithTargets) 1737 lock (m_groupsWithTargets)
1682 { 1738 {
1683 if (m_groupsWithTargets.Count != 0) 1739 if (m_groupsWithTargets.Count != 0)
1684 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values); 1740 objs = new List<UUID>(m_groupsWithTargets.Keys);
1685 } 1741 }
1686 1742
1687 if (objs != null) 1743 if (objs != null)
1688 { 1744 {
1689 foreach (SceneObjectGroup entry in objs) 1745 foreach (UUID entry in objs)
1690 entry.checkAtTargets(); 1746 {
1747 SceneObjectGroup grp = GetSceneObjectGroup(entry);
1748 if (grp == null)
1749 m_groupsWithTargets.Remove(entry);
1750 else
1751 grp.checkAtTargets();
1752 }
1691 } 1753 }
1692 } 1754 }
1693 1755
@@ -1766,7 +1828,7 @@ namespace OpenSim.Region.Framework.Scenes
1766 msg.fromAgentName = "Server"; 1828 msg.fromAgentName = "Server";
1767 msg.dialog = (byte)19; // Object msg 1829 msg.dialog = (byte)19; // Object msg
1768 msg.fromGroup = false; 1830 msg.fromGroup = false;
1769 msg.offline = (byte)0; 1831 msg.offline = (byte)1;
1770 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1832 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1771 msg.Position = Vector3.Zero; 1833 msg.Position = Vector3.Zero;
1772 msg.RegionID = RegionInfo.RegionID.Guid; 1834 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1995,7 +2057,7 @@ namespace OpenSim.Region.Framework.Scenes
1995 return PhysicsScene.SupportsRaycastWorldFiltered(); 2057 return PhysicsScene.SupportsRaycastWorldFiltered();
1996 } 2058 }
1997 2059
1998 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) 2060 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
1999 { 2061 {
2000 if (PhysicsScene == null) 2062 if (PhysicsScene == null)
2001 return null; 2063 return null;
@@ -2017,14 +2079,24 @@ namespace OpenSim.Region.Framework.Scenes
2017 /// <returns></returns> 2079 /// <returns></returns>
2018 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2080 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
2019 { 2081 {
2082
2083 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2084 Vector3 wpos = Vector3.Zero;
2085 // Check for water surface intersection from above
2086 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2087 {
2088 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2089 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2090 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2091 wpos.Z = wheight;
2092 }
2093
2020 Vector3 pos = Vector3.Zero; 2094 Vector3 pos = Vector3.Zero;
2021 if (RayEndIsIntersection == (byte)1) 2095 if (RayEndIsIntersection == (byte)1)
2022 { 2096 {
2023 pos = RayEnd; 2097 pos = RayEnd;
2024 return pos;
2025 } 2098 }
2026 2099 else if (RayTargetID != UUID.Zero)
2027 if (RayTargetID != UUID.Zero)
2028 { 2100 {
2029 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2101 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
2030 2102
@@ -2046,7 +2118,7 @@ namespace OpenSim.Region.Framework.Scenes
2046 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 2118 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
2047 2119
2048 // Un-comment out the following line to Get Raytrace results printed to the console. 2120 // Un-comment out the following line to Get Raytrace results printed to the console.
2049 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 2121 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
2050 float ScaleOffset = 0.5f; 2122 float ScaleOffset = 0.5f;
2051 2123
2052 // If we hit something 2124 // If we hit something
@@ -2069,13 +2141,10 @@ namespace OpenSim.Region.Framework.Scenes
2069 //pos.Z -= 0.25F; 2141 //pos.Z -= 0.25F;
2070 2142
2071 } 2143 }
2072
2073 return pos;
2074 } 2144 }
2075 else 2145 else
2076 { 2146 {
2077 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2147 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2078
2079 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2148 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2080 2149
2081 // Un-comment the following line to print the raytrace results to the console. 2150 // Un-comment the following line to print the raytrace results to the console.
@@ -2084,13 +2153,12 @@ namespace OpenSim.Region.Framework.Scenes
2084 if (ei.HitTF) 2153 if (ei.HitTF)
2085 { 2154 {
2086 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2155 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2087 } else 2156 }
2157 else
2088 { 2158 {
2089 // fall back to our stupid functionality 2159 // fall back to our stupid functionality
2090 pos = RayEnd; 2160 pos = RayEnd;
2091 } 2161 }
2092
2093 return pos;
2094 } 2162 }
2095 } 2163 }
2096 else 2164 else
@@ -2101,8 +2169,12 @@ namespace OpenSim.Region.Framework.Scenes
2101 //increase height so its above the ground. 2169 //increase height so its above the ground.
2102 //should be getting the normal of the ground at the rez point and using that? 2170 //should be getting the normal of the ground at the rez point and using that?
2103 pos.Z += scale.Z / 2f; 2171 pos.Z += scale.Z / 2f;
2104 return pos; 2172// return pos;
2105 } 2173 }
2174
2175 // check against posible water intercept
2176 if (wpos.Z > pos.Z) pos = wpos;
2177 return pos;
2106 } 2178 }
2107 2179
2108 2180
@@ -2193,12 +2265,12 @@ namespace OpenSim.Region.Framework.Scenes
2193 { 2265 {
2194 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates)) 2266 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates))
2195 { 2267 {
2268 sceneObject.IsDeleted = false;
2196 EventManager.TriggerObjectAddedToScene(sceneObject); 2269 EventManager.TriggerObjectAddedToScene(sceneObject);
2197 return true; 2270 return true;
2198 } 2271 }
2199 2272
2200 return false; 2273 return false;
2201
2202 } 2274 }
2203 2275
2204 /// <summary> 2276 /// <summary>
@@ -2290,6 +2362,15 @@ namespace OpenSim.Region.Framework.Scenes
2290 /// </summary> 2362 /// </summary>
2291 public void DeleteAllSceneObjects() 2363 public void DeleteAllSceneObjects()
2292 { 2364 {
2365 DeleteAllSceneObjects(false);
2366 }
2367
2368 /// <summary>
2369 /// Delete every object from the scene. This does not include attachments worn by avatars.
2370 /// </summary>
2371 public void DeleteAllSceneObjects(bool exceptNoCopy)
2372 {
2373 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2293 lock (Entities) 2374 lock (Entities)
2294 { 2375 {
2295 EntityBase[] entities = Entities.GetEntities(); 2376 EntityBase[] entities = Entities.GetEntities();
@@ -2298,11 +2379,24 @@ namespace OpenSim.Region.Framework.Scenes
2298 if (e is SceneObjectGroup) 2379 if (e is SceneObjectGroup)
2299 { 2380 {
2300 SceneObjectGroup sog = (SceneObjectGroup)e; 2381 SceneObjectGroup sog = (SceneObjectGroup)e;
2301 if (!sog.IsAttachment) 2382 if (sog != null && !sog.IsAttachment)
2302 DeleteSceneObject((SceneObjectGroup)e, false); 2383 {
2384 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2385 {
2386 DeleteSceneObject((SceneObjectGroup)e, false);
2387 }
2388 else
2389 {
2390 toReturn.Add((SceneObjectGroup)e);
2391 }
2392 }
2303 } 2393 }
2304 } 2394 }
2305 } 2395 }
2396 if (toReturn.Count > 0)
2397 {
2398 returnObjects(toReturn.ToArray(), UUID.Zero);
2399 }
2306 } 2400 }
2307 2401
2308 /// <summary> 2402 /// <summary>
@@ -2337,6 +2431,12 @@ namespace OpenSim.Region.Framework.Scenes
2337 2431
2338 foreach (SceneObjectPart part in partList) 2432 foreach (SceneObjectPart part in partList)
2339 { 2433 {
2434 if (part.KeyframeMotion != null)
2435 {
2436 part.KeyframeMotion.Delete();
2437 part.KeyframeMotion = null;
2438 }
2439
2340 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0)) 2440 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
2341 { 2441 {
2342 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? 2442 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
@@ -2354,6 +2454,8 @@ namespace OpenSim.Region.Framework.Scenes
2354 } 2454 }
2355 2455
2356 group.DeleteGroupFromScene(silent); 2456 group.DeleteGroupFromScene(silent);
2457 if (!silent)
2458 SendKillObject(new List<uint>() { group.LocalId });
2357 2459
2358// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2460// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2359 } 2461 }
@@ -2644,7 +2746,7 @@ namespace OpenSim.Region.Framework.Scenes
2644 // If the user is banned, we won't let any of their objects 2746 // If the user is banned, we won't let any of their objects
2645 // enter. Period. 2747 // enter. Period.
2646 // 2748 //
2647 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID)) 2749 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
2648 { 2750 {
2649 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID); 2751 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
2650 return false; 2752 return false;
@@ -2652,6 +2754,8 @@ namespace OpenSim.Region.Framework.Scenes
2652 2754
2653 if (newPosition != Vector3.Zero) 2755 if (newPosition != Vector3.Zero)
2654 newObject.RootPart.GroupPosition = newPosition; 2756 newObject.RootPart.GroupPosition = newPosition;
2757 if (newObject.RootPart.KeyframeMotion != null)
2758 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2655 2759
2656 if (!AddSceneObject(newObject)) 2760 if (!AddSceneObject(newObject))
2657 { 2761 {
@@ -2696,6 +2800,23 @@ namespace OpenSim.Region.Framework.Scenes
2696 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2800 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2697 public bool AddSceneObject(SceneObjectGroup sceneObject) 2801 public bool AddSceneObject(SceneObjectGroup sceneObject)
2698 { 2802 {
2803 if (sceneObject.OwnerID == UUID.Zero)
2804 {
2805 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2806 return false;
2807 }
2808
2809 // If the user is banned, we won't let any of their objects
2810 // enter. Period.
2811 //
2812 int flags = GetUserFlags(sceneObject.OwnerID);
2813 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2814 {
2815 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2816
2817 return false;
2818 }
2819
2699 // Force allocation of new LocalId 2820 // Force allocation of new LocalId
2700 // 2821 //
2701 SceneObjectPart[] parts = sceneObject.Parts; 2822 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2729,16 +2850,27 @@ namespace OpenSim.Region.Framework.Scenes
2729 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2850 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2730 2851
2731 if (AttachmentsModule != null) 2852 if (AttachmentsModule != null)
2732 AttachmentsModule.AttachObject(sp, grp, 0, false, false); 2853 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false);
2733 } 2854 }
2734 else 2855 else
2735 { 2856 {
2857 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2736 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2858 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2737 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2859 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2738 } 2860 }
2861 if (sceneObject.OwnerID == UUID.Zero)
2862 {
2863 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2864 return false;
2865 }
2739 } 2866 }
2740 else 2867 else
2741 { 2868 {
2869 if (sceneObject.OwnerID == UUID.Zero)
2870 {
2871 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2872 return false;
2873 }
2742 AddRestoredSceneObject(sceneObject, true, false); 2874 AddRestoredSceneObject(sceneObject, true, false);
2743 } 2875 }
2744 2876
@@ -2755,6 +2887,24 @@ namespace OpenSim.Region.Framework.Scenes
2755 return 2; // StateSource.PrimCrossing 2887 return 2; // StateSource.PrimCrossing
2756 } 2888 }
2757 2889
2890 public int GetUserFlags(UUID user)
2891 {
2892 //Unfortunately the SP approach means that the value is cached until region is restarted
2893 /*
2894 ScenePresence sp;
2895 if (TryGetScenePresence(user, out sp))
2896 {
2897 return sp.UserFlags;
2898 }
2899 else
2900 {
2901 */
2902 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2903 if (uac == null)
2904 return 0;
2905 return uac.UserFlags;
2906 //}
2907 }
2758 #endregion 2908 #endregion
2759 2909
2760 #region Add/Remove Avatar Methods 2910 #region Add/Remove Avatar Methods
@@ -2787,7 +2937,7 @@ namespace OpenSim.Region.Framework.Scenes
2787 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2937 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2788 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2938 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2789 2939
2790 // CheckHeartbeat(); 2940 CheckHeartbeat();
2791 2941
2792 sp = GetScenePresence(client.AgentId); 2942 sp = GetScenePresence(client.AgentId);
2793 2943
@@ -2818,6 +2968,7 @@ namespace OpenSim.Region.Framework.Scenes
2818 // start the scripts again (since this is done in RezAttachments()). 2968 // start the scripts again (since this is done in RezAttachments()).
2819 // XXX: This is convoluted. 2969 // XXX: This is convoluted.
2820 sp.IsChildAgent = false; 2970 sp.IsChildAgent = false;
2971 sp.IsLoggingIn = true;
2821 2972
2822 if (AttachmentsModule != null) 2973 if (AttachmentsModule != null)
2823 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); }); 2974 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); });
@@ -2931,19 +3082,14 @@ namespace OpenSim.Region.Framework.Scenes
2931 // and the scene presence and the client, if they exist 3082 // and the scene presence and the client, if they exist
2932 try 3083 try
2933 { 3084 {
2934 // We need to wait for the client to make UDP contact first. 3085 ScenePresence sp = GetScenePresence(agentID);
2935 // It's the UDP contact that creates the scene presence 3086
2936 ScenePresence sp = WaitGetScenePresence(agentID);
2937 if (sp != null) 3087 if (sp != null)
2938 { 3088 {
2939 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3089 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2940
2941 sp.ControllingClient.Close(); 3090 sp.ControllingClient.Close();
2942 } 3091 }
2943 else 3092
2944 {
2945 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2946 }
2947 // BANG! SLASH! 3093 // BANG! SLASH!
2948 m_authenticateHandler.RemoveCircuit(agentID); 3094 m_authenticateHandler.RemoveCircuit(agentID);
2949 3095
@@ -2988,6 +3134,8 @@ namespace OpenSim.Region.Framework.Scenes
2988 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3134 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2989 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3135 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2990 3136
3137 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3138
2991 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3139 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2992 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3140 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2993 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3141 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -3044,6 +3192,7 @@ namespace OpenSim.Region.Framework.Scenes
3044 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3192 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
3045 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3193 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
3046 client.OnCopyInventoryItem += CopyInventoryItem; 3194 client.OnCopyInventoryItem += CopyInventoryItem;
3195 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
3047 client.OnMoveInventoryItem += MoveInventoryItem; 3196 client.OnMoveInventoryItem += MoveInventoryItem;
3048 client.OnRemoveInventoryItem += RemoveInventoryItem; 3197 client.OnRemoveInventoryItem += RemoveInventoryItem;
3049 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3198 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3115,6 +3264,8 @@ namespace OpenSim.Region.Framework.Scenes
3115 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3264 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3116 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3265 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3117 3266
3267 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3268
3118 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3269 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3119 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3270 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3120 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3271 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3217,7 +3368,7 @@ namespace OpenSim.Region.Framework.Scenes
3217 /// </summary> 3368 /// </summary>
3218 /// <param name="agentId">The avatar's Unique ID</param> 3369 /// <param name="agentId">The avatar's Unique ID</param>
3219 /// <param name="client">The IClientAPI for the client</param> 3370 /// <param name="client">The IClientAPI for the client</param>
3220 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3371 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3221 { 3372 {
3222 if (EntityTransferModule != null) 3373 if (EntityTransferModule != null)
3223 { 3374 {
@@ -3228,6 +3379,7 @@ namespace OpenSim.Region.Framework.Scenes
3228 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3379 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3229 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3380 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3230 } 3381 }
3382 return false;
3231 } 3383 }
3232 3384
3233 /// <summary> 3385 /// <summary>
@@ -3337,6 +3489,16 @@ namespace OpenSim.Region.Framework.Scenes
3337 /// <param name="flags"></param> 3489 /// <param name="flags"></param>
3338 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3490 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3339 { 3491 {
3492 //Add half the avatar's height so that the user doesn't fall through prims
3493 ScenePresence presence;
3494 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3495 {
3496 if (presence.Appearance != null)
3497 {
3498 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3499 }
3500 }
3501
3340 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3502 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3341 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3503 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3342 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3504 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3474,6 +3636,7 @@ namespace OpenSim.Region.Framework.Scenes
3474 // It's possible for child agents to have transactions if changes are being made cross-border. 3636 // It's possible for child agents to have transactions if changes are being made cross-border.
3475 if (AgentTransactionsModule != null) 3637 if (AgentTransactionsModule != null)
3476 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 3638 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3639 m_log.Debug("[Scene] The avatar has left the building");
3477 } 3640 }
3478 catch (Exception e) 3641 catch (Exception e)
3479 { 3642 {
@@ -3666,38 +3829,39 @@ namespace OpenSim.Region.Framework.Scenes
3666 agent.firstname, agent.lastname, agent.Viewer); 3829 agent.firstname, agent.lastname, agent.Viewer);
3667 reason = "Access denied, your viewer is banned by the region owner"; 3830 reason = "Access denied, your viewer is banned by the region owner";
3668 return false; 3831 return false;
3669 } 3832 }
3833
3834
3835 ScenePresence sp = GetScenePresence(agent.AgentID);
3836
3837 if (sp != null && !sp.IsChildAgent)
3838 {
3839 // We have a zombie from a crashed session.
3840 // Or the same user is trying to be root twice here, won't work.
3841 // Kill it.
3842 m_log.WarnFormat(
3843 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3844 sp.Name, sp.UUID, RegionInfo.RegionName);
3670 3845
3671 ILandObject land; 3846 sp.ControllingClient.Close(true, true);
3847 sp = null;
3848 }
3672 3849
3673 lock (agent) 3850 lock (agent)
3674 { 3851 {
3675 ScenePresence sp = GetScenePresence(agent.AgentID);
3676
3677 if (sp != null && !sp.IsChildAgent)
3678 {
3679 // We have a zombie from a crashed session.
3680 // Or the same user is trying to be root twice here, won't work.
3681 // Kill it.
3682 m_log.WarnFormat(
3683 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3684 sp.Name, sp.UUID, RegionInfo.RegionName);
3685
3686 sp.ControllingClient.Close(true);
3687 sp = null;
3688 }
3689
3690 land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3691
3692 //On login test land permisions 3852 //On login test land permisions
3693 if (vialogin) 3853 if (vialogin)
3694 { 3854 {
3695 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3855 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3856 if (cache != null)
3857 cache.Remove(agent.firstname + " " + agent.lastname);
3858 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3696 { 3859 {
3860 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3697 return false; 3861 return false;
3698 } 3862 }
3699 } 3863 }
3700 3864
3701 if (sp == null) // We don't have an [child] agent here already 3865 if (sp == null) // We don't have an [child] agent here already
3702 { 3866 {
3703 if (requirePresenceLookup) 3867 if (requirePresenceLookup)
@@ -3706,34 +3870,36 @@ namespace OpenSim.Region.Framework.Scenes
3706 { 3870 {
3707 if (!VerifyUserPresence(agent, out reason)) 3871 if (!VerifyUserPresence(agent, out reason))
3708 return false; 3872 return false;
3709 } 3873 } catch (Exception e)
3710 catch (Exception e)
3711 { 3874 {
3712 m_log.ErrorFormat( 3875 m_log.ErrorFormat(
3713 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace); 3876 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace);
3714
3715 return false; 3877 return false;
3716 } 3878 }
3717 } 3879 }
3718 3880
3719 try 3881 try
3720 { 3882 {
3721 if (!AuthorizeUser(agent, out reason)) 3883 // Always check estate if this is a login. Always
3722 return false; 3884 // check if banned regions are to be blacked out.
3885 if (vialogin || (!m_seeIntoBannedRegion))
3886 {
3887 if (!AuthorizeUser(agent, out reason))
3888 return false;
3889 }
3723 } 3890 }
3724 catch (Exception e) 3891 catch (Exception e)
3725 { 3892 {
3726 m_log.ErrorFormat( 3893 m_log.ErrorFormat(
3727 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3894 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
3728
3729 return false; 3895 return false;
3730 } 3896 }
3731 3897
3732 m_log.InfoFormat( 3898 m_log.InfoFormat(
3733 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})", 3899 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})",
3734 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname, 3900 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
3735 agent.AgentID, agent.circuitcode); 3901 agent.AgentID, agent.circuitcode);
3736 3902
3737 if (CapsModule != null) 3903 if (CapsModule != null)
3738 { 3904 {
3739 CapsModule.SetAgentCapsSeeds(agent); 3905 CapsModule.SetAgentCapsSeeds(agent);
@@ -3745,15 +3911,15 @@ namespace OpenSim.Region.Framework.Scenes
3745 // Let the SP know how we got here. This has a lot of interesting 3911 // Let the SP know how we got here. This has a lot of interesting
3746 // uses down the line. 3912 // uses down the line.
3747 sp.TeleportFlags = (TPFlags)teleportFlags; 3913 sp.TeleportFlags = (TPFlags)teleportFlags;
3748 3914
3749 if (sp.IsChildAgent) 3915 if (sp.IsChildAgent)
3750 { 3916 {
3751 m_log.DebugFormat( 3917 m_log.DebugFormat(
3752 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}", 3918 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
3753 agent.AgentID, RegionInfo.RegionName); 3919 agent.AgentID, RegionInfo.RegionName);
3754 3920
3755 sp.AdjustKnownSeeds(); 3921 sp.AdjustKnownSeeds();
3756 3922
3757 if (CapsModule != null) 3923 if (CapsModule != null)
3758 CapsModule.SetAgentCapsSeeds(agent); 3924 CapsModule.SetAgentCapsSeeds(agent);
3759 } 3925 }
@@ -3855,6 +4021,8 @@ namespace OpenSim.Region.Framework.Scenes
3855 } 4021 }
3856 4022
3857 // Honor parcel landing type and position. 4023 // Honor parcel landing type and position.
4024 /*
4025 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3858 if (land != null) 4026 if (land != null)
3859 { 4027 {
3860 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 4028 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3862,25 +4030,43 @@ namespace OpenSim.Region.Framework.Scenes
3862 agent.startpos = land.LandData.UserLocation; 4030 agent.startpos = land.LandData.UserLocation;
3863 } 4031 }
3864 } 4032 }
4033 */// This is now handled properly in ScenePresence.MakeRootAgent
3865 } 4034 }
3866 4035
3867 return true; 4036 return true;
3868 } 4037 }
3869 4038
3870 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 4039 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3871 { 4040 {
3872 bool banned = land.IsBannedFromLand(agent.AgentID); 4041 if (posX < 0)
3873 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 4042 posX = 0;
4043 else if (posX >= 256)
4044 posX = 255.999f;
4045 if (posY < 0)
4046 posY = 0;
4047 else if (posY >= 256)
4048 posY = 255.999f;
4049
4050 reason = String.Empty;
4051 if (Permissions.IsGod(agentID))
4052 return true;
4053
4054 ILandObject land = LandChannel.GetLandObject(posX, posY);
4055 if (land == null)
4056 return false;
4057
4058 bool banned = land.IsBannedFromLand(agentID);
4059 bool restricted = land.IsRestrictedFromLand(agentID);
3874 4060
3875 if (banned || restricted) 4061 if (banned || restricted)
3876 { 4062 {
3877 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 4063 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3878 if (nearestParcel != null) 4064 if (nearestParcel != null)
3879 { 4065 {
3880 //Move agent to nearest allowed 4066 //Move agent to nearest allowed
3881 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 4067 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3882 agent.startpos.X = newPosition.X; 4068 posX = newPosition.X;
3883 agent.startpos.Y = newPosition.Y; 4069 posY = newPosition.Y;
3884 } 4070 }
3885 else 4071 else
3886 { 4072 {
@@ -3942,7 +4128,7 @@ namespace OpenSim.Region.Framework.Scenes
3942 4128
3943 if (!m_strictAccessControl) return true; 4129 if (!m_strictAccessControl) return true;
3944 if (Permissions.IsGod(agent.AgentID)) return true; 4130 if (Permissions.IsGod(agent.AgentID)) return true;
3945 4131
3946 if (AuthorizationService != null) 4132 if (AuthorizationService != null)
3947 { 4133 {
3948 if (!AuthorizationService.IsAuthorizedForRegion( 4134 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3957,7 +4143,7 @@ namespace OpenSim.Region.Framework.Scenes
3957 4143
3958 if (RegionInfo.EstateSettings != null) 4144 if (RegionInfo.EstateSettings != null)
3959 { 4145 {
3960 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4146 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, 0))
3961 { 4147 {
3962 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4148 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3963 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4149 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4147,6 +4333,15 @@ namespace OpenSim.Region.Framework.Scenes
4147 4333
4148 // XPTO: if this agent is not allowed here as root, always return false 4334 // XPTO: if this agent is not allowed here as root, always return false
4149 4335
4336 // We have to wait until the viewer contacts this region after receiving EAC.
4337 // That calls AddNewClient, which finally creates the ScenePresence
4338 int flags = GetUserFlags(cAgentData.AgentID);
4339 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4340 {
4341 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4342 return false;
4343 }
4344
4150 // TODO: This check should probably be in QueryAccess(). 4345 // TODO: This check should probably be in QueryAccess().
4151 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4346 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4152 if (nearestParcel == null) 4347 if (nearestParcel == null)
@@ -4211,7 +4406,7 @@ namespace OpenSim.Region.Framework.Scenes
4211 /// <param name='agentID'></param> 4406 /// <param name='agentID'></param>
4212 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4407 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4213 { 4408 {
4214 int ntimes = 10; 4409 int ntimes = 30;
4215 ScenePresence sp = null; 4410 ScenePresence sp = null;
4216 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4411 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4217 Thread.Sleep(1000); 4412 Thread.Sleep(1000);
@@ -4241,6 +4436,16 @@ namespace OpenSim.Region.Framework.Scenes
4241 return false; 4436 return false;
4242 } 4437 }
4243 4438
4439 public bool IncomingCloseAgent(UUID agentID)
4440 {
4441 return IncomingCloseAgent(agentID, false);
4442 }
4443
4444 public bool IncomingCloseChildAgent(UUID agentID)
4445 {
4446 return IncomingCloseAgent(agentID, true);
4447 }
4448
4244 /// <summary> 4449 /// <summary>
4245 /// Tell a single agent to disconnect from the region. 4450 /// Tell a single agent to disconnect from the region.
4246 /// </summary> 4451 /// </summary>
@@ -4256,7 +4461,7 @@ namespace OpenSim.Region.Framework.Scenes
4256 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4461 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4257 if (presence != null) 4462 if (presence != null)
4258 { 4463 {
4259 presence.ControllingClient.Close(force); 4464 presence.ControllingClient.Close(force, force);
4260 return true; 4465 return true;
4261 } 4466 }
4262 4467
@@ -4902,7 +5107,7 @@ namespace OpenSim.Region.Framework.Scenes
4902 { 5107 {
4903 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 5108 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
4904 { 5109 {
4905 if (grp.RootPart.Expires <= DateTime.Now) 5110 if (grp.GetSittingAvatarsCount() == 0 && grp.RootPart.Expires <= DateTime.Now)
4906 DeleteSceneObject(grp, false); 5111 DeleteSceneObject(grp, false);
4907 } 5112 }
4908 } 5113 }
@@ -4916,35 +5121,81 @@ namespace OpenSim.Region.Framework.Scenes
4916 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5121 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
4917 } 5122 }
4918 5123
4919 public int GetHealth() 5124 public int GetHealth(out int flags, out string message)
4920 { 5125 {
4921 // Returns: 5126 // Returns:
4922 // 1 = sim is up and accepting http requests. The heartbeat has 5127 // 1 = sim is up and accepting http requests. The heartbeat has
4923 // stopped and the sim is probably locked up, but a remote 5128 // stopped and the sim is probably locked up, but a remote
4924 // admin restart may succeed 5129 // admin restart may succeed
4925 // 5130 //
4926 // 2 = Sim is up and the heartbeat is running. The sim is likely 5131 // 2 = Sim is up and the heartbeat is running. The sim is likely
4927 // usable for people within and logins _may_ work 5132 // usable for people within
5133 //
5134 // 3 = Sim is up and one packet thread is running. Sim is
5135 // unstable and will not accept new logins
5136 //
5137 // 4 = Sim is up and both packet threads are running. Sim is
5138 // likely usable
4928 // 5139 //
4929 // 3 = We have seen a new user enter within the past 4 minutes 5140 // 5 = We have seen a new user enter within the past 4 minutes
4930 // which can be seen as positive confirmation of sim health 5141 // which can be seen as positive confirmation of sim health
4931 // 5142 //
5143
5144 flags = 0;
5145 message = String.Empty;
5146
5147 CheckHeartbeat();
5148
5149 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5150 {
5151 // We're still starting
5152 // 0 means "in startup", it can't happen another way, since
5153 // to get here, we must be able to accept http connections
5154 return 0;
5155 }
5156
4932 int health=1; // Start at 1, means we're up 5157 int health=1; // Start at 1, means we're up
4933 5158
4934 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5159 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4935 health += 1; 5160 {
5161 health+=1;
5162 flags |= 1;
5163 }
5164
5165 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5166 {
5167 health+=1;
5168 flags |= 2;
5169 }
5170
5171 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5172 {
5173 health+=1;
5174 flags |= 4;
5175 }
4936 else 5176 else
5177 {
5178int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5179System.Diagnostics.Process proc = new System.Diagnostics.Process();
5180proc.EnableRaisingEvents=false;
5181proc.StartInfo.FileName = "/bin/kill";
5182proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5183proc.Start();
5184proc.WaitForExit();
5185Thread.Sleep(1000);
5186Environment.Exit(1);
5187 }
5188
5189 if (flags != 7)
4937 return health; 5190 return health;
4938 5191
4939 // A login in the last 4 mins? We can't be doing too badly 5192 // A login in the last 4 mins? We can't be doing too badly
4940 // 5193 //
4941 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5194 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4942 health++; 5195 health++;
4943 else 5196 else
4944 return health; 5197 return health;
4945 5198
4946// CheckHeartbeat();
4947
4948 return health; 5199 return health;
4949 } 5200 }
4950 5201
@@ -5032,7 +5283,7 @@ namespace OpenSim.Region.Framework.Scenes
5032 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 5283 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
5033 if (wasUsingPhysics) 5284 if (wasUsingPhysics)
5034 { 5285 {
5035 jointProxyObject.UpdatePrimFlags(false, false, true, false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock 5286 jointProxyObject.UpdatePrimFlags(false, false, true, false,false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock
5036 } 5287 }
5037 } 5288 }
5038 5289
@@ -5131,14 +5382,14 @@ namespace OpenSim.Region.Framework.Scenes
5131 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5382 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5132 } 5383 }
5133 5384
5134// private void CheckHeartbeat() 5385 private void CheckHeartbeat()
5135// { 5386 {
5136// if (m_firstHeartbeat) 5387 if (m_firstHeartbeat)
5137// return; 5388 return;
5138// 5389
5139// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5390 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5140// StartTimer(); 5391 Start();
5141// } 5392 }
5142 5393
5143 public override ISceneObject DeserializeObject(string representation) 5394 public override ISceneObject DeserializeObject(string representation)
5144 { 5395 {
@@ -5150,9 +5401,14 @@ namespace OpenSim.Region.Framework.Scenes
5150 get { return m_allowScriptCrossings; } 5401 get { return m_allowScriptCrossings; }
5151 } 5402 }
5152 5403
5153 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5404 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5154 { 5405 {
5155 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5406 return GetNearestAllowedPosition(avatar, null);
5407 }
5408
5409 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5410 {
5411 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
5156 5412
5157 if (nearestParcel != null) 5413 if (nearestParcel != null)
5158 { 5414 {
@@ -5161,10 +5417,7 @@ namespace OpenSim.Region.Framework.Scenes
5161 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5417 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5162 if (nearestPoint != null) 5418 if (nearestPoint != null)
5163 { 5419 {
5164// m_log.DebugFormat( 5420 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
5165// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
5166// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
5167
5168 return nearestPoint.Value; 5421 return nearestPoint.Value;
5169 } 5422 }
5170 5423
@@ -5174,17 +5427,20 @@ namespace OpenSim.Region.Framework.Scenes
5174 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5427 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5175 if (nearestPoint != null) 5428 if (nearestPoint != null)
5176 { 5429 {
5177// m_log.DebugFormat( 5430 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
5178// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
5179
5180 return nearestPoint.Value; 5431 return nearestPoint.Value;
5181 } 5432 }
5182 5433
5183 //Ultimate backup if we have no idea where they are 5434 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
5184// m_log.DebugFormat( 5435 if (dest != excludeParcel)
5185// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5436 {
5437 // Ultimate backup if we have no idea where they are and
5438 // the last allowed position was in another parcel
5439 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5440 return avatar.lastKnownAllowedPosition;
5441 }
5186 5442
5187 return avatar.lastKnownAllowedPosition; 5443 // else fall through to region edge
5188 } 5444 }
5189 5445
5190 //Go to the edge, this happens in teleporting to a region with no available parcels 5446 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -5218,13 +5474,18 @@ namespace OpenSim.Region.Framework.Scenes
5218 5474
5219 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5475 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5220 { 5476 {
5477 return GetNearestAllowedParcel(avatarId, x, y, null);
5478 }
5479
5480 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5481 {
5221 List<ILandObject> all = AllParcels(); 5482 List<ILandObject> all = AllParcels();
5222 float minParcelDistance = float.MaxValue; 5483 float minParcelDistance = float.MaxValue;
5223 ILandObject nearestParcel = null; 5484 ILandObject nearestParcel = null;
5224 5485
5225 foreach (var parcel in all) 5486 foreach (var parcel in all)
5226 { 5487 {
5227 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5488 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
5228 { 5489 {
5229 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5490 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5230 if (parcelDistance < minParcelDistance) 5491 if (parcelDistance < minParcelDistance)
@@ -5440,7 +5701,55 @@ namespace OpenSim.Region.Framework.Scenes
5440 mapModule.GenerateMaptile(); 5701 mapModule.GenerateMaptile();
5441 } 5702 }
5442 5703
5443 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5704// public void CleanDroppedAttachments()
5705// {
5706// List<SceneObjectGroup> objectsToDelete =
5707// new List<SceneObjectGroup>();
5708//
5709// lock (m_cleaningAttachments)
5710// {
5711// ForEachSOG(delegate (SceneObjectGroup grp)
5712// {
5713// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5714// {
5715// UUID agentID = grp.OwnerID;
5716// if (agentID == UUID.Zero)
5717// {
5718// objectsToDelete.Add(grp);
5719// return;
5720// }
5721//
5722// ScenePresence sp = GetScenePresence(agentID);
5723// if (sp == null)
5724// {
5725// objectsToDelete.Add(grp);
5726// return;
5727// }
5728// }
5729// });
5730// }
5731//
5732// foreach (SceneObjectGroup grp in objectsToDelete)
5733// {
5734// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5735// DeleteSceneObject(grp, true);
5736// }
5737// }
5738
5739 public void ThreadAlive(int threadCode)
5740 {
5741 switch(threadCode)
5742 {
5743 case 1: // Incoming
5744 m_lastIncoming = Util.EnvironmentTickCount();
5745 break;
5746 case 2: // Incoming
5747 m_lastOutgoing = Util.EnvironmentTickCount();
5748 break;
5749 }
5750 }
5751
5752 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5444 { 5753 {
5445 RegenerateMaptile(); 5754 RegenerateMaptile();
5446 5755
@@ -5468,6 +5777,8 @@ namespace OpenSim.Region.Framework.Scenes
5468 /// <returns></returns> 5777 /// <returns></returns>
5469 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5778 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5470 { 5779 {
5780 reason = "You are banned from the region";
5781
5471 if (EntityTransferModule.IsInTransit(agentID)) 5782 if (EntityTransferModule.IsInTransit(agentID))
5472 { 5783 {
5473 reason = "Agent is still in transit from this region"; 5784 reason = "Agent is still in transit from this region";
@@ -5479,6 +5790,12 @@ namespace OpenSim.Region.Framework.Scenes
5479 return false; 5790 return false;
5480 } 5791 }
5481 5792
5793 if (Permissions.IsGod(agentID))
5794 {
5795 reason = String.Empty;
5796 return true;
5797 }
5798
5482 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5799 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5483 // However, the long term fix is to make sure root agent count is always accurate. 5800 // However, the long term fix is to make sure root agent count is always accurate.
5484 m_sceneGraph.RecalculateStats(); 5801 m_sceneGraph.RecalculateStats();
@@ -5499,6 +5816,41 @@ namespace OpenSim.Region.Framework.Scenes
5499 } 5816 }
5500 } 5817 }
5501 5818
5819 ScenePresence presence = GetScenePresence(agentID);
5820 IClientAPI client = null;
5821 AgentCircuitData aCircuit = null;
5822
5823 if (presence != null)
5824 {
5825 client = presence.ControllingClient;
5826 if (client != null)
5827 aCircuit = client.RequestClientInfo();
5828 }
5829
5830 // We may be called before there is a presence or a client.
5831 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5832 if (client == null)
5833 {
5834 aCircuit = new AgentCircuitData();
5835 aCircuit.AgentID = agentID;
5836 aCircuit.firstname = String.Empty;
5837 aCircuit.lastname = String.Empty;
5838 }
5839
5840 try
5841 {
5842 if (!AuthorizeUser(aCircuit, out reason))
5843 {
5844 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5845 return false;
5846 }
5847 }
5848 catch (Exception e)
5849 {
5850 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5851 return false;
5852 }
5853
5502 if (position == Vector3.Zero) // Teleport 5854 if (position == Vector3.Zero) // Teleport
5503 { 5855 {
5504 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5856 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5527,13 +5879,46 @@ namespace OpenSim.Region.Framework.Scenes
5527 } 5879 }
5528 } 5880 }
5529 } 5881 }
5882
5883 float posX = 128.0f;
5884 float posY = 128.0f;
5885
5886 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5887 {
5888 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5889 return false;
5890 }
5891 }
5892 else // Walking
5893 {
5894 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5895 if (land == null)
5896 return false;
5897
5898 bool banned = land.IsBannedFromLand(agentID);
5899 bool restricted = land.IsRestrictedFromLand(agentID);
5900
5901 if (banned || restricted)
5902 return false;
5530 } 5903 }
5531 5904
5532 reason = String.Empty; 5905 reason = String.Empty;
5533 return true; 5906 return true;
5534 } 5907 }
5535 5908
5536 /// <summary> 5909 public void StartTimerWatchdog()
5910 {
5911 m_timerWatchdog.Interval = 1000;
5912 m_timerWatchdog.Elapsed += TimerWatchdog;
5913 m_timerWatchdog.AutoReset = true;
5914 m_timerWatchdog.Start();
5915 }
5916
5917 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5918 {
5919 CheckHeartbeat();
5920 }
5921
5537 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5922 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5538 /// autopilot that moves an avatar to a sit target!. 5923 /// autopilot that moves an avatar to a sit target!.
5539 /// </summary> 5924 /// </summary>
@@ -5612,6 +5997,11 @@ namespace OpenSim.Region.Framework.Scenes
5612 return m_SpawnPoint - 1; 5997 return m_SpawnPoint - 1;
5613 } 5998 }
5614 5999
6000 private void HandleGcCollect(string module, string[] args)
6001 {
6002 GC.Collect();
6003 }
6004
5615 /// <summary> 6005 /// <summary>
5616 /// Wrappers to get physics modules retrieve assets. 6006 /// Wrappers to get physics modules retrieve assets.
5617 /// </summary> 6007 /// </summary>