Ejemplo n.º 1
0
    public void Execute()
    {
        Debug.Log("Build test connection.");
        _clientConnection.Connect("127.0.0.1", 6543);
        Debug.Log("Creating streams.");

        Debug.Log("Write login packages");

        string username = UsernameField.text;
        string password = PasswordField.text;

        _packageParser.ParsePackageToStream(new LoginRequestPackage
        {
            Username = username,
            Password = password,
        }, _clientConnection.Writer);

        Debug.Log("Receive Login Response Packages");
        var packageData = _packageParser.ParsePackageFromStream(_clientConnection.Reader);

        Debug.Log($"Received Login Response Package TYPE: {packageData.GetType()} result: {(packageData as LoginResponsePackage).IsValid}");

        MenuManager menuManager = GetComponentInChildren <MenuManager>(true);

        menuManager.RaceSelectionMenu();
    }
Ejemplo n.º 2
0
        public void HandleLoginRequest(ClientConnection connection, LoginRequest parseObjectData)
        {
            logger.LogInformation("Login Request received");
            logger.LogDebug($"Login DATA user: {parseObjectData.Username} PW: {parseObjectData.Password}");

            (bool userNameExists, bool passwordCorrect, int userId) =
                (userRepository.UserExists(parseObjectData.Username, parseObjectData.Password));
            if (!userNameExists)
            {
                logger.LogInformation("Username does not exist");
                return;
            }
            if (!passwordCorrect)
            {
                logger.LogInformation("Incorrect password");
                return;
            }
            packageParser.ParsePackageToStream(new LoginResponse()
            {
                IsValidLogin = true
            }, connection.Writer);
        }
Ejemplo n.º 3
0
        private async void OnPackageReceive(object obj)
        {
            try
            {
                _logger.LogInformation("NetworkService.ReceiveThread successfully started.");
                while (Running)
                {
                    await Task.Delay(1);

                    if (Running)
                    {
                        lock (AddRemoveLocker)
                        {
                            if (++_packageCounter == 1000)
                            {
                                _packageCounter = 0;
                                foreach (ClientConnection client in _clients)
                                {
                                    try
                                    {
                                        _packageParser.ParsePackageToStream(new KeepAllivePackage(), client.Writer);
                                    }
                                    catch (Exception e)
                                    {
                                        //_invalidConnections.Add(client);
                                        _clients.Remove(client);
                                        _logger.LogWarning($"NetworkServices.OnPackageReceive KEEP ALIVE Exception: {e.Message}");
                                    }
                                }
                            }

                            foreach (ClientConnection client in _clients)
                            {
                                if (0 < client.AvailableBytes)
                                {
                                    _logger.LogInformation($"Package from client {client.ConnectionId}");
                                    PackageBase package = _packageParser.ParsePackageFromStream(client.Reader);
                                    _packageDispatcher.DispatchPackage(package, client);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                _logger.LogError("NetworkServices stopped.");
            }
        }
Ejemplo n.º 4
0
        public void HandleLogin(ClientConnection connection, LoginRequestPackage parseObjectData)
        {
            _logger.LogInformation("Login Request");
            _logger.LogDebug($"Login data Username: {parseObjectData.Username}, Password: {parseObjectData.Password}");

            if (!_userRepository.Exists(parseObjectData.Username))
            {
                return;
            }

            (var passwordOK, int userId) = _userRepository.PasswordOK(parseObjectData.Username, parseObjectData.Password);
            if (!passwordOK)
            {
                _logger.LogInformation("Wrong password.");
                return;
            }

            _packageParser.ParsePackageToStream(new LoginResponsePackage {
                IsValid = true
            }, connection.Writer);
        }
 public void SendPackage(Package package)
 {
     packageParser.ParsePackageToStream(package, clientConnection.Writer);
 }