示例#1
0
        public (D1Chess_Srv.EfModel.Token, Result) Post_GetMoves(D1Chess_Srv.EfModel.Token pEfToken, object pData)
        {
            var pWhitesTurnPiecePos = ((JObject)pData).ToObject <PWhitesTurnPiecePos>();
            var turn = Move.GetTurn(pWhitesTurnPiecePos.WhitesTurn, pWhitesTurnPiecePos.PiecePos);

            return(pEfToken, new Result(turn));
        }
示例#2
0
        public (D1Chess_Srv.EfModel.Token, Result) Get_Restart(D1Chess_Srv.EfModel.Token pEfToken)
        {
            var gameId = pEfToken.IsAnonymous ? pEfToken.DeviceId.Value : pEfToken.UserId.Value;
            var efGame = EfGame.Get(gameId);

            efGame.Script = null;
            EfGame.Update(efGame);
            return(pEfToken, new Result(true));
        }
示例#3
0
        public (D1Chess_Srv.EfModel.Token, Result) Post_Search(D1Chess_Srv.EfModel.Token pEfToken, object pData)
        {
            var pSearch   = ((JObject)pData).ToObject <PSearch>();
            var efProfile = EfProfile.GetForUserIdProfileIdx(pEfToken.UserId.Value, pSearch.ProfileIdx);

            efProfile.Search_By = pSearch.By;
            switch (pSearch.By)
            {
            case "G": efProfile.SearchText_Group = pSearch.Text; break;

            case "F": efProfile.SearchText_NameFirst = pSearch.Text; break;

            case "L": efProfile.SearchText_NameLast = pSearch.Text; break;

            case "U": efProfile.SearchText_UserId = pSearch.Text; break;
            }
            efProfile.Search_RatingMin = pSearch.Min;
            efProfile.Search_RatingMax = pSearch.Max;
            var efProfiles = new List <D1Chess_Srv.EfModel.Profile>();
            var profiles   = new List <object>();

            foreach (var profile in efProfiles)
            {
                profiles.Add(
                    new {
                    UserId    = profile.UserIDText,
                    Photo_Src = Images.GetBase64String(profile.PhotoBytes),
                    Name      = profile.NameFirst + " " + profile.NameLast,
                    profile.Rating
                }
                    );
            }

            //Context.Profiles.Update(efProfile);
            Context.Save();
            return(pEfToken, new Result(profiles));
        }
示例#4
0
        public (D1Chess_Srv.EfModel.Token, Result) Post_Turn(D1Chess_Srv.EfModel.Token pEfToken, object pData)
        {
            #region Prep
            var  pTurn = ((JObject)pData).ToObject <PTurn>();
            Guid gameId;
            var  game_Script   = new List <List <Script> >();
            var  turn_piecePos = Move.StartPiecePos;
            #endregion


            if (pTurn.GameId == null || pTurn.GameId == Guid.Empty)
            {
                gameId = pEfToken.IsAnonymous ? pEfToken.DeviceId.Value : pEfToken.UserId.Value;
            }
            else
            {
                gameId = pTurn.GameId.Value;
            }
            var efGame = EfGame.Get(gameId);
            var add    = efGame == null;
            efGame = EfGame.Convert(efGame, pEfToken);

            if (pTurn.Idx > 0)
            {
                if (efGame.PiecePos != null)
                {
                    turn_piecePos = JsonConvert.DeserializeObject <int[]>(efGame.PiecePos);
                }
                game_Script = JsonConvert.DeserializeObject <List <List <Script> > >(efGame.Script);
                if (pTurn.Idx < game_Script.Count)
                {
                    #region RollBack
                    if (pTurn.Idx < game_Script.Count())
                    {
                        for (var xT = game_Script.Count() - 1; xT > pTurn.Idx - 1; xT--)
                        {
                            for (var xS = game_Script[xT].Count() - 1; xS >= 0; xS--)
                            {
                                turn_piecePos[game_Script[xT][xS].PieceIdx] = game_Script[xT][xS].PrevIdx;
                            }
                        }
                    }
                    game_Script = game_Script.GetRange(0, pTurn.Idx); //  Truncate Script
                    #endregion
                }
            }
            game_Script.Add(pTurn.Script);
            foreach (var script in pTurn.Script)
            {
                turn_piecePos[script.PieceIdx] = script.PosIdx;
            }

            efGame.Script   = JsonConvert.SerializeObject(game_Script);
            efGame.PiecePos = JsonConvert.SerializeObject(turn_piecePos);

            if (add)
            {
                EfGame.Add(efGame);
            }
            else
            {
                EfGame.Update(efGame);
            }
            Context.Save();


            var turn = Move.GetTurn(pTurn.Idx, turn_piecePos);

            //int? opRating = null;
            int?meRating = null;
            if (pTurn.GameId == null)
            {
                return(pEfToken, new Result(new { Turn = turn }));
            }
            else
            {
                var eOpUserGame = EfUserGame.GetForIdDifferentUserId(pTurn.GameId, pEfToken.UserId.Value);
                var efOpUser    = EfUser.Get(eOpUserGame.UserId);
                //if (efOpUser.ConnectionId != null)
                //    Hub.Send(efOpUser.ConnectionId, "TurnSave", new { GameId = pTurn.GameId.Value, Script = pTurn.Script, Turn = turn, Rating = opRating });
                return(pEfToken, new Result(new { GameId = pTurn.GameId, Turn = turn, Rating = meRating }));
            }
        }
示例#5
0
 public object GetPractice(D1Chess_Srv.EfModel.Token pEfToken)
 {
     return(GetGame(pEfToken.IsAnonymous ? pEfToken.DeviceId.Value : pEfToken.UserId.Value));
 }