public ActionResult Details(int id, GameMapVariant model) { var variant = GameMapService.GetVariant(id); variant.Title = model.Title; variant.ShortDescription = model.ShortDescription; variant.Description = model.Description; variant.MinPlayers = model.MinPlayers; variant.MaxPlayers = model.MaxPlayers; variant.IsStaffPick = model.IsStaffPick; if (ModelState.IsValid) { string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/Forge/"), variant.File.FileName); using (FileStream stream = System.IO.File.Open(path, FileMode.Open)) { VariantLib.ForgeVariant forge = new VariantLib.ForgeVariant(stream); forge.VariantDescription = variant.ShortDescription; forge.VariantName = variant.Title; forge.Save(); } GameMapService.Save(); this.SetAlert(string.Format("The variant '{0}' has been updated.", variant.Title), AlertType.Success); return(RedirectToAction("Index")); } return(View(variant)); }
public void Forge(int id, string token) { if (!TokenService.ValidateDateTimeToken(token)) { Response.StatusCode = 403; Response.End(); return; } var variant = GameMapService.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; GameMapService.Save(); Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + variant.DownloadName); Response.TransmitFile(Path.Combine(Server.MapPath("~/Content/Files/Forge"), variant.File.FileName)); Response.End(); }
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) })); }
// 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, GameMapVariant model) { var variant = GameMapService.GetVariant(id); variant.IsDeleted = !variant.IsDeleted; GameMapService.Save(); this.SetAlert(string.Format("The variant '{0}' has been deleted.", variant.Title), AlertType.Success); return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { var variant = GameMapService.GetVariant(id); if (variant == null) { return(HttpNotFound()); } return(View(variant)); }
public ActionResult Edit(int id) { var variant = GameMapService.GetVariant(id); if (!(variant.AuthorId == User.Identity.GetUserId <int>() || User.IsInRole("Mod"))) { return(new HttpUnauthorizedResult()); } return(View(variant)); }
// 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), })); }
public ActionResult Reply(ViewModels.ReplyRequest model) { var variant = GameMapService.GetVariant(model.Id); if (ModelState.IsValid) { int id = GameMapService.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 })); }
public ActionResult Delete(int id, GameMapVariant model) { var variant = GameMapService.GetVariant(id); if (!(variant.AuthorId == User.Identity.GetUserId <int>() || User.IsInRole("Mod"))) { return(new HttpUnauthorizedResult()); } variant.IsDeleted = true; GameMapService.Save(); SetAlert(string.Format("The forge variant {0} is deleted.", variant.Title), AlertType.Success); return(RedirectToAction("Index")); }
public ActionResult Edit(int id, Models.GameMapVariant model) { if (ModelState.IsValid) { var variant = GameMapService.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; variant.MinPlayers = model.MinPlayers; variant.MaxPlayers = model.MaxPlayers; string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/Forge/"), variant.File.FileName); using (FileStream stream = System.IO.File.Open(path, FileMode.Open)) { VariantLib.ForgeVariant forge = new VariantLib.ForgeVariant(stream); forge.VariantDescription = variant.ShortDescription; forge.VariantName = variant.Title; forge.Save(); } if (User.IsInRole("Mod")) { variant.IsStaffPick = model.IsStaffPick; } GameMapService.Save(); SetAlert(string.Format("The forge variant is saved.", variant.Title), AlertType.Success); return(RedirectToAction("Details", new { slug = variant.Slug })); } return(View(model)); }
// GET: Admin/ForgeVariant public ActionResult Index(string q, int?page, int?typeId, bool?staffPick, string sort = "release", string order = "descending", string author = "") { ViewBag.selectedMapId = typeId; ViewBag.typeId = GameMapService.GetMapSelectlist(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 = GameMapService.SearchVariants(q, sort, order == "ascending" ? true : false, typeId, staffPick, authorId, false); return(View(maps.ToPagedList(page ?? 1, 50))); }
public ActionResult Forge(int id) { var variant = GameMapService.GetVariant(id); if (variant == null || variant.IsDeleted) { return(HttpNotFound()); } return(Json(new { Type = "Forge", TypeName = variant.GameMap.Name, Id = variant.Id, Name = variant.Title, Author = variant.Author.UserName, Description = variant.ShortDescription, Icon = @"/content/images/maps/thumbs/" + variant.GameMap.InternalName + ".jpg", Download = Url.Action("Forge", "Download", new { id = variant.Id, token = TokenService.CreateDateTimeToken() }), Provider = "HaloShare", ProviderIcon = "/content/images/logo/white.png" }, JsonRequestBehavior.AllowGet)); }
public ActionResult Details(int slug) { ViewBag.Token = TokenService.CreateDateTimeToken(); return(View(GameMapService.GetVariant(slug))); }
public ActionResult Rate(int id, int rating) { return(Json(GameMapService.Rate(id, User.Identity.GetUserId <int>(), rating))); }
public ActionResult Forge(ViewModels.UploadViewModel model) { Response.TrySkipIisCustomErrors = true; if (ModelState.IsValid) { var currentUser = UserManager.FindById(User.Identity.GetUserId <int>()); Models.GameMapVariant variant = new Models.GameMapVariant(); 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() + ".vrt", UploadedOn = variant.CreatedOn, MD5 = model.File.InputStream.ToMD5() }; // Validate the variant to see if it's not a duplicate. var validateMap = GameMapService.ValidateHash(variant.File.MD5); if (validateMap != null) { Response.StatusCode = 400; return(Content(string.Format( "<b>Keep it Clean!</b> The forge variant has already been uploaded: <a target=\"_blank\" href=\"{0}\">{1}</a>.", Url.Action("Details", "Forge", new { slug = validateMap.Slug }), validateMap.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 the map is in the new format.")); } else if (detectType == VariantType.GameVariant) { // The given map doesn't exist. model.File.InputStream.Close(); Response.StatusCode = 400; return(Content("<strong>PARDON OUR DUST!</strong> Can't upload game variant as forge variant.")); } string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/Forge/"), variant.File.FileName); using (var stream = new System.IO.MemoryStream()) { model.File.InputStream.Seek(0, System.IO.SeekOrigin.Begin); model.File.InputStream.CopyTo(stream); ForgeVariant variantItem = new ForgeVariant(stream); var map = GameMapService.GetMapByInternalId(variantItem.MapId); if (map != null) { variant.GameMapId = map.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 map.")); } } GameMapService.AddVariant(variant); GameMapService.Save(); return(Content(Url.Action("Details", "Forge", new { slug = variant.Slug }))); } Response.StatusCode = 400; return(View("~/Views/Shared/_ModelState.cshtml")); }