diff options
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs | 237 |
1 files changed, 0 insertions, 237 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs deleted file mode 100644 index 2322d7c..0000000 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs +++ /dev/null | |||
@@ -1,237 +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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Client; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | |||
36 | using OpenMetaverse; | ||
37 | using Nini.Config; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | ||
41 | { | ||
42 | public class InventoryCache | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | protected BaseInventoryConnector m_Connector; | ||
49 | protected List<Scene> m_Scenes; | ||
50 | |||
51 | // The cache proper | ||
52 | protected Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>> m_InventoryCache; | ||
53 | |||
54 | // A cache of userIDs --> ServiceURLs, for HGBroker only | ||
55 | protected Dictionary<UUID, string> m_InventoryURLs = | ||
56 | new Dictionary<UUID, string>(); | ||
57 | |||
58 | public virtual void Init(IConfigSource source, BaseInventoryConnector connector) | ||
59 | { | ||
60 | m_Scenes = new List<Scene>(); | ||
61 | m_InventoryCache = new Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>>(); | ||
62 | m_Connector = connector; | ||
63 | } | ||
64 | |||
65 | public virtual void AddRegion(Scene scene) | ||
66 | { | ||
67 | m_Scenes.Add(scene); | ||
68 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | ||
69 | scene.EventManager.OnClientClosed += OnClientClosed; | ||
70 | } | ||
71 | |||
72 | public virtual void RemoveRegion(Scene scene) | ||
73 | { | ||
74 | if ((m_Scenes != null) && m_Scenes.Contains(scene)) | ||
75 | { | ||
76 | m_Scenes.Remove(scene); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | void OnMakeRootAgent(ScenePresence presence) | ||
81 | { | ||
82 | // Get system folders | ||
83 | |||
84 | // First check if they're here already | ||
85 | lock (m_InventoryCache) | ||
86 | { | ||
87 | if (m_InventoryCache.ContainsKey(presence.UUID)) | ||
88 | { | ||
89 | m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent, system folders for {0} {1} already in cache", presence.Firstname, presence.Lastname); | ||
90 | return; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | // If not, go get them and place them in the cache | ||
95 | Dictionary<AssetType, InventoryFolderBase> folders = CacheSystemFolders(presence.UUID); | ||
96 | CacheInventoryServiceURL(presence.Scene, presence.UUID); | ||
97 | |||
98 | m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent in {0}, fetched system folders for {1} {2}: count {3}", | ||
99 | presence.Scene.RegionInfo.RegionName, presence.Firstname, presence.Lastname, folders.Count); | ||
100 | |||
101 | } | ||
102 | |||
103 | void OnClientClosed(UUID clientID, Scene scene) | ||
104 | { | ||
105 | if (m_InventoryCache.ContainsKey(clientID)) // if it's still in cache | ||
106 | { | ||
107 | ScenePresence sp = null; | ||
108 | foreach (Scene s in m_Scenes) | ||
109 | { | ||
110 | s.TryGetScenePresence(clientID, out sp); | ||
111 | if ((sp != null) && !sp.IsChildAgent && (s != scene)) | ||
112 | { | ||
113 | m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping system folders in cache", | ||
114 | scene.RegionInfo.RegionName, clientID); | ||
115 | return; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | m_log.DebugFormat( | ||
120 | "[INVENTORY CACHE]: OnClientClosed in {0}, user {1} out of sim. Dropping system folders", | ||
121 | scene.RegionInfo.RegionName, clientID); | ||
122 | DropCachedSystemFolders(clientID); | ||
123 | DropInventoryServiceURL(clientID); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Cache a user's 'system' folders. | ||
129 | /// </summary> | ||
130 | /// <param name="userID"></param> | ||
131 | /// <returns>Folders cached</returns> | ||
132 | protected Dictionary<AssetType, InventoryFolderBase> CacheSystemFolders(UUID userID) | ||
133 | { | ||
134 | // If not, go get them and place them in the cache | ||
135 | Dictionary<AssetType, InventoryFolderBase> folders = m_Connector.GetSystemFolders(userID); | ||
136 | |||
137 | if (folders.Count > 0) | ||
138 | lock (m_InventoryCache) | ||
139 | m_InventoryCache.Add(userID, folders); | ||
140 | |||
141 | return folders; | ||
142 | } | ||
143 | |||
144 | /// <summary> | ||
145 | /// Drop a user's cached 'system' folders | ||
146 | /// </summary> | ||
147 | /// <param name="userID"></param> | ||
148 | protected void DropCachedSystemFolders(UUID userID) | ||
149 | { | ||
150 | // Drop system folders | ||
151 | lock (m_InventoryCache) | ||
152 | if (m_InventoryCache.ContainsKey(userID)) | ||
153 | m_InventoryCache.Remove(userID); | ||
154 | } | ||
155 | |||
156 | /// <summary> | ||
157 | /// Get the system folder for a particular asset type | ||
158 | /// </summary> | ||
159 | /// <param name="userID"></param> | ||
160 | /// <param name="type"></param> | ||
161 | /// <returns></returns> | ||
162 | public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) | ||
163 | { | ||
164 | m_log.DebugFormat("[INVENTORY CACHE]: Getting folder for asset type {0} for user {1}", type, userID); | ||
165 | |||
166 | Dictionary<AssetType, InventoryFolderBase> folders = null; | ||
167 | |||
168 | lock (m_InventoryCache) | ||
169 | { | ||
170 | m_InventoryCache.TryGetValue(userID, out folders); | ||
171 | |||
172 | // In some situations (such as non-secured standalones), system folders can be requested without | ||
173 | // the user being logged in. So we need to try caching them here if we don't already have them. | ||
174 | if (null == folders) | ||
175 | CacheSystemFolders(userID); | ||
176 | |||
177 | m_InventoryCache.TryGetValue(userID, out folders); | ||
178 | } | ||
179 | |||
180 | if ((folders != null) && folders.ContainsKey(type)) | ||
181 | { | ||
182 | m_log.DebugFormat( | ||
183 | "[INVENTORY CACHE]: Returning folder {0} as type {1} for {2}", folders[type], type, userID); | ||
184 | |||
185 | return folders[type]; | ||
186 | } | ||
187 | |||
188 | m_log.WarnFormat("[INVENTORY CACHE]: Could not find folder for system type {0} for {1}", type, userID); | ||
189 | |||
190 | return null; | ||
191 | } | ||
192 | |||
193 | /// <summary> | ||
194 | /// Gets the user's inventory URL from its serviceURLs, if the user is foreign, | ||
195 | /// and sticks it in the cache | ||
196 | /// </summary> | ||
197 | /// <param name="userID"></param> | ||
198 | private void CacheInventoryServiceURL(Scene scene, UUID userID) | ||
199 | { | ||
200 | if (scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, userID) == null) | ||
201 | { | ||
202 | // The user does not have a local account; let's cache its service URL | ||
203 | string inventoryURL = string.Empty; | ||
204 | ScenePresence sp = null; | ||
205 | scene.TryGetScenePresence(userID, out sp); | ||
206 | if (sp != null) | ||
207 | { | ||
208 | AgentCircuitData aCircuit = scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); | ||
209 | if (aCircuit.ServiceURLs.ContainsKey("InventoryServerURI")) | ||
210 | { | ||
211 | inventoryURL = aCircuit.ServiceURLs["InventoryServerURI"].ToString(); | ||
212 | if (inventoryURL != null && inventoryURL != string.Empty) | ||
213 | { | ||
214 | inventoryURL = inventoryURL.Trim(new char[] { '/' }); | ||
215 | m_InventoryURLs.Add(userID, inventoryURL); | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | |||
222 | private void DropInventoryServiceURL(UUID userID) | ||
223 | { | ||
224 | lock (m_InventoryURLs) | ||
225 | if (m_InventoryURLs.ContainsKey(userID)) | ||
226 | m_InventoryURLs.Remove(userID); | ||
227 | } | ||
228 | |||
229 | public string GetInventoryServiceURL(UUID userID) | ||
230 | { | ||
231 | if (m_InventoryURLs.ContainsKey(userID)) | ||
232 | return m_InventoryURLs[userID]; | ||
233 | |||
234 | return null; | ||
235 | } | ||
236 | } | ||
237 | } | ||