From 23e597dede56acedb7668b881edeb0ef9af078db Mon Sep 17 00:00:00 2001 From: Bitl Date: Fri, 13 Jan 2023 00:16:31 -0700 Subject: [PATCH] update scripts --- changelog.txt | 7 ++ .../novetusexts/webproxy/AwardBadge.cs | 50 ++++++------ .../novetusexts/webproxy/HasBadge.cs | 76 +++++++++++++++++++ .../novetusexts/webproxy/StaticPages.cs | 71 +++++++++++++++++ .../novetusexts/webproxy/StudioLaunchPage.cs | 33 -------- .../novetusexts/webproxy/UploadWarnings.cs | 12 ++- 6 files changed, 190 insertions(+), 59 deletions(-) create mode 100644 defaultaddons/novetusexts/webproxy/HasBadge.cs create mode 100644 defaultaddons/novetusexts/webproxy/StaticPages.cs delete mode 100644 defaultaddons/novetusexts/webproxy/StudioLaunchPage.cs diff --git a/changelog.txt b/changelog.txt index 04cc096..41a98c4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,12 @@ 1.3 Snapshot v22.8412.32591.1 Enhancements: +- Added support for HasBadge to the Web Proxy. +- Merged some static APIs into one extension. +- Restored the Help button functionality. +- All clients now work properly with the Web Proxy. +---------------------------------------------------------------------------- +1.3 Snapshot v22.8412.32591.1 +Enhancements: - Added badge support to the Web Proxy. - The Easter Egg now loads up a server and a client, rather than loading a client in Play Solo mode. - Further improved web proxy reliability. diff --git a/defaultaddons/novetusexts/webproxy/AwardBadge.cs b/defaultaddons/novetusexts/webproxy/AwardBadge.cs index d8e498e..8dd4e07 100644 --- a/defaultaddons/novetusexts/webproxy/AwardBadge.cs +++ b/defaultaddons/novetusexts/webproxy/AwardBadge.cs @@ -20,20 +20,10 @@ public class AwardBadge : IWebProxyExtension } private static readonly string BadgeDatabasePath = GlobalPaths.ConfigDir + "\\BadgeDatabase.ini"; - private string BadgeDatabaseSection = "BadgeDatabase"; + private static readonly string BadgeDatabaseSection = "BadgeDatabase"; private string MetadataFileExtension = "_meta.ini"; private INIFile ini = new INIFile(BadgeDatabasePath); - public override string Name() - { - return "Badge Award Extension"; - } - - public override string Author() - { - return "Bitl"; - } - void AddBadgeToDB(long BadgeID, bool Awarded = false) { CreateBadgeDatabaseIfNeeded(); @@ -62,11 +52,6 @@ public class AwardBadge : IWebProxyExtension } } - public override void OnExtensionLoad() - { - CreateBadgeDatabaseIfNeeded(); - } - BadgeData LoadMetadata(long BadgeID) { BadgeData result; @@ -100,11 +85,6 @@ public class AwardBadge : IWebProxyExtension return result; } - public override bool IsValidURL(string absolutePath, string host) - { - return absolutePath.EndsWith("/game/badge/awardbadge.ashx"); - } - string GenerateBadgeString(string creatorName, string badgeName, long id) { if (PlayerHasBadge(id)) @@ -115,9 +95,33 @@ public class AwardBadge : IWebProxyExtension return GlobalVars.UserConfiguration.PlayerName + " won " + creatorName + "'s \"" + badgeName + "\" award!"; } + public override string Name() + { + return "Badge Award API Extension"; + } + + public override string Version() + { + return "1.0.1"; + } + + public override string Author() + { + return "Bitl"; + } + + public override void OnExtensionLoad() + { + CreateBadgeDatabaseIfNeeded(); + } + + public override bool IsValidURL(string absolutePath, string host) + { + return absolutePath.EndsWith("/game/badge/awardbadge.ashx"); + } + public override async Task OnRequest(object sender, SessionEventArgs e) { - await Util.Delay(1000); string query = e.HttpClient.Request.RequestUri.Query; long badgeid = 0; long userid = 0; @@ -132,6 +136,6 @@ public class AwardBadge : IWebProxyExtension string badgeAwardString = GenerateBadgeString(meta.BadgeCreatorName, meta.BadgeName, badgeid); AddBadgeToDB(badgeid, true); - e.Ok(badgeAwardString, NetFuncs.GenerateHeaders(badgeAwardString.Length.ToString())); + e.Ok(badgeAwardString, NetFuncs.GenerateHeaders(badgeAwardString.Length.ToString(), "text/plain")); } } \ No newline at end of file diff --git a/defaultaddons/novetusexts/webproxy/HasBadge.cs b/defaultaddons/novetusexts/webproxy/HasBadge.cs new file mode 100644 index 0000000..d674893 --- /dev/null +++ b/defaultaddons/novetusexts/webproxy/HasBadge.cs @@ -0,0 +1,76 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Web; +using System.Net; +using System.Collections.Generic; +using Titanium.Web.Proxy; +using Titanium.Web.Proxy.EventArguments; +using Titanium.Web.Proxy.Http; +using Titanium.Web.Proxy.Models; +using Novetus.Core; + +public class HasBadge : IWebProxyExtension +{ + private static readonly string BadgeDatabasePath = GlobalPaths.ConfigDir + "\\BadgeDatabase.ini"; + private static readonly string BadgeDatabaseSection = "BadgeDatabase"; + private INIFile ini = new INIFile(BadgeDatabasePath); + + public override string Name() + { + return "Badge Checker API Extension"; + } + + public override string Author() + { + return "Bitl"; + } + + bool PlayerHasBadge(long BadgeID) + { + CreateBadgeDatabaseIfNeeded(); + + if (ini.IniValueExists(BadgeID.ToString())) + { + string awarded = ini.IniReadValue(BadgeDatabaseSection, BadgeID.ToString(), "False"); + return Convert.ToBoolean(awarded); + } + + return false; + } + + void CreateBadgeDatabaseIfNeeded() + { + if (!File.Exists(BadgeDatabasePath)) + { + Util.ConsolePrint("WARNING - " + BadgeDatabasePath + " not found. Creating empty badge database.", 5); + File.Create(BadgeDatabasePath).Dispose(); + } + } + + public override void OnExtensionLoad() + { + CreateBadgeDatabaseIfNeeded(); + } + + public override bool IsValidURL(string absolutePath, string host) + { + return absolutePath.EndsWith("/game/badge/hasbadge.ashx"); + } + + public override async Task OnRequest(object sender, SessionEventArgs e) + { + string query = e.HttpClient.Request.RequestUri.Query; + long badgeid = 0; + long userid = 0; + if (!long.TryParse(NetFuncs.FindQueryString(query, "badgeid"), out badgeid) && + !long.TryParse(NetFuncs.FindQueryString(query, "userid"), out userid)) + { + e.GenericResponse("", HttpStatusCode.BadRequest); + return; + } + + string hasBadgeResult = PlayerHasBadge(badgeid) ? "Success" : "Failure"; + e.Ok(hasBadgeResult, NetFuncs.GenerateHeaders(hasBadgeResult.Length.ToString(), "text/plain")); + } +} \ No newline at end of file diff --git a/defaultaddons/novetusexts/webproxy/StaticPages.cs b/defaultaddons/novetusexts/webproxy/StaticPages.cs new file mode 100644 index 0000000..f809edc --- /dev/null +++ b/defaultaddons/novetusexts/webproxy/StaticPages.cs @@ -0,0 +1,71 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Web; +using System.Collections.Generic; +using System.Linq; +using Titanium.Web.Proxy; +using Titanium.Web.Proxy.EventArguments; +using Titanium.Web.Proxy.Http; +using Titanium.Web.Proxy.Models; +using Novetus.Core; + +public class StaticPages : IWebProxyExtension +{ + public override string Name() + { + return "Static APIs Extension"; + } + + public override string Author() + { + return "Bitl"; + } + + static string GetStudioPageOutput() + { + return "Welcome to Novetus " + GlobalVars.ProgramInformation.Version + "!"; + } + + static string GetHelpPageOutput() + { + string path = GlobalPaths.NovetusExtsWebProxy + @"\\webpages\\Help.html"; + return File.ReadAllText(path); + } + + Dictionary staticPages = new Dictionary() + { + {"/ide/landing.aspx", GetStudioPageOutput()}, + {"/discover", GetStudioPageOutput()}, + {"/my/places.aspx", GetStudioPageOutput()}, + {"/game/badge/isbadgedisabled.ashx", "0"}, + {"/game/help.aspx", GetHelpPageOutput()} + }; + + public override bool IsValidURL(string absolutePath, string host) + { + foreach(var item in staticPages.Keys) + { + if (absolutePath.StartsWith(item) || absolutePath.EndsWith(item)) + { + return true; + } + } + + return false; + } + + public override async Task OnRequest(object sender, SessionEventArgs e) + { + string absPath = e.HttpClient.Request.RequestUri.AbsolutePath.ToLowerInvariant(); + + foreach(var item in staticPages.Keys) + { + if (absPath.StartsWith(item) || absPath.EndsWith(item)) + { + string result = staticPages[item]; + e.Ok(result, NetFuncs.GenerateHeaders(result.Length.ToString(), "text/html")); + } + } + } +} \ No newline at end of file diff --git a/defaultaddons/novetusexts/webproxy/StudioLaunchPage.cs b/defaultaddons/novetusexts/webproxy/StudioLaunchPage.cs deleted file mode 100644 index 9eaf555..0000000 --- a/defaultaddons/novetusexts/webproxy/StudioLaunchPage.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using System.Web; -using System.Collections.Generic; -using Titanium.Web.Proxy; -using Titanium.Web.Proxy.EventArguments; -using Titanium.Web.Proxy.Http; -using Titanium.Web.Proxy.Models; -using Novetus.Core; - -public class StudioLaunchPage : IWebProxyExtension -{ - public override string Name() - { - return "Studio Launch Page Extension"; - } - - public override string Author() - { - return "Bitl"; - } - - public override bool IsValidURL(string absolutePath, string host) - { - return absolutePath.EndsWith("/ide/landing.aspx") || absolutePath.EndsWith("/my/places.aspx"); - } - - public override async Task OnRequest(object sender, SessionEventArgs e) - { - e.Ok("Welcome to Novetus Studio version " + GlobalVars.ProgramInformation.Version); - } -} \ No newline at end of file diff --git a/defaultaddons/novetusexts/webproxy/UploadWarnings.cs b/defaultaddons/novetusexts/webproxy/UploadWarnings.cs index 7048ae7..18d9dee 100644 --- a/defaultaddons/novetusexts/webproxy/UploadWarnings.cs +++ b/defaultaddons/novetusexts/webproxy/UploadWarnings.cs @@ -16,6 +16,11 @@ public class UploadWarnings : IWebProxyExtension return "Upload Dialog Warnings Extension"; } + public override string Version() + { + return "1.0.1"; + } + public override string Author() { return "Bitl"; @@ -31,14 +36,15 @@ public class UploadWarnings : IWebProxyExtension string absPath = e.HttpClient.Request.RequestUri.AbsolutePath.ToLowerInvariant(); string type = "video"; - string folder = "Videos"; + string folder = "My Videos"; if (absPath.EndsWith("/uploadmedia/postimage.aspx")) { type = "screenshot"; - folder = "Pictures"; + folder = "My Pictures"; } - e.Ok("Your " + type + " was saved! Look in the Roblox folder in your " + folder + " folder!"); + string result = "Your " + type + " was saved! Look in the Roblox folder in your " + folder + " folder!"; + e.Ok(result, NetFuncs.GenerateHeaders(result.Length.ToString(), "text/plain")); } } \ No newline at end of file