Пример #1
0
        /// <summary>
        /// Add a Friend Entry to GamePlayer Friends List.
        /// </summary>
        /// <param name="Player">GamePlayer to Add Friend to.</param>
        /// <param name="Friend">Friend's Name to Add</param>
        /// <returns>True if friend was added successfully</returns>
        public bool AddFriendToPlayerList(GamePlayer Player, string Friend)
        {
            if (Player == null)
            {
                throw new ArgumentNullException("Player");
            }

            if (Friend == null)
            {
                throw new ArgumentNullException("Friend");
            }

            Friend = Friend.Trim();

            if (string.IsNullOrEmpty(Friend))
            {
                throw new ArgumentException("Friend need to be a valid non-empty or white space string!", "Friend");
            }

            var success = false;

            if (!PlayersFriendsListsCache.TryUpdate(Player, list => {
                if (list.Contains(Friend))
                {
                    return(list);
                }

                success = true;
                return(list.Concat(new [] { Friend }).ToArray());
            }))
            {
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("Gameplayer ({0}) was not registered in Friends Manager Cache while trying to Add a new Friend ({1})", Player, Friend);
                }
            }

            if (success)
            {
                Player.Out.SendAddFriends(new [] { Friend });
                Player.SerializedFriendsList = this[Player];

                var offlineFriend = Database.SelectObjects <DOLCharacters>("`Name` = @Name", new QueryParameter("@Name", Friend)).FirstOrDefault();

                if (offlineFriend != null)
                {
                    if (!PlayersFriendsStatusCache.TryUpdate(Player, list => list.Where(frd => frd.Name != Friend)
                                                             .Concat(new [] { new FriendStatus(offlineFriend.Name, offlineFriend.Level, offlineFriend.Class, offlineFriend.LastPlayed) })
                                                             .ToArray()))
                    {
                        if (log.IsWarnEnabled)
                        {
                            log.WarnFormat("Gameplayer ({0}) was not registered in Friends Manager Status Cache while trying to Add a new Friend ({1})", Player, Friend);
                        }
                    }
                }
            }

            return(success);
        }
Пример #2
0
        /// <summary>
        /// Remove a Friend Entry from GamePlayer Friends List.
        /// </summary>
        /// <param name="Player">GamePlayer to Add Friend to.</param>
        /// <param name="Friend">Friend's Name to Add</param>
        /// <returns>True if friend was added successfully</returns>
        public bool RemoveFriendFromPlayerList(GamePlayer Player, string Friend)
        {
            if (Player == null)
            {
                throw new ArgumentNullException("Player");
            }

            if (Friend == null)
            {
                throw new ArgumentNullException("Friend");
            }

            Friend = Friend.Trim();

            if (string.IsNullOrEmpty(Friend))
            {
                throw new ArgumentException("Friend need to be a valid non-empty or white space string!", "Friend");
            }

            var success = false;

            if (!PlayersFriendsListsCache.TryUpdate(Player, list => {
                var result = list.Except(new [] { Friend }).ToArray();
                if (result.Length < list.Length)
                {
                    success = true;
                    return(result);
                }

                return(list);
            }))
            {
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("Gameplayer ({0}) was not registered in Friends Manager Cache while trying to Remove a Friend ({1})", Player, Friend);
                }
            }

            if (success)
            {
                Player.Out.SendRemoveFriends(new [] { Friend });
                Player.SerializedFriendsList = this[Player];

                if (!PlayersFriendsStatusCache.TryUpdate(Player, list => list.Where(frd => frd.Name != Friend).ToArray()))
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("Gameplayer ({0}) was not registered in Friends Manager Status Cache while trying to Remove a Friend ({1})", Player, Friend);
                    }
                }
            }

            return(success);
        }