void AddToActive(CollisionSkin cs, SkinTester st) { int n = active_.Count; float xMin = cs.WorldBoundingBox.Min.X; bool active = (cs.Owner != null) && cs.Owner.IsActive; for (int i = 0; i != n;) { CollisionSkin asi = active_[i]; if (asi.WorldBoundingBox.Max.X < xMin) { // prune no longer interesting boxes from potential overlaps --n; active_.RemoveAt(i); } else { bool active2 = active || (active_[i].Owner != null && asi.Owner.IsActive); if (active2 && BoundingBoxHelper.OverlapTest(ref cs.WorldBoundingBox, ref asi.WorldBoundingBox)) { if (active) { st.TestSkin(cs, asi); } else { st.TestSkin(asi, cs); } } ++i; } } active_.Add(cs); }
/// <summary> /// AddToActive /// </summary> /// <param name="cs"></param> /// <param name="st"></param> void AddToActive(CollisionSkin cs, SkinTester st) { int n = active_.Count; float xMin = cs.WorldBoundingBox.Min.X; bool active = (cs.Owner != null) && cs.Owner.IsActive; // BEN-OPTIMISATION: unsafe i.e. Remove array boundary checks. #if !WINDOWS_PHONE unsafe { #endif CollisionSkin asi; for (int i = 0; i != n;) { asi = active_[i]; if (asi.WorldBoundingBox.Max.X < xMin) { // prune no longer interesting boxes from potential overlaps --n; active_.RemoveAt(i); } else { // BEN-OPTIMISATION: Inlined BoundingBoxHelper.OverlapTest() and removed two redundant // comparisons the X comparison and the extra "if (active)" which can // be removed by rearranging. if (active) { if (!((cs.WorldBoundingBox.Min.Z >= asi.WorldBoundingBox.Max.Z) || (cs.WorldBoundingBox.Max.Z <= asi.WorldBoundingBox.Min.Z) || (cs.WorldBoundingBox.Min.Y >= asi.WorldBoundingBox.Max.Y) || (cs.WorldBoundingBox.Max.Y <= asi.WorldBoundingBox.Min.Y) || (cs.WorldBoundingBox.Max.X <= asi.WorldBoundingBox.Min.X))) { st.TestSkin(cs, asi); } } else if (active_[i].Owner != null && asi.Owner.IsActive && !((cs.WorldBoundingBox.Min.Z >= asi.WorldBoundingBox.Max.Z) || (cs.WorldBoundingBox.Max.Z <= asi.WorldBoundingBox.Min.Z) || (cs.WorldBoundingBox.Min.Y >= asi.WorldBoundingBox.Max.Y) || (cs.WorldBoundingBox.Max.Y <= asi.WorldBoundingBox.Min.Y) || (cs.WorldBoundingBox.Max.X <= asi.WorldBoundingBox.Min.X))) { st.TestSkin(asi, cs); } ++i; } } #if !WINDOWS_PHONE } // unsafe #endif active_.Add(cs); }
public async Task Preview(string skinId, int dragonId, [ExactValuePrecondition("-s")] string swapSilhouette, [ExactValuePrecondition("-apparel")] string apparel = null) { await StartPreview().ContinueWith(async msg => { var result = await SkinTester.GenerateOrFetchPreview(skinId, dragonId, true); if (!result.Success) { await msg.Result.ModifyAsync(x => x.Embed = ErrorEmbed(result.GetDiscordErrorMessage).Build()); } else { SaveStatistics(result); await msg.Result.ModifyAsync(x => x.Embed = GeneratedPreviewEmbed(result, apparel != null)); } }); }
public async Task <ActionResult> Preview(PreviewModelGet model) { var skin = DataContext.Skins.Include(x => x.Creator.FRUser).FirstOrDefault(x => x.GeneratedId == model.SkinId); if (skin == null) { AddErrorNotification("Skin not found"); return(RedirectToRoute("Home")); } if (skin.Coverage == null) { await UpdateCoverage(skin, DataContext); } try { var isOwn = Request.IsAuthenticated && skin.Creator?.Id == HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>(); if (isOwn && skin.Visibility == SkinVisiblity.HideEverywhere) { AddInfoNotification("Notice: You have set this skin to be hidden everywhere, only people who you share the link to this skin with can see this skin."); } return(View(new PreviewModelViewModel { Title = skin.Title, Description = skin.Description, SkinId = model.SkinId, PreviewUrl = (await SkinTester.GenerateOrFetchDummyPreview(skin.GeneratedId, skin.Version)).Urls[0], Coverage = skin.Coverage, Creator = skin.Creator, DragonType = (DragonType)skin.DragonType, Gender = (Gender)skin.GenderType, Visibility = skin.Visibility, Version = skin.Version })); } catch (FileNotFoundException) { AddErrorNotification("Skin not found"); return(RedirectToRoute("Home")); } }
public async Task Lookup(string skinId) { var skin = DbContext.Skins.Include(x => x.Creator.FRUser).FirstOrDefault(x => x.GeneratedId == skinId); if (skin == null) { if (skinId.All(char.IsDigit)) { try { var intSkinId = int.Parse(skinId); var realItemSearch = DbContext.FRItems.FirstOrDefault(x => x.FRId == intSkinId && x.ItemCategory == FRItemCategory.Skins); if (realItemSearch != null) { await ReplyAsync(embed : ErrorEmbed($"Skin not found, however there is a Flight Rising skin with that ID: `{realItemSearch.Name}`.\nIf you meant to search for a real skin please use the following command instead: `{await SettingManager.GetSettingValue("GUILDCONFIG_PREFIX", Context.Guild)}lookup skin {realItemSearch.FRId}`").Build()); return; } } catch { } } await ReplyAsync(embed : ErrorEmbed("Skin not found.").Build()); } else { var previewUrl = (await SkinTester.GenerateOrFetchDummyPreview(skin.GeneratedId, skin.Version)).Urls[0]; var embed = new EmbedBuilder(); embed.WithTitle(skin.Title ?? "_No title_"); embed.WithImageUrl($"{CDNBasePath}{previewUrl}"); embed.WithDescription(skin.Description ?? "_No description_"); embed.WithAuthor(new EmbedAuthorBuilder() .WithName(skin.Creator?.UserName ?? "Anonymous") .WithUrl(skin.Creator != null ? $"{WebsiteBaseUrl}/profile/{skin.Creator.UserName}" : null)); embed.WithFooter(new EmbedFooterBuilder().WithText($"Version {skin.Version}")); embed.WithUrl($"{WebsiteBaseUrl}/skintester/preview/{skinId}"); await ReplyAsync(embed : embed.Build()); } }
public async Task <ActionResult> Manage(ManageModelGet model) { var skin = DataContext.Skins.Include(x => x.Previews).FirstOrDefault(x => x.GeneratedId == model.SkinId && x.SecretKey == model.SecretKey); if (skin == null) { AddErrorNotification("Skin not found or secret invalid"); return(RedirectToRoute("Home")); } else { if (skin.Creator != null) { if (!Request.IsAuthenticated) { AddErrorNotification("This skin is linked to an acocunt, please log in to manage this skin."); return(RedirectToRoute("Home")); } else if (skin.Creator.Id != HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>()) { AddErrorNotification("This skin is linked to a different account than the one that is logged in, you can only manage your own skins."); return(RedirectToRoute("Home")); } } if (skin.Coverage == null) { await UpdateCoverage(skin, DataContext); } return(View(new ManageModelViewModel { Skin = skin, PreviewImageUrl = (await SkinTester.GenerateOrFetchDummyPreview(skin.GeneratedId, skin.Version)).Urls[0], PreviewUrl = Url.RouteUrl("Preview", new { SkinId = skin.GeneratedId }, "https"), ShareUrl = skin.ShareUrl })); } }
private void AddToActive(CollisionSkin cs, SkinTester st) { var n = active_.Count; var xMin = cs.WorldBoundingBox.Min.X; var active = cs.Owner != null && cs.Owner.IsActive; unsafe { CollisionSkin asi; for (var i = 0; i != n;) { asi = active_[i]; if (asi.WorldBoundingBox.Max.X < xMin) { --n; active_.RemoveAt(i); } else { if (active) { if (!(cs.WorldBoundingBox.Min.Z >= asi.WorldBoundingBox.Max.Z || cs.WorldBoundingBox.Max.Z <= asi.WorldBoundingBox.Min.Z || cs.WorldBoundingBox.Min.Y >= asi.WorldBoundingBox.Max.Y || cs.WorldBoundingBox.Max.Y <= asi.WorldBoundingBox.Min.Y || cs.WorldBoundingBox.Max.X <= asi.WorldBoundingBox.Min.X)) { st.TestSkin(cs, asi); } } else if (active_[i].Owner != null && asi.Owner.IsActive && !(cs.WorldBoundingBox.Min.Z >= asi.WorldBoundingBox.Max.Z || cs.WorldBoundingBox.Max.Z <= asi.WorldBoundingBox.Min.Z || cs.WorldBoundingBox.Min.Y >= asi.WorldBoundingBox.Max.Y || cs.WorldBoundingBox.Max.Y <= asi.WorldBoundingBox.Min.Y || cs.WorldBoundingBox.Max.X <= asi.WorldBoundingBox.Min.X)) { st.TestSkin(asi, cs); } ++i; } } } active_.Add(cs); }
public async Task <ActionResult> Preview(PreviewModelPost model) { if (!ModelState.IsValid) { return(RedirectToRoute("Preview", new { model.SkinId })); } PreviewResult result = null; if (model.DragonId != null) { result = await SkinTester.GenerateOrFetchPreview(model.SkinId, model.DragonId.Value, model.SwapSilhouette, model.Force); } else if (!string.IsNullOrWhiteSpace(model.ScryerUrl)) { result = await SkinTester.GenerateOrFetchPreview(model.SkinId, model.ScryerUrl, model.Force); } else if (!string.IsNullOrWhiteSpace(model.DressingRoomUrl)) { result = await SkinTester.GenerateOrFetchPreview(model.SkinId, model.DressingRoomUrl, model.Force); } if (result == null || !result.Success) { AddErrorNotification(result?.GetHtmlErrorMessage); return(RedirectToRoute("Preview", new { model.SkinId })); } await SavePreviewStatistics(result); return(View("PreviewResult", new PreviewModelPostViewModel { SkinId = model.SkinId, Result = result, Dragon = result.Dragon })); }
public async Task <ActionResult> Upload(UploadModelPost model) { var azureImageService = new AzureImageService(); var randomizedId = CodeHelpers.GenerateId(5, DataContext.Skins.Select(x => x.GeneratedId).ToList()); var secretKey = CodeHelpers.GenerateId(7); Bitmap skinImage = null; try { skinImage = (Bitmap)Image.FromStream(model.Skin.InputStream); if (skinImage.Width != 350 || skinImage.Height != 350) { AddErrorNotification("Image needs to be 350px x 350px. Just like FR."); return(View()); } } catch { AddErrorNotification("Upload is not a valid png image"); return(View()); } try { var fixPixelFormat = SkinTester.FixPixelFormat(skinImage); if (fixPixelFormat != null) { skinImage = fixPixelFormat; } model.Skin.InputStream.Position = 0; var url = await azureImageService.WriteImage($@"skins\{randomizedId}.png", model.Skin.InputStream); Bitmap dragonImage = null; using (var client = new WebClient()) { var dwagonImageBytes = client.DownloadDataTaskAsync(string.Format(FRHelpers.DressingRoomDummyUrl, (int)model.DragonType, (int)model.Gender)); try { using (var memStream = new MemoryStream(await dwagonImageBytes, false)) dragonImage = (Bitmap)Image.FromStream(memStream); } catch { } } var skin = new Skin { GeneratedId = randomizedId, SecretKey = secretKey, Title = model.Title, Description = model.Description, DragonType = (int)model.DragonType, GenderType = (int)model.Gender, Coverage = GetCoveragePercentage(skinImage, dragonImage) }; skinImage.Dispose(); if (Request.IsAuthenticated) { var userId = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>(); skin.Creator = DataContext.Users.FirstOrDefault(x => x.Id == userId); skin.Visibility = skin.Creator.ProfileSettings.DefaultSkinsArePublic ? skin.Creator.ProfileSettings.DefaultShowSkinsInBrowse ? SkinVisiblity.Visible : SkinVisiblity.HideFromBrowse : SkinVisiblity.HideEverywhere; } DataContext.Skins.Add(skin); await DataContext.SaveChangesAsync(); return(View("UploadResult", new UploadModelPostViewModel { SkinId = randomizedId, SecretKey = secretKey, PreviewImageUrl = (await SkinTester.GenerateOrFetchDummyPreview(randomizedId, skin.Version)).Urls[0] })); } catch { AddErrorNotification("Something went wrong uploading"); return(View()); } }
public async Task <string> GetDummyPreviewImage(string skinId, int version) { return((await SkinTester.GenerateOrFetchDummyPreview(skinId, version)).Urls[0]); }