From 45288f2dac1324ed0231f884285e4601e6da2347 Mon Sep 17 00:00:00 2001 From: the0show <62229104+The0Show@users.noreply.github.com> Date: Sun, 12 Oct 2025 23:26:51 -0400 Subject: [PATCH 1/5] feat(client): add ability to open URLs (w/ clipboard & confirmation UI) --- config/ui/game/common.cfg | 66 ++++++++++++++++++++++++++++++++++++++ config/ui/game/support.cfg | 42 ++++++++++++++++++++++++ src/engine/client.cpp | 10 ++++++ 3 files changed, 118 insertions(+) diff --git a/config/ui/game/common.cfg b/config/ui/game/common.cfg index f6bc6c87e..f10131bda 100644 --- a/config/ui/game/common.cfg +++ b/config/ui/game/common.cfg @@ -26,6 +26,9 @@ gameui_confirm_text = "" // Confirm panel action gameui_confirm_action = [] +// Open link panel link +gameui_openlink_href = "" + // Number of widget states to reset gameui_num_states = 0 @@ -491,6 +494,12 @@ gameui_confirm = [ gameui_open ui_gameui_confirm ] +gameui_openlink = [ + gameui_openlink_href = $arg1 + + gameui_open ui_gameui_openlink +] + //////////// @@ -593,6 +602,63 @@ ui_gameui_confirm_dims = 0.72 ] ] +ui_gameui_openlink_dims = 0.72 + +# ui_gameui_openlink = [ + #(gameui_begin_ids) + + uivlist 0.05 [ + uistyle clampx + + uicolour 0x55010101 0 0 [ + uistyle clampx + + uitext "Open external link in your default browser?" 1.5 + + ui_gameui_shadowhoriz + ] + + uitext $gameui_openlink_href 1.5 + + uivlist 0 [ + ui_gameui_prettybutton [ + p_label = "Open in Browser" + p_label_align = 0 + p_width = 0.3 + p_pad_h_shift = 0 + p_on_click = [ + open_url $gameui_openlink_href + gameui_close + ] + p_id = #(gameui_get_id prettybutton) + ] + + ui_gameui_prettybutton [ + p_label = "Copy to Clipboard" + p_label_align = 0 + p_width = 0.3 + p_pad_h_shift = 0 + p_on_click = [ + set_clipboard $gameui_openlink_href + gameui_close + ] + p_id = #(gameui_get_id prettybutton) + ] + + ui_gameui_prettybutton [ + p_label = "Cancel" + p_label_align = 0 + p_width = 0.3 + p_pad_h_shift = 0 + p_on_click = [ + gameui_close + ] + p_id = #(gameui_get_id prettybutton) + ] + ] + ] +] + ui_gameui_panel = [ // Initialize state gameui_hovering = 0 diff --git a/config/ui/game/support.cfg b/config/ui/game/support.cfg index eda0d5438..c067a0eb4 100644 --- a/config/ui/game/support.cfg +++ b/config/ui/game/support.cfg @@ -21,6 +21,20 @@ ui_gameui_support_about_dims = 0.72 ui_gameui_horizgroup [ uicolourtext "(C) 2009-2025 Quinton Reeves, Lee Salzman, Sławomir Błauciak" 0xaaaaaa uicolourtext "https://www.redeclipse.net/" #(hsvtohex 8 0.85 0.8) + + uispace 0.02 0.02 [ + ui_gameui_button [ + p_label = "Visit Website" + p_label_size = 1.2 + p_width = 0.12 + p_height = 0.04 + p_colour = 0xff8888 + p_on_click = [ + gameui_openlink "https://www.redeclipse.net/" + ] + p_id = #(gameui_get_id) + ] + ] ] [ p_label = "Red Eclipse Engine" p_width = 0.4 @@ -29,6 +43,20 @@ ui_gameui_support_about_dims = 0.72 ui_gameui_horizgroup [ uicolourtext "(C) 2009-2025 Red Eclipse Team" 0xaaaaaa uicolourtext "https://www.redeclipse.net/" #(hsvtohex 8 0.85 0.8) + + uispace 0.02 0.02 [ + ui_gameui_button [ + p_label = "Visit Website" + p_label_size = 1.2 + p_width = 0.12 + p_height = 0.04 + p_colour = 0xff8888 + p_on_click = [ + gameui_openlink "https://www.redeclipse.net/" + ] + p_id = #(gameui_get_id) + ] + ] ] [ p_label = "Red Eclipse Assets" p_width = 0.4 @@ -37,6 +65,20 @@ ui_gameui_support_about_dims = 0.72 ui_gameui_horizgroup [ uicolourtext "(C) 2014-2024 Lee Salzman, et. al." 0xaaaaaa uicolourtext "http://tesseract.gg/" #(hsvtohex 8 0.85 0.8) + + uispace 0.02 0.02 [ + ui_gameui_button [ + p_label = "Visit Website" + p_label_size = 1.2 + p_width = 0.12 + p_height = 0.04 + p_colour = 0xff8888 + p_on_click = [ + gameui_openlink "http://tesseract.gg/" + ] + p_id = #(gameui_get_id) + ] + ] ] [ p_label = "Tesseract Engine" p_width = 0.4 diff --git a/src/engine/client.cpp b/src/engine/client.cpp index c9ba88185..b20b55703 100644 --- a/src/engine/client.cpp +++ b/src/engine/client.cpp @@ -65,6 +65,16 @@ ICOMMAND(0, connectedport, "", (), intret(address ? address->port : -1); }); +ICOMMAND(0, open_url, "s", (char *href), +{ + SDL_OpenURL(href); +}); + +ICOMMAND(0, set_clipboard, "s", (char *data), +{ + SDL_SetClipboardText(data); +}); + VARR(connectstatus, 0); void abortconnect(bool msg) From 21287e0f335a4ed58cae6320f5e77c42e66f259f Mon Sep 17 00:00:00 2001 From: the0show <62229104+The0Show@users.noreply.github.com> Date: Sun, 12 Oct 2025 23:46:37 -0400 Subject: [PATCH 2/5] fix: add text wrap to open link dialog --- config/ui/game/common.cfg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/ui/game/common.cfg b/config/ui/game/common.cfg index f10131bda..38a5820da 100644 --- a/config/ui/game/common.cfg +++ b/config/ui/game/common.cfg @@ -618,7 +618,9 @@ ui_gameui_openlink_dims = 0.72 ui_gameui_shadowhoriz ] - uitext $gameui_openlink_href 1.5 + uitext $gameui_openlink_href 1.5 [ + uitextwrap 0.68 + ] uivlist 0 [ ui_gameui_prettybutton [ From 474c114ec1ec4dfa9a7b4610fac615641d450adb Mon Sep 17 00:00:00 2001 From: the0show <62229104+The0Show@users.noreply.github.com> Date: Mon, 13 Oct 2025 00:07:27 -0400 Subject: [PATCH 3/5] validate URLs opened with `/open_url` probably not the best approach... --- src/engine/client.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/engine/client.cpp b/src/engine/client.cpp index b20b55703..43c46a4c6 100644 --- a/src/engine/client.cpp +++ b/src/engine/client.cpp @@ -40,6 +40,17 @@ bool connected(bool attempt, bool local) return curpeer || (attempt && connpeer) || (local && haslocalclients()); } +bool isvalidurl(char *href){ + int len = strlen(href); + if(len < 7) return false; + + if(strncmp("http://", href, 7) == 0) return true; + + if(len >= 8 && strncmp("https://", href, 8) == 0) return true; + + return false; +} + const ENetAddress *connectedpeer() { return curpeer ? &curpeer->address : NULL; @@ -67,7 +78,7 @@ ICOMMAND(0, connectedport, "", (), ICOMMAND(0, open_url, "s", (char *href), { - SDL_OpenURL(href); + if(isvalidurl(href)) SDL_OpenURL(href); }); ICOMMAND(0, set_clipboard, "s", (char *data), From 4bf78efd688cab6564a6eebdb47b45d1e0348ecd Mon Sep 17 00:00:00 2001 From: the0show <62229104+The0Show@users.noreply.github.com> Date: Mon, 13 Oct 2025 00:26:38 -0400 Subject: [PATCH 4/5] remove the "Visit Website" test buttons i added (and forgot to remove...) --- config/ui/game/support.cfg | 42 -------------------------------------- 1 file changed, 42 deletions(-) diff --git a/config/ui/game/support.cfg b/config/ui/game/support.cfg index c067a0eb4..eda0d5438 100644 --- a/config/ui/game/support.cfg +++ b/config/ui/game/support.cfg @@ -21,20 +21,6 @@ ui_gameui_support_about_dims = 0.72 ui_gameui_horizgroup [ uicolourtext "(C) 2009-2025 Quinton Reeves, Lee Salzman, Sławomir Błauciak" 0xaaaaaa uicolourtext "https://www.redeclipse.net/" #(hsvtohex 8 0.85 0.8) - - uispace 0.02 0.02 [ - ui_gameui_button [ - p_label = "Visit Website" - p_label_size = 1.2 - p_width = 0.12 - p_height = 0.04 - p_colour = 0xff8888 - p_on_click = [ - gameui_openlink "https://www.redeclipse.net/" - ] - p_id = #(gameui_get_id) - ] - ] ] [ p_label = "Red Eclipse Engine" p_width = 0.4 @@ -43,20 +29,6 @@ ui_gameui_support_about_dims = 0.72 ui_gameui_horizgroup [ uicolourtext "(C) 2009-2025 Red Eclipse Team" 0xaaaaaa uicolourtext "https://www.redeclipse.net/" #(hsvtohex 8 0.85 0.8) - - uispace 0.02 0.02 [ - ui_gameui_button [ - p_label = "Visit Website" - p_label_size = 1.2 - p_width = 0.12 - p_height = 0.04 - p_colour = 0xff8888 - p_on_click = [ - gameui_openlink "https://www.redeclipse.net/" - ] - p_id = #(gameui_get_id) - ] - ] ] [ p_label = "Red Eclipse Assets" p_width = 0.4 @@ -65,20 +37,6 @@ ui_gameui_support_about_dims = 0.72 ui_gameui_horizgroup [ uicolourtext "(C) 2014-2024 Lee Salzman, et. al." 0xaaaaaa uicolourtext "http://tesseract.gg/" #(hsvtohex 8 0.85 0.8) - - uispace 0.02 0.02 [ - ui_gameui_button [ - p_label = "Visit Website" - p_label_size = 1.2 - p_width = 0.12 - p_height = 0.04 - p_colour = 0xff8888 - p_on_click = [ - gameui_openlink "http://tesseract.gg/" - ] - p_id = #(gameui_get_id) - ] - ] ] [ p_label = "Tesseract Engine" p_width = 0.4 From 8c49c15e59c66f8dc0c83ce564754356079b0fa6 Mon Sep 17 00:00:00 2001 From: the0show <62229104+The0Show@users.noreply.github.com> Date: Mon, 13 Oct 2025 12:27:29 -0400 Subject: [PATCH 5/5] style: Fix code style issues BREAKING CHANGE: `/open_url` is now `/openurl` `/set_clipboard` is now `/setclipboard` --- config/ui/game/common.cfg | 4 ++-- src/engine/client.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/ui/game/common.cfg b/config/ui/game/common.cfg index 38a5820da..8cfd06168 100644 --- a/config/ui/game/common.cfg +++ b/config/ui/game/common.cfg @@ -629,7 +629,7 @@ ui_gameui_openlink_dims = 0.72 p_width = 0.3 p_pad_h_shift = 0 p_on_click = [ - open_url $gameui_openlink_href + openurl $gameui_openlink_href gameui_close ] p_id = #(gameui_get_id prettybutton) @@ -641,7 +641,7 @@ ui_gameui_openlink_dims = 0.72 p_width = 0.3 p_pad_h_shift = 0 p_on_click = [ - set_clipboard $gameui_openlink_href + setclipboard $gameui_openlink_href gameui_close ] p_id = #(gameui_get_id prettybutton) diff --git a/src/engine/client.cpp b/src/engine/client.cpp index 43c46a4c6..ae8111483 100644 --- a/src/engine/client.cpp +++ b/src/engine/client.cpp @@ -40,13 +40,14 @@ bool connected(bool attempt, bool local) return curpeer || (attempt && connpeer) || (local && haslocalclients()); } -bool isvalidurl(char *href){ +bool isvalidurl(char *href) +{ int len = strlen(href); if(len < 7) return false; - if(strncmp("http://", href, 7) == 0) return true; + if(!strncmp("http://", href, 7)) return true; - if(len >= 8 && strncmp("https://", href, 8) == 0) return true; + if(len >= 8 && !strncmp("https://", href, 8)) return true; return false; } @@ -76,12 +77,12 @@ ICOMMAND(0, connectedport, "", (), intret(address ? address->port : -1); }); -ICOMMAND(0, open_url, "s", (char *href), +ICOMMAND(0, openurl, "s", (char *href), { if(isvalidurl(href)) SDL_OpenURL(href); }); -ICOMMAND(0, set_clipboard, "s", (char *data), +ICOMMAND(0, setclipboard, "s", (char *data), { SDL_SetClipboardText(data); });