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 5b61538..a229a9a 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 string[] possibleMapConfigSections = new string[] { "Map", "Startup" }; 924 string[] possibleMapConfigSections = new string[] { "Map", "Startup" };
901 925
@@ -935,7 +959,7 @@ namespace OpenSim.Region.Framework.Scenes
935 string grant = startupConfig.GetString("AllowedClients", String.Empty); 959 string grant = startupConfig.GetString("AllowedClients", String.Empty);
936 if (grant.Length > 0) 960 if (grant.Length > 0)
937 { 961 {
938 foreach (string viewer in grant.Split('|')) 962 foreach (string viewer in grant.Split(','))
939 { 963 {
940 m_AllowedViewers.Add(viewer.Trim().ToLower()); 964 m_AllowedViewers.Add(viewer.Trim().ToLower());
941 } 965 }
@@ -944,7 +968,7 @@ namespace OpenSim.Region.Framework.Scenes
944 grant = startupConfig.GetString("BannedClients", String.Empty); 968 grant = startupConfig.GetString("BannedClients", String.Empty);
945 if (grant.Length > 0) 969 if (grant.Length > 0)
946 { 970 {
947 foreach (string viewer in grant.Split('|')) 971 foreach (string viewer in grant.Split(','))
948 { 972 {
949 m_BannedViewers.Add(viewer.Trim().ToLower()); 973 m_BannedViewers.Add(viewer.Trim().ToLower());
950 } 974 }
@@ -1004,6 +1028,8 @@ namespace OpenSim.Region.Framework.Scenes
1004 StatsReporter = new SimStatsReporter(this); 1028 StatsReporter = new SimStatsReporter(this);
1005 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 1029 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
1006 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 1030 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
1031
1032 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
1007 } 1033 }
1008 1034
1009 public Scene(RegionInfo regInfo) : base(regInfo) 1035 public Scene(RegionInfo regInfo) : base(regInfo)
@@ -1299,8 +1325,11 @@ namespace OpenSim.Region.Framework.Scenes
1299 // Stop all client threads. 1325 // Stop all client threads.
1300 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); }); 1326 ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); });
1301 1327
1302 m_log.Debug("[SCENE]: Persisting changed objects"); 1328 m_log.Debug("[SCENE]: TriggerSceneShuttingDown");
1303 EventManager.TriggerSceneShuttingDown(this); 1329 EventManager.TriggerSceneShuttingDown(this);
1330
1331 m_log.Debug("[SCENE]: Persisting changed objects");
1332
1304 Backup(false); 1333 Backup(false);
1305 m_sceneGraph.Close(); 1334 m_sceneGraph.Close();
1306 1335
@@ -1314,6 +1343,7 @@ namespace OpenSim.Region.Framework.Scenes
1314 // attempt to reference a null or disposed physics scene. 1343 // attempt to reference a null or disposed physics scene.
1315 if (PhysicsScene != null) 1344 if (PhysicsScene != null)
1316 { 1345 {
1346 m_log.Debug("[SCENE]: Dispose Physics");
1317 PhysicsScene phys = PhysicsScene; 1347 PhysicsScene phys = PhysicsScene;
1318 // remove the physics engine from both Scene and SceneGraph 1348 // remove the physics engine from both Scene and SceneGraph
1319 PhysicsScene = null; 1349 PhysicsScene = null;
@@ -1336,11 +1366,29 @@ namespace OpenSim.Region.Framework.Scenes
1336 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 1366 //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
1337 if (m_heartbeatThread != null) 1367 if (m_heartbeatThread != null)
1338 { 1368 {
1369 m_hbRestarts++;
1370 if(m_hbRestarts > 10)
1371 Environment.Exit(1);
1372 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1373
1374//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1375//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1376//proc.EnableRaisingEvents=false;
1377//proc.StartInfo.FileName = "/bin/kill";
1378//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1379//proc.Start();
1380//proc.WaitForExit();
1381//Thread.Sleep(1000);
1382//Environment.Exit(1);
1339 m_heartbeatThread.Abort(); 1383 m_heartbeatThread.Abort();
1384 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1340 m_heartbeatThread = null; 1385 m_heartbeatThread = null;
1341 } 1386 }
1342// m_lastUpdate = Util.EnvironmentTickCount(); 1387// m_lastUpdate = Util.EnvironmentTickCount();
1343 1388
1389// m_sceneGraph.PreparePhysicsSimulation();
1390
1391
1344 m_heartbeatThread 1392 m_heartbeatThread
1345 = Watchdog.StartThread( 1393 = Watchdog.StartThread(
1346 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false); 1394 Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false);
@@ -1483,16 +1531,20 @@ namespace OpenSim.Region.Framework.Scenes
1483 endFrame = Frame + frames; 1531 endFrame = Frame + frames;
1484 1532
1485 float physicsFPS = 0f; 1533 float physicsFPS = 0f;
1486 int previousFrameTick, tmpMS; 1534 int tmpMS;
1487 int maintc = Util.EnvironmentTickCount(); 1535 int previousFrameTick;
1536 int maintc;
1537 int sleepMS;
1538 int framestart;
1488 1539
1489 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) 1540 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
1490 { 1541 {
1542 framestart = Util.EnvironmentTickCount();
1491 ++Frame; 1543 ++Frame;
1492 1544
1493// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1545// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1494 1546
1495 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1547 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1496 1548
1497 try 1549 try
1498 { 1550 {
@@ -1544,6 +1596,7 @@ namespace OpenSim.Region.Framework.Scenes
1544 m_sceneGraph.UpdatePresences(); 1596 m_sceneGraph.UpdatePresences();
1545 1597
1546 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1598 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1599
1547 1600
1548 // Delete temp-on-rez stuff 1601 // Delete temp-on-rez stuff
1549 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1602 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
@@ -1625,34 +1678,37 @@ namespace OpenSim.Region.Framework.Scenes
1625 1678
1626 Watchdog.UpdateThread(); 1679 Watchdog.UpdateThread();
1627 1680
1681 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1682
1683 StatsReporter.AddPhysicsFPS(physicsFPS);
1684 StatsReporter.AddTimeDilation(TimeDilation);
1685 StatsReporter.AddFPS(1);
1686
1687 StatsReporter.addAgentMS(agentMS);
1688 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1689 StatsReporter.addOtherMS(otherMS);
1690 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1691
1628 previousFrameTick = m_lastFrameTick; 1692 previousFrameTick = m_lastFrameTick;
1629 m_lastFrameTick = Util.EnvironmentTickCount(); 1693 m_lastFrameTick = Util.EnvironmentTickCount();
1630 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc); 1694 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
1631 tmpMS = (int)(MinFrameTime * 1000) - tmpMS; 1695 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1632 1696
1697 m_firstHeartbeat = false;
1698
1699 sleepMS = Util.EnvironmentTickCount();
1700
1633 if (tmpMS > 0) 1701 if (tmpMS > 0)
1634 {
1635 Thread.Sleep(tmpMS); 1702 Thread.Sleep(tmpMS);
1636 spareMS += tmpMS;
1637 }
1638
1639 frameMS = Util.EnvironmentTickCountSubtract(maintc);
1640 maintc = Util.EnvironmentTickCount();
1641 1703
1642 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; 1704 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1705 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1706 StatsReporter.addSleepMS(sleepMS);
1707 StatsReporter.addFrameMS(frameMS);
1643 1708
1644 // if (Frame%m_update_avatars == 0) 1709 // if (Frame%m_update_avatars == 0)
1645 // UpdateInWorldTime(); 1710 // UpdateInWorldTime();
1646 StatsReporter.AddPhysicsFPS(physicsFPS);
1647 StatsReporter.AddTimeDilation(TimeDilation);
1648 StatsReporter.AddFPS(1);
1649 1711
1650 StatsReporter.addFrameMS(frameMS);
1651 StatsReporter.addAgentMS(agentMS);
1652 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1653 StatsReporter.addOtherMS(otherMS);
1654 StatsReporter.AddSpareMS(spareMS);
1655 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1656 1712
1657 // Optionally warn if a frame takes double the amount of time that it should. 1713 // Optionally warn if a frame takes double the amount of time that it should.
1658 if (DebugUpdates 1714 if (DebugUpdates
@@ -1669,7 +1725,7 @@ namespace OpenSim.Region.Framework.Scenes
1669 public void AddGroupTarget(SceneObjectGroup grp) 1725 public void AddGroupTarget(SceneObjectGroup grp)
1670 { 1726 {
1671 lock (m_groupsWithTargets) 1727 lock (m_groupsWithTargets)
1672 m_groupsWithTargets[grp.UUID] = grp; 1728 m_groupsWithTargets[grp.UUID] = 0;
1673 } 1729 }
1674 1730
1675 public void RemoveGroupTarget(SceneObjectGroup grp) 1731 public void RemoveGroupTarget(SceneObjectGroup grp)
@@ -1680,18 +1736,24 @@ namespace OpenSim.Region.Framework.Scenes
1680 1736
1681 private void CheckAtTargets() 1737 private void CheckAtTargets()
1682 { 1738 {
1683 List<SceneObjectGroup> objs = null; 1739 List<UUID> objs = null;
1684 1740
1685 lock (m_groupsWithTargets) 1741 lock (m_groupsWithTargets)
1686 { 1742 {
1687 if (m_groupsWithTargets.Count != 0) 1743 if (m_groupsWithTargets.Count != 0)
1688 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values); 1744 objs = new List<UUID>(m_groupsWithTargets.Keys);
1689 } 1745 }
1690 1746
1691 if (objs != null) 1747 if (objs != null)
1692 { 1748 {
1693 foreach (SceneObjectGroup entry in objs) 1749 foreach (UUID entry in objs)
1694 entry.checkAtTargets(); 1750 {
1751 SceneObjectGroup grp = GetSceneObjectGroup(entry);
1752 if (grp == null)
1753 m_groupsWithTargets.Remove(entry);
1754 else
1755 grp.checkAtTargets();
1756 }
1695 } 1757 }
1696 } 1758 }
1697 1759
@@ -1770,7 +1832,7 @@ namespace OpenSim.Region.Framework.Scenes
1770 msg.fromAgentName = "Server"; 1832 msg.fromAgentName = "Server";
1771 msg.dialog = (byte)19; // Object msg 1833 msg.dialog = (byte)19; // Object msg
1772 msg.fromGroup = false; 1834 msg.fromGroup = false;
1773 msg.offline = (byte)0; 1835 msg.offline = (byte)1;
1774 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 1836 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
1775 msg.Position = Vector3.Zero; 1837 msg.Position = Vector3.Zero;
1776 msg.RegionID = RegionInfo.RegionID.Guid; 1838 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -1999,7 +2061,7 @@ namespace OpenSim.Region.Framework.Scenes
1999 return PhysicsScene.SupportsRaycastWorldFiltered(); 2061 return PhysicsScene.SupportsRaycastWorldFiltered();
2000 } 2062 }
2001 2063
2002 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) 2064 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2003 { 2065 {
2004 if (PhysicsScene == null) 2066 if (PhysicsScene == null)
2005 return null; 2067 return null;
@@ -2021,14 +2083,24 @@ namespace OpenSim.Region.Framework.Scenes
2021 /// <returns></returns> 2083 /// <returns></returns>
2022 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2084 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
2023 { 2085 {
2086
2087 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2088 Vector3 wpos = Vector3.Zero;
2089 // Check for water surface intersection from above
2090 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2091 {
2092 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2093 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2094 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2095 wpos.Z = wheight;
2096 }
2097
2024 Vector3 pos = Vector3.Zero; 2098 Vector3 pos = Vector3.Zero;
2025 if (RayEndIsIntersection == (byte)1) 2099 if (RayEndIsIntersection == (byte)1)
2026 { 2100 {
2027 pos = RayEnd; 2101 pos = RayEnd;
2028 return pos;
2029 } 2102 }
2030 2103 else if (RayTargetID != UUID.Zero)
2031 if (RayTargetID != UUID.Zero)
2032 { 2104 {
2033 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2105 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
2034 2106
@@ -2050,7 +2122,7 @@ namespace OpenSim.Region.Framework.Scenes
2050 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); 2122 EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
2051 2123
2052 // Un-comment out the following line to Get Raytrace results printed to the console. 2124 // Un-comment out the following line to Get Raytrace results printed to the console.
2053 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 2125 // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
2054 float ScaleOffset = 0.5f; 2126 float ScaleOffset = 0.5f;
2055 2127
2056 // If we hit something 2128 // If we hit something
@@ -2073,13 +2145,10 @@ namespace OpenSim.Region.Framework.Scenes
2073 //pos.Z -= 0.25F; 2145 //pos.Z -= 0.25F;
2074 2146
2075 } 2147 }
2076
2077 return pos;
2078 } 2148 }
2079 else 2149 else
2080 { 2150 {
2081 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2151 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2082
2083 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2152 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2084 2153
2085 // Un-comment the following line to print the raytrace results to the console. 2154 // Un-comment the following line to print the raytrace results to the console.
@@ -2088,13 +2157,12 @@ namespace OpenSim.Region.Framework.Scenes
2088 if (ei.HitTF) 2157 if (ei.HitTF)
2089 { 2158 {
2090 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); 2159 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2091 } else 2160 }
2161 else
2092 { 2162 {
2093 // fall back to our stupid functionality 2163 // fall back to our stupid functionality
2094 pos = RayEnd; 2164 pos = RayEnd;
2095 } 2165 }
2096
2097 return pos;
2098 } 2166 }
2099 } 2167 }
2100 else 2168 else
@@ -2105,8 +2173,12 @@ namespace OpenSim.Region.Framework.Scenes
2105 //increase height so its above the ground. 2173 //increase height so its above the ground.
2106 //should be getting the normal of the ground at the rez point and using that? 2174 //should be getting the normal of the ground at the rez point and using that?
2107 pos.Z += scale.Z / 2f; 2175 pos.Z += scale.Z / 2f;
2108 return pos; 2176// return pos;
2109 } 2177 }
2178
2179 // check against posible water intercept
2180 if (wpos.Z > pos.Z) pos = wpos;
2181 return pos;
2110 } 2182 }
2111 2183
2112 2184
@@ -2197,12 +2269,12 @@ namespace OpenSim.Region.Framework.Scenes
2197 { 2269 {
2198 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates)) 2270 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates))
2199 { 2271 {
2272 sceneObject.IsDeleted = false;
2200 EventManager.TriggerObjectAddedToScene(sceneObject); 2273 EventManager.TriggerObjectAddedToScene(sceneObject);
2201 return true; 2274 return true;
2202 } 2275 }
2203 2276
2204 return false; 2277 return false;
2205
2206 } 2278 }
2207 2279
2208 /// <summary> 2280 /// <summary>
@@ -2294,6 +2366,15 @@ namespace OpenSim.Region.Framework.Scenes
2294 /// </summary> 2366 /// </summary>
2295 public void DeleteAllSceneObjects() 2367 public void DeleteAllSceneObjects()
2296 { 2368 {
2369 DeleteAllSceneObjects(false);
2370 }
2371
2372 /// <summary>
2373 /// Delete every object from the scene. This does not include attachments worn by avatars.
2374 /// </summary>
2375 public void DeleteAllSceneObjects(bool exceptNoCopy)
2376 {
2377 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2297 lock (Entities) 2378 lock (Entities)
2298 { 2379 {
2299 EntityBase[] entities = Entities.GetEntities(); 2380 EntityBase[] entities = Entities.GetEntities();
@@ -2302,11 +2383,24 @@ namespace OpenSim.Region.Framework.Scenes
2302 if (e is SceneObjectGroup) 2383 if (e is SceneObjectGroup)
2303 { 2384 {
2304 SceneObjectGroup sog = (SceneObjectGroup)e; 2385 SceneObjectGroup sog = (SceneObjectGroup)e;
2305 if (!sog.IsAttachment) 2386 if (sog != null && !sog.IsAttachment)
2306 DeleteSceneObject((SceneObjectGroup)e, false); 2387 {
2388 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2389 {
2390 DeleteSceneObject((SceneObjectGroup)e, false);
2391 }
2392 else
2393 {
2394 toReturn.Add((SceneObjectGroup)e);
2395 }
2396 }
2307 } 2397 }
2308 } 2398 }
2309 } 2399 }
2400 if (toReturn.Count > 0)
2401 {
2402 returnObjects(toReturn.ToArray(), UUID.Zero);
2403 }
2310 } 2404 }
2311 2405
2312 /// <summary> 2406 /// <summary>
@@ -2341,6 +2435,12 @@ namespace OpenSim.Region.Framework.Scenes
2341 2435
2342 foreach (SceneObjectPart part in partList) 2436 foreach (SceneObjectPart part in partList)
2343 { 2437 {
2438 if (part.KeyframeMotion != null)
2439 {
2440 part.KeyframeMotion.Delete();
2441 part.KeyframeMotion = null;
2442 }
2443
2344 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0)) 2444 if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
2345 { 2445 {
2346 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? 2446 PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
@@ -2358,6 +2458,8 @@ namespace OpenSim.Region.Framework.Scenes
2358 } 2458 }
2359 2459
2360 group.DeleteGroupFromScene(silent); 2460 group.DeleteGroupFromScene(silent);
2461 if (!silent)
2462 SendKillObject(new List<uint>() { group.LocalId });
2361 2463
2362// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2464// m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2363 } 2465 }
@@ -2648,7 +2750,7 @@ namespace OpenSim.Region.Framework.Scenes
2648 // If the user is banned, we won't let any of their objects 2750 // If the user is banned, we won't let any of their objects
2649 // enter. Period. 2751 // enter. Period.
2650 // 2752 //
2651 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID)) 2753 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
2652 { 2754 {
2653 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID); 2755 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
2654 return false; 2756 return false;
@@ -2656,6 +2758,8 @@ namespace OpenSim.Region.Framework.Scenes
2656 2758
2657 if (newPosition != Vector3.Zero) 2759 if (newPosition != Vector3.Zero)
2658 newObject.RootPart.GroupPosition = newPosition; 2760 newObject.RootPart.GroupPosition = newPosition;
2761 if (newObject.RootPart.KeyframeMotion != null)
2762 newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
2659 2763
2660 if (!AddSceneObject(newObject)) 2764 if (!AddSceneObject(newObject))
2661 { 2765 {
@@ -2700,6 +2804,23 @@ namespace OpenSim.Region.Framework.Scenes
2700 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 2804 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2701 public bool AddSceneObject(SceneObjectGroup sceneObject) 2805 public bool AddSceneObject(SceneObjectGroup sceneObject)
2702 { 2806 {
2807 if (sceneObject.OwnerID == UUID.Zero)
2808 {
2809 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
2810 return false;
2811 }
2812
2813 // If the user is banned, we won't let any of their objects
2814 // enter. Period.
2815 //
2816 int flags = GetUserFlags(sceneObject.OwnerID);
2817 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
2818 {
2819 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
2820
2821 return false;
2822 }
2823
2703 // Force allocation of new LocalId 2824 // Force allocation of new LocalId
2704 // 2825 //
2705 SceneObjectPart[] parts = sceneObject.Parts; 2826 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2733,16 +2854,27 @@ namespace OpenSim.Region.Framework.Scenes
2733 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2854 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2734 2855
2735 if (AttachmentsModule != null) 2856 if (AttachmentsModule != null)
2736 AttachmentsModule.AttachObject(sp, grp, 0, false, false); 2857 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false);
2737 } 2858 }
2738 else 2859 else
2739 { 2860 {
2861 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2740 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2862 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2741 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 2863 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2742 } 2864 }
2865 if (sceneObject.OwnerID == UUID.Zero)
2866 {
2867 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
2868 return false;
2869 }
2743 } 2870 }
2744 else 2871 else
2745 { 2872 {
2873 if (sceneObject.OwnerID == UUID.Zero)
2874 {
2875 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
2876 return false;
2877 }
2746 AddRestoredSceneObject(sceneObject, true, false); 2878 AddRestoredSceneObject(sceneObject, true, false);
2747 } 2879 }
2748 2880
@@ -2759,6 +2891,24 @@ namespace OpenSim.Region.Framework.Scenes
2759 return 2; // StateSource.PrimCrossing 2891 return 2; // StateSource.PrimCrossing
2760 } 2892 }
2761 2893
2894 public int GetUserFlags(UUID user)
2895 {
2896 //Unfortunately the SP approach means that the value is cached until region is restarted
2897 /*
2898 ScenePresence sp;
2899 if (TryGetScenePresence(user, out sp))
2900 {
2901 return sp.UserFlags;
2902 }
2903 else
2904 {
2905 */
2906 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
2907 if (uac == null)
2908 return 0;
2909 return uac.UserFlags;
2910 //}
2911 }
2762 #endregion 2912 #endregion
2763 2913
2764 #region Add/Remove Avatar Methods 2914 #region Add/Remove Avatar Methods
@@ -2791,7 +2941,7 @@ namespace OpenSim.Region.Framework.Scenes
2791 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 2941 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2792 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 2942 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
2793 2943
2794 // CheckHeartbeat(); 2944 CheckHeartbeat();
2795 2945
2796 sp = GetScenePresence(client.AgentId); 2946 sp = GetScenePresence(client.AgentId);
2797 2947
@@ -2809,6 +2959,13 @@ namespace OpenSim.Region.Framework.Scenes
2809 SubscribeToClientEvents(client); 2959 SubscribeToClientEvents(client);
2810 2960
2811 sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type); 2961 sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type);
2962 InventoryFolderBase cof = InventoryService.GetFolderForType(client.AgentId, (AssetType)46);
2963 if (cof == null)
2964 sp.COF = UUID.Zero;
2965 else
2966 sp.COF = cof.ID;
2967
2968 m_log.DebugFormat("[SCENE]: COF for {0} is {1}", client.AgentId, sp.COF);
2812 m_eventManager.TriggerOnNewPresence(sp); 2969 m_eventManager.TriggerOnNewPresence(sp);
2813 2970
2814 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags; 2971 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags;
@@ -2822,6 +2979,7 @@ namespace OpenSim.Region.Framework.Scenes
2822 // start the scripts again (since this is done in RezAttachments()). 2979 // start the scripts again (since this is done in RezAttachments()).
2823 // XXX: This is convoluted. 2980 // XXX: This is convoluted.
2824 sp.IsChildAgent = false; 2981 sp.IsChildAgent = false;
2982 sp.IsLoggingIn = true;
2825 2983
2826 if (AttachmentsModule != null) 2984 if (AttachmentsModule != null)
2827 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); }); 2985 Util.FireAndForget(delegate(object o) { AttachmentsModule.RezAttachments(sp); });
@@ -2935,19 +3093,14 @@ namespace OpenSim.Region.Framework.Scenes
2935 // and the scene presence and the client, if they exist 3093 // and the scene presence and the client, if they exist
2936 try 3094 try
2937 { 3095 {
2938 // We need to wait for the client to make UDP contact first. 3096 ScenePresence sp = GetScenePresence(agentID);
2939 // It's the UDP contact that creates the scene presence 3097
2940 ScenePresence sp = WaitGetScenePresence(agentID);
2941 if (sp != null) 3098 if (sp != null)
2942 { 3099 {
2943 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3100 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
2944
2945 sp.ControllingClient.Close(); 3101 sp.ControllingClient.Close();
2946 } 3102 }
2947 else 3103
2948 {
2949 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
2950 }
2951 // BANG! SLASH! 3104 // BANG! SLASH!
2952 m_authenticateHandler.RemoveCircuit(agentID); 3105 m_authenticateHandler.RemoveCircuit(agentID);
2953 3106
@@ -2992,6 +3145,8 @@ namespace OpenSim.Region.Framework.Scenes
2992 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3145 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
2993 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3146 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
2994 3147
3148 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3149
2995 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3150 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
2996 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3151 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
2997 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3152 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -3048,6 +3203,7 @@ namespace OpenSim.Region.Framework.Scenes
3048 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3203 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
3049 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3204 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
3050 client.OnCopyInventoryItem += CopyInventoryItem; 3205 client.OnCopyInventoryItem += CopyInventoryItem;
3206 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
3051 client.OnMoveInventoryItem += MoveInventoryItem; 3207 client.OnMoveInventoryItem += MoveInventoryItem;
3052 client.OnRemoveInventoryItem += RemoveInventoryItem; 3208 client.OnRemoveInventoryItem += RemoveInventoryItem;
3053 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3209 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3119,6 +3275,8 @@ namespace OpenSim.Region.Framework.Scenes
3119 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3275 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3120 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3276 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3121 3277
3278 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3279
3122 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3280 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3123 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3281 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3124 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3282 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3221,7 +3379,7 @@ namespace OpenSim.Region.Framework.Scenes
3221 /// </summary> 3379 /// </summary>
3222 /// <param name="agentId">The avatar's Unique ID</param> 3380 /// <param name="agentId">The avatar's Unique ID</param>
3223 /// <param name="client">The IClientAPI for the client</param> 3381 /// <param name="client">The IClientAPI for the client</param>
3224 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3382 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3225 { 3383 {
3226 if (EntityTransferModule != null) 3384 if (EntityTransferModule != null)
3227 { 3385 {
@@ -3232,6 +3390,7 @@ namespace OpenSim.Region.Framework.Scenes
3232 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3390 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3233 client.SendTeleportFailed("Unable to perform teleports on this simulator."); 3391 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3234 } 3392 }
3393 return false;
3235 } 3394 }
3236 3395
3237 /// <summary> 3396 /// <summary>
@@ -3341,6 +3500,16 @@ namespace OpenSim.Region.Framework.Scenes
3341 /// <param name="flags"></param> 3500 /// <param name="flags"></param>
3342 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3501 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3343 { 3502 {
3503 //Add half the avatar's height so that the user doesn't fall through prims
3504 ScenePresence presence;
3505 if (TryGetScenePresence(remoteClient.AgentId, out presence))
3506 {
3507 if (presence.Appearance != null)
3508 {
3509 position.Z = position.Z + (presence.Appearance.AvatarHeight / 2);
3510 }
3511 }
3512
3344 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3513 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3345 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3514 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3346 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3515 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
@@ -3478,6 +3647,7 @@ namespace OpenSim.Region.Framework.Scenes
3478 // It's possible for child agents to have transactions if changes are being made cross-border. 3647 // It's possible for child agents to have transactions if changes are being made cross-border.
3479 if (AgentTransactionsModule != null) 3648 if (AgentTransactionsModule != null)
3480 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 3649 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3650 m_log.Debug("[Scene] The avatar has left the building");
3481 } 3651 }
3482 catch (Exception e) 3652 catch (Exception e)
3483 { 3653 {
@@ -3670,38 +3840,39 @@ namespace OpenSim.Region.Framework.Scenes
3670 agent.firstname, agent.lastname, agent.Viewer); 3840 agent.firstname, agent.lastname, agent.Viewer);
3671 reason = "Access denied, your viewer is banned by the region owner"; 3841 reason = "Access denied, your viewer is banned by the region owner";
3672 return false; 3842 return false;
3673 } 3843 }
3844
3845
3846 ScenePresence sp = GetScenePresence(agent.AgentID);
3674 3847
3675 ILandObject land; 3848 if (sp != null && !sp.IsChildAgent)
3849 {
3850 // We have a zombie from a crashed session.
3851 // Or the same user is trying to be root twice here, won't work.
3852 // Kill it.
3853 m_log.WarnFormat(
3854 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3855 sp.Name, sp.UUID, RegionInfo.RegionName);
3856
3857 sp.ControllingClient.Close(true, true);
3858 sp = null;
3859 }
3676 3860
3677 lock (agent) 3861 lock (agent)
3678 { 3862 {
3679 ScenePresence sp = GetScenePresence(agent.AgentID);
3680
3681 if (sp != null && !sp.IsChildAgent)
3682 {
3683 // We have a zombie from a crashed session.
3684 // Or the same user is trying to be root twice here, won't work.
3685 // Kill it.
3686 m_log.WarnFormat(
3687 "[SCENE]: Existing root scene presence detected for {0} {1} in {2} when connecting. Removing existing presence.",
3688 sp.Name, sp.UUID, RegionInfo.RegionName);
3689
3690 sp.ControllingClient.Close(true);
3691 sp = null;
3692 }
3693
3694 land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3695
3696 //On login test land permisions 3863 //On login test land permisions
3697 if (vialogin) 3864 if (vialogin)
3698 { 3865 {
3699 if (land != null && !TestLandRestrictions(agent, land, out reason)) 3866 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
3867 if (cache != null)
3868 cache.Remove(agent.firstname + " " + agent.lastname);
3869 if (!TestLandRestrictions(agent.AgentID, out reason, ref agent.startpos.X, ref agent.startpos.Y))
3700 { 3870 {
3871 m_log.DebugFormat("[CONNECTION BEGIN]: Denying access to {0} due to no land access", agent.AgentID.ToString());
3701 return false; 3872 return false;
3702 } 3873 }
3703 } 3874 }
3704 3875
3705 if (sp == null) // We don't have an [child] agent here already 3876 if (sp == null) // We don't have an [child] agent here already
3706 { 3877 {
3707 if (requirePresenceLookup) 3878 if (requirePresenceLookup)
@@ -3710,34 +3881,36 @@ namespace OpenSim.Region.Framework.Scenes
3710 { 3881 {
3711 if (!VerifyUserPresence(agent, out reason)) 3882 if (!VerifyUserPresence(agent, out reason))
3712 return false; 3883 return false;
3713 } 3884 } catch (Exception e)
3714 catch (Exception e)
3715 { 3885 {
3716 m_log.ErrorFormat( 3886 m_log.ErrorFormat(
3717 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace); 3887 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace);
3718
3719 return false; 3888 return false;
3720 } 3889 }
3721 } 3890 }
3722 3891
3723 try 3892 try
3724 { 3893 {
3725 if (!AuthorizeUser(agent, out reason)) 3894 // Always check estate if this is a login. Always
3726 return false; 3895 // check if banned regions are to be blacked out.
3896 if (vialogin || (!m_seeIntoBannedRegion))
3897 {
3898 if (!AuthorizeUser(agent, out reason))
3899 return false;
3900 }
3727 } 3901 }
3728 catch (Exception e) 3902 catch (Exception e)
3729 { 3903 {
3730 m_log.ErrorFormat( 3904 m_log.ErrorFormat(
3731 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace); 3905 "[SCENE]: Exception authorizing user {0}{1}", e.Message, e.StackTrace);
3732
3733 return false; 3906 return false;
3734 } 3907 }
3735 3908
3736 m_log.InfoFormat( 3909 m_log.InfoFormat(
3737 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})", 3910 "[SCENE]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})",
3738 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname, 3911 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
3739 agent.AgentID, agent.circuitcode); 3912 agent.AgentID, agent.circuitcode);
3740 3913
3741 if (CapsModule != null) 3914 if (CapsModule != null)
3742 { 3915 {
3743 CapsModule.SetAgentCapsSeeds(agent); 3916 CapsModule.SetAgentCapsSeeds(agent);
@@ -3749,15 +3922,15 @@ namespace OpenSim.Region.Framework.Scenes
3749 // Let the SP know how we got here. This has a lot of interesting 3922 // Let the SP know how we got here. This has a lot of interesting
3750 // uses down the line. 3923 // uses down the line.
3751 sp.TeleportFlags = (TPFlags)teleportFlags; 3924 sp.TeleportFlags = (TPFlags)teleportFlags;
3752 3925
3753 if (sp.IsChildAgent) 3926 if (sp.IsChildAgent)
3754 { 3927 {
3755 m_log.DebugFormat( 3928 m_log.DebugFormat(
3756 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}", 3929 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
3757 agent.AgentID, RegionInfo.RegionName); 3930 agent.AgentID, RegionInfo.RegionName);
3758 3931
3759 sp.AdjustKnownSeeds(); 3932 sp.AdjustKnownSeeds();
3760 3933
3761 if (CapsModule != null) 3934 if (CapsModule != null)
3762 CapsModule.SetAgentCapsSeeds(agent); 3935 CapsModule.SetAgentCapsSeeds(agent);
3763 } 3936 }
@@ -3859,6 +4032,8 @@ namespace OpenSim.Region.Framework.Scenes
3859 } 4032 }
3860 4033
3861 // Honor parcel landing type and position. 4034 // Honor parcel landing type and position.
4035 /*
4036 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3862 if (land != null) 4037 if (land != null)
3863 { 4038 {
3864 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 4039 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3866,25 +4041,43 @@ namespace OpenSim.Region.Framework.Scenes
3866 agent.startpos = land.LandData.UserLocation; 4041 agent.startpos = land.LandData.UserLocation;
3867 } 4042 }
3868 } 4043 }
4044 */// This is now handled properly in ScenePresence.MakeRootAgent
3869 } 4045 }
3870 4046
3871 return true; 4047 return true;
3872 } 4048 }
3873 4049
3874 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason) 4050 public bool TestLandRestrictions(UUID agentID, out string reason, ref float posX, ref float posY)
3875 { 4051 {
3876 bool banned = land.IsBannedFromLand(agent.AgentID); 4052 if (posX < 0)
3877 bool restricted = land.IsRestrictedFromLand(agent.AgentID); 4053 posX = 0;
4054 else if (posX >= 256)
4055 posX = 255.999f;
4056 if (posY < 0)
4057 posY = 0;
4058 else if (posY >= 256)
4059 posY = 255.999f;
4060
4061 reason = String.Empty;
4062 if (Permissions.IsGod(agentID))
4063 return true;
4064
4065 ILandObject land = LandChannel.GetLandObject(posX, posY);
4066 if (land == null)
4067 return false;
4068
4069 bool banned = land.IsBannedFromLand(agentID);
4070 bool restricted = land.IsRestrictedFromLand(agentID);
3878 4071
3879 if (banned || restricted) 4072 if (banned || restricted)
3880 { 4073 {
3881 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y); 4074 ILandObject nearestParcel = GetNearestAllowedParcel(agentID, posX, posY);
3882 if (nearestParcel != null) 4075 if (nearestParcel != null)
3883 { 4076 {
3884 //Move agent to nearest allowed 4077 //Move agent to nearest allowed
3885 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel); 4078 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3886 agent.startpos.X = newPosition.X; 4079 posX = newPosition.X;
3887 agent.startpos.Y = newPosition.Y; 4080 posY = newPosition.Y;
3888 } 4081 }
3889 else 4082 else
3890 { 4083 {
@@ -3946,7 +4139,7 @@ namespace OpenSim.Region.Framework.Scenes
3946 4139
3947 if (!m_strictAccessControl) return true; 4140 if (!m_strictAccessControl) return true;
3948 if (Permissions.IsGod(agent.AgentID)) return true; 4141 if (Permissions.IsGod(agent.AgentID)) return true;
3949 4142
3950 if (AuthorizationService != null) 4143 if (AuthorizationService != null)
3951 { 4144 {
3952 if (!AuthorizationService.IsAuthorizedForRegion( 4145 if (!AuthorizationService.IsAuthorizedForRegion(
@@ -3961,7 +4154,7 @@ namespace OpenSim.Region.Framework.Scenes
3961 4154
3962 if (RegionInfo.EstateSettings != null) 4155 if (RegionInfo.EstateSettings != null)
3963 { 4156 {
3964 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4157 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, 0))
3965 { 4158 {
3966 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4159 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
3967 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4160 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4151,6 +4344,15 @@ namespace OpenSim.Region.Framework.Scenes
4151 4344
4152 // XPTO: if this agent is not allowed here as root, always return false 4345 // XPTO: if this agent is not allowed here as root, always return false
4153 4346
4347 // We have to wait until the viewer contacts this region after receiving EAC.
4348 // That calls AddNewClient, which finally creates the ScenePresence
4349 int flags = GetUserFlags(cAgentData.AgentID);
4350 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4351 {
4352 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4353 return false;
4354 }
4355
4154 // TODO: This check should probably be in QueryAccess(). 4356 // TODO: This check should probably be in QueryAccess().
4155 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4357 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4156 if (nearestParcel == null) 4358 if (nearestParcel == null)
@@ -4215,7 +4417,7 @@ namespace OpenSim.Region.Framework.Scenes
4215 /// <param name='agentID'></param> 4417 /// <param name='agentID'></param>
4216 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4418 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4217 { 4419 {
4218 int ntimes = 10; 4420 int ntimes = 30;
4219 ScenePresence sp = null; 4421 ScenePresence sp = null;
4220 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4422 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4221 Thread.Sleep(1000); 4423 Thread.Sleep(1000);
@@ -4245,6 +4447,16 @@ namespace OpenSim.Region.Framework.Scenes
4245 return false; 4447 return false;
4246 } 4448 }
4247 4449
4450 public bool IncomingCloseAgent(UUID agentID)
4451 {
4452 return IncomingCloseAgent(agentID, false);
4453 }
4454
4455 public bool IncomingCloseChildAgent(UUID agentID)
4456 {
4457 return IncomingCloseAgent(agentID, true);
4458 }
4459
4248 /// <summary> 4460 /// <summary>
4249 /// Tell a single agent to disconnect from the region. 4461 /// Tell a single agent to disconnect from the region.
4250 /// </summary> 4462 /// </summary>
@@ -4260,7 +4472,7 @@ namespace OpenSim.Region.Framework.Scenes
4260 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4472 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4261 if (presence != null) 4473 if (presence != null)
4262 { 4474 {
4263 presence.ControllingClient.Close(force); 4475 presence.ControllingClient.Close(force, force);
4264 return true; 4476 return true;
4265 } 4477 }
4266 4478
@@ -4893,7 +5105,7 @@ namespace OpenSim.Region.Framework.Scenes
4893 { 5105 {
4894 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 5106 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
4895 { 5107 {
4896 if (grp.RootPart.Expires <= DateTime.Now) 5108 if (grp.GetSittingAvatarsCount() == 0 && grp.RootPart.Expires <= DateTime.Now)
4897 DeleteSceneObject(grp, false); 5109 DeleteSceneObject(grp, false);
4898 } 5110 }
4899 } 5111 }
@@ -4907,35 +5119,81 @@ namespace OpenSim.Region.Framework.Scenes
4907 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5119 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
4908 } 5120 }
4909 5121
4910 public int GetHealth() 5122 public int GetHealth(out int flags, out string message)
4911 { 5123 {
4912 // Returns: 5124 // Returns:
4913 // 1 = sim is up and accepting http requests. The heartbeat has 5125 // 1 = sim is up and accepting http requests. The heartbeat has
4914 // stopped and the sim is probably locked up, but a remote 5126 // stopped and the sim is probably locked up, but a remote
4915 // admin restart may succeed 5127 // admin restart may succeed
4916 // 5128 //
4917 // 2 = Sim is up and the heartbeat is running. The sim is likely 5129 // 2 = Sim is up and the heartbeat is running. The sim is likely
4918 // usable for people within and logins _may_ work 5130 // usable for people within
5131 //
5132 // 3 = Sim is up and one packet thread is running. Sim is
5133 // unstable and will not accept new logins
4919 // 5134 //
4920 // 3 = We have seen a new user enter within the past 4 minutes 5135 // 4 = Sim is up and both packet threads are running. Sim is
5136 // likely usable
5137 //
5138 // 5 = We have seen a new user enter within the past 4 minutes
4921 // which can be seen as positive confirmation of sim health 5139 // which can be seen as positive confirmation of sim health
4922 // 5140 //
5141
5142 flags = 0;
5143 message = String.Empty;
5144
5145 CheckHeartbeat();
5146
5147 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5148 {
5149 // We're still starting
5150 // 0 means "in startup", it can't happen another way, since
5151 // to get here, we must be able to accept http connections
5152 return 0;
5153 }
5154
4923 int health=1; // Start at 1, means we're up 5155 int health=1; // Start at 1, means we're up
4924 5156
4925 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5157 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
4926 health += 1; 5158 {
5159 health+=1;
5160 flags |= 1;
5161 }
5162
5163 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5164 {
5165 health+=1;
5166 flags |= 2;
5167 }
5168
5169 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5170 {
5171 health+=1;
5172 flags |= 4;
5173 }
4927 else 5174 else
5175 {
5176int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5177System.Diagnostics.Process proc = new System.Diagnostics.Process();
5178proc.EnableRaisingEvents=false;
5179proc.StartInfo.FileName = "/bin/kill";
5180proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5181proc.Start();
5182proc.WaitForExit();
5183Thread.Sleep(1000);
5184Environment.Exit(1);
5185 }
5186
5187 if (flags != 7)
4928 return health; 5188 return health;
4929 5189
4930 // A login in the last 4 mins? We can't be doing too badly 5190 // A login in the last 4 mins? We can't be doing too badly
4931 // 5191 //
4932 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5192 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
4933 health++; 5193 health++;
4934 else 5194 else
4935 return health; 5195 return health;
4936 5196
4937// CheckHeartbeat();
4938
4939 return health; 5197 return health;
4940 } 5198 }
4941 5199
@@ -5023,7 +5281,7 @@ namespace OpenSim.Region.Framework.Scenes
5023 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 5281 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
5024 if (wasUsingPhysics) 5282 if (wasUsingPhysics)
5025 { 5283 {
5026 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 5284 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
5027 } 5285 }
5028 } 5286 }
5029 5287
@@ -5122,14 +5380,14 @@ namespace OpenSim.Region.Framework.Scenes
5122 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 5380 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5123 } 5381 }
5124 5382
5125// private void CheckHeartbeat() 5383 private void CheckHeartbeat()
5126// { 5384 {
5127// if (m_firstHeartbeat) 5385 if (m_firstHeartbeat)
5128// return; 5386 return;
5129// 5387
5130// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 5388 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5131// StartTimer(); 5389 Start();
5132// } 5390 }
5133 5391
5134 public override ISceneObject DeserializeObject(string representation) 5392 public override ISceneObject DeserializeObject(string representation)
5135 { 5393 {
@@ -5141,9 +5399,14 @@ namespace OpenSim.Region.Framework.Scenes
5141 get { return m_allowScriptCrossings; } 5399 get { return m_allowScriptCrossings; }
5142 } 5400 }
5143 5401
5144 public Vector3? GetNearestAllowedPosition(ScenePresence avatar) 5402 public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
5403 {
5404 return GetNearestAllowedPosition(avatar, null);
5405 }
5406
5407 public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
5145 { 5408 {
5146 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 5409 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
5147 5410
5148 if (nearestParcel != null) 5411 if (nearestParcel != null)
5149 { 5412 {
@@ -5152,10 +5415,7 @@ namespace OpenSim.Region.Framework.Scenes
5152 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5415 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5153 if (nearestPoint != null) 5416 if (nearestPoint != null)
5154 { 5417 {
5155// m_log.DebugFormat( 5418 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
5156// "[SCENE]: Found a sane previous position based on velocity for {0}, sending them to {1} in {2}",
5157// avatar.Name, nearestPoint, nearestParcel.LandData.Name);
5158
5159 return nearestPoint.Value; 5419 return nearestPoint.Value;
5160 } 5420 }
5161 5421
@@ -5165,17 +5425,20 @@ namespace OpenSim.Region.Framework.Scenes
5165 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel); 5425 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
5166 if (nearestPoint != null) 5426 if (nearestPoint != null)
5167 { 5427 {
5168// m_log.DebugFormat( 5428 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
5169// "[SCENE]: {0} had a zero velocity, sending them to {1}", avatar.Name, nearestPoint);
5170
5171 return nearestPoint.Value; 5429 return nearestPoint.Value;
5172 } 5430 }
5173 5431
5174 //Ultimate backup if we have no idea where they are 5432 ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
5175// m_log.DebugFormat( 5433 if (dest != excludeParcel)
5176// "[SCENE]: No idea where {0} is, sending them to {1}", avatar.Name, avatar.lastKnownAllowedPosition); 5434 {
5435 // Ultimate backup if we have no idea where they are and
5436 // the last allowed position was in another parcel
5437 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
5438 return avatar.lastKnownAllowedPosition;
5439 }
5177 5440
5178 return avatar.lastKnownAllowedPosition; 5441 // else fall through to region edge
5179 } 5442 }
5180 5443
5181 //Go to the edge, this happens in teleporting to a region with no available parcels 5444 //Go to the edge, this happens in teleporting to a region with no available parcels
@@ -5209,13 +5472,18 @@ namespace OpenSim.Region.Framework.Scenes
5209 5472
5210 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) 5473 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5211 { 5474 {
5475 return GetNearestAllowedParcel(avatarId, x, y, null);
5476 }
5477
5478 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
5479 {
5212 List<ILandObject> all = AllParcels(); 5480 List<ILandObject> all = AllParcels();
5213 float minParcelDistance = float.MaxValue; 5481 float minParcelDistance = float.MaxValue;
5214 ILandObject nearestParcel = null; 5482 ILandObject nearestParcel = null;
5215 5483
5216 foreach (var parcel in all) 5484 foreach (var parcel in all)
5217 { 5485 {
5218 if (!parcel.IsEitherBannedOrRestricted(avatarId)) 5486 if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
5219 { 5487 {
5220 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); 5488 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5221 if (parcelDistance < minParcelDistance) 5489 if (parcelDistance < minParcelDistance)
@@ -5431,7 +5699,55 @@ namespace OpenSim.Region.Framework.Scenes
5431 mapModule.GenerateMaptile(); 5699 mapModule.GenerateMaptile();
5432 } 5700 }
5433 5701
5434 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 5702// public void CleanDroppedAttachments()
5703// {
5704// List<SceneObjectGroup> objectsToDelete =
5705// new List<SceneObjectGroup>();
5706//
5707// lock (m_cleaningAttachments)
5708// {
5709// ForEachSOG(delegate (SceneObjectGroup grp)
5710// {
5711// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
5712// {
5713// UUID agentID = grp.OwnerID;
5714// if (agentID == UUID.Zero)
5715// {
5716// objectsToDelete.Add(grp);
5717// return;
5718// }
5719//
5720// ScenePresence sp = GetScenePresence(agentID);
5721// if (sp == null)
5722// {
5723// objectsToDelete.Add(grp);
5724// return;
5725// }
5726// }
5727// });
5728// }
5729//
5730// foreach (SceneObjectGroup grp in objectsToDelete)
5731// {
5732// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
5733// DeleteSceneObject(grp, true);
5734// }
5735// }
5736
5737 public void ThreadAlive(int threadCode)
5738 {
5739 switch(threadCode)
5740 {
5741 case 1: // Incoming
5742 m_lastIncoming = Util.EnvironmentTickCount();
5743 break;
5744 case 2: // Incoming
5745 m_lastOutgoing = Util.EnvironmentTickCount();
5746 break;
5747 }
5748 }
5749
5750 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5435 { 5751 {
5436 RegenerateMaptile(); 5752 RegenerateMaptile();
5437 5753
@@ -5459,6 +5775,8 @@ namespace OpenSim.Region.Framework.Scenes
5459 /// <returns></returns> 5775 /// <returns></returns>
5460 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5776 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5461 { 5777 {
5778 reason = "You are banned from the region";
5779
5462 if (EntityTransferModule.IsInTransit(agentID)) 5780 if (EntityTransferModule.IsInTransit(agentID))
5463 { 5781 {
5464 reason = "Agent is still in transit from this region"; 5782 reason = "Agent is still in transit from this region";
@@ -5470,6 +5788,12 @@ namespace OpenSim.Region.Framework.Scenes
5470 return false; 5788 return false;
5471 } 5789 }
5472 5790
5791 if (Permissions.IsGod(agentID))
5792 {
5793 reason = String.Empty;
5794 return true;
5795 }
5796
5473 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 5797 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5474 // However, the long term fix is to make sure root agent count is always accurate. 5798 // However, the long term fix is to make sure root agent count is always accurate.
5475 m_sceneGraph.RecalculateStats(); 5799 m_sceneGraph.RecalculateStats();
@@ -5490,6 +5814,41 @@ namespace OpenSim.Region.Framework.Scenes
5490 } 5814 }
5491 } 5815 }
5492 5816
5817 ScenePresence presence = GetScenePresence(agentID);
5818 IClientAPI client = null;
5819 AgentCircuitData aCircuit = null;
5820
5821 if (presence != null)
5822 {
5823 client = presence.ControllingClient;
5824 if (client != null)
5825 aCircuit = client.RequestClientInfo();
5826 }
5827
5828 // We may be called before there is a presence or a client.
5829 // Fake AgentCircuitData to keep IAuthorizationModule smiling
5830 if (client == null)
5831 {
5832 aCircuit = new AgentCircuitData();
5833 aCircuit.AgentID = agentID;
5834 aCircuit.firstname = String.Empty;
5835 aCircuit.lastname = String.Empty;
5836 }
5837
5838 try
5839 {
5840 if (!AuthorizeUser(aCircuit, out reason))
5841 {
5842 // m_log.DebugFormat("[SCENE]: Denying access for {0}", agentID);
5843 return false;
5844 }
5845 }
5846 catch (Exception e)
5847 {
5848 m_log.DebugFormat("[SCENE]: Exception authorizing agent: {0} "+ e.StackTrace, e.Message);
5849 return false;
5850 }
5851
5493 if (position == Vector3.Zero) // Teleport 5852 if (position == Vector3.Zero) // Teleport
5494 { 5853 {
5495 if (!RegionInfo.EstateSettings.AllowDirectTeleport) 5854 if (!RegionInfo.EstateSettings.AllowDirectTeleport)
@@ -5523,13 +5882,46 @@ namespace OpenSim.Region.Framework.Scenes
5523 } 5882 }
5524 } 5883 }
5525 } 5884 }
5885
5886 float posX = 128.0f;
5887 float posY = 128.0f;
5888
5889 if (!TestLandRestrictions(agentID, out reason, ref posX, ref posY))
5890 {
5891 // m_log.DebugFormat("[SCENE]: Denying {0} because they are banned on all parcels", agentID);
5892 return false;
5893 }
5894 }
5895 else // Walking
5896 {
5897 ILandObject land = LandChannel.GetLandObject(position.X, position.Y);
5898 if (land == null)
5899 return false;
5900
5901 bool banned = land.IsBannedFromLand(agentID);
5902 bool restricted = land.IsRestrictedFromLand(agentID);
5903
5904 if (banned || restricted)
5905 return false;
5526 } 5906 }
5527 5907
5528 reason = String.Empty; 5908 reason = String.Empty;
5529 return true; 5909 return true;
5530 } 5910 }
5531 5911
5532 /// <summary> 5912 public void StartTimerWatchdog()
5913 {
5914 m_timerWatchdog.Interval = 1000;
5915 m_timerWatchdog.Elapsed += TimerWatchdog;
5916 m_timerWatchdog.AutoReset = true;
5917 m_timerWatchdog.Start();
5918 }
5919
5920 public void TimerWatchdog(object sender, ElapsedEventArgs e)
5921 {
5922 CheckHeartbeat();
5923 }
5924
5533 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 5925 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5534 /// autopilot that moves an avatar to a sit target!. 5926 /// autopilot that moves an avatar to a sit target!.
5535 /// </summary> 5927 /// </summary>
@@ -5608,6 +6000,11 @@ namespace OpenSim.Region.Framework.Scenes
5608 return m_SpawnPoint - 1; 6000 return m_SpawnPoint - 1;
5609 } 6001 }
5610 6002
6003 private void HandleGcCollect(string module, string[] args)
6004 {
6005 GC.Collect();
6006 }
6007
5611 /// <summary> 6008 /// <summary>
5612 /// Wrappers to get physics modules retrieve assets. 6009 /// Wrappers to get physics modules retrieve assets.
5613 /// </summary> 6010 /// </summary>