From 2de19035ff28f4063bfcfb05152371adc3c61f44 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 30 Aug 2022 17:42:03 +0200 Subject: [PATCH] Allow changing the Misuzu base URL. --- .gitignore | 1 + SharpChat/Flashii/FlashiiAuth.cs | 2 +- SharpChat/Flashii/FlashiiBan.cs | 2 +- SharpChat/Flashii/FlashiiBump.cs | 2 +- SharpChat/Flashii/FlashiiUrls.cs | 43 ++++++++++++++++++++++++-------- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ffa8fec..de3d414 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ mariadb.txt login_key.txt http-motd.txt _webdb.txt +msz_url.txt # User-specific files *.suo diff --git a/SharpChat/Flashii/FlashiiAuth.cs b/SharpChat/Flashii/FlashiiAuth.cs index 3dd3ef0..2e0f580 100644 --- a/SharpChat/Flashii/FlashiiAuth.cs +++ b/SharpChat/Flashii/FlashiiAuth.cs @@ -68,7 +68,7 @@ namespace SharpChat.Flashii { }; #endif - using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, FlashiiUrls.AUTH) { + using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, FlashiiUrls.AuthURL) { Content = new ByteArrayContent(authRequest.GetJSON()), Headers = { { @"X-SharpChat-Signature", authRequest.Hash }, diff --git a/SharpChat/Flashii/FlashiiBan.cs b/SharpChat/Flashii/FlashiiBan.cs index 39b2257..d32ac66 100644 --- a/SharpChat/Flashii/FlashiiBan.cs +++ b/SharpChat/Flashii/FlashiiBan.cs @@ -25,7 +25,7 @@ namespace SharpChat.Flashii { if(httpClient == null) throw new ArgumentNullException(nameof(httpClient)); - using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, FlashiiUrls.BANS) { + using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, FlashiiUrls.BansURL) { Headers = { { @"X-SharpChat-Signature", STRING.GetSignedHash() }, }, diff --git a/SharpChat/Flashii/FlashiiBump.cs b/SharpChat/Flashii/FlashiiBump.cs index 5eafb2e..17ff15e 100644 --- a/SharpChat/Flashii/FlashiiBump.cs +++ b/SharpChat/Flashii/FlashiiBump.cs @@ -31,7 +31,7 @@ namespace SharpChat.Flashii { byte[] data = JsonSerializer.SerializeToUtf8Bytes(users); - using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, FlashiiUrls.BUMP) { + using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, FlashiiUrls.BumpURL) { Content = new ByteArrayContent(data), Headers = { { @"X-SharpChat-Signature", data.GetSignedHash() }, diff --git a/SharpChat/Flashii/FlashiiUrls.cs b/SharpChat/Flashii/FlashiiUrls.cs index 58c939b..4b4bdfb 100644 --- a/SharpChat/Flashii/FlashiiUrls.cs +++ b/SharpChat/Flashii/FlashiiUrls.cs @@ -1,14 +1,35 @@ -namespace SharpChat.Flashii { - public static class FlashiiUrls { - public const string BASE_URL = -#if DEBUG - @"https://misuzu.misaka.nl/_sockchat"; -#else - @"https://flashii.net/_sockchat"; -#endif +using System.IO; - public const string AUTH = BASE_URL + @"/verify"; - public const string BANS = BASE_URL + @"/bans"; - public const string BUMP = BASE_URL + @"/bump"; +namespace SharpChat.Flashii { + public static class FlashiiUrls { + private const string BASE_URL_FILE = @"msz_url.txt"; + private const string BASE_URL = @"https://flashii.net"; + + private const string AUTH = BASE_URL + @"/_sockchat/verify"; + private const string BANS = BASE_URL + @"/_sockchat/bans"; + private const string BUMP = BASE_URL + @"/_sockchat/bump"; + + public static string AuthURL { get; } + public static string BansURL { get; } + public static string BumpURL { get; } + + static FlashiiUrls() { + AuthURL = GetURL(AUTH); + BansURL = GetURL(BANS); + BumpURL = GetURL(BUMP); + } + + public static string GetBaseURL() { + if(!File.Exists(BASE_URL_FILE)) + return BASE_URL; + string url = File.ReadAllText(BASE_URL_FILE).Trim().Trim('/'); + if(string.IsNullOrEmpty(url)) + return BASE_URL; + return url; + } + + public static string GetURL(string path) { + return GetBaseURL() + path; + } } }