Пример #1
0
        static void Main(string[] args)
        {
            DbContextOptions <JusticePortalContext> x = new DbContextOptions <JusticePortalContext>();

            db = new DBFuncs(new JusticePortalContext());
            var rec    = db.GetBlock(int.Parse(ConfigurationManager.AppSettings["SebraBlockId"]));
            var json   = JObject.Parse(rec.Jsonvalues);
            var docArr = json["docs"] as JArray;
            int days   = 0;

            if (!int.TryParse(ConfigurationManager.AppSettings["days"], out days))
            {
                days = 3;
            }

            var today      = DateTime.Now.AddDays(-days).ToString("yyyy-MM-dd"); //"2020-07-02"
            var currentDoc = (docArr ?? throw new InvalidOperationException()).FirstOrDefault(x => x["date"].Value <string>() == today);

            if (currentDoc == null)
            {
                return;
            }
            var docRec = db.GetBlob(currentDoc["docId"].Value <string>());

            File.WriteAllBytes(ConfigurationManager.AppSettings["pathForExport"], docRec.Content);
        }
Пример #2
0
 public void AutoLogIn()
 {
     if (loadedRememberMe)
     {
         DBFuncs.LogIn(loadedUsername, loadedPwhash, true);
     }
 }
Пример #3
0
 void OnregBtnClick()
 {
     nameStr = UIManager.GetInputStr("nameInput");
     pwdStr  = UIManager.GetInputStr("pwdInput");
     //PlaySE
     MusicManager.PlaySe("click");
     if (nameStr == "" || pwdStr == "")
     {
         GameFuncs.CreateMsg("用户名或密码不能为空!");
         return;
     }
     else
     {
         if (DBFuncs.FindPlayer(nameStr, pwdStr))
         {
             //弹出对话框"用户名已存在!"
             GameFuncs.CreateMsg("用户名已存在!");
         }
         else
         {
             //Register
             DBFuncs.AddPlayer(nameStr, pwdStr);
             GameFuncs.CreateMsg("注册成功!请点击登录进入游戏");
         }
     }
 }
Пример #4
0
    public void TryToSignUp()
    {
        EverythingOff();

        waitingDisplay.SetActive(true);
        cancelContainer.SetActive(true);
        DBFuncs.CreateAccount(signUp_UsernameText.text, signUp_Password.text, signUp_Email.text);
    }
Пример #5
0
 private void OnApplicationQuit()
 {
     //update db
     //update player
     if (Globals.player != null)
     {
         DBFuncs.UpdatePlayer();
         JsonFuncs.StoreHeroes();
         JsonFuncs.StoreDresses();
         JsonFuncs.StoreItems();
         JsonFuncs.StoreRoom();
     }
 }
Пример #6
0
    void Start()
    {
        DBFuncs.InitAllLists();
        Globals.lastScene = "Login";
        Button loginBtn = UIManager.GetButton("loginBtn");

        loginBtn.onClick.AddListener(OnloginBtnClick);
        Button regBtn = UIManager.GetButton("regBtn");

        regBtn.onClick.AddListener(OnregBtnClick);

        //PlayBGM
        MusicManager.PlayBgm("normal");
    }
Пример #7
0
    void OnloginBtnClick()
    {
        nameStr = UIManager.GetInputStr("nameInput");
        pwdStr  = UIManager.GetInputStr("pwdInput");
        //PlaySE
        MusicManager.PlaySe("click");;
        //Formal
        //Globals.isFirst = DBFuncs.FindSingle<int>("Players", "isFirst");
        if (nameStr == "" || pwdStr == "")
        {
            GameFuncs.CreateMsg("用户名或密码不能为空!");
            return;
        }
        else
        {
            if (DBFuncs.FindPlayer(nameStr, pwdStr))
            {
                //Enter Loading->Chat/Main
                if (Globals.player.isFirst)
                {
                    Globals.player.isFirst = false;
                    //Test
                    Globals.currentDialog = "test";

                    Globals.nextScene = "Main";
                    GameFuncs.GoToSceneAsync("Chat");
                }
                else
                {
                    //Load Globals.items&Globals.heroes
                    GameFuncs.GoToSceneAsync("Main");
                }
            }
            else
            {
                //弹出对话框"用户名或密码错误!"
                GameFuncs.CreateMsg("用户名或密码错误!");
            }
        }
    }
