Beispiel #1
0
        /// <summary>
        /// Add Player to Friends Manager Cache
        /// </summary>
        /// <param name="Player">Gameplayer to Add</param>
        public void AddPlayerFriendsListToCache(GamePlayer Player)
        {
            if (Player == null)
            {
                throw new ArgumentNullException("Player");
            }

            var friends = Player.SerializedFriendsList;

            if (!PlayersFriendsListsCache.AddIfNotExists(Player, friends))
            {
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("Gameplayer ({0}) is already registered in Friends Manager Cache while adding!", Player);
                }
            }

            var offlineFriends = new FriendStatus[0];

            if (friends.Any())
            {
                offlineFriends = Database.SelectObjects <DOLCharacters>("`Name` = @Name", friends.Select(name => new[] { new QueryParameter("@Name", name) })).SelectMany(chars => chars)
                                 .Select(chr => new FriendStatus(chr.Name, chr.Level, chr.Class, chr.LastPlayed)).ToArray();
            }

            if (!PlayersFriendsStatusCache.AddIfNotExists(Player, offlineFriends))
            {
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("Gameplayer ({0}) is already registered in Friends Manager Status Cache while adding!", Player);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Notify Friends of this Player that he exited Game
        /// </summary>
        /// <param name="Player">GamePlayer to notify to friends</param>
        private void NotifyPlayerFriendsExitingGame(GamePlayer Player)
        {
            var playerName   = Player.Name;
            var playerUpdate = new [] { playerName };

            foreach (GamePlayer friend in PlayersFriendsListsCache.Where(kv => kv.Value.Contains(playerName)).Select(kv => kv.Key))
            {
                friend.Out.SendRemoveFriends(playerUpdate);
            }

            var offline = new FriendStatus(Player.Name, Player.Level, Player.CharacterClass.ID, DateTime.Now);

            PlayersFriendsStatusCache.FreezeWhile(dict => {
                foreach (var list in dict.Where(kv => kv.Value.Any(frd => frd.Name == Player.Name)).ToArray())
                {
                    dict[list.Key] = list.Value.Where(frd => frd.Name != Player.Name).Concat(new [] { offline }).ToArray();
                }
            });
        }
		/// <summary>
		/// Add Player to Friends Manager Cache
		/// </summary>
		/// <param name="Player">Gameplayer to Add</param>
		public void AddPlayerFriendsListToCache(GamePlayer Player)
		{
			if (Player == null)
				throw new ArgumentNullException("Player");

			var friends = Player.SerializedFriendsList;
			
			if (!PlayersFriendsListsCache.AddIfNotExists(Player, friends))
			{
				if (log.IsWarnEnabled)
					log.WarnFormat("Gameplayer ({0}) is already registered in Friends Manager Cache while adding!", Player);
			}
			
			var offlineFriends = new FriendStatus[0];
			if (friends.Any())
			{
				offlineFriends = Database.SelectObjects<DOLCharacters>("`Name` = @Name", friends.Select(name => new[] { new QueryParameter("@Name", name) })).SelectMany(chars => chars)
					.Select(chr => new FriendStatus(chr.Name, chr.Level, chr.Class, chr.LastPlayed)).ToArray();
			}
			
			if (!PlayersFriendsStatusCache.AddIfNotExists(Player, offlineFriends))
			{
				if (log.IsWarnEnabled)
					log.WarnFormat("Gameplayer ({0}) is already registered in Friends Manager Status Cache while adding!", Player);
			}
			
		}
		/// <summary>
		/// Notify Friends of this Player that he exited Game
		/// </summary>
		/// <param name="Player">GamePlayer to notify to friends</param>
		private void NotifyPlayerFriendsExitingGame(GamePlayer Player)
		{
			var playerName = Player.Name;
			var playerUpdate = new [] { playerName };
			
			foreach (GamePlayer friend in PlayersFriendsListsCache.Where(kv => kv.Value.Contains(playerName)).Select(kv => kv.Key))
			{
				friend.Out.SendRemoveFriends(playerUpdate);
			}
			
			var offline = new FriendStatus(Player.Name, Player.Level, Player.CharacterClass.ID, DateTime.Now);
			
			PlayersFriendsStatusCache.FreezeWhile(dict => {
			                                      	foreach (var list in dict.Where(kv => kv.Value.Any(frd => frd.Name == Player.Name)).ToArray())
			                                      		dict[list.Key] = list.Value.Where(frd => frd.Name != Player.Name).Concat(new [] { offline }).ToArray();
			                                      });
		}