public void GetJackpot(byte betType, byte roomID)
        {
            try
            {
                long   accountId   = AccountSession.AccountID;
                string accountName = AccountSession.AccountName;

                if (CacheCounter.CheckIpPostFrequency(10, "GetJackpot") > 50)
                {
                    NLogManager.LogMessage(string.Format("BlockGetJackpot=>{0},{1}", accountId, IPAddressHelper.GetClientIP()));
                    return;
                }
                if ((accountId < 1 || string.IsNullOrEmpty(accountName)))
                {
                    throw new NotAuthorizedException(NOT_LOGIN_MESSAGE);
                }
                if ((betType < 1 || betType > 2 || roomID < 1 || roomID > 4))
                {
                    throw new InvalidOperationException(INVALID_DATA_MESSAGE);
                }
                MiniPokerHandler.Instance.AddPlayer(accountId);
                MiniPokerHandler.Instance.MpGetJackpot(betType, roomID, base.Context.ConnectionId);
            }
            catch (Exception exception)
            {
                NLogManager.PublishException(exception);
            }
        }
 public long Spin(byte betType, byte roomID)
 {
     try
     {
         long   accountId   = AccountSession.AccountID;
         string accountName = AccountSession.AccountName;
         if (accountId < 1 || string.IsNullOrEmpty(accountName))
         {
             return(-1001);
         }
         if ((betType < 1 || betType > 2 || roomID < 1 || roomID > 4))
         {
             Logout();
             NLogManager.LogMessage(string.Format("BlockAcc=> {0} ({1}) Wrong Input.", accountName, accountId));
             return(-1001);
         }
         float maxSpinPerSecond =
             int.Parse(System.Configuration.ConfigurationManager.AppSettings["MAX_SPIN_PER_SECOND"]);
         if (maxSpinPerSecond % 2 > 0)
         {
             maxSpinPerSecond += 1;
         }
         if (CacheCounter.CheckAccountActionFrequencyMiliSecond(accountId.ToString(), 1000 / maxSpinPerSecond, "Spin") > 1)
         {
             NLogManager.LogMessage(string.Format("BlockAccFast=> {0} ({1}) quay liên tục 1 giây {2} lần.",
                                                  accountName, accountId, maxSpinPerSecond));
             return(-1001);
         }
         if (CacheCounter.AccountActionCounter(accountId.ToString(), "SpinAm") > 5)
         {
             NLogManager.LogMessage(string.Format("BlockAccAm=> {0} ({1}) bắn âm > 5 lần.", accountName, accountId));
             return(-1003);
         }
         MiniPokerHandler.Instance.UpdatePlayer(accountId);
         int res = MiniPokerHandler.Instance.MpSpin(accountId, accountName, betType, roomID, base.Context.ConnectionId, _isMobilePl);
         if (res < 0)
         {
             CacheCounter.CheckAccountActionFrequency(accountId.ToString(), 15, "SpinAm");
         }
         return(res);
     }
     catch (NotAuthorizedException notAuthorizedException)
     {
         NLogManager.PublishException(notAuthorizedException);
         return(-51);
     }
     catch (Exception exception)
     {
         NLogManager.PublishException(exception);
     }
     return(-99);
 }
Beispiel #3
0
        public int Spin(MoneyType moneyType, int roomId, string lines)
        {
            long   accountId   = AccountSession.AccountID;
            string accountName = AccountSession.AccountName;

            try
            {
                if (accountId < 1 || String.IsNullOrEmpty(accountName))
                {
                    return((int)Enums.ErrorCode.NotAuthen);
                }

                if (CacheCounter.AccountActionCounter(accountId.ToString(), "BlockSpamSpin") > 0)
                {
                    NLogManager.LogMessage($"BlockSpinAm=>Acc:{accountId}|User:{accountName}|Lines:{lines}|Ip:{IPAddressHelper.GetClientIP()}");
                    return(-1002);
                }

                var spinData = GameHandler.Instance.Spin(accountId, accountName, lines, moneyType, roomId);
                if (spinData != null && spinData.ResponseStatus < 0)
                {
                    if (CacheCounter.CheckAccountActionFrequency(accountName, 10, "InvalidSpin") > 5)
                    {
                        //Block Spin 10s
                        CacheCounter.CheckAccountActionFrequency(accountName, 10, "BlockSpamSpin");
                    }
                    string message = "Rất tiếc hệ thống của chúng tôi đang bận!Mời bạn thử lại sau!";
                    if (spinData.ResponseStatus == -51)
                    {
                        message = "Số dư của bạn không đủ";
                    }
                    else if (spinData.ResponseStatus == -232)
                    {
                        message = "Số line chọn không hợp lệ";
                    }
                    Clients.Caller.message(spinData.ResponseStatus, message);
                }
                Clients.Caller.resultSpin(spinData);

                return((int)Enums.ErrorCode.SuccessRequest);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
                return((int)Enums.ErrorCode.Exception);
            }
        }
