diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateUserData.cs | 188 |
1 files changed, 180 insertions, 8 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs index e0f6db7..6076f90 100644 --- a/OpenSim/Data/NHibernate/NHibernateUserData.cs +++ b/OpenSim/Data/NHibernate/NHibernateUserData.cs | |||
@@ -97,11 +97,18 @@ namespace OpenSim.Data.NHibernate | |||
97 | 97 | ||
98 | override public void AddNewUserProfile(UserProfileData profile) | 98 | override public void AddNewUserProfile(UserProfileData profile) |
99 | { | 99 | { |
100 | if (profile.ID == UUID.Zero) | ||
101 | { | ||
102 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add User {0} {1} with zero UUID, throwintg exception as this is programming error ", profile.FirstName, profile.SurName); | ||
103 | return; | ||
104 | } | ||
105 | |||
100 | if (!ExistsUser(profile.ID)) | 106 | if (!ExistsUser(profile.ID)) |
101 | { | 107 | { |
102 | m_log.InfoFormat("[NHIBERNATE] AddNewUserProfile {0}", profile.ID); | 108 | m_log.InfoFormat("[NHIBERNATE] AddNewUserProfile {0}", profile.ID); |
103 | manager.Save(profile); | 109 | manager.Save(profile); |
104 | SetAgentData(profile.ID, profile.CurrentAgent); | 110 | // Agent should not be saved according to BasicUserTest.T015_UserPersistency() |
111 | // SetAgentData(profile.ID, profile.CurrentAgent); | ||
105 | 112 | ||
106 | } | 113 | } |
107 | else | 114 | else |
@@ -131,7 +138,8 @@ namespace OpenSim.Data.NHibernate | |||
131 | if (ExistsUser(profile.ID)) | 138 | if (ExistsUser(profile.ID)) |
132 | { | 139 | { |
133 | manager.Update(profile); | 140 | manager.Update(profile); |
134 | SetAgentData(profile.ID, profile.CurrentAgent); | 141 | // Agent should not be saved according to BasicUserTest.T015_UserPersistency() |
142 | // SetAgentData(profile.ID, profile.CurrentAgent); | ||
135 | return true; | 143 | return true; |
136 | } | 144 | } |
137 | else | 145 | else |
@@ -144,6 +152,19 @@ namespace OpenSim.Data.NHibernate | |||
144 | 152 | ||
145 | override public void AddNewUserAgent(UserAgentData agent) | 153 | override public void AddNewUserAgent(UserAgentData agent) |
146 | { | 154 | { |
155 | if (agent.ProfileID == UUID.Zero) | ||
156 | { | ||
157 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero user id. Agent session id: {0}", agent.SessionID); | ||
158 | return; | ||
159 | } | ||
160 | |||
161 | if (agent.SessionID == UUID.Zero) | ||
162 | { | ||
163 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero session id. User profile id: {0}", agent.SessionID); | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | |||
147 | UserAgentData old = (UserAgentData)manager.Load(typeof(UserAgentData), agent.ProfileID); | 168 | UserAgentData old = (UserAgentData)manager.Load(typeof(UserAgentData), agent.ProfileID); |
148 | if (old != null) | 169 | if (old != null) |
149 | { | 170 | { |
@@ -214,12 +235,163 @@ namespace OpenSim.Data.NHibernate | |||
214 | } | 235 | } |
215 | 236 | ||
216 | // TODO: actually implement these | 237 | // TODO: actually implement these |
217 | public override void StoreWebLoginKey(UUID agentID, UUID webLoginKey) { return; } | 238 | public override void StoreWebLoginKey(UUID agentID, UUID webLoginKey) |
218 | public override void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) { return; } | 239 | { |
219 | public override void RemoveUserFriend(UUID friendlistowner, UUID friend) { return; } | 240 | UserProfileData user=GetUserByUUID(agentID); |
220 | public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) { return; } | 241 | user.WebLoginKey = webLoginKey; |
221 | public override List<FriendListItem> GetUserFriendList(UUID friendlistowner) { return new List<FriendListItem>(); } | 242 | UpdateUserProfile(user); |
222 | public override Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids) { return new Dictionary<UUID, FriendRegionInfo>(); } | 243 | return; |
244 | } | ||
245 | |||
246 | public override void AddNewUserFriend(UUID ownerId, UUID friendId, uint perms) | ||
247 | { | ||
248 | if (!FriendRelationExists(ownerId,friendId)) | ||
249 | { | ||
250 | manager.Save(new UserFriend(UUID.Random(), ownerId, friendId, perms)); | ||
251 | } | ||
252 | if (!FriendRelationExists(friendId, ownerId)) | ||
253 | { | ||
254 | manager.Save(new UserFriend(UUID.Random(), friendId, ownerId, perms)); | ||
255 | } | ||
256 | return; | ||
257 | } | ||
258 | |||
259 | private bool FriendRelationExists(UUID ownerId, UUID friendId) | ||
260 | { | ||
261 | using (ISession session = manager.GetSession()) | ||
262 | { | ||
263 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
264 | criteria.Add(Expression.Eq("OwnerID", ownerId)); | ||
265 | criteria.Add(Expression.Eq("FriendID", friendId)); | ||
266 | return criteria.List().Count > 0; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | public override void RemoveUserFriend(UUID ownerId, UUID friendId) | ||
271 | { | ||
272 | using (ISession session = manager.GetSession()) | ||
273 | { | ||
274 | using (ITransaction transaction = session.BeginTransaction()) | ||
275 | { | ||
276 | |||
277 | { | ||
278 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
279 | criteria.Add(Expression.Eq("OwnerID", ownerId)); | ||
280 | criteria.Add(Expression.Eq("FriendID", friendId)); | ||
281 | |||
282 | foreach (UserFriend userFriend in criteria.List()) | ||
283 | { | ||
284 | session.Delete(userFriend); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | { | ||
289 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
290 | criteria.Add(Expression.Eq("OwnerID", friendId)); | ||
291 | criteria.Add(Expression.Eq("FriendID", ownerId)); | ||
292 | |||
293 | foreach (UserFriend userFriend in criteria.List()) | ||
294 | { | ||
295 | session.Delete(userFriend); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | transaction.Commit(); | ||
300 | } | ||
301 | } | ||
302 | return; | ||
303 | } | ||
304 | |||
305 | |||
306 | public override void UpdateUserFriendPerms(UUID ownerId, UUID friendId, uint perms) | ||
307 | { | ||
308 | using (ISession session = manager.GetSession()) | ||
309 | { | ||
310 | using (ITransaction transaction = session.BeginTransaction()) | ||
311 | { | ||
312 | { | ||
313 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
314 | criteria.Add(Expression.Eq("OwnerID", ownerId)); | ||
315 | criteria.Add(Expression.Eq("FriendID", friendId)); | ||
316 | |||
317 | foreach (UserFriend userFriend in criteria.List()) | ||
318 | { | ||
319 | userFriend.FriendPermissions = perms; | ||
320 | session.Update(userFriend); | ||
321 | } | ||
322 | } | ||
323 | transaction.Commit(); | ||
324 | } | ||
325 | } | ||
326 | return; | ||
327 | } | ||
328 | |||
329 | public override List<FriendListItem> GetUserFriendList(UUID ownerId) | ||
330 | { | ||
331 | List<FriendListItem> friendList=new List<FriendListItem>(); | ||
332 | Dictionary<UUID, FriendListItem> friendListItemDictionary = new Dictionary<UUID, FriendListItem>(); | ||
333 | |||
334 | using (ISession session = manager.GetSession()) | ||
335 | { | ||
336 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
337 | criteria.Add(Expression.Or( | ||
338 | Expression.Eq("OwnerID", ownerId), | ||
339 | Expression.Eq("FriendID", ownerId) | ||
340 | )); | ||
341 | |||
342 | foreach (UserFriend userFriend in criteria.List()) | ||
343 | { | ||
344 | if (userFriend.OwnerID == ownerId) | ||
345 | { | ||
346 | FriendListItem friendListItem = new FriendListItem(); | ||
347 | friendListItem.FriendListOwner = userFriend.OwnerID; | ||
348 | friendListItem.Friend = userFriend.FriendID; | ||
349 | friendListItem.FriendPerms = userFriend.FriendPermissions; | ||
350 | friendListItemDictionary.Add(userFriend.FriendID, friendListItem); | ||
351 | friendList.Add(friendListItem); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | // Reading permissions to other direction | ||
356 | foreach (UserFriend userFriend in criteria.List()) | ||
357 | { | ||
358 | if (userFriend.FriendID == ownerId) | ||
359 | { | ||
360 | //Ignore if there is no reverse relation existing. | ||
361 | //if (friendListItemDictionary.ContainsKey(userFriend.OwnerID)) | ||
362 | { | ||
363 | FriendListItem friendListItem = friendListItemDictionary[userFriend.OwnerID]; | ||
364 | friendListItem.FriendListOwnerPerms = userFriend.FriendPermissions; | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | |||
369 | } | ||
370 | |||
371 | return friendList; | ||
372 | } | ||
373 | |||
374 | |||
375 | public override Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> friendsIds) | ||
376 | { | ||
377 | Dictionary<UUID, FriendRegionInfo> friendRegionInfos=new Dictionary<UUID, FriendRegionInfo>(); | ||
378 | |||
379 | foreach(UUID friendId in friendsIds) | ||
380 | { | ||
381 | UserAgentData agent=GetAgentByUUID(friendId); | ||
382 | if (agent != null) | ||
383 | { | ||
384 | FriendRegionInfo fri = new FriendRegionInfo(); | ||
385 | fri.isOnline = agent.AgentOnline; | ||
386 | fri.regionHandle = agent.Handle; | ||
387 | |||
388 | friendRegionInfos[friendId] = fri; | ||
389 | } | ||
390 | } | ||
391 | |||
392 | return friendRegionInfos; | ||
393 | } | ||
394 | |||
223 | public override bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return true; } | 395 | public override bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return true; } |
224 | public override bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return true; } | 396 | public override bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return true; } |
225 | 397 | ||