Skip to content

Commit

Permalink
Relay configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Drulikar committed Feb 22, 2024
1 parent 7209b6d commit 7bdd18e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 44 deletions.
5 changes: 4 additions & 1 deletion code/controllers/configuration/config_entry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
var/key_mode
var/value_mode
var/splitter = " "
var/to_lower_keys = TRUE

/datum/config_entry/keyed_list/New()
. = ..()
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions code/controllers/configuration/entries/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions code/modules/tgui_panel/ping_relay.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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(.)
Expand Down
1 change: 1 addition & 0 deletions config/example/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions config/example/relays.txt
Original file line number Diff line number Diff line change
@@ -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
61 changes: 18 additions & 43 deletions tgui/packages/tgui/interfaces/PingRelaysPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -188,10 +156,17 @@ class PingApp extends Component {
}

export const PingRelaysPanel = () => {
const { data } = useBackend();
const { relay_names, relay_pings, relay_cons } = data;

return (
<Window width={400} height={300} theme={'weyland'}>
<Window.Content>
<PingApp />
<PingApp
relayNames={relay_names}
relayPings={relay_pings}
relayCons={relay_cons}
/>
</Window.Content>
</Window>
);
Expand Down

0 comments on commit 7bdd18e

Please sign in to comment.