Ejemplo n.º 1
0
        /// <inheritdoc/>
        public void SetOnlineState(Guid characterId, string characterName, int serverId)
        {
            if (!this.OnlineFriends.TryGetValue(characterName, out var observer))
            {
                if (!this.GameServers.TryGetValue(serverId, out var gameServer))
                {
                    return;
                }

                observer = new OnlineFriend(gameServer)
                {
                    PlayerName = characterName,
                    ServerId   = (byte)gameServer.Id
                };
                this.OnlineFriends.Add(characterName, observer);

                using (var context = this.repositoryManager.CreateNewFriendServerContext())
                    using (this.repositoryManager.UseContext(context))
                    {
                        var friendRepository = this.repositoryManager.GetRepository <FriendViewItem, IFriendViewItemRepository <FriendViewItem> >();
                        var friendlist       = friendRepository.GetFriends(characterId);
                        foreach (var friend in friendlist)
                        {
                            if (!friend.Accepted || friend.RequestOpen)
                            {
                                continue;
                            }

                            if (this.OnlineFriends.TryGetValue(friend.FriendName, out var onlineFriend))
                            {
                                observer.AddSubscription(onlineFriend.Subscribe(observer));
                                onlineFriend.AddSubscription(observer.Subscribe(onlineFriend));

                                observer.OnNext(onlineFriend);
                            }
                        }
                    }
            }

            observer.ChangeServer(serverId == InvisibleServerId ? OfflineServerId : serverId);

            if (serverId == OfflineServerId)
            {
                this.OnlineFriends.Remove(observer.PlayerName);
                observer.OnCompleted();
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void SetOnlineState(Guid characterId, string characterName, int serverId)
        {
            if (!this.OnlineFriends.TryGetValue(characterName, out var observer))
            {
                if (!this.GameServers.TryGetValue(serverId, out var gameServer))
                {
                    return;
                }

                observer = new OnlineFriend(gameServer)
                {
                    PlayerName = characterName,
                    ServerId   = (byte)gameServer.Id,
                };
                this.OnlineFriends.Add(characterName, observer);

                using var context = this.persistenceContextProvider.CreateNewFriendServerContext();
                var friends = context.GetFriends(characterId);
                foreach (var friend in friends)
                {
                    if (!friend.Accepted || friend.RequestOpen)
                    {
                        continue;
                    }

                    if (this.OnlineFriends.TryGetValue(friend.FriendName, out var onlineFriend))
                    {
                        observer.AddSubscription(onlineFriend.Subscribe(observer));
                        onlineFriend.AddSubscription(observer.Subscribe(onlineFriend));

                        observer.OnNext(onlineFriend);
                    }
                }
            }

            observer.ChangeServer(serverId == InvisibleServerId ? OfflineServerId : serverId);

            if (serverId == OfflineServerId)
            {
                this.OnlineFriends.Remove(observer.PlayerName);
                observer.OnCompleted();
            }
        }