Esempio n. 1
0
        private void SendWin(string sessionId, UserWinData winData)
        {
            UserInfo userInfo    = null;
            decimal  moneyAmount = 0;

            try
            {
                userInfo    = context.GetSession(sessionId)?.GetUserInfo(context);
                moneyAmount = winData.WinData.Sum(a => a.Amount);

                if (!winData.IsPlayingForFun)
                {
                    var result = accountingFacade.RegisterPlayerWins(context.Game.IdLong, winData.CasinoId, winData.UserId, winData.AccountId, winData.RoundId, winData, winData.AccessPointId, winData.ExternalSessionId, winData.ExternalSessionIp, winData.SeamlessMode, winData.ClientType);
                    if (userInfo != null)
                    {
                        userInfo.SetBalance(result);
                        SendBalanceChanged(sessionId, userInfo.Balance, userInfo.totalLoss);
                    }

                    if (moneyAmount > 0)
                    {
                        accountingFacade.UpdateGameIncome(winData.CasinoId, context.Game.IdLong, EnvironmentHelper.CurrentTime, winData.Currency, 0.0m, moneyAmount, true);
                    }
                }
                else
                {
                    if (trackFunData && moneyAmount > 0)
                    {
                        accountingFacade.UpdateGameIncome(winData.CasinoId, context.Game.IdLong, EnvironmentHelper.CurrentTime, winData.Currency, 0.0m, moneyAmount, false);
                    }
                }

                if (moneyAmount > 0)
                {
                    foreach (var userWinItemData in winData.WinData)
                    {
                        context.Game.ExecuteCallback(this, winData.SuccessCallback, false, sessionId, userWinItemData.WinDataObject, userWinItemData.Amount);
                    }
                }
            }
            catch (Exception ex)
            {
                if (userInfo != null)
                {
                    userInfo.totalWinAmount -= moneyAmount;
                }

                context.Game.LogError(ex);

                try
                {
                    if (moneyAmount > 0)
                    {
                        context.Game.ExecuteCallback(this, winData.FailureCallback, false, sessionId);
                    }
                }
                catch (Exception exx)
                {
                    context.Game.LogError(exx);
                }
            }
        }
Esempio n. 2
0
        public long registerBet(string sessionId, string roundId, string amount, object betData, string comment)
        {
            context.RegisterSessionActivity(sessionId);
            if (context.Game.Runtime.IsDisabled)
            {
                return(-1);
            }

            var userInfo = context.getUserInfo(sessionId);

            if (userInfo == null)
            {
                return(-1);
            }

            var moneyAmount = amount.ToDecimal();

            if (moneyAmount < 0.01m)
            {
                context.Game.Log($"User (fun: {userInfo.isPlayingForFun}, account: {userInfo.AccountId}, casino-id: {userInfo.CasinoId}) made bet (type: '{betData.SerializeJSON()}', amount: '{amount}', round: '{roundId}', reason: '{comment}') couldn't make bet: invalid amount: {moneyAmount}");
                return(-1);
            }

            if (userInfo.Balance < moneyAmount)
            {
                context.Game.Log($"User (fun: {userInfo.isPlayingForFun}, account: {userInfo.AccountId}, casino-id: {userInfo.CasinoId}) made bet (type: '{betData.SerializeJSON()}', amount: '{amount}', round: '{roundId}', reason: '{comment}') couldn't make bet: not enough money");
                return(-1);
            }

            var roundIdLong = roundId.ToLong(0);

            try
            {
                userInfo.Balance        -= moneyAmount;
                userInfo.totalBetAmount += moneyAmount;

                userInfo.roundWinAmount = 0;

                context.Game.Log($"User (fun: {userInfo.isPlayingForFun}, account: {userInfo.AccountId}, casino-id: {userInfo.CasinoId}) made bet (type: '{betData.SerializeJSON()}', amount: '{amount}', round: '{roundIdLong}', reason: '{comment}').");

                if (!userInfo.isPlayingForFun)
                {
                    if (!userWinStore.ContainsKey(sessionId))
                    {
                        userWinStore[sessionId] = new UserWinData(roundIdLong, userInfo.Seamless, userInfo.CasinoId, userInfo.UserId, userInfo.AccountId, userInfo.AccessPointId, userInfo.ExternalSessionId, userInfo.ExternalSessionIp, userInfo.locale.CurrencyValue, userInfo.ClientType, userInfo.isPlayingForFun);
                    }
                }

                betUsers[sessionId] = userInfo;

                UserBetStore userBetStore;
                if (!userBetStores.TryGetValue(sessionId, out userBetStore))
                {
                    userBetStore             = new UserBetStore();
                    userBetStores[sessionId] = userBetStore;
                }

                var betResult = userBetStore.MakeBet(roundIdLong, roundCounters, betData, userInfo.locale.CurrencyValue, moneyAmount, comment);

                SendBalanceChanged(sessionId, userInfo.Balance, userInfo.totalLoss);

                context.Game.SetPlayerBets(sessionId, userBetStore.GetBets(roundIdLong).Sum(b => b.Amount));

                context.Game.Log("Bet has been successfully registered.", context.Game.Name);

                if (!userInfo.isPlayingForFun)
                {
                    reportTracker.Add(userInfo.CasinoId, context.Game.IdLong, userInfo.UserId, new Dictionary <string, object>
                    {
                        { "userId", userInfo.UserId },
                        { "username", userInfo.Username },
                        { "gameId", context.Game.IdLong },
                        { "gameTitle", context.Game.Id },
                        { "type", LiveActivityTypeEnum.Bet },
                        { "currency", (long)userInfo.locale.CurrencyValue },
                        { "amount", amount },
                        { "date", EnvironmentHelper.CurrentTime },
                        { "data", betData },
                        { "resultBalance", userInfo.Balance },
                    });
                }

                return(betResult.BetId);
            }
            catch (Exception ex)
            {
                context.Game.LogError(ex);
                return(-1);
            }
        }
