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.cs1168
1 files changed, 621 insertions, 547 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index db073e8..671f8fc 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics;
30using System.Drawing; 31using System.Drawing;
31using System.Drawing.Imaging; 32using System.Drawing.Imaging;
32using System.IO; 33using System.IO;
@@ -41,8 +42,7 @@ using OpenMetaverse.Imaging;
41using OpenSim.Framework; 42using OpenSim.Framework;
42using OpenSim.Services.Interfaces; 43using OpenSim.Services.Interfaces;
43using OpenSim.Framework.Communications; 44using OpenSim.Framework.Communications;
44using OpenSim.Framework.Communications.Cache; 45
45using OpenSim.Framework.Communications.Clients;
46using OpenSim.Framework.Console; 46using OpenSim.Framework.Console;
47using OpenSim.Region.Framework.Interfaces; 47using OpenSim.Region.Framework.Interfaces;
48using OpenSim.Region.Framework.Scenes.Scripting; 48using OpenSim.Region.Framework.Scenes.Scripting;
@@ -131,7 +131,6 @@ namespace OpenSim.Region.Framework.Scenes
131 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing 131 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing
132 private int m_incrementsof15seconds; 132 private int m_incrementsof15seconds;
133 private volatile bool m_backingup; 133 private volatile bool m_backingup;
134 private bool m_useAsyncWhenPossible;
135 134
136 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); 135 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>();
137 private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>(); 136 private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>();
@@ -141,7 +140,6 @@ namespace OpenSim.Region.Framework.Scenes
141 protected ModuleLoader m_moduleLoader; 140 protected ModuleLoader m_moduleLoader;
142 protected StorageManager m_storageManager; 141 protected StorageManager m_storageManager;
143 protected AgentCircuitManager m_authenticateHandler; 142 protected AgentCircuitManager m_authenticateHandler;
144 public CommunicationsManager CommsManager;
145 143
146 protected SceneCommunicationService m_sceneGridService; 144 protected SceneCommunicationService m_sceneGridService;
147 public bool LoginsDisabled = true; 145 public bool LoginsDisabled = true;
@@ -203,11 +201,11 @@ namespace OpenSim.Region.Framework.Scenes
203 { 201 {
204 m_AuthorizationService = RequestModuleInterface<IAuthorizationService>(); 202 m_AuthorizationService = RequestModuleInterface<IAuthorizationService>();
205 203
206 if (m_AuthorizationService == null) 204 //if (m_AuthorizationService == null)
207 { 205 //{
208 // don't throw an exception if no authorization service is set for the time being 206 // // don't throw an exception if no authorization service is set for the time being
209 m_log.InfoFormat("[SCENE]: No Authorization service is configured"); 207 // m_log.InfoFormat("[SCENE]: No Authorization service is configured");
210 } 208 //}
211 } 209 }
212 210
213 return m_AuthorizationService; 211 return m_AuthorizationService;
@@ -254,8 +252,76 @@ namespace OpenSim.Region.Framework.Scenes
254 } 252 }
255 } 253 }
256 254
255 protected ILibraryService m_LibraryService;
256
257 public ILibraryService LibraryService
258 {
259 get
260 {
261 if (m_LibraryService == null)
262 m_LibraryService = RequestModuleInterface<ILibraryService>();
263
264 return m_LibraryService;
265 }
266 }
267
268 protected ISimulationService m_simulationService;
269 public ISimulationService SimulationService
270 {
271 get
272 {
273 if (m_simulationService == null)
274 m_simulationService = RequestModuleInterface<ISimulationService>();
275 return m_simulationService;
276 }
277 }
278
279 protected IAuthenticationService m_AuthenticationService;
280 public IAuthenticationService AuthenticationService
281 {
282 get
283 {
284 if (m_AuthenticationService == null)
285 m_AuthenticationService = RequestModuleInterface<IAuthenticationService>();
286 return m_AuthenticationService;
287 }
288 }
289
290 protected IPresenceService m_PresenceService;
291 public IPresenceService PresenceService
292 {
293 get
294 {
295 if (m_PresenceService == null)
296 m_PresenceService = RequestModuleInterface<IPresenceService>();
297 return m_PresenceService;
298 }
299 }
300 protected IUserAccountService m_UserAccountService;
301 public IUserAccountService UserAccountService
302 {
303 get
304 {
305 if (m_UserAccountService == null)
306 m_UserAccountService = RequestModuleInterface<IUserAccountService>();
307 return m_UserAccountService;
308 }
309 }
310
311 protected OpenSim.Services.Interfaces.IAvatarService m_AvatarService;
312 public OpenSim.Services.Interfaces.IAvatarService AvatarService
313 {
314 get
315 {
316 if (m_AvatarService == null)
317 m_AvatarService = RequestModuleInterface<IAvatarService>();
318 return m_AvatarService;
319 }
320 }
321
257 protected IXMLRPC m_xmlrpcModule; 322 protected IXMLRPC m_xmlrpcModule;
258 protected IWorldComm m_worldCommModule; 323 protected IWorldComm m_worldCommModule;
324 public IAttachmentsModule AttachmentsModule { get; set; }
259 protected IAvatarFactory m_AvatarFactory; 325 protected IAvatarFactory m_AvatarFactory;
260 public IAvatarFactory AvatarFactory 326 public IAvatarFactory AvatarFactory
261 { 327 {
@@ -263,10 +329,8 @@ namespace OpenSim.Region.Framework.Scenes
263 } 329 }
264 protected IConfigSource m_config; 330 protected IConfigSource m_config;
265 protected IRegionSerialiserModule m_serialiser; 331 protected IRegionSerialiserModule m_serialiser;
266 protected IInterregionCommsOut m_interregionCommsOut;
267 protected IInterregionCommsIn m_interregionCommsIn;
268 protected IDialogModule m_dialogModule; 332 protected IDialogModule m_dialogModule;
269 protected ITeleportModule m_teleportModule; 333 protected IEntityTransferModule m_teleportModule;
270 334
271 protected ICapabilitiesModule m_capsModule; 335 protected ICapabilitiesModule m_capsModule;
272 public ICapabilitiesModule CapsModule 336 public ICapabilitiesModule CapsModule
@@ -497,7 +561,7 @@ namespace OpenSim.Region.Framework.Scenes
497 #region Constructors 561 #region Constructors
498 562
499 public Scene(RegionInfo regInfo, AgentCircuitManager authen, 563 public Scene(RegionInfo regInfo, AgentCircuitManager authen,
500 CommunicationsManager commsMan, SceneCommunicationService sceneGridService, 564 SceneCommunicationService sceneGridService,
501 StorageManager storeManager, 565 StorageManager storeManager,
502 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim, 566 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim,
503 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion) 567 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
@@ -533,7 +597,6 @@ namespace OpenSim.Region.Framework.Scenes
533 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4); 597 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4);
534 m_moduleLoader = moduleLoader; 598 m_moduleLoader = moduleLoader;
535 m_authenticateHandler = authen; 599 m_authenticateHandler = authen;
536 CommsManager = commsMan;
537 m_sceneGridService = sceneGridService; 600 m_sceneGridService = sceneGridService;
538 m_storageManager = storeManager; 601 m_storageManager = storeManager;
539 m_regInfo = regInfo; 602 m_regInfo = regInfo;
@@ -557,7 +620,46 @@ namespace OpenSim.Region.Framework.Scenes
557 620
558 if (m_storageManager.EstateDataStore != null) 621 if (m_storageManager.EstateDataStore != null)
559 { 622 {
560 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 623 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false);
624 if (m_regInfo.EstateSettings.EstateID == 0) // No record at all
625 {
626 MainConsole.Instance.Output("Your region is not part of an estate.");
627 while (true)
628 {
629 string response = MainConsole.Instance.CmdPrompt("Do you wish to join an existing estate?", "no", new List<string>() {"yes", "no"});
630 if (response == "no")
631 {
632 // Create a new estate
633 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, true);
634
635 m_regInfo.EstateSettings.EstateName = MainConsole.Instance.CmdPrompt("New estate name", m_regInfo.EstateSettings.EstateName);
636 m_regInfo.EstateSettings.Save();
637 break;
638 }
639 else
640 {
641 response = MainConsole.Instance.CmdPrompt("Estate name to join", "None");
642 if (response == "None")
643 continue;
644
645 List<int> estateIDs = m_storageManager.EstateDataStore.GetEstates(response);
646 if (estateIDs.Count < 1)
647 {
648 MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again");
649 continue;
650 }
651
652 int estateID = estateIDs[0];
653
654 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(estateID);
655
656 if (m_storageManager.EstateDataStore.LinkRegion(m_regInfo.RegionID, estateID))
657 break;
658
659 MainConsole.Instance.Output("Joining the estate failed. Please try again.");
660 }
661 }
662 }
561 } 663 }
562 664
563 //Bind Storage Manager functions to some land manager functions for this scene 665 //Bind Storage Manager functions to some land manager functions for this scene
@@ -606,9 +708,6 @@ namespace OpenSim.Region.Framework.Scenes
606 // 708 //
607 IConfig startupConfig = m_config.Configs["Startup"]; 709 IConfig startupConfig = m_config.Configs["Startup"];
608 710
609 // Should we try to run loops synchronously or asynchronously?
610 m_useAsyncWhenPossible = startupConfig.GetBoolean("use_async_when_possible", false);
611
612 //Animation states 711 //Animation states
613 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 712 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
614 // TODO: Change default to true once the feature is supported 713 // TODO: Change default to true once the feature is supported
@@ -792,6 +891,36 @@ namespace OpenSim.Region.Framework.Scenes
792 return m_simulatorVersion; 891 return m_simulatorVersion;
793 } 892 }
794 893
894 public string[] GetUserNames(UUID uuid)
895 {
896 string[] returnstring = new string[0];
897
898 UserAccount account = UserAccountService.GetUserAccount(RegionInfo.ScopeID, uuid);
899
900 if (account != null)
901 {
902 returnstring = new string[2];
903 returnstring[0] = account.FirstName;
904 returnstring[1] = account.LastName;
905 }
906
907 return returnstring;
908 }
909
910 public string GetUserName(UUID uuid)
911 {
912 string[] names = GetUserNames(uuid);
913 if (names.Length == 2)
914 {
915 string firstname = names[0];
916 string lastname = names[1];
917
918 return firstname + " " + lastname;
919
920 }
921 return "(hippos)";
922 }
923
795 /// <summary> 924 /// <summary>
796 /// Another region is up. 925 /// Another region is up.
797 /// 926 ///
@@ -825,7 +954,7 @@ namespace OpenSim.Region.Framework.Scenes
825 regInfo.RegionName = otherRegion.RegionName; 954 regInfo.RegionName = otherRegion.RegionName;
826 regInfo.ScopeID = otherRegion.ScopeID; 955 regInfo.ScopeID = otherRegion.ScopeID;
827 regInfo.ExternalHostName = otherRegion.ExternalHostName; 956 regInfo.ExternalHostName = otherRegion.ExternalHostName;
828 957 GridRegion r = new GridRegion(regInfo);
829 try 958 try
830 { 959 {
831 ForEachScenePresence(delegate(ScenePresence agent) 960 ForEachScenePresence(delegate(ScenePresence agent)
@@ -839,7 +968,8 @@ namespace OpenSim.Region.Framework.Scenes
839 List<ulong> old = new List<ulong>(); 968 List<ulong> old = new List<ulong>();
840 old.Add(otherRegion.RegionHandle); 969 old.Add(otherRegion.RegionHandle);
841 agent.DropOldNeighbours(old); 970 agent.DropOldNeighbours(old);
842 InformClientOfNeighbor(agent, regInfo); 971 if (m_teleportModule != null)
972 m_teleportModule.EnableChildAgent(agent, r);
843 } 973 }
844 } 974 }
845 ); 975 );
@@ -999,6 +1129,7 @@ namespace OpenSim.Region.Framework.Scenes
999 { 1129 {
1000 foreach (RegionInfo region in m_regionRestartNotifyList) 1130 foreach (RegionInfo region in m_regionRestartNotifyList)
1001 { 1131 {
1132 GridRegion r = new GridRegion(region);
1002 try 1133 try
1003 { 1134 {
1004 ForEachScenePresence(delegate(ScenePresence agent) 1135 ForEachScenePresence(delegate(ScenePresence agent)
@@ -1006,9 +1137,8 @@ namespace OpenSim.Region.Framework.Scenes
1006 // If agent is a root agent. 1137 // If agent is a root agent.
1007 if (!agent.IsChildAgent) 1138 if (!agent.IsChildAgent)
1008 { 1139 {
1009 //agent.ControllingClient.new 1140 if (m_teleportModule != null)
1010 //this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); 1141 m_teleportModule.EnableChildAgent(agent, r);
1011 InformClientOfNeighbor(agent, region);
1012 } 1142 }
1013 } 1143 }
1014 ); 1144 );
@@ -1067,10 +1197,7 @@ namespace OpenSim.Region.Framework.Scenes
1067 1197
1068 public int GetInaccurateNeighborCount() 1198 public int GetInaccurateNeighborCount()
1069 { 1199 {
1070 lock (m_neighbours) 1200 return m_neighbours.Count;
1071 {
1072 return m_neighbours.Count;
1073 }
1074 } 1201 }
1075 1202
1076 // This is the method that shuts down the scene. 1203 // This is the method that shuts down the scene.
@@ -1150,12 +1277,89 @@ namespace OpenSim.Region.Framework.Scenes
1150 m_worldCommModule = RequestModuleInterface<IWorldComm>(); 1277 m_worldCommModule = RequestModuleInterface<IWorldComm>();
1151 XferManager = RequestModuleInterface<IXfer>(); 1278 XferManager = RequestModuleInterface<IXfer>();
1152 m_AvatarFactory = RequestModuleInterface<IAvatarFactory>(); 1279 m_AvatarFactory = RequestModuleInterface<IAvatarFactory>();
1280 AttachmentsModule = RequestModuleInterface<IAttachmentsModule>();
1153 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>(); 1281 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>();
1154 m_interregionCommsOut = RequestModuleInterface<IInterregionCommsOut>();
1155 m_interregionCommsIn = RequestModuleInterface<IInterregionCommsIn>();
1156 m_dialogModule = RequestModuleInterface<IDialogModule>(); 1282 m_dialogModule = RequestModuleInterface<IDialogModule>();
1157 m_capsModule = RequestModuleInterface<ICapabilitiesModule>(); 1283 m_capsModule = RequestModuleInterface<ICapabilitiesModule>();
1158 m_teleportModule = RequestModuleInterface<ITeleportModule>(); 1284 m_teleportModule = RequestModuleInterface<IEntityTransferModule>();
1285
1286 // Shoving this in here for now, because we have the needed
1287 // interfaces at this point
1288 //
1289 // TODO: Find a better place for this
1290 //
1291 while (m_regInfo.EstateSettings.EstateOwner == UUID.Zero && MainConsole.Instance != null)
1292 {
1293 MainConsole.Instance.Output("The current estate has no owner set.");
1294 string first = MainConsole.Instance.CmdPrompt("Estate owner first name", "Test");
1295 string last = MainConsole.Instance.CmdPrompt("Estate owner last name", "User");
1296
1297 UserAccount account = UserAccountService.GetUserAccount(m_regInfo.ScopeID, first, last);
1298
1299 if (account == null)
1300 {
1301 // Create a new account
1302 account = new UserAccount(m_regInfo.ScopeID, first, last, String.Empty);
1303 if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
1304 {
1305 account.ServiceURLs = new Dictionary<string, object>();
1306 account.ServiceURLs["HomeURI"] = string.Empty;
1307 account.ServiceURLs["GatekeeperURI"] = string.Empty;
1308 account.ServiceURLs["InventoryServerURI"] = string.Empty;
1309 account.ServiceURLs["AssetServerURI"] = string.Empty;
1310 }
1311
1312 if (UserAccountService.StoreUserAccount(account))
1313 {
1314 string password = MainConsole.Instance.PasswdPrompt("Password");
1315 string email = MainConsole.Instance.CmdPrompt("Email", "");
1316
1317 account.Email = email;
1318 UserAccountService.StoreUserAccount(account);
1319
1320 bool success = false;
1321 success = AuthenticationService.SetPassword(account.PrincipalID, password);
1322 if (!success)
1323 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
1324 first, last);
1325
1326 GridRegion home = null;
1327 if (GridService != null)
1328 {
1329 List<GridRegion> defaultRegions = GridService.GetDefaultRegions(UUID.Zero);
1330 if (defaultRegions != null && defaultRegions.Count >= 1)
1331 home = defaultRegions[0];
1332
1333 if (PresenceService != null && home != null)
1334 PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
1335 else
1336 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
1337 first, last);
1338
1339 }
1340 else
1341 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
1342 first, last);
1343
1344 if (InventoryService != null)
1345 success = InventoryService.CreateUserInventory(account.PrincipalID);
1346 if (!success)
1347 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
1348 first, last);
1349
1350
1351 m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", first, last);
1352
1353 m_regInfo.EstateSettings.EstateOwner = account.PrincipalID;
1354 m_regInfo.EstateSettings.Save();
1355 }
1356 }
1357 else
1358 {
1359 m_regInfo.EstateSettings.EstateOwner = account.PrincipalID;
1360 m_regInfo.EstateSettings.Save();
1361 }
1362 }
1159 } 1363 }
1160 1364
1161 #endregion 1365 #endregion
@@ -1539,7 +1743,7 @@ namespace OpenSim.Region.Framework.Scenes
1539 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1743 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1540 } 1744 }
1541 1745
1542 public void StoreWindlightProfile(RegionMeta7WindlightData wl) 1746 public void StoreWindlightProfile(RegionLightShareData wl)
1543 { 1747 {
1544 m_regInfo.WindlightSettings = wl; 1748 m_regInfo.WindlightSettings = wl;
1545 m_storageManager.DataStore.StoreRegionWindlightSettings(wl); 1749 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
@@ -1605,7 +1809,9 @@ namespace OpenSim.Region.Framework.Scenes
1605 GridRegion region = new GridRegion(RegionInfo); 1809 GridRegion region = new GridRegion(RegionInfo);
1606 string error = GridService.RegisterRegion(RegionInfo.ScopeID, region); 1810 string error = GridService.RegisterRegion(RegionInfo.ScopeID, region);
1607 if (error != String.Empty) 1811 if (error != String.Empty)
1812 {
1608 throw new Exception(error); 1813 throw new Exception(error);
1814 }
1609 1815
1610 m_sceneGridService.SetScene(this); 1816 m_sceneGridService.SetScene(this);
1611 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo); 1817 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo);
@@ -2017,7 +2223,6 @@ namespace OpenSim.Region.Framework.Scenes
2017 /// Move the given scene object into a new region depending on which region its absolute position has moved 2223 /// Move the given scene object into a new region depending on which region its absolute position has moved
2018 /// into. 2224 /// into.
2019 /// 2225 ///
2020 /// This method locates the new region handle and offsets the prim position for the new region
2021 /// </summary> 2226 /// </summary>
2022 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param> 2227 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
2023 /// <param name="grp">the scene object that we're crossing</param> 2228 /// <param name="grp">the scene object that we're crossing</param>
@@ -2059,191 +2264,8 @@ namespace OpenSim.Region.Framework.Scenes
2059 return; 2264 return;
2060 } 2265 }
2061 2266
2062 int thisx = (int)RegionInfo.RegionLocX; 2267 if (m_teleportModule != null)
2063 int thisy = (int)RegionInfo.RegionLocY; 2268 m_teleportModule.Cross(grp, attemptedPosition, silent);
2064 Vector3 EastCross = new Vector3(0.1f,0,0);
2065 Vector3 WestCross = new Vector3(-0.1f, 0, 0);
2066 Vector3 NorthCross = new Vector3(0, 0.1f, 0);
2067 Vector3 SouthCross = new Vector3(0, -0.1f, 0);
2068
2069
2070 // use this if no borders were crossed!
2071 ulong newRegionHandle
2072 = Util.UIntsToLong((uint)((thisx) * Constants.RegionSize),
2073 (uint)((thisy) * Constants.RegionSize));
2074
2075 Vector3 pos = attemptedPosition;
2076
2077 int changeX = 1;
2078 int changeY = 1;
2079
2080 if (TestBorderCross(attemptedPosition + WestCross, Cardinals.W))
2081 {
2082 if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2083 {
2084
2085 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2086
2087 if (crossedBorderx.BorderLine.Z > 0)
2088 {
2089 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2090 changeX = (int)(crossedBorderx.BorderLine.Z /(int) Constants.RegionSize);
2091 }
2092 else
2093 pos.X = ((pos.X + Constants.RegionSize));
2094
2095 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2096 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2097
2098 if (crossedBordery.BorderLine.Z > 0)
2099 {
2100 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2101 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2102 }
2103 else
2104 pos.Y = ((pos.Y + Constants.RegionSize));
2105
2106
2107
2108 newRegionHandle
2109 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2110 (uint)((thisy - changeY) * Constants.RegionSize));
2111 // x - 1
2112 // y - 1
2113 }
2114 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2115 {
2116 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2117
2118 if (crossedBorderx.BorderLine.Z > 0)
2119 {
2120 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2121 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2122 }
2123 else
2124 pos.X = ((pos.X + Constants.RegionSize));
2125
2126
2127 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2128 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2129
2130 try
2131 {
2132 if (crossedBordery.BorderLine.Z > 0)
2133 {
2134 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2135 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2136 }
2137 else
2138 pos.Y = ((pos.Y + Constants.RegionSize));
2139
2140 newRegionHandle
2141 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2142 (uint)((thisy + changeY) * Constants.RegionSize));
2143 // x - 1
2144 // y + 1
2145 }
2146 catch (Exception ex)
2147 {
2148 }
2149 }
2150 else
2151 {
2152 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2153
2154 if (crossedBorderx.BorderLine.Z > 0)
2155 {
2156 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2157 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2158 }
2159 else
2160 pos.X = ((pos.X + Constants.RegionSize));
2161
2162 newRegionHandle
2163 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2164 (uint) (thisy*Constants.RegionSize));
2165 // x - 1
2166 }
2167 }
2168 else if (TestBorderCross(attemptedPosition + EastCross, Cardinals.E))
2169 {
2170 if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2171 {
2172
2173 pos.X = ((pos.X - Constants.RegionSize));
2174 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2175 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2176
2177 if (crossedBordery.BorderLine.Z > 0)
2178 {
2179 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2180 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2181 }
2182 else
2183 pos.Y = ((pos.Y + Constants.RegionSize));
2184
2185
2186 newRegionHandle
2187 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2188 (uint)((thisy - changeY) * Constants.RegionSize));
2189 // x + 1
2190 // y - 1
2191 }
2192 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2193 {
2194 pos.X = ((pos.X - Constants.RegionSize));
2195 pos.Y = ((pos.Y - Constants.RegionSize));
2196 newRegionHandle
2197 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2198 (uint)((thisy + changeY) * Constants.RegionSize));
2199 // x + 1
2200 // y + 1
2201 }
2202 else
2203 {
2204 pos.X = ((pos.X - Constants.RegionSize));
2205 newRegionHandle
2206 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2207 (uint) (thisy*Constants.RegionSize));
2208 // x + 1
2209 }
2210 }
2211 else if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2212 {
2213 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2214 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2215
2216 if (crossedBordery.BorderLine.Z > 0)
2217 {
2218 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2219 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2220 }
2221 else
2222 pos.Y = ((pos.Y + Constants.RegionSize));
2223
2224 newRegionHandle
2225 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - changeY) * Constants.RegionSize));
2226 // y - 1
2227 }
2228 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2229 {
2230
2231 pos.Y = ((pos.Y - Constants.RegionSize));
2232 newRegionHandle
2233 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + changeY) * Constants.RegionSize));
2234 // y + 1
2235 }
2236
2237 // Offset the positions for the new region across the border
2238 Vector3 oldGroupPosition = grp.RootPart.GroupPosition;
2239 grp.OffsetForNewRegion(pos);
2240
2241 // If we fail to cross the border, then reset the position of the scene object on that border.
2242 if (!CrossPrimGroupIntoNewRegion(newRegionHandle, grp, silent))
2243 {
2244 grp.OffsetForNewRegion(oldGroupPosition);
2245 grp.ScheduleGroupForFullUpdate();
2246 }
2247 } 2269 }
2248 2270
2249 public Border GetCrossedBorder(Vector3 position, Cardinals gridline) 2271 public Border GetCrossedBorder(Vector3 position, Cardinals gridline)
@@ -2427,75 +2449,6 @@ namespace OpenSim.Region.Framework.Scenes
2427 2449
2428 2450
2429 /// <summary> 2451 /// <summary>
2430 /// Move the given scene object into a new region
2431 /// </summary>
2432 /// <param name="newRegionHandle"></param>
2433 /// <param name="grp">Scene Object Group that we're crossing</param>
2434 /// <returns>
2435 /// true if the crossing itself was successful, false on failure
2436 /// FIMXE: we still return true if the crossing object was not successfully deleted from the originating region
2437 /// </returns>
2438 public bool CrossPrimGroupIntoNewRegion(ulong newRegionHandle, SceneObjectGroup grp, bool silent)
2439 {
2440 //m_log.Debug(" >>> CrossPrimGroupIntoNewRegion <<<");
2441
2442 bool successYN = false;
2443 grp.RootPart.UpdateFlag = 0;
2444 //int primcrossingXMLmethod = 0;
2445
2446 if (newRegionHandle != 0)
2447 {
2448 //string objectState = grp.GetStateSnapshot();
2449
2450 //successYN
2451 // = m_sceneGridService.PrimCrossToNeighboringRegion(
2452 // newRegionHandle, grp.UUID, m_serialiser.SaveGroupToXml2(grp), primcrossingXMLmethod);
2453 //if (successYN && (objectState != "") && m_allowScriptCrossings)
2454 //{
2455 // successYN = m_sceneGridService.PrimCrossToNeighboringRegion(
2456 // newRegionHandle, grp.UUID, objectState, 100);
2457 //}
2458
2459 // And the new channel...
2460 if (m_interregionCommsOut != null)
2461 successYN = m_interregionCommsOut.SendCreateObject(newRegionHandle, grp, true);
2462
2463 if (successYN)
2464 {
2465 // We remove the object here
2466 try
2467 {
2468 DeleteSceneObject(grp, silent);
2469 }
2470 catch (Exception e)
2471 {
2472 m_log.ErrorFormat(
2473 "[INTERREGION]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
2474 grp, e);
2475 }
2476 }
2477 else
2478 {
2479 if (!grp.IsDeleted)
2480 {
2481 if (grp.RootPart.PhysActor != null)
2482 {
2483 grp.RootPart.PhysActor.CrossingFailure();
2484 }
2485 }
2486
2487 m_log.ErrorFormat("[INTERREGION]: Prim crossing failed for {0}", grp);
2488 }
2489 }
2490 else
2491 {
2492 m_log.Error("[INTERREGION]: region handle was unexpectedly 0 in Scene.CrossPrimGroupIntoNewRegion()");
2493 }
2494
2495 return successYN;
2496 }
2497
2498 /// <summary>
2499 /// Called when objects or attachments cross the border between regions. 2452 /// Called when objects or attachments cross the border between regions.
2500 /// </summary> 2453 /// </summary>
2501 /// <param name="sog"></param> 2454 /// <param name="sog"></param>
@@ -2539,10 +2492,10 @@ namespace OpenSim.Region.Framework.Scenes
2539 //m_log.DebugFormat(" >>> IncomingCreateObject(userID, itemID) <<< {0} {1}", userID, itemID); 2492 //m_log.DebugFormat(" >>> IncomingCreateObject(userID, itemID) <<< {0} {1}", userID, itemID);
2540 2493
2541 ScenePresence sp = GetScenePresence(userID); 2494 ScenePresence sp = GetScenePresence(userID);
2542 if (sp != null) 2495 if (sp != null && AttachmentsModule != null)
2543 { 2496 {
2544 uint attPt = (uint)sp.Appearance.GetAttachpoint(itemID); 2497 uint attPt = (uint)sp.Appearance.GetAttachpoint(itemID);
2545 m_sceneGraph.RezSingleAttachment(sp.ControllingClient, itemID, attPt); 2498 AttachmentsModule.RezSingleAttachmentFromInventory(sp.ControllingClient, itemID, attPt);
2546 } 2499 }
2547 2500
2548 return false; 2501 return false;
@@ -2567,6 +2520,9 @@ namespace OpenSim.Region.Framework.Scenes
2567 2520
2568 return false; 2521 return false;
2569 } 2522 }
2523
2524 sceneObject.SetScene(this);
2525
2570 // Force allocation of new LocalId 2526 // Force allocation of new LocalId
2571 // 2527 //
2572 foreach (SceneObjectPart p in sceneObject.Children.Values) 2528 foreach (SceneObjectPart p in sceneObject.Children.Values)
@@ -2603,9 +2559,11 @@ namespace OpenSim.Region.Framework.Scenes
2603 //grp.SetFromAssetID(grp.RootPart.LastOwnerID); 2559 //grp.SetFromAssetID(grp.RootPart.LastOwnerID);
2604 m_log.DebugFormat( 2560 m_log.DebugFormat(
2605 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition); 2561 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition);
2562
2563 if (AttachmentsModule != null)
2564 AttachmentsModule.AttachObject(
2565 sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition, false);
2606 2566
2607 AttachObject(
2608 sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition, false);
2609 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2567 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2610 grp.SendGroupFullUpdate(); 2568 grp.SendGroupFullUpdate();
2611 } 2569 }
@@ -2645,6 +2603,8 @@ namespace OpenSim.Region.Framework.Scenes
2645 /// <param name="client"></param> 2603 /// <param name="client"></param>
2646 public override void AddNewClient(IClientAPI client) 2604 public override void AddNewClient(IClientAPI client)
2647 { 2605 {
2606 bool vialogin = false;
2607
2648 m_clientManager.Add(client); 2608 m_clientManager.Add(client);
2649 2609
2650 CheckHeartbeat(); 2610 CheckHeartbeat();
@@ -2679,23 +2639,48 @@ namespace OpenSim.Region.Framework.Scenes
2679 { 2639 {
2680 AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); 2640 AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode);
2681 2641
2682 m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); 2642 // Do the verification here
2683 /* 2643 System.Net.EndPoint ep = client.GetClientEP();
2684 string logMsg = string.Format("[SCENE]: Adding new {0} agent for {1} in {2}", 2644 if (aCircuit != null)
2685 ((aCircuit.child == true) ? "child" : "root"), client.Name, 2645 {
2686 RegionInfo.RegionName); 2646 if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0)
2687 2647 {
2688 m_log.Debug(logMsg); 2648 m_log.DebugFormat("[Scene]: Incoming client {0} {1} in region {2} via Login", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName);
2689 */ 2649 vialogin = true;
2650 IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>();
2651 if (userVerification != null && ep != null)
2652 {
2653 if (!userVerification.VerifyClient(aCircuit, ep.ToString()))
2654 {
2655 // uh-oh, this is fishy
2656 m_log.WarnFormat("[Scene]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.",
2657 client.AgentId, client.SessionId, ep.ToString());
2658 try
2659 {
2660 client.Close();
2661 }
2662 catch (Exception e)
2663 {
2664 m_log.DebugFormat("[Scene]: Exception while closing aborted client: {0}", e.StackTrace);
2665 }
2666 return;
2667 }
2668 else
2669 m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} returned true", aCircuit.firstname, aCircuit.lastname);
2670 }
2671 }
2672 }
2690 2673
2691 CommsManager.UserProfileCacheService.AddNewUser(client.AgentId); 2674 m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName);
2692 2675
2693 ScenePresence sp = CreateAndAddScenePresence(client); 2676 ScenePresence sp = CreateAndAddScenePresence(client);
2677 if (aCircuit != null)
2678 sp.Appearance = aCircuit.Appearance;
2694 2679
2695 // HERE!!! Do the initial attachments right here 2680 // HERE!!! Do the initial attachments right here
2696 // first agent upon login is a root agent by design. 2681 // first agent upon login is a root agent by design.
2697 // All other AddNewClient calls find aCircuit.child to be true 2682 // All other AddNewClient calls find aCircuit.child to be true
2698 if (aCircuit == null || aCircuit.child == false) 2683 if (aCircuit == null || (aCircuit != null && aCircuit.child == false))
2699 { 2684 {
2700 sp.IsChildAgent = false; 2685 sp.IsChildAgent = false;
2701 Util.FireAndForget(delegate(object o) { sp.RezAttachments(); }); 2686 Util.FireAndForget(delegate(object o) { sp.RezAttachments(); });
@@ -2704,6 +2689,8 @@ namespace OpenSim.Region.Framework.Scenes
2704 2689
2705 m_LastLogin = Util.EnvironmentTickCount(); 2690 m_LastLogin = Util.EnvironmentTickCount();
2706 EventManager.TriggerOnNewClient(client); 2691 EventManager.TriggerOnNewClient(client);
2692 if (vialogin)
2693 EventManager.TriggerOnClientLogin(client);
2707 } 2694 }
2708 2695
2709 2696
@@ -2809,19 +2796,22 @@ namespace OpenSim.Region.Framework.Scenes
2809 } 2796 }
2810 2797
2811 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client) 2798 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client)
2812 { 2799 {
2813 client.OnRezSingleAttachmentFromInv += RezSingleAttachment; 2800 client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments;
2814 client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments;
2815 client.OnDetachAttachmentIntoInv += DetachSingleAttachmentToInv;
2816 client.OnObjectAttach += m_sceneGraph.AttachObject;
2817 client.OnObjectDetach += m_sceneGraph.DetachObject; 2801 client.OnObjectDetach += m_sceneGraph.DetachObject;
2802
2803 if (AttachmentsModule != null)
2804 {
2805 client.OnRezSingleAttachmentFromInv += AttachmentsModule.RezSingleAttachmentFromInventory;
2806 client.OnObjectAttach += AttachmentsModule.AttachObject;
2807 client.OnDetachAttachmentIntoInv += AttachmentsModule.ShowDetachInUserInventory;
2808 }
2818 } 2809 }
2819 2810
2820 public virtual void SubscribeToClientTeleportEvents(IClientAPI client) 2811 public virtual void SubscribeToClientTeleportEvents(IClientAPI client)
2821 { 2812 {
2822 client.OnTeleportLocationRequest += RequestTeleportLocation; 2813 client.OnTeleportLocationRequest += RequestTeleportLocation;
2823 client.OnTeleportLandmarkRequest += RequestTeleportLandmark; 2814 client.OnTeleportLandmarkRequest += RequestTeleportLandmark;
2824 client.OnTeleportHomeRequest += TeleportClientHome;
2825 } 2815 }
2826 2816
2827 public virtual void SubscribeToClientScriptEvents(IClientAPI client) 2817 public virtual void SubscribeToClientScriptEvents(IClientAPI client)
@@ -2841,7 +2831,7 @@ namespace OpenSim.Region.Framework.Scenes
2841 2831
2842 public virtual void SubscribeToClientGridEvents(IClientAPI client) 2832 public virtual void SubscribeToClientGridEvents(IClientAPI client)
2843 { 2833 {
2844 client.OnNameFromUUIDRequest += CommsManager.HandleUUIDNameRequest; 2834 client.OnNameFromUUIDRequest += HandleUUIDNameRequest;
2845 client.OnMoneyTransferRequest += ProcessMoneyTransferRequest; 2835 client.OnMoneyTransferRequest += ProcessMoneyTransferRequest;
2846 client.OnAvatarPickerRequest += ProcessAvatarPickerRequest; 2836 client.OnAvatarPickerRequest += ProcessAvatarPickerRequest;
2847 client.OnSetStartLocationRequest += SetHomeRezPoint; 2837 client.OnSetStartLocationRequest += SetHomeRezPoint;
@@ -2863,7 +2853,6 @@ namespace OpenSim.Region.Framework.Scenes
2863 2853
2864 protected virtual void UnsubscribeToClientEvents(IClientAPI client) 2854 protected virtual void UnsubscribeToClientEvents(IClientAPI client)
2865 { 2855 {
2866
2867 } 2856 }
2868 2857
2869 /// <summary> 2858 /// <summary>
@@ -2885,7 +2874,6 @@ namespace OpenSim.Region.Framework.Scenes
2885 2874
2886 UnSubscribeToClientNetworkEvents(client); 2875 UnSubscribeToClientNetworkEvents(client);
2887 2876
2888
2889 // EventManager.TriggerOnNewClient(client); 2877 // EventManager.TriggerOnNewClient(client);
2890 } 2878 }
2891 2879
@@ -2942,7 +2930,6 @@ namespace OpenSim.Region.Framework.Scenes
2942 client.OnRezObject -= RezObject; 2930 client.OnRezObject -= RezObject;
2943 } 2931 }
2944 2932
2945
2946 public virtual void UnSubscribeToClientInventoryEvents(IClientAPI client) 2933 public virtual void UnSubscribeToClientInventoryEvents(IClientAPI client)
2947 { 2934 {
2948 client.OnCreateNewInventoryItem -= CreateNewInventoryItem; 2935 client.OnCreateNewInventoryItem -= CreateNewInventoryItem;
@@ -2966,18 +2953,22 @@ namespace OpenSim.Region.Framework.Scenes
2966 2953
2967 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client) 2954 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client)
2968 { 2955 {
2969 client.OnRezSingleAttachmentFromInv -= RezSingleAttachment; 2956 client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments;
2970 client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments;
2971 client.OnDetachAttachmentIntoInv -= DetachSingleAttachmentToInv;
2972 client.OnObjectAttach -= m_sceneGraph.AttachObject;
2973 client.OnObjectDetach -= m_sceneGraph.DetachObject; 2957 client.OnObjectDetach -= m_sceneGraph.DetachObject;
2958
2959 if (AttachmentsModule != null)
2960 {
2961 client.OnRezSingleAttachmentFromInv -= AttachmentsModule.RezSingleAttachmentFromInventory;
2962 client.OnObjectAttach -= AttachmentsModule.AttachObject;
2963 client.OnDetachAttachmentIntoInv -= AttachmentsModule.ShowDetachInUserInventory;
2964 }
2974 } 2965 }
2975 2966
2976 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client) 2967 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client)
2977 { 2968 {
2978 client.OnTeleportLocationRequest -= RequestTeleportLocation; 2969 client.OnTeleportLocationRequest -= RequestTeleportLocation;
2979 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark; 2970 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark;
2980 client.OnTeleportHomeRequest -= TeleportClientHome; 2971 //client.OnTeleportHomeRequest -= TeleportClientHome;
2981 } 2972 }
2982 2973
2983 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client) 2974 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client)
@@ -2997,7 +2988,7 @@ namespace OpenSim.Region.Framework.Scenes
2997 2988
2998 public virtual void UnSubscribeToClientGridEvents(IClientAPI client) 2989 public virtual void UnSubscribeToClientGridEvents(IClientAPI client)
2999 { 2990 {
3000 client.OnNameFromUUIDRequest -= CommsManager.HandleUUIDNameRequest; 2991 client.OnNameFromUUIDRequest -= HandleUUIDNameRequest;
3001 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest; 2992 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest;
3002 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest; 2993 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest;
3003 client.OnSetStartLocationRequest -= SetHomeRezPoint; 2994 client.OnSetStartLocationRequest -= SetHomeRezPoint;
@@ -3024,30 +3015,12 @@ namespace OpenSim.Region.Framework.Scenes
3024 /// <param name="client">The IClientAPI for the client</param> 3015 /// <param name="client">The IClientAPI for the client</param>
3025 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3016 public virtual void TeleportClientHome(UUID agentId, IClientAPI client)
3026 { 3017 {
3027 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(agentId); 3018 if (m_teleportModule != null)
3028 if (UserProfile != null) 3019 m_teleportModule.TeleportHome(agentId, client);
3020 else
3029 { 3021 {
3030 GridRegion regionInfo = GridService.GetRegionByUUID(UUID.Zero, UserProfile.HomeRegionID); 3022 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3031 if (regionInfo == null) 3023 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3032 {
3033 uint x = 0, y = 0;
3034 Utils.LongToUInts(UserProfile.HomeRegion, out x, out y);
3035 regionInfo = GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
3036 if (regionInfo != null) // home region can be away temporarily, too
3037 {
3038 UserProfile.HomeRegionID = regionInfo.RegionID;
3039 CommsManager.UserService.UpdateUserProfile(UserProfile);
3040 }
3041 }
3042 if (regionInfo == null)
3043 {
3044 // can't find the Home region: Tell viewer and abort
3045 client.SendTeleportFailed("Your home-region could not be found.");
3046 return;
3047 }
3048 RequestTeleportLocation(
3049 client, regionInfo.RegionHandle, UserProfile.HomeLocation, UserProfile.HomeLookAt,
3050 (uint)(TPFlags.SetLastToTarget | TPFlags.ViaHome));
3051 } 3024 }
3052 } 3025 }
3053 3026
@@ -3138,7 +3111,7 @@ namespace OpenSim.Region.Framework.Scenes
3138 } 3111 }
3139 3112
3140 /// <summary> 3113 /// <summary>
3141 /// Sets the Home Point. The GridService uses this to know where to put a user when they log-in 3114 /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
3142 /// </summary> 3115 /// </summary>
3143 /// <param name="remoteClient"></param> 3116 /// <param name="remoteClient"></param>
3144 /// <param name="regionHandle"></param> 3117 /// <param name="regionHandle"></param>
@@ -3147,27 +3120,11 @@ namespace OpenSim.Region.Framework.Scenes
3147 /// <param name="flags"></param> 3120 /// <param name="flags"></param>
3148 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3121 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3149 { 3122 {
3150 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(remoteClient.AgentId); 3123 if (PresenceService.SetHomeLocation(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3151 if (UserProfile != null)
3152 {
3153 // I know I'm ignoring the regionHandle provided by the teleport location request.
3154 // reusing the TeleportLocationRequest delegate, so regionHandle isn't valid
3155 UserProfile.HomeRegionID = RegionInfo.RegionID;
3156 // TODO: The next line can be removed, as soon as only homeRegionID based UserServers are around.
3157 // TODO: The HomeRegion property can be removed then, too
3158 UserProfile.HomeRegion = RegionInfo.RegionHandle;
3159
3160 UserProfile.HomeLocation = position;
3161 UserProfile.HomeLookAt = lookAt;
3162 CommsManager.UserService.UpdateUserProfile(UserProfile);
3163
3164 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3124 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3165 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3125 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
3166 }
3167 else 3126 else
3168 {
3169 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed."); 3127 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed.");
3170 }
3171 } 3128 }
3172 3129
3173 /// <summary> 3130 /// <summary>
@@ -3240,14 +3197,12 @@ namespace OpenSim.Region.Framework.Scenes
3240 m_sceneGraph.removeUserCount(!childagentYN); 3197 m_sceneGraph.removeUserCount(!childagentYN);
3241 CapsModule.RemoveCapsHandler(agentID); 3198 CapsModule.RemoveCapsHandler(agentID);
3242 3199
3243 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID)) 3200 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
3244 { 3201 // this method is doing is HORRIBLE!!!
3245 CommsManager.UserProfileCacheService.RemoveUser(agentID); 3202 avatar.Scene.NeedSceneCacheClear(avatar.UUID);
3246 }
3247 3203
3248 if (!avatar.IsChildAgent) 3204 if (!avatar.IsChildAgent)
3249 { 3205 {
3250 m_sceneGridService.LogOffUser(agentID, RegionInfo.RegionID, RegionInfo.RegionHandle, avatar.AbsolutePosition, avatar.Lookat);
3251 //List<ulong> childknownRegions = new List<ulong>(); 3206 //List<ulong> childknownRegions = new List<ulong>();
3252 //List<ulong> ckn = avatar.KnownChildRegionHandles; 3207 //List<ulong> ckn = avatar.KnownChildRegionHandles;
3253 //for (int i = 0; i < ckn.Count; i++) 3208 //for (int i = 0; i < ckn.Count; i++)
@@ -3302,12 +3257,6 @@ namespace OpenSim.Region.Framework.Scenes
3302 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3257 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3303 } 3258 }
3304 3259
3305 // Remove client agent from profile, so new logins will work
3306 if (!childagentYN)
3307 {
3308 m_sceneGridService.ClearUserAgent(agentID);
3309 }
3310
3311 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3260 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3312 3261
3313 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3262 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
@@ -3380,14 +3329,6 @@ namespace OpenSim.Region.Framework.Scenes
3380 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3329 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3381 m_sceneGridService.KiPrimitive += SendKillObject; 3330 m_sceneGridService.KiPrimitive += SendKillObject;
3382 m_sceneGridService.OnGetLandData += GetLandData; 3331 m_sceneGridService.OnGetLandData += GetLandData;
3383
3384 if (m_interregionCommsIn != null)
3385 {
3386 m_log.Debug("[SCENE]: Registering with InterregionCommsIn");
3387 m_interregionCommsIn.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3388 }
3389 else
3390 m_log.Debug("[SCENE]: Unable to register with InterregionCommsIn");
3391 } 3332 }
3392 3333
3393 /// <summary> 3334 /// <summary>
@@ -3405,9 +3346,6 @@ namespace OpenSim.Region.Framework.Scenes
3405 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent; 3346 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent;
3406 m_sceneGridService.OnGetLandData -= GetLandData; 3347 m_sceneGridService.OnGetLandData -= GetLandData;
3407 3348
3408 if (m_interregionCommsIn != null)
3409 m_interregionCommsIn.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
3410
3411 // this does nothing; should be removed 3349 // this does nothing; should be removed
3412 m_sceneGridService.Close(); 3350 m_sceneGridService.Close();
3413 3351
@@ -3444,6 +3382,7 @@ namespace OpenSim.Region.Framework.Scenes
3444 /// also return a reason.</returns> 3382 /// also return a reason.</returns>
3445 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason) 3383 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason)
3446 { 3384 {
3385 TeleportFlags tp = (TeleportFlags)teleportFlags;
3447 //Teleport flags: 3386 //Teleport flags:
3448 // 3387 //
3449 // TeleportFlags.ViaGodlikeLure - Border Crossing 3388 // TeleportFlags.ViaGodlikeLure - Border Crossing
@@ -3464,7 +3403,7 @@ namespace OpenSim.Region.Framework.Scenes
3464 agent.AgentID, agent.circuitcode, teleportFlags); 3403 agent.AgentID, agent.circuitcode, teleportFlags);
3465 3404
3466 reason = String.Empty; 3405 reason = String.Empty;
3467 if (!AuthenticateUser(agent, out reason)) 3406 if (!VerifyUserPresence(agent, out reason))
3468 return false; 3407 return false;
3469 3408
3470 if (!AuthorizeUser(agent, out reason)) 3409 if (!AuthorizeUser(agent, out reason))
@@ -3477,7 +3416,18 @@ namespace OpenSim.Region.Framework.Scenes
3477 3416
3478 CapsModule.NewUserConnection(agent); 3417 CapsModule.NewUserConnection(agent);
3479 3418
3480 ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID); 3419 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3420
3421 //On login or border crossing test land permisions
3422 if (tp != TeleportFlags.Default)
3423 {
3424 if (land != null && !TestLandRestrictions(agent, land, out reason))
3425 {
3426 return false;
3427 }
3428 }
3429
3430 ScenePresence sp = GetScenePresence(agent.AgentID);
3481 if (sp != null) 3431 if (sp != null)
3482 { 3432 {
3483 m_log.DebugFormat( 3433 m_log.DebugFormat(
@@ -3564,40 +3514,73 @@ namespace OpenSim.Region.Framework.Scenes
3564 */// This is now handled properly in ScenePresence.MakeRootAgent 3514 */// This is now handled properly in ScenePresence.MakeRootAgent
3565 } 3515 }
3566 3516
3517 agent.teleportFlags = teleportFlags;
3567 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3518 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
3568 3519
3569 // rewrite session_id 3520 return true;
3570 CachedUserInfo userinfo = CommsManager.UserProfileCacheService.GetUserDetails(agent.AgentID); 3521 }
3571 if (userinfo != null) 3522
3572 { 3523 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason)
3573 userinfo.SessionID = agent.SessionID; 3524 {
3574 } 3525
3575 else 3526 bool banned = land.IsBannedFromLand(agent.AgentID);
3527 bool restricted = land.IsRestrictedFromLand(agent.AgentID);
3528
3529 if (banned || restricted)
3576 { 3530 {
3577 m_log.WarnFormat( 3531 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y);
3578 "[CONNECTION BEGIN]: We couldn't find a User Info record for {0}. This is usually an indication that the UUID we're looking up is invalid", agent.AgentID); 3532 if (nearestParcel != null)
3533 {
3534 //Move agent to nearest allowed
3535 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3536 agent.startpos.X = newPosition.X;
3537 agent.startpos.Y = newPosition.Y;
3538 }
3539 else
3540 {
3541 if (banned)
3542 {
3543 reason = "Cannot regioncross into banned parcel.";
3544 }
3545 else
3546 {
3547 reason = String.Format("Denied access to private region {0}: You are not on the access list for that region.",
3548 RegionInfo.RegionName);
3549 }
3550 return false;
3551 }
3579 } 3552 }
3580 3553 reason = "";
3581 return true; 3554 return true;
3582 } 3555 }
3583 3556
3584 /// <summary> 3557 /// <summary>
3585 /// Verifies that the user has a session on the Grid 3558 /// Verifies that the user has a presence on the Grid
3586 /// </summary> 3559 /// </summary>
3587 /// <param name="agent">Circuit Data of the Agent we're verifying</param> 3560 /// <param name="agent">Circuit Data of the Agent we're verifying</param>
3588 /// <param name="reason">Outputs the reason for the false response on this string</param> 3561 /// <param name="reason">Outputs the reason for the false response on this string</param>
3589 /// <returns>True if the user has a session on the grid. False if it does not. False will 3562 /// <returns>True if the user has a session on the grid. False if it does not. False will
3590 /// also return a reason.</returns> 3563 /// also return a reason.</returns>
3591 public virtual bool AuthenticateUser(AgentCircuitData agent, out string reason) 3564 public virtual bool VerifyUserPresence(AgentCircuitData agent, out string reason)
3592 { 3565 {
3593 reason = String.Empty; 3566 reason = String.Empty;
3594 3567
3595 bool result = CommsManager.UserService.VerifySession(agent.AgentID, agent.SessionID); 3568 IPresenceService presence = RequestModuleInterface<IPresenceService>();
3596 m_log.Debug("[CONNECTION BEGIN]: User authentication returned " + result); 3569 if (presence == null)
3597 if (!result) 3570 {
3598 reason = String.Format("Failed to authenticate user {0} {1}, access denied.", agent.firstname, agent.lastname); 3571 reason = String.Format("Failed to verify user {0} {1} in region {2}. Presence service does not exist.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3572 return false;
3573 }
3574
3575 OpenSim.Services.Interfaces.PresenceInfo pinfo = presence.GetAgent(agent.SessionID);
3576
3577 if (pinfo == null || (pinfo != null && pinfo.Online == false))
3578 {
3579 reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3580 return false;
3581 }
3599 3582
3600 return result; 3583 return true;
3601 } 3584 }
3602 3585
3603 /// <summary> 3586 /// <summary>
@@ -3702,6 +3685,18 @@ namespace OpenSim.Region.Framework.Scenes
3702 return true; 3685 return true;
3703 } 3686 }
3704 3687
3688 private ILandObject GetParcelAtPoint(float x, float y)
3689 {
3690 foreach (var parcel in AllParcels())
3691 {
3692 if (parcel.ContainsPoint((int)x,(int)y))
3693 {
3694 return parcel;
3695 }
3696 }
3697 return null;
3698 }
3699
3705 /// <summary> 3700 /// <summary>
3706 /// Update an AgentCircuitData object with new information 3701 /// Update an AgentCircuitData object with new information
3707 /// </summary> 3702 /// </summary>
@@ -3730,8 +3725,7 @@ namespace OpenSim.Region.Framework.Scenes
3730 /// <param name="message">message to display to the user. Reason for being logged off</param> 3725 /// <param name="message">message to display to the user. Reason for being logged off</param>
3731 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message) 3726 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message)
3732 { 3727 {
3733 ScenePresence loggingOffUser = null; 3728 ScenePresence loggingOffUser = GetScenePresence(AvatarID);
3734 loggingOffUser = GetScenePresence(AvatarID);
3735 if (loggingOffUser != null) 3729 if (loggingOffUser != null)
3736 { 3730 {
3737 UUID localRegionSecret = UUID.Zero; 3731 UUID localRegionSecret = UUID.Zero;
@@ -3767,10 +3761,8 @@ namespace OpenSim.Region.Framework.Scenes
3767 /// <param name="isFlying"></param> 3761 /// <param name="isFlying"></param>
3768 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) 3762 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying)
3769 { 3763 {
3770 ScenePresence presence; 3764 ScenePresence presence = GetScenePresence(agentID);
3771 m_sceneGraph.TryGetAvatar(agentID, out presence); 3765 if(presence != null)
3772
3773 if (presence != null)
3774 { 3766 {
3775 try 3767 try
3776 { 3768 {
@@ -3798,8 +3790,8 @@ namespace OpenSim.Region.Framework.Scenes
3798 /// <returns>true if we handled it.</returns> 3790 /// <returns>true if we handled it.</returns>
3799 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData) 3791 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData)
3800 { 3792 {
3801// m_log.DebugFormat( 3793 m_log.DebugFormat(
3802// "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName); 3794 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
3803 3795
3804 // We have to wait until the viewer contacts this region after receiving EAC. 3796 // We have to wait until the viewer contacts this region after receiving EAC.
3805 // That calls AddNewClient, which finally creates the ScenePresence 3797 // That calls AddNewClient, which finally creates the ScenePresence
@@ -3868,16 +3860,6 @@ namespace OpenSim.Region.Framework.Scenes
3868 return false; 3860 return false;
3869 } 3861 }
3870 3862
3871 public virtual bool IncomingReleaseAgent(UUID id)
3872 {
3873 return m_sceneGridService.ReleaseAgent(id);
3874 }
3875
3876 public void SendReleaseAgent(ulong regionHandle, UUID id, string uri)
3877 {
3878 m_interregionCommsOut.SendReleaseAgent(regionHandle, id, uri);
3879 }
3880
3881 /// <summary> 3863 /// <summary>
3882 /// Tell a single agent to disconnect from the region. 3864 /// Tell a single agent to disconnect from the region.
3883 /// </summary> 3865 /// </summary>
@@ -3922,30 +3904,6 @@ namespace OpenSim.Region.Framework.Scenes
3922 } 3904 }
3923 3905
3924 /// <summary> 3906 /// <summary>
3925 /// Tell neighboring regions about this agent
3926 /// When the regions respond with a true value,
3927 /// tell the agents about the region.
3928 ///
3929 /// We have to tell the regions about the agents first otherwise it'll deny them access
3930 ///
3931 /// </summary>
3932 /// <param name="presence"></param>
3933 public void InformClientOfNeighbours(ScenePresence presence)
3934 {
3935 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3936 }
3937
3938 /// <summary>
3939 /// Tell a neighboring region about this agent
3940 /// </summary>
3941 /// <param name="presence"></param>
3942 /// <param name="region"></param>
3943 public void InformClientOfNeighbor(ScenePresence presence, RegionInfo region)
3944 {
3945 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3946 }
3947
3948 /// <summary>
3949 /// Tries to teleport agent to other region. 3907 /// Tries to teleport agent to other region.
3950 /// </summary> 3908 /// </summary>
3951 /// <param name="remoteClient"></param> 3909 /// <param name="remoteClient"></param>
@@ -3978,9 +3936,7 @@ namespace OpenSim.Region.Framework.Scenes
3978 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position, 3936 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position,
3979 Vector3 lookAt, uint teleportFlags) 3937 Vector3 lookAt, uint teleportFlags)
3980 { 3938 {
3981 ScenePresence sp; 3939 ScenePresence sp = GetScenePresence(remoteClient.AgentId);
3982 m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp);
3983
3984 if (sp != null) 3940 if (sp != null)
3985 { 3941 {
3986 uint regionX = m_regInfo.RegionLocX; 3942 uint regionX = m_regInfo.RegionLocX;
@@ -4020,16 +3976,12 @@ namespace OpenSim.Region.Framework.Scenes
4020 } 3976 }
4021 3977
4022 if (m_teleportModule != null) 3978 if (m_teleportModule != null)
4023 { 3979 m_teleportModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
4024 m_teleportModule.RequestTeleportToLocation(sp, regionHandle,
4025 position, lookAt, teleportFlags);
4026 }
4027 else 3980 else
4028 { 3981 {
4029 m_sceneGridService.RequestTeleportToLocation(sp, regionHandle, 3982 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active");
4030 position, lookAt, teleportFlags); 3983 sp.ControllingClient.SendTeleportFailed("Unable to perform teleports on this simulator.");
4031 } 3984 }
4032
4033 } 3985 }
4034 } 3986 }
4035 3987
@@ -4055,7 +4007,12 @@ namespace OpenSim.Region.Framework.Scenes
4055 4007
4056 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying) 4008 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying)
4057 { 4009 {
4058 m_sceneGridService.CrossAgentToNewRegion(this, agent, isFlying); 4010 if (m_teleportModule != null)
4011 m_teleportModule.Cross(agent, isFlying);
4012 else
4013 {
4014 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule");
4015 }
4059 } 4016 }
4060 4017
4061 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence) 4018 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence)
@@ -4081,35 +4038,6 @@ namespace OpenSim.Region.Framework.Scenes
4081 objectCapacity = objects; 4038 objectCapacity = objects;
4082 } 4039 }
4083 4040
4084 public List<FriendListItem> GetFriendList(string id)
4085 {
4086 UUID avatarID;
4087 if (!UUID.TryParse(id, out avatarID))
4088 return new List<FriendListItem>();
4089
4090 return CommsManager.GetUserFriendList(avatarID);
4091 }
4092
4093 public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
4094 {
4095 return CommsManager.GetFriendRegionInfos(uuids);
4096 }
4097
4098 public virtual void StoreAddFriendship(UUID ownerID, UUID friendID, uint perms)
4099 {
4100 m_sceneGridService.AddNewUserFriend(ownerID, friendID, perms);
4101 }
4102
4103 public virtual void StoreUpdateFriendship(UUID ownerID, UUID friendID, uint perms)
4104 {
4105 m_sceneGridService.UpdateUserFriendPerms(ownerID, friendID, perms);
4106 }
4107
4108 public virtual void StoreRemoveFriendship(UUID ownerID, UUID ExfriendID)
4109 {
4110 m_sceneGridService.RemoveUserFriend(ownerID, ExfriendID);
4111 }
4112
4113 #endregion 4041 #endregion
4114 4042
4115 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set) 4043 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set)
@@ -4187,17 +4115,17 @@ namespace OpenSim.Region.Framework.Scenes
4187 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", 4115 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname",
4188 "Agent ID", "Session ID", "Circuit", "IP", "World"); 4116 "Agent ID", "Session ID", "Circuit", "IP", "World");
4189 4117
4190 foreach (ScenePresence scenePresence in GetAvatars()) 4118 ForEachScenePresence(delegate(ScenePresence sp)
4191 { 4119 {
4192 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}", 4120 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}",
4193 scenePresence.Firstname, 4121 sp.Firstname,
4194 scenePresence.Lastname, 4122 sp.Lastname,
4195 scenePresence.UUID, 4123 sp.UUID,
4196 scenePresence.ControllingClient.AgentId, 4124 sp.ControllingClient.AgentId,
4197 "Unknown", 4125 "Unknown",
4198 "Unknown", 4126 "Unknown",
4199 RegionInfo.RegionName); 4127 RegionInfo.RegionName);
4200 } 4128 });
4201 4129
4202 break; 4130 break;
4203 } 4131 }
@@ -4363,56 +4291,45 @@ namespace OpenSim.Region.Framework.Scenes
4363 m_sceneGraph.RemovePhysicalPrim(num); 4291 m_sceneGraph.RemovePhysicalPrim(num);
4364 } 4292 }
4365 4293
4366 //The idea is to have a group of method that return a list of avatars meeting some requirement 4294 public int GetRootAgentCount()
4367 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
4368
4369 /// <summary>
4370 /// Return a list of all avatars in this region.
4371 /// This list is a new object, so it can be iterated over without locking.
4372 /// </summary>
4373 /// <returns></returns>
4374 public List<ScenePresence> GetAvatars()
4375 { 4295 {
4376 return m_sceneGraph.GetAvatars(); 4296 return m_sceneGraph.GetRootAgentCount();
4377 } 4297 }
4378 4298
4379 /// <summary> 4299 public int GetChildAgentCount()
4380 /// Cheaply return the number of avatars in a region (without fetching a list object)
4381 /// </summary>
4382 public int GetRootAgentCount()
4383 { 4300 {
4384 return m_sceneGraph.GetRootAgentCount(); 4301 return m_sceneGraph.GetChildAgentCount();
4385 } 4302 }
4386 4303
4387 /// <summary> 4304 /// <summary>
4388 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents. 4305 /// Request a scene presence by UUID. Fast, indexed lookup.
4389 /// This list is a new object, so it can be iterated over without locking.
4390 /// </summary> 4306 /// </summary>
4391 /// <returns></returns> 4307 /// <param name="agentID"></param>
4392 public ScenePresence[] GetScenePresences() 4308 /// <returns>null if the presence was not found</returns>
4309 public ScenePresence GetScenePresence(UUID agentID)
4393 { 4310 {
4394 return m_sceneGraph.GetScenePresences(); 4311 return m_sceneGraph.GetScenePresence(agentID);
4395 } 4312 }
4396 4313
4397 /// <summary> 4314 /// <summary>
4398 /// Request a filtered list of ScenePresences in this region. 4315 /// Request the scene presence by name.
4399 /// This list is a new object, so it can be iterated over without locking.
4400 /// </summary> 4316 /// </summary>
4401 /// <param name="filter"></param> 4317 /// <param name="firstName"></param>
4402 /// <returns></returns> 4318 /// <param name="lastName"></param>
4403 public List<ScenePresence> GetScenePresences(FilterAvatarList filter) 4319 /// <returns>null if the presence was not found</returns>
4320 public ScenePresence GetScenePresence(string firstName, string lastName)
4404 { 4321 {
4405 return m_sceneGraph.GetScenePresences(filter); 4322 return m_sceneGraph.GetScenePresence(firstName, lastName);
4406 } 4323 }
4407 4324
4408 /// <summary> 4325 /// <summary>
4409 /// Request a scene presence by UUID 4326 /// Request the scene presence by localID.
4410 /// </summary> 4327 /// </summary>
4411 /// <param name="avatarID"></param> 4328 /// <param name="localID"></param>
4412 /// <returns></returns> 4329 /// <returns>null if the presence was not found</returns>
4413 public ScenePresence GetScenePresence(UUID avatarID) 4330 public ScenePresence GetScenePresence(uint localID)
4414 { 4331 {
4415 return m_sceneGraph.GetScenePresence(avatarID); 4332 return m_sceneGraph.GetScenePresence(localID);
4416 } 4333 }
4417 4334
4418 public override bool PresenceChildStatus(UUID avatarID) 4335 public override bool PresenceChildStatus(UUID avatarID)
@@ -4430,25 +4347,14 @@ namespace OpenSim.Region.Framework.Scenes
4430 } 4347 }
4431 4348
4432 /// <summary> 4349 /// <summary>
4433 /// 4350 /// Performs action on all scene presences.
4434 /// </summary> 4351 /// </summary>
4435 /// <param name="action"></param> 4352 /// <param name="action"></param>
4436 public void ForEachScenePresence(Action<ScenePresence> action) 4353 public void ForEachScenePresence(Action<ScenePresence> action)
4437 { 4354 {
4438 // We don't want to try to send messages if there are no avatars.
4439 if (m_sceneGraph != null) 4355 if (m_sceneGraph != null)
4440 { 4356 {
4441 try 4357 m_sceneGraph.ForEachScenePresence(action);
4442 {
4443 ScenePresence[] presences = GetScenePresences();
4444 for (int i = 0; i < presences.Length; i++)
4445 action(presences[i]);
4446 }
4447 catch (Exception e)
4448 {
4449 m_log.Info("[BUG] in " + RegionInfo.RegionName + ": " + e.ToString());
4450 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
4451 }
4452 } 4358 }
4453 } 4359 }
4454 4360
@@ -4512,9 +4418,9 @@ namespace OpenSim.Region.Framework.Scenes
4512 return m_sceneGraph.GetGroupByPrim(localID); 4418 return m_sceneGraph.GetGroupByPrim(localID);
4513 } 4419 }
4514 4420
4515 public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 4421 public override bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
4516 { 4422 {
4517 return m_sceneGraph.TryGetAvatar(avatarId, out avatar); 4423 return m_sceneGraph.TryGetScenePresence(avatarId, out avatar);
4518 } 4424 }
4519 4425
4520 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 4426 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
@@ -4524,20 +4430,7 @@ namespace OpenSim.Region.Framework.Scenes
4524 4430
4525 public void ForEachClient(Action<IClientAPI> action) 4431 public void ForEachClient(Action<IClientAPI> action)
4526 { 4432 {
4527 ForEachClient(action, m_useAsyncWhenPossible);
4528 }
4529
4530 public void ForEachClient(Action<IClientAPI> action, bool doAsynchronous)
4531 {
4532 // FIXME: Asynchronous iteration is disabled until we have a threading model that
4533 // can support calling this function from an async packet handler without
4534 // potentially deadlocking
4535 m_clientManager.ForEachSync(action); 4433 m_clientManager.ForEachSync(action);
4536
4537 //if (doAsynchronous)
4538 // m_clientManager.ForEach(action);
4539 //else
4540 // m_clientManager.ForEachSync(action);
4541 } 4434 }
4542 4435
4543 public bool TryGetClient(UUID avatarID, out IClientAPI client) 4436 public bool TryGetClient(UUID avatarID, out IClientAPI client)
@@ -4709,7 +4602,8 @@ namespace OpenSim.Region.Framework.Scenes
4709 group.GetPartName(localID), 4602 group.GetPartName(localID),
4710 group.GetPartDescription(localID), 4603 group.GetPartDescription(localID),
4711 (sbyte)AssetType.Object, 4604 (sbyte)AssetType.Object,
4712 Utils.StringToBytes(sceneObjectXml)); 4605 Utils.StringToBytes(sceneObjectXml),
4606 group.OwnerID);
4713 AssetService.Store(asset); 4607 AssetService.Store(asset);
4714 4608
4715 InventoryItemBase item = new InventoryItemBase(); 4609 InventoryItemBase item = new InventoryItemBase();
@@ -5033,5 +4927,185 @@ namespace OpenSim.Region.Framework.Scenes
5033 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4927 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000)
5034 StartTimer(); 4928 StartTimer();
5035 } 4929 }
4930
4931 public override ISceneObject DeserializeObject(string representation)
4932 {
4933 return SceneObjectSerializer.FromXml2Format(representation);
4934 }
4935
4936 public override bool AllowScriptCrossings
4937 {
4938 get { return m_allowScriptCrossings; }
4939 }
4940
4941 public Vector3? GetNearestAllowedPosition(ScenePresence avatar)
4942 {
4943 //simulate to make sure we have pretty up to date positions
4944 PhysicsScene.Simulate(0);
4945
4946 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
4947
4948 if (nearestParcel != null)
4949 {
4950 Vector3 dir = Vector3.Normalize(Vector3.Multiply(avatar.Velocity, -1));
4951 //Try to get a location that feels like where they came from
4952 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4953 if (nearestPoint != null)
4954 {
4955 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4956 return nearestPoint.Value;
4957 }
4958
4959 //Sometimes velocity might be zero (local teleport), so try finding point along path from avatar to center of nearest parcel
4960 Vector3 directionToParcelCenter = Vector3.Subtract(GetParcelCenterAtGround(nearestParcel), avatar.AbsolutePosition);
4961 dir = Vector3.Normalize(directionToParcelCenter);
4962 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4963 if (nearestPoint != null)
4964 {
4965 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4966 return nearestPoint.Value;
4967 }
4968
4969 //Ultimate backup if we have no idea where they are
4970 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
4971 return avatar.lastKnownAllowedPosition;
4972
4973 }
4974
4975 //Go to the edge, this happens in teleporting to a region with no available parcels
4976 Vector3 nearestRegionEdgePoint = GetNearestRegionEdgePosition(avatar);
4977 //Debug.WriteLine("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString());
4978 return nearestRegionEdgePoint;
4979 return null;
4980 }
4981
4982 private Vector3 GetParcelCenterAtGround(ILandObject parcel)
4983 {
4984 Vector2 center = GetParcelCenter(parcel);
4985 return GetPositionAtGround(center.X, center.Y);
4986 }
4987
4988 private Vector3? GetNearestPointInParcelAlongDirectionFromPoint(Vector3 pos, Vector3 direction, ILandObject parcel)
4989 {
4990 Vector3 unitDirection = Vector3.Normalize(direction);
4991 //Making distance to search go through some sane limit of distance
4992 for (float distance = 0; distance < Constants.RegionSize * 2; distance += .5f)
4993 {
4994 Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance));
4995 if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y))
4996 {
4997 return testPos;
4998 }
4999 }
5000 return null;
5001 }
5002
5003 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5004 {
5005 List<ILandObject> all = AllParcels();
5006 float minParcelDistance = float.MaxValue;
5007 ILandObject nearestParcel = null;
5008
5009 foreach (var parcel in all)
5010 {
5011 if (!parcel.IsEitherBannedOrRestricted(avatarId))
5012 {
5013 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5014 if (parcelDistance < minParcelDistance)
5015 {
5016 minParcelDistance = parcelDistance;
5017 nearestParcel = parcel;
5018 }
5019 }
5020 }
5021
5022 return nearestParcel;
5023 }
5024
5025 private List<ILandObject> AllParcels()
5026 {
5027 return LandChannel.AllParcels();
5028 }
5029
5030 private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y)
5031 {
5032 return Vector2.Distance(new Vector2(x, y), GetParcelCenter(parcel));
5033 }
5034
5035 //calculate the average center point of a parcel
5036 private Vector2 GetParcelCenter(ILandObject parcel)
5037 {
5038 int count = 0;
5039 int avgx = 0;
5040 int avgy = 0;
5041 for (int x = 0; x < Constants.RegionSize; x++)
5042 {
5043 for (int y = 0; y < Constants.RegionSize; y++)
5044 {
5045 //Just keep a running average as we check if all the points are inside or not
5046 if (parcel.ContainsPoint(x, y))
5047 {
5048 if (count == 0)
5049 {
5050 avgx = x;
5051 avgy = y;
5052 }
5053 else
5054 {
5055 avgx = (avgx * count + x) / (count + 1);
5056 avgy = (avgy * count + y) / (count + 1);
5057 }
5058 count += 1;
5059 }
5060 }
5061 }
5062 return new Vector2(avgx, avgy);
5063 }
5064
5065 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
5066 {
5067 float xdistance = avatar.AbsolutePosition.X < Constants.RegionSize / 2 ? avatar.AbsolutePosition.X : Constants.RegionSize - avatar.AbsolutePosition.X;
5068 float ydistance = avatar.AbsolutePosition.Y < Constants.RegionSize / 2 ? avatar.AbsolutePosition.Y : Constants.RegionSize - avatar.AbsolutePosition.Y;
5069
5070 //find out what vertical edge to go to
5071 if (xdistance < ydistance)
5072 {
5073 if (avatar.AbsolutePosition.X < Constants.RegionSize / 2)
5074 {
5075 return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
5076 }
5077 else
5078 {
5079 return GetPositionAtAvatarHeightOrGroundHeight(avatar, Constants.RegionSize, avatar.AbsolutePosition.Y);
5080 }
5081 }
5082 //find out what horizontal edge to go to
5083 else
5084 {
5085 if (avatar.AbsolutePosition.Y < Constants.RegionSize / 2)
5086 {
5087 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
5088 }
5089 else
5090 {
5091 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, Constants.RegionSize);
5092 }
5093 }
5094 }
5095
5096 private Vector3 GetPositionAtAvatarHeightOrGroundHeight(ScenePresence avatar, float x, float y)
5097 {
5098 Vector3 ground = GetPositionAtGround(x, y);
5099 if (avatar.AbsolutePosition.Z > ground.Z)
5100 {
5101 ground.Z = avatar.AbsolutePosition.Z;
5102 }
5103 return ground;
5104 }
5105
5106 private Vector3 GetPositionAtGround(float x, float y)
5107 {
5108 return new Vector3(x, y, GetGroundHeight(x, y));
5109 }
5036 } 5110 }
5037} 5111}