public IHttpActionResult RequestCommand()
        {
            AuthResult auth = authorizeAndVerifyGameStart();

            if (auth.result != null)
            {
                return(auth.result);
            }

            var gameModel = auth.game;
            var game      = gameModel.getGame();
            var player    = auth.player;

            bool    isTurn  = isPlayerTurn(game, player);
            Command command = CommandInterface.GetCommand(gameModel, player);

            if (isTurn)
            {
                if (CommandInterface.GetCommandForPlayer(player.Name) == null)
                {
                    command = new Command {
                        command = CommandType.TakeTurn
                    };
                    CommandInterface.SetCommandForPlayer(player.Name, command);
                }
            }

            return(Ok(command));
        }
        public IHttpActionResult DisproveSuggestion([FromBody] Card card)
        {
            AuthResult auth = authorizeAndVerifyGameStart();

            if (auth.result != null)
            {
                return(auth.result);
            }

            // TODO: authorize call from correct player

            DisproveData result = new DisproveData();

            result.card             = card;
            result.card             = new Card(Weapon.Pipe);
            result.disprovingPlayer = auth.player.Name;
            var cmdData = new CommandData {
                disproveData = result
            };

            // remove player's need to disprove suggestion
            CommandInterface.SetCommandForPlayer(result.disprovingPlayer, null);

            // set command for current player's turn
            var playerName = auth.game.getGame().getPlayerTurn().name;
            var resultCmd  = new Command {
                command = CommandType.DisproveResult, data = cmdData
            };

            CommandInterface.SetCommandForPlayer(playerName, resultCmd);

            return(Created("", ""));
        }
        public IHttpActionResult MakeSuggestion([FromBody] Accusation accusation)
        {
            AuthResult auth = authorizeAndVerifyGameStart();

            if (auth.result != null)
            {
                return(auth.result);
            }

            // TODO: validate accusationData data

            var game   = auth.game.getGame();
            var player = auth.player;

            if (!isPlayerTurn(game, player))
            {
                return(Unauthorized());
            }

            Command command = new Command();

            command.command = CommandType.SuggestionMade;

            SuggestionData data = new SuggestionData {
                playerName = player.Name, accusation = accusation
            };
            var cmdData = new CommandData {
                suggestData = data
            };
            var disprovingPlayer = game.makeSuggestion(player.Name, accusation);

            if (disprovingPlayer != null)
            {
                data.disprovingPlayer = disprovingPlayer.name;
                var disproveCmd = new Command {
                    command = CommandType.DisproveSuggestion, data = cmdData
                };
                CommandInterface.SetCommandForPlayer(disprovingPlayer.name, disproveCmd);

                var waitCmd = new Command {
                    command = CommandType.Wait
                };
                CommandInterface.SetCommandForPlayer(player.Name, waitCmd);
            }

            command.data = cmdData;
            CommandInterface.SetCommandForEveryone(auth.game, command);

            return(Created("", data));
        }
        public IHttpActionResult EndTurn()
        {
            AuthResult auth = authorizeAndVerifyGameStart();

            if (auth.result != null)
            {
                return(auth.result);
            }

            var game   = auth.game.getGame();
            var player = auth.player;

            if (!isPlayerTurn(game, player))
            {
                return(Unauthorized());
            }

            game.nextPlayer();

            var cmd = new Command {
                command = CommandType.TurnEnd
            };

            CommandInterface.SetCommandForEveryone(auth.game, cmd);

            // remove 'TakeTurn' command from current player
            CommandInterface.SetCommandForPlayer(auth.player.Name, null);

            // Set command for next player's turn
            cmd = new Command {
                command = CommandType.TakeTurn
            };
            var nextPlayer = game.getPlayerTurn();

            CommandInterface.SetCommandForPlayer(nextPlayer.name, cmd);

            return(Created("", ""));
        }
        // This API can only be called by the host player
        public IHttpActionResult StartGame()
        {
            AuthResult auth = authorizePlayerMatchesGame();

            if (auth.result != null)
            {
                return(auth.result);
            }

            PlayerModel player = auth.player;
            GameModel   game   = auth.game;

            if (!game.Hostname.Equals(player.Name))
            {
                return(Unauthorized());
            }

            if (game.start())
            {
                var cmd = new Command {
                    command = CommandType.GameStart
                };
                CommandInterface.SetCommandForEveryone(game, cmd);

                var startPlayer = game.getGame().getPlayerTurn().name;
                cmd = new Command {
                    command = CommandType.TakeTurn
                };
                CommandInterface.SetCommandForPlayer(startPlayer, cmd);

                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(BadRequest());
            }
        }