Esempio n. 1
0
        public async Task <dynamic> MakeWithdrawOffer([FromBody] WithdrawOfferModel withdrawModel)
        {
            if (!TryValidateModel(withdrawModel))
            {
                return(BadRequest(withdrawModel));
            }

            var steamId = User.GetSteamId();
            var items   = withdrawModel.Items.Select(item => new AssetAndDescriptionId
            {
                AssetId       = item.AssetId,
                DescriptionId = item.DescriptionId
            }).ToList();

            if (_betOrWithdrawQueueManager.DoesExist(steamId))
            {
                return(new StatusCodeResult(503));
            }
            _betOrWithdrawQueueManager.Add(steamId, QueueAction.Withdraw);
            try
            {
                var res = await _steamService.MakeWithdrawOfferAsync(steamId, items);

                return(res);
            }
            catch (TradeLinkNotSetExeption)
            {
                return(BadRequest("User does not have a valid tradelink"));
            }
            finally
            {
                _betOrWithdrawQueueManager.Remover(steamId);
            }
        }
Esempio n. 2
0
        private async Task ProcessItemInQueue()
        {
            var item = _betQueue.Next();

            if (_betOrWithdrawQueueManager.DoesExist(item.SteamId))
            {
                await _betHubConnections.Error(item.SteamId, item.RoundId, "You alredy have a pending bet or withdraw.");

                return;
            }

            _betOrWithdrawQueueManager.Add(item.SteamId, QueueAction.Bet);
            try
            {
                var match = await _repoServiceFactory.MatchRepoService.GetCurrentMatch();

                if (item.RoundId != match.RoundId)
                {
                    throw new MatchRoundIdNotSameException("The match roundId is not the same as the roundId that the user want to bet on");
                }

                await _betService.PlaceBetOnJackpotMatch(match, _currentMatchSettings.ToJackpotMatchSetting(), item.GamMode,
                                                         item.AssetAndDescriptionIds,
                                                         item.SteamId);
            }
            catch (Exception ex)
            {
                _logService.Error(null, null, ex, new Dictionary <string, object>());

                if (
                    ex is GameModeIsNotEnabledException ||
                    ex is ToManyItemsOnBetException ||
                    ex is ToFewItemsOnBetException ||
                    ex is NotAllowedAppIdOnMatchException ||
                    ex is ToMuchValueOnBetException ||
                    ex is ToLittleValueOnBetException ||
                    ex is InvalidItemException
                    )
                {
                    await _betHubConnections.Error(item.SteamId, item.RoundId, ex.Message);

                    return;
                }

                await _betHubConnections.Error(item.SteamId, item.RoundId, "Something went wrong, please try again later.");

                return;
            }
            finally
            {
                _betOrWithdrawQueueManager.Remover(item.SteamId);
            }

            await _betHubConnections.Success(item.SteamId, item.RoundId);
        }
Esempio n. 3
0
        private async void ProcessItemInQueue()
        {
            while (true)
            {
                if (_betQueue.IsEmpty())
                {
                    await Task.Delay(200);

                    continue;
                }

                var item = _betQueue.Next();

                if (_betOrWithdrawQueueManager.DoesExist(item.SteamId))
                {
                    await _betHubConnections.Error(item.SteamId, item.RoundId, "You alredy have a pending bet or withdraw.");

                    continue;
                }

                DatabaseModel.CoinFlip       match;
                DatabaseModel.JackpotSetting matchSetting;
                try
                {
                    match = await _repoServiceFactory.CoinFlipMatchRepoService.FindAsync(item.RoundId);

                    matchSetting = await _repoServiceFactory.JackpotSettingRepo.Find(match.SettingId);
                }
                catch (Exception e)
                {
                    _logService.Error(null, null, e, new Dictionary <string, object>());
                    await _betHubConnections.Error(item.SteamId, item.RoundId, "Something went wrong, please try again later.");

                    continue;
                }

                var bets = await _repoServiceFactory.BetRepoService.FindAsync(item.RoundId, _currentGamemode.Id);

                if (bets.Count == 2)
                {
                    await _betHubConnections.Error(item.SteamId, item.RoundId, "The match has no empty slots");

                    continue;
                }

                _betOrWithdrawQueueManager.Add(item.SteamId, QueueAction.Bet);
                try
                {
                    await _betService.PlaceBetOnCoinFlipMatch(match, matchSetting.ToJackpotMatchSetting(), item.GamMode, item.AssetAndDescriptionIds,
                                                              item.SteamId);
                }
                catch (Exception ex)
                {
                    _logService.Error(null, null, ex, new Dictionary <string, object>());

                    if (
                        ex is GameModeIsNotEnabledException ||
                        ex is ToManyItemsOnBetException ||
                        ex is ToFewItemsOnBetException ||
                        ex is NotAllowedAppIdOnMatchException ||
                        ex is ToMuchValueOnBetException ||
                        ex is ToLittleValueOnBetException ||
                        ex is InvalidItemException
                        )
                    {
                        await _betHubConnections.Error(item.SteamId, item.RoundId, ex.Message);

                        continue;
                    }

                    await _betHubConnections.Error(item.SteamId, item.RoundId, "Something went wrong, please try again later.");

                    continue;
                }
                finally
                {
                    _betOrWithdrawQueueManager.Remover(item.SteamId);
                }

                await _betHubConnections.Success(item.SteamId, item.RoundId);
            }
        }