mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Merge pull request #11755 from peppy/fix-message-formatter-domain
Fix MessageFormatter not working for custom endpoints
This commit is contained in:
commit
dad6e7e825
@ -103,26 +103,26 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
private void testLinksGeneral()
|
private void testLinksGeneral()
|
||||||
{
|
{
|
||||||
addMessageWithChecks("test!");
|
addMessageWithChecks("test!");
|
||||||
addMessageWithChecks("osu.ppy.sh!");
|
addMessageWithChecks("dev.ppy.sh!");
|
||||||
addMessageWithChecks("https://osu.ppy.sh!", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("https://dev.ppy.sh!", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("00:12:345 (1,2) - Test?", 1, expectedActions: LinkAction.OpenEditorTimestamp);
|
addMessageWithChecks("00:12:345 (1,2) - Test?", 1, expectedActions: LinkAction.OpenEditorTimestamp);
|
||||||
addMessageWithChecks("Wiki link for tasty [[Performance Points]]", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("Wiki link for tasty [[Performance Points]]", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("(osu forums)[https://osu.ppy.sh/forum] (old link format)", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("(osu forums)[https://dev.ppy.sh/forum] (old link format)", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("[https://osu.ppy.sh/home New site] (new link format)", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("[https://dev.ppy.sh/home New site] (new link format)", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("[osu forums](https://osu.ppy.sh/forum) (new link format 2)", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("[osu forums](https://dev.ppy.sh/forum) (new link format 2)", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("[https://osu.ppy.sh/home This is only a link to the new osu webpage but this is supposed to test word wrap.]", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("[https://dev.ppy.sh/home This is only a link to the new osu webpage but this is supposed to test word wrap.]", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("is now listening to [https://osu.ppy.sh/s/93523 IMAGE -MATERIAL- <Version 0>]", 1, true, expectedActions: LinkAction.OpenBeatmapSet);
|
addMessageWithChecks("is now listening to [https://dev.ppy.sh/s/93523 IMAGE -MATERIAL- <Version 0>]", 1, true, expectedActions: LinkAction.OpenBeatmapSet);
|
||||||
addMessageWithChecks("is now playing [https://osu.ppy.sh/b/252238 IMAGE -MATERIAL- <Version 0>]", 1, true, expectedActions: LinkAction.OpenBeatmap);
|
addMessageWithChecks("is now playing [https://dev.ppy.sh/b/252238 IMAGE -MATERIAL- <Version 0>]", 1, true, expectedActions: LinkAction.OpenBeatmap);
|
||||||
addMessageWithChecks("Let's (try)[https://osu.ppy.sh/home] [https://osu.ppy.sh/b/252238 multiple links] https://osu.ppy.sh/home", 3,
|
addMessageWithChecks("Let's (try)[https://dev.ppy.sh/home] [https://dev.ppy.sh/b/252238 multiple links] https://dev.ppy.sh/home", 3,
|
||||||
expectedActions: new[] { LinkAction.External, LinkAction.OpenBeatmap, LinkAction.External });
|
expectedActions: new[] { LinkAction.External, LinkAction.OpenBeatmap, LinkAction.External });
|
||||||
addMessageWithChecks("[https://osu.ppy.sh/home New link format with escaped [and \\[ paired] braces]", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("[https://dev.ppy.sh/home New link format with escaped [and \\[ paired] braces]", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("[Markdown link format with escaped [and \\[ paired] braces](https://osu.ppy.sh/home)", 1, expectedActions: LinkAction.External);
|
addMessageWithChecks("[Markdown link format with escaped [and \\[ paired] braces](https://dev.ppy.sh/home)", 1, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("(Old link format with escaped (and \\( paired) parentheses)[https://osu.ppy.sh/home] and [[also a rogue wiki link]]", 2, expectedActions: new[] { LinkAction.External, LinkAction.External });
|
addMessageWithChecks("(Old link format with escaped (and \\( paired) parentheses)[https://dev.ppy.sh/home] and [[also a rogue wiki link]]", 2, expectedActions: new[] { LinkAction.External, LinkAction.External });
|
||||||
// note that there's 0 links here (they get removed if a channel is not found)
|
// note that there's 0 links here (they get removed if a channel is not found)
|
||||||
addMessageWithChecks("#lobby or #osu would be blue (and work) in the ChatDisplay test (when a proper ChatOverlay is present).");
|
addMessageWithChecks("#lobby or #osu would be blue (and work) in the ChatDisplay test (when a proper ChatOverlay is present).");
|
||||||
addMessageWithChecks("I am important!", 0, false, true);
|
addMessageWithChecks("I am important!", 0, false, true);
|
||||||
addMessageWithChecks("feels important", 0, true, true);
|
addMessageWithChecks("feels important", 0, true, true);
|
||||||
addMessageWithChecks("likes to post this [https://osu.ppy.sh/home link].", 1, true, true, expectedActions: LinkAction.External);
|
addMessageWithChecks("likes to post this [https://dev.ppy.sh/home link].", 1, true, true, expectedActions: LinkAction.External);
|
||||||
addMessageWithChecks("Join my multiplayer game osump://12346.", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
addMessageWithChecks("Join my multiplayer game osump://12346.", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
||||||
addMessageWithChecks("Join my [multiplayer game](osump://12346).", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
addMessageWithChecks("Join my [multiplayer game](osump://12346).", 1, expectedActions: LinkAction.JoinMultiplayerMatch);
|
||||||
addMessageWithChecks("Join my [#english](osu://chan/#english).", 1, expectedActions: LinkAction.OpenChannel);
|
addMessageWithChecks("Join my [#english](osu://chan/#english).", 1, expectedActions: LinkAction.OpenChannel);
|
||||||
@ -136,9 +136,9 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
int echoCounter = 0;
|
int echoCounter = 0;
|
||||||
|
|
||||||
addEchoWithWait("sent!", "received!");
|
addEchoWithWait("sent!", "received!");
|
||||||
addEchoWithWait("https://osu.ppy.sh/home", null, 500);
|
addEchoWithWait("https://dev.ppy.sh/home", null, 500);
|
||||||
addEchoWithWait("[https://osu.ppy.sh/forum let's try multiple words too!]");
|
addEchoWithWait("[https://dev.ppy.sh/forum let's try multiple words too!]");
|
||||||
addEchoWithWait("(long loading times! clickable while loading?)[https://osu.ppy.sh/home]", null, 5000);
|
addEchoWithWait("(long loading times! clickable while loading?)[https://dev.ppy.sh/home]", null, 5000);
|
||||||
|
|
||||||
void addEchoWithWait(string text, string completeText = null, double delay = 250)
|
void addEchoWithWait(string text, string completeText = null, double delay = 250)
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,18 @@ namespace osu.Game.Online.Chat
|
|||||||
// Unicode emojis
|
// Unicode emojis
|
||||||
private static readonly Regex emoji_regex = new Regex(@"(\uD83D[\uDC00-\uDE4F])");
|
private static readonly Regex emoji_regex = new Regex(@"(\uD83D[\uDC00-\uDE4F])");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The root URL for the website, used for chat link matching.
|
||||||
|
/// </summary>
|
||||||
|
public static string WebsiteRootUrl
|
||||||
|
{
|
||||||
|
set => websiteRootUrl = value
|
||||||
|
.Trim('/') // trim potential trailing slash/
|
||||||
|
.Split('/').Last(); // only keep domain name, ignoring protocol.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string websiteRootUrl = "osu.ppy.sh";
|
||||||
|
|
||||||
private static void handleMatches(Regex regex, string display, string link, MessageFormatterResult result, int startIndex = 0, LinkAction? linkActionOverride = null, char[] escapeChars = null)
|
private static void handleMatches(Regex regex, string display, string link, MessageFormatterResult result, int startIndex = 0, LinkAction? linkActionOverride = null, char[] escapeChars = null)
|
||||||
{
|
{
|
||||||
int captureOffset = 0;
|
int captureOffset = 0;
|
||||||
@ -119,7 +131,7 @@ namespace osu.Game.Online.Chat
|
|||||||
case "http":
|
case "http":
|
||||||
case "https":
|
case "https":
|
||||||
// length > 3 since all these links need another argument to work
|
// length > 3 since all these links need another argument to work
|
||||||
if (args.Length > 3 && args[1] == "osu.ppy.sh")
|
if (args.Length > 3 && args[1].EndsWith(websiteRootUrl, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var mainArg = args[3];
|
var mainArg = args[3];
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ using osu.Game.Input;
|
|||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.Online;
|
using osu.Game.Online;
|
||||||
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.Spectator;
|
using osu.Game.Online.Spectator;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
@ -225,6 +226,8 @@ namespace osu.Game
|
|||||||
|
|
||||||
EndpointConfiguration endpoints = UseDevelopmentServer ? (EndpointConfiguration)new DevelopmentEndpointConfiguration() : new ProductionEndpointConfiguration();
|
EndpointConfiguration endpoints = UseDevelopmentServer ? (EndpointConfiguration)new DevelopmentEndpointConfiguration() : new ProductionEndpointConfiguration();
|
||||||
|
|
||||||
|
MessageFormatter.WebsiteRootUrl = endpoints.WebsiteRootUrl;
|
||||||
|
|
||||||
dependencies.CacheAs(API ??= new APIAccess(LocalConfig, endpoints));
|
dependencies.CacheAs(API ??= new APIAccess(LocalConfig, endpoints));
|
||||||
|
|
||||||
dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient(endpoints));
|
dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient(endpoints));
|
||||||
|
Loading…
Reference in New Issue
Block a user