mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 09:42:29 +00:00
Preference support for Guests (#72332)
## About The Pull Request Makes it to where if you connect as a guest preferences don't error out the ass Resolves https://github.com/tgstation/tgstation/issues/72268 ## Why It's Good For The Game Easier local debugging, and for servers that let guests join ## Changelog 🆑 server: Preferences now support guests /🆑
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* A savefile implementation that handles all data using json.
|
* A savefile implementation that handles all data using json.
|
||||||
* Also saves it using JSON too, fancy.
|
* Also saves it using JSON too, fancy.
|
||||||
|
* If you pass in a null path, it simply acts as a memory tree instead, and cannot be saved.
|
||||||
*/
|
*/
|
||||||
/datum/json_savefile
|
/datum/json_savefile
|
||||||
var/path = ""
|
var/path = ""
|
||||||
@@ -13,7 +14,7 @@ GENERAL_PROTECT_DATUM(/datum/json_savefile)
|
|||||||
/datum/json_savefile/New(path)
|
/datum/json_savefile/New(path)
|
||||||
src.path = path
|
src.path = path
|
||||||
tree = list()
|
tree = list()
|
||||||
if(fexists(path))
|
if(path && fexists(path))
|
||||||
load()
|
load()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +44,7 @@ GENERAL_PROTECT_DATUM(/datum/json_savefile)
|
|||||||
tree?.Cut()
|
tree?.Cut()
|
||||||
|
|
||||||
/datum/json_savefile/proc/load()
|
/datum/json_savefile/proc/load()
|
||||||
if(!fexists(path))
|
if(!path || !fexists(path))
|
||||||
return FALSE
|
return FALSE
|
||||||
try
|
try
|
||||||
tree = json_decode(rustg_file_read(path))
|
tree = json_decode(rustg_file_read(path))
|
||||||
@@ -53,7 +54,8 @@ GENERAL_PROTECT_DATUM(/datum/json_savefile)
|
|||||||
return FALSE
|
return FALSE
|
||||||
|
|
||||||
/datum/json_savefile/proc/save()
|
/datum/json_savefile/proc/save()
|
||||||
rustg_file_write(json_encode(tree), path)
|
if(path)
|
||||||
|
rustg_file_write(json_encode(tree), path)
|
||||||
|
|
||||||
/// Traverses the entire dir tree of the given savefile and dynamically assembles the tree from it
|
/// Traverses the entire dir tree of the given savefile and dynamically assembles the tree from it
|
||||||
/datum/json_savefile/proc/import_byond_savefile(savefile/savefile)
|
/datum/json_savefile/proc/import_byond_savefile(savefile/savefile)
|
||||||
|
|||||||
@@ -2,20 +2,26 @@ GLOBAL_LIST_EMPTY(preferences_datums)
|
|||||||
|
|
||||||
/datum/preferences
|
/datum/preferences
|
||||||
var/client/parent
|
var/client/parent
|
||||||
//doohickeys for savefiles
|
/// The path to the general savefile for this datum
|
||||||
var/path
|
var/path
|
||||||
var/default_slot = 1 //Holder so it doesn't default to slot 1, rather the last one used
|
/// Whether or not we allow saving/loading. Used for guests, if they're enabled
|
||||||
|
var/load_and_save = TRUE
|
||||||
|
/// Ensures that we always load the last used save, QOL
|
||||||
|
var/default_slot = 1
|
||||||
|
/// The maximum number of slots we're allowed to contain
|
||||||
var/max_save_slots = 3
|
var/max_save_slots = 3
|
||||||
|
|
||||||
//non-preference stuff
|
/// Bitflags for communications that are muted
|
||||||
var/muted = 0
|
var/muted = NONE
|
||||||
|
/// Last IP that this client has connected from
|
||||||
var/last_ip
|
var/last_ip
|
||||||
|
/// Last CID that this client has connected from
|
||||||
var/last_id
|
var/last_id
|
||||||
|
|
||||||
//game-preferences
|
/// Cached changelog size, to detect new changelogs since last join
|
||||||
var/lastchangelog = "" //Saved changlog filesize to detect if there was a change
|
var/lastchangelog = ""
|
||||||
|
|
||||||
//Antag preferences
|
/// List of ROLE_X that the client wants to be eligible for
|
||||||
var/list/be_special = list() //Special role selection
|
var/list/be_special = list() //Special role selection
|
||||||
|
|
||||||
/// Custom keybindings. Map of keybind names to keyboard inputs.
|
/// Custom keybindings. Map of keybind names to keyboard inputs.
|
||||||
@@ -95,13 +101,13 @@ GLOBAL_LIST_EMPTY(preferences_datums)
|
|||||||
middleware += new middleware_type(src)
|
middleware += new middleware_type(src)
|
||||||
|
|
||||||
if(IS_CLIENT_OR_MOCK(parent))
|
if(IS_CLIENT_OR_MOCK(parent))
|
||||||
if(!is_guest_key(parent.key))
|
load_and_save = !is_guest_key(parent.key)
|
||||||
load_path(parent.ckey)
|
load_path(parent.ckey)
|
||||||
if(!fexists(path))
|
if(load_and_save && !fexists(path))
|
||||||
try_savefile_type_migration()
|
try_savefile_type_migration()
|
||||||
unlock_content = !!parent.IsByondMember()
|
unlock_content = !!parent.IsByondMember()
|
||||||
if(unlock_content)
|
if(unlock_content)
|
||||||
max_save_slots = 8
|
max_save_slots = 8
|
||||||
else
|
else
|
||||||
CRASH("attempted to create a preferences datum without a client or mock!")
|
CRASH("attempted to create a preferences datum without a client or mock!")
|
||||||
load_savefile()
|
load_savefile()
|
||||||
|
|||||||
@@ -140,14 +140,14 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
|
|||||||
to_chat(parent, span_danger("[conflicted.category]: [conflicted.full_name] needs updating"))
|
to_chat(parent, span_danger("[conflicted.category]: [conflicted.full_name] needs updating"))
|
||||||
|
|
||||||
/datum/preferences/proc/load_path(ckey, filename="preferences.json")
|
/datum/preferences/proc/load_path(ckey, filename="preferences.json")
|
||||||
if(!ckey)
|
if(!ckey || !load_and_save)
|
||||||
return
|
return
|
||||||
path = "data/player_saves/[ckey[1]]/[ckey]/[filename]"
|
path = "data/player_saves/[ckey[1]]/[ckey]/[filename]"
|
||||||
|
|
||||||
/datum/preferences/proc/load_savefile()
|
/datum/preferences/proc/load_savefile()
|
||||||
if(!path)
|
if(load_and_save && !path)
|
||||||
CRASH("Attempted to load savefile without first loading a path!")
|
CRASH("Attempted to load savefile without first loading a path!")
|
||||||
savefile = new /datum/json_savefile(path)
|
savefile = new /datum/json_savefile(load_and_save ? path : null)
|
||||||
|
|
||||||
/datum/preferences/proc/load_preferences()
|
/datum/preferences/proc/load_preferences()
|
||||||
if(!savefile)
|
if(!savefile)
|
||||||
@@ -158,7 +158,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
|
|||||||
return FALSE
|
return FALSE
|
||||||
|
|
||||||
var/needs_update = save_data_needs_update(savefile.get_entry())
|
var/needs_update = save_data_needs_update(savefile.get_entry())
|
||||||
if(needs_update == -2) //fatal, can't load any data
|
if(load_and_save && (needs_update == -2)) //fatal, can't load any data
|
||||||
var/bacpath = "[path].updatebac" //todo: if the savefile version is higher then the server, check the backup, and give the player a prompt to load the backup
|
var/bacpath = "[path].updatebac" //todo: if the savefile version is higher then the server, check the backup, and give the player a prompt to load the backup
|
||||||
if (fexists(bacpath))
|
if (fexists(bacpath))
|
||||||
fdel(bacpath) //only keep 1 version of backup
|
fdel(bacpath) //only keep 1 version of backup
|
||||||
@@ -263,7 +263,6 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
|
|||||||
|
|
||||||
/datum/preferences/proc/load_character(slot)
|
/datum/preferences/proc/load_character(slot)
|
||||||
SHOULD_NOT_SLEEP(TRUE)
|
SHOULD_NOT_SLEEP(TRUE)
|
||||||
|
|
||||||
if(!slot)
|
if(!slot)
|
||||||
slot = default_slot
|
slot = default_slot
|
||||||
slot = sanitize_integer(slot, 1, max_save_slots, initial(default_slot))
|
slot = sanitize_integer(slot, 1, max_save_slots, initial(default_slot))
|
||||||
@@ -317,7 +316,6 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
|
|||||||
|
|
||||||
/datum/preferences/proc/save_character()
|
/datum/preferences/proc/save_character()
|
||||||
SHOULD_NOT_SLEEP(TRUE)
|
SHOULD_NOT_SLEEP(TRUE)
|
||||||
|
|
||||||
if(!path)
|
if(!path)
|
||||||
return FALSE
|
return FALSE
|
||||||
var/tree_key = "character[default_slot]"
|
var/tree_key = "character[default_slot]"
|
||||||
|
|||||||
Reference in New Issue
Block a user