Exemplo n.º 1
0
        public List <Message> ConvertToMessages(List <WebSocketMessage> messages)
        {
            var output = new List <Message>();

            foreach (var message in messages)
            {
                if (message.System == SystemTypes.Login)
                {
                    output.Add(new UnauthorizedMessage
                    {
                        Player     = null,
                        Connection = message.Connection,
                        System     = message.System,
                        Type       = message.Type,
                        Data       = message.Data
                    });

                    continue;
                }

                Player player = null;

                var playerId = _socketRepository.GetPlayerId(message.Connection.Id);

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

                if (player == null)
                {
                    continue;
                }

                output.Add(new Message
                {
                    Player = player,
                    System = message.System,
                    Type   = message.Type,
                    Data   = message.Data
                });
            }

            return(output);
        }