1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
using OpenSim.Framework.Interfaces;
using OpenSim.Framework.Data;
using OpenSim.Framework.Communications;
namespace OpenSim.Framework.Communications.Caches
{
public class UserProfileCache
{
public Dictionary<LLUUID, CachedUserInfo> UserProfiles = new Dictionary<LLUUID, CachedUserInfo>();
private CommunicationsManager m_parent;
public UserProfileCache(CommunicationsManager parent)
{
m_parent = parent;
}
/// <summary>
/// A new user has moved into a region in this instance
/// so get info from servers
/// </summary>
/// <param name="userID"></param>
public void AddNewUser(LLUUID userID)
{
if (!this.UserProfiles.ContainsKey(userID))
{
CachedUserInfo userInfo = new CachedUserInfo();
userInfo.UserProfile = this.RequestUserProfileForUser(userID);
if (userInfo.UserProfile != null)
{
this.RequestInventoryForUser(userID, userInfo);
this.UserProfiles.Add(userID, userInfo);
}
else
{
//no profile for this user, what do we do now?
Console.WriteLine("UserProfileCache.cs: user profile for user not found");
}
}
else
{
//already have a cached profile for this user
//we should make sure its upto date with the user server version
}
}
/// <summary>
/// A new user has moved into a region in this instance
/// so get info from servers
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
public void AddNewUser(string firstName, string lastName)
{
}
/// <summary>
/// A user has left this instance
/// so make sure servers have been updated
/// Then remove cached info
/// </summary>
/// <param name="userID"></param>
public void UserLogOut(LLUUID userID)
{
}
public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, string folderName, LLUUID parentID)
{
if (this.UserProfiles.ContainsKey(remoteClient.AgentId))
{
CachedUserInfo userInfo = this.UserProfiles[remoteClient.AgentId];
if (userInfo.RootFolder.folderID == parentID)
{
userInfo.RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
}
else
{
InventoryFolder parentFolder = userInfo.RootFolder.HasSubFolder(parentID);
if (parentFolder != null)
{
parentFolder.CreateNewSubFolder(folderID, folderName, folderType);
}
}
}
}
public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
{
if (this.UserProfiles.ContainsKey(remoteClient.AgentId))
{
CachedUserInfo userInfo = this.UserProfiles[remoteClient.AgentId];
if (userInfo.RootFolder.folderID == folderID)
{
if (fetchItems)
{
remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, userInfo.RootFolder.RequestListOfItems());
}
}
else
{
InventoryFolder parentFolder = userInfo.RootFolder.HasSubFolder(folderID);
if(parentFolder != null)
{
if(fetchItems)
{
remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, parentFolder.RequestListOfItems());
}
}
}
}
}
/// <summary>
/// Request the user profile from User server
/// </summary>
/// <param name="userID"></param>
private UserProfileData RequestUserProfileForUser(LLUUID userID)
{
return this.m_parent.UserServer.GetUserProfile(userID);
}
/// <summary>
/// Request Iventory Info from Inventory server
/// </summary>
/// <param name="userID"></param>
private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo)
{
// this.m_parent.InventoryServer.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive);
//for now we manually create the root folder,
// but should be requesting all inventory from inventory server.
InventoryFolder rootFolder = new InventoryFolder();
rootFolder.agentID = userID;
rootFolder.folderID = userInfo.UserProfile.rootInventoryFolderID;
rootFolder.name = "My Inventory";
rootFolder.parentID = LLUUID.Zero;
rootFolder.type = 8;
rootFolder.version = 1;
userInfo.FolderReceive(userID, rootFolder);
}
/// <summary>
/// Make sure UserProfile is updated on user server
/// </summary>
/// <param name="userID"></param>
private void UpdateUserProfileToServer(LLUUID userID)
{
}
/// <summary>
/// Update Inventory data to Inventory server
/// </summary>
/// <param name="userID"></param>
private void UpdateInventoryToServer(LLUUID userID)
{
}
}
}
|