aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs140
-rw-r--r--OpenSim/Region/Framework/Interfaces/IDialogModule.cs5
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityInventory.cs5
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs (renamed from OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs)46
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs8
-rw-r--r--OpenSim/Region/Framework/Interfaces/IFriendsModule.cs16
-rw-r--r--OpenSim/Region/Framework/Interfaces/IGroupsMessagingModule.cs73
-rw-r--r--OpenSim/Region/Framework/Interfaces/IGroupsModule.cs39
-rw-r--r--OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs (renamed from OpenSim/Region/Framework/Interfaces/ITeleportModule.cs)16
-rw-r--r--OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs4
-rw-r--r--OpenSim/Region/Framework/Interfaces/IPresenceModule.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs12
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs4
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionModule.cs3
-rw-r--r--OpenSim/Region/Framework/Interfaces/IScriptModule.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs13
-rw-r--r--OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs5
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs55
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs265
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs174
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs77
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs391
-rw-r--r--OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs3
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs825
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs73
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs1175
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs28
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs1243
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs407
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs33
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs85
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs153
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs138
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs315
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs1
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs1
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs5
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs3
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs14
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/StandaloneTeleportTests.cs9
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs6
-rw-r--r--OpenSim/Region/Framework/Scenes/UuidGatherer.cs48
45 files changed, 1765 insertions, 4201 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
new file mode 100644
index 0000000..958847b
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
@@ -0,0 +1,140 @@
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 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.Xml;
30using OpenMetaverse;
31using OpenMetaverse.Packets;
32using OpenSim.Framework;
33using OpenSim.Region.Framework.Scenes;
34
35namespace OpenSim.Region.Framework.Interfaces
36{
37 public interface IAttachmentsModule
38 {
39 /// <summary>
40 /// Attach an object to an avatar from the world.
41 /// </summary>
42 /// <param name="controllingClient"></param>
43 /// <param name="localID"></param>
44 /// <param name="attachPoint"></param>
45 /// <param name="rot"></param>
46 /// <param name="silent"></param>
47 void AttachObject(
48 IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, bool silent);
49
50 /// <summary>
51 /// Attach an object to an avatar.
52 /// </summary>
53 /// <param name="controllingClient"></param>
54 /// <param name="localID"></param>
55 /// <param name="attachPoint"></param>
56 /// <param name="rot"></param>
57 /// <param name="attachPos"></param>
58 /// <param name="silent"></param>
59 /// <returns>true if the object was successfully attached, false otherwise</returns>
60 bool AttachObject(
61 IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, Vector3 attachPos, bool silent);
62
63 /// <summary>
64 /// Rez an attachment from user inventory and change inventory status to match.
65 /// </summary>
66 /// <param name="remoteClient"></param>
67 /// <param name="itemID"></param>
68 /// <param name="AttachmentPt"></param>
69 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
70 UUID RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt);
71
72 /// <summary>
73 /// Rez an attachment from user inventory
74 /// </summary>
75 /// <param name="remoteClient"></param>
76 /// <param name="itemID"></param>
77 /// <param name="AttachmentPt"></param>
78 /// <param name="updateinventoryStatus">
79 /// If true, we also update the user's inventory to show that the attachment is set. If false, we do not.
80 /// False is required so that we don't attempt to update information when a user enters a scene with the
81 /// attachment already correctly set up in inventory.
82 /// <returns>The uuid of the scene object that was attached. Null if the scene object could not be found</returns>
83 UUID RezSingleAttachmentFromInventory(
84 IClientAPI remoteClient, UUID itemID, uint AttachmentPt, bool updateInventoryStatus);
85
86 // Same as above, but also load script states from a separate doc
87 UUID RezSingleAttachmentFromInventory(
88 IClientAPI remoteClient, UUID itemID, uint AttachmentPt, bool updateInventoryStatus, XmlDocument doc);
89
90 /// <summary>
91 /// Rez multiple attachments from a user's inventory
92 /// </summary>
93 /// <param name="remoteClient"></param>
94 /// <param name="header"></param>
95 /// <param name="objects"></param>
96 void RezMultipleAttachmentsFromInventory(
97 IClientAPI remoteClient,
98 RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
99 RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects);
100
101 /// <summary>
102 /// Detach an object from the avatar.
103 /// </summary>
104 ///
105 /// This method is called in response to a client's detach request, so we only update the information in
106 /// inventory
107 /// <param name="objectLocalID"></param>
108 /// <param name="remoteClient"></param>
109 void DetachObject(uint objectLocalID, IClientAPI remoteClient);
110
111 /// <summary>
112 /// Detach the given item to the ground.
113 /// </summary>
114 /// <param name="itemID"></param>
115 /// <param name="remoteClient"></param>
116 void DetachSingleAttachmentToGround(UUID itemID, IClientAPI remoteClient);
117
118 /// <summary>
119 /// Update the user inventory to the attachment of an item
120 /// </summary>
121 /// <param name="att"></param>
122 /// <param name="remoteClient"></param>
123 /// <param name="itemID"></param>
124 /// <param name="AttachmentPt"></param>
125 /// <returns></returns>
126 UUID SetAttachmentInventoryStatus(
127 SceneObjectGroup att, IClientAPI remoteClient, UUID itemID, uint AttachmentPt);
128
129 /// <summary>
130 /// Update the user inventory to show a detach.
131 /// </summary>
132 /// <param name="itemID">
133 /// A <see cref="UUID"/>
134 /// </param>
135 /// <param name="remoteClient">
136 /// A <see cref="IClientAPI"/>
137 /// </param>
138 void ShowDetachInUserInventory(UUID itemID, IClientAPI remoteClient);
139 }
140}
diff --git a/OpenSim/Region/Framework/Interfaces/IDialogModule.cs b/OpenSim/Region/Framework/Interfaces/IDialogModule.cs
index ce57c44..35b4b63 100644
--- a/OpenSim/Region/Framework/Interfaces/IDialogModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IDialogModule.cs
@@ -131,5 +131,10 @@ namespace OpenSim.Region.Framework.Interfaces
131 /// <param name="fromAvatarName">The name of the user doing the sending</param> 131 /// <param name="fromAvatarName">The name of the user doing the sending</param>
132 /// <param name="message">The message being sent to the user</param> 132 /// <param name="message">The message being sent to the user</param>
133 void SendNotificationToUsersInEstate(UUID fromAvatarID, string fromAvatarName, string message); 133 void SendNotificationToUsersInEstate(UUID fromAvatarID, string fromAvatarName, string message);
134
135 /// <summary>
136 /// Send a textbox entry for the client to respond to
137 /// </summary>
138 void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid);
134 } 139 }
135} 140}
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
index 16ca3f9..1e2f60b 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
@@ -73,6 +73,9 @@ namespace OpenSim.Region.Framework.Interfaces
73 /// </summary> 73 /// </summary>
74 void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource); 74 void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource);
75 75
76 ArrayList GetScriptErrors(UUID itemID);
77 void ResumeScripts();
78
76 /// <summary> 79 /// <summary>
77 /// Stop all the scripts in this entity. 80 /// Stop all the scripts in this entity.
78 /// </summary> 81 /// </summary>
@@ -160,6 +163,7 @@ namespace OpenSim.Region.Framework.Interfaces
160 /// in this prim's inventory.</param> 163 /// in this prim's inventory.</param>
161 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 164 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
162 bool UpdateInventoryItem(TaskInventoryItem item); 165 bool UpdateInventoryItem(TaskInventoryItem item);
166 bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents);
163 167
164 /// <summary> 168 /// <summary>
165 /// Remove an item from this entity's inventory 169 /// Remove an item from this entity's inventory
@@ -212,5 +216,6 @@ namespace OpenSim.Region.Framework.Interfaces
212 /// A <see cref="Dictionary`2"/> 216 /// A <see cref="Dictionary`2"/>
213 /// </returns> 217 /// </returns>
214 Dictionary<UUID, string> GetScriptStates(); 218 Dictionary<UUID, string> GetScriptStates();
219 Dictionary<UUID, string> GetScriptStates(bool oldIDs);
215 } 220 }
216} 221}
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
index 5d4e7ac..e8738c4 100644
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
@@ -26,31 +26,35 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
30
31using OpenSim.Framework;
32using OpenSim.Services.Interfaces; 29using OpenSim.Services.Interfaces;
30using GridRegion = OpenSim.Services.Interfaces.GridRegion;
31
33using OpenMetaverse; 32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Scenes;
34 35
35namespace OpenSim.Region.Framework.Scenes.Hypergrid 36namespace OpenSim.Region.Framework.Interfaces
36{ 37{
37 public class HGUuidGatherer : UuidGatherer 38 public interface IEntityTransferModule
39 {
40 void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position,
41 Vector3 lookAt, uint teleportFlags);
42
43 void TeleportHome(UUID id, IClientAPI client);
44
45 void Cross(ScenePresence agent, bool isFlying);
46
47 void AgentArrivedAtDestination(UUID agent);
48
49 void EnableChildAgents(ScenePresence agent);
50
51 void EnableChildAgent(ScenePresence agent, GridRegion region);
52
53 void Cross(SceneObjectGroup sog, Vector3 position, bool silent);
54 }
55
56 public interface IUserAgentVerificationModule
38 { 57 {
39 protected string m_assetServerURL; 58 bool VerifyClient(AgentCircuitData aCircuit, string token);
40 protected HGAssetMapper m_assetMapper;
41
42 public HGUuidGatherer(HGAssetMapper assMap, IAssetService assetCache, string assetServerURL) : base(assetCache)
43 {
44 m_assetMapper = assMap;
45 m_assetServerURL = assetServerURL;
46 }
47
48 protected override AssetBase GetAsset(UUID uuid)
49 {
50 if (string.Empty == m_assetServerURL)
51 return m_assetCache.Get(uuid.ToString());
52 else
53 return m_assetMapper.FetchAsset(m_assetServerURL, uuid);
54 }
55 } 59 }
56} 60}
diff --git a/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs b/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs
index 668ff98..87c7a05 100644
--- a/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs
@@ -25,6 +25,7 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System.Collections.Generic;
28using OpenMetaverse; 29using OpenMetaverse;
29using OpenSim.Framework; 30using OpenSim.Framework;
30 31
@@ -34,7 +35,12 @@ namespace OpenSim.Region.Framework.Interfaces
34 { 35 {
35 void Initialise(string connectstring); 36 void Initialise(string connectstring);
36 37
37 EstateSettings LoadEstateSettings(UUID regionID); 38 EstateSettings LoadEstateSettings(UUID regionID, bool create);
39 EstateSettings LoadEstateSettings(int estateID);
38 void StoreEstateSettings(EstateSettings es); 40 void StoreEstateSettings(EstateSettings es);
41 List<int> GetEstates(string search);
42 bool LinkRegion(UUID regionID, int estateID);
43 List<UUID> GetRegions(int estateID);
44 bool DeleteEstate(int estateID);
39 } 45 }
40} 46}
diff --git a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs
index 8386030..0ff7dee 100644
--- a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs
@@ -33,19 +33,7 @@ namespace OpenSim.Region.Framework.Interfaces
33{ 33{
34 public interface IFriendsModule 34 public interface IFriendsModule
35 { 35 {
36 /// <summary> 36 uint GetFriendPerms(UUID PrincipalID, UUID FriendID);
37 /// Offer a friendship to a user from the server end rather than by direct initiation from a client. 37 void SendFriendsOnlineIfNeeded(IClientAPI client);
38 /// </summary>
39 /// <param name="fromUserId">
40 /// A user with this id must existing in the user data store, but need not be logged on.
41 /// </param>
42 /// <param name="toUserClient">
43 /// An actually logged in client to which the offer is being made.
44 /// FIXME: This is somewhat too tightly coupled - it should arguably be possible to offer friendships even if the
45 /// receiving user is not currently online.
46 /// </param>
47 /// <param name="offerMessage"></param>
48 void OfferFriendship(UUID fromUserId, IClientAPI toUserClient, string offerMessage);
49 List<FriendListItem> GetUserFriends(UUID agentID);
50 } 38 }
51} 39}
diff --git a/OpenSim/Region/Framework/Interfaces/IGroupsMessagingModule.cs b/OpenSim/Region/Framework/Interfaces/IGroupsMessagingModule.cs
new file mode 100644
index 0000000..f158236
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IGroupsMessagingModule.cs
@@ -0,0 +1,73 @@
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;
29using OpenSim.Framework;
30
31namespace OpenSim.Region.Framework.Interfaces
32{
33 /// <summary>
34 /// Provide mechanisms for messaging groups.
35 /// </summary>
36 ///
37 /// TODO: Provide a mechanism for receiving group messages as well as sending them
38 ///
39 public interface IGroupsMessagingModule
40 {
41 /// <summary>
42 /// Start a group chat session.
43 /// </summary>
44 /// You must call this before calling SendMessageToGroup(). If a chat session for this group is already taking
45 /// place then the agent will added to that session.
46 /// <param name="agentID">
47 /// A UUID that represents the agent being added. If you are agentless (e.g. you are
48 /// a region module), then you can use any random ID.
49 /// </param>
50 /// <param name="groupID">
51 /// The ID for the group to join. Currently, the session ID used is identical to the
52 /// group ID.
53 /// </param>
54 /// <returns>
55 /// True if the chat session was started successfully, false otherwise.
56 /// </returns>
57 bool StartGroupChatSession(UUID agentID, UUID groupID);
58
59 /// <summary>
60 /// Send a message to an entire group.
61 /// </summary>
62 /// <param name="im">
63 /// The message itself. The fields that must be populated are
64 ///
65 /// imSessionID - Populate this with the group ID (session ID and group ID are currently identical)
66 /// fromAgentName - Populate this with whatever arbitrary name you want to show up in the chat dialog
67 /// message - The message itself
68 /// dialog - This must be (byte)InstantMessageDialog.SessionSend
69 /// </param>
70 /// <param name="groupID"></param>
71 void SendMessageToGroup(GridInstantMessage im, UUID groupID);
72 }
73} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs b/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs
index 8980b2d..2c091e7 100644
--- a/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs
@@ -37,21 +37,51 @@ namespace OpenSim.Region.Framework.Interfaces
37 { 37 {
38 event NewGroupNotice OnNewGroupNotice; 38 event NewGroupNotice OnNewGroupNotice;
39 39
40 /// <summary>
41 /// Create a group
42 /// </summary>
43 /// <param name="remoteClient"></param>
44 /// <param name="name"></param>
45 /// <param name="charter"></param>
46 /// <param name="showInList"></param>
47 /// <param name="insigniaID"></param>
48 /// <param name="membershipFee"></param>
49 /// <param name="openEnrollment"></param>
50 /// <param name="allowPublish"></param>
51 /// <param name="maturePublish"></param>
52 /// <returns>The UUID of the created group</returns>
53 UUID CreateGroup(
54 IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee,
55 bool openEnrollment, bool allowPublish, bool maturePublish);
56
57 /// <summary>
58 /// Get a group
59 /// </summary>
60 /// <param name="name">Name of the group</param>
61 /// <returns>The group's data. Null if there is no such group.</returns>
62 GroupRecord GetGroupRecord(string name);
63
64 /// <summary>
65 /// Get a group
66 /// </summary>
67 /// <param name="GroupID">ID of the group</param>
68 /// <returns>The group's data. Null if there is no such group.</returns>
69 GroupRecord GetGroupRecord(UUID GroupID);
70
40 void ActivateGroup(IClientAPI remoteClient, UUID groupID); 71 void ActivateGroup(IClientAPI remoteClient, UUID groupID);
41 List<GroupTitlesData> GroupTitlesRequest(IClientAPI remoteClient, UUID groupID); 72 List<GroupTitlesData> GroupTitlesRequest(IClientAPI remoteClient, UUID groupID);
42 List<GroupMembersData> GroupMembersRequest(IClientAPI remoteClient, UUID groupID); 73 List<GroupMembersData> GroupMembersRequest(IClientAPI remoteClient, UUID groupID);
43 List<GroupRolesData> GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID); 74 List<GroupRolesData> GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID);
44 List<GroupRoleMembersData> GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID); 75 List<GroupRoleMembersData> GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID);
45 GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID); 76 GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID);
46 GroupMembershipData[] GetMembershipData(UUID UserID); 77 GroupMembershipData[] GetMembershipData(UUID UserID);
47 GroupMembershipData GetMembershipData(UUID GroupID, UUID UserID); 78 GroupMembershipData GetMembershipData(UUID GroupID, UUID UserID);
48 79
49 void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish); 80 void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish);
50 81
51 void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile); 82 void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile);
52 83
53 void GroupTitleUpdate(IClientAPI remoteClient, UUID GroupID, UUID TitleRoleID); 84 void GroupTitleUpdate(IClientAPI remoteClient, UUID GroupID, UUID TitleRoleID);
54 UUID CreateGroup(IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish);
55 85
56 GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID GroupID); 86 GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID GroupID);
57 string GetGroupTitle(UUID avatarID); 87 string GetGroupTitle(UUID avatarID);
@@ -64,7 +94,6 @@ namespace OpenSim.Region.Framework.Interfaces
64 void LeaveGroupRequest(IClientAPI remoteClient, UUID GroupID); 94 void LeaveGroupRequest(IClientAPI remoteClient, UUID GroupID);
65 void EjectGroupMemberRequest(IClientAPI remoteClient, UUID GroupID, UUID EjecteeID); 95 void EjectGroupMemberRequest(IClientAPI remoteClient, UUID GroupID, UUID EjecteeID);
66 void InviteGroupRequest(IClientAPI remoteClient, UUID GroupID, UUID InviteeID, UUID RoleID); 96 void InviteGroupRequest(IClientAPI remoteClient, UUID GroupID, UUID InviteeID, UUID RoleID);
67 GroupRecord GetGroupRecord(UUID GroupID);
68 void NotifyChange(UUID GroupID); 97 void NotifyChange(UUID GroupID);
69 } 98 }
70} 99} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Interfaces/ITeleportModule.cs b/OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs
index 5f9129d..8185258 100644
--- a/OpenSim/Region/Framework/Interfaces/ITeleportModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IInventoryAccessModule.cs
@@ -27,15 +27,21 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30
31using OpenMetaverse; 31using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes; 32using OpenSim.Region.Framework.Scenes;
33 33
34using OpenMetaverse;
35
34namespace OpenSim.Region.Framework.Interfaces 36namespace OpenSim.Region.Framework.Interfaces
35{ 37{
36 public interface ITeleportModule 38 public interface IInventoryAccessModule
37 { 39 {
38 void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position, 40 UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data);
39 Vector3 lookAt, uint teleportFlags); 41 UUID DeleteToInventory(DeRezAction action, UUID folderID, SceneObjectGroup objectGroup, IClientAPI remoteClient);
42 SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
43 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
44 bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment);
45 void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver);
40 } 46 }
41} 47}
diff --git a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs
index 2d038ce..fbadd91 100644
--- a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs
@@ -27,7 +27,7 @@
27 27
28using System; 28using System;
29using System.IO; 29using System.IO;
30using OpenSim.Framework.Communications.Cache; 30using OpenSim.Services.Interfaces;
31 31
32namespace OpenSim.Region.Framework.Interfaces 32namespace OpenSim.Region.Framework.Interfaces
33{ 33{
@@ -41,7 +41,7 @@ namespace OpenSim.Region.Framework.Interfaces
41 /// <param name="savePath">The stream to which the archive was saved</param> 41 /// <param name="savePath">The stream to which the archive was saved</param>
42 /// <param name="reportedException">Contains the exception generated if the save did not succeed</param> 42 /// <param name="reportedException">Contains the exception generated if the save did not succeed</param>
43 public delegate void InventoryArchiveSaved( 43 public delegate void InventoryArchiveSaved(
44 Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException); 44 Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, Exception reportedException);
45 45
46 public interface IInventoryArchiverModule 46 public interface IInventoryArchiverModule
47 { 47 {
diff --git a/OpenSim/Region/Framework/Interfaces/IPresenceModule.cs b/OpenSim/Region/Framework/Interfaces/IPresenceModule.cs
index 630c6a3..d44c1e1 100644
--- a/OpenSim/Region/Framework/Interfaces/IPresenceModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IPresenceModule.cs
@@ -31,13 +31,13 @@ namespace OpenSim.Region.Framework.Interfaces
31{ 31{
32 public struct PresenceInfo 32 public struct PresenceInfo
33 { 33 {
34 public UUID userID; 34 public string UserID;
35 public UUID regionID; 35 public UUID RegionID;
36 36
37 public PresenceInfo(UUID userID, UUID regionID) 37 public PresenceInfo(string userID, UUID regionID)
38 { 38 {
39 this.userID = userID; 39 UserID = userID;
40 this.regionID = regionID; 40 RegionID = regionID;
41 } 41 }
42 } 42 }
43 43
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
index 991d60c..89e59d0 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
@@ -90,8 +90,12 @@ namespace OpenSim.Region.Framework.Interfaces
90 /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region 90 /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region
91 /// settings in the archive will be ignored. 91 /// settings in the archive will be ignored.
92 /// </param> 92 /// </param>
93 /// <param name="skipAssets">
94 /// If true, the archive is loaded without loading any assets contained within it. This is useful if the
95 /// assets are already known to be present in the grid's asset service.
96 /// </param>
93 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> 97 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
94 void DearchiveRegion(string loadPath, bool merge, Guid requestId); 98 void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId);
95 99
96 /// <summary> 100 /// <summary>
97 /// Dearchive a region from a stream. This replaces the existing scene. 101 /// Dearchive a region from a stream. This replaces the existing scene.
@@ -113,7 +117,11 @@ namespace OpenSim.Region.Framework.Interfaces
113 /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region 117 /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region
114 /// settings in the archive will be ignored. 118 /// settings in the archive will be ignored.
115 /// </param> 119 /// </param>
120 /// <param name="skipAssets">
121 /// If true, the archive is loaded without loading any assets contained within it. This is useful if the
122 /// assets are already known to be present in the grid's asset service.
123 /// </param
116 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> 124 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
117 void DearchiveRegion(Stream loadStream, bool merge, Guid requestId); 125 void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId);
118 } 126 }
119} 127}
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
index 7312799..3e8e196 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
@@ -103,8 +103,8 @@ namespace OpenSim.Region.Framework.Interfaces
103 103
104 void StoreRegionSettings(RegionSettings rs); 104 void StoreRegionSettings(RegionSettings rs);
105 RegionSettings LoadRegionSettings(UUID regionUUID); 105 RegionSettings LoadRegionSettings(UUID regionUUID);
106 RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID); 106 RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID);
107 void StoreRegionWindlightSettings(RegionMeta7WindlightData wl); 107 void StoreRegionWindlightSettings(RegionLightShareData wl);
108 108
109 void Shutdown(); 109 void Shutdown();
110 } 110 }
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionModule.cs
index 8eb906c..e25a6e8 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionModule.cs
@@ -30,6 +30,9 @@ using OpenSim.Region.Framework.Scenes;
30 30
31namespace OpenSim.Region.Framework.Interfaces 31namespace OpenSim.Region.Framework.Interfaces
32{ 32{
33 /// <summary>
34 /// DEPRECATED! Use INonSharedRegionModule or ISharedRegionModule instead
35 /// </summary>
33 public interface IRegionModule 36 public interface IRegionModule
34 { 37 {
35 void Initialise(Scene scene, IConfigSource source); 38 void Initialise(Scene scene, IConfigSource source);
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
index e90b300..fecdd1b 100644
--- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
@@ -41,6 +41,14 @@ namespace OpenSim.Region.Framework.Interfaces
41 bool PostScriptEvent(UUID itemID, string name, Object[] args); 41 bool PostScriptEvent(UUID itemID, string name, Object[] args);
42 bool PostObjectEvent(UUID itemID, string name, Object[] args); 42 bool PostObjectEvent(UUID itemID, string name, Object[] args);
43 43
44 // Suspend ALL scripts in a given scene object. The item ID
45 // is the UUID of a SOG, and the method acts on all contained
46 // scripts. This is different from the suspend/resume that
47 // can be issued by a client.
48 //
49 void SuspendScript(UUID itemID);
50 void ResumeScript(UUID itemID);
51
44 ArrayList GetScriptErrors(UUID itemID); 52 ArrayList GetScriptErrors(UUID itemID);
45 } 53 }
46} 54}
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index be0e985..31ca2ab 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -385,7 +385,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
385 } 385 }
386 } 386 }
387 387
388 AssetBase Animasset = new AssetBase(UUID.Random(), "Random Animation", (sbyte)AssetType.Animation); 388 AssetBase Animasset = new AssetBase(UUID.Random(), "Random Animation", (sbyte)AssetType.Animation, m_scenePresence.UUID.ToString());
389 Animasset.Data = anim.ToBytes(); 389 Animasset.Data = anim.ToBytes();
390 Animasset.Temporary = true; 390 Animasset.Temporary = true;
391 Animasset.Local = true; 391 Animasset.Local = true;
@@ -420,11 +420,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation
420 if (m_scenePresence.IsChildAgent) 420 if (m_scenePresence.IsChildAgent)
421 return; 421 return;
422 422
423 m_scenePresence.Scene.ForEachScenePresence( 423 UUID[] animIDs;
424 delegate(ScenePresence SP) 424 int[] sequenceNums;
425 { 425 UUID[] objectIDs;
426 SP.Animator.SendAnimPack(); 426
427 }); 427 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
428 client.SendAnimations(animIDs, sequenceNums, m_scenePresence.ControllingClient.AgentId, objectIDs);
428 } 429 }
429 430
430 /// <summary> 431 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs b/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
index 9a7863b..c08b961 100644
--- a/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
+++ b/OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs
@@ -32,6 +32,7 @@ using System.Timers;
32using log4net; 32using log4net;
33using OpenMetaverse; 33using OpenMetaverse;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
35 36
36namespace OpenSim.Region.Framework.Scenes 37namespace OpenSim.Region.Framework.Scenes
37{ 38{
@@ -137,7 +138,9 @@ namespace OpenSim.Region.Framework.Scenes
137 138
138 try 139 try
139 { 140 {
140 m_scene.DeleteToInventory(x.action, x.folderID, x.objectGroup, x.remoteClient); 141 IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
142 if (invAccess != null)
143 invAccess.DeleteToInventory(x.action, x.folderID, x.objectGroup, x.remoteClient);
141 if (x.permissionToDelete) 144 if (x.permissionToDelete)
142 m_scene.DeleteSceneObject(x.objectGroup, false); 145 m_scene.DeleteSceneObject(x.objectGroup, false);
143 } 146 }
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 7fb1cd8..ef125cd 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -66,13 +66,16 @@ namespace OpenSim.Region.Framework.Scenes
66 public event OnClientConnectCoreDelegate OnClientConnect; 66 public event OnClientConnectCoreDelegate OnClientConnect;
67 67
68 public delegate void OnNewClientDelegate(IClientAPI client); 68 public delegate void OnNewClientDelegate(IClientAPI client);
69 69
70 /// <summary> 70 /// <summary>
71 /// Deprecated in favour of OnClientConnect. 71 /// Deprecated in favour of OnClientConnect.
72 /// Will be marked Obsolete after IClientCore has 100% of IClientAPI interfaces. 72 /// Will be marked Obsolete after IClientCore has 100% of IClientAPI interfaces.
73 /// </summary> 73 /// </summary>
74 public event OnNewClientDelegate OnNewClient; 74 public event OnNewClientDelegate OnNewClient;
75 75
76 public delegate void OnClientLoginDelegate(IClientAPI client);
77 public event OnClientLoginDelegate OnClientLogin;
78
76 public delegate void OnNewPresenceDelegate(ScenePresence presence); 79 public delegate void OnNewPresenceDelegate(ScenePresence presence);
77 80
78 public event OnNewPresenceDelegate OnNewPresence; 81 public event OnNewPresenceDelegate OnNewPresence;
@@ -107,12 +110,12 @@ namespace OpenSim.Region.Framework.Scenes
107 public event OnSetRootAgentSceneDelegate OnSetRootAgentScene; 110 public event OnSetRootAgentSceneDelegate OnSetRootAgentScene;
108 111
109 /// <summary> 112 /// <summary>
110 /// Called when an object is touched/grabbed. 113 /// Fired when an object is touched/grabbed.
111 /// </summary> 114 /// </summary>
112 /// The originalID is the local ID of the part that was actually touched. The localID itself is always that of 115 /// The originalID is the local ID of the part that was actually touched. The localID itself is always that of
113 /// the root part. 116 /// the root part.
114 public delegate void ObjectGrabDelegate(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs);
115 public event ObjectGrabDelegate OnObjectGrab; 117 public event ObjectGrabDelegate OnObjectGrab;
118 public delegate void ObjectGrabDelegate(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs);
116 119
117 public event ObjectGrabDelegate OnObjectGrabbing; 120 public event ObjectGrabDelegate OnObjectGrabbing;
118 public event ObjectDeGrabDelegate OnObjectDeGrab; 121 public event ObjectDeGrabDelegate OnObjectDeGrab;
@@ -120,8 +123,11 @@ namespace OpenSim.Region.Framework.Scenes
120 123
121 public event OnPermissionErrorDelegate OnPermissionError; 124 public event OnPermissionErrorDelegate OnPermissionError;
122 125
123 public delegate void NewRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource); 126 /// <summary>
127 /// Fired when a new script is created.
128 /// </summary>
124 public event NewRezScript OnRezScript; 129 public event NewRezScript OnRezScript;
130 public delegate void NewRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource);
125 131
126 public delegate void RemoveScript(uint localID, UUID itemID); 132 public delegate void RemoveScript(uint localID, UUID itemID);
127 public event RemoveScript OnRemoveScript; 133 public event RemoveScript OnRemoveScript;
@@ -165,36 +171,33 @@ namespace OpenSim.Region.Framework.Scenes
165 171
166 public event ClientClosed OnClientClosed; 172 public event ClientClosed OnClientClosed;
167 173
168 public delegate void ScriptChangedEvent(uint localID, uint change); 174 /// <summary>
169 175 /// This is fired when a scene object property that a script might be interested in (such as color, scale or
176 /// inventory) changes. Only enough information is sent for the LSL changed event
177 /// (see http://lslwiki.net/lslwiki/wakka.php?wakka=changed)
178 /// </summary>
170 public event ScriptChangedEvent OnScriptChangedEvent; 179 public event ScriptChangedEvent OnScriptChangedEvent;
180 public delegate void ScriptChangedEvent(uint localID, uint change);
171 181
172 public delegate void ScriptControlEvent(uint localID, UUID item, UUID avatarID, uint held, uint changed); 182 public delegate void ScriptControlEvent(uint localID, UUID item, UUID avatarID, uint held, uint changed);
173
174 public event ScriptControlEvent OnScriptControlEvent; 183 public event ScriptControlEvent OnScriptControlEvent;
175 184
176 public delegate void ScriptAtTargetEvent(uint localID, uint handle, Vector3 targetpos, Vector3 atpos); 185 public delegate void ScriptAtTargetEvent(uint localID, uint handle, Vector3 targetpos, Vector3 atpos);
177
178 public event ScriptAtTargetEvent OnScriptAtTargetEvent; 186 public event ScriptAtTargetEvent OnScriptAtTargetEvent;
179 187
180 public delegate void ScriptNotAtTargetEvent(uint localID); 188 public delegate void ScriptNotAtTargetEvent(uint localID);
181
182 public event ScriptNotAtTargetEvent OnScriptNotAtTargetEvent; 189 public event ScriptNotAtTargetEvent OnScriptNotAtTargetEvent;
183 190
184 public delegate void ScriptAtRotTargetEvent(uint localID, uint handle, Quaternion targetrot, Quaternion atrot); 191 public delegate void ScriptAtRotTargetEvent(uint localID, uint handle, Quaternion targetrot, Quaternion atrot);
185
186 public event ScriptAtRotTargetEvent OnScriptAtRotTargetEvent; 192 public event ScriptAtRotTargetEvent OnScriptAtRotTargetEvent;
187 193
188 public delegate void ScriptNotAtRotTargetEvent(uint localID); 194 public delegate void ScriptNotAtRotTargetEvent(uint localID);
189
190 public event ScriptNotAtRotTargetEvent OnScriptNotAtRotTargetEvent; 195 public event ScriptNotAtRotTargetEvent OnScriptNotAtRotTargetEvent;
191 196
192 public delegate void ScriptColliding(uint localID, ColliderArgs colliders); 197 public delegate void ScriptColliding(uint localID, ColliderArgs colliders);
193
194 public event ScriptColliding OnScriptColliderStart; 198 public event ScriptColliding OnScriptColliderStart;
195 public event ScriptColliding OnScriptColliding; 199 public event ScriptColliding OnScriptColliding;
196 public event ScriptColliding OnScriptCollidingEnd; 200 public event ScriptColliding OnScriptCollidingEnd;
197
198 public event ScriptColliding OnScriptLandColliderStart; 201 public event ScriptColliding OnScriptLandColliderStart;
199 public event ScriptColliding OnScriptLandColliding; 202 public event ScriptColliding OnScriptLandColliding;
200 public event ScriptColliding OnScriptLandColliderEnd; 203 public event ScriptColliding OnScriptLandColliderEnd;
@@ -204,7 +207,7 @@ namespace OpenSim.Region.Framework.Scenes
204 207
205 public delegate void OnMakeRootAgentDelegate(ScenePresence presence); 208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence);
206 public delegate void OnSaveNewWindlightProfileDelegate(); 209 public delegate void OnSaveNewWindlightProfileDelegate();
207 public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionMeta7WindlightData wl, UUID user); 210 public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionLightShareData wl, UUID user);
208 public event OnMakeRootAgentDelegate OnMakeRootAgent; 211 public event OnMakeRootAgentDelegate OnMakeRootAgent;
209 public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted; 212 public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted;
210 public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile; 213 public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile;
@@ -587,6 +590,28 @@ namespace OpenSim.Region.Framework.Scenes
587 } 590 }
588 } 591 }
589 592
593 public void TriggerOnClientLogin(IClientAPI client)
594 {
595 OnClientLoginDelegate handlerClientLogin = OnClientLogin;
596 if (handlerClientLogin != null)
597 {
598 foreach (OnClientLoginDelegate d in handlerClientLogin.GetInvocationList())
599 {
600 try
601 {
602 d(client);
603 }
604 catch (Exception e)
605 {
606 m_log.ErrorFormat(
607 "[EVENT MANAGER]: Delegate for TriggerOnClientLogin failed - continuing. {0} {1}",
608 e.Message, e.StackTrace);
609 }
610 }
611 }
612
613 }
614
590 public void TriggerOnNewPresence(ScenePresence presence) 615 public void TriggerOnNewPresence(ScenePresence presence)
591 { 616 {
592 OnNewPresenceDelegate handlerNewPresence = OnNewPresence; 617 OnNewPresenceDelegate handlerNewPresence = OnNewPresence;
@@ -1195,7 +1220,7 @@ namespace OpenSim.Region.Framework.Scenes
1195 } 1220 }
1196 } 1221 }
1197 1222
1198 public void TriggerOnSendNewWindlightProfileTargeted(RegionMeta7WindlightData wl, UUID user) 1223 public void TriggerOnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID user)
1199 { 1224 {
1200 OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted; 1225 OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted;
1201 if (handlerSendNewWindlightProfileTargeted != null) 1226 if (handlerSendNewWindlightProfileTargeted != null)
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs
deleted file mode 100644
index ec50598..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs
+++ /dev/null
@@ -1,265 +0,0 @@
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.Threading;
32using log4net;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Framework.Communications.Clients;
37using OpenSim.Region.Framework.Scenes.Serialization;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Services.Interfaces;
40
41//using HyperGrid.Framework;
42//using OpenSim.Region.Communications.Hypergrid;
43
44namespace OpenSim.Region.Framework.Scenes.Hypergrid
45{
46 public class HGAssetMapper
47 {
48 #region Fields
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 // This maps between inventory server urls and inventory server clients
52// private Dictionary<string, InventoryClient> m_inventoryServers = new Dictionary<string, InventoryClient>();
53
54 private Scene m_scene;
55
56 private IHyperAssetService m_hyper;
57 IHyperAssetService HyperlinkAssets
58 {
59 get
60 {
61 if (m_hyper == null)
62 m_hyper = m_scene.RequestModuleInterface<IHyperAssetService>();
63 return m_hyper;
64 }
65 }
66
67 #endregion
68
69 #region Constructor
70
71 public HGAssetMapper(Scene scene)
72 {
73 m_scene = scene;
74 }
75
76 #endregion
77
78 #region Internal functions
79
80// private string UserAssetURL(UUID userID)
81// {
82// CachedUserInfo uinfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
83// if (uinfo != null)
84// return (uinfo.UserProfile.UserAssetURI == "") ? null : uinfo.UserProfile.UserAssetURI;
85// return null;
86// }
87
88// private string UserInventoryURL(UUID userID)
89// {
90// CachedUserInfo uinfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
91// if (uinfo != null)
92// return (uinfo.UserProfile.UserInventoryURI == "") ? null : uinfo.UserProfile.UserInventoryURI;
93// return null;
94// }
95
96
97 public AssetBase FetchAsset(string url, UUID assetID)
98 {
99 AssetBase asset = m_scene.AssetService.Get(url + "/" + assetID.ToString());
100
101 if (asset != null)
102 {
103 m_log.DebugFormat("[HGScene]: Copied asset {0} from {1} to local asset server. ", asset.ID, url);
104 return asset;
105 }
106 return null;
107 }
108
109 public bool PostAsset(string url, AssetBase asset)
110 {
111 if (asset != null)
112 {
113 // See long comment in AssetCache.AddAsset
114 if (!asset.Temporary || asset.Local)
115 {
116 // We need to copy the asset into a new asset, because
117 // we need to set its ID to be URL+UUID, so that the
118 // HGAssetService dispatches it to the remote grid.
119 // It's not pretty, but the best that can be done while
120 // not having a global naming infrastructure
121 AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type);
122 Copy(asset, asset1);
123 try
124 {
125 asset1.ID = url + "/" + asset.ID;
126 }
127 catch
128 {
129 m_log.Warn("[HGScene]: Oops.");
130 }
131
132 m_scene.AssetService.Store(asset1);
133 m_log.DebugFormat("[HGScene]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url);
134 }
135 return true;
136 }
137 else
138 m_log.Warn("[HGScene]: Tried to post asset to remote server, but asset not in local cache.");
139
140 return false;
141 }
142
143 private void Copy(AssetBase from, AssetBase to)
144 {
145 to.Data = from.Data;
146 to.Description = from.Description;
147 to.FullID = from.FullID;
148 to.ID = from.ID;
149 to.Local = from.Local;
150 to.Name = from.Name;
151 to.Temporary = from.Temporary;
152 to.Type = from.Type;
153
154 }
155
156 // TODO: unused
157 // private void Dump(Dictionary<UUID, bool> lst)
158 // {
159 // m_log.Debug("XXX -------- UUID DUMP ------- XXX");
160 // foreach (KeyValuePair<UUID, bool> kvp in lst)
161 // m_log.Debug(" >> " + kvp.Key + " (texture? " + kvp.Value + ")");
162 // m_log.Debug("XXX -------- UUID DUMP ------- XXX");
163 // }
164
165 #endregion
166
167
168 #region Public interface
169
170 public void Get(UUID assetID, UUID ownerID)
171 {
172 // Get the item from the remote asset server onto the local AssetCache
173 // and place an entry in m_assetMap
174
175 string userAssetURL = HyperlinkAssets.GetUserAssetServer(ownerID);
176 if ((userAssetURL != string.Empty) && (userAssetURL != HyperlinkAssets.GetSimAssetServer()))
177 {
178 m_log.Debug("[HGScene]: Fetching object " + assetID + " from asset server " + userAssetURL);
179 AssetBase asset = FetchAsset(userAssetURL, assetID);
180
181 if (asset != null)
182 {
183 // OK, now fetch the inside.
184 Dictionary<UUID, int> ids = new Dictionary<UUID, int>();
185 HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, userAssetURL);
186 uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids);
187 foreach (UUID uuid in ids.Keys)
188 FetchAsset(userAssetURL, uuid);
189
190 m_log.DebugFormat("[HGScene]: Successfully fetched asset {0} from asset server {1}", asset.ID, userAssetURL);
191
192 }
193 else
194 m_log.Warn("[HGScene]: Could not fetch asset from remote asset server " + userAssetURL);
195 }
196 else
197 m_log.Debug("[HGScene]: user's asset server is the local region's asset server");
198 }
199
200 //public InventoryItemBase Get(InventoryItemBase item, UUID rootFolder, CachedUserInfo userInfo)
201 //{
202 // InventoryClient invCli = null;
203 // string inventoryURL = UserInventoryURL(item.Owner);
204 // if (!m_inventoryServers.TryGetValue(inventoryURL, out invCli))
205 // {
206 // m_log.Debug("[HGScene]: Starting new InventorytClient for " + inventoryURL);
207 // invCli = new InventoryClient(inventoryURL);
208 // m_inventoryServers.Add(inventoryURL, invCli);
209 // }
210
211 // item = invCli.GetInventoryItem(item);
212 // if (item != null)
213 // {
214 // // Change the folder, stick it in root folder, all items flattened out here in this region cache
215 // item.Folder = rootFolder;
216 // //userInfo.AddItem(item); don't use this, it calls back to the inventory server
217 // lock (userInfo.RootFolder.Items)
218 // {
219 // userInfo.RootFolder.Items[item.ID] = item;
220 // }
221
222 // }
223 // return item;
224 //}
225
226 public void Post(UUID assetID, UUID ownerID)
227 {
228 // Post the item from the local AssetCache onto the remote asset server
229 // and place an entry in m_assetMap
230
231 string userAssetURL = HyperlinkAssets.GetUserAssetServer(ownerID);
232 if ((userAssetURL != string.Empty) && (userAssetURL != HyperlinkAssets.GetSimAssetServer()))
233 {
234 m_log.Debug("[HGScene]: Posting object " + assetID + " to asset server " + userAssetURL);
235 AssetBase asset = m_scene.AssetService.Get(assetID.ToString());
236 if (asset != null)
237 {
238 Dictionary<UUID, int> ids = new Dictionary<UUID, int>();
239 HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, string.Empty);
240 uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids);
241 foreach (UUID uuid in ids.Keys)
242 {
243 asset = m_scene.AssetService.Get(uuid.ToString());
244 if (asset == null)
245 m_log.DebugFormat("[HGScene]: Could not find asset {0}", uuid);
246 else
247 PostAsset(userAssetURL, asset);
248 }
249
250 // maybe all pieces got there...
251 m_log.DebugFormat("[HGScene]: Successfully posted item {0} to asset server {1}", assetID, userAssetURL);
252
253 }
254 else
255 m_log.DebugFormat("[HGScene]: Something wrong with asset {0}, it could not be found", assetID);
256 }
257 else
258 m_log.Debug("[HGScene]: user's asset server is local region's asset server");
259
260 }
261
262 #endregion
263
264 }
265}
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs
deleted file mode 100644
index 6f7f34f..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs
+++ /dev/null
@@ -1,174 +0,0 @@
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.Reflection;
29using log4net;
30using Nini.Config;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Framework.Communications;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Region.Framework.Interfaces;
36
37namespace OpenSim.Region.Framework.Scenes.Hypergrid
38{
39 public partial class HGScene : Scene
40 {
41 #region Fields
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 private HGAssetMapper m_assMapper;
45 public HGAssetMapper AssetMapper
46 {
47 get { return m_assMapper; }
48 }
49
50 private IHyperAssetService m_hyper;
51 private IHyperAssetService HyperAssets
52 {
53 get
54 {
55 if (m_hyper == null)
56 m_hyper = RequestModuleInterface<IHyperAssetService>();
57 return m_hyper;
58 }
59 }
60
61 #endregion
62
63 #region Constructors
64
65 public HGScene(RegionInfo regInfo, AgentCircuitManager authen,
66 CommunicationsManager commsMan, SceneCommunicationService sceneGridService,
67 StorageManager storeManager,
68 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim,
69 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
70 : base(regInfo, authen, commsMan, sceneGridService, storeManager, moduleLoader,
71 dumpAssetsToFile, physicalPrim, SeeIntoRegionFromNeighbor, config, simulatorVersion)
72 {
73 m_log.Info("[HGScene]: Starting HGScene.");
74 m_assMapper = new HGAssetMapper(this);
75
76 EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem;
77 }
78
79 #endregion
80
81 #region Event handlers
82
83 public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel)
84 {
85 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(avatarID);
86 if (userInfo != null)
87 {
88 m_assMapper.Post(assetID, avatarID);
89 }
90 }
91
92 #endregion
93
94 #region Overrides of Scene.Inventory methods
95
96 ///
97 /// CapsUpdateInventoryItemAsset
98 ///
99 public override UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
100 {
101 UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data);
102
103 UploadInventoryItem(remoteClient.AgentId, newAssetID, "", 0);
104
105 return newAssetID;
106 }
107
108 ///
109 /// DeleteToInventory
110 ///
111 public override UUID DeleteToInventory(DeRezAction action, UUID folderID, SceneObjectGroup objectGroup, IClientAPI remoteClient)
112 {
113 UUID assetID = base.DeleteToInventory(action, folderID, objectGroup, remoteClient);
114
115 if (!assetID.Equals(UUID.Zero))
116 {
117 UploadInventoryItem(remoteClient.AgentId, assetID, "", 0);
118 }
119 else
120 m_log.Debug("[HGScene]: Scene.Inventory did not create asset");
121
122 return assetID;
123 }
124
125 ///
126 /// RezObject
127 ///
128 public override SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
129 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
130 bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
131 {
132 m_log.DebugFormat("[HGScene] RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID);
133
134 //if (fromTaskID.Equals(UUID.Zero))
135 //{
136 InventoryItemBase item = new InventoryItemBase(itemID);
137 item.Owner = remoteClient.AgentId;
138 item = InventoryService.GetItem(item);
139 //if (item == null)
140 //{ // Fetch the item
141 // item = new InventoryItemBase();
142 // item.Owner = remoteClient.AgentId;
143 // item.ID = itemID;
144 // item = m_assMapper.Get(item, userInfo.RootFolder.ID, userInfo);
145 //}
146 if (item != null)
147 {
148 m_assMapper.Get(item.AssetID, remoteClient.AgentId);
149
150 }
151 //}
152
153 // OK, we're done fetching. Pass it up to the default RezObject
154 return base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
155 RezSelected, RemoveItem, fromTaskID, attachment);
156
157 }
158
159 protected override void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
160 {
161 string userAssetServer = HyperAssets.GetUserAssetServer(sender);
162 if ((userAssetServer != string.Empty) && (userAssetServer != HyperAssets.GetSimAssetServer()))
163 m_assMapper.Get(item.AssetID, sender);
164
165 userAssetServer = HyperAssets.GetUserAssetServer(receiver);
166 if ((userAssetServer != string.Empty) && (userAssetServer != HyperAssets.GetSimAssetServer()))
167 m_assMapper.Post(item.AssetID, receiver);
168 }
169
170 #endregion
171
172 }
173
174}
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs
deleted file mode 100644
index b1981b6..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs
+++ /dev/null
@@ -1,77 +0,0 @@
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;
29using OpenSim.Framework;
30using OpenSim.Framework.Communications.Cache;
31using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
32using GridRegion = OpenSim.Services.Interfaces.GridRegion;
33
34namespace OpenSim.Region.Framework.Scenes.Hypergrid
35{
36 public partial class HGScene : Scene
37 {
38 /// <summary>
39 /// Teleport an avatar to their home region
40 /// </summary>
41 /// <param name="agentId"></param>
42 /// <param name="client"></param>
43 public override void TeleportClientHome(UUID agentId, IClientAPI client)
44 {
45 m_log.Debug("[HGScene]: TeleportClientHome " + client.FirstName + " " + client.LastName);
46
47 CachedUserInfo uinfo = CommsManager.UserProfileCacheService.GetUserDetails(agentId);
48 if (uinfo != null)
49 {
50 UserProfileData UserProfile = uinfo.UserProfile;
51
52 if (UserProfile != null)
53 {
54 GridRegion regionInfo = GridService.GetRegionByUUID(UUID.Zero, UserProfile.HomeRegionID);
55 //if (regionInfo != null)
56 //{
57 // UserProfile.HomeRegionID = regionInfo.RegionID;
58 // //CommsManager.UserService.UpdateUserProfile(UserProfile);
59 //}
60 if (regionInfo == null)
61 {
62 // can't find the Home region: Tell viewer and abort
63 client.SendTeleportFailed("Your home-region could not be found.");
64 return;
65 }
66 RequestTeleportLocation(
67 client, regionInfo.RegionHandle, UserProfile.HomeLocation, UserProfile.HomeLookAt,
68 (uint)(TPFlags.SetLastToTarget | TPFlags.ViaHome));
69 }
70 }
71 else
72 client.SendTeleportFailed("Sorry! I lost your home-region information.");
73
74 }
75
76 }
77}
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
deleted file mode 100644
index 416826c..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
+++ /dev/null
@@ -1,391 +0,0 @@
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 log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Client;
37using OpenSim.Framework.Communications;
38using OpenSim.Framework.Communications.Cache;
39using OpenSim.Framework.Capabilities;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Services.Interfaces;
42using GridRegion = OpenSim.Services.Interfaces.GridRegion;
43
44namespace OpenSim.Region.Framework.Scenes.Hypergrid
45{
46 public class HGSceneCommunicationService : SceneCommunicationService
47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IHyperlinkService m_hg;
51 IHyperlinkService HyperlinkService
52 {
53 get
54 {
55 if (m_hg == null)
56 m_hg = m_scene.RequestModuleInterface<IHyperlinkService>();
57 return m_hg;
58 }
59 }
60
61 public HGSceneCommunicationService(CommunicationsManager commsMan) : base(commsMan)
62 {
63 }
64
65
66 /// <summary>
67 /// Try to teleport an agent to a new region.
68 /// </summary>
69 /// <param name="remoteClient"></param>
70 /// <param name="RegionHandle"></param>
71 /// <param name="position"></param>
72 /// <param name="lookAt"></param>
73 /// <param name="flags"></param>
74 public override void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position,
75 Vector3 lookAt, uint teleportFlags)
76 {
77 if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID))
78 return;
79
80 bool destRegionUp = true;
81
82 IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
83
84 // Reset animations; the viewer does that in teleports.
85 avatar.Animator.ResetAnimations();
86
87 if (regionHandle == m_regionInfo.RegionHandle)
88 {
89 // Teleport within the same region
90 if (IsOutsideRegion(avatar.Scene, position) || position.Z < 0)
91 {
92 Vector3 emergencyPos = new Vector3(128, 128, 128);
93
94 m_log.WarnFormat(
95 "[HGSceneCommService]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
96 position, avatar.Name, avatar.UUID, emergencyPos);
97 position = emergencyPos;
98 }
99 // TODO: Get proper AVG Height
100 float localAVHeight = 1.56f;
101
102 float posZLimit = 22;
103
104 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize)
105 {
106 posZLimit = (float) avatar.Scene.Heightmap[(int) position.X, (int) position.Y];
107 }
108
109 float newPosZ = posZLimit + localAVHeight;
110 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
111 {
112 position.Z = newPosZ;
113 }
114
115 // Only send this if the event queue is null
116 if (eq == null)
117 avatar.ControllingClient.SendTeleportLocationStart();
118
119
120 avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
121 avatar.Teleport(position);
122 }
123 else
124 {
125 uint x = 0, y = 0;
126 Utils.LongToUInts(regionHandle, out x, out y);
127 GridRegion reg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
128
129 if (reg != null)
130 {
131
132 uint newRegionX = (uint)(reg.RegionHandle >> 40);
133 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
134 uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
135 uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
136
137 ///
138 /// Hypergrid mod start
139 ///
140 ///
141 bool isHyperLink = (HyperlinkService.GetHyperlinkRegion(reg.RegionHandle) != null);
142 bool isHomeUser = true;
143 ulong realHandle = regionHandle;
144 CachedUserInfo uinfo = m_commsProvider.UserProfileCacheService.GetUserDetails(avatar.UUID);
145 if (uinfo != null)
146 {
147 isHomeUser = HyperlinkService.IsLocalUser(uinfo.UserProfile.ID);
148 realHandle = m_hg.FindRegionHandle(regionHandle);
149 m_log.Debug("XXX ---- home user? " + isHomeUser + " --- hyperlink? " + isHyperLink + " --- real handle: " + realHandle.ToString());
150 }
151 ///
152 /// Hypergrid mod stop
153 ///
154 ///
155
156 if (eq == null)
157 avatar.ControllingClient.SendTeleportLocationStart();
158
159
160 // Let's do DNS resolution only once in this process, please!
161 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
162 // it's actually doing a lot of work.
163 IPEndPoint endPoint = reg.ExternalEndPoint;
164 if (endPoint.Address == null)
165 {
166 // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses.
167 destRegionUp = false;
168 }
169
170 if (destRegionUp)
171 {
172 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
173 // both regions
174 if (avatar.ParentID != (uint)0)
175 avatar.StandUp();
176
177 if (!avatar.ValidateAttachments())
178 {
179 avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
180 return;
181 }
182
183 // the avatar.Close below will clear the child region list. We need this below for (possibly)
184 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
185 //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
186 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
187 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
188 // once we reach here...
189 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
190
191 string capsPath = String.Empty;
192 AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo();
193 agentCircuit.BaseFolder = UUID.Zero;
194 agentCircuit.InventoryFolder = UUID.Zero;
195 agentCircuit.startpos = position;
196 agentCircuit.child = true;
197 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
198 {
199 // brand new agent, let's create a new caps seed
200 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
201 }
202
203 string reason = String.Empty;
204
205 //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
206 if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit, teleportFlags, out reason))
207 {
208 avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
209 reason));
210 return;
211 }
212
213 // Let's close some agents
214 if (isHyperLink) // close them all except this one
215 {
216 List<ulong> regions = new List<ulong>(avatar.KnownChildRegionHandles);
217 regions.Remove(avatar.Scene.RegionInfo.RegionHandle);
218 SendCloseChildAgentConnections(avatar.UUID, regions);
219 }
220 else // close just a few
221 avatar.CloseChildAgents(newRegionX, newRegionY);
222
223 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
224 {
225 capsPath
226 = "http://"
227 + reg.ExternalHostName
228 + ":"
229 + reg.HttpPort
230 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
231
232 if (eq != null)
233 {
234 #region IP Translation for NAT
235 IClientIPEndpoint ipepClient;
236 if (avatar.ClientView.TryGet(out ipepClient))
237 {
238 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
239 }
240 #endregion
241
242 eq.EnableSimulator(realHandle, endPoint, avatar.UUID);
243
244 // ES makes the client send a UseCircuitCode message to the destination,
245 // which triggers a bunch of things there.
246 // So let's wait
247 Thread.Sleep(2000);
248
249 eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath);
250 }
251 else
252 {
253 avatar.ControllingClient.InformClientOfNeighbour(realHandle, endPoint);
254 // TODO: make Event Queue disablable!
255 }
256 }
257 else
258 {
259 // child agent already there
260 agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle);
261 capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
262 + "/CAPS/" + agentCircuit.CapsPath + "0000/";
263 }
264
265 //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
266 // position, false);
267
268 //if (!m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
269 // position, false))
270 //{
271 // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
272 // // We should close that agent we just created over at destination...
273 // List<ulong> lst = new List<ulong>();
274 // lst.Add(realHandle);
275 // SendCloseChildAgentAsync(avatar.UUID, lst);
276 // return;
277 //}
278
279 SetInTransit(avatar.UUID);
280 // Let's send a full update of the agent. This is a synchronous call.
281 AgentData agent = new AgentData();
282 avatar.CopyTo(agent);
283 agent.Position = position;
284 agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
285 "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionHandle.ToString() + "/release/";
286
287 m_interregionCommsOut.SendChildAgentUpdate(reg.RegionHandle, agent);
288
289 m_log.DebugFormat(
290 "[CAPS]: Sending new CAPS seed url {0} to client {1}", agentCircuit.CapsPath, avatar.UUID);
291
292
293 ///
294 /// Hypergrid mod: realHandle instead of reg.RegionHandle
295 ///
296 ///
297 if (eq != null)
298 {
299 eq.TeleportFinishEvent(realHandle, 13, endPoint,
300 4, teleportFlags, capsPath, avatar.UUID);
301 }
302 else
303 {
304 avatar.ControllingClient.SendRegionTeleport(realHandle, 13, endPoint, 4,
305 teleportFlags, capsPath);
306 }
307 ///
308 /// Hypergrid mod stop
309 ///
310
311
312 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
313 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
314 // that the client contacted the destination before we send the attachments and close things here.
315 if (!WaitForCallback(avatar.UUID))
316 {
317 // Client never contacted destination. Let's restore everything back
318 avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
319
320 ResetFromTransit(avatar.UUID);
321 // Yikes! We should just have a ref to scene here.
322 avatar.Scene.InformClientOfNeighbours(avatar);
323
324 // Finally, kill the agent we just created at the destination.
325 m_interregionCommsOut.SendCloseAgent(reg.RegionHandle, avatar.UUID);
326
327 return;
328 }
329
330 // Can't go back from here
331 if (KiPrimitive != null)
332 {
333 KiPrimitive(avatar.LocalId);
334 }
335
336 avatar.MakeChildAgent();
337
338 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
339 avatar.CrossAttachmentsIntoNewRegion(reg.RegionHandle, true);
340
341
342 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
343 ///
344 /// Hypergrid mod: extra check for isHyperLink
345 ///
346 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
347 {
348 Thread.Sleep(5000);
349 avatar.Close();
350 CloseConnection(avatar.UUID);
351 }
352 // if (teleport success) // seems to be always success here
353 // the user may change their profile information in other region,
354 // so the userinfo in UserProfileCache is not reliable any more, delete it
355 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID) || isHyperLink)
356 {
357 m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID);
358 m_log.DebugFormat(
359 "[HGSceneCommService]: User {0} is going to another region, profile cache removed",
360 avatar.UUID);
361 }
362 }
363 else
364 {
365 avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
366 }
367 }
368 else
369 {
370 // TP to a place that doesn't exist (anymore)
371 // Inform the viewer about that
372 avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
373
374 // and set the map-tile to '(Offline)'
375 uint regX, regY;
376 Utils.LongToUInts(regionHandle, out regX, out regY);
377
378 MapBlockData block = new MapBlockData();
379 block.X = (ushort)(regX / Constants.RegionSize);
380 block.Y = (ushort)(regY / Constants.RegionSize);
381 block.Access = 254; // == not there
382
383 List<MapBlockData> blocks = new List<MapBlockData>();
384 blocks.Add(block);
385 avatar.ControllingClient.SendMapBlock(blocks, 0);
386 }
387 }
388 }
389
390 }
391}
diff --git a/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs b/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs
index e9660b1..d25d5dd 100644
--- a/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs
+++ b/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs
@@ -36,8 +36,7 @@ using OpenMetaverse;
36using OpenMetaverse.StructuredData; 36using OpenMetaverse.StructuredData;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications; 38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Communications.Services; 39
40using OpenSim.Framework.Communications.Cache;
41using OpenSim.Framework.Console; 40using OpenSim.Framework.Console;
42using OpenSim.Framework.Servers; 41using OpenSim.Framework.Servers;
43using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index a430bc4..90bce39 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -35,7 +35,6 @@ using OpenMetaverse;
35using OpenMetaverse.Packets; 35using OpenMetaverse.Packets;
36using log4net; 36using log4net;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications.Cache;
39using OpenSim.Region.Framework; 38using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes.Serialization; 40using OpenSim.Region.Framework.Scenes.Serialization;
@@ -64,6 +63,7 @@ namespace OpenSim.Region.Framework.Scenes
64 if (group is SceneObjectGroup) 63 if (group is SceneObjectGroup)
65 { 64 {
66 ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0); 65 ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
66 ((SceneObjectGroup) group).ResumeScripts();
67 } 67 }
68 } 68 }
69 } 69 }
@@ -101,12 +101,6 @@ namespace OpenSim.Region.Framework.Scenes
101 { 101 {
102 userlevel = 1; 102 userlevel = 1;
103 } 103 }
104 // TODO: remove this cruft once MasterAvatar is fully deprecated
105 //
106 if (m_regInfo.MasterAvatarAssignedUUID == AgentID)
107 {
108 userlevel = 2;
109 }
110 EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel); 104 EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel);
111 } 105 }
112 else 106 else
@@ -132,70 +126,17 @@ namespace OpenSim.Region.Framework.Scenes
132 } 126 }
133 127
134 /// <summary> 128 /// <summary>
135 /// Capability originating call to update the asset of an item in an agent's inventory
136 /// </summary>
137 /// <param name="remoteClient"></param>
138 /// <param name="itemID"></param>
139 /// <param name="data"></param>
140 /// <returns></returns>
141 public virtual UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
142 {
143 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
144 item = InventoryService.GetItem(item);
145
146 if (item != null)
147 {
148 if ((InventoryType)item.InvType == InventoryType.Notecard)
149 {
150 if (!Permissions.CanEditNotecard(itemID, UUID.Zero, remoteClient.AgentId))
151 {
152 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
153 return UUID.Zero;
154 }
155
156 remoteClient.SendAgentAlertMessage("Notecard saved", false);
157 }
158 else if ((InventoryType)item.InvType == InventoryType.LSL)
159 {
160 if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId))
161 {
162 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
163 return UUID.Zero;
164 }
165
166 remoteClient.SendAgentAlertMessage("Script saved", false);
167 }
168
169 AssetBase asset =
170 CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data);
171 item.AssetID = asset.FullID;
172 AssetService.Store(asset);
173
174 InventoryService.UpdateItem(item);
175
176 // remoteClient.SendInventoryItemCreateUpdate(item);
177 return (asset.FullID);
178 }
179 else
180 {
181 m_log.ErrorFormat(
182 "[AGENT INVENTORY]: Could not find item {0} for caps inventory update",
183 itemID);
184 }
185
186 return UUID.Zero;
187 }
188
189 /// <summary>
190 /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see> 129 /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
191 /// </summary> 130 /// </summary>
192 public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data) 131 public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data)
193 { 132 {
194 ScenePresence avatar; 133 ScenePresence avatar;
195 134
196 if (TryGetAvatar(avatarId, out avatar)) 135 if (TryGetScenePresence(avatarId, out avatar))
197 { 136 {
198 return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data); 137 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
138 if (invAccess != null)
139 return invAccess.CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
199 } 140 }
200 else 141 else
201 { 142 {
@@ -251,7 +192,7 @@ namespace OpenSim.Region.Framework.Scenes
251 return new ArrayList(); 192 return new ArrayList();
252 } 193 }
253 194
254 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data); 195 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId);
255 AssetService.Store(asset); 196 AssetService.Store(asset);
256 197
257 if (isScriptRunning) 198 if (isScriptRunning)
@@ -261,7 +202,9 @@ namespace OpenSim.Region.Framework.Scenes
261 202
262 // Update item with new asset 203 // Update item with new asset
263 item.AssetID = asset.FullID; 204 item.AssetID = asset.FullID;
264 group.UpdateInventoryItem(item); 205 if (group.UpdateInventoryItem(item))
206 remoteClient.SendAgentAlertMessage("Notecard saved", false);
207
265 part.GetProperties(remoteClient); 208 part.GetProperties(remoteClient);
266 209
267 // Trigger rerunning of script (use TriggerRezScript event, see RezScript) 210 // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
@@ -277,6 +220,7 @@ namespace OpenSim.Region.Framework.Scenes
277 { 220 {
278 remoteClient.SendAgentAlertMessage("Script saved", false); 221 remoteClient.SendAgentAlertMessage("Script saved", false);
279 } 222 }
223 part.ParentGroup.ResumeScripts();
280 return errors; 224 return errors;
281 } 225 }
282 226
@@ -288,7 +232,7 @@ namespace OpenSim.Region.Framework.Scenes
288 { 232 {
289 ScenePresence avatar; 233 ScenePresence avatar;
290 234
291 if (TryGetAvatar(avatarId, out avatar)) 235 if (TryGetScenePresence(avatarId, out avatar))
292 { 236 {
293 return CapsUpdateTaskInventoryScriptAsset( 237 return CapsUpdateTaskInventoryScriptAsset(
294 avatar.ControllingClient, itemId, primId, isScriptRunning, data); 238 avatar.ControllingClient, itemId, primId, isScriptRunning, data);
@@ -477,7 +421,11 @@ namespace OpenSim.Region.Framework.Scenes
477 itemCopy.SaleType = item.SaleType; 421 itemCopy.SaleType = item.SaleType;
478 422
479 if (InventoryService.AddItem(itemCopy)) 423 if (InventoryService.AddItem(itemCopy))
480 TransferInventoryAssets(itemCopy, senderId, recipient); 424 {
425 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
426 if (invAccess != null)
427 invAccess.TransferInventoryAssets(itemCopy, senderId, recipient);
428 }
481 429
482 if (!Permissions.BypassPermissions()) 430 if (!Permissions.BypassPermissions())
483 { 431 {
@@ -499,10 +447,6 @@ namespace OpenSim.Region.Framework.Scenes
499 447
500 } 448 }
501 449
502 protected virtual void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
503 {
504 }
505
506 /// <summary> 450 /// <summary>
507 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent 451 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
508 /// folders) is given. 452 /// folders) is given.
@@ -530,7 +474,6 @@ namespace OpenSim.Region.Framework.Scenes
530 return null; 474 return null;
531 } 475 }
532 476
533
534 if (recipientParentFolderId == UUID.Zero) 477 if (recipientParentFolderId == UUID.Zero)
535 { 478 {
536 InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId); 479 InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId);
@@ -572,7 +515,9 @@ namespace OpenSim.Region.Framework.Scenes
572 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}", 515 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
573 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName); 516 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
574 517
575 InventoryItemBase item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(oldItemID); 518 InventoryItemBase item = null;
519 if (LibraryService != null && LibraryService.LibraryRootFolder != null)
520 item = LibraryService.LibraryRootFolder.FindItem(oldItemID);
576 521
577 if (item == null) 522 if (item == null)
578 { 523 {
@@ -626,15 +571,9 @@ namespace OpenSim.Region.Framework.Scenes
626 /// <summary> 571 /// <summary>
627 /// Create a new asset data structure. 572 /// Create a new asset data structure.
628 /// </summary> 573 /// </summary>
629 /// <param name="name"></param> 574 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, UUID creatorID)
630 /// <param name="description"></param>
631 /// <param name="invType"></param>
632 /// <param name="assetType"></param>
633 /// <param name="data"></param>
634 /// <returns></returns>
635 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
636 { 575 {
637 AssetBase asset = new AssetBase(UUID.Random(), name, assetType); 576 AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID.ToString());
638 asset.Description = description; 577 asset.Description = description;
639 asset.Data = (data == null) ? new byte[1] : data; 578 asset.Data = (data == null) ? new byte[1] : data;
640 579
@@ -744,13 +683,9 @@ namespace OpenSim.Region.Framework.Scenes
744 683
745 if (transactionID == UUID.Zero) 684 if (transactionID == UUID.Zero)
746 { 685 {
747 CachedUserInfo userInfo 686 ScenePresence presence;
748 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 687 if (TryGetScenePresence(remoteClient.AgentId, out presence))
749
750 if (userInfo != null)
751 { 688 {
752 ScenePresence presence;
753 TryGetAvatar(remoteClient.AgentId, out presence);
754 byte[] data = null; 689 byte[] data = null;
755 690
756 if (invType == (sbyte)InventoryType.Landmark && presence != null) 691 if (invType == (sbyte)InventoryType.Landmark && presence != null)
@@ -764,7 +699,7 @@ namespace OpenSim.Region.Framework.Scenes
764 data = Encoding.ASCII.GetBytes(strdata); 699 data = Encoding.ASCII.GetBytes(strdata);
765 } 700 }
766 701
767 AssetBase asset = CreateAsset(name, description, assetType, data); 702 AssetBase asset = CreateAsset(name, description, assetType, data, remoteClient.AgentId);
768 AssetService.Store(asset); 703 AssetService.Store(asset);
769 704
770 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate); 705 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate);
@@ -772,7 +707,7 @@ namespace OpenSim.Region.Framework.Scenes
772 else 707 else
773 { 708 {
774 m_log.ErrorFormat( 709 m_log.ErrorFormat(
775 "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem", 710 "ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
776 remoteClient.AgentId); 711 remoteClient.AgentId);
777 } 712 }
778 } 713 }
@@ -788,6 +723,37 @@ namespace OpenSim.Region.Framework.Scenes
788 } 723 }
789 } 724 }
790 725
726 private void HandleLinkInventoryItem(IClientAPI remoteClient, UUID transActionID, UUID folderID,
727 uint callbackID, string description, string name,
728 sbyte invType, sbyte type, UUID olditemID)
729 {
730 m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item link {0} in folder {1} pointing to {2}", name, folderID, olditemID);
731
732 if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
733 return;
734
735 ScenePresence presence;
736 if (TryGetScenePresence(remoteClient.AgentId, out presence))
737 {
738 byte[] data = null;
739
740 AssetBase asset = new AssetBase();
741 asset.FullID = olditemID;
742 asset.Type = type;
743 asset.Name = name;
744 asset.Description = description;
745
746 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, name, 0, callbackID, asset, invType, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch());
747
748 }
749 else
750 {
751 m_log.ErrorFormat(
752 "ScenePresence for agent uuid {0} unexpectedly not found in HandleLinkInventoryItem",
753 remoteClient.AgentId);
754 }
755 }
756
791 /// <summary> 757 /// <summary>
792 /// Remove an inventory item for the client's inventory 758 /// Remove an inventory item for the client's inventory
793 /// </summary> 759 /// </summary>
@@ -1011,7 +977,7 @@ namespace OpenSim.Region.Framework.Scenes
1011 { 977 {
1012 ScenePresence avatar; 978 ScenePresence avatar;
1013 979
1014 if (TryGetAvatar(avatarId, out avatar)) 980 if (TryGetScenePresence(avatarId, out avatar))
1015 { 981 {
1016 return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId); 982 return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
1017 } 983 }
@@ -1125,7 +1091,7 @@ namespace OpenSim.Region.Framework.Scenes
1125 1091
1126 ScenePresence avatar; 1092 ScenePresence avatar;
1127 1093
1128 if (TryGetAvatar(srcTaskItem.OwnerID, out avatar)) 1094 if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
1129 { 1095 {
1130 destPart.GetProperties(avatar.ControllingClient); 1096 destPart.GetProperties(avatar.ControllingClient);
1131 } 1097 }
@@ -1153,7 +1119,7 @@ namespace OpenSim.Region.Framework.Scenes
1153 } 1119 }
1154 1120
1155 ScenePresence avatar = null; 1121 ScenePresence avatar = null;
1156 if (TryGetAvatar(destID, out avatar)) 1122 if (TryGetScenePresence(destID, out avatar))
1157 { 1123 {
1158 //profile.SendInventoryDecendents(avatar.ControllingClient, 1124 //profile.SendInventoryDecendents(avatar.ControllingClient,
1159 // profile.RootFolder.ID, true, false); 1125 // profile.RootFolder.ID, true, false);
@@ -1169,15 +1135,21 @@ namespace OpenSim.Region.Framework.Scenes
1169 1135
1170 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems) 1136 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
1171 { 1137 {
1172 m_log.DebugFormat("[AGENT INVENTORY]: Send Inventory Folder {0} Update to {1} {2}", folder.Name, client.FirstName, client.LastName); 1138 if (folder == null)
1139 return;
1140
1141 // Fetch the folder contents
1173 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID); 1142 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
1174 InventoryFolderBase containingFolder = new InventoryFolderBase(); 1143
1175 containingFolder.ID = folder.ID; 1144 // Fetch the folder itself to get its current version
1176 containingFolder.Owner = client.AgentId; 1145 InventoryFolderBase containingFolder = new InventoryFolderBase(folder.ID, client.AgentId);
1177 containingFolder = InventoryService.GetFolder(containingFolder); 1146 containingFolder = InventoryService.GetFolder(containingFolder);
1178 int version = containingFolder.Version;
1179 1147
1180 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, version, fetchFolders, fetchItems); 1148 //m_log.DebugFormat("[AGENT INVENTORY]: Sending inventory folder contents ({0} nodes) for \"{1}\" to {2} {3}",
1149 // contents.Folders.Count + contents.Items.Count, containingFolder.Name, client.FirstName, client.LastName);
1150
1151 if (containingFolder != null)
1152 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, containingFolder.Version, fetchFolders, fetchItems);
1181 } 1153 }
1182 1154
1183 /// <summary> 1155 /// <summary>
@@ -1219,11 +1191,12 @@ namespace OpenSim.Region.Framework.Scenes
1219 item = InventoryService.GetItem(item); 1191 item = InventoryService.GetItem(item);
1220 1192
1221 // Try library 1193 // Try library
1222 if (null == item) 1194 if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
1223 { 1195 {
1224 item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID); 1196 item = LibraryService.LibraryRootFolder.FindItem(itemID);
1225 } 1197 }
1226 1198
1199 // If we've found the item in the user's inventory or in the library
1227 if (item != null) 1200 if (item != null)
1228 { 1201 {
1229 part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID); 1202 part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID);
@@ -1258,7 +1231,10 @@ namespace OpenSim.Region.Framework.Scenes
1258 remoteClient, part, transactionID, currentItem); 1231 remoteClient, part, transactionID, currentItem);
1259 } 1232 }
1260 if (part.Inventory.UpdateInventoryItem(itemInfo)) 1233 if (part.Inventory.UpdateInventoryItem(itemInfo))
1234 {
1235 remoteClient.SendAgentAlertMessage("Notecard saved", false);
1261 part.GetProperties(remoteClient); 1236 part.GetProperties(remoteClient);
1237 }
1262 } 1238 }
1263 } 1239 }
1264 else 1240 else
@@ -1288,9 +1264,9 @@ namespace OpenSim.Region.Framework.Scenes
1288 1264
1289 // Try library 1265 // Try library
1290 // XXX clumsy, possibly should be one call 1266 // XXX clumsy, possibly should be one call
1291 if (null == item) 1267 if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
1292 { 1268 {
1293 item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID); 1269 item = LibraryService.LibraryRootFolder.FindItem(itemID);
1294 } 1270 }
1295 1271
1296 if (item != null) 1272 if (item != null)
@@ -1310,6 +1286,7 @@ namespace OpenSim.Region.Framework.Scenes
1310 // "Rezzed script {0} into prim local ID {1} for user {2}", 1286 // "Rezzed script {0} into prim local ID {1} for user {2}",
1311 // item.inventoryName, localID, remoteClient.Name); 1287 // item.inventoryName, localID, remoteClient.Name);
1312 part.GetProperties(remoteClient); 1288 part.GetProperties(remoteClient);
1289 part.ParentGroup.ResumeScripts();
1313 } 1290 }
1314 else 1291 else
1315 { 1292 {
@@ -1347,7 +1324,9 @@ namespace OpenSim.Region.Framework.Scenes
1347 itemBase.InvType, part.UUID, remoteClient.AgentId)) 1324 itemBase.InvType, part.UUID, remoteClient.AgentId))
1348 return; 1325 return;
1349 1326
1350 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}")); 1327 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
1328 Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
1329 remoteClient.AgentId);
1351 AssetService.Store(asset); 1330 AssetService.Store(asset);
1352 1331
1353 TaskInventoryItem taskItem = new TaskInventoryItem(); 1332 TaskInventoryItem taskItem = new TaskInventoryItem();
@@ -1377,6 +1356,7 @@ namespace OpenSim.Region.Framework.Scenes
1377 part.GetProperties(remoteClient); 1356 part.GetProperties(remoteClient);
1378 1357
1379 part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0); 1358 part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
1359 part.ParentGroup.ResumeScripts();
1380 } 1360 }
1381 } 1361 }
1382 1362
@@ -1480,9 +1460,11 @@ namespace OpenSim.Region.Framework.Scenes
1480 destPart.Inventory.CreateScriptInstance(destTaskItem, start_param, false, DefaultScriptEngine, 0); 1460 destPart.Inventory.CreateScriptInstance(destTaskItem, start_param, false, DefaultScriptEngine, 0);
1481 } 1461 }
1482 1462
1463 destPart.ParentGroup.ResumeScripts();
1464
1483 ScenePresence avatar; 1465 ScenePresence avatar;
1484 1466
1485 if (TryGetAvatar(srcTaskItem.OwnerID, out avatar)) 1467 if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
1486 { 1468 {
1487 destPart.GetProperties(avatar.ControllingClient); 1469 destPart.GetProperties(avatar.ControllingClient);
1488 } 1470 }
@@ -1616,237 +1598,6 @@ namespace OpenSim.Region.Framework.Scenes
1616 } 1598 }
1617 } 1599 }
1618 1600
1619 /// <summary>
1620 /// Delete a scene object from a scene and place in the given avatar's inventory.
1621 /// Returns the UUID of the newly created asset.
1622 /// </summary>
1623 /// <param name="action"></param>
1624 /// <param name="folderID"></param>
1625 /// <param name="objectGroup"></param>
1626 /// <param name="remoteClient"> </param>
1627 public virtual UUID DeleteToInventory(DeRezAction action, UUID folderID,
1628 SceneObjectGroup objectGroup, IClientAPI remoteClient)
1629 {
1630 UUID assetID = UUID.Zero;
1631
1632 Vector3 inventoryStoredPosition = new Vector3
1633 (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
1634 ? 250
1635 : objectGroup.AbsolutePosition.X)
1636 ,
1637 (objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
1638 ? 250
1639 : objectGroup.AbsolutePosition.X,
1640 objectGroup.AbsolutePosition.Z);
1641
1642 Vector3 originalPosition = objectGroup.AbsolutePosition;
1643
1644 objectGroup.AbsolutePosition = inventoryStoredPosition;
1645
1646 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
1647
1648 objectGroup.AbsolutePosition = originalPosition;
1649
1650 // Get the user info of the item destination
1651 //
1652 UUID userID = UUID.Zero;
1653
1654 if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
1655 action == DeRezAction.SaveToExistingUserInventoryItem)
1656 {
1657 // Take or take copy require a taker
1658 // Saving changes requires a local user
1659 //
1660 if (remoteClient == null)
1661 return UUID.Zero;
1662
1663 userID = remoteClient.AgentId;
1664 }
1665 else
1666 {
1667 // All returns / deletes go to the object owner
1668 //
1669
1670 userID = objectGroup.RootPart.OwnerID;
1671 }
1672
1673 if (userID == UUID.Zero) // Can't proceed
1674 {
1675 return UUID.Zero;
1676 }
1677
1678 // If we're returning someone's item, it goes back to the
1679 // owner's Lost And Found folder.
1680 // Delete is treated like return in this case
1681 // Deleting your own items makes them go to trash
1682 //
1683
1684 InventoryFolderBase folder = null;
1685 InventoryItemBase item = null;
1686
1687 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1688 {
1689 item = new InventoryItemBase(objectGroup.RootPart.FromUserInventoryItemID, userID);
1690 item = InventoryService.GetItem(item);
1691
1692 //item = userInfo.RootFolder.FindItem(
1693 // objectGroup.RootPart.FromUserInventoryItemID);
1694
1695 if (null == item)
1696 {
1697 m_log.DebugFormat(
1698 "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.",
1699 objectGroup.Name, objectGroup.UUID);
1700 return UUID.Zero;
1701 }
1702 }
1703 else
1704 {
1705 // Folder magic
1706 //
1707 if (action == DeRezAction.Delete)
1708 {
1709 // Deleting someone else's item
1710 //
1711
1712
1713 if (remoteClient == null ||
1714 objectGroup.OwnerID != remoteClient.AgentId)
1715 {
1716 // Folder skeleton may not be loaded and we
1717 // have to wait for the inventory to find
1718 // the destination folder
1719 //
1720 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1721 }
1722 else
1723 {
1724 // Assume inventory skeleton was loaded during login
1725 // and all folders can be found
1726 //
1727 folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
1728 }
1729 }
1730 else if (action == DeRezAction.Return)
1731 {
1732
1733 // Dump to lost + found unconditionally
1734 //
1735 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1736 }
1737
1738 if (folderID == UUID.Zero && folder == null)
1739 {
1740 if (action == DeRezAction.Delete)
1741 {
1742 // Deletes go to trash by default
1743 //
1744 folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
1745 }
1746 else
1747 {
1748 // Catch all. Use lost & found
1749 //
1750
1751 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1752 }
1753 }
1754
1755 if (folder == null) // None of the above
1756 {
1757 //folder = userInfo.RootFolder.FindFolder(folderID);
1758 folder = new InventoryFolderBase(folderID);
1759
1760 if (folder == null) // Nowhere to put it
1761 {
1762 return UUID.Zero;
1763 }
1764 }
1765
1766 item = new InventoryItemBase();
1767 item.CreatorId = objectGroup.RootPart.CreatorID.ToString();
1768 item.ID = UUID.Random();
1769 item.InvType = (int)InventoryType.Object;
1770 item.Folder = folder.ID;
1771 item.Owner = userID;
1772 }
1773
1774 AssetBase asset = CreateAsset(
1775 objectGroup.GetPartName(objectGroup.RootPart.LocalId),
1776 objectGroup.GetPartDescription(objectGroup.RootPart.LocalId),
1777 (sbyte)AssetType.Object,
1778 Utils.StringToBytes(sceneObjectXml));
1779 AssetService.Store(asset);
1780 assetID = asset.FullID;
1781
1782 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1783 {
1784 item.AssetID = asset.FullID;
1785 InventoryService.UpdateItem(item);
1786 }
1787 else
1788 {
1789 item.AssetID = asset.FullID;
1790
1791 if (remoteClient != null && (remoteClient.AgentId != objectGroup.RootPart.OwnerID) && Permissions.PropagatePermissions())
1792 {
1793 uint perms=objectGroup.GetEffectivePermissions();
1794 uint nextPerms=(perms & 7) << 13;
1795 if ((nextPerms & (uint)PermissionMask.Copy) == 0)
1796 perms &= ~(uint)PermissionMask.Copy;
1797 if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
1798 perms &= ~(uint)PermissionMask.Transfer;
1799 if ((nextPerms & (uint)PermissionMask.Modify) == 0)
1800 perms &= ~(uint)PermissionMask.Modify;
1801
1802 item.BasePermissions = perms & objectGroup.RootPart.NextOwnerMask;
1803 item.CurrentPermissions = item.BasePermissions;
1804 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1805 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
1806 item.GroupPermissions = objectGroup.RootPart.GroupMask & objectGroup.RootPart.NextOwnerMask;
1807 item.CurrentPermissions |= 8; // Slam!
1808 }
1809 else
1810 {
1811 uint ownerPerms = objectGroup.GetEffectivePermissions();
1812 if ((objectGroup.RootPart.OwnerMask & (uint)PermissionMask.Modify) != 0)
1813 ownerPerms |= (uint)PermissionMask.Modify;
1814
1815 item.BasePermissions = ownerPerms;
1816 item.CurrentPermissions = ownerPerms;
1817
1818 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1819 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
1820 item.GroupPermissions = objectGroup.RootPart.GroupMask;
1821
1822 item.CurrentPermissions |= 8; // Slam!
1823 }
1824
1825 // TODO: add the new fields (Flags, Sale info, etc)
1826 item.CreationDate = Util.UnixTimeSinceEpoch();
1827 item.Description = asset.Description;
1828 item.Name = asset.Name;
1829 item.AssetType = asset.Type;
1830
1831 InventoryService.AddItem(item);
1832
1833 if (remoteClient != null && item.Owner == remoteClient.AgentId)
1834 {
1835 remoteClient.SendInventoryItemCreateUpdate(item, 0);
1836 }
1837 else
1838 {
1839 ScenePresence notifyUser = GetScenePresence(item.Owner);
1840 if (notifyUser != null)
1841 {
1842 notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
1843 }
1844 }
1845 }
1846
1847 return assetID;
1848 }
1849
1850 public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID) 1601 public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID)
1851 { 1602 {
1852 SceneObjectGroup objectGroup = grp; 1603 SceneObjectGroup objectGroup = grp;
@@ -1873,7 +1624,8 @@ namespace OpenSim.Region.Framework.Scenes
1873 objectGroup.GetPartName(objectGroup.LocalId), 1624 objectGroup.GetPartName(objectGroup.LocalId),
1874 objectGroup.GetPartDescription(objectGroup.LocalId), 1625 objectGroup.GetPartDescription(objectGroup.LocalId),
1875 (sbyte)AssetType.Object, 1626 (sbyte)AssetType.Object,
1876 Utils.StringToBytes(sceneObjectXml)); 1627 Utils.StringToBytes(sceneObjectXml),
1628 remoteClient.AgentId);
1877 AssetService.Store(asset); 1629 AssetService.Store(asset);
1878 1630
1879 item.AssetID = asset.FullID; 1631 item.AssetID = asset.FullID;
@@ -1920,7 +1672,8 @@ namespace OpenSim.Region.Framework.Scenes
1920 grp.GetPartName(grp.LocalId), 1672 grp.GetPartName(grp.LocalId),
1921 grp.GetPartDescription(grp.LocalId), 1673 grp.GetPartDescription(grp.LocalId),
1922 (sbyte)AssetType.Object, 1674 (sbyte)AssetType.Object,
1923 Utils.StringToBytes(sceneObjectXml)); 1675 Utils.StringToBytes(sceneObjectXml),
1676 remoteClient.AgentId);
1924 AssetService.Store(asset); 1677 AssetService.Store(asset);
1925 1678
1926 InventoryItemBase item = new InventoryItemBase(); 1679 InventoryItemBase item = new InventoryItemBase();
@@ -1987,225 +1740,11 @@ namespace OpenSim.Region.Framework.Scenes
1987 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, 1740 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
1988 bool RezSelected, bool RemoveItem, UUID fromTaskID) 1741 bool RezSelected, bool RemoveItem, UUID fromTaskID)
1989 { 1742 {
1990 RezObject( 1743 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
1991 remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, 1744 if (invAccess != null)
1992 RezSelected, RemoveItem, fromTaskID, false); 1745 invAccess.RezObject(
1993 } 1746 remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
1994 1747 RezSelected, RemoveItem, fromTaskID, false);
1995 /// <summary>
1996 /// Rez an object into the scene from the user's inventory
1997 /// </summary>
1998 /// <param name="remoteClient"></param>
1999 /// <param name="itemID"></param>
2000 /// <param name="RayEnd"></param>
2001 /// <param name="RayStart"></param>
2002 /// <param name="RayTargetID"></param>
2003 /// <param name="BypassRayCast"></param>
2004 /// <param name="RayEndIsIntersection"></param>
2005 /// <param name="RezSelected"></param>
2006 /// <param name="RemoveItem"></param>
2007 /// <param name="fromTaskID"></param>
2008 /// <param name="attachment"></param>
2009 /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful.</returns>
2010 public virtual SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
2011 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
2012 bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
2013 {
2014 // Work out position details
2015 byte bRayEndIsIntersection = (byte)0;
2016
2017 if (RayEndIsIntersection)
2018 {
2019 bRayEndIsIntersection = (byte)1;
2020 }
2021 else
2022 {
2023 bRayEndIsIntersection = (byte)0;
2024 }
2025
2026 Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
2027
2028
2029 Vector3 pos = GetNewRezLocation(
2030 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2031 BypassRayCast, bRayEndIsIntersection,true,scale, false);
2032
2033 // Rez object
2034 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2035 item = InventoryService.GetItem(item);
2036
2037 if (item != null)
2038 {
2039 AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
2040
2041 if (rezAsset != null)
2042 {
2043 UUID itemId = UUID.Zero;
2044
2045 // If we have permission to copy then link the rezzed object back to the user inventory
2046 // item that it came from. This allows us to enable 'save object to inventory'
2047 if (!Permissions.BypassPermissions())
2048 {
2049 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
2050 {
2051 itemId = item.ID;
2052 }
2053 }
2054 else
2055 {
2056 // Brave new fullperm world
2057 //
2058 itemId = item.ID;
2059 }
2060
2061 string xmlData = Utils.BytesToString(rezAsset.Data);
2062 SceneObjectGroup group
2063 = SceneObjectSerializer.FromOriginalXmlFormat(itemId, xmlData);
2064
2065 if (!Permissions.CanRezObject(
2066 group.Children.Count, remoteClient.AgentId, pos)
2067 && !attachment)
2068 {
2069 // The client operates in no fail mode. It will
2070 // have already removed the item from the folder
2071 // if it's no copy.
2072 // Put it back if it's not an attachment
2073 //
2074 if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment))
2075 remoteClient.SendBulkUpdateInventory(item);
2076 return null;
2077 }
2078
2079 group.ResetIDs();
2080
2081 if (attachment)
2082 {
2083 group.RootPart.ObjectFlags |= (uint)PrimFlags.Phantom;
2084 group.RootPart.IsAttachment = true;
2085 }
2086
2087 AddNewSceneObject(group, true);
2088
2089 // m_log.InfoFormat("ray end point for inventory rezz is {0} {1} {2} ", RayEnd.X, RayEnd.Y, RayEnd.Z);
2090 // if attachment we set it's asset id so object updates can reflect that
2091 // if not, we set it's position in world.
2092 if (!attachment)
2093 {
2094 float offsetHeight = 0;
2095 pos = GetNewRezLocation(
2096 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2097 BypassRayCast, bRayEndIsIntersection, true, group.GetAxisAlignedBoundingBox(out offsetHeight), false);
2098 pos.Z += offsetHeight;
2099 group.AbsolutePosition = pos;
2100 // m_log.InfoFormat("rezx point for inventory rezz is {0} {1} {2} and offsetheight was {3}", pos.X, pos.Y, pos.Z, offsetHeight);
2101
2102 }
2103 else
2104 {
2105 group.SetFromItemID(itemID);
2106 }
2107
2108 SceneObjectPart rootPart = null;
2109 try
2110 {
2111 rootPart = group.GetChildPart(group.UUID);
2112 }
2113 catch (NullReferenceException)
2114 {
2115 string isAttachment = "";
2116
2117 if (attachment)
2118 isAttachment = " Object was an attachment";
2119
2120 m_log.Error("[AGENT INVENTORY]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment);
2121 }
2122
2123 // Since renaming the item in the inventory does not affect the name stored
2124 // in the serialization, transfer the correct name from the inventory to the
2125 // object itself before we rez.
2126 rootPart.Name = item.Name;
2127 rootPart.Description = item.Description;
2128
2129 List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
2130
2131 group.SetGroup(remoteClient.ActiveGroupId, remoteClient);
2132 if (rootPart.OwnerID != item.Owner)
2133 {
2134 //Need to kill the for sale here
2135 rootPart.ObjectSaleType = 0;
2136 rootPart.SalePrice = 10;
2137
2138 if (Permissions.PropagatePermissions())
2139 {
2140 if ((item.CurrentPermissions & 8) != 0)
2141 {
2142 foreach (SceneObjectPart part in partList)
2143 {
2144 part.EveryoneMask = item.EveryOnePermissions;
2145 part.NextOwnerMask = item.NextPermissions;
2146 part.GroupMask = 0; // DO NOT propagate here
2147 }
2148 }
2149 group.ApplyNextOwnerPermissions();
2150 }
2151 }
2152
2153 foreach (SceneObjectPart part in partList)
2154 {
2155 if (part.OwnerID != item.Owner)
2156 {
2157 part.LastOwnerID = part.OwnerID;
2158 part.OwnerID = item.Owner;
2159 part.Inventory.ChangeInventoryOwner(item.Owner);
2160 }
2161 else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
2162 {
2163 part.EveryoneMask = item.EveryOnePermissions;
2164 part.NextOwnerMask = item.NextPermissions;
2165
2166 part.GroupMask = 0; // DO NOT propagate here
2167 }
2168 }
2169
2170 rootPart.TrimPermissions();
2171
2172 if (!attachment)
2173 {
2174 if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
2175 {
2176 group.ClearPartAttachmentData();
2177 }
2178 }
2179
2180 if (!attachment)
2181 {
2182 // Fire on_rez
2183 group.CreateScriptInstances(0, true, DefaultScriptEngine, 0);
2184
2185 rootPart.ScheduleFullUpdate();
2186 }
2187
2188 if (!Permissions.BypassPermissions())
2189 {
2190 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
2191 {
2192 // If this is done on attachments, no
2193 // copy ones will be lost, so avoid it
2194 //
2195 if (!attachment)
2196 {
2197 List<UUID> uuids = new List<UUID>();
2198 uuids.Add(item.ID);
2199 InventoryService.DeleteItems(item.Owner, uuids);
2200 }
2201 }
2202 }
2203
2204 return rootPart.ParentGroup;
2205 }
2206 }
2207
2208 return null;
2209 } 1748 }
2210 1749
2211 /// <summary> 1750 /// <summary>
@@ -2343,178 +1882,6 @@ namespace OpenSim.Region.Framework.Scenes
2343 EventManager.TriggerStopScript(part.LocalId, itemID); 1882 EventManager.TriggerStopScript(part.LocalId, itemID);
2344 } 1883 }
2345 1884
2346 internal void SendAttachEvent(uint localID, UUID itemID, UUID avatarID)
2347 {
2348 EventManager.TriggerOnAttach(localID, itemID, avatarID);
2349 }
2350
2351 /// <summary>
2352 /// Called when the client receives a request to rez a single attachment on to the avatar from inventory
2353 /// (RezSingleAttachmentFromInv packet).
2354 /// </summary>
2355 /// <param name="remoteClient"></param>
2356 /// <param name="itemID"></param>
2357 /// <param name="AttachmentPt"></param>
2358 /// <returns></returns>
2359 public UUID RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
2360 {
2361 m_log.DebugFormat("[USER INVENTORY]: Rezzing single attachment from item {0} for {1}", itemID, remoteClient.Name);
2362
2363 SceneObjectGroup att = m_sceneGraph.RezSingleAttachment(remoteClient, itemID, AttachmentPt);
2364
2365 if (att == null)
2366 {
2367 DetachSingleAttachmentToInv(itemID, remoteClient);
2368 return UUID.Zero;
2369 }
2370
2371 return RezSingleAttachment(att, remoteClient, itemID, AttachmentPt);
2372 }
2373
2374 /// <summary>
2375 /// Update the user inventory to reflect an attachment
2376 /// </summary>
2377 /// <param name="att"></param>
2378 /// <param name="remoteClient"></param>
2379 /// <param name="itemID"></param>
2380 /// <param name="AttachmentPt"></param>
2381 /// <returns></returns>
2382 public UUID RezSingleAttachment(SceneObjectGroup att, IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
2383 {
2384 m_log.DebugFormat(
2385 "[USER INVENTORY]: Updating inventory of {0} to show attachment of {1} (item ID {2})",
2386 remoteClient.Name, att.Name, itemID);
2387
2388 if (!att.IsDeleted)
2389 AttachmentPt = att.RootPart.AttachmentPoint;
2390
2391 ScenePresence presence;
2392 if (TryGetAvatar(remoteClient.AgentId, out presence))
2393 {
2394 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2395 item = InventoryService.GetItem(item);
2396
2397 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
2398 }
2399 return att.UUID;
2400 }
2401
2402 public void RezMultipleAttachments(IClientAPI remoteClient, RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
2403 RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects)
2404 {
2405 foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects)
2406 {
2407 RezSingleAttachment(remoteClient, obj.ItemID, obj.AttachmentPt);
2408 }
2409 }
2410
2411 /// <summary>
2412 /// Attach an object.
2413 /// </summary>
2414 /// <param name="controllingClient"></param>
2415 /// <param name="localID"></param>
2416 /// <param name="attachPoint"></param>
2417 /// <param name="rot"></param>
2418 /// <param name="pos"></param>
2419 /// <param name="silent"></param>
2420 /// <returns>true if the object was successfully attached, false otherwise</returns>
2421 public bool AttachObject(IClientAPI controllingClient, uint localID, uint attachPoint, Quaternion rot, Vector3 pos, bool silent)
2422 {
2423 return m_sceneGraph.AttachObject(controllingClient, localID, attachPoint, rot, pos, silent);
2424 }
2425
2426 /// <summary>
2427 /// This registers the item as attached in a user's inventory
2428 /// </summary>
2429 /// <param name="remoteClient"></param>
2430 /// <param name="AttachmentPt"></param>
2431 /// <param name="itemID"></param>
2432 /// <param name="att"></param>
2433 public void AttachObject(IClientAPI remoteClient, uint AttachmentPt, UUID itemID, SceneObjectGroup att)
2434 {
2435// m_log.DebugFormat(
2436// "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}",
2437// att.Name, remoteClient.Name, AttachmentPt, itemID);
2438
2439 if (UUID.Zero == itemID)
2440 {
2441 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error inventory item ID.");
2442 return;
2443 }
2444
2445 if (0 == AttachmentPt)
2446 {
2447 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error attachment point.");
2448 return;
2449 }
2450
2451 if (null == att.RootPart)
2452 {
2453 m_log.Error("[SCENE INVENTORY]: Unable to save attachment for a prim without the rootpart!");
2454 return;
2455 }
2456
2457 ScenePresence presence;
2458 if (TryGetAvatar(remoteClient.AgentId, out presence))
2459 {
2460 // XXYY!!
2461 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2462 item = InventoryService.GetItem(item);
2463 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
2464
2465 if (m_AvatarFactory != null)
2466 m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2467 }
2468 }
2469
2470 public void DetachSingleAttachmentToGround(UUID itemID, IClientAPI remoteClient)
2471 {
2472 SceneObjectPart part = GetSceneObjectPart(itemID);
2473 if (part == null || part.ParentGroup == null)
2474 return;
2475
2476 UUID inventoryID = part.ParentGroup.GetFromItemID();
2477
2478 ScenePresence presence;
2479 if (TryGetAvatar(remoteClient.AgentId, out presence))
2480 {
2481 if (!Permissions.CanRezObject(part.ParentGroup.Children.Count, remoteClient.AgentId, presence.AbsolutePosition))
2482 return;
2483
2484 presence.Appearance.DetachAttachment(itemID);
2485 IAvatarFactory ava = RequestModuleInterface<IAvatarFactory>();
2486 if (ava != null)
2487 {
2488 ava.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2489 }
2490 part.ParentGroup.DetachToGround();
2491
2492 List<UUID> uuids = new List<UUID>();
2493 uuids.Add(inventoryID);
2494 InventoryService.DeleteItems(remoteClient.AgentId, uuids);
2495 remoteClient.SendRemoveInventoryItem(inventoryID);
2496 }
2497 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero);
2498 }
2499
2500 public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
2501 {
2502 ScenePresence presence;
2503 if (TryGetAvatar(remoteClient.AgentId, out presence))
2504 {
2505 presence.Appearance.DetachAttachment(itemID);
2506
2507 // Save avatar attachment information
2508 if (m_AvatarFactory != null)
2509 {
2510 m_log.Info("[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", ItemID: " + itemID);
2511 m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2512 }
2513 }
2514
2515 m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient);
2516 }
2517
2518 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) 1885 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
2519 { 1886 {
2520 EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID); 1887 EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
index ac04dc7..bc10230 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
@@ -32,7 +32,7 @@ using OpenMetaverse;
32using OpenMetaverse.Packets; 32using OpenMetaverse.Packets;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Communications; 34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Communications.Cache; 35using OpenSim.Services.Interfaces;
36 36
37namespace OpenSim.Region.Framework.Scenes 37namespace OpenSim.Region.Framework.Scenes
38{ 38{
@@ -371,14 +371,16 @@ namespace OpenSim.Region.Framework.Scenes
371 { 371 {
372 //EventManager.TriggerAvatarPickerRequest(); 372 //EventManager.TriggerAvatarPickerRequest();
373 373
374 List<AvatarPickerAvatar> AvatarResponses = new List<AvatarPickerAvatar>(); 374 List<UserAccount> accounts = UserAccountService.GetUserAccounts(RegionInfo.ScopeID, query);
375 AvatarResponses = m_sceneGridService.GenerateAgentPickerRequestResponse(RequestID, query); 375
376 if (accounts == null)
377 return;
376 378
377 AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply); 379 AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
378 // TODO: don't create new blocks if recycling an old packet 380 // TODO: don't create new blocks if recycling an old packet
379 381
380 AvatarPickerReplyPacket.DataBlock[] searchData = 382 AvatarPickerReplyPacket.DataBlock[] searchData =
381 new AvatarPickerReplyPacket.DataBlock[AvatarResponses.Count]; 383 new AvatarPickerReplyPacket.DataBlock[accounts.Count];
382 AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock(); 384 AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
383 385
384 agentData.AgentID = avatarID; 386 agentData.AgentID = avatarID;
@@ -387,16 +389,16 @@ namespace OpenSim.Region.Framework.Scenes
387 //byte[] bytes = new byte[AvatarResponses.Count*32]; 389 //byte[] bytes = new byte[AvatarResponses.Count*32];
388 390
389 int i = 0; 391 int i = 0;
390 foreach (AvatarPickerAvatar item in AvatarResponses) 392 foreach (UserAccount item in accounts)
391 { 393 {
392 UUID translatedIDtem = item.AvatarID; 394 UUID translatedIDtem = item.PrincipalID;
393 searchData[i] = new AvatarPickerReplyPacket.DataBlock(); 395 searchData[i] = new AvatarPickerReplyPacket.DataBlock();
394 searchData[i].AvatarID = translatedIDtem; 396 searchData[i].AvatarID = translatedIDtem;
395 searchData[i].FirstName = Utils.StringToBytes((string) item.firstName); 397 searchData[i].FirstName = Utils.StringToBytes((string) item.FirstName);
396 searchData[i].LastName = Utils.StringToBytes((string) item.lastName); 398 searchData[i].LastName = Utils.StringToBytes((string) item.LastName);
397 i++; 399 i++;
398 } 400 }
399 if (AvatarResponses.Count == 0) 401 if (accounts.Count == 0)
400 { 402 {
401 searchData = new AvatarPickerReplyPacket.DataBlock[0]; 403 searchData = new AvatarPickerReplyPacket.DataBlock[0];
402 } 404 }
@@ -455,7 +457,24 @@ namespace OpenSim.Region.Framework.Scenes
455 } 457 }
456 ); 458 );
457 } 459 }
458 460
461 public void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client)
462 {
463 if (LibraryService != null && (LibraryService.LibraryRootFolder.Owner == uuid))
464 {
465 remote_client.SendNameReply(uuid, "Mr", "OpenSim");
466 }
467 else
468 {
469 string[] names = GetUserNames(uuid);
470 if (names.Length == 2)
471 {
472 remote_client.SendNameReply(uuid, names[0], names[1]);
473 }
474
475 }
476 }
477
459 /// <summary> 478 /// <summary>
460 /// Handle a fetch inventory request from the client 479 /// Handle a fetch inventory request from the client
461 /// </summary> 480 /// </summary>
@@ -464,7 +483,7 @@ namespace OpenSim.Region.Framework.Scenes
464 /// <param name="ownerID"></param> 483 /// <param name="ownerID"></param>
465 public void HandleFetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID) 484 public void HandleFetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID)
466 { 485 {
467 if (ownerID == CommsManager.UserProfileCacheService.LibraryRoot.Owner) 486 if (LibraryService != null && LibraryService.LibraryRootFolder != null && ownerID == LibraryService.LibraryRootFolder.Owner)
468 { 487 {
469 //m_log.Debug("request info for library item"); 488 //m_log.Debug("request info for library item");
470 return; 489 return;
@@ -498,13 +517,14 @@ namespace OpenSim.Region.Framework.Scenes
498 // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc. 517 // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
499 // can be handled transparently). 518 // can be handled transparently).
500 InventoryFolderImpl fold = null; 519 InventoryFolderImpl fold = null;
501 if ((fold = CommsManager.UserProfileCacheService.LibraryRoot.FindFolder(folderID)) != null) 520 if (LibraryService != null && LibraryService.LibraryRootFolder != null)
502 { 521 if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
503 remoteClient.SendInventoryFolderDetails( 522 {
504 fold.Owner, folderID, fold.RequestListOfItems(), 523 remoteClient.SendInventoryFolderDetails(
505 fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems); 524 fold.Owner, folderID, fold.RequestListOfItems(),
506 return; 525 fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
507 } 526 return;
527 }
508 528
509 // We're going to send the reply async, because there may be 529 // We're going to send the reply async, because there may be
510 // an enormous quantity of packets -- basically the entire inventory! 530 // an enormous quantity of packets -- basically the entire inventory!
@@ -552,15 +572,16 @@ namespace OpenSim.Region.Framework.Scenes
552 // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc. 572 // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
553 // can be handled transparently). 573 // can be handled transparently).
554 InventoryFolderImpl fold; 574 InventoryFolderImpl fold;
555 if ((fold = CommsManager.UserProfileCacheService.LibraryRoot.FindFolder(folderID)) != null) 575 if (LibraryService != null && LibraryService.LibraryRootFolder != null)
556 { 576 if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
557 version = 0; 577 {
558 InventoryCollection ret = new InventoryCollection(); 578 version = 0;
559 ret.Folders = new List<InventoryFolderBase>(); 579 InventoryCollection ret = new InventoryCollection();
560 ret.Items = fold.RequestListOfItems(); 580 ret.Folders = new List<InventoryFolderBase>();
581 ret.Items = fold.RequestListOfItems();
561 582
562 return ret; 583 return ret;
563 } 584 }
564 585
565 InventoryCollection contents = new InventoryCollection(); 586 InventoryCollection contents = new InventoryCollection();
566 587
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 0556166..8ceb109 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics;
30using System.Drawing; 31using System.Drawing;
31using System.Drawing.Imaging; 32using System.Drawing.Imaging;
32using System.IO; 33using System.IO;
@@ -41,8 +42,7 @@ using OpenMetaverse.Imaging;
41using OpenSim.Framework; 42using OpenSim.Framework;
42using OpenSim.Services.Interfaces; 43using OpenSim.Services.Interfaces;
43using OpenSim.Framework.Communications; 44using OpenSim.Framework.Communications;
44using OpenSim.Framework.Communications.Cache; 45
45using OpenSim.Framework.Communications.Clients;
46using OpenSim.Framework.Console; 46using OpenSim.Framework.Console;
47using OpenSim.Region.Framework.Interfaces; 47using OpenSim.Region.Framework.Interfaces;
48using OpenSim.Region.Framework.Scenes.Scripting; 48using OpenSim.Region.Framework.Scenes.Scripting;
@@ -131,7 +131,6 @@ namespace OpenSim.Region.Framework.Scenes
131 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing 131 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing
132 private int m_incrementsof15seconds; 132 private int m_incrementsof15seconds;
133 private volatile bool m_backingup; 133 private volatile bool m_backingup;
134 private bool m_useAsyncWhenPossible;
135 134
136 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); 135 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>();
137 private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>(); 136 private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>();
@@ -141,7 +140,6 @@ namespace OpenSim.Region.Framework.Scenes
141 protected ModuleLoader m_moduleLoader; 140 protected ModuleLoader m_moduleLoader;
142 protected StorageManager m_storageManager; 141 protected StorageManager m_storageManager;
143 protected AgentCircuitManager m_authenticateHandler; 142 protected AgentCircuitManager m_authenticateHandler;
144 public CommunicationsManager CommsManager;
145 143
146 protected SceneCommunicationService m_sceneGridService; 144 protected SceneCommunicationService m_sceneGridService;
147 public bool LoginsDisabled = true; 145 public bool LoginsDisabled = true;
@@ -203,11 +201,11 @@ namespace OpenSim.Region.Framework.Scenes
203 { 201 {
204 m_AuthorizationService = RequestModuleInterface<IAuthorizationService>(); 202 m_AuthorizationService = RequestModuleInterface<IAuthorizationService>();
205 203
206 if (m_AuthorizationService == null) 204 //if (m_AuthorizationService == null)
207 { 205 //{
208 // don't throw an exception if no authorization service is set for the time being 206 // // don't throw an exception if no authorization service is set for the time being
209 m_log.InfoFormat("[SCENE]: No Authorization service is configured"); 207 // m_log.InfoFormat("[SCENE]: No Authorization service is configured");
210 } 208 //}
211 } 209 }
212 210
213 return m_AuthorizationService; 211 return m_AuthorizationService;
@@ -254,8 +252,76 @@ namespace OpenSim.Region.Framework.Scenes
254 } 252 }
255 } 253 }
256 254
255 protected ILibraryService m_LibraryService;
256
257 public ILibraryService LibraryService
258 {
259 get
260 {
261 if (m_LibraryService == null)
262 m_LibraryService = RequestModuleInterface<ILibraryService>();
263
264 return m_LibraryService;
265 }
266 }
267
268 protected ISimulationService m_simulationService;
269 public ISimulationService SimulationService
270 {
271 get
272 {
273 if (m_simulationService == null)
274 m_simulationService = RequestModuleInterface<ISimulationService>();
275 return m_simulationService;
276 }
277 }
278
279 protected IAuthenticationService m_AuthenticationService;
280 public IAuthenticationService AuthenticationService
281 {
282 get
283 {
284 if (m_AuthenticationService == null)
285 m_AuthenticationService = RequestModuleInterface<IAuthenticationService>();
286 return m_AuthenticationService;
287 }
288 }
289
290 protected IPresenceService m_PresenceService;
291 public IPresenceService PresenceService
292 {
293 get
294 {
295 if (m_PresenceService == null)
296 m_PresenceService = RequestModuleInterface<IPresenceService>();
297 return m_PresenceService;
298 }
299 }
300 protected IUserAccountService m_UserAccountService;
301 public IUserAccountService UserAccountService
302 {
303 get
304 {
305 if (m_UserAccountService == null)
306 m_UserAccountService = RequestModuleInterface<IUserAccountService>();
307 return m_UserAccountService;
308 }
309 }
310
311 protected OpenSim.Services.Interfaces.IAvatarService m_AvatarService;
312 public OpenSim.Services.Interfaces.IAvatarService AvatarService
313 {
314 get
315 {
316 if (m_AvatarService == null)
317 m_AvatarService = RequestModuleInterface<IAvatarService>();
318 return m_AvatarService;
319 }
320 }
321
257 protected IXMLRPC m_xmlrpcModule; 322 protected IXMLRPC m_xmlrpcModule;
258 protected IWorldComm m_worldCommModule; 323 protected IWorldComm m_worldCommModule;
324 public IAttachmentsModule AttachmentsModule { get; set; }
259 protected IAvatarFactory m_AvatarFactory; 325 protected IAvatarFactory m_AvatarFactory;
260 public IAvatarFactory AvatarFactory 326 public IAvatarFactory AvatarFactory
261 { 327 {
@@ -263,10 +329,8 @@ namespace OpenSim.Region.Framework.Scenes
263 } 329 }
264 protected IConfigSource m_config; 330 protected IConfigSource m_config;
265 protected IRegionSerialiserModule m_serialiser; 331 protected IRegionSerialiserModule m_serialiser;
266 protected IInterregionCommsOut m_interregionCommsOut;
267 protected IInterregionCommsIn m_interregionCommsIn;
268 protected IDialogModule m_dialogModule; 332 protected IDialogModule m_dialogModule;
269 protected ITeleportModule m_teleportModule; 333 protected IEntityTransferModule m_teleportModule;
270 334
271 protected ICapabilitiesModule m_capsModule; 335 protected ICapabilitiesModule m_capsModule;
272 public ICapabilitiesModule CapsModule 336 public ICapabilitiesModule CapsModule
@@ -497,7 +561,7 @@ namespace OpenSim.Region.Framework.Scenes
497 #region Constructors 561 #region Constructors
498 562
499 public Scene(RegionInfo regInfo, AgentCircuitManager authen, 563 public Scene(RegionInfo regInfo, AgentCircuitManager authen,
500 CommunicationsManager commsMan, SceneCommunicationService sceneGridService, 564 SceneCommunicationService sceneGridService,
501 StorageManager storeManager, 565 StorageManager storeManager,
502 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim, 566 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim,
503 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion) 567 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
@@ -533,7 +597,6 @@ namespace OpenSim.Region.Framework.Scenes
533 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4); 597 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4);
534 m_moduleLoader = moduleLoader; 598 m_moduleLoader = moduleLoader;
535 m_authenticateHandler = authen; 599 m_authenticateHandler = authen;
536 CommsManager = commsMan;
537 m_sceneGridService = sceneGridService; 600 m_sceneGridService = sceneGridService;
538 m_storageManager = storeManager; 601 m_storageManager = storeManager;
539 m_regInfo = regInfo; 602 m_regInfo = regInfo;
@@ -557,7 +620,46 @@ namespace OpenSim.Region.Framework.Scenes
557 620
558 if (m_storageManager.EstateDataStore != null) 621 if (m_storageManager.EstateDataStore != null)
559 { 622 {
560 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 623 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false);
624 if (m_regInfo.EstateSettings.EstateID == 0) // No record at all
625 {
626 MainConsole.Instance.Output("Your region is not part of an estate.");
627 while (true)
628 {
629 string response = MainConsole.Instance.CmdPrompt("Do you wish to join an existing estate?", "no", new List<string>() {"yes", "no"});
630 if (response == "no")
631 {
632 // Create a new estate
633 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, true);
634
635 m_regInfo.EstateSettings.EstateName = MainConsole.Instance.CmdPrompt("New estate name", m_regInfo.EstateSettings.EstateName);
636 m_regInfo.EstateSettings.Save();
637 break;
638 }
639 else
640 {
641 response = MainConsole.Instance.CmdPrompt("Estate name to join", "None");
642 if (response == "None")
643 continue;
644
645 List<int> estateIDs = m_storageManager.EstateDataStore.GetEstates(response);
646 if (estateIDs.Count < 1)
647 {
648 MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again");
649 continue;
650 }
651
652 int estateID = estateIDs[0];
653
654 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(estateID);
655
656 if (m_storageManager.EstateDataStore.LinkRegion(m_regInfo.RegionID, estateID))
657 break;
658
659 MainConsole.Instance.Output("Joining the estate failed. Please try again.");
660 }
661 }
662 }
561 } 663 }
562 664
563 //Bind Storage Manager functions to some land manager functions for this scene 665 //Bind Storage Manager functions to some land manager functions for this scene
@@ -606,9 +708,6 @@ namespace OpenSim.Region.Framework.Scenes
606 // 708 //
607 IConfig startupConfig = m_config.Configs["Startup"]; 709 IConfig startupConfig = m_config.Configs["Startup"];
608 710
609 // Should we try to run loops synchronously or asynchronously?
610 m_useAsyncWhenPossible = startupConfig.GetBoolean("use_async_when_possible", false);
611
612 //Animation states 711 //Animation states
613 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 712 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
614 // TODO: Change default to true once the feature is supported 713 // TODO: Change default to true once the feature is supported
@@ -792,6 +891,36 @@ namespace OpenSim.Region.Framework.Scenes
792 return m_simulatorVersion; 891 return m_simulatorVersion;
793 } 892 }
794 893
894 public string[] GetUserNames(UUID uuid)
895 {
896 string[] returnstring = new string[0];
897
898 UserAccount account = UserAccountService.GetUserAccount(RegionInfo.ScopeID, uuid);
899
900 if (account != null)
901 {
902 returnstring = new string[2];
903 returnstring[0] = account.FirstName;
904 returnstring[1] = account.LastName;
905 }
906
907 return returnstring;
908 }
909
910 public string GetUserName(UUID uuid)
911 {
912 string[] names = GetUserNames(uuid);
913 if (names.Length == 2)
914 {
915 string firstname = names[0];
916 string lastname = names[1];
917
918 return firstname + " " + lastname;
919
920 }
921 return "(hippos)";
922 }
923
795 /// <summary> 924 /// <summary>
796 /// Another region is up. 925 /// Another region is up.
797 /// 926 ///
@@ -825,7 +954,7 @@ namespace OpenSim.Region.Framework.Scenes
825 regInfo.RegionName = otherRegion.RegionName; 954 regInfo.RegionName = otherRegion.RegionName;
826 regInfo.ScopeID = otherRegion.ScopeID; 955 regInfo.ScopeID = otherRegion.ScopeID;
827 regInfo.ExternalHostName = otherRegion.ExternalHostName; 956 regInfo.ExternalHostName = otherRegion.ExternalHostName;
828 957 GridRegion r = new GridRegion(regInfo);
829 try 958 try
830 { 959 {
831 ForEachScenePresence(delegate(ScenePresence agent) 960 ForEachScenePresence(delegate(ScenePresence agent)
@@ -839,7 +968,8 @@ namespace OpenSim.Region.Framework.Scenes
839 List<ulong> old = new List<ulong>(); 968 List<ulong> old = new List<ulong>();
840 old.Add(otherRegion.RegionHandle); 969 old.Add(otherRegion.RegionHandle);
841 agent.DropOldNeighbours(old); 970 agent.DropOldNeighbours(old);
842 InformClientOfNeighbor(agent, regInfo); 971 if (m_teleportModule != null)
972 m_teleportModule.EnableChildAgent(agent, r);
843 } 973 }
844 } 974 }
845 ); 975 );
@@ -999,6 +1129,7 @@ namespace OpenSim.Region.Framework.Scenes
999 { 1129 {
1000 foreach (RegionInfo region in m_regionRestartNotifyList) 1130 foreach (RegionInfo region in m_regionRestartNotifyList)
1001 { 1131 {
1132 GridRegion r = new GridRegion(region);
1002 try 1133 try
1003 { 1134 {
1004 ForEachScenePresence(delegate(ScenePresence agent) 1135 ForEachScenePresence(delegate(ScenePresence agent)
@@ -1006,9 +1137,8 @@ namespace OpenSim.Region.Framework.Scenes
1006 // If agent is a root agent. 1137 // If agent is a root agent.
1007 if (!agent.IsChildAgent) 1138 if (!agent.IsChildAgent)
1008 { 1139 {
1009 //agent.ControllingClient.new 1140 if (m_teleportModule != null)
1010 //this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); 1141 m_teleportModule.EnableChildAgent(agent, r);
1011 InformClientOfNeighbor(agent, region);
1012 } 1142 }
1013 } 1143 }
1014 ); 1144 );
@@ -1029,7 +1159,6 @@ namespace OpenSim.Region.Framework.Scenes
1029 { 1159 {
1030 if (m_scripts_enabled != !ScriptEngine) 1160 if (m_scripts_enabled != !ScriptEngine)
1031 { 1161 {
1032 // Tedd! Here's the method to disable the scripting engine!
1033 if (ScriptEngine) 1162 if (ScriptEngine)
1034 { 1163 {
1035 m_log.Info("Stopping all Scripts in Scene"); 1164 m_log.Info("Stopping all Scripts in Scene");
@@ -1051,6 +1180,7 @@ namespace OpenSim.Region.Framework.Scenes
1051 if (ent is SceneObjectGroup) 1180 if (ent is SceneObjectGroup)
1052 { 1181 {
1053 ((SceneObjectGroup)ent).CreateScriptInstances(0, false, DefaultScriptEngine, 0); 1182 ((SceneObjectGroup)ent).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
1183 ((SceneObjectGroup)ent).ResumeScripts();
1054 } 1184 }
1055 } 1185 }
1056 } 1186 }
@@ -1067,10 +1197,7 @@ namespace OpenSim.Region.Framework.Scenes
1067 1197
1068 public int GetInaccurateNeighborCount() 1198 public int GetInaccurateNeighborCount()
1069 { 1199 {
1070 lock (m_neighbours) 1200 return m_neighbours.Count;
1071 {
1072 return m_neighbours.Count;
1073 }
1074 } 1201 }
1075 1202
1076 // This is the method that shuts down the scene. 1203 // This is the method that shuts down the scene.
@@ -1150,12 +1277,89 @@ namespace OpenSim.Region.Framework.Scenes
1150 m_worldCommModule = RequestModuleInterface<IWorldComm>(); 1277 m_worldCommModule = RequestModuleInterface<IWorldComm>();
1151 XferManager = RequestModuleInterface<IXfer>(); 1278 XferManager = RequestModuleInterface<IXfer>();
1152 m_AvatarFactory = RequestModuleInterface<IAvatarFactory>(); 1279 m_AvatarFactory = RequestModuleInterface<IAvatarFactory>();
1280 AttachmentsModule = RequestModuleInterface<IAttachmentsModule>();
1153 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>(); 1281 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>();
1154 m_interregionCommsOut = RequestModuleInterface<IInterregionCommsOut>();
1155 m_interregionCommsIn = RequestModuleInterface<IInterregionCommsIn>();
1156 m_dialogModule = RequestModuleInterface<IDialogModule>(); 1282 m_dialogModule = RequestModuleInterface<IDialogModule>();
1157 m_capsModule = RequestModuleInterface<ICapabilitiesModule>(); 1283 m_capsModule = RequestModuleInterface<ICapabilitiesModule>();
1158 m_teleportModule = RequestModuleInterface<ITeleportModule>(); 1284 m_teleportModule = RequestModuleInterface<IEntityTransferModule>();
1285
1286 // Shoving this in here for now, because we have the needed
1287 // interfaces at this point
1288 //
1289 // TODO: Find a better place for this
1290 //
1291 while (m_regInfo.EstateSettings.EstateOwner == UUID.Zero && MainConsole.Instance != null)
1292 {
1293 MainConsole.Instance.Output("The current estate has no owner set.");
1294 string first = MainConsole.Instance.CmdPrompt("Estate owner first name", "Test");
1295 string last = MainConsole.Instance.CmdPrompt("Estate owner last name", "User");
1296
1297 UserAccount account = UserAccountService.GetUserAccount(m_regInfo.ScopeID, first, last);
1298
1299 if (account == null)
1300 {
1301 // Create a new account
1302 account = new UserAccount(m_regInfo.ScopeID, first, last, String.Empty);
1303 if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
1304 {
1305 account.ServiceURLs = new Dictionary<string, object>();
1306 account.ServiceURLs["HomeURI"] = string.Empty;
1307 account.ServiceURLs["GatekeeperURI"] = string.Empty;
1308 account.ServiceURLs["InventoryServerURI"] = string.Empty;
1309 account.ServiceURLs["AssetServerURI"] = string.Empty;
1310 }
1311
1312 if (UserAccountService.StoreUserAccount(account))
1313 {
1314 string password = MainConsole.Instance.PasswdPrompt("Password");
1315 string email = MainConsole.Instance.CmdPrompt("Email", "");
1316
1317 account.Email = email;
1318 UserAccountService.StoreUserAccount(account);
1319
1320 bool success = false;
1321 success = AuthenticationService.SetPassword(account.PrincipalID, password);
1322 if (!success)
1323 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
1324 first, last);
1325
1326 GridRegion home = null;
1327 if (GridService != null)
1328 {
1329 List<GridRegion> defaultRegions = GridService.GetDefaultRegions(UUID.Zero);
1330 if (defaultRegions != null && defaultRegions.Count >= 1)
1331 home = defaultRegions[0];
1332
1333 if (PresenceService != null && home != null)
1334 PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
1335 else
1336 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
1337 first, last);
1338
1339 }
1340 else
1341 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
1342 first, last);
1343
1344 if (InventoryService != null)
1345 success = InventoryService.CreateUserInventory(account.PrincipalID);
1346 if (!success)
1347 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
1348 first, last);
1349
1350
1351 m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", first, last);
1352
1353 m_regInfo.EstateSettings.EstateOwner = account.PrincipalID;
1354 m_regInfo.EstateSettings.Save();
1355 }
1356 }
1357 else
1358 {
1359 m_regInfo.EstateSettings.EstateOwner = account.PrincipalID;
1360 m_regInfo.EstateSettings.Save();
1361 }
1362 }
1159 } 1363 }
1160 1364
1161 #endregion 1365 #endregion
@@ -1539,7 +1743,7 @@ namespace OpenSim.Region.Framework.Scenes
1539 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1743 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1540 } 1744 }
1541 1745
1542 public void StoreWindlightProfile(RegionMeta7WindlightData wl) 1746 public void StoreWindlightProfile(RegionLightShareData wl)
1543 { 1747 {
1544 m_regInfo.WindlightSettings = wl; 1748 m_regInfo.WindlightSettings = wl;
1545 m_storageManager.DataStore.StoreRegionWindlightSettings(wl); 1749 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
@@ -1605,7 +1809,9 @@ namespace OpenSim.Region.Framework.Scenes
1605 GridRegion region = new GridRegion(RegionInfo); 1809 GridRegion region = new GridRegion(RegionInfo);
1606 string error = GridService.RegisterRegion(RegionInfo.ScopeID, region); 1810 string error = GridService.RegisterRegion(RegionInfo.ScopeID, region);
1607 if (error != String.Empty) 1811 if (error != String.Empty)
1812 {
1608 throw new Exception(error); 1813 throw new Exception(error);
1814 }
1609 1815
1610 m_sceneGridService.SetScene(this); 1816 m_sceneGridService.SetScene(this);
1611 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo); 1817 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo);
@@ -2017,7 +2223,6 @@ namespace OpenSim.Region.Framework.Scenes
2017 /// Move the given scene object into a new region depending on which region its absolute position has moved 2223 /// Move the given scene object into a new region depending on which region its absolute position has moved
2018 /// into. 2224 /// into.
2019 /// 2225 ///
2020 /// This method locates the new region handle and offsets the prim position for the new region
2021 /// </summary> 2226 /// </summary>
2022 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param> 2227 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
2023 /// <param name="grp">the scene object that we're crossing</param> 2228 /// <param name="grp">the scene object that we're crossing</param>
@@ -2059,191 +2264,8 @@ namespace OpenSim.Region.Framework.Scenes
2059 return; 2264 return;
2060 } 2265 }
2061 2266
2062 int thisx = (int)RegionInfo.RegionLocX; 2267 if (m_teleportModule != null)
2063 int thisy = (int)RegionInfo.RegionLocY; 2268 m_teleportModule.Cross(grp, attemptedPosition, silent);
2064 Vector3 EastCross = new Vector3(0.1f,0,0);
2065 Vector3 WestCross = new Vector3(-0.1f, 0, 0);
2066 Vector3 NorthCross = new Vector3(0, 0.1f, 0);
2067 Vector3 SouthCross = new Vector3(0, -0.1f, 0);
2068
2069
2070 // use this if no borders were crossed!
2071 ulong newRegionHandle
2072 = Util.UIntsToLong((uint)((thisx) * Constants.RegionSize),
2073 (uint)((thisy) * Constants.RegionSize));
2074
2075 Vector3 pos = attemptedPosition;
2076
2077 int changeX = 1;
2078 int changeY = 1;
2079
2080 if (TestBorderCross(attemptedPosition + WestCross, Cardinals.W))
2081 {
2082 if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2083 {
2084
2085 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2086
2087 if (crossedBorderx.BorderLine.Z > 0)
2088 {
2089 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2090 changeX = (int)(crossedBorderx.BorderLine.Z /(int) Constants.RegionSize);
2091 }
2092 else
2093 pos.X = ((pos.X + Constants.RegionSize));
2094
2095 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2096 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2097
2098 if (crossedBordery.BorderLine.Z > 0)
2099 {
2100 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2101 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2102 }
2103 else
2104 pos.Y = ((pos.Y + Constants.RegionSize));
2105
2106
2107
2108 newRegionHandle
2109 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2110 (uint)((thisy - changeY) * Constants.RegionSize));
2111 // x - 1
2112 // y - 1
2113 }
2114 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2115 {
2116 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2117
2118 if (crossedBorderx.BorderLine.Z > 0)
2119 {
2120 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2121 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2122 }
2123 else
2124 pos.X = ((pos.X + Constants.RegionSize));
2125
2126
2127 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2128 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2129
2130 try
2131 {
2132 if (crossedBordery.BorderLine.Z > 0)
2133 {
2134 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2135 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2136 }
2137 else
2138 pos.Y = ((pos.Y + Constants.RegionSize));
2139
2140 newRegionHandle
2141 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2142 (uint)((thisy + changeY) * Constants.RegionSize));
2143 // x - 1
2144 // y + 1
2145 }
2146 catch (Exception ex)
2147 {
2148 }
2149 }
2150 else
2151 {
2152 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2153
2154 if (crossedBorderx.BorderLine.Z > 0)
2155 {
2156 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2157 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2158 }
2159 else
2160 pos.X = ((pos.X + Constants.RegionSize));
2161
2162 newRegionHandle
2163 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2164 (uint) (thisy*Constants.RegionSize));
2165 // x - 1
2166 }
2167 }
2168 else if (TestBorderCross(attemptedPosition + EastCross, Cardinals.E))
2169 {
2170 if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2171 {
2172
2173 pos.X = ((pos.X - Constants.RegionSize));
2174 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2175 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2176
2177 if (crossedBordery.BorderLine.Z > 0)
2178 {
2179 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2180 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2181 }
2182 else
2183 pos.Y = ((pos.Y + Constants.RegionSize));
2184
2185
2186 newRegionHandle
2187 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2188 (uint)((thisy - changeY) * Constants.RegionSize));
2189 // x + 1
2190 // y - 1
2191 }
2192 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2193 {
2194 pos.X = ((pos.X - Constants.RegionSize));
2195 pos.Y = ((pos.Y - Constants.RegionSize));
2196 newRegionHandle
2197 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2198 (uint)((thisy + changeY) * Constants.RegionSize));
2199 // x + 1
2200 // y + 1
2201 }
2202 else
2203 {
2204 pos.X = ((pos.X - Constants.RegionSize));
2205 newRegionHandle
2206 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2207 (uint) (thisy*Constants.RegionSize));
2208 // x + 1
2209 }
2210 }
2211 else if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2212 {
2213 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2214 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2215
2216 if (crossedBordery.BorderLine.Z > 0)
2217 {
2218 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2219 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2220 }
2221 else
2222 pos.Y = ((pos.Y + Constants.RegionSize));
2223
2224 newRegionHandle
2225 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - changeY) * Constants.RegionSize));
2226 // y - 1
2227 }
2228 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2229 {
2230
2231 pos.Y = ((pos.Y - Constants.RegionSize));
2232 newRegionHandle
2233 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + changeY) * Constants.RegionSize));
2234 // y + 1
2235 }
2236
2237 // Offset the positions for the new region across the border
2238 Vector3 oldGroupPosition = grp.RootPart.GroupPosition;
2239 grp.OffsetForNewRegion(pos);
2240
2241 // If we fail to cross the border, then reset the position of the scene object on that border.
2242 if (!CrossPrimGroupIntoNewRegion(newRegionHandle, grp, silent))
2243 {
2244 grp.OffsetForNewRegion(oldGroupPosition);
2245 grp.ScheduleGroupForFullUpdate();
2246 }
2247 } 2269 }
2248 2270
2249 public Border GetCrossedBorder(Vector3 position, Cardinals gridline) 2271 public Border GetCrossedBorder(Vector3 position, Cardinals gridline)
@@ -2427,75 +2449,6 @@ namespace OpenSim.Region.Framework.Scenes
2427 2449
2428 2450
2429 /// <summary> 2451 /// <summary>
2430 /// Move the given scene object into a new region
2431 /// </summary>
2432 /// <param name="newRegionHandle"></param>
2433 /// <param name="grp">Scene Object Group that we're crossing</param>
2434 /// <returns>
2435 /// true if the crossing itself was successful, false on failure
2436 /// FIMXE: we still return true if the crossing object was not successfully deleted from the originating region
2437 /// </returns>
2438 public bool CrossPrimGroupIntoNewRegion(ulong newRegionHandle, SceneObjectGroup grp, bool silent)
2439 {
2440 //m_log.Debug(" >>> CrossPrimGroupIntoNewRegion <<<");
2441
2442 bool successYN = false;
2443 grp.RootPart.UpdateFlag = 0;
2444 //int primcrossingXMLmethod = 0;
2445
2446 if (newRegionHandle != 0)
2447 {
2448 //string objectState = grp.GetStateSnapshot();
2449
2450 //successYN
2451 // = m_sceneGridService.PrimCrossToNeighboringRegion(
2452 // newRegionHandle, grp.UUID, m_serialiser.SaveGroupToXml2(grp), primcrossingXMLmethod);
2453 //if (successYN && (objectState != "") && m_allowScriptCrossings)
2454 //{
2455 // successYN = m_sceneGridService.PrimCrossToNeighboringRegion(
2456 // newRegionHandle, grp.UUID, objectState, 100);
2457 //}
2458
2459 // And the new channel...
2460 if (m_interregionCommsOut != null)
2461 successYN = m_interregionCommsOut.SendCreateObject(newRegionHandle, grp, true);
2462
2463 if (successYN)
2464 {
2465 // We remove the object here
2466 try
2467 {
2468 DeleteSceneObject(grp, silent);
2469 }
2470 catch (Exception e)
2471 {
2472 m_log.ErrorFormat(
2473 "[INTERREGION]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
2474 grp, e);
2475 }
2476 }
2477 else
2478 {
2479 if (!grp.IsDeleted)
2480 {
2481 if (grp.RootPart.PhysActor != null)
2482 {
2483 grp.RootPart.PhysActor.CrossingFailure();
2484 }
2485 }
2486
2487 m_log.ErrorFormat("[INTERREGION]: Prim crossing failed for {0}", grp);
2488 }
2489 }
2490 else
2491 {
2492 m_log.Error("[INTERREGION]: region handle was unexpectedly 0 in Scene.CrossPrimGroupIntoNewRegion()");
2493 }
2494
2495 return successYN;
2496 }
2497
2498 /// <summary>
2499 /// Called when objects or attachments cross the border between regions. 2452 /// Called when objects or attachments cross the border between regions.
2500 /// </summary> 2453 /// </summary>
2501 /// <param name="sog"></param> 2454 /// <param name="sog"></param>
@@ -2539,10 +2492,10 @@ namespace OpenSim.Region.Framework.Scenes
2539 //m_log.DebugFormat(" >>> IncomingCreateObject(userID, itemID) <<< {0} {1}", userID, itemID); 2492 //m_log.DebugFormat(" >>> IncomingCreateObject(userID, itemID) <<< {0} {1}", userID, itemID);
2540 2493
2541 ScenePresence sp = GetScenePresence(userID); 2494 ScenePresence sp = GetScenePresence(userID);
2542 if (sp != null) 2495 if (sp != null && AttachmentsModule != null)
2543 { 2496 {
2544 uint attPt = (uint)sp.Appearance.GetAttachpoint(itemID); 2497 uint attPt = (uint)sp.Appearance.GetAttachpoint(itemID);
2545 m_sceneGraph.RezSingleAttachment(sp.ControllingClient, itemID, attPt); 2498 AttachmentsModule.RezSingleAttachmentFromInventory(sp.ControllingClient, itemID, attPt);
2546 } 2499 }
2547 2500
2548 return false; 2501 return false;
@@ -2567,6 +2520,9 @@ namespace OpenSim.Region.Framework.Scenes
2567 2520
2568 return false; 2521 return false;
2569 } 2522 }
2523
2524 sceneObject.SetScene(this);
2525
2570 // Force allocation of new LocalId 2526 // Force allocation of new LocalId
2571 // 2527 //
2572 foreach (SceneObjectPart p in sceneObject.Children.Values) 2528 foreach (SceneObjectPart p in sceneObject.Children.Values)
@@ -2603,9 +2559,11 @@ namespace OpenSim.Region.Framework.Scenes
2603 //grp.SetFromAssetID(grp.RootPart.LastOwnerID); 2559 //grp.SetFromAssetID(grp.RootPart.LastOwnerID);
2604 m_log.DebugFormat( 2560 m_log.DebugFormat(
2605 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition); 2561 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition);
2562
2563 if (AttachmentsModule != null)
2564 AttachmentsModule.AttachObject(
2565 sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition, false);
2606 2566
2607 AttachObject(
2608 sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition, false);
2609 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2567 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2610 grp.SendGroupFullUpdate(); 2568 grp.SendGroupFullUpdate();
2611 } 2569 }
@@ -2645,6 +2603,8 @@ namespace OpenSim.Region.Framework.Scenes
2645 /// <param name="client"></param> 2603 /// <param name="client"></param>
2646 public override void AddNewClient(IClientAPI client) 2604 public override void AddNewClient(IClientAPI client)
2647 { 2605 {
2606 bool vialogin = false;
2607
2648 m_clientManager.Add(client); 2608 m_clientManager.Add(client);
2649 2609
2650 CheckHeartbeat(); 2610 CheckHeartbeat();
@@ -2679,23 +2639,48 @@ namespace OpenSim.Region.Framework.Scenes
2679 { 2639 {
2680 AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); 2640 AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode);
2681 2641
2682 m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); 2642 // Do the verification here
2683 /* 2643 System.Net.EndPoint ep = client.GetClientEP();
2684 string logMsg = string.Format("[SCENE]: Adding new {0} agent for {1} in {2}", 2644 if (aCircuit != null)
2685 ((aCircuit.child == true) ? "child" : "root"), client.Name, 2645 {
2686 RegionInfo.RegionName); 2646 if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0)
2687 2647 {
2688 m_log.Debug(logMsg); 2648 m_log.DebugFormat("[Scene]: Incoming client {0} {1} in region {2} via Login", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName);
2689 */ 2649 vialogin = true;
2650 IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>();
2651 if (userVerification != null && ep != null)
2652 {
2653 if (!userVerification.VerifyClient(aCircuit, ep.ToString()))
2654 {
2655 // uh-oh, this is fishy
2656 m_log.WarnFormat("[Scene]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.",
2657 client.AgentId, client.SessionId, ep.ToString());
2658 try
2659 {
2660 client.Close();
2661 }
2662 catch (Exception e)
2663 {
2664 m_log.DebugFormat("[Scene]: Exception while closing aborted client: {0}", e.StackTrace);
2665 }
2666 return;
2667 }
2668 else
2669 m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} returned true", aCircuit.firstname, aCircuit.lastname);
2670 }
2671 }
2672 }
2690 2673
2691 CommsManager.UserProfileCacheService.AddNewUser(client.AgentId); 2674 m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName);
2692 2675
2693 ScenePresence sp = CreateAndAddScenePresence(client); 2676 ScenePresence sp = CreateAndAddScenePresence(client);
2677 if (aCircuit != null)
2678 sp.Appearance = aCircuit.Appearance;
2694 2679
2695 // HERE!!! Do the initial attachments right here 2680 // HERE!!! Do the initial attachments right here
2696 // first agent upon login is a root agent by design. 2681 // first agent upon login is a root agent by design.
2697 // All other AddNewClient calls find aCircuit.child to be true 2682 // All other AddNewClient calls find aCircuit.child to be true
2698 if (aCircuit == null || aCircuit.child == false) 2683 if (aCircuit == null || (aCircuit != null && aCircuit.child == false))
2699 { 2684 {
2700 sp.IsChildAgent = false; 2685 sp.IsChildAgent = false;
2701 Util.FireAndForget(delegate(object o) { sp.RezAttachments(); }); 2686 Util.FireAndForget(delegate(object o) { sp.RezAttachments(); });
@@ -2704,6 +2689,8 @@ namespace OpenSim.Region.Framework.Scenes
2704 2689
2705 m_LastLogin = Util.EnvironmentTickCount(); 2690 m_LastLogin = Util.EnvironmentTickCount();
2706 EventManager.TriggerOnNewClient(client); 2691 EventManager.TriggerOnNewClient(client);
2692 if (vialogin)
2693 EventManager.TriggerOnClientLogin(client);
2707 } 2694 }
2708 2695
2709 2696
@@ -2790,6 +2777,7 @@ namespace OpenSim.Region.Framework.Scenes
2790 public virtual void SubscribeToClientInventoryEvents(IClientAPI client) 2777 public virtual void SubscribeToClientInventoryEvents(IClientAPI client)
2791 { 2778 {
2792 client.OnCreateNewInventoryItem += CreateNewInventoryItem; 2779 client.OnCreateNewInventoryItem += CreateNewInventoryItem;
2780 client.OnLinkInventoryItem += HandleLinkInventoryItem;
2793 client.OnCreateNewInventoryFolder += HandleCreateInventoryFolder; 2781 client.OnCreateNewInventoryFolder += HandleCreateInventoryFolder;
2794 client.OnUpdateInventoryFolder += HandleUpdateInventoryFolder; 2782 client.OnUpdateInventoryFolder += HandleUpdateInventoryFolder;
2795 client.OnMoveInventoryFolder += HandleMoveInventoryFolder; // 2; //!! 2783 client.OnMoveInventoryFolder += HandleMoveInventoryFolder; // 2; //!!
@@ -2809,19 +2797,21 @@ namespace OpenSim.Region.Framework.Scenes
2809 } 2797 }
2810 2798
2811 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client) 2799 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client)
2812 { 2800 {
2813 client.OnRezSingleAttachmentFromInv += RezSingleAttachment; 2801 if (AttachmentsModule != null)
2814 client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments; 2802 {
2815 client.OnDetachAttachmentIntoInv += DetachSingleAttachmentToInv; 2803 client.OnRezSingleAttachmentFromInv += AttachmentsModule.RezSingleAttachmentFromInventory;
2816 client.OnObjectAttach += m_sceneGraph.AttachObject; 2804 client.OnRezMultipleAttachmentsFromInv += AttachmentsModule.RezMultipleAttachmentsFromInventory;
2817 client.OnObjectDetach += m_sceneGraph.DetachObject; 2805 client.OnObjectAttach += AttachmentsModule.AttachObject;
2806 client.OnObjectDetach += AttachmentsModule.DetachObject;
2807 client.OnDetachAttachmentIntoInv += AttachmentsModule.ShowDetachInUserInventory;
2808 }
2818 } 2809 }
2819 2810
2820 public virtual void SubscribeToClientTeleportEvents(IClientAPI client) 2811 public virtual void SubscribeToClientTeleportEvents(IClientAPI client)
2821 { 2812 {
2822 client.OnTeleportLocationRequest += RequestTeleportLocation; 2813 client.OnTeleportLocationRequest += RequestTeleportLocation;
2823 client.OnTeleportLandmarkRequest += RequestTeleportLandmark; 2814 client.OnTeleportLandmarkRequest += RequestTeleportLandmark;
2824 client.OnTeleportHomeRequest += TeleportClientHome;
2825 } 2815 }
2826 2816
2827 public virtual void SubscribeToClientScriptEvents(IClientAPI client) 2817 public virtual void SubscribeToClientScriptEvents(IClientAPI client)
@@ -2841,7 +2831,7 @@ namespace OpenSim.Region.Framework.Scenes
2841 2831
2842 public virtual void SubscribeToClientGridEvents(IClientAPI client) 2832 public virtual void SubscribeToClientGridEvents(IClientAPI client)
2843 { 2833 {
2844 client.OnNameFromUUIDRequest += CommsManager.HandleUUIDNameRequest; 2834 client.OnNameFromUUIDRequest += HandleUUIDNameRequest;
2845 client.OnMoneyTransferRequest += ProcessMoneyTransferRequest; 2835 client.OnMoneyTransferRequest += ProcessMoneyTransferRequest;
2846 client.OnAvatarPickerRequest += ProcessAvatarPickerRequest; 2836 client.OnAvatarPickerRequest += ProcessAvatarPickerRequest;
2847 client.OnSetStartLocationRequest += SetHomeRezPoint; 2837 client.OnSetStartLocationRequest += SetHomeRezPoint;
@@ -2863,7 +2853,6 @@ namespace OpenSim.Region.Framework.Scenes
2863 2853
2864 protected virtual void UnsubscribeToClientEvents(IClientAPI client) 2854 protected virtual void UnsubscribeToClientEvents(IClientAPI client)
2865 { 2855 {
2866
2867 } 2856 }
2868 2857
2869 /// <summary> 2858 /// <summary>
@@ -2885,7 +2874,6 @@ namespace OpenSim.Region.Framework.Scenes
2885 2874
2886 UnSubscribeToClientNetworkEvents(client); 2875 UnSubscribeToClientNetworkEvents(client);
2887 2876
2888
2889 // EventManager.TriggerOnNewClient(client); 2877 // EventManager.TriggerOnNewClient(client);
2890 } 2878 }
2891 2879
@@ -2942,7 +2930,6 @@ namespace OpenSim.Region.Framework.Scenes
2942 client.OnRezObject -= RezObject; 2930 client.OnRezObject -= RezObject;
2943 } 2931 }
2944 2932
2945
2946 public virtual void UnSubscribeToClientInventoryEvents(IClientAPI client) 2933 public virtual void UnSubscribeToClientInventoryEvents(IClientAPI client)
2947 { 2934 {
2948 client.OnCreateNewInventoryItem -= CreateNewInventoryItem; 2935 client.OnCreateNewInventoryItem -= CreateNewInventoryItem;
@@ -2965,19 +2952,22 @@ namespace OpenSim.Region.Framework.Scenes
2965 } 2952 }
2966 2953
2967 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client) 2954 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client)
2968 { 2955 {
2969 client.OnRezSingleAttachmentFromInv -= RezSingleAttachment; 2956 if (AttachmentsModule != null)
2970 client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments; 2957 {
2971 client.OnDetachAttachmentIntoInv -= DetachSingleAttachmentToInv; 2958 client.OnRezSingleAttachmentFromInv -= AttachmentsModule.RezSingleAttachmentFromInventory;
2972 client.OnObjectAttach -= m_sceneGraph.AttachObject; 2959 client.OnRezMultipleAttachmentsFromInv -= AttachmentsModule.RezMultipleAttachmentsFromInventory;
2973 client.OnObjectDetach -= m_sceneGraph.DetachObject; 2960 client.OnObjectAttach -= AttachmentsModule.AttachObject;
2961 client.OnObjectDetach -= AttachmentsModule.DetachObject;
2962 client.OnDetachAttachmentIntoInv -= AttachmentsModule.ShowDetachInUserInventory;
2963 }
2974 } 2964 }
2975 2965
2976 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client) 2966 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client)
2977 { 2967 {
2978 client.OnTeleportLocationRequest -= RequestTeleportLocation; 2968 client.OnTeleportLocationRequest -= RequestTeleportLocation;
2979 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark; 2969 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark;
2980 client.OnTeleportHomeRequest -= TeleportClientHome; 2970 //client.OnTeleportHomeRequest -= TeleportClientHome;
2981 } 2971 }
2982 2972
2983 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client) 2973 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client)
@@ -2997,7 +2987,7 @@ namespace OpenSim.Region.Framework.Scenes
2997 2987
2998 public virtual void UnSubscribeToClientGridEvents(IClientAPI client) 2988 public virtual void UnSubscribeToClientGridEvents(IClientAPI client)
2999 { 2989 {
3000 client.OnNameFromUUIDRequest -= CommsManager.HandleUUIDNameRequest; 2990 client.OnNameFromUUIDRequest -= HandleUUIDNameRequest;
3001 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest; 2991 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest;
3002 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest; 2992 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest;
3003 client.OnSetStartLocationRequest -= SetHomeRezPoint; 2993 client.OnSetStartLocationRequest -= SetHomeRezPoint;
@@ -3024,30 +3014,12 @@ namespace OpenSim.Region.Framework.Scenes
3024 /// <param name="client">The IClientAPI for the client</param> 3014 /// <param name="client">The IClientAPI for the client</param>
3025 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 3015 public virtual void TeleportClientHome(UUID agentId, IClientAPI client)
3026 { 3016 {
3027 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(agentId); 3017 if (m_teleportModule != null)
3028 if (UserProfile != null) 3018 m_teleportModule.TeleportHome(agentId, client);
3019 else
3029 { 3020 {
3030 GridRegion regionInfo = GridService.GetRegionByUUID(UUID.Zero, UserProfile.HomeRegionID); 3021 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
3031 if (regionInfo == null) 3022 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
3032 {
3033 uint x = 0, y = 0;
3034 Utils.LongToUInts(UserProfile.HomeRegion, out x, out y);
3035 regionInfo = GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
3036 if (regionInfo != null) // home region can be away temporarily, too
3037 {
3038 UserProfile.HomeRegionID = regionInfo.RegionID;
3039 CommsManager.UserService.UpdateUserProfile(UserProfile);
3040 }
3041 }
3042 if (regionInfo == null)
3043 {
3044 // can't find the Home region: Tell viewer and abort
3045 client.SendTeleportFailed("Your home-region could not be found.");
3046 return;
3047 }
3048 RequestTeleportLocation(
3049 client, regionInfo.RegionHandle, UserProfile.HomeLocation, UserProfile.HomeLookAt,
3050 (uint)(TPFlags.SetLastToTarget | TPFlags.ViaHome));
3051 } 3023 }
3052 } 3024 }
3053 3025
@@ -3138,7 +3110,7 @@ namespace OpenSim.Region.Framework.Scenes
3138 } 3110 }
3139 3111
3140 /// <summary> 3112 /// <summary>
3141 /// Sets the Home Point. The GridService uses this to know where to put a user when they log-in 3113 /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
3142 /// </summary> 3114 /// </summary>
3143 /// <param name="remoteClient"></param> 3115 /// <param name="remoteClient"></param>
3144 /// <param name="regionHandle"></param> 3116 /// <param name="regionHandle"></param>
@@ -3147,27 +3119,11 @@ namespace OpenSim.Region.Framework.Scenes
3147 /// <param name="flags"></param> 3119 /// <param name="flags"></param>
3148 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3120 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3149 { 3121 {
3150 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(remoteClient.AgentId); 3122 if (PresenceService.SetHomeLocation(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3151 if (UserProfile != null)
3152 {
3153 // I know I'm ignoring the regionHandle provided by the teleport location request.
3154 // reusing the TeleportLocationRequest delegate, so regionHandle isn't valid
3155 UserProfile.HomeRegionID = RegionInfo.RegionID;
3156 // TODO: The next line can be removed, as soon as only homeRegionID based UserServers are around.
3157 // TODO: The HomeRegion property can be removed then, too
3158 UserProfile.HomeRegion = RegionInfo.RegionHandle;
3159
3160 UserProfile.HomeLocation = position;
3161 UserProfile.HomeLookAt = lookAt;
3162 CommsManager.UserService.UpdateUserProfile(UserProfile);
3163
3164 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3123 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3165 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3124 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
3166 }
3167 else 3125 else
3168 {
3169 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed."); 3126 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed.");
3170 }
3171 } 3127 }
3172 3128
3173 /// <summary> 3129 /// <summary>
@@ -3240,14 +3196,12 @@ namespace OpenSim.Region.Framework.Scenes
3240 m_sceneGraph.removeUserCount(!childagentYN); 3196 m_sceneGraph.removeUserCount(!childagentYN);
3241 CapsModule.RemoveCapsHandler(agentID); 3197 CapsModule.RemoveCapsHandler(agentID);
3242 3198
3243 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID)) 3199 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
3244 { 3200 // this method is doing is HORRIBLE!!!
3245 CommsManager.UserProfileCacheService.RemoveUser(agentID); 3201 avatar.Scene.NeedSceneCacheClear(avatar.UUID);
3246 }
3247 3202
3248 if (!avatar.IsChildAgent) 3203 if (!avatar.IsChildAgent)
3249 { 3204 {
3250 m_sceneGridService.LogOffUser(agentID, RegionInfo.RegionID, RegionInfo.RegionHandle, avatar.AbsolutePosition, avatar.Lookat);
3251 //List<ulong> childknownRegions = new List<ulong>(); 3205 //List<ulong> childknownRegions = new List<ulong>();
3252 //List<ulong> ckn = avatar.KnownChildRegionHandles; 3206 //List<ulong> ckn = avatar.KnownChildRegionHandles;
3253 //for (int i = 0; i < ckn.Count; i++) 3207 //for (int i = 0; i < ckn.Count; i++)
@@ -3302,12 +3256,6 @@ namespace OpenSim.Region.Framework.Scenes
3302 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3256 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3303 } 3257 }
3304 3258
3305 // Remove client agent from profile, so new logins will work
3306 if (!childagentYN)
3307 {
3308 m_sceneGridService.ClearUserAgent(agentID);
3309 }
3310
3311 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3259 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3312 3260
3313 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3261 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
@@ -3380,14 +3328,6 @@ namespace OpenSim.Region.Framework.Scenes
3380 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3328 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3381 m_sceneGridService.KiPrimitive += SendKillObject; 3329 m_sceneGridService.KiPrimitive += SendKillObject;
3382 m_sceneGridService.OnGetLandData += GetLandData; 3330 m_sceneGridService.OnGetLandData += GetLandData;
3383
3384 if (m_interregionCommsIn != null)
3385 {
3386 m_log.Debug("[SCENE]: Registering with InterregionCommsIn");
3387 m_interregionCommsIn.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3388 }
3389 else
3390 m_log.Debug("[SCENE]: Unable to register with InterregionCommsIn");
3391 } 3331 }
3392 3332
3393 /// <summary> 3333 /// <summary>
@@ -3405,9 +3345,6 @@ namespace OpenSim.Region.Framework.Scenes
3405 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent; 3345 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent;
3406 m_sceneGridService.OnGetLandData -= GetLandData; 3346 m_sceneGridService.OnGetLandData -= GetLandData;
3407 3347
3408 if (m_interregionCommsIn != null)
3409 m_interregionCommsIn.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
3410
3411 // this does nothing; should be removed 3348 // this does nothing; should be removed
3412 m_sceneGridService.Close(); 3349 m_sceneGridService.Close();
3413 3350
@@ -3444,6 +3381,7 @@ namespace OpenSim.Region.Framework.Scenes
3444 /// also return a reason.</returns> 3381 /// also return a reason.</returns>
3445 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason) 3382 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason)
3446 { 3383 {
3384 TeleportFlags tp = (TeleportFlags)teleportFlags;
3447 //Teleport flags: 3385 //Teleport flags:
3448 // 3386 //
3449 // TeleportFlags.ViaGodlikeLure - Border Crossing 3387 // TeleportFlags.ViaGodlikeLure - Border Crossing
@@ -3464,7 +3402,7 @@ namespace OpenSim.Region.Framework.Scenes
3464 agent.AgentID, agent.circuitcode, teleportFlags); 3402 agent.AgentID, agent.circuitcode, teleportFlags);
3465 3403
3466 reason = String.Empty; 3404 reason = String.Empty;
3467 if (!AuthenticateUser(agent, out reason)) 3405 if (!VerifyUserPresence(agent, out reason))
3468 return false; 3406 return false;
3469 3407
3470 if (!AuthorizeUser(agent, out reason)) 3408 if (!AuthorizeUser(agent, out reason))
@@ -3477,7 +3415,18 @@ namespace OpenSim.Region.Framework.Scenes
3477 3415
3478 CapsModule.NewUserConnection(agent); 3416 CapsModule.NewUserConnection(agent);
3479 3417
3480 ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID); 3418 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3419
3420 //On login or border crossing test land permisions
3421 if (tp != TeleportFlags.Default)
3422 {
3423 if (land != null && !TestLandRestrictions(agent, land, out reason))
3424 {
3425 return false;
3426 }
3427 }
3428
3429 ScenePresence sp = GetScenePresence(agent.AgentID);
3481 if (sp != null) 3430 if (sp != null)
3482 { 3431 {
3483 m_log.DebugFormat( 3432 m_log.DebugFormat(
@@ -3564,40 +3513,73 @@ namespace OpenSim.Region.Framework.Scenes
3564 */// This is now handled properly in ScenePresence.MakeRootAgent 3513 */// This is now handled properly in ScenePresence.MakeRootAgent
3565 } 3514 }
3566 3515
3516 agent.teleportFlags = teleportFlags;
3567 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3517 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
3568 3518
3569 // rewrite session_id 3519 return true;
3570 CachedUserInfo userinfo = CommsManager.UserProfileCacheService.GetUserDetails(agent.AgentID); 3520 }
3571 if (userinfo != null) 3521
3572 { 3522 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason)
3573 userinfo.SessionID = agent.SessionID; 3523 {
3574 } 3524
3575 else 3525 bool banned = land.IsBannedFromLand(agent.AgentID);
3526 bool restricted = land.IsRestrictedFromLand(agent.AgentID);
3527
3528 if (banned || restricted)
3576 { 3529 {
3577 m_log.WarnFormat( 3530 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y);
3578 "[CONNECTION BEGIN]: We couldn't find a User Info record for {0}. This is usually an indication that the UUID we're looking up is invalid", agent.AgentID); 3531 if (nearestParcel != null)
3532 {
3533 //Move agent to nearest allowed
3534 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3535 agent.startpos.X = newPosition.X;
3536 agent.startpos.Y = newPosition.Y;
3537 }
3538 else
3539 {
3540 if (banned)
3541 {
3542 reason = "Cannot regioncross into banned parcel.";
3543 }
3544 else
3545 {
3546 reason = String.Format("Denied access to private region {0}: You are not on the access list for that region.",
3547 RegionInfo.RegionName);
3548 }
3549 return false;
3550 }
3579 } 3551 }
3580 3552 reason = "";
3581 return true; 3553 return true;
3582 } 3554 }
3583 3555
3584 /// <summary> 3556 /// <summary>
3585 /// Verifies that the user has a session on the Grid 3557 /// Verifies that the user has a presence on the Grid
3586 /// </summary> 3558 /// </summary>
3587 /// <param name="agent">Circuit Data of the Agent we're verifying</param> 3559 /// <param name="agent">Circuit Data of the Agent we're verifying</param>
3588 /// <param name="reason">Outputs the reason for the false response on this string</param> 3560 /// <param name="reason">Outputs the reason for the false response on this string</param>
3589 /// <returns>True if the user has a session on the grid. False if it does not. False will 3561 /// <returns>True if the user has a session on the grid. False if it does not. False will
3590 /// also return a reason.</returns> 3562 /// also return a reason.</returns>
3591 public virtual bool AuthenticateUser(AgentCircuitData agent, out string reason) 3563 public virtual bool VerifyUserPresence(AgentCircuitData agent, out string reason)
3592 { 3564 {
3593 reason = String.Empty; 3565 reason = String.Empty;
3594 3566
3595 bool result = CommsManager.UserService.VerifySession(agent.AgentID, agent.SessionID); 3567 IPresenceService presence = RequestModuleInterface<IPresenceService>();
3596 m_log.Debug("[CONNECTION BEGIN]: User authentication returned " + result); 3568 if (presence == null)
3597 if (!result) 3569 {
3598 reason = String.Format("Failed to authenticate user {0} {1}, access denied.", agent.firstname, agent.lastname); 3570 reason = String.Format("Failed to verify user {0} {1} in region {2}. Presence service does not exist.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3571 return false;
3572 }
3573
3574 OpenSim.Services.Interfaces.PresenceInfo pinfo = presence.GetAgent(agent.SessionID);
3575
3576 if (pinfo == null || (pinfo != null && pinfo.Online == false))
3577 {
3578 reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3579 return false;
3580 }
3599 3581
3600 return result; 3582 return true;
3601 } 3583 }
3602 3584
3603 /// <summary> 3585 /// <summary>
@@ -3702,6 +3684,18 @@ namespace OpenSim.Region.Framework.Scenes
3702 return true; 3684 return true;
3703 } 3685 }
3704 3686
3687 private ILandObject GetParcelAtPoint(float x, float y)
3688 {
3689 foreach (var parcel in AllParcels())
3690 {
3691 if (parcel.ContainsPoint((int)x,(int)y))
3692 {
3693 return parcel;
3694 }
3695 }
3696 return null;
3697 }
3698
3705 /// <summary> 3699 /// <summary>
3706 /// Update an AgentCircuitData object with new information 3700 /// Update an AgentCircuitData object with new information
3707 /// </summary> 3701 /// </summary>
@@ -3730,8 +3724,7 @@ namespace OpenSim.Region.Framework.Scenes
3730 /// <param name="message">message to display to the user. Reason for being logged off</param> 3724 /// <param name="message">message to display to the user. Reason for being logged off</param>
3731 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message) 3725 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message)
3732 { 3726 {
3733 ScenePresence loggingOffUser = null; 3727 ScenePresence loggingOffUser = GetScenePresence(AvatarID);
3734 loggingOffUser = GetScenePresence(AvatarID);
3735 if (loggingOffUser != null) 3728 if (loggingOffUser != null)
3736 { 3729 {
3737 UUID localRegionSecret = UUID.Zero; 3730 UUID localRegionSecret = UUID.Zero;
@@ -3767,10 +3760,8 @@ namespace OpenSim.Region.Framework.Scenes
3767 /// <param name="isFlying"></param> 3760 /// <param name="isFlying"></param>
3768 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) 3761 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying)
3769 { 3762 {
3770 ScenePresence presence; 3763 ScenePresence presence = GetScenePresence(agentID);
3771 m_sceneGraph.TryGetAvatar(agentID, out presence); 3764 if(presence != null)
3772
3773 if (presence != null)
3774 { 3765 {
3775 try 3766 try
3776 { 3767 {
@@ -3798,8 +3789,8 @@ namespace OpenSim.Region.Framework.Scenes
3798 /// <returns>true if we handled it.</returns> 3789 /// <returns>true if we handled it.</returns>
3799 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData) 3790 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData)
3800 { 3791 {
3801// m_log.DebugFormat( 3792 m_log.DebugFormat(
3802// "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName); 3793 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
3803 3794
3804 // We have to wait until the viewer contacts this region after receiving EAC. 3795 // We have to wait until the viewer contacts this region after receiving EAC.
3805 // That calls AddNewClient, which finally creates the ScenePresence 3796 // That calls AddNewClient, which finally creates the ScenePresence
@@ -3868,16 +3859,6 @@ namespace OpenSim.Region.Framework.Scenes
3868 return false; 3859 return false;
3869 } 3860 }
3870 3861
3871 public virtual bool IncomingReleaseAgent(UUID id)
3872 {
3873 return m_sceneGridService.ReleaseAgent(id);
3874 }
3875
3876 public void SendReleaseAgent(ulong regionHandle, UUID id, string uri)
3877 {
3878 m_interregionCommsOut.SendReleaseAgent(regionHandle, id, uri);
3879 }
3880
3881 /// <summary> 3862 /// <summary>
3882 /// Tell a single agent to disconnect from the region. 3863 /// Tell a single agent to disconnect from the region.
3883 /// </summary> 3864 /// </summary>
@@ -3922,30 +3903,6 @@ namespace OpenSim.Region.Framework.Scenes
3922 } 3903 }
3923 3904
3924 /// <summary> 3905 /// <summary>
3925 /// Tell neighboring regions about this agent
3926 /// When the regions respond with a true value,
3927 /// tell the agents about the region.
3928 ///
3929 /// We have to tell the regions about the agents first otherwise it'll deny them access
3930 ///
3931 /// </summary>
3932 /// <param name="presence"></param>
3933 public void InformClientOfNeighbours(ScenePresence presence)
3934 {
3935 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3936 }
3937
3938 /// <summary>
3939 /// Tell a neighboring region about this agent
3940 /// </summary>
3941 /// <param name="presence"></param>
3942 /// <param name="region"></param>
3943 public void InformClientOfNeighbor(ScenePresence presence, RegionInfo region)
3944 {
3945 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3946 }
3947
3948 /// <summary>
3949 /// Tries to teleport agent to other region. 3906 /// Tries to teleport agent to other region.
3950 /// </summary> 3907 /// </summary>
3951 /// <param name="remoteClient"></param> 3908 /// <param name="remoteClient"></param>
@@ -3978,9 +3935,7 @@ namespace OpenSim.Region.Framework.Scenes
3978 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position, 3935 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position,
3979 Vector3 lookAt, uint teleportFlags) 3936 Vector3 lookAt, uint teleportFlags)
3980 { 3937 {
3981 ScenePresence sp; 3938 ScenePresence sp = GetScenePresence(remoteClient.AgentId);
3982 m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp);
3983
3984 if (sp != null) 3939 if (sp != null)
3985 { 3940 {
3986 uint regionX = m_regInfo.RegionLocX; 3941 uint regionX = m_regInfo.RegionLocX;
@@ -4020,16 +3975,12 @@ namespace OpenSim.Region.Framework.Scenes
4020 } 3975 }
4021 3976
4022 if (m_teleportModule != null) 3977 if (m_teleportModule != null)
4023 { 3978 m_teleportModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
4024 m_teleportModule.RequestTeleportToLocation(sp, regionHandle,
4025 position, lookAt, teleportFlags);
4026 }
4027 else 3979 else
4028 { 3980 {
4029 m_sceneGridService.RequestTeleportToLocation(sp, regionHandle, 3981 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active");
4030 position, lookAt, teleportFlags); 3982 sp.ControllingClient.SendTeleportFailed("Unable to perform teleports on this simulator.");
4031 } 3983 }
4032
4033 } 3984 }
4034 } 3985 }
4035 3986
@@ -4055,7 +4006,12 @@ namespace OpenSim.Region.Framework.Scenes
4055 4006
4056 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying) 4007 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying)
4057 { 4008 {
4058 m_sceneGridService.CrossAgentToNewRegion(this, agent, isFlying); 4009 if (m_teleportModule != null)
4010 m_teleportModule.Cross(agent, isFlying);
4011 else
4012 {
4013 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule");
4014 }
4059 } 4015 }
4060 4016
4061 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence) 4017 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence)
@@ -4081,35 +4037,6 @@ namespace OpenSim.Region.Framework.Scenes
4081 objectCapacity = objects; 4037 objectCapacity = objects;
4082 } 4038 }
4083 4039
4084 public List<FriendListItem> GetFriendList(string id)
4085 {
4086 UUID avatarID;
4087 if (!UUID.TryParse(id, out avatarID))
4088 return new List<FriendListItem>();
4089
4090 return CommsManager.GetUserFriendList(avatarID);
4091 }
4092
4093 public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
4094 {
4095 return CommsManager.GetFriendRegionInfos(uuids);
4096 }
4097
4098 public virtual void StoreAddFriendship(UUID ownerID, UUID friendID, uint perms)
4099 {
4100 m_sceneGridService.AddNewUserFriend(ownerID, friendID, perms);
4101 }
4102
4103 public virtual void StoreUpdateFriendship(UUID ownerID, UUID friendID, uint perms)
4104 {
4105 m_sceneGridService.UpdateUserFriendPerms(ownerID, friendID, perms);
4106 }
4107
4108 public virtual void StoreRemoveFriendship(UUID ownerID, UUID ExfriendID)
4109 {
4110 m_sceneGridService.RemoveUserFriend(ownerID, ExfriendID);
4111 }
4112
4113 #endregion 4040 #endregion
4114 4041
4115 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set) 4042 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set)
@@ -4187,17 +4114,17 @@ namespace OpenSim.Region.Framework.Scenes
4187 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", 4114 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname",
4188 "Agent ID", "Session ID", "Circuit", "IP", "World"); 4115 "Agent ID", "Session ID", "Circuit", "IP", "World");
4189 4116
4190 foreach (ScenePresence scenePresence in GetAvatars()) 4117 ForEachScenePresence(delegate(ScenePresence sp)
4191 { 4118 {
4192 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}", 4119 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}",
4193 scenePresence.Firstname, 4120 sp.Firstname,
4194 scenePresence.Lastname, 4121 sp.Lastname,
4195 scenePresence.UUID, 4122 sp.UUID,
4196 scenePresence.ControllingClient.AgentId, 4123 sp.ControllingClient.AgentId,
4197 "Unknown", 4124 "Unknown",
4198 "Unknown", 4125 "Unknown",
4199 RegionInfo.RegionName); 4126 RegionInfo.RegionName);
4200 } 4127 });
4201 4128
4202 break; 4129 break;
4203 } 4130 }
@@ -4363,56 +4290,45 @@ namespace OpenSim.Region.Framework.Scenes
4363 m_sceneGraph.RemovePhysicalPrim(num); 4290 m_sceneGraph.RemovePhysicalPrim(num);
4364 } 4291 }
4365 4292
4366 //The idea is to have a group of method that return a list of avatars meeting some requirement 4293 public int GetRootAgentCount()
4367 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
4368
4369 /// <summary>
4370 /// Return a list of all avatars in this region.
4371 /// This list is a new object, so it can be iterated over without locking.
4372 /// </summary>
4373 /// <returns></returns>
4374 public List<ScenePresence> GetAvatars()
4375 { 4294 {
4376 return m_sceneGraph.GetAvatars(); 4295 return m_sceneGraph.GetRootAgentCount();
4377 } 4296 }
4378 4297
4379 /// <summary> 4298 public int GetChildAgentCount()
4380 /// Cheaply return the number of avatars in a region (without fetching a list object)
4381 /// </summary>
4382 public int GetRootAgentCount()
4383 { 4299 {
4384 return m_sceneGraph.GetRootAgentCount(); 4300 return m_sceneGraph.GetChildAgentCount();
4385 } 4301 }
4386 4302
4387 /// <summary> 4303 /// <summary>
4388 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents. 4304 /// Request a scene presence by UUID. Fast, indexed lookup.
4389 /// This list is a new object, so it can be iterated over without locking.
4390 /// </summary> 4305 /// </summary>
4391 /// <returns></returns> 4306 /// <param name="agentID"></param>
4392 public ScenePresence[] GetScenePresences() 4307 /// <returns>null if the presence was not found</returns>
4308 public ScenePresence GetScenePresence(UUID agentID)
4393 { 4309 {
4394 return m_sceneGraph.GetScenePresences(); 4310 return m_sceneGraph.GetScenePresence(agentID);
4395 } 4311 }
4396 4312
4397 /// <summary> 4313 /// <summary>
4398 /// Request a filtered list of ScenePresences in this region. 4314 /// Request the scene presence by name.
4399 /// This list is a new object, so it can be iterated over without locking.
4400 /// </summary> 4315 /// </summary>
4401 /// <param name="filter"></param> 4316 /// <param name="firstName"></param>
4402 /// <returns></returns> 4317 /// <param name="lastName"></param>
4403 public List<ScenePresence> GetScenePresences(FilterAvatarList filter) 4318 /// <returns>null if the presence was not found</returns>
4319 public ScenePresence GetScenePresence(string firstName, string lastName)
4404 { 4320 {
4405 return m_sceneGraph.GetScenePresences(filter); 4321 return m_sceneGraph.GetScenePresence(firstName, lastName);
4406 } 4322 }
4407 4323
4408 /// <summary> 4324 /// <summary>
4409 /// Request a scene presence by UUID 4325 /// Request the scene presence by localID.
4410 /// </summary> 4326 /// </summary>
4411 /// <param name="avatarID"></param> 4327 /// <param name="localID"></param>
4412 /// <returns></returns> 4328 /// <returns>null if the presence was not found</returns>
4413 public ScenePresence GetScenePresence(UUID avatarID) 4329 public ScenePresence GetScenePresence(uint localID)
4414 { 4330 {
4415 return m_sceneGraph.GetScenePresence(avatarID); 4331 return m_sceneGraph.GetScenePresence(localID);
4416 } 4332 }
4417 4333
4418 public override bool PresenceChildStatus(UUID avatarID) 4334 public override bool PresenceChildStatus(UUID avatarID)
@@ -4430,25 +4346,14 @@ namespace OpenSim.Region.Framework.Scenes
4430 } 4346 }
4431 4347
4432 /// <summary> 4348 /// <summary>
4433 /// 4349 /// Performs action on all scene presences.
4434 /// </summary> 4350 /// </summary>
4435 /// <param name="action"></param> 4351 /// <param name="action"></param>
4436 public void ForEachScenePresence(Action<ScenePresence> action) 4352 public void ForEachScenePresence(Action<ScenePresence> action)
4437 { 4353 {
4438 // We don't want to try to send messages if there are no avatars.
4439 if (m_sceneGraph != null) 4354 if (m_sceneGraph != null)
4440 { 4355 {
4441 try 4356 m_sceneGraph.ForEachScenePresence(action);
4442 {
4443 ScenePresence[] presences = GetScenePresences();
4444 for (int i = 0; i < presences.Length; i++)
4445 action(presences[i]);
4446 }
4447 catch (Exception e)
4448 {
4449 m_log.Info("[BUG] in " + RegionInfo.RegionName + ": " + e.ToString());
4450 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
4451 }
4452 } 4357 }
4453 } 4358 }
4454 4359
@@ -4512,9 +4417,9 @@ namespace OpenSim.Region.Framework.Scenes
4512 return m_sceneGraph.GetGroupByPrim(localID); 4417 return m_sceneGraph.GetGroupByPrim(localID);
4513 } 4418 }
4514 4419
4515 public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 4420 public override bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
4516 { 4421 {
4517 return m_sceneGraph.TryGetAvatar(avatarId, out avatar); 4422 return m_sceneGraph.TryGetScenePresence(avatarId, out avatar);
4518 } 4423 }
4519 4424
4520 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 4425 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
@@ -4524,20 +4429,7 @@ namespace OpenSim.Region.Framework.Scenes
4524 4429
4525 public void ForEachClient(Action<IClientAPI> action) 4430 public void ForEachClient(Action<IClientAPI> action)
4526 { 4431 {
4527 ForEachClient(action, m_useAsyncWhenPossible);
4528 }
4529
4530 public void ForEachClient(Action<IClientAPI> action, bool doAsynchronous)
4531 {
4532 // FIXME: Asynchronous iteration is disabled until we have a threading model that
4533 // can support calling this function from an async packet handler without
4534 // potentially deadlocking
4535 m_clientManager.ForEachSync(action); 4432 m_clientManager.ForEachSync(action);
4536
4537 //if (doAsynchronous)
4538 // m_clientManager.ForEach(action);
4539 //else
4540 // m_clientManager.ForEachSync(action);
4541 } 4433 }
4542 4434
4543 public bool TryGetClient(UUID avatarID, out IClientAPI client) 4435 public bool TryGetClient(UUID avatarID, out IClientAPI client)
@@ -4709,7 +4601,8 @@ namespace OpenSim.Region.Framework.Scenes
4709 group.GetPartName(localID), 4601 group.GetPartName(localID),
4710 group.GetPartDescription(localID), 4602 group.GetPartDescription(localID),
4711 (sbyte)AssetType.Object, 4603 (sbyte)AssetType.Object,
4712 Utils.StringToBytes(sceneObjectXml)); 4604 Utils.StringToBytes(sceneObjectXml),
4605 group.OwnerID);
4713 AssetService.Store(asset); 4606 AssetService.Store(asset);
4714 4607
4715 InventoryItemBase item = new InventoryItemBase(); 4608 InventoryItemBase item = new InventoryItemBase();
@@ -5033,5 +4926,185 @@ namespace OpenSim.Region.Framework.Scenes
5033 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4926 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000)
5034 StartTimer(); 4927 StartTimer();
5035 } 4928 }
4929
4930 public override ISceneObject DeserializeObject(string representation)
4931 {
4932 return SceneObjectSerializer.FromXml2Format(representation);
4933 }
4934
4935 public override bool AllowScriptCrossings
4936 {
4937 get { return m_allowScriptCrossings; }
4938 }
4939
4940 public Vector3? GetNearestAllowedPosition(ScenePresence avatar)
4941 {
4942 //simulate to make sure we have pretty up to date positions
4943 PhysicsScene.Simulate(0);
4944
4945 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
4946
4947 if (nearestParcel != null)
4948 {
4949 Vector3 dir = Vector3.Normalize(Vector3.Multiply(avatar.Velocity, -1));
4950 //Try to get a location that feels like where they came from
4951 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4952 if (nearestPoint != null)
4953 {
4954 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4955 return nearestPoint.Value;
4956 }
4957
4958 //Sometimes velocity might be zero (local teleport), so try finding point along path from avatar to center of nearest parcel
4959 Vector3 directionToParcelCenter = Vector3.Subtract(GetParcelCenterAtGround(nearestParcel), avatar.AbsolutePosition);
4960 dir = Vector3.Normalize(directionToParcelCenter);
4961 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4962 if (nearestPoint != null)
4963 {
4964 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4965 return nearestPoint.Value;
4966 }
4967
4968 //Ultimate backup if we have no idea where they are
4969 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
4970 return avatar.lastKnownAllowedPosition;
4971
4972 }
4973
4974 //Go to the edge, this happens in teleporting to a region with no available parcels
4975 Vector3 nearestRegionEdgePoint = GetNearestRegionEdgePosition(avatar);
4976 //Debug.WriteLine("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString());
4977 return nearestRegionEdgePoint;
4978 return null;
4979 }
4980
4981 private Vector3 GetParcelCenterAtGround(ILandObject parcel)
4982 {
4983 Vector2 center = GetParcelCenter(parcel);
4984 return GetPositionAtGround(center.X, center.Y);
4985 }
4986
4987 private Vector3? GetNearestPointInParcelAlongDirectionFromPoint(Vector3 pos, Vector3 direction, ILandObject parcel)
4988 {
4989 Vector3 unitDirection = Vector3.Normalize(direction);
4990 //Making distance to search go through some sane limit of distance
4991 for (float distance = 0; distance < Constants.RegionSize * 2; distance += .5f)
4992 {
4993 Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance));
4994 if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y))
4995 {
4996 return testPos;
4997 }
4998 }
4999 return null;
5000 }
5001
5002 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
5003 {
5004 List<ILandObject> all = AllParcels();
5005 float minParcelDistance = float.MaxValue;
5006 ILandObject nearestParcel = null;
5007
5008 foreach (var parcel in all)
5009 {
5010 if (!parcel.IsEitherBannedOrRestricted(avatarId))
5011 {
5012 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
5013 if (parcelDistance < minParcelDistance)
5014 {
5015 minParcelDistance = parcelDistance;
5016 nearestParcel = parcel;
5017 }
5018 }
5019 }
5020
5021 return nearestParcel;
5022 }
5023
5024 private List<ILandObject> AllParcels()
5025 {
5026 return LandChannel.AllParcels();
5027 }
5028
5029 private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y)
5030 {
5031 return Vector2.Distance(new Vector2(x, y), GetParcelCenter(parcel));
5032 }
5033
5034 //calculate the average center point of a parcel
5035 private Vector2 GetParcelCenter(ILandObject parcel)
5036 {
5037 int count = 0;
5038 int avgx = 0;
5039 int avgy = 0;
5040 for (int x = 0; x < Constants.RegionSize; x++)
5041 {
5042 for (int y = 0; y < Constants.RegionSize; y++)
5043 {
5044 //Just keep a running average as we check if all the points are inside or not
5045 if (parcel.ContainsPoint(x, y))
5046 {
5047 if (count == 0)
5048 {
5049 avgx = x;
5050 avgy = y;
5051 }
5052 else
5053 {
5054 avgx = (avgx * count + x) / (count + 1);
5055 avgy = (avgy * count + y) / (count + 1);
5056 }
5057 count += 1;
5058 }
5059 }
5060 }
5061 return new Vector2(avgx, avgy);
5062 }
5063
5064 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
5065 {
5066 float xdistance = avatar.AbsolutePosition.X < Constants.RegionSize / 2 ? avatar.AbsolutePosition.X : Constants.RegionSize - avatar.AbsolutePosition.X;
5067 float ydistance = avatar.AbsolutePosition.Y < Constants.RegionSize / 2 ? avatar.AbsolutePosition.Y : Constants.RegionSize - avatar.AbsolutePosition.Y;
5068
5069 //find out what vertical edge to go to
5070 if (xdistance < ydistance)
5071 {
5072 if (avatar.AbsolutePosition.X < Constants.RegionSize / 2)
5073 {
5074 return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
5075 }
5076 else
5077 {
5078 return GetPositionAtAvatarHeightOrGroundHeight(avatar, Constants.RegionSize, avatar.AbsolutePosition.Y);
5079 }
5080 }
5081 //find out what horizontal edge to go to
5082 else
5083 {
5084 if (avatar.AbsolutePosition.Y < Constants.RegionSize / 2)
5085 {
5086 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
5087 }
5088 else
5089 {
5090 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, Constants.RegionSize);
5091 }
5092 }
5093 }
5094
5095 private Vector3 GetPositionAtAvatarHeightOrGroundHeight(ScenePresence avatar, float x, float y)
5096 {
5097 Vector3 ground = GetPositionAtGround(x, y);
5098 if (avatar.AbsolutePosition.Z > ground.Z)
5099 {
5100 ground.Z = avatar.AbsolutePosition.Z;
5101 }
5102 return ground;
5103 }
5104
5105 private Vector3 GetPositionAtGround(float x, float y)
5106 {
5107 return new Vector3(x, y, GetGroundHeight(x, y));
5108 }
5036 } 5109 }
5037} 5110}
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index 5e798c0..3218dad 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -34,7 +34,7 @@ using log4net;
34using Nini.Config; 34using Nini.Config;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
37using OpenSim.Framework.Communications.Cache; 37
38using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
39using GridRegion = OpenSim.Services.Interfaces.GridRegion; 39using GridRegion = OpenSim.Services.Interfaces.GridRegion;
40 40
@@ -190,6 +190,21 @@ namespace OpenSim.Region.Framework.Scenes
190 /// <param name="agentID"></param> 190 /// <param name="agentID"></param>
191 public abstract void RemoveClient(UUID agentID); 191 public abstract void RemoveClient(UUID agentID);
192 192
193 public bool TryGetScenePresence(UUID agentID, out object scenePresence)
194 {
195 scenePresence = null;
196 ScenePresence sp = null;
197 if (TryGetScenePresence(agentID, out sp))
198 {
199 scenePresence = sp;
200 return true;
201 }
202
203 return false;
204 }
205
206 public abstract bool TryGetScenePresence(UUID agentID, out ScenePresence scenePresence);
207
193 #endregion 208 #endregion
194 209
195 /// <summary> 210 /// <summary>
@@ -510,5 +525,16 @@ namespace OpenSim.Region.Framework.Scenes
510 525
511 MainConsole.Instance.Commands.AddCommand(modulename, shared, command, shorthelp, longhelp, callback); 526 MainConsole.Instance.Commands.AddCommand(modulename, shared, command, shorthelp, longhelp, callback);
512 } 527 }
528
529 public virtual ISceneObject DeserializeObject(string representation)
530 {
531 return null;
532 }
533
534 public virtual bool AllowScriptCrossings
535 {
536 get { return false; }
537 }
538
513 } 539 }
514} 540}
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 04626d3..9d0e6f4 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -36,7 +36,6 @@ using log4net;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Framework.Client; 37using OpenSim.Framework.Client;
38using OpenSim.Framework.Communications; 38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Communications.Cache;
40using OpenSim.Framework.Capabilities; 39using OpenSim.Framework.Capabilities;
41using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Services.Interfaces; 41using OpenSim.Services.Interfaces;
@@ -56,8 +55,6 @@ namespace OpenSim.Region.Framework.Scenes
56 { 55 {
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 56 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 57
59 protected CommunicationsManager m_commsProvider;
60 protected IInterregionCommsOut m_interregionCommsOut;
61 protected RegionInfo m_regionInfo; 58 protected RegionInfo m_regionInfo;
62 protected Scene m_scene; 59 protected Scene m_scene;
63 60
@@ -106,29 +103,26 @@ namespace OpenSim.Region.Framework.Scenes
106 /// </summary> 103 /// </summary>
107 public event GetLandData OnGetLandData; 104 public event GetLandData OnGetLandData;
108 105
109 private AgentCrossing handlerAvatarCrossingIntoRegion = null; // OnAvatarCrossingIntoRegion; 106// private AgentCrossing handlerAvatarCrossingIntoRegion = null; // OnAvatarCrossingIntoRegion;
110 private ExpectUserDelegate handlerExpectUser = null; // OnExpectUser; 107// private ExpectUserDelegate handlerExpectUser = null; // OnExpectUser;
111 private CloseAgentConnection handlerCloseAgentConnection = null; // OnCloseAgentConnection; 108// private CloseAgentConnection handlerCloseAgentConnection = null; // OnCloseAgentConnection;
112 private PrimCrossing handlerPrimCrossingIntoRegion = null; // OnPrimCrossingIntoRegion; 109// private PrimCrossing handlerPrimCrossingIntoRegion = null; // OnPrimCrossingIntoRegion;
113 //private RegionUp handlerRegionUp = null; // OnRegionUp; 110 //private RegionUp handlerRegionUp = null; // OnRegionUp;
114 private ChildAgentUpdate handlerChildAgentUpdate = null; // OnChildAgentUpdate; 111// private ChildAgentUpdate handlerChildAgentUpdate = null; // OnChildAgentUpdate;
115 //private RemoveKnownRegionsFromAvatarList handlerRemoveKnownRegionFromAvatar = null; // OnRemoveKnownRegionFromAvatar; 112 //private RemoveKnownRegionsFromAvatarList handlerRemoveKnownRegionFromAvatar = null; // OnRemoveKnownRegionFromAvatar;
116 private LogOffUser handlerLogOffUser = null; 113// private LogOffUser handlerLogOffUser = null;
117 private GetLandData handlerGetLandData = null; // OnGetLandData 114// private GetLandData handlerGetLandData = null; // OnGetLandData
118 115
119 public KiPrimitiveDelegate KiPrimitive; 116 public KiPrimitiveDelegate KiPrimitive;
120 117
121 public SceneCommunicationService(CommunicationsManager commsMan) 118 public SceneCommunicationService()
122 { 119 {
123 m_commsProvider = commsMan;
124 m_agentsInTransit = new List<UUID>();
125 } 120 }
126 121
127 public void SetScene(Scene s) 122 public void SetScene(Scene s)
128 { 123 {
129 m_scene = s; 124 m_scene = s;
130 m_regionInfo = s.RegionInfo; 125 m_regionInfo = s.RegionInfo;
131 m_interregionCommsOut = m_scene.RequestModuleInterface<IInterregionCommsOut>();
132 } 126 }
133 127
134 /// <summary> 128 /// <summary>
@@ -148,377 +142,6 @@ namespace OpenSim.Region.Framework.Scenes
148 { 142 {
149 } 143 }
150 144
151 #region CommsManager Event handlers
152
153 /// <summary>
154 /// A New User will arrive shortly, Informs the scene that there's a new user on the way
155 /// </summary>
156 /// <param name="agent">Data we need to ensure that the agent can connect</param>
157 ///
158 protected void NewUserConnection(AgentCircuitData agent)
159 {
160 handlerExpectUser = OnExpectUser;
161 if (handlerExpectUser != null)
162 {
163 //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: OnExpectUser Fired for User:" + agent.firstname + " " + agent.lastname);
164 handlerExpectUser(agent);
165 }
166 }
167
168 /// <summary>
169 /// The Grid has requested us to log-off the user
170 /// </summary>
171 /// <param name="AgentID">Unique ID of agent to log-off</param>
172 /// <param name="RegionSecret">The secret string that the region establishes with the grid when registering</param>
173 /// <param name="message">The message to send to the user that tells them why they were logged off</param>
174 protected void GridLogOffUser(UUID AgentID, UUID RegionSecret, string message)
175 {
176 handlerLogOffUser = OnLogOffUser;
177 if (handlerLogOffUser != null)
178 {
179 handlerLogOffUser(AgentID, RegionSecret, message);
180 }
181 }
182
183 /// <summary>
184 /// Inform the scene that we've got an update about a child agent that we have
185 /// </summary>
186 /// <param name="cAgentData"></param>
187 /// <returns></returns>
188 protected bool ChildAgentUpdate(ChildAgentDataUpdate cAgentData)
189 {
190 handlerChildAgentUpdate = OnChildAgentUpdate;
191 if (handlerChildAgentUpdate != null)
192 handlerChildAgentUpdate(cAgentData);
193
194 return true;
195 }
196
197
198 protected void AgentCrossing(UUID agentID, Vector3 position, bool isFlying)
199 {
200 handlerAvatarCrossingIntoRegion = OnAvatarCrossingIntoRegion;
201 if (handlerAvatarCrossingIntoRegion != null)
202 {
203 handlerAvatarCrossingIntoRegion(agentID, position, isFlying);
204 }
205 }
206
207 protected void PrimCrossing(UUID primID, Vector3 position, bool isPhysical)
208 {
209 handlerPrimCrossingIntoRegion = OnPrimCrossingIntoRegion;
210 if (handlerPrimCrossingIntoRegion != null)
211 {
212 handlerPrimCrossingIntoRegion(primID, position, isPhysical);
213 }
214 }
215
216 protected bool CloseConnection(UUID agentID)
217 {
218 m_log.Debug("[INTERREGION]: Incoming Agent Close Request for agent: " + agentID);
219
220 handlerCloseAgentConnection = OnCloseAgentConnection;
221 if (handlerCloseAgentConnection != null)
222 {
223 return handlerCloseAgentConnection(agentID);
224 }
225
226 return false;
227 }
228
229 protected LandData FetchLandData(uint x, uint y)
230 {
231 handlerGetLandData = OnGetLandData;
232 if (handlerGetLandData != null)
233 {
234 return handlerGetLandData(x, y);
235 }
236 return null;
237 }
238
239 #endregion
240
241 #region Inform Client of Neighbours
242
243 private delegate void InformClientOfNeighbourDelegate(
244 ScenePresence avatar, AgentCircuitData a, GridRegion reg, IPEndPoint endPoint, bool newAgent);
245
246 private void InformClientOfNeighbourCompleted(IAsyncResult iar)
247 {
248 InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate) iar.AsyncState;
249 icon.EndInvoke(iar);
250 }
251
252 /// <summary>
253 /// Async component for informing client of which neighbours exist
254 /// </summary>
255 /// <remarks>
256 /// This needs to run asynchronously, as a network timeout may block the thread for a long while
257 /// </remarks>
258 /// <param name="remoteClient"></param>
259 /// <param name="a"></param>
260 /// <param name="regionHandle"></param>
261 /// <param name="endPoint"></param>
262 private void InformClientOfNeighbourAsync(ScenePresence avatar, AgentCircuitData a, GridRegion reg,
263 IPEndPoint endPoint, bool newAgent)
264 {
265 // Let's wait just a little to give time to originating regions to catch up with closing child agents
266 // after a cross here
267 Thread.Sleep(500);
268
269 uint x, y;
270 Utils.LongToUInts(reg.RegionHandle, out x, out y);
271 x = x / Constants.RegionSize;
272 y = y / Constants.RegionSize;
273 m_log.Info("[INTERGRID]: Starting to inform client about neighbour " + x + ", " + y + "(" + endPoint.ToString() + ")");
274
275 string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
276 + "/CAPS/" + a.CapsPath + "0000/";
277
278 string reason = String.Empty;
279
280
281 bool regionAccepted = m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, a, 0, out reason);
282
283 if (regionAccepted && newAgent)
284 {
285 IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
286 if (eq != null)
287 {
288 #region IP Translation for NAT
289 IClientIPEndpoint ipepClient;
290 if (avatar.ClientView.TryGet(out ipepClient))
291 {
292 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
293 }
294 #endregion
295
296 eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID);
297 eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath);
298 m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1} in region {2}",
299 capsPath, avatar.UUID, avatar.Scene.RegionInfo.RegionName);
300 }
301 else
302 {
303 avatar.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint);
304 // TODO: make Event Queue disablable!
305 }
306
307 m_log.Info("[INTERGRID]: Completed inform client about neighbour " + endPoint.ToString());
308
309 }
310
311 }
312
313 public List<GridRegion> RequestNeighbours(Scene pScene, uint pRegionLocX, uint pRegionLocY)
314 {
315 Border[] northBorders = pScene.NorthBorders.ToArray();
316 Border[] southBorders = pScene.SouthBorders.ToArray();
317 Border[] eastBorders = pScene.EastBorders.ToArray();
318 Border[] westBorders = pScene.WestBorders.ToArray();
319
320 // Legacy one region. Provided for simplicity while testing the all inclusive method in the else statement.
321 if (northBorders.Length <= 1 && southBorders.Length <= 1 && eastBorders.Length <= 1 && westBorders.Length <= 1)
322 {
323 return m_scene.GridService.GetNeighbours(m_regionInfo.ScopeID, m_regionInfo.RegionID);
324 }
325 else
326 {
327 Vector2 extent = Vector2.Zero;
328 for (int i = 0; i < eastBorders.Length; i++)
329 {
330 extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X;
331 }
332 for (int i = 0; i < northBorders.Length; i++)
333 {
334 extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y;
335 }
336
337 // Loss of fraction on purpose
338 extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1;
339 extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1;
340
341 int startX = (int)(pRegionLocX - 1) * (int)Constants.RegionSize;
342 int startY = (int)(pRegionLocY - 1) * (int)Constants.RegionSize;
343
344 int endX = ((int)pRegionLocX + (int)extent.X) * (int)Constants.RegionSize;
345 int endY = ((int)pRegionLocY + (int)extent.Y) * (int)Constants.RegionSize;
346
347 List<GridRegion> neighbours = m_scene.GridService.GetRegionRange(m_regionInfo.ScopeID, startX, endX, startY, endY);
348 neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; });
349
350 return neighbours;
351 }
352 }
353
354 /// <summary>
355 /// This informs all neighboring regions about agent "avatar".
356 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
357 /// </summary>
358 public void EnableNeighbourChildAgents(ScenePresence avatar, List<RegionInfo> lstneighbours)
359 {
360 List<GridRegion> neighbours = new List<GridRegion>();
361
362 if (m_regionInfo != null)
363 {
364 neighbours = RequestNeighbours(avatar.Scene,m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
365 }
366 else
367 {
368 m_log.Debug("[ENABLENEIGHBOURCHILDAGENTS]: m_regionInfo was null in EnableNeighbourChildAgents, is this a NPC?");
369 }
370
371 /// We need to find the difference between the new regions where there are no child agents
372 /// and the regions where there are already child agents. We only send notification to the former.
373 List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
374 neighbourHandles.Add(avatar.Scene.RegionInfo.RegionHandle); // add this region too
375 List<ulong> previousRegionNeighbourHandles ;
376
377 if (avatar.Scene.CapsModule != null)
378 {
379 previousRegionNeighbourHandles =
380 new List<ulong>(avatar.Scene.CapsModule.GetChildrenSeeds(avatar.UUID).Keys);
381 }
382 else
383 {
384 previousRegionNeighbourHandles = new List<ulong>();
385 }
386
387 List<ulong> newRegions = NewNeighbours(neighbourHandles, previousRegionNeighbourHandles);
388 List<ulong> oldRegions = OldNeighbours(neighbourHandles, previousRegionNeighbourHandles);
389
390 //Dump("Current Neighbors", neighbourHandles);
391 //Dump("Previous Neighbours", previousRegionNeighbourHandles);
392 //Dump("New Neighbours", newRegions);
393 //Dump("Old Neighbours", oldRegions);
394
395 /// Update the scene presence's known regions here on this region
396 avatar.DropOldNeighbours(oldRegions);
397
398 /// Collect as many seeds as possible
399 Dictionary<ulong, string> seeds;
400 if (avatar.Scene.CapsModule != null)
401 seeds
402 = new Dictionary<ulong, string>(avatar.Scene.CapsModule.GetChildrenSeeds(avatar.UUID));
403 else
404 seeds = new Dictionary<ulong, string>();
405
406 //m_log.Debug(" !!! No. of seeds: " + seeds.Count);
407 if (!seeds.ContainsKey(avatar.Scene.RegionInfo.RegionHandle))
408 seeds.Add(avatar.Scene.RegionInfo.RegionHandle, avatar.ControllingClient.RequestClientInfo().CapsPath);
409
410 /// Create the necessary child agents
411 List<AgentCircuitData> cagents = new List<AgentCircuitData>();
412 foreach (GridRegion neighbour in neighbours)
413 {
414 if (neighbour.RegionHandle != avatar.Scene.RegionInfo.RegionHandle)
415 {
416
417 AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
418 agent.BaseFolder = UUID.Zero;
419 agent.InventoryFolder = UUID.Zero;
420 agent.startpos = new Vector3(128, 128, 70);
421 agent.child = true;
422
423 if (newRegions.Contains(neighbour.RegionHandle))
424 {
425 agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
426 avatar.AddNeighbourRegion(neighbour.RegionHandle, agent.CapsPath);
427 seeds.Add(neighbour.RegionHandle, agent.CapsPath);
428 }
429 else
430 agent.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, neighbour.RegionHandle);
431
432 cagents.Add(agent);
433 }
434 }
435
436 /// Update all child agent with everyone's seeds
437 foreach (AgentCircuitData a in cagents)
438 {
439 a.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds);
440 }
441
442 if (avatar.Scene.CapsModule != null)
443 {
444 // These two are the same thing!
445 avatar.Scene.CapsModule.SetChildrenSeed(avatar.UUID, seeds);
446 }
447 avatar.KnownRegions = seeds;
448 //avatar.Scene.DumpChildrenSeeds(avatar.UUID);
449 //avatar.DumpKnownRegions();
450
451 bool newAgent = false;
452 int count = 0;
453 foreach (GridRegion neighbour in neighbours)
454 {
455 // Don't do it if there's already an agent in that region
456 if (newRegions.Contains(neighbour.RegionHandle))
457 newAgent = true;
458 else
459 newAgent = false;
460
461 if (neighbour.RegionHandle != avatar.Scene.RegionInfo.RegionHandle)
462 {
463 InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
464 try
465 {
466 d.BeginInvoke(avatar, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent,
467 InformClientOfNeighbourCompleted,
468 d);
469 }
470
471 catch (ArgumentOutOfRangeException)
472 {
473 m_log.ErrorFormat(
474 "[REGIONINFO]: Neighbour Regions response included the current region in the neighbor list. The following region will not display to the client: {0} for region {1} ({2}, {3}).",
475 neighbour.ExternalHostName,
476 neighbour.RegionHandle,
477 neighbour.RegionLocX,
478 neighbour.RegionLocY);
479 }
480 catch (Exception e)
481 {
482 m_log.ErrorFormat(
483 "[REGIONINFO]: Could not resolve external hostname {0} for region {1} ({2}, {3}). {4}",
484 neighbour.ExternalHostName,
485 neighbour.RegionHandle,
486 neighbour.RegionLocX,
487 neighbour.RegionLocY,
488 e);
489
490 // FIXME: Okay, even though we've failed, we're still going to throw the exception on,
491 // since I don't know what will happen if we just let the client continue
492
493 // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes.
494 // throw e;
495
496 }
497 }
498 count++;
499 }
500 }
501
502 /// <summary>
503 /// This informs a single neighboring region about agent "avatar".
504 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
505 /// </summary>
506 public void InformNeighborChildAgent(ScenePresence avatar, GridRegion region)
507 {
508 AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
509 agent.BaseFolder = UUID.Zero;
510 agent.InventoryFolder = UUID.Zero;
511 agent.startpos = new Vector3(128, 128, 70);
512 agent.child = true;
513
514 InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
515 d.BeginInvoke(avatar, agent, region, region.ExternalEndPoint, true,
516 InformClientOfNeighbourCompleted,
517 d);
518 }
519
520 #endregion
521
522 public delegate void InformNeighbourThatRegionUpDelegate(INeighbourService nService, RegionInfo region, ulong regionhandle); 145 public delegate void InformNeighbourThatRegionUpDelegate(INeighbourService nService, RegionInfo region, ulong regionhandle);
523 146
524 private void InformNeighborsThatRegionisUpCompleted(IAsyncResult iar) 147 private void InformNeighborsThatRegionisUpCompleted(IAsyncResult iar)
@@ -550,7 +173,7 @@ namespace OpenSim.Region.Framework.Scenes
550 } 173 }
551 else 174 else
552 { 175 {
553 m_log.WarnFormat("[INTERGRID]: Failed to inform neighbour {0}-{1} that I'm here.", x / Constants.RegionSize, y / Constants.RegionSize); 176 m_log.InfoFormat("[INTERGRID]: Failed to inform neighbour {0}-{1} that I'm here.", x / Constants.RegionSize, y / Constants.RegionSize);
554 } 177 }
555 } 178 }
556 179
@@ -592,7 +215,10 @@ namespace OpenSim.Region.Framework.Scenes
592 try 215 try
593 { 216 {
594 //m_commsProvider.InterRegion.ChildAgentUpdate(regionHandle, cAgentData); 217 //m_commsProvider.InterRegion.ChildAgentUpdate(regionHandle, cAgentData);
595 m_interregionCommsOut.SendChildAgentUpdate(regionHandle, cAgentData); 218 uint x = 0, y = 0;
219 Utils.LongToUInts(regionHandle, out x, out y);
220 GridRegion destination = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
221 m_scene.SimulationService.UpdateAgent(destination, cAgentData);
596 } 222 }
597 catch 223 catch
598 { 224 {
@@ -652,7 +278,10 @@ namespace OpenSim.Region.Framework.Scenes
652 // let's do our best, but there's not much we can do if the neighbour doesn't accept. 278 // let's do our best, but there's not much we can do if the neighbour doesn't accept.
653 279
654 //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); 280 //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID);
655 m_interregionCommsOut.SendCloseAgent(regionHandle, agentID); 281 uint x = 0, y = 0;
282 Utils.LongToUInts(regionHandle, out x, out y);
283 GridRegion destination = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
284 m_scene.SimulationService.CloseAgent(destination, agentID);
656 } 285 }
657 286
658 private void SendCloseChildAgentCompleted(IAsyncResult iar) 287 private void SendCloseChildAgentCompleted(IAsyncResult iar)
@@ -672,848 +301,10 @@ namespace OpenSim.Region.Framework.Scenes
672 } 301 }
673 } 302 }
674 303
675
676 /// <summary>
677 /// Try to teleport an agent to a new region.
678 /// </summary>
679 /// <param name="remoteClient"></param>
680 /// <param name="RegionHandle"></param>
681 /// <param name="position"></param>
682 /// <param name="lookAt"></param>
683 /// <param name="flags"></param>
684 public virtual void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position,
685 Vector3 lookAt, uint teleportFlags)
686 {
687 if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID))
688 return;
689
690 bool destRegionUp = true;
691
692 IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
693
694 // Reset animations; the viewer does that in teleports.
695 avatar.Animator.ResetAnimations();
696
697 if (regionHandle == m_regionInfo.RegionHandle)
698 {
699 m_log.DebugFormat(
700 "[SCENE COMMUNICATION SERVICE]: RequestTeleportToLocation {0} within {1}",
701 position, m_regionInfo.RegionName);
702
703 // Teleport within the same region
704 if (IsOutsideRegion(avatar.Scene, position) || position.Z < 0)
705 {
706 Vector3 emergencyPos = new Vector3(128, 128, 128);
707
708 m_log.WarnFormat(
709 "[SCENE COMMUNICATION SERVICE]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
710 position, avatar.Name, avatar.UUID, emergencyPos);
711 position = emergencyPos;
712 }
713
714 Vector3 currentPos = avatar.AbsolutePosition;
715 ILandObject srcLand = m_scene.LandChannel.GetLandObject(currentPos.X, currentPos.Y);
716 ILandObject destLand = m_scene.LandChannel.GetLandObject(position.X, position.Y);
717 if (srcLand != null && destLand != null && (teleportFlags & (uint)TeleportFlags.ViaLure) == 0 && (teleportFlags & (uint)TeleportFlags.ViaGodlikeLure) == 0)
718 {
719 if (srcLand.LandData.LocalID == destLand.LandData.LocalID)
720 {
721 //TPing within the same parcel. If the landing point is restricted, block the TP.
722 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
723 if (destLand.LandData.LandingType == (byte)1 && destLand.LandData.UserLocation != Vector3.Zero && avatar.GodLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar.UUID) && destLand.LandData.OwnerID != avatar.UUID)
724 {
725 //Disabling this behaviour for now pending review. ~CasperW
726
727 //avatar.ControllingClient.SendAgentAlertMessage("Can't TP to the destination; landing point set.", false);
728 //position = currentPos;
729 }
730 }
731 else
732 {
733 //Tping to a different parcel. Respect the landing point on the destination parcel.
734 if (destLand.LandData.LandingType == (byte)1 && destLand.LandData.UserLocation != Vector3.Zero && avatar.GodLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar.UUID) && destLand.LandData.OwnerID != avatar.UUID)
735 {
736 position = destLand.LandData.UserLocation;
737 }
738 }
739 }
740
741 // TODO: Get proper AVG Height
742 float localAVHeight = 1.56f;
743 float posZLimit = 22;
744
745 // TODO: Check other Scene HeightField
746 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <=(int)Constants.RegionSize)
747 {
748 posZLimit = (float) avatar.Scene.Heightmap[(int) position.X, (int) position.Y];
749 }
750
751 float newPosZ = posZLimit + localAVHeight;
752 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
753 {
754 position.Z = newPosZ;
755 }
756
757 // Only send this if the event queue is null
758 if (eq == null)
759 avatar.ControllingClient.SendTeleportLocationStart();
760
761 avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
762 avatar.Teleport(position);
763 }
764 else
765 {
766 uint x = 0, y = 0;
767 Utils.LongToUInts(regionHandle, out x, out y);
768 GridRegion reg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
769
770 if (reg != null)
771 {
772 m_log.DebugFormat(
773 "[SCENE COMMUNICATION SERVICE]: RequestTeleportToLocation to {0} in {1}",
774 position, reg.RegionName);
775
776 if (eq == null)
777 avatar.ControllingClient.SendTeleportLocationStart();
778
779 // Let's do DNS resolution only once in this process, please!
780 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
781 // it's actually doing a lot of work.
782 IPEndPoint endPoint = reg.ExternalEndPoint;
783 if (endPoint.Address == null)
784 {
785 // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses.
786 destRegionUp = false;
787 }
788
789 if (destRegionUp)
790 {
791 uint newRegionX = (uint)(reg.RegionHandle >> 40);
792 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
793 uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
794 uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
795
796 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
797 // both regions
798 if (avatar.ParentID != (uint)0)
799 avatar.StandUp();
800
801 if (!avatar.ValidateAttachments())
802 {
803 avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
804 return;
805 }
806
807 // the avatar.Close below will clear the child region list. We need this below for (possibly)
808 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
809 //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
810 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
811 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
812 // once we reach here...
813 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
814
815 string capsPath = String.Empty;
816 AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo();
817 agentCircuit.BaseFolder = UUID.Zero;
818 agentCircuit.InventoryFolder = UUID.Zero;
819 agentCircuit.startpos = position;
820 agentCircuit.child = true;
821
822 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
823 {
824 // brand new agent, let's create a new caps seed
825 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
826 }
827
828 string reason = String.Empty;
829
830 // Let's create an agent there if one doesn't exist yet.
831 //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
832 if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit, teleportFlags, out reason))
833 {
834 avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
835 reason));
836 return;
837 }
838
839 // OK, it got this agent. Let's close some child agents
840 avatar.CloseChildAgents(newRegionX, newRegionY);
841
842 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
843 {
844 #region IP Translation for NAT
845 IClientIPEndpoint ipepClient;
846 if (avatar.ClientView.TryGet(out ipepClient))
847 {
848 capsPath
849 = "http://"
850 + NetworkUtil.GetHostFor(ipepClient.EndPoint, reg.ExternalHostName)
851 + ":"
852 + reg.HttpPort
853 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
854 }
855 else
856 {
857 capsPath
858 = "http://"
859 + reg.ExternalHostName
860 + ":"
861 + reg.HttpPort
862 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
863 }
864 #endregion
865
866 if (eq != null)
867 {
868 #region IP Translation for NAT
869 // Uses ipepClient above
870 if (avatar.ClientView.TryGet(out ipepClient))
871 {
872 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
873 }
874 #endregion
875
876 eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID);
877
878 // ES makes the client send a UseCircuitCode message to the destination,
879 // which triggers a bunch of things there.
880 // So let's wait
881 Thread.Sleep(2000);
882
883 eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath);
884 }
885 else
886 {
887 avatar.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint);
888 }
889 }
890 else
891 {
892 agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle);
893 capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
894 + "/CAPS/" + agentCircuit.CapsPath + "0000/";
895 }
896
897 // Expect avatar crossing is a heavy-duty function at the destination.
898 // That is where MakeRoot is called, which fetches appearance and inventory.
899 // Plus triggers OnMakeRoot, which spawns a series of asynchronous updates.
900 //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
901 // position, false);
902
903 //{
904 // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
905 // // We should close that agent we just created over at destination...
906 // List<ulong> lst = new List<ulong>();
907 // lst.Add(reg.RegionHandle);
908 // SendCloseChildAgentAsync(avatar.UUID, lst);
909 // return;
910 //}
911
912 SetInTransit(avatar.UUID);
913 // Let's send a full update of the agent. This is a synchronous call.
914 AgentData agent = new AgentData();
915 avatar.CopyTo(agent);
916 agent.Position = position;
917 agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
918 "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionHandle.ToString() + "/release/";
919
920 m_interregionCommsOut.SendChildAgentUpdate(reg.RegionHandle, agent);
921
922 m_log.DebugFormat(
923 "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, avatar.UUID);
924
925
926 if (eq != null)
927 {
928 eq.TeleportFinishEvent(reg.RegionHandle, 13, endPoint,
929 0, teleportFlags, capsPath, avatar.UUID);
930 }
931 else
932 {
933 avatar.ControllingClient.SendRegionTeleport(reg.RegionHandle, 13, endPoint, 4,
934 teleportFlags, capsPath);
935 }
936
937 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
938 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
939 // that the client contacted the destination before we send the attachments and close things here.
940 if (!WaitForCallback(avatar.UUID))
941 {
942 // Client never contacted destination. Let's restore everything back
943 avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
944
945 ResetFromTransit(avatar.UUID);
946
947 // Yikes! We should just have a ref to scene here.
948 avatar.Scene.InformClientOfNeighbours(avatar);
949
950 // Finally, kill the agent we just created at the destination.
951 m_interregionCommsOut.SendCloseAgent(reg.RegionHandle, avatar.UUID);
952
953 return;
954 }
955
956 // Can't go back from here
957 if (KiPrimitive != null)
958 {
959 KiPrimitive(avatar.LocalId);
960 }
961
962 avatar.MakeChildAgent();
963
964 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
965 avatar.CrossAttachmentsIntoNewRegion(reg.RegionHandle, true);
966
967 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
968
969 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
970 {
971 Thread.Sleep(5000);
972 avatar.Close();
973 CloseConnection(avatar.UUID);
974 }
975 else
976 // now we have a child agent in this region.
977 avatar.Reset();
978
979
980 // if (teleport success) // seems to be always success here
981 // the user may change their profile information in other region,
982 // so the userinfo in UserProfileCache is not reliable any more, delete it
983 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID))
984 {
985 m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID);
986 m_log.DebugFormat(
987 "[SCENE COMMUNICATION SERVICE]: User {0} is going to another region, profile cache removed",
988 avatar.UUID);
989 }
990 }
991 else
992 {
993 avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
994 }
995 }
996 else
997 {
998 // TP to a place that doesn't exist (anymore)
999 // Inform the viewer about that
1000 avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
1001
1002 // and set the map-tile to '(Offline)'
1003 uint regX, regY;
1004 Utils.LongToUInts(regionHandle, out regX, out regY);
1005
1006 MapBlockData block = new MapBlockData();
1007 block.X = (ushort)(regX / Constants.RegionSize);
1008 block.Y = (ushort)(regY / Constants.RegionSize);
1009 block.Access = 254; // == not there
1010
1011 List<MapBlockData> blocks = new List<MapBlockData>();
1012 blocks.Add(block);
1013 avatar.ControllingClient.SendMapBlock(blocks, 0);
1014 }
1015 }
1016 }
1017
1018 protected bool IsOutsideRegion(Scene s, Vector3 pos)
1019 {
1020
1021 if (s.TestBorderCross(pos,Cardinals.N))
1022 return true;
1023 if (s.TestBorderCross(pos, Cardinals.S))
1024 return true;
1025 if (s.TestBorderCross(pos, Cardinals.E))
1026 return true;
1027 if (s.TestBorderCross(pos, Cardinals.W))
1028 return true;
1029
1030 return false;
1031 }
1032
1033 public bool WaitForCallback(UUID id)
1034 {
1035 int count = 400;
1036 while (m_agentsInTransit.Contains(id) && count-- > 0)
1037 {
1038 //m_log.Debug(" >>> Waiting... " + count);
1039 Thread.Sleep(100);
1040 }
1041
1042 if (count > 0)
1043 return true;
1044 else
1045 return false;
1046 }
1047
1048 public bool ReleaseAgent(UUID id)
1049 {
1050 //m_log.Debug(" >>> ReleaseAgent called <<< ");
1051 return ResetFromTransit(id);
1052 }
1053
1054 public void SetInTransit(UUID id)
1055 {
1056 lock (m_agentsInTransit)
1057 {
1058 if (!m_agentsInTransit.Contains(id))
1059 m_agentsInTransit.Add(id);
1060 }
1061 }
1062
1063 protected bool ResetFromTransit(UUID id)
1064 {
1065 lock (m_agentsInTransit)
1066 {
1067 if (m_agentsInTransit.Contains(id))
1068 {
1069 m_agentsInTransit.Remove(id);
1070 return true;
1071 }
1072 }
1073 return false;
1074 }
1075
1076 private List<ulong> NeighbourHandles(List<GridRegion> neighbours)
1077 {
1078 List<ulong> handles = new List<ulong>();
1079 foreach (GridRegion reg in neighbours)
1080 {
1081 handles.Add(reg.RegionHandle);
1082 }
1083 return handles;
1084 }
1085
1086 private List<ulong> NewNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
1087 {
1088 return currentNeighbours.FindAll(delegate(ulong handle) { return !previousNeighbours.Contains(handle); });
1089 }
1090
1091// private List<ulong> CommonNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
1092// {
1093// return currentNeighbours.FindAll(delegate(ulong handle) { return previousNeighbours.Contains(handle); });
1094// }
1095
1096 private List<ulong> OldNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
1097 {
1098 return previousNeighbours.FindAll(delegate(ulong handle) { return !currentNeighbours.Contains(handle); });
1099 }
1100
1101 public void CrossAgentToNewRegion(Scene scene, ScenePresence agent, bool isFlying)
1102 {
1103 Vector3 pos = agent.AbsolutePosition;
1104 Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
1105 uint neighbourx = m_regionInfo.RegionLocX;
1106 uint neighboury = m_regionInfo.RegionLocY;
1107 const float boundaryDistance = 1.7f;
1108 Vector3 northCross = new Vector3(0,boundaryDistance, 0);
1109 Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
1110 Vector3 eastCross = new Vector3(boundaryDistance, 0, 0);
1111 Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0);
1112
1113 // distance to edge that will trigger crossing
1114
1115
1116 // distance into new region to place avatar
1117 const float enterDistance = 0.5f;
1118
1119 if (scene.TestBorderCross(pos + westCross, Cardinals.W))
1120 {
1121 if (scene.TestBorderCross(pos + northCross, Cardinals.N))
1122 {
1123 Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
1124 neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
1125 }
1126 else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
1127 {
1128 Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
1129 if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
1130 {
1131 neighboury--;
1132 newpos.Y = Constants.RegionSize - enterDistance;
1133 }
1134 else
1135 {
1136 neighboury = b.TriggerRegionY;
1137 neighbourx = b.TriggerRegionX;
1138
1139 Vector3 newposition = pos;
1140 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
1141 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
1142 agent.ControllingClient.SendAgentAlertMessage(
1143 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1144 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
1145 return;
1146 }
1147 }
1148
1149 Border ba = scene.GetCrossedBorder(pos + westCross, Cardinals.W);
1150 if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
1151 {
1152 neighbourx--;
1153 newpos.X = Constants.RegionSize - enterDistance;
1154 }
1155 else
1156 {
1157 neighboury = ba.TriggerRegionY;
1158 neighbourx = ba.TriggerRegionX;
1159
1160
1161 Vector3 newposition = pos;
1162 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
1163 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
1164 agent.ControllingClient.SendAgentAlertMessage(
1165 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1166 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
1167
1168
1169 return;
1170 }
1171
1172 }
1173 else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
1174 {
1175 Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E);
1176 neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
1177 newpos.X = enterDistance;
1178
1179 if (scene.TestBorderCross(pos + southCross, Cardinals.S))
1180 {
1181 Border ba = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
1182 if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
1183 {
1184 neighboury--;
1185 newpos.Y = Constants.RegionSize - enterDistance;
1186 }
1187 else
1188 {
1189 neighboury = ba.TriggerRegionY;
1190 neighbourx = ba.TriggerRegionX;
1191 Vector3 newposition = pos;
1192 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
1193 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
1194 agent.ControllingClient.SendAgentAlertMessage(
1195 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1196 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
1197 return;
1198 }
1199 }
1200 else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
1201 {
1202 Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
1203 neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize);
1204 newpos.Y = enterDistance;
1205 }
1206
1207
1208 }
1209 else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
1210 {
1211 Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
1212 if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
1213 {
1214 neighboury--;
1215 newpos.Y = Constants.RegionSize - enterDistance;
1216 }
1217 else
1218 {
1219 neighboury = b.TriggerRegionY;
1220 neighbourx = b.TriggerRegionX;
1221 Vector3 newposition = pos;
1222 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
1223 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
1224 agent.ControllingClient.SendAgentAlertMessage(
1225 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
1226 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
1227 return;
1228 }
1229 }
1230 else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
1231 {
1232
1233 Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
1234 neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
1235 newpos.Y = enterDistance;
1236 }
1237
1238 /*
1239
1240 if (pos.X < boundaryDistance) //West
1241 {
1242 neighbourx--;
1243 newpos.X = Constants.RegionSize - enterDistance;
1244 }
1245 else if (pos.X > Constants.RegionSize - boundaryDistance) // East
1246 {
1247 neighbourx++;
1248 newpos.X = enterDistance;
1249 }
1250
1251 if (pos.Y < boundaryDistance) // South
1252 {
1253 neighboury--;
1254 newpos.Y = Constants.RegionSize - enterDistance;
1255 }
1256 else if (pos.Y > Constants.RegionSize - boundaryDistance) // North
1257 {
1258 neighboury++;
1259 newpos.Y = enterDistance;
1260 }
1261 */
1262
1263 CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync;
1264 d.BeginInvoke(agent, newpos, neighbourx, neighboury, isFlying, CrossAgentToNewRegionCompleted, d);
1265 }
1266
1267 public delegate void InformClientToInitateTeleportToLocationDelegate(ScenePresence agent, uint regionX, uint regionY,
1268 Vector3 position,
1269 Scene initiatingScene);
1270
1271 public void InformClientToInitateTeleportToLocation(ScenePresence agent, uint regionX, uint regionY, Vector3 position,
1272 Scene initiatingScene)
1273 {
1274
1275 // This assumes that we know what our neighbors are.
1276
1277 InformClientToInitateTeleportToLocationDelegate d = InformClientToInitiateTeleportToLocationAsync;
1278 d.BeginInvoke(agent,regionX,regionY,position,initiatingScene,
1279 InformClientToInitiateTeleportToLocationCompleted,
1280 d);
1281 }
1282
1283 public void InformClientToInitiateTeleportToLocationAsync(ScenePresence agent, uint regionX, uint regionY, Vector3 position,
1284 Scene initiatingScene)
1285 {
1286 Thread.Sleep(10000);
1287 IMessageTransferModule im = initiatingScene.RequestModuleInterface<IMessageTransferModule>();
1288 if (im != null)
1289 {
1290 UUID gotoLocation = Util.BuildFakeParcelID(
1291 Util.UIntsToLong(
1292 (regionX *
1293 (uint)Constants.RegionSize),
1294 (regionY *
1295 (uint)Constants.RegionSize)),
1296 (uint)(int)position.X,
1297 (uint)(int)position.Y,
1298 (uint)(int)position.Z);
1299 GridInstantMessage m = new GridInstantMessage(initiatingScene, UUID.Zero,
1300 "Region", agent.UUID,
1301 (byte)InstantMessageDialog.GodLikeRequestTeleport, false,
1302 "", gotoLocation, false, new Vector3(127, 0, 0),
1303 new Byte[0]);
1304 im.SendInstantMessage(m, delegate(bool success)
1305 {
1306 m_log.DebugFormat("[CLIENT]: Client Initiating Teleport sending IM success = {0}", success);
1307 });
1308
1309 }
1310 }
1311
1312 private void InformClientToInitiateTeleportToLocationCompleted(IAsyncResult iar)
1313 {
1314 InformClientToInitateTeleportToLocationDelegate icon =
1315 (InformClientToInitateTeleportToLocationDelegate) iar.AsyncState;
1316 icon.EndInvoke(iar);
1317 }
1318
1319 public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying);
1320
1321 /// <summary>
1322 /// This Closes child agents on neighboring regions
1323 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
1324 /// </summary>
1325 protected ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying)
1326 {
1327 m_log.DebugFormat("[SCENE COMM]: Crossing agent {0} {1} to {2}-{3}", agent.Firstname, agent.Lastname, neighbourx, neighboury);
1328
1329 ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
1330
1331 int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);
1332 GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
1333
1334 if (neighbourRegion != null && agent.ValidateAttachments())
1335 {
1336 pos = pos + (agent.Velocity);
1337
1338 //CachedUserInfo userInfo = m_commsProvider.UserProfileCacheService.GetUserDetails(agent.UUID);
1339 //if (userInfo != null)
1340 //{
1341 // userInfo.DropInventory();
1342 //}
1343 //else
1344 //{
1345 // m_log.WarnFormat("[SCENE COMM]: No cached user info found for {0} {1} on leaving region {2}",
1346 // agent.Name, agent.UUID, agent.Scene.RegionInfo.RegionName);
1347 //}
1348
1349 //bool crossingSuccessful =
1350 // CrossToNeighbouringRegion(neighbourHandle, agent.ControllingClient.AgentId, pos,
1351 //isFlying);
1352
1353 SetInTransit(agent.UUID);
1354 AgentData cAgent = new AgentData();
1355 agent.CopyTo(cAgent);
1356 cAgent.Position = pos;
1357 if (isFlying)
1358 cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
1359 cAgent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
1360 "/agent/" + agent.UUID.ToString() + "/" + agent.Scene.RegionInfo.RegionHandle.ToString() + "/release/";
1361
1362 m_interregionCommsOut.SendChildAgentUpdate(neighbourHandle, cAgent);
1363
1364 // Next, let's close the child agent connections that are too far away.
1365 agent.CloseChildAgents(neighbourx, neighboury);
1366
1367 //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
1368 agent.ControllingClient.RequestClientInfo();
1369
1370 //m_log.Debug("BEFORE CROSS");
1371 //Scene.DumpChildrenSeeds(UUID);
1372 //DumpKnownRegions();
1373 string agentcaps;
1374 if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps))
1375 {
1376 m_log.ErrorFormat("[SCENE COMM]: No CAPS information for region handle {0}, exiting CrossToNewRegion.",
1377 neighbourRegion.RegionHandle);
1378 return agent;
1379 }
1380 // TODO Should construct this behind a method
1381 string capsPath =
1382 "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort
1383 + "/CAPS/" + agentcaps /*circuitdata.CapsPath*/ + "0000/";
1384
1385 m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, agent.UUID);
1386
1387 IEventQueue eq = agent.Scene.RequestModuleInterface<IEventQueue>();
1388 if (eq != null)
1389 {
1390 eq.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
1391 capsPath, agent.UUID, agent.ControllingClient.SessionId);
1392 }
1393 else
1394 {
1395 agent.ControllingClient.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
1396 capsPath);
1397 }
1398
1399 if (!WaitForCallback(agent.UUID))
1400 {
1401 ResetFromTransit(agent.UUID);
1402
1403 // Yikes! We should just have a ref to scene here.
1404 agent.Scene.InformClientOfNeighbours(agent);
1405
1406 return agent;
1407 }
1408
1409 agent.MakeChildAgent();
1410 // now we have a child agent in this region. Request all interesting data about other (root) agents
1411 agent.SendInitialFullUpdateToAllClients();
1412
1413 agent.CrossAttachmentsIntoNewRegion(neighbourHandle, true);
1414
1415 // m_scene.SendKillObject(m_localId);
1416
1417 agent.Scene.NotifyMyCoarseLocationChange();
1418 // the user may change their profile information in other region,
1419 // so the userinfo in UserProfileCache is not reliable any more, delete it
1420 if (agent.Scene.NeedSceneCacheClear(agent.UUID))
1421 {
1422 agent.Scene.CommsManager.UserProfileCacheService.RemoveUser(agent.UUID);
1423 m_log.DebugFormat(
1424 "[SCENE COMM]: User {0} is going to another region, profile cache removed", agent.UUID);
1425 }
1426 }
1427
1428 //m_log.Debug("AFTER CROSS");
1429 //Scene.DumpChildrenSeeds(UUID);
1430 //DumpKnownRegions();
1431 return agent;
1432 }
1433
1434 private void CrossAgentToNewRegionCompleted(IAsyncResult iar)
1435 {
1436 CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState;
1437 ScenePresence agent = icon.EndInvoke(iar);
1438
1439 // If the cross was successful, this agent is a child agent
1440 if (agent.IsChildAgent)
1441 {
1442 agent.Reset();
1443 }
1444 else // Not successful
1445 {
1446 //CachedUserInfo userInfo = m_commsProvider.UserProfileCacheService.GetUserDetails(agent.UUID);
1447 //if (userInfo != null)
1448 //{
1449 // userInfo.FetchInventory();
1450 //}
1451 agent.RestoreInCurrentScene();
1452 }
1453 // In any case
1454 agent.NotInTransit();
1455
1456 //m_log.DebugFormat("[SCENE COMM]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname);
1457 }
1458
1459
1460 public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
1461 {
1462 m_commsProvider.LogOffUser(userid, regionid, regionhandle, position, lookat);
1463 }
1464
1465 // deprecated as of 2008-08-27
1466 public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
1467 {
1468 m_commsProvider.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
1469 }
1470
1471 public void ClearUserAgent(UUID avatarID)
1472 {
1473 m_commsProvider.UserService.ClearUserAgent(avatarID);
1474 }
1475
1476 public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
1477 {
1478 m_commsProvider.AddNewUserFriend(friendlistowner, friend, perms);
1479 }
1480
1481 public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
1482 {
1483 m_commsProvider.UpdateUserFriendPerms(friendlistowner, friend, perms);
1484 }
1485
1486 public void RemoveUserFriend(UUID friendlistowner, UUID friend)
1487 {
1488 m_commsProvider.RemoveUserFriend(friendlistowner, friend);
1489 }
1490
1491 public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
1492 {
1493 return m_commsProvider.GetUserFriendList(friendlistowner);
1494 }
1495
1496 public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
1497 {
1498 return m_commsProvider.GenerateAgentPickerRequestResponse(queryID, query);
1499 }
1500
1501 public List<GridRegion> RequestNamedRegions(string name, int maxNumber) 304 public List<GridRegion> RequestNamedRegions(string name, int maxNumber)
1502 { 305 {
1503 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); 306 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber);
1504 } 307 }
1505 308
1506 //private void Dump(string msg, List<ulong> handles)
1507 //{
1508 // m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg);
1509 // foreach (ulong handle in handles)
1510 // {
1511 // uint x, y;
1512 // Utils.LongToUInts(handle, out x, out y);
1513 // x = x / Constants.RegionSize;
1514 // y = y / Constants.RegionSize;
1515 // m_log.InfoFormat("({0}, {1})", x, y);
1516 // }
1517 //}
1518 } 309 }
1519} 310}
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 090f379..f43de20 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -35,6 +35,7 @@ using log4net;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.Framework.Scenes.Types; 36using OpenSim.Region.Framework.Scenes.Types;
37using OpenSim.Region.Physics.Manager; 37using OpenSim.Region.Physics.Manager;
38using OpenSim.Region.Framework.Interfaces;
38 39
39namespace OpenSim.Region.Framework.Scenes 40namespace OpenSim.Region.Framework.Scenes
40{ 41{
@@ -164,9 +165,10 @@ namespace OpenSim.Region.Framework.Scenes
164 165
165 protected internal void UpdatePresences() 166 protected internal void UpdatePresences()
166 { 167 {
167 ScenePresence[] updateScenePresences = GetScenePresences(); 168 ForEachScenePresence(delegate(ScenePresence presence)
168 for (int i = 0; i < updateScenePresences.Length; i++) 169 {
169 updateScenePresences[i].Update(); 170 presence.Update();
171 });
170 } 172 }
171 173
172 protected internal float UpdatePhysics(double elapsed) 174 protected internal float UpdatePhysics(double elapsed)
@@ -195,9 +197,10 @@ namespace OpenSim.Region.Framework.Scenes
195 197
196 protected internal void UpdateScenePresenceMovement() 198 protected internal void UpdateScenePresenceMovement()
197 { 199 {
198 ScenePresence[] moveEntities = GetScenePresences(); 200 ForEachScenePresence(delegate(ScenePresence presence)
199 for (int i = 0; i < moveEntities.Length; i++) 201 {
200 moveEntities[i].UpdateMovement(); 202 presence.UpdateMovement();
203 });
201 } 204 }
202 205
203 #endregion 206 #endregion
@@ -464,9 +467,7 @@ namespace OpenSim.Region.Framework.Scenes
464 { 467 {
465 SceneObjectGroup group = GetGroupByPrim(objectLocalID); 468 SceneObjectGroup group = GetGroupByPrim(objectLocalID);
466 if (group != null) 469 if (group != null)
467 { 470 m_parentScene.AttachmentsModule.DetachSingleAttachmentToGround(group.UUID, remoteClient);
468 m_parentScene.DetachSingleAttachmentToGround(group.UUID, remoteClient);
469 }
470 } 471 }
471 472
472 protected internal void DetachObject(uint objectLocalID, IClientAPI remoteClient) 473 protected internal void DetachObject(uint objectLocalID, IClientAPI remoteClient)
@@ -475,7 +476,7 @@ namespace OpenSim.Region.Framework.Scenes
475 if (group != null) 476 if (group != null)
476 { 477 {
477 //group.DetachToGround(); 478 //group.DetachToGround();
478 m_parentScene.DetachSingleAttachmentToInv(group.GetFromItemID(), remoteClient); 479 m_parentScene.AttachmentsModule.ShowDetachInUserInventory(group.GetFromItemID(), remoteClient);
479 } 480 }
480 } 481 }
481 482
@@ -509,212 +510,6 @@ namespace OpenSim.Region.Framework.Scenes
509 } 510 }
510 } 511 }
511 512
512 /// <summary>
513 /// Event Handling routine for Attach Object
514 /// </summary>
515 /// <param name="remoteClient"></param>
516 /// <param name="objectLocalID"></param>
517 /// <param name="AttachmentPt"></param>
518 /// <param name="rot"></param>
519 protected internal void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, bool silent)
520 {
521 // If we can't take it, we can't attach it!
522 SceneObjectPart part = m_parentScene.GetSceneObjectPart(objectLocalID);
523 if (part == null)
524 return;
525
526 if (!m_parentScene.Permissions.CanTakeObject(part.UUID, remoteClient.AgentId))
527 return;
528
529 // Calls attach with a Zero position
530 if (AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, Vector3.Zero, false))
531 {
532 m_parentScene.SendAttachEvent(objectLocalID, part.ParentGroup.GetFromItemID(), remoteClient.AgentId);
533
534 // Save avatar attachment information
535 ScenePresence presence;
536 if (m_parentScene.AvatarFactory != null && m_parentScene.TryGetAvatar(remoteClient.AgentId, out presence))
537 {
538 m_log.Info(
539 "[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
540 + ", AttachmentPoint: " + AttachmentPt);
541
542 m_parentScene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
543 }
544 }
545 }
546
547 /// <summary>
548 /// Rez an attachment
549 /// </summary>
550 /// <param name="remoteClient"></param>
551 /// <param name="itemID"></param>
552 /// <param name="AttachmentPt"></param>
553 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
554 public SceneObjectGroup RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
555 {
556 SceneObjectGroup objatt = m_parentScene.RezObject(remoteClient,
557 itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
558 false, false, remoteClient.AgentId, true);
559
560// m_log.DebugFormat(
561// "[SCENE GRAPH]: Retrieved single object {0} for attachment to {1} on point {2}",
562// objatt.Name, remoteClient.Name, AttachmentPt);
563
564 if (objatt != null)
565 {
566 bool tainted = false;
567 if (AttachmentPt != 0 && AttachmentPt != objatt.GetAttachmentPoint())
568 tainted = true;
569
570 AttachObject(remoteClient, objatt.LocalId, AttachmentPt, Quaternion.Identity, objatt.AbsolutePosition, false);
571 //objatt.ScheduleGroupForFullUpdate();
572
573 if (tainted)
574 objatt.HasGroupChanged = true;
575
576 // Fire after attach, so we don't get messy perms dialogs
577 // 3 == AttachedRez
578 objatt.CreateScriptInstances(0, true, m_parentScene.DefaultScriptEngine, 3);
579
580 // Do this last so that event listeners have access to all the effects of the attachment
581 m_parentScene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, remoteClient.AgentId);
582 }
583 else
584 {
585 m_log.WarnFormat(
586 "[SCENE GRAPH]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
587 itemID, remoteClient.Name, AttachmentPt);
588 }
589
590 return objatt;
591 }
592
593 // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards.
594 // To LocalId or UUID, *THAT* is the question. How now Brown UUID??
595 public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
596 {
597 if (itemID == UUID.Zero) // If this happened, someone made a mistake....
598 return;
599
600 // We can NOT use the dictionries here, as we are looking
601 // for an entity by the fromAssetID, which is NOT the prim UUID
602 //
603 List<EntityBase> detachEntities = GetEntities();
604 SceneObjectGroup group;
605
606 foreach (EntityBase entity in detachEntities)
607 {
608 if (entity is SceneObjectGroup)
609 {
610 group = (SceneObjectGroup)entity;
611 if (group.GetFromItemID() == itemID)
612 {
613 m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero);
614 bool hasScripts = false;
615 foreach (SceneObjectPart part in group.Children.Values)
616 {
617 if (part.Inventory.ContainsScripts())
618 {
619 hasScripts = true;
620 break;
621 }
622 }
623
624 if (hasScripts) // Allow the object to execute the attach(NULL_KEY) event
625 System.Threading.Thread.Sleep(100);
626 group.DetachToInventoryPrep();
627 m_log.Debug("[DETACH]: Saving attachpoint: " +
628 ((uint)group.GetAttachmentPoint()).ToString());
629 m_parentScene.UpdateKnownItem(remoteClient, group,
630 group.GetFromItemID(), group.OwnerID);
631 m_parentScene.DeleteSceneObject(group, false);
632 return;
633 }
634 }
635 }
636 }
637
638 /// <summary>
639 /// Attach a scene object to an avatar.
640 /// </summary>
641 /// <param name="remoteClient"></param>
642 /// <param name="objectLocalID"></param>
643 /// <param name="AttachmentPt"></param>
644 /// <param name="rot"></param>
645 /// <param name="attachPos"></param>
646 /// <param name="silent"></param>
647 /// <returns>true if the attachment was successful, false otherwise</returns>
648 protected internal bool AttachObject(
649 IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, Vector3 attachPos, bool silent)
650 {
651 SceneObjectGroup group = GetGroupByPrim(objectLocalID);
652 if (group != null)
653 {
654 if (m_parentScene.Permissions.CanTakeObject(group.UUID, remoteClient.AgentId))
655 {
656 // If the attachment point isn't the same as the one previously used
657 // set it's offset position = 0 so that it appears on the attachment point
658 // and not in a weird location somewhere unknown.
659 if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint())
660 {
661 attachPos = Vector3.Zero;
662 }
663
664 // AttachmentPt 0 means the client chose to 'wear' the attachment.
665 if (AttachmentPt == 0)
666 {
667 // Check object for stored attachment point
668 AttachmentPt = (uint)group.GetAttachmentPoint();
669 }
670
671 // if we still didn't find a suitable attachment point.......
672 if (AttachmentPt == 0)
673 {
674 // Stick it on left hand with Zero Offset from the attachment point.
675 AttachmentPt = (uint)AttachmentPoint.LeftHand;
676 attachPos = Vector3.Zero;
677 }
678
679 group.SetAttachmentPoint((byte)AttachmentPt);
680 group.AbsolutePosition = attachPos;
681
682 // Saves and gets itemID
683 UUID itemId;
684
685 if (group.GetFromItemID() == UUID.Zero)
686 {
687 m_parentScene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId, out itemId);
688 }
689 else
690 {
691 itemId = group.GetFromItemID();
692 }
693
694 m_parentScene.AttachObject(remoteClient, AttachmentPt, itemId, group);
695
696 group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos, silent);
697 // In case it is later dropped again, don't let
698 // it get cleaned up
699 //
700 group.RootPart.RemFlag(PrimFlags.TemporaryOnRez);
701 group.HasGroupChanged = false;
702 }
703 else
704 {
705 remoteClient.SendAgentAlertMessage("You don't have sufficient permissions to attach this object", false);
706 return false;
707 }
708 }
709 else
710 {
711 m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID);
712 return false;
713 }
714
715 return true;
716 }
717
718 protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance) 513 protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance)
719 { 514 {
720 ScenePresence newAvatar = null; 515 ScenePresence newAvatar = null;
@@ -845,18 +640,16 @@ namespace OpenSim.Region.Framework.Scenes
845 640
846 public void RecalculateStats() 641 public void RecalculateStats()
847 { 642 {
848 ScenePresence[] presences = GetScenePresences();
849 int rootcount = 0; 643 int rootcount = 0;
850 int childcount = 0; 644 int childcount = 0;
851 645
852 for (int i = 0; i < presences.Length; i++) 646 ForEachScenePresence(delegate(ScenePresence presence)
853 { 647 {
854 ScenePresence user = presences[i]; 648 if (presence.IsChildAgent)
855 if (user.IsChildAgent)
856 ++childcount; 649 ++childcount;
857 else 650 else
858 ++rootcount; 651 ++rootcount;
859 } 652 });
860 653
861 m_numRootAgents = rootcount; 654 m_numRootAgents = rootcount;
862 m_numChildAgents = childcount; 655 m_numChildAgents = childcount;
@@ -903,25 +696,6 @@ namespace OpenSim.Region.Framework.Scenes
903 #endregion 696 #endregion
904 697
905 #region Get Methods 698 #region Get Methods
906
907 /// <summary>
908 /// Request a List of all scene presences in this scene. This is a new list, so no
909 /// locking is required to iterate over it.
910 /// </summary>
911 /// <returns></returns>
912 protected internal ScenePresence[] GetScenePresences()
913 {
914 return m_scenePresenceArray;
915 }
916
917 protected internal List<ScenePresence> GetAvatars()
918 {
919 List<ScenePresence> result =
920 GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
921
922 return result;
923 }
924
925 /// <summary> 699 /// <summary>
926 /// Get the controlling client for the given avatar, if there is one. 700 /// Get the controlling client for the given avatar, if there is one.
927 /// 701 ///
@@ -948,41 +722,83 @@ namespace OpenSim.Region.Framework.Scenes
948 } 722 }
949 723
950 /// <summary> 724 /// <summary>
951 /// Request a filtered list of m_scenePresences in this World 725 /// Request a copy of m_scenePresences in this World
726 /// There is no guarantee that presences will remain in the scene after the list is returned.
727 /// This list should remain private to SceneGraph. Callers wishing to iterate should instead
728 /// pass a delegate to ForEachScenePresence.
952 /// </summary> 729 /// </summary>
953 /// <returns></returns> 730 /// <returns></returns>
954 protected internal List<ScenePresence> GetScenePresences(FilterAvatarList filter) 731 private List<ScenePresence> GetScenePresences()
955 { 732 {
956 // No locking of scene presences here since we're passing back a list... 733 lock (m_scenePresences)
957 734 return new List<ScenePresence>(m_scenePresenceArray);
958 List<ScenePresence> result = new List<ScenePresence>(); 735 }
959 ScenePresence[] scenePresences = GetScenePresences();
960 736
961 for (int i = 0; i < scenePresences.Length; i++) 737 /// <summary>
738 /// Request a scene presence by UUID. Fast, indexed lookup.
739 /// </summary>
740 /// <param name="agentID"></param>
741 /// <returns>null if the presence was not found</returns>
742 protected internal ScenePresence GetScenePresence(UUID agentID)
743 {
744 ScenePresence sp;
745 lock (m_scenePresences)
962 { 746 {
963 ScenePresence avatar = scenePresences[i]; 747 m_scenePresences.TryGetValue(agentID, out sp);
964 if (filter(avatar))
965 result.Add(avatar);
966 } 748 }
749 return sp;
750 }
967 751
968 return result; 752 /// <summary>
753 /// Request the scene presence by name.
754 /// </summary>
755 /// <param name="firstName"></param>
756 /// <param name="lastName"></param>
757 /// <returns>null if the presence was not found</returns>
758 protected internal ScenePresence GetScenePresence(string firstName, string lastName)
759 {
760 foreach (ScenePresence presence in GetScenePresences())
761 {
762 if (presence.Firstname == firstName && presence.Lastname == lastName)
763 return presence;
764 }
765 return null;
969 } 766 }
970 767
971 /// <summary> 768 /// <summary>
972 /// Request a scene presence by UUID 769 /// Request the scene presence by localID.
973 /// </summary> 770 /// </summary>
974 /// <param name="avatarID"></param> 771 /// <param name="localID"></param>
975 /// <returns>null if the agent was not found</returns> 772 /// <returns>null if the presence was not found</returns>
976 protected internal ScenePresence GetScenePresence(UUID agentID) 773 protected internal ScenePresence GetScenePresence(uint localID)
774 {
775 foreach (ScenePresence presence in GetScenePresences())
776 if (presence.LocalId == localID)
777 return presence;
778 return null;
779 }
780
781 protected internal bool TryGetScenePresence(UUID agentID, out ScenePresence avatar)
977 { 782 {
978 ScenePresence sp;
979
980 lock (m_scenePresences) 783 lock (m_scenePresences)
981 { 784 {
982 m_scenePresences.TryGetValue(agentID, out sp); 785 m_scenePresences.TryGetValue(agentID, out avatar);
983 } 786 }
787 return (avatar != null);
788 }
984 789
985 return sp; 790 protected internal bool TryGetAvatarByName(string name, out ScenePresence avatar)
791 {
792 avatar = null;
793 foreach (ScenePresence presence in GetScenePresences())
794 {
795 if (String.Compare(name, presence.ControllingClient.Name, true) == 0)
796 {
797 avatar = presence;
798 break;
799 }
800 }
801 return (avatar != null);
986 } 802 }
987 803
988 /// <summary> 804 /// <summary>
@@ -1136,34 +952,6 @@ namespace OpenSim.Region.Framework.Scenes
1136 return group.GetChildPart(fullID); 952 return group.GetChildPart(fullID);
1137 } 953 }
1138 954
1139 protected internal bool TryGetAvatar(UUID avatarId, out ScenePresence avatar)
1140 {
1141 lock (m_scenePresences)
1142 return m_scenePresences.TryGetValue(avatarId, out avatar);
1143 }
1144
1145 protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
1146 {
1147 ScenePresence[] presences = GetScenePresences();
1148
1149 for (int i = 0; i < presences.Length; i++)
1150 {
1151 ScenePresence presence = presences[i];
1152
1153 if (!presence.IsChildAgent)
1154 {
1155 if (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0)
1156 {
1157 avatar = presence;
1158 return true;
1159 }
1160 }
1161 }
1162
1163 avatar = null;
1164 return false;
1165 }
1166
1167 /// <summary> 955 /// <summary>
1168 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over 956 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over
1169 /// it 957 /// it
@@ -1226,6 +1014,10 @@ namespace OpenSim.Region.Framework.Scenes
1226 return UUID.Zero; 1014 return UUID.Zero;
1227 } 1015 }
1228 1016
1017 /// <summary>
1018 /// Performs action on all scene object groups.
1019 /// </summary>
1020 /// <param name="action"></param>
1229 protected internal void ForEachSOG(Action<SceneObjectGroup> action) 1021 protected internal void ForEachSOG(Action<SceneObjectGroup> action)
1230 { 1022 {
1231 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values); 1023 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values);
@@ -1242,6 +1034,46 @@ namespace OpenSim.Region.Framework.Scenes
1242 } 1034 }
1243 } 1035 }
1244 } 1036 }
1037
1038
1039 /// <summary>
1040 /// Performs action on all scene presences. This can ultimately run the actions in parallel but
1041 /// any delegates passed in will need to implement their own locking on data they reference and
1042 /// modify outside of the scope of the delegate.
1043 /// </summary>
1044 /// <param name="action"></param>
1045 public void ForEachScenePresence(Action<ScenePresence> action)
1046 {
1047 // Once all callers have their delegates configured for parallelism, we can unleash this
1048 /*
1049 Action<ScenePresence> protectedAction = new Action<ScenePresence>(delegate(ScenePresence sp)
1050 {
1051 try
1052 {
1053 action(sp);
1054 }
1055 catch (Exception e)
1056 {
1057 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1058 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1059 }
1060 });
1061 Parallel.ForEach<ScenePresence>(GetScenePresences(), protectedAction);
1062 */
1063 // For now, perform actiona serially
1064 foreach (ScenePresence sp in GetScenePresences())
1065 {
1066 try
1067 {
1068 action(sp);
1069 }
1070 catch (Exception e)
1071 {
1072 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1073 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1074 }
1075 }
1076 }
1245 1077
1246 #endregion 1078 #endregion
1247 1079
@@ -1924,6 +1756,7 @@ namespace OpenSim.Region.Framework.Scenes
1924 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 0); 1756 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 0);
1925 copy.HasGroupChanged = true; 1757 copy.HasGroupChanged = true;
1926 copy.ScheduleGroupForFullUpdate(); 1758 copy.ScheduleGroupForFullUpdate();
1759 copy.ResumeScripts();
1927 1760
1928 // required for physics to update it's position 1761 // required for physics to update it's position
1929 copy.AbsolutePosition = copy.AbsolutePosition; 1762 copy.AbsolutePosition = copy.AbsolutePosition;
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index c2e3370..3b84734 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -414,22 +414,18 @@ namespace OpenSim.Region.Framework.Scenes
414 ForEachCurrentScene( 414 ForEachCurrentScene(
415 delegate(Scene scene) 415 delegate(Scene scene)
416 { 416 {
417 ScenePresence[] scenePresences = scene.GetScenePresences(); 417 scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
418
419 for (int i = 0; i < scenePresences.Length; i++)
420 { 418 {
421 ScenePresence scenePresence = scenePresences[i];
422
423 if (!scenePresence.IsChildAgent) 419 if (!scenePresence.IsChildAgent)
424 { 420 {
425 m_log.ErrorFormat("Packet debug for {0} {1} set to {2}", 421 m_log.DebugFormat("Packet debug for {0} {1} set to {2}",
426 scenePresence.Firstname, 422 scenePresence.Firstname,
427 scenePresence.Lastname, 423 scenePresence.Lastname,
428 newDebug); 424 newDebug);
429 425
430 scenePresence.ControllingClient.SetDebugPacketLevel(newDebug); 426 scenePresence.ControllingClient.SetDebugPacketLevel(newDebug);
431 } 427 }
432 } 428 });
433 } 429 }
434 ); 430 );
435 } 431 }
@@ -441,14 +437,11 @@ namespace OpenSim.Region.Framework.Scenes
441 ForEachCurrentScene( 437 ForEachCurrentScene(
442 delegate(Scene scene) 438 delegate(Scene scene)
443 { 439 {
444 ScenePresence[] scenePresences = scene.GetScenePresences(); 440 scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
445
446 for (int i = 0; i < scenePresences.Length; i++)
447 { 441 {
448 ScenePresence scenePresence = scenePresences[i];
449 if (!scenePresence.IsChildAgent) 442 if (!scenePresence.IsChildAgent)
450 avatars.Add(scenePresence); 443 avatars.Add(scenePresence);
451 } 444 });
452 } 445 }
453 ); 446 );
454 447
@@ -461,18 +454,20 @@ namespace OpenSim.Region.Framework.Scenes
461 454
462 ForEachCurrentScene(delegate(Scene scene) 455 ForEachCurrentScene(delegate(Scene scene)
463 { 456 {
464 ScenePresence[] scenePresences = scene.GetScenePresences(); 457 scene.ForEachScenePresence(delegate(ScenePresence sp)
465 presences.AddRange(scenePresences); 458 {
459 presences.Add(sp);
460 });
466 }); 461 });
467 462
468 return presences; 463 return presences;
469 } 464 }
470 465
471 public RegionInfo GetRegionInfo(ulong regionHandle) 466 public RegionInfo GetRegionInfo(UUID regionID)
472 { 467 {
473 foreach (Scene scene in m_localScenes) 468 foreach (Scene scene in m_localScenes)
474 { 469 {
475 if (scene.RegionInfo.RegionHandle == regionHandle) 470 if (scene.RegionInfo.RegionID == regionID)
476 { 471 {
477 return scene.RegionInfo; 472 return scene.RegionInfo;
478 } 473 }
@@ -491,11 +486,11 @@ namespace OpenSim.Region.Framework.Scenes
491 ForEachCurrentScene(delegate(Scene scene) { scene.HandleEditCommand(cmdparams); }); 486 ForEachCurrentScene(delegate(Scene scene) { scene.HandleEditCommand(cmdparams); });
492 } 487 }
493 488
494 public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 489 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
495 { 490 {
496 foreach (Scene scene in m_localScenes) 491 foreach (Scene scene in m_localScenes)
497 { 492 {
498 if (scene.TryGetAvatar(avatarId, out avatar)) 493 if (scene.TryGetScenePresence(avatarId, out avatar))
499 { 494 {
500 return true; 495 return true;
501 } 496 }
@@ -510,7 +505,7 @@ namespace OpenSim.Region.Framework.Scenes
510 ScenePresence avatar = null; 505 ScenePresence avatar = null;
511 foreach (Scene mScene in m_localScenes) 506 foreach (Scene mScene in m_localScenes)
512 { 507 {
513 if (mScene.TryGetAvatar(avatarId, out avatar)) 508 if (mScene.TryGetScenePresence(avatarId, out avatar))
514 { 509 {
515 scene = mScene; 510 scene = mScene;
516 return true; 511 return true;
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
index 8b58b3e..1149a20 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
@@ -171,7 +171,9 @@ namespace OpenSim.Region.Framework.Scenes
171 item.NextPermissions; 171 item.NextPermissions;
172 taskItem.NextPermissions = item.NextPermissions; 172 taskItem.NextPermissions = item.NextPermissions;
173 taskItem.CurrentPermissions |= 8; 173 taskItem.CurrentPermissions |= 8;
174 } else { 174 }
175 else
176 {
175 taskItem.BasePermissions = item.BasePermissions; 177 taskItem.BasePermissions = item.BasePermissions;
176 taskItem.CurrentPermissions = item.CurrentPermissions; 178 taskItem.CurrentPermissions = item.CurrentPermissions;
177 taskItem.CurrentPermissions |= 8; 179 taskItem.CurrentPermissions |= 8;
@@ -412,5 +414,13 @@ namespace OpenSim.Region.Framework.Scenes
412 scriptModule.SetXMLState(itemID, n.OuterXml); 414 scriptModule.SetXMLState(itemID, n.OuterXml);
413 } 415 }
414 } 416 }
417
418 public void ResumeScripts()
419 {
420 foreach (SceneObjectPart part in m_parts.Values)
421 {
422 part.Inventory.ResumeScripts();
423 }
424 }
415 } 425 }
416} 426}
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 13d1d4e..1c6f2d1 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -418,6 +418,7 @@ namespace OpenSim.Region.Framework.Scenes
418 RootPart.ScriptSetPhysicsStatus(false); 418 RootPart.ScriptSetPhysicsStatus(false);
419 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), 419 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
420 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); 420 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
421 lockPartsForRead(false);
421 return; 422 return;
422 } 423 }
423 } 424 }
@@ -530,8 +531,8 @@ namespace OpenSim.Region.Framework.Scenes
530 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>(); 531 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
531 public List<SceneObjectPart> PlaySoundSlavePrims 532 public List<SceneObjectPart> PlaySoundSlavePrims
532 { 533 {
533 get { return m_LoopSoundSlavePrims; } 534 get { return m_PlaySoundSlavePrims; }
534 set { m_LoopSoundSlavePrims = value; } 535 set { m_PlaySoundSlavePrims = value; }
535 } 536 }
536 537
537 private SceneObjectPart m_LoopSoundMasterPrim = null; 538 private SceneObjectPart m_LoopSoundMasterPrim = null;
@@ -686,7 +687,7 @@ namespace OpenSim.Region.Framework.Scenes
686 ApplyPhysics(m_scene.m_physicalPrim); 687 ApplyPhysics(m_scene.m_physicalPrim);
687 688
688 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 689 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
689 // for the same object with very different properties. The caller must schedule the update. 690 // for the same object with very different properties. The caller must schedule the update.
690 //ScheduleGroupForFullUpdate(); 691 //ScheduleGroupForFullUpdate();
691 } 692 }
692 693
@@ -1040,6 +1041,11 @@ namespace OpenSim.Region.Framework.Scenes
1040 1041
1041 public void SaveScriptedState(XmlTextWriter writer) 1042 public void SaveScriptedState(XmlTextWriter writer)
1042 { 1043 {
1044 SaveScriptedState(writer, false);
1045 }
1046
1047 public void SaveScriptedState(XmlTextWriter writer, bool oldIDs)
1048 {
1043 XmlDocument doc = new XmlDocument(); 1049 XmlDocument doc = new XmlDocument();
1044 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1050 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
1045 1051
@@ -1049,7 +1055,7 @@ namespace OpenSim.Region.Framework.Scenes
1049 foreach (SceneObjectPart part in m_parts.Values) 1055 foreach (SceneObjectPart part in m_parts.Values)
1050 { 1056 {
1051 1057
1052 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); 1058 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(oldIDs);
1053 foreach (UUID itemid in pstates.Keys) 1059 foreach (UUID itemid in pstates.Keys)
1054 { 1060 {
1055 states.Add(itemid, pstates[itemid]); 1061 states.Add(itemid, pstates[itemid]);
@@ -1411,21 +1417,20 @@ namespace OpenSim.Region.Framework.Scenes
1411 { 1417 {
1412// part.Inventory.RemoveScriptInstances(); 1418// part.Inventory.RemoveScriptInstances();
1413 1419
1414 ScenePresence[] avatars = Scene.GetScenePresences(); 1420 Scene.ForEachScenePresence(delegate (ScenePresence sp)
1415 for (int i = 0; i < avatars.Length; i++)
1416 { 1421 {
1417 if (avatars[i].ParentID == LocalId) 1422 if (sp.ParentID == LocalId)
1418 { 1423 {
1419 avatars[i].StandUp(); 1424 sp.StandUp();
1420 } 1425 }
1421 1426
1422 if (!silent) 1427 if (!silent)
1423 { 1428 {
1424 part.UpdateFlag = 0; 1429 part.UpdateFlag = 0;
1425 if (part == m_rootPart) 1430 if (part == m_rootPart)
1426 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1431 sp.ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1427 } 1432 }
1428 } 1433 });
1429 1434
1430 } 1435 }
1431 1436
@@ -1647,11 +1652,10 @@ namespace OpenSim.Region.Framework.Scenes
1647 1652
1648 #endregion 1653 #endregion
1649 1654
1650 #region Client Updating
1651
1652 public void SendFullUpdateToClient(IClientAPI remoteClient) 1655 public void SendFullUpdateToClient(IClientAPI remoteClient)
1653 { 1656 {
1654 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1657 RootPart.SendFullUpdate(
1658 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1655 1659
1656 lockPartsForRead(true); 1660 lockPartsForRead(true);
1657 { 1661 {
@@ -1659,42 +1663,12 @@ namespace OpenSim.Region.Framework.Scenes
1659 { 1663 {
1660 1664
1661 if (part != RootPart) 1665 if (part != RootPart)
1662 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1666 part.SendFullUpdate(
1663 1667 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
1664 } 1668 }
1665 } 1669 }
1666 lockPartsForRead(false);
1667 } 1670 }
1668 1671
1669 /// <summary>
1670 /// Send a full update to the client for the given part
1671 /// </summary>
1672 /// <param name="remoteClient"></param>
1673 /// <param name="part"></param>
1674 internal void SendPartFullUpdate(IClientAPI remoteClient, SceneObjectPart part, uint clientFlags)
1675 {
1676// m_log.DebugFormat(
1677// "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
1678
1679 if (m_rootPart.UUID == part.UUID)
1680 {
1681 if (IsAttachment)
1682 {
1683 part.SendFullUpdateToClient(remoteClient, m_rootPart.AttachedPos, clientFlags);
1684 }
1685 else
1686 {
1687 part.SendFullUpdateToClient(remoteClient, AbsolutePosition, clientFlags);
1688 }
1689 }
1690 else
1691 {
1692 part.SendFullUpdateToClient(remoteClient, clientFlags);
1693 }
1694 }
1695
1696 #endregion
1697
1698 #region Copying 1672 #region Copying
1699 1673
1700 /// <summary> 1674 /// <summary>
@@ -2206,14 +2180,12 @@ namespace OpenSim.Region.Framework.Scenes
2206 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2180 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
2207 { 2181 {
2208 lockPartsForRead(true); 2182 lockPartsForRead(true);
2183
2184 foreach (SceneObjectPart part in m_parts.Values)
2209 { 2185 {
2210 foreach (SceneObjectPart part in m_parts.Values) 2186 part.AddTerseUpdateToAvatar(presence);
2211 {
2212
2213 part.AddTerseUpdateToAvatar(presence);
2214
2215 }
2216 } 2187 }
2188
2217 lockPartsForRead(false); 2189 lockPartsForRead(false);
2218 } 2190 }
2219 2191
@@ -2246,14 +2218,11 @@ namespace OpenSim.Region.Framework.Scenes
2246 public void ScheduleGroupForTerseUpdate() 2218 public void ScheduleGroupForTerseUpdate()
2247 { 2219 {
2248 lockPartsForRead(true); 2220 lockPartsForRead(true);
2221 foreach (SceneObjectPart part in m_parts.Values)
2249 { 2222 {
2250 foreach (SceneObjectPart part in m_parts.Values) 2223 part.ScheduleTerseUpdate();
2251 {
2252
2253 part.ScheduleTerseUpdate();
2254
2255 }
2256 } 2224 }
2225
2257 lockPartsForRead(false); 2226 lockPartsForRead(false);
2258 } 2227 }
2259 2228
@@ -3107,8 +3076,8 @@ namespace OpenSim.Region.Framework.Scenes
3107 { 3076 {
3108 if (obPart.UUID != m_rootPart.UUID) 3077 if (obPart.UUID != m_rootPart.UUID)
3109 { 3078 {
3110 obPart.IgnoreUndoUpdate = true;
3111 Vector3 oldSize = new Vector3(obPart.Scale); 3079 Vector3 oldSize = new Vector3(obPart.Scale);
3080 obPart.IgnoreUndoUpdate = true;
3112 3081
3113 float f = 1.0f; 3082 float f = 1.0f;
3114 float a = 1.0f; 3083 float a = 1.0f;
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 548a64f..4b2641c 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -573,8 +573,8 @@ namespace OpenSim.Region.Framework.Scenes
573 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>(); 573 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
574 public List<SceneObjectPart> PlaySoundSlavePrims 574 public List<SceneObjectPart> PlaySoundSlavePrims
575 { 575 {
576 get { return m_LoopSoundSlavePrims; } 576 get { return m_PlaySoundSlavePrims; }
577 set { m_LoopSoundSlavePrims = value; } 577 set { m_PlaySoundSlavePrims = value; }
578 } 578 }
579 579
580 private SceneObjectPart m_LoopSoundMasterPrim = null; 580 private SceneObjectPart m_LoopSoundMasterPrim = null;
@@ -682,7 +682,7 @@ namespace OpenSim.Region.Framework.Scenes
682 if (m_parentGroup != null) // TODO can there be a SOP without a SOG? 682 if (m_parentGroup != null) // TODO can there be a SOP without a SOG?
683 { 683 {
684 ScenePresence avatar; 684 ScenePresence avatar;
685 if (m_parentGroup.Scene.TryGetAvatar(m_sitTargetAvatar, out avatar)) 685 if (m_parentGroup.Scene.TryGetScenePresence(m_sitTargetAvatar, out avatar))
686 { 686 {
687 avatar.ParentPosition = GetWorldPosition(); 687 avatar.ParentPosition = GetWorldPosition();
688 } 688 }
@@ -1208,15 +1208,14 @@ namespace OpenSim.Region.Framework.Scenes
1208 1208
1209 private void SendObjectPropertiesToClient(UUID AgentID) 1209 private void SendObjectPropertiesToClient(UUID AgentID)
1210 { 1210 {
1211 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 1211 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
1212 for (int i = 0; i < avatars.Length; i++)
1213 { 1212 {
1214 // Ugly reference :( 1213 // Ugly reference :(
1215 if (avatars[i].UUID == AgentID) 1214 if (avatar.UUID == AgentID)
1216 { 1215 {
1217 m_parentGroup.GetProperties(avatars[i].ControllingClient); 1216 m_parentGroup.GetProperties(avatar.ControllingClient);
1218 } 1217 }
1219 } 1218 });
1220 } 1219 }
1221 1220
1222 // TODO: unused: 1221 // TODO: unused:
@@ -1271,11 +1270,10 @@ namespace OpenSim.Region.Framework.Scenes
1271 /// </summary> 1270 /// </summary>
1272 public void AddFullUpdateToAllAvatars() 1271 public void AddFullUpdateToAllAvatars()
1273 { 1272 {
1274 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 1273 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
1275 for (int i = 0; i < avatars.Length; i++)
1276 { 1274 {
1277 avatars[i].SceneViewer.QueuePartForUpdate(this); 1275 avatar.SceneViewer.QueuePartForUpdate(this);
1278 } 1276 });
1279 } 1277 }
1280 1278
1281 public void AddFullUpdateToAvatar(ScenePresence presence) 1279 public void AddFullUpdateToAvatar(ScenePresence presence)
@@ -1296,11 +1294,10 @@ namespace OpenSim.Region.Framework.Scenes
1296 /// Terse updates 1294 /// Terse updates
1297 public void AddTerseUpdateToAllAvatars() 1295 public void AddTerseUpdateToAllAvatars()
1298 { 1296 {
1299 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 1297 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
1300 for (int i = 0; i < avatars.Length; i++)
1301 { 1298 {
1302 avatars[i].SceneViewer.QueuePartForUpdate(this); 1299 avatar.SceneViewer.QueuePartForUpdate(this);
1303 } 1300 });
1304 } 1301 }
1305 1302
1306 public void AddTerseUpdateToAvatar(ScenePresence presence) 1303 public void AddTerseUpdateToAvatar(ScenePresence presence)
@@ -1335,11 +1332,11 @@ namespace OpenSim.Region.Framework.Scenes
1335 if (volume < 0) 1332 if (volume < 0)
1336 volume = 0; 1333 volume = 0;
1337 1334
1338 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 1335 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
1339 foreach (ScenePresence p in avatarts)
1340 { 1336 {
1341 p.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume); 1337 if(!sp.IsChildAgent)
1342 } 1338 sp.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
1339 });
1343 } 1340 }
1344 1341
1345 /// <summary> 1342 /// <summary>
@@ -2060,6 +2057,7 @@ namespace OpenSim.Region.Framework.Scenes
2060 { 2057 {
2061 m_lastColliders.Remove(localID); 2058 m_lastColliders.Remove(localID);
2062 } 2059 }
2060
2063 if (m_parentGroup == null) 2061 if (m_parentGroup == null)
2064 return; 2062 return;
2065 if (m_parentGroup.IsDeleted) 2063 if (m_parentGroup.IsDeleted)
@@ -2136,17 +2134,13 @@ namespace OpenSim.Region.Framework.Scenes
2136 } 2134 }
2137 else 2135 else
2138 { 2136 {
2139 ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); 2137 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
2140
2141 for (int i = 0; i < avlist.Length; i++)
2142 { 2138 {
2143 ScenePresence av = avlist[i];
2144
2145 if (av.LocalId == localId) 2139 if (av.LocalId == localId)
2146 { 2140 {
2147 if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) 2141 if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
2148 { 2142 {
2149 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); 2143 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
2150 //If it is 1, it is to accept ONLY collisions from this avatar 2144 //If it is 1, it is to accept ONLY collisions from this avatar
2151 if (found) 2145 if (found)
2152 { 2146 {
@@ -2168,7 +2162,7 @@ namespace OpenSim.Region.Framework.Scenes
2168 } 2162 }
2169 else 2163 else
2170 { 2164 {
2171 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); 2165 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
2172 //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work 2166 //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
2173 if (!found) 2167 if (!found)
2174 { 2168 {
@@ -2186,7 +2180,7 @@ namespace OpenSim.Region.Framework.Scenes
2186 } 2180 }
2187 2181
2188 } 2182 }
2189 } 2183 });
2190 } 2184 }
2191 } 2185 }
2192 if (colliding.Count > 0) 2186 if (colliding.Count > 0)
@@ -2272,17 +2266,13 @@ namespace OpenSim.Region.Framework.Scenes
2272 } 2266 }
2273 else 2267 else
2274 { 2268 {
2275 ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); 2269 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
2276
2277 for (int i = 0; i < avlist.Length; i++)
2278 { 2270 {
2279 ScenePresence av = avlist[i];
2280
2281 if (av.LocalId == localId) 2271 if (av.LocalId == localId)
2282 { 2272 {
2283 if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) 2273 if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
2284 { 2274 {
2285 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); 2275 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
2286 //If it is 1, it is to accept ONLY collisions from this avatar 2276 //If it is 1, it is to accept ONLY collisions from this avatar
2287 if (found) 2277 if (found)
2288 { 2278 {
@@ -2304,7 +2294,7 @@ namespace OpenSim.Region.Framework.Scenes
2304 } 2294 }
2305 else 2295 else
2306 { 2296 {
2307 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); 2297 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
2308 //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work 2298 //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
2309 if (!found) 2299 if (!found)
2310 { 2300 {
@@ -2322,7 +2312,7 @@ namespace OpenSim.Region.Framework.Scenes
2322 } 2312 }
2323 2313
2324 } 2314 }
2325 } 2315 });
2326 } 2316 }
2327 } 2317 }
2328 if (colliding.Count > 0) 2318 if (colliding.Count > 0)
@@ -2403,17 +2393,13 @@ namespace OpenSim.Region.Framework.Scenes
2403 } 2393 }
2404 else 2394 else
2405 { 2395 {
2406 ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); 2396 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
2407
2408 for (int i = 0; i < avlist.Length; i++)
2409 { 2397 {
2410 ScenePresence av = avlist[i];
2411
2412 if (av.LocalId == localId) 2398 if (av.LocalId == localId)
2413 { 2399 {
2414 if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) 2400 if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
2415 { 2401 {
2416 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); 2402 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
2417 //If it is 1, it is to accept ONLY collisions from this avatar 2403 //If it is 1, it is to accept ONLY collisions from this avatar
2418 if (found) 2404 if (found)
2419 { 2405 {
@@ -2435,7 +2421,7 @@ namespace OpenSim.Region.Framework.Scenes
2435 } 2421 }
2436 else 2422 else
2437 { 2423 {
2438 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); 2424 bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
2439 //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work 2425 //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
2440 if (!found) 2426 if (!found)
2441 { 2427 {
@@ -2453,7 +2439,7 @@ namespace OpenSim.Region.Framework.Scenes
2453 } 2439 }
2454 2440
2455 } 2441 }
2456 } 2442 });
2457 } 2443 }
2458 } 2444 }
2459 2445
@@ -2640,12 +2626,13 @@ namespace OpenSim.Region.Framework.Scenes
2640 TaskInventory.LockItemsForRead(false); 2626 TaskInventory.LockItemsForRead(false);
2641 } 2627 }
2642 2628
2643 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 2629 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
2644 foreach (ScenePresence p in avatarts)
2645 { 2630 {
2646 if (!(Util.GetDistanceTo(p.AbsolutePosition, AbsolutePosition) >= 100)) 2631 if (sp.IsChildAgent)
2647 p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID); 2632 return;
2648 } 2633 if (!(Util.GetDistanceTo(sp.AbsolutePosition, AbsolutePosition) >= 100))
2634 sp.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
2635 });
2649 } 2636 }
2650 2637
2651 public void RemFlag(PrimFlags flag) 2638 public void RemFlag(PrimFlags flag)
@@ -2820,41 +2807,66 @@ namespace OpenSim.Region.Framework.Scenes
2820 } 2807 }
2821 } 2808 }
2822 2809
2810// /// <summary>
2811// ///
2812// /// </summary>
2813// /// <param name="remoteClient"></param>
2814// public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
2815// {
2816// m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags);
2817// }
2818
2819
2823 /// <summary> 2820 /// <summary>
2824 /// 2821 /// Send a full update to the client for the given part
2825 /// </summary> 2822 /// </summary>
2826 /// <param name="remoteClient"></param> 2823 /// <param name="remoteClient"></param>
2827 public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags) 2824 /// <param name="clientFlags"></param>
2825 protected internal void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
2828 { 2826 {
2829 m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags); 2827// m_log.DebugFormat(
2828// "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
2829
2830 if (IsRoot)
2831 {
2832 if (IsAttachment)
2833 {
2834 SendFullUpdateToClient(remoteClient, AttachedPos, clientFlags);
2835 }
2836 else
2837 {
2838 SendFullUpdateToClient(remoteClient, AbsolutePosition, clientFlags);
2839 }
2840 }
2841 else
2842 {
2843 SendFullUpdateToClient(remoteClient, clientFlags);
2844 }
2830 } 2845 }
2831 2846
2832 /// <summary> 2847 /// <summary>
2833 /// 2848 /// Send a full update for this part to all clients.
2834 /// </summary> 2849 /// </summary>
2835 public void SendFullUpdateToAllClients() 2850 public void SendFullUpdateToAllClients()
2836 { 2851 {
2837 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 2852 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
2838 for (int i = 0; i < avatars.Length; i++)
2839 { 2853 {
2840 // Ugly reference :( 2854 SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID));
2841 m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this, 2855 });
2842 avatars[i].GenerateClientFlags(UUID));
2843 }
2844 } 2856 }
2845 2857
2858 /// <summary>
2859 /// Send a full update to all clients except the one nominated.
2860 /// </summary>
2861 /// <param name="agentID"></param>
2846 public void SendFullUpdateToAllClientsExcept(UUID agentID) 2862 public void SendFullUpdateToAllClientsExcept(UUID agentID)
2847 { 2863 {
2848 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 2864 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
2849 for (int i = 0; i < avatars.Length; i++)
2850 { 2865 {
2851 // Ugly reference :( 2866 // Ugly reference :(
2852 if (avatars[i].UUID != agentID) 2867 if (avatar.UUID != agentID)
2853 { 2868 SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID));
2854 m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this, 2869 });
2855 avatars[i].GenerateClientFlags(UUID));
2856 }
2857 }
2858 } 2870 }
2859 2871
2860 /// <summary> 2872 /// <summary>
@@ -3055,11 +3067,10 @@ namespace OpenSim.Region.Framework.Scenes
3055 /// </summary> 3067 /// </summary>
3056 public void SendTerseUpdateToAllClients() 3068 public void SendTerseUpdateToAllClients()
3057 { 3069 {
3058 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 3070 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
3059 for (int i = 0; i < avatars.Length; i++)
3060 { 3071 {
3061 SendTerseUpdateToClient(avatars[i].ControllingClient); 3072 SendTerseUpdateToClient(avatar.ControllingClient);
3062 } 3073 });
3063 } 3074 }
3064 3075
3065 public void SetAttachmentPoint(uint AttachmentPoint) 3076 public void SetAttachmentPoint(uint AttachmentPoint)
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index a2fceb7..bc3225a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -34,7 +34,6 @@ using System.Reflection;
34using OpenMetaverse; 34using OpenMetaverse;
35using log4net; 35using log4net;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Framework.Communications.Cache;
38using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes.Scripting; 38using OpenSim.Region.Framework.Scenes.Scripting;
40 39
@@ -213,7 +212,7 @@ namespace OpenSim.Region.Framework.Scenes
213 } 212 }
214 } 213 }
215 214
216 private ArrayList GetScriptErrors(UUID itemID) 215 public ArrayList GetScriptErrors(UUID itemID)
217 { 216 {
218 ArrayList ret = new ArrayList(); 217 ArrayList ret = new ArrayList();
219 218
@@ -296,38 +295,36 @@ namespace OpenSim.Region.Framework.Scenes
296 return; 295 return;
297 } 296 }
298 297
299 m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset) 298 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
300 { 299 if (null == asset)
301 if (null == asset) 300 {
302 { 301 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
303 string msg = String.Format("asset ID {0} could not be found", item.AssetID); 302 StoreScriptError(item.ItemID, msg);
304 StoreScriptError(item.ItemID, msg); 303 m_log.ErrorFormat(
305 m_log.ErrorFormat( 304 "[PRIM INVENTORY]: " +
306 "[PRIM INVENTORY]: " + 305 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
307 "Couldn't start script {0}, {1} at {2} in {3} since {4}", 306 item.Name, item.ItemID, m_part.AbsolutePosition,
308 item.Name, item.ItemID, m_part.AbsolutePosition, 307 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
309 m_part.ParentGroup.Scene.RegionInfo.RegionName, msg); 308 }
310 } 309 else
311 else 310 {
312 { 311 if (m_part.ParentGroup.m_savedScriptState != null)
313 if (m_part.ParentGroup.m_savedScriptState != null) 312 RestoreSavedScriptState(item.OldItemID, item.ItemID);
314 RestoreSavedScriptState(item.OldItemID, item.ItemID); 313
315 m_items.LockItemsForWrite(true); 314 m_items.LockItemsForWrite(true);
316 m_items[item.ItemID].PermsMask = 0; 315
317 m_items[item.ItemID].PermsGranter = UUID.Zero; 316 m_items[item.ItemID].PermsMask = 0;
318 m_items.LockItemsForWrite(false); 317 m_items[item.ItemID].PermsGranter = UUID.Zero;
319 string script = Utils.BytesToString(asset.Data); 318
320 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 319 m_items.LockItemsForWrite(false);
321 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 320
322 StoreScriptErrors(item.ItemID, null); 321 string script = Utils.BytesToString(asset.Data);
323 m_part.ParentGroup.AddActiveScriptCount(1); 322 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
324 m_part.ScheduleFullUpdate(); 323 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
325 } 324 StoreScriptErrors(item.ItemID, null);
326 }); 325 m_part.ParentGroup.AddActiveScriptCount(1);
327 } 326 m_part.ScheduleFullUpdate();
328 else 327 }
329 {
330 StoreScriptError(item.ItemID, "scripts disabled");
331 } 328 }
332 } 329 }
333 330
@@ -654,6 +651,7 @@ namespace OpenSim.Region.Framework.Scenes
654 item.ParentID = m_part.UUID; 651 item.ParentID = m_part.UUID;
655 item.ParentPartID = m_part.UUID; 652 item.ParentPartID = m_part.UUID;
656 item.Name = name; 653 item.Name = name;
654 item.GroupID = m_part.GroupID;
657 655
658 m_items.LockItemsForWrite(true); 656 m_items.LockItemsForWrite(true);
659 m_items.Add(item.ItemID, item); 657 m_items.Add(item.ItemID, item);
@@ -716,15 +714,16 @@ namespace OpenSim.Region.Framework.Scenes
716 { 714 {
717 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(); 715 IList<TaskInventoryItem> items = new List<TaskInventoryItem>();
718 716
719 lock (m_items) 717 m_items.LockItemsForRead(true);
718
719 foreach (TaskInventoryItem item in m_items.Values)
720 { 720 {
721 foreach (TaskInventoryItem item in m_items.Values) 721 if (item.Name == name)
722 { 722 items.Add(item);
723 if (item.Name == name)
724 items.Add(item);
725 }
726 } 723 }
727 724
725 m_items.LockItemsForRead(false);
726
728 return items; 727 return items;
729 } 728 }
730 729
@@ -736,6 +735,11 @@ namespace OpenSim.Region.Framework.Scenes
736 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 735 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
737 public bool UpdateInventoryItem(TaskInventoryItem item) 736 public bool UpdateInventoryItem(TaskInventoryItem item)
738 { 737 {
738 return UpdateInventoryItem(item, true);
739 }
740
741 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents)
742 {
739 m_items.LockItemsForWrite(true); 743 m_items.LockItemsForWrite(true);
740 744
741 if (m_items.ContainsKey(item.ItemID)) 745 if (m_items.ContainsKey(item.ItemID))
@@ -743,6 +747,12 @@ namespace OpenSim.Region.Framework.Scenes
743 item.ParentID = m_part.UUID; 747 item.ParentID = m_part.UUID;
744 item.ParentPartID = m_part.UUID; 748 item.ParentPartID = m_part.UUID;
745 item.Flags = m_items[item.ItemID].Flags; 749 item.Flags = m_items[item.ItemID].Flags;
750
751 // If group permissions have been set on, check that the groupID is up to date in case it has
752 // changed since permissions were last set.
753 if (item.GroupPermissions != (uint)PermissionMask.None)
754 item.GroupID = m_part.GroupID;
755
746 if (item.AssetID == UUID.Zero) 756 if (item.AssetID == UUID.Zero)
747 { 757 {
748 item.AssetID = m_items[item.ItemID].AssetID; 758 item.AssetID = m_items[item.ItemID].AssetID;
@@ -760,8 +770,8 @@ namespace OpenSim.Region.Framework.Scenes
760 770
761 m_items[item.ItemID] = item; 771 m_items[item.ItemID] = item;
762 m_inventorySerial++; 772 m_inventorySerial++;
763 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 773 if (fireScriptEvents)
764 774 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
765 HasInventoryChanged = true; 775 HasInventoryChanged = true;
766 m_part.ParentGroup.HasGroupChanged = true; 776 m_part.ParentGroup.HasGroupChanged = true;
767 m_items.LockItemsForWrite(false); 777 m_items.LockItemsForWrite(false);
@@ -896,6 +906,7 @@ namespace OpenSim.Region.Framework.Scenes
896 uint everyoneMask = 0; 906 uint everyoneMask = 0;
897 uint baseMask = item.BasePermissions; 907 uint baseMask = item.BasePermissions;
898 uint ownerMask = item.CurrentPermissions; 908 uint ownerMask = item.CurrentPermissions;
909 uint groupMask = item.GroupPermissions;
899 910
900 invString.AddItemStart(); 911 invString.AddItemStart();
901 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 912 invString.AddNameValueLine("item_id", item.ItemID.ToString());
@@ -905,7 +916,7 @@ namespace OpenSim.Region.Framework.Scenes
905 916
906 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 917 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
907 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 918 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
908 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0)); 919 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
909 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 920 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
910 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 921 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
911 922
@@ -1112,6 +1123,11 @@ namespace OpenSim.Region.Framework.Scenes
1112 1123
1113 public Dictionary<UUID, string> GetScriptStates() 1124 public Dictionary<UUID, string> GetScriptStates()
1114 { 1125 {
1126 return GetScriptStates(false);
1127 }
1128
1129 public Dictionary<UUID, string> GetScriptStates(bool oldIDs)
1130 {
1115 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>(); 1131 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
1116 1132
1117 Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); 1133 Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
@@ -1129,8 +1145,16 @@ namespace OpenSim.Region.Framework.Scenes
1129 string n = e.GetXMLState(item.ItemID); 1145 string n = e.GetXMLState(item.ItemID);
1130 if (n != String.Empty) 1146 if (n != String.Empty)
1131 { 1147 {
1132 if (!ret.ContainsKey(item.ItemID)) 1148 if (oldIDs)
1133 ret[item.ItemID] = n; 1149 {
1150 if (!ret.ContainsKey(item.OldItemID))
1151 ret[item.OldItemID] = n;
1152 }
1153 else
1154 {
1155 if (!ret.ContainsKey(item.ItemID))
1156 ret[item.ItemID] = n;
1157 }
1134 break; 1158 break;
1135 } 1159 }
1136 } 1160 }
@@ -1139,5 +1163,29 @@ namespace OpenSim.Region.Framework.Scenes
1139 } 1163 }
1140 return ret; 1164 return ret;
1141 } 1165 }
1166
1167 public void ResumeScripts()
1168 {
1169 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
1170 if (engines == null)
1171 return;
1172
1173
1174 Items.LockItemsForRead(true);
1175
1176 foreach (TaskInventoryItem item in m_items.Values)
1177 {
1178 if (item.InvType == (int)InventoryType.LSL)
1179 {
1180 foreach (IScriptModule engine in engines)
1181 {
1182 if (engine != null)
1183 engine.ResumeScript(item.ItemID);
1184 }
1185 }
1186 }
1187
1188 Items.LockItemsForRead(false);
1189 }
1142 } 1190 }
1143} 1191}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 2603fe1..ceb4395 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Timers; 32using System.Timers;
@@ -33,12 +34,12 @@ using OpenMetaverse;
33using log4net; 34using log4net;
34using OpenSim.Framework; 35using OpenSim.Framework;
35using OpenSim.Framework.Client; 36using OpenSim.Framework.Client;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes.Animation; 38using OpenSim.Region.Framework.Scenes.Animation;
39using OpenSim.Region.Framework.Scenes.Types; 39using OpenSim.Region.Framework.Scenes.Types;
40using OpenSim.Region.Physics.Manager; 40using OpenSim.Region.Physics.Manager;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion; 41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42using OpenSim.Services.Interfaces;
42 43
43namespace OpenSim.Region.Framework.Scenes 44namespace OpenSim.Region.Framework.Scenes
44{ 45{
@@ -150,7 +151,8 @@ namespace OpenSim.Region.Framework.Scenes
150 151
151 private float m_sitAvatarHeight = 2.0f; 152 private float m_sitAvatarHeight = 2.0f;
152 153
153 private float m_godlevel; 154 private int m_godLevel;
155 private int m_userLevel;
154 156
155 private bool m_invulnerable = true; 157 private bool m_invulnerable = true;
156 158
@@ -266,6 +268,8 @@ namespace OpenSim.Region.Framework.Scenes
266 268
267 // For teleports and crossings callbacks 269 // For teleports and crossings callbacks
268 string m_callbackURI; 270 string m_callbackURI;
271 UUID m_originRegionID;
272
269 ulong m_rootRegionHandle; 273 ulong m_rootRegionHandle;
270 274
271 /// <value> 275 /// <value>
@@ -302,9 +306,14 @@ namespace OpenSim.Region.Framework.Scenes
302 get { return m_invulnerable; } 306 get { return m_invulnerable; }
303 } 307 }
304 308
305 public float GodLevel 309 public int UserLevel
310 {
311 get { return m_userLevel; }
312 }
313
314 public int GodLevel
306 { 315 {
307 get { return m_godlevel; } 316 get { return m_godLevel; }
308 } 317 }
309 318
310 public ulong RegionHandle 319 public ulong RegionHandle
@@ -457,7 +466,7 @@ namespace OpenSim.Region.Framework.Scenes
457 PhysicsActor actor = m_physicsActor; 466 PhysicsActor actor = m_physicsActor;
458// if (actor != null) 467// if (actor != null)
459 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting! 468 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
460 m_pos = actor.Position; 469 m_pos = actor.Position;
461 470
462 return m_parentPosition + m_pos; 471 return m_parentPosition + m_pos;
463 } 472 }
@@ -678,6 +687,11 @@ namespace OpenSim.Region.Framework.Scenes
678 m_regionInfo = reginfo; 687 m_regionInfo = reginfo;
679 m_localId = m_scene.AllocateLocalId(); 688 m_localId = m_scene.AllocateLocalId();
680 689
690 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
691
692 if (account != null)
693 m_userLevel = account.UserLevel;
694
681 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 695 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
682 if (gm != null) 696 if (gm != null)
683 m_grouptitle = gm.GetGroupTitle(m_uuid); 697 m_grouptitle = gm.GetGroupTitle(m_uuid);
@@ -868,47 +882,22 @@ namespace OpenSim.Region.Framework.Scenes
868 if (land != null) 882 if (land != null)
869 { 883 {
870 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni. 884 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
871 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && m_godlevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid) 885 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && m_userLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid)
872 { 886 {
873 pos = land.LandData.UserLocation; 887 pos = land.LandData.UserLocation;
874 } 888 }
875 } 889 }
876 } 890 }
877 891
878 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) 892 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
879 { 893 {
880 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
881
882 if (pos.X < 0)
883 {
884 emergencyPos.X = (int)Constants.RegionSize + pos.X;
885 if (!(pos.Y < 0))
886 emergencyPos.Y = pos.Y;
887 if (!(pos.Z < 0))
888 emergencyPos.X = pos.X;
889 }
890 if (pos.Y < 0)
891 {
892 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
893 if (!(pos.X < 0))
894 emergencyPos.X = pos.X;
895 if (!(pos.Z < 0))
896 emergencyPos.Z = pos.Z;
897 }
898 if (pos.Z < 0)
899 {
900 if (!(pos.X < 0))
901 emergencyPos.X = pos.X;
902 if (!(pos.Y < 0))
903 emergencyPos.Y = pos.Y;
904 //Leave as 128
905 }
906
907 m_log.WarnFormat( 894 m_log.WarnFormat(
908 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}", 895 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
909 pos, Name, UUID, emergencyPos); 896 pos, Name, UUID);
910 897
911 pos = emergencyPos; 898 if (pos.X < 0f) pos.X = 0f;
899 if (pos.Y < 0f) pos.Y = 0f;
900 if (pos.Z < 0f) pos.Z = 0f;
912 } 901 }
913 902
914 float localAVHeight = 1.56f; 903 float localAVHeight = 1.56f;
@@ -919,7 +908,7 @@ namespace OpenSim.Region.Framework.Scenes
919 908
920 float posZLimit = 0; 909 float posZLimit = 0;
921 910
922 if (pos.X <Constants.RegionSize && pos.Y < Constants.RegionSize) 911 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
923 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 912 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
924 913
925 float newPosZ = posZLimit + localAVHeight / 2; 914 float newPosZ = posZLimit + localAVHeight / 2;
@@ -971,14 +960,12 @@ namespace OpenSim.Region.Framework.Scenes
971 960
972 m_isChildAgent = false; 961 m_isChildAgent = false;
973 962
974 ScenePresence[] animAgents = m_scene.GetScenePresences(); 963 // send the animations of the other presences to me
975 for (int i = 0; i < animAgents.Length; i++) 964 m_scene.ForEachScenePresence(delegate(ScenePresence presence)
976 { 965 {
977 ScenePresence presence = animAgents[i];
978
979 if (presence != this) 966 if (presence != this)
980 presence.Animator.SendAnimPackToClient(ControllingClient); 967 presence.Animator.SendAnimPackToClient(ControllingClient);
981 } 968 });
982 969
983 m_scene.EventManager.TriggerOnMakeRootAgent(this); 970 m_scene.EventManager.TriggerOnMakeRootAgent(this);
984 } 971 }
@@ -1162,8 +1149,10 @@ namespace OpenSim.Region.Framework.Scenes
1162 /// This is called upon a very important packet sent from the client, 1149 /// This is called upon a very important packet sent from the client,
1163 /// so it's client-controlled. Never call this method directly. 1150 /// so it's client-controlled. Never call this method directly.
1164 /// </summary> 1151 /// </summary>
1165 public void CompleteMovement() 1152 public void CompleteMovement(IClientAPI client)
1166 { 1153 {
1154 //m_log.Debug("[SCENE PRESENCE]: CompleteMovement");
1155
1167 Vector3 look = Velocity; 1156 Vector3 look = Velocity;
1168 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1157 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1169 { 1158 {
@@ -1188,7 +1177,7 @@ namespace OpenSim.Region.Framework.Scenes
1188 if ((m_callbackURI != null) && !m_callbackURI.Equals("")) 1177 if ((m_callbackURI != null) && !m_callbackURI.Equals(""))
1189 { 1178 {
1190 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); 1179 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI);
1191 Scene.SendReleaseAgent(m_rootRegionHandle, UUID, m_callbackURI); 1180 Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI);
1192 m_callbackURI = null; 1181 m_callbackURI = null;
1193 } 1182 }
1194 1183
@@ -1196,6 +1185,21 @@ namespace OpenSim.Region.Framework.Scenes
1196 1185
1197 m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); 1186 m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look);
1198 SendInitialData(); 1187 SendInitialData();
1188
1189 // Create child agents in neighbouring regions
1190 if (!m_isChildAgent)
1191 {
1192 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1193 if (m_agentTransfer != null)
1194 m_agentTransfer.EnableChildAgents(this);
1195 else
1196 m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active");
1197
1198 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1199 if (friendsModule != null)
1200 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1201 }
1202
1199 } 1203 }
1200 1204
1201 /// <summary> 1205 /// <summary>
@@ -1264,6 +1268,7 @@ namespace OpenSim.Region.Framework.Scenes
1264 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1268 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1265 1269
1266 m_pos = m_LastFinitePos; 1270 m_pos = m_LastFinitePos;
1271
1267 if (!m_pos.IsFinite()) 1272 if (!m_pos.IsFinite())
1268 { 1273 {
1269 m_pos.X = 127f; 1274 m_pos.X = 127f;
@@ -1901,6 +1906,7 @@ namespace OpenSim.Region.Framework.Scenes
1901 { 1906 {
1902 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center 1907 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1903 autopilotTarget = part.AbsolutePosition; 1908 autopilotTarget = part.AbsolutePosition;
1909//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
1904 } 1910 }
1905 else return; // occupied small 1911 else return; // occupied small
1906 } // end large/small 1912 } // end large/small
@@ -2277,7 +2283,8 @@ namespace OpenSim.Region.Framework.Scenes
2277 m_pos += SIT_TARGET_ADJUSTMENT; 2283 m_pos += SIT_TARGET_ADJUSTMENT;
2278 m_bodyRot = sitTargetOrient; 2284 m_bodyRot = sitTargetOrient;
2279 m_parentPosition = part.AbsolutePosition; 2285 m_parentPosition = part.AbsolutePosition;
2280 part.IsOccupied = true; 2286 part.IsOccupied = true;
2287Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2281 } 2288 }
2282 else 2289 else
2283 { 2290 {
@@ -2399,6 +2406,7 @@ namespace OpenSim.Region.Framework.Scenes
2399 { 2406 {
2400 if (m_isChildAgent) 2407 if (m_isChildAgent)
2401 { 2408 {
2409 // WHAT???
2402 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); 2410 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");
2403 2411
2404 // we have to reset the user's child agent connections. 2412 // we have to reset the user's child agent connections.
@@ -2422,7 +2430,9 @@ namespace OpenSim.Region.Framework.Scenes
2422 2430
2423 if (m_scene.SceneGridService != null) 2431 if (m_scene.SceneGridService != null)
2424 { 2432 {
2425 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>()); 2433 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
2434 if (m_agentTransfer != null)
2435 m_agentTransfer.EnableChildAgents(this);
2426 } 2436 }
2427 2437
2428 return; 2438 return;
@@ -2590,35 +2600,33 @@ namespace OpenSim.Region.Framework.Scenes
2590 2600
2591 List<Vector3> CoarseLocations = new List<Vector3>(); 2601 List<Vector3> CoarseLocations = new List<Vector3>();
2592 List<UUID> AvatarUUIDs = new List<UUID>(); 2602 List<UUID> AvatarUUIDs = new List<UUID>();
2593 List<ScenePresence> avatars = m_scene.GetAvatars(); 2603 m_scene.ForEachScenePresence(delegate(ScenePresence sp)
2594 for (int i = 0; i < avatars.Count; i++)
2595 { 2604 {
2596 // Requested by LibOMV. Send Course Location on self. 2605 if (sp.IsChildAgent)
2597 //if (avatars[i] != this) 2606 return;
2598 //{ 2607
2599 if (avatars[i].ParentID != 0) 2608 if (sp.ParentID != 0)
2609 {
2610 // sitting avatar
2611 SceneObjectPart sop = m_scene.GetSceneObjectPart(sp.ParentID);
2612 if (sop != null)
2600 { 2613 {
2601 // sitting avatar 2614 CoarseLocations.Add(sop.AbsolutePosition + sp.m_pos);
2602 SceneObjectPart sop = m_scene.GetSceneObjectPart(avatars[i].ParentID); 2615 AvatarUUIDs.Add(sp.UUID);
2603 if (sop != null)
2604 {
2605 CoarseLocations.Add(sop.AbsolutePosition + avatars[i].m_pos);
2606 AvatarUUIDs.Add(avatars[i].UUID);
2607 }
2608 else
2609 {
2610 // we can't find the parent.. ! arg!
2611 CoarseLocations.Add(avatars[i].m_pos);
2612 AvatarUUIDs.Add(avatars[i].UUID);
2613 }
2614 } 2616 }
2615 else 2617 else
2616 { 2618 {
2617 CoarseLocations.Add(avatars[i].m_pos); 2619 // we can't find the parent.. ! arg!
2618 AvatarUUIDs.Add(avatars[i].UUID); 2620 CoarseLocations.Add(sp.m_pos);
2621 AvatarUUIDs.Add(sp.UUID);
2619 } 2622 }
2620 //} 2623 }
2621 } 2624 else
2625 {
2626 CoarseLocations.Add(sp.m_pos);
2627 AvatarUUIDs.Add(sp.UUID);
2628 }
2629 });
2622 2630
2623 m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations); 2631 m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations);
2624 2632
@@ -2660,13 +2668,10 @@ namespace OpenSim.Region.Framework.Scenes
2660 public void SendInitialFullUpdateToAllClients() 2668 public void SendInitialFullUpdateToAllClients()
2661 { 2669 {
2662 m_perfMonMS = Util.EnvironmentTickCount(); 2670 m_perfMonMS = Util.EnvironmentTickCount();
2663 2671 int avUpdates = 0;
2664 ScenePresence[] avatars = m_scene.GetScenePresences(); 2672 m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
2665
2666 for (int i = 0; i < avatars.Length; i++)
2667 { 2673 {
2668 ScenePresence avatar = avatars[i]; 2674 ++avUpdates;
2669
2670 // only send if this is the root (children are only "listening posts" in a foreign region) 2675 // only send if this is the root (children are only "listening posts" in a foreign region)
2671 if (!IsChildAgent) 2676 if (!IsChildAgent)
2672 { 2677 {
@@ -2682,9 +2687,9 @@ namespace OpenSim.Region.Framework.Scenes
2682 avatar.Animator.SendAnimPackToClient(ControllingClient); 2687 avatar.Animator.SendAnimPackToClient(ControllingClient);
2683 } 2688 }
2684 } 2689 }
2685 } 2690 });
2686 2691
2687 m_scene.StatsReporter.AddAgentUpdates(avatars.Length); 2692 m_scene.StatsReporter.AddAgentUpdates(avUpdates);
2688 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2693 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2689 2694
2690 //Animator.SendAnimPack(); 2695 //Animator.SendAnimPack();
@@ -2695,13 +2700,15 @@ namespace OpenSim.Region.Framework.Scenes
2695 m_perfMonMS = Util.EnvironmentTickCount(); 2700 m_perfMonMS = Util.EnvironmentTickCount();
2696 2701
2697 // only send update from root agents to other clients; children are only "listening posts" 2702 // only send update from root agents to other clients; children are only "listening posts"
2698 List<ScenePresence> avatars = m_scene.GetAvatars(); 2703 int count = 0;
2699 foreach (ScenePresence avatar in avatars) 2704 m_scene.ForEachScenePresence(delegate(ScenePresence sp)
2700 { 2705 {
2701 SendFullUpdateToOtherClient(avatar); 2706 if (sp.IsChildAgent)
2702 2707 return;
2703 } 2708 SendFullUpdateToOtherClient(sp);
2704 m_scene.StatsReporter.AddAgentUpdates(avatars.Count); 2709 ++count;
2710 });
2711 m_scene.StatsReporter.AddAgentUpdates(count);
2705 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2712 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2706 2713
2707 Animator.SendAnimPack(); 2714 Animator.SendAnimPack();
@@ -2722,14 +2729,9 @@ namespace OpenSim.Region.Framework.Scenes
2722 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2729 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2723 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); 2730 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot));
2724 2731
2725 if (!m_isChildAgent)
2726 {
2727 m_scene.InformClientOfNeighbours(this);
2728 }
2729
2730 SendInitialFullUpdateToAllClients(); 2732 SendInitialFullUpdateToAllClients();
2731 SendAppearanceToAllOtherAgents(); 2733 SendAppearanceToAllOtherAgents();
2732 } 2734 }
2733 2735
2734 /// <summary> 2736 /// <summary>
2735 /// Tell the client for this scene presence what items it should be wearing now 2737 /// Tell the client for this scene presence what items it should be wearing now
@@ -2811,14 +2813,19 @@ namespace OpenSim.Region.Framework.Scenes
2811 } 2813 }
2812 } 2814 }
2813 } 2815 }
2816
2814 } 2817 }
2815 2818
2819
2816 #endregion Bake Cache Check 2820 #endregion Bake Cache Check
2817 2821
2818 m_appearance.SetAppearance(textureEntry, visualParams); 2822 m_appearance.SetAppearance(textureEntry, visualParams);
2819 if (m_appearance.AvatarHeight > 0) 2823 if (m_appearance.AvatarHeight > 0)
2820 SetHeight(m_appearance.AvatarHeight); 2824 SetHeight(m_appearance.AvatarHeight);
2821 m_scene.CommsManager.AvatarService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance); 2825
2826 // This is not needed, because only the transient data changed
2827 //AvatarData adata = new AvatarData(m_appearance);
2828 //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata);
2822 2829
2823 SendAppearanceToAllOtherAgents(); 2830 SendAppearanceToAllOtherAgents();
2824 if (!m_startAnimationSet) 2831 if (!m_startAnimationSet)
@@ -2838,7 +2845,8 @@ namespace OpenSim.Region.Framework.Scenes
2838 public void SetWearable(int wearableId, AvatarWearable wearable) 2845 public void SetWearable(int wearableId, AvatarWearable wearable)
2839 { 2846 {
2840 m_appearance.SetWearable(wearableId, wearable); 2847 m_appearance.SetWearable(wearableId, wearable);
2841 m_scene.CommsManager.AvatarService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance); 2848 AvatarData adata = new AvatarData(m_appearance);
2849 m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata);
2842 m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); 2850 m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
2843 } 2851 }
2844 2852
@@ -2860,7 +2868,12 @@ namespace OpenSim.Region.Framework.Scenes
2860 /// </summary> 2868 /// </summary>
2861 protected void CheckForSignificantMovement() 2869 protected void CheckForSignificantMovement()
2862 { 2870 {
2863 if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > 0.5) 2871 // Movement updates for agents in neighboring regions are sent directly to clients.
2872 // This value only affects how often agent positions are sent to neighbor regions
2873 // for things such as distance-based update prioritization
2874 const float SIGNIFICANT_MOVEMENT = 2.0f;
2875
2876 if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT)
2864 { 2877 {
2865 posLastSignificantMove = AbsolutePosition; 2878 posLastSignificantMove = AbsolutePosition;
2866 m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); 2879 m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient);
@@ -2871,18 +2884,19 @@ namespace OpenSim.Region.Framework.Scenes
2871 if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance || 2884 if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance ||
2872 Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance) 2885 Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance)
2873 { 2886 {
2887 m_lastChildAgentUpdatePosition = AbsolutePosition;
2888 m_lastChildAgentUpdateCamPosition = CameraPosition;
2889
2874 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); 2890 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
2875 cadu.ActiveGroupID = UUID.Zero.Guid; 2891 cadu.ActiveGroupID = UUID.Zero.Guid;
2876 cadu.AgentID = UUID.Guid; 2892 cadu.AgentID = UUID.Guid;
2877 cadu.alwaysrun = m_setAlwaysRun; 2893 cadu.alwaysrun = m_setAlwaysRun;
2878 cadu.AVHeight = m_avHeight; 2894 cadu.AVHeight = m_avHeight;
2879 sLLVector3 tempCameraCenter = new sLLVector3(new Vector3(m_CameraCenter.X, m_CameraCenter.Y, m_CameraCenter.Z)); 2895 Vector3 tempCameraCenter = m_CameraCenter;
2880 cadu.cameraPosition = tempCameraCenter; 2896 cadu.cameraPosition = tempCameraCenter;
2881 cadu.drawdistance = m_DrawDistance; 2897 cadu.drawdistance = m_DrawDistance;
2882 if (m_scene.Permissions.IsGod(new UUID(cadu.AgentID)))
2883 cadu.godlevel = m_godlevel;
2884 cadu.GroupAccess = 0; 2898 cadu.GroupAccess = 0;
2885 cadu.Position = new sLLVector3(AbsolutePosition); 2899 cadu.Position = AbsolutePosition;
2886 cadu.regionHandle = m_rootRegionHandle; 2900 cadu.regionHandle = m_rootRegionHandle;
2887 float multiplier = 1; 2901 float multiplier = 1;
2888 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); 2902 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount();
@@ -2897,15 +2911,12 @@ namespace OpenSim.Region.Framework.Scenes
2897 2911
2898 //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); 2912 //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString());
2899 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); 2913 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier);
2900 cadu.Velocity = new sLLVector3(Velocity); 2914 cadu.Velocity = Velocity;
2901 2915
2902 AgentPosition agentpos = new AgentPosition(); 2916 AgentPosition agentpos = new AgentPosition();
2903 agentpos.CopyFrom(cadu); 2917 agentpos.CopyFrom(cadu);
2904 2918
2905 m_scene.SendOutChildAgentUpdates(agentpos, this); 2919 m_scene.SendOutChildAgentUpdates(agentpos, this);
2906
2907 m_lastChildAgentUpdatePosition = AbsolutePosition;
2908 m_lastChildAgentUpdateCamPosition = CameraPosition;
2909 } 2920 }
2910 } 2921 }
2911 2922
@@ -3161,18 +3172,21 @@ namespace OpenSim.Region.Framework.Scenes
3161 // For now, assign god level 200 to anyone 3172 // For now, assign god level 200 to anyone
3162 // who is granted god powers, but has no god level set. 3173 // who is granted god powers, but has no god level set.
3163 // 3174 //
3164 CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); 3175 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID);
3165 if (profile.UserProfile.GodLevel > 0) 3176 if (account != null)
3166 m_godlevel = profile.UserProfile.GodLevel; 3177 {
3167 else 3178 if (account.UserLevel > 0)
3168 m_godlevel = 200; 3179 m_godLevel = account.UserLevel;
3180 else
3181 m_godLevel = 200;
3182 }
3169 } 3183 }
3170 else 3184 else
3171 { 3185 {
3172 m_godlevel = 0; 3186 m_godLevel = 0;
3173 } 3187 }
3174 3188
3175 ControllingClient.SendAdminResponse(token, (uint)m_godlevel); 3189 ControllingClient.SendAdminResponse(token, (uint)m_godLevel);
3176 } 3190 }
3177 3191
3178 #region Child Agent Updates 3192 #region Child Agent Updates
@@ -3231,7 +3245,7 @@ namespace OpenSim.Region.Framework.Scenes
3231 public void CopyTo(AgentData cAgent) 3245 public void CopyTo(AgentData cAgent)
3232 { 3246 {
3233 cAgent.AgentID = UUID; 3247 cAgent.AgentID = UUID;
3234 cAgent.RegionHandle = m_rootRegionHandle; 3248 cAgent.RegionID = Scene.RegionInfo.RegionID;
3235 3249
3236 cAgent.Position = AbsolutePosition; 3250 cAgent.Position = AbsolutePosition;
3237 cAgent.Velocity = m_velocity; 3251 cAgent.Velocity = m_velocity;
@@ -3263,7 +3277,7 @@ namespace OpenSim.Region.Framework.Scenes
3263 cAgent.ControlFlags = (uint)m_AgentControlFlags; 3277 cAgent.ControlFlags = (uint)m_AgentControlFlags;
3264 3278
3265 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3279 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3266 cAgent.GodLevel = (byte)m_godlevel; 3280 cAgent.GodLevel = (byte)m_godLevel;
3267 else 3281 else
3268 cAgent.GodLevel = (byte) 0; 3282 cAgent.GodLevel = (byte) 0;
3269 3283
@@ -3330,11 +3344,12 @@ namespace OpenSim.Region.Framework.Scenes
3330 3344
3331 public void CopyFrom(AgentData cAgent) 3345 public void CopyFrom(AgentData cAgent)
3332 { 3346 {
3333 m_rootRegionHandle = cAgent.RegionHandle; 3347 m_originRegionID = cAgent.RegionID;
3334 3348
3335 m_callbackURI = cAgent.CallbackURI; 3349 m_callbackURI = cAgent.CallbackURI;
3336 3350
3337 m_pos = cAgent.Position; 3351 m_pos = cAgent.Position;
3352
3338 m_velocity = cAgent.Velocity; 3353 m_velocity = cAgent.Velocity;
3339 m_CameraCenter = cAgent.Center; 3354 m_CameraCenter = cAgent.Center;
3340 //m_avHeight = cAgent.Size.Z; 3355 //m_avHeight = cAgent.Size.Z;
@@ -3352,7 +3367,7 @@ namespace OpenSim.Region.Framework.Scenes
3352 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; 3367 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags;
3353 3368
3354 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3369 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3355 m_godlevel = cAgent.GodLevel; 3370 m_godLevel = cAgent.GodLevel;
3356 m_setAlwaysRun = cAgent.AlwaysRun; 3371 m_setAlwaysRun = cAgent.AlwaysRun;
3357 3372
3358 uint i = 0; 3373 uint i = 0;
@@ -3710,36 +3725,6 @@ namespace OpenSim.Region.Framework.Scenes
3710 } 3725 }
3711 } 3726 }
3712 3727
3713 public bool CrossAttachmentsIntoNewRegion(ulong regionHandle, bool silent)
3714 {
3715 lock (m_attachments)
3716 {
3717 // Validate
3718 foreach (SceneObjectGroup gobj in m_attachments)
3719 {
3720 if (gobj == null || gobj.IsDeleted)
3721 return false;
3722 }
3723
3724 foreach (SceneObjectGroup gobj in m_attachments)
3725 {
3726 // If the prim group is null then something must have happened to it!
3727 if (gobj != null && gobj.RootPart != null)
3728 {
3729 // Set the parent localID to 0 so it transfers over properly.
3730 gobj.RootPart.SetParentLocalId(0);
3731 gobj.AbsolutePosition = gobj.RootPart.AttachedPos;
3732 gobj.RootPart.IsAttachment = false;
3733 //gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
3734 m_log.DebugFormat("[ATTACHMENT]: Sending attachment {0} to region {1}", gobj.UUID, regionHandle);
3735 m_scene.CrossPrimGroupIntoNewRegion(regionHandle, gobj, silent);
3736 }
3737 }
3738 m_attachments.Clear();
3739
3740 return true;
3741 }
3742 }
3743 3728
3744 public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) 3729 public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene)
3745 { 3730 {
@@ -3975,10 +3960,36 @@ namespace OpenSim.Region.Framework.Scenes
3975 { 3960 {
3976 if (null == m_appearance) 3961 if (null == m_appearance)
3977 { 3962 {
3978 m_log.WarnFormat("[ATTACHMENT] Appearance has not been initialized for agent {0}", UUID); 3963 m_log.WarnFormat("[ATTACHMENT]: Appearance has not been initialized for agent {0}", UUID);
3979 return; 3964 return;
3980 } 3965 }
3981 3966
3967 XmlDocument doc = new XmlDocument();
3968 string stateData = String.Empty;
3969
3970 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
3971 if (attServ != null)
3972 {
3973 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
3974 stateData = attServ.Get(ControllingClient.AgentId.ToString());
3975 doc.LoadXml(stateData);
3976 }
3977
3978 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
3979
3980 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
3981 if (nodes.Count > 0)
3982 {
3983 foreach (XmlNode n in nodes)
3984 {
3985 XmlElement elem = (XmlElement)n;
3986 string itemID = elem.GetAttribute("ItemID");
3987 string xml = elem.InnerXml;
3988
3989 itemData[new UUID(itemID)] = xml;
3990 }
3991 }
3992
3982 List<int> attPoints = m_appearance.GetAttachedPoints(); 3993 List<int> attPoints = m_appearance.GetAttachedPoints();
3983 foreach (int p in attPoints) 3994 foreach (int p in attPoints)
3984 { 3995 {
@@ -3998,13 +4009,21 @@ namespace OpenSim.Region.Framework.Scenes
3998 4009
3999 try 4010 try
4000 { 4011 {
4001 // Rez from inventory 4012 string xmlData;
4002 UUID asset = m_scene.RezSingleAttachment(ControllingClient, 4013 XmlDocument d = new XmlDocument();
4003 itemID, (uint)p); 4014 if (itemData.TryGetValue(itemID, out xmlData))
4015 {
4016 d.LoadXml(xmlData);
4017 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4018 }
4004 4019
4005 m_log.InfoFormat("[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", 4020 // Rez from inventory
4006 p, itemID, assetID, asset); 4021 UUID asset
4022 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4007 4023
4024 m_log.InfoFormat(
4025 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})",
4026 p, itemID, assetID, asset);
4008 } 4027 }
4009 catch (Exception e) 4028 catch (Exception e)
4010 { 4029 {
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index 1cff0eb..4ba4fab 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -31,7 +31,6 @@ using OpenMetaverse;
31using log4net; 31using log4net;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Framework.Client; 33using OpenSim.Framework.Client;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Region.Framework.Interfaces; 34using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes.Types; 35using OpenSim.Region.Framework.Scenes.Types;
37 36
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
index cf0f345..b6677f0 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
@@ -182,6 +182,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
182 foreach (SceneObjectGroup sceneObject in sceneObjects) 182 foreach (SceneObjectGroup sceneObject in sceneObjects)
183 { 183 {
184 sceneObject.CreateScriptInstances(0, true, scene.DefaultScriptEngine, 0); 184 sceneObject.CreateScriptInstances(0, true, scene.DefaultScriptEngine, 0);
185 sceneObject.ResumeScripts();
185 } 186 }
186 } 187 }
187 188
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
index 8230f32..dd9f8f6 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
@@ -65,6 +65,11 @@ namespace OpenSim.Region.Framework.Scenes.Tests
65 { 65 {
66 throw new NotImplementedException(); 66 throw new NotImplementedException();
67 } 67 }
68
69 public override bool TryGetScenePresence(UUID agentID, out ScenePresence scenePresence)
70 {
71 throw new NotImplementedException();
72 }
68 } 73 }
69 74
70 [Test] 75 [Test]
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs
index 0ed00de..78f2ae3 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs
@@ -32,8 +32,7 @@ using NUnit.Framework.SyntaxHelpers;
32using OpenMetaverse; 32using OpenMetaverse;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Communications; 34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Communications.Cache; 35
36using OpenSim.Region.Communications.Local;
37using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
38using OpenSim.Tests.Common; 37using OpenSim.Tests.Common;
39using OpenSim.Tests.Common.Mock; 38using OpenSim.Tests.Common.Mock;
@@ -87,6 +86,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
87 public void TestDeleteSceneObjectAsync() 86 public void TestDeleteSceneObjectAsync()
88 { 87 {
89 TestHelper.InMethod(); 88 TestHelper.InMethod();
89 //log4net.Config.XmlConfigurator.Configure();
90 90
91 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001"); 91 UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
92 92
@@ -95,16 +95,18 @@ namespace OpenSim.Region.Framework.Scenes.Tests
95 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. 95 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
96 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; 96 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
97 sogd.Enabled = false; 97 sogd.Enabled = false;
98 98
99 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene); 99 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
100 100
101 IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId); 101 IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
102 scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero); 102 scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
103 103
104 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); 104 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
105
105 Assert.That(retrievedPart, Is.Not.Null); 106 Assert.That(retrievedPart, Is.Not.Null);
106 107
107 sogd.InventoryDeQueueAndDelete(); 108 sogd.InventoryDeQueueAndDelete();
109
108 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId); 110 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
109 Assert.That(retrievedPart2, Is.Null); 111 Assert.That(retrievedPart2, Is.Null);
110 } 112 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
index 709cca2..0b7608d 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectLinkingTests.cs
@@ -32,8 +32,7 @@ using NUnit.Framework.SyntaxHelpers;
32using OpenMetaverse; 32using OpenMetaverse;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Communications; 34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Communications.Cache; 35
36using OpenSim.Region.Communications.Local;
37using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
38using OpenSim.Tests.Common; 37using OpenSim.Tests.Common;
39using OpenSim.Tests.Common.Mock; 38using OpenSim.Tests.Common.Mock;
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
index f00dd66..501207e 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
@@ -40,8 +40,8 @@ using OpenSim.Framework;
40using OpenSim.Framework.Communications; 40using OpenSim.Framework.Communications;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Interfaces; 42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion;
44using OpenSim.Region.CoreModules.World.Serialiser; 43using OpenSim.Region.CoreModules.World.Serialiser;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45using OpenSim.Tests.Common; 45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock; 46using OpenSim.Tests.Common.Mock;
47using OpenSim.Tests.Common.Setup; 47using OpenSim.Tests.Common.Setup;
@@ -58,7 +58,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
58 public UUID agent1, agent2, agent3; 58 public UUID agent1, agent2, agent3;
59 public static Random random; 59 public static Random random;
60 public ulong region1,region2,region3; 60 public ulong region1,region2,region3;
61 public TestCommunicationsManager cm;
62 public AgentCircuitData acd1; 61 public AgentCircuitData acd1;
63 public SceneObjectGroup sog1, sog2, sog3; 62 public SceneObjectGroup sog1, sog2, sog3;
64 public TestClient testclient; 63 public TestClient testclient;
@@ -66,12 +65,11 @@ namespace OpenSim.Region.Framework.Scenes.Tests
66 [TestFixtureSetUp] 65 [TestFixtureSetUp]
67 public void Init() 66 public void Init()
68 { 67 {
69 cm = new TestCommunicationsManager(); 68 scene = SceneSetupHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
70 scene = SceneSetupHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000, cm); 69 scene2 = SceneSetupHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
71 scene2 = SceneSetupHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000, cm); 70 scene3 = SceneSetupHelpers.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000);
72 scene3 = SceneSetupHelpers.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000, cm);
73 71
74 ISharedRegionModule interregionComms = new RESTInterregionComms(); 72 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
75 interregionComms.Initialise(new IniConfigSource()); 73 interregionComms.Initialise(new IniConfigSource());
76 interregionComms.PostInitialise(); 74 interregionComms.PostInitialise();
77 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms); 75 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
@@ -373,7 +371,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
373 371
374 Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross"); 372 Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross");
375 373
376 Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); 374 //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful");
377 Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); 375 Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted");
378 Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); 376 Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects");
379 } 377 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
index 5abbb82..8b2d387 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -101,13 +101,13 @@ namespace OpenSim.Region.Framework.Scenes.Tests
101 { 101 {
102 throw new NotImplementedException(); 102 throw new NotImplementedException();
103 } 103 }
104 public RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID) 104 public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
105 { 105 {
106 //This connector doesn't support the windlight module yet 106 //This connector doesn't support the windlight module yet
107 //Return default LL windlight settings 107 //Return default LL windlight settings
108 return new RegionMeta7WindlightData(); 108 return new RegionLightShareData();
109 } 109 }
110 public void StoreRegionWindlightSettings(RegionMeta7WindlightData wl) 110 public void StoreRegionWindlightSettings(RegionLightShareData wl)
111 { 111 {
112 //This connector doesn't support the windlight module yet 112 //This connector doesn't support the windlight module yet
113 } 113 }
@@ -141,7 +141,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
141 RegionInfo regionInfo = new RegionInfo(0,0,null,null); 141 RegionInfo regionInfo = new RegionInfo(0,0,null,null);
142 FakeStorageManager storageManager = new FakeStorageManager(); 142 FakeStorageManager storageManager = new FakeStorageManager();
143 143
144 new Scene(regionInfo, null, null, null, storageManager, null, false, false, false, null, null); 144 new Scene(regionInfo, null, null, storageManager, null, false, false, false, null, null);
145 } 145 }
146 } 146 }
147} 147}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/StandaloneTeleportTests.cs b/OpenSim/Region/Framework/Scenes/Tests/StandaloneTeleportTests.cs
index b46eb8e..cafe48a 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/StandaloneTeleportTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/StandaloneTeleportTests.cs
@@ -34,7 +34,7 @@ using OpenMetaverse;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Communications; 35using OpenSim.Framework.Communications;
36using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion; 37using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
38using OpenSim.Tests.Common; 38using OpenSim.Tests.Common;
39using OpenSim.Tests.Common.Mock; 39using OpenSim.Tests.Common.Mock;
40using OpenSim.Tests.Common.Setup; 40using OpenSim.Tests.Common.Setup;
@@ -113,17 +113,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests
113 113
114 UUID sceneAId = UUID.Parse("00000000-0000-0000-0000-000000000100"); 114 UUID sceneAId = UUID.Parse("00000000-0000-0000-0000-000000000100");
115 UUID sceneBId = UUID.Parse("00000000-0000-0000-0000-000000000200"); 115 UUID sceneBId = UUID.Parse("00000000-0000-0000-0000-000000000200");
116 TestCommunicationsManager cm = new TestCommunicationsManager();
117 116
118 // shared module 117 // shared module
119 ISharedRegionModule interregionComms = new RESTInterregionComms(); 118 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
120 119
121 120
122 Scene sceneB = SceneSetupHelpers.SetupScene("sceneB", sceneBId, 1010, 1010, cm, "grid"); 121 Scene sceneB = SceneSetupHelpers.SetupScene("sceneB", sceneBId, 1010, 1010, "grid");
123 SceneSetupHelpers.SetupSceneModules(sceneB, new IniConfigSource(), interregionComms); 122 SceneSetupHelpers.SetupSceneModules(sceneB, new IniConfigSource(), interregionComms);
124 sceneB.RegisterRegionWithGrid(); 123 sceneB.RegisterRegionWithGrid();
125 124
126 Scene sceneA = SceneSetupHelpers.SetupScene("sceneA", sceneAId, 1000, 1000, cm, "grid"); 125 Scene sceneA = SceneSetupHelpers.SetupScene("sceneA", sceneAId, 1000, 1000, "grid");
127 SceneSetupHelpers.SetupSceneModules(sceneA, new IniConfigSource(), interregionComms); 126 SceneSetupHelpers.SetupSceneModules(sceneA, new IniConfigSource(), interregionComms);
128 sceneA.RegisterRegionWithGrid(); 127 sceneA.RegisterRegionWithGrid();
129 128
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
index a36c4db..8b80ebe 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
@@ -58,10 +58,10 @@ namespace OpenSim.Region.Framework.Scenes.Tests
58 TestHelper.InMethod(); 58 TestHelper.InMethod();
59 59
60 UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); 60 UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
61 AssetBase corruptAsset = AssetHelpers.CreateAsset(corruptAssetUuid, "CORRUPT ASSET"); 61 AssetBase corruptAsset = AssetHelpers.CreateAsset(corruptAssetUuid, "CORRUPT ASSET", UUID.Zero);
62 m_assetService.Store(corruptAsset); 62 m_assetService.Store(corruptAsset);
63 63
64 IDictionary<UUID, int> foundAssetUuids = new Dictionary<UUID, int>(); 64 IDictionary<UUID, AssetType> foundAssetUuids = new Dictionary<UUID, AssetType>();
65 m_uuidGatherer.GatherAssetUuids(corruptAssetUuid, AssetType.Object, foundAssetUuids); 65 m_uuidGatherer.GatherAssetUuids(corruptAssetUuid, AssetType.Object, foundAssetUuids);
66 66
67 // We count the uuid as gathered even if the asset itself is corrupt. 67 // We count the uuid as gathered even if the asset itself is corrupt.
@@ -77,7 +77,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
77 TestHelper.InMethod(); 77 TestHelper.InMethod();
78 78
79 UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); 79 UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
80 IDictionary<UUID, int> foundAssetUuids = new Dictionary<UUID, int>(); 80 IDictionary<UUID, AssetType> foundAssetUuids = new Dictionary<UUID, AssetType>();
81 81
82 m_uuidGatherer.GatherAssetUuids(missingAssetUuid, AssetType.Object, foundAssetUuids); 82 m_uuidGatherer.GatherAssetUuids(missingAssetUuid, AssetType.Object, foundAssetUuids);
83 83
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
index 3edb677..0ec3cc3 100644
--- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
+++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
@@ -84,9 +84,9 @@ namespace OpenSim.Region.Framework.Scenes
84 /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param> 84 /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param>
85 /// <param name="assetType">The type of the asset for the uuid given</param> 85 /// <param name="assetType">The type of the asset for the uuid given</param>
86 /// <param name="assetUuids">The assets gathered</param> 86 /// <param name="assetUuids">The assets gathered</param>
87 public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary<UUID, int> assetUuids) 87 public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary<UUID, AssetType> assetUuids)
88 { 88 {
89 assetUuids[assetUuid] = 1; 89 assetUuids[assetUuid] = assetType;
90 90
91 if (AssetType.Bodypart == assetType || AssetType.Clothing == assetType) 91 if (AssetType.Bodypart == assetType || AssetType.Clothing == assetType)
92 { 92 {
@@ -116,7 +116,7 @@ namespace OpenSim.Region.Framework.Scenes
116 /// 116 ///
117 /// <param name="sceneObject">The scene object for which to gather assets</param> 117 /// <param name="sceneObject">The scene object for which to gather assets</param>
118 /// <param name="assetUuids">The assets gathered</param> 118 /// <param name="assetUuids">The assets gathered</param>
119 public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary<UUID, int> assetUuids) 119 public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary<UUID, AssetType> assetUuids)
120 { 120 {
121// m_log.DebugFormat( 121// m_log.DebugFormat(
122// "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID); 122// "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID);
@@ -129,25 +129,26 @@ namespace OpenSim.Region.Framework.Scenes
129 try 129 try
130 { 130 {
131 Primitive.TextureEntry textureEntry = part.Shape.Textures; 131 Primitive.TextureEntry textureEntry = part.Shape.Textures;
132 132 if (textureEntry != null)
133 // Get the prim's default texture. This will be used for faces which don't have their own texture
134 assetUuids[textureEntry.DefaultTexture.TextureID] = 1;
135
136 // XXX: Not a great way to iterate through face textures, but there's no
137 // other method available to tell how many faces there actually are
138 //int i = 0;
139 foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures)
140 { 133 {
141 if (texture != null) 134 // Get the prim's default texture. This will be used for faces which don't have their own texture
135 if (textureEntry.DefaultTexture != null)
136 assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture;
137
138 if (textureEntry.FaceTextures != null)
142 { 139 {
143 //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++); 140 // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
144 assetUuids[texture.TextureID] = 1; 141 foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures)
142 {
143 if (texture != null)
144 assetUuids[texture.TextureID] = AssetType.Texture;
145 }
145 } 146 }
146 } 147 }
147 148
148 // If the prim is a sculpt then preserve this information too 149 // If the prim is a sculpt then preserve this information too
149 if (part.Shape.SculptTexture != UUID.Zero) 150 if (part.Shape.SculptTexture != UUID.Zero)
150 assetUuids[part.Shape.SculptTexture] = 1; 151 assetUuids[part.Shape.SculptTexture] = AssetType.Texture;
151 152
152 TaskInventoryDictionary taskDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 153 TaskInventoryDictionary taskDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
153 154
@@ -217,7 +218,7 @@ namespace OpenSim.Region.Framework.Scenes
217 /// </summary> 218 /// </summary>
218 /// <param name="scriptUuid"></param> 219 /// <param name="scriptUuid"></param>
219 /// <param name="assetUuids">Dictionary in which to record the references</param> 220 /// <param name="assetUuids">Dictionary in which to record the references</param>
220 protected void GetScriptAssetUuids(UUID scriptUuid, IDictionary<UUID, int> assetUuids) 221 protected void GetScriptAssetUuids(UUID scriptUuid, IDictionary<UUID, AssetType> assetUuids)
221 { 222 {
222 AssetBase scriptAsset = GetAsset(scriptUuid); 223 AssetBase scriptAsset = GetAsset(scriptUuid);
223 224
@@ -232,7 +233,9 @@ namespace OpenSim.Region.Framework.Scenes
232 { 233 {
233 UUID uuid = new UUID(uuidMatch.Value); 234 UUID uuid = new UUID(uuidMatch.Value);
234 //m_log.DebugFormat("[ARCHIVER]: Recording {0} in script", uuid); 235 //m_log.DebugFormat("[ARCHIVER]: Recording {0} in script", uuid);
235 assetUuids[uuid] = 1; 236
237 // Assume AssetIDs embedded in scripts are textures
238 assetUuids[uuid] = AssetType.Texture;
236 } 239 }
237 } 240 }
238 } 241 }
@@ -242,7 +245,7 @@ namespace OpenSim.Region.Framework.Scenes
242 /// </summary> 245 /// </summary>
243 /// <param name="wearableAssetUuid"></param> 246 /// <param name="wearableAssetUuid"></param>
244 /// <param name="assetUuids">Dictionary in which to record the references</param> 247 /// <param name="assetUuids">Dictionary in which to record the references</param>
245 protected void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary<UUID, int> assetUuids) 248 protected void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary<UUID, AssetType> assetUuids)
246 { 249 {
247 AssetBase assetBase = GetAsset(wearableAssetUuid); 250 AssetBase assetBase = GetAsset(wearableAssetUuid);
248 251
@@ -257,8 +260,7 @@ namespace OpenSim.Region.Framework.Scenes
257 260
258 foreach (UUID uuid in wearableAsset.Textures.Values) 261 foreach (UUID uuid in wearableAsset.Textures.Values)
259 { 262 {
260 //m_log.DebugFormat("[ARCHIVER]: Got bodypart uuid {0}", uuid); 263 assetUuids[uuid] = AssetType.Texture;
261 assetUuids[uuid] = 1;
262 } 264 }
263 } 265 }
264 } 266 }
@@ -270,7 +272,7 @@ namespace OpenSim.Region.Framework.Scenes
270 /// </summary> 272 /// </summary>
271 /// <param name="sceneObject"></param> 273 /// <param name="sceneObject"></param>
272 /// <param name="assetUuids"></param> 274 /// <param name="assetUuids"></param>
273 protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, int> assetUuids) 275 protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, AssetType> assetUuids)
274 { 276 {
275 AssetBase objectAsset = GetAsset(sceneObjectUuid); 277 AssetBase objectAsset = GetAsset(sceneObjectUuid);
276 278
@@ -284,7 +286,7 @@ namespace OpenSim.Region.Framework.Scenes
284 } 286 }
285 } 287 }
286 288
287 protected void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, int> assetUuids) 289 protected void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, AssetType> assetUuids)
288 { 290 {
289 AssetBase assetBase = GetAsset(gestureUuid); 291 AssetBase assetBase = GetAsset(gestureUuid);
290 292
@@ -316,7 +318,7 @@ namespace OpenSim.Region.Framework.Scenes
316 // If it can be parsed as a UUID, it is an asset ID 318 // If it can be parsed as a UUID, it is an asset ID
317 UUID uuid; 319 UUID uuid;
318 if (UUID.TryParse(id, out uuid)) 320 if (UUID.TryParse(id, out uuid))
319 assetUuids[uuid] = 1; 321 assetUuids[uuid] = AssetType.Animation;
320 } 322 }
321 } 323 }
322 } 324 }