Пример #1
0
        public ActionResult Create([Bind(Include = "GameID,GameName,GameDescription, Platform, ")] GamesData games, HttpPostedFileBase ImageFile)
        {
            if (ModelState.IsValid)
            {
                if (ImageFile != null)
                {
                    string pic  = System.IO.Path.GetFileName(ImageFile.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/images/profile"), pic);
                    ImageFile.SaveAs(path);

                    games.ImagePath = pic;

                    using (MemoryStream ms = new MemoryStream())
                    {
                        ImageFile.InputStream.CopyTo(ms);
                        games.Picture = ms.GetBuffer();
                    }
                }
                db.games.Add(games);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(games));
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            GamesData games = db.games.Find(id);

            db.games.Remove(games);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public static GamesData NewGame(MyContext db, NewGameInput input)
        {
            var newgame = new GamesData
            {
                EntryId     = GuidGenerator.GenerateSequentialGuid(),
                GameMetaId  = db.GamesMeta.Single(x => x.Shortcode.Equals(input.Shortcode)).GameId,
                Closed      = false,
                Alert       = false,
                ClockStart  = input.ClockStart,
                ClockInc    = input.ClockInc,
                ClockMax    = input.ClockMax,
                ClockFrozen = false,
                Variants    = input.Variants
            };

            db.GamesData.Add(newgame);

            foreach (var p in input.Gameobj.Players)
            {
                var oid      = PlayerId2OwnerId(db, GuidGenerator.HelperStringToBA(p));
                var newclock = new GamesDataClocks
                {
                    GameId  = newgame.EntryId,
                    OwnerId = oid,
                    Bank    = (short)newgame.ClockStart
                };
                db.GamesDataClocks.Add(newclock);
                var newplayer = new GamesDataPlayers
                {
                    GameId  = newgame.EntryId,
                    OwnerId = oid,
                };
                db.GamesDataPlayers.Add(newplayer);
            }

            foreach (var p in input.Gameobj.Whoseturn())
            {
                var newwho = new GamesDataWhoseturn
                {
                    GameId  = newgame.EntryId,
                    OwnerId = PlayerId2OwnerId(db, GuidGenerator.HelperStringToBA(p)),
                };
                db.GamesDataWhoseturn.Add(newwho);
            }

            var newstate = new GamesDataStates
            {
                StateId   = GuidGenerator.GenerateSequentialGuid(),
                GameId    = newgame.EntryId,
                State     = input.Gameobj.Serialize(),
                RenderRep = input.Gameobj.Render()
            };

            db.GamesDataStates.Add(newstate);
            return(newgame);
        }
Пример #4
0
 public ActionResult Edit([Bind(Include = "GameID,GameName,GameDescription,Platform")] GamesData games)
 {
     if (ModelState.IsValid)
     {
         db.Entry(games).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(games));
 }
Пример #5
0
        public ActionResult Create(Game game)
        {
            if (game.Winner != game.Loser)
            {
                GamesData.PersistGame(game);
                Games.Add(game);
                Players.UpdateRatings(game);
            }

            return(Redirect("~/"));
        }
Пример #6
0
        /// <summary>
        ///     Get the game data matching the specified title
        /// </summary>
        /// <param name="gamesData"></param>
        /// <param name="gameTitle">Title of the game</param>
        /// <returns>Game information</returns>
        internal static GamesData.Game GetGameByTitle(GamesData gamesData, string gameTitle)
        {
            foreach (GamesData.Game game in gamesData.Games)
            {
                if (game.Title.Equals(gameTitle))
                {
                    return(game);
                }
            }

            throw new Exception("Unable to find game data for the given title");
        }
Пример #7
0
        // GET: GamesData/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GamesData games = db.games.Find(id);

            if (games == null)
            {
                return(HttpNotFound());
            }
            return(View(games));
        }
Пример #8
0
        public static List <GameData> GetGameData()
        {
            List <GameData> categories = new List <GameData>();

            XmlSerializer serializer = new XmlSerializer(typeof(GamesData));

            using (FileStream fileStream = new FileStream(Properties.Settings.Default.DefaultDir + @"\Resources\Sources\GameData.xml", FileMode.Open))
            {
                GamesData result = (GamesData)serializer.Deserialize(fileStream);
                categories = result.Games;
            }

            return(categories);
        }
Пример #9
0
        public static void WriteGameData(List <GameData> GameData)
        {
            string GamesDataPath = Properties.Settings.Default.DefaultDir + @"\Resources\Sources\GameData.xml";

            GamesData gd = new GamesData();

            gd.Games = GameData;

            XmlSerializer LibrarySerializer = new XmlSerializer(typeof(GamesData));

            using (StreamWriter Writer = new StreamWriter(GamesDataPath))
            {
                LibrarySerializer.Serialize(Writer, gd);
            }
        }
Пример #10
0
        // GET: GamesData/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GamesData games = db.games.Find(id);

            if (games == null)
            {
                throw new HttpException(404, "Course Id not Found!");
                //return HttpNotFound();
            }
            return(View(games));
        }
