public ActionResult Details(int id, GameTypeVariant model)
        {
            var variant = GameTypeService.GetVariant(id);

            variant.Title            = model.Title;
            variant.ShortDescription = model.ShortDescription;
            variant.Description      = model.Description;
            variant.IsStaffPick      = model.IsStaffPick;
            if (ModelState.IsValid)
            {
                string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/GameType/"), variant.File.FileName);
                using (FileStream stream = System.IO.File.Open(path, FileMode.Open))
                {
                    VariantLib.GameVariant game = new VariantLib.GameVariant(stream);

                    game.VariantDescription = variant.ShortDescription;
                    game.VariantName        = variant.Title;
                    game.Save();
                }

                GameTypeService.Save();

                this.SetAlert(string.Format("The variant '{0}' has been updated.", variant.Title), AlertType.Success);
                return(RedirectToAction("Index"));
            }
            return(View(variant));
        }
Example #2
0
        public void GameType(int id, string token)
        {
            if (!TokenService.ValidateDateTimeToken(token))
            {
                Response.StatusCode = 403;
                Response.End();
                return;
            }

            var variant = GameTypeService.GetVariant(id);

            variant.File.Downloads.Add(new FileDownload()
            {
                DownloadedOn = DateTime.UtcNow,
                UserId       = Request.IsAuthenticated ? (int?)User.Identity.GetUserId <int>() : null,
                UserIP       = Request.UserHostAddress
            });
            variant.File.DownloadCount += 1;
            GameTypeService.Save();

            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + variant.DownloadName);
            Response.TransmitFile(Path.Combine(Server.MapPath("~/Content/Files/GameType"), variant.File.FileName));
            Response.End();
        }
Example #3
0
 public ActionResult Index()
 {
     return(View(new ViewModels.HomeViewModel
     {
         Maps = GameMapService.SearchVariants("", "release", false, null, true, null).Take(3),
         Types = GameTypeService.SearchVariants("", "release", false, null, true, null).Take(3)
     }));
 }
Example #4
0
 // GET: Upload
 public ActionResult Index()
 {
     return(View(new ViewModels.UploadIndex
     {
         JsonGameMaps = Newtonsoft.Json.JsonConvert.SerializeObject(GameMapService.GetMaps()),
         JsonGameTypes = Newtonsoft.Json.JsonConvert.SerializeObject(GameTypeService.GetTypes())
     }));
 }
        public ActionResult Delete(int id, GameTypeVariant model)
        {
            var variant = GameTypeService.GetVariant(id);

            variant.IsDeleted = !variant.IsDeleted;
            GameTypeService.Save();

            this.SetAlert(string.Format("The variant '{0}' has been deleted.", variant.Title), AlertType.Success);
            return(RedirectToAction("Index"));
        }
Example #6
0
        public ActionResult Edit(int id)
        {
            var variant = GameTypeService.GetVariant(id);

            if (!(variant.AuthorId == User.Identity.GetUserId <int>() || User.IsInRole("Mod")))
            {
                return(new HttpUnauthorizedResult());
            }

            return(View(variant));
        }
        public ActionResult Delete(int id)
        {
            var variant = GameTypeService.GetVariant(id);

            if (variant == null)
            {
                return(HttpNotFound());
            }

            return(View(variant));
        }
Example #8
0
 // GET: Admin/Home
 public ActionResult Index()
 {
     return(View(new Models.HomeIndexViewModel
     {
         AccountCount = UserService.Count(),
         ReactionCount = ReactionService.Count(),
         UploadCount = FileService.Count(),
         DownloadCount = FileService.DownloadCount(),
         GameVariants = GameTypeService.SearchVariants("", "release", false, null, null, null).Take(5),
         ForgeVariants = GameMapService.SearchVariants("", "release", false, null, null, null).Take(5),
     }));
 }
Example #9
0
        public ActionResult Reply(ViewModels.ReplyRequest model)
        {
            var variant = GameTypeService.GetVariant(model.Id);

            if (ModelState.IsValid)
            {
                int id = GameTypeService.Reply(model, User.Identity.GetUserId <int>());

                return(new RedirectResult(Url.Action("Details", new { slug = variant.Slug }) + "#reactions-" + id));
            }
            SetAlert("<strong>PARDON OUR DUST!</strong> Something went wrong when trying to reply, please try again.", AlertType.Danger);

            return(RedirectToAction("Details", new { slug = variant.Slug }));
        }
Example #10
0
        public ActionResult Delete(int id, GameTypeVariant model)
        {
            var variant = GameTypeService.GetVariant(id);

            if (!(variant.AuthorId == User.Identity.GetUserId <int>() || User.IsInRole("Mod")))
            {
                return(new HttpUnauthorizedResult());
            }

            variant.IsDeleted = true;
            GameTypeService.Save();

            SetAlert(string.Format("The game variant {0} is deleted.", variant.Title), AlertType.Success);
            return(RedirectToAction("Index"));
        }
Example #11
0
        public ActionResult Index(string q, int?page, int?typeId, bool?staffPick, string sort = "release", string order = "descending", string author = "")
        {
            ViewBag.selectedMapId = typeId;
            ViewBag.typeId        = GameTypeService.GetTypeSelectlist(typeId);
            ViewBag.q             = q;
            ViewBag.order         = order;
            ViewBag.sort          = sort;
            ViewBag.staffPick     = staffPick;


            int?authorId = null;

            if (!string.IsNullOrWhiteSpace(author))
            {
                var user = UserManager.FindByName(author);
                authorId       = user.Id;
                ViewBag.author = user.UserName;
            }

            var maps = GameTypeService.SearchVariants(q, sort, order == "ascending" ? true : false, typeId, staffPick, authorId);

            return(View(maps.ToPagedList(page ?? 1, 15)));
        }