Пример #8
0
    public void TryToLogIn()
    {
        offlineContainer.SetActive(false);
        onlineContainer.SetActive(false);
        cancelContainer.SetActive(true);

        LogInMenu.SetActive(false);
        LogInContainer.SetActive(false);
        SignUpContainer.SetActive(false);
        ForgotPwContainer.SetActive(false);
        popup.SetActive(false);

        waitingDisplay.SetActive(true);

        if (RememberMeToggle.isOn)
        {
            Debug.Log("Hash: " + loadedPwhash);
            DBFuncs.LogIn(loadedUsername, loadedPwhash, true);
        }
        else
        {
            DBFuncs.LogIn(logIn_UsernameText.text, logIn_Password.text);
        }
    }
Пример #9
0
 void Awake()
 {
     self = this;
 }
Пример #10
0
 public BaseController(JusticePortalContext jpc)
 {
     this.db = new DBFuncs(jpc);
 }
Пример #11
0
        private void Console(MyContext db)
        {
            Field <GamesDataType>(
                "newConsole",
                description: "Issue a new console command to a game",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <NewConsoleInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <NewConsoleDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can play.");
                }

                if (!Enum.IsDefined(typeof(ConsoleCommands), input.command))
                {
                    throw new ExecutionError("The command you issued was unrecognized. This shouldn't happen if you issued the request through the official front end.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The game ID you provided is malformed. Please verify and try again.");
                }

                //Does this game id exist?
                var game = db.GamesData.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (game == null)
                {
                    throw new ExecutionError("The game id you provided (" + input.id + ") does not appear to exist.");
                }

                if (game.Closed)
                {
                    throw new ExecutionError("This game has ended. No further actions are possible.");
                }

                //For some reason, `.Any(x => x.OwnerId.Equals(user.OwnerId))` is not working. I don't know why yet.
                if (!game.GamesDataPlayers.Select(x => x.Owner).Contains(user))
                {
                    throw new ExecutionError("You're not participating in this game and so cannot issue console commands.");
                }

                //Command-specific error checks
                switch ((ConsoleCommands)input.command)
                {
                case ConsoleCommands.DRAW:
                    break;

                case ConsoleCommands.FREEZE:
                    if (game.ClockFrozen)
                    {
                        throw new InvalidOperationException("The clocks are already frozen.");
                    }
                    break;

                case ConsoleCommands.THAW:
                    if (!game.ClockFrozen)
                    {
                        throw new InvalidOperationException("The clocks are not frozen.");
                    }
                    break;
                }

                var consolekey = GuidGenerator.GenerateSequentialGuid();
                var cmd        = new Consoles
                {
                    EntryId = consolekey,
                    GameId  = game.EntryId,
                    Game    = game,
                    OwnerId = user.OwnerId,
                    Owner   = user,
                    Command = input.command
                };
                db.Consoles.Add(cmd);

                var vote = new ConsolesVotes
                {
                    EntryId         = GuidGenerator.GenerateSequentialGuid(),
                    ConsoleId       = consolekey,
                    Voter           = user.OwnerId,
                    VoterNavigation = user,
                    Vote            = true
                };
                db.ConsolesVotes.Add(vote);
                db.SaveChanges();

                return(game);
            }
                );
            Field <GamesDataType>(
                "withdrawConsole",
                description: "Withdraw a console command",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <WithdrawConsoleInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <WithdrawConsoleDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can play.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The command ID you provided is malformed. Please verify and try again.");
                }

                //Does this console command exist?
                var cmd = db.Consoles.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (cmd == null)
                {
                    throw new ExecutionError("The command id you provided (" + input.id + ") does not appear to exist.");
                }

                if (cmd.OwnerId != user.OwnerId)
                {
                    throw new ExecutionError("Only the person who issued the command can withdraw it.");
                }

                GamesData game = cmd.Game;
                db.Consoles.Remove(cmd);
                db.SaveChanges();

                return(game);
            }
                );
            Field <GamesDataType>(
                "voteConsole",
                description: "Vote on a console command",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <VoteConsoleInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <VoteConsoleDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can play.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The command ID you provided is malformed. Please verify and try again.");
                }

                //Does this console command exist?
                var cmd = db.Consoles.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (cmd == null)
                {
                    throw new ExecutionError("The command id you provided (" + input.id + ") does not appear to exist.");
                }

                GamesData game = cmd.Game;
                //Delete any existing votes by this user
                db.ConsolesVotes.RemoveRange(db.ConsolesVotes.Where(x => x.ConsoleId.Equals(cmd.EntryId) && x.Voter.Equals(user.OwnerId)));
                //Set their vote
                var vote = new ConsolesVotes
                {
                    EntryId         = GuidGenerator.GenerateSequentialGuid(),
                    ConsoleId       = cmd.EntryId,
                    Console         = cmd,
                    Voter           = user.OwnerId,
                    VoterNavigation = user,
                    Vote            = input.vote
                };
                db.ConsolesVotes.Add(vote);
                db.SaveChanges();

                //Check if all the votes are in and execute if so
                if (db.ConsolesVotes.Where(x => x.ConsoleId.Equals(cmd.EntryId)).ToArray().Length == game.GamesDataPlayers.Count)
                {
                    //Load the latest game state
                    Game gameobj;
                    try
                    {
                        gameobj = GameFactory.LoadGame(game.GameMeta.Shortcode, game.GamesDataStates.Last().State);
                    }
                    catch (Exception e)
                    {
                        throw new ExecutionError("An error occurred while trying to load the game. Please alert the administrators. The game code said the following: " + e.Message);
                    }

                    var args = new ExecuteCommandInput
                    {
                        Gameobj = gameobj,
                        Gamerec = game,
                        Console = cmd
                    };
                    DBFuncs.ExecuteCommand(db, args);
                    db.Consoles.Remove(cmd);
                }

                db.SaveChanges();
                return(game);
            }
                );
        }