Пример #11
0
        public ActionResult _GetGameList()
        {
            string    lang  = !string.IsNullOrEmpty(Request.QueryString["locale"]) ? Request.QueryString["locale"] : "en";
            GamesData games = ProcessController.GetGames(new BaseApiData {
            });

            ViewBag.GameList = games.games;


            Dictionary <int, List <GamesData.Game> > sortedGameList = new Dictionary <int, List <GamesData.Game> >();

            foreach (var game in games.games)
            {
                if (lang != "en")
                {
                    game.translatedName = game.translatedNames.First(x => x.locale == lang).translation;
                }
                if (lang != "zh-CN")
                {
                    game.simplifiedChineseName = game.translatedNames.First(x => x.locale == "zh-CN").translation;
                }

                if (sortedGameList.ContainsKey(game.gameTypeId))
                {
                    sortedGameList[game.gameTypeId].Add(game);
                }
                else
                {
                    sortedGameList.Add(game.gameTypeId, new List <GamesData.Game> {
                        game
                    });
                }
            }



            SelectList langList = new SelectList(sortedGameList[11][0].translatedNames, "locale", "locale", lang);


            ViewBag.LangList       = langList;
            ViewBag.Lang           = lang;
            ViewBag.SortedGameList = sortedGameList;


            ViewBag.Message = "Your contact page.";

            return(PartialView());
        }
Пример #12
0
        public static void Load(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var gamesFile = path + "Games.txt";

            Games.Initialise(GamesData.Load(gamesFile));

            var playersFile = path + "Players.txt";

            Players.Initialise(PlayersData.Load(playersFile));

            var retiredPlayersFile = path + "RetiredPlayers.txt";

            RetiredPlayers.Initialise(RetiredPlayersData.Load(retiredPlayersFile));
        }
Пример #13
0
    private IEnumerator Load()
    {
        string songName = "C:/videogames/settings.json";
        string url      = string.Format("file://{0}", songName);

        print(url);
        WWW www = new WWW(url);

        yield return(www);

        data = JsonUtility.FromJson <GamesData>(www.text) as GamesData;
        int id = 0;

        foreach (GameData gameData in data.games)
        {
            gameData.id = id;
            id++;
        }
        GetComponent <MainScreen>().Init();
    }
Пример #14
0
        public static GamesData GetGames(BaseApiData baseApi)
        {
            try
            {
                GamesData games = new GamesData();
                string    uri   = "https://ws-test.insvr.com/jsonapi/getgames";

                string param = JsonConvert.SerializeObject(baseApi, Formatting.Indented);

                string response = SendRequest(uri, param);

                GamesData gameList = JsonConvert.DeserializeObject <GamesData>(response);

                return(gameList);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #15
0
        public async Task GetRandomGame(CommandContext ctx)
        {
            string json = "https://static.nvidiagrid.net/supported-public-game-list/gfnpc.json?JSON";

            using (var client = new HttpClient())
            {
                var result = await client.GetAsync(json);

                var str = await result.Content.ReadAsStringAsync();

                var obj = JsonConvert.DeserializeObject <List <GamesData> >(str);

                Random    rnd  = new Random();
                GamesData item = obj[rnd.Next(0, obj.Count)];

                var msg = ($" \n 🎮 Hey { ctx.User.Username } you should try ```{item.ToString()}```");

                var embed = new DiscordEmbedBuilder
                {
                    Description = msg,
                };
                await ctx.RespondAsync(embed : embed).ConfigureAwait(false);
            }
        }
Пример #16
0
 /// <summary>
 ///     Retrieves the games and mods data into the application
 /// </summary>
 private static void LoadData()
 {
     GamesData = Utilities.GetGamesData();
     ModsData  = Utilities.GetModsData();
 }
Пример #17
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);
            }
                );
        }
 public static void Load()
 {
     Players.Initialise(PlayersData.Load());
     Games.Initialise(GamesData.Load());
 }
Пример #19
0
 public ActionResult Delete(string Id)
 {
     GamesData.Delete(Id);
     Games.Initialise(GamesData.Load());
     return(Redirect("/Games"));
 }