Esempio n. 3
0
        //TODO Check roundBetId exists
        public long registerWin(string sessionId, string roundId, string roundBetId, string amount, object winBetData, string comment, object successCallback, object failureCallback)
        {
            context.RegisterSessionActivity(sessionId);

            var userInfo = context.getUserInfo(sessionId) ?? (betUsers.ContainsKey(sessionId) ? betUsers[sessionId] : tempUsers.ContainsKey(sessionId) ? tempUsers[sessionId] : null);

            if (userInfo == null)
            {
                if (!betUsers.TryGetValue(sessionId, out userInfo))
                {
                    tempUsers.TryGetValue(sessionId, out userInfo);
                }
            }

            if (userInfo == null)
            {
                return(-2);
            }

            var moneyAmount = amount.ToDecimal();

            if (moneyAmount < 0.01m)
            {
                context.Game.Log($"Invalid amount: {moneyAmount}");
                return(-3);
            }

            var roundIdLong    = roundId.ToLong(0);
            var roundBetIdLong = roundBetId.ToLong(0);

            context.Game.Log($"User (fun: {userInfo.isPlayingForFun}, account: {userInfo.AccountId}, casino-id: {userInfo.CasinoId}) won (amount: '{amount}', round: '{roundIdLong}', roundBetId '{roundBetId}', betData '{winBetData.SerializeJSON()}' reason: '{comment}').");
            context.storageHelper.RegisterWin(userInfo, moneyAmount, winBetData);

            var winDataInfo = new Dictionary <string, object>
            {
                { "gameId", context.Game.Id },
                { "roundId", roundIdLong },
                { "roundBetId", roundBetIdLong },
                { "winData", winBetData },
                { "comment", comment }
            };

            userInfo.totalWinAmount += moneyAmount;
            userInfo.roundWinAmount += moneyAmount;
            context.Game.SetPlayerWin(sessionId, userInfo.roundWinAmount);

            if (!userWinStore.ContainsKey(sessionId))
            {
                userWinStore[sessionId] = new UserWinData(roundIdLong, userInfo.Seamless, userInfo.CasinoId, userInfo.UserId, userInfo.AccountId, userInfo.AccessPointId, userInfo.ExternalSessionId, userInfo.ExternalSessionIp, userInfo.locale.CurrencyValue, userInfo.ClientType, userInfo.isPlayingForFun);
            }

            userWinStore[sessionId].SuccessCallback = successCallback;
            userWinStore[sessionId].FailureCallback = failureCallback;
            userWinStore[sessionId].WinData.Add(new UserWinItemData(roundBetIdLong, moneyAmount, winBetData, winDataInfo));

            userInfo.Balance += moneyAmount;
            SendBalanceChanged(sessionId, userInfo.Balance, userInfo.totalLoss);

            if (!userInfo.isPlayingForFun)
            {
                reportTracker.Add(userInfo.CasinoId, context.Game.IdLong, userInfo.UserId, new Dictionary <string, object>
                {
                    { "userId", userInfo.UserId },
                    { "username", userInfo.Username },
                    { "gameId", context.Game.IdLong },
                    { "gameTitle", context.Game.Id },
                    { "type", LiveActivityTypeEnum.Win },
                    { "currency", (long)userInfo.locale.CurrencyValue },
                    { "amount", amount },
                    { "date", EnvironmentHelper.CurrentTime },
                    { "data", winBetData },
                    { "resultBalance", userInfo.balance },
                });
            }

            Task.Run(delegate
            {
                try
                {
                    context.Game.RunInSync(() => SendWins(sessionId), ignoreGameStatus: true);
                }
                catch (Exception ex)
                {
                    if (userInfo != null)
                    {
                        userInfo.totalWinAmount -= moneyAmount;
                    }

                    context.Game.LogError(ex);

                    try
                    {
                        context.Game.ExecuteCallback(this, failureCallback, false, sessionId);
                    }
                    catch (Exception exx)
                    {
                        context.Game.LogError(exx);
                    }
                }
            });

            return(0);
        }