aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/AsyncSceneObjectGroupDeleter.cs5
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs57
-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/Hypergrid/HGUuidGatherer.cs56
-rw-r--r--OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs3
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs693
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs73
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs958
-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.cs195
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs6
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs98
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs55
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs180
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs1
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs5
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs21
-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.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/StandaloneTeleportTests.cs9
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs2
28 files changed, 934 insertions, 3684 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index be0e985..fd7d44f 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;
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..1650946 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,21 +110,24 @@ 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;
119 public event ScriptResetDelegate OnScriptReset; 122 public event ScriptResetDelegate OnScriptReset;
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;
@@ -163,38 +169,35 @@ namespace OpenSim.Region.Framework.Scenes
163 169
164 public delegate void ClientClosed(UUID clientID, Scene scene); 170 public delegate void ClientClosed(UUID clientID, Scene scene);
165 171
166 public event ClientClosed OnClientClosed; 172 public event ClientClosed OnClientClosed;
167
168 public delegate void ScriptChangedEvent(uint localID, uint change);
169 173
174 /// <summary>
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;
@@ -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;
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/Hypergrid/HGUuidGatherer.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs
deleted file mode 100644
index 5d4e7ac..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs
+++ /dev/null
@@ -1,56 +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;
30
31using OpenSim.Framework;
32using OpenSim.Services.Interfaces;
33using OpenMetaverse;
34
35namespace OpenSim.Region.Framework.Scenes.Hypergrid
36{
37 public class HGUuidGatherer : UuidGatherer
38 {
39 protected string m_assetServerURL;
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 }
56}
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 b2b061e..eb51019 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -35,7 +35,7 @@ using OpenMetaverse;
35using OpenMetaverse.Packets; 35using OpenMetaverse.Packets;
36using log4net; 36using log4net;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications.Cache; 38
39using OpenSim.Region.Framework; 39using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes.Serialization; 41using OpenSim.Region.Framework.Scenes.Serialization;
@@ -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,61 +126,6 @@ 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)
@@ -195,7 +134,9 @@ namespace OpenSim.Region.Framework.Scenes
195 134
196 if (TryGetAvatar(avatarId, out avatar)) 135 if (TryGetAvatar(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)
@@ -478,7 +419,11 @@ namespace OpenSim.Region.Framework.Scenes
478 itemCopy.SaleType = item.SaleType; 419 itemCopy.SaleType = item.SaleType;
479 420
480 if (InventoryService.AddItem(itemCopy)) 421 if (InventoryService.AddItem(itemCopy))
481 TransferInventoryAssets(itemCopy, senderId, recipient); 422 {
423 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
424 if (invAccess != null)
425 invAccess.TransferInventoryAssets(itemCopy, senderId, recipient);
426 }
482 427
483 if (!Permissions.BypassPermissions()) 428 if (!Permissions.BypassPermissions())
484 { 429 {
@@ -500,10 +445,6 @@ namespace OpenSim.Region.Framework.Scenes
500 445
501 } 446 }
502 447
503 protected virtual void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
504 {
505 }
506
507 /// <summary> 448 /// <summary>
508 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent 449 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
509 /// folders) is given. 450 /// folders) is given.
@@ -573,7 +514,9 @@ namespace OpenSim.Region.Framework.Scenes
573 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}", 514 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
574 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName); 515 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
575 516
576 InventoryItemBase item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(oldItemID); 517 InventoryItemBase item = null;
518 if (LibraryService != null && LibraryService.LibraryRootFolder != null)
519 item = LibraryService.LibraryRootFolder.FindItem(oldItemID);
577 520
578 if (item == null) 521 if (item == null)
579 { 522 {
@@ -627,15 +570,9 @@ namespace OpenSim.Region.Framework.Scenes
627 /// <summary> 570 /// <summary>
628 /// Create a new asset data structure. 571 /// Create a new asset data structure.
629 /// </summary> 572 /// </summary>
630 /// <param name="name"></param> 573 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, UUID creatorID)
631 /// <param name="description"></param>
632 /// <param name="invType"></param>
633 /// <param name="assetType"></param>
634 /// <param name="data"></param>
635 /// <returns></returns>
636 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
637 { 574 {
638 AssetBase asset = new AssetBase(UUID.Random(), name, assetType); 575 AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID.ToString());
639 asset.Description = description; 576 asset.Description = description;
640 asset.Data = (data == null) ? new byte[1] : data; 577 asset.Data = (data == null) ? new byte[1] : data;
641 578
@@ -745,13 +682,9 @@ namespace OpenSim.Region.Framework.Scenes
745 682
746 if (transactionID == UUID.Zero) 683 if (transactionID == UUID.Zero)
747 { 684 {
748 CachedUserInfo userInfo 685 ScenePresence presence;
749 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 686 if (TryGetAvatar(remoteClient.AgentId, out presence))
750
751 if (userInfo != null)
752 { 687 {
753 ScenePresence presence;
754 TryGetAvatar(remoteClient.AgentId, out presence);
755 byte[] data = null; 688 byte[] data = null;
756 689
757 if (invType == (sbyte)InventoryType.Landmark && presence != null) 690 if (invType == (sbyte)InventoryType.Landmark && presence != null)
@@ -765,7 +698,7 @@ namespace OpenSim.Region.Framework.Scenes
765 data = Encoding.ASCII.GetBytes(strdata); 698 data = Encoding.ASCII.GetBytes(strdata);
766 } 699 }
767 700
768 AssetBase asset = CreateAsset(name, description, assetType, data); 701 AssetBase asset = CreateAsset(name, description, assetType, data, remoteClient.AgentId);
769 AssetService.Store(asset); 702 AssetService.Store(asset);
770 703
771 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate); 704 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate);
@@ -773,7 +706,7 @@ namespace OpenSim.Region.Framework.Scenes
773 else 706 else
774 { 707 {
775 m_log.ErrorFormat( 708 m_log.ErrorFormat(
776 "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem", 709 "ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
777 remoteClient.AgentId); 710 remoteClient.AgentId);
778 } 711 }
779 } 712 }
@@ -1170,15 +1103,21 @@ namespace OpenSim.Region.Framework.Scenes
1170 1103
1171 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems) 1104 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
1172 { 1105 {
1106 if (folder == null)
1107 return;
1108
1173 m_log.DebugFormat("[AGENT INVENTORY]: Send Inventory Folder {0} Update to {1} {2}", folder.Name, client.FirstName, client.LastName); 1109 m_log.DebugFormat("[AGENT INVENTORY]: Send Inventory Folder {0} Update to {1} {2}", folder.Name, client.FirstName, client.LastName);
1174 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID); 1110 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
1175 InventoryFolderBase containingFolder = new InventoryFolderBase(); 1111 InventoryFolderBase containingFolder = new InventoryFolderBase();
1176 containingFolder.ID = folder.ID; 1112 containingFolder.ID = folder.ID;
1177 containingFolder.Owner = client.AgentId; 1113 containingFolder.Owner = client.AgentId;
1178 containingFolder = InventoryService.GetFolder(containingFolder); 1114 containingFolder = InventoryService.GetFolder(containingFolder);
1179 int version = containingFolder.Version; 1115 if (containingFolder != null)
1116 {
1117 int version = containingFolder.Version;
1180 1118
1181 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, version, fetchFolders, fetchItems); 1119 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, version, fetchFolders, fetchItems);
1120 }
1182 } 1121 }
1183 1122
1184 /// <summary> 1123 /// <summary>
@@ -1220,9 +1159,9 @@ namespace OpenSim.Region.Framework.Scenes
1220 item = InventoryService.GetItem(item); 1159 item = InventoryService.GetItem(item);
1221 1160
1222 // Try library 1161 // Try library
1223 if (null == item) 1162 if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
1224 { 1163 {
1225 item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID); 1164 item = LibraryService.LibraryRootFolder.FindItem(itemID);
1226 } 1165 }
1227 1166
1228 if (item != null) 1167 if (item != null)
@@ -1289,9 +1228,9 @@ namespace OpenSim.Region.Framework.Scenes
1289 1228
1290 // Try library 1229 // Try library
1291 // XXX clumsy, possibly should be one call 1230 // XXX clumsy, possibly should be one call
1292 if (null == item) 1231 if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
1293 { 1232 {
1294 item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID); 1233 item = LibraryService.LibraryRootFolder.FindItem(itemID);
1295 } 1234 }
1296 1235
1297 if (item != null) 1236 if (item != null)
@@ -1348,7 +1287,9 @@ namespace OpenSim.Region.Framework.Scenes
1348 itemBase.InvType, part.UUID, remoteClient.AgentId)) 1287 itemBase.InvType, part.UUID, remoteClient.AgentId))
1349 return; 1288 return;
1350 1289
1351 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}")); 1290 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
1291 Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
1292 remoteClient.AgentId);
1352 AssetService.Store(asset); 1293 AssetService.Store(asset);
1353 1294
1354 TaskInventoryItem taskItem = new TaskInventoryItem(); 1295 TaskInventoryItem taskItem = new TaskInventoryItem();
@@ -1616,237 +1557,6 @@ namespace OpenSim.Region.Framework.Scenes
1616 } 1557 }
1617 } 1558 }
1618 1559
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) 1560 public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID)
1851 { 1561 {
1852 SceneObjectGroup objectGroup = grp; 1562 SceneObjectGroup objectGroup = grp;
@@ -1873,7 +1583,8 @@ namespace OpenSim.Region.Framework.Scenes
1873 objectGroup.GetPartName(objectGroup.LocalId), 1583 objectGroup.GetPartName(objectGroup.LocalId),
1874 objectGroup.GetPartDescription(objectGroup.LocalId), 1584 objectGroup.GetPartDescription(objectGroup.LocalId),
1875 (sbyte)AssetType.Object, 1585 (sbyte)AssetType.Object,
1876 Utils.StringToBytes(sceneObjectXml)); 1586 Utils.StringToBytes(sceneObjectXml),
1587 remoteClient.AgentId);
1877 AssetService.Store(asset); 1588 AssetService.Store(asset);
1878 1589
1879 item.AssetID = asset.FullID; 1590 item.AssetID = asset.FullID;
@@ -1920,7 +1631,8 @@ namespace OpenSim.Region.Framework.Scenes
1920 grp.GetPartName(grp.LocalId), 1631 grp.GetPartName(grp.LocalId),
1921 grp.GetPartDescription(grp.LocalId), 1632 grp.GetPartDescription(grp.LocalId),
1922 (sbyte)AssetType.Object, 1633 (sbyte)AssetType.Object,
1923 Utils.StringToBytes(sceneObjectXml)); 1634 Utils.StringToBytes(sceneObjectXml),
1635 remoteClient.AgentId);
1924 AssetService.Store(asset); 1636 AssetService.Store(asset);
1925 1637
1926 InventoryItemBase item = new InventoryItemBase(); 1638 InventoryItemBase item = new InventoryItemBase();
@@ -1987,225 +1699,11 @@ namespace OpenSim.Region.Framework.Scenes
1987 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, 1699 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
1988 bool RezSelected, bool RemoveItem, UUID fromTaskID) 1700 bool RezSelected, bool RemoveItem, UUID fromTaskID)
1989 { 1701 {
1990 RezObject( 1702 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
1991 remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, 1703 if (invAccess != null)
1992 RezSelected, RemoveItem, fromTaskID, false); 1704 invAccess.RezObject(
1993 } 1705 remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
1994 1706 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 } 1707 }
2210 1708
2211 /// <summary> 1709 /// <summary>
@@ -2348,35 +1846,27 @@ namespace OpenSim.Region.Framework.Scenes
2348 EventManager.TriggerOnAttach(localID, itemID, avatarID); 1846 EventManager.TriggerOnAttach(localID, itemID, avatarID);
2349 } 1847 }
2350 1848
2351 public UUID RezSingleAttachment(IClientAPI remoteClient, UUID itemID, 1849 /// <summary>
2352 uint AttachmentPt) 1850 /// Called when the client receives a request to rez a single attachment on to the avatar from inventory
1851 /// (RezSingleAttachmentFromInv packet).
1852 /// </summary>
1853 /// <param name="remoteClient"></param>
1854 /// <param name="itemID"></param>
1855 /// <param name="AttachmentPt"></param>
1856 /// <returns></returns>
1857 public UUID RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
2353 { 1858 {
1859 m_log.DebugFormat("[USER INVENTORY]: Rezzing single attachment from item {0} for {1}", itemID, remoteClient.Name);
1860
2354 SceneObjectGroup att = m_sceneGraph.RezSingleAttachment(remoteClient, itemID, AttachmentPt); 1861 SceneObjectGroup att = m_sceneGraph.RezSingleAttachment(remoteClient, itemID, AttachmentPt);
2355 1862
2356 if (att == null) 1863 if (att == null)
2357 { 1864 {
2358 DetachSingleAttachmentToInv(itemID, remoteClient); 1865 AttachmentsModule.ShowDetachInUserInventory(itemID, remoteClient);
2359 return UUID.Zero; 1866 return UUID.Zero;
2360 } 1867 }
2361 1868
2362 return RezSingleAttachment(att, remoteClient, itemID, AttachmentPt); 1869 return AttachmentsModule.SetAttachmentInventoryStatus(att, remoteClient, itemID, AttachmentPt);
2363 }
2364
2365 public UUID RezSingleAttachment(SceneObjectGroup att,
2366 IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
2367 {
2368 if (!att.IsDeleted)
2369 AttachmentPt = att.RootPart.AttachmentPoint;
2370
2371 ScenePresence presence;
2372 if (TryGetAvatar(remoteClient.AgentId, out presence))
2373 {
2374 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2375 item = InventoryService.GetItem(item);
2376
2377 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
2378 }
2379 return att.UUID;
2380 } 1870 }
2381 1871
2382 public void RezMultipleAttachments(IClientAPI remoteClient, RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header, 1872 public void RezMultipleAttachments(IClientAPI remoteClient, RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
@@ -2388,57 +1878,6 @@ namespace OpenSim.Region.Framework.Scenes
2388 } 1878 }
2389 } 1879 }
2390 1880
2391 /// <summary>
2392 /// Attach an object.
2393 /// </summary>
2394 /// <param name="controllingClient"></param>
2395 /// <param name="localID"></param>
2396 /// <param name="attachPoint"></param>
2397 /// <param name="rot"></param>
2398 /// <param name="pos"></param>
2399 /// <param name="silent"></param>
2400 /// <returns>true if the object was successfully attached, false otherwise</returns>
2401 public bool AttachObject(IClientAPI controllingClient, uint localID, uint attachPoint, Quaternion rot, Vector3 pos, bool silent)
2402 {
2403 return m_sceneGraph.AttachObject(controllingClient, localID, attachPoint, rot, pos, silent);
2404 }
2405
2406 public void AttachObject(IClientAPI remoteClient, uint AttachmentPt, UUID itemID, SceneObjectGroup att)
2407 {
2408 if (UUID.Zero == itemID)
2409 {
2410 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error inventory item ID.");
2411 return;
2412 }
2413
2414 if (0 == AttachmentPt)
2415 {
2416 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error attachment point.");
2417 return;
2418 }
2419
2420 if (null == att.RootPart)
2421 {
2422 m_log.Error("[SCENE INVENTORY]: Unable to save attachment for a prim without the rootpart!");
2423 return;
2424 }
2425
2426 ScenePresence presence;
2427 if (TryGetAvatar(remoteClient.AgentId, out presence))
2428 {
2429 // XXYY!!
2430 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2431 item = InventoryService.GetItem(item);
2432 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
2433
2434 if (m_AvatarFactory != null)
2435 {
2436 m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2437 }
2438
2439 }
2440 }
2441
2442 public void DetachSingleAttachmentToGround(UUID itemID, IClientAPI remoteClient) 1881 public void DetachSingleAttachmentToGround(UUID itemID, IClientAPI remoteClient)
2443 { 1882 {
2444 SceneObjectPart part = GetSceneObjectPart(itemID); 1883 SceneObjectPart part = GetSceneObjectPart(itemID);
@@ -2469,24 +1908,6 @@ namespace OpenSim.Region.Framework.Scenes
2469 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero); 1908 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero);
2470 } 1909 }
2471 1910
2472 public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
2473 {
2474 ScenePresence presence;
2475 if (TryGetAvatar(remoteClient.AgentId, out presence))
2476 {
2477 presence.Appearance.DetachAttachment(itemID);
2478
2479 // Save avatar attachment information
2480 if (m_AvatarFactory != null)
2481 {
2482 m_log.Info("[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", ItemID: " + itemID);
2483 m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2484 }
2485 }
2486
2487 m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient);
2488 }
2489
2490 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) 1911 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
2491 { 1912 {
2492 EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID); 1913 EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
@@ -2518,6 +1939,7 @@ namespace OpenSim.Region.Framework.Scenes
2518 { 1939 {
2519 sog.SetOwnerId(ownerID); 1940 sog.SetOwnerId(ownerID);
2520 sog.SetGroup(groupID, remoteClient); 1941 sog.SetGroup(groupID, remoteClient);
1942 sog.ScheduleGroupForFullUpdate();
2521 1943
2522 foreach (SceneObjectPart child in sog.Children.Values) 1944 foreach (SceneObjectPart child in sog.Children.Values)
2523 child.Inventory.ChangeInventoryOwner(ownerID); 1945 child.Inventory.ChangeInventoryOwner(ownerID);
@@ -2539,6 +1961,7 @@ namespace OpenSim.Region.Framework.Scenes
2539 sog.SetOwnerId(groupID); 1961 sog.SetOwnerId(groupID);
2540 sog.ApplyNextOwnerPermissions(); 1962 sog.ApplyNextOwnerPermissions();
2541 } 1963 }
1964
2542 } 1965 }
2543 1966
2544 foreach (uint localID in localIDs) 1967 foreach (uint localID in localIDs)
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 ab0d397..d5d1825 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;
@@ -141,7 +141,6 @@ namespace OpenSim.Region.Framework.Scenes
141 protected ModuleLoader m_moduleLoader; 141 protected ModuleLoader m_moduleLoader;
142 protected StorageManager m_storageManager; 142 protected StorageManager m_storageManager;
143 protected AgentCircuitManager m_authenticateHandler; 143 protected AgentCircuitManager m_authenticateHandler;
144 public CommunicationsManager CommsManager;
145 144
146 protected SceneCommunicationService m_sceneGridService; 145 protected SceneCommunicationService m_sceneGridService;
147 public bool LoginsDisabled = true; 146 public bool LoginsDisabled = true;
@@ -189,11 +188,11 @@ namespace OpenSim.Region.Framework.Scenes
189 { 188 {
190 m_AuthorizationService = RequestModuleInterface<IAuthorizationService>(); 189 m_AuthorizationService = RequestModuleInterface<IAuthorizationService>();
191 190
192 if (m_AuthorizationService == null) 191 //if (m_AuthorizationService == null)
193 { 192 //{
194 // don't throw an exception if no authorization service is set for the time being 193 // // don't throw an exception if no authorization service is set for the time being
195 m_log.InfoFormat("[SCENE]: No Authorization service is configured"); 194 // m_log.InfoFormat("[SCENE]: No Authorization service is configured");
196 } 195 //}
197 } 196 }
198 197
199 return m_AuthorizationService; 198 return m_AuthorizationService;
@@ -240,8 +239,76 @@ namespace OpenSim.Region.Framework.Scenes
240 } 239 }
241 } 240 }
242 241
242 protected ILibraryService m_LibraryService;
243
244 public ILibraryService LibraryService
245 {
246 get
247 {
248 if (m_LibraryService == null)
249 m_LibraryService = RequestModuleInterface<ILibraryService>();
250
251 return m_LibraryService;
252 }
253 }
254
255 protected ISimulationService m_simulationService;
256 public ISimulationService SimulationService
257 {
258 get
259 {
260 if (m_simulationService == null)
261 m_simulationService = RequestModuleInterface<ISimulationService>();
262 return m_simulationService;
263 }
264 }
265
266 protected IAuthenticationService m_AuthenticationService;
267 public IAuthenticationService AuthenticationService
268 {
269 get
270 {
271 if (m_AuthenticationService == null)
272 m_AuthenticationService = RequestModuleInterface<IAuthenticationService>();
273 return m_AuthenticationService;
274 }
275 }
276
277 protected IPresenceService m_PresenceService;
278 public IPresenceService PresenceService
279 {
280 get
281 {
282 if (m_PresenceService == null)
283 m_PresenceService = RequestModuleInterface<IPresenceService>();
284 return m_PresenceService;
285 }
286 }
287 protected IUserAccountService m_UserAccountService;
288 public IUserAccountService UserAccountService
289 {
290 get
291 {
292 if (m_UserAccountService == null)
293 m_UserAccountService = RequestModuleInterface<IUserAccountService>();
294 return m_UserAccountService;
295 }
296 }
297
298 protected OpenSim.Services.Interfaces.IAvatarService m_AvatarService;
299 public OpenSim.Services.Interfaces.IAvatarService AvatarService
300 {
301 get
302 {
303 if (m_AvatarService == null)
304 m_AvatarService = RequestModuleInterface<IAvatarService>();
305 return m_AvatarService;
306 }
307 }
308
243 protected IXMLRPC m_xmlrpcModule; 309 protected IXMLRPC m_xmlrpcModule;
244 protected IWorldComm m_worldCommModule; 310 protected IWorldComm m_worldCommModule;
311 public IAttachmentsModule AttachmentsModule { get; set; }
245 protected IAvatarFactory m_AvatarFactory; 312 protected IAvatarFactory m_AvatarFactory;
246 public IAvatarFactory AvatarFactory 313 public IAvatarFactory AvatarFactory
247 { 314 {
@@ -249,10 +316,8 @@ namespace OpenSim.Region.Framework.Scenes
249 } 316 }
250 protected IConfigSource m_config; 317 protected IConfigSource m_config;
251 protected IRegionSerialiserModule m_serialiser; 318 protected IRegionSerialiserModule m_serialiser;
252 protected IInterregionCommsOut m_interregionCommsOut;
253 protected IInterregionCommsIn m_interregionCommsIn;
254 protected IDialogModule m_dialogModule; 319 protected IDialogModule m_dialogModule;
255 protected ITeleportModule m_teleportModule; 320 protected IEntityTransferModule m_teleportModule;
256 321
257 protected ICapabilitiesModule m_capsModule; 322 protected ICapabilitiesModule m_capsModule;
258 public ICapabilitiesModule CapsModule 323 public ICapabilitiesModule CapsModule
@@ -483,7 +548,7 @@ namespace OpenSim.Region.Framework.Scenes
483 #region Constructors 548 #region Constructors
484 549
485 public Scene(RegionInfo regInfo, AgentCircuitManager authen, 550 public Scene(RegionInfo regInfo, AgentCircuitManager authen,
486 CommunicationsManager commsMan, SceneCommunicationService sceneGridService, 551 SceneCommunicationService sceneGridService,
487 StorageManager storeManager, 552 StorageManager storeManager,
488 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim, 553 ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim,
489 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion) 554 bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
@@ -519,7 +584,6 @@ namespace OpenSim.Region.Framework.Scenes
519 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4); 584 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4);
520 m_moduleLoader = moduleLoader; 585 m_moduleLoader = moduleLoader;
521 m_authenticateHandler = authen; 586 m_authenticateHandler = authen;
522 CommsManager = commsMan;
523 m_sceneGridService = sceneGridService; 587 m_sceneGridService = sceneGridService;
524 m_storageManager = storeManager; 588 m_storageManager = storeManager;
525 m_regInfo = regInfo; 589 m_regInfo = regInfo;
@@ -778,6 +842,36 @@ namespace OpenSim.Region.Framework.Scenes
778 return m_simulatorVersion; 842 return m_simulatorVersion;
779 } 843 }
780 844
845 public string[] GetUserNames(UUID uuid)
846 {
847 string[] returnstring = new string[0];
848
849 UserAccount account = UserAccountService.GetUserAccount(RegionInfo.ScopeID, uuid);
850
851 if (account != null)
852 {
853 returnstring = new string[2];
854 returnstring[0] = account.FirstName;
855 returnstring[1] = account.LastName;
856 }
857
858 return returnstring;
859 }
860
861 public string GetUserName(UUID uuid)
862 {
863 string[] names = GetUserNames(uuid);
864 if (names.Length == 2)
865 {
866 string firstname = names[0];
867 string lastname = names[1];
868
869 return firstname + " " + lastname;
870
871 }
872 return "(hippos)";
873 }
874
781 /// <summary> 875 /// <summary>
782 /// Another region is up. 876 /// Another region is up.
783 /// 877 ///
@@ -811,7 +905,7 @@ namespace OpenSim.Region.Framework.Scenes
811 regInfo.RegionName = otherRegion.RegionName; 905 regInfo.RegionName = otherRegion.RegionName;
812 regInfo.ScopeID = otherRegion.ScopeID; 906 regInfo.ScopeID = otherRegion.ScopeID;
813 regInfo.ExternalHostName = otherRegion.ExternalHostName; 907 regInfo.ExternalHostName = otherRegion.ExternalHostName;
814 908 GridRegion r = new GridRegion(regInfo);
815 try 909 try
816 { 910 {
817 ForEachScenePresence(delegate(ScenePresence agent) 911 ForEachScenePresence(delegate(ScenePresence agent)
@@ -825,7 +919,8 @@ namespace OpenSim.Region.Framework.Scenes
825 List<ulong> old = new List<ulong>(); 919 List<ulong> old = new List<ulong>();
826 old.Add(otherRegion.RegionHandle); 920 old.Add(otherRegion.RegionHandle);
827 agent.DropOldNeighbours(old); 921 agent.DropOldNeighbours(old);
828 InformClientOfNeighbor(agent, regInfo); 922 if (m_teleportModule != null)
923 m_teleportModule.EnableChildAgent(agent, r);
829 } 924 }
830 } 925 }
831 ); 926 );
@@ -985,6 +1080,7 @@ namespace OpenSim.Region.Framework.Scenes
985 { 1080 {
986 foreach (RegionInfo region in m_regionRestartNotifyList) 1081 foreach (RegionInfo region in m_regionRestartNotifyList)
987 { 1082 {
1083 GridRegion r = new GridRegion(region);
988 try 1084 try
989 { 1085 {
990 ForEachScenePresence(delegate(ScenePresence agent) 1086 ForEachScenePresence(delegate(ScenePresence agent)
@@ -992,9 +1088,8 @@ namespace OpenSim.Region.Framework.Scenes
992 // If agent is a root agent. 1088 // If agent is a root agent.
993 if (!agent.IsChildAgent) 1089 if (!agent.IsChildAgent)
994 { 1090 {
995 //agent.ControllingClient.new 1091 if (m_teleportModule != null)
996 //this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); 1092 m_teleportModule.EnableChildAgent(agent, r);
997 InformClientOfNeighbor(agent, region);
998 } 1093 }
999 } 1094 }
1000 ); 1095 );
@@ -1053,10 +1148,7 @@ namespace OpenSim.Region.Framework.Scenes
1053 1148
1054 public int GetInaccurateNeighborCount() 1149 public int GetInaccurateNeighborCount()
1055 { 1150 {
1056 lock (m_neighbours) 1151 return m_neighbours.Count;
1057 {
1058 return m_neighbours.Count;
1059 }
1060 } 1152 }
1061 1153
1062 // This is the method that shuts down the scene. 1154 // This is the method that shuts down the scene.
@@ -1136,12 +1228,11 @@ namespace OpenSim.Region.Framework.Scenes
1136 m_worldCommModule = RequestModuleInterface<IWorldComm>(); 1228 m_worldCommModule = RequestModuleInterface<IWorldComm>();
1137 XferManager = RequestModuleInterface<IXfer>(); 1229 XferManager = RequestModuleInterface<IXfer>();
1138 m_AvatarFactory = RequestModuleInterface<IAvatarFactory>(); 1230 m_AvatarFactory = RequestModuleInterface<IAvatarFactory>();
1231 AttachmentsModule = RequestModuleInterface<IAttachmentsModule>();
1139 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>(); 1232 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>();
1140 m_interregionCommsOut = RequestModuleInterface<IInterregionCommsOut>();
1141 m_interregionCommsIn = RequestModuleInterface<IInterregionCommsIn>();
1142 m_dialogModule = RequestModuleInterface<IDialogModule>(); 1233 m_dialogModule = RequestModuleInterface<IDialogModule>();
1143 m_capsModule = RequestModuleInterface<ICapabilitiesModule>(); 1234 m_capsModule = RequestModuleInterface<ICapabilitiesModule>();
1144 m_teleportModule = RequestModuleInterface<ITeleportModule>(); 1235 m_teleportModule = RequestModuleInterface<IEntityTransferModule>();
1145 } 1236 }
1146 1237
1147 #endregion 1238 #endregion
@@ -1591,7 +1682,9 @@ namespace OpenSim.Region.Framework.Scenes
1591 GridRegion region = new GridRegion(RegionInfo); 1682 GridRegion region = new GridRegion(RegionInfo);
1592 string error = GridService.RegisterRegion(RegionInfo.ScopeID, region); 1683 string error = GridService.RegisterRegion(RegionInfo.ScopeID, region);
1593 if (error != String.Empty) 1684 if (error != String.Empty)
1685 {
1594 throw new Exception(error); 1686 throw new Exception(error);
1687 }
1595 1688
1596 m_sceneGridService.SetScene(this); 1689 m_sceneGridService.SetScene(this);
1597 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo); 1690 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo);
@@ -1840,14 +1933,22 @@ namespace OpenSim.Region.Framework.Scenes
1840 //m_log.DebugFormat( 1933 //m_log.DebugFormat(
1841 // "[SCENE]: Scene.AddNewPrim() pcode {0} called for {1} in {2}", shape.PCode, ownerID, RegionInfo.RegionName); 1934 // "[SCENE]: Scene.AddNewPrim() pcode {0} called for {1} in {2}", shape.PCode, ownerID, RegionInfo.RegionName);
1842 1935
1936 SceneObjectGroup sceneObject = null;
1937
1843 // If an entity creator has been registered for this prim type then use that 1938 // If an entity creator has been registered for this prim type then use that
1844 if (m_entityCreators.ContainsKey((PCode)shape.PCode)) 1939 if (m_entityCreators.ContainsKey((PCode)shape.PCode))
1845 return m_entityCreators[(PCode)shape.PCode].CreateEntity(ownerID, groupID, pos, rot, shape); 1940 {
1941 sceneObject = m_entityCreators[(PCode)shape.PCode].CreateEntity(ownerID, groupID, pos, rot, shape);
1942 }
1943 else
1944 {
1945 // Otherwise, use this default creation code;
1946 sceneObject = new SceneObjectGroup(ownerID, pos, rot, shape);
1947 AddNewSceneObject(sceneObject, true);
1948 sceneObject.SetGroup(groupID, null);
1949 }
1846 1950
1847 // Otherwise, use this default creation code; 1951 sceneObject.ScheduleGroupForFullUpdate();
1848 SceneObjectGroup sceneObject = new SceneObjectGroup(ownerID, pos, rot, shape);
1849 AddNewSceneObject(sceneObject, true);
1850 sceneObject.SetGroup(groupID, null);
1851 1952
1852 return sceneObject; 1953 return sceneObject;
1853 } 1954 }
@@ -1875,7 +1976,7 @@ namespace OpenSim.Region.Framework.Scenes
1875 } 1976 }
1876 1977
1877 /// <summary> 1978 /// <summary>
1878 /// Add a newly created object to the scene 1979 /// Add a newly created object to the scene. Updates are also sent to viewers.
1879 /// </summary> 1980 /// </summary>
1880 /// <param name="sceneObject"></param> 1981 /// <param name="sceneObject"></param>
1881 /// <param name="attachToBackup"> 1982 /// <param name="attachToBackup">
@@ -1884,8 +1985,25 @@ namespace OpenSim.Region.Framework.Scenes
1884 /// </param> 1985 /// </param>
1885 public bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup) 1986 public bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup)
1886 { 1987 {
1887 return m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup); 1988 return AddNewSceneObject(sceneObject, attachToBackup, true);
1888 } 1989 }
1990
1991 /// <summary>
1992 /// Add a newly created object to the scene
1993 /// </summary>
1994 /// <param name="sceneObject"></param>
1995 /// <param name="attachToBackup">
1996 /// If true, the object is made persistent into the scene.
1997 /// If false, the object will not persist over server restarts
1998 /// </param>
1999 /// <param name="sendClientUpdates">
2000 /// If true, updates for the new scene object are sent to all viewers in range.
2001 /// If false, it is left to the caller to schedule the update
2002 /// </param>
2003 public bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
2004 {
2005 return m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, sendClientUpdates);
2006 }
1889 2007
1890 /// <summary> 2008 /// <summary>
1891 /// Delete every object from the scene 2009 /// Delete every object from the scene
@@ -1978,7 +2096,6 @@ namespace OpenSim.Region.Framework.Scenes
1978 /// Move the given scene object into a new region depending on which region its absolute position has moved 2096 /// Move the given scene object into a new region depending on which region its absolute position has moved
1979 /// into. 2097 /// into.
1980 /// 2098 ///
1981 /// This method locates the new region handle and offsets the prim position for the new region
1982 /// </summary> 2099 /// </summary>
1983 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param> 2100 /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
1984 /// <param name="grp">the scene object that we're crossing</param> 2101 /// <param name="grp">the scene object that we're crossing</param>
@@ -2020,191 +2137,8 @@ namespace OpenSim.Region.Framework.Scenes
2020 return; 2137 return;
2021 } 2138 }
2022 2139
2023 int thisx = (int)RegionInfo.RegionLocX; 2140 if (m_teleportModule != null)
2024 int thisy = (int)RegionInfo.RegionLocY; 2141 m_teleportModule.Cross(grp, attemptedPosition, silent);
2025 Vector3 EastCross = new Vector3(0.1f,0,0);
2026 Vector3 WestCross = new Vector3(-0.1f, 0, 0);
2027 Vector3 NorthCross = new Vector3(0, 0.1f, 0);
2028 Vector3 SouthCross = new Vector3(0, -0.1f, 0);
2029
2030
2031 // use this if no borders were crossed!
2032 ulong newRegionHandle
2033 = Util.UIntsToLong((uint)((thisx) * Constants.RegionSize),
2034 (uint)((thisy) * Constants.RegionSize));
2035
2036 Vector3 pos = attemptedPosition;
2037
2038 int changeX = 1;
2039 int changeY = 1;
2040
2041 if (TestBorderCross(attemptedPosition + WestCross, Cardinals.W))
2042 {
2043 if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2044 {
2045
2046 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2047
2048 if (crossedBorderx.BorderLine.Z > 0)
2049 {
2050 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2051 changeX = (int)(crossedBorderx.BorderLine.Z /(int) Constants.RegionSize);
2052 }
2053 else
2054 pos.X = ((pos.X + Constants.RegionSize));
2055
2056 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2057 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2058
2059 if (crossedBordery.BorderLine.Z > 0)
2060 {
2061 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2062 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2063 }
2064 else
2065 pos.Y = ((pos.Y + Constants.RegionSize));
2066
2067
2068
2069 newRegionHandle
2070 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2071 (uint)((thisy - changeY) * Constants.RegionSize));
2072 // x - 1
2073 // y - 1
2074 }
2075 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2076 {
2077 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2078
2079 if (crossedBorderx.BorderLine.Z > 0)
2080 {
2081 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2082 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2083 }
2084 else
2085 pos.X = ((pos.X + Constants.RegionSize));
2086
2087
2088 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2089 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2090
2091 try
2092 {
2093 if (crossedBordery.BorderLine.Z > 0)
2094 {
2095 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2096 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2097 }
2098 else
2099 pos.Y = ((pos.Y + Constants.RegionSize));
2100
2101 newRegionHandle
2102 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2103 (uint)((thisy + changeY) * Constants.RegionSize));
2104 // x - 1
2105 // y + 1
2106 }
2107 catch (Exception ex)
2108 {
2109 }
2110 }
2111 else
2112 {
2113 Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
2114
2115 if (crossedBorderx.BorderLine.Z > 0)
2116 {
2117 pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
2118 changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
2119 }
2120 else
2121 pos.X = ((pos.X + Constants.RegionSize));
2122
2123 newRegionHandle
2124 = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
2125 (uint) (thisy*Constants.RegionSize));
2126 // x - 1
2127 }
2128 }
2129 else if (TestBorderCross(attemptedPosition + EastCross, Cardinals.E))
2130 {
2131 if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2132 {
2133
2134 pos.X = ((pos.X - Constants.RegionSize));
2135 Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
2136 //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
2137
2138 if (crossedBordery.BorderLine.Z > 0)
2139 {
2140 pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
2141 changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
2142 }
2143 else
2144 pos.Y = ((pos.Y + Constants.RegionSize));
2145
2146
2147 newRegionHandle
2148 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2149 (uint)((thisy - changeY) * Constants.RegionSize));
2150 // x + 1
2151 // y - 1
2152 }
2153 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2154 {
2155 pos.X = ((pos.X - Constants.RegionSize));
2156 pos.Y = ((pos.Y - Constants.RegionSize));
2157 newRegionHandle
2158 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2159 (uint)((thisy + changeY) * Constants.RegionSize));
2160 // x + 1
2161 // y + 1
2162 }
2163 else
2164 {
2165 pos.X = ((pos.X - Constants.RegionSize));
2166 newRegionHandle
2167 = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
2168 (uint) (thisy*Constants.RegionSize));
2169 // x + 1
2170 }
2171 }
2172 else if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
2173 {
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 newRegionHandle
2186 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - changeY) * Constants.RegionSize));
2187 // y - 1
2188 }
2189 else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
2190 {
2191
2192 pos.Y = ((pos.Y - Constants.RegionSize));
2193 newRegionHandle
2194 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + changeY) * Constants.RegionSize));
2195 // y + 1
2196 }
2197
2198 // Offset the positions for the new region across the border
2199 Vector3 oldGroupPosition = grp.RootPart.GroupPosition;
2200 grp.OffsetForNewRegion(pos);
2201
2202 // If we fail to cross the border, then reset the position of the scene object on that border.
2203 if (!CrossPrimGroupIntoNewRegion(newRegionHandle, grp, silent))
2204 {
2205 grp.OffsetForNewRegion(oldGroupPosition);
2206 grp.ScheduleGroupForFullUpdate();
2207 }
2208 } 2142 }
2209 2143
2210 public Border GetCrossedBorder(Vector3 position, Cardinals gridline) 2144 public Border GetCrossedBorder(Vector3 position, Cardinals gridline)
@@ -2388,75 +2322,6 @@ namespace OpenSim.Region.Framework.Scenes
2388 2322
2389 2323
2390 /// <summary> 2324 /// <summary>
2391 /// Move the given scene object into a new region
2392 /// </summary>
2393 /// <param name="newRegionHandle"></param>
2394 /// <param name="grp">Scene Object Group that we're crossing</param>
2395 /// <returns>
2396 /// true if the crossing itself was successful, false on failure
2397 /// FIMXE: we still return true if the crossing object was not successfully deleted from the originating region
2398 /// </returns>
2399 public bool CrossPrimGroupIntoNewRegion(ulong newRegionHandle, SceneObjectGroup grp, bool silent)
2400 {
2401 //m_log.Debug(" >>> CrossPrimGroupIntoNewRegion <<<");
2402
2403 bool successYN = false;
2404 grp.RootPart.UpdateFlag = 0;
2405 //int primcrossingXMLmethod = 0;
2406
2407 if (newRegionHandle != 0)
2408 {
2409 //string objectState = grp.GetStateSnapshot();
2410
2411 //successYN
2412 // = m_sceneGridService.PrimCrossToNeighboringRegion(
2413 // newRegionHandle, grp.UUID, m_serialiser.SaveGroupToXml2(grp), primcrossingXMLmethod);
2414 //if (successYN && (objectState != "") && m_allowScriptCrossings)
2415 //{
2416 // successYN = m_sceneGridService.PrimCrossToNeighboringRegion(
2417 // newRegionHandle, grp.UUID, objectState, 100);
2418 //}
2419
2420 // And the new channel...
2421 if (m_interregionCommsOut != null)
2422 successYN = m_interregionCommsOut.SendCreateObject(newRegionHandle, grp, true);
2423
2424 if (successYN)
2425 {
2426 // We remove the object here
2427 try
2428 {
2429 DeleteSceneObject(grp, silent);
2430 }
2431 catch (Exception e)
2432 {
2433 m_log.ErrorFormat(
2434 "[INTERREGION]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
2435 grp, e);
2436 }
2437 }
2438 else
2439 {
2440 if (!grp.IsDeleted)
2441 {
2442 if (grp.RootPart.PhysActor != null)
2443 {
2444 grp.RootPart.PhysActor.CrossingFailure();
2445 }
2446 }
2447
2448 m_log.ErrorFormat("[INTERREGION]: Prim crossing failed for {0}", grp);
2449 }
2450 }
2451 else
2452 {
2453 m_log.Error("[INTERREGION]: region handle was unexpectedly 0 in Scene.CrossPrimGroupIntoNewRegion()");
2454 }
2455
2456 return successYN;
2457 }
2458
2459 /// <summary>
2460 /// Called when objects or attachments cross the border between regions. 2325 /// Called when objects or attachments cross the border between regions.
2461 /// </summary> 2326 /// </summary>
2462 /// <param name="sog"></param> 2327 /// <param name="sog"></param>
@@ -2528,6 +2393,9 @@ namespace OpenSim.Region.Framework.Scenes
2528 2393
2529 return false; 2394 return false;
2530 } 2395 }
2396
2397 sceneObject.SetScene(this);
2398
2531 // Force allocation of new LocalId 2399 // Force allocation of new LocalId
2532 // 2400 //
2533 foreach (SceneObjectPart p in sceneObject.Children.Values) 2401 foreach (SceneObjectPart p in sceneObject.Children.Values)
@@ -2564,9 +2432,11 @@ namespace OpenSim.Region.Framework.Scenes
2564 //grp.SetFromAssetID(grp.RootPart.LastOwnerID); 2432 //grp.SetFromAssetID(grp.RootPart.LastOwnerID);
2565 m_log.DebugFormat( 2433 m_log.DebugFormat(
2566 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition); 2434 "[ATTACHMENT]: Attach to avatar {0} at position {1}", sp.UUID, grp.AbsolutePosition);
2435
2436 if (AttachmentsModule != null)
2437 AttachmentsModule.AttachObject(
2438 sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition, false);
2567 2439
2568 AttachObject(
2569 sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition, false);
2570 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 2440 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2571 grp.SendGroupFullUpdate(); 2441 grp.SendGroupFullUpdate();
2572 } 2442 }
@@ -2606,6 +2476,8 @@ namespace OpenSim.Region.Framework.Scenes
2606 /// <param name="client"></param> 2476 /// <param name="client"></param>
2607 public override void AddNewClient(IClientAPI client) 2477 public override void AddNewClient(IClientAPI client)
2608 { 2478 {
2479 bool vialogin = false;
2480
2609 m_clientManager.Add(client); 2481 m_clientManager.Add(client);
2610 2482
2611 CheckHeartbeat(); 2483 CheckHeartbeat();
@@ -2640,23 +2512,48 @@ namespace OpenSim.Region.Framework.Scenes
2640 { 2512 {
2641 AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); 2513 AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode);
2642 2514
2643 m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); 2515 // Do the verification here
2644 /* 2516 System.Net.EndPoint ep = client.GetClientEP();
2645 string logMsg = string.Format("[SCENE]: Adding new {0} agent for {1} in {2}", 2517 if (aCircuit != null)
2646 ((aCircuit.child == true) ? "child" : "root"), client.Name, 2518 {
2647 RegionInfo.RegionName); 2519 if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0)
2648 2520 {
2649 m_log.Debug(logMsg); 2521 m_log.DebugFormat("[Scene]: Incoming client {0} {1} in region {2} via Login", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName);
2650 */ 2522 vialogin = true;
2523 IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>();
2524 if (userVerification != null && ep != null)
2525 {
2526 if (!userVerification.VerifyClient(aCircuit, ep.ToString()))
2527 {
2528 // uh-oh, this is fishy
2529 m_log.WarnFormat("[Scene]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.",
2530 client.AgentId, client.SessionId, ep.ToString());
2531 try
2532 {
2533 client.Close();
2534 }
2535 catch (Exception e)
2536 {
2537 m_log.DebugFormat("[Scene]: Exception while closing aborted client: {0}", e.StackTrace);
2538 }
2539 return;
2540 }
2541 else
2542 m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} returned true", aCircuit.firstname, aCircuit.lastname);
2543 }
2544 }
2545 }
2651 2546
2652 CommsManager.UserProfileCacheService.AddNewUser(client.AgentId); 2547 m_log.Debug("[Scene] Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName);
2653 2548
2654 ScenePresence sp = CreateAndAddScenePresence(client); 2549 ScenePresence sp = CreateAndAddScenePresence(client);
2550 if (aCircuit != null)
2551 sp.Appearance = aCircuit.Appearance;
2655 2552
2656 // HERE!!! Do the initial attachments right here 2553 // HERE!!! Do the initial attachments right here
2657 // first agent upon login is a root agent by design. 2554 // first agent upon login is a root agent by design.
2658 // All other AddNewClient calls find aCircuit.child to be true 2555 // All other AddNewClient calls find aCircuit.child to be true
2659 if (aCircuit == null || aCircuit.child == false) 2556 if (aCircuit == null || (aCircuit != null && aCircuit.child == false))
2660 { 2557 {
2661 sp.IsChildAgent = false; 2558 sp.IsChildAgent = false;
2662 Util.FireAndForget(delegate(object o) { sp.RezAttachments(); }); 2559 Util.FireAndForget(delegate(object o) { sp.RezAttachments(); });
@@ -2665,6 +2562,8 @@ namespace OpenSim.Region.Framework.Scenes
2665 2562
2666 m_LastLogin = Util.EnvironmentTickCount(); 2563 m_LastLogin = Util.EnvironmentTickCount();
2667 EventManager.TriggerOnNewClient(client); 2564 EventManager.TriggerOnNewClient(client);
2565 if (vialogin)
2566 EventManager.TriggerOnClientLogin(client);
2668 } 2567 }
2669 2568
2670 2569
@@ -2772,17 +2671,18 @@ namespace OpenSim.Region.Framework.Scenes
2772 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client) 2671 public virtual void SubscribeToClientAttachmentEvents(IClientAPI client)
2773 { 2672 {
2774 client.OnRezSingleAttachmentFromInv += RezSingleAttachment; 2673 client.OnRezSingleAttachmentFromInv += RezSingleAttachment;
2775 client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments; 2674 client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments;
2776 client.OnDetachAttachmentIntoInv += DetachSingleAttachmentToInv;
2777 client.OnObjectAttach += m_sceneGraph.AttachObject; 2675 client.OnObjectAttach += m_sceneGraph.AttachObject;
2778 client.OnObjectDetach += m_sceneGraph.DetachObject; 2676 client.OnObjectDetach += m_sceneGraph.DetachObject;
2677
2678 if (AttachmentsModule != null)
2679 client.OnDetachAttachmentIntoInv += AttachmentsModule.ShowDetachInUserInventory;
2779 } 2680 }
2780 2681
2781 public virtual void SubscribeToClientTeleportEvents(IClientAPI client) 2682 public virtual void SubscribeToClientTeleportEvents(IClientAPI client)
2782 { 2683 {
2783 client.OnTeleportLocationRequest += RequestTeleportLocation; 2684 client.OnTeleportLocationRequest += RequestTeleportLocation;
2784 client.OnTeleportLandmarkRequest += RequestTeleportLandmark; 2685 client.OnTeleportLandmarkRequest += RequestTeleportLandmark;
2785 client.OnTeleportHomeRequest += TeleportClientHome;
2786 } 2686 }
2787 2687
2788 public virtual void SubscribeToClientScriptEvents(IClientAPI client) 2688 public virtual void SubscribeToClientScriptEvents(IClientAPI client)
@@ -2802,7 +2702,7 @@ namespace OpenSim.Region.Framework.Scenes
2802 2702
2803 public virtual void SubscribeToClientGridEvents(IClientAPI client) 2703 public virtual void SubscribeToClientGridEvents(IClientAPI client)
2804 { 2704 {
2805 client.OnNameFromUUIDRequest += CommsManager.HandleUUIDNameRequest; 2705 client.OnNameFromUUIDRequest += HandleUUIDNameRequest;
2806 client.OnMoneyTransferRequest += ProcessMoneyTransferRequest; 2706 client.OnMoneyTransferRequest += ProcessMoneyTransferRequest;
2807 client.OnAvatarPickerRequest += ProcessAvatarPickerRequest; 2707 client.OnAvatarPickerRequest += ProcessAvatarPickerRequest;
2808 client.OnSetStartLocationRequest += SetHomeRezPoint; 2708 client.OnSetStartLocationRequest += SetHomeRezPoint;
@@ -2823,8 +2723,7 @@ namespace OpenSim.Region.Framework.Scenes
2823 } 2723 }
2824 2724
2825 protected virtual void UnsubscribeToClientEvents(IClientAPI client) 2725 protected virtual void UnsubscribeToClientEvents(IClientAPI client)
2826 { 2726 {
2827
2828 } 2727 }
2829 2728
2830 /// <summary> 2729 /// <summary>
@@ -2846,7 +2745,6 @@ namespace OpenSim.Region.Framework.Scenes
2846 2745
2847 UnSubscribeToClientNetworkEvents(client); 2746 UnSubscribeToClientNetworkEvents(client);
2848 2747
2849
2850 // EventManager.TriggerOnNewClient(client); 2748 // EventManager.TriggerOnNewClient(client);
2851 } 2749 }
2852 2750
@@ -2926,19 +2824,21 @@ namespace OpenSim.Region.Framework.Scenes
2926 } 2824 }
2927 2825
2928 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client) 2826 public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client)
2929 { 2827 {
2930 client.OnRezSingleAttachmentFromInv -= RezSingleAttachment;
2931 client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments; 2828 client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments;
2932 client.OnDetachAttachmentIntoInv -= DetachSingleAttachmentToInv; 2829 client.OnRezSingleAttachmentFromInv -= RezSingleAttachment;
2933 client.OnObjectAttach -= m_sceneGraph.AttachObject; 2830 client.OnObjectAttach -= m_sceneGraph.AttachObject;
2934 client.OnObjectDetach -= m_sceneGraph.DetachObject; 2831 client.OnObjectDetach -= m_sceneGraph.DetachObject;
2832
2833 if (AttachmentsModule != null)
2834 client.OnDetachAttachmentIntoInv -= AttachmentsModule.ShowDetachInUserInventory;
2935 } 2835 }
2936 2836
2937 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client) 2837 public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client)
2938 { 2838 {
2939 client.OnTeleportLocationRequest -= RequestTeleportLocation; 2839 client.OnTeleportLocationRequest -= RequestTeleportLocation;
2940 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark; 2840 client.OnTeleportLandmarkRequest -= RequestTeleportLandmark;
2941 client.OnTeleportHomeRequest -= TeleportClientHome; 2841 //client.OnTeleportHomeRequest -= TeleportClientHome;
2942 } 2842 }
2943 2843
2944 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client) 2844 public virtual void UnSubscribeToClientScriptEvents(IClientAPI client)
@@ -2958,7 +2858,7 @@ namespace OpenSim.Region.Framework.Scenes
2958 2858
2959 public virtual void UnSubscribeToClientGridEvents(IClientAPI client) 2859 public virtual void UnSubscribeToClientGridEvents(IClientAPI client)
2960 { 2860 {
2961 client.OnNameFromUUIDRequest -= CommsManager.HandleUUIDNameRequest; 2861 client.OnNameFromUUIDRequest -= HandleUUIDNameRequest;
2962 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest; 2862 client.OnMoneyTransferRequest -= ProcessMoneyTransferRequest;
2963 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest; 2863 client.OnAvatarPickerRequest -= ProcessAvatarPickerRequest;
2964 client.OnSetStartLocationRequest -= SetHomeRezPoint; 2864 client.OnSetStartLocationRequest -= SetHomeRezPoint;
@@ -2985,30 +2885,12 @@ namespace OpenSim.Region.Framework.Scenes
2985 /// <param name="client">The IClientAPI for the client</param> 2885 /// <param name="client">The IClientAPI for the client</param>
2986 public virtual void TeleportClientHome(UUID agentId, IClientAPI client) 2886 public virtual void TeleportClientHome(UUID agentId, IClientAPI client)
2987 { 2887 {
2988 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(agentId); 2888 if (m_teleportModule != null)
2989 if (UserProfile != null) 2889 m_teleportModule.TeleportHome(agentId, client);
2890 else
2990 { 2891 {
2991 GridRegion regionInfo = GridService.GetRegionByUUID(UUID.Zero, UserProfile.HomeRegionID); 2892 m_log.DebugFormat("[SCENE]: Unable to teleport user home: no AgentTransferModule is active");
2992 if (regionInfo == null) 2893 client.SendTeleportFailed("Unable to perform teleports on this simulator.");
2993 {
2994 uint x = 0, y = 0;
2995 Utils.LongToUInts(UserProfile.HomeRegion, out x, out y);
2996 regionInfo = GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
2997 if (regionInfo != null) // home region can be away temporarily, too
2998 {
2999 UserProfile.HomeRegionID = regionInfo.RegionID;
3000 CommsManager.UserService.UpdateUserProfile(UserProfile);
3001 }
3002 }
3003 if (regionInfo == null)
3004 {
3005 // can't find the Home region: Tell viewer and abort
3006 client.SendTeleportFailed("Your home-region could not be found.");
3007 return;
3008 }
3009 RequestTeleportLocation(
3010 client, regionInfo.RegionHandle, UserProfile.HomeLocation, UserProfile.HomeLookAt,
3011 (uint)(TPFlags.SetLastToTarget | TPFlags.ViaHome));
3012 } 2894 }
3013 } 2895 }
3014 2896
@@ -3099,7 +2981,7 @@ namespace OpenSim.Region.Framework.Scenes
3099 } 2981 }
3100 2982
3101 /// <summary> 2983 /// <summary>
3102 /// Sets the Home Point. The GridService uses this to know where to put a user when they log-in 2984 /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
3103 /// </summary> 2985 /// </summary>
3104 /// <param name="remoteClient"></param> 2986 /// <param name="remoteClient"></param>
3105 /// <param name="regionHandle"></param> 2987 /// <param name="regionHandle"></param>
@@ -3108,27 +2990,11 @@ namespace OpenSim.Region.Framework.Scenes
3108 /// <param name="flags"></param> 2990 /// <param name="flags"></param>
3109 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 2991 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3110 { 2992 {
3111 UserProfileData UserProfile = CommsManager.UserService.GetUserProfile(remoteClient.AgentId); 2993 if (PresenceService.SetHomeLocation(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3112 if (UserProfile != null)
3113 {
3114 // I know I'm ignoring the regionHandle provided by the teleport location request.
3115 // reusing the TeleportLocationRequest delegate, so regionHandle isn't valid
3116 UserProfile.HomeRegionID = RegionInfo.RegionID;
3117 // TODO: The next line can be removed, as soon as only homeRegionID based UserServers are around.
3118 // TODO: The HomeRegion property can be removed then, too
3119 UserProfile.HomeRegion = RegionInfo.RegionHandle;
3120
3121 UserProfile.HomeLocation = position;
3122 UserProfile.HomeLookAt = lookAt;
3123 CommsManager.UserService.UpdateUserProfile(UserProfile);
3124
3125 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 2994 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3126 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 2995 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
3127 }
3128 else 2996 else
3129 {
3130 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed."); 2997 m_dialogModule.SendAlertToUser(remoteClient, "Set Home request Failed.");
3131 }
3132 } 2998 }
3133 2999
3134 /// <summary> 3000 /// <summary>
@@ -3201,14 +3067,12 @@ namespace OpenSim.Region.Framework.Scenes
3201 m_sceneGraph.removeUserCount(!childagentYN); 3067 m_sceneGraph.removeUserCount(!childagentYN);
3202 CapsModule.RemoveCapsHandler(agentID); 3068 CapsModule.RemoveCapsHandler(agentID);
3203 3069
3204 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID)) 3070 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
3205 { 3071 // this method is doing is HORRIBLE!!!
3206 CommsManager.UserProfileCacheService.RemoveUser(agentID); 3072 avatar.Scene.NeedSceneCacheClear(avatar.UUID);
3207 }
3208 3073
3209 if (!avatar.IsChildAgent) 3074 if (!avatar.IsChildAgent)
3210 { 3075 {
3211 m_sceneGridService.LogOffUser(agentID, RegionInfo.RegionID, RegionInfo.RegionHandle, avatar.AbsolutePosition, avatar.Lookat);
3212 //List<ulong> childknownRegions = new List<ulong>(); 3076 //List<ulong> childknownRegions = new List<ulong>();
3213 //List<ulong> ckn = avatar.KnownChildRegionHandles; 3077 //List<ulong> ckn = avatar.KnownChildRegionHandles;
3214 //for (int i = 0; i < ckn.Count; i++) 3078 //for (int i = 0; i < ckn.Count; i++)
@@ -3263,12 +3127,6 @@ namespace OpenSim.Region.Framework.Scenes
3263 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString()); 3127 m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
3264 } 3128 }
3265 3129
3266 // Remove client agent from profile, so new logins will work
3267 if (!childagentYN)
3268 {
3269 m_sceneGridService.ClearUserAgent(agentID);
3270 }
3271
3272 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode); 3130 m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
3273 3131
3274 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 3132 //m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
@@ -3341,15 +3199,6 @@ namespace OpenSim.Region.Framework.Scenes
3341 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid; 3199 m_sceneGridService.OnLogOffUser += HandleLogOffUserFromGrid;
3342 m_sceneGridService.KiPrimitive += SendKillObject; 3200 m_sceneGridService.KiPrimitive += SendKillObject;
3343 m_sceneGridService.OnGetLandData += GetLandData; 3201 m_sceneGridService.OnGetLandData += GetLandData;
3344
3345 if (m_interregionCommsIn != null)
3346 {
3347 m_log.Debug("[SCENE]: Registering with InterregionCommsIn");
3348 m_interregionCommsIn.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
3349 }
3350 else
3351 m_log.Debug("[SCENE]: Unable to register with InterregionCommsIn");
3352
3353 } 3202 }
3354 3203
3355 /// <summary> 3204 /// <summary>
@@ -3367,9 +3216,6 @@ namespace OpenSim.Region.Framework.Scenes
3367 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent; 3216 m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent;
3368 m_sceneGridService.OnGetLandData -= GetLandData; 3217 m_sceneGridService.OnGetLandData -= GetLandData;
3369 3218
3370 if (m_interregionCommsIn != null)
3371 m_interregionCommsIn.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
3372
3373 // this does nothing; should be removed 3219 // this does nothing; should be removed
3374 m_sceneGridService.Close(); 3220 m_sceneGridService.Close();
3375 3221
@@ -3406,6 +3252,7 @@ namespace OpenSim.Region.Framework.Scenes
3406 /// also return a reason.</returns> 3252 /// also return a reason.</returns>
3407 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason) 3253 public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason)
3408 { 3254 {
3255 TeleportFlags tp = (TeleportFlags)teleportFlags;
3409 //Teleport flags: 3256 //Teleport flags:
3410 // 3257 //
3411 // TeleportFlags.ViaGodlikeLure - Border Crossing 3258 // TeleportFlags.ViaGodlikeLure - Border Crossing
@@ -3426,7 +3273,7 @@ namespace OpenSim.Region.Framework.Scenes
3426 agent.AgentID, agent.circuitcode, teleportFlags); 3273 agent.AgentID, agent.circuitcode, teleportFlags);
3427 3274
3428 reason = String.Empty; 3275 reason = String.Empty;
3429 if (!AuthenticateUser(agent, out reason)) 3276 if (!VerifyUserPresence(agent, out reason))
3430 return false; 3277 return false;
3431 3278
3432 if (!AuthorizeUser(agent, out reason)) 3279 if (!AuthorizeUser(agent, out reason))
@@ -3439,6 +3286,17 @@ namespace OpenSim.Region.Framework.Scenes
3439 3286
3440 CapsModule.NewUserConnection(agent); 3287 CapsModule.NewUserConnection(agent);
3441 3288
3289 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3290
3291 //On login or border crossing test land permisions
3292 if (tp != TeleportFlags.Default)
3293 {
3294 if (land != null && !TestLandRestrictions(agent, land, out reason))
3295 {
3296 return false;
3297 }
3298 }
3299
3442 ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID); 3300 ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID);
3443 if (sp != null) 3301 if (sp != null)
3444 { 3302 {
@@ -3526,40 +3384,73 @@ namespace OpenSim.Region.Framework.Scenes
3526 */// This is now handled properly in ScenePresence.MakeRootAgent 3384 */// This is now handled properly in ScenePresence.MakeRootAgent
3527 } 3385 }
3528 3386
3387 agent.teleportFlags = teleportFlags;
3529 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3388 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
3530 3389
3531 // rewrite session_id 3390 return true;
3532 CachedUserInfo userinfo = CommsManager.UserProfileCacheService.GetUserDetails(agent.AgentID); 3391 }
3533 if (userinfo != null) 3392
3534 { 3393 private bool TestLandRestrictions(AgentCircuitData agent, ILandObject land, out string reason)
3535 userinfo.SessionID = agent.SessionID; 3394 {
3536 } 3395
3537 else 3396 bool banned = land.IsBannedFromLand(agent.AgentID);
3397 bool restricted = land.IsRestrictedFromLand(agent.AgentID);
3398
3399 if (banned || restricted)
3538 { 3400 {
3539 m_log.WarnFormat( 3401 ILandObject nearestParcel = GetNearestAllowedParcel(agent.AgentID, agent.startpos.X, agent.startpos.Y);
3540 "[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); 3402 if (nearestParcel != null)
3403 {
3404 //Move agent to nearest allowed
3405 Vector3 newPosition = GetParcelCenterAtGround(nearestParcel);
3406 agent.startpos.X = newPosition.X;
3407 agent.startpos.Y = newPosition.Y;
3408 }
3409 else
3410 {
3411 if (banned)
3412 {
3413 reason = "Cannot regioncross into banned parcel.";
3414 }
3415 else
3416 {
3417 reason = String.Format("Denied access to private region {0}: You are not on the access list for that region.",
3418 RegionInfo.RegionName);
3419 }
3420 return false;
3421 }
3541 } 3422 }
3542 3423 reason = "";
3543 return true; 3424 return true;
3544 } 3425 }
3545 3426
3546 /// <summary> 3427 /// <summary>
3547 /// Verifies that the user has a session on the Grid 3428 /// Verifies that the user has a presence on the Grid
3548 /// </summary> 3429 /// </summary>
3549 /// <param name="agent">Circuit Data of the Agent we're verifying</param> 3430 /// <param name="agent">Circuit Data of the Agent we're verifying</param>
3550 /// <param name="reason">Outputs the reason for the false response on this string</param> 3431 /// <param name="reason">Outputs the reason for the false response on this string</param>
3551 /// <returns>True if the user has a session on the grid. False if it does not. False will 3432 /// <returns>True if the user has a session on the grid. False if it does not. False will
3552 /// also return a reason.</returns> 3433 /// also return a reason.</returns>
3553 public virtual bool AuthenticateUser(AgentCircuitData agent, out string reason) 3434 public virtual bool VerifyUserPresence(AgentCircuitData agent, out string reason)
3554 { 3435 {
3555 reason = String.Empty; 3436 reason = String.Empty;
3556 3437
3557 bool result = CommsManager.UserService.VerifySession(agent.AgentID, agent.SessionID); 3438 IPresenceService presence = RequestModuleInterface<IPresenceService>();
3558 m_log.Debug("[CONNECTION BEGIN]: User authentication returned " + result); 3439 if (presence == null)
3559 if (!result) 3440 {
3560 reason = String.Format("Failed to authenticate user {0} {1}, access denied.", agent.firstname, agent.lastname); 3441 reason = String.Format("Failed to verify user {0} {1} in region {2}. Presence service does not exist.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3442 return false;
3443 }
3444
3445 OpenSim.Services.Interfaces.PresenceInfo pinfo = presence.GetAgent(agent.SessionID);
3446
3447 if (pinfo == null || (pinfo != null && pinfo.Online == false))
3448 {
3449 reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3450 return false;
3451 }
3561 3452
3562 return result; 3453 return true;
3563 } 3454 }
3564 3455
3565 /// <summary> 3456 /// <summary>
@@ -3664,6 +3555,18 @@ namespace OpenSim.Region.Framework.Scenes
3664 return true; 3555 return true;
3665 } 3556 }
3666 3557
3558 private ILandObject GetParcelAtPoint(float x, float y)
3559 {
3560 foreach (var parcel in AllParcels())
3561 {
3562 if( parcel.ContainsPoint((int)x,(int)y))
3563 {
3564 return parcel;
3565 }
3566 }
3567 return null;
3568 }
3569
3667 /// <summary> 3570 /// <summary>
3668 /// Update an AgentCircuitData object with new information 3571 /// Update an AgentCircuitData object with new information
3669 /// </summary> 3572 /// </summary>
@@ -3760,8 +3663,8 @@ namespace OpenSim.Region.Framework.Scenes
3760 /// <returns>true if we handled it.</returns> 3663 /// <returns>true if we handled it.</returns>
3761 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData) 3664 public virtual bool IncomingChildAgentDataUpdate(AgentData cAgentData)
3762 { 3665 {
3763// m_log.DebugFormat( 3666 m_log.DebugFormat(
3764// "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName); 3667 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
3765 3668
3766 // We have to wait until the viewer contacts this region after receiving EAC. 3669 // We have to wait until the viewer contacts this region after receiving EAC.
3767 // That calls AddNewClient, which finally creates the ScenePresence 3670 // That calls AddNewClient, which finally creates the ScenePresence
@@ -3830,16 +3733,6 @@ namespace OpenSim.Region.Framework.Scenes
3830 return false; 3733 return false;
3831 } 3734 }
3832 3735
3833 public virtual bool IncomingReleaseAgent(UUID id)
3834 {
3835 return m_sceneGridService.ReleaseAgent(id);
3836 }
3837
3838 public void SendReleaseAgent(ulong regionHandle, UUID id, string uri)
3839 {
3840 m_interregionCommsOut.SendReleaseAgent(regionHandle, id, uri);
3841 }
3842
3843 /// <summary> 3736 /// <summary>
3844 /// Tell a single agent to disconnect from the region. 3737 /// Tell a single agent to disconnect from the region.
3845 /// </summary> 3738 /// </summary>
@@ -3884,30 +3777,6 @@ namespace OpenSim.Region.Framework.Scenes
3884 } 3777 }
3885 3778
3886 /// <summary> 3779 /// <summary>
3887 /// Tell neighboring regions about this agent
3888 /// When the regions respond with a true value,
3889 /// tell the agents about the region.
3890 ///
3891 /// We have to tell the regions about the agents first otherwise it'll deny them access
3892 ///
3893 /// </summary>
3894 /// <param name="presence"></param>
3895 public void InformClientOfNeighbours(ScenePresence presence)
3896 {
3897 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3898 }
3899
3900 /// <summary>
3901 /// Tell a neighboring region about this agent
3902 /// </summary>
3903 /// <param name="presence"></param>
3904 /// <param name="region"></param>
3905 public void InformClientOfNeighbor(ScenePresence presence, RegionInfo region)
3906 {
3907 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3908 }
3909
3910 /// <summary>
3911 /// Tries to teleport agent to other region. 3780 /// Tries to teleport agent to other region.
3912 /// </summary> 3781 /// </summary>
3913 /// <param name="remoteClient"></param> 3782 /// <param name="remoteClient"></param>
@@ -3982,16 +3851,12 @@ namespace OpenSim.Region.Framework.Scenes
3982 } 3851 }
3983 3852
3984 if (m_teleportModule != null) 3853 if (m_teleportModule != null)
3985 { 3854 m_teleportModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
3986 m_teleportModule.RequestTeleportToLocation(sp, regionHandle,
3987 position, lookAt, teleportFlags);
3988 }
3989 else 3855 else
3990 { 3856 {
3991 m_sceneGridService.RequestTeleportToLocation(sp, regionHandle, 3857 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active");
3992 position, lookAt, teleportFlags); 3858 sp.ControllingClient.SendTeleportFailed("Unable to perform teleports on this simulator.");
3993 } 3859 }
3994
3995 } 3860 }
3996 } 3861 }
3997 3862
@@ -4017,7 +3882,12 @@ namespace OpenSim.Region.Framework.Scenes
4017 3882
4018 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying) 3883 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying)
4019 { 3884 {
4020 m_sceneGridService.CrossAgentToNewRegion(this, agent, isFlying); 3885 if (m_teleportModule != null)
3886 m_teleportModule.Cross(agent, isFlying);
3887 else
3888 {
3889 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule");
3890 }
4021 } 3891 }
4022 3892
4023 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence) 3893 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence)
@@ -4043,35 +3913,6 @@ namespace OpenSim.Region.Framework.Scenes
4043 objectCapacity = objects; 3913 objectCapacity = objects;
4044 } 3914 }
4045 3915
4046 public List<FriendListItem> GetFriendList(string id)
4047 {
4048 UUID avatarID;
4049 if (!UUID.TryParse(id, out avatarID))
4050 return new List<FriendListItem>();
4051
4052 return CommsManager.GetUserFriendList(avatarID);
4053 }
4054
4055 public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
4056 {
4057 return CommsManager.GetFriendRegionInfos(uuids);
4058 }
4059
4060 public virtual void StoreAddFriendship(UUID ownerID, UUID friendID, uint perms)
4061 {
4062 m_sceneGridService.AddNewUserFriend(ownerID, friendID, perms);
4063 }
4064
4065 public virtual void StoreUpdateFriendship(UUID ownerID, UUID friendID, uint perms)
4066 {
4067 m_sceneGridService.UpdateUserFriendPerms(ownerID, friendID, perms);
4068 }
4069
4070 public virtual void StoreRemoveFriendship(UUID ownerID, UUID ExfriendID)
4071 {
4072 m_sceneGridService.RemoveUserFriend(ownerID, ExfriendID);
4073 }
4074
4075 #endregion 3916 #endregion
4076 3917
4077 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set) 3918 public void HandleObjectPermissionsUpdate(IClientAPI controller, UUID agentID, UUID sessionID, byte field, uint localId, uint mask, byte set)
@@ -4466,7 +4307,7 @@ namespace OpenSim.Region.Framework.Scenes
4466 return m_sceneGraph.GetGroupByPrim(localID); 4307 return m_sceneGraph.GetGroupByPrim(localID);
4467 } 4308 }
4468 4309
4469 public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 4310 public override bool TryGetAvatar(UUID avatarId, out ScenePresence avatar)
4470 { 4311 {
4471 return m_sceneGraph.TryGetAvatar(avatarId, out avatar); 4312 return m_sceneGraph.TryGetAvatar(avatarId, out avatar);
4472 } 4313 }
@@ -4663,7 +4504,8 @@ namespace OpenSim.Region.Framework.Scenes
4663 group.GetPartName(localID), 4504 group.GetPartName(localID),
4664 group.GetPartDescription(localID), 4505 group.GetPartDescription(localID),
4665 (sbyte)AssetType.Object, 4506 (sbyte)AssetType.Object,
4666 Utils.StringToBytes(sceneObjectXml)); 4507 Utils.StringToBytes(sceneObjectXml),
4508 group.OwnerID);
4667 AssetService.Store(asset); 4509 AssetService.Store(asset);
4668 4510
4669 InventoryItemBase item = new InventoryItemBase(); 4511 InventoryItemBase item = new InventoryItemBase();
@@ -4987,5 +4829,185 @@ namespace OpenSim.Region.Framework.Scenes
4987 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000) 4829 if (Util.EnvironmentTickCountSubtract(m_lastUpdate) > 2000)
4988 StartTimer(); 4830 StartTimer();
4989 } 4831 }
4832
4833 public override ISceneObject DeserializeObject(string representation)
4834 {
4835 return SceneObjectSerializer.FromXml2Format(representation);
4836 }
4837
4838 public override bool AllowScriptCrossings
4839 {
4840 get { return m_allowScriptCrossings; }
4841 }
4842
4843 public Vector3? GetNearestAllowedPosition(ScenePresence avatar)
4844 {
4845 //simulate to make sure we have pretty up to date positions
4846 PhysicsScene.Simulate(0);
4847
4848 ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
4849
4850 if (nearestParcel != null)
4851 {
4852 Vector3 dir = Vector3.Normalize(Vector3.Multiply(avatar.Velocity, -1));
4853 //Try to get a location that feels like where they came from
4854 Vector3? nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4855 if (nearestPoint != null)
4856 {
4857 Debug.WriteLine("Found a sane previous position based on velocity, sending them to: " + nearestPoint.ToString());
4858 return nearestPoint.Value;
4859 }
4860
4861 //Sometimes velocity might be zero (local teleport), so try finding point along path from avatar to center of nearest parcel
4862 Vector3 directionToParcelCenter = Vector3.Subtract(GetParcelCenterAtGround(nearestParcel), avatar.AbsolutePosition);
4863 dir = Vector3.Normalize(directionToParcelCenter);
4864 nearestPoint = GetNearestPointInParcelAlongDirectionFromPoint(avatar.AbsolutePosition, dir, nearestParcel);
4865 if (nearestPoint != null)
4866 {
4867 Debug.WriteLine("They had a zero velocity, sending them to: " + nearestPoint.ToString());
4868 return nearestPoint.Value;
4869 }
4870
4871 //Ultimate backup if we have no idea where they are
4872 Debug.WriteLine("Have no idea where they are, sending them to: " + avatar.lastKnownAllowedPosition.ToString());
4873 return avatar.lastKnownAllowedPosition;
4874
4875 }
4876
4877 //Go to the edge, this happens in teleporting to a region with no available parcels
4878 Vector3 nearestRegionEdgePoint = GetNearestRegionEdgePosition(avatar);
4879 //Debug.WriteLine("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString());
4880 return nearestRegionEdgePoint;
4881 return null;
4882 }
4883
4884 private Vector3 GetParcelCenterAtGround(ILandObject parcel)
4885 {
4886 Vector2 center = GetParcelCenter(parcel);
4887 return GetPositionAtGround(center.X, center.Y);
4888 }
4889
4890 private Vector3? GetNearestPointInParcelAlongDirectionFromPoint(Vector3 pos, Vector3 direction, ILandObject parcel)
4891 {
4892 Vector3 unitDirection = Vector3.Normalize(direction);
4893 //Making distance to search go through some sane limit of distance
4894 for (float distance = 0; distance < Constants.RegionSize * 2; distance += .5f)
4895 {
4896 Vector3 testPos = Vector3.Add(pos, Vector3.Multiply(unitDirection, distance));
4897 if (parcel.ContainsPoint((int)testPos.X, (int)testPos.Y))
4898 {
4899 return testPos;
4900 }
4901 }
4902 return null;
4903 }
4904
4905 public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
4906 {
4907 List<ILandObject> all = AllParcels();
4908 float minParcelDistance = float.MaxValue;
4909 ILandObject nearestParcel = null;
4910
4911 foreach (var parcel in all)
4912 {
4913 if (!parcel.IsEitherBannedOrRestricted(avatarId))
4914 {
4915 float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
4916 if (parcelDistance < minParcelDistance)
4917 {
4918 minParcelDistance = parcelDistance;
4919 nearestParcel = parcel;
4920 }
4921 }
4922 }
4923
4924 return nearestParcel;
4925 }
4926
4927 private List<ILandObject> AllParcels()
4928 {
4929 return LandChannel.AllParcels();
4930 }
4931
4932 private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y)
4933 {
4934 return Vector2.Distance(new Vector2(x, y), GetParcelCenter(parcel));
4935 }
4936
4937 //calculate the average center point of a parcel
4938 private Vector2 GetParcelCenter(ILandObject parcel)
4939 {
4940 int count = 0;
4941 int avgx = 0;
4942 int avgy = 0;
4943 for (int x = 0; x < Constants.RegionSize; x++)
4944 {
4945 for (int y = 0; y < Constants.RegionSize; y++)
4946 {
4947 //Just keep a running average as we check if all the points are inside or not
4948 if (parcel.ContainsPoint(x, y))
4949 {
4950 if (count == 0)
4951 {
4952 avgx = x;
4953 avgy = y;
4954 }
4955 else
4956 {
4957 avgx = (avgx * count + x) / (count + 1);
4958 avgy = (avgy * count + y) / (count + 1);
4959 }
4960 count += 1;
4961 }
4962 }
4963 }
4964 return new Vector2(avgx, avgy);
4965 }
4966
4967 private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
4968 {
4969 float xdistance = avatar.AbsolutePosition.X < Constants.RegionSize / 2 ? avatar.AbsolutePosition.X : Constants.RegionSize - avatar.AbsolutePosition.X;
4970 float ydistance = avatar.AbsolutePosition.Y < Constants.RegionSize / 2 ? avatar.AbsolutePosition.Y : Constants.RegionSize - avatar.AbsolutePosition.Y;
4971
4972 //find out what vertical edge to go to
4973 if (xdistance < ydistance)
4974 {
4975 if (avatar.AbsolutePosition.X < Constants.RegionSize / 2)
4976 {
4977 return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
4978 }
4979 else
4980 {
4981 return GetPositionAtAvatarHeightOrGroundHeight(avatar, Constants.RegionSize, avatar.AbsolutePosition.Y);
4982 }
4983 }
4984 //find out what horizontal edge to go to
4985 else
4986 {
4987 if (avatar.AbsolutePosition.Y < Constants.RegionSize / 2)
4988 {
4989 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
4990 }
4991 else
4992 {
4993 return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, Constants.RegionSize);
4994 }
4995 }
4996 }
4997
4998 private Vector3 GetPositionAtAvatarHeightOrGroundHeight(ScenePresence avatar, float x, float y)
4999 {
5000 Vector3 ground = GetPositionAtGround(x, y);
5001 if( avatar.AbsolutePosition.Z > ground.Z)
5002 {
5003 ground.Z = avatar.AbsolutePosition.Z;
5004 }
5005 return ground;
5006 }
5007
5008 private Vector3 GetPositionAtGround(float x, float y)
5009 {
5010 return new Vector3(x, y, GetGroundHeight(x, y));
5011 }
4990 } 5012 }
4991} 5013}
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index 5e798c0..74476ed 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 TryGetAvatar(UUID agentID, out object scenePresence)
194 {
195 scenePresence = null;
196 ScenePresence sp = null;
197 if (TryGetAvatar(agentID, out sp))
198 {
199 scenePresence = sp;
200 return true;
201 }
202
203 return false;
204 }
205
206 public abstract bool TryGetAvatar(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 5f84252..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 = 200;
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 e28d29f..4e41b07 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{
@@ -252,7 +253,7 @@ namespace OpenSim.Region.Framework.Scenes
252 sceneObject.HasGroupChanged = true; 253 sceneObject.HasGroupChanged = true;
253 } 254 }
254 255
255 return AddSceneObject(sceneObject, attachToBackup); 256 return AddSceneObject(sceneObject, attachToBackup, true);
256 } 257 }
257 258
258 /// <summary> 259 /// <summary>
@@ -267,12 +268,12 @@ namespace OpenSim.Region.Framework.Scenes
267 /// <returns> 268 /// <returns>
268 /// true if the object was added, false if an object with the same uuid was already in the scene 269 /// true if the object was added, false if an object with the same uuid was already in the scene
269 /// </returns> 270 /// </returns>
270 protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup) 271 protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
271 { 272 {
272 // Ensure that we persist this new scene object 273 // Ensure that we persist this new scene object
273 sceneObject.HasGroupChanged = true; 274 sceneObject.HasGroupChanged = true;
274 275
275 return AddSceneObject(sceneObject, attachToBackup); 276 return AddSceneObject(sceneObject, attachToBackup, sendClientUpdates);
276 } 277 }
277 278
278 /// <summary> 279 /// <summary>
@@ -284,12 +285,19 @@ namespace OpenSim.Region.Framework.Scenes
284 /// If true, the object is made persistent into the scene. 285 /// If true, the object is made persistent into the scene.
285 /// If false, the object will not persist over server restarts 286 /// If false, the object will not persist over server restarts
286 /// </param> 287 /// </param>
287 /// <returns>true if the object was added, false if an object with the same uuid was already in the scene 288 /// <param name="sendClientUpdates">
289 /// If true, updates for the new scene object are sent to all viewers in range.
290 /// If false, it is left to the caller to schedule the update
291 /// </param>
292 /// <returns>
293 /// true if the object was added, false if an object with the same uuid was already in the scene
288 /// </returns> 294 /// </returns>
289 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup) 295 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
290 { 296 {
291 if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero) 297 if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero)
292 return false; 298 return false;
299
300 bool alreadyExisted = false;
293 301
294 if (m_parentScene.m_clampPrimSize) 302 if (m_parentScene.m_clampPrimSize)
295 { 303 {
@@ -310,6 +318,9 @@ namespace OpenSim.Region.Framework.Scenes
310 318
311 sceneObject.AttachToScene(m_parentScene); 319 sceneObject.AttachToScene(m_parentScene);
312 320
321 if (sendClientUpdates)
322 sceneObject.ScheduleGroupForFullUpdate();
323
313 lock (sceneObject) 324 lock (sceneObject)
314 { 325 {
315 if (!Entities.ContainsKey(sceneObject.UUID)) 326 if (!Entities.ContainsKey(sceneObject.UUID))
@@ -333,12 +344,14 @@ namespace OpenSim.Region.Framework.Scenes
333 SceneObjectGroupsByLocalID[part.LocalId] = sceneObject; 344 SceneObjectGroupsByLocalID[part.LocalId] = sceneObject;
334 } 345 }
335 } 346 }
336 347 }
337 return true; 348 else
349 {
350 alreadyExisted = true;
338 } 351 }
339 } 352 }
340 353
341 return false; 354 return alreadyExisted;
342 } 355 }
343 356
344 /// <summary> 357 /// <summary>
@@ -463,7 +476,7 @@ namespace OpenSim.Region.Framework.Scenes
463 if (group != null) 476 if (group != null)
464 { 477 {
465 //group.DetachToGround(); 478 //group.DetachToGround();
466 m_parentScene.DetachSingleAttachmentToInv(group.GetFromItemID(), remoteClient); 479 m_parentScene.AttachmentsModule.ShowDetachInUserInventory(group.GetFromItemID(), remoteClient);
467 } 480 }
468 } 481 }
469 482
@@ -515,7 +528,7 @@ namespace OpenSim.Region.Framework.Scenes
515 return; 528 return;
516 529
517 // Calls attach with a Zero position 530 // Calls attach with a Zero position
518 if (AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, Vector3.Zero, false)) 531 if (m_parentScene.AttachmentsModule.AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, Vector3.Zero, false))
519 { 532 {
520 m_parentScene.SendAttachEvent(objectLocalID, part.ParentGroup.GetFromItemID(), remoteClient.AgentId); 533 m_parentScene.SendAttachEvent(objectLocalID, part.ParentGroup.GetFromItemID(), remoteClient.AgentId);
521 534
@@ -541,23 +554,30 @@ namespace OpenSim.Region.Framework.Scenes
541 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns> 554 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
542 public SceneObjectGroup RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) 555 public SceneObjectGroup RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
543 { 556 {
544 SceneObjectGroup objatt = m_parentScene.RezObject(remoteClient, 557 IInventoryAccessModule invAccess = m_parentScene.RequestModuleInterface<IInventoryAccessModule>();
545 itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true, 558 if (invAccess != null)
546 false, false, remoteClient.AgentId, true);
547
548 if (objatt != null)
549 { 559 {
550 bool tainted = false; 560 SceneObjectGroup objatt = invAccess.RezObject(remoteClient,
551 if (AttachmentPt != 0 && AttachmentPt != objatt.GetAttachmentPoint()) 561 itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
552 tainted = true; 562 false, false, remoteClient.AgentId, true);
553 563
554 if (AttachObject( 564// m_log.DebugFormat(
555 remoteClient, objatt.LocalId, AttachmentPt, Quaternion.Identity, objatt.AbsolutePosition, false)) 565// "[SCENE GRAPH]: Retrieved single object {0} for attachment to {1} on point {2}",
566// objatt.Name, remoteClient.Name, AttachmentPt);
567
568 if (objatt != null)
556 { 569 {
557 objatt.ScheduleGroupForFullUpdate(); 570 bool tainted = false;
571 if (AttachmentPt != 0 && AttachmentPt != objatt.GetAttachmentPoint())
572 tainted = true;
573
574 m_parentScene.AttachmentsModule.AttachObject(
575 remoteClient, objatt.LocalId, AttachmentPt, Quaternion.Identity, objatt.AbsolutePosition, false);
576 //objatt.ScheduleGroupForFullUpdate();
577
558 if (tainted) 578 if (tainted)
559 objatt.HasGroupChanged = true; 579 objatt.HasGroupChanged = true;
560 580
561 // Fire after attach, so we don't get messy perms dialogs 581 // Fire after attach, so we don't get messy perms dialogs
562 // 3 == AttachedRez 582 // 3 == AttachedRez
563 objatt.CreateScriptInstances(0, true, m_parentScene.DefaultScriptEngine, 3); 583 objatt.CreateScriptInstances(0, true, m_parentScene.DefaultScriptEngine, 3);
@@ -565,134 +585,17 @@ namespace OpenSim.Region.Framework.Scenes
565 // Do this last so that event listeners have access to all the effects of the attachment 585 // Do this last so that event listeners have access to all the effects of the attachment
566 m_parentScene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, remoteClient.AgentId); 586 m_parentScene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, remoteClient.AgentId);
567 } 587 }
568 }
569
570 return objatt;
571 }
572
573 // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards.
574 // To LocalId or UUID, *THAT* is the question. How now Brown UUID??
575 public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
576 {
577 if (itemID == UUID.Zero) // If this happened, someone made a mistake....
578 return;
579
580 // We can NOT use the dictionries here, as we are looking
581 // for an entity by the fromAssetID, which is NOT the prim UUID
582 //
583 List<EntityBase> detachEntities = GetEntities();
584 SceneObjectGroup group;
585
586 foreach (EntityBase entity in detachEntities)
587 {
588 if (entity is SceneObjectGroup)
589 {
590 group = (SceneObjectGroup)entity;
591 if (group.GetFromItemID() == itemID)
592 {
593 m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero);
594 bool hasScripts = false;
595 foreach (SceneObjectPart part in group.Children.Values)
596 {
597 if (part.Inventory.ContainsScripts())
598 {
599 hasScripts = true;
600 break;
601 }
602 }
603
604 if (hasScripts) // Allow the object to execute the attach(NULL_KEY) event
605 System.Threading.Thread.Sleep(100);
606 group.DetachToInventoryPrep();
607 m_log.Debug("[DETACH]: Saving attachpoint: " +
608 ((uint)group.GetAttachmentPoint()).ToString());
609 m_parentScene.UpdateKnownItem(remoteClient, group,
610 group.GetFromItemID(), group.OwnerID);
611 m_parentScene.DeleteSceneObject(group, false);
612 return;
613 }
614 }
615 }
616 }
617
618 /// <summary>
619 /// Attach a scene object to an avatar.
620 /// </summary>
621 /// <param name="remoteClient"></param>
622 /// <param name="objectLocalID"></param>
623 /// <param name="AttachmentPt"></param>
624 /// <param name="rot"></param>
625 /// <param name="attachPos"></param>
626 /// <param name="silent"></param>
627 /// <returns>true if the attachment was successful, false otherwise</returns>
628 protected internal bool AttachObject(
629 IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, Vector3 attachPos, bool silent)
630 {
631 SceneObjectGroup group = GetGroupByPrim(objectLocalID);
632 if (group != null)
633 {
634 if (m_parentScene.Permissions.CanTakeObject(group.UUID, remoteClient.AgentId))
635 {
636 // If the attachment point isn't the same as the one previously used
637 // set it's offset position = 0 so that it appears on the attachment point
638 // and not in a weird location somewhere unknown.
639 if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint())
640 {
641 attachPos = Vector3.Zero;
642 }
643
644 // AttachmentPt 0 means the client chose to 'wear' the attachment.
645 if (AttachmentPt == 0)
646 {
647 // Check object for stored attachment point
648 AttachmentPt = (uint)group.GetAttachmentPoint();
649 }
650
651 // if we still didn't find a suitable attachment point.......
652 if (AttachmentPt == 0)
653 {
654 // Stick it on left hand with Zero Offset from the attachment point.
655 AttachmentPt = (uint)AttachmentPoint.LeftHand;
656 attachPos = Vector3.Zero;
657 }
658
659 group.SetAttachmentPoint((byte)AttachmentPt);
660 group.AbsolutePosition = attachPos;
661
662 // Saves and gets itemID
663 UUID itemId;
664
665 if (group.GetFromItemID() == UUID.Zero)
666 {
667 m_parentScene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId, out itemId);
668 }
669 else
670 {
671 itemId = group.GetFromItemID();
672 }
673
674 m_parentScene.AttachObject(remoteClient, AttachmentPt, itemId, group);
675
676 group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos, silent);
677 // In case it is later dropped again, don't let
678 // it get cleaned up
679 //
680 group.RootPart.RemFlag(PrimFlags.TemporaryOnRez);
681 group.HasGroupChanged = false;
682 }
683 else 588 else
684 { 589 {
685 remoteClient.SendAgentAlertMessage("You don't have sufficient permissions to attach this object", false); 590 m_log.WarnFormat(
686 return false; 591 "[SCENE GRAPH]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
592 itemID, remoteClient.Name, AttachmentPt);
687 } 593 }
594
595 return objatt;
688 } 596 }
689 else 597
690 { 598 return null;
691 m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID);
692 return false;
693 }
694
695 return true;
696 } 599 }
697 600
698 protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance) 601 protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance)
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index c2e3370..680c39a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -422,7 +422,7 @@ namespace OpenSim.Region.Framework.Scenes
422 422
423 if (!scenePresence.IsChildAgent) 423 if (!scenePresence.IsChildAgent)
424 { 424 {
425 m_log.ErrorFormat("Packet debug for {0} {1} set to {2}", 425 m_log.DebugFormat("Packet debug for {0} {1} set to {2}",
426 scenePresence.Firstname, 426 scenePresence.Firstname,
427 scenePresence.Lastname, 427 scenePresence.Lastname,
428 newDebug); 428 newDebug);
@@ -468,11 +468,11 @@ namespace OpenSim.Region.Framework.Scenes
468 return presences; 468 return presences;
469 } 469 }
470 470
471 public RegionInfo GetRegionInfo(ulong regionHandle) 471 public RegionInfo GetRegionInfo(UUID regionID)
472 { 472 {
473 foreach (Scene scene in m_localScenes) 473 foreach (Scene scene in m_localScenes)
474 { 474 {
475 if (scene.RegionInfo.RegionHandle == regionHandle) 475 if (scene.RegionInfo.RegionID == regionID)
476 { 476 {
477 return scene.RegionInfo; 477 return scene.RegionInfo;
478 } 478 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 5443c28..6c4b39d 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -377,6 +377,7 @@ namespace OpenSim.Region.Framework.Scenes
377 RootPart.ScriptSetPhysicsStatus(false); 377 RootPart.ScriptSetPhysicsStatus(false);
378 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), 378 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
379 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); 379 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
380 lockPartsForRead(false);
380 return; 381 return;
381 } 382 }
382 } 383 }
@@ -489,8 +490,8 @@ namespace OpenSim.Region.Framework.Scenes
489 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>(); 490 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
490 public List<SceneObjectPart> PlaySoundSlavePrims 491 public List<SceneObjectPart> PlaySoundSlavePrims
491 { 492 {
492 get { return m_LoopSoundSlavePrims; } 493 get { return m_PlaySoundSlavePrims; }
493 set { m_LoopSoundSlavePrims = value; } 494 set { m_PlaySoundSlavePrims = value; }
494 } 495 }
495 496
496 private SceneObjectPart m_LoopSoundMasterPrim = null; 497 private SceneObjectPart m_LoopSoundMasterPrim = null;
@@ -642,8 +643,10 @@ namespace OpenSim.Region.Framework.Scenes
642 } 643 }
643 644
644 ApplyPhysics(m_scene.m_physicalPrim); 645 ApplyPhysics(m_scene.m_physicalPrim);
645 646
646 ScheduleGroupForFullUpdate(); 647 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
648 // for the same object with very different properties. The caller must schedule the update.
649 //ScheduleGroupForFullUpdate();
647 } 650 }
648 651
649 public Vector3 GroupScale() 652 public Vector3 GroupScale()
@@ -1045,10 +1048,11 @@ namespace OpenSim.Region.Framework.Scenes
1045 // don't attach attachments to child agents 1048 // don't attach attachments to child agents
1046 if (avatar.IsChildAgent) return; 1049 if (avatar.IsChildAgent) return;
1047 1050
1051// m_log.DebugFormat("[SOG]: Adding attachment {0} to avatar {1}", Name, avatar.Name);
1052
1048 DetachFromBackup(); 1053 DetachFromBackup();
1049 1054
1050 // Remove from database and parcel prim count 1055 // Remove from database and parcel prim count
1051 //
1052 m_scene.DeleteFromStorage(UUID); 1056 m_scene.DeleteFromStorage(UUID);
1053 m_scene.EventManager.TriggerParcelPrimCountTainted(); 1057 m_scene.EventManager.TriggerParcelPrimCountTainted();
1054 1058
@@ -1074,7 +1078,6 @@ namespace OpenSim.Region.Framework.Scenes
1074 SetAttachmentPoint(Convert.ToByte(attachmentpoint)); 1078 SetAttachmentPoint(Convert.ToByte(attachmentpoint));
1075 1079
1076 avatar.AddAttachment(this); 1080 avatar.AddAttachment(this);
1077 m_log.Debug("[SOG]: Added attachment " + UUID + " to avatar " + avatar.UUID);
1078 1081
1079 if (!silent) 1082 if (!silent)
1080 { 1083 {
@@ -1091,6 +1094,12 @@ namespace OpenSim.Region.Framework.Scenes
1091 ScheduleGroupForFullUpdate(); 1094 ScheduleGroupForFullUpdate();
1092 } 1095 }
1093 } 1096 }
1097 else
1098 {
1099 m_log.WarnFormat(
1100 "[SOG]: Tried to add attachment {0} to avatar with UUID {1} in region {2} but the avatar is not present",
1101 UUID, agentID, Scene.RegionInfo.RegionName);
1102 }
1094 } 1103 }
1095 1104
1096 public byte GetAttachmentPoint() 1105 public byte GetAttachmentPoint()
@@ -1597,11 +1606,10 @@ namespace OpenSim.Region.Framework.Scenes
1597 1606
1598 #endregion 1607 #endregion
1599 1608
1600 #region Client Updating
1601
1602 public void SendFullUpdateToClient(IClientAPI remoteClient) 1609 public void SendFullUpdateToClient(IClientAPI remoteClient)
1603 { 1610 {
1604 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1611 RootPart.SendFullUpdate(
1612 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1605 1613
1606 lockPartsForRead(true); 1614 lockPartsForRead(true);
1607 { 1615 {
@@ -1609,42 +1617,12 @@ namespace OpenSim.Region.Framework.Scenes
1609 { 1617 {
1610 1618
1611 if (part != RootPart) 1619 if (part != RootPart)
1612 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1620 part.SendFullUpdate(
1613 1621 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
1614 }
1615 }
1616 lockPartsForRead(false);
1617 }
1618
1619 /// <summary>
1620 /// Send a full update to the client for the given part
1621 /// </summary>
1622 /// <param name="remoteClient"></param>
1623 /// <param name="part"></param>
1624 internal void SendPartFullUpdate(IClientAPI remoteClient, SceneObjectPart part, uint clientFlags)
1625 {
1626// m_log.DebugFormat(
1627// "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
1628
1629 if (m_rootPart.UUID == part.UUID)
1630 {
1631 if (IsAttachment)
1632 {
1633 part.SendFullUpdateToClient(remoteClient, m_rootPart.AttachedPos, clientFlags);
1634 }
1635 else
1636 {
1637 part.SendFullUpdateToClient(remoteClient, AbsolutePosition, clientFlags);
1638 } 1622 }
1639 } 1623 }
1640 else
1641 {
1642 part.SendFullUpdateToClient(remoteClient, clientFlags);
1643 }
1644 } 1624 }
1645 1625
1646 #endregion
1647
1648 #region Copying 1626 #region Copying
1649 1627
1650 /// <summary> 1628 /// <summary>
@@ -2136,6 +2114,8 @@ namespace OpenSim.Region.Framework.Scenes
2136 2114
2137 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2115 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
2138 { 2116 {
2117// m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1} just to avatar {2}", Name, UUID, presence.Name);
2118
2139 RootPart.AddFullUpdateToAvatar(presence); 2119 RootPart.AddFullUpdateToAvatar(presence);
2140 2120
2141 lockPartsForRead(true); 2121 lockPartsForRead(true);
@@ -2154,14 +2134,12 @@ namespace OpenSim.Region.Framework.Scenes
2154 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2134 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
2155 { 2135 {
2156 lockPartsForRead(true); 2136 lockPartsForRead(true);
2137
2138 foreach (SceneObjectPart part in m_parts.Values)
2157 { 2139 {
2158 foreach (SceneObjectPart part in m_parts.Values) 2140 part.AddTerseUpdateToAvatar(presence);
2159 {
2160
2161 part.AddTerseUpdateToAvatar(presence);
2162
2163 }
2164 } 2141 }
2142
2165 lockPartsForRead(false); 2143 lockPartsForRead(false);
2166 } 2144 }
2167 2145
@@ -2170,6 +2148,8 @@ namespace OpenSim.Region.Framework.Scenes
2170 /// </summary> 2148 /// </summary>
2171 public void ScheduleGroupForFullUpdate() 2149 public void ScheduleGroupForFullUpdate()
2172 { 2150 {
2151// m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, UUID);
2152
2173 checkAtTargets(); 2153 checkAtTargets();
2174 RootPart.ScheduleFullUpdate(); 2154 RootPart.ScheduleFullUpdate();
2175 2155
@@ -2192,14 +2172,12 @@ namespace OpenSim.Region.Framework.Scenes
2192 public void ScheduleGroupForTerseUpdate() 2172 public void ScheduleGroupForTerseUpdate()
2193 { 2173 {
2194 lockPartsForRead(true); 2174 lockPartsForRead(true);
2175
2176 foreach (SceneObjectPart part in m_parts.Values)
2195 { 2177 {
2196 foreach (SceneObjectPart part in m_parts.Values) 2178 part.ScheduleTerseUpdate();
2197 {
2198
2199 part.ScheduleTerseUpdate();
2200
2201 }
2202 } 2179 }
2180
2203 lockPartsForRead(false); 2181 lockPartsForRead(false);
2204 } 2182 }
2205 2183
@@ -2207,9 +2185,11 @@ namespace OpenSim.Region.Framework.Scenes
2207 /// Immediately send a full update for this scene object. 2185 /// Immediately send a full update for this scene object.
2208 /// </summary> 2186 /// </summary>
2209 public void SendGroupFullUpdate() 2187 public void SendGroupFullUpdate()
2210 { 2188 {
2211 if (IsDeleted) 2189 if (IsDeleted)
2212 return; 2190 return;
2191
2192// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
2213 2193
2214 RootPart.SendFullUpdateToAllClients(); 2194 RootPart.SendFullUpdateToAllClients();
2215 2195
@@ -2229,7 +2209,7 @@ namespace OpenSim.Region.Framework.Scenes
2229 /// <summary> 2209 /// <summary>
2230 /// Immediately send an update for this scene object's root prim only. 2210 /// Immediately send an update for this scene object's root prim only.
2231 /// This is for updates regarding the object as a whole, and none of its parts in particular. 2211 /// This is for updates regarding the object as a whole, and none of its parts in particular.
2232 /// Note: this may not be cused by opensim (it probably should) but it's used by 2212 /// Note: this may not be used by opensim (it probably should) but it's used by
2233 /// external modules. 2213 /// external modules.
2234 /// </summary> 2214 /// </summary>
2235 public void SendGroupRootTerseUpdate() 2215 public void SendGroupRootTerseUpdate()
@@ -2244,6 +2224,7 @@ namespace OpenSim.Region.Framework.Scenes
2244 { 2224 {
2245 if (m_scene == null) // Need to check here as it's null during object creation 2225 if (m_scene == null) // Need to check here as it's null during object creation
2246 return; 2226 return;
2227
2247 m_scene.SceneGraph.AddToUpdateList(this); 2228 m_scene.SceneGraph.AddToUpdateList(this);
2248 } 2229 }
2249 2230
@@ -3050,8 +3031,8 @@ namespace OpenSim.Region.Framework.Scenes
3050 { 3031 {
3051 if (obPart.UUID != m_rootPart.UUID) 3032 if (obPart.UUID != m_rootPart.UUID)
3052 { 3033 {
3053 obPart.IgnoreUndoUpdate = true;
3054 Vector3 oldSize = new Vector3(obPart.Scale); 3034 Vector3 oldSize = new Vector3(obPart.Scale);
3035 obPart.IgnoreUndoUpdate = true;
3055 3036
3056 float f = 1.0f; 3037 float f = 1.0f;
3057 float a = 1.0f; 3038 float a = 1.0f;
@@ -3745,7 +3726,10 @@ namespace OpenSim.Region.Framework.Scenes
3745 HasGroupChanged = true; 3726 HasGroupChanged = true;
3746 } 3727 }
3747 lockPartsForRead(false); 3728 lockPartsForRead(false);
3748 ScheduleGroupForFullUpdate(); 3729
3730 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
3731 // for the same object with very different properties. The caller must schedule the update.
3732 //ScheduleGroupForFullUpdate();
3749 } 3733 }
3750 3734
3751 public void TriggerScriptChangedEvent(Changed val) 3735 public void TriggerScriptChangedEvent(Changed val)
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 548a64f..c8ac014 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;
@@ -2820,29 +2820,59 @@ namespace OpenSim.Region.Framework.Scenes
2820 } 2820 }
2821 } 2821 }
2822 2822
2823// /// <summary>
2824// ///
2825// /// </summary>
2826// /// <param name="remoteClient"></param>
2827// public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
2828// {
2829// m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags);
2830// }
2831
2832
2823 /// <summary> 2833 /// <summary>
2824 /// 2834 /// Send a full update to the client for the given part
2825 /// </summary> 2835 /// </summary>
2826 /// <param name="remoteClient"></param> 2836 /// <param name="remoteClient"></param>
2827 public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags) 2837 /// <param name="clientFlags"></param>
2838 protected internal void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
2828 { 2839 {
2829 m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags); 2840// m_log.DebugFormat(
2830 } 2841// "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
2842
2843 if (IsRoot)
2844 {
2845 if (IsAttachment)
2846 {
2847 SendFullUpdateToClient(remoteClient, AttachedPos, clientFlags);
2848 }
2849 else
2850 {
2851 SendFullUpdateToClient(remoteClient, AbsolutePosition, clientFlags);
2852 }
2853 }
2854 else
2855 {
2856 SendFullUpdateToClient(remoteClient, clientFlags);
2857 }
2858 }
2831 2859
2832 /// <summary> 2860 /// <summary>
2833 /// 2861 /// Send a full update for this part to all clients.
2834 /// </summary> 2862 /// </summary>
2835 public void SendFullUpdateToAllClients() 2863 public void SendFullUpdateToAllClients()
2836 { 2864 {
2837 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 2865 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences();
2838 for (int i = 0; i < avatars.Length; i++) 2866 for (int i = 0; i < avatars.Length; i++)
2839 { 2867 {
2840 // Ugly reference :( 2868 SendFullUpdate(avatars[i].ControllingClient, avatars[i].GenerateClientFlags(UUID));
2841 m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
2842 avatars[i].GenerateClientFlags(UUID));
2843 } 2869 }
2844 } 2870 }
2845 2871
2872 /// <summary>
2873 /// Send a full update to all clients except the one nominated.
2874 /// </summary>
2875 /// <param name="agentID"></param>
2846 public void SendFullUpdateToAllClientsExcept(UUID agentID) 2876 public void SendFullUpdateToAllClientsExcept(UUID agentID)
2847 { 2877 {
2848 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 2878 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences();
@@ -2850,10 +2880,7 @@ namespace OpenSim.Region.Framework.Scenes
2850 { 2880 {
2851 // Ugly reference :( 2881 // Ugly reference :(
2852 if (avatars[i].UUID != agentID) 2882 if (avatars[i].UUID != agentID)
2853 { 2883 SendFullUpdate(avatars[i].ControllingClient, avatars[i].GenerateClientFlags(UUID));
2854 m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
2855 avatars[i].GenerateClientFlags(UUID));
2856 }
2857 } 2884 }
2858 } 2885 }
2859 2886
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 5d00917..836622d 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
@@ -642,7 +641,6 @@ namespace OpenSim.Region.Framework.Scenes
642 m_items[item.ItemID] = item; 641 m_items[item.ItemID] = item;
643 m_inventorySerial++; 642 m_inventorySerial++;
644 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 643 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
645
646 HasInventoryChanged = true; 644 HasInventoryChanged = true;
647 m_part.ParentGroup.HasGroupChanged = true; 645 m_part.ParentGroup.HasGroupChanged = true;
648 m_items.LockItemsForWrite(false); 646 m_items.LockItemsForWrite(false);
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 123d6f3..d8f93d7 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -33,12 +33,12 @@ using OpenMetaverse;
33using log4net; 33using log4net;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Client; 35using OpenSim.Framework.Client;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes.Animation; 37using OpenSim.Region.Framework.Scenes.Animation;
39using OpenSim.Region.Framework.Scenes.Types; 38using OpenSim.Region.Framework.Scenes.Types;
40using OpenSim.Region.Physics.Manager; 39using OpenSim.Region.Physics.Manager;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion; 40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41using OpenSim.Services.Interfaces;
42 42
43namespace OpenSim.Region.Framework.Scenes 43namespace OpenSim.Region.Framework.Scenes
44{ 44{
@@ -150,7 +150,8 @@ namespace OpenSim.Region.Framework.Scenes
150 150
151 private float m_sitAvatarHeight = 2.0f; 151 private float m_sitAvatarHeight = 2.0f;
152 152
153 private float m_godlevel; 153 private int m_godLevel;
154 private int m_userLevel;
154 155
155 private bool m_invulnerable = true; 156 private bool m_invulnerable = true;
156 157
@@ -266,6 +267,8 @@ namespace OpenSim.Region.Framework.Scenes
266 267
267 // For teleports and crossings callbacks 268 // For teleports and crossings callbacks
268 string m_callbackURI; 269 string m_callbackURI;
270 UUID m_originRegionID;
271
269 ulong m_rootRegionHandle; 272 ulong m_rootRegionHandle;
270 273
271 /// <value> 274 /// <value>
@@ -302,9 +305,14 @@ namespace OpenSim.Region.Framework.Scenes
302 get { return m_invulnerable; } 305 get { return m_invulnerable; }
303 } 306 }
304 307
305 public float GodLevel 308 public int UserLevel
309 {
310 get { return m_userLevel; }
311 }
312
313 public int GodLevel
306 { 314 {
307 get { return m_godlevel; } 315 get { return m_godLevel; }
308 } 316 }
309 317
310 public ulong RegionHandle 318 public ulong RegionHandle
@@ -676,6 +684,10 @@ namespace OpenSim.Region.Framework.Scenes
676 m_regionInfo = reginfo; 684 m_regionInfo = reginfo;
677 m_localId = m_scene.AllocateLocalId(); 685 m_localId = m_scene.AllocateLocalId();
678 686
687 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
688
689 m_userLevel = account.UserLevel;
690
679 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 691 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
680 if (gm != null) 692 if (gm != null)
681 m_grouptitle = gm.GetGroupTitle(m_uuid); 693 m_grouptitle = gm.GetGroupTitle(m_uuid);
@@ -866,47 +878,22 @@ namespace OpenSim.Region.Framework.Scenes
866 if (land != null) 878 if (land != null)
867 { 879 {
868 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni. 880 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
869 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) 881 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)
870 { 882 {
871 pos = land.LandData.UserLocation; 883 pos = land.LandData.UserLocation;
872 } 884 }
873 } 885 }
874 } 886 }
875 887
876 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) 888 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
877 { 889 {
878 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
879
880 if (pos.X < 0)
881 {
882 emergencyPos.X = (int)Constants.RegionSize + pos.X;
883 if (!(pos.Y < 0))
884 emergencyPos.Y = pos.Y;
885 if (!(pos.Z < 0))
886 emergencyPos.X = pos.X;
887 }
888 if (pos.Y < 0)
889 {
890 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
891 if (!(pos.X < 0))
892 emergencyPos.X = pos.X;
893 if (!(pos.Z < 0))
894 emergencyPos.Z = pos.Z;
895 }
896 if (pos.Z < 0)
897 {
898 if (!(pos.X < 0))
899 emergencyPos.X = pos.X;
900 if (!(pos.Y < 0))
901 emergencyPos.Y = pos.Y;
902 //Leave as 128
903 }
904
905 m_log.WarnFormat( 890 m_log.WarnFormat(
906 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}", 891 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
907 pos, Name, UUID, emergencyPos); 892 pos, Name, UUID);
908 893
909 pos = emergencyPos; 894 if (pos.X < 0f) pos.X = 0f;
895 if (pos.Y < 0f) pos.Y = 0f;
896 if (pos.Z < 0f) pos.Z = 0f;
910 } 897 }
911 898
912 float localAVHeight = 1.56f; 899 float localAVHeight = 1.56f;
@@ -917,7 +904,7 @@ namespace OpenSim.Region.Framework.Scenes
917 904
918 float posZLimit = 0; 905 float posZLimit = 0;
919 906
920 if (pos.X <Constants.RegionSize && pos.Y < Constants.RegionSize) 907 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
921 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 908 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
922 909
923 float newPosZ = posZLimit + localAVHeight / 2; 910 float newPosZ = posZLimit + localAVHeight / 2;
@@ -1160,8 +1147,10 @@ namespace OpenSim.Region.Framework.Scenes
1160 /// This is called upon a very important packet sent from the client, 1147 /// This is called upon a very important packet sent from the client,
1161 /// so it's client-controlled. Never call this method directly. 1148 /// so it's client-controlled. Never call this method directly.
1162 /// </summary> 1149 /// </summary>
1163 public void CompleteMovement() 1150 public void CompleteMovement(IClientAPI client)
1164 { 1151 {
1152 //m_log.Debug("[SCENE PRESENCE]: CompleteMovement");
1153
1165 Vector3 look = Velocity; 1154 Vector3 look = Velocity;
1166 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1155 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1167 { 1156 {
@@ -1186,7 +1175,7 @@ namespace OpenSim.Region.Framework.Scenes
1186 if ((m_callbackURI != null) && !m_callbackURI.Equals("")) 1175 if ((m_callbackURI != null) && !m_callbackURI.Equals(""))
1187 { 1176 {
1188 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); 1177 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI);
1189 Scene.SendReleaseAgent(m_rootRegionHandle, UUID, m_callbackURI); 1178 Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI);
1190 m_callbackURI = null; 1179 m_callbackURI = null;
1191 } 1180 }
1192 1181
@@ -1194,6 +1183,21 @@ namespace OpenSim.Region.Framework.Scenes
1194 1183
1195 m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); 1184 m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look);
1196 SendInitialData(); 1185 SendInitialData();
1186
1187 // Create child agents in neighbouring regions
1188 if (!m_isChildAgent)
1189 {
1190 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1191 if (m_agentTransfer != null)
1192 m_agentTransfer.EnableChildAgents(this);
1193 else
1194 m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active");
1195
1196 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1197 if (friendsModule != null)
1198 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1199 }
1200
1197 } 1201 }
1198 1202
1199 /// <summary> 1203 /// <summary>
@@ -2397,6 +2401,7 @@ namespace OpenSim.Region.Framework.Scenes
2397 { 2401 {
2398 if (m_isChildAgent) 2402 if (m_isChildAgent)
2399 { 2403 {
2404 // WHAT???
2400 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); 2405 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");
2401 2406
2402 // we have to reset the user's child agent connections. 2407 // we have to reset the user's child agent connections.
@@ -2420,7 +2425,9 @@ namespace OpenSim.Region.Framework.Scenes
2420 2425
2421 if (m_scene.SceneGridService != null) 2426 if (m_scene.SceneGridService != null)
2422 { 2427 {
2423 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>()); 2428 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
2429 if (m_agentTransfer != null)
2430 m_agentTransfer.EnableChildAgents(this);
2424 } 2431 }
2425 2432
2426 return; 2433 return;
@@ -2720,14 +2727,9 @@ namespace OpenSim.Region.Framework.Scenes
2720 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2727 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2721 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); 2728 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot));
2722 2729
2723 if (!m_isChildAgent)
2724 {
2725 m_scene.InformClientOfNeighbours(this);
2726 }
2727
2728 SendInitialFullUpdateToAllClients(); 2730 SendInitialFullUpdateToAllClients();
2729 SendAppearanceToAllOtherAgents(); 2731 SendAppearanceToAllOtherAgents();
2730 } 2732 }
2731 2733
2732 /// <summary> 2734 /// <summary>
2733 /// Tell the client for this scene presence what items it should be wearing now 2735 /// Tell the client for this scene presence what items it should be wearing now
@@ -2809,14 +2811,19 @@ namespace OpenSim.Region.Framework.Scenes
2809 } 2811 }
2810 } 2812 }
2811 } 2813 }
2814
2812 } 2815 }
2813 2816
2817
2814 #endregion Bake Cache Check 2818 #endregion Bake Cache Check
2815 2819
2816 m_appearance.SetAppearance(textureEntry, visualParams); 2820 m_appearance.SetAppearance(textureEntry, visualParams);
2817 if (m_appearance.AvatarHeight > 0) 2821 if (m_appearance.AvatarHeight > 0)
2818 SetHeight(m_appearance.AvatarHeight); 2822 SetHeight(m_appearance.AvatarHeight);
2819 m_scene.CommsManager.AvatarService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance); 2823
2824 // This is not needed, because only the transient data changed
2825 //AvatarData adata = new AvatarData(m_appearance);
2826 //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata);
2820 2827
2821 SendAppearanceToAllOtherAgents(); 2828 SendAppearanceToAllOtherAgents();
2822 if (!m_startAnimationSet) 2829 if (!m_startAnimationSet)
@@ -2836,7 +2843,8 @@ namespace OpenSim.Region.Framework.Scenes
2836 public void SetWearable(int wearableId, AvatarWearable wearable) 2843 public void SetWearable(int wearableId, AvatarWearable wearable)
2837 { 2844 {
2838 m_appearance.SetWearable(wearableId, wearable); 2845 m_appearance.SetWearable(wearableId, wearable);
2839 m_scene.CommsManager.AvatarService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance); 2846 AvatarData adata = new AvatarData(m_appearance);
2847 m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata);
2840 m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); 2848 m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
2841 } 2849 }
2842 2850
@@ -2858,7 +2866,12 @@ namespace OpenSim.Region.Framework.Scenes
2858 /// </summary> 2866 /// </summary>
2859 protected void CheckForSignificantMovement() 2867 protected void CheckForSignificantMovement()
2860 { 2868 {
2861 if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > 0.5) 2869 // Movement updates for agents in neighboring regions are sent directly to clients.
2870 // This value only affects how often agent positions are sent to neighbor regions
2871 // for things such as distance-based update prioritization
2872 const float SIGNIFICANT_MOVEMENT = 2.0f;
2873
2874 if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT)
2862 { 2875 {
2863 posLastSignificantMove = AbsolutePosition; 2876 posLastSignificantMove = AbsolutePosition;
2864 m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); 2877 m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient);
@@ -2869,18 +2882,19 @@ namespace OpenSim.Region.Framework.Scenes
2869 if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance || 2882 if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance ||
2870 Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance) 2883 Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance)
2871 { 2884 {
2885 m_lastChildAgentUpdatePosition = AbsolutePosition;
2886 m_lastChildAgentUpdateCamPosition = CameraPosition;
2887
2872 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); 2888 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
2873 cadu.ActiveGroupID = UUID.Zero.Guid; 2889 cadu.ActiveGroupID = UUID.Zero.Guid;
2874 cadu.AgentID = UUID.Guid; 2890 cadu.AgentID = UUID.Guid;
2875 cadu.alwaysrun = m_setAlwaysRun; 2891 cadu.alwaysrun = m_setAlwaysRun;
2876 cadu.AVHeight = m_avHeight; 2892 cadu.AVHeight = m_avHeight;
2877 sLLVector3 tempCameraCenter = new sLLVector3(new Vector3(m_CameraCenter.X, m_CameraCenter.Y, m_CameraCenter.Z)); 2893 Vector3 tempCameraCenter = m_CameraCenter;
2878 cadu.cameraPosition = tempCameraCenter; 2894 cadu.cameraPosition = tempCameraCenter;
2879 cadu.drawdistance = m_DrawDistance; 2895 cadu.drawdistance = m_DrawDistance;
2880 if (m_scene.Permissions.IsGod(new UUID(cadu.AgentID)))
2881 cadu.godlevel = m_godlevel;
2882 cadu.GroupAccess = 0; 2896 cadu.GroupAccess = 0;
2883 cadu.Position = new sLLVector3(AbsolutePosition); 2897 cadu.Position = AbsolutePosition;
2884 cadu.regionHandle = m_rootRegionHandle; 2898 cadu.regionHandle = m_rootRegionHandle;
2885 float multiplier = 1; 2899 float multiplier = 1;
2886 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); 2900 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount();
@@ -2895,15 +2909,12 @@ namespace OpenSim.Region.Framework.Scenes
2895 2909
2896 //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); 2910 //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString());
2897 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); 2911 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier);
2898 cadu.Velocity = new sLLVector3(Velocity); 2912 cadu.Velocity = Velocity;
2899 2913
2900 AgentPosition agentpos = new AgentPosition(); 2914 AgentPosition agentpos = new AgentPosition();
2901 agentpos.CopyFrom(cadu); 2915 agentpos.CopyFrom(cadu);
2902 2916
2903 m_scene.SendOutChildAgentUpdates(agentpos, this); 2917 m_scene.SendOutChildAgentUpdates(agentpos, this);
2904
2905 m_lastChildAgentUpdatePosition = AbsolutePosition;
2906 m_lastChildAgentUpdateCamPosition = CameraPosition;
2907 } 2918 }
2908 } 2919 }
2909 2920
@@ -3159,18 +3170,21 @@ namespace OpenSim.Region.Framework.Scenes
3159 // For now, assign god level 200 to anyone 3170 // For now, assign god level 200 to anyone
3160 // who is granted god powers, but has no god level set. 3171 // who is granted god powers, but has no god level set.
3161 // 3172 //
3162 CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); 3173 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID);
3163 if (profile.UserProfile.GodLevel > 0) 3174 if (account != null)
3164 m_godlevel = profile.UserProfile.GodLevel; 3175 {
3165 else 3176 if (account.UserLevel > 0)
3166 m_godlevel = 200; 3177 m_godLevel = account.UserLevel;
3178 else
3179 m_godLevel = 200;
3180 }
3167 } 3181 }
3168 else 3182 else
3169 { 3183 {
3170 m_godlevel = 0; 3184 m_godLevel = 0;
3171 } 3185 }
3172 3186
3173 ControllingClient.SendAdminResponse(token, (uint)m_godlevel); 3187 ControllingClient.SendAdminResponse(token, (uint)m_godLevel);
3174 } 3188 }
3175 3189
3176 #region Child Agent Updates 3190 #region Child Agent Updates
@@ -3229,7 +3243,7 @@ namespace OpenSim.Region.Framework.Scenes
3229 public void CopyTo(AgentData cAgent) 3243 public void CopyTo(AgentData cAgent)
3230 { 3244 {
3231 cAgent.AgentID = UUID; 3245 cAgent.AgentID = UUID;
3232 cAgent.RegionHandle = m_rootRegionHandle; 3246 cAgent.RegionID = Scene.RegionInfo.RegionID;
3233 3247
3234 cAgent.Position = AbsolutePosition; 3248 cAgent.Position = AbsolutePosition;
3235 cAgent.Velocity = m_velocity; 3249 cAgent.Velocity = m_velocity;
@@ -3261,7 +3275,7 @@ namespace OpenSim.Region.Framework.Scenes
3261 cAgent.ControlFlags = (uint)m_AgentControlFlags; 3275 cAgent.ControlFlags = (uint)m_AgentControlFlags;
3262 3276
3263 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3277 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3264 cAgent.GodLevel = (byte)m_godlevel; 3278 cAgent.GodLevel = (byte)m_godLevel;
3265 else 3279 else
3266 cAgent.GodLevel = (byte) 0; 3280 cAgent.GodLevel = (byte) 0;
3267 3281
@@ -3328,7 +3342,7 @@ namespace OpenSim.Region.Framework.Scenes
3328 3342
3329 public void CopyFrom(AgentData cAgent) 3343 public void CopyFrom(AgentData cAgent)
3330 { 3344 {
3331 m_rootRegionHandle = cAgent.RegionHandle; 3345 m_originRegionID = cAgent.RegionID;
3332 3346
3333 m_callbackURI = cAgent.CallbackURI; 3347 m_callbackURI = cAgent.CallbackURI;
3334 3348
@@ -3350,7 +3364,7 @@ namespace OpenSim.Region.Framework.Scenes
3350 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; 3364 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags;
3351 3365
3352 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3366 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3353 m_godlevel = cAgent.GodLevel; 3367 m_godLevel = cAgent.GodLevel;
3354 m_setAlwaysRun = cAgent.AlwaysRun; 3368 m_setAlwaysRun = cAgent.AlwaysRun;
3355 3369
3356 uint i = 0; 3370 uint i = 0;
@@ -3708,36 +3722,6 @@ namespace OpenSim.Region.Framework.Scenes
3708 } 3722 }
3709 } 3723 }
3710 3724
3711 public bool CrossAttachmentsIntoNewRegion(ulong regionHandle, bool silent)
3712 {
3713 lock (m_attachments)
3714 {
3715 // Validate
3716 foreach (SceneObjectGroup gobj in m_attachments)
3717 {
3718 if (gobj == null || gobj.IsDeleted)
3719 return false;
3720 }
3721
3722 foreach (SceneObjectGroup gobj in m_attachments)
3723 {
3724 // If the prim group is null then something must have happened to it!
3725 if (gobj != null && gobj.RootPart != null)
3726 {
3727 // Set the parent localID to 0 so it transfers over properly.
3728 gobj.RootPart.SetParentLocalId(0);
3729 gobj.AbsolutePosition = gobj.RootPart.AttachedPos;
3730 gobj.RootPart.IsAttachment = false;
3731 //gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
3732 m_log.DebugFormat("[ATTACHMENT]: Sending attachment {0} to region {1}", gobj.UUID, regionHandle);
3733 m_scene.CrossPrimGroupIntoNewRegion(regionHandle, gobj, silent);
3734 }
3735 }
3736 m_attachments.Clear();
3737
3738 return true;
3739 }
3740 }
3741 3725
3742 public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) 3726 public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene)
3743 { 3727 {
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/Tests/SceneBaseTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
index 8230f32..840039c 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 TryGetAvatar(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..b50d4ca 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;
@@ -95,16 +94,24 @@ 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. 94 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
96 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; 95 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
97 sogd.Enabled = false; 96 sogd.Enabled = false;
98 97
99 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene); 98 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
100 99
101 IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId); 100 try
102 scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero); 101 {
103 102 IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
103 scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
104 }
105 catch (Exception e)
106 {
107 Console.WriteLine("Exception: " + e.StackTrace);
108 }
104 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); 109 SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
110
105 Assert.That(retrievedPart, Is.Not.Null); 111 Assert.That(retrievedPart, Is.Not.Null);
106 112
107 sogd.InventoryDeQueueAndDelete(); 113 sogd.InventoryDeQueueAndDelete();
114
108 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId); 115 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(part.LocalId);
109 Assert.That(retrievedPart2, Is.Null); 116 Assert.That(retrievedPart2, Is.Null);
110 } 117 }
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..68035ca 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -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..6686264 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs
@@ -58,7 +58,7 @@ 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, int> foundAssetUuids = new Dictionary<UUID, int>();