From 7bdd18ee8aaa1685ec5342010a52a2495d02463a Mon Sep 17 00:00:00 2001 From: Drulikar Date: Thu, 22 Feb 2024 15:15:33 -0800 Subject: [PATCH] Relay configs --- .../controllers/configuration/config_entry.dm | 5 +- .../configuration/entries/general.dm | 13 ++++ code/modules/tgui_panel/ping_relay.dm | 19 ++++++ config/example/config.txt | 1 + config/example/relays.txt | 22 +++++++ .../tgui/interfaces/PingRelaysPanel.jsx | 61 ++++++------------- 6 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 config/example/relays.txt diff --git a/code/controllers/configuration/config_entry.dm b/code/controllers/configuration/config_entry.dm index c47531f5fc45..2cc5107fdbc8 100644 --- a/code/controllers/configuration/config_entry.dm +++ b/code/controllers/configuration/config_entry.dm @@ -137,6 +137,7 @@ var/key_mode var/value_mode var/splitter = " " + var/to_lower_keys = TRUE /datum/config_entry/keyed_list/New() . = ..() @@ -153,7 +154,9 @@ var/key_value = null if(key_pos || value_mode == VALUE_MODE_FLAG) - key_name = lowertext(copytext(str_val, 1, key_pos)) + key_name = copytext(str_val, 1, key_pos) + if(to_lower_keys) + key_name = lowertext(key_name) if(key_pos) key_value = copytext(str_val, key_pos + length(str_val[key_pos])) var/new_key diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index 83929ecf8803..1a374f7180f3 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -629,3 +629,16 @@ This maintains a list of ip addresses that are able to bypass topic filtering. /datum/config_entry/flag/guest_ban /datum/config_entry/flag/auto_profile + +/// Relay Ping Browser configuration +/datum/config_entry/keyed_list/connection_relay_ping + splitter = "|" + key_mode = KEY_MODE_TEXT + value_mode = VALUE_MODE_TEXT + to_lower_keys = FALSE + +/datum/config_entry/keyed_list/connection_relay_con + splitter = "|" + key_mode = KEY_MODE_TEXT + value_mode = VALUE_MODE_TEXT + to_lower_keys = FALSE diff --git a/code/modules/tgui_panel/ping_relay.dm b/code/modules/tgui_panel/ping_relay.dm index 8bff79fa14f6..6e5aa967e907 100644 --- a/code/modules/tgui_panel/ping_relay.dm +++ b/code/modules/tgui_panel/ping_relay.dm @@ -13,6 +13,25 @@ GLOBAL_DATUM_INIT(relays_panel, /datum/ping_relay_tgui, new) /datum/ping_relay_tgui/ui_state(mob/user) return GLOB.always_state +/datum/ping_relay_tgui/ui_static_data(mob/user) + var/list/data = list() + var/list/relay_names = list() + var/list/relay_pings = list() + var/list/relay_cons = list() + + var/list/relay_ping_conf = CONFIG_GET(keyed_list/connection_relay_ping) + var/list/relay_con_conf = CONFIG_GET(keyed_list/connection_relay_con) + for(var/key in relay_ping_conf) + // assumption: keys are the same in both configs + relay_names += key + relay_pings += relay_ping_conf[key] + relay_cons += relay_con_conf[key] + + data["relay_names"] = relay_names + data["relay_pings"] = relay_pings + data["relay_cons"] = relay_cons + return data + /datum/ping_relay_tgui/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) . = ..() if(.) diff --git a/config/example/config.txt b/config/example/config.txt index f9e0956593a9..f055a5d65bff 100644 --- a/config/example/config.txt +++ b/config/example/config.txt @@ -4,6 +4,7 @@ # $include dbconfig.txt # $include resources.txt # $include icon_source.txt +# $include relays.txt ## Server name: This appears at the top of the screen in-game. In this case it will read "tgstation: station_name" where station_name is the randomly generated name of the station for the round. Remove the # infront of SERVERNAME and replace 'tgstation' with the name of your choice # SERVERNAME spacestation13 diff --git a/config/example/relays.txt b/config/example/relays.txt new file mode 100644 index 000000000000..562e917fa484 --- /dev/null +++ b/config/example/relays.txt @@ -0,0 +1,22 @@ +## Settings controlling the relay ping browser accessed via PingIndicator in TGChat +## Pings are performed by timing how long it takes to download favicon.ico from the PingURL + +## Connection Relays: Name must match both ping and connect pairs +## CONNECTION_RELAY_PING Name|PingURL +## CONNECTION_RELAY_CON Name|ConnectURL +CONNECTION_RELAY_PING Direct|play.cm-ss13.com:8998 +CONNECTION_RELAY_CON Direct|play.cm-ss13.com:1400 +CONNECTION_RELAY_PING United Kingdom, London|uk.cm-ss13.com:8998 +CONNECTION_RELAY_CON United Kingdom, London|uk.cm-ss13.com:1400 +CONNECTION_RELAY_PING France, Gravelines|eu-w.cm-ss13.com:8998 +CONNECTION_RELAY_CON France, Gravelines|eu-w.cm-ss13.com:1400 +CONNECTION_RELAY_PING Poland, Warsaw|eu-e.cm-ss13.com:8998 +CONNECTION_RELAY_CON Poland, Warsaw|eu-e.cm-ss13.com:1400 +CONNECTION_RELAY_PING Oregon, Hillsboro|us-w.cm-ss13.com:8998 +CONNECTION_RELAY_CON Oregon, Hillsboro|us-w.cm-ss13.com:1400 +CONNECTION_RELAY_PING Virginia, Vint Hill|us-e.cm-ss13.com:8998 +CONNECTION_RELAY_CON Virginia, Vint Hill|us-e.cm-ss13.com:1400 +CONNECTION_RELAY_PING Singapore|asia-se.cm-ss13.com:8998 +CONNECTION_RELAY_CON Singapore|asia-se.cm-ss13.com:1400 +CONNECTION_RELAY_PING Australia, Sydney|aus.cm-ss13.com:8998 +CONNECTION_RELAY_CON Australia, Sydney|aus.cm-ss13.com:1400 diff --git a/tgui/packages/tgui/interfaces/PingRelaysPanel.jsx b/tgui/packages/tgui/interfaces/PingRelaysPanel.jsx index 48f672ee77c1..5b2c316b300d 100644 --- a/tgui/packages/tgui/interfaces/PingRelaysPanel.jsx +++ b/tgui/packages/tgui/interfaces/PingRelaysPanel.jsx @@ -6,7 +6,6 @@ import { Color } from 'common/color'; import { Ping } from 'common/ping'; import { Component } from 'react'; -const RELAY_COUNT = 8; const RED = new Color(220, 40, 40); export class PingResult { @@ -30,16 +29,12 @@ class PingApp extends Component { super(); this.pinger = new Ping(); + this.results = new Array(); this.state = { currentIndex: 0, lastClickedIndex: 0, lastClickedState: false, }; - - this.results = new Array(RELAY_COUNT); - for (let i = 0; i < RELAY_COUNT; i++) { - this.results[i] = new PingResult(); - } } startTest(desc, pingURL, connectURL) { @@ -64,42 +59,15 @@ class PingApp extends Component { } componentDidMount() { - this.startTest('Direct', 'play.cm-ss13.com:8998', 'play.cm-ss13.com:1400'); - this.startTest( - 'United Kingdom, London', - 'uk.cm-ss13.com:8998', - 'uk.cm-ss13.com:1400' - ); - this.startTest( - 'France, Gravelines', - 'eu-w.cm-ss13.com:8998', - 'eu-w.cm-ss13.com:1400' - ); - this.startTest( - 'Poland, Warsaw', - 'eu-e.cm-ss13.com:8998', - 'eu-e.cm-ss13.com:1400' - ); - this.startTest( - 'Oregon, Hillsboro', - 'us-w.cm-ss13.com:8998', - 'us-w.cm-ss13.com:1400' - ); - this.startTest( - 'Virginia, Vint Hill', - 'us-e.cm-ss13.com:8998', - 'us-e.cm-ss13.com:1400' - ); - this.startTest( - 'Singapore', - 'asia-se.cm-ss13.com:8998', - 'asia-se.cm-ss13.com:1400' - ); - this.startTest( - 'Australia, Sydney', - 'aus.cm-ss13.com:8998', - 'aus.cm-ss13.com:1400' - ); + this.setState({ currentIndex: 0 }); + for (let i = 0; i < this.props.relayNames.length; i++) { + this.results.push(new PingResult()); + this.startTest( + this.props.relayNames[i], + this.props.relayPings[i], + this.props.relayCons[i] + ); + } } componentWillUnmount() { @@ -188,10 +156,17 @@ class PingApp extends Component { } export const PingRelaysPanel = () => { + const { data } = useBackend(); + const { relay_names, relay_pings, relay_cons } = data; + return ( - + );