/// <summary> /// Cache the friends list or increment the refcount for the existing friends list. /// </summary> /// <param name="client"> /// </param> /// <returns> /// Returns true if the list was fetched, false if it wasn't /// </returns> protected virtual bool CacheFriends(IClientAPI client) { bool result = false; UserFriendData friendsData; UUID agentID = client.AgentId; if (!m_Friends.TryGetValue(agentID, out friendsData)) { /* better to do some unnecessary fetches outside of an WriterLock instead of trying to reduce that and locking up the FriendsModule */ friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Friends = GetFriendsFromService(client); try { m_Friends.AddIfNotExists(agentID, delegate() { result = true; return(friendsData); }); } catch (ThreadedClasses.RwLockedDictionary <UUID, UserFriendData> .KeyAlreadyExistsException) { } } return(result); }
private void OnNewClient(IClientAPI client) { client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += OnTerminateFriendship; client.OnGrantUserRights += OnGrantUserRights; // Asynchronously fetch the friends list or increment the refcount for the existing // friends list Util.FireAndForget( delegate(object o) { lock (m_Friends) { UserFriendData friendsData; if (m_Friends.TryGetValue(client.AgentId, out friendsData)) { friendsData.Refcount++; } else { friendsData = new UserFriendData(); friendsData.PrincipalID = client.AgentId; friendsData.Friends = FriendsService.GetFriends(client.AgentId); friendsData.Refcount = 1; m_Friends[client.AgentId] = friendsData; } } } ); }
public void Show(User user) { try { var userAddingFriendData = new UserFriendData(); Console.WriteLine("Введите почтовый адрес пользователя которого хотите добавить в друзья: "); userAddingFriendData.FriendEmail = Console.ReadLine(); userAddingFriendData.UserId = user.Id; this.userService.AddFriend(userAddingFriendData); SuccessMessage.Show("Вы успешно добавили пользователя в друзья!"); } catch (UserNotFoundException) { AlertMessage.Show("Пользователя с указанным почтовым адресом не существует!"); } catch (Exception) { AlertMessage.Show("Произоша ошибка при добавлении пользотваеля в друзья!"); } }
private void OnNewClient(IClientAPI client) { client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += OnTerminateFriendship; client.OnGrantUserRights += OnGrantUserRights; lock (m_Friends) { if (m_Friends.ContainsKey(client.AgentId)) { m_Friends[client.AgentId].Refcount++; return; } UserFriendData newFriends = new UserFriendData(); newFriends.PrincipalID = client.AgentId; newFriends.Friends = m_FriendsService.GetFriends(client.AgentId); newFriends.Refcount = 1; newFriends.RegionID = UUID.Zero; m_Friends.Add(client.AgentId, newFriends); } }
private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) { if (!m_Friends.ContainsKey(remoteClient.AgentId)) { return; } m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); // Let's find the friend in this user's friend list UserFriendData fd = m_Friends[remoteClient.AgentId]; FriendInfo friend = null; foreach (FriendInfo fi in fd.Friends) { if (fi.Friend == target.ToString()) { friend = fi; } } if (friend != null) // Found it { // Store it on the DB FriendsService.StoreFriend(requester, target.ToString(), rights); // Store it in the local cache int myFlags = friend.MyFlags; friend.MyFlags = rights; // Always send this back to the original client remoteClient.SendChangeUserRights(requester, target, rights); // // Notify the friend // // Try local if (LocalGrantRights(requester, target, myFlags, rights)) { return; } PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() }); if (friendSessions != null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); // TODO: You might want to send the delta to save the lookup // on the other end!! m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights); } } } }
private void UpdateFriendsCache(UUID agentID) { UserFriendData friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Refcount = 0; friendsData.Friends = FriendsService.GetFriends(agentID); lock (m_Friends) { m_Friends[agentID] = friendsData; } }
private void UpdateFriendsCache(UUID agentID) { UserFriendData friendsData = new UserFriendData { PrincipalID = agentID, Refcount = 0, Friends = FriendsService.GetFriends(agentID).ToArray() }; lock (m_Friends) { m_Friends[agentID] = friendsData; } }
public uint GetFriendPerms(UUID principalID, UUID friendID) { if (!m_Friends.ContainsKey(principalID)) { return(0); } UserFriendData data = m_Friends[principalID]; foreach (FriendInfo fi in data.Friends) { if (fi.Friend == friendID.ToString()) { return((uint)fi.TheirFlags); } } return(0); }
public void AddFriend(UserFriendData userAddingFriendData) { var findUserEntity = userRepository.FindByEmail(userAddingFriendData.FriendEmail); if (findUserEntity is null) { throw new UserNotFoundException(); } var friendEntity = new FriendEntity() { user_id = userAddingFriendData.UserId, friend_id = findUserEntity.Id }; if (this.friendRepository.Create(friendEntity) == 0) { throw new Exception(); } }
/// <summary> /// Cache the friends list or increment the refcount for the existing friends list. /// </summary> /// <param name="client"> /// </param> /// <returns> /// Returns true if the list was fetched, false if it wasn't /// </returns> protected virtual bool CacheFriends(IClientAPI client) { UUID agentID = client.AgentId; lock (m_Friends) { UserFriendData friendsData; if (m_Friends.TryGetValue(agentID, out friendsData)) { friendsData.Refcount++; return(false); } else { friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Friends = GetFriendsFromService(client); friendsData.Refcount = 1; m_Friends[agentID] = friendsData; return(true); } } }
private void UpdateFriendsCache(UUID agentID) { UserFriendData friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Refcount = 0; friendsData.Friends = FriendsService.GetFriends(agentID); lock (m_Friends) { m_Friends[agentID] = friendsData; } }
/// <summary> /// Cache the friends list or increment the refcount for the existing friends list. /// </summary> /// <param name="client"> /// </param> /// <returns> /// Returns true if the list was fetched, false if it wasn't /// </returns> protected virtual bool CacheFriends(IClientAPI client) { UUID agentID = client.AgentId; lock (m_Friends) { UserFriendData friendsData; if (m_Friends.TryGetValue(agentID, out friendsData)) { friendsData.Refcount++; return false; } else { friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Friends = GetFriendsFromService(client); friendsData.Refcount = 1; m_Friends[agentID] = friendsData; return true; } } }
private void OnMakeRootAgent(ScenePresence sp) { UUID agentID = sp.ControllingClient.AgentId; Util.FireAndForget( delegate(object o) { lock (m_Friends) { UserFriendData friendsData; if (m_Friends.TryGetValue(agentID, out friendsData)) { friendsData.Refcount++; } else { friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Friends = FriendsService.GetFriends(agentID); friendsData.Refcount = 1; m_Friends[agentID] = friendsData; } } // Inform the friends that this user is online StatusChange(agentID, true); // Register that we need to send the list of online friends to this user lock (m_NeedsListOfFriends) m_NeedsListOfFriends.Add(agentID); UpdateFriendsCache(agentID); } ); }
private void OnNewClient(IClientAPI client) { client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += OnTerminateFriendship; client.OnGrantUserRights += OnGrantUserRights; // Asynchronously fetch the friends list or increment the refcount for the existing // friends list Util.FireAndForget( delegate(object o) { lock (m_Friends) { UserFriendData friendsData; if (m_Friends.TryGetValue(client.AgentId, out friendsData)) { friendsData.Refcount++; } else { friendsData = new UserFriendData(); friendsData.PrincipalID = client.AgentId; friendsData.Friends = FriendsService.GetFriends(client.AgentId); friendsData.Refcount = 1; m_Friends[client.AgentId] = friendsData; } } } ); }
/// <summary> /// Cache the friends list or increment the refcount for the existing friends list. /// </summary> /// <param name="client"> /// </param> /// <returns> /// Returns true if the list was fetched, false if it wasn't /// </returns> protected virtual bool CacheFriends(IClientAPI client) { bool result = false; UserFriendData friendsData; UUID agentID = client.AgentId; if (!m_Friends.TryGetValue(agentID, out friendsData)) { /* better to do some unnecessary fetches outside of an WriterLock instead of trying to reduce that and locking up the FriendsModule */ friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Friends = GetFriendsFromService(client); try { m_Friends.AddIfNotExists(agentID, delegate() { result = true; return friendsData; }); } catch(ThreadedClasses.RwLockedDictionary<UUID, UserFriendData>.KeyAlreadyExistsException) { } } return result; }
private void UpdateFriendsCache(UUID agentID) { UserFriendData friendsData = new UserFriendData { PrincipalID = agentID, Refcount = 0, Friends = FriendsService.GetFriends(agentID).ToArray() }; lock (m_Friends) { m_Friends[agentID] = friendsData; } }
private void OnNewClient(IClientAPI client) { client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += OnTerminateFriendship; client.OnGrantUserRights += OnGrantUserRights; client.OnLogout += OnLogout; if (m_Friends.ContainsKey(client.AgentId)) { m_Friends[client.AgentId].Refcount++; return; } UserFriendData newFriends = new UserFriendData(); newFriends.PrincipalID = client.AgentId; newFriends.Friends = m_FriendsService.GetFriends(client.AgentId); newFriends.Refcount = 1; newFriends.RegionID = UUID.Zero; m_Friends.Add(client.AgentId, newFriends); //StatusChange(client.AgentId, true); }
private void OnMakeRootAgent(ScenePresence sp) { UUID agentID = sp.ControllingClient.AgentId; Util.FireAndForget( delegate(object o) { lock (m_Friends) { UserFriendData friendsData; if (m_Friends.TryGetValue(agentID, out friendsData)) { friendsData.Refcount++; } else { friendsData = new UserFriendData(); friendsData.PrincipalID = agentID; friendsData.Friends = FriendsService.GetFriends(agentID); friendsData.Refcount = 1; m_Friends[agentID] = friendsData; } } //Only update friends and send status changes if the client is logging in if ((sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID).teleportFlags & (uint)TeleportFlags.ViaLogin) != 0) { // Inform the friends that this user is online StatusChange(agentID, true); // Register that we need to send the list of online friends to this user lock (m_NeedsListOfFriends) m_NeedsListOfFriends.Add(agentID); UpdateFriendsCache(agentID); } } ); }