コード例 #1
0
        public ActionResult GetCaptcha()
        {
            GeetestLib geetest        = new GeetestLib(GeetestConfig.publicKey, GeetestConfig.privateKey);
            string     userID         = RandomUtil.CreateRandomStr(10);
            byte       gtServerStatus = geetest.preProcess(userID, "web", ConfigurationManager.AppSettings["ClientIP"]);

            Session[GeetestLib.gtServerStatusSessionKey] = gtServerStatus;
            Session["userID"] = userID;
            return(Content(geetest.getResponseStr()));
        }
コード例 #2
0
ファイル: UsersBll.cs プロジェクト: drawde/FriendshipFirst
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="mobile"></param>
        /// <param name="email"></param>
        /// <param name="invitationCode"></param>
        /// <param name="nickName"></param>
        /// <param name="headImg"></param>
        /// <returns></returns>
        public string Register(string userName, string pwd, string mobile, string email, string nickName, string headImg = "")
        {
            if (userName.IsNullOrEmpty() || pwd.IsNullOrEmpty() || nickName.IsNullOrEmpty())
            {
                return(JsonStringResult.Error(OperateResCodeEnum.参数错误));
            }
            if (!StringUtil.IsNatural_Number(userName))
            {
                return(JsonStringResult.Error(OperateResCodeEnum.参数错误));
            }
            if (IsRepeat(userName))
            {
                return(JsonStringResult.Error(OperateResCodeEnum.用户名重复));
            }
            //if (!mobile.IsNullOrEmpty() && IsMobileRepeat(mobile))
            //{
            //    return OperateJsonRes.Error(OperateResCodeEnum.手机号重复);
            //}
            //if (!email.IsNullOrEmpty() && IsEmailRepeat(email))
            //{
            //    return OperateJsonRes.Error(OperateResCodeEnum.邮箱重复);
            //}
            string userCode = SignUtil.CreateSign(userName + RandomUtil.CreateRandomStr(10) + DateTime.Now.ToString("yyyyMMddHHmmss"));

            FF_User user = new FF_User();

            user.AddTime    = DateTime.Now;
            user.Email      = email.TryParseString();
            user.Mobile     = mobile.TryParseString();
            user.Password   = SignUtil.CreateSign(pwd);
            user.UserCode   = userCode;
            user.UserName   = userName;
            user.NickName   = nickName;
            user.HeadImg    = headImg.TryParseString();
            user.SecretCode = SignUtil.CreateSign(user.UserName + user.UserCode + RandomUtil.CreateRandomStr(10) + DateTime.Now.Ticks);
            user.OpenID     = "";
            _repository.Insert(user);


            return(JsonStringResult.SuccessResult(user.UserCode));
        }
コード例 #3
0
        public APIResultBase AddOrUpdate(HS_GameTable gameTable, GameStyleEnum GameStyle)
        {
            if (gameTable.CreateUserCode.IsNullOrEmpty() || gameTable.TableName.IsNullOrEmpty())
            {
                return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误));
            }
            if (_repository.Get(c => (c.CreateUserCode == gameTable.CreateUserCode || c.PlayerUserCode == gameTable.CreateUserCode) && gameTable.ID < 1 && c.TableStatus == (int)TableStatusEnum.正常).Result.TotalItemsCount > 0)
            {
                return(JsonModelResult.PackageFail(OperateResCodeEnum.时只能创建或占用一个游戏房间));
            }
            if (gameTable.ID > 0)
            {
                //gameTable.AddTime = _repository.GetByKey(gameTable.ID).Result.AddTime;
                _repository.Update(gameTable);
                return(JsonModelResult.PackageSuccess(gameTable.ID.ToString()));
            }
            else
            {
                DateTime now = DateTime.Now;
                gameTable.PlayerUserCode = "";
                gameTable.TableCode      = SignUtil.CreateSign(UsersBll.Instance.GetUserByAdmin(gameTable.CreateUserCode).SecretCode + RandomUtil.CreateRandomStr(8) + now.Ticks);
                gameTable.AddTime        = DateTime.Now;
                using (FriendshipFirstContext context = new FriendshipFirstContext())
                {
                    gameTable.BankerCode = gameTable.CreateUserCode;
                    context.hs_gametable.Add(gameTable);
                    FF_Game game = new FF_Game();
                    game.AddTime          = now;
                    game.BankerCode       = gameTable.CreateUserCode;
                    game.GameStatus       = GameStyle == GameStyleEnum.庄家模式 ? (int)GameStatusEnum.初始化 : (int)GameStatusEnum.已开始;
                    game.CurrentRoundCode = SignUtil.CreateSign(gameTable.CreateUserCode + RandomUtil.CreateRandomStr(8) + game.AddTime.Ticks);
                    game.NextRoundCode    = SignUtil.CreateSign(gameTable.CreateUserCode + RandomUtil.CreateRandomStr(8) + game.AddTime.AddMinutes(5).Ticks);
                    game.GameCode         = gameTable.TableCode;
                    game.GameStyle        = (int)GameStyle;
                    context.ff_game.Add(game);

                    FF_GameRecord record = new FF_GameRecord
                    {
                        AddTime      = now,
                        BetMoney     = 0,
                        IsBanker     = true,
                        PlayerStatus = (int)PlayerStatusEnum.已下注,
                        RoundCode    = game.CurrentRoundCode,
                        UserCode     = game.BankerCode,
                        WinMoney     = 0,
                        Balance      = 0,
                        GameCode     = game.GameCode,
                        IsActivity   = false,
                        RoomIndex    = 0
                    };
                    context.ff_gamerecord.Add(record);

                    context.SaveChanges();
                }
                return(JsonModelResult.PackageSuccess <HS_GameTable>(gameTable));
            }
        }
