Server regions (#18867)

This commit is contained in:
AffectedArc07
2022-08-21 21:27:23 +01:00
committed by GitHub
parent afbae8af1b
commit 8ec53aca7a
7 changed files with 69 additions and 4 deletions
+33
View File
@@ -417,6 +417,9 @@
if(karmaholder)
karmaholder.processRefunds(mob)
// Tell client about their connection
to_chat(src, "<span class='notice'>You are currently connected [prefs.server_region ? "via the <b>[prefs.server_region]</b> relay" : "directly"] to Paradise.</span>")
to_chat(src, "<span class='notice'>You can change this using the <code>Change Region</code> verb in the OOC tab, as selecting a region closer to you may reduce latency.</span>")
/client/proc/is_connecting_from_localhost()
var/static/list/localhost_addresses = list("127.0.0.1", "::1")
@@ -1196,6 +1199,36 @@
popup.set_content(output)
popup.open(FALSE)
/client/verb/change_region()
set category = "OOC"
set name = "Change Region"
if(!length(GLOB.configuration.system.region_map))
to_chat(usr, "<span class='warning'>Error: No extra regions defined for this server</span>")
return
var/list/target_regions = list("--DIRECT--")
for(var/region in GLOB.configuration.system.region_map)
target_regions += region
var/formatted_existing = (prefs.server_region ? prefs.server_region : "--DIRECT--")
var/choice = input(usr, "Select a region for routing optimisation.\nSelecting --DIRECT-- will bypass routing optimisations.", "Region", formatted_existing) as null|anything in target_regions
if(!choice || (choice == formatted_existing))
return
prefs.server_region = choice
prefs.save_preferences(src)
alert(usr, "Now routing you from [formatted_existing] to [choice]. You will briefly disconnect.", "ALERT", "Ok")
if(choice == "--DIRECT--")
src << link("byond://[GLOB.configuration.url.server_url]")
else
src << link(GLOB.configuration.system.region_map[choice])
#undef LIMITER_SIZE
#undef CURRENT_SECOND
#undef SECOND_COUNT
@@ -2,6 +2,8 @@
priority = 10
/datum/client_login_processor/load_preferences/get_query(client/C)
// If you ever need to remove a column from here, just replace the column name with NULL
// This saves you having to go around the entire codebase and fix columns
var/datum/db_query/query = SSdbcore.NewQuery({"SELECT
ooccolor,
UI_style,
@@ -24,7 +26,8 @@
screentip_color,
ghost_darkness_level,
colourblind_mode,
keybindings
keybindings,
server_region
FROM player
WHERE ckey=:ckey"}, list(
"ckey" = C.ckey
@@ -123,6 +123,8 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
var/list/datum/keybindings = list()
/// Keybinding overrides ("name" => ["key"...])
var/list/keybindings_overrides = null
/// Player's region override for routing optimisation
var/server_region = null
/datum/preferences/New(client/C, datum/db_query/Q) // Process our query
parent = C
@@ -26,6 +26,7 @@
ghost_darkness_level = query.item[20]
colourblind_mode = query.item[21]
keybindings = init_keybindings(raw = query.item[22])
server_region = query.item[23]
lastchangelog_2 = lastchangelog // Clone please
@@ -48,6 +49,11 @@
screentip_color = sanitize_hexcolor(screentip_color, initial(screentip_color))
ghost_darkness_level = sanitize_integer(ghost_darkness_level, 0, 255, initial(ghost_darkness_level))
colourblind_mode = sanitize_inlist(colourblind_mode, list(COLOURBLIND_MODE_NONE, COLOURBLIND_MODE_DEUTER, COLOURBLIND_MODE_PROT, COLOURBLIND_MODE_TRIT), COLOURBLIND_MODE_NONE)
// Sanitize the region
if(!(server_region in GLOB.configuration.system.region_map))
server_region = null // This region doesnt exist anymore
return TRUE
/datum/preferences/proc/save_preferences(client/C)
@@ -82,7 +88,8 @@
screentip_color=:screentip_color,
ghost_darkness_level=:ghost_darkness_level,
colourblind_mode=:colourblind_mode,
keybindings=:keybindings
keybindings=:keybindings,
server_region=:server_region
WHERE ckey=:ckey"}, list(
// OH GOD THE PARAMETERS
"ooccolour" = ooccolor,
@@ -107,6 +114,7 @@
"colourblind_mode" = colourblind_mode,
"keybindings" = json_encode(keybindings_overrides),
"ckey" = C.ckey,
"server_region" = server_region,
))
if(!query.warn_execute())