Пример #12
0
        private void Challenges(MyContext db)
        {
            Field <ChallengeType>(
                "issueChallenge",
                description: "Issue a new challenge",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <NewChallengeInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <NewChallengeDTO>("input");

                var game = db.GamesMeta.SingleOrDefault(x => x.Shortcode.Equals(input.game));
                if (game == null)
                {
                    throw new ExecutionError("Could not find a game with the name " + input.game + ".");
                }
                //Validate numPlayers
                int[] counts = game.PlayerCounts.Split(',').Select(x => int.Parse(x)).ToArray();
                if (!counts.Contains(input.numPlayers))
                {
                    throw new ExecutionError("The number of players you requested (" + input.numPlayers.ToString() + ") is not supported by " + game.Name + ". Only the following are acceptable: " + game.PlayerCounts + ".");
                }
                //Set clock to default if necessary
                if ((input.clockStart == null) || (input.clockStart < 1))
                {
                    input.clockStart = 72;
                }
                if ((input.clockInc == null) || (input.clockInc < 1))
                {
                    input.clockInc = 24;
                }
                if ((input.clockMax == null) || (input.clockMax < 1))
                {
                    input.clockMax = 240;
                }
                //Validate variants
                List <string> vars = game.GamesMetaVariants.Select(x => x.Name).ToList();
                vars.Add("Unrated");
                vars.Add("Hard Time");
                foreach (var variant in input.variants)
                {
                    if (!vars.Contains(variant))
                    {
                        throw new ExecutionError("The variant '" + variant + "' is not supported by " + game.Name + ".");
                    }
                }
                //Validate any challengees (including seat)
                foreach (var player in input.challengees)
                {
                    if (!db.Owners.Any(x => x.OwnerId.Equals(GuidGenerator.HelperStringToBA(player))))
                    {
                        throw new ExecutionError("Could not find player ID " + player + ".");
                    }
                }

                //Build record
                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You do not appear to have a user profile. You must create a profile before playing.");
                }
                byte[] challengeId = GuidGenerator.GenerateSequentialGuid();
                var rec            = new Challenges {
                    ChallengeId = challengeId,
                    GameId      = game.GameId,
                    OwnerId     = user.OwnerId,
                    NumPlayers  = (byte)input.numPlayers,
                    Notes       = input.notes,
                    ClockStart  = (ushort)input.clockStart,
                    ClockInc    = (ushort)input.clockInc,
                    ClockMax    = (ushort)input.clockMax,
                };
                if (input.variants.Length > 0)
                {
                    rec.Variants = String.Join('\n', input.variants);
                }
                //Add issuer
                var issuer = new ChallengesPlayers {
                    EntryId     = GuidGenerator.GenerateSequentialGuid(),
                    ChallengeId = challengeId,
                    OwnerId     = user.OwnerId,
                    Confirmed   = true
                };
                bool seated = false;
                if (input.seat != null)
                {
                    if (input.numPlayers != 2)
                    {
                        throw new ExecutionError("The 'seat' field is only meaningful in two-player games.");
                    }
                    if ((input.seat != 1) && (input.seat != 2))
                    {
                        throw new ExecutionError("The only valid values of 'seat' are '1' and '2'.");
                    }
                    seated      = true;
                    issuer.Seat = (byte)input.seat;
                }
                rec.ChallengesPlayers.Add(issuer);
                foreach (var player in input.challengees)
                {
                    var node = new ChallengesPlayers {
                        EntryId     = GuidGenerator.GenerateSequentialGuid(),
                        ChallengeId = challengeId,
                        OwnerId     = GuidGenerator.HelperStringToBA(player),
                        Confirmed   = false
                    };
                    if (seated)
                    {
                        node.Seat = (byte)((input.seat % 2) + 1);
                    }
                    rec.ChallengesPlayers.Add(node);
                }

                db.Challenges.Add(rec);
                db.SaveChanges();
                return(rec);
            }
                );
            Field <ChallengeType>(
                "respondChallenge",
                description: "Confirm or withdraw from a pending challenge",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <RespondChallengeInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <RespondChallengeDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! You must create a profile before you can play.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The challenge ID you provided is malformed. Please verify and try again.");
                }

                var challenge = db.Challenges.SingleOrDefault(x => x.ChallengeId.Equals(binaryid));
                if (challenge == null)
                {
                    throw new ExecutionError("The challenge '" + input.id + "' does not appear to exist.");
                }

                var player = db.ChallengesPlayers.SingleOrDefault(x => x.ChallengeId.Equals(challenge.ChallengeId) && x.OwnerId.Equals(user.OwnerId));
                //challenge.ChallengesPlayers.SingleOrDefault(x => x.OwnerId.Equals(user.OwnerId));

                //if confirming
                if (input.confirmed)
                {
                    //They were directly invited and so are already in the database
                    if ((player != null) && (!player.Confirmed))
                    {
                        player.Confirmed = true;
                        db.ChallengesPlayers.Update(player);
                    }
                    //otherwise, add them
                    else if (player == null)
                    {
                        var node = new ChallengesPlayers
                        {
                            EntryId     = GuidGenerator.GenerateSequentialGuid(),
                            ChallengeId = GuidGenerator.HelperStringToBA(input.id),
                            OwnerId     = user.OwnerId,
                            Confirmed   = true,
                            Seat        = null
                        };
                        db.ChallengesPlayers.Add(node);
                    }

                    //Check for full challenge and create game if necessary
                    if (challenge.ChallengesPlayers.Where(x => x.Confirmed).Count() == challenge.NumPlayers)
                    {
                        //Prepare the variant and player lists for the game factory
                        string[] variants;
                        if (String.IsNullOrWhiteSpace(challenge.Variants))
                        {
                            variants = new string[0];
                        }
                        else
                        {
                            variants = challenge.Variants.Split('\n');
                        }
                        string[] players;
                        if (challenge.NumPlayers == 2)
                        {
                            var plist  = new List <string>();
                            var parray = challenge.ChallengesPlayers.ToArray();
                            //only one of the players will have a defined seat
                            if ((parray[0].Seat == 1) || (parray[1].Seat == 2))
                            {
                                plist.Add(GuidGenerator.HelperBAToString(parray[0].Owner.PlayerId));
                                plist.Add(GuidGenerator.HelperBAToString(parray[1].Owner.PlayerId));
                            }
                            else if ((parray[0].Seat == 2) || (parray[1].Seat == 1))
                            {
                                plist.Add(GuidGenerator.HelperBAToString(parray[1].Owner.PlayerId));
                                plist.Add(GuidGenerator.HelperBAToString(parray[0].Owner.PlayerId));
                            }
                            else
                            {
                                foreach (var o in challenge.ChallengesPlayers.Select(x => (Owners)x.Owner))
                                {
                                    plist.Add(GuidGenerator.HelperBAToString(o.PlayerId));
                                }
                                plist.Shuffle();
                            }
                            players = plist.ToArray();
                        }
                        else
                        {
                            var plist = new List <string>();
                            foreach (var o in challenge.ChallengesPlayers.Select(x => (Owners)x.Owner))
                            {
                                plist.Add(GuidGenerator.HelperBAToString(o.PlayerId));
                            }
                            plist.Shuffle();
                            players = plist.ToArray();
                        }

                        //Now create the game object. If it fails, then everything aborts.
                        Game gameobj;
                        try
                        {
                            gameobj = GameFactory.CreateGame(challenge.Game.Shortcode, players, variants);
                        }
                        catch (ArgumentException e)
                        {
                            throw new ExecutionError("An error occurred while trying to create the game. Please alert the administrators. The game code said the following: " + e.Message);
                        }
                        //Everything appears to be in order, so now we create the various DB objects and store them
                        var ngdata = new NewGameInput
                        {
                            Gameobj    = gameobj,
                            Shortcode  = challenge.Game.Shortcode,
                            ClockStart = challenge.ClockStart,
                            ClockMax   = challenge.ClockMax,
                            ClockInc   = challenge.ClockInc,
                            Variants   = challenge.Variants
                        };
                        var newgame = DBFuncs.NewGame(db, ngdata);

                        //Delete the challenge
                        db.Challenges.Remove(challenge);
                    }
                }
                //if withdrawing and the player entry already exists
                else if (player != null)
                {
                    //Is it the challenge issuer who's withdrawing?
                    if (player.OwnerId.SequenceEqual(challenge.OwnerId))
                    {
                        db.Challenges.Remove(challenge);
                    }
                    //Or someone else?
                    else
                    {
                        db.ChallengesPlayers.Remove(player);
                    }
                }
                db.SaveChanges();
                return(challenge);
            }
                );
        }