Example #12
0
        public ActionResult GameType(int id)
        {
            var variant = GameTypeService.GetVariant(id);

            if (variant == null || variant.IsDeleted)
            {
                return(HttpNotFound());
            }

            return(Json(new
            {
                Type = "GameType",
                TypeName = variant.GameType.Name,
                Id = variant.Id,
                Name = variant.Title,
                Author = variant.Author.UserName,
                Description = variant.ShortDescription,
                Icon = @"/content/images/gametypes/thumbs/" + variant.GameType.InternalName + ".png",
                Download = Url.Action("Forge", "Download", new { id = variant.Id, token = TokenService.CreateDateTimeToken() }),
                Provider = "HaloShare",
                ProviderIcon = "/content/images/logo/white.png"
            }, JsonRequestBehavior.AllowGet));
        }
Example #13
0
        public ActionResult Edit(int id, Models.GameTypeVariant model)
        {
            if (ModelState.IsValid)
            {
                var variant = GameTypeService.GetVariant(id);

                if (!(variant.AuthorId == User.Identity.GetUserId <int>() || User.IsInRole("Mod")))
                {
                    return(new HttpUnauthorizedResult());
                }

                variant.Title            = model.Title;
                variant.Description      = model.Description;
                variant.ShortDescription = model.ShortDescription;

                string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/GameType/"), variant.File.FileName);
                using (FileStream stream = System.IO.File.Open(path, FileMode.Open))
                {
                    VariantLib.GameVariant type = new VariantLib.GameVariant(stream);

                    type.VariantDescription = variant.ShortDescription;
                    type.VariantName        = variant.Title;
                    type.Save();
                }

                if (User.IsInRole("Mod"))
                {
                    variant.IsStaffPick = model.IsStaffPick;
                }

                GameTypeService.Save();

                SetAlert(string.Format("The game variant is saved.", variant.Title), AlertType.Success);
                return(RedirectToAction("Details", new { slug = variant.Slug }));
            }
            return(View(model));
        }
Example #14
0
 public ActionResult Details(int slug)
 {
     ViewBag.Token = TokenService.CreateDateTimeToken();
     return(View(GameTypeService.GetVariant(slug)));
 }
Example #15
0
 public ActionResult Rate(int id, int rating)
 {
     return(Json(GameTypeService.Rate(id, User.Identity.GetUserId <int>(), rating)));
 }
Example #16
0
        public ActionResult GameType(ViewModels.UploadViewModel model)
        {
            Response.TrySkipIisCustomErrors = true;
            if (ModelState.IsValid)
            {
                var currentUser = UserManager.FindById(User.Identity.GetUserId <int>());

                Models.GameTypeVariant variant = new Models.GameTypeVariant();
                variant.Title            = model.Title.Replace("\0", "");
                variant.ShortDescription = model.Description;
                variant.Description      = model.Content;
                variant.CreatedOn        = DateTime.UtcNow;
                variant.AuthorId         = User.Identity.GetUserId <int>();
                variant.File             = new Models.File()
                {
                    FileSize   = model.File.ContentLength,
                    FileName   = Guid.NewGuid().ToString() + ".gtv",
                    UploadedOn = variant.CreatedOn,
                    MD5        = model.File.InputStream.ToMD5()
                };

                var validateGame = GameTypeService.ValidateHash(variant.File.MD5);

                if (validateGame != null)
                {
                    Response.StatusCode = 400;
                    return(Content(string.Format(
                                       "<b>Keep it Clean!</b> The game variant has already been uploaded: <a target=\"_blank\" href=\"{0}\">{1}</a>.",
                                       Url.Action("Details", "GameType", new { slug = validateGame.Slug }),
                                       validateGame.Title)));
                }

                /* Read the map type from the uploaded file.
                 * This is also a validation message to make sure
                 * that the file uploaded is an actual map.
                 */

                var detectType = VariantDetector.Detect(model.File.InputStream);
                if (detectType == VariantType.Invalid)
                {
                    // The given map doesn't exist.
                    model.File.InputStream.Close();

                    Response.StatusCode = 400;
                    return(Content("<b>Keep it Clean!</b> The file uploaded is invalid. Please make sure it's a valid game variant."));
                }
                else if (detectType == VariantType.ForgeVariant)
                {
                    // The given map doesn't exist.
                    model.File.InputStream.Close();

                    Response.StatusCode = 400;
                    return(Content("<strong>PARDON OUR DUST!</strong> Can't upload forge variant as game variant."));
                }

                string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/GameType/"), variant.File.FileName);
                using (var stream = new System.IO.MemoryStream())
                {
                    model.File.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                    model.File.InputStream.CopyTo(stream);

                    GameVariant variantItem = new GameVariant(stream);

                    var type = GameTypeService.GetByInternalId(variantItem.TypeId);

                    if (type != null)
                    {
                        variant.GameTypeId = type.Id;

                        variantItem.VariantName = model.Title;
                        //variantItem.VariantAuthor = currentUser.UploaderName;
                        variantItem.VariantDescription = variant.ShortDescription;
                        variantItem.Save();


                        // Save the file.
                        using (var fileStream = System.IO.File.Create(path))
                        {
                            stream.Seek(0, System.IO.SeekOrigin.Begin);
                            stream.CopyTo(fileStream);
                        }
                    }
                    else
                    {
                        Response.StatusCode = 400;
                        return(Content("<strong>PARDON OUR DUST!</strong> We currently do not support the uploaded gametype."));
                    }
                }

                GameTypeService.AddVariant(variant);
                GameTypeService.Save();

                return(Content(Url.Action("Details", "GameType", new { slug = variant.Slug })));
            }

            Response.StatusCode = 400;
            return(View("~/Views/Shared/_ModelState.cshtml"));
        }