Beispiel #4
0
 public void GetAccountInfoHiLo()
 {
     try
     {
         long   accountId   = AccountSession.AccountID;
         string accountName = AccountSession.AccountName;
         if ((accountId < 1 || string.IsNullOrEmpty(accountName)))
         {
             throw new NotAuthorizedException(NOT_LOGIN_MESSAGE);
         }
         if (CacheCounter.CheckAccountActionFrequency(accountId.ToString(), 15, "GetAccInfo") > 6)
         {
             NLogManager.LogMessage(string.Format("BlockGetAccInfo=>Acc:{0}|User:{1}",
                                                  accountId, accountName));
             return;
         }
         var resultAccInfo = AbstractDaoMinigame.Instance().CreateMiniHiloDao()
                             .GetAccountInfo((int)accountId, accountName);
         NLogManager.LogMessage("resultAccInfo: " + JsonConvert.SerializeObject(resultAccInfo));
         if (resultAccInfo.currentTurnId > 0)
         {
             if (resultAccInfo.remainTime <= 0)
             {
                 NLogManager.LogMessage(string.Format("AutoFinishSession:Acc:{0}|User:{1}|Turn:{2}",
                                                      accountId, accountName, resultAccInfo.currentTurnId));
                 if (HiLoHandler.Instance.AutoFinishSession(resultAccInfo, accountId, accountName, IPAddressHelper.GetClientIP()))
                 {
                     HiLoHandler.Instance.FinishAccSession(resultAccInfo.currentTurnId);
                     return;
                 }
             }
             Clients.Caller.resultHiLoAccountInfo(resultAccInfo);
         }
     }
     catch (Exception exception)
     {
         NLogManager.LogError("ERROR GetAccountInfoHiLo: " + exception);
         NLogManager.PublishException(exception);
     }
 }
        public void HideSlot()
        {
            try
            {
                long   accountId   = AccountSession.AccountID;
                string accountName = AccountSession.AccountName;

                if (CacheCounter.CheckIpPostFrequency(10, "HideSlot") > 30)
                {
                    NLogManager.LogMessage(string.Format("BlockHideSlot=>{0},{1}", accountId, IPAddressHelper.GetClientIP()));
                    return;
                }
                if ((accountId < 1 || string.IsNullOrEmpty(accountName)))
                {
                    throw new NotAuthorizedException(NOT_LOGIN_MESSAGE);
                }
                MiniPokerHandler.Instance.RemovePlayer(accountId);
                MiniPokerHandler.Instance.MpHideSlot(base.Context.ConnectionId);
            }
            catch (Exception exception)
            {
                NLogManager.PublishException(exception);
            }
        }
Beispiel #6
0
        public int Spin(int roomId)
        {
            try
            {
                var moneyType = MoneyType.Gold;

                if (roomId < 1 || roomId > 4)
                {
                    return(-303);
                }
                //Kiểm tra xem tài khoản vi phạm bắn số lần respone âm
                var totalFailRequest = int.Parse(ConfigurationManager.AppSettings["TotalFailRq"]);
                if (CheckStatusFrequency("SpinLoi") >= totalFailRequest)
                {
                    var totalSecondFail = int.Parse(ConfigurationManager.AppSettings["TimmerFailRq"]);
                    AddStatusFrequency(totalSecondFail, "SpinLoi");
                    return(-1999);
                }
                long   accountId   = AccountSession.AccountID;
                string accountName = AccountSession.AccountName;


                if (accountId < 1 || String.IsNullOrEmpty(accountName))
                {
                    return((int)Enums.ErrorCode.NotAuthen);
                }

                float maxSpinPerSecond =
                    Config.GetIntegerAppSettings("MAX_SPIN_PER_SECOND", 5);
                if (maxSpinPerSecond % 2 > 0)
                {
                    maxSpinPerSecond += 1;
                }
                if (CacheCounter.CheckAccountActionFrequencyMiliSecond(accountId.ToString(), 1000 / maxSpinPerSecond, "Spin") > 1)
                {
                    NLogManager.LogMessage(string.Format("BlockAccFast=> {0} ({1}) quay liên tục 1 giây {2} lần.",
                                                         accountName, accountId, maxSpinPerSecond));
                    return(-1001);
                }
                if (CacheCounter.AccountActionCounter(accountId.ToString(), "SpinAm") > 5)
                {
                    NLogManager.LogMessage(string.Format("BlockAccAm=> {0} ({1}) bắn âm > 5 lần.", accountName, accountId));
                    return(-1003);
                }

                var spinData = GameHandler.Instance.PlaySpin(roomId, moneyType);

                if (spinData.ResponseStatus == -48)
                {
                    Clients.Caller.message("Error-48", 3);
                    return(-48);
                }

                if (spinData.ResponseStatus >= 0)
                {
                    Clients.Caller.ResultSpin(spinData);
                    return((int)Enums.ErrorCode.Success);
                }

                else
                {
                    return(spinData.ResponseStatus);
                }
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
                return((int)Enums.ErrorCode.Exception);
            }
        }