コード例 #4
0
        /// <summary>
        /// 结算
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="targetUserCode"></param>
        /// <param name="gameCode"></param>
        /// <param name="money"></param>
        /// <returns></returns>
        public APIResultBase Settlement(string userCode, string targetUserCode, string gameCode, decimal money)
        {
            FF_Game   game     = null;
            CGameUser gameUser = null;

            using (FriendshipFirstContext context = new FriendshipFirstContext())
            {
                game = context.ff_game.Where(c => c.GameCode == gameCode).OrderByDescending(c => c.AddTime).FirstOrDefault();
                if (game.GameStatus != (int)GameStatusEnum.已开始 && game.GameStatus != (int)GameStatusEnum.结算中)
                {
                    return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误));
                }
                game.GameStatus = (int)GameStatusEnum.结算中;
                var lstRec       = context.ff_gamerecord.Where(c => c.RoundCode == game.CurrentRoundCode);
                var record       = lstRec.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == userCode);
                var targetRecord = lstRec.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == targetUserCode);
                record.BetMoney  = 0;
                record.Balance  += money;
                record.WinMoney += money;

                bool isAllSettlemented = false;
                if (game.GameStyle == (int)GameStyleEnum.庄家模式)
                {
                    if (record.IsBanker == false)
                    {
                        record.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }
                    else if (lstRec.Count(c => c.IsBanker == false && c.PlayerStatus != (int)PlayerStatusEnum.已结算) <= 1)
                    {
                        record.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }

                    targetRecord.Balance  -= money;
                    targetRecord.WinMoney -= money;
                    if (targetRecord.IsBanker == false)
                    {
                        targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }
                    else if (lstRec.Count(c => c.IsBanker == false && c.PlayerStatus != (int)PlayerStatusEnum.已结算) <= 1)
                    {
                        targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }
                    isAllSettlemented = (record.PlayerStatus == (int)PlayerStatusEnum.已结算 && targetRecord.PlayerStatus == (int)PlayerStatusEnum.已结算);
                }
                else
                {
                    record.PlayerStatus = (int)PlayerStatusEnum.已结算;

                    targetRecord.Balance     -= money;
                    targetRecord.WinMoney    -= money;
                    targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算;

                    isAllSettlemented = !lstRec.Any(c => c.PlayerStatus != (int)PlayerStatusEnum.已结算 && c.UserCode != userCode && c.UserCode != targetUserCode);
                }

                if (isAllSettlemented)
                {
                    DateTime now = DateTime.Now;
                    var      lst = lstRec.ToList();
                    game.CurrentRoundCode = game.NextRoundCode;
                    game.NextRoundCode    = SignUtil.CreateSign(game.BankerCode + RandomUtil.CreateRandomStr(8) + now.Ticks);

                    if (game.GameStyle == (int)GameStyleEnum.庄家模式)
                    {
                        game.GameStatus = (int)GameStatusEnum.已结算;
                        AddUserToNextBankerRound(lst, game, now, context);
                    }
                    else
                    {
                        game.GameStatus = (int)GameStatusEnum.已开始;
                        AddUserToNextFreeModelRound(lst, game, now, context);
                    }
                }
                context.SaveChanges();
                gameUser = GameRecordBll.Instance.GetUser(userCode, game.GameCode, context);

                //gameUser = data.Where(c => c.UserCode == userCode && c.GameCode == gameCode).OrderByDescending(c => c.AddTime).FirstOrDefault();
            }
            return(JsonModelResult.PackageSuccess(gameUser));
        }