Пример #13
0
 public HomeController(JusticePortalContext jpc, ICielaComm cielaComm, IConfiguration config)
 {
     this.db        = new DBFuncs(jpc);
     this.cielaComm = cielaComm;
     this.config    = config;
 }
Пример #14
0
        private void GamesData(MyContext db)
        {
            Field <GamesDataType>(
                "moveGame",
                description: "Submit a move to a game",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <MoveGameInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <MoveGameDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can play.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The game ID you provided is malformed. Please verify and try again.");
                }

                //Does this game id exist?
                var game = db.GamesData.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (game == null)
                {
                    throw new ExecutionError("The game id you provided (" + input.id + ") does not appear to exist.");
                }

                if (game.Closed)
                {
                    throw new ExecutionError("This game has ended. No further moves are possible.");
                }

                //Load the latest game state
                Game gameobj;
                try
                {
                    gameobj = GameFactory.LoadGame(game.GameMeta.Shortcode, game.GamesDataStates.Last().State);
                }
                catch (Exception e)
                {
                    throw new ExecutionError("An error occurred while trying to load the game. Please alert the administrators. The game code said the following: " + e.Message);
                }

                //Is the move legal?
                Game newgameobj;
                try
                {
                    newgameobj = gameobj.Move(GuidGenerator.HelperBAToString(user.PlayerId), input.move);
                }
                catch (Exception e)
                {
                    throw new ExecutionError("Your move was not accepted. The game code said the following: " + e.Message);
                }

                //Build game object
                var uginput = new UpdateGameInput
                {
                    Gameobj = newgameobj,
                    Gamerec = game,
                    Mover   = user.OwnerId
                };
                DBFuncs.UpdateGame(db, uginput);
                db.SaveChanges();

                return(game);
            }
                );
            Field <GamesDataPreviewType>(
                "moveGamePreview",
                description: "Preview a move to a game",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <MoveGameInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <MoveGameDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can play.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The game ID you provided is malformed. Please verify and try again.");
                }

                //Does this game id exist?
                var game = db.GamesData.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (game == null)
                {
                    throw new ExecutionError("The game id you provided (" + input.id + ") does not appear to exist.");
                }

                if (game.Closed)
                {
                    throw new ExecutionError("This game has ended. No further moves are possible.");
                }

                //Load the latest game state
                Game gameobj;
                try
                {
                    gameobj = GameFactory.LoadGame(game.GameMeta.Shortcode, game.GamesDataStates.Last().State);
                }
                catch (Exception e)
                {
                    throw new ExecutionError("An error occurred while trying to load the game. Please alert the administrators. The game code said the following: " + e.Message);
                }

                //Is the move legal?
                Game newgameobj;
                try
                {
                    newgameobj = gameobj.Move(GuidGenerator.HelperBAToString(user.PlayerId), input.move);
                }
                catch (Exception e)
                {
                    throw new ExecutionError("Your move was not accepted. The game code said the following: " + e.Message);
                }

                return(newgameobj);
            }
                );
            Field <GamesDataChatType>(
                "newChat",
                description: "Post a new chat message to a game",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <NewChatInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <NewChatDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can chat in games.");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The game ID you provided is malformed. Please verify and try again.");
                }

                //Does this game id exist?
                var game = db.GamesData.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (game == null)
                {
                    throw new ExecutionError("The game id you provided (" + input.id + ") does not appear to exist.");
                }

                var rec = new GamesDataChats
                {
                    ChatId  = GuidGenerator.GenerateSequentialGuid(),
                    GameId  = binaryid,
                    OwnerId = user.OwnerId,
                    Message = input.message
                };
                db.GamesDataChats.Add(rec);
                db.SaveChanges();
                return(rec);
            }
                );
            Field <GamesDataType>(
                "resignGame",
                description: "Resign from a game in progress",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ResignGameInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <ResignGameDTO>("input");

                var user = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (user == null)
                {
                    throw new ExecutionError("You don't appear to have a user account! Only registered users can play.");
                }

                if (!input.confirmed)
                {
                    throw new ExecutionError("You must set `confirmed` to `true` to proceed. This action cannot be undone!");
                }

                byte[] binaryid;
                try
                {
                    binaryid = GuidGenerator.HelperStringToBA(input.id);
                }
                catch
                {
                    throw new ExecutionError("The game ID you provided is malformed. Please verify and try again.");
                }

                //Does this game id exist?
                var game = db.GamesData.SingleOrDefault(x => x.EntryId.Equals(binaryid));
                if (game == null)
                {
                    throw new ExecutionError("The game id you provided (" + input.id + ") does not appear to exist.");
                }

                if (game.Closed)
                {
                    throw new ExecutionError("This game has ended. No further moves are possible.");
                }

                //Load the latest game state
                Game gameobj;
                try
                {
                    gameobj = GameFactory.LoadGame(game.GameMeta.Shortcode, game.GamesDataStates.Last().State);
                }
                catch (Exception e)
                {
                    throw new ExecutionError("An error occurred while trying to load the game. Please alert the administrators. The game code said the following: " + e.Message);
                }

                //Is the move legal?
                Game newgameobj;
                try
                {
                    newgameobj = gameobj.Resign(GuidGenerator.HelperBAToString(user.PlayerId));
                }
                catch (Exception e)
                {
                    throw new ExecutionError("The resignation failed. The game code said the following: " + e.Message);
                }

                //Build game object
                var uginput = new UpdateGameInput
                {
                    Gameobj = newgameobj,
                    Gamerec = game,
                    Mover   = user.OwnerId
                };
                DBFuncs.UpdateGame(db, uginput);
                db.SaveChanges();

                return(game);
            }
                );
        }