Exemplo n.º 1
0
        public void Run(IList <Message> messages)
        {
            foreach (var message in messages.Where(m => m.System == SystemTypes.Movement))
            {
                switch (message.Type)
                {
                case SystemTypes.MovementTypes.Move:
                    ProcessMovementRequest(message);
                    break;
                }
            }

            foreach (var(key, movement) in _movementRepository.GetAll())
            {
                var traveledTime = (movement.StartTime + movement.TravelTime);
                if (traveledTime <= DateTimeOffset.Now.ToUnixTimeMilliseconds())
                {
                    var node = movement.Nodes.Last();
                    _positionRepository.SetPlayerPosition(movement.Player, node);

                    _movementRepository.Remove(key);

                    _movementSender.SetPosition(movement.Player, node);

                    _locationSender.Update(movement.Player.Node);
                    _locationSender.Update(node);
                }
            }
        }
Exemplo n.º 2
0
        private void SendPlayerInformation(Player player, ClientConnection connection, string token)
        {
            var currentConnection = _socketRepository.GetConnection(player.Id);

            if (currentConnection != null)
            {
                _loginSender.Logout(currentConnection);
            }

            _socketRepository.AddConnection(player.Id, connection);
            //_positionRepository.SetPlayerPosition(player, player.Node);

            _loginSender.Success(player, token);
            _joinSender.Join(player);
            _locationSender.Update(player.Node);
        }
Exemplo n.º 3
0
        public void HandleDeadPlayers()
        {
            var connections = _socketRepository.GetAllConnections();
            var timeouts    = connections.Where(x => x.TcpClient == null || x.IsTimedOut()).ToList();

            foreach (var timeout in timeouts)
            {
                Player player   = null;
                var    playerId = _socketRepository.GetPlayerId(timeout.Id);

                if (playerId.HasValue)
                {
                    player = _playerRepository.GetPlayerById(playerId.Value);
                }

                Console.WriteLine($"Connection removed: {timeout.Id} - {timeout.LastMessage}");
                _socketRepository.RemoveConnection(timeout.Id);

                if (player != null)
                {
                    _locationSender.Update(player.Node);
                }
            }
        }