Exemplo n.º 1
0
        public async Task GetConnectionId()
        {
            var httpContext = this.Context.GetHttpContext();
            var username    = httpContext.Request.Query["username"];

            if (string.IsNullOrEmpty(username))
            {
                username = Context.User.Identity.Name;
            }

            Debug.WriteLine($"GetConnectionId() username={username}");

            if (!string.IsNullOrEmpty(username))
            {
                _connectionManager.AddConnection(username, Context.ConnectionId);
            }


            var group = httpContext.Request.Query["group"];

            if (!string.IsNullOrEmpty(group))
            {
                await AddToGroup(group);
            }
        }
Exemplo n.º 2
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            disposables.Add(host);
            return(host.LogIn(usernameOrEmail, password)
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}",
                         address.ApiUri,
                         usernameOrEmail,
                         successful ? "SUCCEEDED" : "FAILED",
                         isDotCom ? "GitHub.com" : address.WebUri.Host
                         );
                if (successful)
                {
                    if (isDotCom)
                    {
                        GitHubHost = host;
                    }
                    else
                    {
                        EnterpriseHost = host;
                    }
                    connectionManager.AddConnection(address, usernameOrEmail);
                }
            }));
        }
Exemplo n.º 3
0
        public string GetConnectionId()
        {
            var httpContext = Context.GetHttpContext();
            var userId      = httpContext.Request.Query["userId"];

            _connectionManager.AddConnection(userId, Context.ConnectionId);
            return(Context.ConnectionId);
        }
Exemplo n.º 4
0
        public override Task OnConnectedAsync()
        {
            var httpContext = this.Context.GetHttpContext();
            var userName    = httpContext.Request.Query["username"];

            _connectionManager.AddConnection(userName, Context.ConnectionId);
            return(base.OnConnectedAsync());
        }
Exemplo n.º 5
0
        public string GetConnectionId()
        {
            var username = GetUsername();

            _manager.AddConnection(username, Context.ConnectionId);

            return(Context.ConnectionId);
        }
Exemplo n.º 6
0
        public override Task OnConnectedAsync()
        {
            string userId       = _authService.GetCurrentUserId();
            string connectionId = Context.ConnectionId;

            _connectionManager.AddConnection(userId, connectionId);

            return(base.OnConnectedAsync());
        }
Exemplo n.º 7
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            Guard.ArgumentNotNull(address, nameof(address));
            Guard.ArgumentNotEmptyString(usernameOrEmail, nameof(usernameOrEmail));
            Guard.ArgumentNotEmptyString(password, nameof(password));

            var isDotCom = HostAddress.GitHubDotComHostAddress == address;

            return(Observable.Defer(async() =>
            {
                var host = await RepositoryHostFactory.Create(address);

                return host.LogIn(usernameOrEmail, password)
                .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(result =>
                {
                    bool successful = result.IsSuccess();
                    log.Information("Log in to {Host} host '{ApiUri}' with username '{UsernameOrEmail}' {Successful}",
                                    isDotCom ? "GitHub.com" : address.WebUri.Host,
                                    address.ApiUri,
                                    usernameOrEmail,
                                    successful ? "SUCCEEDED" : "FAILED"
                                    );
                    if (successful)
                    {
                        // Make sure that GitHubHost/EnterpriseHost are set when the connections
                        // changed event is raised and likewise that the connection is added when
                        // the property changed notification is sent.
                        if (isDotCom)
                        {
                            githubHost = host;
                        }
                        else
                        {
                            enterpriseHost = host;
                        }

                        connectionManager.AddConnection(address, usernameOrEmail);

                        if (isDotCom)
                        {
                            this.RaisePropertyChanged(nameof(GitHubHost));
                        }
                        else
                        {
                            this.RaisePropertyChanged(nameof(EnterpriseHost));
                        }
                    }
                });
            }));
        }
Exemplo n.º 8
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var msg = message as Event;

            if (msg == null)
            {
            }

            if (!_manager.ConnectionRegisted(context.Channel.Id.AsLongText()))
            {
                if (msg.EventType == EventType.Login)
                {
                    if (_serializer.TryDeserialize <LoginInfo>(msg.Content, out var info))
                    {
                        if (_validator.Validate(info.User, info.Password))
                        {
                            _manager.AddConnection(context.Channel.Id.AsLongText(), new ConnectionInfo(context.Channel));
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }
            else if (msg.EventType == EventType.HeartBeat)
            {
            }
            else if (msg.EventType == EventType.Request)
            {
                if (_serializer.TryDeserialize <ConfigCenterServiceRequest>(msg.Content, out var request))
                {
                }
                else
                {
                    context.FireChannelRead(request);
                }
            }
            else
            {
            }
        }
Exemplo n.º 9
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            return(host.LogIn(usernameOrEmail, password)
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}",
                         address.ApiUri,
                         usernameOrEmail,
                         successful ? "SUCCEEDED" : "FAILED",
                         isDotCom ? "GitHub.com" : address.WebUri.Host
                         );
                if (successful)
                {
                    // Make sure that GitHubHost/EnterpriseHost are set when the connections
                    // changed event is raised and likewise that the connection is added when
                    // the property changed notification is sent.
                    if (isDotCom)
                    {
                        githubHost = host;
                    }
                    else
                    {
                        enterpriseHost = host;
                    }

                    connectionManager.AddConnection(address, usernameOrEmail);

                    if (isDotCom)
                    {
                        this.RaisePropertyChanged(nameof(GitHubHost));
                    }
                    else
                    {
                        this.RaisePropertyChanged(nameof(EnterpriseHost));
                    }
                }
            }));
        }
        public async Task ProcessIncomingPacketAsync(Packet packet)
        {
            if (packet is ConnectionPacket)
            {
                var connectionPacket = packet as ConnectionPacket;
                var acceptPacket     = new AcceptConnectionPacket();

                var addedClient     = _connectionManager.AddConnection(connectionPacket);
                var connectedClient = _connectionManager.GetClientById(addedClient.Id);

                _gameStateManager.AddPlayer(connectedClient.Id);

                var currentWorldState = _gameStateManager.GetLastWorldState();

                await _socketManager.SendAsync(acceptPacket.SetIdentifier(addedClient.Id)
                                               .SetWorldState(currentWorldState)
                                               .Serialize(),
                                               connectedClient);

                await _socketManager.SendAsync(connectionPacket
                                               .SetIdentifier(addedClient.Id)
                                               .Serialize(),
                                               recipients : _connectionManager.GetAllAvailableRecipients(),
                                               except : connectedClient
                                               );
            }

            if (packet is PingPacket)
            {
                var pingPacket = packet as PingPacket;

                _connectionManager.SetAsPinged(pingPacket.ClientId);

                await _clientManager.PingClientAsync(pingPacket.ClientId);
            }

            if (packet is MovementPacket)
            {
                var movementPacket = packet as MovementPacket;

                _gameStateManager.MovePlayer(movementPacket.ClientId, movementPacket.PacketSequenceNumber, movementPacket.Direction);
            }
        }
Exemplo n.º 11
0
        public Task <string> GetConnectionId()
        {
            _connectionManager.AddConnection(Guid.Empty, Context.ConnectionId);

            return(Task.FromResult(Context.ConnectionId));
        }
Exemplo n.º 12
0
 public override async Task OnConnectedAsync() => await _connectionManager.AddConnection(Context.ConnectionId);
Exemplo n.º 13
0
        public async Task ConnectionAddAsync(string userId)
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, userId);

            await _connectionManager.AddConnection(userId, Context.ConnectionId);
        }