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.cs1175
1 files changed, 624 insertions, 551 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 0556166..8ceb109 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 );
@@ -1029,7 +1159,6 @@ namespace OpenSim.Region.Framework.Scenes
1029 { 1159 {
1030 if (m_scripts_enabled != !ScriptEngine) 1160 if (m_scripts_enabled != !ScriptEngine)
1031 { 1161 {
1032 // Tedd! Here's the method to disable the scripting engine!
1033 if (ScriptEngine) 1162 if (ScriptEngine)
1034 { 1163 {
1035 m_log.Info("Stopping all Scripts in Scene"); 1164 m_log.Info("Stopping all Scripts in Scene");
@@ -1051,6 +1180,7 @@ namespace OpenSim.Region.Framework.Scenes
1051 if (ent is SceneObjectGroup) 1180 if (ent is SceneObjectGroup)
1052 { 1181 {
1053 ((SceneObjectGroup)ent).CreateScriptInstances(0, false, DefaultScriptEngine, 0); 1182 ((SceneObjectGroup)ent).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
1183 ((SceneObjectGroup)ent).ResumeScripts();
1054 } 1184 }
1055 } 1185 }
1056 } 1186 }
@@ -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
@@ -2790,6 +2777,7 @@ namespace OpenSim.Region.Framework.Scenes
2790 public virtual void SubscribeToClientInventoryEvents(IClientAPI client) 2777 public virtual void SubscribeToClientInventoryEvents(IClientAPI client)
2791 { 2778 {
2792 client.OnCreateNewInventoryItem += CreateNewInventoryItem; 2779 client.OnCreateNewInventoryItem += CreateNewInventoryItem;
2780 client.OnLinkInventoryItem += HandleLinkInventoryItem;
2793 client.OnCreateNewInventoryFolder += HandleCreateInventoryFolder; 2781 client.OnCreateNewInventoryFolder += HandleCreateInventoryFolder;
2794 client.OnUpdateInventoryFolder += HandleUpdateInventoryFolder; 2782 client.OnUpdateInventoryFolder += HandleUpdateInventoryFolder;
2795 client.OnMoveInventoryFolder += HandleMoveInventoryFolder; // 2; //!! 2783 client.OnMoveInventoryFolder += HandleMoveInventoryFolder; // 2; //!!
@@ -2809,19 +2797,21 @@ namespace OpenSim.Region.Framework.Scenes
2809 } 2797 }
2810 2798
2811 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client) 2799 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client)
2812 { 2800 {
2813 client.OnRezSingleAttachmentFromInv += RezSingleAttachment; 2801 if (AttachmentsModule != null)
2814 client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments; 2802 {
2815 client.OnDetachAttachmentIntoInv += DetachSingleAttachmentToInv; 2803 client.OnRezSingleAttachmentFromInv += AttachmentsModule.RezSingleAttachmentFromInventory;
2816 client.OnObjectAttach += m_sceneGraph.AttachObject; 2804 client.OnRezMultipleAttachmentsFromInv += AttachmentsModule.RezMultipleAttachmentsFromInventory;
2817 client.OnObjectDetach += m_sceneGraph.DetachObject; 2805 client.OnObjectAttach += AttachmentsModule.AttachObject;
2806 client.OnObjectDetach += AttachmentsModule.DetachObject;
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;
@@ -2965,19 +2952,22 @@ namespace OpenSim.Region.Framework.Scenes
2965 } 2952 }
2966 2953
2967 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client) 2954 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client)
2968 { 2955 {
2969 client.OnRezSingleAttachmentFromInv -= RezSingleAttachment; 2956 if (AttachmentsModule != null)
2970 client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments; 2957 {
2971 client.OnDetachAttachmentIntoInv -= DetachSingleAttachmentToInv; 2958 client.OnRezSingleAttachmentFromInv -= AttachmentsModule.RezSingleAttachmentFromInventory;
2972 client.OnObjectAttach -= m_sceneGraph.AttachObject; 2959 client.OnRezMultipleAttachmentsFromInv -= AttachmentsModule.RezMultipleAttachmentsFromInventory;
2973 client.OnObjectDetach -= m_sceneGraph.DetachObject; 2960 client.OnObjectAttach -= AttachmentsModule.AttachObject;
2961 client.OnObjectDetach -= AttachmentsModule.DetachObject;
2962 client.OnDetachAttachmentIntoInv -= AttachmentsModule.ShowDetachInUserInventory;
2963 }
2974 } 2964 }
2975 2965
2976 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client) 2966 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client)
2977 { 2967 {
2978 client.OnTeleportLocationRequest -= RequestTeleportLocation; 2968 client.OnTeleportLocationRequest -= RequestTeleportLocation;
2979 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark; 2969 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark;
2980 client.OnTeleportHomeRequest -= TeleportClientHome; 2970 //client.OnTeleportHomeRequest -= TeleportClientHome;
2981 } 2971 }
2982 2972
2983 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client) 2973 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client)
@@ -2997,7 +2987,7 @@ namespace OpenSim.Region.Framework.Scenes
2997 2987
2998 public virtual void UnSubscribeToClientGridEvents(IClientAPI client) 2988 public virtual void UnSubscribeToClientGridEvents(IClientAPI client)
2999 { 2989 {
3000 client.OnNameFromUUIDRequest -= CommsManager.HandleUUIDNameRequest; 2990 client.OnNameFromUUIDRequest -= HandleUUIDNameRequest;
3001 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest; 2991 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest;
3002 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest; 2992 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest;
3003 client.OnSetStartLocationRequest -= SetHomeRezPoint; 2993 client.OnSetStartLocationRequest -= SetHomeRezPoint;
@@ -3024,30 +3014,12 @@ namespace OpenSim.Region.Framework.Scenes
3024 /// <param name="client">The IClientAPI for the client</param> 3014 /// <param name="client">The IClientAPI for the client</param>
3025 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3015 public virtual void TeleportClientHome(UUID agentId, IClientAPI client)
3026 { 3016 {
3027 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(agentId); 3017 if (m_teleportModule != null)
3028 if (UserProfile != null) 3018 m_teleportModule.TeleportHome(agentId, client);
3019 else
3029 { 3020 {
3030 GridRegion regionInfo = GridService.GetRegionByUUID(UUID.Zero, UserProfile.HomeRegionID); 3021 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3031 if (regionInfo == null) 3022 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 } 3023 }
3052 } 3024 }
3053 3025
@@ -3138,7 +3110,7 @@ namespace OpenSim.Region.Framework.Scenes
3138 } 3110 }
3139 3111
3140 /// <summary> 3112 /// <summary>
3141 /// Sets the Home Point. The GridService uses this to know where to put a user when they log-in 3113 /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
3142 /// </summary> 3114 /// </summary>
3143 /// <param name="remoteClient"></param> 3115 /// <param name="remoteClient"></param>
3144 /// <param name="regionHandle"></param> 3116 /// <param name="regionHandle"></param>
@@ -3147,27 +3119,11 @@ namespace OpenSim.Region.Framework.Scenes
3147 /// <param name="flags"></param> 3119 /// <param name="flags"></param>
3148 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3120 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3149 { 3121 {
3150 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(remoteClient.AgentId); 3122 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. 3123 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3165 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3124 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
3166 }
3167 else 3125 else
3168 {
3169 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed."); 3126 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed.");
3170 }
3171 } 3127 }
3172 3128
3173 /// <summary> 3129 /// <summary>
@@ -3240,14 +3196,12 @@ namespace OpenSim.Region.Framework.Scenes
3240 m_sceneGraph.removeUserCount(!childagentYN); 3196 m_sceneGraph.removeUserCount(!childagentYN);
3241 CapsModule.RemoveCapsHandler(agentID); 3197 CapsModule.RemoveCapsHandler(agentID);
3242 3198
3243 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID)) 3199 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
3244 { 3200 // this method is doing is HORRIBLE!!!
3245 CommsManager.UserProfileCacheService.RemoveUser(agentID); 3201 avatar.Scene.NeedSceneCacheClear(avatar.UUID);
3246 }
3247 3202
3248 if (!avatar.IsChildAgent) 3203 if (!avatar.IsChildAgent)
3249 { 3204 {
3250 m_sceneGridService.LogOffUser(agentID, RegionInfo.RegionID, RegionInfo.RegionHandle, avatar.AbsolutePosition, avatar.Lookat);
3251 //List<ulong> childknownRegions = new List<ulong>(); 3205 //List<ulong> childknownRegions = new List<ulong>();
3252 //List<ulong> ckn = avatar.KnownChildRegionHandles; 3206 //List<ulong> ckn = avatar.KnownChildRegionHandles;
3253 //for (int i = 0; i < ckn.Count; i++) 3207 //for (int i = 0; i < ckn.Count; i++)
@@ -3302,12 +3256,6 @@ namespace OpenSim.Region.Framework.Scenes
3302 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3256 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3303 } 3257 }
3304 3258
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); 3259 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3312 3260
3313 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3261 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
@@ -3380,14 +3328,6 @@ namespace OpenSim.Region.Framework.Scenes
3380 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3328 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3381 m_sceneGridService.KiPrimitive += SendKillObject; 3329 m_sceneGridService.KiPrimitive += SendKillObject;
3382 m_sceneGridService.OnGetLandData += GetLandData; 3330 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 } 3331 }
3392 3332
3393 /// <summary> 3333 /// <summary>
@@ -3405,9 +3345,6 @@ namespace OpenSim.Region.Framework.Scenes
3405 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent; 3345 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent;
3406 m_sceneGridService.OnGetLandData -= GetLandData; 3346 m_sceneGridService.OnGetLandData -= GetLandData;
3407 3347
3408 if (m_interregionCommsIn != null)
3409 m_interregionCommsIn.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
3410
3411 // this does nothing; should be removed 3348 // this does nothing; should be removed
3412 m_sceneGridService.Close(); 3349 m_sceneGridService.Close();
3413 3350
@@ -3444,6 +3381,7 @@ namespace OpenSim.Region.Framework.Scenes
3444 /// also return a reason.</returns> 3381 /// also return a reason.</returns>
3445 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason) 3382 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason)
3446 { 3383 {
3384 TeleportFlags tp = (TeleportFlags)teleportFlags;
3447 //Teleport flags: 3385 //Teleport flags:
3448 // 3386 //
3449 // TeleportFlags.ViaGodlikeLure - Border Crossing 3387 // TeleportFlags.ViaGodlikeLure - Border Crossing
@@ -3464,7 +3402,7 @@ namespace OpenSim.Region.Framework.Scenes
3464 agent.AgentID, agent.circuitcode, teleportFlags); 3402 agent.AgentID, agent.circuitcode, teleportFlags);
3465 3403
3466 reason = String.Empty; 3404 reason = String.Empty;
3467 if (!AuthenticateUser(agent, out reason)) 3405 if (!VerifyUserPresence(agent, out reason))
3468 return false; 3406 return false;
3469 3407
3470 if (!AuthorizeUser(agent, out reason)) 3408 if (!AuthorizeUser(agent, out reason))
@@ -3477,7 +3415,18 @@ namespace OpenSim.Region.Framework.Scenes
3477 3415
3478 CapsModule.NewUserConnection(agent); 3416 CapsModule.NewUserConnection(agent);
3479 3417
3480 ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID); 3418 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3419
3420 //On login or border crossing test land permisions
3421 if (tp != TeleportFlags.Default)
3422 {
3423 if (land != null && !TestLandRestrictions(agent, land, out reason))
3424 {
3425 return false;
3426 }
3427 }
3428
3429 ScenePresence sp = GetScenePresence(agent.AgentID);
3481 if (sp != null) 3430 if (sp != null)
3482 { 3431 {
3483 m_log.DebugFormat( 3432 m_log.DebugFormat(
@@ -3564,40 +3513,73 @@ namespace OpenSim.Region.Framework.Scenes
3564 */// This is now handled properly in ScenePresence.MakeRootAgent 3513 */// This is now handled properly in ScenePresence.MakeRootAgent
3565 } 3514 }
3566 3515
3516 agent.teleportFlags = teleportFlags;
3567 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3517 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
3568 3518
3569 // rewrite session_id 3519 return true;
3570 CachedUserInfo userinfo = CommsManager.UserProfileCacheService.GetUserDetails(agent.AgentID); 3520 }
3571 if (userinfo != null) 3521
3572 { 3522 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason)
3573 userinfo.SessionID = agent.SessionID; 3523 {
3574 } 3524
3575 else 3525 bool banned = land.IsBannedFromLand(agent.AgentID);
3526 bool restricted = land.IsRestrictedFromLand(agent.AgentID);
3527
3528 if (banned || restricted)
3576 { 3529 {
3577 m_log.WarnFormat( 3530 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); 3531 if (nearestParcel != null)
3532 {
3533 //Move agent to nearest allowed
3534 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3535 agent.startpos.X = newPosition.X;
3536 agent.startpos.Y = newPosition.Y;
3537 }
3538 else
3539 {
3540 if (banned)
3541 {
3542 reason = "Cannot regioncross into banned parcel.";
3543 }
3544 else
3545 {
3546 reason = String.Format("Denied access to private region {0}: You are not on the access list for that region.",
3547 RegionInfo.RegionName);
3548 }
3549 return false;
3550 }
3579 } 3551 }
3580 3552 reason = "";
3581 return true; 3553 return true;
3582 } 3554 }
3583 3555
3584 /// <summary> 3556 /// <summary>
3585 /// Verifies that the user has a session on the Grid 3557 /// Verifies that the user has a presence on the Grid
3586 /// </summary> 3558 /// </summary>
3587 /// <param name="agent">Circuit Data of the Agent we're verifying</param> 3559 /// <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> 3560 /// <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 3561 /// <returns>True if the user has a session on the grid. False if it does not. False will
3590 /// also return a reason.</returns> 3562 /// also return a reason.</returns>
3591 public virtual bool AuthenticateUser(AgentCircuitData agent, out string reason) 3563 public virtual bool VerifyUserPresence(AgentCircuitData agent, out string reason)
3592 { 3564 {
3593 reason = String.Empty; 3565 reason = String.Empty;
3594 3566
3595 bool result = CommsManager.UserService.VerifySession(agent.AgentID, agent.SessionID); 3567 IPresenceService presence = RequestModuleInterface<IPresenceService>();
3596 m_log.Debug("[CONNECTION BEGIN]: User authentication returned " + result); 3568 if (presence == null)
3597 if (!result) 3569 {
3598 reason = String.Format("Failed to authenticate user {0} {1}, access denied.", agent.firstname, agent.lastname); 3570 reason = String.Format("Failed to verify user {0} {1} in region {2}. Presence service does not exist.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3571 return false;
3572 }
3573
3574 OpenSim.Services.Interfaces.PresenceInfo pinfo = presence.GetAgent(agent.SessionID);
3575
3576 if (pinfo == null || (pinfo != null && pinfo.Online == false))
3577 {
3578 reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3579 return false;
3580 }
3599 3581
3600 return result; 3582 return true;
3601 } 3583 }
3602 3584
3603 /// <summary> 3585 /// <summary>
@@ -3702,6 +3684,18 @@ namespace OpenSim.Region.Framework.Scenes
3702 return true; 3684 return true;
3703 } 3685 }
3704 3686
3687 private ILandObject GetParcelAtPoint(float x, float y)
3688 {
3689 foreach (var parcel in AllParcels())
3690 {
3691 if (parcel.ContainsPoint((int)x,(int)y))
3692 {
3693 return parcel;
3694 }
3695 }
3696 return null;
3697 }
3698
3705 /// <summary> 3699 /// <summary>
3706 /// Update an AgentCircuitData object with new information 3700 /// Update an AgentCircuitData object with new information
3707 /// </summary> 3701 /// </summary>
@@ -3730,8 +3724,7 @@ namespace OpenSim.Region.Framework.Scenes
3730 /// <param name="message">message to display to the user. Reason for being logged off</param> 3724 /// <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) 3725 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message)
3732 { 3726 {
3733 ScenePresence loggingOffUser = null; 3727 ScenePresence loggingOffUser = GetScenePresence(AvatarID);
3734 loggingOffUser = GetScenePresence(AvatarID);
3735 if (loggingOffUser != null) 3728 if (loggingOffUser != null)
3736 { 3729 {
3737 UUID localRegionSecret = UUID.Zero; 3730 UUID localRegionSecret = UUID.Zero;
@@ -3767,10 +3760,8 @@ namespace OpenSim.Region.Framework.Scenes
3767 /// <param name="isFlying"></param> 3760 /// <param name="isFlying"></param>
3768 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) 3761 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying)
3769 { 3762 {
3770 ScenePresence presence; 3763 ScenePresence presence = GetScenePresence(agentID);
3771 m_sceneGraph.TryGetAvatar(agentID, out presence); 3764 if(presence != null)
3772
3773 if (presence != null)
3774 { 3765 {
3775 try 3766 try
3776 { 3767 {
@@ -3798,8 +3789,8 @@ namespace OpenSim.Region.Framework.Scenes
3798 /// <returns>true if we handled it.</returns> 3789 /// <returns>true if we handled it.</returns>
3799 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData) 3790 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData)
3800 { 3791 {
3801// m_log.DebugFormat( 3792 m_log.DebugFormat(
3802// "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName); 3793 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
3803 3794
3804 // We have to wait until the viewer contacts this region after receiving EAC. 3795 // We have to wait until the viewer contacts this region after receiving EAC.
3805 // That calls AddNewClient, which finally creates the ScenePresence 3796 // That calls AddNewClient, which finally creates the ScenePresence
@@ -3868,16 +3859,6 @@ namespace OpenSim.Region.Framework.Scenes
3868 return false; 3859 return false;
3869 } 3860 }
3870 3861
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> 3862 /// <summary>
3882 /// Tell a single agent to disconnect from the region. 3863 /// Tell a single agent to disconnect from the region.
3883 /// </summary> 3864 /// </summary>
@@ -3922,30 +3903,6 @@ namespace OpenSim.Region.Framework.Scenes
3922 } 3903 }
3923 3904
3924 /// <summary> 3905 /// <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. 3906 /// Tries to teleport agent to other region.
3950 /// </summary> 3907 /// </summary>
3951 /// <param name="remoteClient"></param> 3908 /// <param name="remoteClient"></param>
@@ -3978,9 +3935,7 @@ namespace OpenSim.Region.Framework.Scenes
3978 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position, 3935 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position,
3979 Vector3 lookAt, uint teleportFlags) 3936 Vector3 lookAt, uint teleportFlags)
3980 { 3937 {
3981 ScenePresence sp; 3938 ScenePresence sp = GetScenePresence(remoteClient.AgentId);
3982 m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp);
3983
3984 if (sp != null) 3939 if (sp != null)
3985 { 3940 {
3986 uint regionX = m_regInfo.RegionLocX; 3941 uint regionX = m_regInfo.RegionLocX;
@@ -4020,16 +3975,12 @@ namespace OpenSim.Region.Framework.Scenes
4020 } 3975 }
4021 3976
4022 if (m_teleportModule != null) 3977 if (m_teleportModule != null)
4023 { 3978 m_teleportModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
4024 m_teleportModule.RequestTeleportToLocation(sp, regionHandle,
4025 position, lookAt, teleportFlags);
4026 }
4027 else 3979 else
4028 { 3980 {
4029 m_sceneGridService.RequestTeleportToLocation(sp, regionHandle, 3981 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active");
4030 position, lookAt, teleportFlags); 3982 sp.ControllingClient.SendTeleportFailed("Unable to perform teleports on this simulator.");
4031 } 3983 }
4032
4033 } 3984 }
4034 } 3985 }
4035 3986
@@ -4055,7 +4006,12 @@ namespace OpenSim.Region.Framework.Scenes
4055 4006
4056 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying) 4007 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying)
4057 { 4008 {
4058 m_sceneGridService.CrossAgentToNewRegion(this, agent, isFlying); 4009 if (m_teleportModule != null)
4010 m_teleportModule.Cross(agent, isFlying);
4011 else
4012 {
4013 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule");
4014 }
4059 } 4015 }
4060 4016
4061 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence) 4017 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence)
@@ -4081,35 +4037,6 @@ namespace OpenSim.Region.Framework.Scenes
4081 objectCapacity = objects; 4037 objectCapacity = objects;
4082 } 4038 }
4083 4039
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 4040 #endregion
4114 4041
4115 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set) 4042 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set)
@@ -4187,17 +4114,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", 4114 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"); 4115 "Agent ID", "Session ID", "Circuit", "IP", "World");
4189 4116
4190 foreach (ScenePresence scenePresence in GetAvatars()) 4117 ForEachScenePresence(delegate(ScenePresence sp)
4191 { 4118 {
4192 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}", 4119 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}",
4193 scenePresence.Firstname, 4120 sp.Firstname,
4194 scenePresence.Lastname, 4121 sp.Lastname,
4195 scenePresence.UUID, 4122 sp.UUID,
4196 scenePresence.ControllingClient.AgentId, 4123 sp.ControllingClient.AgentId,
4197 "Unknown", 4124 "Unknown",
4198 "Unknown", 4125 "Unknown",
4199 RegionInfo.RegionName); 4126 RegionInfo.RegionName);
4200 } 4127 });
4201 4128
4202 break; 4129 break;
4203 } 4130 }
@@ -4363,56 +4290,45 @@ namespace OpenSim.Region.Framework.Scenes
4363 m_sceneGraph.RemovePhysicalPrim(num); 4290 m_sceneGraph.RemovePhysicalPrim(num);
4364 } 4291 }
4365 4292
4366 //The idea is to have a group of method that return a list of avatars meeting some requirement 4293 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 { 4294 {
4376 return m_sceneGraph.GetAvatars(); 4295 return m_sceneGraph.GetRootAgentCount();
4377 } 4296 }
4378 4297
4379 /// <summary> 4298 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 { 4299 {
4384 return m_sceneGraph.GetRootAgentCount(); 4300 return m_sceneGraph.GetChildAgentCount();
4385 } 4301 }
4386 4302
4387 /// <summary> 4303 /// <summary>
4388 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents. 4304 /// 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> 4305 /// </summary>
4391 /// <returns></returns> 4306 /// <param name="agentID"></param>
4392 public ScenePresence[] GetScenePresences() 4307 /// <returns>null if the presence was not found</returns>
4308 public ScenePresence GetScenePresence(UUID agentID)
4393 { 4309 {
4394 return m_sceneGraph.GetScenePresences(); 4310 return m_sceneGraph.GetScenePresence(agentID);
4395 } 4311 }
4396 4312
4397 /// <summary> 4313 /// <summary>
4398 /// Request a filtered list of ScenePresences in this region. 4314 /// Request the scene presence by name.
4399 /// This list is a new object, so it can be iterated over without locking.
4400 /// </summary> 4315 /// </summary>
4401 /// <param name="filter"></param> 4316 /// <param name="firstName"></param>
4402 /// <returns></returns> 4317 /// <param name="lastName"></param>
4403 public List<ScenePresence> GetScenePresences(FilterAvatarList filter) 4318 /// <returns>null if the presence was not found</returns>
4319 public ScenePresence GetScenePresence(string firstName, string lastName)
4404 { 4320 {
4405 return m_sceneGraph.GetScenePresences(filter); 4321 return m_sceneGraph.GetScenePresence(firstName, lastName);
4406 } 4322 }
4407 4323
4408 /// <summary> 4324 /// <summary>
4409 /// Request a scene presence by UUID 4325 /// Request the scene presence by localID.
4410 /// </summary> 4326 /// </summary>
4411 /// <param name="avatarID"></param> 4327 /// <param name="localID"></param>
4412 /// <returns></returns> 4328 /// <returns>null if the presence was not found</returns>
4413 public ScenePresence GetScenePresence(UUID avatarID) 4329 public ScenePresence GetScenePresence(uint localID)
4414 { 4330 {
4415 return m_sceneGraph.GetScenePresence(avatarID); 4331 return m_sceneGraph.GetScenePresence(localID);
4416 } 4332 }
4417 4333
4418 public override bool PresenceChildStatus(UUID avatarID) 4334 public override bool PresenceChildStatus(UUID avatarID)
@@ -4430,25 +4346,14 @@ namespace OpenSim.Region.Framework.Scenes
4430 } 4346 }
4431 4347
4432 /// <summary> 4348 /// <summary>
4433 /// 4349 /// Performs action on all scene presences.
4434 /// </summary> 4350 /// </summary>
4435 /// <param name="action"></param> 4351 /// <param name="action"></param>
4436 public void ForEachScenePresence(Action<ScenePresence> action) 4352 public void ForEachScenePresence(Action<ScenePresence> action)
4437 { 4353 {
4438 // We don't want to try to send messages if there are no avatars.
4439 if (m_sceneGraph != null) 4354 if (m_sceneGraph != null)
4440 { 4355 {
4441 try 4356 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 } 4357 }
4453 } 4358 }
4454 4359
@@ -4512,9 +4417,9 @@ namespace OpenSim.Region.Framework.Scenes
4512 return m_sceneGraph.GetGroupByPrim(localID); 4417 return m_sceneGraph.GetGroupByPrim(localID);
4513 } 4418 }
4514 4419
4515 public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 4420 public override bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
4516 { 4421 {
4517 return m_sceneGraph.TryGetAvatar(avatarId, out avatar); 4422 return m_sceneGraph.TryGetScenePresence(avatarId, out avatar);
4518 } 4423 }
4519 4424
4520 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 4425 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
@@ -4524,20 +4429,7 @@ namespace OpenSim.Region.Framework.Scenes
4524 4429
4525 public void ForEachClient(Action<IClientAPI> action) 4430 public void ForEachClient(Action<IClientAPI> action)
4526 { 4431 {
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); 4432 m_clientManager.ForEachSync(action);
4536
4537 //if (doAsynchronous)
4538 // m_clientManager.ForEach(action);
4539 //else
4540 // m_clientManager.ForEachSync(action);
4541 } 4433 }
4542 4434
4543 public bool TryGetClient(UUID avatarID, out IClientAPI client) 4435 public bool TryGetClient(UUID avatarID, out IClientAPI client)
@@ -4709,7 +4601,8 @@ namespace OpenSim.Region.Framework.Scenes
4709 group.GetPartName(localID), 4601 group.GetPartName(localID),
4710 group.GetPartDescription(localID), 4602 group.GetPartDescription(localID),
4711 (sbyte)AssetType.Object, 4603 (sbyte)AssetType.Object,
4712 Utils.StringToBytes(sceneObjectXml)); 4604 Utils.StringToBytes(sceneObjectXml),
4605 group.OwnerID);
4713 AssetService.Store(asset); 4606 AssetService.Store(asset);
4714 4607
4715 InventoryItemBase item = new InventoryItemBase(); 4608 InventoryItemBase item = new InventoryItemBase();
@@ -5033,5 +4926,185 @@ namespace OpenSim.Region.Framework.Scenes
5033 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4926 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000)
5034 StartTimer(); 4927 StartTimer();
5035 } 4928 }
4929
4930 public override ISceneObject DeserializeObject(string representation)
4931 {
4932 return SceneObjectSerializer.FromXml2Format(representation);
4933 }
4934
4935 public override bool AllowScriptCrossings
4936 {
4937 get { return m_allowScriptCrossings; }
4938 }
4939
4940 public Vector3? GetNearestAllowedPosition(ScenePresence avatar)
4941 {
4942 //simulate to make sure we have pretty up to date positions
4943 PhysicsScene.Simulate(0);
4944
4945 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
4946
4947 if (nearestParcel != null)
4948 {
4949 Vector3 dir = Vector3.Normalize(Vector3.Multiply(avatar.Velocity, -1));
4950 //Try to get a location that feels like where they came from
4951 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4952 if (nearestPoint != null)
4953 {
4954 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4955 return nearestPoint.Value;
4956 }
4957
4958 //Sometimes velocity might be zero (local teleport), so try finding point along path from avatar to center of nearest parcel
4959 Vector3 directionToParcelCenter = Vector3.Subtract(GetParcelCenterAtGround(nearestParcel), avatar.AbsolutePosition);
4960 dir = Vector3.Normalize(directionToParcelCenter);
4961 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4962 if (nearestPoint != null)
4963 {
4964 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4965 return nearestPoint.Value;
4966 }
4967
4968 //Ultimate backup if we have no idea where they are
4969 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
4970 return avatar.lastKnownAllowedPosition;
4971
4972 }
4973
4974 //Go to the edge, this happens in teleporting to a region with no available parcels
4975 Vector3 nearestRegionEdgePoint = GetNearestRegionEdgePosition(avatar);
4976 //Debug.WriteLine("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString());
4977 return nearestRegionEdgePoint;
4978 return null;
4979 }
4980
4981 private Vector3 GetParcelCenterAtGround(ILandObject parcel)
4982 {
4983 Vector2 center = GetParcelCenter(parcel);
4984 return GetPositionAtGround(center.X, center.Y);
4985 }
4986
4987 private Vector3? GetNearestPointInParcelAlongDirectionFromPoint(Vector3 pos, Vector3 direction, ILandObject parcel)
4988 {
4989 Vector3 unitDirection = Vector3.Normalize(direction);
4990 //Making distance to search go through some sane limit of distance
4991 for (float distance = 0; distance < Constants.RegionSize * 2; distance += .5f)
4992 {
4993 Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance));
4994 if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y))
4995 {
4996 return testPos;
4997 }
4998 }
4999 return null;
5000 }
5001
5002 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5003 {
5004 List<ILandObject> all = AllParcels();
5005 float minParcelDistance = float.MaxValue;
5006 ILandObject nearestParcel = null;
5007
5008 foreach (var parcel in all)
5009 {
5010 if (!parcel.IsEitherBannedOrRestricted(avatarId))
5011 {
5012 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5013 if (parcelDistance < minParcelDistance)
5014 {
5015 minParcelDistance = parcelDistance;
5016 nearestParcel = parcel;
5017 }
5018 }
5019 }
5020
5021 return nearestParcel;
5022 }
5023
5024 private List<ILandObject> AllParcels()
5025 {
5026 return LandChannel.AllParcels();
5027 }
5028
5029 private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y)
5030 {
5031 return Vector2.Distance(new Vector2(x, y), GetParcelCenter(parcel));
5032 }
5033
5034 //calculate the average center point of a parcel
5035 private Vector2 GetParcelCenter(ILandObject parcel)
5036 {
5037 int count = 0;
5038 int avgx = 0;
5039 int avgy = 0;
5040 for (int x = 0; x < Constants.RegionSize; x++)
5041 {
5042 for (int y = 0; y < Constants.RegionSize; y++)
5043 {
5044 //Just keep a running average as we check if all the points are inside or not
5045 if (parcel.ContainsPoint(x, y))
5046 {
5047 if (count == 0)
5048 {
5049 avgx = x;
5050 avgy = y;
5051 }
5052 else
5053 {
5054 avgx = (avgx * count + x) / (count + 1);
5055 avgy = (avgy * count + y) / (count + 1);
5056 }
5057 count += 1;
5058 }
5059 }
5060 }
5061 return new Vector2(avgx, avgy);
5062 }
5063
5064 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
5065 {
5066 float xdistance = avatar.AbsolutePosition.X < Constants.RegionSize / 2 ? avatar.AbsolutePosition.X : Constants.RegionSize - avatar.AbsolutePosition.X;
5067 float ydistance = avatar.AbsolutePosition.Y < Constants.RegionSize / 2 ? avatar.AbsolutePosition.Y : Constants.RegionSize - avatar.AbsolutePosition.Y;
5068
5069 //find out what vertical edge to go to
5070 if (xdistance < ydistance)
5071 {
5072 if (avatar.AbsolutePosition.X < Constants.RegionSize / 2)
5073 {
5074 return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
5075 }
5076 else
5077 {
5078 return GetPositionAtAvatarHeightOrGroundHeight(avatar, Constants.RegionSize, avatar.AbsolutePosition.Y);
5079 }
5080 }
5081 //find out what horizontal edge to go to
5082 else
5083 {
5084 if (avatar.AbsolutePosition.Y < Constants.RegionSize / 2)
5085 {
5086 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
5087 }
5088 else
5089 {
5090 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, Constants.RegionSize);
5091 }
5092 }
5093 }
5094
5095 private Vector3 GetPositionAtAvatarHeightOrGroundHeight(ScenePresence avatar, float x, float y)
5096 {
5097 Vector3 ground = GetPositionAtGround(x, y);
5098 if (avatar.AbsolutePosition.Z > ground.Z)
5099 {
5100 ground.Z = avatar.AbsolutePosition.Z;
5101 }
5102 return ground;
5103 }
5104
5105 private Vector3 GetPositionAtGround(float x, float y)
5106 {
5107 return new Vector3(x, y, GetGroundHeight(x, y));
5108 }
5036 } 5109 }
5037} 5110}