-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
395 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
GLOBAL_DATUM_INIT(relays_panel, /datum/ping_relay_tgui, new) | ||
|
||
/datum/tgui_panel/proc/ping_relays() | ||
GLOB.relays_panel.tgui_interact(client.mob) | ||
|
||
/datum/ping_relay_tgui/tgui_interact(mob/user, datum/tgui/ui) | ||
var/list/relay_ping_conf = CONFIG_GET(keyed_list/connection_relay_ping) | ||
if(!length(relay_ping_conf)) | ||
to_chat(user, "There are no relays configured to test.") | ||
return | ||
|
||
ui = SStgui.try_update_ui(user, src, ui) | ||
if(!ui) | ||
ui = new(user, src, "PingRelaysPanel", "Relay Pings") | ||
ui.open() | ||
ui.set_autoupdate(FALSE) | ||
|
||
/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(.) | ||
return | ||
|
||
var/mob/user = ui.user | ||
|
||
switch(action) | ||
if("connect") | ||
user << link(params["url"]) | ||
ui.close() | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Adapted pinging library based on: | ||
* @file https://www.jsdelivr.com/package/npm/ping.js | ||
* @copyright 2021 Alfred Gutierrez | ||
* @license MIT | ||
*/ | ||
|
||
/** | ||
* Creates a Ping instance. | ||
* @returns {Ping} | ||
* @constructor | ||
*/ | ||
export class Ping { | ||
constructor(opt) { | ||
this.opt = opt || {}; | ||
this.favicon = this.opt.favicon || '/favicon.ico'; | ||
this.timeout = this.opt.timeout || 10000; | ||
this.logError = this.opt.logError || false; | ||
this.abort = false; | ||
} | ||
|
||
/** | ||
* Pings source after a delay and triggers a callback when completed. | ||
* @param source Source of the website or server, including protocol and port. | ||
* @param callback Callback function to trigger when completed. Returns error and ping value. | ||
* @param delay Optional number of milliseconds to wait before starting. | ||
*/ | ||
ping(source, callback, delay = 1000) { | ||
this.abort = false; | ||
let timer; | ||
if (delay > 0) { | ||
timer = setTimeout(() => { | ||
if (this.abort) { | ||
return; | ||
} | ||
this.pingNow(source, callback); | ||
}, delay); | ||
return; | ||
} | ||
this.pingNow(source, callback); | ||
} | ||
|
||
/** | ||
* Pings source immediately and triggers a callback when completed. | ||
* @param source Source of the website or server, including protocol and port. | ||
* @param callback Callback function to trigger when completed. Returns error and ping value. | ||
*/ | ||
pingNow(source, callback) { | ||
let self = this; | ||
self.abort = false; | ||
self.wasSuccess = false; | ||
self.img = new Image(); | ||
self.img.onload = (e) => { | ||
self.wasSuccess = true; | ||
pingCheck.call(self, e); | ||
}; | ||
self.img.onerror = (e) => { | ||
self.wasSuccess = false; | ||
pingCheck.call(self, e); | ||
}; | ||
|
||
let timer; | ||
let start = new Date(); | ||
|
||
if (self.timeout) { | ||
timer = setTimeout(() => { | ||
self.wasSuccess = false; | ||
pingCheck.call(self, undefined); | ||
}, self.timeout); | ||
} | ||
|
||
/** | ||
* Times ping and triggers callback. | ||
*/ | ||
const pingCheck = function (e) { | ||
if (timer) { | ||
clearTimeout(timer); | ||
} | ||
if (this.abort) { | ||
return; | ||
} | ||
let pong = new Date() - start; | ||
|
||
if (typeof callback === 'function') { | ||
// When operating in timeout mode, the timeout callback doesn't pass [event] as e. | ||
// Notice [this] instead of [self], since .call() was used with context | ||
if (!this.wasSuccess) { | ||
if (self.logError) { | ||
console.error('error loading resource: ' + e.error); | ||
} | ||
return callback(e ? 'Error' : 'Timed Out', pong); | ||
} | ||
return callback(null, pong); | ||
} else { | ||
throw new Error('Callback is not a function.'); | ||
} | ||
}; | ||
|
||
self.img.src = source + self.favicon + '?' + +new Date(); // Trigger image load with cache buster | ||
} | ||
|
||
/** | ||
* Aborts any pending ping request. | ||
*/ | ||
cancel() { | ||
this.abort = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.