aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Application/OpenSim.cs198
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs25
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs53
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs100
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs13
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs3
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs12
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs4
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs4
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs93
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs14
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs16
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs4
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs4
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs9
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs5
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs24
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs197
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs175
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs3
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs9
-rw-r--r--OpenSim/Region/ClientStack/RegionApplicationBase.cs17
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs15
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs10
-rw-r--r--OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs308
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs305
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs35
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs4
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs1
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs17
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Commands/UserCommandsModule.cs189
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs33
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs59
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs92
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs124
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs7
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs14
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs10
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs6
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs8
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs1100
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs269
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs126
-rw-r--r--OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs5
-rw-r--r--OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs80
-rw-r--r--OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs7
-rw-r--r--OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs116
-rw-r--r--OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs224
-rw-r--r--OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs24
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs26
-rw-r--r--OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs9
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs3
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsIn/Land/LandServiceInConnectorModule.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsIn/Neighbour/NeighbourServiceInConnectorModule.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs28
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs15
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs13
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs219
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs7
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs26
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs121
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs20
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs67
-rw-r--r--OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs12
-rw-r--r--OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs17
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs35
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs9
-rw-r--r--OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs1
-rw-r--r--OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs328
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs53
-rw-r--r--OpenSim/Region/CoreModules/World/Region/RegionCommandsModule.cs155
-rw-r--r--OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Sound/SoundModule.cs7
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs103
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs21
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs26
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs1
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs380
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs (renamed from OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs)88
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs24
-rw-r--r--OpenSim/Region/DataSnapshot/DataRequestHandler.cs4
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs25
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityInventory.cs54
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs23
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEnvironmentModule.cs36
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEstateModule.cs3
-rw-r--r--OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs48
-rw-r--r--OpenSim/Region/Framework/Interfaces/INPCModule.cs36
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionCombinerModule.cs59
-rw-r--r--OpenSim/Region/Framework/Interfaces/IScenePresence.cs6
-rw-r--r--OpenSim/Region/Framework/Interfaces/IScriptModule.cs18
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs20
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs20
-rw-r--r--OpenSim/Region/Framework/Interfaces/IUrlModule.cs1
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs19
-rw-r--r--OpenSim/Region/Framework/Scenes/AsyncInventorySender.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs49
-rw-r--r--OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs9
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs78
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Permissions.cs17
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs606
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs37
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs18
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs117
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs44
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs302
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs495
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs20
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs45
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs72
-rw-r--r--OpenSim/Region/Framework/Scenes/SimStatsReporter.cs300
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs19
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs10
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs154
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs130
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs23
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs478
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs5
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs195
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs17
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs53
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs54
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs4
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs500
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs430
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs499
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs25
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs58
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs6
-rw-r--r--OpenSim/Region/OptionalModules/World/WorldView/WorldViewModule.cs15
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs42
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs314
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs41
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs14
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs10
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs472
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdeScene.cs428
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs444
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionConnections.cs37
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs41
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs846
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs299
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs35
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs39
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs31
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs139
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs355
-rw-r--r--OpenSim/Region/UserStatistics/WebStatsModule.cs170
195 files changed, 10528 insertions, 4768 deletions
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index fb1e831..1458ff9 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics;
31using System.IO; 32using System.IO;
32using System.Reflection; 33using System.Reflection;
33using System.Text; 34using System.Text;
@@ -69,6 +70,7 @@ namespace OpenSim
69 private Regex m_consolePromptRegex = new Regex(@"([^\\])\\(\w)", RegexOptions.Compiled); 70 private Regex m_consolePromptRegex = new Regex(@"([^\\])\\(\w)", RegexOptions.Compiled);
70 71
71 private string m_timedScript = "disabled"; 72 private string m_timedScript = "disabled";
73 private int m_timeInterval = 1200;
72 private Timer m_scriptTimer; 74 private Timer m_scriptTimer;
73 75
74 public OpenSim(IConfigSource configSource) : base(configSource) 76 public OpenSim(IConfigSource configSource) : base(configSource)
@@ -98,6 +100,10 @@ namespace OpenSim
98 m_consolePort = (uint)networkConfig.GetInt("console_port", 0); 100 m_consolePort = (uint)networkConfig.GetInt("console_port", 0);
99 101
100 m_timedScript = startupConfig.GetString("timer_Script", "disabled"); 102 m_timedScript = startupConfig.GetString("timer_Script", "disabled");
103 if (m_timedScript != "disabled")
104 {
105 m_timeInterval = startupConfig.GetInt("timer_Interval", 1200);
106 }
101 107
102 if (m_logFileAppender != null) 108 if (m_logFileAppender != null)
103 { 109 {
@@ -138,7 +144,7 @@ namespace OpenSim
138 m_log.Info("===================================================================="); 144 m_log.Info("====================================================================");
139 m_log.Info("========================= STARTING OPENSIM ========================="); 145 m_log.Info("========================= STARTING OPENSIM =========================");
140 m_log.Info("===================================================================="); 146 m_log.Info("====================================================================");
141 147
142 //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString()); 148 //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
143 // http://msdn.microsoft.com/en-us/library/bb384202.aspx 149 // http://msdn.microsoft.com/en-us/library/bb384202.aspx
144 //GCSettings.LatencyMode = GCLatencyMode.Batch; 150 //GCSettings.LatencyMode = GCLatencyMode.Batch;
@@ -215,7 +221,7 @@ namespace OpenSim
215 { 221 {
216 m_scriptTimer = new Timer(); 222 m_scriptTimer = new Timer();
217 m_scriptTimer.Enabled = true; 223 m_scriptTimer.Enabled = true;
218 m_scriptTimer.Interval = 1200*1000; 224 m_scriptTimer.Interval = m_timeInterval*1000;
219 m_scriptTimer.Elapsed += RunAutoTimerScript; 225 m_scriptTimer.Elapsed += RunAutoTimerScript;
220 } 226 }
221 } 227 }
@@ -225,12 +231,14 @@ namespace OpenSim
225 /// </summary> 231 /// </summary>
226 private void RegisterConsoleCommands() 232 private void RegisterConsoleCommands()
227 { 233 {
228 m_console.Commands.AddCommand("Regions", false, "force update", 234 MainServer.RegisterHttpConsoleCommands(m_console);
235
236 m_console.Commands.AddCommand("Objects", false, "force update",
229 "force update", 237 "force update",
230 "Force the update of all objects on clients", 238 "Force the update of all objects on clients",
231 HandleForceUpdate); 239 HandleForceUpdate);
232 240
233 m_console.Commands.AddCommand("Comms", false, "debug packet", 241 m_console.Commands.AddCommand("Debug", false, "debug packet",
234 "debug packet <level> [<avatar-first-name> <avatar-last-name>]", 242 "debug packet <level> [<avatar-first-name> <avatar-last-name>]",
235 "Turn on packet debugging", 243 "Turn on packet debugging",
236 "If level > 255 then all incoming and outgoing packets are logged.\n" 244 "If level > 255 then all incoming and outgoing packets are logged.\n"
@@ -242,17 +250,9 @@ namespace OpenSim
242 + "If an avatar name is given then only packets from that avatar are logged", 250 + "If an avatar name is given then only packets from that avatar are logged",
243 Debug); 251 Debug);
244 252
245 m_console.Commands.AddCommand("Comms", false, "debug http", 253 m_console.Commands.AddCommand("Debug", false, "debug teleport", "debug teleport", "Toggle teleport route debugging", Debug);
246 "debug http <level>",
247 "Turn on inbound http request debugging for everything except the event queue (see debug eq).",
248 "If level >= 2 then the handler used to service the request is logged.\n"
249 + "If level >= 1 then incoming HTTP requests are logged.\n"
250 + "If level <= 0 then no extra http logging is done.\n",
251 Debug);
252
253 m_console.Commands.AddCommand("Comms", false, "debug teleport", "debug teleport", "Toggle teleport route debugging", Debug);
254 254
255 m_console.Commands.AddCommand("Regions", false, "debug scene", 255 m_console.Commands.AddCommand("Debug", false, "debug scene",
256 "debug scene <scripting> <collisions> <physics>", 256 "debug scene <scripting> <collisions> <physics>",
257 "Turn on scene debugging", Debug); 257 "Turn on scene debugging", Debug);
258 258
@@ -306,7 +306,7 @@ namespace OpenSim
306 + " If this is not given then the oar is saved to region.oar in the current directory.", 306 + " If this is not given then the oar is saved to region.oar in the current directory.",
307 SaveOar); 307 SaveOar);
308 308
309 m_console.Commands.AddCommand("Regions", false, "edit scale", 309 m_console.Commands.AddCommand("Objects", false, "edit scale",
310 "edit scale <name> <x> <y> <z>", 310 "edit scale <name> <x> <y> <z>",
311 "Change the scale of a named prim", HandleEditScale); 311 "Change the scale of a named prim", HandleEditScale);
312 312
@@ -349,7 +349,7 @@ namespace OpenSim
349 "show ratings", 349 "show ratings",
350 "Show rating data", HandleShow); 350 "Show rating data", HandleShow);
351 351
352 m_console.Commands.AddCommand("Regions", false, "backup", 352 m_console.Commands.AddCommand("Objects", false, "backup",
353 "backup", 353 "backup",
354 "Persist currently unsaved object changes immediately instead of waiting for the normal persistence call.", RunCommand); 354 "Persist currently unsaved object changes immediately instead of waiting for the normal persistence call.", RunCommand);
355 355
@@ -409,10 +409,6 @@ namespace OpenSim
409 m_console.Commands.AddCommand("General", false, "modules unload", 409 m_console.Commands.AddCommand("General", false, "modules unload",
410 "modules unload <name>", 410 "modules unload <name>",
411 "Unload a module", HandleModules); 411 "Unload a module", HandleModules);
412
413 m_console.Commands.AddCommand("Regions", false, "kill uuid",
414 "kill uuid <UUID>",
415 "Kill an object by UUID", KillUUID);
416 } 412 }
417 413
418 public override void ShutdownSpecific() 414 public override void ShutdownSpecific()
@@ -437,12 +433,16 @@ namespace OpenSim
437 } 433 }
438 } 434 }
439 435
440 private void WatchdogTimeoutHandler(System.Threading.Thread thread, int lastTick) 436 private void WatchdogTimeoutHandler(Watchdog.ThreadWatchdogInfo twi)
441 { 437 {
442 int now = Environment.TickCount & Int32.MaxValue; 438 int now = Environment.TickCount & Int32.MaxValue;
443 439
444 m_log.ErrorFormat("[WATCHDOG]: Timeout detected for thread \"{0}\". ThreadState={1}. Last tick was {2}ms ago", 440 m_log.ErrorFormat(
445 thread.Name, thread.ThreadState, now - lastTick); 441 "[WATCHDOG]: Timeout detected for thread \"{0}\". ThreadState={1}. Last tick was {2}ms ago. {3}",
442 twi.Thread.Name,
443 twi.Thread.ThreadState,
444 now - twi.LastTick,
445 twi.AlarmMethod != null ? string.Format("Data: {0}", twi.AlarmMethod()) : "");
446 } 446 }
447 447
448 #region Console Commands 448 #region Console Commands
@@ -481,10 +481,10 @@ namespace OpenSim
481 else 481 else
482 presence.ControllingClient.Kick("\nYou have been logged out by an administrator.\n"); 482 presence.ControllingClient.Kick("\nYou have been logged out by an administrator.\n");
483 483
484 // ...and close on our side
485 presence.Scene.IncomingCloseAgent(presence.UUID); 484 presence.Scene.IncomingCloseAgent(presence.UUID);
486 } 485 }
487 } 486 }
487
488 MainConsole.Instance.Output(""); 488 MainConsole.Instance.Output("");
489 } 489 }
490 490
@@ -618,10 +618,11 @@ namespace OpenSim
618 return; 618 return;
619 } 619 }
620 620
621 PopulateRegionEstateInfo(regInfo); 621 bool changed = PopulateRegionEstateInfo(regInfo);
622 IScene scene; 622 IScene scene;
623 CreateRegion(regInfo, true, out scene); 623 CreateRegion(regInfo, true, out scene);
624 regInfo.EstateSettings.Save(); 624 if (changed)
625 regInfo.EstateSettings.Save();
625 } 626 }
626 627
627 /// <summary> 628 /// <summary>
@@ -903,21 +904,6 @@ namespace OpenSim
903 904
904 break; 905 break;
905 906
906 case "http":
907 if (args.Length == 3)
908 {
909 int newDebug;
910 if (int.TryParse(args[2], out newDebug))
911 {
912 MainServer.Instance.DebugLevel = newDebug;
913 MainConsole.Instance.OutputFormat("Debug http level set to {0}", newDebug);
914 break;
915 }
916 }
917
918 MainConsole.Instance.Output("Usage: debug http 0..2");
919 break;
920
921 case "scene": 907 case "scene":
922 if (args.Length == 4) 908 if (args.Length == 4)
923 { 909 {
@@ -969,8 +955,7 @@ namespace OpenSim
969 if (showParams.Length > 1 && showParams[1] == "full") 955 if (showParams.Length > 1 && showParams[1] == "full")
970 { 956 {
971 agents = m_sceneManager.GetCurrentScenePresences(); 957 agents = m_sceneManager.GetCurrentScenePresences();
972 } 958 } else
973 else
974 { 959 {
975 agents = m_sceneManager.GetCurrentSceneAvatars(); 960 agents = m_sceneManager.GetCurrentSceneAvatars();
976 } 961 }
@@ -979,7 +964,8 @@ namespace OpenSim
979 964
980 MainConsole.Instance.Output( 965 MainConsole.Instance.Output(
981 String.Format("{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}", "Firstname", "Lastname", 966 String.Format("{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}", "Firstname", "Lastname",
982 "Agent ID", "Root/Child", "Region", "Position")); 967 "Agent ID", "Root/Child", "Region", "Position")
968 );
983 969
984 foreach (ScenePresence presence in agents) 970 foreach (ScenePresence presence in agents)
985 { 971 {
@@ -989,8 +975,7 @@ namespace OpenSim
989 if (regionInfo == null) 975 if (regionInfo == null)
990 { 976 {
991 regionName = "Unresolvable"; 977 regionName = "Unresolvable";
992 } 978 } else
993 else
994 { 979 {
995 regionName = regionInfo.RegionName; 980 regionName = regionInfo.RegionName;
996 } 981 }
@@ -1003,7 +988,8 @@ namespace OpenSim
1003 presence.UUID, 988 presence.UUID,
1004 presence.IsChildAgent ? "Child" : "Root", 989 presence.IsChildAgent ? "Child" : "Root",
1005 regionName, 990 regionName,
1006 presence.AbsolutePosition.ToString())); 991 presence.AbsolutePosition.ToString())
992 );
1007 } 993 }
1008 994
1009 MainConsole.Instance.Output(String.Empty); 995 MainConsole.Instance.Output(String.Empty);
@@ -1012,16 +998,20 @@ namespace OpenSim
1012 case "connections": 998 case "connections":
1013 System.Text.StringBuilder connections = new System.Text.StringBuilder("Connections:\n"); 999 System.Text.StringBuilder connections = new System.Text.StringBuilder("Connections:\n");
1014 m_sceneManager.ForEachScene( 1000 m_sceneManager.ForEachScene(
1015 delegate(Scene scene) 1001 delegate(Scene scene) {
1016 { 1002 scene.ForEachClient(
1017 scene.ForEachClient( 1003 delegate(IClientAPI client) {
1018 delegate(IClientAPI client) 1004 connections.AppendFormat(
1019 { 1005 "{0}: {1} ({2}) from {3} on circuit {4}\n",
1020 connections.AppendFormat("{0}: {1} ({2}) from {3} on circuit {4}\n", 1006 scene.RegionInfo.RegionName,
1021 scene.RegionInfo.RegionName, client.Name, client.AgentId, client.RemoteEndPoint, client.CircuitCode); 1007 client.Name,
1022 } 1008 client.AgentId,
1009 client.RemoteEndPoint,
1010 client.CircuitCode
1023 ); 1011 );
1024 } 1012 }
1013 );
1014 }
1025 ); 1015 );
1026 1016
1027 MainConsole.Instance.Output(connections.ToString()); 1017 MainConsole.Instance.Output(connections.ToString());
@@ -1030,13 +1020,17 @@ namespace OpenSim
1030 case "circuits": 1020 case "circuits":
1031 System.Text.StringBuilder acd = new System.Text.StringBuilder("Agent Circuits:\n"); 1021 System.Text.StringBuilder acd = new System.Text.StringBuilder("Agent Circuits:\n");
1032 m_sceneManager.ForEachScene( 1022 m_sceneManager.ForEachScene(
1033 delegate(Scene scene) 1023 delegate(Scene scene) {
1034 { 1024 //this.HttpServer.
1035 //this.HttpServer. 1025 acd.AppendFormat("{0}:\n", scene.RegionInfo.RegionName);
1036 acd.AppendFormat("{0}:\n", scene.RegionInfo.RegionName); 1026 foreach (AgentCircuitData aCircuit in scene.AuthenticateHandler.GetAgentCircuits().Values)
1037 foreach (AgentCircuitData aCircuit in scene.AuthenticateHandler.GetAgentCircuits().Values) 1027 acd.AppendFormat(
1038 acd.AppendFormat("\t{0} {1} ({2})\n", aCircuit.firstname, aCircuit.lastname, (aCircuit.child ? "Child" : "Root")); 1028 "\t{0} {1} ({2})\n",
1039 } 1029 aCircuit.firstname,
1030 aCircuit.lastname,
1031 (aCircuit.child ? "Child" : "Root")
1032 );
1033 }
1040 ); 1034 );
1041 1035
1042 MainConsole.Instance.Output(acd.ToString()); 1036 MainConsole.Instance.Output(acd.ToString());
@@ -1077,17 +1071,29 @@ namespace OpenSim
1077 } 1071 }
1078 1072
1079 m_sceneManager.ForEachScene( 1073 m_sceneManager.ForEachScene(
1080 delegate(Scene scene) 1074 delegate(Scene scene) {
1075 m_log.Error("The currently loaded modules in " + scene.RegionInfo.RegionName + " are:");
1076 foreach (IRegionModule module in scene.Modules.Values)
1081 { 1077 {
1082 m_log.Error("The currently loaded modules in " + scene.RegionInfo.RegionName + " are:"); 1078 if (!module.IsSharedModule)
1083 foreach (IRegionModule module in scene.Modules.Values)
1084 { 1079 {
1085 if (!module.IsSharedModule) 1080 m_log.Error("Region Module: " + module.Name);
1086 {
1087 m_log.Error("Region Module: " + module.Name);
1088 }
1089 } 1081 }
1090 }); 1082 }
1083 }
1084 );
1085
1086 m_sceneManager.ForEachScene(
1087 delegate(Scene scene) {
1088 MainConsole.Instance.Output("Loaded new region modules in" + scene.RegionInfo.RegionName + " are:");
1089 foreach (IRegionModuleBase module in scene.RegionModules.Values)
1090 {
1091 Type type = module.GetType().GetInterface("ISharedRegionModule");
1092 string module_type = type != null ? "Shared" : "Non-Shared";
1093 MainConsole.Instance.OutputFormat("New Region Module ({0}): {1}", module_type, module.Name);
1094 }
1095 }
1096 );
1091 1097
1092 MainConsole.Instance.Output(""); 1098 MainConsole.Instance.Output("");
1093 break; 1099 break;
@@ -1299,58 +1305,6 @@ namespace OpenSim
1299 return result; 1305 return result;
1300 } 1306 }
1301 1307
1302 /// <summary>
1303 /// Kill an object given its UUID.
1304 /// </summary>
1305 /// <param name="cmdparams"></param>
1306 protected void KillUUID(string module, string[] cmdparams)
1307 {
1308 if (cmdparams.Length > 2)
1309 {
1310 UUID id = UUID.Zero;
1311 SceneObjectGroup grp = null;
1312 Scene sc = null;
1313
1314 if (!UUID.TryParse(cmdparams[2], out id))
1315 {
1316 MainConsole.Instance.Output("[KillUUID]: Error bad UUID format!");
1317 return;
1318 }
1319
1320 m_sceneManager.ForEachScene(
1321 delegate(Scene scene)
1322 {
1323 SceneObjectPart part = scene.GetSceneObjectPart(id);
1324 if (part == null)
1325 return;
1326
1327 grp = part.ParentGroup;
1328 sc = scene;
1329 });
1330
1331 if (grp == null)
1332 {
1333 MainConsole.Instance.Output(String.Format("[KillUUID]: Given UUID {0} not found!", id));
1334 }
1335 else
1336 {
1337 MainConsole.Instance.Output(String.Format("[KillUUID]: Found UUID {0} in scene {1}", id, sc.RegionInfo.RegionName));
1338 try
1339 {
1340 sc.DeleteSceneObject(grp, false);
1341 }
1342 catch (Exception e)
1343 {
1344 m_log.ErrorFormat("[KillUUID]: Error while removing objects from scene: " + e);
1345 }
1346 }
1347 }
1348 else
1349 {
1350 MainConsole.Instance.Output("[KillUUID]: Usage: kill uuid <UUID>");
1351 }
1352 }
1353
1354 #endregion 1308 #endregion
1355 } 1309 }
1356} 1310}
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index ddc7f10..76ac246 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -232,7 +232,7 @@ namespace OpenSim
232 232
233 base.StartupSpecific(); 233 base.StartupSpecific();
234 234
235 m_stats = StatsManager.StartCollectingSimExtraStats(); 235 m_stats = StatsManager.SimExtraStats;
236 236
237 // Create a ModuleLoader instance 237 // Create a ModuleLoader instance
238 m_moduleLoader = new ModuleLoader(m_config.Source); 238 m_moduleLoader = new ModuleLoader(m_config.Source);
@@ -437,7 +437,7 @@ namespace OpenSim
437 scene.LoadPrimsFromStorage(regionInfo.originRegionID); 437 scene.LoadPrimsFromStorage(regionInfo.originRegionID);
438 438
439 // TODO : Try setting resource for region xstats here on scene 439 // TODO : Try setting resource for region xstats here on scene
440 MainServer.Instance.AddStreamHandler(new Region.Framework.Scenes.RegionStatsHandler(regionInfo)); 440 MainServer.Instance.AddStreamHandler(new RegionStatsHandler(regionInfo));
441 441
442 scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID); 442 scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
443 scene.EventManager.TriggerParcelPrimCountUpdate(); 443 scene.EventManager.TriggerParcelPrimCountUpdate();
@@ -856,6 +856,9 @@ namespace OpenSim
856 return Util.UTF8.GetBytes("OK"); 856 return Util.UTF8.GetBytes("OK");
857 } 857 }
858 858
859 public string Name { get { return "SimStatus"; } }
860 public string Description { get { return "Simulator Status"; } }
861
859 public string ContentType 862 public string ContentType
860 { 863 {
861 get { return "text/plain"; } 864 get { return "text/plain"; }
@@ -880,6 +883,9 @@ namespace OpenSim
880 { 883 {
881 OpenSimBase m_opensim; 884 OpenSimBase m_opensim;
882 string osXStatsURI = String.Empty; 885 string osXStatsURI = String.Empty;
886
887 public string Name { get { return "XSimStatus"; } }
888 public string Description { get { return "Simulator XStatus"; } }
883 889
884 public XSimStatusHandler(OpenSimBase sim) 890 public XSimStatusHandler(OpenSimBase sim)
885 { 891 {
@@ -920,6 +926,9 @@ namespace OpenSim
920 { 926 {
921 OpenSimBase m_opensim; 927 OpenSimBase m_opensim;
922 string osUXStatsURI = String.Empty; 928 string osUXStatsURI = String.Empty;
929
930 public string Name { get { return "UXSimStatus"; } }
931 public string Description { get { return "Simulator UXStatus"; } }
923 932
924 public UXSimStatusHandler(OpenSimBase sim) 933 public UXSimStatusHandler(OpenSimBase sim)
925 { 934 {
@@ -1051,13 +1060,13 @@ namespace OpenSim
1051 /// Load the estate information for the provided RegionInfo object. 1060 /// Load the estate information for the provided RegionInfo object.
1052 /// </summary> 1061 /// </summary>
1053 /// <param name="regInfo"></param> 1062 /// <param name="regInfo"></param>
1054 public void PopulateRegionEstateInfo(RegionInfo regInfo) 1063 public bool PopulateRegionEstateInfo(RegionInfo regInfo)
1055 { 1064 {
1056 if (EstateDataService != null) 1065 if (EstateDataService != null)
1057 regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false); 1066 regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false);
1058 1067
1059 if (regInfo.EstateSettings.EstateID != 0) 1068 if (regInfo.EstateSettings.EstateID != 0)
1060 return; 1069 return false; // estate info in the database did not change
1061 1070
1062 m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName); 1071 m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName);
1063 1072
@@ -1092,7 +1101,7 @@ namespace OpenSim
1092 } 1101 }
1093 1102
1094 if (defaultEstateJoined) 1103 if (defaultEstateJoined)
1095 return; 1104 return true; // need to update the database
1096 else 1105 else
1097 m_log.ErrorFormat( 1106 m_log.ErrorFormat(
1098 "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName); 1107 "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName);
@@ -1154,8 +1163,10 @@ namespace OpenSim
1154 MainConsole.Instance.Output("Joining the estate failed. Please try again."); 1163 MainConsole.Instance.Output("Joining the estate failed. Please try again.");
1155 } 1164 }
1156 } 1165 }
1157 } 1166 }
1158 } 1167
1168 return true; // need to update the database
1169 }
1159 } 1170 }
1160 1171
1161 public class OpenSimConfigSource 1172 public class OpenSimConfigSource
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
index ef6dedb..d397893 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
@@ -158,7 +158,9 @@ namespace OpenSim.Region.ClientStack.Linden
158 try 158 try
159 { 159 {
160 // the root of all evil 160 // the root of all evil
161 m_HostCapsObj.RegisterHandler("SEED", new RestStreamHandler("POST", capsBase + m_requestPath, SeedCapRequest)); 161 m_HostCapsObj.RegisterHandler(
162 "SEED", new RestStreamHandler("POST", capsBase + m_requestPath, SeedCapRequest, "SEED", null));
163
162 m_log.DebugFormat( 164 m_log.DebugFormat(
163 "[CAPS]: Registered seed capability {0} for {1}", capsBase + m_requestPath, m_HostCapsObj.AgentID); 165 "[CAPS]: Registered seed capability {0} for {1}", capsBase + m_requestPath, m_HostCapsObj.AgentID);
164 166
@@ -166,7 +168,10 @@ namespace OpenSim.Region.ClientStack.Linden
166 // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST", 168 // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST",
167 // capsBase + m_mapLayerPath, 169 // capsBase + m_mapLayerPath,
168 // GetMapLayer); 170 // GetMapLayer);
169 IRequestHandler req = new RestStreamHandler("POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory); 171 IRequestHandler req
172 = new RestStreamHandler(
173 "POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory, "UpdateScript", null);
174
170 m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req); 175 m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req);
171 m_HostCapsObj.RegisterHandler("UpdateScriptTask", req); 176 m_HostCapsObj.RegisterHandler("UpdateScriptTask", req);
172 } 177 }
@@ -181,14 +186,22 @@ namespace OpenSim.Region.ClientStack.Linden
181 try 186 try
182 { 187 {
183 // I don't think this one works... 188 // I don't think this one works...
184 m_HostCapsObj.RegisterHandler("NewFileAgentInventory", new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", 189 m_HostCapsObj.RegisterHandler(
185 capsBase + m_newInventory, 190 "NewFileAgentInventory",
186 NewAgentInventoryRequest)); 191 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>(
187 IRequestHandler req = new RestStreamHandler("POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory); 192 "POST",
193 capsBase + m_newInventory,
194 NewAgentInventoryRequest,
195 "NewFileAgentInventory",
196 null));
197
198 IRequestHandler req
199 = new RestStreamHandler(
200 "POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory, "Update*", null);
201
188 m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req); 202 m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req);
189 m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req); 203 m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req);
190 m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); 204 m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req);
191 m_HostCapsObj.RegisterHandler("CopyInventoryFromNotecard", new RestStreamHandler("POST", capsBase + m_copyFromNotecardPath, CopyInventoryFromNotecard));
192 IRequestHandler getObjectPhysicsDataHandler = new RestStreamHandler("POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData); 205 IRequestHandler getObjectPhysicsDataHandler = new RestStreamHandler("POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData);
193 m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); 206 m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler);
194 IRequestHandler getObjectCostHandler = new RestStreamHandler("POST", capsBase + m_getObjectCostPath, GetObjectCost); 207 IRequestHandler getObjectCostHandler = new RestStreamHandler("POST", capsBase + m_getObjectCostPath, GetObjectCost);
@@ -197,6 +210,12 @@ namespace OpenSim.Region.ClientStack.Linden
197 m_HostCapsObj.RegisterHandler("ResourceCostSelected", ResourceCostSelectedHandler); 210 m_HostCapsObj.RegisterHandler("ResourceCostSelected", ResourceCostSelectedHandler);
198 211
199 212
213
214 m_HostCapsObj.RegisterHandler(
215 "CopyInventoryFromNotecard",
216 new RestStreamHandler(
217 "POST", capsBase + m_copyFromNotecardPath, CopyInventoryFromNotecard, "CopyInventoryFromNotecard", null));
218
200 // As of RC 1.22.9 of the Linden client this is 219 // As of RC 1.22.9 of the Linden client this is
201 // supported 220 // supported
202 221
@@ -245,7 +264,10 @@ namespace OpenSim.Region.ClientStack.Linden
245 264
246 if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) 265 if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
247 { 266 {
248 m_log.DebugFormat("[CAPS]: Unauthorized CAPS client"); 267 m_log.DebugFormat(
268 "[CAPS]: Unauthorized CAPS client {0} from {1}",
269 m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint);
270
249 return string.Empty; 271 return string.Empty;
250 } 272 }
251 273
@@ -296,7 +318,9 @@ namespace OpenSim.Region.ClientStack.Linden
296 m_dumpAssetsToFile); 318 m_dumpAssetsToFile);
297 uploader.OnUpLoad += TaskScriptUpdated; 319 uploader.OnUpLoad += TaskScriptUpdated;
298 320
299 m_HostCapsObj.HttpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); 321 m_HostCapsObj.HttpListener.AddStreamHandler(
322 new BinaryStreamHandler(
323 "POST", capsBase + uploaderPath, uploader.uploaderCaps, "TaskInventoryScriptUpdater", null));
300 324
301 string protocol = "http://"; 325 string protocol = "http://";
302 326
@@ -423,8 +447,14 @@ namespace OpenSim.Region.ClientStack.Linden
423 AssetUploader uploader = 447 AssetUploader uploader =
424 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, 448 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
425 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); 449 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
450
426 m_HostCapsObj.HttpListener.AddStreamHandler( 451 m_HostCapsObj.HttpListener.AddStreamHandler(
427 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); 452 new BinaryStreamHandler(
453 "POST",
454 capsBase + uploaderPath,
455 uploader.uploaderCaps,
456 "NewAgentInventoryRequest",
457 m_HostCapsObj.AgentID.ToString()));
428 458
429 string protocol = "http://"; 459 string protocol = "http://";
430 460
@@ -740,7 +770,8 @@ namespace OpenSim.Region.ClientStack.Linden
740 uploader.OnUpLoad += ItemUpdated; 770 uploader.OnUpLoad += ItemUpdated;
741 771
742 m_HostCapsObj.HttpListener.AddStreamHandler( 772 m_HostCapsObj.HttpListener.AddStreamHandler(
743 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); 773 new BinaryStreamHandler(
774 "POST", capsBase + uploaderPath, uploader.uploaderCaps, "NoteCardAgentInventory", null));
744 775
745 string protocol = "http://"; 776 string protocol = "http://";
746 777
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
index a91b02c..0d7390b 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
@@ -106,13 +106,14 @@ namespace OpenSim.Region.ClientStack.Linden
106 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 106 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
107 107
108 MainConsole.Instance.Commands.AddCommand( 108 MainConsole.Instance.Commands.AddCommand(
109 "Comms", 109 "Debug",
110 false, 110 false,
111 "debug eq", 111 "debug eq",
112 "debug eq [0|1]", 112 "debug eq [0|1|2]",
113 "Turn on event queue debugging", 113 "Turn on event queue debugging"
114 "debug eq 1 will turn on event queue debugging. This will log all outgoing event queue messages to clients.\n" 114 + "<= 0 - turns off all event queue logging"
115 + "debug eq 0 will turn off event queue debugging.", 115 + ">= 1 - turns on outgoing event logging"
116 + ">= 2 - turns on poll notification",
116 HandleDebugEq); 117 HandleDebugEq);
117 } 118 }
118 else 119 else
@@ -235,19 +236,19 @@ namespace OpenSim.Region.ClientStack.Linden
235// ClientClosed(client.AgentId); 236// ClientClosed(client.AgentId);
236// } 237// }
237 238
238 private void ClientClosed(UUID AgentID, Scene scene) 239 private void ClientClosed(UUID agentID, Scene scene)
239 { 240 {
240// m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", AgentID, m_scene.RegionInfo.RegionName); 241// m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
241 242
242 int count = 0; 243 int count = 0;
243 while (queues.ContainsKey(AgentID) && queues[AgentID].Count > 0 && count++ < 5) 244 while (queues.ContainsKey(agentID) && queues[agentID].Count > 0 && count++ < 5)
244 { 245 {
245 Thread.Sleep(1000); 246 Thread.Sleep(1000);
246 } 247 }
247 248
248 lock (queues) 249 lock (queues)
249 { 250 {
250 queues.Remove(AgentID); 251 queues.Remove(agentID);
251 } 252 }
252 253
253 List<UUID> removeitems = new List<UUID>(); 254 List<UUID> removeitems = new List<UUID>();
@@ -256,7 +257,7 @@ namespace OpenSim.Region.ClientStack.Linden
256 foreach (UUID ky in m_AvatarQueueUUIDMapping.Keys) 257 foreach (UUID ky in m_AvatarQueueUUIDMapping.Keys)
257 { 258 {
258// m_log.DebugFormat("[EVENTQUEUE]: Found key {0} in m_AvatarQueueUUIDMapping while looking for {1}", ky, AgentID); 259// m_log.DebugFormat("[EVENTQUEUE]: Found key {0} in m_AvatarQueueUUIDMapping while looking for {1}", ky, AgentID);
259 if (ky == AgentID) 260 if (ky == agentID)
260 { 261 {
261 removeitems.Add(ky); 262 removeitems.Add(ky);
262 } 263 }
@@ -267,7 +268,12 @@ namespace OpenSim.Region.ClientStack.Linden
267 UUID eventQueueGetUuid = m_AvatarQueueUUIDMapping[ky]; 268 UUID eventQueueGetUuid = m_AvatarQueueUUIDMapping[ky];
268 m_AvatarQueueUUIDMapping.Remove(ky); 269 m_AvatarQueueUUIDMapping.Remove(ky);
269 270
270 MainServer.Instance.RemovePollServiceHTTPHandler("","/CAPS/EQG/" + eventQueueGetUuid.ToString() + "/"); 271 string eqgPath = GenerateEqgCapPath(eventQueueGetUuid);
272 MainServer.Instance.RemovePollServiceHTTPHandler("", eqgPath);
273
274// m_log.DebugFormat(
275// "[EVENT QUEUE GET MODULE]: Removed EQG handler {0} for {1} in {2}",
276// eqgPath, agentID, m_scene.RegionInfo.RegionName);
271 } 277 }
272 } 278 }
273 279
@@ -281,7 +287,7 @@ namespace OpenSim.Region.ClientStack.Linden
281 { 287 {
282 searchval = m_QueueUUIDAvatarMapping[ky]; 288 searchval = m_QueueUUIDAvatarMapping[ky];
283 289
284 if (searchval == AgentID) 290 if (searchval == agentID)
285 { 291 {
286 removeitems.Add(ky); 292 removeitems.Add(ky);
287 } 293 }
@@ -305,6 +311,15 @@ namespace OpenSim.Region.ClientStack.Linden
305 //} 311 //}
306 } 312 }
307 313
314 /// <summary>
315 /// Generate an Event Queue Get handler path for the given eqg uuid.
316 /// </summary>
317 /// <param name='eqgUuid'></param>
318 private string GenerateEqgCapPath(UUID eqgUuid)
319 {
320 return string.Format("/CAPS/EQG/{0}/", eqgUuid);
321 }
322
308 public void OnRegisterCaps(UUID agentID, Caps caps) 323 public void OnRegisterCaps(UUID agentID, Caps caps)
309 { 324 {
310 // Register an event queue for the client 325 // Register an event queue for the client
@@ -316,8 +331,7 @@ namespace OpenSim.Region.ClientStack.Linden
316 // Let's instantiate a Queue for this agent right now 331 // Let's instantiate a Queue for this agent right now
317 TryGetQueue(agentID); 332 TryGetQueue(agentID);
318 333
319 string capsBase = "/CAPS/EQG/"; 334 UUID eventQueueGetUUID;
320 UUID EventQueueGetUUID = UUID.Zero;
321 335
322 lock (m_AvatarQueueUUIDMapping) 336 lock (m_AvatarQueueUUIDMapping)
323 { 337 {
@@ -325,44 +339,50 @@ namespace OpenSim.Region.ClientStack.Linden
325 if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) 339 if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
326 { 340 {
327 //m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!"); 341 //m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
328 EventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; 342 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
329 } 343 }
330 else 344 else
331 { 345 {
332 EventQueueGetUUID = UUID.Random(); 346 eventQueueGetUUID = UUID.Random();
333 //m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!"); 347 //m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!");
334 } 348 }
335 } 349 }
336 350
337 lock (m_QueueUUIDAvatarMapping) 351 lock (m_QueueUUIDAvatarMapping)
338 { 352 {
339 if (!m_QueueUUIDAvatarMapping.ContainsKey(EventQueueGetUUID)) 353 if (!m_QueueUUIDAvatarMapping.ContainsKey(eventQueueGetUUID))
340 m_QueueUUIDAvatarMapping.Add(EventQueueGetUUID, agentID); 354 m_QueueUUIDAvatarMapping.Add(eventQueueGetUUID, agentID);
341 } 355 }
342 356
343 lock (m_AvatarQueueUUIDMapping) 357 lock (m_AvatarQueueUUIDMapping)
344 { 358 {
345 if (!m_AvatarQueueUUIDMapping.ContainsKey(agentID)) 359 if (!m_AvatarQueueUUIDMapping.ContainsKey(agentID))
346 m_AvatarQueueUUIDMapping.Add(agentID, EventQueueGetUUID); 360 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID);
347 } 361 }
348 362
363 string eventQueueGetPath = GenerateEqgCapPath(eventQueueGetUUID);
364
349 // Register this as a caps handler 365 // Register this as a caps handler
350 // FIXME: Confusingly, we need to register separate as a capability so that the client is told about 366 // FIXME: Confusingly, we need to register separate as a capability so that the client is told about
351 // EventQueueGet when it receive capability information, but then we replace the rest handler immediately 367 // EventQueueGet when it receive capability information, but then we replace the rest handler immediately
352 // afterwards with the poll service. So for now, we'll pass a null instead to simplify code reading, but 368 // afterwards with the poll service. So for now, we'll pass a null instead to simplify code reading, but
353 // really it should be possible to directly register the poll handler as a capability. 369 // really it should be possible to directly register the poll handler as a capability.
354 caps.RegisterHandler("EventQueueGet", 370 caps.RegisterHandler("EventQueueGet", new RestHTTPHandler("POST", eventQueueGetPath, null));
355 new RestHTTPHandler("POST", capsBase + EventQueueGetUUID.ToString() + "/", null));
356// delegate(Hashtable m_dhttpMethod) 371// delegate(Hashtable m_dhttpMethod)
357// { 372// {
358// return ProcessQueue(m_dhttpMethod, agentID, caps); 373// return ProcessQueue(m_dhttpMethod, agentID, caps);
359// })); 374// }));
360 375
361 // This will persist this beyond the expiry of the caps handlers 376 // This will persist this beyond the expiry of the caps handlers
377 // TODO: Add EventQueueGet name/description for diagnostics
362 MainServer.Instance.AddPollServiceHTTPHandler( 378 MainServer.Instance.AddPollServiceHTTPHandler(
363 capsBase + EventQueueGetUUID.ToString() + "/", 379 eventQueueGetPath,
364 new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents, agentID)); 380 new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents, agentID));
365 381
382// m_log.DebugFormat(
383// "[EVENT QUEUE GET MODULE]: Registered EQG handler {0} for {1} in {2}",
384// eventQueueGetPath, agentID, m_scene.RegionInfo.RegionName);
385
366 Random rnd = new Random(Environment.TickCount); 386 Random rnd = new Random(Environment.TickCount);
367 lock (m_ids) 387 lock (m_ids)
368 { 388 {
@@ -384,9 +404,25 @@ namespace OpenSim.Region.ClientStack.Linden
384 return false; 404 return false;
385 } 405 }
386 406
407 /// <summary>
408 /// Logs a debug line for an outbound event queue message if appropriate.
409 /// </summary>
410 /// <param name='element'>Element containing message</param>
411 private void LogOutboundDebugMessage(OSD element, UUID agentId)
412 {
413 if (element is OSDMap)
414 {
415 OSDMap ev = (OSDMap)element;
416 m_log.DebugFormat(
417 "Eq OUT {0,-30} to {1,-20} {2,-20}",
418 ev["message"], m_scene.GetScenePresence(agentId).Name, m_scene.RegionInfo.RegionName);
419 }
420 }
421
387 public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request) 422 public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request)
388 { 423 {
389// m_log.DebugFormat("[EVENT QUEUE GET MODULE]: Invoked GetEvents() for {0}", pAgentId); 424 if (DebugLevel >= 2)
425 m_log.DebugFormat("POLLED FOR EQ MESSAGES BY {0} in {1}", pAgentId, m_scene.RegionInfo.RegionName);
390 426
391 Queue<OSD> queue = TryGetQueue(pAgentId); 427 Queue<OSD> queue = TryGetQueue(pAgentId);
392 OSD element; 428 OSD element;
@@ -410,13 +446,8 @@ namespace OpenSim.Region.ClientStack.Linden
410 } 446 }
411 else 447 else
412 { 448 {
413 if (DebugLevel > 0 && element is OSDMap) 449 if (DebugLevel > 0)
414 { 450 LogOutboundDebugMessage(element, pAgentId);
415 OSDMap ev = (OSDMap)element;
416 m_log.DebugFormat(
417 "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
418 ev["message"], m_scene.GetScenePresence(pAgentId).Name);
419 }
420 451
421 array.Add(element); 452 array.Add(element);
422 453
@@ -426,13 +457,8 @@ namespace OpenSim.Region.ClientStack.Linden
426 { 457 {
427 element = queue.Dequeue(); 458 element = queue.Dequeue();
428 459
429 if (DebugLevel > 0 && element is OSDMap) 460 if (DebugLevel > 0)
430 { 461 LogOutboundDebugMessage(element, pAgentId);
431 OSDMap ev = (OSDMap)element;
432 m_log.DebugFormat(
433 "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
434 ev["message"], m_scene.GetScenePresence(pAgentId).Name);
435 }
436 462
437 array.Add(element); 463 array.Add(element);
438 thisID++; 464 thisID++;
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs
index a5209b7..cd70410 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs
@@ -51,7 +51,16 @@ namespace OpenSim.Region.ClientStack.Linden.Tests
51 [SetUp] 51 [SetUp]
52 public void SetUp() 52 public void SetUp()
53 { 53 {
54 MainServer.Instance = new BaseHttpServer(9999, false, 9998, ""); 54 uint port = 9999;
55 uint sslPort = 9998;
56
57 // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
58 // variables and the VM is not restarted between tests.
59 MainServer.RemoveHttpServer(port);
60
61 BaseHttpServer server = new BaseHttpServer(port, false, sslPort, "");
62 MainServer.AddHttpServer(server);
63 MainServer.Instance = server;
55 64
56 IConfigSource config = new IniConfigSource(); 65 IConfigSource config = new IniConfigSource();
57 config.AddConfig("Startup"); 66 config.AddConfig("Startup");
@@ -60,7 +69,7 @@ namespace OpenSim.Region.ClientStack.Linden.Tests
60 CapabilitiesModule capsModule = new CapabilitiesModule(); 69 CapabilitiesModule capsModule = new CapabilitiesModule();
61 EventQueueGetModule eqgModule = new EventQueueGetModule(); 70 EventQueueGetModule eqgModule = new EventQueueGetModule();
62 71
63 m_scene = SceneHelpers.SetupScene(); 72 m_scene = new SceneHelpers().SetupScene();
64 SceneHelpers.SetupSceneModules(m_scene, config, capsModule, eqgModule); 73 SceneHelpers.SetupSceneModules(m_scene, config, capsModule, eqgModule);
65 } 74 }
66 75
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
index 14501c7..cb5afcc 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
@@ -132,7 +132,8 @@ namespace OpenSim.Region.ClientStack.Linden
132 capUrl = "/CAPS/" + UUID.Random(); 132 capUrl = "/CAPS/" + UUID.Random();
133 133
134 IRequestHandler reqHandler 134 IRequestHandler reqHandler
135 = new RestStreamHandler("POST", capUrl, m_fetchHandler.FetchInventoryRequest); 135 = new RestStreamHandler(
136 "POST", capUrl, m_fetchHandler.FetchInventoryRequest, capName, agentID.ToString());
136 137
137 caps.RegisterHandler(capName, reqHandler); 138 caps.RegisterHandler(capName, reqHandler);
138 } 139 }
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
index e7bd2e7..0d7b1fc 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
@@ -120,11 +120,13 @@ namespace OpenSim.Region.ClientStack.Linden
120 { 120 {
121// m_log.DebugFormat("[GETMESH]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); 121// m_log.DebugFormat("[GETMESH]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName);
122 GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); 122 GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService);
123 IRequestHandler reqHandler = new RestHTTPHandler("GET", "/CAPS/" + UUID.Random(), 123 IRequestHandler reqHandler
124 delegate(Hashtable m_dhttpMethod) 124 = new RestHTTPHandler(
125 { 125 "GET",
126 return gmeshHandler.ProcessGetMesh(m_dhttpMethod, UUID.Zero, null); 126 "/CAPS/" + UUID.Random(),
127 }); 127 httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null),
128 "GetMesh",
129 agentID.ToString());
128 130
129 caps.RegisterHandler("GetMesh", reqHandler); 131 caps.RegisterHandler("GetMesh", reqHandler);
130 } 132 }
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs
index fffcee2..5ae9cc3 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs
@@ -130,7 +130,9 @@ namespace OpenSim.Region.ClientStack.Linden
130 if (m_URL == "localhost") 130 if (m_URL == "localhost")
131 { 131 {
132// m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); 132// m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName);
133 caps.RegisterHandler("GetTexture", new GetTextureHandler("/CAPS/" + capID + "/", m_assetService)); 133 caps.RegisterHandler(
134 "GetTexture",
135 new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString()));
134 } 136 }
135 else 137 else
136 { 138 {
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs
index 18c7eae..44a6883 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs
@@ -117,7 +117,9 @@ namespace OpenSim.Region.ClientStack.Linden
117 117
118 public void RegisterCaps(UUID agentID, Caps caps) 118 public void RegisterCaps(UUID agentID, Caps caps)
119 { 119 {
120 IRequestHandler reqHandler = new RestHTTPHandler("GET", "/CAPS/" + UUID.Random(), MeshUploadFlag); 120 IRequestHandler reqHandler
121 = new RestHTTPHandler("GET", "/CAPS/" + UUID.Random(), MeshUploadFlag, "MeshUploadFlag", agentID.ToString());
122
121 caps.RegisterHandler("MeshUploadFlag", reqHandler); 123 caps.RegisterHandler("MeshUploadFlag", reqHandler);
122 m_agentID = agentID; 124 m_agentID = agentID;
123 } 125 }
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs
index 91872c5..52c4f44 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs
@@ -115,67 +115,66 @@ namespace OpenSim.Region.ClientStack.Linden
115 UUID capID = UUID.Random(); 115 UUID capID = UUID.Random();
116 116
117// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); 117// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID);
118 caps.RegisterHandler("NewFileAgentInventoryVariablePrice", 118 caps.RegisterHandler(
119 119 "NewFileAgentInventoryVariablePrice",
120 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>("POST", 120 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>(
121 "/CAPS/" + capID.ToString(), 121 "POST",
122 delegate(LLSDAssetUploadRequest req) 122 "/CAPS/" + capID.ToString(),
123 { 123 req => NewAgentInventoryRequest(req, agentID),
124 return NewAgentInventoryRequest(req,agentID); 124 "NewFileAgentInventoryVariablePrice",
125 })); 125 agentID.ToString()));
126
127 } 126 }
128 127
129 #endregion 128 #endregion
130 129
131 public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID) 130 public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID)
132 { 131 {
133
134 //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit 132 //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit
135 // You need to be aware of this and 133 // you need to be aware of this
136
137 134
138 //if (llsdRequest.asset_type == "texture" || 135 //if (llsdRequest.asset_type == "texture" ||
139 // llsdRequest.asset_type == "animation" || 136 // llsdRequest.asset_type == "animation" ||
140 // llsdRequest.asset_type == "sound") 137 // llsdRequest.asset_type == "sound")
141 // { 138 // {
142 // check user level 139 // check user level
143 ScenePresence avatar = null;
144 IClientAPI client = null;
145 m_scene.TryGetScenePresence(agentID, out avatar);
146 140
147 if (avatar != null) 141 ScenePresence avatar = null;
142 IClientAPI client = null;
143 m_scene.TryGetScenePresence(agentID, out avatar);
144
145 if (avatar != null)
146 {
147 client = avatar.ControllingClient;
148
149 if (avatar.UserLevel < m_levelUpload)
148 { 150 {
149 client = avatar.ControllingClient; 151 if (client != null)
150 152 client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
151 if (avatar.UserLevel < m_levelUpload) 153
152 { 154 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
153 if (client != null) 155 errorResponse.rsvp = "";
154 client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); 156 errorResponse.state = "error";
155 157 return errorResponse;
156 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
157 errorResponse.rsvp = "";
158 errorResponse.state = "error";
159 return errorResponse;
160 }
161 } 158 }
159 }
162 160
163 // check funds 161 // check funds
164 IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>(); 162 IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>();
165 163
166 if (mm != null) 164 if (mm != null)
165 {
166 if (!mm.UploadCovered(agentID, mm.UploadCharge))
167 { 167 {
168 if (!mm.UploadCovered(agentID, mm.UploadCharge)) 168 if (client != null)
169 { 169 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
170 if (client != null) 170
171 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); 171 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
172 172 errorResponse.rsvp = "";
173 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); 173 errorResponse.state = "error";
174 errorResponse.rsvp = ""; 174 return errorResponse;
175 errorResponse.state = "error";
176 return errorResponse;
177 }
178 } 175 }
176 }
177
179 // } 178 // }
180 179
181 string assetName = llsdRequest.name; 180 string assetName = llsdRequest.name;
@@ -189,8 +188,14 @@ namespace OpenSim.Region.ClientStack.Linden
189 AssetUploader uploader = 188 AssetUploader uploader =
190 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, 189 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
191 llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile); 190 llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile);
191
192 MainServer.Instance.AddStreamHandler( 192 MainServer.Instance.AddStreamHandler(
193 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); 193 new BinaryStreamHandler(
194 "POST",
195 capsBase + uploaderPath,
196 uploader.uploaderCaps,
197 "NewFileAgentInventoryVariablePrice",
198 agentID.ToString()));
194 199
195 string protocol = "http://"; 200 string protocol = "http://";
196 201
@@ -199,10 +204,9 @@ namespace OpenSim.Region.ClientStack.Linden
199 204
200 string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + 205 string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase +
201 uploaderPath; 206 uploaderPath;
202 207
203 208
204 LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); 209 LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
205
206 210
207 uploadResponse.rsvp = uploaderURL; 211 uploadResponse.rsvp = uploaderURL;
208 uploadResponse.state = "upload"; 212 uploadResponse.state = "upload";
@@ -220,6 +224,7 @@ namespace OpenSim.Region.ClientStack.Linden
220 pinventoryItem, pparentFolder, pdata, pinventoryType, 224 pinventoryItem, pparentFolder, pdata, pinventoryType,
221 passetType,agentID); 225 passetType,agentID);
222 }; 226 };
227
223 return uploadResponse; 228 return uploadResponse;
224 } 229 }
225 230
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs
index 1c47f0e..4ccfc43 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs
@@ -66,12 +66,14 @@ namespace OpenSim.Region.ClientStack.Linden
66 66
67// m_log.InfoFormat("[OBJECTADD]: {0}", "/CAPS/OA/" + capuuid + "/"); 67// m_log.InfoFormat("[OBJECTADD]: {0}", "/CAPS/OA/" + capuuid + "/");
68 68
69 caps.RegisterHandler("ObjectAdd", 69 caps.RegisterHandler(
70 new RestHTTPHandler("POST", "/CAPS/OA/" + capuuid + "/", 70 "ObjectAdd",
71 delegate(Hashtable m_dhttpMethod) 71 new RestHTTPHandler(
72 { 72 "POST",
73 return ProcessAdd(m_dhttpMethod, agentID, caps); 73 "/CAPS/OA/" + capuuid + "/",
74 })); 74 httpMethod => ProcessAdd(httpMethod, agentID, caps),
75 "ObjectAdd",
76 agentID.ToString()));;
75 } 77 }
76 78
77 public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap) 79 public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap)
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs
index 7a3d97e..ba902b2 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs
@@ -106,12 +106,15 @@ namespace OpenSim.Region.ClientStack.Linden
106 UUID capID = UUID.Random(); 106 UUID capID = UUID.Random();
107 107
108// m_log.Debug("[UPLOAD OBJECT ASSET MODULE]: /CAPS/" + capID); 108// m_log.Debug("[UPLOAD OBJECT ASSET MODULE]: /CAPS/" + capID);
109 caps.RegisterHandler("UploadObjectAsset", 109 caps.RegisterHandler(
110 new RestHTTPHandler("POST", "/CAPS/OA/" + capID + "/", 110 "UploadObjectAsset",
111 delegate(Hashtable m_dhttpMethod) 111 new RestHTTPHandler(
112 { 112 "POST",
113 return ProcessAdd(m_dhttpMethod, agentID, caps); 113 "/CAPS/OA/" + capID + "/",
114 })); 114 httpMethod => ProcessAdd(httpMethod, agentID, caps),
115 "UploadObjectAsset",
116 agentID.ToString()));
117
115 /* 118 /*
116 caps.RegisterHandler("NewFileAgentInventoryVariablePrice", 119 caps.RegisterHandler("NewFileAgentInventoryVariablePrice",
117 120
@@ -330,7 +333,6 @@ namespace OpenSim.Region.ClientStack.Linden
330 grp.AbsolutePosition = obj.Position; 333 grp.AbsolutePosition = obj.Position;
331 prim.RotationOffset = obj.Rotation; 334 prim.RotationOffset = obj.Rotation;
332 335
333 grp.IsAttachment = false;
334 // Required for linking 336 // Required for linking
335 grp.RootPart.ClearUpdateSchedule(); 337 grp.RootPart.ClearUpdateSchedule();
336 338
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs
index 1dd8938..8ed0fb3 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs
@@ -154,7 +154,9 @@ namespace OpenSim.Region.ClientStack.Linden
154 public void RegisterCaps(UUID agentID, Caps caps) 154 public void RegisterCaps(UUID agentID, Caps caps)
155 { 155 {
156 IRequestHandler reqHandler 156 IRequestHandler reqHandler
157 = new RestHTTPHandler("GET", "/CAPS/" + UUID.Random(), HandleSimulatorFeaturesRequest); 157 = new RestHTTPHandler(
158 "GET", "/CAPS/" + UUID.Random(),
159 HandleSimulatorFeaturesRequest, "SimulatorFeatures", agentID.ToString());
158 160
159 caps.RegisterHandler("SimulatorFeatures", reqHandler); 161 caps.RegisterHandler("SimulatorFeatures", reqHandler);
160 } 162 }
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
index 45d6071..b3d61a8 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
@@ -106,7 +106,9 @@ namespace OpenSim.Region.ClientStack.Linden
106 "POST", 106 "POST",
107 "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, 107 "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath,
108 new UploadBakedTextureHandler( 108 new UploadBakedTextureHandler(
109 caps, m_scene.AssetService, m_persistBakedTextures).UploadBakedTexture)); 109 caps, m_scene.AssetService, m_persistBakedTextures).UploadBakedTexture,
110 "UploadBakedTexture",
111 agentID.ToString()));
110 } 112 }
111 } 113 }
112} \ No newline at end of file 114} \ No newline at end of file
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
index 10f43d1..2359bd6 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
@@ -144,7 +144,12 @@ namespace OpenSim.Region.ClientStack.Linden
144 capUrl = "/CAPS/" + UUID.Random(); 144 capUrl = "/CAPS/" + UUID.Random();
145 145
146 IRequestHandler reqHandler 146 IRequestHandler reqHandler
147 = new RestStreamHandler("POST", capUrl, m_webFetchHandler.FetchInventoryDescendentsRequest); 147 = new RestStreamHandler(
148 "POST",
149 capUrl,
150 m_webFetchHandler.FetchInventoryDescendentsRequest,
151 "FetchInventoryDescendents2",
152 agentID.ToString());
148 153
149 caps.RegisterHandler(capName, reqHandler); 154 caps.RegisterHandler(capName, reqHandler);
150 } 155 }
@@ -160,4 +165,4 @@ namespace OpenSim.Region.ClientStack.Linden
160// capName, capUrl, m_scene.RegionInfo.RegionName, agentID); 165// capName, capUrl, m_scene.RegionInfo.RegionName, agentID);
161 } 166 }
162 } 167 }
163} 168} \ No newline at end of file
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs b/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs
index 90b3ede..1b8535c 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs
@@ -39,7 +39,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
39 public sealed class IncomingPacket 39 public sealed class IncomingPacket
40 { 40 {
41 /// <summary>Client this packet came from</summary> 41 /// <summary>Client this packet came from</summary>
42 public LLUDPClient Client; 42 public LLClientView Client;
43
43 /// <summary>Packet data that has been received</summary> 44 /// <summary>Packet data that has been received</summary>
44 public Packet Packet; 45 public Packet Packet;
45 46
@@ -48,7 +49,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
48 /// </summary> 49 /// </summary>
49 /// <param name="client">Reference to the client this packet came from</param> 50 /// <param name="client">Reference to the client this packet came from</param>
50 /// <param name="packet">Packet data</param> 51 /// <param name="packet">Packet data</param>
51 public IncomingPacket(LLUDPClient client, Packet packet) 52 public IncomingPacket(LLClientView client, Packet packet)
52 { 53 {
53 Client = client; 54 Client = client;
54 Packet = packet; 55 Packet = packet;
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 5a87958..18602f7 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -515,6 +515,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
515 /// </summary> 515 /// </summary>
516 public void Close(bool sendStop) 516 public void Close(bool sendStop)
517 { 517 {
518 IsActive = false;
519
518 m_log.DebugFormat( 520 m_log.DebugFormat(
519 "[CLIENT]: Close has been called for {0} attached to scene {1}", 521 "[CLIENT]: Close has been called for {0} attached to scene {1}",
520 Name, m_scene.RegionInfo.RegionName); 522 Name, m_scene.RegionInfo.RegionName);
@@ -3902,7 +3904,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3902 canUseImproved = false; 3904 canUseImproved = false;
3903 } 3905 }
3904 } 3906 }
3905 3907
3906 #endregion UpdateFlags to packet type conversion 3908 #endregion UpdateFlags to packet type conversion
3907 3909
3908 #region Block Construction 3910 #region Block Construction
@@ -11860,7 +11862,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11860 if (DebugPacketLevel <= 100 && (packet.Type == PacketType.AvatarAnimation || packet.Type == PacketType.ViewerEffect)) 11862 if (DebugPacketLevel <= 100 && (packet.Type == PacketType.AvatarAnimation || packet.Type == PacketType.ViewerEffect))
11861 logPacket = false; 11863 logPacket = false;
11862 11864
11863 if (DebugPacketLevel <= 50 && packet.Type == PacketType.ImprovedTerseObjectUpdate) 11865 if (DebugPacketLevel <= 50
11866 & (packet.Type == PacketType.ImprovedTerseObjectUpdate || packet.Type == PacketType.ObjectUpdate))
11864 logPacket = false; 11867 logPacket = false;
11865 11868
11866 if (DebugPacketLevel <= 25 && packet.Type == PacketType.ObjectPropertiesFamily) 11869 if (DebugPacketLevel <= 25 && packet.Type == PacketType.ObjectPropertiesFamily)
@@ -12070,10 +12073,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12070 return string.Empty; 12073 return string.Empty;
12071 } 12074 }
12072 12075
12073 public void KillEndDone()
12074 {
12075 }
12076
12077 #region IClientCore 12076 #region IClientCore
12078 12077
12079 private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>(); 12078 private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>();
@@ -12161,21 +12160,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12161 protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID) 12160 protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID)
12162 { 12161 {
12163 UUID requestID = UUID.Zero; 12162 UUID requestID = UUID.Zero;
12164 if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset) 12163 int sourceType = transferRequest.TransferInfo.SourceType;
12164
12165 if (sourceType == (int)SourceType.Asset)
12165 { 12166 {
12166 requestID = new UUID(transferRequest.TransferInfo.Params, 0); 12167 requestID = new UUID(transferRequest.TransferInfo.Params, 0);
12167 } 12168 }
12168 else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimInventoryItem) 12169 else if (sourceType == (int)SourceType.SimInventoryItem)
12169 { 12170 {
12170 requestID = new UUID(transferRequest.TransferInfo.Params, 80); 12171 requestID = new UUID(transferRequest.TransferInfo.Params, 80);
12171 } 12172 }
12172 else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimEstate) 12173 else if (sourceType == (int)SourceType.SimEstate)
12173 { 12174 {
12174 requestID = taskID; 12175 requestID = taskID;
12175 } 12176 }
12176 12177
12177 12178// m_log.DebugFormat(
12178// m_log.DebugFormat("[CLIENT]: {0} requesting asset {1}", Name, requestID); 12179// "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}",
12180// requestID, taskID, (SourceType)sourceType, Name);
12179 12181
12180 12182
12181 //Note, the bool returned from the below function is useless since it is always false. 12183 //Note, the bool returned from the below function is useless since it is always false.
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index 75f783b..9cce725 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -147,21 +147,34 @@ namespace OpenSim.Region.ClientStack.LindenUDP
147 private int m_elapsed500MSOutgoingPacketHandler; 147 private int m_elapsed500MSOutgoingPacketHandler;
148 148
149 /// <summary>Flag to signal when clients should check for resends</summary> 149 /// <summary>Flag to signal when clients should check for resends</summary>
150 private bool m_resendUnacked; 150 protected bool m_resendUnacked;
151
151 /// <summary>Flag to signal when clients should send ACKs</summary> 152 /// <summary>Flag to signal when clients should send ACKs</summary>
152 private bool m_sendAcks; 153 protected bool m_sendAcks;
154
153 /// <summary>Flag to signal when clients should send pings</summary> 155 /// <summary>Flag to signal when clients should send pings</summary>
154 private bool m_sendPing; 156 protected bool m_sendPing;
155 157
156 private int m_defaultRTO = 0; 158 private int m_defaultRTO = 0;
157 private int m_maxRTO = 0; 159 private int m_maxRTO = 0;
158 160 private int m_ackTimeout = 0;
161 private int m_pausedAckTimeout = 0;
159 private bool m_disableFacelights = false; 162 private bool m_disableFacelights = false;
160 163
161 public Socket Server { get { return null; } } 164 public Socket Server { get { return null; } }
162 165
163 private int m_malformedCount = 0; // Guard against a spamming attack 166 private int m_malformedCount = 0; // Guard against a spamming attack
164 167
168 /// <summary>
169 /// Record current outgoing client for monitoring purposes.
170 /// </summary>
171 private IClientAPI m_currentOutgoingClient;
172
173 /// <summary>
174 /// Recording current incoming client for monitoring purposes.
175 /// </summary>
176 private IClientAPI m_currentIncomingClient;
177
165 public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) 178 public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager)
166 : base(listenIP, (int)port) 179 : base(listenIP, (int)port)
167 { 180 {
@@ -198,11 +211,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
198 m_defaultRTO = config.GetInt("DefaultRTO", 0); 211 m_defaultRTO = config.GetInt("DefaultRTO", 0);
199 m_maxRTO = config.GetInt("MaxRTO", 0); 212 m_maxRTO = config.GetInt("MaxRTO", 0);
200 m_disableFacelights = config.GetBoolean("DisableFacelights", false); 213 m_disableFacelights = config.GetBoolean("DisableFacelights", false);
214 m_ackTimeout = 1000 * config.GetInt("AckTimeout", 60);
215 m_pausedAckTimeout = 1000 * config.GetInt("PausedAckTimeout", 300);
201 } 216 }
202 else 217 else
203 { 218 {
204 PrimUpdatesPerCallback = 100; 219 PrimUpdatesPerCallback = 100;
205 TextureSendLimit = 20; 220 TextureSendLimit = 20;
221 m_ackTimeout = 1000 * 60; // 1 minute
222 m_pausedAckTimeout = 1000 * 300; // 5 minutes
206 } 223 }
207 224
208 #region BinaryStats 225 #region BinaryStats
@@ -239,19 +256,56 @@ namespace OpenSim.Region.ClientStack.LindenUDP
239 if (m_scene == null) 256 if (m_scene == null)
240 throw new InvalidOperationException("[LLUDPSERVER]: Cannot LLUDPServer.Start() without an IScene reference"); 257 throw new InvalidOperationException("[LLUDPSERVER]: Cannot LLUDPServer.Start() without an IScene reference");
241 258
242 m_log.Info("[LLUDPSERVER]: Starting the LLUDP server in " + (m_asyncPacketHandling ? "asynchronous" : "synchronous") + " mode"); 259 m_log.InfoFormat(
260 "[LLUDPSERVER]: Starting the LLUDP server in {0} mode",
261 m_asyncPacketHandling ? "asynchronous" : "synchronous");
243 262
244 base.Start(m_recvBufferSize, m_asyncPacketHandling); 263 base.Start(m_recvBufferSize, m_asyncPacketHandling);
245 264
246 // Start the packet processing threads 265 // Start the packet processing threads
247 Watchdog.StartThread( 266 Watchdog.StartThread(
248 IncomingPacketHandler, "Incoming Packets (" + m_scene.RegionInfo.RegionName + ")", ThreadPriority.Normal, false, true); 267 IncomingPacketHandler,
268 string.Format("Incoming Packets ({0})", m_scene.RegionInfo.RegionName),
269 ThreadPriority.Normal,
270 false,
271 true,
272 GetWatchdogIncomingAlarmData,
273 Watchdog.WATCHDOG_TIMEOUT_MS);
274
249 Watchdog.StartThread( 275 Watchdog.StartThread(
250 OutgoingPacketHandler, "Outgoing Packets (" + m_scene.RegionInfo.RegionName + ")", ThreadPriority.Normal, false, true); 276 OutgoingPacketHandler,
277 string.Format("Outgoing Packets ({0})", m_scene.RegionInfo.RegionName),
278 ThreadPriority.Normal,
279 false,
280 true,
281 GetWatchdogOutgoingAlarmData,
282 Watchdog.WATCHDOG_TIMEOUT_MS);
251 283
252 m_elapsedMSSinceLastStatReport = Environment.TickCount; 284 m_elapsedMSSinceLastStatReport = Environment.TickCount;
253 } 285 }
254 286
287 /// <summary>
288 /// If the outgoing UDP thread times out, then return client that was being processed to help with debugging.
289 /// </summary>
290 /// <returns></returns>
291 private string GetWatchdogIncomingAlarmData()
292 {
293 return string.Format(
294 "Client is {0}",
295 m_currentIncomingClient != null ? m_currentIncomingClient.Name : "none");
296 }
297
298 /// <summary>
299 /// If the outgoing UDP thread times out, then return client that was being processed to help with debugging.
300 /// </summary>
301 /// <returns></returns>
302 private string GetWatchdogOutgoingAlarmData()
303 {
304 return string.Format(
305 "Client is {0}",
306 m_currentOutgoingClient != null ? m_currentOutgoingClient.Name : "none");
307 }
308
255 public new void Stop() 309 public new void Stop()
256 { 310 {
257 m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + m_scene.RegionInfo.RegionName); 311 m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + m_scene.RegionInfo.RegionName);
@@ -485,19 +539,34 @@ namespace OpenSim.Region.ClientStack.LindenUDP
485 SendPacket(udpClient, completePing, ThrottleOutPacketType.Unknown, false, null); 539 SendPacket(udpClient, completePing, ThrottleOutPacketType.Unknown, false, null);
486 } 540 }
487 541
488 public void HandleUnacked(LLUDPClient udpClient) 542 public void HandleUnacked(LLClientView client)
489 { 543 {
544 LLUDPClient udpClient = client.UDPClient;
545
490 if (!udpClient.IsConnected) 546 if (!udpClient.IsConnected)
491 return; 547 return;
492 548
493 // Disconnect an agent if no packets are received for some time 549 // Disconnect an agent if no packets are received for some time
494 //FIXME: Make 60 an .ini setting 550 int timeoutTicks = m_ackTimeout;
495 if ((Environment.TickCount & Int32.MaxValue) - udpClient.TickLastPacketReceived > 1000 * 60) 551
552 // Allow more slack if the client is "paused" eg file upload dialogue is open
553 // Some sort of limit is needed in case the client crashes, loses its network connection
554 // or some other disaster prevents it from sendung the AgentResume
555 if (udpClient.IsPaused)
556 timeoutTicks = m_pausedAckTimeout;
557
558 if (client.IsActive &&
559 (Environment.TickCount & Int32.MaxValue) - udpClient.TickLastPacketReceived > timeoutTicks)
496 { 560 {
497 m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + udpClient.AgentID); 561 // We must set IsActive synchronously so that we can stop the packet loop reinvoking this method, even
498 StatsManager.SimExtraStats.AddAbnormalClientThreadTermination(); 562 // though it's set later on by LLClientView.Close()
563 client.IsActive = false;
564
565 // Fire this out on a different thread so that we don't hold up outgoing packet processing for
566 // everybody else if this is being called due to an ack timeout.
567 // This is the same as processing as the async process of a logout request.
568 Util.FireAndForget(o => DeactivateClientDueToTimeout(client));
499 569
500 RemoveClient(udpClient);
501 return; 570 return;
502 } 571 }
503 572
@@ -820,7 +889,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
820 #endregion Ping Check Handling 889 #endregion Ping Check Handling
821 890
822 // Inbox insertion 891 // Inbox insertion
823 packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); 892 packetInbox.Enqueue(new IncomingPacket((LLClientView)client, packet));
824 } 893 }
825 894
826 #region BinaryStats 895 #region BinaryStats
@@ -916,7 +985,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
916 UDPPacketBuffer buffer = (UDPPacketBuffer)array[0]; 985 UDPPacketBuffer buffer = (UDPPacketBuffer)array[0];
917 UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1]; 986 UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1];
918 987
919 m_log.DebugFormat("[LLUDPSERVER]: Handling UseCircuitCode request from {0}", buffer.RemoteEndPoint); 988 m_log.DebugFormat(
989 "[LLUDPSERVER]: Handling UseCircuitCode request for circuit {0} to {1} from IP {2}",
990 uccp.CircuitCode.Code, m_scene.RegionInfo.RegionName, buffer.RemoteEndPoint);
920 991
921 remoteEndPoint = (IPEndPoint)buffer.RemoteEndPoint; 992 remoteEndPoint = (IPEndPoint)buffer.RemoteEndPoint;
922 993
@@ -945,8 +1016,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
945 { 1016 {
946 // Don't create clients for unauthorized requesters. 1017 // Don't create clients for unauthorized requesters.
947 m_log.WarnFormat( 1018 m_log.WarnFormat(
948 "[LLUDPSERVER]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}", 1019 "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}",
949 uccp.CircuitCode.ID, uccp.CircuitCode.Code, remoteEndPoint); 1020 uccp.CircuitCode.ID, m_scene.RegionInfo.RegionName, uccp.CircuitCode.Code, remoteEndPoint);
950 } 1021 }
951 1022
952 // m_log.DebugFormat( 1023 // m_log.DebugFormat(
@@ -1044,15 +1115,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1044 return client; 1115 return client;
1045 } 1116 }
1046 1117
1047 private void RemoveClient(LLUDPClient udpClient) 1118 /// <summary>
1119 /// Deactivates the client if we don't receive any packets within a certain amount of time (default 60 seconds).
1120 /// </summary>
1121 /// <remarks>
1122 /// If a connection is active then we will always receive packets even if nothing else is happening, due to
1123 /// regular client pings.
1124 /// </remarks>
1125 /// <param name='client'></param>
1126 private void DeactivateClientDueToTimeout(IClientAPI client)
1048 { 1127 {
1049 // Remove this client from the scene 1128 // We must set IsActive synchronously so that we can stop the packet loop reinvoking this method, even
1050 IClientAPI client; 1129 // though it's set later on by LLClientView.Close()
1051 if (m_scene.TryGetClient(udpClient.AgentID, out client)) 1130 client.IsActive = false;
1052 { 1131
1053 client.IsLoggingOut = true; 1132 m_log.WarnFormat(
1054 client.Close(false); 1133 "[LLUDPSERVER]: Ack timeout, disconnecting {0} agent for {1} in {2}",
1055 } 1134 client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, m_scene.RegionInfo.RegionName);
1135
1136 StatsManager.SimExtraStats.AddAbnormalClientThreadTermination();
1137
1138 if (!client.SceneAgent.IsChildAgent)
1139 client.Kick("Simulator logged you out due to connection timeout");
1140
1141 Util.FireAndForget(o => client.Close());
1056 } 1142 }
1057 1143
1058 private void IncomingPacketHandler() 1144 private void IncomingPacketHandler()
@@ -1161,6 +1247,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1161 // client. m_packetSent will be set to true if a packet is sent 1247 // client. m_packetSent will be set to true if a packet is sent
1162 m_scene.ForEachClient(clientPacketHandler); 1248 m_scene.ForEachClient(clientPacketHandler);
1163 1249
1250 m_currentOutgoingClient = null;
1251
1164 // If nothing was sent, sleep for the minimum amount of time before a 1252 // If nothing was sent, sleep for the minimum amount of time before a
1165 // token bucket could get more tokens 1253 // token bucket could get more tokens
1166 if (!m_packetSent) 1254 if (!m_packetSent)
@@ -1177,18 +1265,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1177 Watchdog.RemoveThread(); 1265 Watchdog.RemoveThread();
1178 } 1266 }
1179 1267
1180 private void ClientOutgoingPacketHandler(IClientAPI client) 1268 protected void ClientOutgoingPacketHandler(IClientAPI client)
1181 { 1269 {
1270 m_currentOutgoingClient = client;
1271
1182 try 1272 try
1183 { 1273 {
1184 if (client is LLClientView) 1274 if (client is LLClientView)
1185 { 1275 {
1186 LLUDPClient udpClient = ((LLClientView)client).UDPClient; 1276 LLClientView llClient = (LLClientView)client;
1277 LLUDPClient udpClient = llClient.UDPClient;
1187 1278
1188 if (udpClient.IsConnected) 1279 if (udpClient.IsConnected)
1189 { 1280 {
1190 if (m_resendUnacked) 1281 if (m_resendUnacked)
1191 HandleUnacked(udpClient); 1282 HandleUnacked(llClient);
1192 1283
1193 if (m_sendAcks) 1284 if (m_sendAcks)
1194 SendAcks(udpClient); 1285 SendAcks(udpClient);
@@ -1204,8 +1295,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1204 } 1295 }
1205 catch (Exception ex) 1296 catch (Exception ex)
1206 { 1297 {
1207 m_log.Error("[LLUDPSERVER]: OutgoingPacketHandler iteration for " + client.Name + 1298 m_log.Error(
1208 " threw an exception: " + ex.Message, ex); 1299 string.Format("[LLUDPSERVER]: OutgoingPacketHandler iteration for {0} threw ", client.Name), ex);
1209 } 1300 }
1210 } 1301 }
1211 1302
@@ -1231,11 +1322,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1231 { 1322 {
1232 nticks++; 1323 nticks++;
1233 watch1.Start(); 1324 watch1.Start();
1325 m_currentOutgoingClient = client;
1326
1234 try 1327 try
1235 { 1328 {
1236 if (client is LLClientView) 1329 if (client is LLClientView)
1237 { 1330 {
1238 LLUDPClient udpClient = ((LLClientView)client).UDPClient; 1331 LLClientView llClient = (LLClientView)client;
1332 LLUDPClient udpClient = llClient.UDPClient;
1239 1333
1240 if (udpClient.IsConnected) 1334 if (udpClient.IsConnected)
1241 { 1335 {
@@ -1244,7 +1338,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1244 nticksUnack++; 1338 nticksUnack++;
1245 watch2.Start(); 1339 watch2.Start();
1246 1340
1247 HandleUnacked(udpClient); 1341 HandleUnacked(llClient);
1248 1342
1249 watch2.Stop(); 1343 watch2.Stop();
1250 avgResendUnackedTicks = (nticksUnack - 1)/(float)nticksUnack * avgResendUnackedTicks + (watch2.ElapsedTicks / (float)nticksUnack); 1344 avgResendUnackedTicks = (nticksUnack - 1)/(float)nticksUnack * avgResendUnackedTicks + (watch2.ElapsedTicks / (float)nticksUnack);
@@ -1315,23 +1409,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1315 1409
1316 #endregion 1410 #endregion
1317 1411
1318 private void ProcessInPacket(object state) 1412 private void ProcessInPacket(IncomingPacket incomingPacket)
1319 { 1413 {
1320 IncomingPacket incomingPacket = (IncomingPacket)state;
1321 Packet packet = incomingPacket.Packet; 1414 Packet packet = incomingPacket.Packet;
1322 LLUDPClient udpClient = incomingPacket.Client; 1415 LLClientView client = incomingPacket.Client;
1323 IClientAPI client;
1324 1416
1325 // Sanity check 1417 if (client.IsActive)
1326 if (packet == null || udpClient == null)
1327 { 1418 {
1328 m_log.WarnFormat("[LLUDPSERVER]: Processing a packet with incomplete state. Packet=\"{0}\", UDPClient=\"{1}\"", 1419 m_currentIncomingClient = client;
1329 packet, udpClient);
1330 }
1331 1420
1332 // Make sure this client is still alive
1333 if (m_scene.TryGetClient(udpClient.AgentID, out client))
1334 {
1335 try 1421 try
1336 { 1422 {
1337 // Process this packet 1423 // Process this packet
@@ -1346,21 +1432,34 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1346 catch (Exception e) 1432 catch (Exception e)
1347 { 1433 {
1348 // Don't let a failure in an individual client thread crash the whole sim. 1434 // Don't let a failure in an individual client thread crash the whole sim.
1349 m_log.ErrorFormat("[LLUDPSERVER]: Client packet handler for {0} for packet {1} threw an exception", udpClient.AgentID, packet.Type); 1435 m_log.Error(
1350 m_log.Error(e.Message, e); 1436 string.Format(
1437 "[LLUDPSERVER]: Client packet handler for {0} for packet {1} threw ",
1438 client.Name, packet.Type),
1439 e);
1440 }
1441 finally
1442 {
1443 m_currentIncomingClient = null;
1351 } 1444 }
1352 } 1445 }
1353 else 1446 else
1354 { 1447 {
1355 m_log.DebugFormat("[LLUDPSERVER]: Dropping incoming {0} packet for dead client {1}", packet.Type, udpClient.AgentID); 1448 m_log.DebugFormat(
1449 "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}",
1450 packet.Type, client.Name, m_scene.RegionInfo.RegionName);
1356 } 1451 }
1357 } 1452 }
1358 1453
1359 protected void LogoutHandler(IClientAPI client) 1454 protected void LogoutHandler(IClientAPI client)
1360 { 1455 {
1361 client.SendLogoutPacket(); 1456 client.SendLogoutPacket();
1362 if (client.IsActive) 1457
1363 RemoveClient(((LLClientView)client).UDPClient); 1458 if (!client.IsLoggingOut)
1459 {
1460 client.IsLoggingOut = true;
1461 client.Close();
1462 }
1364 } 1463 }
1365 } 1464 }
1366} 1465}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
index a575e36..109a8e1 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
@@ -45,6 +45,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
45 [TestFixture] 45 [TestFixture]
46 public class BasicCircuitTests 46 public class BasicCircuitTests
47 { 47 {
48 private Scene m_scene;
49 private TestLLUDPServer m_udpServer;
50
48 [TestFixtureSetUp] 51 [TestFixtureSetUp]
49 public void FixtureInit() 52 public void FixtureInit()
50 { 53 {
@@ -61,83 +64,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
61 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; 64 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
62 } 65 }
63 66
64// /// <summary> 67 [SetUp]
65// /// Add a client for testing 68 public void SetUp()
66// /// </summary> 69 {
67// /// <param name="scene"></param> 70 m_scene = new SceneHelpers().SetupScene();
68// /// <param name="testLLUDPServer"></param> 71 }
69// /// <param name="testPacketServer"></param>
70// /// <param name="acm">Agent circuit manager used in setting up the stack</param>
71// protected void SetupStack(
72// IScene scene, out TestLLUDPServer testLLUDPServer, out TestLLPacketServer testPacketServer,
73// out AgentCircuitManager acm)
74// {
75// IConfigSource configSource = new IniConfigSource();
76// ClientStackUserSettings userSettings = new ClientStackUserSettings();
77// testLLUDPServer = new TestLLUDPServer();
78// acm = new AgentCircuitManager();
79//
80// uint port = 666;
81// testLLUDPServer.Initialise(null, ref port, 0, false, configSource, acm);
82// testPacketServer = new TestLLPacketServer(testLLUDPServer, userSettings);
83// testLLUDPServer.LocalScene = scene;
84// }
85
86// /// <summary>
87// /// Set up a client for tests which aren't concerned with this process itself and where only one client is being
88// /// tested
89// /// </summary>
90// /// <param name="circuitCode"></param>
91// /// <param name="epSender"></param>
92// /// <param name="testLLUDPServer"></param>
93// /// <param name="acm"></param>
94// protected void AddClient(
95// uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm)
96// {
97// UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001");
98// UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002");
99//
100// AddClient(circuitCode, epSender, myAgentUuid, mySessionUuid, testLLUDPServer, acm);
101// }
102
103// /// <summary>
104// /// Set up a client for tests which aren't concerned with this process itself
105// /// </summary>
106// /// <param name="circuitCode"></param>
107// /// <param name="epSender"></param>
108// /// <param name="agentId"></param>
109// /// <param name="sessionId"></param>
110// /// <param name="testLLUDPServer"></param>
111// /// <param name="acm"></param>
112// protected void AddClient(
113// uint circuitCode, EndPoint epSender, UUID agentId, UUID sessionId,
114// TestLLUDPServer testLLUDPServer, AgentCircuitManager acm)
115// {
116// AgentCircuitData acd = new AgentCircuitData();
117// acd.AgentID = agentId;
118// acd.SessionID = sessionId;
119//
120// UseCircuitCodePacket uccp = new UseCircuitCodePacket();
121//
122// UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
123// = new UseCircuitCodePacket.CircuitCodeBlock();
124// uccpCcBlock.Code = circuitCode;
125// uccpCcBlock.ID = agentId;
126// uccpCcBlock.SessionID = sessionId;
127// uccp.CircuitCode = uccpCcBlock;
128//
129// acm.AddNewCircuit(circuitCode, acd);
130//
131// testLLUDPServer.LoadReceive(uccp, epSender);
132// testLLUDPServer.ReceiveData(null);
133// }
134 72
135 /// <summary> 73 /// <summary>
136 /// Build an object name packet for test purposes 74 /// Build an object name packet for test purposes
137 /// </summary> 75 /// </summary>
138 /// <param name="objectLocalId"></param> 76 /// <param name="objectLocalId"></param>
139 /// <param name="objectName"></param> 77 /// <param name="objectName"></param>
140 protected ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName) 78 private ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName)
141 { 79 {
142 ObjectNamePacket onp = new ObjectNamePacket(); 80 ObjectNamePacket onp = new ObjectNamePacket();
143 ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock(); 81 ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock();
@@ -148,6 +86,55 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
148 86
149 return onp; 87 return onp;
150 } 88 }
89
90 private void AddUdpServer()
91 {
92 AddUdpServer(new IniConfigSource());
93 }
94
95 private void AddUdpServer(IniConfigSource configSource)
96 {
97 uint port = 0;
98 AgentCircuitManager acm = m_scene.AuthenticateHandler;
99
100 m_udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
101 m_udpServer.AddScene(m_scene);
102 }
103
104 /// <summary>
105 /// Used by tests that aren't testing this stage.
106 /// </summary>
107 private ScenePresence AddClient()
108 {
109 UUID myAgentUuid = TestHelpers.ParseTail(0x1);
110 UUID mySessionUuid = TestHelpers.ParseTail(0x2);
111 uint myCircuitCode = 123456;
112 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
113
114 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
115
116 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
117 = new UseCircuitCodePacket.CircuitCodeBlock();
118 uccpCcBlock.Code = myCircuitCode;
119 uccpCcBlock.ID = myAgentUuid;
120 uccpCcBlock.SessionID = mySessionUuid;
121 uccp.CircuitCode = uccpCcBlock;
122
123 byte[] uccpBytes = uccp.ToBytes();
124 UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
125 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
126 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
127
128 AgentCircuitData acd = new AgentCircuitData();
129 acd.AgentID = myAgentUuid;
130 acd.SessionID = mySessionUuid;
131
132 m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd);
133
134 m_udpServer.PacketReceived(upb);
135
136 return m_scene.GetScenePresence(myAgentUuid);
137 }
151 138
152 /// <summary> 139 /// <summary>
153 /// Test adding a client to the stack 140 /// Test adding a client to the stack
@@ -158,19 +145,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
158 TestHelpers.InMethod(); 145 TestHelpers.InMethod();
159// XmlConfigurator.Configure(); 146// XmlConfigurator.Configure();
160 147
161 TestScene scene = SceneHelpers.SetupScene(); 148 AddUdpServer();
162 uint myCircuitCode = 123456; 149
163 UUID myAgentUuid = TestHelpers.ParseTail(0x1); 150 UUID myAgentUuid = TestHelpers.ParseTail(0x1);
164 UUID mySessionUuid = TestHelpers.ParseTail(0x2); 151 UUID mySessionUuid = TestHelpers.ParseTail(0x2);
152 uint myCircuitCode = 123456;
165 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); 153 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
166 154
167 uint port = 0;
168 AgentCircuitManager acm = scene.AuthenticateHandler;
169
170 TestLLUDPServer llUdpServer
171 = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, new IniConfigSource(), acm);
172 llUdpServer.AddScene(scene);
173
174 UseCircuitCodePacket uccp = new UseCircuitCodePacket(); 155 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
175 156
176 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock 157 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
@@ -185,26 +166,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
185 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. 166 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
186 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); 167 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
187 168
188 llUdpServer.PacketReceived(upb); 169 m_udpServer.PacketReceived(upb);
189 170
190 // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet 171 // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet
191 Assert.That(scene.GetScenePresence(myAgentUuid), Is.Null); 172 Assert.That(m_scene.GetScenePresence(myAgentUuid), Is.Null);
192 173
193 AgentCircuitData acd = new AgentCircuitData(); 174 AgentCircuitData acd = new AgentCircuitData();
194 acd.AgentID = myAgentUuid; 175 acd.AgentID = myAgentUuid;
195 acd.SessionID = mySessionUuid; 176 acd.SessionID = mySessionUuid;
196 177
197 acm.AddNewCircuit(myCircuitCode, acd); 178 m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd);
198 179
199 llUdpServer.PacketReceived(upb); 180 m_udpServer.PacketReceived(upb);
200 181
201 // Should succeed now 182 // Should succeed now
202 ScenePresence sp = scene.GetScenePresence(myAgentUuid); 183 ScenePresence sp = m_scene.GetScenePresence(myAgentUuid);
203 Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); 184 Assert.That(sp.UUID, Is.EqualTo(myAgentUuid));
204 185
205 Assert.That(llUdpServer.PacketsSent.Count, Is.EqualTo(1)); 186 Assert.That(m_udpServer.PacketsSent.Count, Is.EqualTo(1));
206 187
207 Packet packet = llUdpServer.PacketsSent[0]; 188 Packet packet = m_udpServer.PacketsSent[0];
208 Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); 189 Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket)));
209 190
210 PacketAckPacket ackPacket = packet as PacketAckPacket; 191 PacketAckPacket ackPacket = packet as PacketAckPacket;
@@ -212,6 +193,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
212 Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0)); 193 Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0));
213 } 194 }
214 195
196 [Test]
197 public void TestLogoutClientDueToAck()
198 {
199 TestHelpers.InMethod();
200// TestHelpers.EnableLogging();
201
202 IniConfigSource ics = new IniConfigSource();
203 IConfig config = ics.AddConfig("ClientStack.LindenUDP");
204 config.Set("AckTimeout", -1);
205 AddUdpServer(ics);
206
207 ScenePresence sp = AddClient();
208 m_udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false);
209
210 ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID);
211 Assert.That(spAfterAckTimeout, Is.Null);
212
213// TestHelpers.DisableLogging();
214 }
215
215// /// <summary> 216// /// <summary>
216// /// Test removing a client from the stack 217// /// Test removing a client from the stack
217// /// </summary> 218// /// </summary>
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
index 1b68d68..5fcf376 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
@@ -79,7 +79,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
79 79
80 J2KDecoderModule j2kdm = new J2KDecoderModule(); 80 J2KDecoderModule j2kdm = new J2KDecoderModule();
81 81
82 scene = SceneHelpers.SetupScene(); 82 SceneHelpers sceneHelpers = new SceneHelpers();
83 scene = sceneHelpers.SetupScene();
83 SceneHelpers.SetupSceneModules(scene, j2kdm); 84 SceneHelpers.SetupSceneModules(scene, j2kdm);
84 85
85 tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene); 86 tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene);
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
index 0302385..27b9e5b 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
@@ -59,6 +59,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
59 PacketsSent.Add(packet); 59 PacketsSent.Add(packet);
60 } 60 }
61 61
62 public void ClientOutgoingPacketHandler(IClientAPI client, bool resendUnacked, bool sendAcks, bool sendPing)
63 {
64 m_resendUnacked = resendUnacked;
65 m_sendAcks = sendAcks;
66 m_sendPing = sendPing;
67
68 ClientOutgoingPacketHandler(client);
69 }
70
62//// /// <summary> 71//// /// <summary>
63//// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive 72//// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive
64//// /// </summary> 73//// /// </summary>
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
index 6e3a58e..c4324e8 100644
--- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs
+++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
@@ -94,24 +94,21 @@ namespace OpenSim.Region.ClientStack
94 m_log.InfoFormat("[REGION SERVER]: Starting HTTP server on port {0}", m_httpServerPort); 94 m_log.InfoFormat("[REGION SERVER]: Starting HTTP server on port {0}", m_httpServerPort);
95 m_httpServer.Start(); 95 m_httpServer.Start();
96 96
97 MainServer.AddHttpServer(m_httpServer);
97 MainServer.Instance = m_httpServer; 98 MainServer.Instance = m_httpServer;
98 99
99 // "OOB" Server 100 // "OOB" Server
100 if (m_networkServersInfo.ssl_listener) 101 if (m_networkServersInfo.ssl_listener)
101 { 102 {
102 BaseHttpServer server = null; 103 BaseHttpServer server = new BaseHttpServer(
103 server = new BaseHttpServer(
104 m_networkServersInfo.https_port, m_networkServersInfo.ssl_listener, m_networkServersInfo.cert_path, 104 m_networkServersInfo.https_port, m_networkServersInfo.ssl_listener, m_networkServersInfo.cert_path,
105 m_networkServersInfo.cert_pass); 105 m_networkServersInfo.cert_pass);
106 // Add the server to m_Servers
107 if(server != null)
108 {
109 m_log.InfoFormat("[REGION SERVER]: Starting HTTPS server on port {0}", server.Port);
110 MainServer.AddHttpServer(server);
111 server.Start();
112 }
113 }
114 106
107 m_log.InfoFormat("[REGION SERVER]: Starting HTTPS server on port {0}", server.Port);
108 MainServer.AddHttpServer(server);
109 server.Start();
110 }
111
115 base.StartupSpecific(); 112 base.StartupSpecific();
116 } 113 }
117 114
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
index 874693e..7081989 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -42,8 +42,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
42 public class AssetTransactionModule : INonSharedRegionModule, 42 public class AssetTransactionModule : INonSharedRegionModule,
43 IAgentAssetTransactions 43 IAgentAssetTransactions
44 { 44 {
45// private static readonly ILog m_log = LogManager.GetLogger( 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46// MethodBase.GetCurrentMethod().DeclaringType);
47 46
48 protected Scene m_Scene; 47 protected Scene m_Scene;
49 private bool m_dumpAssetsToFile = false; 48 private bool m_dumpAssetsToFile = false;
@@ -209,15 +208,15 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
209 /// and comes through this method. 208 /// and comes through this method.
210 /// </summary> 209 /// </summary>
211 /// <param name="remoteClient"></param> 210 /// <param name="remoteClient"></param>
211 /// <param name="part"></param>
212 /// <param name="transactionID"></param> 212 /// <param name="transactionID"></param>
213 /// <param name="item"></param> 213 /// <param name="item"></param>
214 public void HandleTaskItemUpdateFromTransaction(IClientAPI remoteClient, 214 public void HandleTaskItemUpdateFromTransaction(
215 SceneObjectPart part, UUID transactionID, 215 IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
216 TaskInventoryItem item)
217 { 216 {
218// m_log.DebugFormat( 217 m_log.DebugFormat(
219// "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}", 218 "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0} in {1} for {2} in {3}",
220// item.Name); 219 item.Name, part.Name, remoteClient.Name, m_Scene.RegionInfo.RegionName);
221 220
222 AgentAssetTransactions transactions = 221 AgentAssetTransactions transactions =
223 GetUserTransactions(remoteClient.AgentId); 222 GetUserTransactions(remoteClient.AgentId);
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index 127ca1d..7d7176f 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -83,7 +83,7 @@ namespace Flotsam.RegionModules.AssetCache
83 private Dictionary<string, ManualResetEvent> m_CurrentlyWriting = new Dictionary<string, ManualResetEvent>(); 83 private Dictionary<string, ManualResetEvent> m_CurrentlyWriting = new Dictionary<string, ManualResetEvent>();
84 private int m_WaitOnInprogressTimeout = 3000; 84 private int m_WaitOnInprogressTimeout = 3000;
85#else 85#else
86 private List<string> m_CurrentlyWriting = new List<string>(); 86 private HashSet<string> m_CurrentlyWriting = new HashSet<string>();
87#endif 87#endif
88 88
89 private bool m_FileCacheEnabled = true; 89 private bool m_FileCacheEnabled = true;
@@ -143,7 +143,7 @@ namespace Flotsam.RegionModules.AssetCache
143 IConfig assetConfig = source.Configs["AssetCache"]; 143 IConfig assetConfig = source.Configs["AssetCache"];
144 if (assetConfig == null) 144 if (assetConfig == null)
145 { 145 {
146 m_log.Warn( 146 m_log.Debug(
147 "[FLOTSAM ASSET CACHE]: AssetCache section missing from config (not copied config-include/FlotsamCache.ini.example? Using defaults."); 147 "[FLOTSAM ASSET CACHE]: AssetCache section missing from config (not copied config-include/FlotsamCache.ini.example? Using defaults.");
148 } 148 }
149 else 149 else
@@ -272,7 +272,11 @@ namespace Flotsam.RegionModules.AssetCache
272 // the other thread has updated the time for us. 272 // the other thread has updated the time for us.
273 try 273 try
274 { 274 {
275 File.SetLastAccessTime(filename, DateTime.Now); 275 lock (m_CurrentlyWriting)
276 {
277 if (!m_CurrentlyWriting.Contains(filename))
278 File.SetLastAccessTime(filename, DateTime.Now);
279 }
276 } 280 }
277 catch 281 catch
278 { 282 {
diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs
index 5adb845..c91b25f 100644
--- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs
+++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Region.CoreModules.Asset.Tests
65 config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true"); 65 config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true");
66 66
67 m_cache = new FlotsamAssetCache(); 67 m_cache = new FlotsamAssetCache();
68 m_scene = SceneHelpers.SetupScene(); 68 m_scene = new SceneHelpers().SetupScene();
69 SceneHelpers.SetupSceneModules(m_scene, config, m_cache); 69 SceneHelpers.SetupSceneModules(m_scene, config, m_cache);
70 } 70 }
71 71
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index fd7cad2..fcf682b 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 private Scene m_scene; 52 private Scene m_scene;
53 private IDialogModule m_dialogModule; 53 private IInventoryAccessModule m_invAccessModule;
54 54
55 /// <summary> 55 /// <summary>
56 /// Are attachments enabled? 56 /// Are attachments enabled?
@@ -72,7 +72,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
72 public void AddRegion(Scene scene) 72 public void AddRegion(Scene scene)
73 { 73 {
74 m_scene = scene; 74 m_scene = scene;
75 m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>();
76 m_scene.RegisterModuleInterface<IAttachmentsModule>(this); 75 m_scene.RegisterModuleInterface<IAttachmentsModule>(this);
77 76
78 if (Enabled) 77 if (Enabled)
@@ -89,7 +88,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
89 m_scene.EventManager.OnNewClient -= SubscribeToClientEvents; 88 m_scene.EventManager.OnNewClient -= SubscribeToClientEvents;
90 } 89 }
91 90
92 public void RegionLoaded(Scene scene) {} 91 public void RegionLoaded(Scene scene)
92 {
93 m_invAccessModule = m_scene.RequestModuleInterface<IInventoryAccessModule>();
94 }
93 95
94 public void Close() 96 public void Close()
95 { 97 {
@@ -100,6 +102,56 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
100 102
101 #region IAttachmentsModule 103 #region IAttachmentsModule
102 104
105 public void CopyAttachments(IScenePresence sp, AgentData ad)
106 {
107 lock (sp.AttachmentsSyncLock)
108 {
109 // Attachment objects
110 List<SceneObjectGroup> attachments = sp.GetAttachments();
111 if (attachments.Count > 0)
112 {
113 ad.AttachmentObjects = new List<ISceneObject>();
114 ad.AttachmentObjectStates = new List<string>();
115 // IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
116 sp.InTransitScriptStates.Clear();
117
118 foreach (SceneObjectGroup sog in attachments)
119 {
120 // We need to make a copy and pass that copy
121 // because of transfers withn the same sim
122 ISceneObject clone = sog.CloneForNewScene();
123 // Attachment module assumes that GroupPosition holds the offsets...!
124 ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos;
125 ((SceneObjectGroup)clone).IsAttachment = false;
126 ad.AttachmentObjects.Add(clone);
127 string state = sog.GetStateSnapshot();
128 ad.AttachmentObjectStates.Add(state);
129 sp.InTransitScriptStates.Add(state);
130 // Let's remove the scripts of the original object here
131 sog.RemoveScriptInstances(true);
132 }
133 }
134 }
135 }
136
137 public void CopyAttachments(AgentData ad, IScenePresence sp)
138 {
139 if (ad.AttachmentObjects != null && ad.AttachmentObjects.Count > 0)
140 {
141 lock (sp.AttachmentsSyncLock)
142 sp.ClearAttachments();
143
144 int i = 0;
145 foreach (ISceneObject so in ad.AttachmentObjects)
146 {
147 ((SceneObjectGroup)so).LocalId = 0;
148 ((SceneObjectGroup)so).RootPart.ClearUpdateSchedule();
149 so.SetState(ad.AttachmentObjectStates[i++], m_scene);
150 m_scene.IncomingCreateObject(Vector3.Zero, so);
151 }
152 }
153 }
154
103 /// <summary> 155 /// <summary>
104 /// RezAttachments. This should only be called upon login on the first region. 156 /// RezAttachments. This should only be called upon login on the first region.
105 /// Attachment rezzings on crossings and TPs are done in a different way. 157 /// Attachment rezzings on crossings and TPs are done in a different way.
@@ -189,36 +241,47 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
189 } 241 }
190 catch (Exception e) 242 catch (Exception e)
191 { 243 {
192 m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment: {0}{1}", e.Message, e.StackTrace); 244 UUID agentId = (sp.ControllingClient == null) ? (UUID)null : sp.ControllingClient.AgentId;
245 m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment with itemID {0}, assetID {1}, point {2} for {3}: {4}\n{5}",
246 attach.ItemID, attach.AssetID, p, agentId, e.Message, e.StackTrace);
193 } 247 }
194 } 248 }
195 } 249 }
196 250
197 public void SaveChangedAttachments(IScenePresence sp, bool saveAllScripted) 251 public void DeRezAttachments(IScenePresence sp, bool saveChanged, bool saveAllScripted)
198 { 252 {
199// m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name);
200
201 if (!Enabled) 253 if (!Enabled)
202 return; 254 return;
203 255
204 foreach (SceneObjectGroup grp in sp.GetAttachments()) 256// m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name);
257
258 lock (sp.AttachmentsSyncLock)
205 { 259 {
206 grp.IsAttachment = false; 260 foreach (SceneObjectGroup grp in sp.GetAttachments())
207 grp.AbsolutePosition = grp.RootPart.AttachedPos; 261 {
208 UpdateKnownItem(sp, grp, saveAllScripted); 262 grp.Scene.DeleteSceneObject(grp, false);
209 grp.IsAttachment = true; 263
264 if (saveChanged || saveAllScripted)
265 {
266 grp.IsAttachment = false;
267 grp.AbsolutePosition = grp.RootPart.AttachedPos;
268 UpdateKnownItem(sp, grp, saveAllScripted);
269 }
270 }
271
272 sp.ClearAttachments();
210 } 273 }
211 } 274 }
212 275
213 public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent) 276 public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent)
214 { 277 {
215// m_log.DebugFormat(
216// "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
217// m_scene.RegionInfo.RegionName, sp.Name, silent);
218
219 if (!Enabled) 278 if (!Enabled)
220 return; 279 return;
221 280
281// m_log.DebugFormat(
282// "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
283// m_scene.RegionInfo.RegionName, sp.Name, silent);
284
222 foreach (SceneObjectGroup sop in sp.GetAttachments()) 285 foreach (SceneObjectGroup sop in sp.GetAttachments())
223 { 286 {
224 sop.Scene.DeleteSceneObject(sop, silent); 287 sop.Scene.DeleteSceneObject(sop, silent);
@@ -458,7 +521,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
458 lock (sp.AttachmentsSyncLock) 521 lock (sp.AttachmentsSyncLock)
459 { 522 {
460 // Save avatar attachment information 523 // Save avatar attachment information
461 m_log.Debug("[ATTACHMENTS MODULE]: Detaching from UserID: " + sp.UUID + ", ItemID: " + itemID); 524// m_log.Debug("[ATTACHMENTS MODULE]: Detaching from UserID: " + sp.UUID + ", ItemID: " + itemID);
462 525
463 bool changed = sp.Appearance.DetachAttachment(itemID); 526 bool changed = sp.Appearance.DetachAttachment(itemID);
464 if (changed && m_scene.AvatarFactory != null) 527 if (changed && m_scene.AvatarFactory != null)
@@ -473,17 +536,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
473 if (!Enabled) 536 if (!Enabled)
474 return; 537 return;
475 538
476 // First we save the
477 // attachment point information, then we update the relative
478 // positioning. Then we have to mark the object as NOT an
479 // attachment. This is necessary in order to correctly save
480 // and retrieve GroupPosition information for the attachment.
481 // Finally, we restore the object's attachment status.
482 uint attachmentPoint = sog.AttachmentPoint;
483 sog.UpdateGroupPosition(pos); 539 sog.UpdateGroupPosition(pos);
484 sog.IsAttachment = false;
485 sog.AbsolutePosition = sog.RootPart.AttachedPos;
486 sog.AttachmentPoint = attachmentPoint;
487 sog.HasGroupChanged = true; 540 sog.HasGroupChanged = true;
488 } 541 }
489 542
@@ -538,9 +591,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
538 591
539 if (grp.HasGroupChanged || (saveAllScripted && grp.ContainsScripts())) 592 if (grp.HasGroupChanged || (saveAllScripted && grp.ContainsScripts()))
540 { 593 {
541 m_log.DebugFormat( 594// m_log.DebugFormat(
542 "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", 595// "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}",
543 grp.UUID, grp.AttachmentPoint); 596// grp.UUID, grp.AttachmentPoint);
544 597
545 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); 598 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
546 599
@@ -571,12 +624,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
571 } 624 }
572 grp.HasGroupChanged = false; // Prevent it being saved over and over 625 grp.HasGroupChanged = false; // Prevent it being saved over and over
573 } 626 }
574 else 627// else
575 { 628// {
576 m_log.DebugFormat( 629// m_log.DebugFormat(
577 "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}", 630// "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
578 grp.UUID, grp.AttachmentPoint); 631// grp.UUID, grp.AttachmentPoint);
579 } 632// }
580 } 633 }
581 634
582 /// <summary> 635 /// <summary>
@@ -594,9 +647,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
594 private void AttachToAgent( 647 private void AttachToAgent(
595 IScenePresence sp, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent) 648 IScenePresence sp, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
596 { 649 {
597 // m_log.DebugFormat( 650// m_log.DebugFormat(
598 // "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}", 651// "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}",
599 // so.Name, avatar.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos); 652// so.Name, sp.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos);
600 653
601 so.DetachFromBackup(); 654 so.DetachFromBackup();
602 655
@@ -627,6 +680,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
627 { 680 {
628 m_scene.SendKillObject(new List<uint> { so.RootPart.LocalId }); 681 m_scene.SendKillObject(new List<uint> { so.RootPart.LocalId });
629 } 682 }
683 else if (so.HasPrivateAttachmentPoint)
684 {
685// m_log.DebugFormat(
686// "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}",
687// so.Name, sp.Name, so.AttachmentPoint);
688
689 // As this scene object can now only be seen by the attaching avatar, tell everybody else in the
690 // scene that it's no longer in their awareness.
691 m_scene.ForEachClient(
692 client =>
693 { if (client.AgentId != so.AttachedAvatar)
694 client.SendKillObject(m_scene.RegionInfo.RegionHandle, new List<uint>() { so.LocalId });
695 });
696 }
630 697
631 so.IsSelected = false; // fudge.... 698 so.IsSelected = false; // fudge....
632 so.ScheduleGroupForFullUpdate(); 699 so.ScheduleGroupForFullUpdate();
@@ -645,6 +712,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
645 /// <returns>The user inventory item created that holds the attachment.</returns> 712 /// <returns>The user inventory item created that holds the attachment.</returns>
646 private InventoryItemBase AddSceneObjectAsNewAttachmentInInv(IScenePresence sp, SceneObjectGroup grp) 713 private InventoryItemBase AddSceneObjectAsNewAttachmentInInv(IScenePresence sp, SceneObjectGroup grp)
647 { 714 {
715 if (m_invAccessModule == null)
716 return null;
717
648 // m_log.DebugFormat( 718 // m_log.DebugFormat(
649 // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", 719 // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
650 // grp.Name, grp.LocalId, remoteClient.Name); 720 // grp.Name, grp.LocalId, remoteClient.Name);
@@ -721,16 +791,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
721 // sets itemID so client can show item as 'attached' in inventory 791 // sets itemID so client can show item as 'attached' in inventory
722 grp.FromItemID = item.ID; 792 grp.FromItemID = item.ID;
723 793
724 if (m_scene.AddInventoryItem(item))
725 {
726 sp.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
727 }
728 else
729 {
730 if (m_dialogModule != null)
731 m_dialogModule.SendAlertToUser(sp.ControllingClient, "Operation failed");
732 }
733
734 return item; 794 return item;
735 } 795 }
736 796
@@ -759,6 +819,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
759 { 819 {
760 m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero); 820 m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero);
761 sp.RemoveAttachment(group); 821 sp.RemoveAttachment(group);
822 m_scene.DeleteSceneObject(group, false);
762 823
763 // Prepare sog for storage 824 // Prepare sog for storage
764 group.AttachedAvatar = UUID.Zero; 825 group.AttachedAvatar = UUID.Zero;
@@ -767,7 +828,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
767 group.AbsolutePosition = group.RootPart.AttachedPos; 828 group.AbsolutePosition = group.RootPart.AttachedPos;
768 829
769 UpdateKnownItem(sp, group, true); 830 UpdateKnownItem(sp, group, true);
770 m_scene.DeleteSceneObject(group, false);
771 831
772 return; 832 return;
773 } 833 }
@@ -779,76 +839,75 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
779 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal( 839 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
780 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, XmlDocument doc) 840 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, XmlDocument doc)
781 { 841 {
782 IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>(); 842 if (m_invAccessModule == null)
783 if (invAccess != null) 843 return null;
844
845 lock (sp.AttachmentsSyncLock)
784 { 846 {
785 lock (sp.AttachmentsSyncLock) 847 SceneObjectGroup objatt;
786 {
787 SceneObjectGroup objatt;
788
789 if (itemID != UUID.Zero)
790 objatt = invAccess.RezObject(sp.ControllingClient,
791 itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
792 false, false, sp.UUID, true);
793 else
794 objatt = invAccess.RezObject(sp.ControllingClient,
795 null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
796 false, false, sp.UUID, true);
797
798 // m_log.DebugFormat(
799 // "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}",
800 // objatt.Name, remoteClient.Name, AttachmentPt);
801
802 if (objatt != null)
803 {
804 // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller.
805 objatt.HasGroupChanged = false;
806 bool tainted = false;
807 if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint)
808 tainted = true;
809
810 // This will throw if the attachment fails
811 try
812 {
813 AttachObject(sp, objatt, attachmentPt, false, false);
814 }
815 catch (Exception e)
816 {
817 m_log.ErrorFormat(
818 "[ATTACHMENTS MODULE]: Failed to attach {0} {1} for {2}, exception {3}{4}",
819 objatt.Name, objatt.UUID, sp.Name, e.Message, e.StackTrace);
820
821 // Make sure the object doesn't stick around and bail
822 sp.RemoveAttachment(objatt);
823 m_scene.DeleteSceneObject(objatt, false);
824 return null;
825 }
826
827 if (tainted)
828 objatt.HasGroupChanged = true;
829
830 if (doc != null)
831 {
832 objatt.LoadScriptState(doc);
833 objatt.ResetOwnerChangeFlag();
834 }
835 848
836 // Fire after attach, so we don't get messy perms dialogs 849 if (itemID != UUID.Zero)
837 // 4 == AttachedRez 850 objatt = m_invAccessModule.RezObject(sp.ControllingClient,
838 objatt.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4); 851 itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
839 objatt.ResumeScripts(); 852 false, false, sp.UUID, true);
840 853 else
841 // Do this last so that event listeners have access to all the effects of the attachment 854 objatt = m_invAccessModule.RezObject(sp.ControllingClient,
842 m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID); 855 null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
856 false, false, sp.UUID, true);
843 857
844 return objatt; 858// m_log.DebugFormat(
859// "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}",
860// objatt.Name, remoteClient.Name, AttachmentPt);
861
862 if (objatt != null)
863 {
864 // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller.
865 objatt.HasGroupChanged = false;
866 bool tainted = false;
867 if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint)
868 tainted = true;
869
870 // This will throw if the attachment fails
871 try
872 {
873 AttachObject(sp, objatt, attachmentPt, false, false);
845 } 874 }
846 else 875 catch (Exception e)
876 {
877 m_log.ErrorFormat(
878 "[ATTACHMENTS MODULE]: Failed to attach {0} {1} for {2}, exception {3}{4}",
879 objatt.Name, objatt.UUID, sp.Name, e.Message, e.StackTrace);
880
881 // Make sure the object doesn't stick around and bail
882 sp.RemoveAttachment(objatt);
883 m_scene.DeleteSceneObject(objatt, false);
884 return null;
885 }
886
887 if (tainted)
888 objatt.HasGroupChanged = true;
889
890 if (doc != null)
847 { 891 {
848 m_log.WarnFormat( 892 objatt.LoadScriptState(doc);
849 "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}", 893 objatt.ResetOwnerChangeFlag();
850 itemID, sp.Name, attachmentPt);
851 } 894 }
895
896 // Fire after attach, so we don't get messy perms dialogs
897 // 4 == AttachedRez
898 objatt.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4);
899 objatt.ResumeScripts();
900
901 // Do this last so that event listeners have access to all the effects of the attachment
902 m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID);
903
904 return objatt;
905 }
906 else
907 {
908 m_log.WarnFormat(
909 "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
910 itemID, sp.Name, attachmentPt);
852 } 911 }
853 } 912 }
854 913
@@ -864,9 +923,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
864 /// <param name="att"></param> 923 /// <param name="att"></param>
865 private void ShowAttachInUserInventory(IScenePresence sp, uint AttachmentPt, UUID itemID, SceneObjectGroup att) 924 private void ShowAttachInUserInventory(IScenePresence sp, uint AttachmentPt, UUID itemID, SceneObjectGroup att)
866 { 925 {
867 // m_log.DebugFormat( 926// m_log.DebugFormat(
868 // "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}", 927// "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}",
869 // att.Name, sp.Name, AttachmentPt, itemID); 928// att.Name, sp.Name, AttachmentPt, itemID);
870 929
871 if (UUID.Zero == itemID) 930 if (UUID.Zero == itemID)
872 { 931 {
@@ -929,9 +988,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
929 988
930 private void Client_OnObjectAttach(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) 989 private void Client_OnObjectAttach(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent)
931 { 990 {
932 // m_log.DebugFormat( 991// m_log.DebugFormat(
933 // "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})", 992// "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
934 // objectLocalID, remoteClient.Name, AttachmentPt, silent); 993// objectLocalID, remoteClient.Name, AttachmentPt, silent);
935 994
936 if (!Enabled) 995 if (!Enabled)
937 return; 996 return;
@@ -967,13 +1026,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
967 // Calls attach with a Zero position 1026 // Calls attach with a Zero position
968 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, true)) 1027 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, true))
969 { 1028 {
970 m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId); 1029// m_log.Debug(
1030// "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
1031// + ", AttachmentPoint: " + AttachmentPt);
971 1032
972 // Save avatar attachment information 1033 // Save avatar attachment information
973 m_log.Debug( 1034 m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId);
974 "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
975 + ", AttachmentPoint: " + AttachmentPt);
976
977 } 1035 }
978 } 1036 }
979 catch (Exception e) 1037 catch (Exception e)
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
index 7119ad2..1c10422 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
@@ -38,11 +38,14 @@ using OpenMetaverse;
38using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Framework.Communications; 39using OpenSim.Framework.Communications;
40using OpenSim.Region.CoreModules.Avatar.Attachments; 40using OpenSim.Region.CoreModules.Avatar.Attachments;
41using OpenSim.Region.CoreModules.Framework;
42using OpenSim.Region.CoreModules.Framework.EntityTransfer;
41using OpenSim.Region.CoreModules.Framework.InventoryAccess; 43using OpenSim.Region.CoreModules.Framework.InventoryAccess;
42using OpenSim.Region.CoreModules.World.Serialiser; 44using OpenSim.Region.CoreModules.World.Serialiser;
43using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; 45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
44using OpenSim.Region.Framework.Scenes; 46using OpenSim.Region.Framework.Scenes;
45using OpenSim.Region.Framework.Interfaces; 47using OpenSim.Region.Framework.Interfaces;
48using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common; 49using OpenSim.Tests.Common;
47using OpenSim.Tests.Common.Mock; 50using OpenSim.Tests.Common.Mock;
48 51
@@ -52,12 +55,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
52 /// Attachment tests 55 /// Attachment tests
53 /// </summary> 56 /// </summary>
54 [TestFixture] 57 [TestFixture]
55 public class AttachmentsModuleTests 58 public class AttachmentsModuleTests : OpenSimTestCase
56 { 59 {
57 private Scene scene;
58 private AttachmentsModule m_attMod;
59 private ScenePresence m_presence;
60
61 [TestFixtureSetUp] 60 [TestFixtureSetUp]
62 public void FixtureInit() 61 public void FixtureInit()
63 { 62 {
@@ -65,18 +64,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
65 Util.FireAndForgetMethod = FireAndForgetMethod.None; 64 Util.FireAndForgetMethod = FireAndForgetMethod.None;
66 } 65 }
67 66
68 [SetUp]
69 public void Init()
70 {
71 IConfigSource config = new IniConfigSource();
72 config.AddConfig("Modules");
73 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
74
75 scene = SceneHelpers.SetupScene();
76 m_attMod = new AttachmentsModule();
77 SceneHelpers.SetupSceneModules(scene, config, m_attMod, new BasicInventoryAccessModule());
78 }
79
80 [TestFixtureTearDown] 67 [TestFixtureTearDown]
81 public void TearDown() 68 public void TearDown()
82 { 69 {
@@ -85,32 +72,63 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
85 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; 72 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
86 } 73 }
87 74
75 private Scene CreateDefaultTestScene()
76 {
77 IConfigSource config = new IniConfigSource();
78 config.AddConfig("Modules");
79 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
80
81 Scene scene = new SceneHelpers().SetupScene();
82 SceneHelpers.SetupSceneModules(scene, config, new AttachmentsModule(), new BasicInventoryAccessModule());
83
84 return scene;
85 }
86
88 /// <summary> 87 /// <summary>
89 /// Add the standard presence for a test. 88 /// Creates an attachment item in the given user's inventory. Does not attach.
90 /// </summary> 89 /// </summary>
91 private void AddPresence() 90 /// <remarks>
91 /// A user with the given ID and an inventory must already exist.
92 /// </remarks>
93 /// <returns>
94 /// The attachment item.
95 /// </returns>
96 /// <param name='scene'></param>
97 /// <param name='userId'></param>
98 /// <param name='attName'></param>
99 /// <param name='rawItemId'></param>
100 /// <param name='rawAssetId'></param>
101 private InventoryItemBase CreateAttachmentItem(
102 Scene scene, UUID userId, string attName, int rawItemId, int rawAssetId)
92 { 103 {
93 UUID userId = TestHelpers.ParseTail(0x1); 104 return UserInventoryHelpers.CreateInventoryItem(
94 UserAccountHelpers.CreateUserWithInventory(scene, userId); 105 scene,
95 m_presence = SceneHelpers.AddScenePresence(scene, userId); 106 attName,
107 TestHelpers.ParseTail(rawItemId),
108 TestHelpers.ParseTail(rawAssetId),
109 userId,
110 InventoryType.Object);
96 } 111 }
97 112
98 [Test] 113 [Test]
99 public void TestAddAttachmentFromGround() 114 public void TestAddAttachmentFromGround()
100 { 115 {
101 TestHelpers.InMethod(); 116 TestHelpers.InMethod();
102// log4net.Config.XmlConfigurator.Configure(); 117// TestHelpers.EnableLogging();
118
119 Scene scene = CreateDefaultTestScene();
120 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
121 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
103 122
104 AddPresence();
105 string attName = "att"; 123 string attName = "att";
106 124
107 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; 125 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID).ParentGroup;
108 126
109 m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false, false); 127 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false);
110 128
111 // Check status on scene presence 129 // Check status on scene presence
112 Assert.That(m_presence.HasAttachments(), Is.True); 130 Assert.That(sp.HasAttachments(), Is.True);
113 List<SceneObjectGroup> attachments = m_presence.GetAttachments(); 131 List<SceneObjectGroup> attachments = sp.GetAttachments();
114 Assert.That(attachments.Count, Is.EqualTo(1)); 132 Assert.That(attachments.Count, Is.EqualTo(1));
115 SceneObjectGroup attSo = attachments[0]; 133 SceneObjectGroup attSo = attachments[0];
116 Assert.That(attSo.Name, Is.EqualTo(attName)); 134 Assert.That(attSo.Name, Is.EqualTo(attName));
@@ -121,8 +139,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
121 139
122 // Check item status 140 // Check item status
123 Assert.That( 141 Assert.That(
124 m_presence.Appearance.GetAttachpoint(attSo.FromItemID), 142 sp.Appearance.GetAttachpoint(attSo.FromItemID),
125 Is.EqualTo((int)AttachmentPoint.Chest)); 143 Is.EqualTo((int)AttachmentPoint.Chest));
144
145 InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID));
146 Assert.That(attachmentItem, Is.Not.Null);
147 Assert.That(attachmentItem.Name, Is.EqualTo(attName));
148
149 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object);
150 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
151
152// TestHelpers.DisableLogging();
126 } 153 }
127 154
128 [Test] 155 [Test]
@@ -131,32 +158,29 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
131 TestHelpers.InMethod(); 158 TestHelpers.InMethod();
132// log4net.Config.XmlConfigurator.Configure(); 159// log4net.Config.XmlConfigurator.Configure();
133 160
134 AddPresence(); 161 Scene scene = CreateDefaultTestScene();
162 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
163 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
135 164
136 UUID attItemId = TestHelpers.ParseTail(0x2); 165 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
137 UUID attAssetId = TestHelpers.ParseTail(0x3);
138 string attName = "att";
139
140 UserInventoryHelpers.CreateInventoryItem(
141 scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
142 166
143 m_attMod.RezSingleAttachmentFromInventory( 167 scene.AttachmentsModule.RezSingleAttachmentFromInventory(
144 m_presence, attItemId, (uint)AttachmentPoint.Chest); 168 sp, attItem.ID, (uint)AttachmentPoint.Chest);
145 169
146 // Check scene presence status 170 // Check scene presence status
147 Assert.That(m_presence.HasAttachments(), Is.True); 171 Assert.That(sp.HasAttachments(), Is.True);
148 List<SceneObjectGroup> attachments = m_presence.GetAttachments(); 172 List<SceneObjectGroup> attachments = sp.GetAttachments();
149 Assert.That(attachments.Count, Is.EqualTo(1)); 173 Assert.That(attachments.Count, Is.EqualTo(1));
150 SceneObjectGroup attSo = attachments[0]; 174 SceneObjectGroup attSo = attachments[0];
151 Assert.That(attSo.Name, Is.EqualTo(attName)); 175 Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
152 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); 176 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
153 Assert.That(attSo.IsAttachment); 177 Assert.That(attSo.IsAttachment);
154 Assert.That(attSo.UsesPhysics, Is.False); 178 Assert.That(attSo.UsesPhysics, Is.False);
155 Assert.That(attSo.IsTemporary, Is.False); 179 Assert.That(attSo.IsTemporary, Is.False);
156 180
157 // Check appearance status 181 // Check appearance status
158 Assert.That(m_presence.Appearance.GetAttachments().Count, Is.EqualTo(1)); 182 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
159 Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest)); 183 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
160 } 184 }
161 185
162 [Test] 186 [Test]
@@ -165,29 +189,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
165 TestHelpers.InMethod(); 189 TestHelpers.InMethod();
166// log4net.Config.XmlConfigurator.Configure(); 190// log4net.Config.XmlConfigurator.Configure();
167 191
168 AddPresence(); 192 Scene scene = CreateDefaultTestScene();
193 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
194 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
169 195
170 UUID attItemId = TestHelpers.ParseTail(0x2); 196 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
171 UUID attAssetId = TestHelpers.ParseTail(0x3);
172 string attName = "att";
173
174 UserInventoryHelpers.CreateInventoryItem(
175 scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
176 197
177 ISceneEntity so = m_attMod.RezSingleAttachmentFromInventory( 198 ISceneEntity so
178 m_presence, attItemId, (uint)AttachmentPoint.Chest); 199 = scene.AttachmentsModule.RezSingleAttachmentFromInventory(
179 m_attMod.DetachSingleAttachmentToGround(m_presence, so.LocalId); 200 sp, attItem.ID, (uint)AttachmentPoint.Chest);
201 scene.AttachmentsModule.DetachSingleAttachmentToGround(sp, so.LocalId);
180 202
181 // Check scene presence status 203 // Check scene presence status
182 Assert.That(m_presence.HasAttachments(), Is.False); 204 Assert.That(sp.HasAttachments(), Is.False);
183 List<SceneObjectGroup> attachments = m_presence.GetAttachments(); 205 List<SceneObjectGroup> attachments = sp.GetAttachments();
184 Assert.That(attachments.Count, Is.EqualTo(0)); 206 Assert.That(attachments.Count, Is.EqualTo(0));
185 207
186 // Check appearance status 208 // Check appearance status
187 Assert.That(m_presence.Appearance.GetAttachments().Count, Is.EqualTo(0)); 209 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(0));
188 210
189 // Check item status 211 // Check item status
190 Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Null); 212 Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItem.ID)), Is.Null);
191 213
192 // Check object in scene 214 // Check object in scene
193 Assert.That(scene.GetSceneObjectGroup("att"), Is.Not.Null); 215 Assert.That(scene.GetSceneObjectGroup("att"), Is.Not.Null);
@@ -199,26 +221,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
199 TestHelpers.InMethod(); 221 TestHelpers.InMethod();
200// log4net.Config.XmlConfigurator.Configure(); 222// log4net.Config.XmlConfigurator.Configure();
201 223
202 AddPresence(); 224 Scene scene = CreateDefaultTestScene();
203 225 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
204 UUID attItemId = TestHelpers.ParseTail(0x2); 226 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
205 UUID attAssetId = TestHelpers.ParseTail(0x3);
206 string attName = "att";
207 227
208 UserInventoryHelpers.CreateInventoryItem( 228 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
209 scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
210 229
211 m_attMod.RezSingleAttachmentFromInventory( 230 scene.AttachmentsModule.RezSingleAttachmentFromInventory(
212 m_presence, attItemId, (uint)AttachmentPoint.Chest); 231 sp, attItem.ID, (uint)AttachmentPoint.Chest);
213 m_attMod.DetachSingleAttachmentToInv(m_presence, attItemId); 232 scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, attItem.ID);
214 233
215 // Check status on scene presence 234 // Check status on scene presence
216 Assert.That(m_presence.HasAttachments(), Is.False); 235 Assert.That(sp.HasAttachments(), Is.False);
217 List<SceneObjectGroup> attachments = m_presence.GetAttachments(); 236 List<SceneObjectGroup> attachments = sp.GetAttachments();
218 Assert.That(attachments.Count, Is.EqualTo(0)); 237 Assert.That(attachments.Count, Is.EqualTo(0));
219 238
220 // Check item status 239 // Check item status
221 Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo(0)); 240 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo(0));
222 } 241 }
223 242
224 /// <summary> 243 /// <summary>
@@ -230,17 +249,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
230 TestHelpers.InMethod(); 249 TestHelpers.InMethod();
231// log4net.Config.XmlConfigurator.Configure(); 250// log4net.Config.XmlConfigurator.Configure();
232 251
233 UUID userId = TestHelpers.ParseTail(0x1); 252 Scene scene = CreateDefaultTestScene();
234 UUID attItemId = TestHelpers.ParseTail(0x2); 253 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
235 UUID attAssetId = TestHelpers.ParseTail(0x3); 254 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
236 string attName = "att";
237
238 UserAccountHelpers.CreateUserWithInventory(scene, userId);
239 InventoryItemBase attItem
240 = UserInventoryHelpers.CreateInventoryItem(
241 scene, attName, attItemId, attAssetId, userId, InventoryType.Object);
242 255
243 AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); 256 AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
244 acd.Appearance = new AvatarAppearance(); 257 acd.Appearance = new AvatarAppearance();
245 acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID); 258 acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
246 ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd); 259 ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd);
@@ -259,17 +272,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
259 TestHelpers.InMethod(); 272 TestHelpers.InMethod();
260// log4net.Config.XmlConfigurator.Configure(); 273// log4net.Config.XmlConfigurator.Configure();
261 274
262 UUID userId = TestHelpers.ParseTail(0x1); 275 Scene scene = CreateDefaultTestScene();
263 UUID attItemId = TestHelpers.ParseTail(0x2); 276 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
264 UUID attAssetId = TestHelpers.ParseTail(0x3); 277 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
265 string attName = "att";
266 278
267 UserAccountHelpers.CreateUserWithInventory(scene, userId); 279 AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
268 InventoryItemBase attItem
269 = UserInventoryHelpers.CreateInventoryItem(
270 scene, attName, attItemId, attAssetId, userId, InventoryType.Object);
271
272 AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
273 acd.Appearance = new AvatarAppearance(); 280 acd.Appearance = new AvatarAppearance();
274 acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID); 281 acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
275 ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd); 282 ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd);
@@ -279,7 +286,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
279 286
280 Assert.That(attachments.Count, Is.EqualTo(1)); 287 Assert.That(attachments.Count, Is.EqualTo(1));
281 SceneObjectGroup attSo = attachments[0]; 288 SceneObjectGroup attSo = attachments[0];
282 Assert.That(attSo.Name, Is.EqualTo(attName)); 289 Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
283 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); 290 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
284 Assert.That(attSo.IsAttachment); 291 Assert.That(attSo.IsAttachment);
285 Assert.That(attSo.UsesPhysics, Is.False); 292 Assert.That(attSo.UsesPhysics, Is.False);
@@ -289,9 +296,119 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
289 List<AvatarAttachment> retreivedAttachments = presence.Appearance.GetAttachments(); 296 List<AvatarAttachment> retreivedAttachments = presence.Appearance.GetAttachments();
290 Assert.That(retreivedAttachments.Count, Is.EqualTo(1)); 297 Assert.That(retreivedAttachments.Count, Is.EqualTo(1));
291 Assert.That(retreivedAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest)); 298 Assert.That(retreivedAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
292 Assert.That(retreivedAttachments[0].ItemID, Is.EqualTo(attItemId)); 299 Assert.That(retreivedAttachments[0].ItemID, Is.EqualTo(attItem.ID));
293 Assert.That(retreivedAttachments[0].AssetID, Is.EqualTo(attAssetId)); 300 Assert.That(retreivedAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
294 Assert.That(presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest)); 301 Assert.That(presence.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
302 }
303
304 [Test]
305 public void TestUpdateAttachmentPosition()
306 {
307 TestHelpers.InMethod();
308
309 Scene scene = CreateDefaultTestScene();
310 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
311 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
312
313 AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
314 acd.Appearance = new AvatarAppearance();
315 acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
316 ScenePresence sp = SceneHelpers.AddScenePresence(scene, acd);
317
318 SceneObjectGroup attSo = sp.GetAttachments()[0];
319
320 Vector3 newPosition = new Vector3(1, 2, 4);
321
322 scene.SceneGraph.UpdatePrimGroupPosition(attSo.LocalId, newPosition, sp.ControllingClient);
323
324 Assert.That(attSo.AbsolutePosition, Is.EqualTo(sp.AbsolutePosition));
325 Assert.That(attSo.RootPart.AttachedPos, Is.EqualTo(newPosition));
326 }
327
328 [Test]
329 public void TestSameSimulatorNeighbouringRegionsTeleport()
330 {
331 TestHelpers.InMethod();
332// TestHelpers.EnableLogging();
333
334 AttachmentsModule attModA = new AttachmentsModule();
335 AttachmentsModule attModB = new AttachmentsModule();
336 EntityTransferModule etmA = new EntityTransferModule();
337 EntityTransferModule etmB = new EntityTransferModule();
338 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
339
340 IConfigSource config = new IniConfigSource();
341 IConfig modulesConfig = config.AddConfig("Modules");
342 modulesConfig.Set("EntityTransferModule", etmA.Name);
343 modulesConfig.Set("SimulationServices", lscm.Name);
344 IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
345
346 // In order to run a single threaded regression test we do not want the entity transfer module waiting
347 // for a callback from the destination scene before removing its avatar data.
348 entityTransferConfig.Set("wait_for_callback", false);
349
350 modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
351
352 SceneHelpers sh = new SceneHelpers();
353 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
354 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
355
356 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
357 SceneHelpers.SetupSceneModules(
358 sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule());
359 SceneHelpers.SetupSceneModules(
360 sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule());
361
362 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1);
363 ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, ua1.PrincipalID, sh.SceneManager);
364 beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32);
365
366 InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20);
367
368 sceneA.AttachmentsModule.RezSingleAttachmentFromInventory(
369 beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest);
370
371 Vector3 teleportPosition = new Vector3(10, 11, 12);
372 Vector3 teleportLookAt = new Vector3(20, 21, 22);
373
374 sceneA.RequestTeleportLocation(
375 beforeTeleportSp.ControllingClient,
376 sceneB.RegionInfo.RegionHandle,
377 teleportPosition,
378 teleportLookAt,
379 (uint)TeleportFlags.ViaLocation);
380
381 ((TestClient)beforeTeleportSp.ControllingClient).CompleteTeleportClientSide();
382
383 // Check attachments have made it into sceneB
384 ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID);
385
386 // This is appearance data, as opposed to actually rezzed attachments
387 List<AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments();
388 Assert.That(sceneBAttachments.Count, Is.EqualTo(1));
389 Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
390 Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID));
391 Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
392 Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
393
394 // This is the actual attachment
395 List<SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments();
396 Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1));
397 SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0];
398 Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
399 Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
400
401 // Check attachments have been removed from sceneA
402 ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID);
403
404 // Since this is appearance data, it is still present on the child avatar!
405 List<AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments();
406 Assert.That(sceneAAttachments.Count, Is.EqualTo(1));
407 Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
408
409 // This is the actual attachment, which should no longer exist
410 List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments();
411 Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0));
295 } 412 }
296 413
297 // I'm commenting this test because scene setup NEEDS InventoryService to 414 // I'm commenting this test because scene setup NEEDS InventoryService to
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index 2bebd30..89cc4f6 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -128,7 +128,9 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
128 /// <param name="visualParam"></param> 128 /// <param name="visualParam"></param>
129 public void SetAppearance(IScenePresence sp, Primitive.TextureEntry textureEntry, byte[] visualParams) 129 public void SetAppearance(IScenePresence sp, Primitive.TextureEntry textureEntry, byte[] visualParams)
130 { 130 {
131 // m_log.InfoFormat("[AVFACTORY]: start SetAppearance for {0}", client.AgentId); 131// m_log.DebugFormat(
132// "[AVFACTORY]: start SetAppearance for {0}, te {1}, visualParams {2}",
133// sp.Name, textureEntry, visualParams);
132 134
133 // TODO: This is probably not necessary any longer, just assume the 135 // TODO: This is probably not necessary any longer, just assume the
134 // textureEntry set implies that the appearance transaction is complete 136 // textureEntry set implies that the appearance transaction is complete
@@ -158,7 +160,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
158 // Process the baked texture array 160 // Process the baked texture array
159 if (textureEntry != null) 161 if (textureEntry != null)
160 { 162 {
161 m_log.InfoFormat("[AVFACTORY]: Received texture update for {0} {1}", sp.Name, sp.UUID); 163// m_log.DebugFormat("[AVFACTORY]: Received texture update for {0} {1}", sp.Name, sp.UUID);
162 164
163// WriteBakedTexturesReport(sp, m_log.DebugFormat); 165// WriteBakedTexturesReport(sp, m_log.DebugFormat);
164 166
@@ -208,7 +210,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
208 ScenePresence sp = m_scene.GetScenePresence(agentId); 210 ScenePresence sp = m_scene.GetScenePresence(agentId);
209 if (sp == null) 211 if (sp == null)
210 { 212 {
211 m_log.WarnFormat("[AVFACTORY]: Agent {0} no longer in the scene", agentId); 213 // This is expected if the user has gone away.
214// m_log.DebugFormat("[AVFACTORY]: Agent {0} no longer in the scene", agentId);
212 return false; 215 return false;
213 } 216 }
214 217
@@ -248,10 +251,10 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
248 251
249 if (bakedTextureFace == null) 252 if (bakedTextureFace == null)
250 { 253 {
251 m_log.WarnFormat( 254 // This can happen legitimately, since some baked textures might not exist
252 "[AV FACTORY]: No texture ID set for {0} for {1} in {2} not found when trying to save permanently", 255 //m_log.WarnFormat(
253 bakeType, sp.Name, m_scene.RegionInfo.RegionName); 256 // "[AV FACTORY]: No texture ID set for {0} for {1} in {2} not found when trying to save permanently",
254 257 // bakeType, sp.Name, m_scene.RegionInfo.RegionName);
255 continue; 258 continue;
256 } 259 }
257 260
@@ -337,7 +340,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
337 return false; 340 return false;
338 } 341 }
339 342
340 m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1}", sp.Name, sp.UUID); 343// m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1}", sp.Name, sp.UUID);
341 344
342 // If we only found default textures, then the appearance is not cached 345 // If we only found default textures, then the appearance is not cached
343 return (defonly ? false : true); 346 return (defonly ? false : true);
@@ -370,11 +373,21 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
370 if (missingTexturesOnly) 373 if (missingTexturesOnly)
371 { 374 {
372 if (m_scene.AssetService.Get(face.TextureID.ToString()) != null) 375 if (m_scene.AssetService.Get(face.TextureID.ToString()) != null)
376 {
373 continue; 377 continue;
378 }
374 else 379 else
380 {
381 // On inter-simulator teleports, this occurs if baked textures are not being stored by the
382 // grid asset service (which means that they are not available to the new region and so have
383 // to be re-requested from the client).
384 //
385 // The only available core OpenSimulator behaviour right now
386 // is not to store these textures, temporarily or otherwise.
375 m_log.DebugFormat( 387 m_log.DebugFormat(
376 "[AVFACTORY]: Missing baked texture {0} ({1}) for {2}, requesting rebake.", 388 "[AVFACTORY]: Missing baked texture {0} ({1}) for {2}, requesting rebake.",
377 face.TextureID, idx, sp.Name); 389 face.TextureID, idx, sp.Name);
390 }
378 } 391 }
379 else 392 else
380 { 393 {
@@ -417,7 +430,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
417// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); 430// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]);
418 431
419 int ftIndex = (int)AppearanceManager.BakeTypeToAgentTextureIndex(bakeType); 432 int ftIndex = (int)AppearanceManager.BakeTypeToAgentTextureIndex(bakeType);
420 bakedTextures[bakeType] = faceTextures[ftIndex]; 433 Primitive.TextureEntryFace texture = faceTextures[ftIndex]; // this will be null if there's no such baked texture
434 bakedTextures[bakeType] = texture;
421 } 435 }
422 436
423 return bakedTextures; 437 return bakedTextures;
@@ -482,7 +496,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
482 ScenePresence sp = m_scene.GetScenePresence(agentid); 496 ScenePresence sp = m_scene.GetScenePresence(agentid);
483 if (sp == null) 497 if (sp == null)
484 { 498 {
485 m_log.WarnFormat("[AVFACTORY]: Agent {0} no longer in the scene", agentid); 499 // This is expected if the user has gone away.
500// m_log.DebugFormat("[AVFACTORY]: Agent {0} no longer in the scene", agentid);
486 return; 501 return;
487 } 502 }
488 503
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs
index 11a0a86..848b3bf 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
53 UUID userId = TestHelpers.ParseTail(0x1); 53 UUID userId = TestHelpers.ParseTail(0x1);
54 54
55 AvatarFactoryModule afm = new AvatarFactoryModule(); 55 AvatarFactoryModule afm = new AvatarFactoryModule();
56 TestScene scene = SceneHelpers.SetupScene(); 56 TestScene scene = new SceneHelpers().SetupScene();
57 SceneHelpers.SetupSceneModules(scene, afm); 57 SceneHelpers.SetupSceneModules(scene, afm);
58 ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId); 58 ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
59 59
@@ -81,7 +81,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
81 CoreAssetCache assetCache = new CoreAssetCache(); 81 CoreAssetCache assetCache = new CoreAssetCache();
82 82
83 AvatarFactoryModule afm = new AvatarFactoryModule(); 83 AvatarFactoryModule afm = new AvatarFactoryModule();
84 TestScene scene = SceneHelpers.SetupScene(assetCache); 84 TestScene scene = new SceneHelpers(assetCache).SetupScene();
85 SceneHelpers.SetupSceneModules(scene, afm); 85 SceneHelpers.SetupSceneModules(scene, afm);
86 ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId); 86 ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
87 87
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
index 357c2af..bc42fd1 100644
--- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
@@ -266,7 +266,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
266 receiverIDs.Add(presence.UUID); 266 receiverIDs.Add(presence.UUID);
267 } 267 }
268 } 268 }
269
270 } 269 }
271 ); 270 );
272 } 271 }
diff --git a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs
index 0babeb5..3a91465 100644
--- a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs
@@ -96,6 +96,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
96 ScenePresence killingAvatar = null; 96 ScenePresence killingAvatar = null;
97// string killingAvatarMessage; 97// string killingAvatarMessage;
98 98
99 // check to see if it is an NPC and just remove it
100 INPCModule NPCmodule = deadAvatar.Scene.RequestModuleInterface<INPCModule>();
101 if (NPCmodule != null && NPCmodule.DeleteNPC(deadAvatar.UUID, deadAvatar.Scene))
102 {
103 return;
104 }
105
99 if (killerObjectLocalID == 0) 106 if (killerObjectLocalID == 0)
100 deadAvatarMessage = "You committed suicide!"; 107 deadAvatarMessage = "You committed suicide!";
101 else 108 else
@@ -145,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
145 catch (InvalidOperationException) 152 catch (InvalidOperationException)
146 { } 153 { }
147 154
148 deadAvatar.Health = 100; 155 deadAvatar.setHealthWithUpdate(100.0f);
149 deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient); 156 deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient);
150 } 157 }
151 158
@@ -154,14 +161,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
154 try 161 try
155 { 162 {
156 ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 163 ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
157 164 if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0
158 if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0) 165 || avatar.Scene.RegionInfo.RegionSettings.AllowDamage)
159 { 166 {
160 avatar.Invulnerable = false; 167 avatar.Invulnerable = false;
161 } 168 }
162 else 169 else
163 { 170 {
164 avatar.Invulnerable = true; 171 avatar.Invulnerable = true;
172 if (avatar.Health < 100.0f)
173 {
174 avatar.setHealthWithUpdate(100.0f);
175 }
165 } 176 }
166 } 177 }
167 catch (Exception) 178 catch (Exception)
diff --git a/OpenSim/Region/CoreModules/Avatar/Commands/UserCommandsModule.cs b/OpenSim/Region/CoreModules/Avatar/Commands/UserCommandsModule.cs
new file mode 100644
index 0000000..4bcd2ac
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Commands/UserCommandsModule.cs
@@ -0,0 +1,189 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Text.RegularExpressions;
33using log4net;
34using Mono.Addins;
35using NDesk.Options;
36using Nini.Config;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Statistics;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43
44namespace OpenSim.Region.CoreModules.Avatars.Commands
45{
46 /// <summary>
47 /// A module that holds commands for manipulating objects in the scene.
48 /// </summary>
49 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserCommandsModule")]
50 public class UserCommandsModule : ISharedRegionModule
51 {
52// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 public const string TeleportUserCommandSyntax = "teleport user <first-name> <last-name> <destination>";
55
56 public static Regex InterRegionDestinationRegex
57 = new Regex(@"^(?<regionName>.+)/(?<x>\d+)/(?<y>\d+)/(?<z>\d+)$", RegexOptions.Compiled);
58
59 public static Regex WithinRegionDestinationRegex
60 = new Regex(@"^(?<x>\d+)/(?<y>\d+)/(?<z>\d+)$", RegexOptions.Compiled);
61
62 private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
63
64 public string Name { get { return "User Commands Module"; } }
65
66 public Type ReplaceableInterface { get { return null; } }
67
68 public void Initialise(IConfigSource source)
69 {
70// m_log.DebugFormat("[USER COMMANDS MODULE]: INITIALIZED MODULE");
71 }
72
73 public void PostInitialise()
74 {
75// m_log.DebugFormat("[USER COMMANDS MODULE]: POST INITIALIZED MODULE");
76 }
77
78 public void Close()
79 {
80// m_log.DebugFormat("[USER COMMANDS MODULE]: CLOSED MODULE");
81 }
82
83 public void AddRegion(Scene scene)
84 {
85// m_log.DebugFormat("[USER COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
86
87 lock (m_scenes)
88 m_scenes[scene.RegionInfo.RegionID] = scene;
89
90 scene.AddCommand(
91 "Users",
92 this,
93 "teleport user",
94 TeleportUserCommandSyntax,
95 "Teleport a user in this simulator to the given destination",
96 "<destination> is in format [<region-name>]/<x>/<y>/<z>, e.g. regionone/20/30/40 or just 20/30/40 to teleport within same region."
97 + "\nIf the region contains a space then the whole destination must be in quotes, e.g. \"region one/20/30/40\"",
98 HandleTeleportUser);
99 }
100
101 public void RemoveRegion(Scene scene)
102 {
103// m_log.DebugFormat("[USER COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
104
105 lock (m_scenes)
106 m_scenes.Remove(scene.RegionInfo.RegionID);
107 }
108
109 public void RegionLoaded(Scene scene)
110 {
111// m_log.DebugFormat("[USER COMMANDS MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
112 }
113
114 private ScenePresence GetUser(string firstName, string lastName)
115 {
116 ScenePresence userFound = null;
117
118 lock (m_scenes)
119 {
120 foreach (Scene scene in m_scenes.Values)
121 {
122 ScenePresence user = scene.GetScenePresence(firstName, lastName);
123 if (user != null && !user.IsChildAgent)
124 {
125 userFound = user;
126 break;
127 }
128 }
129 }
130
131 return userFound;
132 }
133
134 private void HandleTeleportUser(string module, string[] cmd)
135 {
136 if (cmd.Length < 5)
137 {
138 MainConsole.Instance.OutputFormat("Usage: " + TeleportUserCommandSyntax);
139 return;
140 }
141
142 string firstName = cmd[2];
143 string lastName = cmd[3];
144 string rawDestination = cmd[4];
145
146 ScenePresence user = GetUser(firstName, lastName);
147
148 if (user == null)
149 {
150 MainConsole.Instance.OutputFormat("No user found with name {0} {1}", firstName, lastName);
151 return;
152 }
153
154// MainConsole.Instance.OutputFormat("rawDestination [{0}]", rawDestination);
155
156 Match m = WithinRegionDestinationRegex.Match(rawDestination);
157
158 if (!m.Success)
159 {
160 m = InterRegionDestinationRegex.Match(rawDestination);
161
162 if (!m.Success)
163 {
164 MainConsole.Instance.OutputFormat("Invalid destination {0}", rawDestination);
165 return;
166 }
167 }
168
169 string regionName
170 = m.Groups["regionName"].Success ? m.Groups["regionName"].Value : user.Scene.RegionInfo.RegionName;
171
172 MainConsole.Instance.OutputFormat(
173 "Teleporting {0} to {1},{2},{3} in {4}",
174 user.Name,
175 m.Groups["x"], m.Groups["y"], m.Groups["z"],
176 regionName);
177
178 user.Scene.RequestTeleportLocation(
179 user.ControllingClient,
180 regionName,
181 new Vector3(
182 float.Parse(m.Groups["x"].Value),
183 float.Parse(m.Groups["y"].Value),
184 float.Parse(m.Groups["z"].Value)),
185 user.Lookat,
186 (uint)TeleportFlags.ViaLocation);
187 }
188 }
189} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index f64c161..24ec435 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -162,7 +162,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
162 } 162 }
163 } 163 }
164 164
165 protected void InitModule(IConfigSource config) 165 protected virtual void InitModule(IConfigSource config)
166 { 166 {
167 IConfig friendsConfig = config.Configs["Friends"]; 167 IConfig friendsConfig = config.Configs["Friends"];
168 if (friendsConfig != null) 168 if (friendsConfig != null)
@@ -449,29 +449,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
449 /// </summary> 449 /// </summary>
450 public IClientAPI LocateClientObject(UUID agentID) 450 public IClientAPI LocateClientObject(UUID agentID)
451 { 451 {
452 Scene scene = GetClientScene(agentID);
453 if (scene != null)
454 {
455 ScenePresence presence = scene.GetScenePresence(agentID);
456 if (presence != null)
457 return presence.ControllingClient;
458 }
459
460 return null;
461 }
462
463 /// <summary>
464 /// Find the scene for an agent
465 /// </summary>
466 private Scene GetClientScene(UUID agentId)
467 {
468 lock (m_Scenes) 452 lock (m_Scenes)
469 { 453 {
470 foreach (Scene scene in m_Scenes) 454 foreach (Scene scene in m_Scenes)
471 { 455 {
472 ScenePresence presence = scene.GetScenePresence(agentId); 456 ScenePresence presence = scene.GetScenePresence(agentID);
473 if (presence != null && !presence.IsChildAgent) 457 if (presence != null && !presence.IsChildAgent)
474 return scene; 458 return presence.ControllingClient;
475 } 459 }
476 } 460 }
477 461
@@ -498,7 +482,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
498 Util.FireAndForget( 482 Util.FireAndForget(
499 delegate 483 delegate
500 { 484 {
501 m_log.DebugFormat("[FRIENDS MODULE]: Notifying {0} friends", friendList.Count); 485 m_log.DebugFormat(
486 "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}",
487 friendList.Count, agentID, online);
488
502 // Notify about this user status 489 // Notify about this user status
503 StatusNotify(friendList, agentID, online); 490 StatusNotify(friendList, agentID, online);
504 } 491 }
@@ -515,7 +502,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
515 { 502 {
516 // Try local 503 // Try local
517 if (LocalStatusNotification(userID, friendID, online)) 504 if (LocalStatusNotification(userID, friendID, online))
518 return; 505 continue;
519 506
520 // The friend is not here [as root]. Let's forward. 507 // The friend is not here [as root]. Let's forward.
521 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 508 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
@@ -523,11 +510,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
523 { 510 {
524 PresenceInfo friendSession = null; 511 PresenceInfo friendSession = null;
525 foreach (PresenceInfo pinfo in friendSessions) 512 foreach (PresenceInfo pinfo in friendSessions)
513 {
526 if (pinfo.RegionID != UUID.Zero) // let's guard against sessions-gone-bad 514 if (pinfo.RegionID != UUID.Zero) // let's guard against sessions-gone-bad
527 { 515 {
528 friendSession = pinfo; 516 friendSession = pinfo;
529 break; 517 break;
530 } 518 }
519 }
531 520
532 if (friendSession != null) 521 if (friendSession != null)
533 { 522 {
@@ -546,7 +535,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
546 } 535 }
547 } 536 }
548 537
549 private void OnInstantMessage(IClientAPI client, GridInstantMessage im) 538 protected virtual void OnInstantMessage(IClientAPI client, GridInstantMessage im)
550 { 539 {
551 if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) 540 if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered)
552 { 541 {
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
index 9a6d277..06f27e2 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -50,6 +50,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
50 { 50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 52
53 private int m_levelHGFriends = 0;
54
53 IUserManagement m_uMan; 55 IUserManagement m_uMan;
54 public IUserManagement UserManagementModule 56 public IUserManagement UserManagementModule
55 { 57 {
@@ -87,6 +89,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
87 m_StatusNotifier = new HGStatusNotifier(this); 89 m_StatusNotifier = new HGStatusNotifier(this);
88 } 90 }
89 91
92 protected override void InitModule(IConfigSource config)
93 {
94 base.InitModule(config);
95
96 // Additionally to the base method
97 IConfig friendsConfig = config.Configs["HGFriendsModule"];
98 if (friendsConfig != null)
99 {
100 m_levelHGFriends = friendsConfig.GetInt("LevelHGFriends", 0);
101
102 // TODO: read in all config variables pertaining to
103 // HG friendship permissions
104 }
105 }
106
90 #endregion 107 #endregion
91 108
92 #region IFriendsSimConnector 109 #region IFriendsSimConnector
@@ -105,6 +122,35 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
105 122
106 #endregion 123 #endregion
107 124
125 protected override void OnInstantMessage(IClientAPI client, GridInstantMessage im)
126 {
127 if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered)
128 {
129 // we got a friendship offer
130 UUID principalID = new UUID(im.fromAgentID);
131 UUID friendID = new UUID(im.toAgentID);
132
133 // Check if friendID is foreigner and if principalID has the permission
134 // to request friendships with foreigners. If not, return immediately.
135 if (!UserManagementModule.IsLocalGridUser(friendID))
136 {
137 ScenePresence avatar = null;
138 ((Scene)client.Scene).TryGetScenePresence(principalID, out avatar);
139
140 if (avatar == null)
141 return;
142
143 if (avatar.UserLevel < m_levelHGFriends)
144 {
145 client.SendAgentAlertMessage("Unable to send friendship invitation to foreigner. Insufficient permissions.", false);
146 return;
147 }
148 }
149 }
150
151 base.OnInstantMessage(client, im);
152 }
153
108 protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders) 154 protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
109 { 155 {
110 // Update the local cache. Yes, we need to do it right here 156 // Update the local cache. Yes, we need to do it right here
@@ -369,12 +415,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
369 415
370 protected override void StoreBackwards(UUID friendID, UUID agentID) 416 protected override void StoreBackwards(UUID friendID, UUID agentID)
371 { 417 {
372 Boolean agentIsLocal = true; 418 bool agentIsLocal = true;
373 Boolean friendIsLocal = true; 419// bool friendIsLocal = true;
420
374 if (UserManagementModule != null) 421 if (UserManagementModule != null)
375 { 422 {
376 agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); 423 agentIsLocal = UserManagementModule.IsLocalGridUser(agentID);
377 friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); 424// friendIsLocal = UserManagementModule.IsLocalGridUser(friendID);
378 } 425 }
379 426
380 // Is the requester a local user? 427 // Is the requester a local user?
@@ -461,7 +508,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
461 { 508 {
462 friendUUI = finfo.Friend; 509 friendUUI = finfo.Friend;
463 theFriendUUID = friendUUI; 510 theFriendUUID = friendUUI;
464 UUID utmp = UUID.Zero; String url = String.Empty; String first = String.Empty, last = String.Empty, tmp = String.Empty; 511 UUID utmp = UUID.Zero;
512 string url = String.Empty;
513 string first = String.Empty;
514 string last = String.Empty;
515
465 // If it's confirming the friendship, we already have the full UUI with the secret 516 // If it's confirming the friendship, we already have the full UUI with the secret
466 if (Util.ParseUniversalUserIdentifier(theFriendUUID, out utmp, out url, out first, out last, out secret)) 517 if (Util.ParseUniversalUserIdentifier(theFriendUUID, out utmp, out url, out first, out last, out secret))
467 { 518 {
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
index 45b4264..7a197f7 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
@@ -78,7 +78,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
78 config.AddConfig("FriendsService"); 78 config.AddConfig("FriendsService");
79 config.Configs["FriendsService"].Set("StorageProvider", "OpenSim.Data.Null.dll"); 79 config.Configs["FriendsService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
80 80
81 m_scene = SceneHelpers.SetupScene(); 81 m_scene = new SceneHelpers().SetupScene();
82 m_fm = new FriendsModule(); 82 m_fm = new FriendsModule();
83 SceneHelpers.SetupSceneModules(m_scene, config, m_fm); 83 SceneHelpers.SetupSceneModules(m_scene, config, m_fm);
84 } 84 }
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
index 8560c73..6587ead 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
@@ -39,6 +39,9 @@ using OpenSim.Framework.Serialization.External;
39using OpenSim.Region.CoreModules.World.Archiver; 39using OpenSim.Region.CoreModules.World.Archiver;
40using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Services.Interfaces; 41using OpenSim.Services.Interfaces;
42using Ionic.Zlib;
43using GZipStream = Ionic.Zlib.GZipStream;
44using CompressionMode = Ionic.Zlib.CompressionMode;
42 45
43namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver 46namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
44{ 47{
@@ -91,7 +94,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
91 /// Constructor 94 /// Constructor
92 /// </summary> 95 /// </summary>
93 public InventoryArchiveWriteRequest( 96 public InventoryArchiveWriteRequest(
94 Guid id, InventoryArchiverModule module, Scene scene, 97 Guid id, InventoryArchiverModule module, Scene scene,
95 UserAccount userInfo, string invPath, string savePath) 98 UserAccount userInfo, string invPath, string savePath)
96 : this( 99 : this(
97 id, 100 id,
@@ -99,7 +102,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
99 scene, 102 scene,
100 userInfo, 103 userInfo,
101 invPath, 104 invPath,
102 new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress)) 105 new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress, CompressionLevel.BestCompression))
103 { 106 {
104 } 107 }
105 108
@@ -107,7 +110,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
107 /// Constructor 110 /// Constructor
108 /// </summary> 111 /// </summary>
109 public InventoryArchiveWriteRequest( 112 public InventoryArchiveWriteRequest(
110 Guid id, InventoryArchiverModule module, Scene scene, 113 Guid id, InventoryArchiverModule module, Scene scene,
111 UserAccount userInfo, string invPath, Stream saveStream) 114 UserAccount userInfo, string invPath, Stream saveStream)
112 { 115 {
113 m_id = id; 116 m_id = id;
@@ -125,7 +128,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
125 { 128 {
126 Exception reportedException = null; 129 Exception reportedException = null;
127 bool succeeded = true; 130 bool succeeded = true;
128 131
129 try 132 try
130 { 133 {
131 m_archiveWriter.Close(); 134 m_archiveWriter.Close();
@@ -146,6 +149,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
146 149
147 protected void SaveInvItem(InventoryItemBase inventoryItem, string path, Dictionary<string, object> options, IUserAccountService userAccountService) 150 protected void SaveInvItem(InventoryItemBase inventoryItem, string path, Dictionary<string, object> options, IUserAccountService userAccountService)
148 { 151 {
152 if (options.ContainsKey("exclude"))
153 {
154 if (((List<String>)options["exclude"]).Contains(inventoryItem.Name) ||
155 ((List<String>)options["exclude"]).Contains(inventoryItem.ID.ToString()))
156 {
157 if (options.ContainsKey("verbose"))
158 {
159 m_log.InfoFormat(
160 "[INVENTORY ARCHIVER]: Skipping inventory item {0} {1} at {2}",
161 inventoryItem.Name, inventoryItem.ID, path);
162 }
163 return;
164 }
165 }
166
149 if (options.ContainsKey("verbose")) 167 if (options.ContainsKey("verbose"))
150 m_log.InfoFormat( 168 m_log.InfoFormat(
151 "[INVENTORY ARCHIVER]: Saving item {0} {1} with asset {2}", 169 "[INVENTORY ARCHIVER]: Saving item {0} {1} with asset {2}",
@@ -175,9 +193,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
175 /// <param name="options"></param> 193 /// <param name="options"></param>
176 /// <param name="userAccountService"></param> 194 /// <param name="userAccountService"></param>
177 protected void SaveInvFolder( 195 protected void SaveInvFolder(
178 InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself, 196 InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself,
179 Dictionary<string, object> options, IUserAccountService userAccountService) 197 Dictionary<string, object> options, IUserAccountService userAccountService)
180 { 198 {
199 if (options.ContainsKey("excludefolders"))
200 {
201 if (((List<String>)options["excludefolders"]).Contains(inventoryFolder.Name) ||
202 ((List<String>)options["excludefolders"]).Contains(inventoryFolder.ID.ToString()))
203 {
204 if (options.ContainsKey("verbose"))
205 {
206 m_log.InfoFormat(
207 "[INVENTORY ARCHIVER]: Skipping folder {0} at {1}",
208 inventoryFolder.Name, path);
209 }
210 return;
211 }
212 }
213
214 if (options.ContainsKey("verbose"))
215 m_log.InfoFormat("[INVENTORY ARCHIVER]: Saving folder {0}", inventoryFolder.Name);
216
181 if (saveThisFolderItself) 217 if (saveThisFolderItself)
182 { 218 {
183 path += CreateArchiveFolderName(inventoryFolder); 219 path += CreateArchiveFolderName(inventoryFolder);
@@ -186,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
186 m_archiveWriter.WriteDir(path); 222 m_archiveWriter.WriteDir(path);
187 } 223 }
188 224
189 InventoryCollection contents 225 InventoryCollection contents
190 = m_scene.InventoryService.GetFolderContent(inventoryFolder.Owner, inventoryFolder.ID); 226 = m_scene.InventoryService.GetFolderContent(inventoryFolder.Owner, inventoryFolder.ID);
191 227
192 foreach (InventoryFolderBase childFolder in contents.Folders) 228 foreach (InventoryFolderBase childFolder in contents.Folders)
@@ -213,16 +249,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
213 InventoryFolderBase inventoryFolder = null; 249 InventoryFolderBase inventoryFolder = null;
214 InventoryItemBase inventoryItem = null; 250 InventoryItemBase inventoryItem = null;
215 InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.PrincipalID); 251 InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.PrincipalID);
216 252
217 bool saveFolderContentsOnly = false; 253 bool saveFolderContentsOnly = false;
218 254
219 // Eliminate double slashes and any leading / on the path. 255 // Eliminate double slashes and any leading / on the path.
220 string[] components 256 string[] components
221 = m_invPath.Split( 257 = m_invPath.Split(
222 new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); 258 new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);
223 259
224 int maxComponentIndex = components.Length - 1; 260 int maxComponentIndex = components.Length - 1;
225 261
226 // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the 262 // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the
227 // folder itself. This may get more sophisicated later on 263 // folder itself. This may get more sophisicated later on
228 if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD) 264 if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD)
@@ -230,13 +266,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
230 saveFolderContentsOnly = true; 266 saveFolderContentsOnly = true;
231 maxComponentIndex--; 267 maxComponentIndex--;
232 } 268 }
233 269
234 m_invPath = String.Empty; 270 m_invPath = String.Empty;
235 for (int i = 0; i <= maxComponentIndex; i++) 271 for (int i = 0; i <= maxComponentIndex; i++)
236 { 272 {
237 m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER; 273 m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER;
238 } 274 }
239 275
240 // Annoyingly Split actually returns the original string if the input string consists only of delimiters 276 // Annoyingly Split actually returns the original string if the input string consists only of delimiters
241 // Therefore if we still start with a / after the split, then we need the root folder 277 // Therefore if we still start with a / after the split, then we need the root folder
242 if (m_invPath.Length == 0) 278 if (m_invPath.Length == 0)
@@ -246,25 +282,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
246 else 282 else
247 { 283 {
248 m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); 284 m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
249 List<InventoryFolderBase> candidateFolders 285 List<InventoryFolderBase> candidateFolders
250 = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath); 286 = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath);
251 if (candidateFolders.Count > 0) 287 if (candidateFolders.Count > 0)
252 inventoryFolder = candidateFolders[0]; 288 inventoryFolder = candidateFolders[0];
253 } 289 }
254 290
255 // The path may point to an item instead 291 // The path may point to an item instead
256 if (inventoryFolder == null) 292 if (inventoryFolder == null)
257 inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath); 293 inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath);
258 294
259 if (null == inventoryFolder && null == inventoryItem) 295 if (null == inventoryFolder && null == inventoryItem)
260 { 296 {
261 // We couldn't find the path indicated 297 // We couldn't find the path indicated
262 string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath); 298 string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath);
263 Exception e = new InventoryArchiverException(errorMessage); 299 Exception e = new InventoryArchiverException(errorMessage);
264 m_module.TriggerInventoryArchiveSaved(m_id, false, m_userInfo, m_invPath, m_saveStream, e); 300 m_module.TriggerInventoryArchiveSaved(m_id, false, m_userInfo, m_invPath, m_saveStream, e);
265 throw e; 301 throw e;
266 } 302 }
267 303
268 m_archiveWriter = new TarArchiveWriter(m_saveStream); 304 m_archiveWriter = new TarArchiveWriter(m_saveStream);
269 305
270 m_log.InfoFormat("[INVENTORY ARCHIVER]: Adding control file to archive."); 306 m_log.InfoFormat("[INVENTORY ARCHIVER]: Adding control file to archive.");
@@ -278,10 +314,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
278 { 314 {
279 m_log.DebugFormat( 315 m_log.DebugFormat(
280 "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}", 316 "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
281 inventoryFolder.Name, 317 inventoryFolder.Name,
282 inventoryFolder.ID, 318 inventoryFolder.ID,
283 m_invPath == String.Empty ? InventoryFolderImpl.PATH_DELIMITER : m_invPath); 319 m_invPath == String.Empty ? InventoryFolderImpl.PATH_DELIMITER : m_invPath);
284 320
285 //recurse through all dirs getting dirs and files 321 //recurse through all dirs getting dirs and files
286 SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !saveFolderContentsOnly, options, userAccountService); 322 SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !saveFolderContentsOnly, options, userAccountService);
287 } 323 }
@@ -290,10 +326,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
290 m_log.DebugFormat( 326 m_log.DebugFormat(
291 "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}", 327 "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
292 inventoryItem.Name, inventoryItem.ID, m_invPath); 328 inventoryItem.Name, inventoryItem.ID, m_invPath);
293 329
294 SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH, options, userAccountService); 330 SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH, options, userAccountService);
295 } 331 }
296 332
297 // Don't put all this profile information into the archive right now. 333 // Don't put all this profile information into the archive right now.
298 //SaveUsers(); 334 //SaveUsers();
299 335
@@ -352,7 +388,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
352 /// 388 ///
353 /// These names are prepended with an inventory folder's UUID so that more than one folder can have the 389 /// These names are prepended with an inventory folder's UUID so that more than one folder can have the
354 /// same name 390 /// same name
355 /// 391 ///
356 /// <param name="folder"></param> 392 /// <param name="folder"></param>
357 /// <returns></returns> 393 /// <returns></returns>
358 public static string CreateArchiveFolderName(InventoryFolderBase folder) 394 public static string CreateArchiveFolderName(InventoryFolderBase folder)
@@ -366,7 +402,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
366 /// 402 ///
367 /// These names are prepended with an inventory item's UUID so that more than one item can have the 403 /// These names are prepended with an inventory item's UUID so that more than one item can have the
368 /// same name 404 /// same name
369 /// 405 ///
370 /// <param name="item"></param> 406 /// <param name="item"></param>
371 /// <returns></returns> 407 /// <returns></returns>
372 public static string CreateArchiveItemName(InventoryItemBase item) 408 public static string CreateArchiveItemName(InventoryItemBase item)
@@ -412,7 +448,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
412 public string CreateControlFile(Dictionary<string, object> options) 448 public string CreateControlFile(Dictionary<string, object> options)
413 { 449 {
414 int majorVersion, minorVersion; 450 int majorVersion, minorVersion;
415 451
416 if (options.ContainsKey("home")) 452 if (options.ContainsKey("home"))
417 { 453 {
418 majorVersion = 1; 454 majorVersion = 1;
@@ -422,10 +458,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
422 { 458 {
423 majorVersion = 0; 459 majorVersion = 0;
424 minorVersion = 3; 460 minorVersion = 3;
425 } 461 }
426 462
427 m_log.InfoFormat("[INVENTORY ARCHIVER]: Creating version {0}.{1} IAR", majorVersion, minorVersion); 463 m_log.InfoFormat("[INVENTORY ARCHIVER]: Creating version {0}.{1} IAR", majorVersion, minorVersion);
428 464
429 StringWriter sw = new StringWriter(); 465 StringWriter sw = new StringWriter();
430 XmlTextWriter xtw = new XmlTextWriter(sw); 466 XmlTextWriter xtw = new XmlTextWriter(sw);
431 xtw.Formatting = Formatting.Indented; 467 xtw.Formatting = Formatting.Indented;
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
index ac22c3f..cf87010 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
@@ -47,18 +47,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
47 public class InventoryArchiverModule : IRegionModule, IInventoryArchiverModule 47 public class InventoryArchiverModule : IRegionModule, IInventoryArchiverModule
48 { 48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 public string Name { get { return "Inventory Archiver Module"; } } 51 public string Name { get { return "Inventory Archiver Module"; } }
52 52
53 public bool IsSharedModule { get { return true; } } 53 public bool IsSharedModule { get { return true; } }
54 54
55 /// <value> 55 /// <value>
56 /// Enable or disable checking whether the iar user is actually logged in 56 /// Enable or disable checking whether the iar user is actually logged in
57 /// </value> 57 /// </value>
58// public bool DisablePresenceChecks { get; set; } 58// public bool DisablePresenceChecks { get; set; }
59 59
60 public event InventoryArchiveSaved OnInventoryArchiveSaved; 60 public event InventoryArchiveSaved OnInventoryArchiveSaved;
61 61
62 /// <summary> 62 /// <summary>
63 /// The file to load and save inventory if no filename has been specified 63 /// The file to load and save inventory if no filename has been specified
64 /// </summary> 64 /// </summary>
@@ -68,7 +68,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
68 /// Pending save completions initiated from the console 68 /// Pending save completions initiated from the console
69 /// </value> 69 /// </value>
70 protected List<Guid> m_pendingConsoleSaves = new List<Guid>(); 70 protected List<Guid> m_pendingConsoleSaves = new List<Guid>();
71 71
72 /// <value> 72 /// <value>
73 /// All scenes that this module knows about 73 /// All scenes that this module knows about
74 /// </value> 74 /// </value>
@@ -106,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
106 { 106 {
107 scene.RegisterModuleInterface<IInventoryArchiverModule>(this); 107 scene.RegisterModuleInterface<IInventoryArchiverModule>(this);
108 OnInventoryArchiveSaved += SaveInvConsoleCommandCompleted; 108 OnInventoryArchiveSaved += SaveInvConsoleCommandCompleted;
109 109
110 scene.AddCommand( 110 scene.AddCommand(
111 "Archiving", this, "load iar", 111 "Archiving", this, "load iar",
112 "load iar [-m|--merge] <first> <last> <inventory path> <password> [<IAR path>]", 112 "load iar [-m|--merge] <first> <last> <inventory path> <password> [<IAR path>]",
@@ -119,11 +119,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
119 + "<IAR path> is the filesystem path or URI from which to load the IAR." 119 + "<IAR path> is the filesystem path or URI from which to load the IAR."
120 + string.Format(" If this is not given then the filename {0} in the current directory is used", DEFAULT_INV_BACKUP_FILENAME), 120 + string.Format(" If this is not given then the filename {0} in the current directory is used", DEFAULT_INV_BACKUP_FILENAME),
121 HandleLoadInvConsoleCommand); 121 HandleLoadInvConsoleCommand);
122 122
123 scene.AddCommand( 123 scene.AddCommand(
124 "Archiving", this, "save iar", 124 "Archiving", this, "save iar",
125 "save iar [-h|--home=<url>] [--noassets] <first> <last> <inventory path> <password> [<IAR path>] [-c|--creators] [-v|--verbose]", 125 "save iar [-h|--home=<url>] [--noassets] <first> <last> <inventory path> <password> [<IAR path>] [-c|--creators] [-e|--exclude=<name/uuid>] [-f|--excludefolder=<foldername/uuid>] [-v|--verbose]",
126 "Save user inventory archive (IAR).", 126 "Save user inventory archive (IAR).",
127 "<first> is the user's first name.\n" 127 "<first> is the user's first name.\n"
128 + "<last> is the user's last name.\n" 128 + "<last> is the user's last name.\n"
129 + "<inventory path> is the path inside the user's inventory for the folder/item to be saved.\n" 129 + "<inventory path> is the path inside the user's inventory for the folder/item to be saved.\n"
@@ -131,32 +131,34 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
131 + string.Format(" If this is not given then the filename {0} in the current directory is used.\n", DEFAULT_INV_BACKUP_FILENAME) 131 + string.Format(" If this is not given then the filename {0} in the current directory is used.\n", DEFAULT_INV_BACKUP_FILENAME)
132 + "-h|--home=<url> adds the url of the profile service to the saved user information.\n" 132 + "-h|--home=<url> adds the url of the profile service to the saved user information.\n"
133 + "-c|--creators preserves information about foreign creators.\n" 133 + "-c|--creators preserves information about foreign creators.\n"
134 + "-e|--exclude=<name/uuid> don't save the inventory item in archive" + Environment.NewLine
135 + "-f|--excludefolder=<folder/uuid> don't save contents of the folder in archive" + Environment.NewLine
134 + "-v|--verbose extra debug messages.\n" 136 + "-v|--verbose extra debug messages.\n"
135 + "--noassets stops assets being saved to the IAR.", 137 + "--noassets stops assets being saved to the IAR.",
136 HandleSaveInvConsoleCommand); 138 HandleSaveInvConsoleCommand);
137 139
138 m_aScene = scene; 140 m_aScene = scene;
139 } 141 }
140 142
141 m_scenes[scene.RegionInfo.RegionID] = scene; 143 m_scenes[scene.RegionInfo.RegionID] = scene;
142 } 144 }
143 145
144 public void PostInitialise() {} 146 public void PostInitialise() {}
145 147
146 public void Close() {} 148 public void Close() {}
147 149
148 /// <summary> 150 /// <summary>
149 /// Trigger the inventory archive saved event. 151 /// Trigger the inventory archive saved event.
150 /// </summary> 152 /// </summary>
151 protected internal void TriggerInventoryArchiveSaved( 153 protected internal void TriggerInventoryArchiveSaved(
152 Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, 154 Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream,
153 Exception reportedException) 155 Exception reportedException)
154 { 156 {
155 InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved; 157 InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved;
156 if (handlerInventoryArchiveSaved != null) 158 if (handlerInventoryArchiveSaved != null)
157 handlerInventoryArchiveSaved(id, succeeded, userInfo, invPath, saveStream, reportedException); 159 handlerInventoryArchiveSaved(id, succeeded, userInfo, invPath, saveStream, reportedException);
158 } 160 }
159 161
160 public bool ArchiveInventory( 162 public bool ArchiveInventory(
161 Guid id, string firstName, string lastName, string invPath, string pass, Stream saveStream) 163 Guid id, string firstName, string lastName, string invPath, string pass, Stream saveStream)
162 { 164 {
@@ -164,7 +166,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
164 } 166 }
165 167
166 public bool ArchiveInventory( 168 public bool ArchiveInventory(
167 Guid id, string firstName, string lastName, string invPath, string pass, Stream saveStream, 169 Guid id, string firstName, string lastName, string invPath, string pass, Stream saveStream,
168 Dictionary<string, object> options) 170 Dictionary<string, object> options)
169 { 171 {
170 if (m_scenes.Count > 0) 172 if (m_scenes.Count > 0)
@@ -188,7 +190,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
188 190
189 return false; 191 return false;
190 } 192 }
191 193
192 return true; 194 return true;
193// } 195// }
194// else 196// else
@@ -202,15 +204,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
202 204
203 return false; 205 return false;
204 } 206 }
205 207
206 public bool ArchiveInventory( 208 public bool ArchiveInventory(
207 Guid id, string firstName, string lastName, string invPath, string pass, string savePath, 209 Guid id, string firstName, string lastName, string invPath, string pass, string savePath,
208 Dictionary<string, object> options) 210 Dictionary<string, object> options)
209 { 211 {
210 if (m_scenes.Count > 0) 212 if (m_scenes.Count > 0)
211 { 213 {
212 UserAccount userInfo = GetUserInfo(firstName, lastName, pass); 214 UserAccount userInfo = GetUserInfo(firstName, lastName, pass);
213 215
214 if (userInfo != null) 216 if (userInfo != null)
215 { 217 {
216// if (CheckPresence(userInfo.PrincipalID)) 218// if (CheckPresence(userInfo.PrincipalID))
@@ -228,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
228 230
229 return false; 231 return false;
230 } 232 }
231 233
232 return true; 234 return true;
233// } 235// }
234// else 236// else
@@ -239,7 +241,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
239// } 241// }
240 } 242 }
241 } 243 }
242 244
243 return false; 245 return false;
244 } 246 }
245 247
@@ -247,9 +249,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
247 { 249 {
248 return DearchiveInventory(firstName, lastName, invPath, pass, loadStream, new Dictionary<string, object>()); 250 return DearchiveInventory(firstName, lastName, invPath, pass, loadStream, new Dictionary<string, object>());
249 } 251 }
250 252
251 public bool DearchiveInventory( 253 public bool DearchiveInventory(
252 string firstName, string lastName, string invPath, string pass, Stream loadStream, 254 string firstName, string lastName, string invPath, string pass, Stream loadStream,
253 Dictionary<string, object> options) 255 Dictionary<string, object> options)
254 { 256 {
255 if (m_scenes.Count > 0) 257 if (m_scenes.Count > 0)
@@ -295,22 +297,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
295 297
296 return false; 298 return false;
297 } 299 }
298 300
299 public bool DearchiveInventory( 301 public bool DearchiveInventory(
300 string firstName, string lastName, string invPath, string pass, string loadPath, 302 string firstName, string lastName, string invPath, string pass, string loadPath,
301 Dictionary<string, object> options) 303 Dictionary<string, object> options)
302 { 304 {
303 if (m_scenes.Count > 0) 305 if (m_scenes.Count > 0)
304 { 306 {
305 UserAccount userInfo = GetUserInfo(firstName, lastName, pass); 307 UserAccount userInfo = GetUserInfo(firstName, lastName, pass);
306 308
307 if (userInfo != null) 309 if (userInfo != null)
308 { 310 {
309// if (CheckPresence(userInfo.PrincipalID)) 311// if (CheckPresence(userInfo.PrincipalID))
310// { 312// {
311 InventoryArchiveReadRequest request; 313 InventoryArchiveReadRequest request;
312 bool merge = (options.ContainsKey("merge") ? (bool)options["merge"] : false); 314 bool merge = (options.ContainsKey("merge") ? (bool)options["merge"] : false);
313 315
314 try 316 try
315 { 317 {
316 request = new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath, merge); 318 request = new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath, merge);
@@ -324,7 +326,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
324 326
325 return false; 327 return false;
326 } 328 }
327 329
328 UpdateClientWithLoadedNodes(userInfo, request.Execute()); 330 UpdateClientWithLoadedNodes(userInfo, request.Execute());
329 331
330 return true; 332 return true;
@@ -340,7 +342,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
340 342
341 return false; 343 return false;
342 } 344 }
343 345
344 /// <summary> 346 /// <summary>
345 /// Load inventory from an inventory file archive 347 /// Load inventory from an inventory file archive
346 /// </summary> 348 /// </summary>
@@ -351,26 +353,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
351 { 353 {
352 Dictionary<string, object> options = new Dictionary<string, object>(); 354 Dictionary<string, object> options = new Dictionary<string, object>();
353 OptionSet optionSet = new OptionSet().Add("m|merge", delegate (string v) { options["merge"] = v != null; }); 355 OptionSet optionSet = new OptionSet().Add("m|merge", delegate (string v) { options["merge"] = v != null; });
354 356
355 List<string> mainParams = optionSet.Parse(cmdparams); 357 List<string> mainParams = optionSet.Parse(cmdparams);
356 358
357 if (mainParams.Count < 6) 359 if (mainParams.Count < 6)
358 { 360 {
359 m_log.Error( 361 m_log.Error(
360 "[INVENTORY ARCHIVER]: usage is load iar [-m|--merge] <first name> <last name> <inventory path> <user password> [<load file path>]"); 362 "[INVENTORY ARCHIVER]: usage is load iar [-m|--merge] <first name> <last name> <inventory path> <user password> [<load file path>]");
361 return; 363 return;
362 } 364 }
363 365
364 string firstName = mainParams[2]; 366 string firstName = mainParams[2];
365 string lastName = mainParams[3]; 367 string lastName = mainParams[3];
366 string invPath = mainParams[4]; 368 string invPath = mainParams[4];
367 string pass = mainParams[5]; 369 string pass = mainParams[5];
368 string loadPath = (mainParams.Count > 6 ? mainParams[6] : DEFAULT_INV_BACKUP_FILENAME); 370 string loadPath = (mainParams.Count > 6 ? mainParams[6] : DEFAULT_INV_BACKUP_FILENAME);
369 371
370 m_log.InfoFormat( 372 m_log.InfoFormat(
371 "[INVENTORY ARCHIVER]: Loading archive {0} to inventory path {1} for {2} {3}", 373 "[INVENTORY ARCHIVER]: Loading archive {0} to inventory path {1} for {2} {3}",
372 loadPath, invPath, firstName, lastName); 374 loadPath, invPath, firstName, lastName);
373 375
374 if (DearchiveInventory(firstName, lastName, invPath, pass, loadPath, options)) 376 if (DearchiveInventory(firstName, lastName, invPath, pass, loadPath, options))
375 m_log.InfoFormat( 377 m_log.InfoFormat(
376 "[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}", 378 "[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}",
@@ -381,7 +383,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
381 m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", e.Message); 383 m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", e.Message);
382 } 384 }
383 } 385 }
384 386
385 /// <summary> 387 /// <summary>
386 /// Save inventory to a file archive 388 /// Save inventory to a file archive
387 /// </summary> 389 /// </summary>
@@ -398,6 +400,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
398 ops.Add("v|verbose", delegate(string v) { options["verbose"] = v; }); 400 ops.Add("v|verbose", delegate(string v) { options["verbose"] = v; });
399 ops.Add("c|creators", delegate(string v) { options["creators"] = v; }); 401 ops.Add("c|creators", delegate(string v) { options["creators"] = v; });
400 ops.Add("noassets", delegate(string v) { options["noassets"] = v != null; }); 402 ops.Add("noassets", delegate(string v) { options["noassets"] = v != null; });
403 ops.Add("e|exclude=", delegate(string v)
404 {
405 if (!options.ContainsKey("exclude"))
406 options["exclude"] = new List<String>();
407 ((List<String>)options["exclude"]).Add(v);
408 });
409 ops.Add("f|excludefolder=", delegate(string v)
410 {
411 if (!options.ContainsKey("excludefolders"))
412 options["excludefolders"] = new List<String>();
413 ((List<String>)options["excludefolders"]).Add(v);
414 });
401 415
402 List<string> mainParams = ops.Parse(cmdparams); 416 List<string> mainParams = ops.Parse(cmdparams);
403 417
@@ -406,10 +420,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
406 if (mainParams.Count < 6) 420 if (mainParams.Count < 6)
407 { 421 {
408 m_log.Error( 422 m_log.Error(
409 "[INVENTORY ARCHIVER]: usage is save iar [-h|--home=<url>] [--noassets] <first name> <last name> <inventory path> <user password> [<save file path>] [-c|--creators] [-v|--verbose]"); 423 "[INVENTORY ARCHIVER]: save iar [-h|--home=<url>] [--noassets] <first> <last> <inventory path> <password> [<IAR path>] [-c|--creators] [-e|--exclude=<name/uuid>] [-f|--excludefolder=<foldername/uuid>] [-v|--verbose]");
410 return; 424 return;
411 } 425 }
412 426
413 if (options.ContainsKey("home")) 427 if (options.ContainsKey("home"))
414 m_log.WarnFormat("[INVENTORY ARCHIVER]: Please be aware that inventory archives with creator information are not compatible with OpenSim 0.7.0.2 and earlier. Do not use the -home option if you want to produce a compatible IAR"); 428 m_log.WarnFormat("[INVENTORY ARCHIVER]: Please be aware that inventory archives with creator information are not compatible with OpenSim 0.7.0.2 and earlier. Do not use the -home option if you want to produce a compatible IAR");
415 429
@@ -418,7 +432,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
418 string invPath = mainParams[4]; 432 string invPath = mainParams[4];
419 string pass = mainParams[5]; 433 string pass = mainParams[5];
420 string savePath = (mainParams.Count > 6 ? mainParams[6] : DEFAULT_INV_BACKUP_FILENAME); 434 string savePath = (mainParams.Count > 6 ? mainParams[6] : DEFAULT_INV_BACKUP_FILENAME);
421 435
422 m_log.InfoFormat( 436 m_log.InfoFormat(
423 "[INVENTORY ARCHIVER]: Saving archive {0} using inventory path {1} for {2} {3}", 437 "[INVENTORY ARCHIVER]: Saving archive {0} using inventory path {1} for {2} {3}",
424 savePath, invPath, firstName, lastName); 438 savePath, invPath, firstName, lastName);
@@ -433,9 +447,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
433 m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", e.Message); 447 m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", e.Message);
434 } 448 }
435 } 449 }
436 450
437 private void SaveInvConsoleCommandCompleted( 451 private void SaveInvConsoleCommandCompleted(
438 Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, 452 Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream,
439 Exception reportedException) 453 Exception reportedException)
440 { 454 {
441 lock (m_pendingConsoleSaves) 455 lock (m_pendingConsoleSaves)
@@ -445,7 +459,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
445 else 459 else
446 return; 460 return;
447 } 461 }
448 462
449 if (succeeded) 463 if (succeeded)
450 { 464 {
451 m_log.InfoFormat("[INVENTORY ARCHIVER]: Saved archive for {0} {1}", userInfo.FirstName, userInfo.LastName); 465 m_log.InfoFormat("[INVENTORY ARCHIVER]: Saved archive for {0} {1}", userInfo.FirstName, userInfo.LastName);
@@ -453,11 +467,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
453 else 467 else
454 { 468 {
455 m_log.ErrorFormat( 469 m_log.ErrorFormat(
456 "[INVENTORY ARCHIVER]: Archive save for {0} {1} failed - {2}", 470 "[INVENTORY ARCHIVER]: Archive save for {0} {1} failed - {2}",
457 userInfo.FirstName, userInfo.LastName, reportedException.Message); 471 userInfo.FirstName, userInfo.LastName, reportedException.Message);
458 } 472 }
459 } 473 }
460 474
461 /// <summary> 475 /// <summary>
462 /// Get user information for the given name. 476 /// Get user information for the given name.
463 /// </summary> 477 /// </summary>
@@ -467,13 +481,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
467 /// <returns></returns> 481 /// <returns></returns>
468 protected UserAccount GetUserInfo(string firstName, string lastName, string pass) 482 protected UserAccount GetUserInfo(string firstName, string lastName, string pass)
469 { 483 {
470 UserAccount account 484 UserAccount account
471 = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, firstName, lastName); 485 = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, firstName, lastName);
472 486
473 if (null == account) 487 if (null == account)
474 { 488 {
475 m_log.ErrorFormat( 489 m_log.ErrorFormat(
476 "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1}", 490 "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1}",
477 firstName, lastName); 491 firstName, lastName);
478 return null; 492 return null;
479 } 493 }
@@ -488,7 +502,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
488 else 502 else
489 { 503 {
490 m_log.ErrorFormat( 504 m_log.ErrorFormat(
491 "[INVENTORY ARCHIVER]: Password for user {0} {1} incorrect. Please try again.", 505 "[INVENTORY ARCHIVER]: Password for user {0} {1} incorrect. Please try again.",
492 firstName, lastName); 506 firstName, lastName);
493 return null; 507 return null;
494 } 508 }
@@ -499,7 +513,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
499 return null; 513 return null;
500 } 514 }
501 } 515 }
502 516
503 /// <summary> 517 /// <summary>
504 /// Notify the client of loaded nodes if they are logged in 518 /// Notify the client of loaded nodes if they are logged in
505 /// </summary> 519 /// </summary>
@@ -508,22 +522,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
508 { 522 {
509 if (loadedNodes.Count == 0) 523 if (loadedNodes.Count == 0)
510 return; 524 return;
511 525
512 foreach (Scene scene in m_scenes.Values) 526 foreach (Scene scene in m_scenes.Values)
513 { 527 {
514 ScenePresence user = scene.GetScenePresence(userInfo.PrincipalID); 528 ScenePresence user = scene.GetScenePresence(userInfo.PrincipalID);
515 529
516 if (user != null && !user.IsChildAgent) 530 if (user != null && !user.IsChildAgent)
517 { 531 {
518 foreach (InventoryNodeBase node in loadedNodes) 532 foreach (InventoryNodeBase node in loadedNodes)
519 { 533 {
520// m_log.DebugFormat( 534// m_log.DebugFormat(
521// "[INVENTORY ARCHIVER]: Notifying {0} of loaded inventory node {1}", 535// "[INVENTORY ARCHIVER]: Notifying {0} of loaded inventory node {1}",
522// user.Name, node.Name); 536// user.Name, node.Name);
523 537
524 user.ControllingClient.SendBulkUpdateInventory(node); 538 user.ControllingClient.SendBulkUpdateInventory(node);
525 } 539 }
526 540
527 break; 541 break;
528 } 542 }
529 } 543 }
@@ -538,7 +552,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
538// { 552// {
539// if (DisablePresenceChecks) 553// if (DisablePresenceChecks)
540// return true; 554// return true;
541// 555//
542// foreach (Scene scene in m_scenes.Values) 556// foreach (Scene scene in m_scenes.Values)
543// { 557// {
544// ScenePresence p; 558// ScenePresence p;
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs
index 19ef571..1056865 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs
@@ -48,7 +48,7 @@ using OpenSim.Tests.Common.Mock;
48namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests 48namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
49{ 49{
50 [TestFixture] 50 [TestFixture]
51 public class InventoryArchiveTestCase 51 public class InventoryArchiveTestCase : OpenSimTestCase
52 { 52 {
53 protected ManualResetEvent mre = new ManualResetEvent(false); 53 protected ManualResetEvent mre = new ManualResetEvent(false);
54 54
@@ -84,8 +84,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
84 protected string m_coaItemName = "Coalesced Item"; 84 protected string m_coaItemName = "Coalesced Item";
85 85
86 [SetUp] 86 [SetUp]
87 public virtual void SetUp() 87 public override void SetUp()
88 { 88 {
89 base.SetUp();
89 m_iarStream = new MemoryStream(m_iarStreamBytes); 90 m_iarStream = new MemoryStream(m_iarStreamBytes);
90 } 91 }
91 92
@@ -100,7 +101,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
100// log4net.Config.XmlConfigurator.Configure(); 101// log4net.Config.XmlConfigurator.Configure();
101 102
102 InventoryArchiverModule archiverModule = new InventoryArchiverModule(); 103 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
103 Scene scene = SceneHelpers.SetupScene(); 104 Scene scene = new SceneHelpers().SetupScene();
104 SceneHelpers.SetupSceneModules(scene, archiverModule); 105 SceneHelpers.SetupSceneModules(scene, archiverModule);
105 106
106 UserAccountHelpers.CreateUserWithInventory(scene, m_uaLL1, "hampshire"); 107 UserAccountHelpers.CreateUserWithInventory(scene, m_uaLL1, "hampshire");
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index e409c8e..b112b6d 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -61,7 +61,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
61 SerialiserModule serialiserModule = new SerialiserModule(); 61 SerialiserModule serialiserModule = new SerialiserModule();
62 m_archiverModule = new InventoryArchiverModule(); 62 m_archiverModule = new InventoryArchiverModule();
63 63
64 m_scene = SceneHelpers.SetupScene(); 64 m_scene = new SceneHelpers().SetupScene();
65 SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule); 65 SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule);
66 } 66 }
67 67
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
index 417c20c..6eb3605 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
@@ -62,7 +62,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
62 62
63 InventoryArchiverModule archiverModule = new InventoryArchiverModule(); 63 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
64 64
65 Scene scene = SceneHelpers.SetupScene(); 65 Scene scene = new SceneHelpers().SetupScene();
66 SceneHelpers.SetupSceneModules(scene, archiverModule); 66 SceneHelpers.SetupSceneModules(scene, archiverModule);
67 67
68 // Create user 68 // Create user
@@ -179,7 +179,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
179 InventoryArchiverModule archiverModule = new InventoryArchiverModule(); 179 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
180 180
181 // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene 181 // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
182 Scene scene = SceneHelpers.SetupScene(); 182 Scene scene = new SceneHelpers().SetupScene();
183 183
184 SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); 184 SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
185 185
@@ -222,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
222 222
223 SerialiserModule serialiserModule = new SerialiserModule(); 223 SerialiserModule serialiserModule = new SerialiserModule();
224 InventoryArchiverModule archiverModule = new InventoryArchiverModule(); 224 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
225 Scene scene = SceneHelpers.SetupScene(); 225 Scene scene = new SceneHelpers().SetupScene();
226 SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); 226 SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
227 227
228 UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "password"); 228 UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "password");
@@ -247,7 +247,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
247 247
248 InventoryArchiverModule archiverModule = new InventoryArchiverModule(); 248 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
249 249
250 Scene scene = SceneHelpers.SetupScene(); 250 Scene scene = new SceneHelpers().SetupScene();
251 SceneHelpers.SetupSceneModules(scene, archiverModule); 251 SceneHelpers.SetupSceneModules(scene, archiverModule);
252 252
253 // Create user 253 // Create user
@@ -326,7 +326,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
326 TestHelpers.InMethod(); 326 TestHelpers.InMethod();
327// log4net.Config.XmlConfigurator.Configure(); 327// log4net.Config.XmlConfigurator.Configure();
328 328
329 Scene scene = SceneHelpers.SetupScene(); 329 Scene scene = new SceneHelpers().SetupScene();
330 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene); 330 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
331 331
332 Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>(); 332 Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
@@ -393,7 +393,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
393 TestHelpers.InMethod(); 393 TestHelpers.InMethod();
394 //log4net.Config.XmlConfigurator.Configure(); 394 //log4net.Config.XmlConfigurator.Configure();
395 395
396 Scene scene = SceneHelpers.SetupScene(); 396 Scene scene = new SceneHelpers().SetupScene();
397 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene); 397 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
398 398
399 string folder1ExistingName = "a"; 399 string folder1ExistingName = "a";
@@ -444,7 +444,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
444 TestHelpers.InMethod(); 444 TestHelpers.InMethod();
445// log4net.Config.XmlConfigurator.Configure(); 445// log4net.Config.XmlConfigurator.Configure();
446 446
447 Scene scene = SceneHelpers.SetupScene(); 447 Scene scene = new SceneHelpers().SetupScene();
448 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene); 448 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
449 449
450 string folder1ExistingName = "a"; 450 string folder1ExistingName = "a";
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
index bc5c1ff..92cf9d1 100644
--- a/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
@@ -240,13 +240,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
240 { 240 {
241 ScenePresence sp = scene.GetScenePresence(client.AgentId); 241 ScenePresence sp = scene.GetScenePresence(client.AgentId);
242 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>(); 242 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>();
243 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>(); 243
244 if (transferMod != null && sp != null && eq != null) 244 if (transferMod != null && sp != null)
245 transferMod.DoTeleport(sp, gatekeeper, finalDestination, im.Position + new Vector3(0.5f, 0.5f, 0f), Vector3.UnitX, teleportflags, eq); 245 transferMod.DoTeleport(
246 sp, gatekeeper, finalDestination, im.Position + new Vector3(0.5f, 0.5f, 0f),
247 Vector3.UnitX, teleportflags);
246 } 248 }
247 } 249 }
248 } 250 }
249 } 251 }
250 } 252 }
251 } 253 }
252} 254} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
index dcfdf8f..a889984 100644
--- a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
@@ -151,6 +151,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
151 Scene scene = (Scene)(client.Scene); 151 Scene scene = (Scene)(client.Scene);
152 ScenePresence presence = scene.GetScenePresence(client.AgentId); 152 ScenePresence presence = scene.GetScenePresence(client.AgentId);
153 153
154 // Round up Z co-ordinate rather than round-down by casting. This stops tall avatars from being given
155 // a teleport Z co-ordinate by short avatars that drops them through or embeds them in thin floors on
156 // arrival.
157 //
158 // Ideally we would give the exact float position adjusting for the relative height of the two avatars
159 // but it looks like a float component isn't possible with a parcel ID.
154 UUID dest = Util.BuildFakeParcelID( 160 UUID dest = Util.BuildFakeParcelID(
155 scene.RegionInfo.RegionHandle, 161 scene.RegionInfo.RegionHandle,
156 (uint)presence.AbsolutePosition.X, 162 (uint)presence.AbsolutePosition.X,
diff --git a/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs
index 8101ca2..87ca327 100644
--- a/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs
@@ -57,14 +57,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile
57 57
58 public void Initialise(IConfigSource config) 58 public void Initialise(IConfigSource config)
59 { 59 {
60 // This can be reduced later as the loader will determine
61 // whether we are needed
62 if (config.Configs["Profile"] != null)
63 {
64 if (config.Configs["Profile"].GetString("Module", string.Empty) != "BasicProfileModule")
65 return;
66 }
67
68 m_log.DebugFormat("[PROFILE MODULE]: Basic Profile Module enabled"); 60 m_log.DebugFormat("[PROFILE MODULE]: Basic Profile Module enabled");
69 m_Enabled = true; 61 m_Enabled = true;
70 } 62 }
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
index 2b790f4..560f807 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
@@ -30,7 +30,6 @@ using System.Collections.Generic;
30using System.Net; 30using System.Net;
31using System.Reflection; 31using System.Reflection;
32using System.Threading; 32using System.Threading;
33
34using OpenSim.Framework; 33using OpenSim.Framework;
35using OpenSim.Framework.Capabilities; 34using OpenSim.Framework.Capabilities;
36using OpenSim.Framework.Client; 35using OpenSim.Framework.Client;
@@ -47,29 +46,39 @@ using Nini.Config;
47 46
48namespace OpenSim.Region.CoreModules.Framework.EntityTransfer 47namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
49{ 48{
50 public class EntityTransferModule : ISharedRegionModule, IEntityTransferModule 49 public class EntityTransferModule : INonSharedRegionModule, IEntityTransferModule
51 { 50 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 52
53 public const int DefaultMaxTransferDistance = 4095;
54 public const bool WaitForAgentArrivedAtDestinationDefault = true;
55
54 /// <summary> 56 /// <summary>
55 /// The maximum distance, in standard region units (256m) that an agent is allowed to transfer. 57 /// The maximum distance, in standard region units (256m) that an agent is allowed to transfer.
56 /// </summary> 58 /// </summary>
57 private int m_MaxTransferDistance = 4095; 59 public int MaxTransferDistance { get; set; }
58 public int MaxTransferDistance
59 {
60 get { return m_MaxTransferDistance; }
61 set { m_MaxTransferDistance = value; }
62 }
63 60
64 private int m_levelHGTeleport = 0; 61 /// <summary>
62 /// If true then on a teleport, the source region waits for a callback from the destination region. If
63 /// a callback fails to arrive within a set time then the user is pulled back into the source region.
64 /// </summary>
65 public bool WaitForAgentArrivedAtDestination { get; set; }
65 66
66 protected bool m_Enabled = false; 67 protected bool m_Enabled = false;
67 protected Scene m_aScene; 68
68 protected List<Scene> m_Scenes = new List<Scene>(); 69 public Scene Scene { get; private set; }
69 protected List<UUID> m_agentsInTransit; 70
71 /// <summary>
72 /// Handles recording and manipulation of state for entities that are in transfer within or between regions
73 /// (cross or teleport).
74 /// </summary>
75 private EntityTransferStateMachine m_entityTransferStateMachine;
76
70 private ExpiringCache<UUID, ExpiringCache<ulong, DateTime>> m_bannedRegions = 77 private ExpiringCache<UUID, ExpiringCache<ulong, DateTime>> m_bannedRegions =
71 new ExpiringCache<UUID, ExpiringCache<ulong, DateTime>>(); 78 new ExpiringCache<UUID, ExpiringCache<ulong, DateTime>>();
72 79
80 private IEventQueue m_eqModule;
81
73 #region ISharedRegionModule 82 #region ISharedRegionModule
74 83
75 public Type ReplaceableInterface 84 public Type ReplaceableInterface
@@ -105,11 +114,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
105 IConfig transferConfig = source.Configs["EntityTransfer"]; 114 IConfig transferConfig = source.Configs["EntityTransfer"];
106 if (transferConfig != null) 115 if (transferConfig != null)
107 { 116 {
108 MaxTransferDistance = transferConfig.GetInt("max_distance", 4095); 117 WaitForAgentArrivedAtDestination
109 m_levelHGTeleport = transferConfig.GetInt("LevelHGTeleport", 0); 118 = transferConfig.GetBoolean("wait_for_callback", WaitForAgentArrivedAtDestinationDefault);
119
120 MaxTransferDistance = transferConfig.GetInt("max_distance", DefaultMaxTransferDistance);
121 }
122 else
123 {
124 MaxTransferDistance = DefaultMaxTransferDistance;
110 } 125 }
111 126
112 m_agentsInTransit = new List<UUID>(); 127 m_entityTransferStateMachine = new EntityTransferStateMachine(this);
128
113 m_Enabled = true; 129 m_Enabled = true;
114 } 130 }
115 131
@@ -122,10 +138,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
122 if (!m_Enabled) 138 if (!m_Enabled)
123 return; 139 return;
124 140
125 if (m_aScene == null) 141 Scene = scene;
126 m_aScene = scene;
127 142
128 m_Scenes.Add(scene);
129 scene.RegisterModuleInterface<IEntityTransferModule>(this); 143 scene.RegisterModuleInterface<IEntityTransferModule>(this);
130 scene.EventManager.OnNewClient += OnNewClient; 144 scene.EventManager.OnNewClient += OnNewClient;
131 } 145 }
@@ -136,26 +150,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
136 client.OnTeleportLandmarkRequest += RequestTeleportLandmark; 150 client.OnTeleportLandmarkRequest += RequestTeleportLandmark;
137 } 151 }
138 152
139 public virtual void Close() 153 public virtual void Close() {}
140 {
141 if (!m_Enabled)
142 return;
143 }
144 154
145 public virtual void RemoveRegion(Scene scene) 155 public virtual void RemoveRegion(Scene scene) {}
146 {
147 if (!m_Enabled)
148 return;
149 if (scene == m_aScene)
150 m_aScene = null;
151
152 m_Scenes.Remove(scene);
153 }
154 156
155 public virtual void RegionLoaded(Scene scene) 157 public virtual void RegionLoaded(Scene scene)
156 { 158 {
157 if (!m_Enabled) 159 if (!m_Enabled)
158 return; 160 return;
161
162 m_eqModule = Scene.RequestModuleInterface<IEventQueue>();
159 } 163 }
160 164
161 #endregion 165 #endregion
@@ -164,170 +168,257 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
164 168
165 public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags) 169 public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags)
166 { 170 {
171 if (sp.Scene.Permissions.IsGridGod(sp.UUID))
172 {
173 // This user will be a God in the destination scene, too
174 teleportFlags |= (uint)TeleportFlags.Godlike;
175 }
176
167 if (!sp.Scene.Permissions.CanTeleport(sp.UUID)) 177 if (!sp.Scene.Permissions.CanTeleport(sp.UUID))
168 return; 178 return;
169 179
170 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
171
172 // Reset animations; the viewer does that in teleports. 180 // Reset animations; the viewer does that in teleports.
173 sp.Animator.ResetAnimations(); 181 sp.Animator.ResetAnimations();
174 182
183 string destinationRegionName = "(not found)";
184
175 try 185 try
176 { 186 {
177 if (regionHandle == sp.Scene.RegionInfo.RegionHandle) 187 if (regionHandle == sp.Scene.RegionInfo.RegionHandle)
178 { 188 {
179 m_log.DebugFormat( 189 destinationRegionName = sp.Scene.RegionInfo.RegionName;
180 "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation {0} within {1}",
181 position, sp.Scene.RegionInfo.RegionName);
182 190
183 // Teleport within the same region 191 TeleportAgentWithinRegion(sp, position, lookAt, teleportFlags);
184 if (IsOutsideRegion(sp.Scene, position) || position.Z < 0) 192 }
185 { 193 else // Another region possibly in another simulator
186 Vector3 emergencyPos = new Vector3(128, 128, 128); 194 {
195 GridRegion finalDestination;
196 TeleportAgentToDifferentRegion(
197 sp, regionHandle, position, lookAt, teleportFlags, out finalDestination);
187 198
188 m_log.WarnFormat( 199 if (finalDestination != null)
189 "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}", 200 destinationRegionName = finalDestination.RegionName;
190 position, sp.Name, sp.UUID, emergencyPos); 201 }
191 position = emergencyPos; 202 }
192 } 203 catch (Exception e)
204 {
205 m_log.ErrorFormat(
206 "[ENTITY TRANSFER MODULE]: Exception on teleport of {0} from {1}@{2} to {3}@{4}: {5}{6}",
207 sp.Name, sp.AbsolutePosition, sp.Scene.RegionInfo.RegionName, position, destinationRegionName,
208 e.Message, e.StackTrace);
193 209
194 // TODO: Get proper AVG Height 210 // Make sure that we clear the in-transit flag so that future teleport attempts don't always fail.
195 float localAVHeight = 1.56f; 211 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
196 float posZLimit = 22;
197 212
198 // TODO: Check other Scene HeightField 213 sp.ControllingClient.SendTeleportFailed("Internal error");
199 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize) 214 }
200 { 215 }
201 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
202 }
203 216
204 float newPosZ = posZLimit + localAVHeight; 217 /// <summary>
205 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 218 /// Teleports the agent within its current region.
206 { 219 /// </summary>
207 position.Z = newPosZ; 220 /// <param name="sp"></param>
208 } 221 /// <param name="position"></param>
222 /// <param name="lookAt"></param>
223 /// <param name="teleportFlags"></param
224 private void TeleportAgentWithinRegion(ScenePresence sp, Vector3 position, Vector3 lookAt, uint teleportFlags)
225 {
226 m_log.DebugFormat(
227 "[ENTITY TRANSFER MODULE]: Teleport for {0} to {1} within {2}",
228 sp.Name, position, sp.Scene.RegionInfo.RegionName);
209 229
210 sp.ControllingClient.SendTeleportStart(teleportFlags); 230 if (!m_entityTransferStateMachine.SetInTransit(sp.UUID))
231 {
232 m_log.DebugFormat(
233 "[ENTITY TRANSFER MODULE]: Ignoring within region teleport request of {0} {1} to {2} - agent is already in transit.",
234 sp.Name, sp.UUID, position);
211 235
212 sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); 236 return;
213 sp.TeleportFlags = (Constants.TeleportFlags)teleportFlags; 237 }
214 sp.Teleport(position);
215 238
216 foreach (SceneObjectGroup grp in sp.GetAttachments()) 239 // Teleport within the same region
217 { 240 if (IsOutsideRegion(sp.Scene, position) || position.Z < 0)
218 sp.Scene.EventManager.TriggerOnScriptChangedEvent(grp.LocalId, (uint)Changed.TELEPORT); 241 {
219 } 242 Vector3 emergencyPos = new Vector3(128, 128, 128);
243
244 m_log.WarnFormat(
245 "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
246 position, sp.Name, sp.UUID, emergencyPos);
247
248 position = emergencyPos;
249 }
250
251 // TODO: Get proper AVG Height
252 float localAVHeight = 1.56f;
253 float posZLimit = 22;
254
255 // TODO: Check other Scene HeightField
256 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize)
257 {
258 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
259 }
260
261 float newPosZ = posZLimit + localAVHeight;
262 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
263 {
264 position.Z = newPosZ;
265 }
266
267 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring);
268
269 sp.ControllingClient.SendTeleportStart(teleportFlags);
270
271 sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
272 sp.TeleportFlags = (Constants.TeleportFlags)teleportFlags;
273 sp.Velocity = Vector3.Zero;
274 sp.Teleport(position);
275
276 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.ReceivedAtDestination);
277
278 foreach (SceneObjectGroup grp in sp.GetAttachments())
279 {
280 sp.Scene.EventManager.TriggerOnScriptChangedEvent(grp.LocalId, (uint)Changed.TELEPORT);
281 }
282
283 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp);
284 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
285 }
286
287 /// <summary>
288 /// Teleports the agent to a different region.
289 /// </summary>
290 /// <param name='sp'></param>
291 /// <param name='regionHandle'>/param>
292 /// <param name='position'></param>
293 /// <param name='lookAt'></param>
294 /// <param name='teleportFlags'></param>
295 /// <param name='finalDestination'></param>
296 private void TeleportAgentToDifferentRegion(
297 ScenePresence sp, ulong regionHandle, Vector3 position,
298 Vector3 lookAt, uint teleportFlags, out GridRegion finalDestination)
299 {
300 uint x = 0, y = 0;
301 Utils.LongToUInts(regionHandle, out x, out y);
302 GridRegion reg = Scene.GridService.GetRegionByPosition(sp.Scene.RegionInfo.ScopeID, (int)x, (int)y);
303
304 if (reg != null)
305 {
306 finalDestination = GetFinalDestination(reg);
307
308 if (finalDestination == null)
309 {
310 m_log.WarnFormat(
311 "[ENTITY TRANSFER MODULE]: Final destination is having problems. Unable to teleport {0} {1}",
312 sp.Name, sp.UUID);
313
314 sp.ControllingClient.SendTeleportFailed("Problem at destination");
315 return;
220 } 316 }
221 else // Another region possibly in another simulator 317
318 // Check that these are not the same coordinates
319 if (finalDestination.RegionLocX == sp.Scene.RegionInfo.RegionLocX &&
320 finalDestination.RegionLocY == sp.Scene.RegionInfo.RegionLocY)
222 { 321 {
223 uint x = 0, y = 0; 322 // Can't do. Viewer crashes
224 Utils.LongToUInts(regionHandle, out x, out y); 323 sp.ControllingClient.SendTeleportFailed("Space warp! You would crash. Move to a different region and try again.");
225 GridRegion reg = m_aScene.GridService.GetRegionByPosition(sp.Scene.RegionInfo.ScopeID, (int)x, (int)y); 324 return;
325 }
226 326
227 if (reg != null) 327 //
228 { 328 // This is it
229 GridRegion finalDestination = GetFinalDestination(reg); 329 //
230 if (finalDestination == null) 330 DoTeleport(sp, reg, finalDestination, position, lookAt, teleportFlags);
231 { 331 //
232 m_log.WarnFormat("[ENTITY TRANSFER MODULE]: Final destination is having problems. Unable to teleport agent."); 332 //
233 sp.ControllingClient.SendTeleportFailed("Problem at destination"); 333 //
234 return; 334 }
235 } 335 else
336 {
337 finalDestination = null;
236 338
237 // check if HyperGrid teleport is allowed, based on user level 339 // TP to a place that doesn't exist (anymore)
238 int flags = m_aScene.GridService.GetRegionFlags(sp.Scene.RegionInfo.ScopeID, reg.RegionID); 340 // Inform the viewer about that
341 sp.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
239 342
240 if (((flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) && (sp.UserLevel < m_levelHGTeleport)) 343 // and set the map-tile to '(Offline)'
241 { 344 uint regX, regY;
242 m_log.WarnFormat("[ENTITY TRANSFER MODULE]: Final destination link is non permitted hypergrid region. Unable to teleport agent."); 345 Utils.LongToUInts(regionHandle, out regX, out regY);
243 sp.ControllingClient.SendTeleportFailed("HyperGrid teleport not permitted");
244 return;
245 }
246 346
247 uint curX = 0, curY = 0; 347 MapBlockData block = new MapBlockData();
248 Utils.LongToUInts(sp.Scene.RegionInfo.RegionHandle, out curX, out curY); 348 block.X = (ushort)(regX / Constants.RegionSize);
249 int curCellX = (int)(curX / Constants.RegionSize); 349 block.Y = (ushort)(regY / Constants.RegionSize);
250 int curCellY = (int)(curY / Constants.RegionSize); 350 block.Access = 254; // == not there
251 int destCellX = (int)(finalDestination.RegionLocX / Constants.RegionSize);
252 int destCellY = (int)(finalDestination.RegionLocY / Constants.RegionSize);
253 351
352 List<MapBlockData> blocks = new List<MapBlockData>();
353 blocks.Add(block);
354 sp.ControllingClient.SendMapBlock(blocks, 0);
355 }
356 }
357
358 /// <summary>
359 /// Determines whether this instance is within the max transfer distance.
360 /// </summary>
361 /// <param name="sourceRegion"></param>
362 /// <param name="destRegion"></param>
363 /// <returns>
364 /// <c>true</c> if this instance is within max transfer distance; otherwise, <c>false</c>.
365 /// </returns>
366 private bool IsWithinMaxTeleportDistance(RegionInfo sourceRegion, GridRegion destRegion)
367 {
254// m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Source co-ords are x={0} y={1}", curRegionX, curRegionY); 368// m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Source co-ords are x={0} y={1}", curRegionX, curRegionY);
255// 369//
256// m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Final dest is x={0} y={1} {2}@{3}", 370// m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Final dest is x={0} y={1} {2}@{3}",
257// destRegionX, destRegionY, finalDestination.RegionID, finalDestination.ServerURI); 371// destRegionX, destRegionY, finalDestination.RegionID, finalDestination.ServerURI);
258 372
259 // Check that these are not the same coordinates 373 // Insanely, RegionLoc on RegionInfo is the 256m map co-ord whilst GridRegion.RegionLoc is the raw meters position.
260 if (finalDestination.RegionLocX == sp.Scene.RegionInfo.RegionLocX && 374 return Math.Abs(sourceRegion.RegionLocX - destRegion.RegionCoordX) <= MaxTransferDistance
261 finalDestination.RegionLocY == sp.Scene.RegionInfo.RegionLocY) 375 && Math.Abs(sourceRegion.RegionLocY - destRegion.RegionCoordY) <= MaxTransferDistance;
262 { 376 }
263 // Can't do. Viewer crashes
264 sp.ControllingClient.SendTeleportFailed("Space warp! You would crash. Move to a different region and try again.");
265 return;
266 }
267
268 if (Math.Abs(curCellX - destCellX) > MaxTransferDistance || Math.Abs(curCellY - destCellY) > MaxTransferDistance)
269 {
270 sp.ControllingClient.SendTeleportFailed(
271 string.Format(
272 "Can't teleport to {0} ({1},{2}) from {3} ({4},{5}), destination is more than {6} regions way",
273 finalDestination.RegionName, destCellX, destCellY,
274 sp.Scene.RegionInfo.RegionName, curCellX, curCellY,
275 MaxTransferDistance));
276
277 return;
278 }
279 377
280 // 378 public void DoTeleport(
281 // This is it 379 ScenePresence sp, GridRegion reg, GridRegion finalDestination,
282 // 380 Vector3 position, Vector3 lookAt, uint teleportFlags)
283 DoTeleport(sp, reg, finalDestination, position, lookAt, teleportFlags, eq); 381 {
284 // 382 // Record that this agent is in transit so that we can prevent simultaneous requests and do later detection
285 // 383 // of whether the destination region completes the teleport.
286 // 384 if (!m_entityTransferStateMachine.SetInTransit(sp.UUID))
287 }
288 else
289 {
290 // TP to a place that doesn't exist (anymore)
291 // Inform the viewer about that
292 sp.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
293
294 // and set the map-tile to '(Offline)'
295 uint regX, regY;
296 Utils.LongToUInts(regionHandle, out regX, out regY);
297
298 MapBlockData block = new MapBlockData();
299 block.X = (ushort)(regX / Constants.RegionSize);
300 block.Y = (ushort)(regY / Constants.RegionSize);
301 block.Access = 254; // == not there
302
303 List<MapBlockData> blocks = new List<MapBlockData>();
304 blocks.Add(block);
305 sp.ControllingClient.SendMapBlock(blocks, 0);
306 }
307 }
308 }
309 catch (Exception e)
310 { 385 {
311 m_log.WarnFormat("[ENTITY TRANSFER MODULE]: Exception on teleport: {0} {1}", e.Message, e.StackTrace); 386 m_log.DebugFormat(
312 sp.ControllingClient.SendTeleportFailed("Internal error"); 387 "[ENTITY TRANSFER MODULE]: Ignoring teleport request of {0} {1} to {2} ({3}) {4}/{5} - agent is already in transit.",
388 sp.Name, sp.UUID, reg.ServerURI, finalDestination.ServerURI, finalDestination.RegionName, position);
389
390 return;
313 } 391 }
314 }
315 392
316 public void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq)
317 {
318 if (reg == null || finalDestination == null) 393 if (reg == null || finalDestination == null)
319 { 394 {
320 sp.ControllingClient.SendTeleportFailed("Unable to locate destination"); 395 sp.ControllingClient.SendTeleportFailed("Unable to locate destination");
321 return; 396 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
322 }
323 397
324 if (IsInTransit(sp.UUID)) // Avie is already on the way. Caller shouldn't do this.
325 return; 398 return;
399 }
326 400
327 m_log.DebugFormat( 401 m_log.DebugFormat(
328 "[ENTITY TRANSFER MODULE]: Request Teleport to {0} ({1}) {2}/{3}", 402 "[ENTITY TRANSFER MODULE]: Teleporting {0} {1} from {2} to {3} ({4}) {5}/{6}",
403 sp.Name, sp.UUID, sp.Scene.RegionInfo.RegionName,
329 reg.ServerURI, finalDestination.ServerURI, finalDestination.RegionName, position); 404 reg.ServerURI, finalDestination.ServerURI, finalDestination.RegionName, position);
330 405
406 RegionInfo sourceRegion = sp.Scene.RegionInfo;
407
408 if (!IsWithinMaxTeleportDistance(sourceRegion, finalDestination))
409 {
410 sp.ControllingClient.SendTeleportFailed(
411 string.Format(
412 "Can't teleport to {0} ({1},{2}) from {3} ({4},{5}), destination is more than {6} regions way",
413 finalDestination.RegionName, finalDestination.RegionCoordX, finalDestination.RegionCoordY,
414 sourceRegion.RegionName, sourceRegion.RegionLocX, sourceRegion.RegionLocY,
415 MaxTransferDistance));
416
417 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
418
419 return;
420 }
421
331 uint newRegionX = (uint)(reg.RegionHandle >> 40); 422 uint newRegionX = (uint)(reg.RegionHandle >> 40);
332 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); 423 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
333 uint oldRegionX = (uint)(sp.Scene.RegionInfo.RegionHandle >> 40); 424 uint oldRegionX = (uint)(sp.Scene.RegionInfo.RegionHandle >> 40);
@@ -339,17 +430,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
339 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, 430 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
340 // it's actually doing a lot of work. 431 // it's actually doing a lot of work.
341 IPEndPoint endPoint = finalDestination.ExternalEndPoint; 432 IPEndPoint endPoint = finalDestination.ExternalEndPoint;
342 if (endPoint != null && endPoint.Address != null) 433 if (endPoint == null || endPoint.Address == null)
343 { 434 {
344 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from 435 sp.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
345 // both regions 436 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
346 if (sp.ParentID != (uint)0)
347 sp.StandUp();
348 437
349 if (!sp.ValidateAttachments()) 438 return;
350 m_log.DebugFormat( 439 }
351 "[ENTITY TRANSFER MODULE]: Failed validation of all attachments for teleport of {0} from {1} to {2}. Continuing.", 440
352 sp.Name, sp.Scene.RegionInfo.RegionName, finalDestination.RegionName); 441 if (!sp.ValidateAttachments())
442 m_log.DebugFormat(
443 "[ENTITY TRANSFER MODULE]: Failed validation of all attachments for teleport of {0} from {1} to {2}. Continuing.",
444 sp.Name, sp.Scene.RegionInfo.RegionName, finalDestination.RegionName);
353 445
354// if (!sp.ValidateAttachments()) 446// if (!sp.ValidateAttachments())
355// { 447// {
@@ -357,218 +449,245 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
357// return; 449// return;
358// } 450// }
359 451
360 string reason; 452 string reason;
361 string version; 453 string version;
362 if (!m_aScene.SimulationService.QueryAccess(finalDestination, sp.ControllingClient.AgentId, Vector3.Zero, out version, out reason)) 454 if (!Scene.SimulationService.QueryAccess(
363 { 455 finalDestination, sp.ControllingClient.AgentId, Vector3.Zero, out version, out reason))
364 sp.ControllingClient.SendTeleportFailed("Teleport failed: " + reason); 456 {
365 return; 457 sp.ControllingClient.SendTeleportFailed(reason);
366 } 458 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
367 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Destination is running version {0}", version);
368
369 sp.ControllingClient.SendTeleportStart(teleportFlags);
370
371 // the avatar.Close below will clear the child region list. We need this below for (possibly)
372 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
373 //List<ulong> childRegions = avatar.KnownRegionHandles;
374 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
375 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
376 // once we reach here...
377 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
378
379 string capsPath = String.Empty;
380
381 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
382 AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo();
383 agentCircuit.startpos = position;
384 agentCircuit.child = true;
385 agentCircuit.Appearance = sp.Appearance;
386 if (currentAgentCircuit != null)
387 {
388 agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs;
389 agentCircuit.IPAddress = currentAgentCircuit.IPAddress;
390 agentCircuit.Viewer = currentAgentCircuit.Viewer;
391 agentCircuit.Channel = currentAgentCircuit.Channel;
392 agentCircuit.Mac = currentAgentCircuit.Mac;
393 agentCircuit.Id0 = currentAgentCircuit.Id0;
394 }
395 459
396 if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY)) 460 m_log.DebugFormat(
397 { 461 "[ENTITY TRANSFER MODULE]: {0} was stopped from teleporting from {1} to {2} because {3}",
398 // brand new agent, let's create a new caps seed 462 sp.Name, sp.Scene.RegionInfo.RegionName, finalDestination.RegionName, reason);
399 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
400 }
401 463
402 // Let's create an agent there if one doesn't exist yet. 464 return;
403 bool logout = false; 465 }
404 if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout))
405 {
406 sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}",
407 reason));
408 return;
409 }
410 466
411 // OK, it got this agent. Let's close some child agents 467 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Destination is running version {0}", version);
412 sp.CloseChildAgents(newRegionX, newRegionY);
413 IClientIPEndpoint ipepClient;
414 if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY))
415 {
416 //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Creating agent...");
417 #region IP Translation for NAT
418 // Uses ipepClient above
419 if (sp.ClientView.TryGet(out ipepClient))
420 {
421 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
422 }
423 #endregion
424 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
425 468
426 if (eq != null) 469 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
427 { 470 // both regions
428 eq.EnableSimulator(destinationHandle, endPoint, sp.UUID); 471 if (sp.ParentID != (uint)0)
472 sp.StandUp();
429 473
430 // ES makes the client send a UseCircuitCode message to the destination, 474 sp.ControllingClient.SendTeleportStart(teleportFlags);
431 // which triggers a bunch of things there.
432 // So let's wait
433 Thread.Sleep(200);
434 475
435 eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath); 476 // the avatar.Close below will clear the child region list. We need this below for (possibly)
477 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
478 //List<ulong> childRegions = avatar.KnownRegionHandles;
479 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
480 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
481 // once we reach here...
482 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
436 483
437 } 484 string capsPath = String.Empty;
438 else
439 {
440 sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint);
441 }
442 }
443 else
444 {
445 agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle);
446 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
447 }
448 485
486 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
487 AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo();
488 agentCircuit.startpos = position;
489 agentCircuit.child = true;
490 agentCircuit.Appearance = sp.Appearance;
491 if (currentAgentCircuit != null)
492 {
493 agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs;
494 agentCircuit.IPAddress = currentAgentCircuit.IPAddress;
495 agentCircuit.Viewer = currentAgentCircuit.Viewer;
496 agentCircuit.Channel = currentAgentCircuit.Channel;
497 agentCircuit.Mac = currentAgentCircuit.Mac;
498 agentCircuit.Id0 = currentAgentCircuit.Id0;
499 }
449 500
450 SetInTransit(sp.UUID); 501 if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY))
502 {
503 // brand new agent, let's create a new caps seed
504 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
505 }
451 506
452 // Let's send a full update of the agent. This is a synchronous call. 507 // Let's create an agent there if one doesn't exist yet.
453 AgentData agent = new AgentData(); 508 bool logout = false;
454 sp.CopyTo(agent); 509 if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout))
455 agent.Position = position; 510 {
456 SetCallbackURL(agent, sp.Scene.RegionInfo); 511 sp.ControllingClient.SendTeleportFailed(String.Format("Teleport refused: {0}", reason));
512 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
457 513
458 //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Updating agent..."); 514 m_log.DebugFormat(
515 "[ENTITY TRANSFER MODULE]: Teleport of {0} from {1} to {2} was refused because {3}",
516 sp.Name, sp.Scene.RegionInfo.RegionName, finalDestination.RegionName, reason);
459 517
460 if (!UpdateAgent(reg, finalDestination, agent)) 518 return;
519 }
520
521 // Past this point we have to attempt clean up if the teleport fails, so update transfer state.
522 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring);
523
524 // OK, it got this agent. Let's close some child agents
525 sp.CloseChildAgents(newRegionX, newRegionY);
526
527 IClientIPEndpoint ipepClient;
528 if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY))
529 {
530 //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Creating agent...");
531 #region IP Translation for NAT
532 // Uses ipepClient above
533 if (sp.ClientView.TryGet(out ipepClient))
461 { 534 {
462 // Region doesn't take it 535 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
463 m_log.WarnFormat(
464 "[ENTITY TRANSFER MODULE]: UpdateAgent failed on teleport of {0} to {1}. Returning avatar to source region.",
465 sp.Name, finalDestination.RegionName);
466
467 Fail(sp, finalDestination, logout);
468 return;
469 } 536 }
537 #endregion
538 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
470 539
471 sp.ControllingClient.SendTeleportProgress(teleportFlags | (uint)TeleportFlags.DisableCancel, "sending_dest"); 540 if (m_eqModule != null)
541 {
542 m_eqModule.EnableSimulator(destinationHandle, endPoint, sp.UUID);
472 543
473 m_log.DebugFormat( 544 // ES makes the client send a UseCircuitCode message to the destination,
474 "[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, sp.UUID); 545 // which triggers a bunch of things there.
546 // So let's wait
547 Thread.Sleep(200);
548
549 m_eqModule.EstablishAgentCommunication(sp.UUID, endPoint, capsPath);
475 550
476 if (eq != null)
477 {
478 eq.TeleportFinishEvent(destinationHandle, 13, endPoint,
479 0, teleportFlags, capsPath, sp.UUID);
480 } 551 }
481 else 552 else
482 { 553 {
483 sp.ControllingClient.SendRegionTeleport(destinationHandle, 13, endPoint, 4, 554 sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint);
484 teleportFlags, capsPath);
485 } 555 }
556 }
557 else
558 {
559 agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle);
560 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
561 }
486 562
487 // Let's set this to true tentatively. This does not trigger OnChildAgent 563 // Let's send a full update of the agent. This is a synchronous call.
488 sp.IsChildAgent = true; 564 AgentData agent = new AgentData();
565 sp.CopyTo(agent);
566 agent.Position = position;
567 SetCallbackURL(agent, sp.Scene.RegionInfo);
489 568
490 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which 569 //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Updating agent...");
491 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
492 // that the client contacted the destination before we close things here.
493 if (!WaitForCallback(sp.UUID))
494 {
495 m_log.WarnFormat(
496 "[ENTITY TRANSFER MODULE]: Teleport of {0} to {1} failed due to no callback from destination region. Returning avatar to source region.",
497 sp.Name, finalDestination.RegionName);
498
499 Fail(sp, finalDestination, logout);
500 return;
501 }
502 570
503 // For backwards compatibility 571 if (!UpdateAgent(reg, finalDestination, agent))
504 if (version == "Unknown" || version == string.Empty) 572 {
505 { 573 // Region doesn't take it
506 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it 574 m_log.WarnFormat(
507 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Old simulator, sending attachments one by one..."); 575 "[ENTITY TRANSFER MODULE]: UpdateAgent failed on teleport of {0} to {1} from {2}. Returning avatar to source region.",
508 CrossAttachmentsIntoNewRegion(finalDestination, sp, true); 576 sp.Name, finalDestination.RegionName, sp.Scene.RegionInfo.RegionName);
509 } 577
578 Fail(sp, finalDestination, logout);
579 return;
580 }
510 581
511 // May need to logout or other cleanup 582 sp.ControllingClient.SendTeleportProgress(teleportFlags | (uint)TeleportFlags.DisableCancel, "sending_dest");
512 AgentHasMovedAway(sp, logout);
513 583
514 // Well, this is it. The agent is over there. 584 m_log.DebugFormat(
515 KillEntity(sp.Scene, sp.LocalId); 585 "[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} from {1} to {2}",
586 capsPath, sp.Scene.RegionInfo.RegionName, sp.Name);
516 587
517 // Now let's make it officially a child agent 588 if (m_eqModule != null)
518 sp.MakeChildAgent(); 589 {
590 m_eqModule.TeleportFinishEvent(destinationHandle, 13, endPoint, 0, teleportFlags, capsPath, sp.UUID);
591 }
592 else
593 {
594 sp.ControllingClient.SendRegionTeleport(destinationHandle, 13, endPoint, 4,
595 teleportFlags, capsPath);
596 }
519 597
520// sp.Scene.CleanDroppedAttachments(); 598 // Let's set this to true tentatively. This does not trigger OnChildAgent
599 sp.IsChildAgent = true;
600
601 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
602 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
603 // that the client contacted the destination before we close things here.
604 if (!m_entityTransferStateMachine.WaitForAgentArrivedAtDestination(sp.UUID))
605 {
606 m_log.WarnFormat(
607 "[ENTITY TRANSFER MODULE]: Teleport of {0} to {1} from {2} failed due to no callback from destination region. Returning avatar to source region.",
608 sp.Name, finalDestination.RegionName, sp.Scene.RegionInfo.RegionName);
609
610 Fail(sp, finalDestination, logout);
611 return;
612 }
521 613
522 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone 614 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp);
523 615
524 if (NeedsClosing(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) 616 // For backwards compatibility
525 { 617 if (version == "Unknown" || version == string.Empty)
526 Thread.Sleep(5000); 618 {
527 sp.Close(); 619 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
528 sp.Scene.IncomingCloseAgent(sp.UUID); 620 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Old simulator, sending attachments one by one...");
529 } 621 CrossAttachmentsIntoNewRegion(finalDestination, sp, true);
530 else 622 }
531 {
532 // now we have a child agent in this region.
533 sp.Reset();
534 }
535 623
536 // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE! 624 // May need to logout or other cleanup
537 if (sp.Scene.NeedSceneCacheClear(sp.UUID)) 625 AgentHasMovedAway(sp, logout);
538 { 626
539 m_log.DebugFormat( 627 // Well, this is it. The agent is over there.
540 "[ENTITY TRANSFER MODULE]: User {0} is going to another region, profile cache removed", 628 KillEntity(sp.Scene, sp.LocalId);
541 sp.UUID); 629
542 } 630 // Now let's make it officially a child agent
631 sp.MakeChildAgent();
632
633// sp.Scene.CleanDroppedAttachments();
634
635 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
636
637 if (NeedsClosing(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
638 {
639 // We need to delay here because Imprudence viewers, unlike v1 or v3, have a short (<200ms, <500ms) delay before
640 // they regard the new region as the current region after receiving the AgentMovementComplete
641 // response. If close is sent before then, it will cause the viewer to quit instead.
642 //
643 // This sleep can be increased if necessary. However, whilst it's active,
644 // an agent cannot teleport back to this region if it has teleported away.
645 Thread.Sleep(2000);
646
647 sp.Scene.IncomingCloseAgent(sp.UUID);
543 } 648 }
544 else 649 else
545 { 650 {
546 sp.ControllingClient.SendTeleportFailed("Remote Region appears to be down"); 651 // now we have a child agent in this region.
652 sp.Reset();
547 } 653 }
654
655 // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
656 if (sp.Scene.NeedSceneCacheClear(sp.UUID))
657 {
658 m_log.DebugFormat(
659 "[ENTITY TRANSFER MODULE]: User {0} is going to another region, profile cache removed",
660 sp.UUID);
661 }
662
663 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
548 } 664 }
549 665
550 protected virtual void Fail(ScenePresence sp, GridRegion finalDestination, bool logout) 666 protected virtual void Fail(ScenePresence sp, GridRegion finalDestination, bool logout)
551 { 667 {
668 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp);
669
552 // Client never contacted destination. Let's restore everything back 670 // Client never contacted destination. Let's restore everything back
553 sp.ControllingClient.SendTeleportFailed("Problems connecting to destination."); 671 sp.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
554 672
555 // Fail. Reset it back 673 // Fail. Reset it back
556 sp.IsChildAgent = false; 674 sp.IsChildAgent = false;
557 ReInstantiateScripts(sp); 675 ReInstantiateScripts(sp);
558 ResetFromTransit(sp.UUID);
559 676
560 EnableChildAgents(sp); 677 EnableChildAgents(sp);
561 678
562 // Finally, kill the agent we just created at the destination. 679 // Finally, kill the agent we just created at the destination.
563 m_aScene.SimulationService.CloseAgent(finalDestination, sp.UUID); 680 Scene.SimulationService.CloseAgent(finalDestination, sp.UUID);
564 681
565 sp.Scene.EventManager.TriggerTeleportFail(sp.ControllingClient, logout); 682 sp.Scene.EventManager.TriggerTeleportFail(sp.ControllingClient, logout);
683
684 m_entityTransferStateMachine.ResetFromTransit(sp.UUID);
566 } 685 }
567 686
568 protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason, out bool logout) 687 protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason, out bool logout)
569 { 688 {
570 logout = false; 689 logout = false;
571 bool success = m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); 690 bool success = Scene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason);
572 691
573 if (success) 692 if (success)
574 sp.Scene.EventManager.TriggerTeleportStart(sp.ControllingClient, reg, finalDestination, teleportFlags, logout); 693 sp.Scene.EventManager.TriggerTeleportStart(sp.ControllingClient, reg, finalDestination, teleportFlags, logout);
@@ -578,19 +697,27 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
578 697
579 protected virtual bool UpdateAgent(GridRegion reg, GridRegion finalDestination, AgentData agent) 698 protected virtual bool UpdateAgent(GridRegion reg, GridRegion finalDestination, AgentData agent)
580 { 699 {
581 return m_aScene.SimulationService.UpdateAgent(finalDestination, agent); 700 return Scene.SimulationService.UpdateAgent(finalDestination, agent);
582 } 701 }
583 702
584 protected virtual void SetCallbackURL(AgentData agent, RegionInfo region) 703 protected virtual void SetCallbackURL(AgentData agent, RegionInfo region)
585 { 704 {
586 agent.CallbackURI = region.ServerURI + "agent/" + agent.AgentID.ToString() + "/" + region.RegionID.ToString() + "/release/"; 705 agent.CallbackURI = region.ServerURI + "agent/" + agent.AgentID.ToString() + "/" + region.RegionID.ToString() + "/release/";
587 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Set callback URL to {0}", agent.CallbackURI);
588 706
707 m_log.DebugFormat(
708 "[ENTITY TRANSFER MODULE]: Set release callback URL to {0} in {1}",
709 agent.CallbackURI, region.RegionName);
589 } 710 }
590 711
712 /// <summary>
713 /// Clean up operations once an agent has moved away through cross or teleport.
714 /// </summary>
715 /// <param name='sp'></param>
716 /// <param name='logout'></param>
591 protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout) 717 protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout)
592 { 718 {
593 sp.Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, true); 719 if (sp.Scene.AttachmentsModule != null)
720 sp.Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, true);
594 } 721 }
595 722
596 protected void KillEntity(Scene scene, uint localID) 723 protected void KillEntity(Scene scene, uint localID)
@@ -615,7 +742,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
615 742
616 protected virtual bool IsOutsideRegion(Scene s, Vector3 pos) 743 protected virtual bool IsOutsideRegion(Scene s, Vector3 pos)
617 { 744 {
618
619 if (s.TestBorderCross(pos, Cardinals.N)) 745 if (s.TestBorderCross(pos, Cardinals.N))
620 return true; 746 return true;
621 if (s.TestBorderCross(pos, Cardinals.S)) 747 if (s.TestBorderCross(pos, Cardinals.S))
@@ -628,7 +754,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
628 return false; 754 return false;
629 } 755 }
630 756
631
632 #endregion 757 #endregion
633 758
634 #region Landmark Teleport 759 #region Landmark Teleport
@@ -640,7 +765,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
640 /// <param name="position"></param> 765 /// <param name="position"></param>
641 public virtual void RequestTeleportLandmark(IClientAPI remoteClient, AssetLandmark lm) 766 public virtual void RequestTeleportLandmark(IClientAPI remoteClient, AssetLandmark lm)
642 { 767 {
643 GridRegion info = m_aScene.GridService.GetRegionByUUID(UUID.Zero, lm.RegionID); 768 GridRegion info = Scene.GridService.GetRegionByUUID(UUID.Zero, lm.RegionID);
644 769
645 if (info == null) 770 if (info == null)
646 { 771 {
@@ -663,10 +788,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
663 788
664 public virtual bool TeleportHome(UUID id, IClientAPI client) 789 public virtual bool TeleportHome(UUID id, IClientAPI client)
665 { 790 {
666 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.FirstName, client.LastName); 791 m_log.DebugFormat(
792 "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, client.AgentId);
667 793
668 //OpenSim.Services.Interfaces.PresenceInfo pinfo = m_aScene.PresenceService.GetAgent(client.SessionId); 794 //OpenSim.Services.Interfaces.PresenceInfo pinfo = Scene.PresenceService.GetAgent(client.SessionId);
669 GridUserInfo uinfo = m_aScene.GridUserService.GetGridUserInfo(client.AgentId.ToString()); 795 GridUserInfo uinfo = Scene.GridUserService.GetGridUserInfo(client.AgentId.ToString());
670 796
671 if (uinfo != null) 797 if (uinfo != null)
672 { 798 {
@@ -676,7 +802,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
676 client.SendTeleportFailed("You don't have a home position set."); 802 client.SendTeleportFailed("You don't have a home position set.");
677 return false; 803 return false;
678 } 804 }
679 GridRegion regionInfo = m_aScene.GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID); 805 GridRegion regionInfo = Scene.GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID);
680 if (regionInfo == null) 806 if (regionInfo == null)
681 { 807 {
682 // can't find the Home region: Tell viewer and abort 808 // can't find the Home region: Tell viewer and abort
@@ -684,8 +810,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
684 return false; 810 return false;
685 } 811 }
686 812
687 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: User's home region is {0} {1} ({2}-{3})", 813 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Home region of {0} is {1} ({2}-{3})",
688 regionInfo.RegionName, regionInfo.RegionID, regionInfo.RegionLocX / Constants.RegionSize, regionInfo.RegionLocY / Constants.RegionSize); 814 client.Name, regionInfo.RegionName, regionInfo.RegionCoordX, regionInfo.RegionCoordY);
689 815
690 // a little eekie that this goes back to Scene and with a forced cast, will fix that at some point... 816 // a little eekie that this goes back to Scene and with a forced cast, will fix that at some point...
691 ((Scene)(client.Scene)).RequestTeleportLocation( 817 ((Scene)(client.Scene)).RequestTeleportLocation(
@@ -736,7 +862,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
736 862
737 neighbourx--; 863 neighbourx--;
738 newpos.X = Constants.RegionSize - enterDistance; 864 newpos.X = Constants.RegionSize - enterDistance;
739
740 } 865 }
741 else if (scene.TestBorderCross(pos + eastCross, Cardinals.E)) 866 else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
742 { 867 {
@@ -922,107 +1047,123 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
922 ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, GridRegion neighbourRegion, 1047 ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, GridRegion neighbourRegion,
923 bool isFlying, string version) 1048 bool isFlying, string version)
924 { 1049 {
1050 if (neighbourRegion == null)
1051 return agent;
1052
925 try 1053 try
926 { 1054 {
1055 m_entityTransferStateMachine.SetInTransit(agent.UUID);
1056
927 ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize)); 1057 ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
928 1058
929 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Crossing agent {0} {1} to {2}-{3} running version {4}", agent.Firstname, agent.Lastname, neighbourx, neighboury, version); 1059 m_log.DebugFormat(
1060 "[ENTITY TRANSFER MODULE]: Crossing agent {0} {1} to {2}-{3} running version {4}",
1061 agent.Firstname, agent.Lastname, neighbourx, neighboury, version);
930 1062
931 Scene m_scene = agent.Scene; 1063 Scene m_scene = agent.Scene;
932 1064
933 if (neighbourRegion != null) 1065 if (!agent.ValidateAttachments())
1066 m_log.DebugFormat(
1067 "[ENTITY TRANSFER MODULE]: Failed validation of all attachments for region crossing of {0} from {1} to {2}. Continuing.",
1068 agent.Name, agent.Scene.RegionInfo.RegionName, neighbourRegion.RegionName);
1069
1070 pos = pos + agent.Velocity;
1071 Vector3 vel2 = new Vector3(agent.Velocity.X, agent.Velocity.Y, 0);
1072
1073 agent.RemoveFromPhysicalScene();
1074
1075 AgentData cAgent = new AgentData();
1076 agent.CopyTo(cAgent);
1077 cAgent.Position = pos;
1078 if (isFlying)
1079 cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
1080
1081 // We don't need the callback anymnore
1082 cAgent.CallbackURI = String.Empty;
1083
1084 // Beyond this point, extra cleanup is needed beyond removing transit state
1085 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.Transferring);
1086
1087 if (!m_scene.SimulationService.UpdateAgent(neighbourRegion, cAgent))
934 { 1088 {
935 if (!agent.ValidateAttachments()) 1089 // region doesn't take it
936 m_log.DebugFormat( 1090 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.CleaningUp);
937 "[ENTITY TRANSFER MODULE]: Failed validation of all attachments for region crossing of {0} from {1} to {2}. Continuing.",
938 agent.Name, agent.Scene.RegionInfo.RegionName, neighbourRegion.RegionName);
939 1091
940 pos = pos + agent.Velocity; 1092 ReInstantiateScripts(agent);
941 Vector3 vel2 = new Vector3(agent.Velocity.X, agent.Velocity.Y, 0); 1093 agent.AddToPhysicalScene(isFlying);
1094 m_entityTransferStateMachine.ResetFromTransit(agent.UUID);
942 1095
943 agent.RemoveFromPhysicalScene(); 1096 return agent;
944 SetInTransit(agent.UUID); 1097 }
945 1098
946 AgentData cAgent = new AgentData(); 1099 //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
947 agent.CopyTo(cAgent); 1100 agent.ControllingClient.RequestClientInfo();
948 cAgent.Position = pos;
949 if (isFlying)
950 cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
951 1101
952 // We don't need the callback anymnore 1102 //m_log.Debug("BEFORE CROSS");
953 cAgent.CallbackURI = String.Empty; 1103 //Scene.DumpChildrenSeeds(UUID);
1104 //DumpKnownRegions();
1105 string agentcaps;
1106 if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps))
1107 {
1108 m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: No ENTITY TRANSFER MODULE information for region handle {0}, exiting CrossToNewRegion.",
1109 neighbourRegion.RegionHandle);
1110 return agent;
1111 }
1112 // No turning back
1113 agent.IsChildAgent = true;
954 1114
955 if (!m_scene.SimulationService.UpdateAgent(neighbourRegion, cAgent)) 1115 string capsPath = neighbourRegion.ServerURI + CapsUtil.GetCapsSeedPath(agentcaps);
956 {
957 // region doesn't take it
958 ReInstantiateScripts(agent);
959 agent.AddToPhysicalScene(isFlying);
960 ResetFromTransit(agent.UUID);
961 return agent;
962 }
963
964 //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
965 agent.ControllingClient.RequestClientInfo();
966
967 //m_log.Debug("BEFORE CROSS");
968 //Scene.DumpChildrenSeeds(UUID);
969 //DumpKnownRegions();
970 string agentcaps;
971 if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps))
972 {
973 m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: No ENTITY TRANSFER MODULE information for region handle {0}, exiting CrossToNewRegion.",
974 neighbourRegion.RegionHandle);
975 return agent;
976 }
977 // No turning back
978 agent.IsChildAgent = true;
979 1116
980 string capsPath = neighbourRegion.ServerURI + CapsUtil.GetCapsSeedPath(agentcaps); 1117 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, agent.UUID);
981
982 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, agent.UUID);
983 1118
984 IEventQueue eq = agent.Scene.RequestModuleInterface<IEventQueue>(); 1119 if (m_eqModule != null)
985 if (eq != null) 1120 {
986 { 1121 m_eqModule.CrossRegion(
987 eq.CrossRegion(neighbourHandle, pos, vel2 /* agent.Velocity */, neighbourRegion.ExternalEndPoint, 1122 neighbourHandle, pos, vel2 /* agent.Velocity */, neighbourRegion.ExternalEndPoint,
988 capsPath, agent.UUID, agent.ControllingClient.SessionId); 1123 capsPath, agent.UUID, agent.ControllingClient.SessionId);
989 } 1124 }
990 else 1125 else
991 { 1126 {
992 agent.ControllingClient.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint, 1127 agent.ControllingClient.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
993 capsPath); 1128 capsPath);
994 } 1129 }
995 1130
996 // SUCCESS! 1131 // SUCCESS!
997 agent.MakeChildAgent(); 1132 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.ReceivedAtDestination);
998 ResetFromTransit(agent.UUID);
999 1133
1000 // now we have a child agent in this region. Request all interesting data about other (root) agents 1134 // Unlike a teleport, here we do not wait for the destination region to confirm the receipt.
1001 agent.SendOtherAgentsAvatarDataToMe(); 1135 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.CleaningUp);
1002 agent.SendOtherAgentsAppearanceToMe();
1003 1136
1004 // Backwards compatibility. Best effort 1137 agent.MakeChildAgent();
1005 if (version == "Unknown" || version == string.Empty)
1006 {
1007 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: neighbor with old version, passing attachments one by one...");
1008 Thread.Sleep(3000); // wait a little now that we're not waiting for the callback
1009 CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true);
1010 }
1011 1138
1139 // FIXME: Possibly this should occur lower down after other commands to close other agents,
1140 // but not sure yet what the side effects would be.
1141 m_entityTransferStateMachine.ResetFromTransit(agent.UUID);
1012 1142
1013 // Next, let's close the child agent connections that are too far away. 1143 // now we have a child agent in this region. Request all interesting data about other (root) agents
1014 agent.CloseChildAgents(neighbourx, neighboury); 1144 agent.SendOtherAgentsAvatarDataToMe();
1015 1145 agent.SendOtherAgentsAppearanceToMe();
1016 AgentHasMovedAway(agent, false); 1146
1017 1147 // Backwards compatibility. Best effort
1018 // the user may change their profile information in other region, 1148 if (version == "Unknown" || version == string.Empty)
1019 // so the userinfo in UserProfileCache is not reliable any more, delete it 1149 {
1020 // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE! 1150 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: neighbor with old version, passing attachments one by one...");
1021 if (agent.Scene.NeedSceneCacheClear(agent.UUID)) 1151 Thread.Sleep(3000); // wait a little now that we're not waiting for the callback
1022 { 1152 CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true);
1023 m_log.DebugFormat( 1153 }
1024 "[ENTITY TRANSFER MODULE]: User {0} is going to another region", agent.UUID); 1154
1025 } 1155 // Next, let's close the child agent connections that are too far away.
1156 agent.CloseChildAgents(neighbourx, neighboury);
1157
1158 AgentHasMovedAway(agent, false);
1159
1160 // the user may change their profile information in other region,
1161 // so the userinfo in UserProfileCache is not reliable any more, delete it
1162 // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
1163 if (agent.Scene.NeedSceneCacheClear(agent.UUID))
1164 {
1165 m_log.DebugFormat(
1166 "[ENTITY TRANSFER MODULE]: User {0} is going to another region", agent.UUID);
1026 } 1167 }
1027 1168
1028 //m_log.Debug("AFTER CROSS"); 1169 //m_log.Debug("AFTER CROSS");
@@ -1034,11 +1175,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1034 m_log.ErrorFormat( 1175 m_log.ErrorFormat(
1035 "[ENTITY TRANSFER MODULE]: Problem crossing user {0} to new region {1} from {2}. Exception {3}{4}", 1176 "[ENTITY TRANSFER MODULE]: Problem crossing user {0} to new region {1} from {2}. Exception {3}{4}",
1036 agent.Name, neighbourRegion.RegionName, agent.Scene.RegionInfo.RegionName, e.Message, e.StackTrace); 1177 agent.Name, neighbourRegion.RegionName, agent.Scene.RegionInfo.RegionName, e.Message, e.StackTrace);
1178
1179 // TODO: Might be worth attempting other restoration here such as reinstantiation of scripts, etc.
1037 } 1180 }
1038 1181
1039 return agent; 1182 return agent;
1040 } 1183 }
1041 1184
1042 private void CrossAgentToNewRegionCompleted(IAsyncResult iar) 1185 private void CrossAgentToNewRegionCompleted(IAsyncResult iar)
1043 { 1186 {
1044 CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState; 1187 CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState;
@@ -1186,7 +1329,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1186 { 1329 {
1187 if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle) 1330 if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle)
1188 { 1331 {
1189
1190 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); 1332 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
1191 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo(); 1333 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
1192 agent.BaseFolder = UUID.Zero; 1334 agent.BaseFolder = UUID.Zero;
@@ -1211,7 +1353,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1211 seeds.Add(neighbour.RegionHandle, agent.CapsPath); 1353 seeds.Add(neighbour.RegionHandle, agent.CapsPath);
1212 } 1354 }
1213 else 1355 else
1356 {
1214 agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, neighbour.RegionHandle); 1357 agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, neighbour.RegionHandle);
1358 }
1215 1359
1216 cagents.Add(agent); 1360 cagents.Add(agent);
1217 } 1361 }
@@ -1322,24 +1466,21 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1322 // after a cross here 1466 // after a cross here
1323 Thread.Sleep(500); 1467 Thread.Sleep(500);
1324 1468
1325 Scene m_scene = sp.Scene; 1469 Scene scene = sp.Scene;
1326 1470
1327 uint x, y; 1471 m_log.DebugFormat(
1328 Utils.LongToUInts(reg.RegionHandle, out x, out y); 1472 "[ENTITY TRANSFER MODULE]: Informing {0} {1} about neighbour {2} {3} at ({4},{5})",
1329 x = x / Constants.RegionSize; 1473 sp.Name, sp.UUID, reg.RegionName, endPoint, reg.RegionCoordX, reg.RegionCoordY);
1330 y = y / Constants.RegionSize;
1331 m_log.Debug("[ENTITY TRANSFER MODULE]: Starting to inform client about neighbour " + x + ", " + y + "(" + endPoint + ")");
1332 1474
1333 string capsPath = reg.ServerURI + CapsUtil.GetCapsSeedPath(a.CapsPath); 1475 string capsPath = reg.ServerURI + CapsUtil.GetCapsSeedPath(a.CapsPath);
1334 1476
1335 string reason = String.Empty; 1477 string reason = String.Empty;
1336 1478
1337 bool regionAccepted = m_scene.SimulationService.CreateAgent(reg, a, (uint)TeleportFlags.Default, out reason); 1479 bool regionAccepted = scene.SimulationService.CreateAgent(reg, a, (uint)TeleportFlags.Default, out reason);
1338 1480
1339 if (regionAccepted && newAgent) 1481 if (regionAccepted && newAgent)
1340 { 1482 {
1341 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>(); 1483 if (m_eqModule != null)
1342 if (eq != null)
1343 { 1484 {
1344 #region IP Translation for NAT 1485 #region IP Translation for NAT
1345 IClientIPEndpoint ipepClient; 1486 IClientIPEndpoint ipepClient;
@@ -1351,10 +1492,10 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1351 1492
1352 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: {0} is sending {1} EnableSimulator for neighbour region {2} @ {3} " + 1493 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: {0} is sending {1} EnableSimulator for neighbour region {2} @ {3} " +
1353 "and EstablishAgentCommunication with seed cap {4}", 1494 "and EstablishAgentCommunication with seed cap {4}",
1354 m_scene.RegionInfo.RegionName, sp.Name, reg.RegionName, reg.RegionHandle, capsPath); 1495 scene.RegionInfo.RegionName, sp.Name, reg.RegionName, reg.RegionHandle, capsPath);
1355 1496
1356 eq.EnableSimulator(reg.RegionHandle, endPoint, sp.UUID); 1497 m_eqModule.EnableSimulator(reg.RegionHandle, endPoint, sp.UUID);
1357 eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath); 1498 m_eqModule.EstablishAgentCommunication(sp.UUID, endPoint, capsPath);
1358 } 1499 }
1359 else 1500 else
1360 { 1501 {
@@ -1362,8 +1503,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1362 // TODO: make Event Queue disablable! 1503 // TODO: make Event Queue disablable!
1363 } 1504 }
1364 1505
1365 m_log.Debug("[ENTITY TRANSFER MODULE]: Completed inform client about neighbour " + endPoint.ToString()); 1506 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Completed inform {0} {1} about neighbour {2}", sp.Name, sp.UUID, endPoint);
1366 } 1507 }
1508
1509 if (!regionAccepted)
1510 m_log.WarnFormat(
1511 "[ENTITY TRANSFER MODULE]: Region {0} did not accept {1} {2}: {3}",
1512 reg.RegionName, sp.Name, sp.UUID, reason);
1367 } 1513 }
1368 1514
1369 /// <summary> 1515 /// <summary>
@@ -1471,17 +1617,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1471 1617
1472 #endregion 1618 #endregion
1473 1619
1474
1475 #region Agent Arrived 1620 #region Agent Arrived
1621
1476 public void AgentArrivedAtDestination(UUID id) 1622 public void AgentArrivedAtDestination(UUID id)
1477 { 1623 {
1478 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Agent {0} released", id); 1624 m_entityTransferStateMachine.SetAgentArrivedAtDestination(id);
1479 ResetFromTransit(id);
1480 } 1625 }
1481 1626
1482 #endregion 1627 #endregion
1483 1628
1484 #region Object Transfers 1629 #region Object Transfers
1630
1485 /// <summary> 1631 /// <summary>
1486 /// Move the given scene object into a new region depending on which region its absolute position has moved 1632 /// Move the given scene object into a new region depending on which region its absolute position has moved
1487 /// into. 1633 /// into.
@@ -1747,8 +1893,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1747 //// And the new channel... 1893 //// And the new channel...
1748 //if (m_interregionCommsOut != null) 1894 //if (m_interregionCommsOut != null)
1749 // successYN = m_interregionCommsOut.SendCreateObject(newRegionHandle, grp, true); 1895 // successYN = m_interregionCommsOut.SendCreateObject(newRegionHandle, grp, true);
1750 if (m_aScene.SimulationService != null) 1896 if (Scene.SimulationService != null)
1751 successYN = m_aScene.SimulationService.CreateObject(destination, newPosition, grp, true); 1897 successYN = Scene.SimulationService.CreateObject(destination, newPosition, grp, true);
1752 1898
1753 if (successYN) 1899 if (successYN)
1754 { 1900 {
@@ -1792,86 +1938,52 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1792 return successYN; 1938 return successYN;
1793 } 1939 }
1794 1940
1795 protected bool CrossAttachmentsIntoNewRegion(GridRegion destination, ScenePresence sp, bool silent) 1941 /// <summary>
1942 /// Cross the attachments for an avatar into the destination region.
1943 /// </summary>
1944 /// <remarks>
1945 /// This is only invoked for simulators released prior to April 2011. Versions of OpenSimulator since then
1946 /// transfer attachments in one go as part of the ChildAgentDataUpdate data passed in the update agent call.
1947 /// </remarks>
1948 /// <param name='destination'></param>
1949 /// <param name='sp'></param>
1950 /// <param name='silent'></param>
1951 protected void CrossAttachmentsIntoNewRegion(GridRegion destination, ScenePresence sp, bool silent)
1796 { 1952 {
1797 List<SceneObjectGroup> m_attachments = sp.GetAttachments(); 1953 List<SceneObjectGroup> attachments = sp.GetAttachments();
1798 1954
1799 // Validate 1955// m_log.DebugFormat(
1800// foreach (SceneObjectGroup gobj in m_attachments) 1956// "[ENTITY TRANSFER MODULE]: Crossing {0} attachments into {1} for {2}",
1801// { 1957// m_attachments.Count, destination.RegionName, sp.Name);
1802// if (gobj == null || gobj.IsDeleted)
1803// return false;
1804// }
1805 1958
1806 foreach (SceneObjectGroup gobj in m_attachments) 1959 foreach (SceneObjectGroup gobj in attachments)
1807 { 1960 {
1808 // If the prim group is null then something must have happened to it! 1961 // If the prim group is null then something must have happened to it!
1809 if (gobj != null && !gobj.IsDeleted) 1962 if (gobj != null && !gobj.IsDeleted)
1810 { 1963 {
1811 // Set the parent localID to 0 so it transfers over properly. 1964 SceneObjectGroup clone = (SceneObjectGroup)gobj.CloneForNewScene();
1812 gobj.RootPart.SetParentLocalId(0); 1965 clone.RootPart.GroupPosition = gobj.RootPart.AttachedPos;
1813 gobj.AbsolutePosition = gobj.RootPart.AttachedPos; 1966 clone.IsAttachment = false;
1814 gobj.IsAttachment = false; 1967
1815 //gobj.RootPart.LastOwnerID = gobj.GetFromAssetID(); 1968 //gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
1816 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Sending attachment {0} to region {1}", gobj.UUID, destination.RegionName); 1969 m_log.DebugFormat(
1817 CrossPrimGroupIntoNewRegion(destination, Vector3.Zero, gobj, silent); 1970 "[ENTITY TRANSFER MODULE]: Sending attachment {0} to region {1}",
1971 clone.UUID, destination.RegionName);
1972
1973 CrossPrimGroupIntoNewRegion(destination, Vector3.Zero, clone, silent);
1818 } 1974 }
1819 } 1975 }
1820 1976
1821 sp.ClearAttachments(); 1977 sp.ClearAttachments();
1822
1823 return true;
1824 } 1978 }
1825 1979
1826 #endregion 1980 #endregion
1827 1981
1828 #region Misc 1982 #region Misc
1829 1983
1830 protected bool WaitForCallback(UUID id) 1984 public bool IsInTransit(UUID id)
1831 {
1832 int count = 200;
1833 while (m_agentsInTransit.Contains(id) && count-- > 0)
1834 {
1835 //m_log.Debug(" >>> Waiting... " + count);
1836 Thread.Sleep(100);
1837 }
1838
1839 if (count > 0)
1840 return true;
1841 else
1842 return false;
1843 }
1844
1845 protected void SetInTransit(UUID id)
1846 {
1847 lock (m_agentsInTransit)
1848 {
1849 if (!m_agentsInTransit.Contains(id))
1850 m_agentsInTransit.Add(id);
1851 }
1852 }
1853
1854 protected bool IsInTransit(UUID id)
1855 { 1985 {
1856 lock (m_agentsInTransit) 1986 return m_entityTransferStateMachine.IsInTransit(id);
1857 {
1858 if (m_agentsInTransit.Contains(id))
1859 return true;
1860 }
1861 return false;
1862 }
1863
1864 protected bool ResetFromTransit(UUID id)
1865 {
1866 lock (m_agentsInTransit)
1867 {
1868 if (m_agentsInTransit.Contains(id))
1869 {
1870 m_agentsInTransit.Remove(id);
1871 return true;
1872 }
1873 }
1874 return false;
1875 } 1987 }
1876 1988
1877 protected void ReInstantiateScripts(ScenePresence sp) 1989 protected void ReInstantiateScripts(ScenePresence sp)
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
new file mode 100644
index 0000000..d0cab49
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
@@ -0,0 +1,269 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using System.Threading;
33using OpenMetaverse;
34using log4net;
35using Nini.Config;
36using OpenSim.Framework;
37using OpenSim.Framework.Capabilities;
38using OpenSim.Framework.Client;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.Physics.Manager;
42using OpenSim.Services.Interfaces;
43using GridRegion = OpenSim.Services.Interfaces.GridRegion;
44
45namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
46{
47 /// <summary>
48 /// The possible states that an agent can be in when its being transferred between regions.
49 /// </summary>
50 /// <remarks>
51 /// This is a state machine.
52 ///
53 /// [Entry] => Preparing
54 /// Preparing => { Transferring || CleaningUp || [Exit] }
55 /// Transferring => { ReceivedAtDestination || CleaningUp }
56 /// ReceivedAtDestination => CleaningUp
57 /// CleaningUp => [Exit]
58 ///
59 /// In other words, agents normally travel throwing Preparing => Transferring => ReceivedAtDestination => CleaningUp
60 /// However, any state can transition to CleaningUp if the teleport has failed.
61 /// </remarks>
62 enum AgentTransferState
63 {
64 Preparing, // The agent is being prepared for transfer
65 Transferring, // The agent is in the process of being transferred to a destination
66 ReceivedAtDestination, // The destination has notified us that the agent has been successfully received
67 CleaningUp // The agent is being changed to child/removed after a transfer
68 }
69
70 /// <summary>
71 /// Records the state of entities when they are in transfer within or between regions (cross or teleport).
72 /// </summary>
73 public class EntityTransferStateMachine
74 {
75 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
76
77 /// <summary>
78 /// If true then on a teleport, the source region waits for a callback from the destination region. If
79 /// a callback fails to arrive within a set time then the user is pulled back into the source region.
80 /// </summary>
81 public bool EnableWaitForAgentArrivedAtDestination { get; set; }
82
83 private EntityTransferModule m_mod;
84
85 private Dictionary<UUID, AgentTransferState> m_agentsInTransit = new Dictionary<UUID, AgentTransferState>();
86
87 public EntityTransferStateMachine(EntityTransferModule module)
88 {
89 m_mod = module;
90 }
91
92 /// <summary>
93 /// Set that an agent is in transit.
94 /// </summary>
95 /// <param name='id'>The ID of the agent being teleported</param>
96 /// <returns>true if the agent was not already in transit, false if it was</returns>
97 internal bool SetInTransit(UUID id)
98 {
99 lock (m_agentsInTransit)
100 {
101 if (!m_agentsInTransit.ContainsKey(id))
102 {
103 m_agentsInTransit[id] = AgentTransferState.Preparing;
104 return true;
105 }
106 }
107
108 return false;
109 }
110
111 /// <summary>
112 /// Updates the state of an agent that is already in transit.
113 /// </summary>
114 /// <param name='id'></param>
115 /// <param name='newState'></param>
116 /// <returns></returns>
117 /// <exception cref='Exception'>Illegal transitions will throw an Exception</exception>
118 internal void UpdateInTransit(UUID id, AgentTransferState newState)
119 {
120 lock (m_agentsInTransit)
121 {
122 // Illegal to try and update an agent that's not actually in transit.
123 if (!m_agentsInTransit.ContainsKey(id))
124 throw new Exception(
125 string.Format(
126 "Agent with ID {0} is not registered as in transit in {1}",
127 id, m_mod.Scene.RegionInfo.RegionName));
128
129 AgentTransferState oldState = m_agentsInTransit[id];
130
131 bool transitionOkay = false;
132
133 if (newState == AgentTransferState.CleaningUp && oldState != AgentTransferState.CleaningUp)
134 transitionOkay = true;
135 else if (newState == AgentTransferState.Transferring && oldState == AgentTransferState.Preparing)
136 transitionOkay = true;
137 else if (newState == AgentTransferState.ReceivedAtDestination && oldState == AgentTransferState.Transferring)
138 transitionOkay = true;
139
140 if (transitionOkay)
141 m_agentsInTransit[id] = newState;
142 else
143 throw new Exception(
144 string.Format(
145 "Agent with ID {0} is not allowed to move from old transit state {1} to new state {2} in {3}",
146 id, oldState, newState, m_mod.Scene.RegionInfo.RegionName));
147 }
148 }
149
150 internal bool IsInTransit(UUID id)
151 {
152 lock (m_agentsInTransit)
153 return m_agentsInTransit.ContainsKey(id);
154 }
155
156 /// <summary>
157 /// Removes an agent from the transit state machine.
158 /// </summary>
159 /// <param name='id'></param>
160 /// <returns>true if the agent was flagged as being teleported when this method was called, false otherwise</returns>
161 internal bool ResetFromTransit(UUID id)
162 {
163 lock (m_agentsInTransit)
164 {
165 if (m_agentsInTransit.ContainsKey(id))
166 {
167 AgentTransferState state = m_agentsInTransit[id];
168
169 if (state == AgentTransferState.Transferring || state == AgentTransferState.ReceivedAtDestination)
170 {
171 // FIXME: For now, we allow exit from any state since a thrown exception in teleport is now guranteed
172 // to be handled properly - ResetFromTransit() could be invoked at any step along the process
173 m_log.WarnFormat(
174 "[ENTITY TRANSFER STATE MACHINE]: Agent with ID {0} should not exit directly from state {1}, should go to {2} state first in {3}",
175 id, state, AgentTransferState.CleaningUp, m_mod.Scene.RegionInfo.RegionName);
176
177// throw new Exception(
178// "Agent with ID {0} cannot exit directly from state {1}, it must go to {2} state first",
179// state, AgentTransferState.CleaningUp);
180 }
181
182 m_agentsInTransit.Remove(id);
183
184 m_log.DebugFormat(
185 "[ENTITY TRANSFER STATE MACHINE]: Agent {0} cleared from transit in {1}",
186 id, m_mod.Scene.RegionInfo.RegionName);
187
188 return true;
189 }
190 }
191
192 m_log.WarnFormat(
193 "[ENTITY TRANSFER STATE MACHINE]: Agent {0} requested to clear from transit in {1} but was already cleared",
194 id, m_mod.Scene.RegionInfo.RegionName);
195
196 return false;
197 }
198
199 internal bool WaitForAgentArrivedAtDestination(UUID id)
200 {
201 if (!m_mod.WaitForAgentArrivedAtDestination)
202 return true;
203
204 lock (m_agentsInTransit)
205 {
206 if (!IsInTransit(id))
207 throw new Exception(
208 string.Format(
209 "Asked to wait for destination callback for agent with ID {0} in {1} but agent is not in transit",
210 id, m_mod.Scene.RegionInfo.RegionName));
211
212 AgentTransferState currentState = m_agentsInTransit[id];
213
214 if (currentState != AgentTransferState.Transferring && currentState != AgentTransferState.ReceivedAtDestination)
215 throw new Exception(
216 string.Format(
217 "Asked to wait for destination callback for agent with ID {0} in {1} but agent is in state {2}",
218 id, m_mod.Scene.RegionInfo.RegionName, currentState));
219 }
220
221 int count = 200;
222
223 // There should be no race condition here since no other code should be removing the agent transfer or
224 // changing the state to another other than Transferring => ReceivedAtDestination.
225 while (m_agentsInTransit[id] != AgentTransferState.ReceivedAtDestination && count-- > 0)
226 {
227// m_log.Debug(" >>> Waiting... " + count);
228 Thread.Sleep(100);
229 }
230
231 return count > 0;
232 }
233
234 internal void SetAgentArrivedAtDestination(UUID id)
235 {
236 lock (m_agentsInTransit)
237 {
238 if (!m_agentsInTransit.ContainsKey(id))
239 {
240 m_log.WarnFormat(
241 "[ENTITY TRANSFER STATE MACHINE]: Region {0} received notification of arrival in destination of agent {1} but no teleport request is active",
242 m_mod.Scene.RegionInfo.RegionName, id);
243
244 return;
245 }
246
247 AgentTransferState currentState = m_agentsInTransit[id];
248
249 if (currentState == AgentTransferState.ReceivedAtDestination)
250 {
251 // An anomoly but don't make this an outright failure - destination region could be overzealous in sending notification.
252 m_log.WarnFormat(
253 "[ENTITY TRANSFER STATE MACHINE]: Region {0} received notification of arrival in destination of agent {1} but notification has already previously been received",
254 m_mod.Scene.RegionInfo.RegionName, id);
255 }
256 else if (currentState != AgentTransferState.Transferring)
257 {
258 m_log.ErrorFormat(
259 "[ENTITY TRANSFER STATE MACHINE]: Region {0} received notification of arrival in destination of agent {1} but agent is in state {2}",
260 m_mod.Scene.RegionInfo.RegionName, id, currentState);
261
262 return;
263 }
264
265 m_agentsInTransit[id] = AgentTransferState.ReceivedAtDestination;
266 }
267 }
268 }
269} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
index 8b5ad23..3010b59 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
@@ -45,11 +45,12 @@ using Nini.Config;
45 45
46namespace OpenSim.Region.CoreModules.Framework.EntityTransfer 46namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
47{ 47{
48 public class HGEntityTransferModule : EntityTransferModule, ISharedRegionModule, IEntityTransferModule, IUserAgentVerificationModule 48 public class HGEntityTransferModule
49 : EntityTransferModule, INonSharedRegionModule, IEntityTransferModule, IUserAgentVerificationModule
49 { 50 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 52
52 private bool m_Initialized = false; 53 private int m_levelHGTeleport = 0;
53 54
54 private GatekeeperServiceConnector m_GatekeeperConnector; 55 private GatekeeperServiceConnector m_GatekeeperConnector;
55 56
@@ -63,11 +64,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
63 public override void Initialise(IConfigSource source) 64 public override void Initialise(IConfigSource source)
64 { 65 {
65 IConfig moduleConfig = source.Configs["Modules"]; 66 IConfig moduleConfig = source.Configs["Modules"];
67
66 if (moduleConfig != null) 68 if (moduleConfig != null)
67 { 69 {
68 string name = moduleConfig.GetString("EntityTransferModule", ""); 70 string name = moduleConfig.GetString("EntityTransferModule", "");
69 if (name == Name) 71 if (name == Name)
70 { 72 {
73 IConfig transferConfig = source.Configs["EntityTransfer"];
74 if (transferConfig != null)
75 m_levelHGTeleport = transferConfig.GetInt("LevelHGTeleport", 0);
76
71 InitialiseCommon(source); 77 InitialiseCommon(source);
72 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name); 78 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name);
73 } 79 }
@@ -77,10 +83,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
77 public override void AddRegion(Scene scene) 83 public override void AddRegion(Scene scene)
78 { 84 {
79 base.AddRegion(scene); 85 base.AddRegion(scene);
86
80 if (m_Enabled) 87 if (m_Enabled)
81 {
82 scene.RegisterModuleInterface<IUserAgentVerificationModule>(this); 88 scene.RegisterModuleInterface<IUserAgentVerificationModule>(this);
83 }
84 } 89 }
85 90
86 protected override void OnNewClient(IClientAPI client) 91 protected override void OnNewClient(IClientAPI client)
@@ -93,33 +98,28 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
93 public override void RegionLoaded(Scene scene) 98 public override void RegionLoaded(Scene scene)
94 { 99 {
95 base.RegionLoaded(scene); 100 base.RegionLoaded(scene);
96 if (m_Enabled)
97 if (!m_Initialized)
98 {
99 m_GatekeeperConnector = new GatekeeperServiceConnector(scene.AssetService);
100 m_Initialized = true;
101
102 }
103 101
102 if (m_Enabled)
103 m_GatekeeperConnector = new GatekeeperServiceConnector(scene.AssetService);
104 } 104 }
105
105 public override void RemoveRegion(Scene scene) 106 public override void RemoveRegion(Scene scene)
106 { 107 {
107 base.AddRegion(scene); 108 base.AddRegion(scene);
109
108 if (m_Enabled) 110 if (m_Enabled)
109 {
110 scene.UnregisterModuleInterface<IUserAgentVerificationModule>(this); 111 scene.UnregisterModuleInterface<IUserAgentVerificationModule>(this);
111 }
112 } 112 }
113 113
114
115 #endregion 114 #endregion
116 115
117 #region HG overrides of IEntiryTransferModule 116 #region HG overrides of IEntiryTransferModule
118 117
119 protected override GridRegion GetFinalDestination(GridRegion region) 118 protected override GridRegion GetFinalDestination(GridRegion region)
120 { 119 {
121 int flags = m_aScene.GridService.GetRegionFlags(m_aScene.RegionInfo.ScopeID, region.RegionID); 120 int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, region.RegionID);
122 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: region {0} flags: {1}", region.RegionID, flags); 121 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: region {0} flags: {1}", region.RegionID, flags);
122
123 if ((flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) 123 if ((flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0)
124 { 124 {
125 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Destination region {0} is hyperlink", region.RegionID); 125 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Destination region {0} is hyperlink", region.RegionID);
@@ -130,6 +130,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
130 m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: GetHyperlinkRegion to Gatekeeper {0} failed", region.ServerURI); 130 m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: GetHyperlinkRegion to Gatekeeper {0} failed", region.ServerURI);
131 return real_destination; 131 return real_destination;
132 } 132 }
133
133 return region; 134 return region;
134 } 135 }
135 136
@@ -138,7 +139,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
138 if (base.NeedsClosing(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) 139 if (base.NeedsClosing(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
139 return true; 140 return true;
140 141
141 int flags = m_aScene.GridService.GetRegionFlags(m_aScene.RegionInfo.ScopeID, reg.RegionID); 142 int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID);
142 if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) 143 if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0)
143 return true; 144 return true;
144 145
@@ -151,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
151 if (logout) 152 if (logout)
152 { 153 {
153 // Log them out of this grid 154 // Log them out of this grid
154 m_aScene.PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 155 Scene.PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
155 } 156 }
156 } 157 }
157 158
@@ -160,10 +161,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
160 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: CreateAgent {0} {1}", reg.ServerURI, finalDestination.ServerURI); 161 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: CreateAgent {0} {1}", reg.ServerURI, finalDestination.ServerURI);
161 reason = string.Empty; 162 reason = string.Empty;
162 logout = false; 163 logout = false;
163 int flags = m_aScene.GridService.GetRegionFlags(m_aScene.RegionInfo.ScopeID, reg.RegionID); 164 int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID);
164 if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) 165 if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0)
165 { 166 {
166 // this user is going to another grid 167 // this user is going to another grid
168 // check if HyperGrid teleport is allowed, based on user level
169 if (sp.UserLevel < m_levelHGTeleport)
170 {
171 m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to HG teleport agent due to insufficient UserLevel.");
172 reason = "Hypergrid teleport not allowed";
173 return false;
174 }
175
167 if (agentCircuit.ServiceURLs.ContainsKey("HomeURI")) 176 if (agentCircuit.ServiceURLs.ContainsKey("HomeURI"))
168 { 177 {
169 string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString(); 178 string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString();
@@ -193,10 +202,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
193 202
194 public override bool TeleportHome(UUID id, IClientAPI client) 203 public override bool TeleportHome(UUID id, IClientAPI client)
195 { 204 {
196 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.FirstName, client.LastName); 205 m_log.DebugFormat(
206 "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, client.AgentId);
197 207
198 // Let's find out if this is a foreign user or a local user 208 // Let's find out if this is a foreign user or a local user
199 IUserManagement uMan = m_aScene.RequestModuleInterface<IUserManagement>(); 209 IUserManagement uMan = Scene.RequestModuleInterface<IUserManagement>();
200 if (uMan != null && uMan.IsLocalGridUser(id)) 210 if (uMan != null && uMan.IsLocalGridUser(id))
201 { 211 {
202 // local grid user 212 // local grid user
@@ -232,13 +242,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
232 return false; 242 return false;
233 } 243 }
234 244
235 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
236 GridRegion homeGatekeeper = MakeRegion(aCircuit); 245 GridRegion homeGatekeeper = MakeRegion(aCircuit);
237 246
238 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}", 247 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}",
239 aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName); 248 aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName);
240 249
241 DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome), eq); 250 DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
242 return true; 251 return true;
243 } 252 }
244 253
@@ -252,19 +261,21 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
252 { 261 {
253 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Teleporting agent via landmark to {0} region {1} position {2}", 262 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Teleporting agent via landmark to {0} region {1} position {2}",
254 (lm.Gatekeeper == string.Empty) ? "local" : lm.Gatekeeper, lm.RegionID, lm.Position); 263 (lm.Gatekeeper == string.Empty) ? "local" : lm.Gatekeeper, lm.RegionID, lm.Position);
264
255 if (lm.Gatekeeper == string.Empty) 265 if (lm.Gatekeeper == string.Empty)
256 { 266 {
257 base.RequestTeleportLandmark(remoteClient, lm); 267 base.RequestTeleportLandmark(remoteClient, lm);
258 return; 268 return;
259 } 269 }
260 270
261 GridRegion info = m_aScene.GridService.GetRegionByUUID(UUID.Zero, lm.RegionID); 271 GridRegion info = Scene.GridService.GetRegionByUUID(UUID.Zero, lm.RegionID);
262 272
263 // Local region? 273 // Local region?
264 if (info != null) 274 if (info != null)
265 { 275 {
266 ((Scene)(remoteClient.Scene)).RequestTeleportLocation(remoteClient, info.RegionHandle, lm.Position, 276 ((Scene)(remoteClient.Scene)).RequestTeleportLocation(remoteClient, info.RegionHandle, lm.Position,
267 Vector3.Zero, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark)); 277 Vector3.Zero, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark));
278
268 return; 279 return;
269 } 280 }
270 else 281 else
@@ -275,21 +286,22 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
275 GridRegion gatekeeper = new GridRegion(); 286 GridRegion gatekeeper = new GridRegion();
276 gatekeeper.ServerURI = lm.Gatekeeper; 287 gatekeeper.ServerURI = lm.Gatekeeper;
277 GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(lm.RegionID)); 288 GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(lm.RegionID));
289
278 if (finalDestination != null) 290 if (finalDestination != null)
279 { 291 {
280 ScenePresence sp = scene.GetScenePresence(remoteClient.AgentId); 292 ScenePresence sp = scene.GetScenePresence(remoteClient.AgentId);
281 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>(); 293 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>();
282 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>(); 294
283 if (transferMod != null && sp != null && eq != null) 295 if (transferMod != null && sp != null)
284 transferMod.DoTeleport(sp, gatekeeper, finalDestination, lm.Position, 296 transferMod.DoTeleport(
285 Vector3.UnitX, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark), eq); 297 sp, gatekeeper, finalDestination, lm.Position, Vector3.UnitX,
298 (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark));
286 } 299 }
287 300
288 } 301 }
289 302
290 // can't find the region: Tell viewer and abort 303 // can't find the region: Tell viewer and abort
291 remoteClient.SendTeleportFailed("The teleport destination could not be found."); 304 remoteClient.SendTeleportFailed("The teleport destination could not be found.");
292
293 } 305 }
294 306
295 #endregion 307 #endregion
@@ -304,49 +316,48 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
304 IUserAgentService security = new UserAgentServiceConnector(url); 316 IUserAgentService security = new UserAgentServiceConnector(url);
305 return security.VerifyClient(aCircuit.SessionID, token); 317 return security.VerifyClient(aCircuit.SessionID, token);
306 } 318 }
307 else 319 else
308 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent {0} {1} does not have a HomeURI OH NO!", aCircuit.firstname, aCircuit.lastname); 320 {
321 m_log.DebugFormat(
322 "[HG ENTITY TRANSFER MODULE]: Agent {0} {1} does not have a HomeURI OH NO!",
323 aCircuit.firstname, aCircuit.lastname);
324 }
309 325
310 return false; 326 return false;
311 } 327 }
312 328
313 void OnConnectionClosed(IClientAPI obj) 329 void OnConnectionClosed(IClientAPI obj)
314 { 330 {
315 if (obj.IsLoggingOut) 331 if (obj.SceneAgent.IsChildAgent)
316 { 332 return;
317 object sp = null;
318 if (obj.Scene.TryGetScenePresence(obj.AgentId, out sp))
319 {
320 if (((ScenePresence)sp).IsChildAgent)
321 return;
322 }
323 333
324 // Let's find out if this is a foreign user or a local user 334 // Let's find out if this is a foreign user or a local user
325 IUserManagement uMan = m_aScene.RequestModuleInterface<IUserManagement>(); 335 IUserManagement uMan = Scene.RequestModuleInterface<IUserManagement>();
326 UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, obj.AgentId); 336// UserAccount account = Scene.UserAccountService.GetUserAccount(Scene.RegionInfo.ScopeID, obj.AgentId);
327 if (uMan != null && uMan.IsLocalGridUser(obj.AgentId)) 337
328 { 338 if (uMan != null && uMan.IsLocalGridUser(obj.AgentId))
329 // local grid user 339 {
330 return; 340 // local grid user
331 } 341 return;
342 }
332 343
333 AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode); 344 AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode);
334 345
335 if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) 346 if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
336 { 347 {
337 string url = aCircuit.ServiceURLs["HomeURI"].ToString(); 348 string url = aCircuit.ServiceURLs["HomeURI"].ToString();
338 IUserAgentService security = new UserAgentServiceConnector(url); 349 IUserAgentService security = new UserAgentServiceConnector(url);
339 security.LogoutAgent(obj.AgentId, obj.SessionId); 350 security.LogoutAgent(obj.AgentId, obj.SessionId);
340 //m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Sent logout call to UserAgentService @ {0}", url); 351 //m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Sent logout call to UserAgentService @ {0}", url);
341 } 352 }
342 else 353 else
354 {
343 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: HomeURI not found for agent {0} logout", obj.AgentId); 355 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: HomeURI not found for agent {0} logout", obj.AgentId);
344 } 356 }
345 } 357 }
346 358
347 #endregion 359 #endregion
348 360
349
350 private GridRegion MakeRegion(AgentCircuitData aCircuit) 361 private GridRegion MakeRegion(AgentCircuitData aCircuit)
351 { 362 {
352 GridRegion region = new GridRegion(); 363 GridRegion region = new GridRegion();
@@ -363,6 +374,5 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
363 region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0); 374 region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0);
364 return region; 375 return region;
365 } 376 }
366
367 } 377 }
368} 378} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs
index a71584a..cf72b58 100644
--- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs
@@ -364,8 +364,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
364 { 364 {
365 m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: Changing root inventory for user {0}", client.Name); 365 m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: Changing root inventory for user {0}", client.Name);
366 InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID); 366 InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID);
367 List<UUID> fids = new List<UUID>(); 367
368 List<UUID> iids = new List<UUID>();
369 List<InventoryFolderBase> keep = new List<InventoryFolderBase>(); 368 List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
370 369
371 foreach (InventoryFolderBase f in content.Folders) 370 foreach (InventoryFolderBase f in content.Folders)
@@ -395,4 +394,4 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
395 394
396 #endregion 395 #endregion
397 } 396 }
398} 397} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
index ee9961f..d30c2e2 100644
--- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
@@ -175,7 +175,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
175 sbyte assetType, 175 sbyte assetType,
176 byte wearableType, uint nextOwnerMask, int creationDate) 176 byte wearableType, uint nextOwnerMask, int creationDate)
177 { 177 {
178 m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID); 178 m_log.DebugFormat("[INVENTORY ACCESS MODULE]: Received request to create inventory item {0} in folder {1}", name, folderID);
179 179
180 if (!m_Scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId)) 180 if (!m_Scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
181 return; 181 return;
@@ -210,13 +210,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
210 else 210 else
211 { 211 {
212 m_log.ErrorFormat( 212 m_log.ErrorFormat(
213 "ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem", 213 "[INVENTORY ACCESS MODULE]: ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
214 remoteClient.AgentId); 214 remoteClient.AgentId);
215 } 215 }
216 } 216 }
217 else 217 else
218 { 218 {
219 IAgentAssetTransactions agentTransactions = m_Scene.RequestModuleInterface<IAgentAssetTransactions>(); 219 IAgentAssetTransactions agentTransactions = m_Scene.AgentTransactionsModule;
220 if (agentTransactions != null) 220 if (agentTransactions != null)
221 { 221 {
222 agentTransactions.HandleItemCreationFromTransaction( 222 agentTransactions.HandleItemCreationFromTransaction(
@@ -288,16 +288,19 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
288 else 288 else
289 { 289 {
290 m_log.ErrorFormat( 290 m_log.ErrorFormat(
291 "[AGENT INVENTORY]: Could not find item {0} for caps inventory update", 291 "[INVENTORY ACCESS MODULE]: Could not find item {0} for caps inventory update",
292 itemID); 292 itemID);
293 } 293 }
294 294
295 return UUID.Zero; 295 return UUID.Zero;
296 } 296 }
297 297
298 public virtual UUID CopyToInventory(DeRezAction action, UUID folderID, 298 public virtual List<InventoryItemBase> CopyToInventory(
299 List<SceneObjectGroup> objectGroups, IClientAPI remoteClient) 299 DeRezAction action, UUID folderID,
300 List<SceneObjectGroup> objectGroups, IClientAPI remoteClient, bool asAttachment)
300 { 301 {
302 List<InventoryItemBase> copiedItems = new List<InventoryItemBase>();
303
301 Dictionary<UUID, List<SceneObjectGroup>> bundlesToCopy = new Dictionary<UUID, List<SceneObjectGroup>>(); 304 Dictionary<UUID, List<SceneObjectGroup>> bundlesToCopy = new Dictionary<UUID, List<SceneObjectGroup>>();
302 305
303 if (CoalesceMultipleObjectsToInventory) 306 if (CoalesceMultipleObjectsToInventory)
@@ -324,16 +327,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
324 } 327 }
325 } 328 }
326 329
327 // This is method scoped and will be returned. It will be the 330// m_log.DebugFormat(
328 // last created asset id 331// "[INVENTORY ACCESS MODULE]: Copying {0} object bundles to folder {1} action {2} for {3}",
329 UUID assetID = UUID.Zero; 332// bundlesToCopy.Count, folderID, action, remoteClient.Name);
330 333
331 // Each iteration is really a separate asset being created, 334 // Each iteration is really a separate asset being created,
332 // with distinct destinations as well. 335 // with distinct destinations as well.
333 foreach (List<SceneObjectGroup> bundle in bundlesToCopy.Values) 336 foreach (List<SceneObjectGroup> bundle in bundlesToCopy.Values)
334 assetID = CopyBundleToInventory(action, folderID, bundle, remoteClient); 337 copiedItems.Add(CopyBundleToInventory(action, folderID, bundle, remoteClient, asAttachment));
335 338
336 return assetID; 339 return copiedItems;
337 } 340 }
338 341
339 /// <summary> 342 /// <summary>
@@ -344,12 +347,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
344 /// <param name="folderID"></param> 347 /// <param name="folderID"></param>
345 /// <param name="objlist"></param> 348 /// <param name="objlist"></param>
346 /// <param name="remoteClient"></param> 349 /// <param name="remoteClient"></param>
347 /// <returns></returns> 350 /// <param name="asAttachment">Should be true if the bundle is being copied as an attachment. This prevents
348 protected UUID CopyBundleToInventory( 351 /// attempted serialization of any script state which would abort any operating scripts.</param>
349 DeRezAction action, UUID folderID, List<SceneObjectGroup> objlist, IClientAPI remoteClient) 352 /// <returns>The inventory item created by the copy</returns>
353 protected InventoryItemBase CopyBundleToInventory(
354 DeRezAction action, UUID folderID, List<SceneObjectGroup> objlist, IClientAPI remoteClient,
355 bool asAttachment)
350 { 356 {
351 UUID assetID = UUID.Zero;
352
353 CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); 357 CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero);
354 Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>(); 358 Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>();
355 359
@@ -401,18 +405,27 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
401 405
402 string itemXml; 406 string itemXml;
403 407
408 // If we're being called from a script, then trying to serialize that same script's state will not complete
409 // in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
410 // the client/server crashes rather than logging out normally, the attachment's scripts will resume
411 // without state on relog. Arguably, this is what we want anyway.
404 if (objlist.Count > 1) 412 if (objlist.Count > 1)
405 itemXml = CoalescedSceneObjectsSerializer.ToXml(coa); 413 itemXml = CoalescedSceneObjectsSerializer.ToXml(coa, !asAttachment);
406 else 414 else
407 itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0]); 415 itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment);
408 416
409 // Restore the position of each group now that it has been stored to inventory. 417 // Restore the position of each group now that it has been stored to inventory.
410 foreach (SceneObjectGroup objectGroup in objlist) 418 foreach (SceneObjectGroup objectGroup in objlist)
411 objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; 419 objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];
412 420
413 InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); 421 InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);
422
423// m_log.DebugFormat(
424// "[INVENTORY ACCESS MODULE]: Created item is {0}",
425// item != null ? item.ID.ToString() : "NULL");
426
414 if (item == null) 427 if (item == null)
415 return UUID.Zero; 428 return null;
416 429
417 // Can't know creator is the same, so null it in inventory 430 // Can't know creator is the same, so null it in inventory
418 if (objlist.Count > 1) 431 if (objlist.Count > 1)
@@ -422,7 +435,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
422 } 435 }
423 else 436 else
424 { 437 {
425 item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); 438 item.CreatorId = objlist[0].RootPart.CreatorID.ToString();
439 item.CreatorData = objlist[0].RootPart.CreatorData;
426 item.SaleType = objlist[0].RootPart.ObjectSaleType; 440 item.SaleType = objlist[0].RootPart.ObjectSaleType;
427 item.SalePrice = objlist[0].RootPart.SalePrice; 441 item.SalePrice = objlist[0].RootPart.SalePrice;
428 } 442 }
@@ -435,8 +449,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
435 objlist[0].OwnerID.ToString()); 449 objlist[0].OwnerID.ToString());
436 m_Scene.AssetService.Store(asset); 450 m_Scene.AssetService.Store(asset);
437 451
438 item.AssetID = asset.FullID; 452 item.AssetID = asset.FullID;
439 assetID = asset.FullID;
440 453
441 if (DeRezAction.SaveToExistingUserInventoryItem == action) 454 if (DeRezAction.SaveToExistingUserInventoryItem == action)
442 { 455 {
@@ -469,9 +482,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
469 482
470 // This is a hook to do some per-asset post-processing for subclasses that need that 483 // This is a hook to do some per-asset post-processing for subclasses that need that
471 if (remoteClient != null) 484 if (remoteClient != null)
472 ExportAsset(remoteClient.AgentId, assetID); 485 ExportAsset(remoteClient.AgentId, asset.FullID);
473 486
474 return assetID; 487 return item;
475 } 488 }
476 489
477 protected virtual void ExportAsset(UUID agentID, UUID assetID) 490 protected virtual void ExportAsset(UUID agentID, UUID assetID)
@@ -617,7 +630,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
617 if (null == item) 630 if (null == item)
618 { 631 {
619 m_log.DebugFormat( 632 m_log.DebugFormat(
620 "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.", 633 "[INVENTORY ACCESS MODULE]: Object {0} {1} scheduled for save to inventory has already been deleted.",
621 so.Name, so.UUID); 634 so.Name, so.UUID);
622 635
623 return null; 636 return null;
@@ -668,7 +681,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
668 { 681 {
669 // Catch all. Use lost & found 682 // Catch all. Use lost & found
670 // 683 //
671
672 folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); 684 folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
673 } 685 }
674 } 686 }
@@ -718,7 +730,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
718 730
719 if (item == null) 731 if (item == null)
720 { 732 {
721
722 return null; 733 return null;
723 } 734 }
724 735
@@ -748,7 +759,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
748 else 759 else
749 { 760 {
750 m_log.WarnFormat( 761 m_log.WarnFormat(
751 "[InventoryAccessModule]: Could not find asset {0} for {1} in RezObject()", 762 "[INVENTORY ACCESS MODULE]: Could not find asset {0} for {1} in RezObject()",
752 assetID, remoteClient.Name); 763 assetID, remoteClient.Name);
753 } 764 }
754 765
@@ -859,7 +870,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
859 SceneObjectPart rootPart = group.RootPart; 870 SceneObjectPart rootPart = group.RootPart;
860 871
861// m_log.DebugFormat( 872// m_log.DebugFormat(
862// "[InventoryAccessModule]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", 873// "[INVENTORY ACCESS MODULE]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}",
863// group.Name, group.LocalId, group.UUID, 874// group.Name, group.LocalId, group.UUID,
864// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask, 875// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask,
865// remoteClient.Name); 876// remoteClient.Name);
@@ -867,7 +878,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
867// Vector3 storedPosition = group.AbsolutePosition; 878// Vector3 storedPosition = group.AbsolutePosition;
868 if (group.UUID == UUID.Zero) 879 if (group.UUID == UUID.Zero)
869 { 880 {
870 m_log.Debug("[InventoryAccessModule]: Object has UUID.Zero! Position 3"); 881 m_log.Debug("[INVENTORY ACCESS MODULE]: Object has UUID.Zero! Position 3");
871 } 882 }
872 883
873 foreach (SceneObjectPart part in group.Parts) 884 foreach (SceneObjectPart part in group.Parts)
@@ -928,7 +939,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
928 } 939 }
929 940
930// m_log.DebugFormat( 941// m_log.DebugFormat(
931// "[InventoryAccessModule]: Rezzed {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", 942// "[INVENTORY ACCESS MODULE]: Rezzed {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}",
932// group.Name, group.LocalId, group.UUID, 943// group.Name, group.LocalId, group.UUID,
933// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask, 944// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask,
934// remoteClient.Name); 945// remoteClient.Name);
@@ -1023,8 +1034,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
1023 1034
1024 so.FromFolderID = item.Folder; 1035 so.FromFolderID = item.Folder;
1025 1036
1026// Console.WriteLine("rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}", 1037// m_log.DebugFormat(
1027// rootPart.OwnerID, item.Owner, item.CurrentPermissions); 1038// "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}",
1039// rootPart.OwnerID, item.Owner, item.CurrentPermissions);
1028 1040
1029 if ((rootPart.OwnerID != item.Owner) || 1041 if ((rootPart.OwnerID != item.Owner) ||
1030 (item.CurrentPermissions & 16) != 0 || 1042 (item.CurrentPermissions & 16) != 0 ||
@@ -1160,7 +1172,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
1160 if (assetRequestItem.AssetID != requestID) 1172 if (assetRequestItem.AssetID != requestID)
1161 { 1173 {
1162 m_log.WarnFormat( 1174 m_log.WarnFormat(
1163 "[CLIENT]: {0} requested asset {1} from item {2} but this does not match item's asset {3}", 1175 "[INVENTORY ACCESS MODULE]: {0} requested asset {1} from item {2} but this does not match item's asset {3}",
1164 Name, requestID, itemID, assetRequestItem.AssetID); 1176 Name, requestID, itemID, assetRequestItem.AssetID);
1165 1177
1166 return false; 1178 return false;
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs
index e74310c..21d8bd7 100644
--- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs
@@ -64,8 +64,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests
64 IConfigSource config = new IniConfigSource(); 64 IConfigSource config = new IniConfigSource();
65 config.AddConfig("Modules"); 65 config.AddConfig("Modules");
66 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); 66 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
67 67
68 m_scene = SceneHelpers.SetupScene(); 68 SceneHelpers sceneHelpers = new SceneHelpers();
69 m_scene = sceneHelpers.SetupScene();
69 SceneHelpers.SetupSceneModules(m_scene, config, m_iam); 70 SceneHelpers.SetupSceneModules(m_scene, config, m_iam);
70 71
71 // Create user 72 // Create user
@@ -76,7 +77,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests
76 77
77 AgentCircuitData acd = new AgentCircuitData(); 78 AgentCircuitData acd = new AgentCircuitData();
78 acd.AgentID = m_userId; 79 acd.AgentID = m_userId;
79 m_tc = new TestClient(acd, m_scene); 80 m_tc = new TestClient(acd, m_scene);
80 } 81 }
81 82
82 [Test] 83 [Test]
diff --git a/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs b/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs
index 7f8271d..e135c21 100644
--- a/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/Monitoring/MonitorModule.cs
@@ -49,7 +49,16 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
49 public bool Enabled { get; private set; } 49 public bool Enabled { get; private set; }
50 50
51 private Scene m_scene; 51 private Scene m_scene;
52 private readonly List<IMonitor> m_monitors = new List<IMonitor>(); 52
53 /// <summary>
54 /// These are monitors where we know the static details in advance.
55 /// </summary>
56 /// <remarks>
57 /// Dynamic monitors also exist (we don't know any of the details of what stats we get back here)
58 /// but these are currently hardcoded.
59 /// </remarks>
60 private readonly List<IMonitor> m_staticMonitors = new List<IMonitor>();
61
53 private readonly List<IAlert> m_alerts = new List<IAlert>(); 62 private readonly List<IAlert> m_alerts = new List<IAlert>();
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 63 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 64
@@ -84,9 +93,18 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
84 93
85 public void DebugMonitors(string module, string[] args) 94 public void DebugMonitors(string module, string[] args)
86 { 95 {
87 foreach (IMonitor monitor in m_monitors) 96 foreach (IMonitor monitor in m_staticMonitors)
88 { 97 {
89 m_log.Info("[MonitorModule]: " + m_scene.RegionInfo.RegionName + " reports " + monitor.GetFriendlyName() + " = " + monitor.GetFriendlyValue()); 98 m_log.InfoFormat(
99 "[MONITOR MODULE]: {0} reports {1} = {2}",
100 m_scene.RegionInfo.RegionName, monitor.GetFriendlyName(), monitor.GetFriendlyValue());
101 }
102
103 foreach (KeyValuePair<string, float> tuple in m_scene.StatsReporter.GetExtraSimStats())
104 {
105 m_log.InfoFormat(
106 "[MONITOR MODULE]: {0} reports {1} = {2}",
107 m_scene.RegionInfo.RegionName, tuple.Key, tuple.Value);
90 } 108 }
91 } 109 }
92 110
@@ -106,11 +124,12 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
106 { 124 {
107 string monID = (string) request["monitor"]; 125 string monID = (string) request["monitor"];
108 126
109 foreach (IMonitor monitor in m_monitors) 127 foreach (IMonitor monitor in m_staticMonitors)
110 { 128 {
111 string elemName = monitor.ToString(); 129 string elemName = monitor.ToString();
112 if (elemName.StartsWith(monitor.GetType().Namespace)) 130 if (elemName.StartsWith(monitor.GetType().Namespace))
113 elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1); 131 elemName = elemName.Substring(monitor.GetType().Namespace.Length + 1);
132
114 if (elemName == monID || monitor.ToString() == monID) 133 if (elemName == monID || monitor.ToString() == monID)
115 { 134 {
116 Hashtable ereply3 = new Hashtable(); 135 Hashtable ereply3 = new Hashtable();
@@ -123,6 +142,9 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
123 } 142 }
124 } 143 }
125 144
145 // FIXME: Arguably this should also be done with dynamic monitors but I'm not sure what the above code
146 // is even doing. Why are we inspecting the type of the monitor???
147
126 // No monitor with that name 148 // No monitor with that name
127 Hashtable ereply2 = new Hashtable(); 149 Hashtable ereply2 = new Hashtable();
128 150
@@ -134,12 +156,18 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
134 } 156 }
135 157
136 string xml = "<data>"; 158 string xml = "<data>";
137 foreach (IMonitor monitor in m_monitors) 159 foreach (IMonitor monitor in m_staticMonitors)
138 { 160 {
139 string elemName = monitor.GetName(); 161 string elemName = monitor.GetName();
140 xml += "<" + elemName + ">" + monitor.GetValue().ToString() + "</" + elemName + ">"; 162 xml += "<" + elemName + ">" + monitor.GetValue().ToString() + "</" + elemName + ">";
141// m_log.DebugFormat("[MONITOR MODULE]: {0} = {1}", elemName, monitor.GetValue()); 163// m_log.DebugFormat("[MONITOR MODULE]: {0} = {1}", elemName, monitor.GetValue());
142 } 164 }
165
166 foreach (KeyValuePair<string, float> tuple in m_scene.StatsReporter.GetExtraSimStats())
167 {
168 xml += "<" + tuple.Key + ">" + tuple.Value + "</" + tuple.Key + ">";
169 }
170
143 xml += "</data>"; 171 xml += "</data>";
144 172
145 Hashtable ereply = new Hashtable(); 173 Hashtable ereply = new Hashtable();
@@ -156,20 +184,20 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
156 if (!Enabled) 184 if (!Enabled)
157 return; 185 return;
158 186
159 m_monitors.Add(new AgentCountMonitor(m_scene)); 187 m_staticMonitors.Add(new AgentCountMonitor(m_scene));
160 m_monitors.Add(new ChildAgentCountMonitor(m_scene)); 188 m_staticMonitors.Add(new ChildAgentCountMonitor(m_scene));
161 m_monitors.Add(new GCMemoryMonitor()); 189 m_staticMonitors.Add(new GCMemoryMonitor());
162 m_monitors.Add(new ObjectCountMonitor(m_scene)); 190 m_staticMonitors.Add(new ObjectCountMonitor(m_scene));
163 m_monitors.Add(new PhysicsFrameMonitor(m_scene)); 191 m_staticMonitors.Add(new PhysicsFrameMonitor(m_scene));
164 m_monitors.Add(new PhysicsUpdateFrameMonitor(m_scene)); 192 m_staticMonitors.Add(new PhysicsUpdateFrameMonitor(m_scene));
165 m_monitors.Add(new PWSMemoryMonitor()); 193 m_staticMonitors.Add(new PWSMemoryMonitor());
166 m_monitors.Add(new ThreadCountMonitor()); 194 m_staticMonitors.Add(new ThreadCountMonitor());
167 m_monitors.Add(new TotalFrameMonitor(m_scene)); 195 m_staticMonitors.Add(new TotalFrameMonitor(m_scene));
168 m_monitors.Add(new EventFrameMonitor(m_scene)); 196 m_staticMonitors.Add(new EventFrameMonitor(m_scene));
169 m_monitors.Add(new LandFrameMonitor(m_scene)); 197 m_staticMonitors.Add(new LandFrameMonitor(m_scene));
170 m_monitors.Add(new LastFrameTimeMonitor(m_scene)); 198 m_staticMonitors.Add(new LastFrameTimeMonitor(m_scene));
171 199
172 m_monitors.Add( 200 m_staticMonitors.Add(
173 new GenericMonitor( 201 new GenericMonitor(
174 m_scene, 202 m_scene,
175 "TimeDilationMonitor", 203 "TimeDilationMonitor",
@@ -177,7 +205,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
177 m => m.Scene.StatsReporter.LastReportedSimStats[0], 205 m => m.Scene.StatsReporter.LastReportedSimStats[0],
178 m => m.GetValue().ToString())); 206 m => m.GetValue().ToString()));
179 207
180 m_monitors.Add( 208 m_staticMonitors.Add(
181 new GenericMonitor( 209 new GenericMonitor(
182 m_scene, 210 m_scene,
183 "SimFPSMonitor", 211 "SimFPSMonitor",
@@ -185,7 +213,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
185 m => m.Scene.StatsReporter.LastReportedSimStats[1], 213 m => m.Scene.StatsReporter.LastReportedSimStats[1],
186 m => string.Format("{0}", m.GetValue()))); 214 m => string.Format("{0}", m.GetValue())));
187 215
188 m_monitors.Add( 216 m_staticMonitors.Add(
189 new GenericMonitor( 217 new GenericMonitor(
190 m_scene, 218 m_scene,
191 "PhysicsFPSMonitor", 219 "PhysicsFPSMonitor",
@@ -193,7 +221,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
193 m => m.Scene.StatsReporter.LastReportedSimStats[2], 221 m => m.Scene.StatsReporter.LastReportedSimStats[2],
194 m => string.Format("{0}", m.GetValue()))); 222 m => string.Format("{0}", m.GetValue())));
195 223
196 m_monitors.Add( 224 m_staticMonitors.Add(
197 new GenericMonitor( 225 new GenericMonitor(
198 m_scene, 226 m_scene,
199 "AgentUpdatesPerSecondMonitor", 227 "AgentUpdatesPerSecondMonitor",
@@ -201,15 +229,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
201 m => m.Scene.StatsReporter.LastReportedSimStats[3], 229 m => m.Scene.StatsReporter.LastReportedSimStats[3],
202 m => string.Format("{0} per second", m.GetValue()))); 230 m => string.Format("{0} per second", m.GetValue())));
203 231
204 m_monitors.Add( 232 m_staticMonitors.Add(
205 new GenericMonitor(
206 m_scene,
207 "ObjectUpdatesPerSecondMonitor",
208 "Object Updates",
209 m => m.Scene.StatsReporter.LastReportedObjectUpdates,
210 m => string.Format("{0} per second", m.GetValue())));
211
212 m_monitors.Add(
213 new GenericMonitor( 233 new GenericMonitor(
214 m_scene, 234 m_scene,
215 "ActiveObjectCountMonitor", 235 "ActiveObjectCountMonitor",
@@ -217,7 +237,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
217 m => m.Scene.StatsReporter.LastReportedSimStats[7], 237 m => m.Scene.StatsReporter.LastReportedSimStats[7],
218 m => string.Format("{0}", m.GetValue()))); 238 m => string.Format("{0}", m.GetValue())));
219 239
220 m_monitors.Add( 240 m_staticMonitors.Add(
221 new GenericMonitor( 241 new GenericMonitor(
222 m_scene, 242 m_scene,
223 "ActiveScriptsMonitor", 243 "ActiveScriptsMonitor",
@@ -225,7 +245,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
225 m => m.Scene.StatsReporter.LastReportedSimStats[19], 245 m => m.Scene.StatsReporter.LastReportedSimStats[19],
226 m => string.Format("{0}", m.GetValue()))); 246 m => string.Format("{0}", m.GetValue())));
227 247
228 m_monitors.Add( 248 m_staticMonitors.Add(
229 new GenericMonitor( 249 new GenericMonitor(
230 m_scene, 250 m_scene,
231 "ScriptEventsPerSecondMonitor", 251 "ScriptEventsPerSecondMonitor",
@@ -233,7 +253,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
233 m => m.Scene.StatsReporter.LastReportedSimStats[20], 253 m => m.Scene.StatsReporter.LastReportedSimStats[20],
234 m => string.Format("{0} per second", m.GetValue()))); 254 m => string.Format("{0} per second", m.GetValue())));
235 255
236 m_monitors.Add( 256 m_staticMonitors.Add(
237 new GenericMonitor( 257 new GenericMonitor(
238 m_scene, 258 m_scene,
239 "InPacketsPerSecondMonitor", 259 "InPacketsPerSecondMonitor",
@@ -241,7 +261,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
241 m => m.Scene.StatsReporter.LastReportedSimStats[13], 261 m => m.Scene.StatsReporter.LastReportedSimStats[13],
242 m => string.Format("{0} per second", m.GetValue()))); 262 m => string.Format("{0} per second", m.GetValue())));
243 263
244 m_monitors.Add( 264 m_staticMonitors.Add(
245 new GenericMonitor( 265 new GenericMonitor(
246 m_scene, 266 m_scene,
247 "OutPacketsPerSecondMonitor", 267 "OutPacketsPerSecondMonitor",
@@ -249,7 +269,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
249 m => m.Scene.StatsReporter.LastReportedSimStats[14], 269 m => m.Scene.StatsReporter.LastReportedSimStats[14],
250 m => string.Format("{0} per second", m.GetValue()))); 270 m => string.Format("{0} per second", m.GetValue())));
251 271
252 m_monitors.Add( 272 m_staticMonitors.Add(
253 new GenericMonitor( 273 new GenericMonitor(
254 m_scene, 274 m_scene,
255 "UnackedBytesMonitor", 275 "UnackedBytesMonitor",
@@ -257,7 +277,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
257 m => m.Scene.StatsReporter.LastReportedSimStats[15], 277 m => m.Scene.StatsReporter.LastReportedSimStats[15],
258 m => string.Format("{0}", m.GetValue()))); 278 m => string.Format("{0}", m.GetValue())));
259 279
260 m_monitors.Add( 280 m_staticMonitors.Add(
261 new GenericMonitor( 281 new GenericMonitor(
262 m_scene, 282 m_scene,
263 "PendingDownloadsMonitor", 283 "PendingDownloadsMonitor",
@@ -265,7 +285,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
265 m => m.Scene.StatsReporter.LastReportedSimStats[17], 285 m => m.Scene.StatsReporter.LastReportedSimStats[17],
266 m => string.Format("{0}", m.GetValue()))); 286 m => string.Format("{0}", m.GetValue())));
267 287
268 m_monitors.Add( 288 m_staticMonitors.Add(
269 new GenericMonitor( 289 new GenericMonitor(
270 m_scene, 290 m_scene,
271 "PendingUploadsMonitor", 291 "PendingUploadsMonitor",
@@ -273,7 +293,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
273 m => m.Scene.StatsReporter.LastReportedSimStats[18], 293 m => m.Scene.StatsReporter.LastReportedSimStats[18],
274 m => string.Format("{0}", m.GetValue()))); 294 m => string.Format("{0}", m.GetValue())));
275 295
276 m_monitors.Add( 296 m_staticMonitors.Add(
277 new GenericMonitor( 297 new GenericMonitor(
278 m_scene, 298 m_scene,
279 "TotalFrameTimeMonitor", 299 "TotalFrameTimeMonitor",
@@ -281,7 +301,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
281 m => m.Scene.StatsReporter.LastReportedSimStats[8], 301 m => m.Scene.StatsReporter.LastReportedSimStats[8],
282 m => string.Format("{0} ms", m.GetValue()))); 302 m => string.Format("{0} ms", m.GetValue())));
283 303
284 m_monitors.Add( 304 m_staticMonitors.Add(
285 new GenericMonitor( 305 new GenericMonitor(
286 m_scene, 306 m_scene,
287 "NetFrameTimeMonitor", 307 "NetFrameTimeMonitor",
@@ -289,7 +309,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
289 m => m.Scene.StatsReporter.LastReportedSimStats[9], 309 m => m.Scene.StatsReporter.LastReportedSimStats[9],
290 m => string.Format("{0} ms", m.GetValue()))); 310 m => string.Format("{0} ms", m.GetValue())));
291 311
292 m_monitors.Add( 312 m_staticMonitors.Add(
293 new GenericMonitor( 313 new GenericMonitor(
294 m_scene, 314 m_scene,
295 "PhysicsFrameTimeMonitor", 315 "PhysicsFrameTimeMonitor",
@@ -297,7 +317,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
297 m => m.Scene.StatsReporter.LastReportedSimStats[10], 317 m => m.Scene.StatsReporter.LastReportedSimStats[10],
298 m => string.Format("{0} ms", m.GetValue()))); 318 m => string.Format("{0} ms", m.GetValue())));
299 319
300 m_monitors.Add( 320 m_staticMonitors.Add(
301 new GenericMonitor( 321 new GenericMonitor(
302 m_scene, 322 m_scene,
303 "SimulationFrameTimeMonitor", 323 "SimulationFrameTimeMonitor",
@@ -305,7 +325,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
305 m => m.Scene.StatsReporter.LastReportedSimStats[12], 325 m => m.Scene.StatsReporter.LastReportedSimStats[12],
306 m => string.Format("{0} ms", m.GetValue()))); 326 m => string.Format("{0} ms", m.GetValue())));
307 327
308 m_monitors.Add( 328 m_staticMonitors.Add(
309 new GenericMonitor( 329 new GenericMonitor(
310 m_scene, 330 m_scene,
311 "AgentFrameTimeMonitor", 331 "AgentFrameTimeMonitor",
@@ -313,7 +333,7 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
313 m => m.Scene.StatsReporter.LastReportedSimStats[16], 333 m => m.Scene.StatsReporter.LastReportedSimStats[16],
314 m => string.Format("{0} ms", m.GetValue()))); 334 m => string.Format("{0} ms", m.GetValue())));
315 335
316 m_monitors.Add( 336 m_staticMonitors.Add(
317 new GenericMonitor( 337 new GenericMonitor(
318 m_scene, 338 m_scene,
319 "ImagesFrameTimeMonitor", 339 "ImagesFrameTimeMonitor",
@@ -321,7 +341,15 @@ namespace OpenSim.Region.CoreModules.Framework.Monitoring
321 m => m.Scene.StatsReporter.LastReportedSimStats[11], 341 m => m.Scene.StatsReporter.LastReportedSimStats[11],
322 m => string.Format("{0} ms", m.GetValue()))); 342 m => string.Format("{0} ms", m.GetValue())));
323 343
324 m_alerts.Add(new DeadlockAlert(m_monitors.Find(x => x is LastFrameTimeMonitor) as LastFrameTimeMonitor)); 344 m_staticMonitors.Add(
345 new GenericMonitor(
346 m_scene,
347 "SpareFrameTimeMonitor",
348 "Spare Frame Time",
349 m => m.Scene.StatsReporter.LastReportedSimStats[21],
350 m => string.Format("{0} ms", m.GetValue())));
351
352 m_alerts.Add(new DeadlockAlert(m_staticMonitors.Find(x => x is LastFrameTimeMonitor) as LastFrameTimeMonitor));
325 353
326 foreach (IAlert alert in m_alerts) 354 foreach (IAlert alert in m_alerts)
327 { 355 {
diff --git a/OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs b/OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs
new file mode 100644
index 0000000..1526886
--- /dev/null
+++ b/OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs
@@ -0,0 +1,224 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Framework.Capabilities;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36using log4net;
37using Nini.Config;
38using Mono.Addins;
39
40using Caps = OpenSim.Framework.Capabilities.Caps;
41
42
43namespace OpenSim.Region.CoreModules.World.LightShare
44{
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EnvironmentModule")]
46
47 public class EnvironmentModule : INonSharedRegionModule, IEnvironmentModule
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private Scene m_scene = null;
52 private UUID regionID = UUID.Zero;
53 private static bool Enabled = false;
54
55 private static readonly string capsName = "EnvironmentSettings";
56 private static readonly string capsBase = "/CAPS/0020/";
57
58 private LLSDEnvironmentSetResponse setResponse = null;
59
60 #region INonSharedRegionModule
61 public void Initialise(IConfigSource source)
62 {
63 IConfig config = source.Configs["ClientStack.LindenCaps"];
64
65 if (null == config)
66 return;
67
68 if (config.GetString("Cap_EnvironmentSettings", String.Empty) != "localhost")
69 {
70 m_log.InfoFormat("[{0}]: Module is disabled.", Name);
71 return;
72 }
73
74 Enabled = true;
75
76 m_log.InfoFormat("[{0}]: Module is enabled.", Name);
77 }
78
79 public void Close()
80 {
81 }
82
83 public string Name
84 {
85 get { return "EnvironmentModule"; }
86 }
87
88 public Type ReplaceableInterface
89 {
90 get { return null; }
91 }
92
93 public void AddRegion(Scene scene)
94 {
95 if (!Enabled)
96 return;
97
98 scene.RegisterModuleInterface<IEnvironmentModule>(this);
99 m_scene = scene;
100 regionID = scene.RegionInfo.RegionID;
101 }
102
103 public void RegionLoaded(Scene scene)
104 {
105 if (!Enabled)
106 return;
107
108 setResponse = new LLSDEnvironmentSetResponse();
109 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
110 }
111
112 public void RemoveRegion(Scene scene)
113 {
114 if (Enabled)
115 return;
116
117 scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
118 m_scene = null;
119 }
120 #endregion
121
122 #region IEnvironmentModule
123 public void ResetEnvironmentSettings(UUID regionUUID)
124 {
125 if (!Enabled)
126 return;
127
128 m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionUUID);
129 }
130 #endregion
131
132 #region Events
133 private void OnRegisterCaps(UUID agentID, Caps caps)
134 {
135// m_log.DebugFormat("[{0}]: Register capability for agentID {1} in region {2}",
136// Name, agentID, caps.RegionName);
137
138 string capsPath = capsBase + UUID.Random();
139
140 // Get handler
141 caps.RegisterHandler(
142 capsName,
143 new RestStreamHandler(
144 "GET",
145 capsPath,
146 (request, path, param, httpRequest, httpResponse)
147 => GetEnvironmentSettings(request, path, param, agentID, caps),
148 capsName,
149 agentID.ToString()));
150
151 // Set handler
152 caps.HttpListener.AddStreamHandler(
153 new RestStreamHandler(
154 "POST",
155 capsPath,
156 (request, path, param, httpRequest, httpResponse)
157 => SetEnvironmentSettings(request, path, param, agentID, caps),
158 capsName,
159 agentID.ToString()));
160 }
161 #endregion
162
163 private string GetEnvironmentSettings(string request, string path, string param,
164 UUID agentID, Caps caps)
165 {
166// m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}",
167// Name, agentID, caps.RegionName);
168
169 string env = String.Empty;
170
171 try
172 {
173 env = m_scene.SimulationDataService.LoadRegionEnvironmentSettings(regionID);
174 }
175 catch (Exception e)
176 {
177 m_log.ErrorFormat("[{0}]: Unable to load environment settings for region {1}, Exception: {2} - {3}",
178 Name, caps.RegionName, e.Message, e.StackTrace);
179 }
180
181 if (String.IsNullOrEmpty(env))
182 env = EnvironmentSettings.EmptySettings(UUID.Zero, regionID);
183
184 return env;
185 }
186
187 private string SetEnvironmentSettings(string request, string path, string param,
188 UUID agentID, Caps caps)
189 {
190
191// m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}",
192// Name, agentID, caps.RegionName);
193
194 setResponse.regionID = regionID;
195 setResponse.success = false;
196
197 if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
198 {
199 setResponse.fail_reason = "Insufficient estate permissions, settings has not been saved.";
200 return LLSDHelpers.SerialiseLLSDReply(setResponse);
201 }
202
203 try
204 {
205 m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, request);
206 setResponse.success = true;
207
208 m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}",
209 Name, agentID, caps.RegionName);
210 }
211 catch (Exception e)
212 {
213 m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}",
214 Name, caps.RegionName, e.Message, e.StackTrace);
215
216 setResponse.success = false;
217 setResponse.fail_reason = String.Format("Environment Set for region {0} has failed, settings has not been saved.", caps.RegionName);
218 }
219
220 return LLSDHelpers.SerialiseLLSDReply(setResponse);
221 }
222 }
223}
224
diff --git a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
index 9255791..e91e8b9 100644
--- a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
@@ -64,6 +64,8 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
64 private TimeSpan m_QueueTimeout = new TimeSpan(2, 0, 0); // 2 hours without llGetNextEmail drops the queue 64 private TimeSpan m_QueueTimeout = new TimeSpan(2, 0, 0); // 2 hours without llGetNextEmail drops the queue
65 private string m_InterObjectHostname = "lsl.opensim.local"; 65 private string m_InterObjectHostname = "lsl.opensim.local";
66 66
67 private int m_MaxEmailSize = 4096; // largest email allowed by default, as per lsl docs.
68
67 // Scenes by Region Handle 69 // Scenes by Region Handle
68 private Dictionary<ulong, Scene> m_Scenes = 70 private Dictionary<ulong, Scene> m_Scenes =
69 new Dictionary<ulong, Scene>(); 71 new Dictionary<ulong, Scene>();
@@ -127,6 +129,7 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
127 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT); 129 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT);
128 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN); 130 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN);
129 SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD); 131 SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD);
132 m_MaxEmailSize = SMTPConfig.GetInt("email_max_size", m_MaxEmailSize);
130 } 133 }
131 catch (Exception e) 134 catch (Exception e)
132 { 135 {
@@ -176,18 +179,6 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
176 get { return true; } 179 get { return true; }
177 } 180 }
178 181
179 /// <summary>
180 /// Delay function using thread in seconds
181 /// </summary>
182 /// <param name="seconds"></param>
183 private void DelayInSeconds(int delay)
184 {
185 delay = (int)((float)delay * 1000);
186 if (delay == 0)
187 return;
188 System.Threading.Thread.Sleep(delay);
189 }
190
191 private bool IsLocal(UUID objectID) 182 private bool IsLocal(UUID objectID)
192 { 183 {
193 string unused; 184 string unused;
@@ -267,10 +258,9 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
267 m_log.Error("[EMAIL] REGEX Problem in EMail Address: "+address); 258 m_log.Error("[EMAIL] REGEX Problem in EMail Address: "+address);
268 return; 259 return;
269 } 260 }
270 //FIXME:Check if subject + body = 4096 Byte 261 if ((subject.Length + body.Length) > m_MaxEmailSize)
271 if ((subject.Length + body.Length) > 1024)
272 { 262 {
273 m_log.Error("[EMAIL] subject + body > 1024 Byte"); 263 m_log.Error("[EMAIL] subject + body larger than limit of " + m_MaxEmailSize + " bytes");
274 return; 264 return;
275 } 265 }
276 266
@@ -345,10 +335,6 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
345 // TODO FIX 335 // TODO FIX
346 } 336 }
347 } 337 }
348
349 //DONE: Message as Second Life style
350 //20 second delay - AntiSpam System - for now only 10 seconds
351 DelayInSeconds(10);
352 } 338 }
353 339
354 /// <summary> 340 /// <summary>
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index a701b46..192b4f6 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -77,7 +77,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
77 private Dictionary<string, UrlData> m_UrlMap = 77 private Dictionary<string, UrlData> m_UrlMap =
78 new Dictionary<string, UrlData>(); 78 new Dictionary<string, UrlData>();
79 79
80 80 /// <summary>
81 /// Maximum number of external urls that can be set up by this module.
82 /// </summary>
81 private int m_TotalUrls = 5000; 83 private int m_TotalUrls = 5000;
82 84
83 private uint https_port = 0; 85 private uint https_port = 0;
@@ -85,6 +87,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
85 private IHttpServer m_HttpsServer = null; 87 private IHttpServer m_HttpsServer = null;
86 88
87 private string m_ExternalHostNameForLSL = ""; 89 private string m_ExternalHostNameForLSL = "";
90 public string ExternalHostNameForLSL
91 {
92 get { return m_ExternalHostNameForLSL; }
93 }
88 94
89 public Type ReplaceableInterface 95 public Type ReplaceableInterface
90 { 96 {
@@ -104,6 +110,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
104 { 110 {
105 https_port = (uint) config.Configs["Network"].GetInt("https_port",0); 111 https_port = (uint) config.Configs["Network"].GetInt("https_port",0);
106 } 112 }
113
114 IConfig llFunctionsConfig = config.Configs["LL-Functions"];
115
116 if (llFunctionsConfig != null)
117 m_TotalUrls = llFunctionsConfig.GetInt("max_external_urls_per_simulator", m_TotalUrls);
107 } 118 }
108 119
109 public void PostInitialise() 120 public void PostInitialise()
@@ -147,6 +158,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
147 public void Close() 158 public void Close()
148 { 159 {
149 } 160 }
161
150 public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID) 162 public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
151 { 163 {
152 UUID urlcode = UUID.Random(); 164 UUID urlcode = UUID.Random();
@@ -176,6 +188,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
176 uri, 188 uri,
177 new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); 189 new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode));
178 190
191 m_log.DebugFormat(
192 "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}",
193 uri, itemID, host.Name, host.LocalId);
194
179 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 195 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
180 } 196 }
181 197
@@ -218,6 +234,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
218 uri, 234 uri,
219 new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); 235 new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode));
220 236
237 m_log.DebugFormat(
238 "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
239 uri, itemID, host.Name, host.LocalId);
240
221 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 241 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
222 } 242 }
223 243
@@ -241,6 +261,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
241 m_RequestMap.Remove(req); 261 m_RequestMap.Remove(req);
242 } 262 }
243 263
264// m_log.DebugFormat(
265// "[URL MODULE]: Releasing url {0} for {1} in {2}",
266// url, data.itemID, data.hostID);
267
244 RemoveUrl(data); 268 RemoveUrl(data);
245 m_UrlMap.Remove(url); 269 m_UrlMap.Remove(url);
246 } 270 }
diff --git a/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs b/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs
index 40ffcb4..0003af2 100644
--- a/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs
@@ -131,11 +131,12 @@ namespace OpenSim.Region.CoreModules.Scripting.XMLRPC
131 { 131 {
132 // Start http server 132 // Start http server
133 // Attach xmlrpc handlers 133 // Attach xmlrpc handlers
134 m_log.Info("[XML RPC MODULE]: " + 134// m_log.InfoFormat(
135 "Starting up XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands."); 135// "[XML RPC MODULE]: Starting up XMLRPC Server on port {0} for llRemoteData commands.",
136 BaseHttpServer httpServer = new BaseHttpServer((uint) m_remoteDataPort); 136// m_remoteDataPort);
137
138 IHttpServer httpServer = MainServer.GetHttpServer((uint)m_remoteDataPort);
137 httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData); 139 httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData);
138 httpServer.Start();
139 } 140 }
140 } 141 }
141 142
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs
index 8df1c7b..a7dd0dd 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs
@@ -122,7 +122,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Hypergrid
122 ISimulationService simService = scene.RequestModuleInterface<ISimulationService>(); 122 ISimulationService simService = scene.RequestModuleInterface<ISimulationService>();
123 IFriendsSimConnector friendsConn = scene.RequestModuleInterface<IFriendsSimConnector>(); 123 IFriendsSimConnector friendsConn = scene.RequestModuleInterface<IFriendsSimConnector>();
124 Object[] args = new Object[] { m_Config }; 124 Object[] args = new Object[] { m_Config };
125 IFriendsService friendsService = ServerUtils.LoadPlugin<IFriendsService>(m_LocalServiceDll, args); 125// IFriendsService friendsService = ServerUtils.LoadPlugin<IFriendsService>(m_LocalServiceDll, args)
126 ServerUtils.LoadPlugin<IFriendsService>(m_LocalServiceDll, args);
126 127
127 m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService); 128 m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService);
128 129
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Land/LandServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Land/LandServiceInConnectorModule.cs
index c8f45f6..2f3c350 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Land/LandServiceInConnectorModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Land/LandServiceInConnectorModule.cs
@@ -75,7 +75,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Land
75 if (!m_Enabled) 75 if (!m_Enabled)
76 return; 76 return;
77 77
78 m_log.Info("[LAND IN CONNECTOR]: Starting..."); 78// m_log.Info("[LAND IN CONNECTOR]: Starting...");
79 } 79 }
80 80
81 public void Close() 81 public void Close()
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Neighbour/NeighbourServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Neighbour/NeighbourServiceInConnectorModule.cs
index 3fd89b9..b544ab3 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Neighbour/NeighbourServiceInConnectorModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Neighbour/NeighbourServiceInConnectorModule.cs
@@ -74,7 +74,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Neighbour
74 if (!m_Enabled) 74 if (!m_Enabled)
75 return; 75 return;
76 76
77 m_log.Info("[NEIGHBOUR IN CONNECTOR]: Starting..."); 77// m_log.Info("[NEIGHBOUR IN CONNECTOR]: Starting...");
78 } 78 }
79 79
80 public void Close() 80 public void Close()
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
index 8395f83..008465f 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
@@ -149,7 +149,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
149 149
150 m_aScene = scene; 150 m_aScene = scene;
151 151
152 scene.RegisterModuleInterface<IAssetService>(this); 152 m_aScene.RegisterModuleInterface<IAssetService>(this);
153 } 153 }
154 154
155 public void RemoveRegion(Scene scene) 155 public void RemoveRegion(Scene scene)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
index f0d21e6..4470799 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
55 MethodBase.GetCurrentMethod().DeclaringType); 55 MethodBase.GetCurrentMethod().DeclaringType);
56 56
57 private IUserManagement m_UserManagement; 57 private IUserManagement m_UserManagement;
58 private IGridService m_GridService; 58// private IGridService m_GridService;
59 59
60 private Scene m_Scene; 60 private Scene m_Scene;
61 AccessFlags m_accessValue = AccessFlags.None; 61 AccessFlags m_accessValue = AccessFlags.None;
@@ -65,7 +65,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
65 { 65 {
66 m_Scene = scene; 66 m_Scene = scene;
67 m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); 67 m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
68 m_GridService = scene.GridService; 68// m_GridService = scene.GridService;
69 69
70 if (config != null) 70 if (config != null)
71 { 71 {
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
index 4cf62ec..b0edce7 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
@@ -79,29 +79,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
79 79
80 public void OnConnectionClose(IClientAPI client) 80 public void OnConnectionClose(IClientAPI client)
81 { 81 {
82 if (client.IsLoggingOut) 82 if (client.SceneAgent.IsChildAgent)
83 { 83 return;
84 object sp = null;
85 Vector3 position = new Vector3(128, 128, 0);
86 Vector3 lookat = new Vector3(0, 1, 0);
87
88 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
89 {
90 if (sp is ScenePresence)
91 {
92 if (((ScenePresence)sp).IsChildAgent)
93 return;
94
95 position = ((ScenePresence)sp).AbsolutePosition;
96 lookat = ((ScenePresence)sp).Lookat;
97 }
98 }
99
100// m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
101 m_GridUserService.LoggedOut(client.AgentId.ToString(), client.SessionId, client.Scene.RegionInfo.RegionID, position, lookat);
102 }
103 84
85// m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
86 m_GridUserService.LoggedOut(
87 client.AgentId.ToString(), client.SessionId, client.Scene.RegionInfo.RegionID,
88 client.SceneAgent.AbsolutePosition, client.SceneAgent.Lookat);
104 } 89 }
105
106 } 90 }
107} 91}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index 3b862da..6cd077a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
@@ -149,9 +149,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
149 lock (m_scenes) 149 lock (m_scenes)
150 m_scenes[scene.RegionInfo.RegionID] = scene; 150 m_scenes[scene.RegionInfo.RegionID] = scene;
151 151
152 scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded); 152 scene.EventManager.OnLoginsEnabled += OnLoginsEnabled;
153 } 153 }
154 154
155
155 ///<summary> 156 ///<summary>
156 /// 157 ///
157 ///</summary> 158 ///</summary>
@@ -166,9 +167,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
166 167
167 #endregion ISharedRegionModule 168 #endregion ISharedRegionModule
168 169
169 void EventManager_OnPrimsLoaded(Scene s) 170 void OnLoginsEnabled(string regionName)
170 { 171 {
171 UploadMapTile(s); 172 Scene scene = null;
173 foreach (Scene s in m_scenes.Values)
174 if (s.RegionInfo.RegionName == regionName)
175 {
176 scene = s;
177 break;
178 }
179 if (scene != null)
180 UploadMapTile(scene);
172 } 181 }
173 182
174 183
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
index ccfbf78..172bea1 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
@@ -64,7 +64,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
64 scene.EventManager.OnNewClient -= OnNewClient; 64 scene.EventManager.OnNewClient -= OnNewClient;
65 65
66 m_PresenceService.LogoutRegionAgents(scene.RegionInfo.RegionID); 66 m_PresenceService.LogoutRegionAgents(scene.RegionInfo.RegionID);
67
68 } 67 }
69 68
70 public void OnMakeRootAgent(ScenePresence sp) 69 public void OnMakeRootAgent(ScenePresence sp)
@@ -80,18 +79,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
80 79
81 public void OnConnectionClose(IClientAPI client) 80 public void OnConnectionClose(IClientAPI client)
82 { 81 {
83 if (client.IsLoggingOut) 82 if (!client.SceneAgent.IsChildAgent)
84 { 83 {
85 object sp = null;
86 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
87 {
88 if (sp is ScenePresence)
89 {
90 if (((ScenePresence)sp).IsChildAgent)
91 return;
92 }
93 }
94
95// m_log.DebugFormat("[PRESENCE DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName); 84// m_log.DebugFormat("[PRESENCE DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
96 m_PresenceService.LogoutAgent(client.SessionId); 85 m_PresenceService.LogoutAgent(client.SessionId);
97 } 86 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
index 6e75692..008992e 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Linq;
29using System.Reflection; 30using System.Reflection;
30using log4net; 31using log4net;
31using Nini.Config; 32using Nini.Config;
@@ -41,22 +42,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
41 public class LocalSimulationConnectorModule : ISharedRegionModule, ISimulationService 42 public class LocalSimulationConnectorModule : ISharedRegionModule, ISimulationService
42 { 43 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 // Version of this service
45 private const string m_Version = "SIMULATION/0.1";
46 45
47 private List<Scene> m_sceneList = new List<Scene>(); 46 /// <summary>
47 /// Version of this service
48 /// </summary>
49 private const string m_Version = "SIMULATION/0.1";
48 50
49 private IEntityTransferModule m_AgentTransferModule; 51 /// <summary>
50 protected IEntityTransferModule AgentTransferModule 52 /// Map region ID to scene.
51 { 53 /// </summary>
52 get 54 private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
53 {
54 if (m_AgentTransferModule == null)
55 m_AgentTransferModule = m_sceneList[0].RequestModuleInterface<IEntityTransferModule>();
56 return m_AgentTransferModule;
57 }
58 }
59 55
56 /// <summary>
57 /// Is this module enabled?
58 /// </summary>
60 private bool m_ModuleEnabled = false; 59 private bool m_ModuleEnabled = false;
61 60
62 #region IRegionModule 61 #region IRegionModule
@@ -129,12 +128,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
129 /// <param name="scene"></param> 128 /// <param name="scene"></param>
130 public void RemoveScene(Scene scene) 129 public void RemoveScene(Scene scene)
131 { 130 {
132 lock (m_sceneList) 131 lock (m_scenes)
133 { 132 {
134 if (m_sceneList.Contains(scene)) 133 if (m_scenes.ContainsKey(scene.RegionInfo.RegionID))
135 { 134 m_scenes.Remove(scene.RegionInfo.RegionID);
136 m_sceneList.Remove(scene); 135 else
137 } 136 m_log.WarnFormat(
137 "[LOCAL SIMULATION CONNECTOR]: Tried to remove region {0} but it was not present",
138 scene.RegionInfo.RegionName);
138 } 139 }
139 } 140 }
140 141
@@ -144,13 +145,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
144 /// <param name="scene"></param> 145 /// <param name="scene"></param>
145 public void Init(Scene scene) 146 public void Init(Scene scene)
146 { 147 {
147 if (!m_sceneList.Contains(scene)) 148 lock (m_scenes)
148 { 149 {
149 lock (m_sceneList) 150 if (!m_scenes.ContainsKey(scene.RegionInfo.RegionID))
150 { 151 m_scenes[scene.RegionInfo.RegionID] = scene;
151 m_sceneList.Add(scene); 152 else
152 } 153 m_log.WarnFormat(
153 154 "[LOCAL SIMULATION CONNECTOR]: Tried to add region {0} but it is already present",
155 scene.RegionInfo.RegionName);
154 } 156 }
155 } 157 }
156 158
@@ -158,15 +160,24 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
158 160
159 #region ISimulation 161 #region ISimulation
160 162
161 public IScene GetScene(ulong regionhandle) 163 public IScene GetScene(UUID regionId)
162 { 164 {
163 foreach (Scene s in m_sceneList) 165 if (m_scenes.ContainsKey(regionId))
164 { 166 {
165 if (s.RegionInfo.RegionHandle == regionhandle) 167 return m_scenes[regionId];
166 return s; 168 }
169 else
170 {
171 // FIXME: This was pre-existing behaviour but possibly not a good idea, since it hides an error rather
172 // than making it obvious and fixable. Need to see if the error message comes up in practice.
173 Scene s = m_scenes.Values.ToArray()[0];
174
175 m_log.ErrorFormat(
176 "[LOCAL SIMULATION CONNECTOR]: Region with id {0} not found. Returning {1} {2} instead",
177 regionId, s.RegionInfo.RegionName, s.RegionInfo.RegionID);
178
179 return s;
167 } 180 }
168 // ? weird. should not happen
169 return m_sceneList[0];
170 } 181 }
171 182
172 public ISimulationService GetInnerService() 183 public ISimulationService GetInnerService()
@@ -187,13 +198,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
187 return false; 198 return false;
188 } 199 }
189 200
190 foreach (Scene s in m_sceneList) 201 if (m_scenes.ContainsKey(destination.RegionID))
191 { 202 {
192 if (s.RegionInfo.RegionHandle == destination.RegionHandle) 203// m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Found region {0} to send SendCreateChildAgent", destination.RegionName);
193 { 204 return m_scenes[destination.RegionID].NewUserConnection(aCircuit, teleportFlags, out reason);
194 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Found region {0} to send SendCreateChildAgent", destination.RegionName);
195 return s.NewUserConnection(aCircuit, teleportFlags, out reason);
196 }
197 } 205 }
198 206
199 reason = "Did not find region " + destination.RegionName; 207 reason = "Did not find region " + destination.RegionName;
@@ -205,17 +213,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
205 if (destination == null) 213 if (destination == null)
206 return false; 214 return false;
207 215
208 foreach (Scene s in m_sceneList) 216 if (m_scenes.ContainsKey(destination.RegionID))
209 { 217 {
210 if (s.RegionInfo.RegionHandle == destination.RegionHandle) 218// m_log.DebugFormat(
211 { 219// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
212 m_log.DebugFormat( 220// s.RegionInfo.RegionName, destination.RegionHandle);
213 "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
214 s.RegionInfo.RegionName, destination.RegionHandle);
215 221
216 s.IncomingChildAgentDataUpdate(cAgentData); 222 return m_scenes[destination.RegionID].IncomingChildAgentDataUpdate(cAgentData);
217 return true;
218 }
219 } 223 }
220 224
221// m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle); 225// m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle);
@@ -231,11 +235,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
231 // simulator so when we receive the update we need to hand it to each of the 235 // simulator so when we receive the update we need to hand it to each of the
232 // scenes; scenes each check to see if the is a scene presence for the avatar 236 // scenes; scenes each check to see if the is a scene presence for the avatar
233 // note that we really don't need the GridRegion for this call 237 // note that we really don't need the GridRegion for this call
234 foreach (Scene s in m_sceneList) 238 foreach (Scene s in m_scenes.Values)
235 { 239 {
236 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); 240 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
237 s.IncomingChildAgentDataUpdate(cAgentData); 241 s.IncomingChildAgentDataUpdate(cAgentData);
238 } 242 }
243
239 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); 244 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
240 return true; 245 return true;
241 } 246 }
@@ -247,14 +252,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
247 if (destination == null) 252 if (destination == null)
248 return false; 253 return false;
249 254
250 foreach (Scene s in m_sceneList) 255 if (m_scenes.ContainsKey(destination.RegionID))
251 { 256 {
252 if (s.RegionInfo.RegionHandle == destination.RegionHandle) 257// m_log.DebugFormat(
253 { 258// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
254 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); 259// s.RegionInfo.RegionName, destination.RegionHandle);
255 return s.IncomingRetrieveRootAgent(id, out agent); 260
256 } 261 return m_scenes[destination.RegionID].IncomingRetrieveRootAgent(id, out agent);
257 } 262 }
263
258 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); 264 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
259 return false; 265 return false;
260 } 266 }
@@ -266,59 +272,49 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
266 if (destination == null) 272 if (destination == null)
267 return false; 273 return false;
268 274
269 foreach (Scene s in m_sceneList) 275 if (m_scenes.ContainsKey(destination.RegionID))
270 { 276 {
271 if (s.RegionInfo.RegionID == destination.RegionID) 277// m_log.DebugFormat(
272 return s.QueryAccess(id, position, out reason); 278// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
279// s.RegionInfo.RegionName, destination.RegionHandle);
280
281 return m_scenes[destination.RegionID].QueryAccess(id, position, out reason);
273 } 282 }
283
284 //m_log.Debug("[LOCAL COMMS]: region not found for QueryAccess");
274 return false; 285 return false;
275 } 286 }
276 287
277 public bool ReleaseAgent(UUID origin, UUID id, string uri) 288 public bool ReleaseAgent(UUID originId, UUID agentId, string uri)
278 { 289 {
279 foreach (Scene s in m_sceneList) 290 if (m_scenes.ContainsKey(originId))
280 { 291 {
281 if (s.RegionInfo.RegionID == origin) 292// m_log.DebugFormat(
282 { 293// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
283 m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); 294// s.RegionInfo.RegionName, destination.RegionHandle);
284 AgentTransferModule.AgentArrivedAtDestination(id); 295
285 return true; 296 m_scenes[originId].EntityTransferModule.AgentArrivedAtDestination(agentId);
286// return s.IncomingReleaseAgent(id); 297 return true;
287 }
288 } 298 }
299
289 //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin); 300 //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin);
290 return false; 301 return false;
291 } 302 }
292 303
293 public bool CloseAgent(GridRegion destination, UUID id) 304 public bool CloseChildAgent(GridRegion destination, UUID id)
294 { 305 {
295 if (destination == null) 306 return CloseAgent(destination, id);
296 return false;
297
298 foreach (Scene s in m_sceneList)
299 {
300 if (s.RegionInfo.RegionID == destination.RegionID)
301 {
302 //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent");
303 return s.IncomingCloseAgent(id);
304 }
305 }
306 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
307 return false;
308 } 307 }
309 308
310 public bool CloseChildAgent(GridRegion destination, UUID id) 309 public bool CloseAgent(GridRegion destination, UUID id)
311 { 310 {
312 if (destination == null) 311 if (destination == null)
313 return false; 312 return false;
314 313
315 foreach (Scene s in m_sceneList) 314 if (m_scenes.ContainsKey(destination.RegionID))
316 { 315 {
317 if (s.RegionInfo.RegionID == destination.RegionID) 316 Util.FireAndForget(delegate { m_scenes[destination.RegionID].IncomingCloseAgent(id); });
318 { 317 return true;
319 //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent");
320 return s.IncomingCloseChildAgent(id);
321 }
322 } 318 }
323 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); 319 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
324 return false; 320 return false;
@@ -333,25 +329,28 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
333 if (destination == null) 329 if (destination == null)
334 return false; 330 return false;
335 331
336 foreach (Scene s in m_sceneList) 332 if (m_scenes.ContainsKey(destination.RegionID))
337 { 333 {
338 if (s.RegionInfo.RegionHandle == destination.RegionHandle) 334// m_log.DebugFormat(
335// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
336// s.RegionInfo.RegionName, destination.RegionHandle);
337
338 Scene s = m_scenes[destination.RegionID];
339
340 if (isLocalCall)
341 {
342 // We need to make a local copy of the object
343 ISceneObject sogClone = sog.CloneForNewScene();
344 sogClone.SetState(sog.GetStateSnapshot(), s);
345 return s.IncomingCreateObject(newPosition, sogClone);
346 }
347 else
339 { 348 {
340 //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject"); 349 // Use the object as it came through the wire
341 if (isLocalCall) 350 return s.IncomingCreateObject(newPosition, sog);
342 {
343 // We need to make a local copy of the object
344 ISceneObject sogClone = sog.CloneForNewScene();
345 sogClone.SetState(sog.GetStateSnapshot(), s);
346 return s.IncomingCreateObject(newPosition, sogClone);
347 }
348 else
349 {
350 // Use the object as it came through the wire
351 return s.IncomingCreateObject(newPosition, sog);
352 }
353 } 351 }
354 } 352 }
353
355 return false; 354 return false;
356 } 355 }
357 356
@@ -360,13 +359,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
360 if (destination == null) 359 if (destination == null)
361 return false; 360 return false;
362 361
363 foreach (Scene s in m_sceneList) 362 if (m_scenes.ContainsKey(destination.RegionID))
364 { 363 {
365 if (s.RegionInfo.RegionHandle == destination.RegionHandle) 364// m_log.DebugFormat(
366 { 365// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
367 return s.IncomingCreateObject(userID, itemID); 366// s.RegionInfo.RegionName, destination.RegionHandle);
368 } 367
368 return m_scenes[destination.RegionID].IncomingCreateObject(userID, itemID);
369 } 369 }
370
370 return false; 371 return false;
371 } 372 }
372 373
@@ -377,18 +378,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
377 378
378 public bool IsLocalRegion(ulong regionhandle) 379 public bool IsLocalRegion(ulong regionhandle)
379 { 380 {
380 foreach (Scene s in m_sceneList) 381 foreach (Scene s in m_scenes.Values)
381 if (s.RegionInfo.RegionHandle == regionhandle) 382 if (s.RegionInfo.RegionHandle == regionhandle)
382 return true; 383 return true;
384
383 return false; 385 return false;
384 } 386 }
385 387
386 public bool IsLocalRegion(UUID id) 388 public bool IsLocalRegion(UUID id)
387 { 389 {
388 foreach (Scene s in m_sceneList) 390 return m_scenes.ContainsKey(id);
389 if (s.RegionInfo.RegionID == id)
390 return true;
391 return false;
392 } 391 }
393 392
394 #endregion 393 #endregion
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
index 4b70692..d395413 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
@@ -151,9 +151,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
151 151
152 #region IInterregionComms 152 #region IInterregionComms
153 153
154 public IScene GetScene(ulong handle) 154 public IScene GetScene(UUID regionId)
155 { 155 {
156 return m_localBackend.GetScene(handle); 156 return m_localBackend.GetScene(regionId);
157 } 157 }
158 158
159 public ISimulationService GetInnerService() 159 public ISimulationService GetInnerService()
@@ -226,13 +226,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
226 return m_remoteConnector.RetrieveAgent(destination, id, out agent); 226 return m_remoteConnector.RetrieveAgent(destination, id, out agent);
227 227
228 return false; 228 return false;
229
230 } 229 }
231 230
232 public bool QueryAccess(GridRegion destination, UUID id, Vector3 position, out string version, out string reason) 231 public bool QueryAccess(GridRegion destination, UUID id, Vector3 position, out string version, out string reason)
233 { 232 {
234 reason = "Communications failure"; 233 reason = "Communications failure";
235 version = "Unknown"; 234 version = "Unknown";
235
236 if (destination == null) 236 if (destination == null)
237 return false; 237 return false;
238 238
@@ -245,7 +245,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
245 return m_remoteConnector.QueryAccess(destination, id, position, out version, out reason); 245 return m_remoteConnector.QueryAccess(destination, id, position, out version, out reason);
246 246
247 return false; 247 return false;
248
249 } 248 }
250 249
251 public bool ReleaseAgent(UUID origin, UUID id, string uri) 250 public bool ReleaseAgent(UUID origin, UUID id, string uri)
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index 38db239..619550c 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -41,6 +41,7 @@ using OpenSim.Framework.Serialization.External;
41using OpenSim.Region.CoreModules.World.Terrain; 41using OpenSim.Region.CoreModules.World.Terrain;
42using OpenSim.Region.Framework.Interfaces; 42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes; 43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Region.Framework.Scenes.Serialization;
44using OpenSim.Services.Interfaces; 45using OpenSim.Services.Interfaces;
45 46
46namespace OpenSim.Region.CoreModules.World.Archiver 47namespace OpenSim.Region.CoreModules.World.Archiver
@@ -245,6 +246,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
245 // Reload serialized prims 246 // Reload serialized prims
246 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); 247 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count);
247 248
249 UUID oldTelehubUUID = m_scene.RegionInfo.RegionSettings.TelehubObject;
250
248 IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface<IRegionSerialiserModule>(); 251 IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface<IRegionSerialiserModule>();
249 int sceneObjectsLoadedCount = 0; 252 int sceneObjectsLoadedCount = 0;
250 253
@@ -266,11 +269,21 @@ namespace OpenSim.Region.CoreModules.World.Archiver
266 269
267 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject); 270 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
268 271
272 bool isTelehub = (sceneObject.UUID == oldTelehubUUID);
273
269 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned 274 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
270 // on the same region server and multiple examples a single object archive to be imported 275 // on the same region server and multiple examples a single object archive to be imported
271 // to the same scene (when this is possible). 276 // to the same scene (when this is possible).
272 sceneObject.ResetIDs(); 277 sceneObject.ResetIDs();
273 278
279 if (isTelehub)
280 {
281 // Change the Telehub Object to the new UUID
282 m_scene.RegionInfo.RegionSettings.TelehubObject = sceneObject.UUID;
283 m_scene.RegionInfo.RegionSettings.Save();
284 oldTelehubUUID = UUID.Zero;
285 }
286
274 // Try to retain the original creator/owner/lastowner if their uuid is present on this grid 287 // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
275 // or creator data is present. Otherwise, use the estate owner instead. 288 // or creator data is present. Otherwise, use the estate owner instead.
276 foreach (SceneObjectPart part in sceneObject.Parts) 289 foreach (SceneObjectPart part in sceneObject.Parts)
@@ -347,7 +360,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
347 int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount; 360 int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount;
348 361
349 if (ignoredObjects > 0) 362 if (ignoredObjects > 0)
350 m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene", ignoredObjects); 363 m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene", ignoredObjects);
364
365 if (oldTelehubUUID != UUID.Zero)
366 {
367 m_log.WarnFormat("Telehub object not found: {0}", oldTelehubUUID);
368 m_scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero;
369 m_scene.RegionInfo.RegionSettings.ClearSpawnPoints();
370 }
351 } 371 }
352 372
353 /// <summary> 373 /// <summary>
@@ -523,6 +543,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
523 currentRegionSettings.TerrainTexture4 = loadedRegionSettings.TerrainTexture4; 543 currentRegionSettings.TerrainTexture4 = loadedRegionSettings.TerrainTexture4;
524 currentRegionSettings.UseEstateSun = loadedRegionSettings.UseEstateSun; 544 currentRegionSettings.UseEstateSun = loadedRegionSettings.UseEstateSun;
525 currentRegionSettings.WaterHeight = loadedRegionSettings.WaterHeight; 545 currentRegionSettings.WaterHeight = loadedRegionSettings.WaterHeight;
546 currentRegionSettings.TelehubObject = loadedRegionSettings.TelehubObject;
547 currentRegionSettings.ClearSpawnPoints();
548 foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints())
549 currentRegionSettings.AddSpawnPoint(sp);
526 550
527 currentRegionSettings.Save(); 551 currentRegionSettings.Save();
528 552
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs
index 4d459bf..4edaaca 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs
@@ -40,6 +40,9 @@ using OpenSim.Framework.Serialization;
40using OpenSim.Region.CoreModules.World.Terrain; 40using OpenSim.Region.CoreModules.World.Terrain;
41using OpenSim.Region.Framework.Interfaces; 41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
43using Ionic.Zlib;
44using GZipStream = Ionic.Zlib.GZipStream;
45using CompressionMode = Ionic.Zlib.CompressionMode;
43 46
44namespace OpenSim.Region.CoreModules.World.Archiver 47namespace OpenSim.Region.CoreModules.World.Archiver
45{ 48{
@@ -64,7 +67,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
64 /// Determine whether this archive will save assets. Default is true. 67 /// Determine whether this archive will save assets. Default is true.
65 /// </summary> 68 /// </summary>
66 public bool SaveAssets { get; set; } 69 public bool SaveAssets { get; set; }
67 70
71 protected ArchiverModule m_module;
68 protected Scene m_scene; 72 protected Scene m_scene;
69 protected Stream m_saveStream; 73 protected Stream m_saveStream;
70 protected Guid m_requestId; 74 protected Guid m_requestId;
@@ -72,17 +76,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver
72 /// <summary> 76 /// <summary>
73 /// Constructor 77 /// Constructor
74 /// </summary> 78 /// </summary>
75 /// <param name="scene"></param> 79 /// <param name="module">Calling module</param>
76 /// <param name="savePath">The path to which to save data.</param> 80 /// <param name="savePath">The path to which to save data.</param>
77 /// <param name="requestId">The id associated with this request</param> 81 /// <param name="requestId">The id associated with this request</param>
78 /// <exception cref="System.IO.IOException"> 82 /// <exception cref="System.IO.IOException">
79 /// If there was a problem opening a stream for the file specified by the savePath 83 /// If there was a problem opening a stream for the file specified by the savePath
80 /// </exception> 84 /// </exception>
81 public ArchiveWriteRequestPreparation(Scene scene, string savePath, Guid requestId) : this(scene, requestId) 85 public ArchiveWriteRequestPreparation(ArchiverModule module, string savePath, Guid requestId) : this(module, requestId)
82 { 86 {
83 try 87 try
84 { 88 {
85 m_saveStream = new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress); 89 m_saveStream = new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress, CompressionLevel.BestCompression);
86 } 90 }
87 catch (EntryPointNotFoundException e) 91 catch (EntryPointNotFoundException e)
88 { 92 {
@@ -96,17 +100,23 @@ namespace OpenSim.Region.CoreModules.World.Archiver
96 /// <summary> 100 /// <summary>
97 /// Constructor. 101 /// Constructor.
98 /// </summary> 102 /// </summary>
99 /// <param name="scene"></param> 103 /// <param name="module">Calling module</param>
100 /// <param name="saveStream">The stream to which to save data.</param> 104 /// <param name="saveStream">The stream to which to save data.</param>
101 /// <param name="requestId">The id associated with this request</param> 105 /// <param name="requestId">The id associated with this request</param>
102 public ArchiveWriteRequestPreparation(Scene scene, Stream saveStream, Guid requestId) : this(scene, requestId) 106 public ArchiveWriteRequestPreparation(ArchiverModule module, Stream saveStream, Guid requestId) : this(module, requestId)
103 { 107 {
104 m_saveStream = saveStream; 108 m_saveStream = saveStream;
105 } 109 }
106 110
107 protected ArchiveWriteRequestPreparation(Scene scene, Guid requestId) 111 protected ArchiveWriteRequestPreparation(ArchiverModule module, Guid requestId)
108 { 112 {
109 m_scene = scene; 113 m_module = module;
114
115 // FIXME: This is only here for regression test purposes since they do not supply a module. Need to fix
116 // this.
117 if (m_module != null)
118 m_scene = m_module.Scene;
119
110 m_requestId = requestId; 120 m_requestId = requestId;
111 121
112 SaveAssets = true; 122 SaveAssets = true;
@@ -297,10 +307,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
297 if (checkPermissions.Contains("T") && !canTransfer) 307 if (checkPermissions.Contains("T") && !canTransfer)
298 partPermitted = false; 308 partPermitted = false;
299 309
310 // If the user is the Creator of the object then it can always be included in the OAR
311 bool creator = (obj.CreatorID.Guid == user.Guid);
312 if (creator)
313 partPermitted = true;
314
300 //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount); 315 //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount);
301 //m_log.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, permitted={8}", 316 //m_log.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, creator={8}, permitted={9}",
302 // name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask, 317 // name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask,
303 // permissionClass, checkPermissions, canCopy, canTransfer, permitted); 318 // permissionClass, checkPermissions, canCopy, canTransfer, creator, partPermitted);
304 319
305 if (!partPermitted) 320 if (!partPermitted)
306 { 321 {
@@ -320,7 +335,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
320 /// <returns></returns> 335 /// <returns></returns>
321 public string CreateControlFile(Dictionary<string, object> options) 336 public string CreateControlFile(Dictionary<string, object> options)
322 { 337 {
323 int majorVersion = MAX_MAJOR_VERSION, minorVersion = 7; 338 int majorVersion = MAX_MAJOR_VERSION, minorVersion = 8;
324// 339//
325// if (options.ContainsKey("version")) 340// if (options.ContainsKey("version"))
326// { 341// {
@@ -356,32 +371,66 @@ namespace OpenSim.Region.CoreModules.World.Archiver
356 //if (majorVersion == 1) 371 //if (majorVersion == 1)
357 //{ 372 //{
358 // m_log.WarnFormat("[ARCHIVER]: Please be aware that version 1.0 OARs are not compatible with OpenSim 0.7.0.2 and earlier. Please use the --version=0 option if you want to produce a compatible OAR"); 373 // m_log.WarnFormat("[ARCHIVER]: Please be aware that version 1.0 OARs are not compatible with OpenSim 0.7.0.2 and earlier. Please use the --version=0 option if you want to produce a compatible OAR");
359 //} 374 //}
375
376 String s;
360 377
361 StringWriter sw = new StringWriter(); 378 using (StringWriter sw = new StringWriter())
362 XmlTextWriter xtw = new XmlTextWriter(sw); 379 {
363 xtw.Formatting = Formatting.Indented; 380 using (XmlTextWriter xtw = new XmlTextWriter(sw))
364 xtw.WriteStartDocument(); 381 {
365 xtw.WriteStartElement("archive"); 382 xtw.Formatting = Formatting.Indented;
366 xtw.WriteAttributeString("major_version", majorVersion.ToString()); 383 xtw.WriteStartDocument();
367 xtw.WriteAttributeString("minor_version", minorVersion.ToString()); 384 xtw.WriteStartElement("archive");
368 385 xtw.WriteAttributeString("major_version", majorVersion.ToString());
369 xtw.WriteStartElement("creation_info"); 386 xtw.WriteAttributeString("minor_version", minorVersion.ToString());
370 DateTime now = DateTime.UtcNow; 387
371 TimeSpan t = now - new DateTime(1970, 1, 1); 388 xtw.WriteStartElement("creation_info");
372 xtw.WriteElementString("datetime", ((int)t.TotalSeconds).ToString()); 389 DateTime now = DateTime.UtcNow;
373 xtw.WriteElementString("id", UUID.Random().ToString()); 390 TimeSpan t = now - new DateTime(1970, 1, 1);
374 xtw.WriteEndElement(); 391 xtw.WriteElementString("datetime", ((int)t.TotalSeconds).ToString());
375 392 xtw.WriteElementString("id", UUID.Random().ToString());
376 xtw.WriteElementString("assets_included", SaveAssets.ToString()); 393 xtw.WriteEndElement();
377 394
378 xtw.WriteEndElement(); 395 xtw.WriteStartElement("region_info");
379 396
380 xtw.Flush(); 397 bool isMegaregion;
381 xtw.Close(); 398 Vector2 size;
382 399 IRegionCombinerModule rcMod = null;
383 String s = sw.ToString(); 400
384 sw.Close(); 401 // FIXME: This is only here for regression test purposes since they do not supply a module. Need to fix
402 // this, possibly by doing control file creation somewhere else.
403 if (m_module != null)
404 rcMod = m_module.RegionCombinerModule;
405
406 if (rcMod != null)
407 isMegaregion = rcMod.IsRootForMegaregion(m_scene.RegionInfo.RegionID);
408 else
409 isMegaregion = false;
410
411 if (isMegaregion)
412 size = rcMod.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID);
413 else
414 size = new Vector2((float)Constants.RegionSize, (float)Constants.RegionSize);
415
416 xtw.WriteElementString("is_megaregion", isMegaregion.ToString());
417 xtw.WriteElementString("size_in_meters", string.Format("{0},{1}", size.X, size.Y));
418
419 xtw.WriteEndElement();
420
421 xtw.WriteElementString("assets_included", SaveAssets.ToString());
422
423 xtw.WriteEndElement();
424
425 xtw.Flush();
426 }
427
428 s = sw.ToString();
429 }
430
431// if (m_scene != null)
432// Console.WriteLine(
433// "[ARCHIVE WRITE REQUEST PREPARATION]: Control file for {0} is: {1}", m_scene.RegionInfo.RegionName, s);
385 434
386 return s; 435 return s;
387 } 436 }
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
index f5a5a8d..bf3b124 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
@@ -45,7 +45,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
45 private static readonly ILog m_log = 45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 private Scene m_scene; 48 public Scene Scene { get; private set; }
49 public IRegionCombinerModule RegionCombinerModule { get; private set; }
49 50
50 /// <value> 51 /// <value>
51 /// The file used to load and save an opensimulator archive if no filename has been specified 52 /// The file used to load and save an opensimulator archive if no filename has been specified
@@ -70,13 +71,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
70 71
71 public void AddRegion(Scene scene) 72 public void AddRegion(Scene scene)
72 { 73 {
73 m_scene = scene; 74 Scene = scene;
74 m_scene.RegisterModuleInterface<IRegionArchiverModule>(this); 75 Scene.RegisterModuleInterface<IRegionArchiverModule>(this);
75 //m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName); 76 //m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName);
76 } 77 }
77 78
78 public void RegionLoaded(Scene scene) 79 public void RegionLoaded(Scene scene)
79 { 80 {
81 RegionCombinerModule = scene.RequestModuleInterface<IRegionCombinerModule>();
80 } 82 }
81 83
82 public void RemoveRegion(Scene scene) 84 public void RemoveRegion(Scene scene)
@@ -165,9 +167,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
165 public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options) 167 public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options)
166 { 168 {
167 m_log.InfoFormat( 169 m_log.InfoFormat(
168 "[ARCHIVER]: Writing archive for region {0} to {1}", m_scene.RegionInfo.RegionName, savePath); 170 "[ARCHIVER]: Writing archive for region {0} to {1}", Scene.RegionInfo.RegionName, savePath);
169 171
170 new ArchiveWriteRequestPreparation(m_scene, savePath, requestId).ArchiveRegion(options); 172 new ArchiveWriteRequestPreparation(this, savePath, requestId).ArchiveRegion(options);
171 } 173 }
172 174
173 public void ArchiveRegion(Stream saveStream) 175 public void ArchiveRegion(Stream saveStream)
@@ -182,7 +184,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
182 184
183 public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options) 185 public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options)
184 { 186 {
185 new ArchiveWriteRequestPreparation(m_scene, saveStream, requestId).ArchiveRegion(options); 187 new ArchiveWriteRequestPreparation(this, saveStream, requestId).ArchiveRegion(options);
186 } 188 }
187 189
188 public void DearchiveRegion(string loadPath) 190 public void DearchiveRegion(string loadPath)
@@ -193,9 +195,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
193 public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId) 195 public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId)
194 { 196 {
195 m_log.InfoFormat( 197 m_log.InfoFormat(
196 "[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath); 198 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
197 199
198 new ArchiveReadRequest(m_scene, loadPath, merge, skipAssets, requestId).DearchiveRegion(); 200 new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, requestId).DearchiveRegion();
199 } 201 }
200 202
201 public void DearchiveRegion(Stream loadStream) 203 public void DearchiveRegion(Stream loadStream)
@@ -205,7 +207,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
205 207
206 public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId) 208 public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId)
207 { 209 {
208 new ArchiveReadRequest(m_scene, loadStream, merge, skipAssets, requestId).DearchiveRegion(); 210 new ArchiveReadRequest(Scene, loadStream, merge, skipAssets, requestId).DearchiveRegion();
209 } 211 }
210 } 212 }
211} 213}
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
index 63f1363..5deaf52 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
68 SerialiserModule serialiserModule = new SerialiserModule(); 68 SerialiserModule serialiserModule = new SerialiserModule();
69 TerrainModule terrainModule = new TerrainModule(); 69 TerrainModule terrainModule = new TerrainModule();
70 70
71 m_scene = SceneHelpers.SetupScene(); 71 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, m_archiverModule, serialiserModule, terrainModule); 72 SceneHelpers.SetupSceneModules(m_scene, m_archiverModule, serialiserModule, terrainModule);
73 } 73 }
74 74
@@ -102,9 +102,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
102 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); 102 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
103 Vector3 groupPosition = new Vector3(10, 20, 30); 103 Vector3 groupPosition = new Vector3(10, 20, 30);
104 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); 104 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
105 Vector3 offsetPosition = new Vector3(5, 10, 15); 105// Vector3 offsetPosition = new Vector3(5, 10, 15);
106 106
107 return new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition) { Name = partName }; 107 return new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, Vector3.Zero) { Name = partName };
108 } 108 }
109 109
110 protected SceneObjectPart CreateSceneObjectPart2() 110 protected SceneObjectPart CreateSceneObjectPart2()
@@ -292,6 +292,59 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
292 } 292 }
293 293
294 /// <summary> 294 /// <summary>
295 /// Test loading an OpenSim Region Archive where the scene object parts are not ordered by link number (e.g.
296 /// 2 can come after 3).
297 /// </summary>
298 [Test]
299 public void TestLoadOarUnorderedParts()
300 {
301 TestHelpers.InMethod();
302
303 UUID ownerId = TestHelpers.ParseTail(0xaaaa);
304
305 MemoryStream archiveWriteStream = new MemoryStream();
306 TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);
307
308 tar.WriteFile(
309 ArchiveConstants.CONTROL_FILE_PATH,
310 new ArchiveWriteRequestPreparation(null, (Stream)null, Guid.Empty).CreateControlFile(new Dictionary<string, Object>()));
311
312 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ownerId, "obj1-", 0x11);
313 SceneObjectPart sop2
314 = SceneHelpers.CreateSceneObjectPart("obj1-Part2", TestHelpers.ParseTail(0x12), ownerId);
315 SceneObjectPart sop3
316 = SceneHelpers.CreateSceneObjectPart("obj1-Part3", TestHelpers.ParseTail(0x13), ownerId);
317
318 // Add the parts so they will be written out in reverse order to the oar
319 sog1.AddPart(sop3);
320 sop3.LinkNum = 3;
321 sog1.AddPart(sop2);
322 sop2.LinkNum = 2;
323
324 tar.WriteFile(
325 ArchiveConstants.CreateOarObjectPath(sog1.Name, sog1.UUID, sog1.AbsolutePosition),
326 SceneObjectSerializer.ToXml2Format(sog1));
327
328 tar.Close();
329
330 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
331
332 lock (this)
333 {
334 m_scene.EventManager.OnOarFileLoaded += LoadCompleted;
335 m_archiverModule.DearchiveRegion(archiveReadStream);
336 }
337
338 Assert.That(m_lastErrorMessage, Is.Null);
339
340 SceneObjectPart part2 = m_scene.GetSceneObjectPart("obj1-Part2");
341 Assert.That(part2.LinkNum, Is.EqualTo(2));
342
343 SceneObjectPart part3 = m_scene.GetSceneObjectPart("obj1-Part3");
344 Assert.That(part3.LinkNum, Is.EqualTo(3));
345 }
346
347 /// <summary>
295 /// Test loading an OpenSim Region Archive. 348 /// Test loading an OpenSim Region Archive.
296 /// </summary> 349 /// </summary>
297 [Test] 350 [Test]
@@ -463,7 +516,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
463 SerialiserModule serialiserModule = new SerialiserModule(); 516 SerialiserModule serialiserModule = new SerialiserModule();
464 TerrainModule terrainModule = new TerrainModule(); 517 TerrainModule terrainModule = new TerrainModule();
465 518
466 TestScene scene2 = SceneHelpers.SetupScene(); 519 TestScene scene2 = new SceneHelpers().SetupScene();
467 SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule); 520 SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule);
468 521
469 // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is 522 // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is
@@ -534,6 +587,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
534 rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080"); 587 rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080");
535 rs.UseEstateSun = true; 588 rs.UseEstateSun = true;
536 rs.WaterHeight = 23; 589 rs.WaterHeight = 23;
590 rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111");
591 rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33"));
537 592
538 tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs)); 593 tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs));
539 594
@@ -580,6 +635,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
580 Assert.That(loadedRs.TerrainTexture4, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000080"))); 635 Assert.That(loadedRs.TerrainTexture4, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000080")));
581 Assert.That(loadedRs.UseEstateSun, Is.True); 636 Assert.That(loadedRs.UseEstateSun, Is.True);
582 Assert.That(loadedRs.WaterHeight, Is.EqualTo(23)); 637 Assert.That(loadedRs.WaterHeight, Is.EqualTo(23));
638 Assert.AreEqual(UUID.Zero, loadedRs.TelehubObject); // because no object was found with the original UUID
639 Assert.AreEqual(0, loadedRs.SpawnPoints().Count);
583 } 640 }
584 641
585 /// <summary> 642 /// <summary>
@@ -607,7 +664,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
607 SerialiserModule serialiserModule = new SerialiserModule(); 664 SerialiserModule serialiserModule = new SerialiserModule();
608 TerrainModule terrainModule = new TerrainModule(); 665 TerrainModule terrainModule = new TerrainModule();
609 666
610 Scene scene = SceneHelpers.SetupScene(); 667 Scene scene = new SceneHelpers().SetupScene();
611 SceneHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule); 668 SceneHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule);
612 669
613 m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false); 670 m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false);
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
index d2bbea3..3b84d57 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
73 "set terrain heights <corner> <min> <max> [<x>] [<y>]", 73 "set terrain heights <corner> <min> <max> [<x>] [<y>]",
74 "Sets the terrain texture heights on corner #<corner> to <min>/<max>, if <x> or <y> are specified, it will only " + 74 "Sets the terrain texture heights on corner #<corner> to <min>/<max>, if <x> or <y> are specified, it will only " +
75 "set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" + 75 "set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" +
76 " that coordinate. Corner # SW = 0, NW = 1, SE = 2, NE = 3.", 76 " that coordinate. Corner # SW = 0, NW = 1, SE = 2, NE = 3, all corners = -1.",
77 consoleSetTerrainHeights); 77 consoleSetTerrainHeights);
78 78
79 m_module.Scene.AddCommand( 79 m_module.Scene.AddCommand(
@@ -143,6 +143,16 @@ namespace OpenSim.Region.CoreModules.World.Estate
143 143
144 switch (corner) 144 switch (corner)
145 { 145 {
146 case -1:
147 m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
148 m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
149 m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
150 m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
151 m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
152 m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
153 m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
154 m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
155 break;
146 case 0: 156 case 0:
147 m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue; 157 m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
148 m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue; 158 m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
index 97a2f4a..fdef9d8 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
@@ -170,12 +170,18 @@ namespace OpenSim.Region.CoreModules.World.Estate
170 sendRegionInfoPacketToAll(); 170 sendRegionInfoPacketToAll();
171 } 171 }
172 172
173 public void setEstateTerrainBaseTexture(IClientAPI remoteClient, int corner, UUID texture) 173 public void setEstateTerrainBaseTexture(int level, UUID texture)
174 {
175 setEstateTerrainBaseTexture(null, level, texture);
176 sendRegionHandshakeToAll();
177 }
178
179 public void setEstateTerrainBaseTexture(IClientAPI remoteClient, int level, UUID texture)
174 { 180 {
175 if (texture == UUID.Zero) 181 if (texture == UUID.Zero)
176 return; 182 return;
177 183
178 switch (corner) 184 switch (level)
179 { 185 {
180 case 0: 186 case 0:
181 Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture; 187 Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
@@ -195,6 +201,11 @@ namespace OpenSim.Region.CoreModules.World.Estate
195 sendRegionInfoPacketToAll(); 201 sendRegionInfoPacketToAll();
196 } 202 }
197 203
204 public void setEstateTerrainTextureHeights(int corner, float lowValue, float highValue)
205 {
206 setEstateTerrainTextureHeights(null, corner, lowValue, highValue);
207 }
208
198 public void setEstateTerrainTextureHeights(IClientAPI client, int corner, float lowValue, float highValue) 209 public void setEstateTerrainTextureHeights(IClientAPI client, int corner, float lowValue, float highValue)
199 { 210 {
200 switch (corner) 211 switch (corner)
@@ -993,7 +1004,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
993 { 1004 {
994 RegionHandshakeArgs args = new RegionHandshakeArgs(); 1005 RegionHandshakeArgs args = new RegionHandshakeArgs();
995 1006
996 args.isEstateManager = Scene.RegionInfo.EstateSettings.IsEstateManager(remoteClient.AgentId); 1007 args.isEstateManager = Scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(remoteClient.AgentId);
997 if (Scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero && Scene.RegionInfo.EstateSettings.EstateOwner == remoteClient.AgentId) 1008 if (Scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero && Scene.RegionInfo.EstateSettings.EstateOwner == remoteClient.AgentId)
998 args.isEstateManager = true; 1009 args.isEstateManager = true;
999 1010
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
index add1551..51dcb67 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
@@ -1395,21 +1395,26 @@ namespace OpenSim.Region.CoreModules.World.Land
1395 private void EventManagerOnRegisterCaps(UUID agentID, Caps caps) 1395 private void EventManagerOnRegisterCaps(UUID agentID, Caps caps)
1396 { 1396 {
1397 string capsBase = "/CAPS/" + caps.CapsObjectPath; 1397 string capsBase = "/CAPS/" + caps.CapsObjectPath;
1398 caps.RegisterHandler("RemoteParcelRequest", 1398 caps.RegisterHandler(
1399 new RestStreamHandler("POST", capsBase + remoteParcelRequestPath, 1399 "RemoteParcelRequest",
1400 delegate(string request, string path, string param, 1400 new RestStreamHandler(
1401 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 1401 "POST",
1402 { 1402 capsBase + remoteParcelRequestPath,
1403 return RemoteParcelRequest(request, path, param, agentID, caps); 1403 (request, path, param, httpRequest, httpResponse)
1404 })); 1404 => RemoteParcelRequest(request, path, param, agentID, caps),
1405 "RemoteParcelRequest",
1406 agentID.ToString()));
1407
1405 UUID parcelCapID = UUID.Random(); 1408 UUID parcelCapID = UUID.Random();
1406 caps.RegisterHandler("ParcelPropertiesUpdate", 1409 caps.RegisterHandler(
1407 new RestStreamHandler("POST", "/CAPS/" + parcelCapID, 1410 "ParcelPropertiesUpdate",
1408 delegate(string request, string path, string param, 1411 new RestStreamHandler(
1409 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 1412 "POST",
1410 { 1413 "/CAPS/" + parcelCapID,
1411 return ProcessPropertiesUpdate(request, path, param, agentID, caps); 1414 (request, path, param, httpRequest, httpResponse)
1412 })); 1415 => ProcessPropertiesUpdate(request, path, param, agentID, caps),
1416 "ParcelPropertiesUpdate",
1417 agentID.ToString()));
1413 } 1418 }
1414 private string ProcessPropertiesUpdate(string request, string path, string param, UUID agentID, Caps caps) 1419 private string ProcessPropertiesUpdate(string request, string path, string param, UUID agentID, Caps caps)
1415 { 1420 {
@@ -1774,7 +1779,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1774 1779
1775 Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land); 1780 Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land);
1776 1781
1777 targetAvatar.TeleportWithMomentum(pos); 1782 targetAvatar.TeleportWithMomentum(pos, null);
1778 targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname); 1783 targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
1779 parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected."); 1784 parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
1780 1785
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index 4284444..b7667b9 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -450,7 +450,10 @@ namespace OpenSim.Region.CoreModules.World.Land
450 { 450 {
451 bool isMember; 451 bool isMember;
452 if (m_groupMemberCache.TryGetValue(avatar, out isMember)) 452 if (m_groupMemberCache.TryGetValue(avatar, out isMember))
453 {
454 m_groupMemberCache.Update(avatar, isMember, m_groupMemberCacheTimeout);
453 return isMember; 455 return isMember;
456 }
454 457
455 IGroupsModule groupsModule = m_scene.RequestModuleInterface<IGroupsModule>(); 458 IGroupsModule groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
456 if (groupsModule == null) 459 if (groupsModule == null)
@@ -487,7 +490,7 @@ namespace OpenSim.Region.CoreModules.World.Land
487 if (m_scene.Permissions.IsAdministrator(avatar)) 490 if (m_scene.Permissions.IsAdministrator(avatar))
488 return false; 491 return false;
489 492
490 if (m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar)) 493 if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar))
491 return false; 494 return false;
492 495
493 if (avatar == LandData.OwnerID) 496 if (avatar == LandData.OwnerID)
@@ -517,7 +520,7 @@ namespace OpenSim.Region.CoreModules.World.Land
517 if (m_scene.Permissions.IsAdministrator(avatar)) 520 if (m_scene.Permissions.IsAdministrator(avatar))
518 return false; 521 return false;
519 522
520 if (m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar)) 523 if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar))
521 return false; 524 return false;
522 525
523 if (avatar == LandData.OwnerID) 526 if (avatar == LandData.OwnerID)
@@ -1230,7 +1233,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1230 if (land.LandData.LocalID == LandData.LocalID) 1233 if (land.LandData.LocalID == LandData.LocalID)
1231 { 1234 {
1232 Vector3 pos = m_scene.GetNearestAllowedPosition(presence, land); 1235 Vector3 pos = m_scene.GetNearestAllowedPosition(presence, land);
1233 presence.TeleportWithMomentum(pos); 1236 presence.TeleportWithMomentum(pos, null);
1234 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 1237 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
1235 } 1238 }
1236 } 1239 }
diff --git a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs
index 5122734..102b4d7 100644
--- a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs
@@ -126,7 +126,6 @@ namespace OpenSim.Region.CoreModules.World.Land
126// m_log.DebugFormat( 126// m_log.DebugFormat(
127// "[PRIM COUNT MODULE]: Ignoring OnParcelPrimCountAdd() for {0} on {1} since count is tainted", 127// "[PRIM COUNT MODULE]: Ignoring OnParcelPrimCountAdd() for {0} on {1} since count is tainted",
128// obj.Name, m_Scene.RegionInfo.RegionName); 128// obj.Name, m_Scene.RegionInfo.RegionName);
129
130 } 129 }
131 } 130 }
132 131
diff --git a/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs b/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs
index e553ffa..b5ee4d2 100644
--- a/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs
+++ b/OpenSim/Region/CoreModules/World/Land/Tests/PrimCountModuleTests.cs
@@ -64,7 +64,7 @@ namespace OpenSim.Region.CoreModules.World.Land.Tests
64 { 64 {
65 m_pcm = new PrimCountModule(); 65 m_pcm = new PrimCountModule();
66 LandManagementModule lmm = new LandManagementModule(); 66 LandManagementModule lmm = new LandManagementModule();
67 m_scene = SceneHelpers.SetupScene(); 67 m_scene = new SceneHelpers().SetupScene();
68 SceneHelpers.SetupSceneModules(m_scene, lmm, m_pcm); 68 SceneHelpers.SetupSceneModules(m_scene, lmm, m_pcm);
69 69
70 int xParcelDivider = (int)Constants.RegionSize - 1; 70 int xParcelDivider = (int)Constants.RegionSize - 1;
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
index f86c790..aa306c7 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
@@ -225,7 +225,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
225 int tc = 0; 225 int tc = 0;
226 double[,] hm = whichScene.Heightmap.GetDoubles(); 226 double[,] hm = whichScene.Heightmap.GetDoubles();
227 tc = Environment.TickCount; 227 tc = Environment.TickCount;
228 m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); 228 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile");
229 EntityBase[] objs = whichScene.GetEntities(); 229 EntityBase[] objs = whichScene.GetEntities();
230 Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>(); 230 Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
231 //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>(); 231 //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>();
@@ -541,7 +541,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
541 g.Dispose(); 541 g.Dispose();
542 } // lock entities objs 542 } // lock entities objs
543 543
544 m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms"); 544 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms");
545 return mapbmp; 545 return mapbmp;
546 } 546 }
547 547
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
index eb1a27f..992bff3 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
@@ -54,7 +54,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
54 public void TerrainToBitmap(Bitmap mapbmp) 54 public void TerrainToBitmap(Bitmap mapbmp)
55 { 55 {
56 int tc = Environment.TickCount; 56 int tc = Environment.TickCount;
57 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain"); 57 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Terrain");
58 58
59 double[,] hm = m_scene.Heightmap.GetDoubles(); 59 double[,] hm = m_scene.Heightmap.GetDoubles();
60 bool ShadowDebugContinue = true; 60 bool ShadowDebugContinue = true;
@@ -238,7 +238,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
238 } 238 }
239 } 239 }
240 } 240 }
241 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); 241 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms");
242 } 242 }
243 } 243 }
244} 244}
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
index 1d2141e..d13c2ef 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
@@ -278,7 +278,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
278 public void TerrainToBitmap(Bitmap mapbmp) 278 public void TerrainToBitmap(Bitmap mapbmp)
279 { 279 {
280 int tc = Environment.TickCount; 280 int tc = Environment.TickCount;
281 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain"); 281 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Terrain");
282 282
283 // These textures should be in the AssetCache anyway, as every client conneting to this 283 // These textures should be in the AssetCache anyway, as every client conneting to this
284 // region needs them. Except on start, when the map is recreated (before anyone connected), 284 // region needs them. Except on start, when the map is recreated (before anyone connected),
@@ -412,7 +412,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
412 } 412 }
413 } 413 }
414 } 414 }
415 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); 415 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms");
416 } 416 }
417 } 417 }
418} 418}
diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
index 5239f50..601e81e 100644
--- a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
+++ b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
@@ -145,7 +145,9 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
145 145
146 // Even though we're registering for POST we're going to get GETS and UPDATES too 146 // Even though we're registering for POST we're going to get GETS and UPDATES too
147 caps.RegisterHandler( 147 caps.RegisterHandler(
148 "ObjectMedia", new RestStreamHandler("POST", omCapUrl, HandleObjectMediaMessage)); 148 "ObjectMedia",
149 new RestStreamHandler(
150 "POST", omCapUrl, HandleObjectMediaMessage, "ObjectMedia", agentID.ToString()));
149 } 151 }
150 152
151 string omuCapUrl = "/CAPS/" + UUID.Random(); 153 string omuCapUrl = "/CAPS/" + UUID.Random();
@@ -157,7 +159,9 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
157 159
158 // Even though we're registering for POST we're going to get GETS and UPDATES too 160 // Even though we're registering for POST we're going to get GETS and UPDATES too
159 caps.RegisterHandler( 161 caps.RegisterHandler(
160 "ObjectMediaNavigate", new RestStreamHandler("POST", omuCapUrl, HandleObjectMediaNavigateMessage)); 162 "ObjectMediaNavigate",
163 new RestStreamHandler(
164 "POST", omuCapUrl, HandleObjectMediaNavigateMessage, "ObjectMediaNavigate", agentID.ToString()));
161 } 165 }
162 } 166 }
163 167
diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs b/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs
index 4326606..0545250 100644
--- a/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs
+++ b/OpenSim/Region/CoreModules/World/Media/Moap/Tests/MoapTests.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap.Tests
53 public void SetUp() 53 public void SetUp()
54 { 54 {
55 m_module = new MoapModule(); 55 m_module = new MoapModule();
56 m_scene = SceneHelpers.SetupScene(); 56 m_scene = new SceneHelpers().SetupScene();
57 SceneHelpers.SetupSceneModules(m_scene, m_module); 57 SceneHelpers.SetupSceneModules(m_scene, m_module);
58 } 58 }
59 59
diff --git a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs
index f5a5c92..e5cd3e2 100644
--- a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs
@@ -29,8 +29,10 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using System.Text; 31using System.Text;
32using System.Text.RegularExpressions;
32using log4net; 33using log4net;
33using Mono.Addins; 34using Mono.Addins;
35using NDesk.Options;
34using Nini.Config; 36using Nini.Config;
35using OpenMetaverse; 37using OpenMetaverse;
36using OpenSim.Framework; 38using OpenSim.Framework;
@@ -78,49 +80,64 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
78 m_scene = scene; 80 m_scene = scene;
79 m_console = MainConsole.Instance; 81 m_console = MainConsole.Instance;
80 82
81 m_console.Commands.AddCommand("Regions", false, "delete object owner", 83 m_console.Commands.AddCommand(
82 "delete object owner <UUID>", 84 "Objects", false, "delete object owner",
83 "Delete a scene object by owner", HandleDeleteObject); 85 "delete object owner <UUID>",
84 m_console.Commands.AddCommand("Regions", false, "delete object creator", 86 "Delete a scene object by owner", HandleDeleteObject);
85 "delete object creator <UUID>", 87
86 "Delete a scene object by creator", HandleDeleteObject); 88 m_console.Commands.AddCommand(
87 m_console.Commands.AddCommand("Regions", false, "delete object uuid", 89 "Objects", false, "delete object creator",
88 "delete object uuid <UUID>", 90 "delete object creator <UUID>",
89 "Delete a scene object by uuid", HandleDeleteObject); 91 "Delete a scene object by creator", HandleDeleteObject);
90 m_console.Commands.AddCommand("Regions", false, "delete object name", 92
91 "delete object name <name>", 93 m_console.Commands.AddCommand(
92 "Delete a scene object by name", HandleDeleteObject); 94 "Objects", false, "delete object uuid",
93 m_console.Commands.AddCommand("Regions", false, "delete object outside", 95 "delete object uuid <UUID>",
94 "delete object outside", 96 "Delete a scene object by uuid", HandleDeleteObject);
95 "Delete all scene objects outside region boundaries", HandleDeleteObject); 97
98 m_console.Commands.AddCommand(
99 "Objects", false, "delete object name",
100 "delete object name [--regex] <name>",
101 "Delete a scene object by name.",
102 "If --regex is specified then the name is treatead as a regular expression",
103 HandleDeleteObject);
104
105 m_console.Commands.AddCommand(
106 "Objects", false, "delete object outside",
107 "delete object outside",
108 "Delete all scene objects outside region boundaries", HandleDeleteObject);
96 109
97 m_console.Commands.AddCommand( 110 m_console.Commands.AddCommand(
98 "Regions", 111 "Objects",
99 false, 112 false,
100 "show object uuid", 113 "show object uuid",
101 "show object uuid <UUID>", 114 "show object uuid <UUID>",
102 "Show details of a scene object with the given UUID", HandleShowObjectByUuid); 115 "Show details of a scene object with the given UUID", HandleShowObjectByUuid);
103 116
104 m_console.Commands.AddCommand( 117 m_console.Commands.AddCommand(
105 "Regions", 118 "Objects",
106 false, 119 false,
107 "show object name", 120 "show object name",
108 "show object name <name>", 121 "show object name [--regex] <name>",
109 "Show details of scene objects with the given name", HandleShowObjectByName); 122 "Show details of scene objects with the given name.",
123 "If --regex is specified then the name is treatead as a regular expression",
124 HandleShowObjectByName);
110 125
111 m_console.Commands.AddCommand( 126 m_console.Commands.AddCommand(
112 "Regions", 127 "Objects",
113 false, 128 false,
114 "show part uuid", 129 "show part uuid",
115 "show part uuid <UUID>", 130 "show part uuid <UUID>",
116 "Show details of a scene object parts with the given UUID", HandleShowPartByUuid); 131 "Show details of a scene object parts with the given UUID", HandleShowPartByUuid);
117 132
118 m_console.Commands.AddCommand( 133 m_console.Commands.AddCommand(
119 "Regions", 134 "Objects",
120 false, 135 false,
121 "show part name", 136 "show part name",
122 "show part name <name>", 137 "show part name [--regex] <name>",
123 "Show details of scene object parts with the given name", HandleShowPartByName); 138 "Show details of scene object parts with the given name.",
139 "If --regex is specified then the name is treatead as a regular expression",
140 HandleShowPartByName);
124 } 141 }
125 142
126 public void RemoveRegion(Scene scene) 143 public void RemoveRegion(Scene scene)
@@ -165,22 +182,38 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
165 m_console.OutputFormat(sb.ToString()); 182 m_console.OutputFormat(sb.ToString());
166 } 183 }
167 184
168 private void HandleShowObjectByName(string module, string[] cmd) 185 private void HandleShowObjectByName(string module, string[] cmdparams)
169 { 186 {
170 if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) 187 if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
171 return; 188 return;
172 189
173 if (cmd.Length < 4) 190 bool useRegex = false;
191 OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
192
193 List<string> mainParams = options.Parse(cmdparams);
194
195 if (mainParams.Count < 4)
174 { 196 {
175 m_console.OutputFormat("Usage: show object name <name>"); 197 m_console.OutputFormat("Usage: show object name [--regex] <name>");
176 return; 198 return;
177 } 199 }
178 200
179 string name = cmd[3]; 201 string name = mainParams[3];
180 202
181 List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); 203 List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
204 Action<SceneObjectGroup> searchAction;
182 205
183 m_scene.ForEachSOG(so => { if (so.Name == name) { sceneObjects.Add(so); }}); 206 if (useRegex)
207 {
208 Regex nameRegex = new Regex(name);
209 searchAction = so => { if (nameRegex.IsMatch(so.Name)) { sceneObjects.Add(so); }};
210 }
211 else
212 {
213 searchAction = so => { if (so.Name == name) { sceneObjects.Add(so); }};
214 }
215
216 m_scene.ForEachSOG(searchAction);
184 217
185 if (sceneObjects.Count == 0) 218 if (sceneObjects.Count == 0)
186 { 219 {
@@ -231,22 +264,39 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
231 m_console.OutputFormat(sb.ToString()); 264 m_console.OutputFormat(sb.ToString());
232 } 265 }
233 266
234 private void HandleShowPartByName(string module, string[] cmd) 267 private void HandleShowPartByName(string module, string[] cmdparams)
235 { 268 {
236 if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) 269 if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
237 return; 270 return;
238 271
239 if (cmd.Length < 4) 272 bool useRegex = false;
273 OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
274
275 List<string> mainParams = options.Parse(cmdparams);
276
277 if (mainParams.Count < 4)
240 { 278 {
241 m_console.OutputFormat("Usage: show part name <name>"); 279 m_console.OutputFormat("Usage: show part name [--regex] <name>");
242 return; 280 return;
243 } 281 }
244 282
245 string name = cmd[3]; 283 string name = mainParams[3];
246 284
247 List<SceneObjectPart> parts = new List<SceneObjectPart>(); 285 List<SceneObjectPart> parts = new List<SceneObjectPart>();
248 286
249 m_scene.ForEachSOG(so => so.ForEachPart(sop => { if (sop.Name == name) { parts.Add(sop); } })); 287 Action<SceneObjectGroup> searchAction;
288
289 if (useRegex)
290 {
291 Regex nameRegex = new Regex(name);
292 searchAction = so => so.ForEachPart(sop => { if (nameRegex.IsMatch(sop.Name)) { parts.Add(sop); } });
293 }
294 else
295 {
296 searchAction = so => so.ForEachPart(sop => { if (sop.Name == name) { parts.Add(sop); } });
297 }
298
299 m_scene.ForEachSOG(searchAction);
250 300
251 if (parts.Count == 0) 301 if (parts.Count == 0)
252 { 302 {
@@ -271,6 +321,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
271 sb.AppendFormat("Description: {0}\n", so.Description); 321 sb.AppendFormat("Description: {0}\n", so.Description);
272 sb.AppendFormat("Location: {0} @ {1}\n", so.AbsolutePosition, so.Scene.RegionInfo.RegionName); 322 sb.AppendFormat("Location: {0} @ {1}\n", so.AbsolutePosition, so.Scene.RegionInfo.RegionName);
273 sb.AppendFormat("Parts: {0}\n", so.PrimCount); 323 sb.AppendFormat("Parts: {0}\n", so.PrimCount);
324 sb.AppendFormat("Flags: {0}\n", so.RootPart.Flags);
274 325
275 return sb; 326 return sb;
276 } 327 }
@@ -282,7 +333,8 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
282 sb.AppendFormat("Location: {0} @ {1}\n", sop.AbsolutePosition, sop.ParentGroup.Scene.RegionInfo.RegionName); 333 sb.AppendFormat("Location: {0} @ {1}\n", sop.AbsolutePosition, sop.ParentGroup.Scene.RegionInfo.RegionName);
283 sb.AppendFormat("Parent: {0}", 334 sb.AppendFormat("Parent: {0}",
284 sop.IsRoot ? "Is Root\n" : string.Format("{0} {1}\n", sop.ParentGroup.Name, sop.ParentGroup.UUID)); 335 sop.IsRoot ? "Is Root\n" : string.Format("{0} {1}\n", sop.ParentGroup.Name, sop.ParentGroup.UUID));
285 sb.AppendFormat("Parts: {0}\n", !sop.IsRoot ? "1" : sop.ParentGroup.PrimCount.ToString());; 336 sb.AppendFormat("Link number: {0}\n", sop.LinkNum);
337 sb.AppendFormat("Flags: {0}\n", sop.Flags);
286 338
287 return sb; 339 return sb;
288 } 340 }
@@ -306,105 +358,169 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
306 o = cmd[3]; 358 o = cmd[3];
307 } 359 }
308 360
309 List<SceneObjectGroup> deletes = new List<SceneObjectGroup>(); 361 List<SceneObjectGroup> deletes = null;
310
311 UUID match; 362 UUID match;
363 bool requireConfirmation = true;
312 364
313 switch (mode) 365 switch (mode)
314 { 366 {
315 case "owner": 367 case "owner":
316 if (!UUID.TryParse(o, out match)) 368 if (!UUID.TryParse(o, out match))
317 return; 369 return;
318 370
319 m_scene.ForEachSOG(delegate (SceneObjectGroup g) 371 deletes = new List<SceneObjectGroup>();
320 {
321 if (g.OwnerID == match && !g.IsAttachment)
322 deletes.Add(g);
323 });
324 372
325// if (deletes.Count == 0) 373 m_scene.ForEachSOG(delegate (SceneObjectGroup g)
326// m_console.OutputFormat("No objects were found with owner {0}", match); 374 {
327 375 if (g.OwnerID == match && !g.IsAttachment)
328 break; 376 deletes.Add(g);
377 });
378
379 // if (deletes.Count == 0)
380 // m_console.OutputFormat("No objects were found with owner {0}", match);
381
382 break;
383
384 case "creator":
385 if (!UUID.TryParse(o, out match))
386 return;
329 387
330 case "creator": 388 deletes = new List<SceneObjectGroup>();
331 if (!UUID.TryParse(o, out match))
332 return;
333 389
334 m_scene.ForEachSOG(delegate (SceneObjectGroup g) 390 m_scene.ForEachSOG(delegate (SceneObjectGroup g)
335 { 391 {
336 if (g.RootPart.CreatorID == match && !g.IsAttachment) 392 if (g.RootPart.CreatorID == match && !g.IsAttachment)
337 deletes.Add(g); 393 deletes.Add(g);
338 }); 394 });
395
396 // if (deletes.Count == 0)
397 // m_console.OutputFormat("No objects were found with creator {0}", match);
398
399 break;
400
401 case "uuid":
402 if (!UUID.TryParse(o, out match))
403 return;
339 404
340// if (deletes.Count == 0) 405 requireConfirmation = false;
341// m_console.OutputFormat("No objects were found with creator {0}", match); 406 deletes = new List<SceneObjectGroup>();
407
408 m_scene.ForEachSOG(delegate (SceneObjectGroup g)
409 {
410 if (g.UUID == match && !g.IsAttachment)
411 deletes.Add(g);
412 });
413
414 // if (deletes.Count == 0)
415 // m_console.OutputFormat("No objects were found with uuid {0}", match);
416
417 break;
418
419 case "name":
420 deletes = GetDeleteCandidatesByName(module, cmd);
421 break;
422
423 case "outside":
424 deletes = new List<SceneObjectGroup>();
342 425
343 break; 426 m_scene.ForEachSOG(delegate (SceneObjectGroup g)
427 {
428 SceneObjectPart rootPart = g.RootPart;
429 bool delete = false;
430
431 if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0)
432 {
433 delete = true;
434 }
435 else
436 {
437 ILandObject parcel
438 = m_scene.LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y);
439
440 if (parcel == null || parcel.LandData.Name == "NO LAND")
441 delete = true;
442 }
443
444 if (delete && !g.IsAttachment && !deletes.Contains(g))
445 deletes.Add(g);
446 });
447
448 if (deletes.Count == 0)
449 m_console.OutputFormat("No objects were found outside region bounds");
450
451 break;
344 452
345 case "uuid": 453 default:
346 if (!UUID.TryParse(o, out match)) 454 m_console.OutputFormat("Unrecognized mode {0}", mode);
347 return; 455 return;
456 }
348 457
349 m_scene.ForEachSOG(delegate (SceneObjectGroup g) 458 if (deletes == null || deletes.Count <= 0)
350 { 459 return;
351 if (g.UUID == match && !g.IsAttachment)
352 deletes.Add(g);
353 });
354
355// if (deletes.Count == 0)
356// m_console.OutputFormat("No objects were found with uuid {0}", match);
357
358 break;
359 460
360 case "name": 461 if (requireConfirmation)
361 m_scene.ForEachSOG(delegate (SceneObjectGroup g) 462 {
463 string response = MainConsole.Instance.CmdPrompt(
464 string.Format(
465 "Are you sure that you want to delete {0} objects from {1}",
466 deletes.Count, m_scene.RegionInfo.RegionName),
467 "n");
468
469 if (response.ToLower() != "y")
362 { 470 {
363 if (g.RootPart.Name == o && !g.IsAttachment) 471 MainConsole.Instance.OutputFormat(
364 deletes.Add(g); 472 "Aborting delete of {0} objects from {1}", deletes.Count, m_scene.RegionInfo.RegionName);
365 });
366 473
367// if (deletes.Count == 0) 474 return;
368// m_console.OutputFormat("No objects were found with name {0}", o); 475 }
369 476 }
370 break;
371 477
372 case "outside": 478 m_console.OutputFormat("Deleting {0} objects in {1}", deletes.Count, m_scene.RegionInfo.RegionName);
373 m_scene.ForEachSOG(delegate (SceneObjectGroup g)
374 {
375 SceneObjectPart rootPart = g.RootPart;
376 bool delete = false;
377 479
378 if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0) 480 foreach (SceneObjectGroup g in deletes)
379 { 481 {
380 delete = true; 482 m_console.OutputFormat("Deleting object {0} {1}", g.UUID, g.Name);
381 } 483 m_scene.DeleteSceneObject(g, false);
382 else 484 }
383 { 485 }
384 ILandObject parcel
385 = m_scene.LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y);
386 486
387 if (parcel == null || parcel.LandData.Name == "NO LAND") 487 private List<SceneObjectGroup> GetDeleteCandidatesByName(string module, string[] cmdparams)
388 delete = true; 488 {
389 } 489 if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
490 return null;
390 491
391 if (delete && !g.IsAttachment && !deletes.Contains(g)) 492 bool useRegex = false;
392 deletes.Add(g); 493 OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
393 });
394 494
395// if (deletes.Count == 0) 495 List<string> mainParams = options.Parse(cmdparams);
396// m_console.OutputFormat("No objects were found outside region bounds");
397 496
398 break; 497 if (mainParams.Count < 4)
498 {
499 m_console.OutputFormat("Usage: delete object name [--regex] <name>");
500 return null;
399 } 501 }
400 502
401 m_console.OutputFormat("Deleting {0} objects in {1}", deletes.Count, m_scene.RegionInfo.RegionName); 503 string name = mainParams[3];
402 504
403 foreach (SceneObjectGroup g in deletes) 505 List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
506 Action<SceneObjectGroup> searchAction;
507
508 if (useRegex)
404 { 509 {
405 m_console.OutputFormat("Deleting object {0} {1}", g.UUID, g.Name); 510 Regex nameRegex = new Regex(name);
406 m_scene.DeleteSceneObject(g, false); 511 searchAction = so => { if (nameRegex.IsMatch(so.Name)) { sceneObjects.Add(so); }};
512 }
513 else
514 {
515 searchAction = so => { if (so.Name == name) { sceneObjects.Add(so); }};
407 } 516 }
517
518 m_scene.ForEachSOG(searchAction);
519
520 if (sceneObjects.Count == 0)
521 m_console.OutputFormat("No objects with name {0} found in {1}", name, m_scene.RegionInfo.RegionName);
522
523 return sceneObjects;
408 } 524 }
409 } 525 }
410} \ No newline at end of file 526} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index 82ccaf8..f3d38bc 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -166,6 +166,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
166 m_scene.Permissions.OnDeedParcel += CanDeedParcel; 166 m_scene.Permissions.OnDeedParcel += CanDeedParcel;
167 m_scene.Permissions.OnDeedObject += CanDeedObject; 167 m_scene.Permissions.OnDeedObject += CanDeedObject;
168 m_scene.Permissions.OnIsGod += IsGod; 168 m_scene.Permissions.OnIsGod += IsGod;
169 m_scene.Permissions.OnIsGridGod += IsGridGod;
169 m_scene.Permissions.OnIsAdministrator += IsAdministrator; 170 m_scene.Permissions.OnIsAdministrator += IsAdministrator;
170 m_scene.Permissions.OnDuplicateObject += CanDuplicateObject; 171 m_scene.Permissions.OnDuplicateObject += CanDuplicateObject;
171 m_scene.Permissions.OnDeleteObject += CanDeleteObject; //MAYBE FULLY IMPLEMENTED 172 m_scene.Permissions.OnDeleteObject += CanDeleteObject; //MAYBE FULLY IMPLEMENTED
@@ -220,7 +221,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
220 "Force permissions on or off", 221 "Force permissions on or off",
221 HandleForcePermissions); 222 HandleForcePermissions);
222 223
223 m_scene.AddCommand("Users", this, "debug permissions", 224 m_scene.AddCommand("Debug", this, "debug permissions",
224 "debug permissions <true / false>", 225 "debug permissions <true / false>",
225 "Turn on permissions debugging", 226 "Turn on permissions debugging",
226 HandleDebugPermissions); 227 HandleDebugPermissions);
@@ -347,12 +348,12 @@ namespace OpenSim.Region.CoreModules.World.Permissions
347 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 348 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
348 349
349 if (m_friendsModule == null) 350 if (m_friendsModule == null)
350 m_log.Warn("[PERMISSIONS]: Friends module not found, friend permissions will not work"); 351 m_log.Debug("[PERMISSIONS]: Friends module not found, friend permissions will not work");
351 352
352 m_groupsModule = m_scene.RequestModuleInterface<IGroupsModule>(); 353 m_groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
353 354
354 if (m_groupsModule == null) 355 if (m_groupsModule == null)
355 m_log.Warn("[PERMISSIONS]: Groups module not found, group permissions will not work"); 356 m_log.Debug("[PERMISSIONS]: Groups module not found, group permissions will not work");
356 357
357 m_moapModule = m_scene.RequestModuleInterface<IMoapModule>(); 358 m_moapModule = m_scene.RequestModuleInterface<IMoapModule>();
358 359
@@ -449,39 +450,49 @@ namespace OpenSim.Region.CoreModules.World.Permissions
449 } 450 }
450 451
451 /// <summary> 452 /// <summary>
452 /// Is the given user an administrator (in other words, a god)? 453 /// Is the user regarded as an administrator?
453 /// </summary> 454 /// </summary>
454 /// <param name="user"></param> 455 /// <param name="user"></param>
455 /// <returns></returns> 456 /// <returns></returns>
456 protected bool IsAdministrator(UUID user) 457 protected bool IsAdministrator(UUID user)
457 { 458 {
458 if (user == UUID.Zero) return false; 459 if (user == UUID.Zero)
459 460 return false;
460 if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero) 461
461 { 462 if (m_scene.RegionInfo.EstateSettings.EstateOwner == user && m_RegionOwnerIsGod)
462 if (m_scene.RegionInfo.EstateSettings.EstateOwner == user && m_RegionOwnerIsGod) 463 return true;
463 return true;
464 }
465 464
466 if (IsEstateManager(user) && m_RegionManagerIsGod) 465 if (IsEstateManager(user) && m_RegionManagerIsGod)
467 return true; 466 return true;
468 467
468 if (IsGridGod(user, null))
469 return true;
470
471 return false;
472 }
473
474 /// <summary>
475 /// Is the given user a God throughout the grid (not just in the current scene)?
476 /// </summary>
477 /// <param name="user">The user</param>
478 /// <param name="scene">Unused, can be null</param>
479 /// <returns></returns>
480 protected bool IsGridGod(UUID user, Scene scene)
481 {
482 DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
483 if (m_bypassPermissions) return m_bypassPermissionsValue;
484
485 if (user == UUID.Zero) return false;
486
469 if (m_allowGridGods) 487 if (m_allowGridGods)
470 { 488 {
471 ScenePresence sp = m_scene.GetScenePresence(user); 489 ScenePresence sp = m_scene.GetScenePresence(user);
472 if (sp != null) 490 if (sp != null)
473 { 491 return (sp.UserLevel >= 200);
474 if (sp.UserLevel >= 200)
475 return true;
476 return false;
477 }
478 492
479 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, user); 493 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, user);
480 if (account != null) 494 if (account != null)
481 { 495 return (account.UserLevel >= 200);
482 if (account.UserLevel >= 200)
483 return true;
484 }
485 } 496 }
486 497
487 return false; 498 return false;
@@ -503,7 +514,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
503 { 514 {
504 if (user == UUID.Zero) return false; 515 if (user == UUID.Zero) return false;
505 516
506 return m_scene.RegionInfo.EstateSettings.IsEstateManager(user); 517 return m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(user);
507 } 518 }
508 519
509#endregion 520#endregion
diff --git a/OpenSim/Region/CoreModules/World/Region/RegionCommandsModule.cs b/OpenSim/Region/CoreModules/World/Region/RegionCommandsModule.cs
new file mode 100644
index 0000000..2838e0c
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Region/RegionCommandsModule.cs
@@ -0,0 +1,155 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Text.RegularExpressions;
33using log4net;
34using Mono.Addins;
35using NDesk.Options;
36using Nini.Config;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Statistics;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43
44namespace OpenSim.Region.CoreModules.World.Objects.Commands
45{
46 /// <summary>
47 /// A module that holds commands for manipulating objects in the scene.
48 /// </summary>
49 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RegionCommandsModule")]
50 public class RegionCommandsModule : INonSharedRegionModule
51 {
52 private Scene m_scene;
53 private ICommandConsole m_console;
54
55 public string Name { get { return "Region Commands Module"; } }
56
57 public Type ReplaceableInterface { get { return null; } }
58
59 public void Initialise(IConfigSource source)
60 {
61// m_log.DebugFormat("[REGION COMMANDS MODULE]: INITIALIZED MODULE");
62 }
63
64 public void PostInitialise()
65 {
66// m_log.DebugFormat("[REGION COMMANDS MODULE]: POST INITIALIZED MODULE");
67 }
68
69 public void Close()
70 {
71// m_log.DebugFormat("[REGION COMMANDS MODULE]: CLOSED MODULE");
72 }
73
74 public void AddRegion(Scene scene)
75 {
76// m_log.DebugFormat("[REGION COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
77
78 m_scene = scene;
79 m_console = MainConsole.Instance;
80
81 m_console.Commands.AddCommand(
82 "Regions", false, "show scene",
83 "show scene",
84 "Show live scene information for the currently selected region.", HandleShowScene);
85 }
86
87 public void RemoveRegion(Scene scene)
88 {
89// m_log.DebugFormat("[REGION COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
90 }
91
92 public void RegionLoaded(Scene scene)
93 {
94// m_log.DebugFormat("[REGION COMMANDS MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
95 }
96
97 private void HandleShowScene(string module, string[] cmd)
98 {
99 if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
100 return;
101
102 SimStatsReporter r = m_scene.StatsReporter;
103 float[] stats = r.LastReportedSimStats;
104
105 float timeDilation = stats[0];
106 float simFps = stats[1];
107 float physicsFps = stats[2];
108 float agentUpdates = stats[3];
109 float rootAgents = stats[4];
110 float childAgents = stats[5];
111 float totalPrims = stats[6];
112 float activePrims = stats[7];
113 float totalFrameTime = stats[8];
114// float netFrameTime = stats.StatsBlock[9].StatValue; // Ignored - not used by OpenSimulator
115 float physicsFrameTime = stats[10];
116 float otherFrameTime = stats[11];
117// float imageFrameTime = stats.StatsBlock[12].StatValue; // Ignored
118 float inPacketsPerSecond = stats[13];
119 float outPacketsPerSecond = stats[14];
120 float unackedBytes = stats[15];
121// float agentFrameTime = stats.StatsBlock[16].StatValue; // Not really used
122 float pendingDownloads = stats[17];
123 float pendingUploads = stats[18];
124 float activeScripts = stats[19];
125 float scriptLinesPerSecond = stats[20];
126
127 StringBuilder sb = new StringBuilder();
128 sb.AppendFormat("Scene statistics for {0}\n", m_scene.RegionInfo.RegionName);
129
130 ConsoleDisplayList dispList = new ConsoleDisplayList();
131 dispList.AddRow("Time Dilation", timeDilation);
132 dispList.AddRow("Sim FPS", simFps);
133 dispList.AddRow("Physics FPS", physicsFps);
134 dispList.AddRow("Avatars", rootAgents);
135 dispList.AddRow("Child agents", childAgents);
136 dispList.AddRow("Total prims", totalPrims);
137 dispList.AddRow("Scripts", activeScripts);
138 dispList.AddRow("Script lines processed per second", scriptLinesPerSecond);
139 dispList.AddRow("Physics enabled prims", activePrims);
140 dispList.AddRow("Total frame time", totalFrameTime);
141 dispList.AddRow("Physics frame time", physicsFrameTime);
142 dispList.AddRow("Other frame time", otherFrameTime);
143 dispList.AddRow("Agent Updates per second", agentUpdates);
144 dispList.AddRow("Packets processed from clients per second", inPacketsPerSecond);
145 dispList.AddRow("Packets sent to clients per second", outPacketsPerSecond);
146 dispList.AddRow("Bytes unacknowledged by clients", unackedBytes);
147 dispList.AddRow("Pending asset downloads to clients", pendingDownloads);
148 dispList.AddRow("Pending asset uploads from clients", pendingUploads);
149
150 dispList.AddToStringBuilder(sb);
151
152 MainConsole.Instance.Output(sb.ToString());
153 }
154 }
155} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs b/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs
index d1d2020..7825e3e 100644
--- a/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs
+++ b/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs
@@ -343,7 +343,7 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
343 public void Init() 343 public void Init()
344 { 344 {
345 m_serialiserModule = new SerialiserModule(); 345 m_serialiserModule = new SerialiserModule();
346 m_scene = SceneHelpers.SetupScene(); 346 m_scene = new SceneHelpers().SetupScene();
347 SceneHelpers.SetupSceneModules(m_scene, m_serialiserModule); 347 SceneHelpers.SetupSceneModules(m_scene, m_serialiserModule);
348 } 348 }
349 349
diff --git a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs
index 93b1005..d768a1a 100644
--- a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs
+++ b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs
@@ -78,11 +78,8 @@ namespace OpenSim.Region.CoreModules.World.Sound
78 78
79 if (grp.IsAttachment) 79 if (grp.IsAttachment)
80 { 80 {
81 if (grp.AttachmentPoint > 30) // HUD 81 if (grp.HasPrivateAttachmentPoint && sp.ControllingClient.AgentId != grp.OwnerID)
82 { 82 return;
83 if (sp.ControllingClient.AgentId != grp.OwnerID)
84 return;
85 }
86 83
87 if (sp.ControllingClient.AgentId == grp.OwnerID) 84 if (sp.ControllingClient.AgentId == grp.OwnerID)
88 dis = 0; 85 dis = 0;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index da81dc1..d78ade5 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -59,28 +59,32 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
59 /// <returns>A terrain channel generated from the image.</returns> 59 /// <returns>A terrain channel generated from the image.</returns>
60 public virtual ITerrainChannel LoadFile(string filename) 60 public virtual ITerrainChannel LoadFile(string filename)
61 { 61 {
62 return LoadBitmap(new Bitmap(filename)); 62 using (Bitmap b = new Bitmap(filename))
63 return LoadBitmap(b);
63 } 64 }
64 65
65 public virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h) 66 public virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h)
66 { 67 {
67 Bitmap bitmap = new Bitmap(filename); 68 using (Bitmap bitmap = new Bitmap(filename))
68 ITerrainChannel retval = new TerrainChannel(true);
69
70 for (int x = 0; x < retval.Width; x++)
71 { 69 {
72 for (int y = 0; y < retval.Height; y++) 70 ITerrainChannel retval = new TerrainChannel(true);
71
72 for (int x = 0; x < retval.Width; x++)
73 { 73 {
74 retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.Height - y - 1).GetBrightness() * 128; 74 for (int y = 0; y < retval.Height; y++)
75 {
76 retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.Height - y - 1).GetBrightness() * 128;
77 }
75 } 78 }
76 }
77 79
78 return retval; 80 return retval;
81 }
79 } 82 }
80 83
81 public virtual ITerrainChannel LoadStream(Stream stream) 84 public virtual ITerrainChannel LoadStream(Stream stream)
82 { 85 {
83 return LoadBitmap(new Bitmap(stream)); 86 using (Bitmap b = new Bitmap(stream))
87 return LoadBitmap(b);
84 } 88 }
85 89
86 protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap) 90 protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap)
@@ -134,35 +138,53 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
134 // "Saving the image to the same file it was constructed from is not allowed and throws an exception." 138 // "Saving the image to the same file it was constructed from is not allowed and throws an exception."
135 string tempName = Path.GetTempFileName(); 139 string tempName = Path.GetTempFileName();
136 140
137 Bitmap entireBitmap = null; 141 Bitmap existingBitmap = null;
138 Bitmap thisBitmap = null; 142 Bitmap thisBitmap = null;
139 if (File.Exists(filename)) 143 Bitmap newBitmap = null;
144
145 try
140 { 146 {
141 File.Copy(filename, tempName, true); 147 if (File.Exists(filename))
142 entireBitmap = new Bitmap(tempName); 148 {
143 if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY) 149 File.Copy(filename, tempName, true);
150 existingBitmap = new Bitmap(tempName);
151 if (existingBitmap.Width != fileWidth * regionSizeX || existingBitmap.Height != fileHeight * regionSizeY)
152 {
153 // old file, let's overwrite it
154 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
155 }
156 else
157 {
158 newBitmap = existingBitmap;
159 }
160 }
161 else
144 { 162 {
145 // old file, let's overwrite it 163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
146 entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
147 } 164 }
165
166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
168 for (int x = 0; x < regionSizeX; x++)
169 for (int y = 0; y < regionSizeY; y++)
170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
171
172 Save(newBitmap, filename);
148 } 173 }
149 else 174 finally
150 { 175 {
151 entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); 176 if (existingBitmap != null)
152 } 177 existingBitmap.Dispose();
153 178
154 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); 179 if (thisBitmap != null)
155// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); 180 thisBitmap.Dispose();
156 for (int x = 0; x < regionSizeX; x++)
157 for (int y = 0; y < regionSizeY; y++)
158 entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
159 181
160 Save(entireBitmap, filename); 182 if (newBitmap != null)
161 thisBitmap.Dispose(); 183 newBitmap.Dispose();
162 entireBitmap.Dispose();
163 184
164 if (File.Exists(tempName)) 185 if (File.Exists(tempName))
165 File.Delete(tempName); 186 File.Delete(tempName);
187 }
166 } 188 }
167 189
168 protected virtual void Save(Bitmap bmp, string filename) 190 protected virtual void Save(Bitmap bmp, string filename)
@@ -226,16 +248,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
226 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> 248 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
227 protected static Bitmap CreateBitmapFromMap(ITerrainChannel map) 249 protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
228 { 250 {
229 Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); 251 int pallete;
230 252 Bitmap bmp;
231 int pallete = gradientmapLd.Height; 253 Color[] colours;
232 254
233 Bitmap bmp = new Bitmap(map.Width, map.Height); 255 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
234 Color[] colours = new Color[pallete];
235
236 for (int i = 0; i < pallete; i++)
237 { 256 {
238 colours[i] = gradientmapLd.GetPixel(0, i); 257 pallete = gradientmapLd.Height;
258
259 bmp = new Bitmap(map.Width, map.Height);
260 colours = new Color[pallete];
261
262 for (int i = 0; i < pallete; i++)
263 {
264 colours[i] = gradientmapLd.GetPixel(0, i);
265 }
239 } 266 }
240 267
241 for (int y = 0; y < map.Height; y++) 268 for (int y = 0; y < map.Height; y++)
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
index 699d67a..9cc767a 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
@@ -99,16 +99,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
99 99
100 private static Bitmap CreateBitmapFromMap(ITerrainChannel map) 100 private static Bitmap CreateBitmapFromMap(ITerrainChannel map)
101 { 101 {
102 Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); 102 int pallete;
103 Bitmap bmp;
104 Color[] colours;
103 105
104 int pallete = gradientmapLd.Height; 106 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
105
106 Bitmap bmp = new Bitmap(map.Width, map.Height);
107 Color[] colours = new Color[pallete];
108
109 for (int i = 0; i < pallete; i++)
110 { 107 {
111 colours[i] = gradientmapLd.GetPixel(0, i); 108 pallete = gradientmapLd.Height;
109
110 bmp = new Bitmap(map.Width, map.Height);
111 colours = new Color[pallete];
112
113 for (int i = 0; i < pallete; i++)
114 {
115 colours[i] = gradientmapLd.GetPixel(0, i);
116 }
112 } 117 }
113 118
114 for (int y = 0; y < map.Height; y++) 119 for (int y = 0; y < map.Height; y++)
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
index 5d2f893..b416b82 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
59 } 59 }
60 60
61 //Returns true if this extension is supported for terrain save-tile 61 //Returns true if this extension is supported for terrain save-tile
62 public bool SupportsTileSave() 62 public override bool SupportsTileSave()
63 { 63 {
64 return false; 64 return false;
65 } 65 }
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs
index 1ebf916..7a0db26 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
65 bool eof = false; 65 bool eof = false;
66 66
67 int fileXPoints = 0; 67 int fileXPoints = 0;
68 int fileYPoints = 0; 68// int fileYPoints = 0;
69 69
70 // Terragen file 70 // Terragen file
71 while (eof == false) 71 while (eof == false)
@@ -75,7 +75,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
75 { 75 {
76 case "SIZE": 76 case "SIZE":
77 fileXPoints = bs.ReadInt16() + 1; 77 fileXPoints = bs.ReadInt16() + 1;
78 fileYPoints = fileXPoints; 78// fileYPoints = fileXPoints;
79 bs.ReadInt16(); 79 bs.ReadInt16();
80 break; 80 break;
81 case "XPTS": 81 case "XPTS":
@@ -83,7 +83,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
83 bs.ReadInt16(); 83 bs.ReadInt16();
84 break; 84 break;
85 case "YPTS": 85 case "YPTS":
86 fileYPoints = bs.ReadInt16(); 86// fileYPoints = bs.ReadInt16();
87 bs.ReadInt16();
87 bs.ReadInt16(); 88 bs.ReadInt16();
88 break; 89 break;
89 case "ALTW": 90 case "ALTW":
@@ -164,10 +165,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
164 bool eof = false; 165 bool eof = false;
165 if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") 166 if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
166 { 167 {
167 168// int fileWidth = w;
168 int fileWidth = w; 169// int fileHeight = h;
169 int fileHeight = h;
170
171 170
172 // Terragen file 171 // Terragen file
173 while (eof == false) 172 while (eof == false)
@@ -176,17 +175,20 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
176 switch (tmp) 175 switch (tmp)
177 { 176 {
178 case "SIZE": 177 case "SIZE":
179 int sztmp = bs.ReadInt16() + 1; 178// int sztmp = bs.ReadInt16() + 1;
180 fileWidth = sztmp; 179// fileWidth = sztmp;
181 fileHeight = sztmp; 180// fileHeight = sztmp;
181 bs.ReadInt16();
182 bs.ReadInt16(); 182 bs.ReadInt16();
183 break; 183 break;
184 case "XPTS": 184 case "XPTS":
185 fileWidth = bs.ReadInt16(); 185// fileWidth = bs.ReadInt16();
186 bs.ReadInt16();
186 bs.ReadInt16(); 187 bs.ReadInt16();
187 break; 188 break;
188 case "YPTS": 189 case "YPTS":
189 fileHeight = bs.ReadInt16(); 190// fileHeight = bs.ReadInt16();
191 bs.ReadInt16();
190 bs.ReadInt16(); 192 bs.ReadInt16();
191 break; 193 break;
192 case "ALTW": 194 case "ALTW":
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index e2bd769..5b03ac7 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -724,6 +724,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
724 } 724 }
725 if (shouldTaint) 725 if (shouldTaint)
726 { 726 {
727 m_scene.EventManager.TriggerTerrainTainted();
727 m_tainted = true; 728 m_tainted = true;
728 } 729 }
729 } 730 }
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
index 7bf675d..91252f7 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
@@ -84,218 +84,234 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
84 Debug.Assert(heightRanges.Length == 4); 84 Debug.Assert(heightRanges.Length == 4);
85 85
86 Bitmap[] detailTexture = new Bitmap[4]; 86 Bitmap[] detailTexture = new Bitmap[4];
87 Bitmap output = null;
88 BitmapData outputData = null;
87 89
88 if (textureTerrain) 90 try
89 { 91 {
90 // Swap empty terrain textureIDs with default IDs 92 if (textureTerrain)
91 for (int i = 0; i < textureIDs.Length; i++)
92 { 93 {
93 if (textureIDs[i] == UUID.Zero) 94 // Swap empty terrain textureIDs with default IDs
94 textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i]; 95 for (int i = 0; i < textureIDs.Length; i++)
95 }
96
97 #region Texture Fetching
98
99 if (assetService != null)
100 {
101 for (int i = 0; i < 4; i++)
102 { 96 {
103 AssetBase asset; 97 if (textureIDs[i] == UUID.Zero)
104 UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]); 98 textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
105 99 }
106 // Try to fetch a cached copy of the decoded/resized version of this texture 100
107 asset = assetService.GetCached(cacheID.ToString()); 101 #region Texture Fetching
108 if (asset != null) 102
109 { 103 if (assetService != null)
110 try 104 {
111 { 105 for (int i = 0; i < 4; i++)
112 using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
113 detailTexture[i] = (Bitmap)Image.FromStream(stream);
114 }
115 catch (Exception ex)
116 {
117 m_log.Warn("Failed to decode cached terrain texture " + cacheID +
118 " (textureID: " + textureIDs[i] + "): " + ex.Message);
119 }
120 }
121
122 if (detailTexture[i] == null)
123 { 106 {
124 // Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG 107 AssetBase asset;
125 asset = assetService.Get(textureIDs[i].ToString()); 108 UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
109
110 // Try to fetch a cached copy of the decoded/resized version of this texture
111 asset = assetService.GetCached(cacheID.ToString());
126 if (asset != null) 112 if (asset != null)
127 { 113 {
128 try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); } 114 try
115 {
116 using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
117 detailTexture[i] = (Bitmap)Image.FromStream(stream);
118 }
129 catch (Exception ex) 119 catch (Exception ex)
130 { 120 {
131 m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message); 121 m_log.Warn("Failed to decode cached terrain texture " + cacheID +
122 " (textureID: " + textureIDs[i] + "): " + ex.Message);
132 } 123 }
133 } 124 }
134 125
135 if (detailTexture[i] != null) 126 if (detailTexture[i] == null)
136 { 127 {
137 Bitmap bitmap = detailTexture[i]; 128 // Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
138 129 asset = assetService.Get(textureIDs[i].ToString());
139 // Make sure this texture is the correct size, otherwise resize 130 if (asset != null)
140 if (bitmap.Width != 256 || bitmap.Height != 256)
141 bitmap = ImageUtils.ResizeImage(bitmap, 256, 256);
142
143 // Save the decoded and resized texture to the cache
144 byte[] data;
145 using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
146 { 131 {
147 bitmap.Save(stream, ImageFormat.Png); 132 try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); }
148 data = stream.ToArray(); 133 catch (Exception ex)
134 {
135 m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
136 }
149 } 137 }
150 138
151 // Cache a PNG copy of this terrain texture 139 if (detailTexture[i] != null)
152 AssetBase newAsset = new AssetBase
153 { 140 {
154 Data = data, 141 Bitmap bitmap = detailTexture[i];
155 Description = "PNG", 142
156 Flags = AssetFlags.Collectable, 143 // Make sure this texture is the correct size, otherwise resize
157 FullID = cacheID, 144 if (bitmap.Width != 256 || bitmap.Height != 256)
158 ID = cacheID.ToString(), 145 {
159 Local = true, 146 using (Bitmap origBitmap = bitmap)
160 Name = String.Empty, 147 {
161 Temporary = true, 148 bitmap = ImageUtils.ResizeImage(origBitmap, 256, 256);
162 Type = (sbyte)AssetType.Unknown 149 }
163 }; 150 }
164 newAsset.Metadata.ContentType = "image/png"; 151
165 assetService.Store(newAsset); 152 // Save the decoded and resized texture to the cache
153 byte[] data;
154 using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
155 {
156 bitmap.Save(stream, ImageFormat.Png);
157 data = stream.ToArray();
158 }
159
160 // Cache a PNG copy of this terrain texture
161 AssetBase newAsset = new AssetBase
162 {
163 Data = data,
164 Description = "PNG",
165 Flags = AssetFlags.Collectable,
166 FullID = cacheID,
167 ID = cacheID.ToString(),
168 Local = true,
169 Name = String.Empty,
170 Temporary = true,
171 Type = (sbyte)AssetType.Unknown
172 };
173 newAsset.Metadata.ContentType = "image/png";
174 assetService.Store(newAsset);
175 }
166 } 176 }
167 } 177 }
168 } 178 }
179
180 #endregion Texture Fetching
169 } 181 }
170 182
171 #endregion Texture Fetching 183 // Fill in any missing textures with a solid color
172 } 184 for (int i = 0; i < 4; i++)
173
174 // Fill in any missing textures with a solid color
175 for (int i = 0; i < 4; i++)
176 {
177 if (detailTexture[i] == null)
178 { 185 {
179 // Create a solid color texture for this layer 186 if (detailTexture[i] == null)
180 detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
181 using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
182 { 187 {
183 using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) 188 // Create a solid color texture for this layer
184 gfx.FillRectangle(brush, 0, 0, 256, 256); 189 detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
190 using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
191 {
192 using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
193 gfx.FillRectangle(brush, 0, 0, 256, 256);
194 }
185 } 195 }
186 } 196 }
187 } 197
188 198 #region Layer Map
189 #region Layer Map 199
190 200 float[] layermap = new float[256 * 256];
191 float[] layermap = new float[256 * 256]; 201
192
193 for (int y = 0; y < 256; y++)
194 {
195 for (int x = 0; x < 256; x++)
196 {
197 float height = heightmap[y * 256 + x];
198
199 float pctX = (float)x / 255f;
200 float pctY = (float)y / 255f;
201
202 // Use bilinear interpolation between the four corners of start height and
203 // height range to select the current values at this position
204 float startHeight = ImageUtils.Bilinear(
205 startHeights[0],
206 startHeights[2],
207 startHeights[1],
208 startHeights[3],
209 pctX, pctY);
210 startHeight = Utils.Clamp(startHeight, 0f, 255f);
211
212 float heightRange = ImageUtils.Bilinear(
213 heightRanges[0],
214 heightRanges[2],
215 heightRanges[1],
216 heightRanges[3],
217 pctX, pctY);
218 heightRange = Utils.Clamp(heightRange, 0f, 255f);
219
220 // Generate two frequencies of perlin noise based on our global position
221 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
222 Vector3 vec = new Vector3
223 (
224 ((float)regionPosition.X + x) * 0.20319f,
225 ((float)regionPosition.Y + y) * 0.20319f,
226 height * 0.25f
227 );
228
229 float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
230 float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
231 float noise = (lowFreq + highFreq) * 2f;
232
233 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
234 float layer = ((height + noise - startHeight) / heightRange) * 4f;
235 if (Single.IsNaN(layer)) layer = 0f;
236 layermap[y * 256 + x] = Utils.Clamp(layer, 0f, 3f);
237 }
238 }
239
240 #endregion Layer Map
241
242 #region Texture Compositing
243
244 Bitmap output = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
245 BitmapData outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
246
247 unsafe
248 {
249 // Get handles to all of the texture data arrays
250 BitmapData[] datas = new BitmapData[]
251 {
252 detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
253 detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
254 detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
255 detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
256 };
257
258 int[] comps = new int[]
259 {
260 (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
261 (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
262 (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
263 (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
264 };
265
266 for (int y = 0; y < 256; y++) 202 for (int y = 0; y < 256; y++)
267 { 203 {
268 for (int x = 0; x < 256; x++) 204 for (int x = 0; x < 256; x++)
269 { 205 {
270 float layer = layermap[y * 256 + x]; 206 float height = heightmap[y * 256 + x];
271 207
272 // Select two textures 208 float pctX = (float)x / 255f;
273 int l0 = (int)Math.Floor(layer); 209 float pctY = (float)y / 255f;
274 int l1 = Math.Min(l0 + 1, 3); 210
275 211 // Use bilinear interpolation between the four corners of start height and
276 byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0]; 212 // height range to select the current values at this position
277 byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1]; 213 float startHeight = ImageUtils.Bilinear(
278 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3; 214 startHeights[0],
279 215 startHeights[2],
280 float aB = *(ptrA + 0); 216 startHeights[1],
281 float aG = *(ptrA + 1); 217 startHeights[3],
282 float aR = *(ptrA + 2); 218 pctX, pctY);
283 219 startHeight = Utils.Clamp(startHeight, 0f, 255f);
284 float bB = *(ptrB + 0); 220
285 float bG = *(ptrB + 1); 221 float heightRange = ImageUtils.Bilinear(
286 float bR = *(ptrB + 2); 222 heightRanges[0],
287 223 heightRanges[2],
288 float layerDiff = layer - l0; 224 heightRanges[1],
289 225 heightRanges[3],
290 // Interpolate between the two selected textures 226 pctX, pctY);
291 *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB)); 227 heightRange = Utils.Clamp(heightRange, 0f, 255f);
292 *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG)); 228
293 *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR)); 229 // Generate two frequencies of perlin noise based on our global position
230 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
231 Vector3 vec = new Vector3
232 (
233 ((float)regionPosition.X + x) * 0.20319f,
234 ((float)regionPosition.Y + y) * 0.20319f,
235 height * 0.25f
236 );
237
238 float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
239 float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
240 float noise = (lowFreq + highFreq) * 2f;
241
242 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
243 float layer = ((height + noise - startHeight) / heightRange) * 4f;
244 if (Single.IsNaN(layer)) layer = 0f;
245 layermap[y * 256 + x] = Utils.Clamp(layer, 0f, 3f);
294 } 246 }
295 } 247 }
296 248
249 #endregion Layer Map
250
251 #region Texture Compositing
252
253 output = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
254 outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
255
256 unsafe
257 {
258 // Get handles to all of the texture data arrays
259 BitmapData[] datas = new BitmapData[]
260 {
261 detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
262 detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
263 detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
264 detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
265 };
266
267 int[] comps = new int[]
268 {
269 (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
270 (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
271 (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
272 (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
273 };
274
275 for (int y = 0; y < 256; y++)
276 {
277 for (int x = 0; x < 256; x++)
278 {
279 float layer = layermap[y * 256 + x];
280
281 // Select two textures
282 int l0 = (int)Math.Floor(layer);
283 int l1 = Math.Min(l0 + 1, 3);
284
285 byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0];
286 byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1];
287 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
288
289 float aB = *(ptrA + 0);
290 float aG = *(ptrA + 1);
291 float aR = *(ptrA + 2);
292
293 float bB = *(ptrB + 0);
294 float bG = *(ptrB + 1);
295 float bR = *(ptrB + 2);
296
297 float layerDiff = layer - l0;
298
299 // Interpolate between the two selected textures
300 *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
301 *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
302 *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
303 }
304 }
305
306 for (int i = 0; i < 4; i++)
307 detailTexture[i].UnlockBits(datas[i]);
308 }
309 }
310 finally
311 {
297 for (int i = 0; i < 4; i++) 312 for (int i = 0; i < 4; i++)
298 detailTexture[i].UnlockBits(datas[i]); 313 if (detailTexture[i] != null)
314 detailTexture[i].Dispose();
299 } 315 }
300 316
301 output.UnlockBits(outputData); 317 output.UnlockBits(outputData);
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
index e6f2855..3c48d07 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
@@ -54,8 +54,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
54 private static readonly UUID TEXTURE_METADATA_MAGIC = new UUID("802dc0e0-f080-4931-8b57-d1be8611c4f3"); 54 private static readonly UUID TEXTURE_METADATA_MAGIC = new UUID("802dc0e0-f080-4931-8b57-d1be8611c4f3");
55 private static readonly Color4 WATER_COLOR = new Color4(29, 72, 96, 216); 55 private static readonly Color4 WATER_COLOR = new Color4(29, 72, 96, 216);
56 56
57 private static readonly ILog m_log = 57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 58
60 private Scene m_scene; 59 private Scene m_scene;
61 private IRendering m_primMesher; 60 private IRendering m_primMesher;
@@ -164,7 +163,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
164 } 163 }
165 catch 164 catch
166 { 165 {
167 m_log.Warn("[MAPTILE]: Failed to load StartupConfig"); 166 m_log.Warn("[WARP 3D IMAGE MODULE]: Failed to load StartupConfig");
168 } 167 }
169 168
170 m_colors.Clear(); 169 m_colors.Clear();
@@ -218,7 +217,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
218 Bitmap bitmap = renderer.Scene.getImage(); 217 Bitmap bitmap = renderer.Scene.getImage();
219 218
220 if (m_useAntiAliasing) 219 if (m_useAntiAliasing)
221 bitmap = ImageUtils.ResizeImage(bitmap, viewport.Width, viewport.Height); 220 {
221 using (Bitmap origBitmap = bitmap)
222 bitmap = ImageUtils.ResizeImage(origBitmap, viewport.Width, viewport.Height);
223 }
222 224
223 return bitmap; 225 return bitmap;
224 } 226 }
@@ -233,7 +235,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
233 catch (Exception e) 235 catch (Exception e)
234 { 236 {
235 // JPEG2000 encoder failed 237 // JPEG2000 encoder failed
236 m_log.Error("[MAPTILE]: Failed generating terrain map: " + e); 238 m_log.Error("[WARP 3D IMAGE MODULE]: Failed generating terrain map: ", e);
237 } 239 }
238 240
239 return null; 241 return null;
@@ -332,8 +334,17 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
332 uint globalX, globalY; 334 uint globalX, globalY;
333 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); 335 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);
334 336
335 Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); 337 warp_Texture texture;
336 warp_Texture texture = new warp_Texture(image); 338
339 using (
340 Bitmap image
341 = TerrainSplat.Splat(
342 heightmap, textureIDs, startHeights, heightRanges,
343 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
344 {
345 texture = new warp_Texture(image);
346 }
347
337 warp_Material material = new warp_Material(texture); 348 warp_Material material = new warp_Material(texture);
338 material.setReflectivity(50); 349 material.setReflectivity(50);
339 renderer.Scene.addMaterial("TerrainColor", material); 350 renderer.Scene.addMaterial("TerrainColor", material);
@@ -560,42 +571,46 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
560 { 571 {
561 try 572 try
562 { 573 {
563 Bitmap bitmap = (Bitmap)J2kImage.FromStream(stream); 574 int pixelBytes;
564 width = bitmap.Width;
565 height = bitmap.Height;
566 575
567 BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); 576 using (Bitmap bitmap = (Bitmap)J2kImage.FromStream(stream))
568 int pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
569
570 // Sum up the individual channels
571 unsafe
572 { 577 {
573 if (pixelBytes == 4) 578 width = bitmap.Width;
579 height = bitmap.Height;
580
581 BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
582 pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
583
584 // Sum up the individual channels
585 unsafe
574 { 586 {
575 for (int y = 0; y < height; y++) 587 if (pixelBytes == 4)
576 { 588 {
577 byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); 589 for (int y = 0; y < height; y++)
578
579 for (int x = 0; x < width; x++)
580 { 590 {
581 b += row[x * pixelBytes + 0]; 591 byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
582 g += row[x * pixelBytes + 1]; 592
583 r += row[x * pixelBytes + 2]; 593 for (int x = 0; x < width; x++)
584 a += row[x * pixelBytes + 3]; 594 {
595 b += row[x * pixelBytes + 0];
596 g += row[x * pixelBytes + 1];
597 r += row[x * pixelBytes + 2];
598 a += row[x * pixelBytes + 3];
599 }
585 } 600 }
586 } 601 }
587 } 602 else
588 else
589 {
590 for (int y = 0; y < height; y++)
591 { 603 {
592 byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); 604 for (int y = 0; y < height; y++)
593
594 for (int x = 0; x < width; x++)
595 { 605 {
596 b += row[x * pixelBytes + 0]; 606 byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
597 g += row[x * pixelBytes + 1]; 607
598 r += row[x * pixelBytes + 2]; 608 for (int x = 0; x < width; x++)
609 {
610 b += row[x * pixelBytes + 0];
611 g += row[x * pixelBytes + 1];
612 r += row[x * pixelBytes + 2];
613 }
599 } 614 }
600 } 615 }
601 } 616 }
@@ -617,7 +632,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
617 } 632 }
618 catch (Exception ex) 633 catch (Exception ex)
619 { 634 {
620 m_log.WarnFormat("[MAPTILE]: Error decoding JPEG2000 texture {0} ({1} bytes): {2}", textureID, j2kData.Length, ex.Message); 635 m_log.WarnFormat(
636 "[WARP 3D IMAGE MODULE]: Error decoding JPEG2000 texture {0} ({1} bytes): {2}",
637 textureID, j2kData.Length, ex.Message);
638
621 width = 0; 639 width = 0;
622 height = 0; 640 height = 0;
623 return new Color4(0.5f, 0.5f, 0.5f, 1.0f); 641 return new Color4(0.5f, 0.5f, 0.5f, 1.0f);
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index 899e5ea..724bb4c 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -190,14 +190,15 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
190 { 190 {
191 //m_log.DebugFormat("[WORLD MAP]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 191 //m_log.DebugFormat("[WORLD MAP]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
192 string capsBase = "/CAPS/" + caps.CapsObjectPath; 192 string capsBase = "/CAPS/" + caps.CapsObjectPath;
193 caps.RegisterHandler("MapLayer", 193 caps.RegisterHandler(
194 new RestStreamHandler("POST", capsBase + m_mapLayerPath, 194 "MapLayer",
195 delegate(string request, string path, string param, 195 new RestStreamHandler(
196 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 196 "POST",
197 { 197 capsBase + m_mapLayerPath,
198 return MapLayerRequest(request, path, param, 198 (request, path, param, httpRequest, httpResponse)
199 agentID, caps); 199 => MapLayerRequest(request, path, param, agentID, caps),
200 })); 200 "MapLayer",
201 agentID.ToString()));
201 } 202 }
202 203
203 /// <summary> 204 /// <summary>
@@ -1342,14 +1343,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1342 if (terrain == null) 1343 if (terrain == null)
1343 return; 1344 return;
1344 1345
1346 m_log.DebugFormat("[WORLDMAP]: Generating map image for {0}", m_scene.RegionInfo.RegionName);
1347
1345 byte[] data = terrain.WriteJpeg2000Image(); 1348 byte[] data = terrain.WriteJpeg2000Image();
1346 if (data == null) 1349 if (data == null)
1347 return; 1350 return;
1348 1351
1349 byte[] overlay = GenerateOverlay(); 1352 byte[] overlay = GenerateOverlay();
1350 1353
1351 m_log.Debug("[WORLDMAP]: STORING MAPTILE IMAGE");
1352
1353 UUID terrainImageID = UUID.Random(); 1354 UUID terrainImageID = UUID.Random();
1354 UUID parcelImageID = UUID.Zero; 1355 UUID parcelImageID = UUID.Zero;
1355 1356
@@ -1364,7 +1365,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1364 asset.Flags = AssetFlags.Maptile; 1365 asset.Flags = AssetFlags.Maptile;
1365 1366
1366 // Store the new one 1367 // Store the new one
1367 m_log.DebugFormat("[WORLDMAP]: Storing map tile {0}", asset.ID); 1368 m_log.DebugFormat("[WORLDMAP]: Storing map tile {0} for {1}", asset.ID, m_scene.RegionInfo.RegionName);
1369
1368 m_scene.AssetService.Store(asset); 1370 m_scene.AssetService.Store(asset);
1369 1371
1370 if (overlay != null) 1372 if (overlay != null)
diff --git a/OpenSim/Region/DataSnapshot/DataRequestHandler.cs b/OpenSim/Region/DataSnapshot/DataRequestHandler.cs
index 2f2b3e6..32e93b4 100644
--- a/OpenSim/Region/DataSnapshot/DataRequestHandler.cs
+++ b/OpenSim/Region/DataSnapshot/DataRequestHandler.cs
@@ -42,13 +42,13 @@ namespace OpenSim.Region.DataSnapshot
42{ 42{
43 public class DataRequestHandler 43 public class DataRequestHandler
44 { 44 {
45 private Scene m_scene = null; 45// private Scene m_scene = null;
46 private DataSnapshotManager m_externalData = null; 46 private DataSnapshotManager m_externalData = null;
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 public DataRequestHandler(Scene scene, DataSnapshotManager externalData) 49 public DataRequestHandler(Scene scene, DataSnapshotManager externalData)
50 { 50 {
51 m_scene = scene; 51// m_scene = scene;
52 m_externalData = externalData; 52 m_externalData = externalData;
53 53
54 //Register HTTP handler 54 //Register HTTP handler
diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
index 0516cb1..7446530 100644
--- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
@@ -37,6 +37,20 @@ namespace OpenSim.Region.Framework.Interfaces
37 public interface IAttachmentsModule 37 public interface IAttachmentsModule
38 { 38 {
39 /// <summary> 39 /// <summary>
40 /// Copy attachment data from a ScenePresence into the AgentData structure for transmission to another simulator
41 /// </summary>
42 /// <param name='sp'></param>
43 /// <param name='ad'></param>
44 void CopyAttachments(IScenePresence sp, AgentData ad);
45
46 /// <summary>
47 /// Copy attachment data from an AgentData structure into a ScenePresence.
48 /// </summary>
49 /// <param name='ad'></param>
50 /// <param name='sp'></param>
51 void CopyAttachments(AgentData ad, IScenePresence sp);
52
53 /// <summary>
40 /// RezAttachments. This should only be called upon login on the first region. 54 /// RezAttachments. This should only be called upon login on the first region.
41 /// Attachment rezzings on crossings and TPs are done in a different way. 55 /// Attachment rezzings on crossings and TPs are done in a different way.
42 /// </summary> 56 /// </summary>
@@ -44,10 +58,15 @@ namespace OpenSim.Region.Framework.Interfaces
44 void RezAttachments(IScenePresence sp); 58 void RezAttachments(IScenePresence sp);
45 59
46 /// <summary> 60 /// <summary>
47 /// Save the attachments that have change on this presence. 61 /// Derez the attachements for a scene presence that is closing.
48 /// </summary> 62 /// </summary>
49 /// <param name="sp"></param> 63 /// <remarks>
50 void SaveChangedAttachments(IScenePresence sp, bool saveAllScripted); 64 /// Attachment changes are saved.
65 /// </remarks>
66 /// <param name="sp">The presence closing</param>
67 /// <param name="saveChanged">Save changed attachments.</param>
68 /// <param name="saveAllScripted">Save attachments with scripts even if they haven't changed.</para>
69 void DeRezAttachments(IScenePresence sp, bool saveChanged, bool saveAllScripted);
51 70
52 /// <summary> 71 /// <summary>
53 /// Delete all the presence's attachments from the scene 72 /// Delete all the presence's attachments from the scene
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
index 32f4eea..4f0e100 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
@@ -81,7 +81,12 @@ namespace OpenSim.Region.Framework.Interfaces
81 /// <summary> 81 /// <summary>
82 /// Start all the scripts contained in this entity's inventory 82 /// Start all the scripts contained in this entity's inventory
83 /// </summary> 83 /// </summary>
84 void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource); 84 /// <param name="startParam"></param>
85 /// <param name="postOnRez"></param>
86 /// <param name="engine"></param>
87 /// <param name="stateSource"></param>
88 /// <returns>Number of scripts started.</returns>
89 int CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource);
85 90
86 ArrayList GetScriptErrors(UUID itemID); 91 ArrayList GetScriptErrors(UUID itemID);
87 void ResumeScripts(); 92 void ResumeScripts();
@@ -102,7 +107,11 @@ namespace OpenSim.Region.Framework.Interfaces
102 /// <param name="postOnRez"></param> 107 /// <param name="postOnRez"></param>
103 /// <param name="engine"></param> 108 /// <param name="engine"></param>
104 /// <param name="stateSource"></param> 109 /// <param name="stateSource"></param>
105 void CreateScriptInstance( 110 /// <returns>
111 /// true if the script instance was valid for starting, false otherwise. This does not guarantee
112 /// that the script was actually started, just that the script was valid (i.e. its asset data could be found, etc.)
113 /// </returns>
114 bool CreateScriptInstance(
106 TaskInventoryItem item, int startParam, bool postOnRez, string engine, int stateSource); 115 TaskInventoryItem item, int startParam, bool postOnRez, string engine, int stateSource);
107 116
108 /// <summary> 117 /// <summary>
@@ -113,7 +122,11 @@ namespace OpenSim.Region.Framework.Interfaces
113 /// <param name="postOnRez"></param> 122 /// <param name="postOnRez"></param>
114 /// <param name="engine"></param> 123 /// <param name="engine"></param>
115 /// <param name="stateSource"></param> 124 /// <param name="stateSource"></param>
116 void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource); 125 /// <returns>
126 /// true if the script instance was valid for starting, false otherwise. This does not guarantee
127 /// that the script was actually started, just that the script was valid (i.e. its asset data could be found, etc.)
128 /// </returns>
129 bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
117 130
118 ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource); 131 ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
119 132
@@ -166,6 +179,19 @@ namespace OpenSim.Region.Framework.Interfaces
166 List<TaskInventoryItem> GetInventoryItems(); 179 List<TaskInventoryItem> GetInventoryItems();
167 180
168 /// <summary> 181 /// <summary>
182 /// Gets an inventory item by name
183 /// </summary>
184 /// <remarks>
185 /// This method returns the first inventory item that matches the given name. In SL this is all you need
186 /// since each item in a prim inventory must have a unique name.
187 /// </remarks>
188 /// <param name='name'></param>
189 /// <returns>
190 /// The inventory item. Null if no such item was found.
191 /// </returns>
192 TaskInventoryItem GetInventoryItem(string name);
193
194 /// <summary>
169 /// Get inventory items by name. 195 /// Get inventory items by name.
170 /// </summary> 196 /// </summary>
171 /// <param name="name"></param> 197 /// <param name="name"></param>
@@ -174,7 +200,17 @@ namespace OpenSim.Region.Framework.Interfaces
174 /// If no inventory item has that name then an empty list is returned. 200 /// If no inventory item has that name then an empty list is returned.
175 /// </returns> 201 /// </returns>
176 List<TaskInventoryItem> GetInventoryItems(string name); 202 List<TaskInventoryItem> GetInventoryItems(string name);
177 203
204 /// <summary>
205 /// Get inventory items by type.
206 /// </summary>
207 /// <param type="name"></param>
208 /// <returns>
209 /// A list of inventory items of that type.
210 /// If no inventory items of that type then an empty list is returned.
211 /// </returns>
212 List<TaskInventoryItem> GetInventoryItems(InventoryType type);
213
178 /// <summary> 214 /// <summary>
179 /// Get the scene object referenced by an inventory item. 215 /// Get the scene object referenced by an inventory item.
180 /// </summary> 216 /// </summary>
@@ -228,6 +264,16 @@ namespace OpenSim.Region.Framework.Interfaces
228 bool ContainsScripts(); 264 bool ContainsScripts();
229 265
230 /// <summary> 266 /// <summary>
267 /// Returns the count of scripts contained
268 /// </summary></returns>
269 int ScriptCount();
270
271 /// <summary>
272 /// Returns the count of running scripts contained
273 /// </summary></returns>
274 int RunningScriptCount();
275
276 /// <summary>
231 /// Get the uuids of all items in this inventory 277 /// Get the uuids of all items in this inventory
232 /// </summary> 278 /// </summary>
233 /// <returns></returns> 279 /// <returns></returns>
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
index 76f1641..5bc8e51 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
@@ -39,13 +39,30 @@ namespace OpenSim.Region.Framework.Interfaces
39 39
40 public interface IEntityTransferModule 40 public interface IEntityTransferModule
41 { 41 {
42 void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, 42 /// <summary>
43 Vector3 lookAt, uint teleportFlags); 43 /// Teleport an agent within the same or to a different region.
44 /// </summary>
45 /// <param name='agent'></param>
46 /// <param name='regionHandle'>
47 /// The handle of the destination region. If it's the same as the region currently
48 /// occupied by the agent then the teleport will be within that region.
49 /// </param>
50 /// <param name='position'></param>
51 /// <param name='lookAt'></param>
52 /// <param name='teleportFlags'></param>
53 void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags);
44 54
45 bool TeleportHome(UUID id, IClientAPI client); 55 bool TeleportHome(UUID id, IClientAPI client);
46 56
47 void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, 57 void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination,
48 Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq); 58 Vector3 position, Vector3 lookAt, uint teleportFlags);
59
60 /// <summary>
61 /// Show whether the given agent is being teleported.
62 /// </summary>
63 /// <param name='id'>The agent ID</para></param>
64 /// <returns>true if the agent is in the process of being teleported, false otherwise.</returns>
65 bool IsInTransit(UUID id);
49 66
50 bool Cross(ScenePresence agent, bool isFlying); 67 bool Cross(ScenePresence agent, bool isFlying);
51 68
diff --git a/OpenSim/Region/Framework/Interfaces/IEnvironmentModule.cs b/OpenSim/Region/Framework/Interfaces/IEnvironmentModule.cs
new file mode 100644
index 0000000..7a7b782
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IEnvironmentModule.cs
@@ -0,0 +1,36 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenMetaverse;
29
30namespace OpenSim.Region.Framework.Interfaces
31{
32 public interface IEnvironmentModule
33 {
34 void ResetEnvironmentSettings(UUID regionUUID);
35 }
36}
diff --git a/OpenSim/Region/Framework/Interfaces/IEstateModule.cs b/OpenSim/Region/Framework/Interfaces/IEstateModule.cs
index 72e79ed..ca2ad94 100644
--- a/OpenSim/Region/Framework/Interfaces/IEstateModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEstateModule.cs
@@ -47,5 +47,8 @@ namespace OpenSim.Region.Framework.Interfaces
47 void sendRegionHandshakeToAll(); 47 void sendRegionHandshakeToAll();
48 void TriggerEstateInfoChange(); 48 void TriggerEstateInfoChange();
49 void TriggerRegionInfoChange(); 49 void TriggerRegionInfoChange();
50
51 void setEstateTerrainBaseTexture(int level, UUID texture);
52 void setEstateTerrainTextureHeights(int corner, float lowValue, float highValue);
50 } 53 }
51} 54}
diff --git a/OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs b/OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs
index 1904011..3576e35 100644
--- a/OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs
@@ -49,11 +49,15 @@ namespace OpenSim.Region.Framework.Interfaces
49 /// <param name="folderID"></param> 49 /// <param name="folderID"></param>
50 /// <param name="objectGroups"></param> 50 /// <param name="objectGroups"></param>
51 /// <param name="remoteClient"></param> 51 /// <param name="remoteClient"></param>
52 /// <param name="asAttachment">
53 /// Should be true if the object(s) are begin taken as attachments. False otherwise.
54 /// </param>
52 /// <returns> 55 /// <returns>
53 /// Returns the UUID of the newly created item asset (not the item itself). 56 /// A list of the items created. If there was more than one object and objects are not being coaleseced in
54 /// FIXME: This is not very useful. It would be far more useful to return a list of items instead. 57 /// inventory, then the order of items is in the same order as the input objects.
55 /// </returns> 58 /// </returns>
56 UUID CopyToInventory(DeRezAction action, UUID folderID, List<SceneObjectGroup> objectGroups, IClientAPI remoteClient); 59 List<InventoryItemBase> CopyToInventory(
60 DeRezAction action, UUID folderID, List<SceneObjectGroup> objectGroups, IClientAPI remoteClient, bool asAttachment);
57 61
58 /// <summary> 62 /// <summary>
59 /// Rez an object into the scene from the user's inventory 63 /// Rez an object into the scene from the user's inventory
diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
new file mode 100644
index 0000000..baac6e8
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
@@ -0,0 +1,48 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using OpenMetaverse;
31
32namespace OpenSim.Region.Framework.Interfaces
33{
34 public delegate void TakeValueCallback(string s);
35
36 public interface IJsonStoreModule
37 {
38 bool CreateStore(string value, out UUID result);
39 bool DestroyStore(UUID storeID);
40 bool TestPath(UUID storeID, string path, bool useJson);
41 bool SetValue(UUID storeID, string path, string value, bool useJson);
42 bool RemoveValue(UUID storeID, string path);
43 bool GetValue(UUID storeID, string path, bool useJson, out string value);
44
45 void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback);
46 void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback);
47 }
48}
diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs
index dc3ff89..860483d 100644
--- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs
@@ -113,9 +113,11 @@ namespace OpenSim.Region.Framework.Interfaces
113 /// </param> 113 /// </param>
114 /// <param name="landAtTarget"> 114 /// <param name="landAtTarget">
115 /// If true and the avatar is flying when it reaches the target, land. 115 /// If true and the avatar is flying when it reaches the target, land.
116 /// </param> 116 /// </param> name="running">
117 /// If true, NPC moves with running speed.
117 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns> 118 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
118 bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget); 119 ///
120 bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running);
119 121
120 /// <summary> 122 /// <summary>
121 /// Stop the NPC's current movement. 123 /// Stop the NPC's current movement.
@@ -135,6 +137,36 @@ namespace OpenSim.Region.Framework.Interfaces
135 bool Say(UUID agentID, Scene scene, string text); 137 bool Say(UUID agentID, Scene scene, string text);
136 138
137 /// <summary> 139 /// <summary>
140 /// Get the NPC to say something.
141 /// </summary>
142 /// <param name="agentID">The UUID of the NPC</param>
143 /// <param name="scene"></param>
144 /// <param name="text"></param>
145 /// <param name="channel"></param>
146 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
147 bool Say(UUID agentID, Scene scene, string text, int channel);
148
149 /// <summary>
150 /// Get the NPC to shout something.
151 /// </summary>
152 /// <param name="agentID">The UUID of the NPC</param>
153 /// <param name="scene"></param>
154 /// <param name="text"></param>
155 /// <param name="channel"></param>
156 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
157 bool Shout(UUID agentID, Scene scene, string text, int channel);
158
159 /// <summary>
160 /// Get the NPC to whisper something.
161 /// </summary>
162 /// <param name="agentID">The UUID of the NPC</param>
163 /// <param name="scene"></param>
164 /// <param name="text"></param>
165 /// <param name="channel"></param>
166 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
167 bool Whisper(UUID agentID, Scene scene, string text, int channel);
168
169 /// <summary>
138 /// Sit the NPC. 170 /// Sit the NPC.
139 /// </summary> 171 /// </summary>
140 /// <param name="agentID"></param> 172 /// <param name="agentID"></param>
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionCombinerModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionCombinerModule.cs
new file mode 100644
index 0000000..e03ac5a
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IRegionCombinerModule.cs
@@ -0,0 +1,59 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Text;
32using OpenSim.Region.Framework.Scenes;
33using System.IO;
34using OpenMetaverse;
35
36namespace OpenSim.Region.Framework.Interfaces
37{
38 public interface IRegionCombinerModule
39 {
40 /// <summary>
41 /// Does the given id belong to the root region of a megaregion?
42 /// </summary>
43 bool IsRootForMegaregion(UUID regionId);
44
45 /// <summary>
46 /// Gets the size of megaregion.
47 /// </summary>
48 /// <remarks>
49 /// Returns size in meters.
50 /// Do not rely on this method remaining the same - this area is actively under development.
51 /// </remarks>
52 /// <param name="sceneId">
53 /// The id of the root region for a megaregion.
54 /// This may change in the future to allow any region id that makes up a megaregion.
55 /// Currently, will throw an exception if this does not match a root region.
56 /// </param>
57 Vector2 GetSizeOfMegaregion(UUID regionId);
58 }
59} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Interfaces/IScenePresence.cs b/OpenSim/Region/Framework/Interfaces/IScenePresence.cs
index 5e43843..19a8236 100644
--- a/OpenSim/Region/Framework/Interfaces/IScenePresence.cs
+++ b/OpenSim/Region/Framework/Interfaces/IScenePresence.cs
@@ -41,6 +41,12 @@ namespace OpenSim.Region.Framework.Interfaces
41 public interface IScenePresence : ISceneAgent 41 public interface IScenePresence : ISceneAgent
42 { 42 {
43 /// <summary> 43 /// <summary>
44 /// Copy of the script states while the agent is in transit. This state may
45 /// need to be placed back in case of transfer fail.
46 /// </summary>
47 List<string> InTransitScriptStates { get; }
48
49 /// <summary>
44 /// The AttachmentsModule synchronizes on this to avoid race conditions between commands to add and remove attachments. 50 /// The AttachmentsModule synchronizes on this to avoid race conditions between commands to add and remove attachments.
45 /// </summary> 51 /// </summary>
46 /// <remarks> 52 /// <remarks>
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
index ce66100..42dbedc 100644
--- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
@@ -71,6 +71,14 @@ namespace OpenSim.Region.Framework.Interfaces
71 71
72 bool HasScript(UUID itemID, out bool running); 72 bool HasScript(UUID itemID, out bool running);
73 73
74 /// <summary>
75 /// Returns true if a script is running.
76 /// </summary>
77 /// <param name="itemID">The item ID of the script.</param>
78 bool GetScriptState(UUID itemID);
79
80 void SetRunEnable(UUID instanceID, bool enable);
81
74 void SaveAllState(); 82 void SaveAllState();
75 83
76 /// <summary> 84 /// <summary>
@@ -79,6 +87,14 @@ namespace OpenSim.Region.Framework.Interfaces
79 void StartProcessing(); 87 void StartProcessing();
80 88
81 /// <summary> 89 /// <summary>
90 /// Get the execution times of all scripts in the given array if they are currently running.
91 /// </summary>
92 /// <returns>
93 /// A float the value is a representative execution time in milliseconds of all scripts in that Array.
94 /// </returns>
95 float GetScriptExecutionTime(List<UUID> itemIDs);
96
97 /// <summary>
82 /// Get the execution times of all scripts in each object. 98 /// Get the execution times of all scripts in each object.
83 /// </summary> 99 /// </summary>
84 /// <returns> 100 /// <returns>
@@ -87,4 +103,4 @@ namespace OpenSim.Region.Framework.Interfaces
87 /// </returns> 103 /// </returns>
88 Dictionary<uint, float> GetObjectScriptsExecutionTimes(); 104 Dictionary<uint, float> GetObjectScriptsExecutionTimes();
89 } 105 }
90} \ No newline at end of file 106}
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
index 5b69616..ccb583d 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
@@ -96,6 +96,26 @@ namespace OpenSim.Region.Framework.Interfaces
96 void StoreRegionWindlightSettings(RegionLightShareData wl); 96 void StoreRegionWindlightSettings(RegionLightShareData wl);
97 void RemoveRegionWindlightSettings(UUID regionID); 97 void RemoveRegionWindlightSettings(UUID regionID);
98 98
99 /// <summary>
100 /// Load Environment settings from region storage
101 /// </summary>
102 /// <param name="regionUUID">the region UUID</param>
103 /// <returns>LLSD string for viewer</returns>
104 string LoadRegionEnvironmentSettings(UUID regionUUID);
105
106 /// <summary>
107 /// Store Environment settings into region storage
108 /// </summary>
109 /// <param name="regionUUID">the region UUID</param>
110 /// <param name="settings">LLSD string from viewer</param>
111 void StoreRegionEnvironmentSettings(UUID regionUUID, string settings);
112
113 /// <summary>
114 /// Delete Environment settings from region storage
115 /// </summary>
116 /// <param name="regionUUID">the region UUID</param>
117 void RemoveRegionEnvironmentSettings(UUID regionUUID);
118
99 UUID[] GetObjectIDs(UUID regionID); 119 UUID[] GetObjectIDs(UUID regionID);
100 } 120 }
101} 121}
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
index b7d9cfa..d7c80f7 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
@@ -108,6 +108,26 @@ namespace OpenSim.Region.Framework.Interfaces
108 void RemoveRegionWindlightSettings(UUID regionID); 108 void RemoveRegionWindlightSettings(UUID regionID);
109 UUID[] GetObjectIDs(UUID regionID); 109 UUID[] GetObjectIDs(UUID regionID);
110 110
111 /// <summary>
112 /// Load Environment settings from region storage
113 /// </summary>
114 /// <param name="regionUUID">the region UUID</param>
115 /// <returns>LLSD string for viewer</returns>
116 string LoadRegionEnvironmentSettings(UUID regionUUID);
117
118 /// <summary>
119 /// Store Environment settings into region storage
120 /// </summary>
121 /// <param name="regionUUID">the region UUID</param>
122 /// <param name="settings">LLSD string from viewer</param>
123 void StoreRegionEnvironmentSettings(UUID regionUUID, string settings);
124
125 /// <summary>
126 /// Delete Environment settings from region storage
127 /// </summary>
128 /// <param name="regionUUID">the region UUID</param>
129 void RemoveRegionEnvironmentSettings(UUID regionUUID);
130
111 void Shutdown(); 131 void Shutdown();
112 } 132 }
113} 133}
diff --git a/OpenSim/Region/Framework/Interfaces/IUrlModule.cs b/OpenSim/Region/Framework/Interfaces/IUrlModule.cs
index 1b91166..457444c 100644
--- a/OpenSim/Region/Framework/Interfaces/IUrlModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IUrlModule.cs
@@ -34,6 +34,7 @@ namespace OpenSim.Region.Framework.Interfaces
34{ 34{
35 public interface IUrlModule 35 public interface IUrlModule
36 { 36 {
37 string ExternalHostNameForLSL { get; }
37 UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID); 38 UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID);
38 UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID); 39 UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID);
39 void ReleaseURL(string url); 40 void ReleaseURL(string url);
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index e577958..9ddac19 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -294,6 +294,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
294 return "FALLDOWN"; 294 return "FALLDOWN";
295 } 295 }
296 296
297 // Check if the user has stopped walking just now
298 if (CurrentMovementAnimation == "WALK" && (move == Vector3.Zero))
299 return "STAND";
300
297 return CurrentMovementAnimation; 301 return CurrentMovementAnimation;
298 } 302 }
299 303
@@ -418,13 +422,16 @@ namespace OpenSim.Region.Framework.Scenes.Animation
418 /// </summary> 422 /// </summary>
419 public void UpdateMovementAnimations() 423 public void UpdateMovementAnimations()
420 { 424 {
421 CurrentMovementAnimation = DetermineMovementAnimation(); 425 lock (m_animations)
426 {
427 CurrentMovementAnimation = DetermineMovementAnimation();
422 428
423// m_log.DebugFormat( 429// m_log.DebugFormat(
424// "[SCENE PRESENCE ANIMATOR]: Determined animation {0} for {1} in UpdateMovementAnimations()", 430// "[SCENE PRESENCE ANIMATOR]: Determined animation {0} for {1} in UpdateMovementAnimations()",
425// CurrentMovementAnimation, m_scenePresence.Name); 431// CurrentMovementAnimation, m_scenePresence.Name);
426 432
427 TrySetMovementAnimation(CurrentMovementAnimation); 433 TrySetMovementAnimation(CurrentMovementAnimation);
434 }
428 } 435 }
429 436
430 public UUID[] GetAnimationArray() 437 public UUID[] GetAnimationArray()
diff --git a/OpenSim/Region/Framework/Scenes/AsyncInventorySender.cs b/OpenSim/Region/Framework/Scenes/AsyncInventorySender.cs
index 9cb5674..d9d2e64 100644
--- a/OpenSim/Region/Framework/Scenes/AsyncInventorySender.cs
+++ b/OpenSim/Region/Framework/Scenes/AsyncInventorySender.cs
@@ -137,7 +137,7 @@ namespace OpenSim.Region.Framework.Scenes
137 } 137 }
138 } 138 }
139 139
140 if (fh.Client.IsLoggingOut) 140 if (!fh.Client.IsActive)
141 continue; 141 continue;
142 142
143// m_log.DebugFormat( 143// m_log.DebugFormat(
diff --git a/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs b/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
index f678d07..f555b49 100644
--- a/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
+++ b/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
@@ -117,7 +117,7 @@ namespace OpenSim.Region.Framework.Scenes
117 117
118 private void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e) 118 private void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e)
119 { 119 {
120 m_log.Debug("[ASYNC DELETER]: Starting send to inventory loop"); 120// m_log.Debug("[ASYNC DELETER]: Starting send to inventory loop");
121 121
122 // We must set appearance parameters in the en_US culture in order to avoid issues where values are saved 122 // We must set appearance parameters in the en_US culture in order to avoid issues where values are saved
123 // in a culture where decimal points are commas and then reloaded in a culture which just treats them as 123 // in a culture where decimal points are commas and then reloaded in a culture which just treats them as
@@ -147,15 +147,15 @@ namespace OpenSim.Region.Framework.Scenes
147 { 147 {
148 x = m_inventoryDeletes.Dequeue(); 148 x = m_inventoryDeletes.Dequeue();
149 149
150 m_log.DebugFormat( 150// m_log.DebugFormat(
151 "[ASYNC DELETER]: Sending object to user's inventory, action {1}, count {2}, {0} item(s) remaining.", 151// "[ASYNC DELETER]: Sending object to user's inventory, action {1}, count {2}, {0} item(s) remaining.",
152 left, x.action, x.objectGroups.Count); 152// left, x.action, x.objectGroups.Count);
153 153
154 try 154 try
155 { 155 {
156 IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>(); 156 IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
157 if (invAccess != null) 157 if (invAccess != null)
158 invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient); 158 invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient, false);
159 159
160 if (x.permissionToDelete) 160 if (x.permissionToDelete)
161 { 161 {
@@ -185,7 +185,7 @@ namespace OpenSim.Region.Framework.Scenes
185 e.StackTrace); 185 e.StackTrace);
186 } 186 }
187 187
188 m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue."); 188// m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue.");
189 189
190 return false; 190 return false;
191 } 191 }
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 2365cfe..76a952b 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -53,6 +53,10 @@ namespace OpenSim.Region.Framework.Scenes
53 53
54 public event ClientMovement OnClientMovement; 54 public event ClientMovement OnClientMovement;
55 55
56 public delegate void OnTerrainTaintedDelegate();
57
58 public event OnTerrainTaintedDelegate OnTerrainTainted;
59
56 public delegate void OnTerrainTickDelegate(); 60 public delegate void OnTerrainTickDelegate();
57 61
58 public delegate void OnTerrainUpdateDelegate(); 62 public delegate void OnTerrainUpdateDelegate();
@@ -484,6 +488,9 @@ namespace OpenSim.Region.Framework.Scenes
484 public delegate void SceneObjectPartUpdated(SceneObjectPart sop); 488 public delegate void SceneObjectPartUpdated(SceneObjectPart sop);
485 public event SceneObjectPartUpdated OnSceneObjectPartUpdated; 489 public event SceneObjectPartUpdated OnSceneObjectPartUpdated;
486 490
491 public delegate void ScenePresenceUpdated(ScenePresence sp);
492 public event ScenePresenceUpdated OnScenePresenceUpdated;
493
487 public delegate void RegionUp(GridRegion region); 494 public delegate void RegionUp(GridRegion region);
488 public event RegionUp OnRegionUp; 495 public event RegionUp OnRegionUp;
489 496
@@ -935,6 +942,27 @@ namespace OpenSim.Region.Framework.Scenes
935 } 942 }
936 } 943 }
937 944
945 public void TriggerTerrainTainted()
946 {
947 OnTerrainTaintedDelegate handlerTerrainTainted = OnTerrainTainted;
948 if (handlerTerrainTainted != null)
949 {
950 foreach (OnTerrainTaintedDelegate d in handlerTerrainTainted.GetInvocationList())
951 {
952 try
953 {
954 d();
955 }
956 catch (Exception e)
957 {
958 m_log.ErrorFormat(
959 "[EVENT MANAGER]: Delegate for TriggerTerrainTainted failed - continuing. {0} {1}",
960 e.Message, e.StackTrace);
961 }
962 }
963 }
964 }
965
938 public void TriggerParcelPrimCountAdd(SceneObjectGroup obj) 966 public void TriggerParcelPrimCountAdd(SceneObjectGroup obj)
939 { 967 {
940 OnParcelPrimCountAddDelegate handlerParcelPrimCountAdd = OnParcelPrimCountAdd; 968 OnParcelPrimCountAddDelegate handlerParcelPrimCountAdd = OnParcelPrimCountAdd;
@@ -2367,6 +2395,27 @@ namespace OpenSim.Region.Framework.Scenes
2367 } 2395 }
2368 } 2396 }
2369 2397
2398 public void TriggerScenePresenceUpdated(ScenePresence sp)
2399 {
2400 ScenePresenceUpdated handler = OnScenePresenceUpdated;
2401 if (handler != null)
2402 {
2403 foreach (ScenePresenceUpdated d in handler.GetInvocationList())
2404 {
2405 try
2406 {
2407 d(sp);
2408 }
2409 catch (Exception e)
2410 {
2411 m_log.ErrorFormat(
2412 "[EVENT MANAGER]: Delegate for TriggerScenePresenceUpdated failed - continuing. {0} {1}",
2413 e.Message, e.StackTrace);
2414 }
2415 }
2416 }
2417 }
2418
2370 public void TriggerOnParcelPropertiesUpdateRequest(LandUpdateArgs args, 2419 public void TriggerOnParcelPropertiesUpdateRequest(LandUpdateArgs args,
2371 int local_id, IClientAPI remote_client) 2420 int local_id, IClientAPI remote_client)
2372 { 2421 {
diff --git a/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs b/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs
index 6c5685c..1365831 100644
--- a/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs
+++ b/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs
@@ -48,16 +48,19 @@ namespace OpenSim.Region.Framework.Scenes
48{ 48{
49 public class RegionStatsHandler : IStreamedRequestHandler 49 public class RegionStatsHandler : IStreamedRequestHandler
50 { 50 {
51 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
51 private string osRXStatsURI = String.Empty; 53 private string osRXStatsURI = String.Empty;
52 private string osXStatsURI = String.Empty; 54 private string osXStatsURI = String.Empty;
53 //private string osSecret = String.Empty; 55 //private string osSecret = String.Empty;
54 private OpenSim.Framework.RegionInfo regionInfo; 56 private OpenSim.Framework.RegionInfo regionInfo;
55 public string localZone = TimeZone.CurrentTimeZone.StandardName; 57 public string localZone = TimeZone.CurrentTimeZone.StandardName;
56 public TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); 58 public TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
57
58 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 59
60 public RegionStatsHandler(OpenSim.Framework.RegionInfo region_info) 60 public string Name { get { return "RegionStats"; } }
61 public string Description { get { return "Region Statistics"; } }
62
63 public RegionStatsHandler(RegionInfo region_info)
61 { 64 {
62 regionInfo = region_info; 65 regionInfo = region_info;
63 osRXStatsURI = Util.SHA1Hash(regionInfo.regionSecret); 66 osRXStatsURI = Util.SHA1Hash(regionInfo.regionSecret);
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 29465c0..9776a82 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -60,19 +60,32 @@ namespace OpenSim.Region.Framework.Scenes
60 /// <summary> 60 /// <summary>
61 /// Creates all the scripts in the scene which should be started. 61 /// Creates all the scripts in the scene which should be started.
62 /// </summary> 62 /// </summary>
63 public void CreateScriptInstances() 63 /// <returns>
64 /// Number of scripts that were valid for starting. This does not guarantee that all these scripts
65 /// were actually started, but just that the start could be attempt (e.g. the asset data for the script could be found)
66 /// </returns>
67 public int CreateScriptInstances()
64 { 68 {
65 m_log.Info("[PRIM INVENTORY]: Creating scripts in scene"); 69 m_log.InfoFormat("[SCENE]: Initializing script instances in {0}", RegionInfo.RegionName);
70
71 int scriptsValidForStarting = 0;
66 72
67 EntityBase[] entities = Entities.GetEntities(); 73 EntityBase[] entities = Entities.GetEntities();
68 foreach (EntityBase group in entities) 74 foreach (EntityBase group in entities)
69 { 75 {
70 if (group is SceneObjectGroup) 76 if (group is SceneObjectGroup)
71 { 77 {
72 ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0); 78 scriptsValidForStarting
79 += ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
73 ((SceneObjectGroup) group).ResumeScripts(); 80 ((SceneObjectGroup) group).ResumeScripts();
74 } 81 }
75 } 82 }
83
84 m_log.InfoFormat(
85 "[SCENE]: Initialized {0} script instances in {1}",
86 scriptsValidForStarting, RegionInfo.RegionName);
87
88 return scriptsValidForStarting;
76 } 89 }
77 90
78 /// <summary> 91 /// <summary>
@@ -80,7 +93,7 @@ namespace OpenSim.Region.Framework.Scenes
80 /// </summary> 93 /// </summary>
81 public void StartScripts() 94 public void StartScripts()
82 { 95 {
83 m_log.Info("[PRIM INVENTORY]: Starting scripts in scene"); 96 m_log.InfoFormat("[SCENE]: Starting scripts in {0}, please wait.", RegionInfo.RegionName);
84 97
85 IScriptModule[] engines = RequestModuleInterfaces<IScriptModule>(); 98 IScriptModule[] engines = RequestModuleInterfaces<IScriptModule>();
86 99
@@ -300,6 +313,10 @@ namespace OpenSim.Region.Framework.Scenes
300 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId); 313 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId);
301 AssetService.Store(asset); 314 AssetService.Store(asset);
302 315
316// m_log.DebugFormat(
317// "[PRIM INVENTORY]: Stored asset {0} when updating item {1} in prim {2} for {3}",
318// asset.ID, item.Name, part.Name, remoteClient.Name);
319
303 if (isScriptRunning) 320 if (isScriptRunning)
304 { 321 {
305 part.Inventory.RemoveScriptInstance(item.ItemID, false); 322 part.Inventory.RemoveScriptInstance(item.ItemID, false);
@@ -431,10 +448,9 @@ namespace OpenSim.Region.Framework.Scenes
431 } 448 }
432 else 449 else
433 { 450 {
434 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>(); 451 if (AgentTransactionsModule != null)
435 if (agentTransactions != null)
436 { 452 {
437 agentTransactions.HandleItemUpdateFromTransaction(remoteClient, transactionID, item); 453 AgentTransactionsModule.HandleItemUpdateFromTransaction(remoteClient, transactionID, item);
438 } 454 }
439 } 455 }
440 } 456 }
@@ -950,8 +966,8 @@ namespace OpenSim.Region.Framework.Scenes
950 sbyte invType, sbyte type, UUID olditemID) 966 sbyte invType, sbyte type, UUID olditemID)
951 { 967 {
952// m_log.DebugFormat( 968// m_log.DebugFormat(
953// "[AGENT INVENTORY]: Received request from {0} to create inventory item link {1} in folder {2} pointing to {3}", 969// "[AGENT INVENTORY]: Received request from {0} to create inventory item link {1} in folder {2} pointing to {3}, assetType {4}, inventoryType {5}",
954// remoteClient.Name, name, folderID, olditemID); 970// remoteClient.Name, name, folderID, olditemID, (AssetType)type, (InventoryType)invType);
955 971
956 if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId)) 972 if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
957 return; 973 return;
@@ -984,10 +1000,10 @@ namespace OpenSim.Region.Framework.Scenes
984 asset.Type = type; 1000 asset.Type = type;
985 asset.Name = name; 1001 asset.Name = name;
986 asset.Description = description; 1002 asset.Description = description;
987 1003
988 CreateNewInventoryItem( 1004 CreateNewInventoryItem(
989 remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID, name, 0, callbackID, asset, invType, 1005 remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID, name, 0, callbackID, asset, invType,
990 (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, 1006 (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All,
991 (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch()); 1007 (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch());
992 } 1008 }
993 else 1009 else
@@ -1562,21 +1578,17 @@ namespace OpenSim.Region.Framework.Scenes
1562 // Only look for an uploaded updated asset if we are passed a transaction ID. This is only the 1578 // Only look for an uploaded updated asset if we are passed a transaction ID. This is only the
1563 // case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update) 1579 // case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update)
1564 // will not pass in a transaction ID in the update message. 1580 // will not pass in a transaction ID in the update message.
1565 if (transactionID != UUID.Zero) 1581 if (transactionID != UUID.Zero && AgentTransactionsModule != null)
1566 { 1582 {
1567 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>(); 1583 AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
1568 if (agentTransactions != null) 1584 remoteClient, part, transactionID, currentItem);
1569 { 1585
1570 agentTransactions.HandleTaskItemUpdateFromTransaction( 1586// if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
1571 remoteClient, part, transactionID, currentItem); 1587// remoteClient.SendAgentAlertMessage("Notecard saved", false);
1572 1588// else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
1573// if ((InventoryType)itemInfo.InvType == InventoryType.Notecard) 1589// remoteClient.SendAgentAlertMessage("Script saved", false);
1574// remoteClient.SendAgentAlertMessage("Notecard saved", false); 1590// else
1575// else if ((InventoryType)itemInfo.InvType == InventoryType.LSL) 1591// remoteClient.SendAgentAlertMessage("Item saved", false);
1576// remoteClient.SendAgentAlertMessage("Script saved", false);
1577// else
1578// remoteClient.SendAgentAlertMessage("Item saved", false);
1579 }
1580 } 1592 }
1581 1593
1582 // Base ALWAYS has move 1594 // Base ALWAYS has move
@@ -2286,10 +2298,24 @@ namespace OpenSim.Region.Framework.Scenes
2286 if (part == null) 2298 if (part == null)
2287 return; 2299 return;
2288 2300
2301 IScriptModule[] engines = RequestModuleInterfaces<IScriptModule>();
2302
2289 if (running) 2303 if (running)
2304 {
2305 foreach (IScriptModule engine in engines)
2306 {
2307 engine.SetRunEnable(itemID, true);
2308 }
2290 EventManager.TriggerStartScript(part.LocalId, itemID); 2309 EventManager.TriggerStartScript(part.LocalId, itemID);
2310 }
2291 else 2311 else
2312 {
2313 foreach (IScriptModule engine in engines)
2314 {
2315 engine.SetRunEnable(itemID, false);
2316 }
2292 EventManager.TriggerStopScript(part.LocalId, itemID); 2317 EventManager.TriggerStopScript(part.LocalId, itemID);
2318 }
2293 } 2319 }
2294 2320
2295 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) 2321 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
index e1fedf4..535d87a 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
@@ -67,6 +67,7 @@ namespace OpenSim.Region.Framework.Scenes
67 public delegate bool RunConsoleCommandHandler(UUID user, Scene requestFromScene); 67 public delegate bool RunConsoleCommandHandler(UUID user, Scene requestFromScene);
68 public delegate bool IssueEstateCommandHandler(UUID user, Scene requestFromScene, bool ownerCommand); 68 public delegate bool IssueEstateCommandHandler(UUID user, Scene requestFromScene, bool ownerCommand);
69 public delegate bool IsGodHandler(UUID user, Scene requestFromScene); 69 public delegate bool IsGodHandler(UUID user, Scene requestFromScene);
70 public delegate bool IsGridGodHandler(UUID user, Scene requestFromScene);
70 public delegate bool IsAdministratorHandler(UUID user); 71 public delegate bool IsAdministratorHandler(UUID user);
71 public delegate bool EditParcelHandler(UUID user, ILandObject parcel, Scene scene); 72 public delegate bool EditParcelHandler(UUID user, ILandObject parcel, Scene scene);
72 public delegate bool EditParcelPropertiesHandler(UUID user, ILandObject parcel, GroupPowers p, Scene scene); 73 public delegate bool EditParcelPropertiesHandler(UUID user, ILandObject parcel, GroupPowers p, Scene scene);
@@ -134,6 +135,7 @@ namespace OpenSim.Region.Framework.Scenes
134 public event RunConsoleCommandHandler OnRunConsoleCommand; 135 public event RunConsoleCommandHandler OnRunConsoleCommand;
135 public event IssueEstateCommandHandler OnIssueEstateCommand; 136 public event IssueEstateCommandHandler OnIssueEstateCommand;
136 public event IsGodHandler OnIsGod; 137 public event IsGodHandler OnIsGod;
138 public event IsGridGodHandler OnIsGridGod;
137 public event IsAdministratorHandler OnIsAdministrator; 139 public event IsAdministratorHandler OnIsAdministrator;
138// public event EditParcelHandler OnEditParcel; 140// public event EditParcelHandler OnEditParcel;
139 public event EditParcelPropertiesHandler OnEditParcelProperties; 141 public event EditParcelPropertiesHandler OnEditParcelProperties;
@@ -728,6 +730,21 @@ namespace OpenSim.Region.Framework.Scenes
728 return true; 730 return true;
729 } 731 }
730 732
733 public bool IsGridGod(UUID user)
734 {
735 IsGridGodHandler handler = OnIsGridGod;
736 if (handler != null)
737 {
738 Delegate[] list = handler.GetInvocationList();
739 foreach (IsGridGodHandler h in list)
740 {
741 if (h(user, m_scene) == false)
742 return false;
743 }
744 }
745 return true;
746 }
747
731 public bool IsAdministrator(UUID user) 748 public bool IsAdministrator(UUID user)
732 { 749 {
733 IsAdministratorHandler handler = OnIsAdministrator; 750 IsAdministratorHandler handler = OnIsAdministrator;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 6a120c1..8591b09 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -77,7 +77,12 @@ namespace OpenSim.Region.Framework.Scenes
77 public bool DebugUpdates { get; private set; } 77 public bool DebugUpdates { get; private set; }
78 78
79 public SynchronizeSceneHandler SynchronizeScene; 79 public SynchronizeSceneHandler SynchronizeScene;
80 public SimStatsReporter StatsReporter; 80
81 /// <summary>
82 /// Statistical information for this scene.
83 /// </summary>
84 public SimStatsReporter StatsReporter { get; private set; }
85
81 public List<Border> NorthBorders = new List<Border>(); 86 public List<Border> NorthBorders = new List<Border>();
82 public List<Border> EastBorders = new List<Border>(); 87 public List<Border> EastBorders = new List<Border>();
83 public List<Border> SouthBorders = new List<Border>(); 88 public List<Border> SouthBorders = new List<Border>();
@@ -103,6 +108,7 @@ namespace OpenSim.Region.Framework.Scenes
103 public bool m_trustBinaries; 108 public bool m_trustBinaries;
104 public bool m_allowScriptCrossings; 109 public bool m_allowScriptCrossings;
105 public bool m_useFlySlow; 110 public bool m_useFlySlow;
111 public bool m_useTrashOnDelete = true;
106 112
107 /// <summary> 113 /// <summary>
108 /// Temporarily setting to trigger appearance resends at 60 second intervals. 114 /// Temporarily setting to trigger appearance resends at 60 second intervals.
@@ -163,7 +169,6 @@ namespace OpenSim.Region.Framework.Scenes
163 protected IConfigSource m_config; 169 protected IConfigSource m_config;
164 protected IRegionSerialiserModule m_serialiser; 170 protected IRegionSerialiserModule m_serialiser;
165 protected IDialogModule m_dialogModule; 171 protected IDialogModule m_dialogModule;
166 protected IEntityTransferModule m_teleportModule;
167 protected ICapabilitiesModule m_capsModule; 172 protected ICapabilitiesModule m_capsModule;
168 protected IGroupsModule m_groupsModule; 173 protected IGroupsModule m_groupsModule;
169 174
@@ -217,6 +222,7 @@ namespace OpenSim.Region.Framework.Scenes
217 private int backupMS; 222 private int backupMS;
218 private int terrainMS; 223 private int terrainMS;
219 private int landMS; 224 private int landMS;
225 private int spareMS;
220 226
221 /// <summary> 227 /// <summary>
222 /// Tick at which the last frame was processed. 228 /// Tick at which the last frame was processed.
@@ -458,6 +464,7 @@ namespace OpenSim.Region.Framework.Scenes
458 { 464 {
459 if (m_simulationService == null) 465 if (m_simulationService == null)
460 m_simulationService = RequestModuleInterface<ISimulationService>(); 466 m_simulationService = RequestModuleInterface<ISimulationService>();
467
461 return m_simulationService; 468 return m_simulationService;
462 } 469 }
463 } 470 }
@@ -513,6 +520,9 @@ namespace OpenSim.Region.Framework.Scenes
513 } 520 }
514 521
515 public IAttachmentsModule AttachmentsModule { get; set; } 522 public IAttachmentsModule AttachmentsModule { get; set; }
523 public IEntityTransferModule EntityTransferModule { get; private set; }
524 public IAgentAssetTransactions AgentTransactionsModule { get; private set; }
525 public IUserManagement UserManagementModule { get; private set; }
516 526
517 public IAvatarFactoryModule AvatarFactory 527 public IAvatarFactoryModule AvatarFactory
518 { 528 {
@@ -589,6 +599,20 @@ namespace OpenSim.Region.Framework.Scenes
589 get { return m_sceneGraph.Entities; } 599 get { return m_sceneGraph.Entities; }
590 } 600 }
591 601
602
603 // used in sequence see: SpawnPoint()
604 private int m_SpawnPoint;
605 // can be closest/random/sequence
606 public string SpawnPointRouting
607 {
608 get; private set;
609 }
610 // allow landmarks to pass
611 public bool TelehubAllowLandmarks
612 {
613 get; private set;
614 }
615
592 #endregion Properties 616 #endregion Properties
593 617
594 #region Constructors 618 #region Constructors
@@ -606,7 +630,7 @@ namespace OpenSim.Region.Framework.Scenes
606 630
607 Random random = new Random(); 631 Random random = new Random();
608 632
609 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4); 633 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4);
610 m_moduleLoader = moduleLoader; 634 m_moduleLoader = moduleLoader;
611 m_authenticateHandler = authen; 635 m_authenticateHandler = authen;
612 m_sceneGridService = sceneGridService; 636 m_sceneGridService = sceneGridService;
@@ -726,6 +750,9 @@ namespace OpenSim.Region.Framework.Scenes
726 m_maxPhys = RegionInfo.PhysPrimMax; 750 m_maxPhys = RegionInfo.PhysPrimMax;
727 } 751 }
728 752
753 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
754 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
755
729 // Here, if clamping is requested in either global or 756 // Here, if clamping is requested in either global or
730 // local config, it will be used 757 // local config, it will be used
731 // 758 //
@@ -735,6 +762,7 @@ namespace OpenSim.Region.Framework.Scenes
735 m_clampPrimSize = true; 762 m_clampPrimSize = true;
736 } 763 }
737 764
765 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
738 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 766 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
739 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 767 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
740 m_dontPersistBefore = 768 m_dontPersistBefore =
@@ -833,13 +861,11 @@ namespace OpenSim.Region.Framework.Scenes
833 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 861 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
834 } 862 }
835 863
836 /// <summary>
837 /// Mock constructor for scene group persistency unit tests.
838 /// SceneObjectGroup RegionId property is delegated to Scene.
839 /// </summary>
840 /// <param name="regInfo"></param>
841 public Scene(RegionInfo regInfo) 864 public Scene(RegionInfo regInfo)
842 { 865 {
866 PhysicalPrims = true;
867 CollidablePrims = true;
868
843 BordersLocked = true; 869 BordersLocked = true;
844 Border northBorder = new Border(); 870 Border northBorder = new Border();
845 northBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (int)Constants.RegionSize); //<--- 871 northBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, (int)Constants.RegionSize); //<---
@@ -866,8 +892,6 @@ namespace OpenSim.Region.Framework.Scenes
866 m_eventManager = new EventManager(); 892 m_eventManager = new EventManager();
867 893
868 m_permissions = new ScenePermissions(this); 894 m_permissions = new ScenePermissions(this);
869
870// m_lastUpdate = Util.EnvironmentTickCount();
871 } 895 }
872 896
873 #endregion 897 #endregion
@@ -936,8 +960,8 @@ namespace OpenSim.Region.Framework.Scenes
936 List<ulong> old = new List<ulong>(); 960 List<ulong> old = new List<ulong>();
937 old.Add(otherRegion.RegionHandle); 961 old.Add(otherRegion.RegionHandle);
938 agent.DropOldNeighbours(old); 962 agent.DropOldNeighbours(old);
939 if (m_teleportModule != null && agent.PresenceType != PresenceType.Npc) 963 if (EntityTransferModule != null && agent.PresenceType != PresenceType.Npc)
940 m_teleportModule.EnableChildAgent(agent, otherRegion); 964 EntityTransferModule.EnableChildAgent(agent, otherRegion);
941 }); 965 });
942 } 966 }
943 catch (NullReferenceException) 967 catch (NullReferenceException)
@@ -950,7 +974,7 @@ namespace OpenSim.Region.Framework.Scenes
950 else 974 else
951 { 975 {
952 m_log.InfoFormat( 976 m_log.InfoFormat(
953 "[INTERGRID]: Got notice about far away Region: {0} at ({1}, {2})", 977 "[SCENE]: Got notice about far away Region: {0} at ({1}, {2})",
954 otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY); 978 otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY);
955 } 979 }
956 } 980 }
@@ -1044,13 +1068,13 @@ namespace OpenSim.Region.Framework.Scenes
1044 } 1068 }
1045 } 1069 }
1046 1070
1071 m_log.Error("[REGION]: Closing");
1072 Close();
1073
1047 if (PhysicsScene != null) 1074 if (PhysicsScene != null)
1048 { 1075 {
1049 PhysicsScene.Dispose(); 1076 PhysicsScene.Dispose();
1050 } 1077 }
1051
1052 m_log.Error("[REGION]: Closing");
1053 Close();
1054 1078
1055 m_log.Error("[REGION]: Firing Region Restart Message"); 1079 m_log.Error("[REGION]: Firing Region Restart Message");
1056 1080
@@ -1074,8 +1098,8 @@ namespace OpenSim.Region.Framework.Scenes
1074 { 1098 {
1075 ForEachRootScenePresence(delegate(ScenePresence agent) 1099 ForEachRootScenePresence(delegate(ScenePresence agent)
1076 { 1100 {
1077 if (m_teleportModule != null && agent.PresenceType != PresenceType.Npc) 1101 if (EntityTransferModule != null && agent.PresenceType != PresenceType.Npc)
1078 m_teleportModule.EnableChildAgent(agent, r); 1102 EntityTransferModule.EnableChildAgent(agent, r);
1079 }); 1103 });
1080 } 1104 }
1081 catch (NullReferenceException) 1105 catch (NullReferenceException)
@@ -1265,8 +1289,10 @@ namespace OpenSim.Region.Framework.Scenes
1265 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>(); 1289 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>();
1266 m_dialogModule = RequestModuleInterface<IDialogModule>(); 1290 m_dialogModule = RequestModuleInterface<IDialogModule>();
1267 m_capsModule = RequestModuleInterface<ICapabilitiesModule>(); 1291 m_capsModule = RequestModuleInterface<ICapabilitiesModule>();
1268 m_teleportModule = RequestModuleInterface<IEntityTransferModule>(); 1292 EntityTransferModule = RequestModuleInterface<IEntityTransferModule>();
1269 m_groupsModule = RequestModuleInterface<IGroupsModule>(); 1293 m_groupsModule = RequestModuleInterface<IGroupsModule>();
1294 AgentTransactionsModule = RequestModuleInterface<IAgentAssetTransactions>();
1295 UserManagementModule = RequestModuleInterface<IUserManagement>();
1270 } 1296 }
1271 1297
1272 #endregion 1298 #endregion
@@ -1387,37 +1413,41 @@ namespace OpenSim.Region.Framework.Scenes
1387 endFrame = Frame + frames; 1413 endFrame = Frame + frames;
1388 1414
1389 float physicsFPS = 0f; 1415 float physicsFPS = 0f;
1390 int tmpPhysicsMS, tmpPhysicsMS2, tmpAgentMS, tmpTempOnRezMS, evMS, backMS, terMS; 1416 int previousFrameTick, tmpMS;
1391 int previousFrameTick; 1417 int maintc = Util.EnvironmentTickCount();
1392 int maintc;
1393 int sleepMS;
1394 int framestart;
1395 1418
1396 while (!m_shuttingDown && (endFrame == null || Frame < endFrame)) 1419 while (!m_shuttingDown && (endFrame == null || Frame < endFrame))
1397 { 1420 {
1398 framestart = Util.EnvironmentTickCount();
1399 ++Frame; 1421 ++Frame;
1400 1422
1401// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1423// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1402 1424
1403 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0; 1425 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0;
1404 1426
1405 try 1427 try
1406 { 1428 {
1407 tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1429 // Apply taints in terrain module to terrain in physics scene
1430 if (Frame % m_update_terrain == 0)
1431 {
1432 tmpMS = Util.EnvironmentTickCount();
1433 UpdateTerrain();
1434 terrainMS = Util.EnvironmentTickCountSubtract(tmpMS);
1435 }
1436
1437 tmpMS = Util.EnvironmentTickCount();
1408 if ((Frame % m_update_physics == 0) && m_physics_enabled) 1438 if ((Frame % m_update_physics == 0) && m_physics_enabled)
1409 m_sceneGraph.UpdatePreparePhysics(); 1439 m_sceneGraph.UpdatePreparePhysics();
1410 physicsMS2 = Util.EnvironmentTickCountSubtract(tmpPhysicsMS2); 1440 physicsMS2 = Util.EnvironmentTickCountSubtract(tmpMS);
1411 1441
1412 // Apply any pending avatar force input to the avatar's velocity 1442 // Apply any pending avatar force input to the avatar's velocity
1413 tmpAgentMS = Util.EnvironmentTickCount(); 1443 tmpMS = Util.EnvironmentTickCount();
1414 if (Frame % m_update_entitymovement == 0) 1444 if (Frame % m_update_entitymovement == 0)
1415 m_sceneGraph.UpdateScenePresenceMovement(); 1445 m_sceneGraph.UpdateScenePresenceMovement();
1416 agentMS = Util.EnvironmentTickCountSubtract(tmpAgentMS); 1446 agentMS = Util.EnvironmentTickCountSubtract(tmpMS);
1417 1447
1418 // Perform the main physics update. This will do the actual work of moving objects and avatars according to their 1448 // Perform the main physics update. This will do the actual work of moving objects and avatars according to their
1419 // velocity 1449 // velocity
1420 tmpPhysicsMS = Util.EnvironmentTickCount(); 1450 tmpMS = Util.EnvironmentTickCount();
1421 if (Frame % m_update_physics == 0) 1451 if (Frame % m_update_physics == 0)
1422 { 1452 {
1423 if (m_physics_enabled) 1453 if (m_physics_enabled)
@@ -1426,9 +1456,9 @@ namespace OpenSim.Region.Framework.Scenes
1426 if (SynchronizeScene != null) 1456 if (SynchronizeScene != null)
1427 SynchronizeScene(this); 1457 SynchronizeScene(this);
1428 } 1458 }
1429 physicsMS = Util.EnvironmentTickCountSubtract(tmpPhysicsMS); 1459 physicsMS = Util.EnvironmentTickCountSubtract(tmpMS);
1430 1460
1431 tmpAgentMS = Util.EnvironmentTickCount(); 1461 tmpMS = Util.EnvironmentTickCount();
1432 1462
1433 // Check if any objects have reached their targets 1463 // Check if any objects have reached their targets
1434 CheckAtTargets(); 1464 CheckAtTargets();
@@ -1443,36 +1473,29 @@ namespace OpenSim.Region.Framework.Scenes
1443 if (Frame % m_update_presences == 0) 1473 if (Frame % m_update_presences == 0)
1444 m_sceneGraph.UpdatePresences(); 1474 m_sceneGraph.UpdatePresences();
1445 1475
1446 agentMS += Util.EnvironmentTickCountSubtract(tmpAgentMS); 1476 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1447 1477
1448 // Delete temp-on-rez stuff 1478 // Delete temp-on-rez stuff
1449 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) 1479 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
1450 { 1480 {
1451 tmpTempOnRezMS = Util.EnvironmentTickCount(); 1481 tmpMS = Util.EnvironmentTickCount();
1452 m_cleaningTemps = true; 1482 m_cleaningTemps = true;
1453 Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; }); 1483 Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; });
1454 tempOnRezMS = Util.EnvironmentTickCountSubtract(tmpTempOnRezMS); 1484 tempOnRezMS = Util.EnvironmentTickCountSubtract(tmpMS);
1455 } 1485 }
1456 1486
1457 if (Frame % m_update_events == 0) 1487 if (Frame % m_update_events == 0)
1458 { 1488 {
1459 evMS = Util.EnvironmentTickCount(); 1489 tmpMS = Util.EnvironmentTickCount();
1460 UpdateEvents(); 1490 UpdateEvents();
1461 eventMS = Util.EnvironmentTickCountSubtract(evMS); 1491 eventMS = Util.EnvironmentTickCountSubtract(tmpMS);
1462 } 1492 }
1463 1493
1464 if (Frame % m_update_backup == 0) 1494 if (Frame % m_update_backup == 0)
1465 { 1495 {
1466 backMS = Util.EnvironmentTickCount(); 1496 tmpMS = Util.EnvironmentTickCount();
1467 UpdateStorageBackup(); 1497 UpdateStorageBackup();
1468 backupMS = Util.EnvironmentTickCountSubtract(backMS); 1498 backupMS = Util.EnvironmentTickCountSubtract(tmpMS);
1469 }
1470
1471 if (Frame % m_update_terrain == 0)
1472 {
1473 terMS = Util.EnvironmentTickCount();
1474 UpdateTerrain();
1475 terrainMS = Util.EnvironmentTickCountSubtract(terMS);
1476 } 1499 }
1477 1500
1478 //if (Frame % m_update_land == 0) 1501 //if (Frame % m_update_land == 0)
@@ -1481,29 +1504,6 @@ namespace OpenSim.Region.Framework.Scenes
1481 // UpdateLand(); 1504 // UpdateLand();
1482 // landMS = Util.EnvironmentTickCountSubtract(ldMS); 1505 // landMS = Util.EnvironmentTickCountSubtract(ldMS);
1483 //} 1506 //}
1484
1485 // frameMS = Util.EnvironmentTickCountSubtract(maintc);
1486 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1487
1488 // if (Frame%m_update_avatars == 0)
1489 // UpdateInWorldTime();
1490 StatsReporter.AddPhysicsFPS(physicsFPS);
1491 StatsReporter.AddTimeDilation(TimeDilation);
1492 StatsReporter.AddFPS(1);
1493 StatsReporter.SetRootAgents(m_sceneGraph.GetRootAgentCount());
1494 StatsReporter.SetChildAgents(m_sceneGraph.GetChildAgentCount());
1495 StatsReporter.SetObjects(m_sceneGraph.GetTotalObjectsCount());
1496 StatsReporter.SetActiveObjects(m_sceneGraph.GetActiveObjectsCount());
1497
1498 // frameMS currently records work frame times, not total frame times (work + any required sleep to
1499 // reach min frame time.
1500 // StatsReporter.addFrameMS(frameMS);
1501
1502 StatsReporter.addAgentMS(agentMS);
1503 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1504 StatsReporter.addOtherMS(otherMS);
1505 StatsReporter.SetActiveScripts(m_sceneGraph.GetActiveScriptsCount());
1506 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1507 1507
1508 if (LoginsDisabled && Frame == 20) 1508 if (LoginsDisabled && Frame == 20)
1509 { 1509 {
@@ -1524,11 +1524,11 @@ namespace OpenSim.Region.Framework.Scenes
1524 LoginLock = false; 1524 LoginLock = false;
1525 EventManager.TriggerLoginsEnabled(RegionInfo.RegionName); 1525 EventManager.TriggerLoginsEnabled(RegionInfo.RegionName);
1526 } 1526 }
1527 m_log.DebugFormat("[REGION]: Enabling logins for {0}", RegionInfo.RegionName);
1528 1527
1529 // For RegionReady lockouts 1528 // For RegionReady lockouts
1530 if(LoginLock == false) 1529 if (!LoginLock)
1531 { 1530 {
1531 m_log.InfoFormat("[REGION]: Enabling logins for {0}", RegionInfo.RegionName);
1532 LoginsDisabled = false; 1532 LoginsDisabled = false;
1533 } 1533 }
1534 1534
@@ -1554,23 +1554,36 @@ namespace OpenSim.Region.Framework.Scenes
1554 1554
1555 previousFrameTick = m_lastFrameTick; 1555 previousFrameTick = m_lastFrameTick;
1556 m_lastFrameTick = Util.EnvironmentTickCount(); 1556 m_lastFrameTick = Util.EnvironmentTickCount();
1557 maintc = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart); 1557 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, maintc);
1558 maintc = (int)(MinFrameTime * 1000) - maintc; 1558 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
1559 1559
1560 m_firstHeartbeat = false; 1560 m_firstHeartbeat = false;
1561 1561
1562 if (tmpMS > 0)
1563 {
1564 Thread.Sleep(tmpMS);
1565 spareMS += tmpMS;
1566 }
1567
1568 frameMS = Util.EnvironmentTickCountSubtract(maintc);
1569 maintc = Util.EnvironmentTickCount();
1562 1570
1563 sleepMS = Util.EnvironmentTickCount(); 1571 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1564 1572
1565 if (maintc > 0) 1573 // if (Frame%m_update_avatars == 0)
1566 Thread.Sleep(maintc); 1574 // UpdateInWorldTime();
1575 StatsReporter.AddPhysicsFPS(physicsFPS);
1576 StatsReporter.AddTimeDilation(TimeDilation);
1577 StatsReporter.AddFPS(1);
1567 1578
1568 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
1569 frameMS = Util.EnvironmentTickCountSubtract(framestart);
1570 StatsReporter.addSleepMS(sleepMS);
1571 StatsReporter.addFrameMS(frameMS); 1579 StatsReporter.addFrameMS(frameMS);
1572 1580 StatsReporter.addAgentMS(agentMS);
1573 // Optionally warn if a frame takes double the amount of time that it should. 1581 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1582 StatsReporter.addOtherMS(otherMS);
1583 StatsReporter.AddSpareMS(spareMS);
1584 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1585
1586 // Optionally warn if a frame takes double the amount of time that it should.
1574 if (DebugUpdates 1587 if (DebugUpdates
1575 && Util.EnvironmentTickCountSubtract( 1588 && Util.EnvironmentTickCountSubtract(
1576 m_lastFrameTick, previousFrameTick) > (int)(MinFrameTime * 1000 * 2)) 1589 m_lastFrameTick, previousFrameTick) > (int)(MinFrameTime * 1000 * 2))
@@ -2083,9 +2096,8 @@ namespace OpenSim.Region.Framework.Scenes
2083 sceneObject.SetGroup(groupID, null); 2096 sceneObject.SetGroup(groupID, null);
2084 } 2097 }
2085 2098
2086 IUserManagement uman = RequestModuleInterface<IUserManagement>(); 2099 if (UserManagementModule != null)
2087 if (uman != null) 2100 sceneObject.RootPart.CreatorIdentification = UserManagementModule.GetUserUUI(ownerID);
2088 sceneObject.RootPart.CreatorIdentification = uman.GetUserUUI(ownerID);
2089 2101
2090 sceneObject.ScheduleGroupForFullUpdate(); 2102 sceneObject.ScheduleGroupForFullUpdate();
2091 2103
@@ -2363,8 +2375,8 @@ namespace OpenSim.Region.Framework.Scenes
2363 return; 2375 return;
2364 } 2376 }
2365 2377
2366 if (m_teleportModule != null) 2378 if (EntityTransferModule != null)
2367 m_teleportModule.Cross(grp, attemptedPosition, silent); 2379 EntityTransferModule.Cross(grp, attemptedPosition, silent);
2368 } 2380 }
2369 2381
2370 public Border GetCrossedBorder(Vector3 position, Cardinals gridline) 2382 public Border GetCrossedBorder(Vector3 position, Cardinals gridline)
@@ -2684,10 +2696,10 @@ namespace OpenSim.Region.Framework.Scenes
2684 { 2696 {
2685 SceneObjectGroup grp = sceneObject; 2697 SceneObjectGroup grp = sceneObject;
2686 2698
2687 m_log.DebugFormat( 2699// m_log.DebugFormat(
2688 "[ATTACHMENT]: Received attachment {0}, inworld asset id {1}", grp.FromItemID, grp.UUID); 2700// "[ATTACHMENT]: Received attachment {0}, inworld asset id {1}", grp.FromItemID, grp.UUID);
2689 m_log.DebugFormat( 2701// m_log.DebugFormat(
2690 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition); 2702// "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition);
2691 2703
2692 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2704 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2693 2705
@@ -2783,7 +2795,8 @@ namespace OpenSim.Region.Framework.Scenes
2783 if (sp == null) 2795 if (sp == null)
2784 { 2796 {
2785 m_log.DebugFormat( 2797 m_log.DebugFormat(
2786 "[SCENE]: Adding new child scene presence {0} to scene {1} at pos {2}", client.Name, RegionInfo.RegionName, client.StartPos); 2798 "[SCENE]: Adding new child scene presence {0} {1} to scene {2} at pos {3}",
2799 client.Name, client.AgentId, RegionInfo.RegionName, client.StartPos);
2787 2800
2788 m_clientManager.Add(client); 2801 m_clientManager.Add(client);
2789 SubscribeToClientEvents(client); 2802 SubscribeToClientEvents(client);
@@ -2843,14 +2856,13 @@ namespace OpenSim.Region.Framework.Scenes
2843 /// <param name="aCircuit"></param> 2856 /// <param name="aCircuit"></param>
2844 private void CacheUserName(ScenePresence sp, AgentCircuitData aCircuit) 2857 private void CacheUserName(ScenePresence sp, AgentCircuitData aCircuit)
2845 { 2858 {
2846 IUserManagement uMan = RequestModuleInterface<IUserManagement>(); 2859 if (UserManagementModule != null)
2847 if (uMan != null)
2848 { 2860 {
2849 string first = aCircuit.firstname, last = aCircuit.lastname; 2861 string first = aCircuit.firstname, last = aCircuit.lastname;
2850 2862
2851 if (sp.PresenceType == PresenceType.Npc) 2863 if (sp.PresenceType == PresenceType.Npc)
2852 { 2864 {
2853 uMan.AddUser(aCircuit.AgentID, first, last); 2865 UserManagementModule.AddUser(aCircuit.AgentID, first, last);
2854 } 2866 }
2855 else 2867 else
2856 { 2868 {
@@ -2869,7 +2881,7 @@ namespace OpenSim.Region.Framework.Scenes
2869 } 2881 }
2870 } 2882 }
2871 2883
2872 uMan.AddUser(aCircuit.AgentID, first, last, homeURL); 2884 UserManagementModule.AddUser(aCircuit.AgentID, first, last, homeURL);
2873 } 2885 }
2874 } 2886 }
2875 } 2887 }
@@ -3207,8 +3219,10 @@ namespace OpenSim.Region.Framework.Scenes
3207 /// <param name="client">The IClientAPI for the client</param> 3219 /// <param name="client">The IClientAPI for the client</param>
3208 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client) 3220 public virtual bool TeleportClientHome(UUID agentId, IClientAPI client)
3209 { 3221 {
3210 if (m_teleportModule != null) 3222 if (EntityTransferModule != null)
3211 return m_teleportModule.TeleportHome(agentId, client); 3223 {
3224 EntityTransferModule.TeleportHome(agentId, client);
3225 }
3212 else 3226 else
3213 { 3227 {
3214 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active"); 3228 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
@@ -3370,65 +3384,82 @@ namespace OpenSim.Region.Framework.Scenes
3370// CheckHeartbeat(); 3384// CheckHeartbeat();
3371 bool isChildAgent = false; 3385 bool isChildAgent = false;
3372 ScenePresence avatar = GetScenePresence(agentID); 3386 ScenePresence avatar = GetScenePresence(agentID);
3373 if (avatar != null) 3387
3388 if (avatar == null)
3389 {
3390 m_log.WarnFormat(
3391 "[SCENE]: Called RemoveClient() with agent ID {0} but no such presence is in the scene.", agentID);
3392
3393 return;
3394 }
3395
3396 try
3374 { 3397 {
3375 isChildAgent = avatar.IsChildAgent; 3398 isChildAgent = avatar.IsChildAgent;
3376 3399
3377 if (avatar.ParentID != 0) 3400 m_log.DebugFormat(
3401 "[SCENE]: Removing {0} agent {1} {2} from {3}",
3402 (isChildAgent ? "child" : "root"), avatar.Name, agentID, RegionInfo.RegionName);
3403
3404 // Don't do this to root agents, it's not nice for the viewer
3405 if (closeChildAgents && isChildAgent)
3378 { 3406 {
3379 avatar.StandUp(); 3407 // Tell a single agent to disconnect from the region.
3408 IEventQueue eq = RequestModuleInterface<IEventQueue>();
3409 if (eq != null)
3410 {
3411 eq.DisableSimulator(RegionInfo.RegionHandle, avatar.UUID);
3412 }
3413 else
3414 {
3415 avatar.ControllingClient.SendShutdownConnectionNotice();
3416 }
3380 } 3417 }
3381 3418
3382 try 3419 // Only applies to root agents.
3420 if (avatar.ParentID != 0)
3383 { 3421 {
3384 m_log.DebugFormat( 3422 avatar.StandUp();
3385 "[SCENE]: Removing {0} agent {1} from region {2}", 3423 }
3386 (isChildAgent ? "child" : "root"), agentID, RegionInfo.RegionName);
3387 3424
3388 m_sceneGraph.removeUserCount(!isChildAgent); 3425 m_sceneGraph.removeUserCount(!isChildAgent);
3389 3426
3390 // TODO: We shouldn't use closeChildAgents here - it's being used by the NPC module to stop 3427 // TODO: We shouldn't use closeChildAgents here - it's being used by the NPC module to stop
3391 // unnecessary operations. This should go away once NPCs have no accompanying IClientAPI 3428 // unnecessary operations. This should go away once NPCs have no accompanying IClientAPI
3392 if (closeChildAgents && CapsModule != null) 3429 if (closeChildAgents && CapsModule != null)
3393 CapsModule.RemoveCaps(agentID); 3430 CapsModule.RemoveCaps(agentID);
3394 3431
3395 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever 3432 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
3396 // this method is doing is HORRIBLE!!! 3433 // this method is doing is HORRIBLE!!!
3397 avatar.Scene.NeedSceneCacheClear(avatar.UUID); 3434 avatar.Scene.NeedSceneCacheClear(avatar.UUID);
3398 3435
3399 if (closeChildAgents && !avatar.IsChildAgent) 3436 if (closeChildAgents && !isChildAgent)
3400 {
3401 List<ulong> regions = avatar.KnownRegionHandles;
3402 regions.Remove(RegionInfo.RegionHandle);
3403 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3404 }
3405 m_log.Debug("[Scene] Beginning ClientClosed");
3406 m_eventManager.TriggerClientClosed(agentID, this);
3407 m_log.Debug("[Scene] Finished ClientClosed");
3408 }
3409 catch (NullReferenceException)
3410 { 3437 {
3411 // We don't know which count to remove it from 3438 List<ulong> regions = avatar.KnownRegionHandles;
3412 // Avatar is already disposed :/ 3439 regions.Remove(RegionInfo.RegionHandle);
3440 m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
3413 } 3441 }
3414 3442
3415 try 3443 m_eventManager.TriggerClientClosed(agentID, this);
3444 m_eventManager.TriggerOnRemovePresence(agentID);
3445
3446 if (!isChildAgent)
3416 { 3447 {
3417 m_eventManager.TriggerOnRemovePresence(agentID); 3448 if (AttachmentsModule != null)
3418
3419 if (AttachmentsModule != null && !isChildAgent && avatar.PresenceType != PresenceType.Npc)
3420 { 3449 {
3421 IUserManagement uMan = RequestModuleInterface<IUserManagement>();
3422 // Don't save attachments for HG visitors, it 3450 // Don't save attachments for HG visitors, it
3423 // messes up their inventory. When a HG visitor logs 3451 // messes up their inventory. When a HG visitor logs
3424 // out on a foreign grid, their attachments will be 3452 // out on a foreign grid, their attachments will be
3425 // reloaded in the state they were in when they left 3453 // reloaded in the state they were in when they left
3426 // the home grid. This is best anyway as the visited 3454 // the home grid. This is best anyway as the visited
3427 // grid may use an incompatible script engine. 3455 // grid may use an incompatible script engine.
3428 if (uMan == null || uMan.IsLocalGridUser(avatar.UUID)) 3456 bool saveChanged
3429 AttachmentsModule.SaveChangedAttachments(avatar, false); 3457 = avatar.PresenceType != PresenceType.Npc
3458 && (UserManagementModule == null || UserManagementModule.IsLocalGridUser(avatar.UUID));
3459
3460 AttachmentsModule.DeRezAttachments(avatar, saveChanged, false);
3430 } 3461 }
3431 3462
3432 ForEachClient( 3463 ForEachClient(
3433 delegate(IClientAPI client) 3464 delegate(IClientAPI client)
3434 { 3465 {
@@ -3436,43 +3467,35 @@ namespace OpenSim.Region.Framework.Scenes
3436 try { client.SendKillObject(avatar.RegionHandle, new List<uint> { avatar.LocalId }); } 3467 try { client.SendKillObject(avatar.RegionHandle, new List<uint> { avatar.LocalId }); }
3437 catch (NullReferenceException) { } 3468 catch (NullReferenceException) { }
3438 }); 3469 });
3439
3440 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
3441 if (agentTransactions != null)
3442 {
3443 agentTransactions.RemoveAgentAssetTransactions(agentID);
3444 }
3445 }
3446 finally
3447 {
3448 // Always clean these structures up so that any failure above doesn't cause them to remain in the
3449 // scene with possibly bad effects (e.g. continually timing out on unacked packets and triggering
3450 // the same cleanup exception continually.
3451 // TODO: This should probably extend to the whole method, but we don't want to also catch the NRE
3452 // since this would hide the underlying failure and other associated problems.
3453 m_sceneGraph.RemoveScenePresence(agentID);
3454 m_clientManager.Remove(agentID);
3455 } 3470 }
3456 3471
3457 try 3472 // It's possible for child agents to have transactions if changes are being made cross-border.
3458 { 3473 if (AgentTransactionsModule != null)
3459 avatar.Close(); 3474 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
3460 } 3475
3461 catch (NullReferenceException) 3476 avatar.Close();
3462 { 3477
3463 //We can safely ignore null reference exceptions. It means the avatar are dead and cleaned up anyway.
3464 }
3465 catch (Exception e)
3466 {
3467 m_log.ErrorFormat("[SCENE] Scene.cs:RemoveClient exception {0}{1}", e.Message, e.StackTrace);
3468 }
3469 m_log.Debug("[Scene] Done. Firing RemoveCircuit");
3470 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3478 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3471// CleanDroppedAttachments();
3472 m_log.Debug("[Scene] The avatar has left the building"); 3479 m_log.Debug("[Scene] The avatar has left the building");
3473 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3474 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3475 } 3480 }
3481 catch (Exception e)
3482 {
3483 m_log.Error(
3484 string.Format("[SCENE]: Exception removing {0} from {1}, ", avatar.Name, RegionInfo.RegionName), e);
3485 }
3486 finally
3487 {
3488 // Always clean these structures up so that any failure above doesn't cause them to remain in the
3489 // scene with possibly bad effects (e.g. continually timing out on unacked packets and triggering
3490 // the same cleanup exception continually.
3491 // TODO: This should probably extend to the whole method, but we don't want to also catch the NRE
3492 // since this would hide the underlying failure and other associated problems.
3493 m_sceneGraph.RemoveScenePresence(agentID);
3494 m_clientManager.Remove(agentID);
3495 }
3496
3497 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
3498 //m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
3476 } 3499 }
3477 3500
3478 /// <summary> 3501 /// <summary>
@@ -3554,7 +3577,7 @@ namespace OpenSim.Region.Framework.Scenes
3554 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason, bool requirePresenceLookup) 3577 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason, bool requirePresenceLookup)
3555 { 3578 {
3556 bool vialogin = ((teleportFlags & (uint)TPFlags.ViaLogin) != 0 || 3579 bool vialogin = ((teleportFlags & (uint)TPFlags.ViaLogin) != 0 ||
3557 (teleportFlags & (uint)TPFlags.ViaHGLogin) != 0); 3580 (teleportFlags & (uint)TPFlags.ViaHGLogin) != 0);
3558 bool viahome = ((teleportFlags & (uint)TPFlags.ViaHome) != 0); 3581 bool viahome = ((teleportFlags & (uint)TPFlags.ViaHome) != 0);
3559 bool godlike = ((teleportFlags & (uint)TPFlags.Godlike) != 0); 3582 bool godlike = ((teleportFlags & (uint)TPFlags.Godlike) != 0);
3560 3583
@@ -3570,8 +3593,17 @@ namespace OpenSim.Region.Framework.Scenes
3570 // Don't disable this log message - it's too helpful 3593 // Don't disable this log message - it's too helpful
3571 m_log.DebugFormat( 3594 m_log.DebugFormat(
3572 "[SCENE]: Region {0} told of incoming {1} agent {2} {3} {4} (circuit code {5}, IP {6}, viewer {7}, teleportflags ({8}), position {9})", 3595 "[SCENE]: Region {0} told of incoming {1} agent {2} {3} {4} (circuit code {5}, IP {6}, viewer {7}, teleportflags ({8}), position {9})",
3573 RegionInfo.RegionName, (agent.child ? "child" : "root"),agent.firstname, agent.lastname, 3596 RegionInfo.RegionName,
3574 agent.AgentID, agent.circuitcode, agent.IPAddress, agent.Viewer, ((TPFlags)teleportFlags).ToString(), agent.startpos); 3597 (agent.child ? "child" : "root"),
3598 agent.firstname,
3599 agent.lastname,
3600 agent.AgentID,
3601 agent.circuitcode,
3602 agent.IPAddress,
3603 agent.Viewer,
3604 ((TPFlags)teleportFlags).ToString(),
3605 agent.startpos
3606 );
3575 3607
3576 if (LoginsDisabled) 3608 if (LoginsDisabled)
3577 { 3609 {
@@ -3586,7 +3618,10 @@ namespace OpenSim.Region.Framework.Scenes
3586 // We have a zombie from a crashed session. 3618 // We have a zombie from a crashed session.
3587 // Or the same user is trying to be root twice here, won't work. 3619 // Or the same user is trying to be root twice here, won't work.
3588 // Kill it. 3620 // Kill it.
3589 m_log.DebugFormat("[SCENE]: Zombie scene presence detected for {0} in {1}", agent.AgentID, RegionInfo.RegionName); 3621 m_log.DebugFormat(
3622 "[SCENE]: Zombie scene presence detected for {0} {1} in {2}",
3623 sp.Name, sp.UUID, RegionInfo.RegionName);
3624
3590 sp.ControllingClient.Close(); 3625 sp.ControllingClient.Close();
3591 sp = null; 3626 sp = null;
3592 } 3627 }
@@ -3613,8 +3648,7 @@ namespace OpenSim.Region.Framework.Scenes
3613 { 3648 {
3614 if (!VerifyUserPresence(agent, out reason)) 3649 if (!VerifyUserPresence(agent, out reason))
3615 return false; 3650 return false;
3616 } 3651 } catch (Exception e)
3617 catch (Exception e)
3618 { 3652 {
3619 m_log.ErrorFormat( 3653 m_log.ErrorFormat(
3620 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace); 3654 "[SCENE]: Exception verifying presence {0}{1}", e.Message, e.StackTrace);
@@ -3649,8 +3683,7 @@ namespace OpenSim.Region.Framework.Scenes
3649 CapsModule.SetAgentCapsSeeds(agent); 3683 CapsModule.SetAgentCapsSeeds(agent);
3650 CapsModule.CreateCaps(agent.AgentID); 3684 CapsModule.CreateCaps(agent.AgentID);
3651 } 3685 }
3652 } 3686 } else
3653 else
3654 { 3687 {
3655 // Let the SP know how we got here. This has a lot of interesting 3688 // Let the SP know how we got here. This has a lot of interesting
3656 // uses down the line. 3689 // uses down the line.
@@ -3673,7 +3706,7 @@ namespace OpenSim.Region.Framework.Scenes
3673 agent.teleportFlags = teleportFlags; 3706 agent.teleportFlags = teleportFlags;
3674 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3707 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
3675 3708
3676 if (vialogin) 3709 if (vialogin)
3677 { 3710 {
3678// CleanDroppedAttachments(); 3711// CleanDroppedAttachments();
3679 3712
@@ -3714,8 +3747,7 @@ namespace OpenSim.Region.Framework.Scenes
3714 agent.startpos.Z = 720; 3747 agent.startpos.Z = 720;
3715 } 3748 }
3716 } 3749 }
3717 } 3750 } else
3718 else
3719 { 3751 {
3720 if (agent.startpos.X > EastBorders[0].BorderLine.Z) 3752 if (agent.startpos.X > EastBorders[0].BorderLine.Z)
3721 { 3753 {
@@ -3741,10 +3773,19 @@ namespace OpenSim.Region.Framework.Scenes
3741 SceneObjectGroup telehub = GetSceneObjectGroup(RegionInfo.RegionSettings.TelehubObject); 3773 SceneObjectGroup telehub = GetSceneObjectGroup(RegionInfo.RegionSettings.TelehubObject);
3742 // Can have multiple SpawnPoints 3774 // Can have multiple SpawnPoints
3743 List<SpawnPoint> spawnpoints = RegionInfo.RegionSettings.SpawnPoints(); 3775 List<SpawnPoint> spawnpoints = RegionInfo.RegionSettings.SpawnPoints();
3744 if ( spawnpoints.Count > 1) 3776 if (spawnpoints.Count > 1)
3745 { 3777 {
3746 // We have multiple SpawnPoints, Route the agent to a random one 3778 // We have multiple SpawnPoints, Route the agent to a random or sequential one
3747 agent.startpos = spawnpoints[Util.RandomClass.Next(spawnpoints.Count)].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation); 3779 if (SpawnPointRouting == "random")
3780 agent.startpos = spawnpoints[Util.RandomClass.Next(spawnpoints.Count) - 1].GetLocation(
3781 telehub.AbsolutePosition,
3782 telehub.GroupRotation
3783 );
3784 else
3785 agent.startpos = spawnpoints[SpawnPoint()].GetLocation(
3786 telehub.AbsolutePosition,
3787 telehub.GroupRotation
3788 );
3748 } 3789 }
3749 else 3790 else
3750 { 3791 {
@@ -3981,41 +4022,41 @@ namespace OpenSim.Region.Framework.Scenes
3981 return m_authenticateHandler.TryChangeCiruitCode(oldcc, newcc); 4022 return m_authenticateHandler.TryChangeCiruitCode(oldcc, newcc);
3982 } 4023 }
3983 4024
3984 /// <summary> 4025// /// <summary>
3985 /// The Grid has requested that we log-off a user. Log them off. 4026// /// The Grid has requested that we log-off a user. Log them off.
3986 /// </summary> 4027// /// </summary>
3987 /// <param name="AvatarID">Unique ID of the avatar to log-off</param> 4028// /// <param name="AvatarID">Unique ID of the avatar to log-off</param>
3988 /// <param name="RegionSecret">SecureSessionID of the user, or the RegionSecret text when logging on to the grid</param> 4029// /// <param name="RegionSecret">SecureSessionID of the user, or the RegionSecret text when logging on to the grid</param>
3989 /// <param name="message">message to display to the user. Reason for being logged off</param> 4030// /// <param name="message">message to display to the user. Reason for being logged off</param>
3990 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message) 4031// public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message)
3991 { 4032// {
3992 ScenePresence loggingOffUser = GetScenePresence(AvatarID); 4033// ScenePresence loggingOffUser = GetScenePresence(AvatarID);
3993 if (loggingOffUser != null) 4034// if (loggingOffUser != null)
3994 { 4035// {
3995 UUID localRegionSecret = UUID.Zero; 4036// UUID localRegionSecret = UUID.Zero;
3996 bool parsedsecret = UUID.TryParse(m_regInfo.regionSecret, out localRegionSecret); 4037// bool parsedsecret = UUID.TryParse(m_regInfo.regionSecret, out localRegionSecret);
3997 4038//
3998 // Region Secret is used here in case a new sessionid overwrites an old one on the user server. 4039// // Region Secret is used here in case a new sessionid overwrites an old one on the user server.
3999 // Will update the user server in a few revisions to use it. 4040// // Will update the user server in a few revisions to use it.
4000 4041//
4001 if (RegionSecret == loggingOffUser.ControllingClient.SecureSessionId || (parsedsecret && RegionSecret == localRegionSecret)) 4042// if (RegionSecret == loggingOffUser.ControllingClient.SecureSessionId || (parsedsecret && RegionSecret == localRegionSecret))
4002 { 4043// {
4003 m_sceneGridService.SendCloseChildAgentConnections(loggingOffUser.UUID, loggingOffUser.KnownRegionHandles); 4044// m_sceneGridService.SendCloseChildAgentConnections(loggingOffUser.UUID, loggingOffUser.KnownRegionHandles);
4004 loggingOffUser.ControllingClient.Kick(message); 4045// loggingOffUser.ControllingClient.Kick(message);
4005 // Give them a second to receive the message! 4046// // Give them a second to receive the message!
4006 Thread.Sleep(1000); 4047// Thread.Sleep(1000);
4007 loggingOffUser.ControllingClient.Close(); 4048// loggingOffUser.ControllingClient.Close();
4008 } 4049// }
4009 else 4050// else
4010 { 4051// {
4011 m_log.Info("[USERLOGOFF]: System sending the LogOff user message failed to sucessfully authenticate"); 4052// m_log.Info("[USERLOGOFF]: System sending the LogOff user message failed to sucessfully authenticate");
4012 } 4053// }
4013 } 4054// }
4014 else 4055// else
4015 { 4056// {
4016 m_log.InfoFormat("[USERLOGOFF]: Got a logoff request for {0} but the user isn't here. The user might already have been logged out", AvatarID.ToString()); 4057// m_log.InfoFormat("[USERLOGOFF]: Got a logoff request for {0} but the user isn't here. The user might already have been logged out", AvatarID.ToString());
4017 } 4058// }
4018 } 4059// }
4019 4060
4020 /// <summary> 4061 /// <summary>
4021 /// Triggered when an agent crosses into this sim. Also happens on initial login. 4062 /// Triggered when an agent crosses into this sim. Also happens on initial login.
@@ -4068,21 +4109,19 @@ namespace OpenSim.Region.Framework.Scenes
4068 return false; 4109 return false;
4069 } 4110 }
4070 4111
4112 // TODO: This check should probably be in QueryAccess().
4071 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2); 4113 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, Constants.RegionSize / 2, Constants.RegionSize / 2);
4072 if (nearestParcel == null) 4114 if (nearestParcel == null)
4073 { 4115 {
4074 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: no allowed parcel", cAgentData.AgentID); 4116 m_log.DebugFormat(
4075 return false; 4117 "[SCENE]: Denying root agent entry to {0} in {1}: no allowed parcel",
4076 } 4118 cAgentData.AgentID, RegionInfo.RegionName);
4077
4078 int num = m_sceneGraph.GetNumberOfScenePresences();
4079 4119
4080 if (num >= RegionInfo.RegionSettings.AgentLimit) 4120 return false;
4081 {
4082 if (!Permissions.IsAdministrator(cAgentData.AgentID))
4083 return false;
4084 } 4121 }
4085 4122
4123 // We have to wait until the viewer contacts this region after receiving EAC.
4124 // That calls AddNewClient, which finally creates the ScenePresence
4086 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID); 4125 ScenePresence childAgentUpdate = WaitGetScenePresence(cAgentData.AgentID);
4087 4126
4088 if (childAgentUpdate != null) 4127 if (childAgentUpdate != null)
@@ -4126,14 +4165,28 @@ namespace OpenSim.Region.Framework.Scenes
4126 return false; 4165 return false;
4127 } 4166 }
4128 4167
4168 /// <summary>
4169 /// Poll until the requested ScenePresence appears or we timeout.
4170 /// </summary>
4171 /// <returns>The scene presence is found, else null.</returns>
4172 /// <param name='agentID'></param>
4129 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 4173 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4130 { 4174 {
4131 int ntimes = 10; 4175 int ntimes = 10;
4132 ScenePresence childAgentUpdate = null; 4176 ScenePresence sp = null;
4133 while ((childAgentUpdate = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 4177 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4134 Thread.Sleep(1000); 4178 Thread.Sleep(1000);
4135 return childAgentUpdate;
4136 4179
4180 if (sp == null)
4181 m_log.WarnFormat(
4182 "[SCENE PRESENCE]: Did not find presence with id {0} in {1} before timeout",
4183 agentID, RegionInfo.RegionName);
4184// else
4185// m_log.DebugFormat(
4186// "[SCENE PRESENCE]: Found presence {0} {1} {2} in {3} after {4} waits",
4187// sp.Name, sp.UUID, sp.IsChildAgent ? "child" : "root", RegionInfo.RegionName, 10 - ntimes);
4188
4189 return sp;
4137 } 4190 }
4138 4191
4139 public virtual bool IncomingRetrieveRootAgent(UUID id, out IAgentData agent) 4192 public virtual bool IncomingRetrieveRootAgent(UUID id, out IAgentData agent)
@@ -4171,33 +4224,7 @@ namespace OpenSim.Region.Framework.Scenes
4171 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID); 4224 ScenePresence presence = m_sceneGraph.GetScenePresence(agentID);
4172 if (presence != null) 4225 if (presence != null)
4173 { 4226 {
4174 // Nothing is removed here, so down count it as such 4227 presence.ControllingClient.Close();
4175 if (presence.IsChildAgent)
4176 {
4177 m_sceneGraph.removeUserCount(false);
4178 }
4179 else if (!childOnly)
4180 {
4181 m_sceneGraph.removeUserCount(true);
4182 }
4183
4184 // Don't do this to root agents on logout, it's not nice for the viewer
4185 if (presence.IsChildAgent)
4186 {
4187 // Tell a single agent to disconnect from the region.
4188 IEventQueue eq = RequestModuleInterface<IEventQueue>();
4189 if (eq != null)
4190 {
4191 eq.DisableSimulator(RegionInfo.RegionHandle, agentID);
4192 }
4193 else
4194 presence.ControllingClient.SendShutdownConnectionNotice();
4195 presence.ControllingClient.Close(false);
4196 }
4197 else if (!childOnly)
4198 {
4199 presence.ControllingClient.Close(true);
4200 }
4201 return true; 4228 return true;
4202 } 4229 }
4203 4230
@@ -4283,8 +4310,10 @@ namespace OpenSim.Region.Framework.Scenes
4283 position.Y -= shifty; 4310 position.Y -= shifty;
4284 } 4311 }
4285 4312
4286 if (m_teleportModule != null) 4313 if (EntityTransferModule != null)
4287 m_teleportModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags); 4314 {
4315 EntityTransferModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
4316 }
4288 else 4317 else
4289 { 4318 {
4290 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active"); 4319 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active");
@@ -4295,8 +4324,10 @@ namespace OpenSim.Region.Framework.Scenes
4295 4324
4296 public bool CrossAgentToNewRegion(ScenePresence agent, bool isFlying) 4325 public bool CrossAgentToNewRegion(ScenePresence agent, bool isFlying)
4297 { 4326 {
4298 if (m_teleportModule != null) 4327 if (EntityTransferModule != null)
4299 return m_teleportModule.Cross(agent, isFlying); 4328 {
4329 return EntityTransferModule.Cross(agent, isFlying);
4330 }
4300 else 4331 else
4301 { 4332 {
4302 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule"); 4333 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule");
@@ -5444,29 +5475,58 @@ Environment.Exit(1);
5444 throw new Exception(error); 5475 throw new Exception(error);
5445 } 5476 }
5446 5477
5447 // This method is called across the simulation connector to 5478 /// <summary>
5448 // determine if a given agent is allowed in this region 5479 /// This method is called across the simulation connector to
5449 // AS A ROOT AGENT. Returning false here will prevent them 5480 /// determine if a given agent is allowed in this region
5450 // from logging into the region, teleporting into the region 5481 /// AS A ROOT AGENT
5451 // or corssing the broder walking, but will NOT prevent 5482 /// </summary>
5452 // child agent creation, thereby emulating the SL behavior. 5483 /// <remarks>
5484 /// Returning false here will prevent them
5485 /// from logging into the region, teleporting into the region
5486 /// or corssing the broder walking, but will NOT prevent
5487 /// child agent creation, thereby emulating the SL behavior.
5488 /// </remarks>
5489 /// <param name='agentID'></param>
5490 /// <param name='position'></param>
5491 /// <param name='reason'></param>
5492 /// <returns></returns>
5453 public bool QueryAccess(UUID agentID, Vector3 position, out string reason) 5493 public bool QueryAccess(UUID agentID, Vector3 position, out string reason)
5454 { 5494 {
5455 reason = "You are banned from the region"; 5495 reason = "You are banned from the region";
5456 5496
5497 if (EntityTransferModule.IsInTransit(agentID))
5498 {
5499 reason = "Agent is still in transit from this region";
5500
5501 m_log.WarnFormat(
5502 "[SCENE]: Denying agent {0} entry into {1} since region still has them registered as in transit",
5503 agentID, RegionInfo.RegionName);
5504
5505 return false;
5506 }
5507
5457 if (Permissions.IsGod(agentID)) 5508 if (Permissions.IsGod(agentID))
5458 { 5509 {
5459 reason = String.Empty; 5510 reason = String.Empty;
5460 return true; 5511 return true;
5461 } 5512 }
5462 5513
5463 int num = m_sceneGraph.GetNumberOfScenePresences(); 5514 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5515 // However, the long term fix is to make sure root agent count is always accurate.
5516 m_sceneGraph.RecalculateStats();
5517
5518 int num = m_sceneGraph.GetRootAgentCount();
5464 5519
5465 if (num >= RegionInfo.RegionSettings.AgentLimit) 5520 if (num >= RegionInfo.RegionSettings.AgentLimit)
5466 { 5521 {
5467 if (!Permissions.IsAdministrator(agentID)) 5522 if (!Permissions.IsAdministrator(agentID))
5468 { 5523 {
5469 reason = "The region is full"; 5524 reason = "The region is full";
5525
5526 m_log.DebugFormat(
5527 "[SCENE]: Denying presence with id {0} entry into {1} since region is at agent limit of {2}",
5528 agentID, RegionInfo.RegionName, RegionInfo.RegionSettings.AgentLimit);
5529
5470 return false; 5530 return false;
5471 } 5531 }
5472 } 5532 }
@@ -5637,5 +5697,19 @@ Environment.Exit(1);
5637 } 5697 }
5638 } 5698 }
5639 } 5699 }
5700
5701 // manage and select spawn points in sequence
5702 public int SpawnPoint()
5703 {
5704 int spawnpoints = RegionInfo.RegionSettings.SpawnPoints().Count;
5705
5706 if (spawnpoints == 0)
5707 return 0;
5708
5709 m_SpawnPoint++;
5710 if (m_SpawnPoint > spawnpoints)
5711 m_SpawnPoint = 1;
5712 return m_SpawnPoint - 1;
5713 }
5640 } 5714 }
5641} 5715}
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index b806d91..c1414ee 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -84,16 +84,16 @@ namespace OpenSim.Region.Framework.Scenes
84 if (neighbourService != null) 84 if (neighbourService != null)
85 neighbour = neighbourService.HelloNeighbour(regionhandle, region); 85 neighbour = neighbourService.HelloNeighbour(regionhandle, region);
86 else 86 else
87 m_log.DebugFormat("[SCS]: No neighbour service provided for informing neigbhours of this region"); 87 m_log.DebugFormat("[SCENE COMMUNICATION SERVICE]: No neighbour service provided for informing neigbhours of this region");
88 88
89 if (neighbour != null) 89 if (neighbour != null)
90 { 90 {
91 // m_log.DebugFormat("[INTERGRID]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize); 91 m_log.DebugFormat("[SCENE COMMUNICATION SERVICE]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize);
92 m_scene.EventManager.TriggerOnRegionUp(neighbour); 92 m_scene.EventManager.TriggerOnRegionUp(neighbour);
93 } 93 }
94 else 94 else
95 { 95 {
96 m_log.InfoFormat("[INTERGRID]: Failed to inform neighbour {0}-{1} that I'm here.", x / Constants.RegionSize, y / Constants.RegionSize); 96 m_log.InfoFormat("[SCENE COMMUNICATION SERVICE]: Failed to inform neighbour {0}-{1} that I'm here.", x / Constants.RegionSize, y / Constants.RegionSize);
97 } 97 }
98 } 98 }
99 99
@@ -102,7 +102,7 @@ namespace OpenSim.Region.Framework.Scenes
102 //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName); 102 //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName);
103 103
104 List<GridRegion> neighbours = m_scene.GridService.GetNeighbours(m_scene.RegionInfo.ScopeID, m_scene.RegionInfo.RegionID); 104 List<GridRegion> neighbours = m_scene.GridService.GetNeighbours(m_scene.RegionInfo.ScopeID, m_scene.RegionInfo.RegionID);
105 //m_log.DebugFormat("[INTERGRID]: Informing {0} neighbours that this region is up", neighbours.Count); 105 m_log.DebugFormat("[SCENE COMMUNICATION SERVICE]: Informing {0} neighbours that this region is up", neighbours.Count);
106 foreach (GridRegion n in neighbours) 106 foreach (GridRegion n in neighbours)
107 { 107 {
108 InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync; 108 InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync;
@@ -156,7 +156,9 @@ namespace OpenSim.Region.Framework.Scenes
156 // that the region position is cached or performance will degrade 156 // that the region position is cached or performance will degrade
157 Utils.LongToUInts(regionHandle, out x, out y); 157 Utils.LongToUInts(regionHandle, out x, out y);
158 GridRegion dest = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); 158 GridRegion dest = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
159// bool v = true; 159 if (dest == null)
160 continue;
161
160 if (!simulatorList.Contains(dest.ServerURI)) 162 if (!simulatorList.Contains(dest.ServerURI))
161 { 163 {
162 // we havent seen this simulator before, add it to the list 164 // we havent seen this simulator before, add it to the list
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index b7466be..4c12496 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -101,6 +101,13 @@ namespace OpenSim.Region.Framework.Scenes
101 /// </summary> 101 /// </summary>
102 protected internal Dictionary<uint, SceneObjectGroup> SceneObjectGroupsByLocalPartID = new Dictionary<uint, SceneObjectGroup>(); 102 protected internal Dictionary<uint, SceneObjectGroup> SceneObjectGroupsByLocalPartID = new Dictionary<uint, SceneObjectGroup>();
103 103
104 /// <summary>
105 /// Lock to prevent object group update, linking, delinking and duplication operations from running concurrently.
106 /// </summary>
107 /// <remarks>
108 /// These operations rely on the parts composition of the object. If allowed to run concurrently then race
109 /// conditions can occur.
110 /// </remarks>
104 private Object m_updateLock = new Object(); 111 private Object m_updateLock = new Object();
105 112
106 #endregion 113 #endregion
@@ -775,12 +782,6 @@ namespace OpenSim.Region.Framework.Scenes
775 782
776 public int GetChildAgentCount() 783 public int GetChildAgentCount()
777 { 784 {
778 // some network situations come in where child agents get closed twice.
779 if (m_numChildAgents < 0)
780 {
781 m_numChildAgents = 0;
782 }
783
784 return m_numChildAgents; 785 return m_numChildAgents;
785 } 786 }
786 787
@@ -852,11 +853,6 @@ namespace OpenSim.Region.Framework.Scenes
852 return m_scenePresenceArray; 853 return m_scenePresenceArray;
853 } 854 }
854 855
855 public int GetNumberOfScenePresences()
856 {
857 return m_scenePresenceArray.Count;
858 }
859
860 /// <summary> 856 /// <summary>
861 /// Request a scene presence by UUID. Fast, indexed lookup. 857 /// Request a scene presence by UUID. Fast, indexed lookup.
862 /// </summary> 858 /// </summary>
@@ -2063,12 +2059,14 @@ namespace OpenSim.Region.Framework.Scenes
2063 /// <param name="AgentID"></param> 2059 /// <param name="AgentID"></param>
2064 /// <param name="GroupID"></param> 2060 /// <param name="GroupID"></param>
2065 /// <param name="rot"></param> 2061 /// <param name="rot"></param>
2062 /// <returns>null if duplication fails, otherwise the duplicated object</returns>
2063 /// <summary>
2066 public SceneObjectGroup DuplicateObject(uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot) 2064 public SceneObjectGroup DuplicateObject(uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot)
2067 { 2065 {
2068// m_log.DebugFormat( 2066// m_log.DebugFormat(
2069// "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", 2067// "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}",
2070// originalPrimID, offset, AgentID); 2068// originalPrimID, offset, AgentID);
2071 2069
2072 SceneObjectGroup original = GetGroupByPrim(originalPrimID); 2070 SceneObjectGroup original = GetGroupByPrim(originalPrimID);
2073 if (original != null) 2071 if (original != null)
2074 { 2072 {
@@ -2098,25 +2096,25 @@ namespace OpenSim.Region.Framework.Scenes
2098 2096
2099 // FIXME: This section needs to be refactored so that it just calls AddSceneObject() 2097 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()
2100 Entities.Add(copy); 2098 Entities.Add(copy);
2101 2099
2102 lock (SceneObjectGroupsByFullID) 2100 lock (SceneObjectGroupsByFullID)
2103 SceneObjectGroupsByFullID[copy.UUID] = copy; 2101 SceneObjectGroupsByFullID[copy.UUID] = copy;
2104 2102
2105 SceneObjectPart[] children = copy.Parts; 2103 SceneObjectPart[] children = copy.Parts;
2106 2104
2107 lock (SceneObjectGroupsByFullPartID) 2105 lock (SceneObjectGroupsByFullPartID)
2108 { 2106 {
2109 SceneObjectGroupsByFullPartID[copy.UUID] = copy; 2107 SceneObjectGroupsByFullPartID[copy.UUID] = copy;
2110 foreach (SceneObjectPart part in children) 2108 foreach (SceneObjectPart part in children)
2111 SceneObjectGroupsByFullPartID[part.UUID] = copy; 2109 SceneObjectGroupsByFullPartID[part.UUID] = copy;
2112 } 2110 }
2113 2111
2114 lock (SceneObjectGroupsByLocalPartID) 2112 lock (SceneObjectGroupsByLocalPartID)
2115 { 2113 {
2116 SceneObjectGroupsByLocalPartID[copy.LocalId] = copy; 2114 SceneObjectGroupsByLocalPartID[copy.LocalId] = copy;
2117 foreach (SceneObjectPart part in children) 2115 foreach (SceneObjectPart part in children)
2118 SceneObjectGroupsByLocalPartID[part.LocalId] = copy; 2116 SceneObjectGroupsByLocalPartID[part.LocalId] = copy;
2119 } 2117 }
2120 // PROBABLE END OF FIXME 2118 // PROBABLE END OF FIXME
2121 2119
2122 // Since we copy from a source group that is in selected 2120 // Since we copy from a source group that is in selected
@@ -2148,11 +2146,10 @@ namespace OpenSim.Region.Framework.Scenes
2148 { 2146 {
2149 m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID); 2147 m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
2150 } 2148 }
2151 2149
2152 return null; 2150 return null;
2153 } 2151 }
2154 2152
2155 /// <summary>
2156 /// Calculates the distance between two Vector3s 2153 /// Calculates the distance between two Vector3s
2157 /// </summary> 2154 /// </summary>
2158 /// <param name="v1"></param> 2155 /// <param name="v1"></param>
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
index 2effa25..1038111 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
@@ -54,16 +54,28 @@ namespace OpenSim.Region.Framework.Scenes
54 /// <summary> 54 /// <summary>
55 /// Start the scripts contained in all the prims in this group. 55 /// Start the scripts contained in all the prims in this group.
56 /// </summary> 56 /// </summary>
57 public void CreateScriptInstances(int startParam, bool postOnRez, 57 /// <param name="startParam"></param>
58 string engine, int stateSource) 58 /// <param name="postOnRez"></param>
59 /// <param name="engine"></param>
60 /// <param name="stateSource"></param>
61 /// <returns>
62 /// Number of scripts that were valid for starting. This does not guarantee that all these scripts
63 /// were actually started, but just that the start could be attempt (e.g. the asset data for the script could be found)
64 /// </returns>
65 public int CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
59 { 66 {
67 int scriptsStarted = 0;
68
60 // Don't start scripts if they're turned off in the region! 69 // Don't start scripts if they're turned off in the region!
61 if (!m_scene.RegionInfo.RegionSettings.DisableScripts) 70 if (!m_scene.RegionInfo.RegionSettings.DisableScripts)
62 { 71 {
63 SceneObjectPart[] parts = m_parts.GetArray(); 72 SceneObjectPart[] parts = m_parts.GetArray();
64 for (int i = 0; i < parts.Length; i++) 73 for (int i = 0; i < parts.Length; i++)
65 parts[i].Inventory.CreateScriptInstances(startParam, postOnRez, engine, stateSource); 74 scriptsStarted
75 += parts[i].Inventory.CreateScriptInstances(startParam, postOnRez, engine, stateSource);
66 } 76 }
77
78 return scriptsStarted;
67 } 79 }
68 80
69 /// <summary> 81 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index aab6a49..11d703a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -244,6 +244,22 @@ namespace OpenSim.Region.Framework.Scenes
244 } 244 }
245 } 245 }
246 246
247 /// <summary>
248 /// If this scene object has an attachment point then indicate whether there is a point where
249 /// attachments are perceivable by avatars other than the avatar to which this object is attached.
250 /// </summary>
251 /// <remarks>
252 /// HUDs are not perceivable by other avatars.
253 /// </remarks>
254 public bool HasPrivateAttachmentPoint
255 {
256 get
257 {
258 return AttachmentPoint >= (uint)OpenMetaverse.AttachmentPoint.HUDCenter2
259 && AttachmentPoint <= (uint)OpenMetaverse.AttachmentPoint.HUDBottomRight;
260 }
261 }
262
247 public void ClearPartAttachmentData() 263 public void ClearPartAttachmentData()
248 { 264 {
249 AttachmentPoint = 0; 265 AttachmentPoint = 0;
@@ -1808,8 +1824,9 @@ namespace OpenSim.Region.Framework.Scenes
1808 part.ClearUpdateSchedule(); 1824 part.ClearUpdateSchedule();
1809 if (part == m_rootPart) 1825 if (part == m_rootPart)
1810 { 1826 {
1811 if (!IsAttachment || (AttachedAvatar == avatar.ControllingClient.AgentId) || 1827 if (!IsAttachment
1812 (AttachmentPoint < 31) || (AttachmentPoint > 38)) 1828 || AttachedAvatar == avatar.ControllingClient.AgentId
1829 || !HasPrivateAttachmentPoint)
1813 avatar.ControllingClient.SendKillObject(m_regionHandle, new List<uint> { part.LocalId }); 1830 avatar.ControllingClient.SendKillObject(m_regionHandle, new List<uint> { part.LocalId });
1814 } 1831 }
1815 } 1832 }
@@ -2670,6 +2687,10 @@ namespace OpenSim.Region.Framework.Scenes
2670 /// <summary> 2687 /// <summary>
2671 /// Link the prims in a given group to this group 2688 /// Link the prims in a given group to this group
2672 /// </summary> 2689 /// </summary>
2690 /// <remarks>
2691 /// Do not call this method directly - use Scene.LinkObjects() instead to avoid races between threads.
2692 /// FIXME: There are places where scripts call these methods directly without locking. This is a potential race condition.
2693 /// </remarks>
2673 /// <param name="objectGroup">The group of prims which should be linked to this group</param> 2694 /// <param name="objectGroup">The group of prims which should be linked to this group</param>
2674 public void LinkToGroup(SceneObjectGroup objectGroup) 2695 public void LinkToGroup(SceneObjectGroup objectGroup)
2675 { 2696 {
@@ -2751,6 +2772,7 @@ namespace OpenSim.Region.Framework.Scenes
2751 } 2772 }
2752 2773
2753 linkPart.LinkNum = linkNum++; 2774 linkPart.LinkNum = linkNum++;
2775 linkPart.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
2754 2776
2755 SceneObjectPart[] ogParts = objectGroup.Parts; 2777 SceneObjectPart[] ogParts = objectGroup.Parts;
2756 Array.Sort(ogParts, delegate(SceneObjectPart a, SceneObjectPart b) 2778 Array.Sort(ogParts, delegate(SceneObjectPart a, SceneObjectPart b)
@@ -2802,6 +2824,11 @@ namespace OpenSim.Region.Framework.Scenes
2802 /// Delink the given prim from this group. The delinked prim is established as 2824 /// Delink the given prim from this group. The delinked prim is established as
2803 /// an independent SceneObjectGroup. 2825 /// an independent SceneObjectGroup.
2804 /// </summary> 2826 /// </summary>
2827 /// <remarks>
2828 /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
2829 /// condition. But currently there is no
2830 /// alternative method that does take a lonk to delink a single prim.
2831 /// </remarks>
2805 /// <param name="partID"></param> 2832 /// <param name="partID"></param>
2806 /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns> 2833 /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
2807 public SceneObjectGroup DelinkFromGroup(uint partID) 2834 public SceneObjectGroup DelinkFromGroup(uint partID)
@@ -2813,6 +2840,11 @@ namespace OpenSim.Region.Framework.Scenes
2813 /// Delink the given prim from this group. The delinked prim is established as 2840 /// Delink the given prim from this group. The delinked prim is established as
2814 /// an independent SceneObjectGroup. 2841 /// an independent SceneObjectGroup.
2815 /// </summary> 2842 /// </summary>
2843 /// <remarks>
2844 /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
2845 /// condition. But currently there is no
2846 /// alternative method that does take a lonk to delink a single prim.
2847 /// </remarks>
2816 /// <param name="partID"></param> 2848 /// <param name="partID"></param>
2817 /// <param name="sendEvents"></param> 2849 /// <param name="sendEvents"></param>
2818 /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns> 2850 /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
@@ -2838,6 +2870,11 @@ namespace OpenSim.Region.Framework.Scenes
2838 /// Delink the given prim from this group. The delinked prim is established as 2870 /// Delink the given prim from this group. The delinked prim is established as
2839 /// an independent SceneObjectGroup. 2871 /// an independent SceneObjectGroup.
2840 /// </summary> 2872 /// </summary>
2873 /// <remarks>
2874 /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
2875 /// condition. But currently there is no
2876 /// alternative method that does take a lonk to delink a single prim.
2877 /// </remarks>
2841 /// <param name="partID"></param> 2878 /// <param name="partID"></param>
2842 /// <param name="sendEvents"></param> 2879 /// <param name="sendEvents"></param>
2843 /// <returns>The object group of the newly delinked prim.</returns> 2880 /// <returns>The object group of the newly delinked prim.</returns>
@@ -2971,6 +3008,8 @@ namespace OpenSim.Region.Framework.Scenes
2971 oldRot = part.RotationOffset; 3008 oldRot = part.RotationOffset;
2972 Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot; 3009 Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot;
2973 part.RotationOffset = newRot; 3010 part.RotationOffset = newRot;
3011
3012 part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
2974 } 3013 }
2975 3014
2976 /// <summary> 3015 /// <summary>
@@ -3486,7 +3525,7 @@ namespace OpenSim.Region.Framework.Scenes
3486 3525
3487 //we need to do a terse update even if the move wasn't allowed 3526 //we need to do a terse update even if the move wasn't allowed
3488 // so that the position is reset in the client (the object snaps back) 3527 // so that the position is reset in the client (the object snaps back)
3489 ScheduleGroupForTerseUpdate(); 3528 RootPart.ScheduleTerseUpdate();
3490 } 3529 }
3491 3530
3492 /// <summary> 3531 /// <summary>
@@ -3601,6 +3640,11 @@ namespace OpenSim.Region.Framework.Scenes
3601 m_scene.PhysicsScene.AddPhysicsActorTaint(actor); 3640 m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
3602 } 3641 }
3603 3642
3643 if (IsAttachment)
3644 {
3645 m_rootPart.AttachedPos = pos;
3646 }
3647
3604 AbsolutePosition = pos; 3648 AbsolutePosition = pos;
3605 3649
3606 HasGroupChanged = true; 3650 HasGroupChanged = true;
@@ -4187,7 +4231,72 @@ namespace OpenSim.Region.Framework.Scenes
4187 for (int i = 0; i < parts.Length; i++) 4231 for (int i = 0; i < parts.Length; i++)
4188 parts[i].TriggerScriptChangedEvent(val); 4232 parts[i].TriggerScriptChangedEvent(val);
4189 } 4233 }
4190 4234
4235 /// <summary>
4236 /// Returns a count of the number of scripts in this groups parts.
4237 /// </summary>
4238 public int ScriptCount()
4239 {
4240 int count = 0;
4241 SceneObjectPart[] parts = m_parts.GetArray();
4242 for (int i = 0; i < parts.Length; i++)
4243 count += parts[i].Inventory.ScriptCount();
4244
4245 return count;
4246 }
4247
4248 /// <summary>
4249 /// A float the value is a representative execution time in milliseconds of all scripts in the link set.
4250 /// </summary>
4251 public float ScriptExecutionTime()
4252 {
4253 IScriptModule[] engines = Scene.RequestModuleInterfaces<IScriptModule>();
4254
4255 if (engines.Length == 0) // No engine at all
4256 return 0.0f;
4257
4258 float time = 0.0f;
4259
4260 // get all the scripts in all parts
4261 SceneObjectPart[] parts = m_parts.GetArray();
4262 List<TaskInventoryItem> scripts = new List<TaskInventoryItem>();
4263 for (int i = 0; i < parts.Length; i++)
4264 {
4265 scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL));
4266 }
4267 // extract the UUIDs
4268 List<UUID> ids = new List<UUID>(scripts.Count);
4269 foreach (TaskInventoryItem script in scripts)
4270 {
4271 if (!ids.Contains(script.ItemID))
4272 {
4273 ids.Add(script.ItemID);
4274 }
4275 }
4276 // Offer the list of script UUIDs to each engine found and accumulate the time
4277 foreach (IScriptModule e in engines)
4278 {
4279 if (e != null)
4280 {
4281 time += e.GetScriptExecutionTime(ids);
4282 }
4283 }
4284 return time;
4285 }
4286
4287 /// <summary>
4288 /// Returns a count of the number of running scripts in this groups parts.
4289 /// </summary>
4290 public int RunningScriptCount()
4291 {
4292 int count = 0;
4293 SceneObjectPart[] parts = m_parts.GetArray();
4294 for (int i = 0; i < parts.Length; i++)
4295 count += parts[i].Inventory.RunningScriptCount();
4296
4297 return count;
4298 }
4299
4191 public override string ToString() 4300 public override string ToString()
4192 { 4301 {
4193 return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition); 4302 return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition);
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 8e74dc8..f1e781c 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -1016,7 +1016,18 @@ namespace OpenSim.Region.Framework.Scenes
1016 public int LinkNum 1016 public int LinkNum
1017 { 1017 {
1018 get { return m_linkNum; } 1018 get { return m_linkNum; }
1019 set { m_linkNum = value; } 1019 set
1020 {
1021// if (ParentGroup != null)
1022// {
1023// m_log.DebugFormat(
1024// "[SCENE OBJECT PART]: Setting linknum of {0}@{1} to {2} from {3}",
1025// Name, AbsolutePosition, value, m_linkNum);
1026// Util.PrintCallStack();
1027// }
1028
1029 m_linkNum = value;
1030 }
1020 } 1031 }
1021 1032
1022 public byte ClickAction 1033 public byte ClickAction
@@ -2048,7 +2059,7 @@ namespace OpenSim.Region.Framework.Scenes
2048 else 2059 else
2049 m_log.WarnFormat( 2060 m_log.WarnFormat(
2050 "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data", 2061 "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data",
2051 Name, LocalId, id); 2062 Name, UUID, id);
2052 } 2063 }
2053 2064
2054 /// <summary> 2065 /// <summary>
@@ -2153,6 +2164,9 @@ namespace OpenSim.Region.Framework.Scenes
2153 /// <param name="isNew"></param> 2164 /// <param name="isNew"></param>
2154 public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew) 2165 public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
2155 { 2166 {
2167 if (ParentGroup.Scene == null)
2168 return;
2169
2156 if (!ParentGroup.Scene.PhysicalPrims && UsePhysics) 2170 if (!ParentGroup.Scene.PhysicalPrims && UsePhysics)
2157 return; 2171 return;
2158 2172
@@ -3111,8 +3125,9 @@ namespace OpenSim.Region.Framework.Scenes
3111 if (ParentGroup.IsDeleted) 3125 if (ParentGroup.IsDeleted)
3112 return; 3126 return;
3113 3127
3114 if (ParentGroup.IsAttachment && (ParentGroup.AttachedAvatar != remoteClient.AgentId) && 3128 if (ParentGroup.IsAttachment
3115 (ParentGroup.AttachmentPoint >= 31) && (ParentGroup.AttachmentPoint <= 38)) 3129 && ParentGroup.AttachedAvatar != remoteClient.AgentId
3130 && ParentGroup.HasPrivateAttachmentPoint)
3116 return; 3131 return;
3117 3132
3118 if (remoteClient.AgentId == OwnerID) 3133 if (remoteClient.AgentId == OwnerID)
@@ -3631,7 +3646,6 @@ namespace OpenSim.Region.Framework.Scenes
3631 hasProfileCut = hasDimple; // is it the same thing? 3646 hasProfileCut = hasDimple; // is it the same thing?
3632 } 3647 }
3633 3648
3634
3635 public void SetGroup(UUID groupID, IClientAPI client) 3649 public void SetGroup(UUID groupID, IClientAPI client)
3636 { 3650 {
3637 // Scene.AddNewPrims() calls with client == null so can't use this. 3651 // Scene.AddNewPrims() calls with client == null so can't use this.
@@ -3661,10 +3675,12 @@ namespace OpenSim.Region.Framework.Scenes
3661 3675
3662 public void SetPhysicsAxisRotation() 3676 public void SetPhysicsAxisRotation()
3663 { 3677 {
3664 if (PhysActor != null) 3678 PhysicsActor pa = PhysActor;
3679
3680 if (pa != null)
3665 { 3681 {
3666 PhysActor.LockAngularMotion(RotationAxis); 3682 pa.LockAngularMotion(RotationAxis);
3667 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); 3683 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
3668 } 3684 }
3669 } 3685 }
3670 3686
@@ -4381,7 +4397,7 @@ namespace OpenSim.Region.Framework.Scenes
4381 // For now, we use the NINJA naming scheme for identifying joints. 4397 // For now, we use the NINJA naming scheme for identifying joints.
4382 // In the future, we can support other joint specification schemes such as a 4398 // In the future, we can support other joint specification schemes such as a
4383 // custom checkbox in the viewer GUI. 4399 // custom checkbox in the viewer GUI.
4384 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints) 4400 if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
4385 { 4401 {
4386 string hingeString = "hingejoint"; 4402 string hingeString = "hingejoint";
4387 return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString); 4403 return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString);
@@ -4397,7 +4413,7 @@ namespace OpenSim.Region.Framework.Scenes
4397 // For now, we use the NINJA naming scheme for identifying joints. 4413 // For now, we use the NINJA naming scheme for identifying joints.
4398 // In the future, we can support other joint specification schemes such as a 4414 // In the future, we can support other joint specification schemes such as a
4399 // custom checkbox in the viewer GUI. 4415 // custom checkbox in the viewer GUI.
4400 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints) 4416 if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
4401 { 4417 {
4402 string ballString = "balljoint"; 4418 string ballString = "balljoint";
4403 return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString); 4419 return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString);
@@ -4413,7 +4429,7 @@ namespace OpenSim.Region.Framework.Scenes
4413 // For now, we use the NINJA naming scheme for identifying joints. 4429 // For now, we use the NINJA naming scheme for identifying joints.
4414 // In the future, we can support other joint specification schemes such as a 4430 // In the future, we can support other joint specification schemes such as a
4415 // custom checkbox in the viewer GUI. 4431 // custom checkbox in the viewer GUI.
4416 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints) 4432 if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
4417 { 4433 {
4418 return IsHingeJoint() || IsBallJoint(); 4434 return IsHingeJoint() || IsBallJoint();
4419 } 4435 }
@@ -4534,7 +4550,6 @@ namespace OpenSim.Region.Framework.Scenes
4534 } 4550 }
4535 */ 4551 */
4536 } 4552 }
4537
4538 else // it already has a physical representation 4553 else // it already has a physical representation
4539 { 4554 {
4540 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. 4555 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
@@ -5011,8 +5026,9 @@ namespace OpenSim.Region.Framework.Scenes
5011 if (ParentGroup.IsDeleted) 5026 if (ParentGroup.IsDeleted)
5012 return; 5027 return;
5013 5028
5014 if (ParentGroup.IsAttachment && ((ParentGroup.RootPart != this) || 5029 if (ParentGroup.IsAttachment
5015 ((ParentGroup.AttachedAvatar != remoteClient.AgentId) && (ParentGroup.AttachmentPoint >= 31) && (ParentGroup.AttachmentPoint <= 38)))) 5030 && (ParentGroup.RootPart != this
5031 || ParentGroup.AttachedAvatar != remoteClient.AgentId && ParentGroup.HasPrivateAttachmentPoint))
5016 return; 5032 return;
5017 5033
5018 // Causes this thread to dig into the Client Thread Data. 5034 // Causes this thread to dig into the Client Thread Data.
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 959046a..14ef0fb 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -176,16 +176,14 @@ namespace OpenSim.Region.Framework.Scenes
176 /// <param name="ownerId"></param> 176 /// <param name="ownerId"></param>
177 public void ChangeInventoryOwner(UUID ownerId) 177 public void ChangeInventoryOwner(UUID ownerId)
178 { 178 {
179 m_items.LockItemsForWrite(true); 179 List<TaskInventoryItem> items = GetInventoryItems();
180 if (0 == Items.Count) 180
181 { 181 if (items.Count == 0)
182 m_items.LockItemsForWrite(false);
183 return; 182 return;
184 }
185 183
184 m_items.LockItemsForWrite(true);
186 HasInventoryChanged = true; 185 HasInventoryChanged = true;
187 m_part.ParentGroup.HasGroupChanged = true; 186 m_part.ParentGroup.HasGroupChanged = true;
188 List<TaskInventoryItem> items = GetInventoryItems();
189 foreach (TaskInventoryItem item in items) 187 foreach (TaskInventoryItem item in items)
190 { 188 {
191 if (ownerId != item.OwnerID) 189 if (ownerId != item.OwnerID)
@@ -262,19 +260,16 @@ namespace OpenSim.Region.Framework.Scenes
262 Items.LockItemsForRead(false); 260 Items.LockItemsForRead(false);
263 } 261 }
264 262
265 /// <summary> 263 public int CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
266 /// Start all the scripts contained in this prim's inventory
267 /// </summary>
268 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
269 { 264 {
270 Items.LockItemsForRead(true); 265 int scriptsValidForStarting = 0;
271 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 266
272 Items.LockItemsForRead(false); 267 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
273 foreach (TaskInventoryItem item in items) 268 foreach (TaskInventoryItem item in scripts)
274 { 269 if (CreateScriptInstance(item, startParam, postOnRez, engine, stateSource))
275 if ((int)InventoryType.LSL == item.InvType) 270 scriptsValidForStarting++;
276 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 271
277 } 272 return scriptsValidForStarting;
278 } 273 }
279 274
280 public ArrayList GetScriptErrors(UUID itemID) 275 public ArrayList GetScriptErrors(UUID itemID)
@@ -305,17 +300,11 @@ namespace OpenSim.Region.Framework.Scenes
305 /// </param> 300 /// </param>
306 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 301 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
307 { 302 {
308 Items.LockItemsForRead(true); 303 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
309 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 304 foreach (TaskInventoryItem item in scripts)
310 Items.LockItemsForRead(false);
311
312 foreach (TaskInventoryItem item in items)
313 { 305 {
314 if ((int)InventoryType.LSL == item.InvType) 306 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
315 { 307 m_part.RemoveScriptEvents(item.ItemID);
316 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
317 m_part.RemoveScriptEvents(item.ItemID);
318 }
319 } 308 }
320 } 309 }
321 310
@@ -323,8 +312,8 @@ namespace OpenSim.Region.Framework.Scenes
323 /// Start a script which is in this prim's inventory. 312 /// Start a script which is in this prim's inventory.
324 /// </summary> 313 /// </summary>
325 /// <param name="item"></param> 314 /// <param name="item"></param>
326 /// <returns></returns> 315 /// <returns>true if the script instance was created, false otherwise</returns>
327 public void CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez, string engine, int stateSource) 316 public bool CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez, string engine, int stateSource)
328 { 317 {
329// m_log.DebugFormat("[PRIM INVENTORY]: Starting script {0} {1} in prim {2} {3} in {4}", 318// m_log.DebugFormat("[PRIM INVENTORY]: Starting script {0} {1} in prim {2} {3} in {4}",
330// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName); 319// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName);
@@ -332,61 +321,70 @@ namespace OpenSim.Region.Framework.Scenes
332 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 321 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
333 { 322 {
334 StoreScriptError(item.ItemID, "no permission"); 323 StoreScriptError(item.ItemID, "no permission");
335 return; 324 return false;
336 } 325 }
337 326
338 m_part.AddFlag(PrimFlags.Scripted); 327 m_part.AddFlag(PrimFlags.Scripted);
339 328
340 if (!m_part.ParentGroup.Scene.RegionInfo.RegionSettings.DisableScripts) 329 if (m_part.ParentGroup.Scene.RegionInfo.RegionSettings.DisableScripts)
330 return false;
331
332 if (stateSource == 2 && // Prim crossing
333 m_part.ParentGroup.Scene.m_trustBinaries)
341 { 334 {
342 if (stateSource == 2 && // Prim crossing 335 m_items.LockItemsForWrite(true);
343 m_part.ParentGroup.Scene.m_trustBinaries) 336 m_items[item.ItemID].PermsMask = 0;
344 { 337 m_items[item.ItemID].PermsGranter = UUID.Zero;
345 m_items.LockItemsForWrite(true); 338 m_items.LockItemsForWrite(false);
346 m_items[item.ItemID].PermsMask = 0; 339 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
347 m_items[item.ItemID].PermsGranter = UUID.Zero; 340 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
348 m_items.LockItemsForWrite(false); 341 StoreScriptErrors(item.ItemID, null);
349 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 342 m_part.ParentGroup.AddActiveScriptCount(1);
350 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 343 m_part.ScheduleFullUpdate();
351 StoreScriptErrors(item.ItemID, null); 344 return true;
352 m_part.ParentGroup.AddActiveScriptCount(1); 345 }
353 m_part.ScheduleFullUpdate();
354 return;
355 }
356 346
357 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); 347 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
358 if (null == asset) 348 if (null == asset)
359 { 349 {
360 string msg = String.Format("asset ID {0} could not be found", item.AssetID); 350 m_log.ErrorFormat(
361 StoreScriptError(item.ItemID, msg); 351 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
362 m_log.ErrorFormat( 352 item.Name, item.ItemID, m_part.AbsolutePosition,
353 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
354
355 return false;
356 }
357 else
358 {
359 if (m_part.ParentGroup.m_savedScriptState != null)
360 item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
361
362 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
363 StoreScriptError(item.ItemID, msg);
364 m_log.ErrorFormat(
363 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 365 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
364 item.Name, item.ItemID, m_part.AbsolutePosition, 366 item.Name, item.ItemID, m_part.AbsolutePosition,
365 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); 367 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
366 }
367 else
368 {
369 if (m_part.ParentGroup.m_savedScriptState != null)
370 item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
371 368
372 m_items.LockItemsForWrite(true); 369 m_items.LockItemsForWrite(true);
373 370
374 m_items[item.ItemID].OldItemID = item.OldItemID; 371 m_items[item.ItemID].OldItemID = item.OldItemID;
375 m_items[item.ItemID].PermsMask = 0; 372 m_items[item.ItemID].PermsMask = 0;
376 m_items[item.ItemID].PermsGranter = UUID.Zero; 373 m_items[item.ItemID].PermsGranter = UUID.Zero;
377 374
378 m_items.LockItemsForWrite(false); 375 m_items.LockItemsForWrite(false);
379 376
380 string script = Utils.BytesToString(asset.Data); 377 string script = Utils.BytesToString(asset.Data);
381 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 378 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
382 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 379 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
383 StoreScriptErrors(item.ItemID, null); 380 StoreScriptErrors(item.ItemID, null);
384 if (!item.ScriptRunning) 381 if (!item.ScriptRunning)
385 m_part.ParentGroup.Scene.EventManager.TriggerStopScript( 382 m_part.ParentGroup.Scene.EventManager.TriggerStopScript(
386 m_part.LocalId, item.ItemID); 383 m_part.LocalId, item.ItemID);
387 m_part.ParentGroup.AddActiveScriptCount(1); 384 m_part.ParentGroup.AddActiveScriptCount(1);
388 m_part.ScheduleFullUpdate(); 385 m_part.ScheduleFullUpdate();
389 } 386
387 return true;
390 } 388 }
391 } 389 }
392 390
@@ -459,7 +457,7 @@ namespace OpenSim.Region.Framework.Scenes
459 /// <param name="itemId"> 457 /// <param name="itemId">
460 /// A <see cref="UUID"/> 458 /// A <see cref="UUID"/>
461 /// </param> 459 /// </param>
462 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 460 public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
463 { 461 {
464 lock (m_scriptErrors) 462 lock (m_scriptErrors)
465 { 463 {
@@ -467,6 +465,7 @@ namespace OpenSim.Region.Framework.Scenes
467 m_scriptErrors.Remove(itemId); 465 m_scriptErrors.Remove(itemId);
468 } 466 }
469 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); 467 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
468 return true;
470 } 469 }
471 470
472 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 471 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
@@ -770,14 +769,22 @@ namespace OpenSim.Region.Framework.Scenes
770 return item; 769 return item;
771 } 770 }
772 771
773 /// <summary> 772 public TaskInventoryItem GetInventoryItem(string name)
774 /// Get inventory items by name. 773 {
775 /// </summary> 774 m_items.LockItemsForRead(true);
776 /// <param name="name"></param> 775 foreach (TaskInventoryItem item in m_items.Values)
777 /// <returns> 776 {
778 /// A list of inventory items with that name. 777 if (item.Name == name)
779 /// If no inventory item has that name then an empty list is returned. 778 {
780 /// </returns> 779 m_items.LockItemsForRead(false);
780 return item;
781 }
782 }
783 m_items.LockItemsForRead(false);
784
785 return null;
786 }
787
781 public List<TaskInventoryItem> GetInventoryItems(string name) 788 public List<TaskInventoryItem> GetInventoryItems(string name)
782 { 789 {
783 List<TaskInventoryItem> items = new List<TaskInventoryItem>(); 790 List<TaskInventoryItem> items = new List<TaskInventoryItem>();
@@ -1247,10 +1254,10 @@ namespace OpenSim.Region.Framework.Scenes
1247 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 1254 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1248 item.CurrentPermissions &= ~(uint)PermissionMask.Modify; 1255 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1249 } 1256 }
1250 item.OwnerChanged = true;
1251 item.CurrentPermissions &= item.NextPermissions; 1257 item.CurrentPermissions &= item.NextPermissions;
1252 item.BasePermissions &= item.NextPermissions; 1258 item.BasePermissions &= item.NextPermissions;
1253 item.EveryonePermissions &= item.NextPermissions; 1259 item.EveryonePermissions &= item.NextPermissions;
1260 item.OwnerChanged = true;
1254 item.PermsMask = 0; 1261 item.PermsMask = 0;
1255 item.PermsGranter = UUID.Zero; 1262 item.PermsGranter = UUID.Zero;
1256 } 1263 }
@@ -1281,9 +1288,57 @@ namespace OpenSim.Region.Framework.Scenes
1281 return true; 1288 return true;
1282 } 1289 }
1283 } 1290 }
1291
1284 return false; 1292 return false;
1285 } 1293 }
1286 1294
1295 /// <summary>
1296 /// Returns the count of scripts in this parts inventory.
1297 /// </summary>
1298 /// <returns></returns>
1299 public int ScriptCount()
1300 {
1301 int count = 0;
1302 Items.LockItemsForRead(true);
1303 foreach (TaskInventoryItem item in m_items.Values)
1304 {
1305 if (item.InvType == (int)InventoryType.LSL)
1306 {
1307 count++;
1308 }
1309 }
1310 Items.LockItemsForRead(false);
1311 return count;
1312 }
1313 /// <summary>
1314 /// Returns the count of running scripts in this parts inventory.
1315 /// </summary>
1316 /// <returns></returns>
1317 public int RunningScriptCount()
1318 {
1319 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
1320 if (engines.Length == 0)
1321 return 0;
1322
1323 int count = 0;
1324 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
1325
1326 foreach (TaskInventoryItem item in scripts)
1327 {
1328 foreach (IScriptModule engine in engines)
1329 {
1330 if (engine != null)
1331 {
1332 if (engine.GetScriptState(item.ItemID))
1333 {
1334 count++;
1335 }
1336 }
1337 }
1338 }
1339 return count;
1340 }
1341
1287 public List<UUID> GetInventoryList() 1342 public List<UUID> GetInventoryList()
1288 { 1343 {
1289 List<UUID> ret = new List<UUID>(); 1344 List<UUID> ret = new List<UUID>();
@@ -1298,22 +1353,24 @@ namespace OpenSim.Region.Framework.Scenes
1298 { 1353 {
1299 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1354 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1300 1355
1301 lock (m_items) 1356 Items.LockItemsForRead(true);
1302 ret = new List<TaskInventoryItem>(m_items.Values); 1357 ret = new List<TaskInventoryItem>(m_items.Values);
1358 Items.LockItemsForRead(false);
1303 1359
1304 return ret; 1360 return ret;
1305 } 1361 }
1306 1362
1307 public List<TaskInventoryItem> GetInventoryScripts() 1363 public List<TaskInventoryItem> GetInventoryItems(InventoryType type)
1308 { 1364 {
1309 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1365 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1310 1366
1311 lock (m_items) 1367 Items.LockItemsForRead(true);
1312 { 1368
1313 foreach (TaskInventoryItem item in m_items.Values) 1369 foreach (TaskInventoryItem item in m_items.Values)
1314 if (item.InvType == (int)InventoryType.LSL) 1370 if (item.InvType == (int)type)
1315 ret.Add(item); 1371 ret.Add(item);
1316 } 1372
1373 Items.LockItemsForRead(false);
1317 1374
1318 return ret; 1375 return ret;
1319 } 1376 }
@@ -1335,35 +1392,32 @@ namespace OpenSim.Region.Framework.Scenes
1335 if (engines.Length == 0) // No engine at all 1392 if (engines.Length == 0) // No engine at all
1336 return ret; 1393 return ret;
1337 1394
1338 Items.LockItemsForRead(true); 1395 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
1339 foreach (TaskInventoryItem item in m_items.Values) 1396
1397 foreach (TaskInventoryItem item in scripts)
1340 { 1398 {
1341 if (item.InvType == (int)InventoryType.LSL) 1399 foreach (IScriptModule e in engines)
1342 { 1400 {
1343 foreach (IScriptModule e in engines) 1401 if (e != null)
1344 { 1402 {
1345 if (e != null) 1403 string n = e.GetXMLState(item.ItemID);
1404 if (n != String.Empty)
1346 { 1405 {
1347 string n = e.GetXMLState(item.ItemID); 1406 if (oldIDs)
1348 if (n != String.Empty)
1349 { 1407 {
1350 if (oldIDs) 1408 if (!ret.ContainsKey(item.OldItemID))
1351 { 1409 ret[item.OldItemID] = n;
1352 if (!ret.ContainsKey(item.OldItemID))
1353 ret[item.OldItemID] = n;
1354 }
1355 else
1356 {
1357 if (!ret.ContainsKey(item.ItemID))
1358 ret[item.ItemID] = n;
1359 }
1360 break;
1361 } 1410 }
1411 else
1412 {
1413 if (!ret.ContainsKey(item.ItemID))
1414 ret[item.ItemID] = n;
1415 }
1416 break;
1362 } 1417 }
1363 } 1418 }
1364 } 1419 }
1365 } 1420 }
1366 Items.LockItemsForRead(false);
1367 return ret; 1421 return ret;
1368 } 1422 }
1369 1423
@@ -1373,27 +1427,27 @@ namespace OpenSim.Region.Framework.Scenes
1373 if (engines.Length == 0) 1427 if (engines.Length == 0)
1374 return; 1428 return;
1375 1429
1430 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
1376 1431
1377 Items.LockItemsForRead(true); 1432 foreach (TaskInventoryItem item in scripts)
1378
1379 foreach (TaskInventoryItem item in m_items.Values)
1380 { 1433 {
1381 if (item.InvType == (int)InventoryType.LSL) 1434 foreach (IScriptModule engine in engines)
1382 { 1435 {
1383 foreach (IScriptModule engine in engines) 1436 if (engine != null)
1384 { 1437 {
1385 if (engine != null) 1438// m_log.DebugFormat(
1386 { 1439// "[PRIM INVENTORY]: Resuming script {0} {1} for {2}, OwnerChanged {3}",
1387 if (item.OwnerChanged) 1440// item.Name, item.ItemID, item.OwnerID, item.OwnerChanged);
1388 engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER }); 1441
1389 item.OwnerChanged = false; 1442 engine.ResumeScript(item.ItemID);
1390 engine.ResumeScript(item.ItemID); 1443
1391 } 1444 if (item.OwnerChanged)
1445 engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER });
1446
1447 item.OwnerChanged = false;
1392 } 1448 }
1393 } 1449 }
1394 } 1450 }
1395
1396 Items.LockItemsForRead(false);
1397 } 1451 }
1398 } 1452 }
1399} 1453}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 87b4d9f..159a92a 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -45,6 +45,7 @@ using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags;
45 45
46namespace OpenSim.Region.Framework.Scenes 46namespace OpenSim.Region.Framework.Scenes
47{ 47{
48 [Flags]
48 enum ScriptControlled : uint 49 enum ScriptControlled : uint
49 { 50 {
50 CONTROL_ZERO = 0, 51 CONTROL_ZERO = 0,
@@ -76,6 +77,11 @@ namespace OpenSim.Region.Framework.Scenes
76// { 77// {
77// m_log.Debug("[SCENE PRESENCE] Destructor called"); 78// m_log.Debug("[SCENE PRESENCE] Destructor called");
78// } 79// }
80 private void TriggerScenePresenceUpdated()
81 {
82 if (m_scene != null)
83 m_scene.EventManager.TriggerScenePresenceUpdated(this);
84 }
79 85
80 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 86 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
81 87
@@ -497,6 +503,7 @@ namespace OpenSim.Region.Framework.Scenes
497 //m_log.DebugFormat( 503 //m_log.DebugFormat(
498 // "[ENTITY BASE]: In {0} set AbsolutePosition of {1} to {2}", 504 // "[ENTITY BASE]: In {0} set AbsolutePosition of {1} to {2}",
499 // Scene.RegionInfo.RegionName, Name, m_pos); 505 // Scene.RegionInfo.RegionName, Name, m_pos);
506 TriggerScenePresenceUpdated();
500 } 507 }
501 } 508 }
502 509
@@ -516,6 +523,7 @@ namespace OpenSim.Region.Framework.Scenes
516 return; 523 return;
517 524
518 m_pos = value; 525 m_pos = value;
526 TriggerScenePresenceUpdated();
519 } 527 }
520 } 528 }
521 529
@@ -1086,23 +1094,13 @@ namespace OpenSim.Region.Framework.Scenes
1086 /// <param name="pos"></param> 1094 /// <param name="pos"></param>
1087 public void Teleport(Vector3 pos) 1095 public void Teleport(Vector3 pos)
1088 { 1096 {
1089 bool isFlying = Flying; 1097 TeleportWithMomentum(pos, Vector3.Zero);
1090 RemoveFromPhysicalScene();
1091 Velocity = Vector3.Zero;
1092 CheckLandingPoint(ref pos);
1093 AbsolutePosition = pos;
1094 AddToPhysicalScene(isFlying);
1095
1096 SendTerseUpdateToAllClients();
1097 }
1098
1099 public void TeleportWithMomentum(Vector3 pos)
1100 {
1101 TeleportWithMomentum(pos, null);
1102 } 1098 }
1103 1099
1104 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1100 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
1105 { 1101 {
1102 if (ParentID != (uint)0)
1103 StandUp();
1106 bool isFlying = Flying; 1104 bool isFlying = Flying;
1107 Vector3 vel = Velocity; 1105 Vector3 vel = Velocity;
1108 RemoveFromPhysicalScene(); 1106 RemoveFromPhysicalScene();
@@ -1282,17 +1280,33 @@ namespace OpenSim.Region.Framework.Scenes
1282 1280
1283 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1281 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1284 MakeRootAgent(AbsolutePosition, flying); 1282 MakeRootAgent(AbsolutePosition, flying);
1283 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look);
1284
1285// m_log.DebugFormat("[SCENE PRESENCE] Completed movement");
1285 1286
1286 if ((m_callbackURI != null) && !m_callbackURI.Equals("")) 1287 if ((m_callbackURI != null) && !m_callbackURI.Equals(""))
1287 { 1288 {
1288 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); 1289 // We cannot sleep here since this would hold up the inbound packet processing thread, as
1290 // CompleteMovement() is executed synchronously. However, it might be better to delay the release
1291 // here until we know for sure that the agent is active in this region. Sending AgentMovementComplete
1292 // is not enough for Imprudence clients - there appears to be a small delay (<200ms, <500ms) until they regard this
1293 // region as the current region, meaning that a close sent before then will fail the teleport.
1294// System.Threading.Thread.Sleep(2000);
1295
1296 m_log.DebugFormat(
1297 "[SCENE PRESENCE]: Releasing {0} {1} with callback to {2}",
1298 client.Name, client.AgentId, m_callbackURI);
1299
1289 Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI); 1300 Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI);
1290 m_callbackURI = null; 1301 m_callbackURI = null;
1291 } 1302 }
1303// else
1304// {
1305// m_log.DebugFormat(
1306// "[SCENE PRESENCE]: No callback provided on CompleteMovement of {0} {1} to {2}",
1307// client.Name, client.AgentId, m_scene.RegionInfo.RegionName);
1308// }
1292 1309
1293// m_log.DebugFormat("[SCENE PRESENCE] Completed movement");
1294
1295 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look);
1296 ValidateAndSendAppearanceAndAgentData(); 1310 ValidateAndSendAppearanceAndAgentData();
1297 1311
1298 // Create child agents in neighbouring regions 1312 // Create child agents in neighbouring regions
@@ -1307,7 +1321,6 @@ namespace OpenSim.Region.Framework.Scenes
1307 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1321 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1308 } 1322 }
1309 1323
1310
1311// m_log.DebugFormat( 1324// m_log.DebugFormat(
1312// "[SCENE PRESENCE]: Completing movement of {0} into region {1} took {2}ms", 1325// "[SCENE PRESENCE]: Completing movement of {0} into region {1} took {2}ms",
1313// client.Name, Scene.RegionInfo.RegionName, (DateTime.Now - startTime).Milliseconds); 1326// client.Name, Scene.RegionInfo.RegionName, (DateTime.Now - startTime).Milliseconds);
@@ -1360,7 +1373,7 @@ namespace OpenSim.Region.Framework.Scenes
1360 { 1373 {
1361// m_log.DebugFormat( 1374// m_log.DebugFormat(
1362// "[SCENE PRESENCE]: In {0} received agent update from {1}, flags {2}", 1375// "[SCENE PRESENCE]: In {0} received agent update from {1}, flags {2}",
1363// Scene.RegionInfo.RegionName, remoteClient.Name, agentData.ControlFlags); 1376// Scene.RegionInfo.RegionName, remoteClient.Name, (AgentManager.ControlFlags)agentData.ControlFlags);
1364 1377
1365 if (IsChildAgent) 1378 if (IsChildAgent)
1366 { 1379 {
@@ -1470,14 +1483,8 @@ namespace OpenSim.Region.Framework.Scenes
1470 } 1483 }
1471 } 1484 }
1472 1485
1473 lock (scriptedcontrols) 1486 uint flagsForScripts = (uint)flags;
1474 { 1487 flags = RemoveIgnoredControls(flags, IgnoredControls);
1475 if (scriptedcontrols.Count > 0)
1476 {
1477 SendControlToScripts((uint)flags);
1478 flags = RemoveIgnoredControls(flags, IgnoredControls);
1479 }
1480 }
1481 1488
1482 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1489 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1483 HandleAgentSitOnGround(); 1490 HandleAgentSitOnGround();
@@ -1491,6 +1498,7 @@ namespace OpenSim.Region.Framework.Scenes
1491 PhysicsActor actor = PhysicsActor; 1498 PhysicsActor actor = PhysicsActor;
1492 if (actor == null) 1499 if (actor == null)
1493 { 1500 {
1501 SendControlsToScripts(flagsForScripts);
1494 return; 1502 return;
1495 } 1503 }
1496 1504
@@ -1570,7 +1578,7 @@ namespace OpenSim.Region.Framework.Scenes
1570 MovementFlag |= (byte)nudgehack; 1578 MovementFlag |= (byte)nudgehack;
1571 } 1579 }
1572 1580
1573// m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF); 1581 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF);
1574 MovementFlag += (byte)(uint)DCF; 1582 MovementFlag += (byte)(uint)DCF;
1575 update_movementflag = true; 1583 update_movementflag = true;
1576 } 1584 }
@@ -1583,7 +1591,7 @@ namespace OpenSim.Region.Framework.Scenes
1583 && ((MovementFlag & (byte)nudgehack) == nudgehack)) 1591 && ((MovementFlag & (byte)nudgehack) == nudgehack))
1584 ) // This or is for Nudge forward 1592 ) // This or is for Nudge forward
1585 { 1593 {
1586// m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with lack of {1}", Name, DCF); 1594 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with lack of {1}", Name, DCF);
1587 MovementFlag -= ((byte)(uint)DCF); 1595 MovementFlag -= ((byte)(uint)DCF);
1588 update_movementflag = true; 1596 update_movementflag = true;
1589 1597
@@ -1664,11 +1672,14 @@ namespace OpenSim.Region.Framework.Scenes
1664// } 1672// }
1665// } 1673// }
1666 1674
1667// if (update_movementflag && ParentID == 0) 1675 if (update_movementflag && ParentID == 0)
1668// Animator.UpdateMovementAnimations(); 1676 Animator.UpdateMovementAnimations();
1677
1678 SendControlsToScripts(flagsForScripts);
1669 } 1679 }
1670 1680
1671 m_scene.EventManager.TriggerOnClientMovement(this); 1681 m_scene.EventManager.TriggerOnClientMovement(this);
1682 TriggerScenePresenceUpdated();
1672 } 1683 }
1673 1684
1674 /// <summary> 1685 /// <summary>
@@ -2042,9 +2053,9 @@ namespace OpenSim.Region.Framework.Scenes
2042 { 2053 {
2043 if (SitTargetUnOccupied) 2054 if (SitTargetUnOccupied)
2044 { 2055 {
2045 m_log.DebugFormat( 2056// m_log.DebugFormat(
2046 "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", 2057// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied",
2047 Name, part.Name, part.LocalId); 2058// Name, part.Name, part.LocalId);
2048 2059
2049 part.SitTargetAvatar = UUID; 2060 part.SitTargetAvatar = UUID;
2050 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 2061 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z);
@@ -2056,9 +2067,9 @@ namespace OpenSim.Region.Framework.Scenes
2056 { 2067 {
2057 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2068 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
2058 { 2069 {
2059 m_log.DebugFormat( 2070// m_log.DebugFormat(
2060 "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m", 2071// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
2061 Name, part.Name, part.LocalId); 2072// Name, part.Name, part.LocalId);
2062 2073
2063 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2074 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
2064 canSit = true; 2075 canSit = true;
@@ -2614,6 +2625,7 @@ namespace OpenSim.Region.Framework.Scenes
2614 2625
2615 m_scene.ForEachClient(SendTerseUpdateToClient); 2626 m_scene.ForEachClient(SendTerseUpdateToClient);
2616 } 2627 }
2628 TriggerScenePresenceUpdated();
2617 } 2629 }
2618 2630
2619 public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs) 2631 public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
@@ -2692,7 +2704,7 @@ namespace OpenSim.Region.Framework.Scenes
2692 // If we are using the the cached appearance then send it out to everyone 2704 // If we are using the the cached appearance then send it out to everyone
2693 if (cachedappearance) 2705 if (cachedappearance)
2694 { 2706 {
2695 m_log.DebugFormat("[SCENEPRESENCE]: baked textures are in the cache for {0}", Name); 2707 m_log.DebugFormat("[SCENE PRESENCE]: baked textures are in the cache for {0}", Name);
2696 2708
2697 // If the avatars baked textures are all in the cache, then we have a 2709 // If the avatars baked textures are all in the cache, then we have a
2698 // complete appearance... send it out, if not, then we'll send it when 2710 // complete appearance... send it out, if not, then we'll send it when
@@ -3097,8 +3109,8 @@ namespace OpenSim.Region.Framework.Scenes
3097 x = x / Constants.RegionSize; 3109 x = x / Constants.RegionSize;
3098 y = y / Constants.RegionSize; 3110 y = y / Constants.RegionSize;
3099 3111
3100 //m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); 3112// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
3101 //m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); 3113// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
3102 if (Util.IsOutsideView(DrawDistance, x, newRegionX, y, newRegionY)) 3114 if (Util.IsOutsideView(DrawDistance, x, newRegionX, y, newRegionY))
3103 { 3115 {
3104 byebyeRegions.Add(handle); 3116 byebyeRegions.Add(handle);
@@ -3155,7 +3167,7 @@ namespace OpenSim.Region.Framework.Scenes
3155 3167
3156 public void ChildAgentDataUpdate(AgentData cAgentData) 3168 public void ChildAgentDataUpdate(AgentData cAgentData)
3157 { 3169 {
3158 //m_log.Debug(" >>> ChildAgentDataUpdate <<< " + Scene.RegionInfo.RegionName); 3170// m_log.Debug(" >>> ChildAgentDataUpdate <<< " + Scene.RegionInfo.RegionName);
3159 if (!IsChildAgent) 3171 if (!IsChildAgent)
3160 return; 3172 return;
3161 3173
@@ -3267,31 +3279,8 @@ namespace OpenSim.Region.Framework.Scenes
3267 catch { } 3279 catch { }
3268 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation; 3280 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation;
3269 3281
3270 // Attachment objects 3282 if (Scene.AttachmentsModule != null)
3271 List<SceneObjectGroup> attachments = GetAttachments(); 3283 Scene.AttachmentsModule.CopyAttachments(this, cAgent);
3272 if (attachments.Count > 0)
3273 {
3274 cAgent.AttachmentObjects = new List<ISceneObject>();
3275 cAgent.AttachmentObjectStates = new List<string>();
3276// IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
3277 InTransitScriptStates.Clear();
3278
3279 foreach (SceneObjectGroup sog in attachments)
3280 {
3281 // We need to make a copy and pass that copy
3282 // because of transfers withn the same sim
3283 ISceneObject clone = sog.CloneForNewScene();
3284 // Attachment module assumes that GroupPosition holds the offsets...!
3285 ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos;
3286 ((SceneObjectGroup)clone).IsAttachment = false;
3287 cAgent.AttachmentObjects.Add(clone);
3288 string state = sog.GetStateSnapshot();
3289 cAgent.AttachmentObjectStates.Add(state);
3290 InTransitScriptStates.Add(state);
3291 // Let's remove the scripts of the original object here
3292 sog.RemoveScriptInstances(true);
3293 }
3294 }
3295 } 3284 }
3296 3285
3297 private void CopyFrom(AgentData cAgent) 3286 private void CopyFrom(AgentData cAgent)
@@ -3299,6 +3288,9 @@ namespace OpenSim.Region.Framework.Scenes
3299 m_originRegionID = cAgent.RegionID; 3288 m_originRegionID = cAgent.RegionID;
3300 3289
3301 m_callbackURI = cAgent.CallbackURI; 3290 m_callbackURI = cAgent.CallbackURI;
3291// m_log.DebugFormat(
3292// "[SCENE PRESENCE]: Set callback for {0} in {1} to {2} in CopyFrom()",
3293// Name, m_scene.RegionInfo.RegionName, m_callbackURI);
3302 3294
3303 m_pos = cAgent.Position; 3295 m_pos = cAgent.Position;
3304 m_velocity = cAgent.Velocity; 3296 m_velocity = cAgent.Velocity;
@@ -3363,18 +3355,8 @@ namespace OpenSim.Region.Framework.Scenes
3363 if (cAgent.DefaultAnim != null) 3355 if (cAgent.DefaultAnim != null)
3364 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero); 3356 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
3365 3357
3366 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0) 3358 if (Scene.AttachmentsModule != null)
3367 { 3359 Scene.AttachmentsModule.CopyAttachments(cAgent, this);
3368 m_attachments = new List<SceneObjectGroup>();
3369 int i = 0;
3370 foreach (ISceneObject so in cAgent.AttachmentObjects)
3371 {
3372 ((SceneObjectGroup)so).LocalId = 0;
3373 ((SceneObjectGroup)so).RootPart.ClearUpdateSchedule();
3374 so.SetState(cAgent.AttachmentObjectStates[i++], m_scene);
3375 m_scene.IncomingCreateObject(Vector3.Zero, so);
3376 }
3377 }
3378 } 3360 }
3379 3361
3380 public bool CopyAgent(out IAgentData agent) 3362 public bool CopyAgent(out IAgentData agent)
@@ -3400,6 +3382,7 @@ namespace OpenSim.Region.Framework.Scenes
3400 Velocity = force; 3382 Velocity = force;
3401 3383
3402 m_forceToApply = null; 3384 m_forceToApply = null;
3385 TriggerScenePresenceUpdated();
3403 } 3386 }
3404 } 3387 }
3405 3388
@@ -3507,23 +3490,53 @@ namespace OpenSim.Region.Framework.Scenes
3507 3490
3508 RaiseCollisionScriptEvents(coldata); 3491 RaiseCollisionScriptEvents(coldata);
3509 3492
3510 if (Invulnerable || GodLevel >= 200) 3493 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3494 if (Invulnerable || GodLevel > 0)
3511 return; 3495 return;
3512 3496
3497 // The following may be better in the ICombatModule
3498 // probably tweaking of the values for ground and normal prim collisions will be needed
3513 float starthealth = Health; 3499 float starthealth = Health;
3514 uint killerObj = 0; 3500 uint killerObj = 0;
3501 SceneObjectPart part = null;
3515 foreach (uint localid in coldata.Keys) 3502 foreach (uint localid in coldata.Keys)
3516 { 3503 {
3517 SceneObjectPart part = Scene.GetSceneObjectPart(localid); 3504 if (localid == 0)
3518 3505 {
3519 if (part != null && part.ParentGroup.Damage != -1.0f) 3506 part = null;
3520 Health -= part.ParentGroup.Damage; 3507 }
3508 else
3509 {
3510 part = Scene.GetSceneObjectPart(localid);
3511 }
3512 if (part != null)
3513 {
3514 // Ignore if it has been deleted or volume detect
3515 if (!part.ParentGroup.IsDeleted && !part.ParentGroup.IsVolumeDetect)
3516 {
3517 if (part.ParentGroup.Damage > 0.0f)
3518 {
3519 // Something with damage...
3520 Health -= part.ParentGroup.Damage;
3521 part.ParentGroup.Scene.DeleteSceneObject(part.ParentGroup, false);
3522 }
3523 else
3524 {
3525 // An ordinary prim
3526 if (coldata[localid].PenetrationDepth >= 0.10f)
3527 Health -= coldata[localid].PenetrationDepth * 5.0f;
3528 }
3529 }
3530 }
3521 else 3531 else
3522 { 3532 {
3523 if (coldata[localid].PenetrationDepth >= 0.10f) 3533 // 0 is the ground
3534 // what about collisions with other avatars?
3535 if (localid == 0 && coldata[localid].PenetrationDepth >= 0.10f)
3524 Health -= coldata[localid].PenetrationDepth * 5.0f; 3536 Health -= coldata[localid].PenetrationDepth * 5.0f;
3525 } 3537 }
3526 3538
3539
3527 if (Health <= 0.0f) 3540 if (Health <= 0.0f)
3528 { 3541 {
3529 if (localid != 0) 3542 if (localid != 0)
@@ -3539,7 +3552,16 @@ namespace OpenSim.Region.Framework.Scenes
3539 ControllingClient.SendHealth(Health); 3552 ControllingClient.SendHealth(Health);
3540 } 3553 }
3541 if (Health <= 0) 3554 if (Health <= 0)
3555 {
3542 m_scene.EventManager.TriggerAvatarKill(killerObj, this); 3556 m_scene.EventManager.TriggerAvatarKill(killerObj, this);
3557 }
3558 if (starthealth == Health && Health < 100.0f)
3559 {
3560 Health += 0.03f;
3561 if (Health > 100.0f)
3562 Health = 100.0f;
3563 ControllingClient.SendHealth(Health);
3564 }
3543 } 3565 }
3544 } 3566 }
3545 3567
@@ -3551,9 +3573,6 @@ namespace OpenSim.Region.Framework.Scenes
3551 3573
3552 public void Close() 3574 public void Close()
3553 { 3575 {
3554 if (!IsChildAgent)
3555 m_scene.AttachmentsModule.DeleteAttachmentsFromScene(this, false);
3556
3557 // Clear known regions 3576 // Clear known regions
3558 KnownRegions = new Dictionary<ulong, string>(); 3577 KnownRegions = new Dictionary<ulong, string>();
3559 3578
@@ -3621,6 +3640,63 @@ namespace OpenSim.Region.Framework.Scenes
3621 return m_attachments.Count > 0; 3640 return m_attachments.Count > 0;
3622 } 3641 }
3623 3642
3643 /// <summary>
3644 /// Returns the total count of scripts in all parts inventories.
3645 /// </summary>
3646 public int ScriptCount()
3647 {
3648 int count = 0;
3649 lock (m_attachments)
3650 {
3651 foreach (SceneObjectGroup gobj in m_attachments)
3652 {
3653 if (gobj != null)
3654 {
3655 count += gobj.ScriptCount();
3656 }
3657 }
3658 }
3659 return count;
3660 }
3661
3662 /// <summary>
3663 /// A float the value is a representative execution time in milliseconds of all scripts in all attachments.
3664 /// </summary>
3665 public float ScriptExecutionTime()
3666 {
3667 float time = 0.0f;
3668 lock (m_attachments)
3669 {
3670 foreach (SceneObjectGroup gobj in m_attachments)
3671 {
3672 if (gobj != null)
3673 {
3674 time += gobj.ScriptExecutionTime();
3675 }
3676 }
3677 }
3678 return time;
3679 }
3680
3681 /// <summary>
3682 /// Returns the total count of running scripts in all parts.
3683 /// </summary>
3684 public int RunningScriptCount()
3685 {
3686 int count = 0;
3687 lock (m_attachments)
3688 {
3689 foreach (SceneObjectGroup gobj in m_attachments)
3690 {
3691 if (gobj != null)
3692 {
3693 count += gobj.RunningScriptCount();
3694 }
3695 }
3696 }
3697 return count;
3698 }
3699
3624 public bool HasScriptedAttachments() 3700 public bool HasScriptedAttachments()
3625 { 3701 {
3626 lock (m_attachments) 3702 lock (m_attachments)
@@ -3838,77 +3914,92 @@ namespace OpenSim.Region.Framework.Scenes
3838 } 3914 }
3839 } 3915 }
3840 3916
3841 internal void SendControlToScripts(uint flags) 3917 private void SendControlsToScripts(uint flags)
3842 { 3918 {
3843 ScriptControlled allflags = ScriptControlled.CONTROL_ZERO; 3919 // Notify the scripts only after calling UpdateMovementAnimations(), so that if a script
3844 3920 // (e.g., a walking script) checks which animation is active it will be the correct animation.
3845 if (MouseDown) 3921 lock (scriptedcontrols)
3846 { 3922 {
3847 allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON); 3923 if (scriptedcontrols.Count <= 0)
3848 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0) 3924 return;
3925
3926 ScriptControlled allflags = ScriptControlled.CONTROL_ZERO;
3927
3928 if (MouseDown)
3929 {
3930 allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON);
3931 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0)
3932 {
3933 allflags = ScriptControlled.CONTROL_ZERO;
3934 MouseDown = true;
3935 }
3936 }
3937
3938 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0)
3849 { 3939 {
3850 allflags = ScriptControlled.CONTROL_ZERO; 3940 allflags |= ScriptControlled.CONTROL_ML_LBUTTON;
3851 MouseDown = true; 3941 MouseDown = true;
3852 } 3942 }
3853 } 3943
3944 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0)
3945 {
3946 allflags |= ScriptControlled.CONTROL_LBUTTON;
3947 MouseDown = true;
3948 }
3949
3950 // find all activated controls, whether the scripts are interested in them or not
3951 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0)
3952 {
3953 allflags |= ScriptControlled.CONTROL_FWD;
3954 }
3955
3956 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0)
3957 {
3958 allflags |= ScriptControlled.CONTROL_BACK;
3959 }
3960
3961 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0)
3962 {
3963 allflags |= ScriptControlled.CONTROL_UP;
3964 }
3965
3966 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)
3967 {
3968 allflags |= ScriptControlled.CONTROL_DOWN;
3969 }
3854 3970
3855 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0) 3971 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0)
3856 { 3972 {
3857 allflags |= ScriptControlled.CONTROL_ML_LBUTTON; 3973 allflags |= ScriptControlled.CONTROL_LEFT;
3858 MouseDown = true; 3974 }
3859 } 3975
3860 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0) 3976 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0)
3861 { 3977 {
3862 allflags |= ScriptControlled.CONTROL_LBUTTON; 3978 allflags |= ScriptControlled.CONTROL_RIGHT;
3863 MouseDown = true; 3979 }
3864 } 3980
3981 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
3982 {
3983 allflags |= ScriptControlled.CONTROL_ROT_RIGHT;
3984 }
3985
3986 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
3987 {
3988 allflags |= ScriptControlled.CONTROL_ROT_LEFT;
3989 }
3865 3990
3866 // find all activated controls, whether the scripts are interested in them or not 3991 // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that
3867 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0) 3992 if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands)
3868 {
3869 allflags |= ScriptControlled.CONTROL_FWD;
3870 }
3871 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0)
3872 {
3873 allflags |= ScriptControlled.CONTROL_BACK;
3874 }
3875 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0)
3876 {
3877 allflags |= ScriptControlled.CONTROL_UP;
3878 }
3879 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)
3880 {
3881 allflags |= ScriptControlled.CONTROL_DOWN;
3882 }
3883 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0)
3884 {
3885 allflags |= ScriptControlled.CONTROL_LEFT;
3886 }
3887 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0)
3888 {
3889 allflags |= ScriptControlled.CONTROL_RIGHT;
3890 }
3891 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
3892 {
3893 allflags |= ScriptControlled.CONTROL_ROT_RIGHT;
3894 }
3895 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
3896 {
3897 allflags |= ScriptControlled.CONTROL_ROT_LEFT;
3898 }
3899 // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that
3900 if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands)
3901 {
3902 lock (scriptedcontrols)
3903 { 3993 {
3904 foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols) 3994 foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols)
3905 { 3995 {
3906 UUID scriptUUID = kvp.Key; 3996 UUID scriptUUID = kvp.Key;
3907 ScriptControllers scriptControlData = kvp.Value; 3997 ScriptControllers scriptControlData = kvp.Value;
3908 3998
3909 ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us 3999 ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us
3910 ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle 4000 ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle
3911 ScriptControlled localChange = localHeld ^ localLast; // the changed bits 4001 ScriptControlled localChange = localHeld ^ localLast; // the changed bits
4002
3912 if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO) 4003 if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO)
3913 { 4004 {
3914 // only send if still pressed or just changed 4005 // only send if still pressed or just changed
@@ -3916,9 +4007,9 @@ namespace OpenSim.Region.Framework.Scenes
3916 } 4007 }
3917 } 4008 }
3918 } 4009 }
4010
4011 LastCommands = allflags;
3919 } 4012 }
3920
3921 LastCommands = allflags;
3922 } 4013 }
3923 4014
3924 internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored) 4015 internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored)
@@ -3998,7 +4089,7 @@ namespace OpenSim.Region.Framework.Scenes
3998 land.LandData.UserLocation != Vector3.Zero && 4089 land.LandData.UserLocation != Vector3.Zero &&
3999 land.LandData.OwnerID != m_uuid && 4090 land.LandData.OwnerID != m_uuid &&
4000 (!m_scene.Permissions.IsGod(m_uuid)) && 4091 (!m_scene.Permissions.IsGod(m_uuid)) &&
4001 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid))) 4092 (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid)))
4002 { 4093 {
4003 float curr = Vector3.Distance(AbsolutePosition, pos); 4094 float curr = Vector3.Distance(AbsolutePosition, pos);
4004 if (Vector3.Distance(land.LandData.UserLocation, pos) < curr) 4095 if (Vector3.Distance(land.LandData.UserLocation, pos) < curr)
@@ -4012,13 +4103,13 @@ namespace OpenSim.Region.Framework.Scenes
4012 { 4103 {
4013 if ((m_teleportFlags & (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID)) == 4104 if ((m_teleportFlags & (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID)) ==
4014 (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID) || 4105 (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID) ||
4015 (m_teleportFlags & TeleportFlags.ViaLandmark) != 0 || 4106 (m_scene.TelehubAllowLandmarks == true ? false : ((m_teleportFlags & TeleportFlags.ViaLandmark) != 0 )) ||
4016 (m_teleportFlags & TeleportFlags.ViaLocation) != 0 || 4107 (m_teleportFlags & TeleportFlags.ViaLocation) != 0 ||
4017 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0) 4108 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0)
4018 { 4109 {
4019 if (GodLevel < 200 && 4110 if (GodLevel < 200 &&
4020 ((!m_scene.Permissions.IsGod(m_uuid) && 4111 ((!m_scene.Permissions.IsGod(m_uuid) &&
4021 !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)) || 4112 !m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid)) ||
4022 (m_teleportFlags & TeleportFlags.ViaLocation) != 0 || 4113 (m_teleportFlags & TeleportFlags.ViaLocation) != 0 ||
4023 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0)) 4114 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0))
4024 { 4115 {
@@ -4026,28 +4117,92 @@ namespace OpenSim.Region.Framework.Scenes
4026 if (spawnPoints.Length == 0) 4117 if (spawnPoints.Length == 0)
4027 return; 4118 return;
4028 4119
4029 float distance = 9999; 4120 int index;
4030 int closest = -1; 4121 bool selected = false;
4031 4122
4032 for (int i = 0 ; i < spawnPoints.Length ; i++) 4123 switch (m_scene.SpawnPointRouting)
4033 { 4124 {
4034 Vector3 spawnPosition = spawnPoints[i].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation); 4125 case "random":
4035 Vector3 offset = spawnPosition - pos;
4036 float d = Vector3.Mag(offset);
4037 if (d >= distance)
4038 continue;
4039 ILandObject land = m_scene.LandChannel.GetLandObject(spawnPosition.X, spawnPosition.Y);
4040 if (land == null)
4041 continue;
4042 if (land.IsEitherBannedOrRestricted(UUID))
4043 continue;
4044 distance = d;
4045 closest = i;
4046 }
4047 if (closest == -1)
4048 return;
4049 4126
4050 pos = spawnPoints[closest].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation); 4127 do
4128 {
4129 index = Util.RandomClass.Next(spawnPoints.Length - 1);
4130
4131 Vector3 spawnPosition = spawnPoints[index].GetLocation(
4132 telehub.AbsolutePosition,
4133 telehub.GroupRotation
4134 );
4135 // SpawnPoint sp = spawnPoints[index];
4136
4137 ILandObject land = m_scene.LandChannel.GetLandObject(spawnPosition.X, spawnPosition.Y);
4138 if (land == null || land.IsEitherBannedOrRestricted(UUID))
4139 selected = false;
4140 else
4141 selected = true;
4142
4143 } while ( selected == false);
4144
4145 pos = spawnPoints[index].GetLocation(
4146 telehub.AbsolutePosition,
4147 telehub.GroupRotation
4148 );
4149 return;
4150
4151 case "sequence":
4152
4153 do
4154 {
4155 index = m_scene.SpawnPoint();
4156
4157 Vector3 spawnPosition = spawnPoints[index].GetLocation(
4158 telehub.AbsolutePosition,
4159 telehub.GroupRotation
4160 );
4161 // SpawnPoint sp = spawnPoints[index];
4162
4163 ILandObject land = m_scene.LandChannel.GetLandObject(spawnPosition.X, spawnPosition.Y);
4164 if (land == null || land.IsEitherBannedOrRestricted(UUID))
4165 selected = false;
4166 else
4167 selected = true;
4168
4169 } while (selected == false);
4170
4171 pos = spawnPoints[index].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation);
4172 ;
4173 return;
4174
4175 default:
4176 case "closest":
4177
4178 float distance = 9999;
4179 int closest = -1;
4180
4181 for (int i = 0; i < spawnPoints.Length; i++)
4182 {
4183 Vector3 spawnPosition = spawnPoints[i].GetLocation(
4184 telehub.AbsolutePosition,
4185 telehub.GroupRotation
4186 );
4187 Vector3 offset = spawnPosition - pos;
4188 float d = Vector3.Mag(offset);
4189 if (d >= distance)
4190 continue;
4191 ILandObject land = m_scene.LandChannel.GetLandObject(spawnPosition.X, spawnPosition.Y);
4192 if (land == null)
4193 continue;
4194 if (land.IsEitherBannedOrRestricted(UUID))
4195 continue;
4196 distance = d;
4197 closest = i;
4198 }
4199 if (closest == -1)
4200 return;
4201
4202 pos = spawnPoints[closest].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation);
4203 return;
4204
4205 }
4051 } 4206 }
4052 } 4207 }
4053 } 4208 }
@@ -4092,7 +4247,7 @@ namespace OpenSim.Region.Framework.Scenes
4092 GodLevel < 200 && 4247 GodLevel < 200 &&
4093 ((land.LandData.OwnerID != m_uuid && 4248 ((land.LandData.OwnerID != m_uuid &&
4094 !m_scene.Permissions.IsGod(m_uuid) && 4249 !m_scene.Permissions.IsGod(m_uuid) &&
4095 !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)) || 4250 !m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid)) ||
4096 (m_teleportFlags & TeleportFlags.ViaLocation) != 0 || 4251 (m_teleportFlags & TeleportFlags.ViaLocation) != 0 ||
4097 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0)) 4252 (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0))
4098 { 4253 {
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
index 55455cc..a4f730d 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
@@ -47,14 +47,30 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
47 /// </remarks> 47 /// </remarks>
48 public class CoalescedSceneObjectsSerializer 48 public class CoalescedSceneObjectsSerializer
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 /// <summary> 52 /// <summary>
53 /// Serialize coalesced objects to Xml 53 /// Serialize coalesced objects to Xml
54 /// </summary> 54 /// </summary>
55 /// <param name="coa"></param> 55 /// <param name="coa"></param>
56 /// <param name="doScriptStates">
57 /// If true then serialize script states. This will halt any running scripts
58 /// </param>
56 /// <returns></returns> 59 /// <returns></returns>
57 public static string ToXml(CoalescedSceneObjects coa) 60 public static string ToXml(CoalescedSceneObjects coa)
61 {
62 return ToXml(coa, true);
63 }
64
65 /// <summary>
66 /// Serialize coalesced objects to Xml
67 /// </summary>
68 /// <param name="coa"></param>
69 /// <param name="doScriptStates">
70 /// If true then serialize script states. This will halt any running scripts
71 /// </param>
72 /// <returns></returns>
73 public static string ToXml(CoalescedSceneObjects coa, bool doScriptStates)
58 { 74 {
59 using (StringWriter sw = new StringWriter()) 75 using (StringWriter sw = new StringWriter())
60 { 76 {
@@ -91,7 +107,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
91 writer.WriteAttributeString("offsety", offsets[i].Y.ToString()); 107 writer.WriteAttributeString("offsety", offsets[i].Y.ToString());
92 writer.WriteAttributeString("offsetz", offsets[i].Z.ToString()); 108 writer.WriteAttributeString("offsetz", offsets[i].Z.ToString());
93 109
94 SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, true); 110 SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, doScriptStates);
95 111
96 writer.WriteEndElement(); // SceneObjectGroup 112 writer.WriteEndElement(); // SceneObjectGroup
97 } 113 }
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
index 151eba2..e223f47 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -1538,51 +1538,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1538 } 1538 }
1539 } 1539 }
1540 1540
1541 //////// Read /////////
1542 public static bool Xml2ToSOG(XmlTextReader reader, SceneObjectGroup sog)
1543 {
1544 reader.Read();
1545 reader.ReadStartElement("SceneObjectGroup");
1546 SceneObjectPart root = Xml2ToSOP(reader);
1547 if (root != null)
1548 sog.SetRootPart(root);
1549 else
1550 {
1551 return false;
1552 }
1553
1554 if (sog.UUID == UUID.Zero)
1555 sog.UUID = sog.RootPart.UUID;
1556
1557 reader.Read(); // OtherParts
1558
1559 while (!reader.EOF)
1560 {
1561 switch (reader.NodeType)
1562 {
1563 case XmlNodeType.Element:
1564 if (reader.Name == "SceneObjectPart")
1565 {
1566 SceneObjectPart child = Xml2ToSOP(reader);
1567 if (child != null)
1568 sog.AddPart(child);
1569 }
1570 else
1571 {
1572 //Logger.Log("Found unexpected prim XML element " + reader.Name, Helpers.LogLevel.Debug);
1573 reader.Read();
1574 }
1575 break;
1576 case XmlNodeType.EndElement:
1577 default:
1578 reader.Read();
1579 break;
1580 }
1581
1582 }
1583 return true;
1584 }
1585
1586 public static SceneObjectPart Xml2ToSOP(XmlTextReader reader) 1541 public static SceneObjectPart Xml2ToSOP(XmlTextReader reader)
1587 { 1542 {
1588 SceneObjectPart obj = new SceneObjectPart(); 1543 SceneObjectPart obj = new SceneObjectPart();
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
index d214eba..a3485d2 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
@@ -223,50 +223,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
223 223
224 public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString) 224 public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
225 { 225 {
226 XmlDocument doc = new XmlDocument(); 226 return SceneObjectSerializer.FromXml2Format(xmlString);
227 XmlNode rootNode;
228
229 XmlTextReader reader = new XmlTextReader(new StringReader(xmlString));
230 reader.WhitespaceHandling = WhitespaceHandling.None;
231 doc.Load(reader);
232 reader.Close();
233 rootNode = doc.FirstChild;
234
235 // This is to deal with neighbouring regions that are still surrounding the group xml with the <scene>
236 // tag. It should be possible to remove the first part of this if statement once we go past 0.5.9 (or
237 // when some other changes forces all regions to upgrade).
238 // This might seem rather pointless since prim crossing from this revision to an earlier revision remains
239 // broken. But it isn't much work to accomodate the old format here.
240 if (rootNode.LocalName.Equals("scene"))
241 {
242 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
243 {
244 // There is only ever one prim. This oddity should be removeable post 0.5.9
245 //return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml);
246 using (reader = new XmlTextReader(new StringReader(aPrimNode.OuterXml)))
247 {
248 SceneObjectGroup obj = new SceneObjectGroup();
249 if (SceneObjectSerializer.Xml2ToSOG(reader, obj))
250 return obj;
251
252 return null;
253 }
254 }
255
256 return null;
257 }
258 else
259 {
260 //return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml);
261 using (reader = new XmlTextReader(new StringReader(rootNode.OuterXml)))
262 {
263 SceneObjectGroup obj = new SceneObjectGroup();
264 if (SceneObjectSerializer.Xml2ToSOG(reader, obj))
265 return obj;
266
267 return null;
268 }
269 }
270 } 227 }
271 228
272 /// <summary> 229 /// <summary>
@@ -307,8 +264,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
307 ICollection<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); 264 ICollection<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
308 foreach (XmlNode aPrimNode in rootNode.ChildNodes) 265 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
309 { 266 {
310 SceneObjectGroup obj = CreatePrimFromXml2(scene, aPrimNode.OuterXml); 267 SceneObjectGroup obj = DeserializeGroupFromXml2(aPrimNode.OuterXml);
311 if (obj != null && startScripts) 268 if (startScripts)
312 sceneObjects.Add(obj); 269 sceneObjects.Add(obj);
313 } 270 }
314 271
@@ -319,27 +276,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
319 } 276 }
320 } 277 }
321 278
322 /// <summary>
323 /// Create a prim from the xml2 representation.
324 /// </summary>
325 /// <param name="scene"></param>
326 /// <param name="xmlData"></param>
327 /// <returns>The scene object created. null if the scene object already existed</returns>
328 protected static SceneObjectGroup CreatePrimFromXml2(Scene scene, string xmlData)
329 {
330 //SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData);
331 using (XmlTextReader reader = new XmlTextReader(new StringReader(xmlData)))
332 {
333 SceneObjectGroup obj = new SceneObjectGroup();
334 SceneObjectSerializer.Xml2ToSOG(reader, obj);
335
336 if (scene.AddRestoredSceneObject(obj, true, false))
337 return obj;
338 else
339 return null;
340 }
341 }
342
343 #endregion 279 #endregion
344 } 280 }
345} 281} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
index a4afd47..18e6ece 100644
--- a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
+++ b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
@@ -26,7 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29//using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Timers; 30using System.Timers;
31using OpenMetaverse.Packets; 31using OpenMetaverse.Packets;
32using OpenSim.Framework; 32using OpenSim.Framework;
@@ -35,10 +35,18 @@ using OpenSim.Region.Framework.Interfaces;
35 35
36namespace OpenSim.Region.Framework.Scenes 36namespace OpenSim.Region.Framework.Scenes
37{ 37{
38 /// <summary>
39 /// Collect statistics from the scene to send to the client and for access by other monitoring tools.
40 /// </summary>
41 /// <remarks>
42 /// FIXME: This should be a monitoring region module
43 /// </remarks>
38 public class SimStatsReporter 44 public class SimStatsReporter
39 { 45 {
40// private static readonly log4net.ILog m_log 46 private static readonly log4net.ILog m_log
41// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 47 = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
48
49 public const string LastReportedObjectUpdateStatName = "LastReportedObjectUpdates";
42 50
43 public delegate void SendStatResult(SimStats stats); 51 public delegate void SendStatResult(SimStats stats);
44 52
@@ -48,10 +56,17 @@ namespace OpenSim.Region.Framework.Scenes
48 56
49 public event YourStatsAreWrong OnStatsIncorrect; 57 public event YourStatsAreWrong OnStatsIncorrect;
50 58
51 private SendStatResult handlerSendStatResult = null; 59 private SendStatResult handlerSendStatResult;
52 60
53 private YourStatsAreWrong handlerStatsIncorrect = null; 61 private YourStatsAreWrong handlerStatsIncorrect;
54 62
63 /// <summary>
64 /// These are the IDs of stats sent in the StatsPacket to the viewer.
65 /// </summary>
66 /// <remarks>
67 /// Some of these are not relevant to OpenSimulator since it is architected differently to other simulators
68 /// (e.g. script instructions aren't executed as part of the frame loop so 'script time' is tricky).
69 /// </remarks>
55 public enum Stats : uint 70 public enum Stats : uint
56 { 71 {
57 TimeDilation = 0, 72 TimeDilation = 0,
@@ -75,20 +90,20 @@ namespace OpenSim.Region.Framework.Scenes
75 OutPacketsPerSecond = 18, 90 OutPacketsPerSecond = 18,
76 PendingDownloads = 19, 91 PendingDownloads = 19,
77 PendingUploads = 20, 92 PendingUploads = 20,
78 VirtualSizeKB = 21, 93 VirtualSizeKb = 21,
79 ResidentSizeKB = 22, 94 ResidentSizeKb = 22,
80 PendingLocalUploads = 23, 95 PendingLocalUploads = 23,
81 UnAckedBytes = 24, 96 UnAckedBytes = 24,
82 PhysicsPinnedTasks = 25, 97 PhysicsPinnedTasks = 25,
83 PhysicsLODTasks = 26, 98 PhysicsLodTasks = 26,
84 PhysicsStepMS = 27, 99 SimPhysicsStepMs = 27,
85 PhysicsShapeMS = 28, 100 SimPhysicsShapeMs = 28,
86 PhysicsOtherMS = 29, 101 SimPhysicsOtherMs = 29,
87 PhysicsMemory = 30, 102 SimPhysicsMemory = 30,
88 ScriptEPS = 31, 103 ScriptEps = 31,
89 SimSpareTime = 32, 104 SimSpareMs = 32,
90 SimSleepTime = 33, 105 SimSleepMs = 33,
91 IOPumpTime = 34 106 SimIoPumpTime = 34
92 } 107 }
93 108
94 /// <summary> 109 /// <summary>
@@ -113,11 +128,24 @@ namespace OpenSim.Region.Framework.Scenes
113 get { return lastReportedSimStats; } 128 get { return lastReportedSimStats; }
114 } 129 }
115 130
131 /// <summary>
132 /// Extra sim statistics that are used by monitors but not sent to the client.
133 /// </summary>
134 /// <value>
135 /// The keys are the stat names.
136 /// </value>
137 private Dictionary<string, float> m_lastReportedExtraSimStats = new Dictionary<string, float>();
138
116 // Sending a stats update every 3 seconds- 139 // Sending a stats update every 3 seconds-
117 private int statsUpdatesEveryMS = 3000; 140 private int m_statsUpdatesEveryMS = 3000;
118 private float statsUpdateFactor = 0; 141 private float m_statsUpdateFactor;
119 private float m_timeDilation = 0; 142 private float m_timeDilation;
120 private int m_fps = 0; 143 private int m_fps;
144
145 /// <summary>
146 /// Number of the last frame on which we processed a stats udpate.
147 /// </summary>
148 private uint m_lastUpdateFrame;
121 149
122 /// <summary> 150 /// <summary>
123 /// Our nominal fps target, as expected in fps stats when a sim is running normally. 151 /// Our nominal fps target, as expected in fps stats when a sim is running normally.
@@ -135,43 +163,42 @@ namespace OpenSim.Region.Framework.Scenes
135 private float m_reportedFpsCorrectionFactor = 5; 163 private float m_reportedFpsCorrectionFactor = 5;
136 164
137 // saved last reported value so there is something available for llGetRegionFPS 165 // saved last reported value so there is something available for llGetRegionFPS
138 private float lastReportedSimFPS = 0; 166 private float lastReportedSimFPS;
139 private float[] lastReportedSimStats = new float[23]; 167 private float[] lastReportedSimStats = new float[22];
140 private float m_pfps = 0; 168 private float m_pfps;
141 169
142 /// <summary> 170 /// <summary>
143 /// Number of agent updates requested in this stats cycle 171 /// Number of agent updates requested in this stats cycle
144 /// </summary> 172 /// </summary>
145 private int m_agentUpdates = 0; 173 private int m_agentUpdates;
146 174
147 /// <summary> 175 /// <summary>
148 /// Number of object updates requested in this stats cycle 176 /// Number of object updates requested in this stats cycle
149 /// </summary> 177 /// </summary>
150 private int m_objectUpdates; 178 private int m_objectUpdates;
151 179
152 private int m_frameMS = 0; 180 private int m_frameMS;
153 private int m_netMS = 0; 181 private int m_spareMS;
154 private int m_agentMS = 0; 182 private int m_netMS;
155 private int m_physicsMS = 0; 183 private int m_agentMS;
156 private int m_imageMS = 0; 184 private int m_physicsMS;
157 private int m_otherMS = 0; 185 private int m_imageMS;
158 private int m_sleeptimeMS = 0; 186 private int m_otherMS;
159
160 187
161//Ckrinke: (3-21-08) Comment out to remove a compiler warning. Bring back into play when needed. 188//Ckrinke: (3-21-08) Comment out to remove a compiler warning. Bring back into play when needed.
162//Ckrinke private int m_scriptMS = 0; 189//Ckrinke private int m_scriptMS = 0;
163 190
164 private int m_rootAgents = 0; 191 private int m_rootAgents;
165 private int m_childAgents = 0; 192 private int m_childAgents;
166 private int m_numPrim = 0; 193 private int m_numPrim;
167 private int m_inPacketsPerSecond = 0; 194 private int m_inPacketsPerSecond;
168 private int m_outPacketsPerSecond = 0; 195 private int m_outPacketsPerSecond;
169 private int m_activePrim = 0; 196 private int m_activePrim;
170 private int m_unAckedBytes = 0; 197 private int m_unAckedBytes;
171 private int m_pendingDownloads = 0; 198 private int m_pendingDownloads;
172 private int m_pendingUploads = 0; 199 private int m_pendingUploads = 0; // FIXME: Not currently filled in
173 private int m_activeScripts = 0; 200 private int m_activeScripts;
174 private int m_scriptLinesPerSecond = 0; 201 private int m_scriptLinesPerSecond;
175 202
176 private int m_objectCapacity = 45000; 203 private int m_objectCapacity = 45000;
177 204
@@ -187,13 +214,13 @@ namespace OpenSim.Region.Framework.Scenes
187 { 214 {
188 m_scene = scene; 215 m_scene = scene;
189 m_reportedFpsCorrectionFactor = scene.MinFrameTime * m_nominalReportedFps; 216 m_reportedFpsCorrectionFactor = scene.MinFrameTime * m_nominalReportedFps;
190 statsUpdateFactor = (float)(statsUpdatesEveryMS / 1000); 217 m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000);
191 ReportingRegion = scene.RegionInfo; 218 ReportingRegion = scene.RegionInfo;
192 219
193 m_objectCapacity = scene.RegionInfo.ObjectCapacity; 220 m_objectCapacity = scene.RegionInfo.ObjectCapacity;
194 m_report.AutoReset = true; 221 m_report.AutoReset = true;
195 m_report.Interval = statsUpdatesEveryMS; 222 m_report.Interval = m_statsUpdatesEveryMS;
196 m_report.Elapsed += statsHeartBeat; 223 m_report.Elapsed += TriggerStatsHeartbeat;
197 m_report.Enabled = true; 224 m_report.Enabled = true;
198 225
199 if (StatsManager.SimExtraStats != null) 226 if (StatsManager.SimExtraStats != null)
@@ -202,20 +229,38 @@ namespace OpenSim.Region.Framework.Scenes
202 229
203 public void Close() 230 public void Close()
204 { 231 {
205 m_report.Elapsed -= statsHeartBeat; 232 m_report.Elapsed -= TriggerStatsHeartbeat;
206 m_report.Close(); 233 m_report.Close();
207 } 234 }
208 235
236 /// <summary>
237 /// Sets the number of milliseconds between stat updates.
238 /// </summary>
239 /// <param name='ms'></param>
209 public void SetUpdateMS(int ms) 240 public void SetUpdateMS(int ms)
210 { 241 {
211 statsUpdatesEveryMS = ms; 242 m_statsUpdatesEveryMS = ms;
212 statsUpdateFactor = (float)(statsUpdatesEveryMS / 1000); 243 m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000);
213 m_report.Interval = statsUpdatesEveryMS; 244 m_report.Interval = m_statsUpdatesEveryMS;
245 }
246
247 private void TriggerStatsHeartbeat(object sender, EventArgs args)
248 {
249 try
250 {
251 statsHeartBeat(sender, args);
252 }
253 catch (Exception e)
254 {
255 m_log.Warn(string.Format(
256 "[SIM STATS REPORTER] Update for {0} failed with exception ",
257 m_scene.RegionInfo.RegionName), e);
258 }
214 } 259 }
215 260
216 private void statsHeartBeat(object sender, EventArgs e) 261 private void statsHeartBeat(object sender, EventArgs e)
217 { 262 {
218 SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[23]; 263 SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[22];
219 SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); 264 SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();
220 265
221 // Know what's not thread safe in Mono... modifying timers. 266 // Know what's not thread safe in Mono... modifying timers.
@@ -242,7 +287,7 @@ namespace OpenSim.Region.Framework.Scenes
242 int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor); 287 int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor);
243 288
244 // save the reported value so there is something available for llGetRegionFPS 289 // save the reported value so there is something available for llGetRegionFPS
245 lastReportedSimFPS = reportedFPS / statsUpdateFactor; 290 lastReportedSimFPS = reportedFPS / m_statsUpdateFactor;
246 291
247 float physfps = ((m_pfps / 1000)); 292 float physfps = ((m_pfps / 1000));
248 293
@@ -253,7 +298,6 @@ namespace OpenSim.Region.Framework.Scenes
253 physfps = 0; 298 physfps = 0;
254 299
255#endregion 300#endregion
256 float factor = 1 / statsUpdateFactor;
257 if (reportedFPS <= 0) 301 if (reportedFPS <= 0)
258 reportedFPS = 1; 302 reportedFPS = 1;
259 303
@@ -264,32 +308,38 @@ namespace OpenSim.Region.Framework.Scenes
264 float targetframetime = 1100.0f / (float)m_nominalReportedFps; 308 float targetframetime = 1100.0f / (float)m_nominalReportedFps;
265 309
266 float sparetime; 310 float sparetime;
267 float sleeptime;
268 if (TotalFrameTime > targetframetime) 311 if (TotalFrameTime > targetframetime)
269 { 312 {
270 sparetime = 0; 313 sparetime = 0;
271 sleeptime = 0;
272 }
273 else
274 {
275 sparetime = m_frameMS - m_physicsMS - m_agentMS;
276 sparetime *= perframe;
277 if (sparetime < 0)
278 sparetime = 0;
279 else if (sparetime > TotalFrameTime)
280 sparetime = TotalFrameTime;
281 sleeptime = m_sleeptimeMS * perframe;
282 } 314 }
315
316 m_rootAgents = m_scene.SceneGraph.GetRootAgentCount();
317 m_childAgents = m_scene.SceneGraph.GetChildAgentCount();
318 m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount();
319 m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount();
320 m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount();
321
322 // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code
323 // so that stat numbers are always consistent.
324 CheckStatSanity();
283 325
284 // other MS is actually simulation time 326 // other MS is actually simulation time
285 // m_otherMS = m_frameMS - m_physicsMS - m_imageMS - m_netMS - m_agentMS; 327 // m_otherMS = m_frameMS - m_physicsMS - m_imageMS - m_netMS - m_agentMS;
286 // m_imageMS m_netMS are not included in m_frameMS 328 // m_imageMS m_netMS are not included in m_frameMS
287 329
288 m_otherMS = m_frameMS - m_physicsMS - m_agentMS - m_sleeptimeMS; 330 m_otherMS = m_frameMS - m_physicsMS - m_agentMS;
289 if (m_otherMS < 0) 331 if (m_otherMS < 0)
290 m_otherMS = 0; 332 m_otherMS = 0;
291 333
292 for (int i = 0; i < 23; i++) 334 uint thisFrame = m_scene.Frame;
335 float framesUpdated = (float)(thisFrame - m_lastUpdateFrame) * m_reportedFpsCorrectionFactor;
336 m_lastUpdateFrame = thisFrame;
337
338 // Avoid div-by-zero if somehow we've not updated any frames.
339 if (framesUpdated == 0)
340 framesUpdated = 1;
341
342 for (int i = 0; i < 22; i++)
293 { 343 {
294 sb[i] = new SimStatsPacket.StatBlock(); 344 sb[i] = new SimStatsPacket.StatBlock();
295 } 345 }
@@ -298,13 +348,13 @@ namespace OpenSim.Region.Framework.Scenes
298 sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation ; //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10) / statsUpdateFactor)); 348 sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation ; //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10) / statsUpdateFactor));
299 349
300 sb[1].StatID = (uint) Stats.SimFPS; 350 sb[1].StatID = (uint) Stats.SimFPS;
301 sb[1].StatValue = reportedFPS / statsUpdateFactor; 351 sb[1].StatValue = reportedFPS / m_statsUpdateFactor;
302 352
303 sb[2].StatID = (uint) Stats.PhysicsFPS; 353 sb[2].StatID = (uint) Stats.PhysicsFPS;
304 sb[2].StatValue = physfps / statsUpdateFactor; 354 sb[2].StatValue = physfps / m_statsUpdateFactor;
305 355
306 sb[3].StatID = (uint) Stats.AgentUpdates; 356 sb[3].StatID = (uint) Stats.AgentUpdates;
307 sb[3].StatValue = (m_agentUpdates / statsUpdateFactor); 357 sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor);
308 358
309 sb[4].StatID = (uint) Stats.Agents; 359 sb[4].StatID = (uint) Stats.Agents;
310 sb[4].StatValue = m_rootAgents; 360 sb[4].StatValue = m_rootAgents;
@@ -319,38 +369,31 @@ namespace OpenSim.Region.Framework.Scenes
319 sb[7].StatValue = m_activePrim; 369 sb[7].StatValue = m_activePrim;
320 370
321 sb[8].StatID = (uint)Stats.FrameMS; 371 sb[8].StatID = (uint)Stats.FrameMS;
322 // sb[8].StatValue = m_frameMS / statsUpdateFactor; 372 sb[8].StatValue = m_frameMS / framesUpdated;
323 sb[8].StatValue = TotalFrameTime;
324 373
325 sb[9].StatID = (uint)Stats.NetMS; 374 sb[9].StatID = (uint)Stats.NetMS;
326 // sb[9].StatValue = m_netMS / statsUpdateFactor; 375 sb[9].StatValue = m_netMS / framesUpdated;
327 sb[9].StatValue = m_netMS * perframe;
328 376
329 sb[10].StatID = (uint)Stats.PhysicsMS; 377 sb[10].StatID = (uint)Stats.PhysicsMS;
330 // sb[10].StatValue = m_physicsMS / statsUpdateFactor; 378 sb[10].StatValue = m_physicsMS / framesUpdated;
331 sb[10].StatValue = m_physicsMS * perframe;
332 379
333 sb[11].StatID = (uint)Stats.ImageMS ; 380 sb[11].StatID = (uint)Stats.ImageMS ;
334 // sb[11].StatValue = m_imageMS / statsUpdateFactor; 381 sb[11].StatValue = m_imageMS / framesUpdated;
335 sb[11].StatValue = m_imageMS * perframe;
336 382
337 sb[12].StatID = (uint)Stats.OtherMS; 383 sb[12].StatID = (uint)Stats.OtherMS;
338 // sb[12].StatValue = m_otherMS / statsUpdateFactor; 384 sb[12].StatValue = m_otherMS / framesUpdated;
339 sb[12].StatValue = m_otherMS * perframe;
340
341 385
342 sb[13].StatID = (uint)Stats.InPacketsPerSecond; 386 sb[13].StatID = (uint)Stats.InPacketsPerSecond;
343 sb[13].StatValue = (m_inPacketsPerSecond / statsUpdateFactor); 387 sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor);
344 388
345 sb[14].StatID = (uint)Stats.OutPacketsPerSecond; 389 sb[14].StatID = (uint)Stats.OutPacketsPerSecond;
346 sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor); 390 sb[14].StatValue = (m_outPacketsPerSecond / m_statsUpdateFactor);
347 391
348 sb[15].StatID = (uint)Stats.UnAckedBytes; 392 sb[15].StatID = (uint)Stats.UnAckedBytes;
349 sb[15].StatValue = m_unAckedBytes; 393 sb[15].StatValue = m_unAckedBytes;
350 394
351 sb[16].StatID = (uint)Stats.AgentMS; 395 sb[16].StatID = (uint)Stats.AgentMS;
352// sb[16].StatValue = m_agentMS / statsUpdateFactor; 396 sb[16].StatValue = m_agentMS / framesUpdated;
353 sb[16].StatValue = m_agentMS * perframe;
354 397
355 sb[17].StatID = (uint)Stats.PendingDownloads; 398 sb[17].StatID = (uint)Stats.PendingDownloads;
356 sb[17].StatValue = m_pendingDownloads; 399 sb[17].StatValue = m_pendingDownloads;
@@ -362,15 +405,12 @@ namespace OpenSim.Region.Framework.Scenes
362 sb[19].StatValue = m_activeScripts; 405 sb[19].StatValue = m_activeScripts;
363 406
364 sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; 407 sb[20].StatID = (uint)Stats.ScriptLinesPerSecond;
365 sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor; 408 sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor;
366 409
367 sb[21].StatID = (uint)Stats.SimSpareTime; 410 sb[21].StatID = (uint)Stats.SimSpareMs;
368 sb[21].StatValue = sparetime; 411 sb[21].StatValue = m_spareMS / framesUpdated;
369 412
370 sb[22].StatID = (uint)Stats.SimSleepTime; 413 for (int i = 0; i < 22; i++)
371 sb[22].StatValue = sleeptime;
372
373 for (int i = 0; i < 23; i++)
374 { 414 {
375 lastReportedSimStats[i] = sb[i].StatValue; 415 lastReportedSimStats[i] = sb[i].StatValue;
376 } 416 }
@@ -387,13 +427,32 @@ namespace OpenSim.Region.Framework.Scenes
387 } 427 }
388 428
389 // Extra statistics that aren't currently sent to clients 429 // Extra statistics that aren't currently sent to clients
390 LastReportedObjectUpdates = m_objectUpdates / statsUpdateFactor; 430 lock (m_lastReportedExtraSimStats)
431 {
432 m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor;
433
434 Dictionary<string, float> physicsStats = m_scene.PhysicsScene.GetStats();
435
436 if (physicsStats != null)
437 {
438 foreach (KeyValuePair<string, float> tuple in physicsStats)
439 {
440 // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second
441 // Need to change things so that stats source can indicate whether they are per second or
442 // per frame.
443 if (tuple.Key.EndsWith("MS"))
444 m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated;
445 else
446 m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor;
447 }
448 }
449 }
391 450
392 resetvalues(); 451 ResetValues();
393 } 452 }
394 } 453 }
395 454
396 private void resetvalues() 455 private void ResetValues()
397 { 456 {
398 m_timeDilation = 0; 457 m_timeDilation = 0;
399 m_fps = 0; 458 m_fps = 0;
@@ -411,7 +470,7 @@ namespace OpenSim.Region.Framework.Scenes
411 m_physicsMS = 0; 470 m_physicsMS = 0;
412 m_imageMS = 0; 471 m_imageMS = 0;
413 m_otherMS = 0; 472 m_otherMS = 0;
414 m_sleeptimeMS = 0; 473 m_spareMS = 0;
415 474
416//Ckrinke This variable is not used, so comment to remove compiler warning until it is used. 475//Ckrinke This variable is not used, so comment to remove compiler warning until it is used.
417//Ckrinke m_scriptMS = 0; 476//Ckrinke m_scriptMS = 0;
@@ -433,13 +492,6 @@ namespace OpenSim.Region.Framework.Scenes
433 m_timeDilation = td; 492 m_timeDilation = td;
434 } 493 }
435 494
436 public void SetRootAgents(int rootAgents)
437 {
438 m_rootAgents = rootAgents;
439 CheckStatSanity();
440
441 }
442
443 internal void CheckStatSanity() 495 internal void CheckStatSanity()
444 { 496 {
445 if (m_rootAgents < 0 || m_childAgents < 0) 497 if (m_rootAgents < 0 || m_childAgents < 0)
@@ -456,22 +508,6 @@ namespace OpenSim.Region.Framework.Scenes
456 } 508 }
457 } 509 }
458 510
459 public void SetChildAgents(int childAgents)
460 {
461 m_childAgents = childAgents;
462 CheckStatSanity();
463 }
464
465 public void SetObjects(int objects)
466 {
467 m_numPrim = objects;
468 }
469
470 public void SetActiveObjects(int objects)
471 {
472 m_activePrim = objects;
473 }
474
475 public void AddFPS(int frames) 511 public void AddFPS(int frames)
476 { 512 {
477 m_fps += frames; 513 m_fps += frames;
@@ -513,6 +549,11 @@ namespace OpenSim.Region.Framework.Scenes
513 m_frameMS += ms; 549 m_frameMS += ms;
514 } 550 }
515 551
552 public void AddSpareMS(int ms)
553 {
554 m_spareMS += ms;
555 }
556
516 public void addNetMS(int ms) 557 public void addNetMS(int ms)
517 { 558 {
518 m_netMS += ms; 559 m_netMS += ms;
@@ -538,15 +579,13 @@ namespace OpenSim.Region.Framework.Scenes
538 m_otherMS += ms; 579 m_otherMS += ms;
539 } 580 }
540 581
541 public void addSleepMS(int ms)
542 {
543 m_sleeptimeMS += ms;
544 }
545
546 public void AddPendingDownloads(int count) 582 public void AddPendingDownloads(int count)
547 { 583 {
548 m_pendingDownloads += count; 584 m_pendingDownloads += count;
549 if (m_pendingDownloads < 0) m_pendingDownloads = 0; 585
586 if (m_pendingDownloads < 0)
587 m_pendingDownloads = 0;
588
550 //m_log.InfoFormat("[stats]: Adding {0} to pending downloads to make {1}", count, m_pendingDownloads); 589 //m_log.InfoFormat("[stats]: Adding {0} to pending downloads to make {1}", count, m_pendingDownloads);
551 } 590 }
552 591
@@ -555,11 +594,6 @@ namespace OpenSim.Region.Framework.Scenes
555 m_scriptLinesPerSecond += count; 594 m_scriptLinesPerSecond += count;
556 } 595 }
557 596
558 public void SetActiveScripts(int count)
559 {
560 m_activeScripts = count;
561 }
562
563 public void AddPacketsStats(int inPackets, int outPackets, int unAckedBytes) 597 public void AddPacketsStats(int inPackets, int outPackets, int unAckedBytes)
564 { 598 {
565 AddInPackets(inPackets); 599 AddInPackets(inPackets);
@@ -568,5 +602,11 @@ namespace OpenSim.Region.Framework.Scenes
568 } 602 }
569 603
570 #endregion 604 #endregion
605
606 public Dictionary<string, float> GetExtraSimStats()
607 {
608 lock (m_lastReportedExtraSimStats)
609 return new Dictionary<string, float>(m_lastReportedExtraSimStats);
610 }
571 } 611 }
572} 612}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
index ab6311b..4a21dc9 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO;
30using System.Text; 31using System.Text;
31using NUnit.Framework; 32using NUnit.Framework;
32using OpenMetaverse; 33using OpenMetaverse;
@@ -68,11 +69,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
68 Vector3 position = new Vector3(200,200,21); 69 Vector3 position = new Vector3(200,200,21);
69 70
70 foreach (Border b in testborders) 71 foreach (Border b in testborders)
71 {
72 Assert.That(!b.TestCross(position)); 72 Assert.That(!b.TestCross(position));
73 73
74 }
75
76 position = new Vector3(200,280,21); 74 position = new Vector3(200,280,21);
77 Assert.That(NorthBorder.TestCross(position)); 75 Assert.That(NorthBorder.TestCross(position));
78 76
diff --git a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
index a5d2b23..ea9fc93 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
@@ -45,7 +45,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
45 { 45 {
46 static public Random random; 46 static public Random random;
47 SceneObjectGroup found; 47 SceneObjectGroup found;
48 Scene scene = SceneHelpers.SetupScene(); 48 Scene scene = new SceneHelpers().SetupScene();
49 49
50 [Test] 50 [Test]
51 public void T010_AddObjects() 51 public void T010_AddObjects()
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs
index 9a60e50..d23c965 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneGraphTests.cs
@@ -26,7 +26,9 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.IO;
29using System.Reflection; 30using System.Reflection;
31using System.Text;
30using NUnit.Framework; 32using NUnit.Framework;
31using OpenMetaverse; 33using OpenMetaverse;
32using OpenSim.Framework; 34using OpenSim.Framework;
@@ -44,7 +46,9 @@ namespace OpenSim.Region.Framework.Scenes.Tests
44 public void TestDuplicateObject() 46 public void TestDuplicateObject()
45 { 47 {
46 TestHelpers.InMethod(); 48 TestHelpers.InMethod();
47 Scene scene = SceneHelpers.SetupScene(); 49// TestHelpers.EnableLogging();
50
51 Scene scene = new SceneHelpers().SetupScene();
48 52
49 UUID ownerId = new UUID("00000000-0000-0000-0000-000000000010"); 53 UUID ownerId = new UUID("00000000-0000-0000-0000-000000000010");
50 string part1Name = "part1"; 54 string part1Name = "part1";
@@ -82,6 +86,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
82 Assert.That(dupePart1.PhysActor, Is.Not.Null); 86 Assert.That(dupePart1.PhysActor, Is.Not.Null);
83 Assert.That(dupePart2.PhysActor, Is.Not.Null); 87 Assert.That(dupePart2.PhysActor, Is.Not.Null);
84 */ 88 */
89
90// TestHelpers.DisableLogging();
85 } 91 }
86 } 92 }
87} \ No newline at end of file 93} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs
index 7737d8e..81add43 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs
@@ -88,7 +88,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
88 { 88 {
89 TestHelpers.InMethod(); 89 TestHelpers.InMethod();
90 90
91 Scene scene = SceneHelpers.SetupScene(); 91 Scene scene = new SceneHelpers().SetupScene();
92 int partsToTestCount = 3; 92 int partsToTestCount = 3;
93 93
94 SceneObjectGroup so 94 SceneObjectGroup so
@@ -118,7 +118,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
118 { 118 {
119 TestHelpers.InMethod(); 119 TestHelpers.InMethod();
120 120
121 Scene scene = SceneHelpers.SetupScene(); 121 Scene scene = new SceneHelpers().SetupScene();
122 122
123 string obj1Name = "Alfred"; 123 string obj1Name = "Alfred";
124 string obj2Name = "Betty"; 124 string obj2Name = "Betty";
@@ -152,7 +152,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
152 { 152 {
153 TestHelpers.InMethod(); 153 TestHelpers.InMethod();
154 154
155 Scene scene = SceneHelpers.SetupScene(); 155 Scene scene = new SceneHelpers().SetupScene();
156 int partsToTestCount = 3; 156 int partsToTestCount = 3;
157 157
158 SceneObjectGroup so 158 SceneObjectGroup so
@@ -185,10 +185,15 @@ namespace OpenSim.Region.Framework.Scenes.Tests
185 { 185 {
186 TestHelpers.InMethod(); 186 TestHelpers.InMethod();
187 187
188 TestScene scene = SceneHelpers.SetupScene(); 188 TestScene scene = new SceneHelpers().SetupScene();
189 SceneObjectPart part = SceneHelpers.AddSceneObject(scene); 189 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
190
191 Assert.That(part.ParentGroup.IsDeleted, Is.False);
192
190 scene.DeleteSceneObject(part.ParentGroup, false); 193 scene.DeleteSceneObject(part.ParentGroup, false);
191 194
195 Assert.That(part.ParentGroup.IsDeleted, Is.True);
196
192 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); 197 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
193 Assert.That(retrievedPart, Is.Null); 198 Assert.That(retrievedPart, Is.Null);
194 } 199 }
@@ -204,7 +209,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
204 209
205 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001"); 210 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
206 211
207 TestScene scene = SceneHelpers.SetupScene(); 212 TestScene scene = new SceneHelpers().SetupScene();
208 213
209 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. 214 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
210 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; 215 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
@@ -219,8 +224,12 @@ namespace OpenSim.Region.Framework.Scenes.Tests
219 224
220 Assert.That(retrievedPart, Is.Not.Null); 225 Assert.That(retrievedPart, Is.Not.Null);
221 226
227 Assert.That(part.ParentGroup.IsDeleted, Is.False);
228
222 sogd.InventoryDeQueueAndDelete(); 229 sogd.InventoryDeQueueAndDelete();
223 230
231 Assert.That(part.ParentGroup.IsDeleted, Is.True);
232
224 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId); 233 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
225 Assert.That(retrievedPart2, Is.Null); 234 Assert.That(retrievedPart2, Is.Null);
226 } 235 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs
index 654b1a2..0076f41 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs
@@ -61,7 +61,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
61 61
62 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); 62 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
63 63
64 TestScene scene = SceneHelpers.SetupScene(); 64 TestScene scene = new SceneHelpers().SetupScene();
65 IConfigSource configSource = new IniConfigSource(); 65 IConfigSource configSource = new IniConfigSource();
66 IConfig config = configSource.AddConfig("Startup"); 66 IConfig config = configSource.AddConfig("Startup");
67 config.Set("serverside_object_permissions", true); 67 config.Set("serverside_object_permissions", true);
@@ -100,7 +100,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
100 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); 100 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
101 UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001"); 101 UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001");
102 102
103 TestScene scene = SceneHelpers.SetupScene(); 103 TestScene scene = new SceneHelpers().SetupScene();
104 IConfigSource configSource = new IniConfigSource(); 104 IConfigSource configSource = new IniConfigSource();
105 IConfig config = configSource.AddConfig("Startup"); 105 IConfig config = configSource.AddConfig("Startup");
106 config.Set("serverside_object_permissions", true); 106 config.Set("serverside_object_permissions", true);
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
index be5b4a8..1add3dd 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
55 UUID ownerId = TestHelpers.ParseTail(0x1); 55 UUID ownerId = TestHelpers.ParseTail(0x1);
56 int nParts = 3; 56 int nParts = 3;
57 57
58 TestScene scene = SceneHelpers.SetupScene(); 58 TestScene scene = new SceneHelpers().SetupScene();
59 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(nParts, ownerId, "TestLinkToSelf_", 0x10); 59 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(nParts, ownerId, "TestLinkToSelf_", 0x10);
60 scene.AddSceneObject(sog1); 60 scene.AddSceneObject(sog1);
61 scene.LinkObjects(ownerId, sog1.LocalId, new List<uint>() { sog1.Parts[1].LocalId }); 61 scene.LinkObjects(ownerId, sog1.LocalId, new List<uint>() { sog1.Parts[1].LocalId });
@@ -71,7 +71,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
71 71
72 bool debugtest = false; 72 bool debugtest = false;
73 73
74 Scene scene = SceneHelpers.SetupScene(); 74 Scene scene = new SceneHelpers().SetupScene();
75 SceneObjectPart part1 = SceneHelpers.AddSceneObject(scene); 75 SceneObjectPart part1 = SceneHelpers.AddSceneObject(scene);
76 SceneObjectGroup grp1 = part1.ParentGroup; 76 SceneObjectGroup grp1 = part1.ParentGroup;
77 SceneObjectPart part2 = SceneHelpers.AddSceneObject(scene); 77 SceneObjectPart part2 = SceneHelpers.AddSceneObject(scene);
@@ -153,7 +153,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
153 153
154 bool debugtest = false; 154 bool debugtest = false;
155 155
156 Scene scene = SceneHelpers.SetupScene(); 156 Scene scene = new SceneHelpers().SetupScene();
157 SceneObjectPart part1 = SceneHelpers.AddSceneObject(scene); 157 SceneObjectPart part1 = SceneHelpers.AddSceneObject(scene);
158 SceneObjectGroup grp1 = part1.ParentGroup; 158 SceneObjectGroup grp1 = part1.ParentGroup;
159 SceneObjectPart part2 = SceneHelpers.AddSceneObject(scene); 159 SceneObjectPart part2 = SceneHelpers.AddSceneObject(scene);
@@ -286,7 +286,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
286 TestHelpers.InMethod(); 286 TestHelpers.InMethod();
287 //log4net.Config.XmlConfigurator.Configure(); 287 //log4net.Config.XmlConfigurator.Configure();
288 288
289 TestScene scene = SceneHelpers.SetupScene(); 289 TestScene scene = new SceneHelpers().SetupScene();
290 290
291 string rootPartName = "rootpart"; 291 string rootPartName = "rootpart";
292 UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); 292 UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
@@ -325,7 +325,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
325 TestHelpers.InMethod(); 325 TestHelpers.InMethod();
326 //log4net.Config.XmlConfigurator.Configure(); 326 //log4net.Config.XmlConfigurator.Configure();
327 327
328 TestScene scene = SceneHelpers.SetupScene(); 328 TestScene scene = new SceneHelpers().SetupScene();
329 329
330 string rootPartName = "rootpart"; 330 string rootPartName = "rootpart";
331 UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); 331 UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001");
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs
index b49c6e7..0a94c19 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs
@@ -52,7 +52,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
52 TestHelpers.InMethod(); 52 TestHelpers.InMethod();
53// log4net.Config.XmlConfigurator.Configure(); 53// log4net.Config.XmlConfigurator.Configure();
54 54
55 Scene scene = SceneHelpers.SetupScene(); 55 Scene scene = new SceneHelpers().SetupScene();
56 SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene).ParentGroup; 56 SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene).ParentGroup;
57 57
58 g1.GroupResize(new Vector3(2, 3, 4)); 58 g1.GroupResize(new Vector3(2, 3, 4));
@@ -75,7 +75,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
75 TestHelpers.InMethod(); 75 TestHelpers.InMethod();
76 //log4net.Config.XmlConfigurator.Configure(); 76 //log4net.Config.XmlConfigurator.Configure();
77 77
78 Scene scene = SceneHelpers.SetupScene(); 78 Scene scene = new SceneHelpers().SetupScene();
79 79
80 SceneObjectGroup g1 = SceneHelpers.CreateSceneObject(2, UUID.Zero); 80 SceneObjectGroup g1 = SceneHelpers.CreateSceneObject(2, UUID.Zero);
81 g1.RootPart.Scale = new Vector3(2, 3, 4); 81 g1.RootPart.Scale = new Vector3(2, 3, 4);
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs
index c582cf6..d2361f8 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectScriptTests.cs
@@ -52,7 +52,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
52// UUID itemId = TestHelpers.ParseTail(0x2); 52// UUID itemId = TestHelpers.ParseTail(0x2);
53 string itemName = "Test Script Item"; 53 string itemName = "Test Script Item";
54 54
55 Scene scene = SceneHelpers.SetupScene(); 55 Scene scene = new SceneHelpers().SetupScene();
56 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); 56 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
57 scene.AddNewSceneObject(so, true); 57 scene.AddNewSceneObject(so, true);
58 58
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs
new file mode 100644
index 0000000..6d255aa
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs
@@ -0,0 +1,154 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using System.Threading;
31using NUnit.Framework;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Tests.Common;
37using OpenSim.Tests.Common.Mock;
38
39namespace OpenSim.Region.Framework.Scenes.Tests
40{
41 /// <summary>
42 /// Spatial scene object tests (will eventually cover root and child part position, rotation properties, etc.)
43 /// </summary>
44 [TestFixture]
45 public class SceneObjectSpatialTests
46 {
47 TestScene m_scene;
48 UUID m_ownerId = TestHelpers.ParseTail(0x1);
49
50 [SetUp]
51 public void SetUp()
52 {
53 m_scene = new SceneHelpers().SetupScene();
54 }
55
56 [Test]
57 public void TestGetSceneObjectGroupPosition()
58 {
59 TestHelpers.InMethod();
60
61 Vector3 position = new Vector3(10, 20, 30);
62
63 SceneObjectGroup so
64 = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10);
65 so.AbsolutePosition = position;
66 m_scene.AddNewSceneObject(so, false);
67
68 Assert.That(so.AbsolutePosition, Is.EqualTo(position));
69 }
70
71 [Test]
72 public void TestGetRootPartPosition()
73 {
74 TestHelpers.InMethod();
75
76 Vector3 partPosition = new Vector3(10, 20, 30);
77
78 SceneObjectGroup so
79 = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10);
80 so.AbsolutePosition = partPosition;
81 m_scene.AddNewSceneObject(so, false);
82
83 Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition));
84 Assert.That(so.RootPart.GroupPosition, Is.EqualTo(partPosition));
85 Assert.That(so.RootPart.GetWorldPosition(), Is.EqualTo(partPosition));
86 Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition));
87 Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero));
88 }
89
90 [Test]
91 public void TestGetChildPartPosition()
92 {
93 TestHelpers.InMethod();
94
95 Vector3 rootPartPosition = new Vector3(10, 20, 30);
96 Vector3 childOffsetPosition = new Vector3(2, 3, 4);
97
98 SceneObjectGroup so
99 = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10);
100 so.AbsolutePosition = rootPartPosition;
101 so.Parts[1].OffsetPosition = childOffsetPosition;
102
103 m_scene.AddNewSceneObject(so, false);
104
105 // Calculate child absolute position.
106 Vector3 childPosition = new Vector3(rootPartPosition + childOffsetPosition);
107
108 SceneObjectPart childPart = so.Parts[1];
109 Assert.That(childPart.AbsolutePosition, Is.EqualTo(childPosition));
110 Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition));
111 Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition));
112 Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition));
113 Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition));
114 }
115
116 [Test]
117 public void TestGetChildPartPositionAfterObjectRotation()
118 {
119 TestHelpers.InMethod();
120
121 Vector3 rootPartPosition = new Vector3(10, 20, 30);
122 Vector3 childOffsetPosition = new Vector3(2, 3, 4);
123
124 SceneObjectGroup so
125 = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10);
126 so.AbsolutePosition = rootPartPosition;
127 so.Parts[1].OffsetPosition = childOffsetPosition;
128
129 m_scene.AddNewSceneObject(so, false);
130
131 so.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 0, -90 * Utils.DEG_TO_RAD));
132
133 // Calculate child absolute position.
134 Vector3 rotatedChildOffsetPosition
135 = new Vector3(childOffsetPosition.Y, -childOffsetPosition.X, childOffsetPosition.Z);
136
137 Vector3 childPosition = new Vector3(rootPartPosition + rotatedChildOffsetPosition);
138
139 SceneObjectPart childPart = so.Parts[1];
140
141 // FIXME: Should be childPosition after rotation?
142 Assert.That(childPart.AbsolutePosition, Is.EqualTo(rootPartPosition + childOffsetPosition));
143
144 Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition));
145 Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition));
146
147 // Relative to root part as (0, 0, 0)
148 Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition));
149
150 // Relative to root part as (0, 0, 0)
151 Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition));
152 }
153 }
154} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs
index 2a342d5..742c769 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectStatusTests.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Reflection; 30using System.Reflection;
30using NUnit.Framework; 31using NUnit.Framework;
31using OpenMetaverse; 32using OpenMetaverse;
@@ -43,24 +44,141 @@ namespace OpenSim.Region.Framework.Scenes.Tests
43 [TestFixture] 44 [TestFixture]
44 public class SceneObjectStatusTests 45 public class SceneObjectStatusTests
45 { 46 {
47 private TestScene m_scene;
48 private UUID m_ownerId = TestHelpers.ParseTail(0x1);
49 private SceneObjectGroup m_so1;
50 private SceneObjectGroup m_so2;
51
52 [SetUp]
53 public void Init()
54 {
55 m_scene = new SceneHelpers().SetupScene();
56 m_so1 = SceneHelpers.CreateSceneObject(1, m_ownerId, "so1", 0x10);
57 m_so2 = SceneHelpers.CreateSceneObject(1, m_ownerId, "so2", 0x20);
58 }
59
46 [Test] 60 [Test]
47 public void TestSetPhantom() 61 public void TestSetPhantomSinglePrim()
48 { 62 {
49 TestHelpers.InMethod(); 63 TestHelpers.InMethod();
50 64
51// Scene scene = SceneSetupHelpers.SetupScene(); 65 m_scene.AddSceneObject(m_so1);
52 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, UUID.Zero); 66
53 SceneObjectPart rootPart = so.RootPart; 67 SceneObjectPart rootPart = m_so1.RootPart;
54 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); 68 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None));
55 69
56 so.ScriptSetPhantomStatus(true); 70 m_so1.ScriptSetPhantomStatus(true);
57 71
58// Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags); 72// Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags);
59 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom)); 73 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Phantom));
60 74
61 so.ScriptSetPhantomStatus(false); 75 m_so1.ScriptSetPhantomStatus(false);
62 76
63 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None)); 77 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None));
64 } 78 }
79
80 [Test]
81 public void TestSetPhysicsSinglePrim()
82 {
83 TestHelpers.InMethod();
84
85 m_scene.AddSceneObject(m_so1);
86
87 SceneObjectPart rootPart = m_so1.RootPart;
88 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None));
89
90 m_so1.ScriptSetPhysicsStatus(true);
91
92// Console.WriteLine("so.RootPart.Flags [{0}]", so.RootPart.Flags);
93 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.Physics));
94
95 m_so1.ScriptSetPhysicsStatus(false);
96
97 Assert.That(rootPart.Flags, Is.EqualTo(PrimFlags.None));
98 }
99
100 [Test]
101 public void TestSetPhysicsLinkset()
102 {
103 TestHelpers.InMethod();
104
105 m_scene.AddSceneObject(m_so1);
106 m_scene.AddSceneObject(m_so2);
107
108 m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId });
109
110 m_so1.ScriptSetPhysicsStatus(true);
111
112 Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics));
113 Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics));
114
115 m_so1.ScriptSetPhysicsStatus(false);
116
117 Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.None));
118 Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.None));
119
120 m_so1.ScriptSetPhysicsStatus(true);
121
122 Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics));
123 Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics));
124 }
125
126 /// <summary>
127 /// Test that linking results in the correct physical status for all linkees.
128 /// </summary>
129 [Test]
130 public void TestLinkPhysicsBothPhysical()
131 {
132 TestHelpers.InMethod();
133
134 m_scene.AddSceneObject(m_so1);
135 m_scene.AddSceneObject(m_so2);
136
137 m_so1.ScriptSetPhysicsStatus(true);
138 m_so2.ScriptSetPhysicsStatus(true);
139
140 m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId });
141
142 Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics));
143 Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics));
144 }
145
146 /// <summary>
147 /// Test that linking results in the correct physical status for all linkees.
148 /// </summary>
149 [Test]
150 public void TestLinkPhysicsRootPhysicalOnly()
151 {
152 TestHelpers.InMethod();
153
154 m_scene.AddSceneObject(m_so1);
155 m_scene.AddSceneObject(m_so2);
156
157 m_so1.ScriptSetPhysicsStatus(true);
158
159 m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId });
160
161 Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.Physics));
162 Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.Physics));
163 }
164
165 /// <summary>
166 /// Test that linking results in the correct physical status for all linkees.
167 /// </summary>
168 [Test]
169 public void TestLinkPhysicsChildPhysicalOnly()
170 {
171 TestHelpers.InMethod();
172
173 m_scene.AddSceneObject(m_so1);
174 m_scene.AddSceneObject(m_so2);
175
176 m_so2.ScriptSetPhysicsStatus(true);
177
178 m_scene.LinkObjects(m_ownerId, m_so1.LocalId, new List<uint>() { m_so2.LocalId });
179
180 Assert.That(m_so1.RootPart.Flags, Is.EqualTo(PrimFlags.None));
181 Assert.That(m_so1.Parts[1].Flags, Is.EqualTo(PrimFlags.None));
182 }
65 } 183 }
66} \ No newline at end of file 184} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs
index c13d82e..c7eaff9 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs
@@ -58,7 +58,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
58 58
59 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); 59 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
60 60
61 TestScene scene = SceneHelpers.SetupScene(); 61 TestScene scene = new SceneHelpers().SetupScene();
62 IConfigSource configSource = new IniConfigSource(); 62 IConfigSource configSource = new IniConfigSource();
63 63
64 IConfig startupConfig = configSource.AddConfig("Startup"); 64 IConfig startupConfig = configSource.AddConfig("Startup");
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
index ed9b179..02c45ef 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
@@ -67,10 +67,12 @@ namespace OpenSim.Region.Framework.Scenes.Tests
67 public void Init() 67 public void Init()
68 { 68 {
69 TestHelpers.InMethod(); 69 TestHelpers.InMethod();
70 70
71 scene = SceneHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000); 71 SceneHelpers sh = new SceneHelpers();
72 scene2 = SceneHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000); 72
73 scene3 = SceneHelpers.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000); 73 scene = sh.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
74 scene2 = sh.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
75 scene3 = sh.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000);
74 76
75 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule(); 77 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
76 interregionComms.Initialise(new IniConfigSource()); 78 interregionComms.Initialise(new IniConfigSource());
@@ -99,9 +101,9 @@ namespace OpenSim.Region.Framework.Scenes.Tests
99 public void TestCloseAgent() 101 public void TestCloseAgent()
100 { 102 {
101 TestHelpers.InMethod(); 103 TestHelpers.InMethod();
102// log4net.Config.XmlConfigurator.Configure(); 104// TestHelpers.EnableLogging();
103 105
104 TestScene scene = SceneHelpers.SetupScene(); 106 TestScene scene = new SceneHelpers().SetupScene();
105 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); 107 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
106 108
107 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Not.Null); 109 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Not.Null);
@@ -112,6 +114,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
112 Assert.That(scene.GetScenePresence(sp.UUID), Is.Null); 114 Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
113 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null); 115 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);
114 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0)); 116 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0));
117
118// TestHelpers.DisableLogging();
115 } 119 }
116 120
117 [Test] 121 [Test]
@@ -126,7 +130,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
126 IConfig config = configSource.AddConfig("Modules"); 130 IConfig config = configSource.AddConfig("Modules");
127 config.Set("SimulationServices", "LocalSimulationConnectorModule"); 131 config.Set("SimulationServices", "LocalSimulationConnectorModule");
128 132
129 TestScene scene = SceneHelpers.SetupScene(); 133 SceneHelpers sceneHelpers = new SceneHelpers();
134 TestScene scene = sceneHelpers.SetupScene();
130 SceneHelpers.SetupSceneModules(scene, configSource, lsc); 135 SceneHelpers.SetupSceneModules(scene, configSource, lsc);
131 136
132 UUID agentId = TestHelpers.ParseTail(0x01); 137 UUID agentId = TestHelpers.ParseTail(0x01);
@@ -176,8 +181,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
176 181
177// UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001"); 182// UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
178 183
179 TestScene myScene1 = SceneHelpers.SetupScene("Neighbour y", UUID.Random(), 1000, 1000); 184 TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
180 TestScene myScene2 = SceneHelpers.SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000); 185 TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
181 186
182 IConfigSource configSource = new IniConfigSource(); 187 IConfigSource configSource = new IniConfigSource();
183 IConfig config = configSource.AddConfig("Startup"); 188 IConfig config = configSource.AddConfig("Startup");
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs
index 89f8007..646e5fa 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
59 TestHelpers.InMethod(); 59 TestHelpers.InMethod();
60// log4net.Config.XmlConfigurator.Configure(); 60// log4net.Config.XmlConfigurator.Configure();
61 61
62 TestScene scene = SceneHelpers.SetupScene(); 62 TestScene scene = new SceneHelpers().SetupScene();
63 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); 63 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
64 sp.Flying = true; 64 sp.Flying = true;
65 sp.PhysicsCollisionUpdate(new CollisionEventUpdate()); 65 sp.PhysicsCollisionUpdate(new CollisionEventUpdate());
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs
index cfea10d..1d1ff88 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs
@@ -64,7 +64,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
64 [SetUp] 64 [SetUp]
65 public void Init() 65 public void Init()
66 { 66 {
67 m_scene = SceneHelpers.SetupScene(); 67 m_scene = new SceneHelpers().SetupScene();
68 } 68 }
69 69
70 [Test] 70 [Test]
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
index b7b8db4..313e350 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
50 [SetUp] 50 [SetUp]
51 public void Init() 51 public void Init()
52 { 52 {
53 m_scene = SceneHelpers.SetupScene(); 53 m_scene = new SceneHelpers().SetupScene();
54 m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 54 m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
55 } 55 }
56 56
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs
index bebc10c..a407f01 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs
@@ -34,10 +34,14 @@ using OpenSim.Framework;
34using OpenSim.Framework.Communications; 34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Servers; 35using OpenSim.Framework.Servers;
36using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.CoreModules.Framework;
38using OpenSim.Region.CoreModules.Framework.EntityTransfer;
37using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; 39using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
40using OpenSim.Region.CoreModules.World.Permissions;
38using OpenSim.Tests.Common; 41using OpenSim.Tests.Common;
39using OpenSim.Tests.Common.Mock; 42using OpenSim.Tests.Common.Mock;
40using System.Threading; 43using System.IO;
44using System.Text;
41 45
42namespace OpenSim.Region.Framework.Scenes.Tests 46namespace OpenSim.Region.Framework.Scenes.Tests
43{ 47{
@@ -47,145 +51,367 @@ namespace OpenSim.Region.Framework.Scenes.Tests
47 [TestFixture] 51 [TestFixture]
48 public class ScenePresenceTeleportTests 52 public class ScenePresenceTeleportTests
49 { 53 {
50 /// <summary> 54 [TestFixtureSetUp]
51 /// Test a teleport between two regions that are not neighbours and do not share any neighbours in common. 55 public void FixtureInit()
52 /// </summary> 56 {
53 /// Does not yet do what is says on the tin. 57 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
54 /// Commenting for now 58 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
55 //[Test, LongRunning] 59 }
56 public void TestSimpleNotNeighboursTeleport() 60
61 [TestFixtureTearDown]
62 public void TearDown()
63 {
64 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
65 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
66 // tests really shouldn't).
67 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
68 }
69
70 [Test]
71 public void TestSameRegionTeleport()
57 { 72 {
58 TestHelpers.InMethod(); 73 TestHelpers.InMethod();
59 ThreadRunResults results = new ThreadRunResults(); 74// log4net.Config.XmlConfigurator.Configure();
60 results.Result = false; 75
61 results.Message = "Test did not run"; 76 EntityTransferModule etm = new EntityTransferModule();
62 TestRunning testClass = new TestRunning(results); 77
78 IConfigSource config = new IniConfigSource();
79 config.AddConfig("Modules");
80 // Not strictly necessary since FriendsModule assumes it is the default (!)
81 config.Configs["Modules"].Set("EntityTransferModule", etm.Name);
82
83 TestScene scene = new SceneHelpers().SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
84 SceneHelpers.SetupSceneModules(scene, config, etm);
85
86 Vector3 teleportPosition = new Vector3(10, 11, 12);
87 Vector3 teleportLookAt = new Vector3(20, 21, 22);
88
89 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
90 sp.AbsolutePosition = new Vector3(30, 31, 32);
91 scene.RequestTeleportLocation(
92 sp.ControllingClient,
93 scene.RegionInfo.RegionHandle,
94 teleportPosition,
95 teleportLookAt,
96 (uint)TeleportFlags.ViaLocation);
63 97
64 Thread testThread = new Thread(testClass.run); 98 Assert.That(sp.AbsolutePosition, Is.EqualTo(teleportPosition));
65 99
66 // Seems kind of redundant to start a thread and then join it, however.. We need to protect against 100 Assert.That(scene.GetRootAgentCount(), Is.EqualTo(1));
67 // A thread abort exception in the simulator code. 101 Assert.That(scene.GetChildAgentCount(), Is.EqualTo(0));
68 testThread.Start();
69 testThread.Join();
70 102
71 Assert.That(testClass.results.Result, Is.EqualTo(true), testClass.results.Message); 103 // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
72 // Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod()); 104 // position instead).
105// Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
73 } 106 }
74 107
75 [TearDown] 108 [Test]
76 public void TearDown() 109 public void TestSameSimulatorSeparatedRegionsTeleport()
77 { 110 {
78 try 111 TestHelpers.InMethod();
79 { 112// log4net.Config.XmlConfigurator.Configure();
80 if (MainServer.Instance != null) MainServer.Instance.Stop(); 113
81 } 114 UUID userId = TestHelpers.ParseTail(0x1);
82 catch (NullReferenceException) 115
83 { } 116 EntityTransferModule etmA = new EntityTransferModule();
117 EntityTransferModule etmB = new EntityTransferModule();
118 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
119
120 IConfigSource config = new IniConfigSource();
121 IConfig modulesConfig = config.AddConfig("Modules");
122 modulesConfig.Set("EntityTransferModule", etmA.Name);
123 modulesConfig.Set("SimulationServices", lscm.Name);
124 IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
125
126 // In order to run a single threaded regression test we do not want the entity transfer module waiting
127 // for a callback from the destination scene before removing its avatar data.
128 entityTransferConfig.Set("wait_for_callback", false);
129
130 SceneHelpers sh = new SceneHelpers();
131 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
132 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
133
134 SceneHelpers.SetupSceneModules(sceneA, config, etmA);
135 SceneHelpers.SetupSceneModules(sceneB, config, etmB);
136 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
137
138 Vector3 teleportPosition = new Vector3(10, 11, 12);
139 Vector3 teleportLookAt = new Vector3(20, 21, 22);
140
141 ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
142 sp.AbsolutePosition = new Vector3(30, 31, 32);
143
144 // XXX: A very nasty hack to tell the client about the destination scene without having to crank the whole
145 // UDP stack (?)
146// ((TestClient)sp.ControllingClient).TeleportTargetScene = sceneB;
147
148 sceneA.RequestTeleportLocation(
149 sp.ControllingClient,
150 sceneB.RegionInfo.RegionHandle,
151 teleportPosition,
152 teleportLookAt,
153 (uint)TeleportFlags.ViaLocation);
154
155 ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
156
157 Assert.That(sceneA.GetScenePresence(userId), Is.Null);
158
159 ScenePresence sceneBSp = sceneB.GetScenePresence(userId);
160 Assert.That(sceneBSp, Is.Not.Null);
161 Assert.That(sceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
162 Assert.That(sceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition));
163
164 Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
165 Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
166 Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
167 Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
168
169 // TODO: Add assertions to check correct circuit details in both scenes.
170
171 // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
172 // position instead).
173// Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
84 } 174 }
85 175
86 } 176 /// <summary>
177 /// Test teleport procedures when the target simulator returns false when queried about access.
178 /// </summary>
179 [Test]
180 public void TestSameSimulatorSeparatedRegionsQueryAccessFails()
181 {
182 TestHelpers.InMethod();
183// TestHelpers.EnableLogging();
87 184
88 public class ThreadRunResults 185 UUID userId = TestHelpers.ParseTail(0x1);
89 { 186 Vector3 preTeleportPosition = new Vector3(30, 31, 32);
90 public bool Result = false;
91 public string Message = string.Empty;
92 }
93 187
94 public class TestRunning 188 EntityTransferModule etmA = new EntityTransferModule();
95 { 189 EntityTransferModule etmB = new EntityTransferModule();
96 public ThreadRunResults results; 190
97 public TestRunning(ThreadRunResults t) 191 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
192
193 IConfigSource config = new IniConfigSource();
194 config.AddConfig("Modules");
195 config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
196 config.Configs["Modules"].Set("SimulationServices", lscm.Name);
197
198 config.AddConfig("EntityTransfer");
199
200 // In order to run a single threaded regression test we do not want the entity transfer module waiting
201 // for a callback from the destination scene before removing its avatar data.
202 config.Configs["EntityTransfer"].Set("wait_for_callback", false);
203
204 config.AddConfig("Startup");
205 config.Configs["Startup"].Set("serverside_object_permissions", true);
206
207 SceneHelpers sh = new SceneHelpers();
208 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
209 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
210
211 SceneHelpers.SetupSceneModules(sceneA, config, etmA );
212
213 // We need to set up the permisions module on scene B so that our later use of agent limit to deny
214 // QueryAccess won't succeed anyway because administrators are always allowed in and the default
215 // IsAdministrator if no permissions module is present is true.
216 SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new PermissionsModule(), etmB });
217
218 // Shared scene modules
219 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
220
221 Vector3 teleportPosition = new Vector3(10, 11, 12);
222 Vector3 teleportLookAt = new Vector3(20, 21, 22);
223
224 ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
225 sp.AbsolutePosition = preTeleportPosition;
226
227 // Make sceneB return false on query access
228 sceneB.RegionInfo.RegionSettings.AgentLimit = 0;
229
230 sceneA.RequestTeleportLocation(
231 sp.ControllingClient,
232 sceneB.RegionInfo.RegionHandle,
233 teleportPosition,
234 teleportLookAt,
235 (uint)TeleportFlags.ViaLocation);
236
237// ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
238
239 Assert.That(sceneB.GetScenePresence(userId), Is.Null);
240
241 ScenePresence sceneASp = sceneA.GetScenePresence(userId);
242 Assert.That(sceneASp, Is.Not.Null);
243 Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
244 Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition));
245
246 Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
247 Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
248 Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
249 Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
250
251 // TODO: Add assertions to check correct circuit details in both scenes.
252
253 // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
254 // position instead).
255// Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
256
257// TestHelpers.DisableLogging();
258 }
259
260 /// <summary>
261 /// Test teleport procedures when the target simulator create agent step is refused.
262 /// </summary>
263 [Test]
264 public void TestSameSimulatorSeparatedRegionsCreateAgentFails()
98 { 265 {
99 results = t; 266 TestHelpers.InMethod();
267// TestHelpers.EnableLogging();
268
269 UUID userId = TestHelpers.ParseTail(0x1);
270 Vector3 preTeleportPosition = new Vector3(30, 31, 32);
271
272 EntityTransferModule etmA = new EntityTransferModule();
273 EntityTransferModule etmB = new EntityTransferModule();
274 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
275
276 IConfigSource config = new IniConfigSource();
277 config.AddConfig("Modules");
278 config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
279 config.Configs["Modules"].Set("SimulationServices", lscm.Name);
280
281 config.AddConfig("EntityTransfer");
282
283 // In order to run a single threaded regression test we do not want the entity transfer module waiting
284 // for a callback from the destination scene before removing its avatar data.
285 config.Configs["EntityTransfer"].Set("wait_for_callback", false);
286
287 SceneHelpers sh = new SceneHelpers();
288 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
289 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
290
291 SceneHelpers.SetupSceneModules(sceneA, config, etmA);
292 SceneHelpers.SetupSceneModules(sceneB, config, etmB);
293
294 // Shared scene modules
295 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
296
297 Vector3 teleportPosition = new Vector3(10, 11, 12);
298 Vector3 teleportLookAt = new Vector3(20, 21, 22);
299
300 ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
301 sp.AbsolutePosition = preTeleportPosition;
302
303 // Make sceneB refuse CreateAgent
304 sceneB.LoginsDisabled = true;
305
306 sceneA.RequestTeleportLocation(
307 sp.ControllingClient,
308 sceneB.RegionInfo.RegionHandle,
309 teleportPosition,
310 teleportLookAt,
311 (uint)TeleportFlags.ViaLocation);
312
313// ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
314
315 Assert.That(sceneB.GetScenePresence(userId), Is.Null);
316
317 ScenePresence sceneASp = sceneA.GetScenePresence(userId);
318 Assert.That(sceneASp, Is.Not.Null);
319 Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
320 Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition));
321
322 Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
323 Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
324 Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
325 Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
326
327 // TODO: Add assertions to check correct circuit details in both scenes.
328
329 // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
330 // position instead).
331// Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
332
333// TestHelpers.DisableLogging();
100 } 334 }
101 public void run(object o) 335
336 [Test]
337 public void TestSameSimulatorNeighbouringRegionsTeleport()
102 { 338 {
103 339 TestHelpers.InMethod();
104 //results.Result = true; 340// TestHelpers.EnableLogging();
105 log4net.Config.XmlConfigurator.Configure(); 341
106 342 UUID userId = TestHelpers.ParseTail(0x1);
107 UUID sceneAId = UUID.Parse("00000000-0000-0000-0000-000000000100"); 343
108 UUID sceneBId = UUID.Parse("00000000-0000-0000-0000-000000000200"); 344 EntityTransferModule etmA = new EntityTransferModule();
109 345 EntityTransferModule etmB = new EntityTransferModule();
110 // shared module 346 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
111 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule(); 347
112 348 IConfigSource config = new IniConfigSource();
113 349 IConfig modulesConfig = config.AddConfig("Modules");
114 Scene sceneB = SceneHelpers.SetupScene("sceneB", sceneBId, 1010, 1010); 350 modulesConfig.Set("EntityTransferModule", etmA.Name);
115 SceneHelpers.SetupSceneModules(sceneB, new IniConfigSource(), interregionComms); 351 modulesConfig.Set("SimulationServices", lscm.Name);
116 sceneB.RegisterRegionWithGrid(); 352 IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
117 353
118 Scene sceneA = SceneHelpers.SetupScene("sceneA", sceneAId, 1000, 1000); 354 // In order to run a single threaded regression test we do not want the entity transfer module waiting
119 SceneHelpers.SetupSceneModules(sceneA, new IniConfigSource(), interregionComms); 355 // for a callback from the destination scene before removing its avatar data.
120 sceneA.RegisterRegionWithGrid(); 356 entityTransferConfig.Set("wait_for_callback", false);
121 357
122 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000041"); 358 SceneHelpers sh = new SceneHelpers();
123 TestClient client = (TestClient)SceneHelpers.AddScenePresence(sceneA, agentId).ControllingClient; 359 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
124 360 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
125 ICapabilitiesModule sceneACapsModule = sceneA.RequestModuleInterface<ICapabilitiesModule>(); 361
126 362 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
127 results.Result = (sceneACapsModule.GetCapsPath(agentId) == client.CapsSeedUrl); 363 SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
128 364 SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
129 if (!results.Result) 365
130 { 366 Vector3 teleportPosition = new Vector3(10, 11, 12);
131 results.Message = "Incorrect caps object path set up in sceneA"; 367 Vector3 teleportLookAt = new Vector3(20, 21, 22);
132 return; 368
133 } 369 ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
134 370 originalSp.AbsolutePosition = new Vector3(30, 31, 32);
135 /* 371
136 Assert.That( 372 ScenePresence beforeSceneASp = sceneA.GetScenePresence(userId);
137 sceneACapsModule.GetCapsPath(agentId), 373 Assert.That(beforeSceneASp, Is.Not.Null);
138 Is.EqualTo(client.CapsSeedUrl), 374 Assert.That(beforeSceneASp.IsChildAgent, Is.False);
139 "Incorrect caps object path set up in sceneA"); 375
140 */ 376 ScenePresence beforeSceneBSp = sceneB.GetScenePresence(userId);
141 // FIXME: This is a hack to get the test working - really the normal OpenSim mechanisms should be used. 377 Assert.That(beforeSceneBSp, Is.Not.Null);
142 378 Assert.That(beforeSceneBSp.IsChildAgent, Is.True);
143 379
144 client.TeleportTargetScene = sceneB; 380 // XXX: A very nasty hack to tell the client about the destination scene without having to crank the whole
145 client.Teleport(sceneB.RegionInfo.RegionHandle, new Vector3(100, 100, 100), new Vector3(40, 40, 40)); 381 // UDP stack (?)
146 382// ((TestClient)beforeSceneASp.ControllingClient).TeleportTargetScene = sceneB;
147 results.Result = (sceneB.GetScenePresence(agentId) != null); 383
148 if (!results.Result) 384 sceneA.RequestTeleportLocation(
149 { 385 beforeSceneASp.ControllingClient,
150 results.Message = "Client does not have an agent in sceneB"; 386 sceneB.RegionInfo.RegionHandle,
151 return; 387 teleportPosition,
152 } 388 teleportLookAt,
153 389 (uint)TeleportFlags.ViaLocation);
154 //Assert.That(sceneB.GetScenePresence(agentId), Is.Not.Null, "Client does not have an agent in sceneB"); 390
155 391 ((TestClient)beforeSceneASp.ControllingClient).CompleteTeleportClientSide();
156 //Assert.That(sceneA.GetScenePresence(agentId), Is.Null, "Client still had an agent in sceneA"); 392
157 393 ScenePresence afterSceneASp = sceneA.GetScenePresence(userId);
158 results.Result = (sceneA.GetScenePresence(agentId) == null); 394 Assert.That(afterSceneASp, Is.Not.Null);
159 if (!results.Result) 395 Assert.That(afterSceneASp.IsChildAgent, Is.True);
160 { 396
161 results.Message = "Client still had an agent in sceneA"; 397 ScenePresence afterSceneBSp = sceneB.GetScenePresence(userId);
162 return; 398 Assert.That(afterSceneBSp, Is.Not.Null);
163 } 399 Assert.That(afterSceneBSp.IsChildAgent, Is.False);
164 400 Assert.That(afterSceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
165 ICapabilitiesModule sceneBCapsModule = sceneB.RequestModuleInterface<ICapabilitiesModule>(); 401 Assert.That(afterSceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition));
166 402
167 403 Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
168 results.Result = ("http://" + sceneB.RegionInfo.ExternalHostName + ":" + sceneB.RegionInfo.HttpPort + 404 Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(1));
169 "/CAPS/" + sceneBCapsModule.GetCapsPath(agentId) + "0000/" == client.CapsSeedUrl); 405 Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
170 if (!results.Result) 406 Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
171 { 407
172 results.Message = "Incorrect caps object path set up in sceneB"; 408 // TODO: Add assertions to check correct circuit details in both scenes.
173 return; 409
174 } 410 // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
175 411 // position instead).
176 // Temporary assertion - caps url construction should at least be doable through a method. 412// Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
177 /* 413
178 Assert.That( 414// TestHelpers.DisableLogging();
179 "http://" + sceneB.RegionInfo.ExternalHostName + ":" + sceneB.RegionInfo.HttpPort + "/CAPS/" + sceneBCapsModule.GetCapsPath(agentId) + "0000/",
180 Is.EqualTo(client.CapsSeedUrl),
181 "Incorrect caps object path set up in sceneB");
182 */
183 // This assertion will currently fail since we don't remove the caps paths when no longer needed
184 //Assert.That(sceneACapsModule.GetCapsPath(agentId), Is.Null, "sceneA still had a caps object path");
185
186 // TODO: Check that more of everything is as it should be
187
188 // TODO: test what happens if we try to teleport to a region that doesn't exist
189 } 415 }
190 } 416 }
191} 417} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
index 5c9a77d..d722a09 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -60,7 +60,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
60 { 60 {
61 TestHelpers.InMethod(); 61 TestHelpers.InMethod();
62 62
63 Scene scene = SceneHelpers.SetupScene(); 63 Scene scene = new SceneHelpers().SetupScene();
64 scene.Update(1); 64 scene.Update(1);
65 65
66 Assert.That(scene.Frame, Is.EqualTo(1)); 66 Assert.That(scene.Frame, Is.EqualTo(1));
diff --git a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs
index 55c80f5..d15141b 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs
@@ -58,7 +58,7 @@ namespace OpenSim.Region.Framework.Tests
58 TestHelpers.InMethod(); 58 TestHelpers.InMethod();
59// log4net.Config.XmlConfigurator.Configure(); 59// log4net.Config.XmlConfigurator.Configure();
60 60
61 Scene scene = SceneHelpers.SetupScene(); 61 Scene scene = new SceneHelpers().SetupScene();
62 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); 62 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene);
63 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); 63 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID);
64 SceneObjectPart sop1 = sog1.RootPart; 64 SceneObjectPart sop1 = sog1.RootPart;
@@ -81,7 +81,7 @@ namespace OpenSim.Region.Framework.Tests
81 TestHelpers.InMethod(); 81 TestHelpers.InMethod();
82// log4net.Config.XmlConfigurator.Configure(); 82// log4net.Config.XmlConfigurator.Configure();
83 83
84 Scene scene = SceneHelpers.SetupScene(); 84 Scene scene = new SceneHelpers().SetupScene();
85 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); 85 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene);
86 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); 86 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID);
87 SceneObjectPart sop1 = sog1.RootPart; 87 SceneObjectPart sop1 = sog1.RootPart;
@@ -124,7 +124,7 @@ namespace OpenSim.Region.Framework.Tests
124 TestHelpers.InMethod(); 124 TestHelpers.InMethod();
125// log4net.Config.XmlConfigurator.Configure(); 125// log4net.Config.XmlConfigurator.Configure();
126 126
127 Scene scene = SceneHelpers.SetupScene(); 127 Scene scene = new SceneHelpers().SetupScene();
128 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); 128 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene);
129 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); 129 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID);
130 SceneObjectPart sop1 = sog1.RootPart; 130 SceneObjectPart sop1 = sog1.RootPart;
@@ -153,7 +153,7 @@ namespace OpenSim.Region.Framework.Tests
153 TestHelpers.InMethod(); 153 TestHelpers.InMethod();
154// log4net.Config.XmlConfigurator.Configure(); 154// log4net.Config.XmlConfigurator.Configure();
155 155
156 Scene scene = SceneHelpers.SetupScene(); 156 Scene scene = new SceneHelpers().SetupScene();
157 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene); 157 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene);
158 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID); 158 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, user1.PrincipalID);
159 SceneObjectPart sop1 = sog1.RootPart; 159 SceneObjectPart sop1 = sog1.RootPart;
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs
index 55fc1e7..44d2d45 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs
@@ -58,7 +58,7 @@ namespace OpenSim.Region.Framework.Tests
58 TestHelpers.InMethod(); 58 TestHelpers.InMethod();
59// log4net.Config.XmlConfigurator.Configure(); 59// log4net.Config.XmlConfigurator.Configure();
60 60
61 Scene scene = SceneHelpers.SetupScene(); 61 Scene scene = new SceneHelpers().SetupScene();
62 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001)); 62 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
63 UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002)); 63 UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
64 InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID); 64 InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID);
@@ -85,7 +85,7 @@ namespace OpenSim.Region.Framework.Tests
85 TestHelpers.InMethod(); 85 TestHelpers.InMethod();
86// log4net.Config.XmlConfigurator.Configure(); 86// log4net.Config.XmlConfigurator.Configure();
87 87
88 Scene scene = SceneHelpers.SetupScene(); 88 Scene scene = new SceneHelpers().SetupScene();
89 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001)); 89 UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
90 UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002)); 90 UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
91 InventoryFolderBase folder1 91 InventoryFolderBase folder1
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
index d9fe87c..198e487 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
@@ -47,7 +47,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
47 public void Init() 47 public void Init()
48 { 48 {
49 // FIXME: We don't need a full scene here - it would be enough to set up the asset service. 49 // FIXME: We don't need a full scene here - it would be enough to set up the asset service.
50 Scene scene = SceneHelpers.SetupScene(); 50 Scene scene = new SceneHelpers().SetupScene();
51 m_assetService = scene.AssetService; 51 m_assetService = scene.AssetService;
52 m_uuidGatherer = new UuidGatherer(m_assetService); 52 m_uuidGatherer = new UuidGatherer(m_assetService);
53 } 53 }
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
index eac8e84..b449089 100644
--- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
+++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
@@ -1635,11 +1635,6 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
1635 1635
1636 } 1636 }
1637 1637
1638 public void KillEndDone()
1639 {
1640
1641 }
1642
1643 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler) 1638 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
1644 { 1639 {
1645 return true; 1640 return true;
diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs
new file mode 100644
index 0000000..1b9e3ac
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs
@@ -0,0 +1,195 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Text;
33using log4net;
34using Mono.Addins;
35using Nini.Config;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Framework.Console;
39using OpenSim.Framework.Statistics;
40using OpenSim.Region.ClientStack.LindenUDP;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43
44namespace OpenSim.Region.OptionalModules.Avatar.Attachments
45{
46 /// <summary>
47 /// A module that just holds commands for inspecting avatar appearance.
48 /// </summary>
49 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AttachmentsCommandModule")]
50 public class AttachmentsCommandModule : ISharedRegionModule
51 {
52// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 private List<Scene> m_scenes = new List<Scene>();
55// private IAvatarFactoryModule m_avatarFactory;
56
57 public string Name { get { return "Attachments Command Module"; } }
58
59 public Type ReplaceableInterface { get { return null; } }
60
61 public void Initialise(IConfigSource source)
62 {
63// m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: INITIALIZED MODULE");
64 }
65
66 public void PostInitialise()
67 {
68// m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: POST INITIALIZED MODULE");
69 }
70
71 public void Close()
72 {
73// m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: CLOSED MODULE");
74 }
75
76 public void AddRegion(Scene scene)
77 {
78// m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
79 }
80
81 public void RemoveRegion(Scene scene)
82 {
83// m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
84
85 lock (m_scenes)
86 m_scenes.Remove(scene);
87 }
88
89 public void RegionLoaded(Scene scene)
90 {
91// m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
92
93 lock (m_scenes)
94 m_scenes.Add(scene);
95
96 scene.AddCommand(
97 "Users", this, "attachments show",
98 "attachments show [<first-name> <last-name>]",
99 "Show attachment information for avatars in this simulator.",
100 HandleShowAttachmentsCommand);
101 }
102
103 protected void HandleShowAttachmentsCommand(string module, string[] cmd)
104 {
105 if (cmd.Length != 2 && cmd.Length < 4)
106 {
107 MainConsole.Instance.OutputFormat("Usage: attachments show [<first-name> <last-name>]");
108 return;
109 }
110
111 bool targetNameSupplied = false;
112 string optionalTargetFirstName = null;
113 string optionalTargetLastName = null;
114
115 if (cmd.Length >= 4)
116 {
117 targetNameSupplied = true;
118 optionalTargetFirstName = cmd[2];
119 optionalTargetLastName = cmd[3];
120 }
121
122 StringBuilder sb = new StringBuilder();
123
124 lock (m_scenes)
125 {
126 foreach (Scene scene in m_scenes)
127 {
128 if (targetNameSupplied)
129 {
130 ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
131 if (sp != null && !sp.IsChildAgent)
132 GetAttachmentsReport(sp, sb);
133 }
134 else
135 {
136 scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb));
137 }
138 }
139 }
140
141 MainConsole.Instance.Output(sb.ToString());
142 }
143
144 private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb)
145 {
146 sb.AppendFormat("Attachments for {0}\n", sp.Name);
147
148 ConsoleDisplayTable ct = new ConsoleDisplayTable() { Indent = 2 };
149 ct.Columns.Add(new ConsoleDisplayTableColumn("Attachment Name", 36));
150 ct.Columns.Add(new ConsoleDisplayTableColumn("Local ID", 10));
151 ct.Columns.Add(new ConsoleDisplayTableColumn("Item ID", 36));
152 ct.Columns.Add(new ConsoleDisplayTableColumn("Attach Point", 14));
153 ct.Columns.Add(new ConsoleDisplayTableColumn("Position", 15));
154
155// sb.AppendFormat(
156// " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
157// "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position");
158
159 List<SceneObjectGroup> attachmentObjects = sp.GetAttachments();
160 foreach (SceneObjectGroup attachmentObject in attachmentObjects)
161 {
162// InventoryItemBase attachmentItem
163// = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID));
164
165// if (attachmentItem == null)
166// {
167// sb.AppendFormat(
168// "WARNING: Couldn't find attachment for item {0} at point {1}\n",
169// attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint);
170// continue;
171// }
172// else
173// {
174// sb.AppendFormat(
175// " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
176// attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID,
177// (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos);
178 ct.Rows.Add(
179 new ConsoleDisplayTableRow(
180 new List<string>()
181 {
182 attachmentObject.Name,
183 attachmentObject.LocalId.ToString(),
184 attachmentObject.FromItemID.ToString(),
185 ((AttachmentPoint)attachmentObject.AttachmentPoint).ToString(),
186 attachmentObject.RootPart.AttachedPos.ToString()
187 }));
188// }
189 }
190
191 ct.AddToStringBuilder(sb);
192 sb.Append("\n");
193 }
194 }
195} \ No newline at end of file
diff --git a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
index e68f9d0..2602050 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
@@ -58,6 +58,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
58 private Scene m_scene; 58 private Scene m_scene;
59 private IFriendsModule m_friendsModule; 59 private IFriendsModule m_friendsModule;
60 private IUserManagement m_userManagementModule; 60 private IUserManagement m_userManagementModule;
61 private IPresenceService m_presenceService;
61 62
62// private IAvatarFactoryModule m_avatarFactory; 63// private IAvatarFactoryModule m_avatarFactory;
63 64
@@ -99,8 +100,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
99 100
100 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 101 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
101 m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>(); 102 m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>();
103 m_presenceService = m_scene.RequestModuleInterface<IPresenceService>();
102 104
103 if (m_friendsModule != null && m_userManagementModule != null) 105 if (m_friendsModule != null && m_userManagementModule != null && m_presenceService != null)
104 { 106 {
105 m_scene.AddCommand( 107 m_scene.AddCommand(
106 "Friends", this, "friends show", 108 "Friends", this, "friends show",
@@ -162,7 +164,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
162 164
163 MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId); 165 MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId);
164 166
165 MainConsole.Instance.OutputFormat("UUID, Name, MyFlags, TheirFlags"); 167 MainConsole.Instance.OutputFormat(
168 "{0,-36} {1,-36} {2,-7} {3,7} {4,10}", "UUID", "Name", "Status", "MyFlags", "TheirFlags");
166 169
167 foreach (FriendInfo friend in friends) 170 foreach (FriendInfo friend in friends)
168 { 171 {
@@ -175,14 +178,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
175 178
176 UUID friendId; 179 UUID friendId;
177 string friendName; 180 string friendName;
181 string onlineText;
178 182
179 if (UUID.TryParse(friend.Friend, out friendId)) 183 if (UUID.TryParse(friend.Friend, out friendId))
180 friendName = m_userManagementModule.GetUserName(friendId); 184 friendName = m_userManagementModule.GetUserName(friendId);
181 else 185 else
182 friendName = friend.Friend; 186 friendName = friend.Friend;
183 187
188 OpenSim.Services.Interfaces.PresenceInfo[] pi = m_presenceService.GetAgents(new string[] { friend.Friend });
189 if (pi.Length > 0)
190 onlineText = "online";
191 else
192 onlineText = "offline";
193
184 MainConsole.Instance.OutputFormat( 194 MainConsole.Instance.OutputFormat(
185 "{0} {1} {2} {3}", friend.Friend, friendName, friend.MyFlags, friend.TheirFlags); 195 "{0,-36} {1,-36} {2,-7} {3,-7} {4,-10}",
196 friend.Friend, friendName, onlineText, friend.MyFlags, friend.TheirFlags);
186 } 197 }
187 } 198 }
188 } 199 }
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
index 8af3652..6c53d95 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
@@ -306,30 +306,35 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
306 agentID, caps, scene.RegionInfo.RegionName); 306 agentID, caps, scene.RegionInfo.RegionName);
307 307
308 string capsBase = "/CAPS/" + caps.CapsObjectPath; 308 string capsBase = "/CAPS/" + caps.CapsObjectPath;
309 caps.RegisterHandler("ProvisionVoiceAccountRequest", 309 caps.RegisterHandler(
310 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, 310 "ProvisionVoiceAccountRequest",
311 delegate(string request, string path, string param, 311 new RestStreamHandler(
312 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 312 "POST",
313 { 313 capsBase + m_provisionVoiceAccountRequestPath,
314 return ProvisionVoiceAccountRequest(scene, request, path, param, 314 (request, path, param, httpRequest, httpResponse)
315 agentID, caps); 315 => ProvisionVoiceAccountRequest(scene, request, path, param, agentID, caps),
316 })); 316 "ProvisionVoiceAccountRequest",
317 caps.RegisterHandler("ParcelVoiceInfoRequest", 317 agentID.ToString()));
318 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 318
319 delegate(string request, string path, string param, 319 caps.RegisterHandler(
320 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 320 "ParcelVoiceInfoRequest",
321 { 321 new RestStreamHandler(
322 return ParcelVoiceInfoRequest(scene, request, path, param, 322 "POST",
323 agentID, caps); 323 capsBase + m_parcelVoiceInfoRequestPath,
324 })); 324 (request, path, param, httpRequest, httpResponse)
325 caps.RegisterHandler("ChatSessionRequest", 325 => ParcelVoiceInfoRequest(scene, request, path, param, agentID, caps),
326 new RestStreamHandler("POST", capsBase + m_chatSessionRequestPath, 326 "ParcelVoiceInfoRequest",
327 delegate(string request, string path, string param, 327 agentID.ToString()));
328 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 328
329 { 329 caps.RegisterHandler(
330 return ChatSessionRequest(scene, request, path, param, 330 "ChatSessionRequest",
331 agentID, caps); 331 new RestStreamHandler(
332 })); 332 "POST",
333 capsBase + m_chatSessionRequestPath,
334 (request, path, param, httpRequest, httpResponse)
335 => ChatSessionRequest(scene, request, path, param, agentID, caps),
336 "ChatSessionRequest",
337 agentID.ToString()));
333 } 338 }
334 339
335 /// <summary> 340 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs
index 4dbac1d..396d4c5 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs
@@ -406,30 +406,36 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
406 m_log.DebugFormat("[VivoxVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 406 m_log.DebugFormat("[VivoxVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
407 407
408 string capsBase = "/CAPS/" + caps.CapsObjectPath; 408 string capsBase = "/CAPS/" + caps.CapsObjectPath;
409 caps.RegisterHandler("ProvisionVoiceAccountRequest", 409
410 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, 410 caps.RegisterHandler(
411 delegate(string request, string path, string param, 411 "ProvisionVoiceAccountRequest",
412 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 412 new RestStreamHandler(
413 { 413 "POST",
414 return ProvisionVoiceAccountRequest(scene, request, path, param, 414 capsBase + m_provisionVoiceAccountRequestPath,
415 agentID, caps); 415 (request, path, param, httpRequest, httpResponse)
416 })); 416 => ProvisionVoiceAccountRequest(scene, request, path, param, agentID, caps),
417 caps.RegisterHandler("ParcelVoiceInfoRequest", 417 "ProvisionVoiceAccountRequest",
418 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 418 agentID.ToString()));
419 delegate(string request, string path, string param, 419
420 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 420 caps.RegisterHandler(
421 { 421 "ParcelVoiceInfoRequest",
422 return ParcelVoiceInfoRequest(scene, request, path, param, 422 new RestStreamHandler(
423 agentID, caps); 423 "POST",
424 })); 424 capsBase + m_parcelVoiceInfoRequestPath,
425 caps.RegisterHandler("ChatSessionRequest", 425 (request, path, param, httpRequest, httpResponse)
426 new RestStreamHandler("POST", capsBase + m_chatSessionRequestPath, 426 => ParcelVoiceInfoRequest(scene, request, path, param, agentID, caps),
427 delegate(string request, string path, string param, 427 "ParcelVoiceInfoRequest",
428 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 428 agentID.ToString()));
429 { 429
430 return ChatSessionRequest(scene, request, path, param, 430 caps.RegisterHandler(
431 agentID, caps); 431 "ChatSessionRequest",
432 })); 432 new RestStreamHandler(
433 "POST",
434 capsBase + m_chatSessionRequestPath,
435 (request, path, param, httpRequest, httpResponse)
436 => ChatSessionRequest(scene, request, path, param, agentID, caps),
437 "ChatSessionRequest",
438 agentID.ToString()));
433 } 439 }
434 440
435 /// <summary> 441 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs
index 130513d..5d57f70 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs
@@ -1401,9 +1401,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
1401 { 1401 {
1402 response = WebUtil.PostToService(m_groupsServerURI, requestArgs); 1402 response = WebUtil.PostToService(m_groupsServerURI, requestArgs);
1403 } 1403 }
1404 catch (Exception e) 1404 catch (Exception)
1405 { 1405 {
1406 m_log.InfoFormat("[SIMIAN GROUPS CONNECTOR] request failed {0}",CacheKey); 1406 m_log.ErrorFormat("[SIMIAN GROUPS CONNECTOR]: request failed {0}", CacheKey);
1407 } 1407 }
1408 1408
1409 // and cache the response 1409 // and cache the response
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs
index d2f6327..ac638f1 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests
50 TestHelpers.InMethod(); 50 TestHelpers.InMethod();
51// log4net.Config.XmlConfigurator.Configure(); 51// log4net.Config.XmlConfigurator.Configure();
52 52
53 TestScene scene = SceneHelpers.SetupScene(); 53 TestScene scene = new SceneHelpers().SetupScene();
54 IConfigSource configSource = new IniConfigSource(); 54 IConfigSource configSource = new IniConfigSource();
55 IConfig config = configSource.AddConfig("Groups"); 55 IConfig config = configSource.AddConfig("Groups");
56 config.Set("Enabled", true); 56 config.Set("Enabled", true);
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
new file mode 100644
index 0000000..34894ba
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -0,0 +1,500 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using Mono.Addins;
28
29using System;
30using System.Reflection;
31using System.Threading;
32using System.Text;
33using System.Net;
34using System.Net.Sockets;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using System.Collections.Generic;
43using System.Text.RegularExpressions;
44
45namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
46{
47 public class JsonStore
48 {
49 private static readonly ILog m_log =
50 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private OSD m_ValueStore;
53
54 protected class TakeValueCallbackClass
55 {
56 public string Path { get; set; }
57 public bool UseJson { get; set; }
58 public TakeValueCallback Callback { get; set; }
59
60 public TakeValueCallbackClass(string spath, bool usejson, TakeValueCallback cback)
61 {
62 Path = spath;
63 UseJson = usejson;
64 Callback = cback;
65 }
66 }
67
68 protected List<TakeValueCallbackClass> m_TakeStore;
69 protected List<TakeValueCallbackClass> m_ReadStore;
70
71
72 // -----------------------------------------------------------------
73 /// <summary>
74 ///
75 /// </summary>
76 // -----------------------------------------------------------------
77 public JsonStore() : this("") {}
78
79 public JsonStore(string value)
80 {
81 m_TakeStore = new List<TakeValueCallbackClass>();
82 m_ReadStore = new List<TakeValueCallbackClass>();
83
84 if (String.IsNullOrEmpty(value))
85 m_ValueStore = new OSDMap();
86 else
87 m_ValueStore = OSDParser.DeserializeJson(value);
88 }
89
90 // -----------------------------------------------------------------
91 /// <summary>
92 ///
93 /// </summary>
94 // -----------------------------------------------------------------
95 public bool TestPath(string expr, bool useJson)
96 {
97 Stack<string> path = ParsePathExpression(expr);
98 OSD result = ProcessPathExpression(m_ValueStore,path);
99
100 if (result == null)
101 return false;
102
103 if (useJson || result.Type == OSDType.String)
104 return true;
105
106 return false;
107 }
108
109 // -----------------------------------------------------------------
110 /// <summary>
111 ///
112 /// </summary>
113 // -----------------------------------------------------------------
114 public bool GetValue(string expr, out string value, bool useJson)
115 {
116 Stack<string> path = ParsePathExpression(expr);
117 OSD result = ProcessPathExpression(m_ValueStore,path);
118 return ConvertOutputValue(result,out value,useJson);
119 }
120
121
122 // -----------------------------------------------------------------
123 /// <summary>
124 ///
125 /// </summary>
126 // -----------------------------------------------------------------
127 public bool RemoveValue(string expr)
128 {
129 return SetValueFromExpression(expr,null);
130 }
131
132 // -----------------------------------------------------------------
133 /// <summary>
134 ///
135 /// </summary>
136 // -----------------------------------------------------------------
137 public bool SetValue(string expr, string value, bool useJson)
138 {
139 OSD ovalue = useJson ? OSDParser.DeserializeJson(value) : new OSDString(value);
140 return SetValueFromExpression(expr,ovalue);
141 }
142
143 // -----------------------------------------------------------------
144 /// <summary>
145 ///
146 /// </summary>
147 // -----------------------------------------------------------------
148 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback)
149 {
150 Stack<string> path = ParsePathExpression(expr);
151 string pexpr = PathExpressionToKey(path);
152
153 OSD result = ProcessPathExpression(m_ValueStore,path);
154 if (result == null)
155 {
156 m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
157 return false;
158 }
159
160 string value = String.Empty;
161 if (! ConvertOutputValue(result,out value,useJson))
162 {
163 // the structure does not match the request so i guess we'll wait
164 m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
165 return false;
166 }
167
168 SetValueFromExpression(expr,null);
169 cback(value);
170
171 return true;
172 }
173
174 // -----------------------------------------------------------------
175 /// <summary>
176 ///
177 /// </summary>
178 // -----------------------------------------------------------------
179 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback)
180 {
181 Stack<string> path = ParsePathExpression(expr);
182 string pexpr = PathExpressionToKey(path);
183
184 OSD result = ProcessPathExpression(m_ValueStore,path);
185 if (result == null)
186 {
187 m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
188 return false;
189 }
190
191 string value = String.Empty;
192 if (! ConvertOutputValue(result,out value,useJson))
193 {
194 // the structure does not match the request so i guess we'll wait
195 m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
196 return false;
197 }
198
199 cback(value);
200
201 return true;
202 }
203
204 // -----------------------------------------------------------------
205 /// <summary>
206 ///
207 /// </summary>
208 // -----------------------------------------------------------------
209 protected bool SetValueFromExpression(string expr, OSD ovalue)
210 {
211 Stack<string> path = ParsePathExpression(expr);
212 if (path.Count == 0)
213 {
214 m_ValueStore = ovalue;
215 return true;
216 }
217
218 string pkey = path.Pop();
219 string pexpr = PathExpressionToKey(path);
220 if (pexpr != "")
221 pexpr += ".";
222
223 OSD result = ProcessPathExpression(m_ValueStore,path);
224 if (result == null)
225 return false;
226
227 Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]");
228 MatchCollection amatches = aPattern.Matches(pkey,0);
229
230 if (amatches.Count > 0)
231 {
232 if (result.Type != OSDType.Array)
233 return false;
234
235 OSDArray amap = result as OSDArray;
236
237 Match match = amatches[0];
238 GroupCollection groups = match.Groups;
239 string akey = groups[1].Value;
240
241 if (akey == "+")
242 {
243 string npkey = String.Format("[{0}]",amap.Count);
244
245 amap.Add(ovalue);
246 InvokeNextCallback(pexpr + npkey);
247 return true;
248 }
249
250 int aval = Convert.ToInt32(akey);
251 if (0 <= aval && aval < amap.Count)
252 {
253 if (ovalue == null)
254 amap.RemoveAt(aval);
255 else
256 {
257 amap[aval] = ovalue;
258 InvokeNextCallback(pexpr + pkey);
259 }
260 return true;
261 }
262
263 return false;
264 }
265
266 Regex hPattern = new Regex("{([^}]+)}");
267 MatchCollection hmatches = hPattern.Matches(pkey,0);
268
269 if (hmatches.Count > 0)
270 {
271 Match match = hmatches[0];
272 GroupCollection groups = match.Groups;
273 string hkey = groups[1].Value;
274
275 if (result is OSDMap)
276 {
277 OSDMap hmap = result as OSDMap;
278 if (ovalue != null)
279 {
280 hmap[hkey] = ovalue;
281 InvokeNextCallback(pexpr + pkey);
282 }
283 else if (hmap.ContainsKey(hkey))
284 hmap.Remove(hkey);
285
286 return true;
287 }
288
289 return false;
290 }
291
292 // Shouldn't get here if the path was checked correctly
293 m_log.WarnFormat("[JsonStore] invalid path expression");
294 return false;
295 }
296
297 // -----------------------------------------------------------------
298 /// <summary>
299 ///
300 /// </summary>
301 // -----------------------------------------------------------------
302 protected bool InvokeNextCallback(string pexpr)
303 {
304 // Process all of the reads that match the expression first
305 List<TakeValueCallbackClass> reads =
306 m_ReadStore.FindAll(delegate(TakeValueCallbackClass tb) { return pexpr.StartsWith(tb.Path); });
307
308 foreach (TakeValueCallbackClass readcb in reads)
309 {
310 m_ReadStore.Remove(readcb);
311 ReadValue(readcb.Path,readcb.UseJson,readcb.Callback);
312 }
313
314 // Process one take next
315 TakeValueCallbackClass takecb =
316 m_TakeStore.Find(delegate(TakeValueCallbackClass tb) { return pexpr.StartsWith(tb.Path); });
317
318 if (takecb != null)
319 {
320 m_TakeStore.Remove(takecb);
321 TakeValue(takecb.Path,takecb.UseJson,takecb.Callback);
322
323 return true;
324 }
325
326 return false;
327 }
328
329 // -----------------------------------------------------------------
330 /// <summary>
331 /// Parse the path expression and put the components into a stack. We
332 /// use a stack because we process the path in inverse order later
333 /// </summary>
334 // -----------------------------------------------------------------
335 protected static Stack<string> ParsePathExpression(string path)
336 {
337 Stack<string> m_path = new Stack<string>();
338
339 // add front and rear separators
340 path = "." + path + ".";
341
342 // add separators for quoted paths
343 Regex pass1 = new Regex("{[^}]+}");
344 path = pass1.Replace(path,".$0.",-1,0);
345
346 // add separators for array references
347 Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])");
348 path = pass2.Replace(path,".$0.",-1,0);
349
350 // add quotes to bare identifier
351 Regex pass3 = new Regex("\\.([a-zA-Z]+)");
352 path = pass3.Replace(path,".{$1}",-1,0);
353
354 // remove extra separators
355 Regex pass4 = new Regex("\\.+");
356 path = pass4.Replace(path,".",-1,0);
357
358 Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$");
359 if (validate.IsMatch(path))
360 {
361 Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)");
362 MatchCollection matches = parser.Matches(path,0);
363 foreach (Match match in matches)
364 m_path.Push(match.Groups[1].Value);
365 }
366
367 return m_path;
368 }
369
370 // -----------------------------------------------------------------
371 /// <summary>
372 ///
373 /// </summary>
374 /// <param>path is a stack where the top level of the path is at the bottom of the stack</param>
375 // -----------------------------------------------------------------
376 protected static OSD ProcessPathExpression(OSD map, Stack<string> path)
377 {
378 if (path.Count == 0)
379 return map;
380
381 string pkey = path.Pop();
382
383 OSD rmap = ProcessPathExpression(map,path);
384 if (rmap == null)
385 return null;
386
387 // ---------- Check for an array index ----------
388 Regex aPattern = new Regex("\\[([0-9]+)\\]");
389 MatchCollection amatches = aPattern.Matches(pkey,0);
390
391 if (amatches.Count > 0)
392 {
393 if (rmap.Type != OSDType.Array)
394 {
395 m_log.WarnFormat("[JsonStore] wrong type for key {2}, expecting {0}, got {1}",OSDType.Array,rmap.Type,pkey);
396 return null;
397 }
398
399 OSDArray amap = rmap as OSDArray;
400
401 Match match = amatches[0];
402 GroupCollection groups = match.Groups;
403 string akey = groups[1].Value;
404 int aval = Convert.ToInt32(akey);
405
406 if (aval < amap.Count)
407 return (OSD) amap[aval];
408
409 return null;
410 }
411
412 // ---------- Check for a hash index ----------
413 Regex hPattern = new Regex("{([^}]+)}");
414 MatchCollection hmatches = hPattern.Matches(pkey,0);
415
416 if (hmatches.Count > 0)
417 {
418 if (rmap.Type != OSDType.Map)
419 {
420 m_log.WarnFormat("[JsonStore] wrong type for key {2}, expecting {0}, got {1}",OSDType.Map,rmap.Type,pkey);
421 return null;
422 }
423
424 OSDMap hmap = rmap as OSDMap;
425
426 Match match = hmatches[0];
427 GroupCollection groups = match.Groups;
428 string hkey = groups[1].Value;
429
430 if (hmap.ContainsKey(hkey))
431 return (OSD) hmap[hkey];
432
433 return null;
434 }
435
436 // Shouldn't get here if the path was checked correctly
437 m_log.WarnFormat("[JsonStore] Path type (unknown) does not match the structure");
438 return null;
439 }
440
441 // -----------------------------------------------------------------
442 /// <summary>
443 ///
444 /// </summary>
445 // -----------------------------------------------------------------
446 protected static bool ConvertOutputValue(OSD result, out string value, bool useJson)
447 {
448 value = String.Empty;
449
450 // If we couldn't process the path
451 if (result == null)
452 return false;
453
454 if (useJson)
455 {
456 // The path pointed to an intermediate hash structure
457 if (result.Type == OSDType.Map)
458 {
459 value = OSDParser.SerializeJsonString(result as OSDMap);
460 return true;
461 }
462
463 // The path pointed to an intermediate hash structure
464 if (result.Type == OSDType.Array)
465 {
466 value = OSDParser.SerializeJsonString(result as OSDArray);
467 return true;
468 }
469
470 value = "'" + result.AsString() + "'";
471 return true;
472 }
473
474 if (result.Type == OSDType.String)
475 {
476 value = result.AsString();
477 return true;
478 }
479
480 return false;
481 }
482
483 // -----------------------------------------------------------------
484 /// <summary>
485 ///
486 /// </summary>
487 // -----------------------------------------------------------------
488 protected static string PathExpressionToKey(Stack<string> path)
489 {
490 if (path.Count == 0)
491 return "";
492
493 string pkey = "";
494 foreach (string k in path)
495 pkey = (pkey == "") ? k : (k + "." + pkey);
496
497 return pkey;
498 }
499 }
500}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
new file mode 100644
index 0000000..311531c
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -0,0 +1,430 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using Mono.Addins;
28
29using System;
30using System.Reflection;
31using System.Threading;
32using System.Text;
33using System.Net;
34using System.Net.Sockets;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using System.Collections.Generic;
43using System.Text.RegularExpressions;
44
45
46namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
47{
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")]
49
50 public class JsonStoreModule : INonSharedRegionModule, IJsonStoreModule
51 {
52 private static readonly ILog m_log =
53 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 private IConfig m_config = null;
56 private bool m_enabled = false;
57 private Scene m_scene = null;
58
59 private Dictionary<UUID,JsonStore> m_JsonValueStore;
60 private UUID m_sharedStore;
61
62#region IRegionModule Members
63
64 // -----------------------------------------------------------------
65 /// <summary>
66 /// Name of this shared module is it's class name
67 /// </summary>
68 // -----------------------------------------------------------------
69 public string Name
70 {
71 get { return this.GetType().Name; }
72 }
73
74 // -----------------------------------------------------------------
75 /// <summary>
76 /// Initialise this shared module
77 /// </summary>
78 /// <param name="scene">this region is getting initialised</param>
79 /// <param name="source">nini config, we are not using this</param>
80 // -----------------------------------------------------------------
81 public void Initialise(IConfigSource config)
82 {
83 try
84 {
85 if ((m_config = config.Configs["JsonStore"]) == null)
86 {
87 // There is no configuration, the module is disabled
88 // m_log.InfoFormat("[JsonStore] no configuration info");
89 return;
90 }
91
92 m_enabled = m_config.GetBoolean("Enabled", m_enabled);
93 }
94 catch (Exception e)
95 {
96 m_log.ErrorFormat("[JsonStore] initialization error: {0}",e.Message);
97 return;
98 }
99
100 if (m_enabled)
101 m_log.DebugFormat("[JsonStore] module is enabled");
102 }
103
104 // -----------------------------------------------------------------
105 /// <summary>
106 /// everything is loaded, perform post load configuration
107 /// </summary>
108 // -----------------------------------------------------------------
109 public void PostInitialise()
110 {
111 }
112
113 // -----------------------------------------------------------------
114 /// <summary>
115 /// Nothing to do on close
116 /// </summary>
117 // -----------------------------------------------------------------
118 public void Close()
119 {
120 }
121
122 // -----------------------------------------------------------------
123 /// <summary>
124 /// </summary>
125 // -----------------------------------------------------------------
126 public void AddRegion(Scene scene)
127 {
128 if (m_enabled)
129 {
130 m_scene = scene;
131 m_scene.RegisterModuleInterface<IJsonStoreModule>(this);
132
133 m_sharedStore = UUID.Zero;
134 m_JsonValueStore = new Dictionary<UUID,JsonStore>();
135 m_JsonValueStore.Add(m_sharedStore,new JsonStore(""));
136 }
137 }
138
139 // -----------------------------------------------------------------
140 /// <summary>
141 /// </summary>
142 // -----------------------------------------------------------------
143 public void RemoveRegion(Scene scene)
144 {
145 // need to remove all references to the scene in the subscription
146 // list to enable full garbage collection of the scene object
147 }
148
149 // -----------------------------------------------------------------
150 /// <summary>
151 /// Called when all modules have been added for a region. This is
152 /// where we hook up events
153 /// </summary>
154 // -----------------------------------------------------------------
155 public void RegionLoaded(Scene scene)
156 {
157 if (m_enabled) {}
158 }
159
160 /// -----------------------------------------------------------------
161 /// <summary>
162 /// </summary>
163 // -----------------------------------------------------------------
164 public Type ReplaceableInterface
165 {
166 get { return null; }
167 }
168
169#endregion
170
171#region ScriptInvocationInteface
172
173 // -----------------------------------------------------------------
174 /// <summary>
175 ///
176 /// </summary>
177 // -----------------------------------------------------------------
178 public bool CreateStore(string value, out UUID result)
179 {
180 result = UUID.Zero;
181
182 if (! m_enabled) return false;
183
184 UUID uuid = UUID.Random();
185 JsonStore map = null;
186
187 try
188 {
189 map = new JsonStore(value);
190 }
191 catch (Exception e)
192 {
193 m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message);
194 return false;
195 }
196
197 lock (m_JsonValueStore)
198 m_JsonValueStore.Add(uuid,map);
199
200 result = uuid;
201 return true;
202 }
203
204 // -----------------------------------------------------------------
205 /// <summary>
206 ///
207 /// </summary>
208 // -----------------------------------------------------------------
209 public bool DestroyStore(UUID storeID)
210 {
211 if (! m_enabled) return false;
212
213 lock (m_JsonValueStore)
214 m_JsonValueStore.Remove(storeID);
215
216 return true;
217 }
218
219 // -----------------------------------------------------------------
220 /// <summary>
221 ///
222 /// </summary>
223 // -----------------------------------------------------------------
224 public bool TestPath(UUID storeID, string path, bool useJson)
225 {
226 if (! m_enabled) return false;
227
228 JsonStore map = null;
229 lock (m_JsonValueStore)
230 {
231 if (! m_JsonValueStore.TryGetValue(storeID,out map))
232 {
233 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
234 return true;
235 }
236 }
237
238 try
239 {
240 lock (map)
241 return map.TestPath(path,useJson);
242 }
243 catch (Exception e)
244 {
245 m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message);
246 }
247
248 return false;
249 }
250
251 // -----------------------------------------------------------------
252 /// <summary>
253 ///
254 /// </summary>
255 // -----------------------------------------------------------------
256 public bool SetValue(UUID storeID, string path, string value, bool useJson)
257 {
258 if (! m_enabled) return false;
259
260 JsonStore map = null;
261 lock (m_JsonValueStore)
262 {
263 if (! m_JsonValueStore.TryGetValue(storeID,out map))
264 {
265 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
266 return false;
267 }
268 }
269
270 try
271 {
272 lock (map)
273 if (map.SetValue(path,value,useJson))
274 return true;
275 }
276 catch (Exception e)
277 {
278 m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message);
279 }
280
281 return false;
282 }
283
284 // -----------------------------------------------------------------
285 /// <summary>
286 ///
287 /// </summary>
288 // -----------------------------------------------------------------
289 public bool RemoveValue(UUID storeID, string path)
290 {
291 if (! m_enabled) return false;
292
293 JsonStore map = null;
294 lock (m_JsonValueStore)
295 {
296 if (! m_JsonValueStore.TryGetValue(storeID,out map))
297 {
298 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
299 return false;
300 }
301 }
302
303 try
304 {
305 lock (map)
306 if (map.RemoveValue(path))
307 return true;
308 }
309 catch (Exception e)
310 {
311 m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message);
312 }
313
314 return false;
315 }
316
317 // -----------------------------------------------------------------
318 /// <summary>
319 ///
320 /// </summary>
321 // -----------------------------------------------------------------
322 public bool GetValue(UUID storeID, string path, bool useJson, out string value)
323 {
324 value = String.Empty;
325
326 if (! m_enabled) return false;
327
328 JsonStore map = null;
329 lock (m_JsonValueStore)
330 {
331 if (! m_JsonValueStore.TryGetValue(storeID,out map))
332 return false;
333 }
334
335 try
336 {
337 lock (map)
338 {
339 return map.GetValue(path, out value, useJson);
340 }
341 }
342 catch (Exception e)
343 {
344 m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message);
345 }
346
347 return false;
348 }
349
350 // -----------------------------------------------------------------
351 /// <summary>
352 ///
353 /// </summary>
354 // -----------------------------------------------------------------
355 public void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback)
356 {
357 if (! m_enabled)
358 {
359 cback(String.Empty);
360 return;
361 }
362
363 JsonStore map = null;
364 lock (m_JsonValueStore)
365 {
366 if (! m_JsonValueStore.TryGetValue(storeID,out map))
367 {
368 cback(String.Empty);
369 return;
370 }
371 }
372
373 try
374 {
375 lock (map)
376 {
377 map.TakeValue(path, useJson, cback);
378 return;
379 }
380 }
381 catch (Exception e)
382 {
383 m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString());
384 }
385
386 cback(String.Empty);
387 }
388
389 // -----------------------------------------------------------------
390 /// <summary>
391 ///
392 /// </summary>
393 // -----------------------------------------------------------------
394 public void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback)
395 {
396 if (! m_enabled)
397 {
398 cback(String.Empty);
399 return;
400 }
401
402 JsonStore map = null;
403 lock (m_JsonValueStore)
404 {
405 if (! m_JsonValueStore.TryGetValue(storeID,out map))
406 {
407 cback(String.Empty);
408 return;
409 }
410 }
411
412 try
413 {
414 lock (map)
415 {
416 map.ReadValue(path, useJson, cback);
417 return;
418 }
419 }
420 catch (Exception e)
421 {
422 m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString());
423 }
424
425 cback(String.Empty);
426 }
427
428#endregion
429 }
430}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
new file mode 100644
index 0000000..4949097
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -0,0 +1,499 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using Mono.Addins;
28
29using System;
30using System.Reflection;
31using System.Threading;
32using System.Text;
33using System.Net;
34using System.Net.Sockets;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using System.Collections.Generic;
43using System.Text.RegularExpressions;
44
45namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
46{
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreScriptModule")]
48
49 public class JsonStoreScriptModule : INonSharedRegionModule
50 {
51 private static readonly ILog m_log =
52 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 private IConfig m_config = null;
55 private bool m_enabled = false;
56 private Scene m_scene = null;
57
58 private IScriptModuleComms m_comms;
59 private IJsonStoreModule m_store;
60
61#region IRegionModule Members
62
63 // -----------------------------------------------------------------
64 /// <summary>
65 /// Name of this shared module is it's class name
66 /// </summary>
67 // -----------------------------------------------------------------
68 public string Name
69 {
70 get { return this.GetType().Name; }
71 }
72
73 // -----------------------------------------------------------------
74 /// <summary>
75 /// Initialise this shared module
76 /// </summary>
77 /// <param name="scene">this region is getting initialised</param>
78 /// <param name="source">nini config, we are not using this</param>
79 // -----------------------------------------------------------------
80 public void Initialise(IConfigSource config)
81 {
82 try
83 {
84 if ((m_config = config.Configs["JsonStore"]) == null)
85 {
86 // There is no configuration, the module is disabled
87 // m_log.InfoFormat("[JsonStoreScripts] no configuration info");
88 return;
89 }
90
91 m_enabled = m_config.GetBoolean("Enabled", m_enabled);
92 }
93 catch (Exception e)
94 {
95 m_log.ErrorFormat("[JsonStoreScripts] initialization error: {0}",e.Message);
96 return;
97 }
98
99 if (m_enabled)
100 m_log.DebugFormat("[JsonStoreScripts] module is enabled");
101 }
102
103 // -----------------------------------------------------------------
104 /// <summary>
105 /// everything is loaded, perform post load configuration
106 /// </summary>
107 // -----------------------------------------------------------------
108 public void PostInitialise()
109 {
110 }
111
112 // -----------------------------------------------------------------
113 /// <summary>
114 /// Nothing to do on close
115 /// </summary>
116 // -----------------------------------------------------------------
117 public void Close()
118 {
119 }
120
121 // -----------------------------------------------------------------
122 /// <summary>
123 /// </summary>
124 // -----------------------------------------------------------------
125 public void AddRegion(Scene scene)
126 {
127 }
128
129 // -----------------------------------------------------------------
130 /// <summary>
131 /// </summary>
132 // -----------------------------------------------------------------
133 public void RemoveRegion(Scene scene)
134 {
135 // need to remove all references to the scene in the subscription
136 // list to enable full garbage collection of the scene object
137 }
138
139 // -----------------------------------------------------------------
140 /// <summary>
141 /// Called when all modules have been added for a region. This is
142 /// where we hook up events
143 /// </summary>
144 // -----------------------------------------------------------------
145 public void RegionLoaded(Scene scene)
146 {
147 if (m_enabled)
148 {
149 m_scene = scene;
150 m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>();
151 if (m_comms == null)
152 {
153 m_log.ErrorFormat("[JsonStoreScripts] ScriptModuleComms interface not defined");
154 m_enabled = false;
155 return;
156 }
157
158 m_store = m_scene.RequestModuleInterface<IJsonStoreModule>();
159 if (m_store == null)
160 {
161 m_log.ErrorFormat("[JsonStoreScripts] JsonModule interface not defined");
162 m_enabled = false;
163 return;
164 }
165
166 try
167 {
168 m_comms.RegisterScriptInvocation(this,"JsonCreateStore");
169 m_comms.RegisterScriptInvocation(this,"JsonDestroyStore");
170
171 m_comms.RegisterScriptInvocation(this,"JsonReadNotecard");
172 m_comms.RegisterScriptInvocation(this,"JsonWriteNotecard");
173
174 m_comms.RegisterScriptInvocation(this,"JsonTestPath");
175 m_comms.RegisterScriptInvocation(this,"JsonTestPathJson");
176
177 m_comms.RegisterScriptInvocation(this,"JsonGetValue");
178 m_comms.RegisterScriptInvocation(this,"JsonGetValueJson");
179
180 m_comms.RegisterScriptInvocation(this,"JsonTakeValue");
181 m_comms.RegisterScriptInvocation(this,"JsonTakeValueJson");
182
183 m_comms.RegisterScriptInvocation(this,"JsonReadValue");
184 m_comms.RegisterScriptInvocation(this,"JsonReadValueJson");
185
186 m_comms.RegisterScriptInvocation(this,"JsonSetValue");
187 m_comms.RegisterScriptInvocation(this,"JsonSetValueJson");
188
189 m_comms.RegisterScriptInvocation(this,"JsonRemoveValue");
190 }
191 catch (Exception e)
192 {
193 // See http://opensimulator.org/mantis/view.php?id=5971 for more information
194 m_log.WarnFormat("[JsonStroreScripts] script method registration failed; {0}",e.Message);
195 m_enabled = false;
196 }
197 }
198 }
199
200 /// -----------------------------------------------------------------
201 /// <summary>
202 /// </summary>
203 // -----------------------------------------------------------------
204 public Type ReplaceableInterface
205 {
206 get { return null; }
207 }
208
209#endregion
210
211#region ScriptInvocationInteface
212 // -----------------------------------------------------------------
213 /// <summary>
214 ///
215 /// </summary>
216 // -----------------------------------------------------------------
217 protected void GenerateRuntimeError(string msg)
218 {
219 throw new Exception("JsonStore Runtime Error: " + msg);
220 }
221
222 // -----------------------------------------------------------------
223 /// <summary>
224 ///
225 /// </summary>
226 // -----------------------------------------------------------------
227 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
228 {
229 UUID uuid = UUID.Zero;
230 if (! m_store.CreateStore(value, out uuid))
231 GenerateRuntimeError("Failed to create Json store");
232
233 return uuid;
234 }
235
236 // -----------------------------------------------------------------
237 /// <summary>
238 ///
239 /// </summary>
240 // -----------------------------------------------------------------
241 protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
242 {
243 return m_store.DestroyStore(storeID) ? 1 : 0;
244 }
245
246 // -----------------------------------------------------------------
247 /// <summary>
248 ///
249 /// </summary>
250 // -----------------------------------------------------------------
251 protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID)
252 {
253 UUID reqID = UUID.Random();
254 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); });
255 return reqID;
256 }
257
258 // -----------------------------------------------------------------
259 /// <summary>
260 ///
261 /// </summary>
262 // -----------------------------------------------------------------
263 protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
264 {
265 UUID reqID = UUID.Random();
266 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); });
267 return reqID;
268 }
269
270 // -----------------------------------------------------------------
271 /// <summary>
272 ///
273 /// </summary>
274 // -----------------------------------------------------------------
275 protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
276 {
277 return m_store.TestPath(storeID,path,false) ? 1 : 0;
278 }
279
280 protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path)
281 {
282 return m_store.TestPath(storeID,path,true) ? 1 : 0;
283 }
284
285 // -----------------------------------------------------------------
286 /// <summary>
287 ///
288 /// </summary>
289 // -----------------------------------------------------------------
290 protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
291 {
292 return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
293 }
294
295 protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
296 {
297 return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
298 }
299
300 // -----------------------------------------------------------------
301 /// <summary>
302 ///
303 /// </summary>
304 // -----------------------------------------------------------------
305 protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
306 {
307 return m_store.RemoveValue(storeID,path) ? 1 : 0;
308 }
309
310 // -----------------------------------------------------------------
311 /// <summary>
312 ///
313 /// </summary>
314 // -----------------------------------------------------------------
315 protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
316 {
317 string value = String.Empty;
318 m_store.GetValue(storeID,path,false,out value);
319 return value;
320 }
321
322 protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
323 {
324 string value = String.Empty;
325 m_store.GetValue(storeID,path,true, out value);
326 return value;
327 }
328
329 // -----------------------------------------------------------------
330 /// <summary>
331 ///
332 /// </summary>
333 // -----------------------------------------------------------------
334 protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
335 {
336 UUID reqID = UUID.Random();
337 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); });
338 return reqID;
339 }
340
341 protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
342 {
343 UUID reqID = UUID.Random();
344 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); });
345 return reqID;
346 }
347
348 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
349 {
350 try
351 {
352 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
353 return;
354 }
355 catch (Exception e)
356 {
357 m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString());
358 }
359
360 DispatchValue(scriptID,reqID,String.Empty);
361 }
362
363
364 // -----------------------------------------------------------------
365 /// <summary>
366 ///
367 /// </summary>
368 // -----------------------------------------------------------------
369 protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
370 {
371 UUID reqID = UUID.Random();
372 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); });
373 return reqID;
374 }
375
376 protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
377 {
378 UUID reqID = UUID.Random();
379 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); });
380 return reqID;
381 }
382
383 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
384 {
385 try
386 {
387 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
388 return;
389 }
390 catch (Exception e)
391 {
392 m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString());
393 }
394
395 DispatchValue(scriptID,reqID,String.Empty);
396 }
397
398#endregion
399
400 // -----------------------------------------------------------------
401 /// <summary>
402 ///
403 /// </summary>
404 // -----------------------------------------------------------------
405 protected void DispatchValue(UUID scriptID, UUID reqID, string value)
406 {
407 m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
408 }
409
410 // -----------------------------------------------------------------
411 /// <summary>
412 ///
413 /// </summary>
414 // -----------------------------------------------------------------
415 private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID)
416 {
417 AssetBase a = m_scene.AssetService.Get(assetID.ToString());
418 if (a == null)
419 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID));
420
421 if (a.Type != (sbyte)AssetType.Notecard)
422 GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID));
423
424 m_log.DebugFormat("[JsonStoreScripts] read notecard in context {0}",storeID);
425
426 try
427 {
428 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
429 string jsondata = SLUtil.ParseNotecardToString(enc.GetString(a.Data));
430 int result = m_store.SetValue(storeID,path,jsondata,true) ? 1 : 0;
431 m_comms.DispatchReply(scriptID,result,"",reqID.ToString());
432 return;
433 }
434 catch (Exception e)
435 {
436 m_log.WarnFormat("[JsonStoreScripts] Json parsing failed; {0}",e.Message);
437 }
438
439 GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString()));
440 m_comms.DispatchReply(scriptID,0,"",reqID.ToString());
441 }
442
443 // -----------------------------------------------------------------
444 /// <summary>
445 ///
446 /// </summary>
447 // -----------------------------------------------------------------
448 private void DoJsonWriteNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string name)
449 {
450 string data;
451 if (! m_store.GetValue(storeID,path,true, out data))
452 {
453 m_comms.DispatchReply(scriptID,0,UUID.Zero.ToString(),reqID.ToString());
454 return;
455 }
456
457 SceneObjectPart host = m_scene.GetSceneObjectPart(hostID);
458
459 // Create new asset
460 UUID assetID = UUID.Random();
461 AssetBase asset = new AssetBase(assetID, name, (sbyte)AssetType.Notecard, host.OwnerID.ToString());
462 asset.Description = "Json store";
463
464 int textLength = data.Length;
465 data = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
466 + textLength.ToString() + "\n" + data + "}\n";
467
468 asset.Data = Util.UTF8.GetBytes(data);
469 m_scene.AssetService.Store(asset);
470
471 // Create Task Entry
472 TaskInventoryItem taskItem = new TaskInventoryItem();
473
474 taskItem.ResetIDs(host.UUID);
475 taskItem.ParentID = host.UUID;
476 taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
477 taskItem.Name = asset.Name;
478 taskItem.Description = asset.Description;
479 taskItem.Type = (int)AssetType.Notecard;
480 taskItem.InvType = (int)InventoryType.Notecard;
481 taskItem.OwnerID = host.OwnerID;
482 taskItem.CreatorID = host.OwnerID;
483 taskItem.BasePermissions = (uint)PermissionMask.All;
484 taskItem.CurrentPermissions = (uint)PermissionMask.All;
485 taskItem.EveryonePermissions = 0;
486 taskItem.NextPermissions = (uint)PermissionMask.All;
487 taskItem.GroupID = host.GroupID;
488 taskItem.GroupPermissions = 0;
489 taskItem.Flags = 0;
490 taskItem.PermsGranter = UUID.Zero;
491 taskItem.PermsMask = 0;
492 taskItem.AssetID = asset.FullID;
493
494 host.Inventory.AddInventoryItem(taskItem, false);
495
496 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
497 }
498 }
499}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs
index 922eaaf..d192309 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
68 public Vector3 WorldPosition 68 public Vector3 WorldPosition
69 { 69 {
70 get { return GetSP().AbsolutePosition; } 70 get { return GetSP().AbsolutePosition; }
71 set { GetSP().TeleportWithMomentum(value); } 71 set { GetSP().Teleport(value); }
72 } 72 }
73 73
74 public bool IsChildAgent 74 public bool IsChildAgent
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
index cab30de..74a85e2 100644
--- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
@@ -38,7 +38,7 @@ using OpenMetaverse;
38using System.Linq; 38using System.Linq;
39using System.Linq.Expressions; 39using System.Linq.Expressions;
40 40
41namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms 41namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
42{ 42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] 43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")]
44 class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms 44 class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index 8996865..4fcf40d 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -76,22 +76,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC
76 76
77 public void Say(string message) 77 public void Say(string message)
78 { 78 {
79 SendOnChatFromClient(message, ChatTypeEnum.Say); 79 SendOnChatFromClient(0, message, ChatTypeEnum.Say);
80 } 80 }
81 81
82 public void Shout(string message) 82 public void Say(int channel, string message)
83 { 83 {
84 SendOnChatFromClient(message, ChatTypeEnum.Shout); 84 SendOnChatFromClient(channel, message, ChatTypeEnum.Say);
85 } 85 }
86 86
87 public void Whisper(string message) 87 public void Shout(int channel, string message)
88 { 88 {
89 SendOnChatFromClient(message, ChatTypeEnum.Whisper); 89 SendOnChatFromClient(channel, message, ChatTypeEnum.Shout);
90 }
91
92 public void Whisper(int channel, string message)
93 {
94 SendOnChatFromClient(channel, message, ChatTypeEnum.Whisper);
90 } 95 }
91 96
92 public void Broadcast(string message) 97 public void Broadcast(string message)
93 { 98 {
94 SendOnChatFromClient(message, ChatTypeEnum.Broadcast); 99 SendOnChatFromClient(0, message, ChatTypeEnum.Broadcast);
95 } 100 }
96 101
97 public void GiveMoney(UUID target, int amount) 102 public void GiveMoney(UUID target, int amount)
@@ -146,10 +151,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
146 151
147 #region Internal Functions 152 #region Internal Functions
148 153
149 private void SendOnChatFromClient(string message, ChatTypeEnum chatType) 154 private void SendOnChatFromClient(int channel, string message, ChatTypeEnum chatType)
150 { 155 {
151 OSChatMessage chatFromClient = new OSChatMessage(); 156 OSChatMessage chatFromClient = new OSChatMessage();
152 chatFromClient.Channel = 0; 157 chatFromClient.Channel = channel;
153 chatFromClient.From = Name; 158 chatFromClient.From = Name;
154 chatFromClient.Message = message; 159 chatFromClient.Message = message;
155 chatFromClient.Position = StartPos; 160 chatFromClient.Position = StartPos;
@@ -1046,10 +1051,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
1046 { 1051 {
1047 } 1052 }
1048 1053
1049 public void KillEndDone()
1050 {
1051 }
1052
1053 public void SendEventInfoReply (EventData info) 1054 public void SendEventInfoReply (EventData info)
1054 { 1055 {
1055 } 1056 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index ebf5e84..a32ab2a 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -155,18 +155,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
155 ScenePresence sp; 155 ScenePresence sp;
156 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 156 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
157 { 157 {
158 m_log.DebugFormat(
159 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
160
161 sp.CompleteMovement(npcAvatar, false); 158 sp.CompleteMovement(npcAvatar, false);
162 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 159 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
160 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
163 } 161 }
164 else
165 {
166 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID);
167 npcAvatar.AgentId = UUID.Zero;
168 }
169
170 } 162 }
171 ev.Set(); 163 ev.Set();
172 }); 164 });
@@ -178,7 +170,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
178 return npcAvatar.AgentId; 170 return npcAvatar.AgentId;
179 } 171 }
180 172
181 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget) 173 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running)
182 { 174 {
183 lock (m_avatars) 175 lock (m_avatars)
184 { 176 {
@@ -192,6 +184,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
192 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); 184 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
193 185
194 sp.MoveToTarget(pos, noFly, landAtTarget); 186 sp.MoveToTarget(pos, noFly, landAtTarget);
187 sp.SetAlwaysRun = running;
195 188
196 return true; 189 return true;
197 } 190 }
@@ -221,6 +214,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
221 214
222 public bool Say(UUID agentID, Scene scene, string text) 215 public bool Say(UUID agentID, Scene scene, string text)
223 { 216 {
217 return Say(agentID, scene, text, 0);
218 }
219
220 public bool Say(UUID agentID, Scene scene, string text, int channel)
221 {
224 lock (m_avatars) 222 lock (m_avatars)
225 { 223 {
226 if (m_avatars.ContainsKey(agentID)) 224 if (m_avatars.ContainsKey(agentID))
@@ -228,7 +226,25 @@ namespace OpenSim.Region.OptionalModules.World.NPC
228 ScenePresence sp; 226 ScenePresence sp;
229 scene.TryGetScenePresence(agentID, out sp); 227 scene.TryGetScenePresence(agentID, out sp);
230 228
231 m_avatars[agentID].Say(text); 229 m_avatars[agentID].Say(channel, text);
230
231 return true;
232 }
233 }
234
235 return false;
236 }
237
238 public bool Shout(UUID agentID, Scene scene, string text, int channel)
239 {
240 lock (m_avatars)
241 {
242 if (m_avatars.ContainsKey(agentID))
243 {
244 ScenePresence sp;
245 scene.TryGetScenePresence(agentID, out sp);
246
247 m_avatars[agentID].Shout(channel, text);
232 248
233 return true; 249 return true;
234 } 250 }
@@ -255,6 +271,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC
255 return false; 271 return false;
256 } 272 }
257 273
274 public bool Whisper(UUID agentID, Scene scene, string text, int channel)
275 {
276 lock (m_avatars)
277 {
278 if (m_avatars.ContainsKey(agentID))
279 {
280 ScenePresence sp;
281 scene.TryGetScenePresence(agentID, out sp);
282
283 m_avatars[agentID].Whisper(channel, text);
284
285 return true;
286 }
287 }
288
289 return false;
290 }
291
258 public bool Stand(UUID agentID, Scene scene) 292 public bool Stand(UUID agentID, Scene scene)
259 { 293 {
260 lock (m_avatars) 294 lock (m_avatars)
@@ -308,7 +342,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
308 scene.RemoveClient(agentID, false); 342 scene.RemoveClient(agentID, false);
309 m_avatars.Remove(agentID); 343 m_avatars.Remove(agentID);
310 344
311// m_log.DebugFormat("[NPC MODULE]: Removed {0} {1}", agentID, av.Name); 345 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name);
312 return true; 346 return true;
313 } 347 }
314 } 348 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index eea0b2e..65dad2d 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -85,7 +85,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
85 m_attMod = new AttachmentsModule(); 85 m_attMod = new AttachmentsModule();
86 m_npcMod = new NPCModule(); 86 m_npcMod = new NPCModule();
87 87
88 m_scene = SceneHelpers.SetupScene(); 88 m_scene = new SceneHelpers().SetupScene();
89 SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); 89 SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule());
90 } 90 }
91 91
@@ -242,7 +242,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
242 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); 242 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
243 243
244 Vector3 targetPos = startPos + new Vector3(0, 10, 0); 244 Vector3 targetPos = startPos + new Vector3(0, 10, 0);
245 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false); 245 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
246 246
247 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); 247 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
248 //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); 248 //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f)));
@@ -267,7 +267,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
267 // Try a second movement 267 // Try a second movement
268 startPos = npc.AbsolutePosition; 268 startPos = npc.AbsolutePosition;
269 targetPos = startPos + new Vector3(10, 0, 0); 269 targetPos = startPos + new Vector3(10, 0, 0);
270 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false); 270 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
271 271
272 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); 272 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
273// Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); 273// Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1)));
diff --git a/OpenSim/Region/OptionalModules/World/WorldView/WorldViewModule.cs b/OpenSim/Region/OptionalModules/World/WorldView/WorldViewModule.cs
index 48c242d..1aee39a 100644
--- a/OpenSim/Region/OptionalModules/World/WorldView/WorldViewModule.cs
+++ b/OpenSim/Region/OptionalModules/World/WorldView/WorldViewModule.cs
@@ -113,14 +113,15 @@ namespace OpenSim.Region.OptionalModules.World.WorldView
113 if (!m_Enabled) 113 if (!m_Enabled)
114 return new Byte[0]; 114 return new Byte[0];
115 115
116 Bitmap bmp = m_Generator.CreateViewImage(pos, rot, fov, width, 116 using (Bitmap bmp = m_Generator.CreateViewImage(pos, rot, fov, width, height, usetex))
117 height, usetex); 117 {
118 118 using (MemoryStream str = new MemoryStream())
119 MemoryStream str = new MemoryStream(); 119 {
120 120 bmp.Save(str, ImageFormat.Jpeg);
121 bmp.Save(str, ImageFormat.Jpeg);
122 121
123 return str.ToArray(); 122 return str.ToArray();
123 }
124 }
124 } 125 }
125 } 126 }
126} 127}
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs
index b1a3ff9..e43136a 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs
@@ -36,13 +36,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
36{ 36{
37 public class BasicActor : PhysicsActor 37 public class BasicActor : PhysicsActor
38 { 38 {
39 private Vector3 _position;
40 private Vector3 _velocity;
41 private Vector3 _acceleration;
42 private Vector3 _size; 39 private Vector3 _size;
43 private Vector3 m_rotationalVelocity;
44 private bool flying;
45 private bool iscolliding;
46 40
47 public BasicActor(Vector3 size) 41 public BasicActor(Vector3 size)
48 { 42 {
@@ -55,11 +49,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
55 set { return; } 49 set { return; }
56 } 50 }
57 51
58 public override Vector3 RotationalVelocity 52 public override Vector3 RotationalVelocity { get; set; }
59 {
60 get { return m_rotationalVelocity; }
61 set { m_rotationalVelocity = value; }
62 }
63 53
64 public override bool SetAlwaysRun 54 public override bool SetAlwaysRun
65 { 55 {
@@ -105,17 +95,9 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
105 set { return; } 95 set { return; }
106 } 96 }
107 97
108 public override bool Flying 98 public override bool Flying { get; set; }
109 {
110 get { return flying; }
111 set { flying = value; }
112 }
113 99
114 public override bool IsColliding 100 public override bool IsColliding { get; set; }
115 {
116 get { return iscolliding; }
117 set { iscolliding = value; }
118 }
119 101
120 public override bool CollidingGround 102 public override bool CollidingGround
121 { 103 {
@@ -134,11 +116,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
134 get { return false; } 116 get { return false; }
135 } 117 }
136 118
137 public override Vector3 Position 119 public override Vector3 Position { get; set; }
138 {
139 get { return _position; }
140 set { _position = value; }
141 }
142 120
143 public override Vector3 Size 121 public override Vector3 Size
144 { 122 {
@@ -206,11 +184,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
206 get { return Vector3.Zero; } 184 get { return Vector3.Zero; }
207 } 185 }
208 186
209 public override Vector3 Velocity 187 public override Vector3 Velocity { get; set; }
210 {
211 get { return _velocity; }
212 set { _velocity = value; }
213 }
214 188
215 public override Vector3 Torque 189 public override Vector3 Torque
216 { 190 {
@@ -230,11 +204,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
230 set { } 204 set { }
231 } 205 }
232 206
233 public override Vector3 Acceleration 207 public override Vector3 Acceleration { get; set; }
234 {
235 get { return _acceleration; }
236 set { _acceleration = value; }
237 }
238 208
239 public override bool Kinematic 209 public override bool Kinematic
240 { 210 {
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
new file mode 100644
index 0000000..b89eeed
--- /dev/null
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
@@ -0,0 +1,314 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using Nini.Config;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Physics.Manager;
34
35namespace OpenSim.Region.Physics.BasicPhysicsPlugin
36{
37 public class BasicPhysicsPrim : PhysicsActor
38 {
39 private Vector3 _size;
40 private PrimitiveBaseShape _shape;
41
42 public BasicPhysicsPrim(
43 string name, uint localId, Vector3 position, Vector3 size, Quaternion orientation, PrimitiveBaseShape shape)
44 {
45 Name = name;
46 LocalID = localId;
47 Position = position;
48 Size = size;
49 Orientation = orientation;
50 Shape = shape;
51 }
52
53 public override int PhysicsActorType
54 {
55 get { return (int) ActorTypes.Agent; }
56 set { return; }
57 }
58
59 public override Vector3 RotationalVelocity { get; set; }
60
61 public override bool SetAlwaysRun
62 {
63 get { return false; }
64 set { return; }
65 }
66
67 public override uint LocalID
68 {
69 set { return; }
70 }
71
72 public override bool Grabbed
73 {
74 set { return; }
75 }
76
77 public override bool Selected
78 {
79 set { return; }
80 }
81
82 public override float Buoyancy
83 {
84 get { return 0f; }
85 set { return; }
86 }
87
88 public override bool FloatOnWater
89 {
90 set { return; }
91 }
92
93 public override bool IsPhysical
94 {
95 get { return false; }
96 set { return; }
97 }
98
99 public override bool ThrottleUpdates
100 {
101 get { return false; }
102 set { return; }
103 }
104
105 public override bool Flying { get; set; }
106
107 public override bool IsColliding { get; set; }
108
109 public override bool CollidingGround
110 {
111 get { return false; }
112 set { return; }
113 }
114
115 public override bool CollidingObj
116 {
117 get { return false; }
118 set { return; }
119 }
120
121 public override bool Stopped
122 {
123 get { return false; }
124 }
125
126 public override Vector3 Position { get; set; }
127
128 public override Vector3 Size
129 {
130 get { return _size; }
131 set {
132 _size = value;
133 _size.Z = _size.Z / 2.0f;
134 }
135 }
136
137 public override PrimitiveBaseShape Shape
138 {
139 set { _shape = value; }
140 }
141
142 public override float Mass
143 {
144 get { return 0f; }
145 }
146
147 public override Vector3 Force
148 {
149 get { return Vector3.Zero; }
150 set { return; }
151 }
152
153 public override int VehicleType
154 {
155 get { return 0; }
156 set { return; }
157 }
158
159 public override void VehicleFloatParam(int param, float value)
160 {
161
162 }
163
164 public override void VehicleVectorParam(int param, Vector3 value)
165 {
166
167 }
168
169 public override void VehicleRotationParam(int param, Quaternion rotation)
170 {
171
172 }
173
174 public override void VehicleFlags(int param, bool remove)
175 {
176
177 }
178
179 public override void SetVolumeDetect(int param)
180 {
181
182 }
183
184 public override Vector3 CenterOfMass
185 {
186 get { return Vector3.Zero; }
187 }
188
189 public override Vector3 GeometricCenter
190 {
191 get { return Vector3.Zero; }
192 }
193
194 public override Vector3 Velocity { get; set; }
195
196 public override Vector3 Torque
197 {
198 get { return Vector3.Zero; }
199 set { return; }
200 }
201
202 public override float CollisionScore
203 {
204 get { return 0f; }
205 set { }
206 }
207
208 public override Quaternion Orientation { get; set; }
209
210 public override Vector3 Acceleration { get; set; }
211
212 public override bool Kinematic
213 {
214 get { return true; }
215 set { }
216 }
217
218 public override void link(PhysicsActor obj)
219 {
220 }
221
222 public override void delink()
223 {
224 }
225
226 public override void LockAngularMotion(Vector3 axis)
227 {
228 }
229
230 public override void AddForce(Vector3 force, bool pushforce)
231 {
232 }
233
234 public override void AddAngularForce(Vector3 force, bool pushforce)
235 {
236 }
237
238 public override void SetMomentum(Vector3 momentum)
239 {
240 }
241
242 public override void CrossingFailure()
243 {
244 }
245
246 public override Vector3 PIDTarget
247 {
248 set { return; }
249 }
250
251 public override bool PIDActive
252 {
253 set { return; }
254 }
255
256 public override float PIDTau
257 {
258 set { return; }
259 }
260
261 public override float PIDHoverHeight
262 {
263 set { return; }
264 }
265
266 public override bool PIDHoverActive
267 {
268 set { return; }
269 }
270
271 public override PIDHoverType PIDHoverType
272 {
273 set { return; }
274 }
275
276 public override float PIDHoverTau
277 {
278 set { return; }
279 }
280
281 public override Quaternion APIDTarget
282 {
283 set { return; }
284 }
285
286 public override bool APIDActive
287 {
288 set { return; }
289 }
290
291 public override float APIDStrength
292 {
293 set { return; }
294 }
295
296 public override float APIDDamping
297 {
298 set { return; }
299 }
300
301 public override void SubscribeEvents(int ms)
302 {
303 }
304
305 public override void UnSubscribeEvents()
306 {
307 }
308
309 public override bool SubscribedEvents()
310 {
311 return false;
312 }
313 }
314}
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
index 2e14216..f5826ed 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
@@ -34,9 +34,17 @@ using OpenSim.Region.Physics.Manager;
34 34
35namespace OpenSim.Region.Physics.BasicPhysicsPlugin 35namespace OpenSim.Region.Physics.BasicPhysicsPlugin
36{ 36{
37 /// <summary>
38 /// This is an incomplete extremely basic physics implementation
39 /// </summary>
40 /// <remarks>
41 /// Not useful for anything at the moment apart from some regression testing in other components where some form
42 /// of physics plugin is needed.
43 /// </remarks>
37 public class BasicScene : PhysicsScene 44 public class BasicScene : PhysicsScene
38 { 45 {
39 private List<BasicActor> _actors = new List<BasicActor>(); 46 private List<BasicActor> _actors = new List<BasicActor>();
47 private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>();
40 private float[] _heightMap; 48 private float[] _heightMap;
41 49
42 //protected internal string sceneIdentifier; 50 //protected internal string sceneIdentifier;
@@ -50,10 +58,19 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
50 { 58 {
51 } 59 }
52 60
53 public override void Dispose() 61 public override void Dispose() {}
62
63 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
64 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
54 { 65 {
66 BasicPhysicsPrim prim = new BasicPhysicsPrim(primName, localid, position, size, rotation, pbs);
67 prim.IsPhysical = isPhysical;
68
69 _prims.Add(prim);
55 70
71 return prim;
56 } 72 }
73
57 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) 74 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
58 { 75 {
59 BasicActor act = new BasicActor(size); 76 BasicActor act = new BasicActor(size);
@@ -63,30 +80,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
63 return act; 80 return act;
64 } 81 }
65 82
66 public override void RemovePrim(PhysicsActor prim) 83 public override void RemovePrim(PhysicsActor actor)
67 { 84 {
85 BasicPhysicsPrim prim = (BasicPhysicsPrim)actor;
86 if (_prims.Contains(prim))
87 _prims.Remove(prim);
68 } 88 }
69 89
70 public override void RemoveAvatar(PhysicsActor actor) 90 public override void RemoveAvatar(PhysicsActor actor)
71 { 91 {
72 BasicActor act = (BasicActor) actor; 92 BasicActor act = (BasicActor)actor;
73 if (_actors.Contains(act)) 93 if (_actors.Contains(act))
74 {
75 _actors.Remove(act); 94 _actors.Remove(act);
76 }
77 }
78
79/*
80 public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation)
81 {
82 return null;
83 }
84*/
85
86 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
87 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
88 {
89 return null;
90 } 95 }
91 96
92 public override void AddPhysicsActorTaint(PhysicsActor prim) 97 public override void AddPhysicsActorTaint(PhysicsActor prim)
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index d10a2aa..cfede55 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -241,8 +241,22 @@ namespace OpenSim.Region.Physics.Manager
241 241
242 public abstract void AddPhysicsActorTaint(PhysicsActor prim); 242 public abstract void AddPhysicsActorTaint(PhysicsActor prim);
243 243
244 /// <summary>
245 /// Perform a simulation of the current physics scene over the given timestep.
246 /// </summary>
247 /// <param name="timeStep"></param>
248 /// <returns>The number of frames simulated over that period.</returns>
244 public abstract float Simulate(float timeStep); 249 public abstract float Simulate(float timeStep);
245 250
251 /// <summary>
252 /// Get statistics about this scene.
253 /// </summary>
254 /// <remarks>This facility is currently experimental and subject to change.</remarks>
255 /// <returns>
256 /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null.
257 /// </returns>
258 public virtual Dictionary<string, float> GetStats() { return null; }
259
246 public abstract void GetResults(); 260 public abstract void GetResults();
247 261
248 public abstract void SetTerrain(float[] heightMap); 262 public abstract void SetTerrain(float[] heightMap);
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 8397eb4..54b69a2 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -1261,14 +1261,20 @@ namespace OpenSim.Region.Physics.OdePlugin
1261 { 1261 {
1262 m_requestedUpdateFrequency = ms; 1262 m_requestedUpdateFrequency = ms;
1263 m_eventsubscription = ms; 1263 m_eventsubscription = ms;
1264 CollisionEventsThisFrame.Clear(); 1264
1265 // Don't clear collision event reporting here. This is called directly from scene code and so can lead
1266 // to a race condition with the simulate loop
1267
1265 _parent_scene.AddCollisionEventReporting(this); 1268 _parent_scene.AddCollisionEventReporting(this);
1266 } 1269 }
1267 1270
1268 public override void UnSubscribeEvents() 1271 public override void UnSubscribeEvents()
1269 { 1272 {
1270 CollisionEventsThisFrame.Clear(); 1273 CollisionEventsThisFrame.Clear();
1271 _parent_scene.RemoveCollisionEventReporting(this); 1274
1275 // Don't clear collision event reporting here. This is called directly from scene code and so can lead
1276 // to a race condition with the simulate loop
1277
1272 m_requestedUpdateFrequency = 0; 1278 m_requestedUpdateFrequency = 0;
1273 m_eventsubscription = 0; 1279 m_eventsubscription = 0;
1274 } 1280 }
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 6f37347..a41c856 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -156,7 +156,15 @@ namespace OpenSim.Region.Physics.OdePlugin
156 /// </summary> 156 /// </summary>
157 public IntPtr m_targetSpace = IntPtr.Zero; 157 public IntPtr m_targetSpace = IntPtr.Zero;
158 158
159 /// <summary>
160 /// The prim geometry, used for collision detection.
161 /// </summary>
162 /// <remarks>
163 /// This is never null except for a brief period when the geometry needs to be replaced (due to resizing or
164 /// mesh change) or when the physical prim is being removed from the scene.
165 /// </remarks>
159 public IntPtr prim_geom { get; private set; } 166 public IntPtr prim_geom { get; private set; }
167
160 public IntPtr _triMeshData { get; private set; } 168 public IntPtr _triMeshData { get; private set; }
161 169
162 private IntPtr _linkJointGroup = IntPtr.Zero; 170 private IntPtr _linkJointGroup = IntPtr.Zero;
@@ -325,14 +333,12 @@ namespace OpenSim.Region.Physics.OdePlugin
325 { 333 {
326 prim_geom = geom; 334 prim_geom = geom;
327//Console.WriteLine("SetGeom to " + prim_geom + " for " + Name); 335//Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
328 if (prim_geom != IntPtr.Zero)
329 {
330 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
331 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
332 336
333 _parent_scene.geom_name_map[prim_geom] = Name; 337 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
334 _parent_scene.actor_name_map[prim_geom] = this; 338 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
335 } 339
340 _parent_scene.geom_name_map[prim_geom] = Name;
341 _parent_scene.actor_name_map[prim_geom] = this;
336 342
337 if (childPrim) 343 if (childPrim)
338 { 344 {
@@ -765,11 +771,8 @@ namespace OpenSim.Region.Physics.OdePlugin
765 m_collisionCategories &= ~CollisionCategories.Body; 771 m_collisionCategories &= ~CollisionCategories.Body;
766 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 772 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
767 773
768 if (prim_geom != IntPtr.Zero) 774 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
769 { 775 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
770 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
771 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
772 }
773 776
774 d.BodyDestroy(Body); 777 d.BodyDestroy(Body);
775 lock (childrenPrim) 778 lock (childrenPrim)
@@ -793,11 +796,8 @@ namespace OpenSim.Region.Physics.OdePlugin
793 m_collisionCategories &= ~CollisionCategories.Body; 796 m_collisionCategories &= ~CollisionCategories.Body;
794 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 797 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
795 798
796 if (prim_geom != IntPtr.Zero) 799 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
797 { 800 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
798 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
799 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
800 }
801 801
802 Body = IntPtr.Zero; 802 Body = IntPtr.Zero;
803 } 803 }
@@ -864,10 +864,7 @@ namespace OpenSim.Region.Physics.OdePlugin
864// _parent_scene.waitForSpaceUnlock(m_targetSpace); 864// _parent_scene.waitForSpaceUnlock(m_targetSpace);
865 try 865 try
866 { 866 {
867 if (prim_geom == IntPtr.Zero) 867 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
868 {
869 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
870 }
871 } 868 }
872 catch (AccessViolationException) 869 catch (AccessViolationException)
873 { 870 {
@@ -890,73 +887,67 @@ namespace OpenSim.Region.Physics.OdePlugin
890#if SPAM 887#if SPAM
891Console.WriteLine("ZProcessTaints for " + Name); 888Console.WriteLine("ZProcessTaints for " + Name);
892#endif 889#endif
890
891 // This must be processed as the very first taint so that later operations have a prim_geom to work with
892 // if this is a new prim.
893 if (m_taintadd) 893 if (m_taintadd)
894 {
895 changeadd(); 894 changeadd();
896 }
897
898 if (prim_geom != IntPtr.Zero)
899 {
900 if (!_position.ApproxEquals(m_taintposition, 0f))
901 changemove();
902 895
903 if (m_taintrot != _orientation) 896 if (!_position.ApproxEquals(m_taintposition, 0f))
904 { 897 changemove();
905 if (childPrim && IsPhysical) // For physical child prim... 898
906 { 899 if (m_taintrot != _orientation)
907 rotate(); 900 {
908 // KF: ODE will also rotate the parent prim! 901 if (childPrim && IsPhysical) // For physical child prim...
909 // so rotate the root back to where it was 902 {
910 OdePrim parent = (OdePrim)_parent; 903 rotate();
911 parent.rotate(); 904 // KF: ODE will also rotate the parent prim!
912 } 905 // so rotate the root back to where it was
913 else 906 OdePrim parent = (OdePrim)_parent;
914 { 907 parent.rotate();
915 //Just rotate the prim
916 rotate();
917 }
918 } 908 }
919 909 else
920 if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent)) 910 {
921 changePhysicsStatus(); 911 //Just rotate the prim
912 rotate();
913 }
914 }
915
916 if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent))
917 changePhysicsStatus();
922 918
923 if (!_size.ApproxEquals(m_taintsize, 0f)) 919 if (!_size.ApproxEquals(m_taintsize, 0f))
924 changesize(); 920 changesize();
925 921
926 if (m_taintshape) 922 if (m_taintshape)
927 changeshape(); 923 changeshape();
928 924
929 if (m_taintforce) 925 if (m_taintforce)
930 changeAddForce(); 926 changeAddForce();
931 927
932 if (m_taintaddangularforce) 928 if (m_taintaddangularforce)
933 changeAddAngularForce(); 929 changeAddAngularForce();
934 930
935 if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) 931 if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
936 changeSetTorque(); 932 changeSetTorque();
937 933
938 if (m_taintdisable) 934 if (m_taintdisable)
939 changedisable(); 935 changedisable();
940 936
941 if (m_taintselected != m_isSelected) 937 if (m_taintselected != m_isSelected)
942 changeSelectedStatus(); 938 changeSelectedStatus();
943 939
944 if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) 940 if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
945 changevelocity(); 941 changevelocity();
946 942
947 if (m_taintparent != _parent) 943 if (m_taintparent != _parent)
948 changelink(); 944 changelink();
949 945
950 if (m_taintCollidesWater != m_collidesWater) 946 if (m_taintCollidesWater != m_collidesWater)
951 changefloatonwater(); 947 changefloatonwater();
952 948
953 if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f)) 949 if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
954 changeAngularLock(); 950 changeAngularLock();
955 }
956 else
957 {
958 m_log.ErrorFormat("[PHYSICS]: The scene reused a disposed PhysActor for {0}! *waves finger*, Don't be evil. A couple of things can cause this. An improper prim breakdown(be sure to set prim_geom to zero after d.GeomDestroy! An improper buildup (creating the geom failed). Or, the Scene Reused a physics actor after disposing it.)", Name);
959 }
960 } 951 }
961 952
962 /// <summary> 953 /// <summary>
@@ -1052,150 +1043,146 @@ Console.WriteLine("ZProcessTaints for " + Name);
1052 /// <param name="prim">Child prim</param> 1043 /// <param name="prim">Child prim</param>
1053 private void AddChildPrim(OdePrim prim) 1044 private void AddChildPrim(OdePrim prim)
1054 { 1045 {
1055//Console.WriteLine("AddChildPrim " + Name); 1046 if (LocalID == prim.LocalID)
1056 if (LocalID != prim.LocalID) 1047 return;
1048
1049 if (Body == IntPtr.Zero)
1057 { 1050 {
1058 if (Body == IntPtr.Zero) 1051 Body = d.BodyCreate(_parent_scene.world);
1052 setMass();
1053 }
1054
1055 lock (childrenPrim)
1056 {
1057 if (childrenPrim.Contains(prim))
1058 return;
1059
1060// m_log.DebugFormat(
1061// "[ODE PRIM]: Linking prim {0} {1} to {2} {3}", prim.Name, prim.LocalID, Name, LocalID);
1062
1063 childrenPrim.Add(prim);
1064
1065 foreach (OdePrim prm in childrenPrim)
1059 { 1066 {
1060 Body = d.BodyCreate(_parent_scene.world); 1067 d.Mass m2;
1061 setMass(); 1068 d.MassSetZero(out m2);
1069 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
1070
1071 d.Quaternion quat = new d.Quaternion();
1072 quat.W = prm._orientation.W;
1073 quat.X = prm._orientation.X;
1074 quat.Y = prm._orientation.Y;
1075 quat.Z = prm._orientation.Z;
1076
1077 d.Matrix3 mat = new d.Matrix3();
1078 d.RfromQ(out mat, ref quat);
1079 d.MassRotate(ref m2, ref mat);
1080 d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
1081 d.MassAdd(ref pMass, ref m2);
1062 } 1082 }
1063 if (Body != IntPtr.Zero) 1083
1084 foreach (OdePrim prm in childrenPrim)
1064 { 1085 {
1065 lock (childrenPrim) 1086 prm.m_collisionCategories |= CollisionCategories.Body;
1066 { 1087 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1067 if (!childrenPrim.Contains(prim))
1068 {
1069//Console.WriteLine("childrenPrim.Add " + prim);
1070 childrenPrim.Add(prim);
1071
1072 foreach (OdePrim prm in childrenPrim)
1073 {
1074 d.Mass m2;
1075 d.MassSetZero(out m2);
1076 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
1077
1078 d.Quaternion quat = new d.Quaternion();
1079 quat.W = prm._orientation.W;
1080 quat.X = prm._orientation.X;
1081 quat.Y = prm._orientation.Y;
1082 quat.Z = prm._orientation.Z;
1083
1084 d.Matrix3 mat = new d.Matrix3();
1085 d.RfromQ(out mat, ref quat);
1086 d.MassRotate(ref m2, ref mat);
1087 d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
1088 d.MassAdd(ref pMass, ref m2);
1089 }
1090
1091 foreach (OdePrim prm in childrenPrim)
1092 {
1093 prm.m_collisionCategories |= CollisionCategories.Body;
1094 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1095 1088
1096 if (prm.prim_geom == IntPtr.Zero)
1097 {
1098 m_log.WarnFormat(
1099 "[PHYSICS]: Unable to link one of the linkset elements {0} for parent {1}. No geom yet",
1100 prm.Name, prim.Name);
1101 continue;
1102 }
1103//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name); 1089//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name);
1104 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); 1090 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
1105 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); 1091 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1106
1107 1092
1108 d.Quaternion quat = new d.Quaternion(); 1093 d.Quaternion quat = new d.Quaternion();
1109 quat.W = prm._orientation.W; 1094 quat.W = prm._orientation.W;
1110 quat.X = prm._orientation.X; 1095 quat.X = prm._orientation.X;
1111 quat.Y = prm._orientation.Y; 1096 quat.Y = prm._orientation.Y;
1112 quat.Z = prm._orientation.Z; 1097 quat.Z = prm._orientation.Z;
1113 1098
1114 d.Matrix3 mat = new d.Matrix3(); 1099 d.Matrix3 mat = new d.Matrix3();
1115 d.RfromQ(out mat, ref quat); 1100 d.RfromQ(out mat, ref quat);
1116 if (Body != IntPtr.Zero) 1101 if (Body != IntPtr.Zero)
1117 { 1102 {
1118 d.GeomSetBody(prm.prim_geom, Body); 1103 d.GeomSetBody(prm.prim_geom, Body);
1119 prm.childPrim = true; 1104 prm.childPrim = true;
1120 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z); 1105 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
1121 //d.GeomSetOffsetPosition(prim.prim_geom, 1106 //d.GeomSetOffsetPosition(prim.prim_geom,
1122 // (Position.X - prm.Position.X) - pMass.c.X, 1107 // (Position.X - prm.Position.X) - pMass.c.X,
1123 // (Position.Y - prm.Position.Y) - pMass.c.Y, 1108 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1124 // (Position.Z - prm.Position.Z) - pMass.c.Z); 1109 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1125 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); 1110 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
1126 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat); 1111 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
1127 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z); 1112 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1128 d.BodySetMass(Body, ref pMass); 1113 d.BodySetMass(Body, ref pMass);
1129 } 1114 }
1130 else 1115 else
1131 { 1116 {
1132 m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name); 1117 m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name);
1133 } 1118 }
1134 1119
1135 prm.m_interpenetrationcount = 0; 1120 prm.m_interpenetrationcount = 0;
1136 prm.m_collisionscore = 0; 1121 prm.m_collisionscore = 0;
1137 prm.m_disabled = false; 1122 prm.m_disabled = false;
1138 1123
1139 // The body doesn't already have a finite rotation mode set here 1124 // The body doesn't already have a finite rotation mode set here
1140 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null) 1125 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1141 { 1126 {
1142 prm.createAMotor(m_angularlock); 1127 prm.createAMotor(m_angularlock);
1143 } 1128 }
1144 prm.Body = Body; 1129 prm.Body = Body;
1145 _parent_scene.ActivatePrim(prm); 1130 _parent_scene.ActivatePrim(prm);
1146 } 1131 }
1147 1132
1148 m_collisionCategories |= CollisionCategories.Body; 1133 m_collisionCategories |= CollisionCategories.Body;
1149 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); 1134 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1150 1135
1151//Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name); 1136//Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name);
1152 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1137 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1153//Console.WriteLine(" Post GeomSetCategoryBits 2"); 1138//Console.WriteLine(" Post GeomSetCategoryBits 2");
1154 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1139 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1155
1156 d.Quaternion quat2 = new d.Quaternion();
1157 quat2.W = _orientation.W;
1158 quat2.X = _orientation.X;
1159 quat2.Y = _orientation.Y;
1160 quat2.Z = _orientation.Z;
1161
1162 d.Matrix3 mat2 = new d.Matrix3();
1163 d.RfromQ(out mat2, ref quat2);
1164 d.GeomSetBody(prim_geom, Body);
1165 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1166 //d.GeomSetOffsetPosition(prim.prim_geom,
1167 // (Position.X - prm.Position.X) - pMass.c.X,
1168 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1169 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1170 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1171 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1172 d.BodySetMass(Body, ref pMass);
1173
1174 d.BodySetAutoDisableFlag(Body, true);
1175 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1176 1140
1177 m_interpenetrationcount = 0; 1141 d.Quaternion quat2 = new d.Quaternion();
1178 m_collisionscore = 0; 1142 quat2.W = _orientation.W;
1179 m_disabled = false; 1143 quat2.X = _orientation.X;
1144 quat2.Y = _orientation.Y;
1145 quat2.Z = _orientation.Z;
1180 1146
1181 // The body doesn't already have a finite rotation mode set here 1147 d.Matrix3 mat2 = new d.Matrix3();
1182 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null) 1148 d.RfromQ(out mat2, ref quat2);
1183 { 1149 d.GeomSetBody(prim_geom, Body);
1184 createAMotor(m_angularlock); 1150 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1185 } 1151 //d.GeomSetOffsetPosition(prim.prim_geom,
1186 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); 1152 // (Position.X - prm.Position.X) - pMass.c.X,
1187 if (m_vehicle.Type != Vehicle.TYPE_NONE) 1153 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1188 m_vehicle.Enable(Body, _parent_scene); 1154 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1155 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1156 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1157 d.BodySetMass(Body, ref pMass);
1189 1158
1190 _parent_scene.ActivatePrim(this); 1159 d.BodySetAutoDisableFlag(Body, true);
1191 } 1160 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1192 } 1161
1162 m_interpenetrationcount = 0;
1163 m_collisionscore = 0;
1164 m_disabled = false;
1165
1166 // The body doesn't already have a finite rotation mode set here
1167 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1168 {
1169 createAMotor(m_angularlock);
1193 } 1170 }
1171
1172 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1173
1174 if (m_vehicle.Type != Vehicle.TYPE_NONE)
1175 m_vehicle.Enable(Body, _parent_scene);
1176
1177 _parent_scene.ActivatePrim(this);
1194 } 1178 }
1195 } 1179 }
1196 1180
1197 private void ChildSetGeom(OdePrim odePrim) 1181 private void ChildSetGeom(OdePrim odePrim)
1198 { 1182 {
1183// m_log.DebugFormat(
1184// "[ODE PRIM]: ChildSetGeom {0} {1} for {2} {3}", odePrim.Name, odePrim.LocalID, Name, LocalID);
1185
1199 //if (IsPhysical && Body != IntPtr.Zero) 1186 //if (IsPhysical && Body != IntPtr.Zero)
1200 lock (childrenPrim) 1187 lock (childrenPrim)
1201 { 1188 {
@@ -1210,12 +1197,14 @@ Console.WriteLine("ZProcessTaints for " + Name);
1210 //prm.childPrim = false; 1197 //prm.childPrim = false;
1211 } 1198 }
1212 } 1199 }
1200
1213 disableBody(); 1201 disableBody();
1214 1202
1215 if (Body != IntPtr.Zero) 1203 // Spurious - Body == IntPtr.Zero after disableBody()
1216 { 1204// if (Body != IntPtr.Zero)
1217 _parent_scene.DeactivatePrim(this); 1205// {
1218 } 1206// _parent_scene.DeactivatePrim(this);
1207// }
1219 1208
1220 lock (childrenPrim) 1209 lock (childrenPrim)
1221 { 1210 {
@@ -1229,6 +1218,9 @@ Console.WriteLine("ZProcessTaints for " + Name);
1229 1218
1230 private void ChildDelink(OdePrim odePrim) 1219 private void ChildDelink(OdePrim odePrim)
1231 { 1220 {
1221// m_log.DebugFormat(
1222// "[ODE PRIM]: Delinking prim {0} {1} from {2} {3}", odePrim.Name, odePrim.LocalID, Name, LocalID);
1223
1232 // Okay, we have a delinked child.. need to rebuild the body. 1224 // Okay, we have a delinked child.. need to rebuild the body.
1233 lock (childrenPrim) 1225 lock (childrenPrim)
1234 { 1226 {
@@ -1243,6 +1235,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1243 //prm.childPrim = false; 1235 //prm.childPrim = false;
1244 } 1236 }
1245 } 1237 }
1238
1246 disableBody(); 1239 disableBody();
1247 1240
1248 lock (childrenPrim) 1241 lock (childrenPrim)
@@ -1251,10 +1244,11 @@ Console.WriteLine("ZProcessTaints for " + Name);
1251 childrenPrim.Remove(odePrim); 1244 childrenPrim.Remove(odePrim);
1252 } 1245 }
1253 1246
1254 if (Body != IntPtr.Zero) 1247 // Spurious - Body == IntPtr.Zero after disableBody()
1255 { 1248// if (Body != IntPtr.Zero)
1256 _parent_scene.DeactivatePrim(this); 1249// {
1257 } 1250// _parent_scene.DeactivatePrim(this);
1251// }
1258 1252
1259 lock (childrenPrim) 1253 lock (childrenPrim)
1260 { 1254 {
@@ -1303,11 +1297,8 @@ Console.WriteLine("ZProcessTaints for " + Name);
1303 disableBodySoft(); 1297 disableBodySoft();
1304 } 1298 }
1305 1299
1306 if (prim_geom != IntPtr.Zero) 1300 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1307 { 1301 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1308 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1309 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1310 }
1311 1302
1312 if (IsPhysical) 1303 if (IsPhysical)
1313 { 1304 {
@@ -1328,11 +1319,8 @@ Console.WriteLine("ZProcessTaints for " + Name);
1328 if (m_collidesWater) 1319 if (m_collidesWater)
1329 m_collisionFlags |= CollisionCategories.Water; 1320 m_collisionFlags |= CollisionCategories.Water;
1330 1321
1331 if (prim_geom != IntPtr.Zero) 1322 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1332 { 1323 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1333 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1334 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1335 }
1336 1324
1337 if (IsPhysical) 1325 if (IsPhysical)
1338 { 1326 {
@@ -1472,6 +1460,9 @@ Console.WriteLine("CreateGeom:");
1472 } 1460 }
1473 else 1461 else
1474 { 1462 {
1463 m_log.WarnFormat(
1464 "[ODE PRIM]: Called RemoveGeom() on {0} {1} where geometry was already null.", Name, LocalID);
1465
1475 return false; 1466 return false;
1476 } 1467 }
1477 } 1468 }
@@ -1505,16 +1496,13 @@ Console.WriteLine("changeadd 1");
1505#endif 1496#endif
1506 CreateGeom(m_targetSpace, mesh); 1497 CreateGeom(m_targetSpace, mesh);
1507 1498
1508 if (prim_geom != IntPtr.Zero) 1499 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1509 { 1500 d.Quaternion myrot = new d.Quaternion();
1510 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 1501 myrot.X = _orientation.X;
1511 d.Quaternion myrot = new d.Quaternion(); 1502 myrot.Y = _orientation.Y;
1512 myrot.X = _orientation.X; 1503 myrot.Z = _orientation.Z;
1513 myrot.Y = _orientation.Y; 1504 myrot.W = _orientation.W;
1514 myrot.Z = _orientation.Z; 1505 d.GeomSetQuaternion(prim_geom, ref myrot);
1515 myrot.W = _orientation.W;
1516 d.GeomSetQuaternion(prim_geom, ref myrot);
1517 }
1518 1506
1519 if (IsPhysical && Body == IntPtr.Zero) 1507 if (IsPhysical && Body == IntPtr.Zero)
1520 enableBody(); 1508 enableBody();
@@ -1579,24 +1567,20 @@ Console.WriteLine(" JointCreateFixed");
1579 //m_log.Debug("[BUG]: race!"); 1567 //m_log.Debug("[BUG]: race!");
1580 //} 1568 //}
1581 } 1569 }
1582 else
1583 {
1584 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
1585 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
1586// _parent_scene.waitForSpaceUnlock(m_targetSpace);
1587 1570
1588 IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace); 1571 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
1589 m_targetSpace = tempspace; 1572 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
1573// _parent_scene.waitForSpaceUnlock(m_targetSpace);
1574
1575 IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
1576 m_targetSpace = tempspace;
1590 1577
1591// _parent_scene.waitForSpaceUnlock(m_targetSpace); 1578// _parent_scene.waitForSpaceUnlock(m_targetSpace);
1592 if (prim_geom != IntPtr.Zero) 1579
1593 { 1580 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1594 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1595 1581
1596// _parent_scene.waitForSpaceUnlock(m_targetSpace); 1582// _parent_scene.waitForSpaceUnlock(m_targetSpace);
1597 d.SpaceAdd(m_targetSpace, prim_geom); 1583 d.SpaceAdd(m_targetSpace, prim_geom);
1598 }
1599 }
1600 1584
1601 changeSelectedStatus(); 1585 changeSelectedStatus();
1602 1586
@@ -2047,18 +2031,16 @@ Console.WriteLine(" JointCreateFixed");
2047 { 2031 {
2048 m_collidesWater = m_taintCollidesWater; 2032 m_collidesWater = m_taintCollidesWater;
2049 2033
2050 if (prim_geom != IntPtr.Zero) 2034 if (m_collidesWater)
2051 { 2035 {
2052 if (m_collidesWater) 2036 m_collisionFlags |= CollisionCategories.Water;
2053 {
2054 m_collisionFlags |= CollisionCategories.Water;
2055 }
2056 else
2057 {
2058 m_collisionFlags &= ~CollisionCategories.Water;
2059 }
2060 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2061 } 2037 }
2038 else
2039 {
2040 m_collisionFlags &= ~CollisionCategories.Water;
2041 }
2042
2043 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2062 } 2044 }
2063 2045
2064 /// <summary> 2046 /// <summary>
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 842ff91..c6ecc68 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -30,20 +30,21 @@
30 30
31using System; 31using System;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Diagnostics;
34using System.IO;
35using System.Linq;
33using System.Reflection; 36using System.Reflection;
34using System.Runtime.InteropServices; 37using System.Runtime.InteropServices;
35using System.Threading; 38using System.Threading;
36using System.IO;
37using System.Diagnostics;
38using log4net; 39using log4net;
39using Nini.Config; 40using Nini.Config;
40using Ode.NET; 41using Ode.NET;
42using OpenMetaverse;
41#if USE_DRAWSTUFF 43#if USE_DRAWSTUFF
42using Drawstuff.NET; 44using Drawstuff.NET;
43#endif 45#endif
44using OpenSim.Framework; 46using OpenSim.Framework;
45using OpenSim.Region.Physics.Manager; 47using OpenSim.Region.Physics.Manager;
46using OpenMetaverse;
47 48
48namespace OpenSim.Region.Physics.OdePlugin 49namespace OpenSim.Region.Physics.OdePlugin
49{ 50{
@@ -54,15 +55,15 @@ namespace OpenSim.Region.Physics.OdePlugin
54 End = 2 55 End = 2
55 } 56 }
56 57
57 public struct sCollisionData 58// public struct sCollisionData
58 { 59// {
59 public uint ColliderLocalId; 60// public uint ColliderLocalId;
60 public uint CollidedWithLocalId; 61// public uint CollidedWithLocalId;
61 public int NumberOfCollisions; 62// public int NumberOfCollisions;
62 public int CollisionType; 63// public int CollisionType;
63 public int StatusIndicator; 64// public int StatusIndicator;
64 public int lastframe; 65// public int lastframe;
65 } 66// }
66 67
67 [Flags] 68 [Flags]
68 public enum CollisionCategories : int 69 public enum CollisionCategories : int
@@ -131,6 +132,135 @@ namespace OpenSim.Region.Physics.OdePlugin
131 /// </remarks> 132 /// </remarks>
132 internal static Object UniversalColliderSyncObject = new Object(); 133 internal static Object UniversalColliderSyncObject = new Object();
133 134
135 /// <summary>
136 /// Is stats collecting enabled for this ODE scene?
137 /// </summary>
138 public bool CollectStats { get; set; }
139
140 /// <summary>
141 /// Statistics for this scene.
142 /// </summary>
143 private Dictionary<string, float> m_stats = new Dictionary<string, float>();
144
145 /// <summary>
146 /// Stat name for total number of avatars in this ODE scene.
147 /// </summary>
148 public const string ODETotalAvatarsStatName = "ODETotalAvatars";
149
150 /// <summary>
151 /// Stat name for total number of prims in this ODE scene.
152 /// </summary>
153 public const string ODETotalPrimsStatName = "ODETotalPrims";
154
155 /// <summary>
156 /// Stat name for total number of prims with active physics in this ODE scene.
157 /// </summary>
158 public const string ODEActivePrimsStatName = "ODEActivePrims";
159
160 /// <summary>
161 /// Stat name for the total time spent in ODE frame processing.
162 /// </summary>
163 /// <remarks>
164 /// A sanity check for the main scene loop physics time.
165 /// </remarks>
166 public const string ODETotalFrameMsStatName = "ODETotalFrameMS";
167
168 /// <summary>
169 /// Stat name for time spent processing avatar taints per frame
170 /// </summary>
171 public const string ODEAvatarTaintMsStatName = "ODEAvatarTaintFrameMS";
172
173 /// <summary>
174 /// Stat name for time spent processing prim taints per frame
175 /// </summary>
176 public const string ODEPrimTaintMsStatName = "ODEPrimTaintFrameMS";
177
178 /// <summary>
179 /// Stat name for time spent calculating avatar forces per frame.
180 /// </summary>
181 public const string ODEAvatarForcesFrameMsStatName = "ODEAvatarForcesFrameMS";
182
183 /// <summary>
184 /// Stat name for time spent calculating prim forces per frame
185 /// </summary>
186 public const string ODEPrimForcesFrameMsStatName = "ODEPrimForcesFrameMS";
187
188 /// <summary>
189 /// Stat name for time spent fulfilling raycasting requests per frame
190 /// </summary>
191 public const string ODERaycastingFrameMsStatName = "ODERaycastingFrameMS";
192
193 /// <summary>
194 /// Stat name for time spent in native code that actually steps through the simulation.
195 /// </summary>
196 public const string ODENativeStepFrameMsStatName = "ODENativeStepFrameMS";
197
198 /// <summary>
199 /// Stat name for the number of milliseconds that ODE spends in native space collision code.
200 /// </summary>
201 public const string ODENativeSpaceCollisionFrameMsStatName = "ODENativeSpaceCollisionFrameMS";
202
203 /// <summary>
204 /// Stat name for milliseconds that ODE spends in native geom collision code.
205 /// </summary>
206 public const string ODENativeGeomCollisionFrameMsStatName = "ODENativeGeomCollisionFrameMS";
207
208 /// <summary>
209 /// Time spent in collision processing that is not spent in native space or geom collision code.
210 /// </summary>
211 public const string ODEOtherCollisionFrameMsStatName = "ODEOtherCollisionFrameMS";
212
213 /// <summary>
214 /// Stat name for time spent notifying listeners of collisions
215 /// </summary>
216 public const string ODECollisionNotificationFrameMsStatName = "ODECollisionNotificationFrameMS";
217
218 /// <summary>
219 /// Stat name for milliseconds spent updating avatar position and velocity
220 /// </summary>
221 public const string ODEAvatarUpdateFrameMsStatName = "ODEAvatarUpdateFrameMS";
222
223 /// <summary>
224 /// Stat name for the milliseconds spent updating prim position and velocity
225 /// </summary>
226 public const string ODEPrimUpdateFrameMsStatName = "ODEPrimUpdateFrameMS";
227
228 /// <summary>
229 /// Stat name for avatar collisions with another entity.
230 /// </summary>
231 public const string ODEAvatarContactsStatsName = "ODEAvatarContacts";
232
233 /// <summary>
234 /// Stat name for prim collisions with another entity.
235 /// </summary>
236 public const string ODEPrimContactsStatName = "ODEPrimContacts";
237
238 /// <summary>
239 /// Used to hold tick numbers for stat collection purposes.
240 /// </summary>
241 private int m_nativeCollisionStartTick;
242
243 /// <summary>
244 /// A messy way to tell if we need to avoid adding a collision time because this was already done in the callback.
245 /// </summary>
246 private bool m_inCollisionTiming;
247
248 /// <summary>
249 /// A temporary holder for the number of avatar collisions in a frame, so we can work out how many object
250 /// collisions occured using the _perloopcontact if stats collection is enabled.
251 /// </summary>
252 private int m_tempAvatarCollisionsThisFrame;
253
254 /// <summary>
255 /// Used in calculating physics frame time dilation
256 /// </summary>
257 private int tickCountFrameRun;
258
259 /// <summary>
260 /// Used in calculating physics frame time dilation
261 /// </summary>
262 private int latertickcount;
263
134 private Random fluidRandomizer = new Random(Environment.TickCount); 264 private Random fluidRandomizer = new Random(Environment.TickCount);
135 265
136 private const uint m_regionWidth = Constants.RegionSize; 266 private const uint m_regionWidth = Constants.RegionSize;
@@ -345,9 +475,6 @@ namespace OpenSim.Region.Physics.OdePlugin
345 private OdePrim cp1; 475 private OdePrim cp1;
346 private OdeCharacter cc2; 476 private OdeCharacter cc2;
347 private OdePrim cp2; 477 private OdePrim cp2;
348 private int tickCountFrameRun;
349
350 private int latertickcount=0;
351 //private int cStartStop = 0; 478 //private int cStartStop = 0;
352 //private string cDictKey = ""; 479 //private string cDictKey = "";
353 480
@@ -440,6 +567,8 @@ namespace OpenSim.Region.Physics.OdePlugin
440 // Initialize the mesh plugin 567 // Initialize the mesh plugin
441 public override void Initialise(IMesher meshmerizer, IConfigSource config) 568 public override void Initialise(IMesher meshmerizer, IConfigSource config)
442 { 569 {
570 InitializeExtraStats();
571
443 mesher = meshmerizer; 572 mesher = meshmerizer;
444 m_config = config; 573 m_config = config;
445 // Defaults 574 // Defaults
@@ -464,6 +593,8 @@ namespace OpenSim.Region.Physics.OdePlugin
464 IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"]; 593 IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"];
465 if (physicsconfig != null) 594 if (physicsconfig != null)
466 { 595 {
596 CollectStats = physicsconfig.GetBoolean("collect_stats", false);
597
467 gravityx = physicsconfig.GetFloat("world_gravityx", 0f); 598 gravityx = physicsconfig.GetFloat("world_gravityx", 0f);
468 gravityy = physicsconfig.GetFloat("world_gravityy", 0f); 599 gravityy = physicsconfig.GetFloat("world_gravityy", 0f);
469 gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f); 600 gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f);
@@ -765,6 +896,62 @@ namespace OpenSim.Region.Physics.OdePlugin
765 #region Collision Detection 896 #region Collision Detection
766 897
767 /// <summary> 898 /// <summary>
899 /// Collides two geometries.
900 /// </summary>
901 /// <returns></returns>
902 /// <param name='geom1'></param>
903 /// <param name='geom2'>/param>
904 /// <param name='maxContacts'></param>
905 /// <param name='contactsArray'></param>
906 /// <param name='contactGeomSize'></param>
907 private int CollideGeoms(
908 IntPtr geom1, IntPtr geom2, int maxContacts, Ode.NET.d.ContactGeom[] contactsArray, int contactGeomSize)
909 {
910 int count;
911
912 lock (OdeScene.UniversalColliderSyncObject)
913 {
914 // We do this inside the lock so that we don't count any delay in acquiring it
915 if (CollectStats)
916 m_nativeCollisionStartTick = Util.EnvironmentTickCount();
917
918 count = d.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize);
919 }
920
921 // We do this outside the lock so that any waiting threads aren't held up, though the effect is probably
922 // negligable
923 if (CollectStats)
924 m_stats[ODENativeGeomCollisionFrameMsStatName]
925 += Util.EnvironmentTickCountSubtract(m_nativeCollisionStartTick);
926
927 return count;
928 }
929
930 /// <summary>
931 /// Collide two spaces or a space and a geometry.
932 /// </summary>
933 /// <param name='space1'></param>
934 /// <param name='space2'>/param>
935 /// <param name='data'></param>
936 private void CollideSpaces(IntPtr space1, IntPtr space2, IntPtr data)
937 {
938 if (CollectStats)
939 {
940 m_inCollisionTiming = true;
941 m_nativeCollisionStartTick = Util.EnvironmentTickCount();
942 }
943
944 d.SpaceCollide2(space1, space2, data, nearCallback);
945
946 if (CollectStats && m_inCollisionTiming)
947 {
948 m_stats[ODENativeSpaceCollisionFrameMsStatName]
949 += Util.EnvironmentTickCountSubtract(m_nativeCollisionStartTick);
950 m_inCollisionTiming = false;
951 }
952 }
953
954 /// <summary>
768 /// This is our near callback. A geometry is near a body 955 /// This is our near callback. A geometry is near a body
769 /// </summary> 956 /// </summary>
770 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param> 957 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param>
@@ -772,6 +959,13 @@ namespace OpenSim.Region.Physics.OdePlugin
772 /// <param name="g2">another geometry or space</param> 959 /// <param name="g2">another geometry or space</param>
773 private void near(IntPtr space, IntPtr g1, IntPtr g2) 960 private void near(IntPtr space, IntPtr g1, IntPtr g2)
774 { 961 {
962 if (CollectStats && m_inCollisionTiming)
963 {
964 m_stats[ODENativeSpaceCollisionFrameMsStatName]
965 += Util.EnvironmentTickCountSubtract(m_nativeCollisionStartTick);
966 m_inCollisionTiming = false;
967 }
968
775// m_log.DebugFormat("[PHYSICS]: Colliding {0} and {1} in {2}", g1, g2, space); 969// m_log.DebugFormat("[PHYSICS]: Colliding {0} and {1} in {2}", g1, g2, space);
776 // no lock here! It's invoked from within Simulate(), which is thread-locked 970 // no lock here! It's invoked from within Simulate(), which is thread-locked
777 971
@@ -789,7 +983,7 @@ namespace OpenSim.Region.Physics.OdePlugin
789 // contact points in the space 983 // contact points in the space
790 try 984 try
791 { 985 {
792 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); 986 CollideSpaces(g1, g2, IntPtr.Zero);
793 } 987 }
794 catch (AccessViolationException) 988 catch (AccessViolationException)
795 { 989 {
@@ -832,6 +1026,7 @@ namespace OpenSim.Region.Physics.OdePlugin
832 1026
833 // Figure out how many contact points we have 1027 // Figure out how many contact points we have
834 int count = 0; 1028 int count = 0;
1029
835 try 1030 try
836 { 1031 {
837 // Colliding Geom To Geom 1032 // Colliding Geom To Geom
@@ -843,8 +1038,11 @@ namespace OpenSim.Region.Physics.OdePlugin
843 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) 1038 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
844 return; 1039 return;
845 1040
846 lock (OdeScene.UniversalColliderSyncObject) 1041 count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf);
847 count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); 1042
1043 // All code after this is only relevant if we have any collisions
1044 if (count <= 0)
1045 return;
848 1046
849 if (count > contacts.Length) 1047 if (count > contacts.Length)
850 m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); 1048 m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length);
@@ -1113,14 +1311,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1113 { 1311 {
1114 _perloopContact.Add(curContact); 1312 _perloopContact.Add(curContact);
1115 1313
1116 // If we're colliding against terrain
1117 if (name1 == "Terrain" || name2 == "Terrain") 1314 if (name1 == "Terrain" || name2 == "Terrain")
1118 { 1315 {
1119 // If we're moving
1120 if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && 1316 if ((p2.PhysicsActorType == (int) ActorTypes.Agent) &&
1121 (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) 1317 (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f))
1122 { 1318 {
1123 // Use the movement terrain contact 1319 // Avatar is moving on terrain, use the movement terrain contact
1124 AvatarMovementTerrainContact.geom = curContact; 1320 AvatarMovementTerrainContact.geom = curContact;
1125 1321
1126 if (m_global_contactcount < maxContactsbeforedeath) 1322 if (m_global_contactcount < maxContactsbeforedeath)
@@ -1133,7 +1329,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1133 { 1329 {
1134 if (p2.PhysicsActorType == (int)ActorTypes.Agent) 1330 if (p2.PhysicsActorType == (int)ActorTypes.Agent)
1135 { 1331 {
1136 // Use the non moving terrain contact 1332 // Avatar is standing on terrain, use the non moving terrain contact
1137 TerrainContact.geom = curContact; 1333 TerrainContact.geom = curContact;
1138 1334
1139 if (m_global_contactcount < maxContactsbeforedeath) 1335 if (m_global_contactcount < maxContactsbeforedeath)
@@ -1228,13 +1424,11 @@ namespace OpenSim.Region.Physics.OdePlugin
1228 } 1424 }
1229 else 1425 else
1230 { 1426 {
1231 // we're colliding with prim or avatar
1232 // check if we're moving
1233 if ((p2.PhysicsActorType == (int)ActorTypes.Agent)) 1427 if ((p2.PhysicsActorType == (int)ActorTypes.Agent))
1234 { 1428 {
1235 if ((Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) 1429 if ((Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f))
1236 { 1430 {
1237 // Use the Movement prim contact 1431 // Avatar is moving on a prim, use the Movement prim contact
1238 AvatarMovementprimContact.geom = curContact; 1432 AvatarMovementprimContact.geom = curContact;
1239 1433
1240 if (m_global_contactcount < maxContactsbeforedeath) 1434 if (m_global_contactcount < maxContactsbeforedeath)
@@ -1245,9 +1439,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1245 } 1439 }
1246 else 1440 else
1247 { 1441 {
1248 // Use the non movement contact 1442 // Avatar is standing still on a prim, use the non movement contact
1249 contact.geom = curContact; 1443 contact.geom = curContact;
1250 _perloopContact.Add(curContact);
1251 1444
1252 if (m_global_contactcount < maxContactsbeforedeath) 1445 if (m_global_contactcount < maxContactsbeforedeath)
1253 { 1446 {
@@ -1355,7 +1548,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1355 break; 1548 break;
1356 } 1549 }
1357 } 1550 }
1358 //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); 1551 //m_log.DebugFormat("[Collision]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth));
1359 //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); 1552 //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z));
1360 } 1553 }
1361 } 1554 }
@@ -1578,7 +1771,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1578 // and we'll run it again on all of them. 1771 // and we'll run it again on all of them.
1579 try 1772 try
1580 { 1773 {
1581 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); 1774 CollideSpaces(space, chr.Shell, IntPtr.Zero);
1582 } 1775 }
1583 catch (AccessViolationException) 1776 catch (AccessViolationException)
1584 { 1777 {
@@ -1593,6 +1786,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1593 //} 1786 //}
1594 } 1787 }
1595 1788
1789 if (CollectStats)
1790 {
1791 m_tempAvatarCollisionsThisFrame = _perloopContact.Count;
1792 m_stats[ODEAvatarContactsStatsName] += m_tempAvatarCollisionsThisFrame;
1793 }
1794
1596 List<OdePrim> removeprims = null; 1795 List<OdePrim> removeprims = null;
1597 foreach (OdePrim chr in _activeprims) 1796 foreach (OdePrim chr in _activeprims)
1598 { 1797 {
@@ -1604,7 +1803,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1604 { 1803 {
1605 if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false) 1804 if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false)
1606 { 1805 {
1607 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); 1806 CollideSpaces(space, chr.prim_geom, IntPtr.Zero);
1608 } 1807 }
1609 else 1808 else
1610 { 1809 {
@@ -1625,6 +1824,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1625 } 1824 }
1626 } 1825 }
1627 1826
1827 if (CollectStats)
1828 m_stats[ODEPrimContactsStatName] += _perloopContact.Count - m_tempAvatarCollisionsThisFrame;
1829
1628 if (removeprims != null) 1830 if (removeprims != null)
1629 { 1831 {
1630 foreach (OdePrim chr in removeprims) 1832 foreach (OdePrim chr in removeprims)
@@ -2226,7 +2428,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2226 /// <param name="prim"></param> 2428 /// <param name="prim"></param>
2227 internal void RemovePrimThreadLocked(OdePrim prim) 2429 internal void RemovePrimThreadLocked(OdePrim prim)
2228 { 2430 {
2229//Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName); 2431// m_log.DebugFormat("[ODE SCENE]: Removing physical prim {0} {1}", prim.Name, prim.LocalID);
2432
2230 lock (prim) 2433 lock (prim)
2231 { 2434 {
2232 RemoveCollisionEventReporting(prim); 2435 RemoveCollisionEventReporting(prim);
@@ -2682,21 +2885,23 @@ namespace OpenSim.Region.Physics.OdePlugin
2682 2885
2683 /// <summary> 2886 /// <summary>
2684 /// This is our main simulate loop 2887 /// This is our main simulate loop
2888 /// </summary>
2889 /// <remarks>
2685 /// It's thread locked by a Mutex in the scene. 2890 /// It's thread locked by a Mutex in the scene.
2686 /// It holds Collisions, it instructs ODE to step through the physical reactions 2891 /// It holds Collisions, it instructs ODE to step through the physical reactions
2687 /// It moves the objects around in memory 2892 /// It moves the objects around in memory
2688 /// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup) 2893 /// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
2689 /// </summary> 2894 /// </remarks>
2690 /// <param name="timeStep"></param> 2895 /// <param name="timeStep"></param>
2691 /// <returns></returns> 2896 /// <returns>The number of frames simulated over that period.</returns>
2692 public override float Simulate(float timeStep) 2897 public override float Simulate(float timeStep)
2693 { 2898 {
2899 int startFrameTick = CollectStats ? Util.EnvironmentTickCount() : 0;
2900 int tempTick = 0, tempTick2 = 0;
2901
2694 if (framecount >= int.MaxValue) 2902 if (framecount >= int.MaxValue)
2695 framecount = 0; 2903 framecount = 0;
2696 2904
2697 //if (m_worldOffset != Vector3.Zero)
2698 // return 0;
2699
2700 framecount++; 2905 framecount++;
2701 2906
2702 float fps = 0; 2907 float fps = 0;
@@ -2704,7 +2909,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2704 float timeLeft = timeStep; 2909 float timeLeft = timeStep;
2705 2910
2706 //m_log.Info(timeStep.ToString()); 2911 //m_log.Info(timeStep.ToString());
2707// step_time += timeStep; 2912// step_time += timeSte
2708// 2913//
2709// // If We're loaded down by something else, 2914// // If We're loaded down by something else,
2710// // or debugging with the Visual Studio project on pause 2915// // or debugging with the Visual Studio project on pause
@@ -2770,6 +2975,9 @@ namespace OpenSim.Region.Physics.OdePlugin
2770 { 2975 {
2771 try 2976 try
2772 { 2977 {
2978 if (CollectStats)
2979 tempTick = Util.EnvironmentTickCount();
2980
2773 lock (_taintedActors) 2981 lock (_taintedActors)
2774 { 2982 {
2775 foreach (OdeCharacter character in _taintedActors) 2983 foreach (OdeCharacter character in _taintedActors)
@@ -2778,6 +2986,13 @@ namespace OpenSim.Region.Physics.OdePlugin
2778 _taintedActors.Clear(); 2986 _taintedActors.Clear();
2779 } 2987 }
2780 2988
2989 if (CollectStats)
2990 {
2991 tempTick2 = Util.EnvironmentTickCount();
2992 m_stats[ODEAvatarTaintMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
2993 tempTick = tempTick2;
2994 }
2995
2781 lock (_taintedPrims) 2996 lock (_taintedPrims)
2782 { 2997 {
2783 foreach (OdePrim prim in _taintedPrims) 2998 foreach (OdePrim prim in _taintedPrims)
@@ -2808,6 +3023,13 @@ namespace OpenSim.Region.Physics.OdePlugin
2808 _taintedPrims.Clear(); 3023 _taintedPrims.Clear();
2809 } 3024 }
2810 3025
3026 if (CollectStats)
3027 {
3028 tempTick2 = Util.EnvironmentTickCount();
3029 m_stats[ODEPrimTaintMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3030 tempTick = tempTick2;
3031 }
3032
2811 // Move characters 3033 // Move characters
2812 foreach (OdeCharacter actor in _characters) 3034 foreach (OdeCharacter actor in _characters)
2813 actor.Move(defects); 3035 actor.Move(defects);
@@ -2827,6 +3049,13 @@ namespace OpenSim.Region.Physics.OdePlugin
2827 defects.Clear(); 3049 defects.Clear();
2828 } 3050 }
2829 3051
3052 if (CollectStats)
3053 {
3054 tempTick2 = Util.EnvironmentTickCount();
3055 m_stats[ODEAvatarForcesFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3056 tempTick = tempTick2;
3057 }
3058
2830 // Move other active objects 3059 // Move other active objects
2831 foreach (OdePrim prim in _activeprims) 3060 foreach (OdePrim prim in _activeprims)
2832 { 3061 {
@@ -2834,14 +3063,35 @@ namespace OpenSim.Region.Physics.OdePlugin
2834 prim.Move(timeStep); 3063 prim.Move(timeStep);
2835 } 3064 }
2836 3065
3066 if (CollectStats)
3067 {
3068 tempTick2 = Util.EnvironmentTickCount();
3069 m_stats[ODEPrimForcesFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3070 tempTick = tempTick2;
3071 }
3072
2837 //if ((framecount % m_randomizeWater) == 0) 3073 //if ((framecount % m_randomizeWater) == 0)
2838 // randomizeWater(waterlevel); 3074 // randomizeWater(waterlevel);
2839 3075
2840 //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); 3076 //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests();
2841 m_rayCastManager.ProcessQueuedRequests(); 3077 m_rayCastManager.ProcessQueuedRequests();
2842 3078
3079 if (CollectStats)
3080 {
3081 tempTick2 = Util.EnvironmentTickCount();
3082 m_stats[ODERaycastingFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3083 tempTick = tempTick2;
3084 }
3085
2843 collision_optimized(); 3086 collision_optimized();
2844 3087
3088 if (CollectStats)
3089 {
3090 tempTick2 = Util.EnvironmentTickCount();
3091 m_stats[ODEOtherCollisionFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3092 tempTick = tempTick2;
3093 }
3094
2845 foreach (PhysicsActor obj in _collisionEventPrim.Values) 3095 foreach (PhysicsActor obj in _collisionEventPrim.Values)
2846 { 3096 {
2847// m_log.DebugFormat("[PHYSICS]: Assessing {0} {1} for collision events", obj.SOPName, obj.LocalID); 3097// m_log.DebugFormat("[PHYSICS]: Assessing {0} {1} for collision events", obj.SOPName, obj.LocalID);
@@ -2866,9 +3116,19 @@ namespace OpenSim.Region.Physics.OdePlugin
2866// "[PHYSICS]: Collision contacts to process this frame = {0}", m_global_contactcount); 3116// "[PHYSICS]: Collision contacts to process this frame = {0}", m_global_contactcount);
2867 3117
2868 m_global_contactcount = 0; 3118 m_global_contactcount = 0;
2869 3119
3120 if (CollectStats)
3121 {
3122 tempTick2 = Util.EnvironmentTickCount();
3123 m_stats[ODECollisionNotificationFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3124 tempTick = tempTick2;
3125 }
3126
2870 d.WorldQuickStep(world, ODE_STEPSIZE); 3127 d.WorldQuickStep(world, ODE_STEPSIZE);
2871 3128
3129 if (CollectStats)
3130 m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
3131
2872 d.JointGroupEmpty(contactgroup); 3132 d.JointGroupEmpty(contactgroup);
2873 } 3133 }
2874 catch (Exception e) 3134 catch (Exception e)
@@ -2879,6 +3139,9 @@ namespace OpenSim.Region.Physics.OdePlugin
2879 timeLeft -= ODE_STEPSIZE; 3139 timeLeft -= ODE_STEPSIZE;
2880 } 3140 }
2881 3141
3142 if (CollectStats)
3143 tempTick = Util.EnvironmentTickCount();
3144
2882 foreach (OdeCharacter actor in _characters) 3145 foreach (OdeCharacter actor in _characters)
2883 { 3146 {
2884 if (actor.bad) 3147 if (actor.bad)
@@ -2902,6 +3165,13 @@ namespace OpenSim.Region.Physics.OdePlugin
2902 defects.Clear(); 3165 defects.Clear();
2903 } 3166 }
2904 3167
3168 if (CollectStats)
3169 {
3170 tempTick2 = Util.EnvironmentTickCount();
3171 m_stats[ODEAvatarUpdateFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
3172 tempTick = tempTick2;
3173 }
3174
2905 //if (timeStep < 0.2f) 3175 //if (timeStep < 0.2f)
2906 3176
2907 foreach (OdePrim prim in _activeprims) 3177 foreach (OdePrim prim in _activeprims)
@@ -2915,6 +3185,9 @@ namespace OpenSim.Region.Physics.OdePlugin
2915 } 3185 }
2916 } 3186 }
2917 3187
3188 if (CollectStats)
3189 m_stats[ODEPrimUpdateFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
3190
2918 //DumpJointInfo(); 3191 //DumpJointInfo();
2919 3192
2920 // Finished with all sim stepping. If requested, dump world state to file for debugging. 3193 // Finished with all sim stepping. If requested, dump world state to file for debugging.
@@ -2936,7 +3209,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2936 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); 3209 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
2937 } 3210 }
2938 3211
2939 latertickcount = Util.EnvironmentTickCount() - tickCountFrameRun; 3212 latertickcount = Util.EnvironmentTickCountSubtract(tickCountFrameRun);
2940 3213
2941 // OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics 3214 // OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics
2942 // has a max of 100 ms to run theoretically. 3215 // has a max of 100 ms to run theoretically.
@@ -2956,6 +3229,9 @@ namespace OpenSim.Region.Physics.OdePlugin
2956 tickCountFrameRun = Util.EnvironmentTickCount(); 3229 tickCountFrameRun = Util.EnvironmentTickCount();
2957 } 3230 }
2958 3231
3232 if (CollectStats)
3233 m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick);
3234
2959 return fps; 3235 return fps;
2960 } 3236 }
2961 3237
@@ -3189,7 +3465,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3189 public override bool IsThreaded 3465 public override bool IsThreaded
3190 { 3466 {
3191 // for now we won't be multithreaded 3467 // for now we won't be multithreaded
3192 get { return (false); } 3468 get { return false; }
3193 } 3469 }
3194 3470
3195 #region ODE Specific Terrain Fixes 3471 #region ODE Specific Terrain Fixes
@@ -3765,26 +4041,19 @@ namespace OpenSim.Region.Physics.OdePlugin
3765 4041
3766 public override Dictionary<uint, float> GetTopColliders() 4042 public override Dictionary<uint, float> GetTopColliders()
3767 { 4043 {
3768 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); 4044 Dictionary<uint, float> topColliders;
3769 int cnt = 0; 4045
3770 lock (_prims) 4046 lock (_prims)
3771 { 4047 {
3772 foreach (OdePrim prm in _prims) 4048 List<OdePrim> orderedPrims = new List<OdePrim>(_prims);
3773 { 4049 orderedPrims.OrderByDescending(p => p.CollisionScore).Take(25);
3774 if (prm.CollisionScore > 0) 4050 topColliders = orderedPrims.ToDictionary(p => p.LocalID, p => p.CollisionScore);
3775 { 4051
3776 returncolliders.Add(prm.LocalID, prm.CollisionScore); 4052 foreach (OdePrim p in _prims)
3777 cnt++; 4053 p.CollisionScore = 0;
3778 prm.CollisionScore = 0f;
3779 if (cnt > 25)
3780 {
3781 break;
3782 }
3783 }
3784 }
3785 } 4054 }
3786 4055
3787 return returncolliders; 4056 return topColliders;
3788 } 4057 }
3789 4058
3790 public override bool SupportsRayCast() 4059 public override bool SupportsRayCast()
@@ -3954,5 +4223,52 @@ namespace OpenSim.Region.Physics.OdePlugin
3954 ds.SetViewpoint(ref xyz, ref hpr); 4223 ds.SetViewpoint(ref xyz, ref hpr);
3955 } 4224 }
3956#endif 4225#endif
4226
4227 public override Dictionary<string, float> GetStats()
4228 {
4229 if (!CollectStats)
4230 return null;
4231
4232 Dictionary<string, float> returnStats;
4233
4234 lock (OdeLock)
4235 {
4236 returnStats = new Dictionary<string, float>(m_stats);
4237
4238 // FIXME: This is a SUPER DUMB HACK until we can establish stats that aren't subject to a division by
4239 // 3 from the SimStatsReporter.
4240 returnStats[ODETotalAvatarsStatName] = _characters.Count * 3;
4241 returnStats[ODETotalPrimsStatName] = _prims.Count * 3;
4242 returnStats[ODEActivePrimsStatName] = _activeprims.Count * 3;
4243
4244 InitializeExtraStats();
4245 }
4246
4247 returnStats[ODEOtherCollisionFrameMsStatName]
4248 = returnStats[ODEOtherCollisionFrameMsStatName]
4249 - returnStats[ODENativeSpaceCollisionFrameMsStatName]
4250 - returnStats[ODENativeGeomCollisionFrameMsStatName];
4251
4252 return returnStats;
4253 }
4254
4255 private void InitializeExtraStats()
4256 {
4257 m_stats[ODETotalFrameMsStatName] = 0;
4258 m_stats[ODEAvatarTaintMsStatName] = 0;
4259 m_stats[ODEPrimTaintMsStatName] = 0;
4260 m_stats[ODEAvatarForcesFrameMsStatName] = 0;
4261 m_stats[ODEPrimForcesFrameMsStatName] = 0;
4262 m_stats[ODERaycastingFrameMsStatName] = 0;
4263 m_stats[ODENativeStepFrameMsStatName] = 0;
4264 m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
4265 m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
4266 m_stats[ODEOtherCollisionFrameMsStatName] = 0;
4267 m_stats[ODECollisionNotificationFrameMsStatName] = 0;
4268 m_stats[ODEAvatarContactsStatsName] = 0;
4269 m_stats[ODEPrimContactsStatName] = 0;
4270 m_stats[ODEAvatarUpdateFrameMsStatName] = 0;
4271 m_stats[ODEPrimUpdateFrameMsStatName] = 0;
4272 }
3957 } 4273 }
3958} \ No newline at end of file 4274} \ No newline at end of file
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
index d8d9554..204c4ff 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
@@ -43,9 +43,8 @@ using Mono.Addins;
43[assembly: AddinDependency("OpenSim", "0.5")] 43[assembly: AddinDependency("OpenSim", "0.5")]
44namespace OpenSim.Region.RegionCombinerModule 44namespace OpenSim.Region.RegionCombinerModule
45{ 45{
46
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] 46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
48 public class RegionCombinerModule : ISharedRegionModule 47 public class RegionCombinerModule : ISharedRegionModule, IRegionCombinerModule
49 { 48 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 50
@@ -59,19 +58,33 @@ namespace OpenSim.Region.RegionCombinerModule
59 get { return null; } 58 get { return null; }
60 } 59 }
61 60
61 /// <summary>
62 /// Is this module enabled?
63 /// </summary>
64 private bool m_combineContiguousRegions = false;
65
66 /// <summary>
67 /// This holds the root regions for the megaregions.
68 /// </summary>
69 /// <remarks>
70 /// Usually there is only ever one megaregion (and hence only one entry here).
71 /// </remarks>
62 private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>(); 72 private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>();
63 private bool enabledYN = false; 73
74 /// <summary>
75 /// The scenes that comprise the megaregion.
76 /// </summary>
64 private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>(); 77 private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>();
65 78
66 public void Initialise(IConfigSource source) 79 public void Initialise(IConfigSource source)
67 { 80 {
68 IConfig myConfig = source.Configs["Startup"]; 81 IConfig myConfig = source.Configs["Startup"];
69 enabledYN = myConfig.GetBoolean("CombineContiguousRegions", false); 82 m_combineContiguousRegions = myConfig.GetBoolean("CombineContiguousRegions", false);
70 83
71 if (enabledYN) 84 MainConsole.Instance.Commands.AddCommand(
72 MainConsole.Instance.Commands.AddCommand( 85 "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms",
73 "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms", 86 "Fixes phantom objects after an import to a megaregion or a change from a megaregion back to normal regions",
74 "Fixes phantom objects after an import to megaregions", FixPhantoms); 87 FixPhantoms);
75 } 88 }
76 89
77 public void Close() 90 public void Close()
@@ -80,6 +93,8 @@ namespace OpenSim.Region.RegionCombinerModule
80 93
81 public void AddRegion(Scene scene) 94 public void AddRegion(Scene scene)
82 { 95 {
96 if (m_combineContiguousRegions)
97 scene.RegisterModuleInterface<IRegionCombinerModule>(this);
83 } 98 }
84 99
85 public void RemoveRegion(Scene scene) 100 public void RemoveRegion(Scene scene)
@@ -88,8 +103,113 @@ namespace OpenSim.Region.RegionCombinerModule
88 103
89 public void RegionLoaded(Scene scene) 104 public void RegionLoaded(Scene scene)
90 { 105 {
91 if (enabledYN) 106 lock (m_startingScenes)
107 m_startingScenes.Add(scene.RegionInfo.originRegionID, scene);
108
109 if (m_combineContiguousRegions)
110 {
92 RegionLoadedDoWork(scene); 111 RegionLoadedDoWork(scene);
112
113 scene.EventManager.OnNewPresence += NewPresence;
114 }
115 }
116
117 public bool IsRootForMegaregion(UUID regionId)
118 {
119 lock (m_regions)
120 return m_regions.ContainsKey(regionId);
121 }
122
123 public Vector2 GetSizeOfMegaregion(UUID regionId)
124 {
125 lock (m_regions)
126 {
127 if (m_regions.ContainsKey(regionId))
128 {
129 RegionConnections rootConn = m_regions[regionId];
130
131 return new Vector2((float)rootConn.XEnd, (float)rootConn.YEnd);
132 }
133 }
134
135 throw new Exception(string.Format("Region with id {0} not found", regionId));
136 }
137
138 private void NewPresence(ScenePresence presence)
139 {
140 if (presence.IsChildAgent)
141 {
142 byte[] throttleData;
143
144 try
145 {
146 throttleData = presence.ControllingClient.GetThrottlesPacked(1);
147 }
148 catch (NotImplementedException)
149 {
150 return;
151 }
152
153 if (throttleData == null)
154 return;
155
156 if (throttleData.Length == 0)
157 return;
158
159 if (throttleData.Length != 28)
160 return;
161
162 byte[] adjData;
163 int pos = 0;
164
165 if (!BitConverter.IsLittleEndian)
166 {
167 byte[] newData = new byte[7 * 4];
168 Buffer.BlockCopy(throttleData, 0, newData, 0, 7 * 4);
169
170 for (int i = 0; i < 7; i++)
171 Array.Reverse(newData, i * 4, 4);
172
173 adjData = newData;
174 }
175 else
176 {
177 adjData = throttleData;
178 }
179
180 // 0.125f converts from bits to bytes
181 int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
182 int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
183 int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
184 int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
185 int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
186 int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
187 int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
188 // State is a subcategory of task that we allocate a percentage to
189
190
191 //int total = resend + land + wind + cloud + task + texture + asset;
192
193 byte[] data = new byte[7 * 4];
194 int ii = 0;
195
196 Buffer.BlockCopy(Utils.FloatToBytes(resend), 0, data, ii, 4); ii += 4;
197 Buffer.BlockCopy(Utils.FloatToBytes(land * 50), 0, data, ii, 4); ii += 4;
198 Buffer.BlockCopy(Utils.FloatToBytes(wind), 0, data, ii, 4); ii += 4;
199 Buffer.BlockCopy(Utils.FloatToBytes(cloud), 0, data, ii, 4); ii += 4;
200 Buffer.BlockCopy(Utils.FloatToBytes(task), 0, data, ii, 4); ii += 4;
201 Buffer.BlockCopy(Utils.FloatToBytes(texture), 0, data, ii, 4); ii += 4;
202 Buffer.BlockCopy(Utils.FloatToBytes(asset), 0, data, ii, 4);
203
204 try
205 {
206 presence.ControllingClient.SetChildAgentThrottle(data);
207 }
208 catch (NotImplementedException)
209 {
210 return;
211 }
212 }
93 } 213 }
94 214
95 private void RegionLoadedDoWork(Scene scene) 215 private void RegionLoadedDoWork(Scene scene)
@@ -100,8 +220,6 @@ namespace OpenSim.Region.RegionCombinerModule
100 return; 220 return;
101 // 221 //
102*/ 222*/
103 lock (m_startingScenes)
104 m_startingScenes.Add(scene.RegionInfo.originRegionID, scene);
105 223
106 // Give each region a standard set of non-infinite borders 224 // Give each region a standard set of non-infinite borders
107 Border northBorder = new Border(); 225 Border northBorder = new Border();
@@ -124,24 +242,21 @@ namespace OpenSim.Region.RegionCombinerModule
124 westBorder.CrossDirection = Cardinals.W; 242 westBorder.CrossDirection = Cardinals.W;
125 scene.WestBorders[0] = westBorder; 243 scene.WestBorders[0] = westBorder;
126 244
127 245 RegionConnections newConn = new RegionConnections();
128 246 newConn.ConnectedRegions = new List<RegionData>();
129 RegionConnections regionConnections = new RegionConnections(); 247 newConn.RegionScene = scene;
130 regionConnections.ConnectedRegions = new List<RegionData>(); 248 newConn.RegionLandChannel = scene.LandChannel;
131 regionConnections.RegionScene = scene; 249 newConn.RegionId = scene.RegionInfo.originRegionID;
132 regionConnections.RegionLandChannel = scene.LandChannel; 250 newConn.X = scene.RegionInfo.RegionLocX;
133 regionConnections.RegionId = scene.RegionInfo.originRegionID; 251 newConn.Y = scene.RegionInfo.RegionLocY;
134 regionConnections.X = scene.RegionInfo.RegionLocX; 252 newConn.XEnd = (int)Constants.RegionSize;
135 regionConnections.Y = scene.RegionInfo.RegionLocY; 253 newConn.YEnd = (int)Constants.RegionSize;
136 regionConnections.XEnd = (int)Constants.RegionSize;
137 regionConnections.YEnd = (int)Constants.RegionSize;
138
139 254
140 lock (m_regions) 255 lock (m_regions)
141 { 256 {
142 bool connectedYN = false; 257 bool connectedYN = false;
143 258
144 foreach (RegionConnections conn in m_regions.Values) 259 foreach (RegionConnections rootConn in m_regions.Values)
145 { 260 {
146 #region commented 261 #region commented
147 /* 262 /*
@@ -306,13 +421,9 @@ namespace OpenSim.Region.RegionCombinerModule
306 //xxy 421 //xxy
307 //xxx 422 //xxx
308 423
309 424 if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY >= newConn.PosY)
310 if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd
311 >= (regionConnections.X * (int)Constants.RegionSize))
312 && (((int)conn.Y * (int)Constants.RegionSize)
313 >= (regionConnections.Y * (int)Constants.RegionSize)))
314 { 425 {
315 connectedYN = DoWorkForOneRegionOverPlusXY(conn, regionConnections, scene); 426 connectedYN = DoWorkForOneRegionOverPlusXY(rootConn, newConn, scene);
316 break; 427 break;
317 } 428 }
318 429
@@ -320,12 +431,9 @@ namespace OpenSim.Region.RegionCombinerModule
320 //xyx 431 //xyx
321 //xxx 432 //xxx
322 //xxx 433 //xxx
323 if ((((int)conn.X * (int)Constants.RegionSize) 434 if (rootConn.PosX >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
324 >= (regionConnections.X * (int)Constants.RegionSize))
325 && (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
326 >= (regionConnections.Y * (int)Constants.RegionSize)))
327 { 435 {
328 connectedYN = DoWorkForOneRegionOverXPlusY(conn, regionConnections, scene); 436 connectedYN = DoWorkForOneRegionOverXPlusY(rootConn, newConn, scene);
329 break; 437 break;
330 } 438 }
331 439
@@ -333,12 +441,9 @@ namespace OpenSim.Region.RegionCombinerModule
333 //xxy 441 //xxy
334 //xxx 442 //xxx
335 //xxx 443 //xxx
336 if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd 444 if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
337 >= (regionConnections.X * (int)Constants.RegionSize))
338 && (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
339 >= (regionConnections.Y * (int)Constants.RegionSize)))
340 { 445 {
341 connectedYN = DoWorkForOneRegionOverPlusXPlusY(conn, regionConnections, scene); 446 connectedYN = DoWorkForOneRegionOverPlusXPlusY(rootConn, newConn, scene);
342 break; 447 break;
343 448
344 } 449 }
@@ -347,66 +452,63 @@ namespace OpenSim.Region.RegionCombinerModule
347 // If !connectYN means that this region is a root region 452 // If !connectYN means that this region is a root region
348 if (!connectedYN) 453 if (!connectedYN)
349 { 454 {
350 DoWorkForRootRegion(regionConnections, scene); 455 DoWorkForRootRegion(newConn, scene);
351
352 } 456 }
353 } 457 }
458
354 // Set up infinite borders around the entire AABB of the combined ConnectedRegions 459 // Set up infinite borders around the entire AABB of the combined ConnectedRegions
355 AdjustLargeRegionBounds(); 460 AdjustLargeRegionBounds();
356 } 461 }
357 462
358 private bool DoWorkForOneRegionOverPlusXY(RegionConnections conn, RegionConnections regionConnections, Scene scene) 463 private bool DoWorkForOneRegionOverPlusXY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
359 { 464 {
360 Vector3 offset = Vector3.Zero; 465 Vector3 offset = Vector3.Zero;
361 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) - 466 offset.X = newConn.PosX - rootConn.PosX;
362 ((conn.X * (int)Constants.RegionSize))); 467 offset.Y = newConn.PosY - rootConn.PosY;
363 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
364 ((conn.Y * (int)Constants.RegionSize)));
365 468
366 Vector3 extents = Vector3.Zero; 469 Vector3 extents = Vector3.Zero;
367 extents.Y = conn.YEnd; 470 extents.Y = rootConn.YEnd;
368 extents.X = conn.XEnd + regionConnections.XEnd; 471 extents.X = rootConn.XEnd + newConn.XEnd;
369 472
370 conn.UpdateExtents(extents); 473 rootConn.UpdateExtents(extents);
371 474
372 m_log.DebugFormat("Scene: {0} to the west of Scene{1} Offset: {2}. Extents:{3}", 475 m_log.DebugFormat(
373 conn.RegionScene.RegionInfo.RegionName, 476 "[REGION COMBINER MODULE]: Root region {0} is to the west of region {1}, Offset: {2}, Extents: {3}",
374 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); 477 rootConn.RegionScene.RegionInfo.RegionName,
478 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
375 479
376 scene.BordersLocked = true; 480 scene.BordersLocked = true;
377 conn.RegionScene.BordersLocked = true; 481 rootConn.RegionScene.BordersLocked = true;
378 482
379 RegionData ConnectedRegion = new RegionData(); 483 RegionData ConnectedRegion = new RegionData();
380 ConnectedRegion.Offset = offset; 484 ConnectedRegion.Offset = offset;
381 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID; 485 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
382 ConnectedRegion.RegionScene = scene; 486 ConnectedRegion.RegionScene = scene;
383 conn.ConnectedRegions.Add(ConnectedRegion); 487 rootConn.ConnectedRegions.Add(ConnectedRegion);
384 488
385 // Inform root region Physics about the extents of this region 489 // Inform root region Physics about the extents of this region
386 conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); 490 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
387 491
388 // Inform Child region that it needs to forward it's terrain to the root region 492 // Inform Child region that it needs to forward it's terrain to the root region
389 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); 493 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
390 494
391 // Extend the borders as appropriate 495 // Extend the borders as appropriate
392 lock (conn.RegionScene.EastBorders) 496 lock (rootConn.RegionScene.EastBorders)
393 conn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize; 497 rootConn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize;
394 498
395 lock (conn.RegionScene.NorthBorders) 499 lock (rootConn.RegionScene.NorthBorders)
396 conn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize; 500 rootConn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
397 501
398 lock (conn.RegionScene.SouthBorders) 502 lock (rootConn.RegionScene.SouthBorders)
399 conn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize; 503 rootConn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
400 504
401 lock (scene.WestBorders) 505 lock (scene.WestBorders)
402 { 506 {
403 507 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
404
405 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - conn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
406 508
407 // Trigger auto teleport to root region 509 // Trigger auto teleport to root region
408 scene.WestBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 510 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
409 scene.WestBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 511 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
410 } 512 }
411 513
412 // Reset Terrain.. since terrain loads before we get here, we need to load 514 // Reset Terrain.. since terrain loads before we get here, we need to load
@@ -415,56 +517,58 @@ namespace OpenSim.Region.RegionCombinerModule
415 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); 517 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
416 518
417 // Unlock borders 519 // Unlock borders
418 conn.RegionScene.BordersLocked = false; 520 rootConn.RegionScene.BordersLocked = false;
419 scene.BordersLocked = false; 521 scene.BordersLocked = false;
420 522
421 // Create a client event forwarder and add this region's events to the root region. 523 // Create a client event forwarder and add this region's events to the root region.
422 if (conn.ClientEventForwarder != null) 524 if (rootConn.ClientEventForwarder != null)
423 conn.ClientEventForwarder.AddSceneToEventForwarding(scene); 525 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
424 526
425 return true; 527 return true;
426 } 528 }
427 529
428 private bool DoWorkForOneRegionOverXPlusY(RegionConnections conn, RegionConnections regionConnections, Scene scene) 530 private bool DoWorkForOneRegionOverXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
429 { 531 {
430 Vector3 offset = Vector3.Zero; 532 Vector3 offset = Vector3.Zero;
431 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) - 533 offset.X = newConn.PosX - rootConn.PosX;
432 ((conn.X * (int)Constants.RegionSize))); 534 offset.Y = newConn.PosY - rootConn.PosY;
433 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
434 ((conn.Y * (int)Constants.RegionSize)));
435 535
436 Vector3 extents = Vector3.Zero; 536 Vector3 extents = Vector3.Zero;
437 extents.Y = regionConnections.YEnd + conn.YEnd; 537 extents.Y = newConn.YEnd + rootConn.YEnd;
438 extents.X = conn.XEnd; 538 extents.X = rootConn.XEnd;
439 conn.UpdateExtents(extents); 539 rootConn.UpdateExtents(extents);
440 540
441 scene.BordersLocked = true; 541 scene.BordersLocked = true;
442 conn.RegionScene.BordersLocked = true; 542 rootConn.RegionScene.BordersLocked = true;
443 543
444 RegionData ConnectedRegion = new RegionData(); 544 RegionData ConnectedRegion = new RegionData();
445 ConnectedRegion.Offset = offset; 545 ConnectedRegion.Offset = offset;
446 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID; 546 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
447 ConnectedRegion.RegionScene = scene; 547 ConnectedRegion.RegionScene = scene;
448 conn.ConnectedRegions.Add(ConnectedRegion); 548 rootConn.ConnectedRegions.Add(ConnectedRegion);
549
550 m_log.DebugFormat(
551 "[REGION COMBINER MODULE]: Root region {0} is to the south of region {1}, Offset: {2}, Extents: {3}",
552 rootConn.RegionScene.RegionInfo.RegionName,
553 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
554
555 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
556 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
449 557
450 m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}", 558 lock (rootConn.RegionScene.NorthBorders)
451 conn.RegionScene.RegionInfo.RegionName, 559 rootConn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
452 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
453 560
454 conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); 561 lock (rootConn.RegionScene.EastBorders)
455 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); 562 rootConn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
563
564 lock (rootConn.RegionScene.WestBorders)
565 rootConn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
456 566
457 lock (conn.RegionScene.NorthBorders)
458 conn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
459 lock (conn.RegionScene.EastBorders)
460 conn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
461 lock (conn.RegionScene.WestBorders)
462 conn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
463 lock (scene.SouthBorders) 567 lock (scene.SouthBorders)
464 { 568 {
465 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - conn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south 569 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south
466 scene.SouthBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 570 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
467 scene.SouthBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 571 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
468 } 572 }
469 573
470 // Reset Terrain.. since terrain normally loads first. 574 // Reset Terrain.. since terrain normally loads first.
@@ -473,83 +577,92 @@ namespace OpenSim.Region.RegionCombinerModule
473 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised()); 577 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
474 578
475 scene.BordersLocked = false; 579 scene.BordersLocked = false;
476 conn.RegionScene.BordersLocked = false; 580 rootConn.RegionScene.BordersLocked = false;
477 if (conn.ClientEventForwarder != null) 581
478 conn.ClientEventForwarder.AddSceneToEventForwarding(scene); 582 if (rootConn.ClientEventForwarder != null)
583 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
584
479 return true; 585 return true;
480 } 586 }
481 587
482 private bool DoWorkForOneRegionOverPlusXPlusY(RegionConnections conn, RegionConnections regionConnections, Scene scene) 588 private bool DoWorkForOneRegionOverPlusXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
483 { 589 {
484 Vector3 offset = Vector3.Zero; 590 Vector3 offset = Vector3.Zero;
485 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) - 591 offset.X = newConn.PosX - rootConn.PosX;
486 ((conn.X * (int)Constants.RegionSize))); 592 offset.Y = newConn.PosY - rootConn.PosY;
487 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
488 ((conn.Y * (int)Constants.RegionSize)));
489 593
490 Vector3 extents = Vector3.Zero; 594 Vector3 extents = Vector3.Zero;
491 extents.Y = regionConnections.YEnd + conn.YEnd; 595
492 extents.X = regionConnections.XEnd + conn.XEnd; 596 // We do not want to inflate the extents for regions strictly to the NE of the root region, since this
493 conn.UpdateExtents(extents); 597 // would double count regions strictly to the north and east that have already been added.
598// extents.Y = regionConnections.YEnd + conn.YEnd;
599// extents.X = regionConnections.XEnd + conn.XEnd;
600// conn.UpdateExtents(extents);
601
602 extents.Y = rootConn.YEnd;
603 extents.X = rootConn.XEnd;
494 604
495 scene.BordersLocked = true; 605 scene.BordersLocked = true;
496 conn.RegionScene.BordersLocked = true; 606 rootConn.RegionScene.BordersLocked = true;
497 607
498 RegionData ConnectedRegion = new RegionData(); 608 RegionData ConnectedRegion = new RegionData();
499 ConnectedRegion.Offset = offset; 609 ConnectedRegion.Offset = offset;
500 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID; 610 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
501 ConnectedRegion.RegionScene = scene; 611 ConnectedRegion.RegionScene = scene;
502 612
503 conn.ConnectedRegions.Add(ConnectedRegion); 613 rootConn.ConnectedRegions.Add(ConnectedRegion);
614
615 m_log.DebugFormat(
616 "[REGION COMBINER MODULE]: Region {0} is to the southwest of Scene {1}, Offset: {2}, Extents: {3}",
617 rootConn.RegionScene.RegionInfo.RegionName,
618 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
504 619
505 m_log.DebugFormat("Scene: {0} to the NorthEast of Scene{1} Offset: {2}. Extents:{3}", 620 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
506 conn.RegionScene.RegionInfo.RegionName, 621 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
507 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
508 622
509 conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); 623 lock (rootConn.RegionScene.NorthBorders)
510 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero);
511 lock (conn.RegionScene.NorthBorders)
512 { 624 {
513 if (conn.RegionScene.NorthBorders.Count == 1)// && 2) 625 if (rootConn.RegionScene.NorthBorders.Count == 1)// && 2)
514 { 626 {
515 //compound border 627 //compound border
516 // already locked above 628 // already locked above
517 conn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize; 629 rootConn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
630
631 lock (rootConn.RegionScene.EastBorders)
632 rootConn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
518 633
519 lock (conn.RegionScene.EastBorders) 634 lock (rootConn.RegionScene.WestBorders)
520 conn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize; 635 rootConn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
521 lock (conn.RegionScene.WestBorders)
522 conn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
523 } 636 }
524 } 637 }
525 638
526 lock (scene.SouthBorders) 639 lock (scene.SouthBorders)
527 { 640 {
528 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - conn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south 641 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south
529 scene.SouthBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 642 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
530 scene.SouthBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 643 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
531 } 644 }
532 645
533 lock (conn.RegionScene.EastBorders) 646 lock (rootConn.RegionScene.EastBorders)
534 { 647 {
535 if (conn.RegionScene.EastBorders.Count == 1)// && conn.RegionScene.EastBorders.Count == 2) 648 if (rootConn.RegionScene.EastBorders.Count == 1)// && conn.RegionScene.EastBorders.Count == 2)
536 { 649 {
537 650
538 conn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize; 651 rootConn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize;
539 lock (conn.RegionScene.NorthBorders)
540 conn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
541 lock (conn.RegionScene.SouthBorders)
542 conn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
543 652
653 lock (rootConn.RegionScene.NorthBorders)
654 rootConn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
544 655
656 lock (rootConn.RegionScene.SouthBorders)
657 rootConn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
545 } 658 }
546 } 659 }
547 660
548 lock (scene.WestBorders) 661 lock (scene.WestBorders)
549 { 662 {
550 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - conn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West 663 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
551 scene.WestBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 664 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
552 scene.WestBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 665 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
553 } 666 }
554 667
555 /* 668 /*
@@ -568,46 +681,50 @@ namespace OpenSim.Region.RegionCombinerModule
568 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); 681 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
569 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised()); 682 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
570 scene.BordersLocked = false; 683 scene.BordersLocked = false;
571 conn.RegionScene.BordersLocked = false; 684 rootConn.RegionScene.BordersLocked = false;
572 685
573 if (conn.ClientEventForwarder != null) 686 if (rootConn.ClientEventForwarder != null)
574 conn.ClientEventForwarder.AddSceneToEventForwarding(scene); 687 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
575 688
576 return true; 689 return true;
577 690
578 //scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents); 691 //scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents);
579
580 } 692 }
581 693
582 private void DoWorkForRootRegion(RegionConnections regionConnections, Scene scene) 694 private void DoWorkForRootRegion(RegionConnections rootConn, Scene scene)
583 { 695 {
696 m_log.DebugFormat("[REGION COMBINER MODULE]: Adding root region {0}", scene.RegionInfo.RegionName);
697
584 RegionData rdata = new RegionData(); 698 RegionData rdata = new RegionData();
585 rdata.Offset = Vector3.Zero; 699 rdata.Offset = Vector3.Zero;
586 rdata.RegionId = scene.RegionInfo.originRegionID; 700 rdata.RegionId = scene.RegionInfo.originRegionID;
587 rdata.RegionScene = scene; 701 rdata.RegionScene = scene;
588 // save it's land channel 702 // save it's land channel
589 regionConnections.RegionLandChannel = scene.LandChannel; 703 rootConn.RegionLandChannel = scene.LandChannel;
590 704
591 // Substitue our landchannel 705 // Substitue our landchannel
592 RegionCombinerLargeLandChannel lnd = new RegionCombinerLargeLandChannel(rdata, scene.LandChannel, 706 RegionCombinerLargeLandChannel lnd = new RegionCombinerLargeLandChannel(rdata, scene.LandChannel,
593 regionConnections.ConnectedRegions); 707 rootConn.ConnectedRegions);
708
594 scene.LandChannel = lnd; 709 scene.LandChannel = lnd;
710
595 // Forward the permissions modules of each of the connected regions to the root region 711 // Forward the permissions modules of each of the connected regions to the root region
596 lock (m_regions) 712 lock (m_regions)
597 { 713 {
598 foreach (RegionData r in regionConnections.ConnectedRegions) 714 foreach (RegionData r in rootConn.ConnectedRegions)
599 { 715 {
600 ForwardPermissionRequests(regionConnections, r.RegionScene); 716 ForwardPermissionRequests(rootConn, r.RegionScene);
601 } 717 }
602 }
603 // Create the root region's Client Event Forwarder
604 regionConnections.ClientEventForwarder = new RegionCombinerClientEventForwarder(regionConnections);
605
606 // Sets up the CoarseLocationUpdate forwarder for this root region
607 scene.EventManager.OnNewPresence += SetCourseLocationDelegate;
608 718
609 // Adds this root region to a dictionary of regions that are connectable 719 // Create the root region's Client Event Forwarder
610 m_regions.Add(scene.RegionInfo.originRegionID, regionConnections); 720 rootConn.ClientEventForwarder = new RegionCombinerClientEventForwarder(rootConn);
721
722 // Sets up the CoarseLocationUpdate forwarder for this root region
723 scene.EventManager.OnNewPresence += SetCourseLocationDelegate;
724
725 // Adds this root region to a dictionary of regions that are connectable
726 m_regions.Add(scene.RegionInfo.originRegionID, rootConn);
727 }
611 } 728 }
612 729
613 private void SetCourseLocationDelegate(ScenePresence presence) 730 private void SetCourseLocationDelegate(ScenePresence presence)
@@ -864,6 +981,7 @@ namespace OpenSim.Region.RegionCombinerModule
864 return true; 981 return true;
865 } 982 }
866 } 983 }
984
867 oborder = null; 985 oborder = null;
868 return false; 986 return false;
869 } 987 }
@@ -873,14 +991,19 @@ namespace OpenSim.Region.RegionCombinerModule
873 pPosition = pPosition/(int) Constants.RegionSize; 991 pPosition = pPosition/(int) Constants.RegionSize;
874 int OffsetX = (int) pPosition.X; 992 int OffsetX = (int) pPosition.X;
875 int OffsetY = (int) pPosition.Y; 993 int OffsetY = (int) pPosition.Y;
876 foreach (RegionConnections regConn in m_regions.Values) 994
995 lock (m_regions)
877 { 996 {
878 foreach (RegionData reg in regConn.ConnectedRegions) 997 foreach (RegionConnections regConn in m_regions.Values)
879 { 998 {
880 if (reg.Offset.X == OffsetX && reg.Offset.Y == OffsetY) 999 foreach (RegionData reg in regConn.ConnectedRegions)
881 return reg; 1000 {
1001 if (reg.Offset.X == OffsetX && reg.Offset.Y == OffsetY)
1002 return reg;
1003 }
882 } 1004 }
883 } 1005 }
1006
884 return new RegionData(); 1007 return new RegionData();
885 } 1008 }
886 1009
@@ -936,18 +1059,19 @@ namespace OpenSim.Region.RegionCombinerModule
936 } 1059 }
937 1060
938 #region console commands 1061 #region console commands
1062
939 public void FixPhantoms(string module, string[] cmdparams) 1063 public void FixPhantoms(string module, string[] cmdparams)
940 { 1064 {
941 List<Scene> scenes = new List<Scene>(m_startingScenes.Values); 1065 List<Scene> scenes = new List<Scene>(m_startingScenes.Values);
1066
942 foreach (Scene s in scenes) 1067 foreach (Scene s in scenes)
943 { 1068 {
944 s.ForEachSOG(delegate(SceneObjectGroup e) 1069 MainConsole.Instance.OutputFormat("Fixing phantoms for {0}", s.RegionInfo.RegionName);
945 { 1070
946 e.AbsolutePosition = e.AbsolutePosition; 1071 s.ForEachSOG(so => so.AbsolutePosition = so.AbsolutePosition);
947 }
948 );
949 } 1072 }
950 } 1073 }
1074
951 #endregion 1075 #endregion
952 } 1076 }
953} 1077}
diff --git a/OpenSim/Region/RegionCombinerModule/RegionConnections.cs b/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
index 3aa9f20..fba51d2 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using OpenMetaverse; 30using OpenMetaverse;
31using OpenSim.Framework;
31using OpenSim.Region.Framework.Interfaces; 32using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
33 34
@@ -49,17 +50,45 @@ namespace OpenSim.Region.RegionCombinerModule
49 /// LargeLandChannel for combined region 50 /// LargeLandChannel for combined region
50 /// </summary> 51 /// </summary>
51 public ILandChannel RegionLandChannel; 52 public ILandChannel RegionLandChannel;
53
54 /// <summary>
55 /// The x map co-ordinate for this region (where each co-ordinate is a Constants.RegionSize block).
56 /// </summary>
52 public uint X; 57 public uint X;
58
59 /// <summary>
60 /// The y co-ordinate for this region (where each cor-odinate is a Constants.RegionSize block).
61 /// </summary>
53 public uint Y; 62 public uint Y;
54 public int XEnd; 63
55 public int YEnd; 64 /// <summary>
65 /// The X meters position of this connection.
66 /// </summary>
67 public uint PosX { get { return X * Constants.RegionSize; } }
68
69 /// <summary>
70 /// The Y meters co-ordinate of this connection.
71 /// </summary>
72 public uint PosY { get { return Y * Constants.RegionSize; } }
73
74 /// <summary>
75 /// The size of the megaregion in meters.
76 /// </summary>
77 public uint XEnd;
78
79 /// <summary>
80 /// The size of the megaregion in meters.
81 /// </summary>
82 public uint YEnd;
83
56 public List<RegionData> ConnectedRegions; 84 public List<RegionData> ConnectedRegions;
57 public RegionCombinerPermissionModule PermissionModule; 85 public RegionCombinerPermissionModule PermissionModule;
58 public RegionCombinerClientEventForwarder ClientEventForwarder; 86 public RegionCombinerClientEventForwarder ClientEventForwarder;
87
59 public void UpdateExtents(Vector3 extents) 88 public void UpdateExtents(Vector3 extents)
60 { 89 {
61 XEnd = (int)extents.X; 90 XEnd = (uint)extents.X;
62 YEnd = (int)extents.Y; 91 YEnd = (uint)extents.Y;
63 } 92 }
64 } 93 }
65} \ No newline at end of file 94} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
index bb5bacc..2027ca6 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
@@ -27,17 +27,22 @@
27 27
28using System; 28using System;
29using OpenMetaverse; 29using OpenMetaverse;
30using OpenSim.Framework;
30using OpenSim.Region.Framework.Scenes; 31using OpenSim.Region.Framework.Scenes;
31 32
32
33namespace OpenSim.Region.ScriptEngine.Interfaces 33namespace OpenSim.Region.ScriptEngine.Interfaces
34{ 34{
35 public interface IScriptApi 35 public interface IScriptApi
36 { 36 {
37 // 37 /// <summary>
38 // Each API has an identifier, which is used to load the 38 /// Initialize the API
39 // proper runtime assembly at load time. 39 /// </summary>
40 // 40 /// <remarks>
41 void Initialize(IScriptEngine engine, SceneObjectPart part, uint localID, UUID item); 41 /// Each API has an identifier, which is used to load the
42 /// proper runtime assembly at load time.
43 /// <param name='engine'>/param>
44 /// <param name='part'></param>
45 /// <param name='item'></param>
46 void Initialize(IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item);
42 } 47 }
43} 48} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index b04f6b6..ec13b6c 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -64,6 +64,16 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
64 bool Running { get; set; } 64 bool Running { get; set; }
65 65
66 /// <summary> 66 /// <summary>
67 /// Gets or sets a value indicating whether this
68 /// <see cref="OpenSim.Region.ScriptEngine.Interfaces.IScriptInstance"/> is run.
69 /// For viewer script editor control
70 /// </summary>
71 /// <value>
72 /// <c>true</c> if run; otherwise, <c>false</c>.
73 /// </value>
74 bool Run { get; set; }
75
76 /// <summary>
67 /// Is the script suspended? 77 /// Is the script suspended?
68 /// </summary> 78 /// </summary>
69 bool Suspended { get; set; } 79 bool Suspended { get; set; }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
index 47ed6ba..684138f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
@@ -29,42 +29,43 @@ using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using log4net;
32using OpenSim.Region.ScriptEngine.Interfaces; 33using OpenSim.Region.ScriptEngine.Interfaces;
33 34
34namespace OpenSim.Region.ScriptEngine.Shared.Api 35namespace OpenSim.Region.ScriptEngine.Shared.Api
35{ 36{
36 public class ApiManager 37 public class ApiManager
37 { 38 {
39// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
38 private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>(); 41 private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>();
39 42
40 public string[] GetApis() 43 public string[] GetApis()
41 { 44 {
42 if (m_Apis.Count > 0) 45 if (m_Apis.Count <= 0)
43 { 46 {
44 List<string> l = new List<string>(m_Apis.Keys); 47 Assembly a = Assembly.GetExecutingAssembly();
45 return l.ToArray();
46 }
47 48
48 Assembly a = Assembly.GetExecutingAssembly(); 49 Type[] types = a.GetExportedTypes();
49 50
50 Type[] types = a.GetExportedTypes(); 51 foreach (Type t in types)
51
52 foreach (Type t in types)
53 {
54 string name = t.ToString();
55 int idx = name.LastIndexOf('.');
56 if (idx != -1)
57 name = name.Substring(idx+1);
58
59 if (name.EndsWith("_Api"))
60 { 52 {
61 name = name.Substring(0, name.Length - 4); 53 string name = t.ToString();
62 m_Apis[name] = t; 54 int idx = name.LastIndexOf('.');
55 if (idx != -1)
56 name = name.Substring(idx+1);
57
58 if (name.EndsWith("_Api"))
59 {
60 name = name.Substring(0, name.Length - 4);
61 m_Apis[name] = t;
62 }
63 } 63 }
64 } 64 }
65 65
66 List<string> ret = new List<string>(m_Apis.Keys); 66// m_log.DebugFormat("[API MANAGER]: Found {0} apis", m_Apis.Keys.Count);
67 return ret.ToArray(); 67
68 return new List<string>(m_Apis.Keys).ToArray();
68 } 69 }
69 70
70 public IScriptApi CreateApi(string api) 71 public IScriptApi CreateApi(string api)
@@ -76,4 +77,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
76 return ret; 77 return ret;
77 } 78 }
78 } 79 }
79} 80} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
index 489c1c6..b5fa6de 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -59,16 +59,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
59 { 59 {
60 internal IScriptEngine m_ScriptEngine; 60 internal IScriptEngine m_ScriptEngine;
61 internal SceneObjectPart m_host; 61 internal SceneObjectPart m_host;
62 internal uint m_localID; 62 internal TaskInventoryItem m_item;
63 internal UUID m_itemID;
64 internal bool m_CMFunctionsEnabled = false; 63 internal bool m_CMFunctionsEnabled = false;
65 64
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
67 { 66 {
68 m_ScriptEngine = ScriptEngine; 67 m_ScriptEngine = ScriptEngine;
69 m_host = host; 68 m_host = host;
70 m_localID = localID; 69 m_item = item;
71 m_itemID = itemID;
72 70
73 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false)) 71 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
74 m_CMFunctionsEnabled = true; 72 m_CMFunctionsEnabled = true;
@@ -95,7 +93,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
95 public string cmDetectedCountry(int number) 93 public string cmDetectedCountry(int number)
96 { 94 {
97 m_host.AddScriptLPS(1); 95 m_host.AddScriptLPS(1);
98 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 96 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
99 if (detectedParams == null) 97 if (detectedParams == null)
100 return String.Empty; 98 return String.Empty;
101 return detectedParams.Country; 99 return detectedParams.Country;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index a0dc6cd..389980e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -88,8 +88,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
88 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 88 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
89 protected IScriptEngine m_ScriptEngine; 89 protected IScriptEngine m_ScriptEngine;
90 protected SceneObjectPart m_host; 90 protected SceneObjectPart m_host;
91 protected uint m_localID; 91
92 protected UUID m_itemID; 92 /// <summary>
93 /// The item that hosts this script
94 /// </summary>
95 protected TaskInventoryItem m_item;
96
93 protected bool throwErrorOnNotImplemented = true; 97 protected bool throwErrorOnNotImplemented = true;
94 protected AsyncCommandManager AsyncCommands = null; 98 protected AsyncCommandManager AsyncCommands = null;
95 protected float m_ScriptDelayFactor = 1.0f; 99 protected float m_ScriptDelayFactor = 1.0f;
@@ -107,6 +111,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
107 protected IUrlModule m_UrlModule = null; 111 protected IUrlModule m_UrlModule = null;
108 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = 112 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
109 new Dictionary<UUID, UserInfoCacheEntry>(); 113 new Dictionary<UUID, UserInfoCacheEntry>();
114 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
110 115
111 protected Timer m_ShoutSayTimer; 116 protected Timer m_ShoutSayTimer;
112 protected int m_SayShoutCount = 0; 117 protected int m_SayShoutCount = 0;
@@ -133,7 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
133 {"TURNRIGHT", "Turning Right"} 138 {"TURNRIGHT", "Turning Right"}
134 }; 139 };
135 140
136 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 141 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
137 { 142 {
138 m_ShoutSayTimer = new Timer(1000); 143 m_ShoutSayTimer = new Timer(1000);
139 m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed; 144 m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed;
@@ -142,10 +147,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
142 147
143 m_ScriptEngine = ScriptEngine; 148 m_ScriptEngine = ScriptEngine;
144 m_host = host; 149 m_host = host;
145 m_localID = localID; 150 m_item = item;
146 m_itemID = itemID;
147 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); 151 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
148 152
153 LoadLimits(); // read script limits from config.
154
155 m_TransferModule =
156 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
157 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
158
159 AsyncCommands = new AsyncCommandManager(ScriptEngine);
160 }
161
162 /* load configuration items that affect script, object and run-time behavior. */
163 private void LoadLimits()
164 {
149 m_ScriptDelayFactor = 165 m_ScriptDelayFactor =
150 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 166 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
151 m_ScriptDistanceFactor = 167 m_ScriptDistanceFactor =
@@ -158,12 +174,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
158 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); 174 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255);
159 if (m_notecardLineReadCharsMax > 65535) 175 if (m_notecardLineReadCharsMax > 65535)
160 m_notecardLineReadCharsMax = 65535; 176 m_notecardLineReadCharsMax = 65535;
161 177 // load limits for particular subsystems.
162 m_TransferModule = 178 IConfig SMTPConfig;
163 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); 179 if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) {
164 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 180 // there's an smtp config, so load in the snooze time.
165 181 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
166 AsyncCommands = new AsyncCommandManager(ScriptEngine); 182 }
167 } 183 }
168 184
169 public override Object InitializeLifetimeService() 185 public override Object InitializeLifetimeService()
@@ -195,7 +211,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
195 [DebuggerNonUserCode] 211 [DebuggerNonUserCode]
196 public void state(string newState) 212 public void state(string newState)
197 { 213 {
198 m_ScriptEngine.SetState(m_itemID, newState); 214 m_ScriptEngine.SetState(m_item.ItemID, newState);
199 } 215 }
200 216
201 /// <summary> 217 /// <summary>
@@ -206,7 +222,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
206 public void llResetScript() 222 public void llResetScript()
207 { 223 {
208 m_host.AddScriptLPS(1); 224 m_host.AddScriptLPS(1);
209 m_ScriptEngine.ApiResetScript(m_itemID); 225 m_ScriptEngine.ApiResetScript(m_item.ItemID);
210 } 226 }
211 227
212 public void llResetOtherScript(string name) 228 public void llResetOtherScript(string name)
@@ -358,77 +374,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
358 } 374 }
359 } 375 }
360 376
361 protected UUID InventorySelf()
362 {
363 UUID invItemID = new UUID();
364 bool unlock = false;
365 if (!m_host.TaskInventory.IsReadLockedByMe())
366 {
367 m_host.TaskInventory.LockItemsForRead(true);
368 unlock = true;
369 }
370 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
371 {
372 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
373 {
374 invItemID = inv.Key;
375 break;
376 }
377 }
378 if (unlock)
379 {
380 m_host.TaskInventory.LockItemsForRead(false);
381 }
382 return invItemID;
383 }
384
385 protected UUID InventoryKey(string name, int type) 377 protected UUID InventoryKey(string name, int type)
386 { 378 {
387 m_host.AddScriptLPS(1); 379 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
388 m_host.TaskInventory.LockItemsForRead(true);
389
390 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
391 {
392 if (inv.Value.Name == name)
393 {
394 m_host.TaskInventory.LockItemsForRead(false);
395
396 if (inv.Value.Type != type)
397 {
398 return UUID.Zero;
399 }
400
401 return inv.Value.AssetID;
402 }
403 }
404 380
405 m_host.TaskInventory.LockItemsForRead(false); 381 if (item != null && item.Type == type)
406 return UUID.Zero; 382 return item.AssetID;
407 } 383 else
408 384 return UUID.Zero;
409 protected UUID InventoryKey(string name)
410 {
411 m_host.AddScriptLPS(1);
412
413
414 m_host.TaskInventory.LockItemsForRead(true);
415
416 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
417 {
418 if (inv.Value.Name == name)
419 {
420 m_host.TaskInventory.LockItemsForRead(false);
421 return inv.Value.AssetID;
422 }
423 }
424
425 m_host.TaskInventory.LockItemsForRead(false);
426
427
428 return UUID.Zero;
429 } 385 }
430 386
431
432 /// <summary> 387 /// <summary>
433 /// accepts a valid UUID, -or- a name of an inventory item. 388 /// accepts a valid UUID, -or- a name of an inventory item.
434 /// Returns a valid UUID or UUID.Zero if key invalid and item not found 389 /// Returns a valid UUID or UUID.Zero if key invalid and item not found
@@ -438,19 +393,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
438 /// <returns></returns> 393 /// <returns></returns>
439 protected UUID KeyOrName(string k) 394 protected UUID KeyOrName(string k)
440 { 395 {
441 UUID key = UUID.Zero; 396 UUID key;
442 397
443 // if we can parse the string as a key, use it. 398 // if we can parse the string as a key, use it.
444 if (UUID.TryParse(k, out key))
445 {
446 return key;
447 }
448 // else try to locate the name in inventory of object. found returns key, 399 // else try to locate the name in inventory of object. found returns key,
449 // not found returns UUID.Zero which will translate to the default particle texture 400 // not found returns UUID.Zero
450 else 401 if (!UUID.TryParse(k, out key))
451 { 402 {
452 return InventoryKey(k); 403 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k);
404
405 if (item != null)
406 key = item.AssetID;
407 else
408 key = UUID.Zero;
453 } 409 }
410
411 return key;
454 } 412 }
455 413
456 // convert a LSL_Rotation to a Quaternion 414 // convert a LSL_Rotation to a Quaternion
@@ -986,7 +944,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
986 UUID.TryParse(ID, out keyID); 944 UUID.TryParse(ID, out keyID);
987 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 945 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
988 if (wComm != null) 946 if (wComm != null)
989 return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg); 947 return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
990 else 948 else
991 return -1; 949 return -1;
992 } 950 }
@@ -996,7 +954,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
996 m_host.AddScriptLPS(1); 954 m_host.AddScriptLPS(1);
997 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 955 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
998 if (wComm != null) 956 if (wComm != null)
999 wComm.ListenControl(m_itemID, number, active); 957 wComm.ListenControl(m_item.ItemID, number, active);
1000 } 958 }
1001 959
1002 public void llListenRemove(int number) 960 public void llListenRemove(int number)
@@ -1004,7 +962,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1004 m_host.AddScriptLPS(1); 962 m_host.AddScriptLPS(1);
1005 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 963 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1006 if (wComm != null) 964 if (wComm != null)
1007 wComm.ListenRemove(m_itemID, number); 965 wComm.ListenRemove(m_item.ItemID, number);
1008 } 966 }
1009 967
1010 public void llSensor(string name, string id, int type, double range, double arc) 968 public void llSensor(string name, string id, int type, double range, double arc)
@@ -1013,7 +971,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1013 UUID keyID = UUID.Zero; 971 UUID keyID = UUID.Zero;
1014 UUID.TryParse(id, out keyID); 972 UUID.TryParse(id, out keyID);
1015 973
1016 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host); 974 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
1017 } 975 }
1018 976
1019 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) 977 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
@@ -1022,13 +980,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1022 UUID keyID = UUID.Zero; 980 UUID keyID = UUID.Zero;
1023 UUID.TryParse(id, out keyID); 981 UUID.TryParse(id, out keyID);
1024 982
1025 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host); 983 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
1026 } 984 }
1027 985
1028 public void llSensorRemove() 986 public void llSensorRemove()
1029 { 987 {
1030 m_host.AddScriptLPS(1); 988 m_host.AddScriptLPS(1);
1031 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID); 989 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
1032 } 990 }
1033 991
1034 public string resolveName(UUID objecUUID) 992 public string resolveName(UUID objecUUID)
@@ -1069,7 +1027,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1069 public LSL_String llDetectedName(int number) 1027 public LSL_String llDetectedName(int number)
1070 { 1028 {
1071 m_host.AddScriptLPS(1); 1029 m_host.AddScriptLPS(1);
1072 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1030 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1073 if (detectedParams == null) 1031 if (detectedParams == null)
1074 return String.Empty; 1032 return String.Empty;
1075 return detectedParams.Name; 1033 return detectedParams.Name;
@@ -1078,7 +1036,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1078 public LSL_String llDetectedKey(int number) 1036 public LSL_String llDetectedKey(int number)
1079 { 1037 {
1080 m_host.AddScriptLPS(1); 1038 m_host.AddScriptLPS(1);
1081 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1039 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1082 if (detectedParams == null) 1040 if (detectedParams == null)
1083 return String.Empty; 1041 return String.Empty;
1084 return detectedParams.Key.ToString(); 1042 return detectedParams.Key.ToString();
@@ -1087,7 +1045,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1087 public LSL_String llDetectedOwner(int number) 1045 public LSL_String llDetectedOwner(int number)
1088 { 1046 {
1089 m_host.AddScriptLPS(1); 1047 m_host.AddScriptLPS(1);
1090 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1048 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1091 if (detectedParams == null) 1049 if (detectedParams == null)
1092 return String.Empty; 1050 return String.Empty;
1093 return detectedParams.Owner.ToString(); 1051 return detectedParams.Owner.ToString();
@@ -1096,7 +1054,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1096 public LSL_Integer llDetectedType(int number) 1054 public LSL_Integer llDetectedType(int number)
1097 { 1055 {
1098 m_host.AddScriptLPS(1); 1056 m_host.AddScriptLPS(1);
1099 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1057 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1100 if (detectedParams == null) 1058 if (detectedParams == null)
1101 return 0; 1059 return 0;
1102 return new LSL_Integer(detectedParams.Type); 1060 return new LSL_Integer(detectedParams.Type);
@@ -1105,7 +1063,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1105 public LSL_Vector llDetectedPos(int number) 1063 public LSL_Vector llDetectedPos(int number)
1106 { 1064 {
1107 m_host.AddScriptLPS(1); 1065 m_host.AddScriptLPS(1);
1108 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1066 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1109 if (detectedParams == null) 1067 if (detectedParams == null)
1110 return new LSL_Vector(); 1068 return new LSL_Vector();
1111 return detectedParams.Position; 1069 return detectedParams.Position;
@@ -1114,7 +1072,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1114 public LSL_Vector llDetectedVel(int number) 1072 public LSL_Vector llDetectedVel(int number)
1115 { 1073 {
1116 m_host.AddScriptLPS(1); 1074 m_host.AddScriptLPS(1);
1117 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1075 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1118 if (detectedParams == null) 1076 if (detectedParams == null)
1119 return new LSL_Vector(); 1077 return new LSL_Vector();
1120 return detectedParams.Velocity; 1078 return detectedParams.Velocity;
@@ -1123,7 +1081,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1123 public LSL_Vector llDetectedGrab(int number) 1081 public LSL_Vector llDetectedGrab(int number)
1124 { 1082 {
1125 m_host.AddScriptLPS(1); 1083 m_host.AddScriptLPS(1);
1126 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1084 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1127 if (parms == null) 1085 if (parms == null)
1128 return new LSL_Vector(0, 0, 0); 1086 return new LSL_Vector(0, 0, 0);
1129 1087
@@ -1133,7 +1091,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1133 public LSL_Rotation llDetectedRot(int number) 1091 public LSL_Rotation llDetectedRot(int number)
1134 { 1092 {
1135 m_host.AddScriptLPS(1); 1093 m_host.AddScriptLPS(1);
1136 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1094 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1137 if (detectedParams == null) 1095 if (detectedParams == null)
1138 return new LSL_Rotation(); 1096 return new LSL_Rotation();
1139 return detectedParams.Rotation; 1097 return detectedParams.Rotation;
@@ -1142,7 +1100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1142 public LSL_Integer llDetectedGroup(int number) 1100 public LSL_Integer llDetectedGroup(int number)
1143 { 1101 {
1144 m_host.AddScriptLPS(1); 1102 m_host.AddScriptLPS(1);
1145 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1103 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1146 if (detectedParams == null) 1104 if (detectedParams == null)
1147 return new LSL_Integer(0); 1105 return new LSL_Integer(0);
1148 if (m_host.GroupID == detectedParams.Group) 1106 if (m_host.GroupID == detectedParams.Group)
@@ -1153,7 +1111,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1153 public LSL_Integer llDetectedLinkNumber(int number) 1111 public LSL_Integer llDetectedLinkNumber(int number)
1154 { 1112 {
1155 m_host.AddScriptLPS(1); 1113 m_host.AddScriptLPS(1);
1156 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1114 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1157 if (parms == null) 1115 if (parms == null)
1158 return new LSL_Integer(0); 1116 return new LSL_Integer(0);
1159 1117
@@ -1166,7 +1124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1166 public LSL_Vector llDetectedTouchBinormal(int index) 1124 public LSL_Vector llDetectedTouchBinormal(int index)
1167 { 1125 {
1168 m_host.AddScriptLPS(1); 1126 m_host.AddScriptLPS(1);
1169 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1127 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1170 if (detectedParams == null) 1128 if (detectedParams == null)
1171 return new LSL_Vector(); 1129 return new LSL_Vector();
1172 return detectedParams.TouchBinormal; 1130 return detectedParams.TouchBinormal;
@@ -1178,7 +1136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 public LSL_Integer llDetectedTouchFace(int index) 1136 public LSL_Integer llDetectedTouchFace(int index)
1179 { 1137 {
1180 m_host.AddScriptLPS(1); 1138 m_host.AddScriptLPS(1);
1181 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1139 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1182 if (detectedParams == null) 1140 if (detectedParams == null)
1183 return new LSL_Integer(-1); 1141 return new LSL_Integer(-1);
1184 return new LSL_Integer(detectedParams.TouchFace); 1142 return new LSL_Integer(detectedParams.TouchFace);
@@ -1190,7 +1148,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1190 public LSL_Vector llDetectedTouchNormal(int index) 1148 public LSL_Vector llDetectedTouchNormal(int index)
1191 { 1149 {
1192 m_host.AddScriptLPS(1); 1150 m_host.AddScriptLPS(1);
1193 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1151 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1194 if (detectedParams == null) 1152 if (detectedParams == null)
1195 return new LSL_Vector(); 1153 return new LSL_Vector();
1196 return detectedParams.TouchNormal; 1154 return detectedParams.TouchNormal;
@@ -1202,7 +1160,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 public LSL_Vector llDetectedTouchPos(int index) 1160 public LSL_Vector llDetectedTouchPos(int index)
1203 { 1161 {
1204 m_host.AddScriptLPS(1); 1162 m_host.AddScriptLPS(1);
1205 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1163 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1206 if (detectedParams == null) 1164 if (detectedParams == null)
1207 return new LSL_Vector(); 1165 return new LSL_Vector();
1208 return detectedParams.TouchPos; 1166 return detectedParams.TouchPos;
@@ -1214,7 +1172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1214 public LSL_Vector llDetectedTouchST(int index) 1172 public LSL_Vector llDetectedTouchST(int index)
1215 { 1173 {
1216 m_host.AddScriptLPS(1); 1174 m_host.AddScriptLPS(1);
1217 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1175 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1218 if (detectedParams == null) 1176 if (detectedParams == null)
1219 return new LSL_Vector(-1.0, -1.0, 0.0); 1177 return new LSL_Vector(-1.0, -1.0, 0.0);
1220 return detectedParams.TouchST; 1178 return detectedParams.TouchST;
@@ -1226,7 +1184,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1226 public LSL_Vector llDetectedTouchUV(int index) 1184 public LSL_Vector llDetectedTouchUV(int index)
1227 { 1185 {
1228 m_host.AddScriptLPS(1); 1186 m_host.AddScriptLPS(1);
1229 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1187 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1230 if (detectedParams == null) 1188 if (detectedParams == null)
1231 return new LSL_Vector(-1.0, -1.0, 0.0); 1189 return new LSL_Vector(-1.0, -1.0, 0.0);
1232 return detectedParams.TouchUV; 1190 return detectedParams.TouchUV;
@@ -1929,12 +1887,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1929 1887
1930 return rgb; 1888 return rgb;
1931 } 1889 }
1890
1932 if (face >= 0 && face < GetNumberOfSides(part)) 1891 if (face >= 0 && face < GetNumberOfSides(part))
1933 { 1892 {
1934 texcolor = tex.GetFace((uint)face).RGBA; 1893 texcolor = tex.GetFace((uint)face).RGBA;
1935 rgb.x = texcolor.R; 1894 rgb.x = texcolor.R;
1936 rgb.y = texcolor.G; 1895 rgb.y = texcolor.G;
1937 rgb.z = texcolor.B; 1896 rgb.z = texcolor.B;
1897
1938 return rgb; 1898 return rgb;
1939 } 1899 }
1940 else 1900 else
@@ -2975,20 +2935,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2975 2935
2976 public LSL_Integer llGiveMoney(string destination, int amount) 2936 public LSL_Integer llGiveMoney(string destination, int amount)
2977 { 2937 {
2978 UUID invItemID=InventorySelf();
2979 if (invItemID == UUID.Zero)
2980 return 0;
2981
2982 m_host.AddScriptLPS(1); 2938 m_host.AddScriptLPS(1);
2983 2939
2984 m_host.TaskInventory.LockItemsForRead(true); 2940 if (m_item.PermsGranter == UUID.Zero)
2985 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2986 m_host.TaskInventory.LockItemsForRead(false);
2987
2988 if (item.PermsGranter == UUID.Zero)
2989 return 0; 2941 return 0;
2990 2942
2991 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2943 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
2992 { 2944 {
2993 LSLError("No permissions to give money"); 2945 LSLError("No permissions to give money");
2994 return 0; 2946 return 0;
@@ -3176,11 +3128,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3176 sec = m_MinTimerInterval; 3128 sec = m_MinTimerInterval;
3177 m_host.AddScriptLPS(1); 3129 m_host.AddScriptLPS(1);
3178 // Setting timer repeat 3130 // Setting timer repeat
3179 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3131 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3180 } 3132 }
3181 3133
3182 public virtual void llSleep(double sec) 3134 public virtual void llSleep(double sec)
3183 { 3135 {
3136// m_log.Info("llSleep snoozing " + sec + "s.");
3184 m_host.AddScriptLPS(1); 3137 m_host.AddScriptLPS(1);
3185 Thread.Sleep((int)(sec * 1000)); 3138 Thread.Sleep((int)(sec * 1000));
3186 } 3139 }
@@ -3239,29 +3192,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3239 3192
3240 public void llTakeControls(int controls, int accept, int pass_on) 3193 public void llTakeControls(int controls, int accept, int pass_on)
3241 { 3194 {
3242 TaskInventoryItem item; 3195 if (m_item.PermsGranter != UUID.Zero)
3243
3244 m_host.TaskInventory.LockItemsForRead(true);
3245 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3246 {
3247 m_host.TaskInventory.LockItemsForRead(false);
3248 return;
3249 }
3250 else
3251 {
3252 item = m_host.TaskInventory[InventorySelf()];
3253 }
3254 m_host.TaskInventory.LockItemsForRead(false);
3255
3256 if (item.PermsGranter != UUID.Zero)
3257 { 3196 {
3258 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3197 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3259 3198
3260 if (presence != null) 3199 if (presence != null)
3261 { 3200 {
3262 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3201 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3263 { 3202 {
3264 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3203 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3265 } 3204 }
3266 } 3205 }
3267 } 3206 }
@@ -3271,38 +3210,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3271 3210
3272 public void llReleaseControls() 3211 public void llReleaseControls()
3273 { 3212 {
3274 TaskInventoryItem item;
3275
3276 m_host.TaskInventory.LockItemsForRead(true);
3277 lock (m_host.TaskInventory)
3278 {
3279
3280 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3281 {
3282 m_host.TaskInventory.LockItemsForRead(false);
3283 return;
3284 }
3285 else
3286 {
3287 item = m_host.TaskInventory[InventorySelf()];
3288 }
3289 }
3290 m_host.TaskInventory.LockItemsForRead(false);
3291
3292 m_host.AddScriptLPS(1); 3213 m_host.AddScriptLPS(1);
3293 3214
3294 if (item.PermsGranter != UUID.Zero) 3215 if (m_item.PermsGranter != UUID.Zero)
3295 { 3216 {
3296 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3217 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3297 3218
3298 if (presence != null) 3219 if (presence != null)
3299 { 3220 {
3300 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3221 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3301 { 3222 {
3302 // Unregister controls from Presence 3223 // Unregister controls from Presence
3303 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3224 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3304 // Remove Take Control permission. 3225 // Remove Take Control permission.
3305 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3226 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3306 } 3227 }
3307 } 3228 }
3308 } 3229 }
@@ -3315,86 +3236,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3315 m_UrlModule.ReleaseURL(url); 3236 m_UrlModule.ReleaseURL(url);
3316 } 3237 }
3317 3238
3318 public void llAttachToAvatar(int attachment) 3239 /// <summary>
3240 /// Attach the object containing this script to the avatar that owns it.
3241 /// </summary>
3242 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3243 /// <returns>true if the attach suceeded, false if it did not</returns>
3244 public bool AttachToAvatar(int attachmentPoint)
3319 { 3245 {
3320 m_host.AddScriptLPS(1); 3246 SceneObjectGroup grp = m_host.ParentGroup;
3321 3247 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3322 TaskInventoryItem item;
3323 3248
3324 m_host.TaskInventory.LockItemsForRead(true); 3249 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3325 3250
3326 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3251 if (attachmentsModule != null)
3327 { 3252 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3328 m_host.TaskInventory.LockItemsForRead(false);
3329 return;
3330 }
3331 else 3253 else
3332 { 3254 return false;
3333 item = m_host.TaskInventory[InventorySelf()]; 3255 }
3334 }
3335
3336 m_host.TaskInventory.LockItemsForRead(false);
3337 3256
3338 if (item.PermsGranter != m_host.OwnerID) 3257 /// <summary>
3339 return; 3258 /// Detach the object containing this script from the avatar it is attached to.
3259 /// </summary>
3260 /// <remarks>
3261 /// Nothing happens if the object is not attached.
3262 /// </remarks>
3263 public void DetachFromAvatar()
3264 {
3265 Util.FireAndForget(DetachWrapper, m_host);
3266 }
3340 3267
3341 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3268 private void DetachWrapper(object o)
3342 { 3269 {
3343 SceneObjectGroup grp = m_host.ParentGroup; 3270 SceneObjectPart host = (SceneObjectPart)o;
3344 3271
3345 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3272 SceneObjectGroup grp = host.ParentGroup;
3273 UUID itemID = grp.FromItemID;
3274 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3346 3275
3347 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3276 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3348 if (attachmentsModule != null) 3277 if (attachmentsModule != null)
3349 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true); 3278 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3350 }
3351 } 3279 }
3352 3280
3353 public void llDetachFromAvatar() 3281 public void llAttachToAvatar(int attachmentPoint)
3354 { 3282 {
3355 m_host.AddScriptLPS(1); 3283 m_host.AddScriptLPS(1);
3356 3284
3357 if (m_host.ParentGroup.AttachmentPoint == 0) 3285 if (m_item.PermsGranter != m_host.OwnerID)
3358 return; 3286 return;
3359 3287
3360 TaskInventoryItem item; 3288 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3289 AttachToAvatar(attachmentPoint);
3290 }
3361 3291
3362 m_host.TaskInventory.LockItemsForRead(true); 3292 public void llDetachFromAvatar()
3293 {
3294 m_host.AddScriptLPS(1);
3363 3295
3364 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3296 if (m_host.ParentGroup.AttachmentPoint == 0)
3365 {
3366 m_host.TaskInventory.LockItemsForRead(false);
3367 return; 3297 return;
3368 }
3369 else
3370 {
3371 item = m_host.TaskInventory[InventorySelf()];
3372 }
3373 m_host.TaskInventory.LockItemsForRead(false);
3374
3375 3298
3376 if (item.PermsGranter != m_host.OwnerID) 3299 if (m_item.PermsGranter != m_host.OwnerID)
3377 return; 3300 return;
3378 3301
3379 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3302 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3380 { 3303 DetachFromAvatar();
3381 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3382 if (attachmentsModule != null)
3383 Util.FireAndForget(DetachWrapper, m_host);
3384 }
3385 }
3386
3387 private void DetachWrapper(object o)
3388 {
3389 SceneObjectPart host = (SceneObjectPart)o;
3390
3391 SceneObjectGroup grp = host.ParentGroup;
3392 UUID itemID = grp.FromItemID;
3393 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3394
3395 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3396 if (attachmentsModule != null)
3397 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3398 } 3304 }
3399 3305
3400 public void llTakeCamera(string avatar) 3306 public void llTakeCamera(string avatar)
@@ -3515,7 +3421,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3515 } 3421 }
3516 3422
3517 emailModule.SendEmail(m_host.UUID, address, subject, message); 3423 emailModule.SendEmail(m_host.UUID, address, subject, message);
3518 ScriptSleep(15000); 3424 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3519 } 3425 }
3520 3426
3521 public void llGetNextEmail(string address, string subject) 3427 public void llGetNextEmail(string address, string subject)
@@ -3552,6 +3458,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3552 return m_host.UUID.ToString(); 3458 return m_host.UUID.ToString();
3553 } 3459 }
3554 3460
3461 public LSL_Key llGenerateKey()
3462 {
3463 m_host.AddScriptLPS(1);
3464 return UUID.Random().ToString();
3465 }
3466
3555 public void llSetBuoyancy(double buoyancy) 3467 public void llSetBuoyancy(double buoyancy)
3556 { 3468 {
3557 m_host.AddScriptLPS(1); 3469 m_host.AddScriptLPS(1);
@@ -3598,7 +3510,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3598 m_host.AddScriptLPS(1); 3510 m_host.AddScriptLPS(1);
3599 try 3511 try
3600 { 3512 {
3601 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3513 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3602 } 3514 }
3603 catch (NotImplementedException) 3515 catch (NotImplementedException)
3604 { 3516 {
@@ -3651,29 +3563,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3651 { 3563 {
3652 m_host.AddScriptLPS(1); 3564 m_host.AddScriptLPS(1);
3653 3565
3654 UUID invItemID = InventorySelf(); 3566 if (m_item.PermsGranter == UUID.Zero)
3655 if (invItemID == UUID.Zero)
3656 return;
3657
3658 TaskInventoryItem item;
3659
3660 m_host.TaskInventory.LockItemsForRead(true);
3661 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3662 {
3663 m_host.TaskInventory.LockItemsForRead(false);
3664 return;
3665 }
3666 else
3667 {
3668 item = m_host.TaskInventory[InventorySelf()];
3669 }
3670 m_host.TaskInventory.LockItemsForRead(false);
3671 if (item.PermsGranter == UUID.Zero)
3672 return; 3567 return;
3673 3568
3674 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3569 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3675 { 3570 {
3676 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3571 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3677 3572
3678 if (presence != null) 3573 if (presence != null)
3679 { 3574 {
@@ -3691,41 +3586,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3691 { 3586 {
3692 m_host.AddScriptLPS(1); 3587 m_host.AddScriptLPS(1);
3693 3588
3694 UUID invItemID=InventorySelf(); 3589 if (m_item.PermsGranter == UUID.Zero)
3695 if (invItemID == UUID.Zero)
3696 return;
3697
3698 TaskInventoryItem item;
3699
3700 m_host.TaskInventory.LockItemsForRead(true);
3701 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3702 {
3703 m_host.TaskInventory.LockItemsForRead(false);
3704 return;
3705 }
3706 else
3707 {
3708 item = m_host.TaskInventory[InventorySelf()];
3709 }
3710 m_host.TaskInventory.LockItemsForRead(false);
3711
3712
3713 if (item.PermsGranter == UUID.Zero)
3714 return; 3590 return;
3715 3591
3716 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3592 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3717 { 3593 {
3718 UUID animID = new UUID(); 3594 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3719
3720 if (!UUID.TryParse(anim, out animID))
3721 {
3722 animID=InventoryKey(anim);
3723 }
3724
3725 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3726 3595
3727 if (presence != null) 3596 if (presence != null)
3728 { 3597 {
3598 UUID animID = KeyOrName(anim);
3599
3729 if (animID == UUID.Zero) 3600 if (animID == UUID.Zero)
3730 presence.Animator.RemoveAnimation(anim); 3601 presence.Animator.RemoveAnimation(anim);
3731 else 3602 else
@@ -3758,44 +3629,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3758 public LSL_Integer llGetStartParameter() 3629 public LSL_Integer llGetStartParameter()
3759 { 3630 {
3760 m_host.AddScriptLPS(1); 3631 m_host.AddScriptLPS(1);
3761 return m_ScriptEngine.GetStartParameter(m_itemID); 3632 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3762 } 3633 }
3763 3634
3764 public void llRequestPermissions(string agent, int perm) 3635 public void llRequestPermissions(string agent, int perm)
3765 { 3636 {
3766 UUID agentID = new UUID(); 3637 UUID agentID;
3767 3638
3768 if (!UUID.TryParse(agent, out agentID)) 3639 if (!UUID.TryParse(agent, out agentID))
3769 return; 3640 return;
3770 3641
3771 UUID invItemID = InventorySelf();
3772
3773 if (invItemID == UUID.Zero)
3774 return; // Not in a prim? How??
3775
3776 TaskInventoryItem item;
3777
3778
3779 m_host.TaskInventory.LockItemsForRead(true);
3780 if (!m_host.TaskInventory.ContainsKey(invItemID))
3781 {
3782 m_host.TaskInventory.LockItemsForRead(false);
3783 return;
3784 }
3785 else
3786 {
3787 item = m_host.TaskInventory[invItemID];
3788 }
3789 m_host.TaskInventory.LockItemsForRead(false);
3790
3791 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3642 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3792 { 3643 {
3793 llReleaseControls(); 3644 llReleaseControls();
3794 3645
3795 item.PermsGranter = UUID.Zero; 3646 m_item.PermsGranter = UUID.Zero;
3796 item.PermsMask = 0; 3647 m_item.PermsMask = 0;
3797 3648
3798 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3649 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3799 "run_time_permissions", new Object[] { 3650 "run_time_permissions", new Object[] {
3800 new LSL_Integer(0) }, 3651 new LSL_Integer(0) },
3801 new DetectParams[0])); 3652 new DetectParams[0]));
@@ -3803,7 +3654,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3803 return; 3654 return;
3804 } 3655 }
3805 3656
3806 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3657 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3807 llReleaseControls(); 3658 llReleaseControls();
3808 3659
3809 m_host.AddScriptLPS(1); 3660 m_host.AddScriptLPS(1);
@@ -3820,11 +3671,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3820 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3671 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3821 { 3672 {
3822 m_host.TaskInventory.LockItemsForWrite(true); 3673 m_host.TaskInventory.LockItemsForWrite(true);
3823 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3674 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3824 m_host.TaskInventory[invItemID].PermsMask = perm; 3675 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3825 m_host.TaskInventory.LockItemsForWrite(false); 3676 m_host.TaskInventory.LockItemsForWrite(false);
3826 3677
3827 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3678 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3828 "run_time_permissions", new Object[] { 3679 "run_time_permissions", new Object[] {
3829 new LSL_Integer(perm) }, 3680 new LSL_Integer(perm) },
3830 new DetectParams[0])); 3681 new DetectParams[0]));
@@ -3859,11 +3710,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3859 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3710 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3860 { 3711 {
3861 m_host.TaskInventory.LockItemsForWrite(true); 3712 m_host.TaskInventory.LockItemsForWrite(true);
3862 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3713 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3863 m_host.TaskInventory[invItemID].PermsMask = perm; 3714 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3864 m_host.TaskInventory.LockItemsForWrite(false); 3715 m_host.TaskInventory.LockItemsForWrite(false);
3865 3716
3866 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3717 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3867 "run_time_permissions", new Object[] { 3718 "run_time_permissions", new Object[] {
3868 new LSL_Integer(perm) }, 3719 new LSL_Integer(perm) },
3869 new DetectParams[0])); 3720 new DetectParams[0]));
@@ -3874,9 +3725,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3874 } 3725 }
3875 3726
3876 ScenePresence presence = World.GetScenePresence(agentID); 3727 ScenePresence presence = World.GetScenePresence(agentID);
3877
3878 if (presence != null) 3728 if (presence != null)
3879 { 3729 {
3730 // If permissions are being requested from an NPC and were not implicitly granted above then
3731 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3732 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3733 if (npcModule != null && npcModule.IsNPC(agentID, World))
3734 {
3735 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3736 {
3737 lock (m_host.TaskInventory)
3738 {
3739 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3740 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3741 }
3742
3743 m_ScriptEngine.PostScriptEvent(
3744 m_item.ItemID,
3745 new EventParams(
3746 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3747 }
3748
3749 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3750 // the question!
3751 return;
3752 }
3753
3880 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3754 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3881 if (ownerName == String.Empty) 3755 if (ownerName == String.Empty)
3882 ownerName = "(hippos)"; 3756 ownerName = "(hippos)";
@@ -3884,8 +3758,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3884 if (!m_waitingForScriptAnswer) 3758 if (!m_waitingForScriptAnswer)
3885 { 3759 {
3886 m_host.TaskInventory.LockItemsForWrite(true); 3760 m_host.TaskInventory.LockItemsForWrite(true);
3887 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3761 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3888 m_host.TaskInventory[invItemID].PermsMask = 0; 3762 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3889 m_host.TaskInventory.LockItemsForWrite(false); 3763 m_host.TaskInventory.LockItemsForWrite(false);
3890 3764
3891 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3765 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3893,16 +3767,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3893 } 3767 }
3894 3768
3895 presence.ControllingClient.SendScriptQuestion( 3769 presence.ControllingClient.SendScriptQuestion(
3896 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3770 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3897 3771
3898 return; 3772 return;
3899 } 3773 }
3900 3774
3901 // Requested agent is not in range, refuse perms 3775 // Requested agent is not in range, refuse perms
3902 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3776 m_ScriptEngine.PostScriptEvent(
3903 "run_time_permissions", new Object[] { 3777 m_item.ItemID,
3904 new LSL_Integer(0) }, 3778 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3905 new DetectParams[0]));
3906 } 3779 }
3907 3780
3908 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3781 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3910,24 +3783,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3910 if (taskID != m_host.UUID) 3783 if (taskID != m_host.UUID)
3911 return; 3784 return;
3912 3785
3913 UUID invItemID = InventorySelf(); 3786 client.OnScriptAnswer -= handleScriptAnswer;
3914 3787 m_waitingForScriptAnswer = false;
3915 if (invItemID == UUID.Zero)
3916 return;
3917
3918 client.OnScriptAnswer-=handleScriptAnswer;
3919 m_waitingForScriptAnswer=false;
3920 3788
3921 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3789 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3922 llReleaseControls(); 3790 llReleaseControls();
3923 3791
3924
3925 m_host.TaskInventory.LockItemsForWrite(true); 3792 m_host.TaskInventory.LockItemsForWrite(true);
3926 m_host.TaskInventory[invItemID].PermsMask = answer; 3793 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3927 m_host.TaskInventory.LockItemsForWrite(false); 3794 m_host.TaskInventory.LockItemsForWrite(false);
3928 3795
3929 3796 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3930 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3931 "run_time_permissions", new Object[] { 3797 "run_time_permissions", new Object[] {
3932 new LSL_Integer(answer) }, 3798 new LSL_Integer(answer) },
3933 new DetectParams[0])); 3799 new DetectParams[0]));
@@ -3937,41 +3803,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3937 { 3803 {
3938 m_host.AddScriptLPS(1); 3804 m_host.AddScriptLPS(1);
3939 3805
3940 m_host.TaskInventory.LockItemsForRead(true); 3806 return m_item.PermsGranter.ToString();
3941
3942 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3943 {
3944 if (item.Type == 10 && item.ItemID == m_itemID)
3945 {
3946 m_host.TaskInventory.LockItemsForRead(false);
3947 return item.PermsGranter.ToString();
3948 }
3949 }
3950 m_host.TaskInventory.LockItemsForRead(false);
3951
3952 return UUID.Zero.ToString();
3953 } 3807 }
3954 3808
3955 public LSL_Integer llGetPermissions() 3809 public LSL_Integer llGetPermissions()
3956 { 3810 {
3957 m_host.AddScriptLPS(1); 3811 m_host.AddScriptLPS(1);
3958 3812
3959 m_host.TaskInventory.LockItemsForRead(true); 3813 int perms = m_item.PermsMask;
3960 3814
3961 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3815 if (m_automaticLinkPermission)
3962 { 3816 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3963 if (item.Type == 10 && item.ItemID == m_itemID)
3964 {
3965 int perms = item.PermsMask;
3966 if (m_automaticLinkPermission)
3967 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3968 m_host.TaskInventory.LockItemsForRead(false);
3969 return perms;
3970 }
3971 }
3972 m_host.TaskInventory.LockItemsForRead(false);
3973 3817
3974 return 0; 3818 return perms;
3975 } 3819 }
3976 3820
3977 public LSL_Integer llGetLinkNumber() 3821 public LSL_Integer llGetLinkNumber()
@@ -4009,18 +3853,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4009 public void llCreateLink(string target, int parent) 3853 public void llCreateLink(string target, int parent)
4010 { 3854 {
4011 m_host.AddScriptLPS(1); 3855 m_host.AddScriptLPS(1);
4012 UUID invItemID = InventorySelf(); 3856
4013 UUID targetID; 3857 UUID targetID;
4014 3858
4015 if (!UUID.TryParse(target, out targetID)) 3859 if (!UUID.TryParse(target, out targetID))
4016 return; 3860 return;
4017 3861
4018 TaskInventoryItem item; 3862 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4019 m_host.TaskInventory.LockItemsForRead(true);
4020 item = m_host.TaskInventory[invItemID];
4021 m_host.TaskInventory.LockItemsForRead(false);
4022
4023 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4024 && !m_automaticLinkPermission) 3863 && !m_automaticLinkPermission)
4025 { 3864 {
4026 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3865 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4028,7 +3867,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4028 } 3867 }
4029 3868
4030 IClientAPI client = null; 3869 IClientAPI client = null;
4031 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3870 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4032 if (sp != null) 3871 if (sp != null)
4033 client = sp.ControllingClient; 3872 client = sp.ControllingClient;
4034 3873
@@ -4074,18 +3913,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4074 public void llBreakLink(int linknum) 3913 public void llBreakLink(int linknum)
4075 { 3914 {
4076 m_host.AddScriptLPS(1); 3915 m_host.AddScriptLPS(1);
4077 UUID invItemID = InventorySelf();
4078 3916
4079 m_host.TaskInventory.LockItemsForRead(true); 3917 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4080 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3918 && !m_automaticLinkPermission)
4081 && !m_automaticLinkPermission) 3919 {
4082 { 3920 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4083 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3921 return;
4084 m_host.TaskInventory.LockItemsForRead(false); 3922 }
4085 return; 3923
4086 }
4087 m_host.TaskInventory.LockItemsForRead(false);
4088
4089 if (linknum < ScriptBaseClass.LINK_THIS) 3924 if (linknum < ScriptBaseClass.LINK_THIS)
4090 return; 3925 return;
4091 3926
@@ -4184,12 +4019,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4184 { 4019 {
4185 m_host.AddScriptLPS(1); 4020 m_host.AddScriptLPS(1);
4186 4021
4187 UUID invItemID = InventorySelf(); 4022 TaskInventoryItem item = m_item;
4188
4189 TaskInventoryItem item;
4190 m_host.TaskInventory.LockItemsForRead(true);
4191 item = m_host.TaskInventory[invItemID];
4192 m_host.TaskInventory.LockItemsForRead(false);
4193 4023
4194 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4024 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4195 && !m_automaticLinkPermission) 4025 && !m_automaticLinkPermission)
@@ -4500,7 +4330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4500 { 4330 {
4501 if (item.Name == name) 4331 if (item.Name == name)
4502 { 4332 {
4503 if (item.ItemID == m_itemID) 4333 if (item.ItemID == m_item.ItemID)
4504 throw new ScriptDeleteException(); 4334 throw new ScriptDeleteException();
4505 else 4335 else
4506 m_host.Inventory.RemoveInventoryItem(item.ItemID); 4336 m_host.Inventory.RemoveInventoryItem(item.ItemID);
@@ -4634,8 +4464,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4634 UUID rq = UUID.Random(); 4464 UUID rq = UUID.Random();
4635 4465
4636 UUID tid = AsyncCommands. 4466 UUID tid = AsyncCommands.
4637 DataserverPlugin.RegisterRequest(m_localID, 4467 DataserverPlugin.RegisterRequest(m_host.LocalId,
4638 m_itemID, rq.ToString()); 4468 m_item.ItemID, rq.ToString());
4639 4469
4640 AsyncCommands. 4470 AsyncCommands.
4641 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4471 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4662,8 +4492,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4662 if (item.Type == 3 && item.Name == name) 4492 if (item.Type == 3 && item.Name == name)
4663 { 4493 {
4664 UUID tid = AsyncCommands. 4494 UUID tid = AsyncCommands.
4665 DataserverPlugin.RegisterRequest(m_localID, 4495 DataserverPlugin.RegisterRequest(m_host.LocalId,
4666 m_itemID, item.AssetID.ToString()); 4496 m_item.ItemID, item.AssetID.ToString());
4667 4497
4668 Vector3 region = new Vector3( 4498 Vector3 region = new Vector3(
4669 World.RegionInfo.RegionLocX * Constants.RegionSize, 4499 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -5136,22 +4966,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5136 4966
5137 public LSL_String llGetScriptName() 4967 public LSL_String llGetScriptName()
5138 { 4968 {
5139 string result = String.Empty;
5140
5141 m_host.AddScriptLPS(1); 4969 m_host.AddScriptLPS(1);
5142 4970
5143 m_host.TaskInventory.LockItemsForRead(true); 4971 return m_item.Name != null ? m_item.Name : String.Empty;
5144 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
5145 {
5146 if (item.Type == 10 && item.ItemID == m_itemID)
5147 {
5148 result = item.Name!=null?item.Name:String.Empty;
5149 break;
5150 }
5151 }
5152 m_host.TaskInventory.LockItemsForRead(false);
5153
5154 return result;
5155 } 4972 }
5156 4973
5157 public LSL_Integer llGetLinkNumberOfSides(int link) 4974 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -6285,7 +6102,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6285 } 6102 }
6286 } 6103 }
6287 } 6104 }
6288 List<UUID> presenceIds = new List<UUID>();
6289 6105
6290 World.ForEachRootScenePresence( 6106 World.ForEachRootScenePresence(
6291 delegate (ScenePresence ssp) 6107 delegate (ScenePresence ssp)
@@ -6436,7 +6252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6436 if (m_host.OwnerID == land.LandData.OwnerID) 6252 if (m_host.OwnerID == land.LandData.OwnerID)
6437 { 6253 {
6438 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6254 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6439 presence.TeleportWithMomentum(pos); 6255 presence.TeleportWithMomentum(pos, null);
6440 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6256 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6441 } 6257 }
6442 } 6258 }
@@ -7383,14 +7199,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7383 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7199 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7384 if (xmlrpcMod.IsEnabled()) 7200 if (xmlrpcMod.IsEnabled())
7385 { 7201 {
7386 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7202 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7387 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7203 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7388 if (xmlRpcRouter != null) 7204 if (xmlRpcRouter != null)
7389 { 7205 {
7390 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7206 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7391 7207
7392 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7208 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7393 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7209 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7394 xmlrpcMod.Port.ToString())); 7210 xmlrpcMod.Port.ToString()));
7395 } 7211 }
7396 object[] resobj = new object[] 7212 object[] resobj = new object[]
@@ -7402,7 +7218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7402 new LSL_Integer(0), 7218 new LSL_Integer(0),
7403 new LSL_String(String.Empty) 7219 new LSL_String(String.Empty)
7404 }; 7220 };
7405 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7221 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7406 new DetectParams[0])); 7222 new DetectParams[0]));
7407 } 7223 }
7408 ScriptSleep(1000); 7224 ScriptSleep(1000);
@@ -7413,7 +7229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7413 m_host.AddScriptLPS(1); 7229 m_host.AddScriptLPS(1);
7414 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7230 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7415 ScriptSleep(3000); 7231 ScriptSleep(3000);
7416 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7232 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7417 } 7233 }
7418 7234
7419 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7235 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8413,7 +8229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8413 return; 8229 return;
8414 face = (int)rules.GetLSLIntegerItem(idx++); 8230 face = (int)rules.GetLSLIntegerItem(idx++);
8415 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8231 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8416 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8232 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8417 8233
8418 SetShiny(part, face, shiny, bump); 8234 SetShiny(part, face, shiny, bump);
8419 8235
@@ -10173,7 +9989,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10173 public LSL_String llGetSimulatorHostname() 9989 public LSL_String llGetSimulatorHostname()
10174 { 9990 {
10175 m_host.AddScriptLPS(1); 9991 m_host.AddScriptLPS(1);
10176 return System.Environment.MachineName; 9992 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
9993 return UrlModule.ExternalHostNameForLSL;
10177 } 9994 }
10178 9995
10179 // <summary> 9996 // <summary>
@@ -10512,13 +10329,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10512 { 10329 {
10513 m_host.AddScriptLPS(1); 10330 m_host.AddScriptLPS(1);
10514 if (m_UrlModule != null) 10331 if (m_UrlModule != null)
10515 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10332 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10516 return UUID.Zero.ToString(); 10333 return UUID.Zero.ToString();
10517 } 10334 }
10518 10335
10519 public LSL_String llRequestSimulatorData(string simulator, int data) 10336 public LSL_String llRequestSimulatorData(string simulator, int data)
10520 { 10337 {
10521 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 10338 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10522 10339
10523 try 10340 try
10524 { 10341 {
@@ -10528,7 +10345,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10528 10345
10529 GridRegion info; 10346 GridRegion info;
10530 10347
10531 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 10348 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
10349
10532 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 10350 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10533 else 10351 else
10534 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 10352 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10541,10 +10359,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10541 ScriptSleep(1000); 10359 ScriptSleep(1000);
10542 return UUID.Zero.ToString(); 10360 return UUID.Zero.ToString();
10543 } 10361 }
10544 reply = new LSL_Vector( 10362 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10545 info.RegionLocX, 10363 {
10546 info.RegionLocY, 10364 //Hypergrid Region co-ordinates
10547 0).ToString(); 10365 uint rx = 0, ry = 0;
10366 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
10367
10368 reply = new LSL_Vector(
10369 rx,
10370 ry,
10371 0).ToString();
10372 }
10373 else
10374 {
10375 //Local-cooridnates
10376 reply = new LSL_Vector(
10377 info.RegionLocX,
10378 info.RegionLocY,
10379 0).ToString();
10380 }
10548 break; 10381 break;
10549 case ScriptBaseClass.DATA_SIM_STATUS: 10382 case ScriptBaseClass.DATA_SIM_STATUS:
10550 if (info != null) 10383 if (info != null)
@@ -10580,7 +10413,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10580 UUID rq = UUID.Random(); 10413 UUID rq = UUID.Random();
10581 10414
10582 UUID tid = AsyncCommands. 10415 UUID tid = AsyncCommands.
10583 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 10416 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10584 10417
10585 AsyncCommands. 10418 AsyncCommands.
10586 DataserverPlugin.DataserverReply(rq.ToString(), reply); 10419 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10599,7 +10432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10599 m_host.AddScriptLPS(1); 10432 m_host.AddScriptLPS(1);
10600 10433
10601 if (m_UrlModule != null) 10434 if (m_UrlModule != null)
10602 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10435 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10603 return UUID.Zero.ToString(); 10436 return UUID.Zero.ToString();
10604 } 10437 }
10605 10438
@@ -10635,7 +10468,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10635 // child agents have a mass of 1.0 10468 // child agents have a mass of 1.0
10636 return 1; 10469 return 1;
10637 else 10470 else
10638 return avatar.GetMass(); 10471 return (double)avatar.GetMass();
10639 } 10472 }
10640 catch (KeyNotFoundException) 10473 catch (KeyNotFoundException)
10641 { 10474 {
@@ -11078,32 +10911,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11078 public LSL_Vector llGetCameraPos() 10911 public LSL_Vector llGetCameraPos()
11079 { 10912 {
11080 m_host.AddScriptLPS(1); 10913 m_host.AddScriptLPS(1);
11081 UUID invItemID = InventorySelf();
11082 10914
11083 if (invItemID == UUID.Zero) 10915 if (m_item.PermsGranter == UUID.Zero)
11084 return new LSL_Vector(); 10916 return new LSL_Vector();
11085 10917
11086 m_host.TaskInventory.LockItemsForRead(true); 10918 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11087
11088 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
11089
11090// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
11091 if (agentID == UUID.Zero)
11092 {
11093 m_host.TaskInventory.LockItemsForRead(false);
11094 return new LSL_Vector();
11095 }
11096
11097 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11098 { 10919 {
11099 ShoutError("No permissions to track the camera"); 10920 ShoutError("No permissions to track the camera");
11100 m_host.TaskInventory.LockItemsForRead(false);
11101 return new LSL_Vector(); 10921 return new LSL_Vector();
11102 } 10922 }
11103 m_host.TaskInventory.LockItemsForRead(false);
11104 10923
11105// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10924// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11106 ScenePresence presence = World.GetScenePresence(agentID); 10925 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11107 if (presence != null) 10926 if (presence != null)
11108 { 10927 {
11109 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10928 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -11115,30 +10934,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11115 public LSL_Rotation llGetCameraRot() 10934 public LSL_Rotation llGetCameraRot()
11116 { 10935 {
11117 m_host.AddScriptLPS(1); 10936 m_host.AddScriptLPS(1);
11118 UUID invItemID = InventorySelf();
11119 if (invItemID == UUID.Zero)
11120 return new LSL_Rotation();
11121 10937
11122 m_host.TaskInventory.LockItemsForRead(true); 10938 if (m_item.PermsGranter == UUID.Zero)
11123 10939 return new LSL_Rotation();
11124 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
11125 10940
11126// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10941 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11127 if (agentID == UUID.Zero)
11128 {
11129 m_host.TaskInventory.LockItemsForRead(false);
11130 return new LSL_Rotation();
11131 }
11132 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11133 { 10942 {
11134 ShoutError("No permissions to track the camera"); 10943 ShoutError("No permissions to track the camera");
11135 m_host.TaskInventory.LockItemsForRead(false);
11136 return new LSL_Rotation(); 10944 return new LSL_Rotation();
11137 } 10945 }
11138 m_host.TaskInventory.LockItemsForRead(false);
11139 10946
11140// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10947// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11141 ScenePresence presence = World.GetScenePresence(agentID); 10948 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11142 if (presence != null) 10949 if (presence != null)
11143 { 10950 {
11144 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10951 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -11197,7 +11004,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11197 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 11004 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
11198 { 11005 {
11199 m_host.AddScriptLPS(1); 11006 m_host.AddScriptLPS(1);
11200 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 11007 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
11201 if (detectedParams == null) 11008 if (detectedParams == null)
11202 { 11009 {
11203 if (m_host.ParentGroup.IsAttachment == true) 11010 if (m_host.ParentGroup.IsAttachment == true)
@@ -11321,30 +11128,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11321 { 11128 {
11322 m_host.AddScriptLPS(1); 11129 m_host.AddScriptLPS(1);
11323 11130
11324 // our key in the object we are in
11325 UUID invItemID = InventorySelf();
11326 if (invItemID == UUID.Zero) return;
11327
11328 // the object we are in 11131 // the object we are in
11329 UUID objectID = m_host.ParentUUID; 11132 UUID objectID = m_host.ParentUUID;
11330 if (objectID == UUID.Zero) return; 11133 if (objectID == UUID.Zero)
11134 return;
11331 11135
11332 UUID agentID;
11333 m_host.TaskInventory.LockItemsForRead(true);
11334 // we need the permission first, to know which avatar we want to set the camera for 11136 // we need the permission first, to know which avatar we want to set the camera for
11335 agentID = m_host.TaskInventory[invItemID].PermsGranter; 11137 UUID agentID = m_item.PermsGranter;
11336 11138
11337 if (agentID == UUID.Zero) 11139 if (agentID == UUID.Zero)
11338 {
11339 m_host.TaskInventory.LockItemsForRead(false);
11340 return; 11140 return;
11341 } 11141
11342 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11142 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11343 {
11344 m_host.TaskInventory.LockItemsForRead(false);
11345 return; 11143 return;
11346 }
11347 m_host.TaskInventory.LockItemsForRead(false);
11348 11144
11349 ScenePresence presence = World.GetScenePresence(agentID); 11145 ScenePresence presence = World.GetScenePresence(agentID);
11350 11146
@@ -11386,34 +11182,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11386 { 11182 {
11387 m_host.AddScriptLPS(1); 11183 m_host.AddScriptLPS(1);
11388 11184
11389 // our key in the object we are in
11390 UUID invItemID=InventorySelf();
11391 if (invItemID == UUID.Zero) return;
11392
11393 // the object we are in 11185 // the object we are in
11394 UUID objectID = m_host.ParentUUID; 11186 UUID objectID = m_host.ParentUUID;
11395 if (objectID == UUID.Zero) return; 11187 if (objectID == UUID.Zero)
11188 return;
11396 11189
11397 // we need the permission first, to know which avatar we want to clear the camera for 11190 // we need the permission first, to know which avatar we want to clear the camera for
11398 UUID agentID; 11191 UUID agentID = m_item.PermsGranter;
11399 m_host.TaskInventory.LockItemsForRead(true); 11192
11400 agentID = m_host.TaskInventory[invItemID].PermsGranter;
11401 if (agentID == UUID.Zero) 11193 if (agentID == UUID.Zero)
11402 {
11403 m_host.TaskInventory.LockItemsForRead(false);
11404 return; 11194 return;
11405 } 11195
11406 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11196 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11407 {
11408 m_host.TaskInventory.LockItemsForRead(false);
11409 return; 11197 return;
11410 }
11411 m_host.TaskInventory.LockItemsForRead(false);
11412 11198
11413 ScenePresence presence = World.GetScenePresence(agentID); 11199 ScenePresence presence = World.GetScenePresence(agentID);
11414 11200
11415 // we are not interested in child-agents 11201 // we are not interested in child-agents
11416 if (presence.IsChildAgent) return; 11202 if (presence.IsChildAgent)
11203 return;
11417 11204
11418 presence.ControllingClient.SendClearFollowCamProperties(objectID); 11205 presence.ControllingClient.SendClearFollowCamProperties(objectID);
11419 } 11206 }
@@ -11604,8 +11391,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11604 } 11391 }
11605 } 11392 }
11606 11393
11607 UUID reqID = httpScriptMod. 11394 UUID reqID
11608 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 11395 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11609 11396
11610 if (reqID != UUID.Zero) 11397 if (reqID != UUID.Zero)
11611 return reqID.ToString(); 11398 return reqID.ToString();
@@ -11859,19 +11646,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11859 break; 11646 break;
11860 // For the following 8 see the Object version below 11647 // For the following 8 see the Object version below
11861 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11648 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11862 ret.Add(new LSL_Integer(0)); 11649 ret.Add(new LSL_Integer(av.RunningScriptCount()));
11863 break; 11650 break;
11864 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11651 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11865 ret.Add(new LSL_Integer(0)); 11652 ret.Add(new LSL_Integer(av.ScriptCount()));
11866 break; 11653 break;
11867 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11654 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11868 ret.Add(new LSL_Integer(0)); 11655 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
11869 break; 11656 break;
11870 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11657 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11871 ret.Add(new LSL_Float(0)); 11658 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
11872 break; 11659 break;
11873 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11660 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11874 ret.Add(new LSL_Integer(0)); 11661 ret.Add(new LSL_Integer(1));
11875 break; 11662 break;
11876 case ScriptBaseClass.OBJECT_SERVER_COST: 11663 case ScriptBaseClass.OBJECT_SERVER_COST:
11877 ret.Add(new LSL_Float(0)); 11664 ret.Add(new LSL_Float(0));
@@ -11929,37 +11716,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11929 case ScriptBaseClass.OBJECT_CREATOR: 11716 case ScriptBaseClass.OBJECT_CREATOR:
11930 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11717 ret.Add(new LSL_String(obj.CreatorID.ToString()));
11931 break; 11718 break;
11932 // The following 8 I have intentionaly coded to return zero. They are part of
11933 // "Land Impact" calculations. These calculations are probably not applicable
11934 // to OpenSim, required figures (cpu/memory usage) are not currently tracked
11935 // I have intentionally left these all at zero rather than return possibly
11936 // missleading numbers
11937 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11719 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11938 // in SL this currently includes crashed scripts 11720 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
11939 ret.Add(new LSL_Integer(0));
11940 break; 11721 break;
11941 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11722 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11942 ret.Add(new LSL_Integer(0)); 11723 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
11943 break; 11724 break;
11944 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11725 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11945 // The value returned in SL for mono scripts is 65536 * number of active scripts 11726 // The value returned in SL for mono scripts is 65536 * number of active scripts
11946 ret.Add(new LSL_Integer(0)); 11727 // and 16384 * number of active scripts for LSO. since llGetFreememory
11728 // is coded to give the LSO value use it here
11729 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
11947 break; 11730 break;
11948 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11731 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11949 // Average cpu time per simulator frame expended on all scripts in the objetc 11732 // Average cpu time in seconds per simulator frame expended on all scripts in the object
11950 ret.Add(new LSL_Float(0)); 11733 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
11951 break; 11734 break;
11952 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11735 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11953 // according to the SL wiki A prim or linkset will have prim 11736 // according to the SL wiki A prim or linkset will have prim
11954 // equivalent of the number of prims in a linkset if it does not 11737 // equivalent of the number of prims in a linkset if it does not
11955 // contain a mesh anywhere in the link set or is not a normal prim 11738 // contain a mesh anywhere in the link set or is not a normal prim
11956 // The value returned in SL for normal prims is prim count 11739 // The value returned in SL for normal prims is prim count
11957 ret.Add(new LSL_Integer(0)); 11740 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
11958 break; 11741 break;
11959 11742
11960 // costs below may need to be diferent for root parts, need to check 11743 // costs below may need to be diferent for root parts, need to check
11961 case ScriptBaseClass.OBJECT_SERVER_COST: 11744 case ScriptBaseClass.OBJECT_SERVER_COST:
11962 // The value returned in SL for normal prims is prim count 11745 // The linden calculation is here
11746 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11747 // The value returned in SL for normal prims looks like the prim count
11963 ret.Add(new LSL_Float(0)); 11748 ret.Add(new LSL_Float(0));
11964 break; 11749 break;
11965 case ScriptBaseClass.OBJECT_STREAMING_COST: 11750 case ScriptBaseClass.OBJECT_STREAMING_COST:
@@ -12065,7 +11850,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12065 } 11850 }
12066 11851
12067 // was: UUID tid = tid = AsyncCommands. 11852 // was: UUID tid = tid = AsyncCommands.
12068 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11853 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12069 11854
12070 if (NotecardCache.IsCached(assetID)) 11855 if (NotecardCache.IsCached(assetID))
12071 { 11856 {
@@ -12128,7 +11913,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12128 } 11913 }
12129 11914
12130 // was: UUID tid = tid = AsyncCommands. 11915 // was: UUID tid = tid = AsyncCommands.
12131 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11916 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12132 11917
12133 if (NotecardCache.IsCached(assetID)) 11918 if (NotecardCache.IsCached(assetID))
12134 { 11919 {
@@ -12212,7 +11997,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12212 { 11997 {
12213 UUID rq = UUID.Random(); 11998 UUID rq = UUID.Random();
12214 11999
12215 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12000 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12216 12001
12217 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 12002 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
12218 12003
@@ -12228,7 +12013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12228 { 12013 {
12229 UUID rq = UUID.Random(); 12014 UUID rq = UUID.Random();
12230 12015
12231 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12016 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12232 12017
12233 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 12018 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
12234 12019
@@ -12430,7 +12215,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12430 { 12215 {
12431 Tri t1 = new Tri(); 12216 Tri t1 = new Tri();
12432 Tri t2 = new Tri(); 12217 Tri t2 = new Tri();
12433 12218
12434 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]); 12219 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
12435 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]); 12220 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
12436 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]); 12221 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
@@ -12471,7 +12256,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12471 // sometimes 12256 // sometimes
12472 if (Math.Abs(b) < 0.000001) 12257 if (Math.Abs(b) < 0.000001)
12473 continue; 12258 continue;
12474 12259
12475 double r = a / b; 12260 double r = a / b;
12476 12261
12477 // ray points away from plane 12262 // ray points away from plane
@@ -12731,7 +12516,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12731 bool isAccount = false; 12516 bool isAccount = false;
12732 bool isGroup = false; 12517 bool isGroup = false;
12733 12518
12734 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 12519 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12735 return 0; 12520 return 0;
12736 12521
12737 UUID id = new UUID(); 12522 UUID id = new UUID();
@@ -12793,35 +12578,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12793 return 1; 12578 return 1;
12794 } 12579 }
12795 12580
12796 #region Not Implemented 12581 public LSL_Integer llGetMemoryLimit()
12797 // 12582 {
12798 // Listing the unimplemented lsl functions here, please move 12583 m_host.AddScriptLPS(1);
12799 // them from this region as they are completed 12584 // The value returned for LSO scripts in SL
12800 // 12585 return 16384;
12586 }
12801 12587
12802 public void llGetEnv(LSL_String name) 12588 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12803 { 12589 {
12804 m_host.AddScriptLPS(1); 12590 m_host.AddScriptLPS(1);
12805 NotImplemented("llGetEnv"); 12591 // Treat as an LSO script
12592 return ScriptBaseClass.FALSE;
12806 } 12593 }
12807 12594
12808 public void llGetSPMaxMemory() 12595 public LSL_Integer llGetSPMaxMemory()
12809 { 12596 {
12810 m_host.AddScriptLPS(1); 12597 m_host.AddScriptLPS(1);
12811 NotImplemented("llGetSPMaxMemory"); 12598 // The value returned for LSO scripts in SL
12599 return 16384;
12812 } 12600 }
12813 12601
12814 public virtual LSL_Integer llGetUsedMemory() 12602 public virtual LSL_Integer llGetUsedMemory()
12815 { 12603 {
12816 m_host.AddScriptLPS(1); 12604 m_host.AddScriptLPS(1);
12817 NotImplemented("llGetUsedMemory"); 12605 // The value returned for LSO scripts in SL
12818 return 0; 12606 return 16384;
12819 } 12607 }
12820 12608
12821 public void llScriptProfiler(LSL_Integer flags) 12609 public void llScriptProfiler(LSL_Integer flags)
12822 { 12610 {
12823 m_host.AddScriptLPS(1); 12611 m_host.AddScriptLPS(1);
12824 //NotImplemented("llScriptProfiler"); 12612 // This does nothing for LSO scripts in SL
12613 }
12614
12615 #region Not Implemented
12616 //
12617 // Listing the unimplemented lsl functions here, please move
12618 // them from this region as they are completed
12619 //
12620
12621 public void llGetEnv(LSL_String name)
12622 {
12623 m_host.AddScriptLPS(1);
12624 NotImplemented("llGetEnv");
12825 } 12625 }
12826 12626
12827 public void llSetSoundQueueing(int queue) 12627 public void llSetSoundQueueing(int queue)
@@ -12901,8 +12701,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12901 12701
12902 try 12702 try
12903 { 12703 {
12904 UUID invItemID=InventorySelf(); 12704 TaskInventoryItem item = m_item;
12905 if (invItemID == UUID.Zero) 12705 if (item == null)
12906 { 12706 {
12907 replydata = "SERVICE_ERROR"; 12707 replydata = "SERVICE_ERROR";
12908 return; 12708 return;
@@ -12910,10 +12710,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12910 12710
12911 m_host.AddScriptLPS(1); 12711 m_host.AddScriptLPS(1);
12912 12712
12913 m_host.TaskInventory.LockItemsForRead(true);
12914 TaskInventoryItem item = m_host.TaskInventory[invItemID];
12915 m_host.TaskInventory.LockItemsForRead(false);
12916
12917 if (item.PermsGranter == UUID.Zero) 12713 if (item.PermsGranter == UUID.Zero)
12918 { 12714 {
12919 replydata = "MISSING_PERMISSION_DEBIT"; 12715 replydata = "MISSING_PERMISSION_DEBIT";
@@ -12955,7 +12751,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12955 } 12751 }
12956 finally 12752 finally
12957 { 12753 {
12958 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12754 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
12959 "transaction_result", new Object[] { 12755 "transaction_result", new Object[] {
12960 new LSL_String(txn.ToString()), 12756 new LSL_String(txn.ToString()),
12961 new LSL_Integer(replycode), 12757 new LSL_Integer(replycode),
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index 77a784d..795de80 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -58,17 +58,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
58 { 58 {
59 internal IScriptEngine m_ScriptEngine; 59 internal IScriptEngine m_ScriptEngine;
60 internal SceneObjectPart m_host; 60 internal SceneObjectPart m_host;
61 internal uint m_localID;
62 internal UUID m_itemID;
63 internal bool m_LSFunctionsEnabled = false; 61 internal bool m_LSFunctionsEnabled = false;
64 internal IScriptModuleComms m_comms = null; 62 internal IScriptModuleComms m_comms = null;
65 63
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 64 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
67 { 65 {
68 m_ScriptEngine = ScriptEngine; 66 m_ScriptEngine = ScriptEngine;
69 m_host = host; 67 m_host = host;
70 m_localID = localID;
71 m_itemID = itemID;
72 68
73 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) 69 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
74 m_LSFunctionsEnabled = true; 70 m_LSFunctionsEnabled = true;
@@ -449,7 +445,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
449 LSShoutError("LightShare functions are not enabled."); 445 LSShoutError("LightShare functions are not enabled.");
450 return 0; 446 return 0;
451 } 447 }
452 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 448 if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
453 { 449 {
454 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); 450 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
455 return 0; 451 return 0;
@@ -477,7 +473,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
477 LSShoutError("LightShare functions are not enabled."); 473 LSShoutError("LightShare functions are not enabled.");
478 return; 474 return;
479 } 475 }
480 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 476 if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
481 { 477 {
482 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); 478 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
483 return; 479 return;
@@ -500,7 +496,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
500 LSShoutError("LightShare functions are not enabled."); 496 LSShoutError("LightShare functions are not enabled.");
501 return 0; 497 return 0;
502 } 498 }
503 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 499 if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
504 { 500 {
505 LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners."); 501 LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
506 return 0; 502 return 0;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 7c07e15..4bd3dff 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -57,17 +57,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
57 { 57 {
58 internal IScriptEngine m_ScriptEngine; 58 internal IScriptEngine m_ScriptEngine;
59 internal SceneObjectPart m_host; 59 internal SceneObjectPart m_host;
60 internal uint m_localID; 60 internal TaskInventoryItem m_item;
61 internal UUID m_itemID;
62 internal bool m_MODFunctionsEnabled = false; 61 internal bool m_MODFunctionsEnabled = false;
63 internal IScriptModuleComms m_comms = null; 62 internal IScriptModuleComms m_comms = null;
64 63
65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 64 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
66 { 65 {
67 m_ScriptEngine = ScriptEngine; 66 m_ScriptEngine = ScriptEngine;
68 m_host = host; 67 m_host = host;
69 m_localID = localID; 68 m_item = item;
70 m_itemID = itemID;
71 69
72 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false)) 70 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
73 m_MODFunctionsEnabled = true; 71 m_MODFunctionsEnabled = true;
@@ -252,7 +250,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
252 // non-null but don't trust it completely 250 // non-null but don't trust it completely
253 try 251 try
254 { 252 {
255 object result = m_comms.InvokeOperation(m_host.UUID, m_itemID, fname, convertedParms); 253 object result = m_comms.InvokeOperation(m_host.UUID, m_item.ItemID, fname, convertedParms);
256 if (result != null) 254 if (result != null)
257 return result; 255 return result;
258 256
@@ -279,7 +277,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
279 277
280 UUID req = UUID.Random(); 278 UUID req = UUID.Random();
281 279
282 m_comms.RaiseEvent(m_itemID, req.ToString(), module, command, k); 280 m_comms.RaiseEvent(m_item.ItemID, req.ToString(), module, command, k);
283 281
284 return req.ToString(); 282 return req.ToString();
285 } 283 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 0dc2aa2..795376b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -128,11 +128,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
128 { 128 {
129// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 129// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
130 130
131 public const string GridInfoServiceConfigSectionName = "GridInfoService";
132
131 internal IScriptEngine m_ScriptEngine; 133 internal IScriptEngine m_ScriptEngine;
132 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there 134 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
133 internal SceneObjectPart m_host; 135 internal SceneObjectPart m_host;
134 internal uint m_localID; 136 internal TaskInventoryItem m_item;
135 internal UUID m_itemID;
136 internal bool m_OSFunctionsEnabled = false; 137 internal bool m_OSFunctionsEnabled = false;
137 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 138 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
138 internal float m_ScriptDelayFactor = 1.0f; 139 internal float m_ScriptDelayFactor = 1.0f;
@@ -140,12 +141,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
140 internal bool m_debuggerSafe = false; 141 internal bool m_debuggerSafe = false;
141 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 142 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
142 143
143 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 144 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
144 { 145 {
145 m_ScriptEngine = ScriptEngine; 146 m_ScriptEngine = ScriptEngine;
146 m_host = host; 147 m_host = host;
147 m_localID = localID; 148 m_item = item;
148 m_itemID = itemID;
149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); 149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
150 150
151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
@@ -218,12 +218,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
218 } 218 }
219 } 219 }
220 220
221 /// <summary>
222 /// Initialize the LSL interface.
223 /// </summary>
224 /// <remarks>
225 /// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
226 /// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
227 /// ScriptInstance.
228 /// </remarks>
221 private void InitLSL() 229 private void InitLSL()
222 { 230 {
223 if (m_LSL_Api != null) 231 if (m_LSL_Api != null)
224 return; 232 return;
225 233
226 m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_itemID, "LSL"); 234 m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
227 } 235 }
228 236
229 // 237 //
@@ -342,22 +350,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
342 return; 350 return;
343 } 351 }
344 352
345 TaskInventoryItem ti = m_host.Inventory.GetInventoryItem(m_itemID); 353 UUID ownerID = m_item.OwnerID;
346 if (ti == null)
347 {
348 OSSLError(
349 String.Format("{0} permission error. Can't find script in prim inventory.",
350 function));
351 }
352
353 UUID ownerID = ti.OwnerID;
354 354
355 //OSSL only may be used if objet is in the same group as the parcel 355 //OSSL only may be used if object is in the same group as the parcel
356 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER")) 356 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER"))
357 { 357 {
358 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); 358 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
359 359
360 if (land.LandData.GroupID == ti.GroupID && land.LandData.GroupID != UUID.Zero) 360 if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
361 { 361 {
362 return; 362 return;
363 } 363 }
@@ -378,7 +378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
378 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER")) 378 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER"))
379 { 379 {
380 //Only Estate Managers may use the function 380 //Only Estate Managers may use the function
381 if (World.RegionInfo.EstateSettings.IsEstateManager(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) 381 if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
382 { 382 {
383 return; 383 return;
384 } 384 }
@@ -393,13 +393,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
393 } 393 }
394 } 394 }
395 395
396 if (!m_FunctionPerms[function].AllowedCreators.Contains(ti.CreatorID)) 396 if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
397 OSSLError( 397 OSSLError(
398 String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.", 398 String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.",
399 function)); 399 function));
400 if (ti.CreatorID != ownerID) 400
401 if (m_item.CreatorID != ownerID)
401 { 402 {
402 if ((ti.CurrentPermissions & (uint)PermissionMask.Modify) != 0) 403 if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
403 OSSLError( 404 OSSLError(
404 String.Format("{0} permission denied. Script permissions error.", 405 String.Format("{0} permission denied. Script permissions error.",
405 function)); 406 function));
@@ -730,11 +731,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
730 731
731 m_host.AddScriptLPS(1); 732 m_host.AddScriptLPS(1);
732 733
734 // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
733 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 735 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
734 { 736 {
735 MainConsole.Instance.RunCommand(command); 737 MainConsole.Instance.RunCommand(command);
736 return true; 738 return true;
737 } 739 }
740
738 return false; 741 return false;
739 } 742 }
740 743
@@ -957,21 +960,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
957 UUID avatarID = (UUID)avatar; 960 UUID avatarID = (UUID)avatar;
958 961
959 m_host.AddScriptLPS(1); 962 m_host.AddScriptLPS(1);
963
964 // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
965 // method (though see that doesn't do the is animation check, which is probably a bug) and have both
966 // these functions call that common code. However, this does mean navigating the brain-dead requirement
967 // of calling InitLSL()
960 if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence) 968 if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
961 { 969 {
962 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 970 ScenePresence target = (ScenePresence)World.Entities[avatarID];
963 if (target != null) 971 if (target != null)
964 { 972 {
965 UUID animID = UUID.Zero; 973 UUID animID;
966 m_host.TaskInventory.LockItemsForRead(true); 974
967 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 975 if (!UUID.TryParse(animation, out animID))
968 { 976 {
969 if (inv.Value.Name == animation) 977 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
970 { 978 if (item != null && item.Type == (int)AssetType.Animation)
971 if (inv.Value.Type == (int)AssetType.Animation) 979 animID = item.AssetID;
972 animID = inv.Value.AssetID; 980 else
973 continue; 981 animID = UUID.Zero;
974 }
975 } 982 }
976 m_host.TaskInventory.LockItemsForRead(false); 983 m_host.TaskInventory.LockItemsForRead(false);
977 984
@@ -1178,7 +1185,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 CheckThreatLevel(ThreatLevel.High, "osSetStateEvents"); 1185 CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
1179 m_host.AddScriptLPS(1); 1186 m_host.AddScriptLPS(1);
1180 1187
1181 m_host.SetScriptEvents(m_itemID, events); 1188 m_host.SetScriptEvents(m_item.ItemID, events);
1182 } 1189 }
1183 1190
1184 public void osSetRegionWaterHeight(double height) 1191 public void osSetRegionWaterHeight(double height)
@@ -1186,12 +1193,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1186 CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight"); 1193 CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
1187 1194
1188 m_host.AddScriptLPS(1); 1195 m_host.AddScriptLPS(1);
1189 //Check to make sure that the script's owner is the estate manager/master 1196
1190 //World.Permissions.GenericEstatePermission( 1197 World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1191 if (World.Permissions.IsGod(m_host.OwnerID))
1192 {
1193 World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1194 }
1195 } 1198 }
1196 1199
1197 /// <summary> 1200 /// <summary>
@@ -1202,27 +1205,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param> 1205 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
1203 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour) 1206 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
1204 { 1207 {
1205 CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings"); 1208 CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
1206 1209
1207 m_host.AddScriptLPS(1); 1210 m_host.AddScriptLPS(1);
1208 //Check to make sure that the script's owner is the estate manager/master
1209 //World.Permissions.GenericEstatePermission(
1210 if (World.Permissions.IsGod(m_host.OwnerID))
1211 {
1212 while (sunHour > 24.0)
1213 sunHour -= 24.0;
1214 1211
1215 while (sunHour < 0) 1212 while (sunHour > 24.0)
1216 sunHour += 24.0; 1213 sunHour -= 24.0;
1217 1214
1215 while (sunHour < 0)
1216 sunHour += 24.0;
1218 1217
1219 World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun; 1218 World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
1220 World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30 1219 World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
1221 World.RegionInfo.RegionSettings.FixedSun = sunFixed; 1220 World.RegionInfo.RegionSettings.FixedSun = sunFixed;
1222 World.RegionInfo.RegionSettings.Save(); 1221 World.RegionInfo.RegionSettings.Save();
1223 1222
1224 World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour); 1223 World.EventManager.TriggerEstateToolsSunUpdate(
1225 } 1224 World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour);
1226 } 1225 }
1227 1226
1228 /// <summary> 1227 /// <summary>
@@ -1232,26 +1231,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1232 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param> 1231 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
1233 public void osSetEstateSunSettings(bool sunFixed, double sunHour) 1232 public void osSetEstateSunSettings(bool sunFixed, double sunHour)
1234 { 1233 {
1235 CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings"); 1234 CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
1236 1235
1237 m_host.AddScriptLPS(1); 1236 m_host.AddScriptLPS(1);
1238 //Check to make sure that the script's owner is the estate manager/master
1239 //World.Permissions.GenericEstatePermission(
1240 if (World.Permissions.IsGod(m_host.OwnerID))
1241 {
1242 while (sunHour > 24.0)
1243 sunHour -= 24.0;
1244 1237
1245 while (sunHour < 0) 1238 while (sunHour > 24.0)
1246 sunHour += 24.0; 1239 sunHour -= 24.0;
1247 1240
1248 World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed; 1241 while (sunHour < 0)
1249 World.RegionInfo.EstateSettings.SunPosition = sunHour; 1242 sunHour += 24.0;
1250 World.RegionInfo.EstateSettings.FixedSun = sunFixed;
1251 World.RegionInfo.EstateSettings.Save();
1252 1243
1253 World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour); 1244 World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
1254 } 1245 World.RegionInfo.EstateSettings.SunPosition = sunHour;
1246 World.RegionInfo.EstateSettings.FixedSun = sunFixed;
1247 World.RegionInfo.EstateSettings.Save();
1248
1249 World.EventManager.TriggerEstateToolsSunUpdate(
1250 World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour);
1255 } 1251 }
1256 1252
1257 /// <summary> 1253 /// <summary>
@@ -1627,7 +1623,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1627 1623
1628 public Object osParseJSONNew(string JSON) 1624 public Object osParseJSONNew(string JSON)
1629 { 1625 {
1630 CheckThreatLevel(ThreatLevel.None, "osParseJSON"); 1626 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
1631 1627
1632 m_host.AddScriptLPS(1); 1628 m_host.AddScriptLPS(1);
1633 1629
@@ -1980,7 +1976,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1980 { 1976 {
1981 string retval = String.Empty; 1977 string retval = String.Empty;
1982 IConfigSource config = m_ScriptEngine.ConfigSource; 1978 IConfigSource config = m_ScriptEngine.ConfigSource;
1983 string url = config.Configs["GridInfo"].GetString("GridInfoURI", String.Empty); 1979 string url = null;
1980
1981 IConfig gridInfoConfig = config.Configs["GridInfo"];
1982
1983 if (gridInfoConfig != null)
1984 url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
1984 1985
1985 if (String.IsNullOrEmpty(url)) 1986 if (String.IsNullOrEmpty(url))
1986 return "Configuration Error!"; 1987 return "Configuration Error!";
@@ -2042,8 +2043,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2042 string nick = String.Empty; 2043 string nick = String.Empty;
2043 IConfigSource config = m_ScriptEngine.ConfigSource; 2044 IConfigSource config = m_ScriptEngine.ConfigSource;
2044 2045
2045 if (config.Configs["GridInfo"] != null) 2046 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2046 nick = config.Configs["GridInfo"].GetString("gridnick", nick); 2047 nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
2047 2048
2048 if (String.IsNullOrEmpty(nick)) 2049 if (String.IsNullOrEmpty(nick))
2049 nick = GridUserInfo(InfoType.Nick); 2050 nick = GridUserInfo(InfoType.Nick);
@@ -2059,8 +2060,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2059 string name = String.Empty; 2060 string name = String.Empty;
2060 IConfigSource config = m_ScriptEngine.ConfigSource; 2061 IConfigSource config = m_ScriptEngine.ConfigSource;
2061 2062
2062 if (config.Configs["GridInfo"] != null) 2063 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2063 name = config.Configs["GridInfo"].GetString("gridname", name); 2064 name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
2064 2065
2065 if (String.IsNullOrEmpty(name)) 2066 if (String.IsNullOrEmpty(name))
2066 name = GridUserInfo(InfoType.Name); 2067 name = GridUserInfo(InfoType.Name);
@@ -2076,8 +2077,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2076 string loginURI = String.Empty; 2077 string loginURI = String.Empty;
2077 IConfigSource config = m_ScriptEngine.ConfigSource; 2078 IConfigSource config = m_ScriptEngine.ConfigSource;
2078 2079
2079 if (config.Configs["GridInfo"] != null) 2080 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2080 loginURI = config.Configs["GridInfo"].GetString("login", loginURI); 2081 loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
2081 2082
2082 if (String.IsNullOrEmpty(loginURI)) 2083 if (String.IsNullOrEmpty(loginURI))
2083 loginURI = GridUserInfo(InfoType.Login); 2084 loginURI = GridUserInfo(InfoType.Login);
@@ -2124,8 +2125,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2124 string retval = String.Empty; 2125 string retval = String.Empty;
2125 IConfigSource config = m_ScriptEngine.ConfigSource; 2126 IConfigSource config = m_ScriptEngine.ConfigSource;
2126 2127
2127 if (config.Configs["GridInfo"] != null) 2128 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2128 retval = config.Configs["GridInfo"].GetString(key, retval); 2129 retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
2129 2130
2130 if (String.IsNullOrEmpty(retval)) 2131 if (String.IsNullOrEmpty(retval))
2131 retval = GridUserInfo(InfoType.Custom, key); 2132 retval = GridUserInfo(InfoType.Custom, key);
@@ -2480,7 +2481,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2480 return; 2481 return;
2481 2482
2482 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2483 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2483 module.MoveToTarget(npcId, World, pos, false, true); 2484 module.MoveToTarget(npcId, World, pos, false, true, false);
2484 } 2485 }
2485 } 2486 }
2486 2487
@@ -2505,7 +2506,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2505 World, 2506 World,
2506 pos, 2507 pos,
2507 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, 2508 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2508 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0); 2509 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
2510 (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
2509 } 2511 }
2510 } 2512 }
2511 2513
@@ -2555,7 +2557,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2555 2557
2556 public void osNpcStopMoveToTarget(LSL_Key npc) 2558 public void osNpcStopMoveToTarget(LSL_Key npc)
2557 { 2559 {
2558 CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); 2560 CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
2559 m_host.AddScriptLPS(1); 2561 m_host.AddScriptLPS(1);
2560 2562
2561 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2563 INPCModule module = World.RequestModuleInterface<INPCModule>();
@@ -2572,6 +2574,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2572 2574
2573 public void osNpcSay(LSL_Key npc, string message) 2575 public void osNpcSay(LSL_Key npc, string message)
2574 { 2576 {
2577 osNpcSay(npc, 0, message);
2578 }
2579
2580 public void osNpcSay(LSL_Key npc, int channel, string message)
2581 {
2575 CheckThreatLevel(ThreatLevel.High, "osNpcSay"); 2582 CheckThreatLevel(ThreatLevel.High, "osNpcSay");
2576 m_host.AddScriptLPS(1); 2583 m_host.AddScriptLPS(1);
2577 2584
@@ -2583,7 +2590,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2583 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2590 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2584 return; 2591 return;
2585 2592
2586 module.Say(npcId, World, message); 2593 module.Say(npcId, World, message, channel);
2594 }
2595 }
2596
2597 public void osNpcShout(LSL_Key npc, int channel, string message)
2598 {
2599 CheckThreatLevel(ThreatLevel.High, "osNpcShout");
2600 m_host.AddScriptLPS(1);
2601
2602 INPCModule module = World.RequestModuleInterface<INPCModule>();
2603 if (module != null)
2604 {
2605 UUID npcId = new UUID(npc.m_string);
2606
2607 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2608 return;
2609
2610 module.Shout(npcId, World, message, channel);
2587 } 2611 }
2588 } 2612 }
2589 2613
@@ -2684,6 +2708,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2684 } 2708 }
2685 } 2709 }
2686 2710
2711 public void osNpcWhisper(LSL_Key npc, int channel, string message)
2712 {
2713 CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
2714 m_host.AddScriptLPS(1);
2715
2716 INPCModule module = World.RequestModuleInterface<INPCModule>();
2717 if (module != null)
2718 {
2719 UUID npcId = new UUID(npc.m_string);
2720
2721 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2722 return;
2723
2724 module.Whisper(npcId, World, message, channel);
2725 }
2726 }
2727
2687 /// <summary> 2728 /// <summary>
2688 /// Save the current appearance of the script owner permanently to the named notecard. 2729 /// Save the current appearance of the script owner permanently to the named notecard.
2689 /// </summary> 2730 /// </summary>
@@ -2835,21 +2876,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2835 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); 2876 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
2836 m_host.AddScriptLPS(1); 2877 m_host.AddScriptLPS(1);
2837 2878
2838 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 2879 World.ForEachRootScenePresence(delegate(ScenePresence sp)
2839 { 2880 {
2840 World.ForEachRootScenePresence(delegate(ScenePresence sp) 2881 if (sp.Firstname == FirstName && sp.Lastname == SurName)
2841 { 2882 {
2842 if (sp.Firstname == FirstName && sp.Lastname == SurName) 2883 // kick client...
2843 { 2884 if (alert != null)
2844 // kick client... 2885 sp.ControllingClient.Kick(alert);
2845 if (alert != null)
2846 sp.ControllingClient.Kick(alert);
2847 2886
2848 // ...and close on our side 2887 // ...and close on our side
2849 sp.Scene.IncomingCloseAgent(sp.UUID); 2888 sp.Scene.IncomingCloseAgent(sp.UUID);
2850 } 2889 }
2851 }); 2890 });
2852 }
2853 } 2891 }
2854 2892
2855 public void osCauseDamage(string avatar, double damage) 2893 public void osCauseDamage(string avatar, double damage)
@@ -3095,5 +3133,80 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3095 3133
3096 return ScriptBaseClass.TRUE; 3134 return ScriptBaseClass.TRUE;
3097 } 3135 }
3136
3137 /// <summary>
3138 /// Sets terrain estate texture
3139 /// </summary>
3140 /// <param name="level"></param>
3141 /// <param name="texture"></param>
3142 /// <returns></returns>
3143 public void osSetTerrainTexture(int level, LSL_Key texture)
3144 {
3145 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3146
3147 m_host.AddScriptLPS(1);
3148 //Check to make sure that the script's owner is the estate manager/master
3149 //World.Permissions.GenericEstatePermission(
3150 if (World.Permissions.IsGod(m_host.OwnerID))
3151 {
3152 if (level < 0 || level > 3)
3153 return;
3154
3155 UUID textureID = new UUID();
3156 if (!UUID.TryParse(texture, out textureID))
3157 return;
3158
3159 // estate module is required
3160 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3161 if (estate != null)
3162 estate.setEstateTerrainBaseTexture(level, textureID);
3163 }
3164 }
3165
3166 /// <summary>
3167 /// Sets terrain heights of estate
3168 /// </summary>
3169 /// <param name="corner"></param>
3170 /// <param name="low"></param>
3171 /// <param name="high"></param>
3172 /// <returns></returns>
3173 public void osSetTerrainTextureHeight(int corner, double low, double high)
3174 {
3175 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3176
3177 m_host.AddScriptLPS(1);
3178 //Check to make sure that the script's owner is the estate manager/master
3179 //World.Permissions.GenericEstatePermission(
3180 if (World.Permissions.IsGod(m_host.OwnerID))
3181 {
3182 if (corner < 0 || corner > 3)
3183 return;
3184
3185 // estate module is required
3186 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3187 if (estate != null)
3188 estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
3189 }
3190 }
3191
3192 public void osForceAttachToAvatar(int attachmentPoint)
3193 {
3194 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3195
3196 m_host.AddScriptLPS(1);
3197
3198 InitLSL();
3199 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
3200 }
3201
3202 public void osForceDetachFromAvatar()
3203 {
3204 CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3205
3206 m_host.AddScriptLPS(1);
3207
3208 InitLSL();
3209 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3210 }
3098 } 3211 }
3099} 3212}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 1373971..19f3ce1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -308,7 +308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
308 } 308 }
309 SceneObjectPart SensePoint = ts.host; 309 SceneObjectPart SensePoint = ts.host;
310 310
311 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 311 Vector3 fromRegionPos = SensePoint.GetWorldPosition();
312 312
313 // pre define some things to avoid repeated definitions in the loop body 313 // pre define some things to avoid repeated definitions in the loop body
314 Vector3 toRegionPos; 314 Vector3 toRegionPos;
@@ -323,13 +323,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation! 323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
324 if (SensePoint.ParentGroup.IsAttachment) 324 if (SensePoint.ParentGroup.IsAttachment)
325 { 325 {
326 // In attachments, the sensor cone always orients with the 326 // In attachments, rotate the sensor cone with the
327 // avatar rotation. This may include a nonzero elevation if 327 // avatar rotation. This may include a nonzero elevation if
328 // in mouselook. 328 // in mouselook.
329 // This will not include the rotation and position of the
330 // attachment point (e.g. your head when a sensor is in your
331 // hair attached to your scull. Your hair will turn with
332 // your head but the sensor will stay with your (global)
333 // avatar rotation and position.
334 // Position of a sensor in a child prim attached to an avatar
335 // will be still wrong.
329 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 336 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
330 fromRegionPos = avatar.AbsolutePosition; 337 fromRegionPos = avatar.AbsolutePosition;
331 q = avatar.Rotation; 338 q = avatar.Rotation;
332 } 339 }
340
333 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 341 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
334 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 342 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
335 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 343 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
@@ -441,14 +449,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
441 return sensedEntities; 449 return sensedEntities;
442 450
443 SceneObjectPart SensePoint = ts.host; 451 SceneObjectPart SensePoint = ts.host;
444 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 452 Vector3 fromRegionPos = SensePoint.GetWorldPosition();
445 453
446 Quaternion q = SensePoint.RotationOffset; 454 Quaternion q = SensePoint.GetWorldRotation();
447 if (SensePoint.ParentGroup.IsAttachment) 455 if (SensePoint.ParentGroup.IsAttachment)
448 { 456 {
449 // In attachments, the sensor cone always orients with the 457 // In attachments, rotate the sensor cone with the
450 // avatar rotation. This may include a nonzero elevation if 458 // avatar rotation. This may include a nonzero elevation if
451 // in mouselook. 459 // in mouselook.
460 // This will not include the rotation and position of the
461 // attachment point (e.g. your head when a sensor is in your
462 // hair attached to your scull. Your hair will turn with
463 // your head but the sensor will stay with your (global)
464 // avatar rotation and position.
465 // Position of a sensor in a child prim attached to an avatar
466 // will be still wrong.
452 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 467 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
453 if (avatar == null) 468 if (avatar == null)
454 return sensedEntities; 469 return sensedEntities;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index 50f520a..749fc97 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -105,6 +105,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
105 LSL_Integer llFloor(double f); 105 LSL_Integer llFloor(double f);
106 void llForceMouselook(int mouselook); 106 void llForceMouselook(int mouselook);
107 LSL_Float llFrand(double mag); 107 LSL_Float llFrand(double mag);
108 LSL_Key llGenerateKey();
108 LSL_Vector llGetAccel(); 109 LSL_Vector llGetAccel();
109 LSL_Integer llGetAgentInfo(string id); 110 LSL_Integer llGetAgentInfo(string id);
110 LSL_String llGetAgentLanguage(string id); 111 LSL_String llGetAgentLanguage(string id);
@@ -150,7 +151,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
150 LSL_Rotation llGetLocalRot(); 151 LSL_Rotation llGetLocalRot();
151 LSL_Float llGetMass(); 152 LSL_Float llGetMass();
152 LSL_Float llGetMassMKS(); 153 LSL_Float llGetMassMKS();
153 void llGetNextEmail(string address, string subject); 154 LSL_Integer llGetMemoryLimit();
155 void llGetNextEmail(string address, string subject);
154 LSL_String llGetNotecardLine(string name, int line); 156 LSL_String llGetNotecardLine(string name, int line);
155 LSL_Key llGetNumberOfNotecardLines(string name); 157 LSL_Key llGetNumberOfNotecardLines(string name);
156 LSL_Integer llGetNumberOfPrims(); 158 LSL_Integer llGetNumberOfPrims();
@@ -188,6 +190,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
188 LSL_String llGetScriptName(); 190 LSL_String llGetScriptName();
189 LSL_Integer llGetScriptState(string name); 191 LSL_Integer llGetScriptState(string name);
190 LSL_String llGetSimulatorHostname(); 192 LSL_String llGetSimulatorHostname();
193 LSL_Integer llGetSPMaxMemory();
191 LSL_Integer llGetStartParameter(); 194 LSL_Integer llGetStartParameter();
192 LSL_Integer llGetStatus(int status); 195 LSL_Integer llGetStatus(int status);
193 LSL_String llGetSubString(string src, int start, int end); 196 LSL_String llGetSubString(string src, int start, int end);
@@ -323,6 +326,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
323 void llSay(int channelID, string text); 326 void llSay(int channelID, string text);
324 void llScaleTexture(double u, double v, int face); 327 void llScaleTexture(double u, double v, int face);
325 LSL_Integer llScriptDanger(LSL_Vector pos); 328 LSL_Integer llScriptDanger(LSL_Vector pos);
329 void llScriptProfiler(LSL_Integer flag);
326 LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata); 330 LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata);
327 void llSensor(string name, string id, int type, double range, double arc); 331 void llSensor(string name, string id, int type, double range, double arc);
328 void llSensorRemove(); 332 void llSensorRemove();
@@ -346,6 +350,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
346 void llSetLinkTexture(int linknumber, string texture, int face); 350 void llSetLinkTexture(int linknumber, string texture, int face);
347 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate); 351 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate);
348 void llSetLocalRot(LSL_Rotation rot); 352 void llSetLocalRot(LSL_Rotation rot);
353 LSL_Integer llSetMemoryLimit(LSL_Integer limit);
349 void llSetObjectDesc(string desc); 354 void llSetObjectDesc(string desc);
350 void llSetObjectName(string name); 355 void llSetObjectName(string name);
351 void llSetObjectPermMask(int mask, int value); 356 void llSetObjectPermMask(int mask, int value);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 444a681..7382495 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -98,6 +98,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
98 void osAvatarPlayAnimation(string avatar, string animation); 98 void osAvatarPlayAnimation(string avatar, string animation);
99 void osAvatarStopAnimation(string avatar, string animation); 99 void osAvatarStopAnimation(string avatar, string animation);
100 100
101 // Attachment commands
102
103 /// <summary>
104 /// Attach the object containing this script to the avatar that owns it without checking for PERMISSION_ATTACH
105 /// </summary>
106 /// <param name='attachment'>The attachment point. For example, ATTACH_CHEST</param>
107 void osForceAttachToAvatar(int attachment);
108
109 /// <summary>
110 /// Detach the object containing this script from the avatar it is attached to without checking for PERMISSION_ATTACH
111 /// </summary>
112 /// <remarks>Nothing happens if the object is not attached.</remarks>
113 void osForceDetachFromAvatar();
114
101 //texture draw functions 115 //texture draw functions
102 string osMovePen(string drawList, int x, int y); 116 string osMovePen(string drawList, int x, int y);
103 string osDrawLine(string drawList, int startX, int startY, int endX, int endY); 117 string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
@@ -203,11 +217,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
203 void osNpcSetRot(LSL_Key npc, rotation rot); 217 void osNpcSetRot(LSL_Key npc, rotation rot);
204 void osNpcStopMoveToTarget(LSL_Key npc); 218 void osNpcStopMoveToTarget(LSL_Key npc);
205 void osNpcSay(key npc, string message); 219 void osNpcSay(key npc, string message);
220 void osNpcSay(key npc, int channel, string message);
221 void osNpcShout(key npc, int channel, string message);
206 void osNpcSit(key npc, key target, int options); 222 void osNpcSit(key npc, key target, int options);
207 void osNpcStand(LSL_Key npc); 223 void osNpcStand(LSL_Key npc);
208 void osNpcRemove(key npc); 224 void osNpcRemove(key npc);
209 void osNpcPlayAnimation(LSL_Key npc, string animation); 225 void osNpcPlayAnimation(LSL_Key npc, string animation);
210 void osNpcStopAnimation(LSL_Key npc, string animation); 226 void osNpcStopAnimation(LSL_Key npc, string animation);
227 void osNpcWhisper(key npc, int channel, string message);
211 228
212 LSL_Key osOwnerSaveAppearance(string notecard); 229 LSL_Key osOwnerSaveAppearance(string notecard);
213 LSL_Key osAgentSaveAppearance(key agentId, string notecard); 230 LSL_Key osAgentSaveAppearance(key agentId, string notecard);
@@ -234,5 +251,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
234 251
235 LSL_Integer osInviteToGroup(LSL_Key agentId); 252 LSL_Integer osInviteToGroup(LSL_Key agentId);
236 LSL_Integer osEjectFromGroup(LSL_Key agentId); 253 LSL_Integer osEjectFromGroup(LSL_Key agentId);
254
255 void osSetTerrainTexture(int level, LSL_Key texture);
256 void osSetTerrainTextureHeight(int corner, double low, double high);
237 } 257 }
238} 258}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index ad4f70c..a08cc42 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -383,6 +383,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
383 public const int PRIM_SCULPT_FLAG_INVERT = 64; 383 public const int PRIM_SCULPT_FLAG_INVERT = 64;
384 public const int PRIM_SCULPT_FLAG_MIRROR = 128; 384 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
385 385
386 public const int PROFILE_NONE = 0;
387 public const int PROFILE_SCRIPT_MEMORY = 1;
388
386 public const int MASK_BASE = 0; 389 public const int MASK_BASE = 0;
387 public const int MASK_OWNER = 1; 390 public const int MASK_OWNER = 1;
388 public const int MASK_GROUP = 2; 391 public const int MASK_GROUP = 2;
@@ -641,6 +644,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
641 public const int OS_NPC_FLY = 0; 644 public const int OS_NPC_FLY = 0;
642 public const int OS_NPC_NO_FLY = 1; 645 public const int OS_NPC_NO_FLY = 1;
643 public const int OS_NPC_LAND_AT_TARGET = 2; 646 public const int OS_NPC_LAND_AT_TARGET = 2;
647 public const int OS_NPC_RUNNING = 4;
644 648
645 public const int OS_NPC_SIT_NOW = 0; 649 public const int OS_NPC_SIT_NOW = 0;
646 650
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 116f639..06f2c3c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -165,11 +165,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
165 m_LSL_Functions.llBreakLink(linknum); 165 m_LSL_Functions.llBreakLink(linknum);
166 } 166 }
167 167
168 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
169 {
170 return m_LSL_Functions.llCastRay(start, end, options);
171 }
172
173 public LSL_Integer llCeil(double f) 168 public LSL_Integer llCeil(double f)
174 { 169 {
175 return m_LSL_Functions.llCeil(f); 170 return m_LSL_Functions.llCeil(f);
@@ -376,6 +371,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
376 return m_LSL_Functions.llFrand(mag); 371 return m_LSL_Functions.llFrand(mag);
377 } 372 }
378 373
374 public LSL_Key llGenerateKey()
375 {
376 return m_LSL_Functions.llGenerateKey();
377 }
378
379 public LSL_Vector llGetAccel() 379 public LSL_Vector llGetAccel()
380 { 380 {
381 return m_LSL_Functions.llGetAccel(); 381 return m_LSL_Functions.llGetAccel();
@@ -591,6 +591,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
591 return m_LSL_Functions.llGetMassMKS(); 591 return m_LSL_Functions.llGetMassMKS();
592 } 592 }
593 593
594 public LSL_Integer llGetMemoryLimit()
595 {
596 return m_LSL_Functions.llGetMemoryLimit();
597 }
598
594 public void llGetNextEmail(string address, string subject) 599 public void llGetNextEmail(string address, string subject)
595 { 600 {
596 m_LSL_Functions.llGetNextEmail(address, subject); 601 m_LSL_Functions.llGetNextEmail(address, subject);
@@ -781,6 +786,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
781 return m_LSL_Functions.llGetSimulatorHostname(); 786 return m_LSL_Functions.llGetSimulatorHostname();
782 } 787 }
783 788
789 public LSL_Integer llGetSPMaxMemory()
790 {
791 return m_LSL_Functions.llGetSPMaxMemory();
792 }
793
784 public LSL_Integer llGetStartParameter() 794 public LSL_Integer llGetStartParameter()
785 { 795 {
786 return m_LSL_Functions.llGetStartParameter(); 796 return m_LSL_Functions.llGetStartParameter();
@@ -956,6 +966,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
956 return m_LSL_Functions.llRequestDisplayName(id); 966 return m_LSL_Functions.llRequestDisplayName(id);
957 } 967 }
958 968
969 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
970 {
971 return m_LSL_Functions.llCastRay(start, end, options);
972 }
973
959 public void llLinkParticleSystem(int linknum, LSL_List rules) 974 public void llLinkParticleSystem(int linknum, LSL_List rules)
960 { 975 {
961 m_LSL_Functions.llLinkParticleSystem(linknum, rules); 976 m_LSL_Functions.llLinkParticleSystem(linknum, rules);
@@ -1450,6 +1465,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1450 return m_LSL_Functions.llScriptDanger(pos); 1465 return m_LSL_Functions.llScriptDanger(pos);
1451 } 1466 }
1452 1467
1468 public void llScriptProfiler(LSL_Integer flags)
1469 {
1470 m_LSL_Functions.llScriptProfiler(flags);
1471 }
1472
1453 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata) 1473 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
1454 { 1474 {
1455 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata); 1475 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata);
@@ -1560,6 +1580,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1560 m_LSL_Functions.llSetLocalRot(rot); 1580 m_LSL_Functions.llSetLocalRot(rot);
1561 } 1581 }
1562 1582
1583 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
1584 {
1585 return m_LSL_Functions.llSetMemoryLimit(limit);
1586 }
1587
1563 public void llSetObjectDesc(string desc) 1588 public void llSetObjectDesc(string desc)
1564 { 1589 {
1565 m_LSL_Functions.llSetObjectDesc(desc); 1590 m_LSL_Functions.llSetObjectDesc(desc);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 680cefb4..d230662 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,8 +289,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation); 289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation);
290 } 290 }
291 291
292 // Avatar functions
292 293
293 //Texture Draw functions 294 public void osForceAttachToAvatar(int attachmentPoint)
295 {
296 m_OSSL_Functions.osForceAttachToAvatar(attachmentPoint);
297 }
298
299 public void osForceDetachFromAvatar()
300 {
301 m_OSSL_Functions.osForceDetachFromAvatar();
302 }
303
304 // Texture Draw functions
294 305
295 public string osMovePen(string drawList, int x, int y) 306 public string osMovePen(string drawList, int x, int y)
296 { 307 {
@@ -569,6 +580,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
569 m_OSSL_Functions.osNpcSay(npc, message); 580 m_OSSL_Functions.osNpcSay(npc, message);
570 } 581 }
571 582
583 public void osNpcSay(key npc, int channel, string message)
584 {
585 m_OSSL_Functions.osNpcSay(npc, channel, message);
586 }
587
588
589 public void osNpcShout(key npc, int channel, string message)
590 {
591 m_OSSL_Functions.osNpcShout(npc, channel, message);
592 }
593
572 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 594 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
573 { 595 {
574 m_OSSL_Functions.osNpcSit(npc, target, options); 596 m_OSSL_Functions.osNpcSit(npc, target, options);
@@ -594,6 +616,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 m_OSSL_Functions.osNpcStopAnimation(npc, animation); 616 m_OSSL_Functions.osNpcStopAnimation(npc, animation);
595 } 617 }
596 618
619 public void osNpcWhisper(key npc, int channel, string message)
620 {
621 m_OSSL_Functions.osNpcWhisper(npc, channel, message);
622 }
623
597 public LSL_Key osOwnerSaveAppearance(string notecard) 624 public LSL_Key osOwnerSaveAppearance(string notecard)
598 { 625 {
599 return m_OSSL_Functions.osOwnerSaveAppearance(notecard); 626 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
@@ -878,5 +905,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
878 { 905 {
879 return m_OSSL_Functions.osEjectFromGroup(agentId); 906 return m_OSSL_Functions.osEjectFromGroup(agentId);
880 } 907 }
908
909 public void osSetTerrainTexture(int level, LSL_Key texture)
910 {
911 m_OSSL_Functions.osSetTerrainTexture(level, texture);
912 }
913
914 public void osSetTerrainTextureHeight(int corner, double low, double high)
915 {
916 m_OSSL_Functions.osSetTerrainTextureHeight(corner, low, high);
917 }
881 } 918 }
882} 919}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 5e68d69..3797683 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -121,6 +121,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
121 121
122 public bool Running { get; set; } 122 public bool Running { get; set; }
123 123
124 public bool Run { get; set; }
125
124 public bool Suspended 126 public bool Suspended
125 { 127 {
126 get { return m_Suspended; } 128 get { return m_Suspended; }
@@ -216,6 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
216 m_postOnRez = postOnRez; 218 m_postOnRez = postOnRez;
217 m_AttachedAvatar = part.ParentGroup.AttachedAvatar; 219 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
218 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; 220 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
221 Run = true;
219 222
220 if (part != null) 223 if (part != null)
221 { 224 {
@@ -232,7 +235,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
232 foreach (string api in am.GetApis()) 235 foreach (string api in am.GetApis())
233 { 236 {
234 m_Apis[api] = am.CreateApi(api); 237 m_Apis[api] = am.CreateApi(api);
235 m_Apis[api].Initialize(engine, part, LocalID, itemID); 238 m_Apis[api].Initialize(engine, part, ScriptTask);
236 } 239 }
237 240
238 try 241 try
@@ -330,16 +333,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
330 } 333 }
331 else 334 else
332 { 335 {
333 m_log.ErrorFormat( 336 m_log.WarnFormat(
334 "[SCRIPT INSTANCE]: Unable to load script state from assembly {0}: Memory limit exceeded", 337 "[SCRIPT INSTANCE]: Unable to load script state file {0} for script {1} {2} in {3} {4} (assembly {5}). Memory limit exceeded",
335 assembly); 338 savedState, ScriptName, ItemID, PrimName, ObjectID, assembly);
336 } 339 }
337 } 340 }
338 catch (Exception e) 341 catch (Exception e)
339 { 342 {
340 m_log.ErrorFormat( 343 m_log.ErrorFormat(
341 "[SCRIPT INSTANCE]: Unable to load script state from assembly {0}. XML is {1}. Exception {2}{3}", 344 "[SCRIPT INSTANCE]: Unable to load script state file {0} for script {1} {2} in {3} {4} (assembly {5}). XML is {6}. Exception {7}{8}",
342 assembly, xml, e.Message, e.StackTrace); 345 savedState, ScriptName, ItemID, PrimName, ObjectID, assembly, xml, e.Message, e.StackTrace);
343 } 346 }
344 } 347 }
345// else 348// else
@@ -354,10 +357,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
354 357
355 public void Init() 358 public void Init()
356 { 359 {
357 if (!m_startOnInit) return; 360 if (!m_startOnInit)
361 return;
358 362
359 if (m_startedFromSavedState) 363 if (m_startedFromSavedState)
360 { 364 {
365 if (!Run)
366 return;
367
361 Start(); 368 Start();
362 if (m_postOnRez) 369 if (m_postOnRez)
363 { 370 {
@@ -390,6 +397,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
390 } 397 }
391 else 398 else
392 { 399 {
400 if (!Run)
401 return;
402
393 Start(); 403 Start();
394 PostEvent(new EventParams("state_entry", 404 PostEvent(new EventParams("state_entry",
395 new Object[0], new DetectParams[0])); 405 new Object[0], new DetectParams[0]));
@@ -966,7 +976,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
966 public IScriptApi GetApi(string name) 976 public IScriptApi GetApi(string name)
967 { 977 {
968 if (m_Apis.ContainsKey(name)) 978 if (m_Apis.ContainsKey(name))
979 {
980// m_log.DebugFormat("[SCRIPT INSTANCE]: Found api {0} in {1}@{2}", name, ScriptName, PrimName);
981
969 return m_Apis[name]; 982 return m_Apis[name];
983 }
984
985// m_log.DebugFormat("[SCRIPT INSTANCE]: Did not find api {0} in {1}@{2}", name, ScriptName, PrimName);
986
970 return null; 987 return null;
971 } 988 }
972 989
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs
index bcdc7bf..797bce3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs
@@ -55,6 +55,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
55 public static string Serialize(ScriptInstance instance) 55 public static string Serialize(ScriptInstance instance)
56 { 56 {
57 bool running = instance.Running; 57 bool running = instance.Running;
58 bool enabled = instance.Run;
58 59
59 XmlDocument xmldoc = new XmlDocument(); 60 XmlDocument xmldoc = new XmlDocument();
60 61
@@ -77,6 +78,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
77 78
78 rootElement.AppendChild(run); 79 rootElement.AppendChild(run);
79 80
81 XmlElement run_enable = xmldoc.CreateElement("", "Run", "");
82 run_enable.AppendChild(xmldoc.CreateTextNode(
83 enabled.ToString()));
84
85 rootElement.AppendChild(run_enable);
86
80 Dictionary<string, Object> vars = instance.GetVars(); 87 Dictionary<string, Object> vars = instance.GetVars();
81 88
82 XmlElement variables = xmldoc.CreateElement("", "Variables", ""); 89 XmlElement variables = xmldoc.CreateElement("", "Variables", "");
@@ -225,6 +232,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
225 { 232 {
226 object varValue; 233 object varValue;
227 XmlNodeList partL = rootNode.ChildNodes; 234 XmlNodeList partL = rootNode.ChildNodes;
235 instance.Run = true;
228 236
229 foreach (XmlNode part in partL) 237 foreach (XmlNode part in partL)
230 { 238 {
@@ -236,6 +244,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
236 case "Running": 244 case "Running":
237 instance.Running=bool.Parse(part.InnerText); 245 instance.Running=bool.Parse(part.InnerText);
238 break; 246 break;
247 case "Run":
248 instance.Run = bool.Parse(part.InnerText);
249 break;
239 case "Variables": 250 case "Variables":
240 XmlNodeList varL = part.ChildNodes; 251 XmlNodeList varL = part.ChildNodes;
241 foreach (XmlNode var in varL) 252 foreach (XmlNode var in varL)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
index e2d0db2..c73e22f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
@@ -63,7 +63,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
63 IConfig config = initConfigSource.AddConfig("XEngine"); 63 IConfig config = initConfigSource.AddConfig("XEngine");
64 config.Set("Enabled", "true"); 64 config.Set("Enabled", "true");
65 65
66 m_scene = SceneHelpers.SetupScene(); 66 m_scene = new SceneHelpers().SetupScene();
67 SceneHelpers.SetupSceneModules(m_scene, initConfigSource); 67 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
68 68
69 m_engine = new XEngine.XEngine(); 69 m_engine = new XEngine.XEngine();
@@ -91,7 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
91 TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); 91 TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId);
92 92
93 LSL_Api api = new LSL_Api(); 93 LSL_Api api = new LSL_Api();
94 api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID); 94 api.Initialize(m_engine, so1.RootPart, null);
95 95
96 // Create a second object 96 // Create a second object
97 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); 97 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100);
@@ -124,7 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
124 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); 124 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
125 m_scene.AddSceneObject(so1); 125 m_scene.AddSceneObject(so1);
126 LSL_Api api = new LSL_Api(); 126 LSL_Api api = new LSL_Api();
127 api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID); 127 api.Initialize(m_engine, so1.RootPart, null);
128 128
129 // Create an object embedded inside the first 129 // Create an object embedded inside the first
130 UUID itemId = TestHelpers.ParseTail(0x20); 130 UUID itemId = TestHelpers.ParseTail(0x20);
@@ -134,7 +134,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
134 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); 134 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100);
135 m_scene.AddSceneObject(so2); 135 m_scene.AddSceneObject(so2);
136 LSL_Api api2 = new LSL_Api(); 136 LSL_Api api2 = new LSL_Api();
137 api2.Initialize(m_engine, so2.RootPart, so2.RootPart.LocalId, so2.RootPart.UUID); 137 api2.Initialize(m_engine, so2.RootPart, null);
138 138
139 // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** 139 // *** Firstly, we test where llAllowInventoryDrop() has not been called. ***
140 api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); 140 api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
new file mode 100644
index 0000000..bc3b790
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
@@ -0,0 +1,139 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
45using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common;
47using OpenSim.Tests.Common.Mock;
48
49namespace OpenSim.Region.ScriptEngine.Shared.Tests
50{
51 /// <summary>
52 /// Tests for linking functions in LSL
53 /// </summary>
54 /// <remarks>
55 /// This relates to LSL. Actual linking functionality should be tested in the main
56 /// OpenSim.Region.Framework.Scenes.Tests.SceneObjectLinkingTests.
57 /// </remarks>
58 [TestFixture]
59 public class LSL_ApiLinkingTests
60 {
61 protected Scene m_scene;
62 protected XEngine.XEngine m_engine;
63
64 [SetUp]
65 public void SetUp()
66 {
67 IConfigSource initConfigSource = new IniConfigSource();
68 IConfig config = initConfigSource.AddConfig("XEngine");
69 config.Set("Enabled", "true");
70
71 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
73
74 m_engine = new XEngine.XEngine();
75 m_engine.Initialise(initConfigSource);
76 m_engine.AddRegion(m_scene);
77 }
78
79 [Test]
80 public void TestllCreateLink()
81 {
82 TestHelpers.InMethod();
83
84 UUID ownerId = TestHelpers.ParseTail(0x1);
85
86 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
87 grp1.AbsolutePosition = new Vector3(10, 10, 10);
88 m_scene.AddSceneObject(grp1);
89
90 // FIXME: This should really be a script item (with accompanying script)
91 TaskInventoryItem grp1Item
92 = TaskInventoryHelpers.AddNotecard(m_scene, grp1.RootPart);
93 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
94
95 SceneObjectGroup grp2 = SceneHelpers.CreateSceneObject(2, ownerId, "grp2-", 0x20);
96 grp2.AbsolutePosition = new Vector3(20, 20, 20);
97
98 // <180,0,0>
99 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
100
101 m_scene.AddSceneObject(grp2);
102
103 LSL_Api apiGrp1 = new LSL_Api();
104 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
105
106 apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE);
107
108 Assert.That(grp1.Parts.Length, Is.EqualTo(4));
109 Assert.That(grp2.IsDeleted, Is.True);
110 }
111
112 [Test]
113 public void TestllBreakLink()
114 {
115 TestHelpers.InMethod();
116
117 UUID ownerId = TestHelpers.ParseTail(0x1);
118
119 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
120 grp1.AbsolutePosition = new Vector3(10, 10, 10);
121 m_scene.AddSceneObject(grp1);
122
123 // FIXME: This should really be a script item (with accompanying script)
124 TaskInventoryItem grp1Item
125 = TaskInventoryHelpers.AddNotecard(m_scene, grp1.RootPart);
126 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
127
128 LSL_Api apiGrp1 = new LSL_Api();
129 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
130
131 apiGrp1.llBreakLink(2);
132
133 Assert.That(grp1.Parts.Length, Is.EqualTo(1));
134
135 SceneObjectGroup grp2 = m_scene.GetSceneObjectGroup("grp1-Part1");
136 Assert.That(grp2, Is.Not.Null);
137 }
138 }
139} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
index 9cf9258..f96a156 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -58,7 +58,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
58 IConfig config = initConfigSource.AddConfig("XEngine"); 58 IConfig config = initConfigSource.AddConfig("XEngine");
59 config.Set("Enabled", "true"); 59 config.Set("Enabled", "true");
60 60
61 Scene scene = SceneHelpers.SetupScene(); 61 Scene scene = new SceneHelpers().SetupScene();
62 SceneObjectPart part = SceneHelpers.AddSceneObject(scene); 62 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
63 63
64 XEngine.XEngine engine = new XEngine.XEngine(); 64 XEngine.XEngine engine = new XEngine.XEngine();
@@ -66,8 +66,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
66 engine.AddRegion(scene); 66 engine.AddRegion(scene);
67 67
68 m_lslApi = new LSL_Api(); 68 m_lslApi = new LSL_Api();
69 m_lslApi.Initialize(engine, part, part.LocalId, part.UUID); 69 m_lslApi.Initialize(engine, part, null);
70
71 } 70 }
72 71
73 [Test] 72 [Test]
@@ -261,7 +260,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
261 TestHelpers.InMethod(); 260 TestHelpers.InMethod();
262 261
263 // Create Prim1. 262 // Create Prim1.
264 Scene scene = SceneHelpers.SetupScene(); 263 Scene scene = new SceneHelpers().SetupScene();
265 string obj1Name = "Prim1"; 264 string obj1Name = "Prim1";
266 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); 265 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
267 SceneObjectPart part1 = 266 SceneObjectPart part1 =
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
index 7573dff..3965734 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
@@ -67,7 +67,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
67 config = initConfigSource.AddConfig("NPC"); 67 config = initConfigSource.AddConfig("NPC");
68 config.Set("Enabled", "true"); 68 config.Set("Enabled", "true");
69 69
70 m_scene = SceneHelpers.SetupScene(); 70 m_scene = new SceneHelpers().SetupScene();
71 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); 71 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
72 72
73 m_engine = new XEngine.XEngine(); 73 m_engine = new XEngine.XEngine();
@@ -95,7 +95,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
95 m_scene.AddSceneObject(so); 95 m_scene.AddSceneObject(so);
96 96
97 OSSL_Api osslApi = new OSSL_Api(); 97 OSSL_Api osslApi = new OSSL_Api();
98 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 98 osslApi.Initialize(m_engine, part, null);
99 99
100 string notecardName = "appearanceNc"; 100 string notecardName = "appearanceNc";
101 osslApi.osOwnerSaveAppearance(notecardName); 101 osslApi.osOwnerSaveAppearance(notecardName);
@@ -130,7 +130,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
130 m_scene.AddSceneObject(so); 130 m_scene.AddSceneObject(so);
131 131
132 OSSL_Api osslApi = new OSSL_Api(); 132 OSSL_Api osslApi = new OSSL_Api();
133 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 133 osslApi.Initialize(m_engine, part, null);
134 134
135 string notecardName = "appearanceNc"; 135 string notecardName = "appearanceNc";
136 osslApi.osOwnerSaveAppearance(notecardName); 136 osslApi.osOwnerSaveAppearance(notecardName);
@@ -161,7 +161,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
161 m_scene.AddSceneObject(so); 161 m_scene.AddSceneObject(so);
162 162
163 OSSL_Api osslApi = new OSSL_Api(); 163 OSSL_Api osslApi = new OSSL_Api();
164 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 164 osslApi.Initialize(m_engine, part, null);
165 165
166 string notecardName = "appearanceNc"; 166 string notecardName = "appearanceNc";
167 167
@@ -202,7 +202,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
202 m_scene.AddSceneObject(so); 202 m_scene.AddSceneObject(so);
203 203
204 OSSL_Api osslApi = new OSSL_Api(); 204 OSSL_Api osslApi = new OSSL_Api();
205 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 205 osslApi.Initialize(m_engine, part, null);
206 206
207 string notecardName = "appearanceNc"; 207 string notecardName = "appearanceNc";
208 208
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
index 9d9fc51..0ccd889 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
68 config = initConfigSource.AddConfig("NPC"); 68 config = initConfigSource.AddConfig("NPC");
69 config.Set("Enabled", "true"); 69 config.Set("Enabled", "true");
70 70
71 m_scene = SceneHelpers.SetupScene(); 71 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); 72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
73 73
74 m_engine = new XEngine.XEngine(); 74 m_engine = new XEngine.XEngine();
@@ -104,10 +104,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
104 m_scene.AddSceneObject(otherSo); 104 m_scene.AddSceneObject(otherSo);
105 105
106 OSSL_Api osslApi = new OSSL_Api(); 106 OSSL_Api osslApi = new OSSL_Api();
107 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 107 osslApi.Initialize(m_engine, part, null);
108 108
109 OSSL_Api otherOsslApi = new OSSL_Api(); 109 OSSL_Api otherOsslApi = new OSSL_Api();
110 otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID); 110 otherOsslApi.Initialize(m_engine, otherPart, null);
111 111
112 string notecardName = "appearanceNc"; 112 string notecardName = "appearanceNc";
113 osslApi.osOwnerSaveAppearance(notecardName); 113 osslApi.osOwnerSaveAppearance(notecardName);
@@ -151,7 +151,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
151 m_scene.AddSceneObject(so); 151 m_scene.AddSceneObject(so);
152 152
153 OSSL_Api osslApi = new OSSL_Api(); 153 OSSL_Api osslApi = new OSSL_Api();
154 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 154 osslApi.Initialize(m_engine, part, null);
155 155
156 string notecardName = "appearanceNc"; 156 string notecardName = "appearanceNc";
157 osslApi.osOwnerSaveAppearance(notecardName); 157 osslApi.osOwnerSaveAppearance(notecardName);
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
index 7d7bd82..a3f848c 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests
73 // to AssemblyResolver.OnAssemblyResolve fails. 73 // to AssemblyResolver.OnAssemblyResolve fails.
74 xEngineConfig.Set("AppDomainLoading", "false"); 74 xEngineConfig.Set("AppDomainLoading", "false");
75 75
76 m_scene = SceneHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, null, configSource); 76 m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource);
77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule); 77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);
78 m_scene.StartScripts(); 78 m_scene.StartScripts();
79 } 79 }
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 1e0f01f..79d1944 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -63,6 +63,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
63 { 63 {
64 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 64 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
65 65
66 /// <summary>
67 /// Control the printing of certain debug messages.
68 /// </summary>
69 /// <remarks>
70 /// If DebugLevel >= 1, then we log every time that a script is started.
71 /// </remarks>
72// public int DebugLevel { get; set; }
73
66 private SmartThreadPool m_ThreadPool; 74 private SmartThreadPool m_ThreadPool;
67 private int m_MaxScriptQueue; 75 private int m_MaxScriptQueue;
68 private Scene m_Scene; 76 private Scene m_Scene;
@@ -284,9 +292,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
284 AppDomain.CurrentDomain.AssemblyResolve += 292 AppDomain.CurrentDomain.AssemblyResolve +=
285 OnAssemblyResolve; 293 OnAssemblyResolve;
286 294
287 m_log.InfoFormat("[XEngine] Initializing scripts in region {0}",
288 scene.RegionInfo.RegionName);
289 m_Scene = scene; 295 m_Scene = scene;
296 m_log.InfoFormat("[XEngine]: Initializing scripts in region {0}", m_Scene.RegionInfo.RegionName);
290 297
291 m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2); 298 m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2);
292 m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100); 299 m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100);
@@ -389,9 +396,42 @@ namespace OpenSim.Region.ScriptEngine.XEngine
389 "Starts all stopped scripts." 396 "Starts all stopped scripts."
390 + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", 397 + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.",
391 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); 398 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript));
399
400// MainConsole.Instance.Commands.AddCommand(
401// "Debug", false, "debug xengine", "debug xengine [<level>]",
402// "Turn on detailed xengine debugging.",
403// "If level <= 0, then no extra logging is done.\n"
404// + "If level >= 1, then we log every time that a script is started.",
405// HandleDebugLevelCommand);
392 } 406 }
393 407
394 /// <summary> 408 /// <summary>
409 /// Change debug level
410 /// </summary>
411 /// <param name="module"></param>
412 /// <param name="args"></param>
413// private void HandleDebugLevelCommand(string module, string[] args)
414// {
415// if (args.Length == 3)
416// {
417// int newDebug;
418// if (int.TryParse(args[2], out newDebug))
419// {
420// DebugLevel = newDebug;
421// MainConsole.Instance.OutputFormat("Debug level set to {0}", newDebug);
422// }
423// }
424// else if (args.Length == 2)
425// {
426// MainConsole.Instance.OutputFormat("Current debug level is {0}", DebugLevel);
427// }
428// else
429// {
430// MainConsole.Instance.Output("Usage: debug xengine 0..1");
431// }
432// }
433
434 /// <summary>
395 /// Parse the raw item id into a script instance from the command params if it's present. 435 /// Parse the raw item id into a script instance from the command params if it's present.
396 /// </summary> 436 /// </summary>
397 /// <param name="cmdparams"></param> 437 /// <param name="cmdparams"></param>
@@ -795,35 +835,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
795 int colon = firstline.IndexOf(':'); 835 int colon = firstline.IndexOf(':');
796 if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1) 836 if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1)
797 { 837 {
798 string engineName = firstline.Substring(2, colon-2); 838 string engineName = firstline.Substring(2, colon - 2);
799 839
800 if (names.Contains(engineName)) 840 if (names.Contains(engineName))
801 { 841 {
802 engine = engineName; 842 engine = engineName;
803 script = "//" + script.Substring(script.IndexOf(':')+1); 843 script = "//" + script.Substring(colon + 1);
804 } 844 }
805 else 845 else
806 { 846 {
807 if (engine == ScriptEngineName) 847 if (engine == ScriptEngineName)
808 { 848 {
809 SceneObjectPart part = 849 // If we are falling back on XEngine as the default engine, then only complain to the user
810 m_Scene.GetSceneObjectPart( 850 // if a script language has been explicitly set and it's one that we recognize. If it's
811 localID); 851 // explicitly not allowed or the script is not in LSL then the user will be informed by a later compiler message.
812 852 //
813 TaskInventoryItem item = 853 // This avoids the overwhelming number of false positives where we're in this code because
814 part.Inventory.GetInventoryItem(itemID); 854 // there's a colon in a comment in the first line of a script for entirely
815 855 // unrelated reasons (e.g. vim settings).
816 ScenePresence presence = 856 //
817 m_Scene.GetScenePresence( 857 // TODO: A better fix would be to deprecate simple : detection and look for some less likely
818 item.OwnerID); 858 // string to begin the comment (like #! in unix shell scripts).
819 859 bool scriptExplicitlyInXEngineLanguage = false;
820 if (presence != null) 860 string restOfScript = script.Substring(colon + 1);
861
862 // FIXME: These are hardcoded because they are currently hardcoded in Compiler.cs
863 if (restOfScript.StartsWith("c#")
864 || restOfScript.StartsWith("vb")
865 || restOfScript.StartsWith("lsl")
866 || restOfScript.StartsWith("js")
867 || restOfScript.StartsWith("yp"))
868 scriptExplicitlyInXEngineLanguage = true;
869
870 if (scriptExplicitlyInXEngineLanguage)
821 { 871 {
822 presence.ControllingClient.SendAgentAlertMessage( 872 SceneObjectPart part =
823 "Selected engine unavailable. "+ 873 m_Scene.GetSceneObjectPart(
824 "Running script on "+ 874 localID);
825 ScriptEngineName, 875
826 false); 876 TaskInventoryItem item =
877 part.Inventory.GetInventoryItem(itemID);
878
879 ScenePresence presence =
880 m_Scene.GetScenePresence(
881 item.OwnerID);
882
883 if (presence != null)
884 {
885 presence.ControllingClient.SendAgentAlertMessage(
886 "Selected engine unavailable. "+
887 "Running script on "+
888 ScriptEngineName,
889 false);
890 }
827 } 891 }
828 } 892 }
829 } 893 }
@@ -880,20 +944,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine
880 { 944 {
881 if (m_InitialStartup) 945 if (m_InitialStartup)
882 { 946 {
883 m_InitialStartup = false; 947 // This delay exists to stop mono problems where script compilation and startup would stop the sim
948 // working properly for the session.
884 System.Threading.Thread.Sleep(15000); 949 System.Threading.Thread.Sleep(15000);
950 }
951
952 object[] o;
953
954 int scriptsStarted = 0;
885 955
886 if (m_CompileQueue.Count == 0) 956 while (m_CompileQueue.Dequeue(out o))
957 {
958 if (DoOnRezScript(o))
887 { 959 {
888 // No scripts on region, so won't get triggered later 960 scriptsStarted++;
889 // by the queue becoming empty so we trigger it here 961
890 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); 962 if (m_InitialStartup)
963 if (scriptsStarted % 50 == 0)
964 m_log.InfoFormat(
965 "[XEngine]: Started {0} scripts in {1}", scriptsStarted, m_Scene.RegionInfo.RegionName);
891 } 966 }
892 } 967 }
893 968
894 object[] o; 969 if (m_InitialStartup)
895 while (m_CompileQueue.Dequeue(out o)) 970 m_log.InfoFormat(
896 DoOnRezScript(o); 971 "[XEngine]: Completed starting {0} scripts on {1}", scriptsStarted, m_Scene.RegionInfo.RegionName);
897 972
898 // NOTE: Despite having a lockless queue, this lock is required 973 // NOTE: Despite having a lockless queue, this lock is required
899 // to make sure there is never no compile thread while there 974 // to make sure there is never no compile thread while there
@@ -901,12 +976,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
901 // due to a race condition 976 // due to a race condition
902 // 977 //
903 lock (m_CompileQueue) 978 lock (m_CompileQueue)
904 {
905 m_CurrentCompile = null; 979 m_CurrentCompile = null;
906 } 980
907 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, 981 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount,
908 m_ScriptErrorMessage); 982 m_ScriptErrorMessage);
983
909 m_ScriptFailCount = 0; 984 m_ScriptFailCount = 0;
985 m_InitialStartup = false;
910 986
911 return null; 987 return null;
912 } 988 }
@@ -1089,11 +1165,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1089 1165
1090 AppDomain sandbox; 1166 AppDomain sandbox;
1091 if (m_AppDomainLoading) 1167 if (m_AppDomainLoading)
1168 {
1092 sandbox = AppDomain.CreateDomain( 1169 sandbox = AppDomain.CreateDomain(
1093 m_Scene.RegionInfo.RegionID.ToString(), 1170 m_Scene.RegionInfo.RegionID.ToString(),
1094 evidence, appSetup); 1171 evidence, appSetup);
1172 m_AppDomains[appDomain].AssemblyResolve +=
1173 new ResolveEventHandler(
1174 AssemblyResolver.OnAssemblyResolve);
1175 }
1095 else 1176 else
1177 {
1096 sandbox = AppDomain.CurrentDomain; 1178 sandbox = AppDomain.CurrentDomain;
1179 }
1097 1180
1098 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 1181 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1099 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 1182 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
@@ -1105,9 +1188,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1105 1188
1106 m_AppDomains[appDomain] = sandbox; 1189 m_AppDomains[appDomain] = sandbox;
1107 1190
1108 m_AppDomains[appDomain].AssemblyResolve +=
1109 new ResolveEventHandler(
1110 AssemblyResolver.OnAssemblyResolve);
1111 m_DomainScripts[appDomain] = new List<UUID>(); 1191 m_DomainScripts[appDomain] = new List<UUID>();
1112 } 1192 }
1113 catch (Exception e) 1193 catch (Exception e)
@@ -1392,25 +1472,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1392 return false; 1472 return false;
1393 1473
1394 uuids = m_PrimObjects[localID]; 1474 uuids = m_PrimObjects[localID];
1395
1396 1475
1397 foreach (UUID itemID in uuids) 1476 foreach (UUID itemID in uuids)
1398 {
1399 IScriptInstance instance = null;
1400 try
1401 {
1402 if (m_Scripts.ContainsKey(itemID))
1403 instance = m_Scripts[itemID];
1404 }
1405 catch { /* ignore race conditions */ }
1406
1407 if (instance != null)
1408 { 1477 {
1409 instance.PostEvent(p); 1478 IScriptInstance instance = null;
1410 result = true; 1479 try
1480 {
1481 if (m_Scripts.ContainsKey(itemID))
1482 instance = m_Scripts[itemID];
1483 }
1484 catch { /* ignore race conditions */ }
1485
1486 if (instance != null)
1487 {
1488 instance.PostEvent(p);
1489 result = true;
1490 }
1411 } 1491 }
1412 } 1492 }
1413 }
1414 1493
1415 return result; 1494 return result;
1416 } 1495 }
@@ -1535,6 +1614,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1535 } 1614 }
1536 } 1615 }
1537 1616
1617 public void SetRunEnable(UUID instanceID, bool enable)
1618 {
1619 IScriptInstance instance = GetInstance(instanceID);
1620 if (instance != null)
1621 instance.Run = enable;
1622 }
1623
1538 public bool GetScriptState(UUID itemID) 1624 public bool GetScriptState(UUID itemID)
1539 { 1625 {
1540 IScriptInstance instance = GetInstance(itemID); 1626 IScriptInstance instance = GetInstance(itemID);
@@ -1745,14 +1831,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1745 FileMode.Open, FileAccess.Read)) 1831 FileMode.Open, FileAccess.Read))
1746 { 1832 {
1747 tfs.Read(tdata, 0, tdata.Length); 1833 tfs.Read(tdata, 0, tdata.Length);
1748 tfs.Close();
1749 } 1834 }
1750 1835
1751 assem = new System.Text.ASCIIEncoding().GetString(tdata); 1836 assem = new System.Text.ASCIIEncoding().GetString(tdata);
1752 } 1837 }
1753 catch (Exception e) 1838 catch (Exception e)
1754 { 1839 {
1755 m_log.DebugFormat("[XEngine]: Unable to open script textfile {0}, reason: {1}", assemName+".text", e.Message); 1840 m_log.ErrorFormat(
1841 "[XEngine]: Unable to open script textfile {0}{1}, reason: {2}",
1842 assemName, ".text", e.Message);
1756 } 1843 }
1757 } 1844 }
1758 } 1845 }
@@ -1769,16 +1856,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1769 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read)) 1856 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read))
1770 { 1857 {
1771 fs.Read(data, 0, data.Length); 1858 fs.Read(data, 0, data.Length);
1772 fs.Close();
1773 } 1859 }
1774 1860
1775 assem = System.Convert.ToBase64String(data); 1861 assem = System.Convert.ToBase64String(data);
1776 } 1862 }
1777 catch (Exception e) 1863 catch (Exception e)
1778 { 1864 {
1779 m_log.DebugFormat("[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message); 1865 m_log.ErrorFormat(
1866 "[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message);
1780 } 1867 }
1781
1782 } 1868 }
1783 } 1869 }
1784 1870
@@ -1791,9 +1877,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1791 using (StreamReader msr = new StreamReader(mfs)) 1877 using (StreamReader msr = new StreamReader(mfs))
1792 { 1878 {
1793 map = msr.ReadToEnd(); 1879 map = msr.ReadToEnd();
1794 msr.Close();
1795 } 1880 }
1796 mfs.Close();
1797 } 1881 }
1798 } 1882 }
1799 1883
@@ -1829,6 +1913,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1829 1913
1830 public bool SetXMLState(UUID itemID, string xml) 1914 public bool SetXMLState(UUID itemID, string xml)
1831 { 1915 {
1916// m_log.DebugFormat("[XEngine]: Writing state for script item with ID {0}", itemID);
1917
1832 if (xml == String.Empty) 1918 if (xml == String.Empty)
1833 return false; 1919 return false;
1834 1920
@@ -1889,31 +1975,61 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1889 { 1975 {
1890 using (FileStream fs = File.Create(path)) 1976 using (FileStream fs = File.Create(path))
1891 { 1977 {
1978// m_log.DebugFormat("[XEngine]: Writing assembly file {0}", path);
1979
1892 fs.Write(filedata, 0, filedata.Length); 1980 fs.Write(filedata, 0, filedata.Length);
1893 fs.Close();
1894 } 1981 }
1895 } 1982 }
1896 catch (IOException ex) 1983 catch (IOException ex)
1897 { 1984 {
1898 // if there already exists a file at that location, it may be locked. 1985 // if there already exists a file at that location, it may be locked.
1899 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 1986 m_log.ErrorFormat("[XEngine]: Error whilst writing assembly file {0}, {1}", path, ex.Message);
1900 } 1987 }
1988
1989 string textpath = path + ".text";
1901 try 1990 try
1902 { 1991 {
1903 using (FileStream fs = File.Create(path + ".text")) 1992 using (FileStream fs = File.Create(textpath))
1904 { 1993 {
1905 using (StreamWriter sw = new StreamWriter(fs)) 1994 using (StreamWriter sw = new StreamWriter(fs))
1906 { 1995 {
1996// m_log.DebugFormat("[XEngine]: Writing .text file {0}", textpath);
1997
1907 sw.Write(base64); 1998 sw.Write(base64);
1908 sw.Close();
1909 } 1999 }
1910 fs.Close();
1911 } 2000 }
1912 } 2001 }
1913 catch (IOException ex) 2002 catch (IOException ex)
1914 { 2003 {
1915 // if there already exists a file at that location, it may be locked. 2004 // if there already exists a file at that location, it may be locked.
1916 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 2005 m_log.ErrorFormat("[XEngine]: Error whilst writing .text file {0}, {1}", textpath, ex.Message);
2006 }
2007 }
2008
2009 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
2010 if (mapL.Count > 0)
2011 {
2012 XmlElement mapE = (XmlElement)mapL[0];
2013
2014 string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
2015 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
2016
2017 try
2018 {
2019 using (FileStream mfs = File.Create(mappath))
2020 {
2021 using (StreamWriter msw = new StreamWriter(mfs))
2022 {
2023 // m_log.DebugFormat("[XEngine]: Writing linemap file {0}", mappath);
2024
2025 msw.Write(mapE.InnerText);
2026 }
2027 }
2028 }
2029 catch (IOException ex)
2030 {
2031 // if there already exists a file at that location, it may be locked.
2032 m_log.ErrorFormat("[XEngine]: Linemap file {0} already exists! {1}", mappath, ex.Message);
1917 } 2033 }
1918 } 2034 }
1919 } 2035 }
@@ -1927,43 +2043,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1927 { 2043 {
1928 using (StreamWriter ssw = new StreamWriter(sfs)) 2044 using (StreamWriter ssw = new StreamWriter(sfs))
1929 { 2045 {
2046// m_log.DebugFormat("[XEngine]: Writing state file {0}", statepath);
2047
1930 ssw.Write(stateE.OuterXml); 2048 ssw.Write(stateE.OuterXml);
1931 ssw.Close();
1932 } 2049 }
1933 sfs.Close();
1934 } 2050 }
1935 } 2051 }
1936 catch (IOException ex) 2052 catch (IOException ex)
1937 { 2053 {
1938 // if there already exists a file at that location, it may be locked. 2054 // if there already exists a file at that location, it may be locked.
1939 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); 2055 m_log.ErrorFormat("[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message);
1940 }
1941
1942 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
1943 if (mapL.Count > 0)
1944 {
1945 XmlElement mapE = (XmlElement)mapL[0];
1946
1947 string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
1948 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
1949
1950 try
1951 {
1952 using (FileStream mfs = File.Create(mappath))
1953 {
1954 using (StreamWriter msw = new StreamWriter(mfs))
1955 {
1956 msw.Write(mapE.InnerText);
1957 msw.Close();
1958 }
1959 mfs.Close();
1960 }
1961 }
1962 catch (IOException ex)
1963 {
1964 // if there already exists a file at that location, it may be locked.
1965 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
1966 }
1967 } 2056 }
1968 2057
1969 return true; 2058 return true;
@@ -1997,45 +2086,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1997 if (!topScripts.ContainsKey(si.LocalID)) 2086 if (!topScripts.ContainsKey(si.LocalID))
1998 topScripts[si.RootLocalID] = 0; 2087 topScripts[si.RootLocalID] = 0;
1999 2088
2000// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 2089 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
2001// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 2090 }
2002 2091 }
2003 // Execution time of the script adjusted by it's measurement period to make scripts started at
2004 // different times comparable.
2005// float adjustedExecutionTime
2006// = (float)si.MeasurementPeriodExecutionTime
2007// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod)
2008// / TimeSpan.TicksPerMillisecond;
2009
2010 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2011
2012 // Avoid divide by zerp
2013 if (ticksElapsed == 0)
2014 ticksElapsed = 1;
2015 2092
2016 // Scale execution time to the ideal 55 fps frame time for these reasons. 2093 return topScripts;
2017 // 2094 }
2018 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2019 // 'script execution time per frame', which is the original purpose of this value.
2020 //
2021 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2022 // it impossible to compare scripts.
2023 //
2024 // 3) Scaling the raw execution time to the time that the script has been running is better but
2025 // is still misleading since a script that has just been rezzed may appear to have been running
2026 // for much longer.
2027 //
2028 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2029 // since the figure does not represent actual execution time and very hard running scripts will
2030 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2031 float adjustedExecutionTime
2032 = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2033 2095
2034 topScripts[si.RootLocalID] += adjustedExecutionTime; 2096 public float GetScriptExecutionTime(List<UUID> itemIDs)
2097 {
2098 if (itemIDs == null|| itemIDs.Count == 0)
2099 {
2100 return 0.0f;
2101 }
2102 float time = 0.0f;
2103 long tickNow = Util.EnvironmentTickCount();
2104 IScriptInstance si;
2105 // Calculate the time for all scripts that this engine is executing
2106 // Ignore any others
2107 foreach (UUID id in itemIDs)
2108 {
2109 si = GetInstance(id);
2110 if (si != null && si.Running)
2111 {
2112 time += CalculateAdjustedExectionTime(si, tickNow);
2035 } 2113 }
2036 } 2114 }
2115 return time;
2116 }
2037 2117
2038 return topScripts; 2118 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
2119 {
2120 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2121
2122 // Avoid divide by zero
2123 if (ticksElapsed == 0)
2124 ticksElapsed = 1;
2125
2126 // Scale execution time to the ideal 55 fps frame time for these reasons.
2127 //
2128 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2129 // 'script execution time per frame', which is the original purpose of this value.
2130 //
2131 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2132 // it impossible to compare scripts.
2133 //
2134 // 3) Scaling the raw execution time to the time that the script has been running is better but
2135 // is still misleading since a script that has just been rezzed may appear to have been running
2136 // for much longer.
2137 //
2138 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2139 // since the figure does not represent actual execution time and very hard running scripts will
2140 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2141 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2039 } 2142 }
2040 2143
2041 public void SuspendScript(UUID itemID) 2144 public void SuspendScript(UUID itemID)
diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs
index b9ba4bc..faf746f 100644
--- a/OpenSim/Region/UserStatistics/WebStatsModule.cs
+++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs
@@ -90,7 +90,7 @@ namespace OpenSim.Region.UserStatistics
90 90
91 dbConn = new SqliteConnection("URI=file:LocalUserStatistics.db,version=3"); 91 dbConn = new SqliteConnection("URI=file:LocalUserStatistics.db,version=3");
92 dbConn.Open(); 92 dbConn.Open();
93 CheckAndUpdateDatabase(dbConn); 93 CreateTables(dbConn);
94 94
95 Prototype_distributor protodep = new Prototype_distributor(); 95 Prototype_distributor protodep = new Prototype_distributor();
96 Updater_distributor updatedep = new Updater_distributor(); 96 Updater_distributor updatedep = new Updater_distributor();
@@ -131,7 +131,7 @@ namespace OpenSim.Region.UserStatistics
131 } 131 }
132 } 132 }
133 133
134 public void ReceiveClassicSimStatsPacket(SimStats stats) 134 private void ReceiveClassicSimStatsPacket(SimStats stats)
135 { 135 {
136 if (!enabled) 136 if (!enabled)
137 { 137 {
@@ -163,7 +163,7 @@ namespace OpenSim.Region.UserStatistics
163 } 163 }
164 } 164 }
165 165
166 public Hashtable HandleUnknownCAPSRequest(Hashtable request) 166 private Hashtable HandleUnknownCAPSRequest(Hashtable request)
167 { 167 {
168 //string regpath = request["uri"].ToString(); 168 //string regpath = request["uri"].ToString();
169 int response_code = 200; 169 int response_code = 200;
@@ -178,7 +178,7 @@ namespace OpenSim.Region.UserStatistics
178 return responsedata; 178 return responsedata;
179 } 179 }
180 180
181 public Hashtable HandleStatsRequest(Hashtable request) 181 private Hashtable HandleStatsRequest(Hashtable request)
182 { 182 {
183 lastHit = System.Environment.TickCount; 183 lastHit = System.Environment.TickCount;
184 Hashtable responsedata = new Hashtable(); 184 Hashtable responsedata = new Hashtable();
@@ -237,36 +237,12 @@ namespace OpenSim.Region.UserStatistics
237 237
238 return responsedata; 238 return responsedata;
239 } 239 }
240
241 public void CheckAndUpdateDatabase(SqliteConnection db)
242 {
243 lock (db)
244 {
245 // TODO: FIXME: implement stats migrations
246 const string SQL = @"SELECT * FROM migrations LIMIT 1";
247
248 using (SqliteCommand cmd = new SqliteCommand(SQL, db))
249 {
250 try
251 {
252 cmd.ExecuteNonQuery();
253 }
254 catch (SqliteSyntaxException)
255 {
256 CreateTables(db);
257 }
258 }
259 }
260 }
261 240
262 public void CreateTables(SqliteConnection db) 241 private void CreateTables(SqliteConnection db)
263 { 242 {
264 using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db)) 243 using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db))
265 { 244 {
266 createcmd.ExecuteNonQuery(); 245 createcmd.ExecuteNonQuery();
267
268 createcmd.CommandText = SQL_MIGRA_TABLE_CREATE;
269 createcmd.ExecuteNonQuery();
270 } 246 }
271 } 247 }
272 248
@@ -301,22 +277,23 @@ namespace OpenSim.Region.UserStatistics
301 get { return true; } 277 get { return true; }
302 } 278 }
303 279
304 public void OnRegisterCaps(UUID agentID, Caps caps) 280 private void OnRegisterCaps(UUID agentID, Caps caps)
305 { 281 {
306// m_log.DebugFormat("[WEB STATS MODULE]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 282// m_log.DebugFormat("[WEB STATS MODULE]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
307 283
308 string capsPath = "/CAPS/VS/" + UUID.Random(); 284 string capsPath = "/CAPS/VS/" + UUID.Random();
309 caps.RegisterHandler("ViewerStats", 285 caps.RegisterHandler(
310 new RestStreamHandler("POST", capsPath, 286 "ViewerStats",
311 delegate(string request, string path, string param, 287 new RestStreamHandler(
312 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 288 "POST",
313 { 289 capsPath,
314 return ViewerStatsReport(request, path, param, 290 (request, path, param, httpRequest, httpResponse)
315 agentID, caps); 291 => ViewerStatsReport(request, path, param, agentID, caps),
316 })); 292 "ViewerStats",
293 agentID.ToString()));
317 } 294 }
318 295
319 public void OnDeRegisterCaps(UUID agentID, Caps caps) 296 private void OnDeRegisterCaps(UUID agentID, Caps caps)
320 { 297 {
321 } 298 }
322 299
@@ -336,7 +313,7 @@ namespace OpenSim.Region.UserStatistics
336 } 313 }
337 } 314 }
338 315
339 public void OnMakeRootAgent(ScenePresence agent) 316 private void OnMakeRootAgent(ScenePresence agent)
340 { 317 {
341 UUID regionUUID = GetRegionUUIDFromHandle(agent.RegionHandle); 318 UUID regionUUID = GetRegionUUIDFromHandle(agent.RegionHandle);
342 319
@@ -365,11 +342,11 @@ namespace OpenSim.Region.UserStatistics
365 } 342 }
366 } 343 }
367 344
368 public void OnMakeChildAgent(ScenePresence agent) 345 private void OnMakeChildAgent(ScenePresence agent)
369 { 346 {
370 } 347 }
371 348
372 public void OnClientClosed(UUID agentID, Scene scene) 349 private void OnClientClosed(UUID agentID, Scene scene)
373 { 350 {
374 lock (m_sessions) 351 lock (m_sessions)
375 { 352 {
@@ -380,7 +357,7 @@ namespace OpenSim.Region.UserStatistics
380 } 357 }
381 } 358 }
382 359
383 public string readLogLines(int amount) 360 private string readLogLines(int amount)
384 { 361 {
385 Encoding encoding = Encoding.ASCII; 362 Encoding encoding = Encoding.ASCII;
386 int sizeOfChar = encoding.GetByteCount("\n"); 363 int sizeOfChar = encoding.GetByteCount("\n");
@@ -418,7 +395,7 @@ namespace OpenSim.Region.UserStatistics
418 return encoding.GetString(buffer); 395 return encoding.GetString(buffer);
419 } 396 }
420 397
421 public UUID GetRegionUUIDFromHandle(ulong regionhandle) 398 private UUID GetRegionUUIDFromHandle(ulong regionhandle)
422 { 399 {
423 lock (m_scenes) 400 lock (m_scenes)
424 { 401 {
@@ -441,17 +418,17 @@ namespace OpenSim.Region.UserStatistics
441 /// <param name="agentID"></param> 418 /// <param name="agentID"></param>
442 /// <param name="caps"></param> 419 /// <param name="caps"></param>
443 /// <returns></returns> 420 /// <returns></returns>
444 public string ViewerStatsReport(string request, string path, string param, 421 private string ViewerStatsReport(string request, string path, string param,
445 UUID agentID, Caps caps) 422 UUID agentID, Caps caps)
446 { 423 {
447// m_log.DebugFormat("[WEB STATS MODULE]: Received viewer starts report from {0}", agentID); 424// m_log.DebugFormat("[WEB STATS MODULE]: Received viewer starts report from {0}", agentID);
448 425
449 UpdateUserStats(ParseViewerStats(request,agentID), dbConn); 426 UpdateUserStats(ParseViewerStats(request, agentID), dbConn);
450 427
451 return String.Empty; 428 return String.Empty;
452 } 429 }
453 430
454 public UserSessionID ParseViewerStats(string request, UUID agentID) 431 private UserSessionID ParseViewerStats(string request, UUID agentID)
455 { 432 {
456 UserSessionID uid = new UserSessionID(); 433 UserSessionID uid = new UserSessionID();
457 UserSessionData usd; 434 UserSessionData usd;
@@ -592,14 +569,14 @@ namespace OpenSim.Region.UserStatistics
592 return uid; 569 return uid;
593 } 570 }
594 571
595 public void UpdateUserStats(UserSessionID uid, SqliteConnection db) 572 private void UpdateUserStats(UserSessionID uid, SqliteConnection db)
596 { 573 {
597 if (uid.session_id == UUID.Zero) 574 if (uid.session_id == UUID.Zero)
598 return; 575 return;
599 576
600 lock (db) 577 lock (db)
601 { 578 {
602 using (SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_UPDATE, db)) 579 using (SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_INSERT, db))
603 { 580 {
604 updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString())); 581 updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString()));
605 updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString())); 582 updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString()));
@@ -648,44 +625,26 @@ namespace OpenSim.Region.UserStatistics
648 updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped)); 625 updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped));
649 updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends)); 626 updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends));
650 updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid)); 627 updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid));
651
652 updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit)); 628 updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit));
653 updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent)); 629 updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent));
654 updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet)); 630 updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet));
655
656 updatecmd.Parameters.Add(new SqliteParameter(":session_key", uid.session_data.session_id.ToString()));
657 updatecmd.Parameters.Add(new SqliteParameter(":agent_key", uid.session_data.agent_id.ToString()));
658 updatecmd.Parameters.Add(new SqliteParameter(":region_key", uid.session_data.region_id.ToString()));
659 631
660// m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id); 632// StringBuilder parameters = new StringBuilder();
661 633// SqliteParameterCollection spc = updatecmd.Parameters;
662 int result = updatecmd.ExecuteNonQuery(); 634// foreach (SqliteParameter sp in spc)
663 635// parameters.AppendFormat("{0}={1},", sp.ParameterName, sp.Value);
664 if (result == 0) 636//
665 { 637// m_log.DebugFormat("[WEB STATS MODULE]: Parameters {0}", parameters);
666// m_log.DebugFormat("[WEB STATS MODULE]: Database stats insert for {0}", uid.session_data.agent_id);
667 638
668 updatecmd.CommandText = SQL_STATS_TABLE_INSERT; 639// m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id);
669 640
670 try 641 updatecmd.ExecuteNonQuery();
671 {
672 updatecmd.ExecuteNonQuery();
673 }
674 catch (Exception e)
675 {
676 m_log.WarnFormat(
677 "[WEB STATS MODULE]: failed to write stats for {0}, storage Execution Exception {1}{2}",
678 uid.session_data.agent_id, e.Message, e.StackTrace);
679 }
680 }
681 } 642 }
682 } 643 }
683 } 644 }
684 645
685 #region SQL 646 #region SQL
686 private const string SQL_MIGRA_TABLE_CREATE = @"create table migrations(name varchar(100), version int)"; 647 private const string SQL_STATS_TABLE_CREATE = @"CREATE TABLE IF NOT EXISTS stats_session_data (
687
688 private const string SQL_STATS_TABLE_CREATE = @"CREATE TABLE stats_session_data (
689 session_id VARCHAR(36) NOT NULL PRIMARY KEY, 648 session_id VARCHAR(36) NOT NULL PRIMARY KEY,
690 agent_id VARCHAR(36) NOT NULL DEFAULT '', 649 agent_id VARCHAR(36) NOT NULL DEFAULT '',
691 region_id VARCHAR(36) NOT NULL DEFAULT '', 650 region_id VARCHAR(36) NOT NULL DEFAULT '',
@@ -735,11 +694,11 @@ namespace OpenSim.Region.UserStatistics
735 f_send_packet INT NOT NULL DEFAULT '0' 694 f_send_packet INT NOT NULL DEFAULT '0'
736 );"; 695 );";
737 696
738 private const string SQL_STATS_TABLE_INSERT = @"INSERT INTO stats_session_data ( 697 private const string SQL_STATS_TABLE_INSERT = @"INSERT OR REPLACE INTO stats_session_data (
739session_id, agent_id, region_id, last_updated, remote_ip, name_f, name_l, avg_agents_in_view, min_agents_in_view, max_agents_in_view, 698session_id, agent_id, region_id, last_updated, remote_ip, name_f, name_l, avg_agents_in_view, min_agents_in_view, max_agents_in_view,
740mode_agents_in_view, avg_fps, min_fps, max_fps, mode_fps, a_language, mem_use, meters_traveled, avg_ping, min_ping, max_ping, mode_ping, 699mode_agents_in_view, avg_fps, min_fps, max_fps, mode_fps, a_language, mem_use, meters_traveled, avg_ping, min_ping, max_ping, mode_ping,
741regions_visited, run_time, avg_sim_fps, min_sim_fps, max_sim_fps, mode_sim_fps, start_time, client_version, s_cpu, s_gpu, s_os, s_ram, 700regions_visited, run_time, avg_sim_fps, min_sim_fps, max_sim_fps, mode_sim_fps, start_time, client_version, s_cpu, s_gpu, s_os, s_ram,
742d_object_kb, d_texture_kb, n_in_kb, n_in_pk, n_out_kb, n_out_pk, f_dropped, f_failed_resends, f_invalid, f_invalid, f_off_circuit, 701d_object_kb, d_texture_kb, d_world_kb, n_in_kb, n_in_pk, n_out_kb, n_out_pk, f_dropped, f_failed_resends, f_invalid, f_off_circuit,
743f_resent, f_send_packet 702f_resent, f_send_packet
744) 703)
745VALUES 704VALUES
@@ -747,62 +706,13 @@ VALUES
747:session_id, :agent_id, :region_id, :last_updated, :remote_ip, :name_f, :name_l, :avg_agents_in_view, :min_agents_in_view, :max_agents_in_view, 706:session_id, :agent_id, :region_id, :last_updated, :remote_ip, :name_f, :name_l, :avg_agents_in_view, :min_agents_in_view, :max_agents_in_view,
748:mode_agents_in_view, :avg_fps, :min_fps, :max_fps, :mode_fps, :a_language, :mem_use, :meters_traveled, :avg_ping, :min_ping, :max_ping, :mode_ping, 707:mode_agents_in_view, :avg_fps, :min_fps, :max_fps, :mode_fps, :a_language, :mem_use, :meters_traveled, :avg_ping, :min_ping, :max_ping, :mode_ping,
749:regions_visited, :run_time, :avg_sim_fps, :min_sim_fps, :max_sim_fps, :mode_sim_fps, :start_time, :client_version, :s_cpu, :s_gpu, :s_os, :s_ram, 708:regions_visited, :run_time, :avg_sim_fps, :min_sim_fps, :max_sim_fps, :mode_sim_fps, :start_time, :client_version, :s_cpu, :s_gpu, :s_os, :s_ram,
750:d_object_kb, :d_texture_kb, :n_in_kb, :n_in_pk, :n_out_kb, :n_out_pk, :f_dropped, :f_failed_resends, :f_invalid, :f_invalid, :f_off_circuit, 709:d_object_kb, :d_texture_kb, :d_world_kb, :n_in_kb, :n_in_pk, :n_out_kb, :n_out_pk, :f_dropped, :f_failed_resends, :f_invalid, :f_off_circuit,
751:f_resent, :f_send_packet 710:f_resent, :f_send_packet
752) 711)
753"; 712";
754 713
755 private const string SQL_STATS_TABLE_UPDATE = @" 714 #endregion
756UPDATE stats_session_data 715
757set session_id=:session_id,
758 agent_id=:agent_id,
759 region_id=:region_id,
760 last_updated=:last_updated,
761 remote_ip=:remote_ip,
762 name_f=:name_f,
763 name_l=:name_l,
764 avg_agents_in_view=:avg_agents_in_view,
765 min_agents_in_view=:min_agents_in_view,
766 max_agents_in_view=:max_agents_in_view,
767 mode_agents_in_view=:mode_agents_in_view,
768 avg_fps=:avg_fps,
769 min_fps=:min_fps,
770 max_fps=:max_fps,
771 mode_fps=:mode_fps,
772 a_language=:a_language,
773 mem_use=:mem_use,
774 meters_traveled=:meters_traveled,
775 avg_ping=:avg_ping,
776 min_ping=:min_ping,
777 max_ping=:max_ping,
778 mode_ping=:mode_ping,
779 regions_visited=:regions_visited,
780 run_time=:run_time,
781 avg_sim_fps=:avg_sim_fps,
782 min_sim_fps=:min_sim_fps,
783 max_sim_fps=:max_sim_fps,
784 mode_sim_fps=:mode_sim_fps,
785 start_time=:start_time,
786 client_version=:client_version,
787 s_cpu=:s_cpu,
788 s_gpu=:s_gpu,
789 s_os=:s_os,
790 s_ram=:s_ram,
791 d_object_kb=:d_object_kb,
792 d_texture_kb=:d_texture_kb,
793 d_world_kb=:d_world_kb,
794 n_in_kb=:n_in_kb,
795 n_in_pk=:n_in_pk,
796 n_out_kb=:n_out_kb,
797 n_out_pk=:n_out_pk,
798 f_dropped=:f_dropped,
799 f_failed_resends=:f_failed_resends,
800 f_invalid=:f_invalid,
801 f_off_circuit=:f_off_circuit,
802 f_resent=:f_resent,
803 f_send_packet=:f_send_packet
804WHERE session_id=:session_key AND agent_id=:agent_key AND region_id=:region_key";
805 #endregion
806 } 716 }
807 717
808 public static class UserSessionUtil 718 public static class UserSessionUtil