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)); }
public async Task <PixelResult> GetPixel(GetPixelRequest model) { var game = await GameCache.GetGame(model.GameId); if (game == null) { return(new PixelResult(false, "Game not found")); } if (Context.IsAuthenticated()) { if (game.Status == GameStatus.Started) { var userId = Context.GetUserId(); var rateLimitResult = await CheckRateLimits(userId, game); if (!string.IsNullOrEmpty(rateLimitResult)) { return(new PixelResult(false, rateLimitResult)); } var clickResult = await PixelWriter.AddClick(userId, new AddClickRequest(model.GameId, model.X, model.Y)); if (!clickResult.Success) { return(new PixelResult(false, clickResult.Message)); } } } var result = await PixelReader.GetPixel(model.GameId, model.X, model.Y); if (result == null) { return(new PixelResult(false, "Pixel not found.")); } return(new PixelResult(result)); }