Ejemplo n.º 1
0
        public void DoAction(Connection connection, Request request)
        {
            try
            {
                Client loggedUser   = CurrentClient(request);
                string usernameFrom = loggedUser.Username;

                string action = request.Action();

                List <string> answer = new List <string>();

                answer = answer.Concat(gameLogic.DoAction(usernameFrom, action)).ToList();
                answer.Insert(0, GetPlayerPosition(loggedUser.Username));

                connection.SendMessage(BuildResponse(ResponseCode.Ok, answer.ToArray()));
            }
            catch (RecordNotFoundException e)
            {
                connection.SendMessage(BuildResponse(ResponseCode.NotFound, e.Message));
            }
            catch (ClientNotConnectedException e)
            {
                connection.SendMessage(BuildResponse(ResponseCode.Unauthorized, e.Message));
            }
            catch (ActionException e)
            {
                connection.SendMessage(BuildResponse(ResponseCode.InvalidAction, e.Message));
            }
            catch (BusinessException e)
            {
                connection.SendMessage(BuildResponse(ResponseCode.BadRequest, e.Message));
            }
        }