Beispiel #7
0
        public async Task <long> PlayNow(MoneyType moneyType, int roomId)
        {
            if ((int)moneyType != 1 && (int)moneyType != 2)
            {
                return(-999);
            }

            if (roomId < 1 || roomId > 4)
            {
                return(-888);
            }

            try
            {
                var accountId   = AccountSession.AccountID;
                var accountName = AccountSession.AccountName;
                if (accountId < 1 || string.IsNullOrEmpty(accountName))
                {
                    return(-1001);
                }
                //var connections = ConnectionHandler.Instance.GetConnections(accountId);
                //if (connections.Count > 1)
                //{
                //    var currentConnection = Context.ConnectionId;
                //    foreach(var other in connections.Where(con => !con.Equals(currentConnection)))
                //    {
                //        if(currentConnection != other)
                //            Clients.Client(other).message(-1002, "Tài khoản của bạn đang chơi trên thiết bị khác");
                //    }

                //}
                if (CacheCounter.CheckAccountActionFrequency(accountId.ToString(), 60, "PlayNow") >
                    Config.GetIntegerAppSettings("TotalAllowPlayNow", 60))
                {
                    NLogManager.LogMessage($"BlockPlayNow=>Acc:{accountId}|User:{accountName}|Room:{roomId}|Ip:{IPAddressHelper.GetClientIP()}");
                    return(-1002);
                }

                var gameInfo = GameHandler.Instance.PlayNow(moneyType, roomId, accountId, accountName);
                if (gameInfo.ResponseStatus >= 0)
                {
                    if (moneyType == MoneyType.Gold)
                    {
                        await Groups.Remove(Context.ConnectionId, "Coin");

                        await Groups.Add(Context.ConnectionId, "Gold");
                    }
                    else
                    {
                        await Groups.Remove(Context.ConnectionId, "Gold");

                        await Groups.Add(Context.ConnectionId, "Coin");
                    }
                    Clients.Caller.joinGame(gameInfo);
                }
                return(accountId);
            }
            catch (NotAuthorizedException nig)
            {
                NLogManager.PublishException(nig);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
            return(-1);
        }
Beispiel #8
0
        public int SetBetHiLo(int betType, int stepType, int locationId, int roomId)
        {
            try
            {
                long   accountId   = AccountSession.AccountID;
                string accountName = AccountSession.AccountName;
                if (accountId < 1 || string.IsNullOrEmpty(accountName))
                {
                    NLogManager.LogMessage(string.Format("Chưa đăng nhập"));
                    return(-1001);
                }
                if (betType < 1 || betType > 2 || locationId < 0 || locationId > 1 || roomId < 1 || roomId > 5)
                {
                    Logout();
                    NLogManager.LogMessage(string.Format("BlockAcc=> {0} ({1}) Wrong Input.", accountName, accountId));
                    return(-212);
                }

                if (CacheCounter.CheckAccountActionFrequency(accountId.ToString(), 1, "SetBet") > 2)
                {
                    NLogManager.LogMessage(string.Format("BlockAccFast => {0} ({1}) bet liên tục 1 giây 2 lần.", accountName, accountId));
                    return(-1001);
                }
                if (CacheCounter.AccountActionCounter(accountId.ToString(), "SetBetAm") > 5)
                {
                    NLogManager.LogMessage(string.Format("BlockAccAm => {0} ({1}) bắn âm > 5 lần.", accountName, accountId));
                    return(-1003);
                }
                var result = AbstractDaoMinigame.Instance().CreateMiniHiloDao().
                             SetBet((int)accountId, accountName, roomId, betType, stepType, locationId, IPAddressHelper.GetClientIP(),
                                    1, 1);

                if (stepType == 2 || result.prizeValue == 0 || result.responseStatus < 0)
                {
                    //Kết thúc phiên hoặc thua cuộc
                    HiLoHandler.Instance.FinishAccSession(result.turnId);
                }
                else
                {
                    if (result.responseStatus < 0)
                    {
                        //Add vào list để duyệt check finish phiên
                        var accInfo = new HiLoGetAccountInfoResponse()
                        {
                            currentTurnId  = result.turnId,
                            currentRoomId  = roomId,
                            currentBetType = betType,
                            AccountId      = accountId,
                            AccountName    = accountName,
                            currentStep    = result.step
                        };
                        HiLoHandler.Instance.AddOrUpdateSession(accInfo);
                    }
                }
                if (result.responseStatus < 0)
                {
                    CacheCounter.CheckAccountActionFrequency(accountId.ToString(), 15, "SetBetAm");
                }
                Clients.Caller.resultHiLoSetBet(result);
                return(result.responseStatus);
            }
            catch (Exception exception)
            {
                NLogManager.PublishException(exception);
            }
            return(-99);
        }