Beispiel #1
0
        public async Task <PixelResult> AddPixel(AddPixelRequest model)
        {
            var game = await GameCache.GetGame(model.GameId);

            if (game == null)
            {
                return(new PixelResult(false, "Game not found"));
            }

            if (game.Status != GameStatus.Started)
            {
                return(new PixelResult(false, "Game is not currently active"));
            }

            var pixel = await PixelCache.GetPixel(game.Id, model.X, model.Y);

            if (pixel != null)
            {
                if (pixel.Type == PixelType.Fixed)
                {
                    return(new PixelResult(false, "Cannot overwrite gameboard pixel"));
                }

                if (pixel.Points > model.MaxPoints)
                {
                    return(new PixelResult(false, "Pixel points are greater than Spend Limit"));
                }
            }

            var userId          = Context.GetUserId();
            var rateLimitResult = await CheckRateLimits(userId, game);

            if (!string.IsNullOrEmpty(rateLimitResult))
            {
                return(new PixelResult(false, rateLimitResult));
            }

            var result = await PixelWriter.AddPixel(userId, model);

            if (!result.Success)
            {
                return(new PixelResult(false, result.Message));
            }

            return(new PixelResult(result));
        }