aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
diff options
context:
space:
mode:
authorMW2007-12-02 13:59:15 +0000
committerMW2007-12-02 13:59:15 +0000
commit80609c2b1572d9b946675db486fc46e327171cfa (patch)
tree85a623c1a75255d74883c3f9ba11e5f66a053a18 /OpenSim/Framework/Communications/Cache/UserProfileCache.cs
parentNew Inventory folder should now be stored to the inventory server/database. T... (diff)
downloadopensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.zip
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.gz
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.bz2
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.xz
Some refactoring , mainly on Inventory code.
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/UserProfileCache.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/UserProfileCache.cs203
1 files changed, 0 insertions, 203 deletions
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
deleted file mode 100644
index 3c8ab51..0000000
--- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
+++ /dev/null
@@ -1,203 +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 OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System.Collections.Generic;
29using libsecondlife;
30
31namespace OpenSim.Framework.Communications.Cache
32{
33 public class UserProfileCache
34 {
35 // Fields
36 private readonly CommunicationsManager m_parent;
37 private readonly Dictionary<LLUUID, CachedUserInfo> m_userProfiles = new Dictionary<LLUUID, CachedUserInfo>();
38
39 public LibraryRootFolder libraryRoot = new LibraryRootFolder();
40
41 // Methods
42 public UserProfileCache(CommunicationsManager parent)
43 {
44 m_parent = parent;
45 }
46
47 /// <summary>
48 /// A new user has moved into a region in this instance
49 /// so get info from servers
50 /// </summary>
51 /// <param name="userID"></param>
52 public void AddNewUser(LLUUID userID)
53 {
54 // Potential fix - Multithreading issue.
55 lock (m_userProfiles)
56 {
57 if (!m_userProfiles.ContainsKey(userID))
58 {
59 CachedUserInfo userInfo = new CachedUserInfo(m_parent);
60 userInfo.UserProfile = m_parent.UserService.GetUserProfile(userID);
61
62 if (userInfo.UserProfile != null)
63 {
64 RequestInventoryForUser(userID, userInfo);
65 m_userProfiles.Add(userID, userInfo);
66 }
67 else
68 {
69 System.Console.WriteLine("CACHE", "User profile for user not found");
70 }
71 }
72 }
73 }
74
75 public CachedUserInfo GetUserDetails(LLUUID userID)
76 {
77 if (m_userProfiles.ContainsKey(userID))
78 return m_userProfiles[userID];
79 else
80 return null;
81 }
82
83 public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType,
84 string folderName, LLUUID parentID)
85 {
86 CachedUserInfo userProfile;
87
88 if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
89 {
90 if (userProfile.RootFolder != null)
91 {
92 if (userProfile.RootFolder.folderID == parentID)
93 {
94 InventoryFolderImpl createdFolder =
95 userProfile.RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
96
97 if (createdFolder != null)
98 {
99 InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
100 createdBaseFolder.agentID = createdFolder.agentID;
101 createdBaseFolder.folderID = createdFolder.folderID;
102 createdBaseFolder.name = createdFolder.name;
103 createdBaseFolder.parentID = createdFolder.parentID;
104 createdBaseFolder.type = createdFolder.type;
105 createdBaseFolder.version = createdFolder.version;
106 m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdBaseFolder);
107 }
108 }
109 else
110 {
111 InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(parentID);
112 if (folder != null)
113 {
114 folder.CreateNewSubFolder(folderID, folderName, folderType);
115 }
116 }
117 }
118 }
119 }
120
121 /// <summary>
122 /// Tell the client about the various child items and folders contained in the requested folder.
123 /// </summary>
124 /// <param name="remoteClient"></param>
125 /// <param name="folderID"></param>
126 /// <param name="ownerID"></param>
127 /// <param name="fetchFolders"></param>
128 /// <param name="fetchItems"></param>
129 /// <param name="sortOrder"></param>
130 public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID,
131 bool fetchFolders, bool fetchItems, int sortOrder)
132 {
133 InventoryFolderImpl fold = null;
134 if (folderID == libraryRoot.folderID)
135 {
136 remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID,
137 libraryRoot.RequestListOfItems(), libraryRoot.SubFoldersCount);
138
139 return;
140 }
141
142 if ((fold = libraryRoot.HasSubFolder(folderID)) != null)
143 {
144 remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems(), fold.SubFoldersCount);
145
146 return;
147 }
148
149 CachedUserInfo userProfile;
150 if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
151 {
152 if (userProfile.RootFolder != null)
153 {
154 if (userProfile.RootFolder.folderID == folderID)
155 {
156 if (fetchItems)
157 {
158 remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID,
159 userProfile.RootFolder.RequestListOfItems(), userProfile.RootFolder.SubFoldersCount);
160 }
161 }
162 else
163 {
164 InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(folderID);
165
166 if (fetchItems && folder != null)
167 {
168 remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems(), folder.SubFoldersCount);
169 }
170 }
171 }
172 }
173 }
174
175 public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID)
176 {
177 if (ownerID == libraryRoot.agentID)
178 {
179 //Console.WriteLine("request info for library item");
180
181 return;
182 }
183
184 CachedUserInfo userProfile;
185 if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
186 {
187 if (userProfile.RootFolder != null)
188 {
189 InventoryItemBase item = userProfile.RootFolder.HasItem(itemID);
190 if (item != null)
191 {
192 remoteClient.SendInventoryItemDetails(ownerID, item);
193 }
194 }
195 }
196 }
197
198 private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo)
199 {
200 m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive);
201 }
202 }
203}