Remove experimental race selection and classic class settings

This commit is contained in:
Дмитрий committed 2026-10-13 05:10:48 +05:00
1 parent 736333d23d
commit 9a7a2069c0
5 files changed
+13 -98

No files matched your search

+1 -40
View File
@@ -92,15 +92,8 @@ pub fn playerbots_conf_paths(root: &Path) -> Vec<PathBuf> {
}
/// Checks whether playerbots are configured to allow custom races.
/// Prefers the module preference; older installations fall back to the bot exclusions.
/// Returns true if AiPlayerbot.ExcludedBotRaces exists and does not exclude general custom races.
pub fn is_bot_custom_races_allowed(root: &Path) -> Option<bool> {
if let Ok(bytes) = fs::read(root.join("Core/configs/modules/coa_custom_races.conf")) {
if let Ok(conf) = crate::config::parser::ConfFile::parse_bytes(&bytes) {
if let Some(value) = conf.get("CoACustomRaces.BotsEnable") {
return Some(matches!(value.trim().trim_matches('"').to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"));
}
}
}
for path in playerbots_conf_paths(root) {
if let Ok(bytes) = fs::read(&path) {
if let Ok(conf) = crate::config::parser::ConfFile::parse_bytes(&bytes) {
@@ -121,11 +114,6 @@ pub fn sync_bot_races_config(root: &Path, allow_custom_races: bool) -> Result<()
} else {
EXCLUDED_BOT_RACES_RECOMMENDED
};
let enabled = fs::read(root.join("Core/configs/modules/coa_custom_races.conf")).ok()
.and_then(|bytes| crate::config::parser::ConfFile::parse_bytes(&bytes).ok())
.and_then(|conf| conf.get("CoACustomRaces.EnabledRaces").map(str::to_string))
.unwrap_or_else(|| "*".into());
let excluded = excluded_for_selection(excluded, if allow_custom_races { &enabled } else { "" });
for path in playerbots_conf_paths(root) {
if let Ok(bytes) = fs::read(&path) {
if let Ok(mut conf) = crate::config::parser::ConfFile::parse_bytes(&bytes) {
@@ -145,18 +133,6 @@ pub fn sync_bot_races_config(root: &Path, allow_custom_races: bool) -> Result<()
Ok(())
}
fn excluded_for_selection(base: &str, enabled: &str) -> String {
let selected = enabled.trim().trim_matches('"');
if selected == "*" { return base.to_string(); }
let allowed: std::collections::BTreeSet<u8> = selected.split(',').filter_map(|id| id.trim().parse().ok()).collect();
let mut excluded: std::collections::BTreeSet<u8> = base.split(',').filter_map(|id| id.parse().ok()).collect();
for race in 1..=255u8 {
let stock = race <= 11 && race != 9;
if !stock && !allowed.contains(&race) { excluded.insert(race); }
}
excluded.into_iter().map(|id| id.to_string()).collect::<Vec<_>>().join(",")
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ClientPatchState {
@@ -555,21 +531,6 @@ pub fn install_client_patches(
mod tests {
use super::*;
#[test]
fn bot_race_selection_preserves_stability_exclusions_and_stock_races() {
let excluded = excluded_for_selection(EXCLUDED_BOT_RACES_EXPERIMENTAL, "12,19");
let ids: std::collections::BTreeSet<u8> = excluded.split(',').map(|id| id.parse().unwrap()).collect();
assert!(!ids.contains(&12));
assert!(ids.contains(&19));
assert!(ids.contains(&14) && ids.contains(&128));
assert!(!ids.contains(&1) && !ids.contains(&11));
assert_eq!(excluded_for_selection(EXCLUDED_BOT_RACES_EXPERIMENTAL, "*"), EXCLUDED_BOT_RACES_EXPERIMENTAL);
let off = excluded_for_selection(EXCLUDED_BOT_RACES_RECOMMENDED, "");
let off: std::collections::BTreeSet<u8> = off.split(',').map(|id| id.parse().unwrap()).collect();
assert!(off.contains(&12) && off.contains(&255));
assert!(!off.contains(&1) && !off.contains(&11));
}
#[test]
fn disabling_restores_original_client_files_and_enabling_restores_custom_files() {
let temp = tempfile::tempdir().unwrap();
+10 -37
View File
@@ -127,8 +127,7 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
let name = conf_name(root, &e);
let conf = dir(root).join(&name);
let dist = dir(root).join(format!("{name}.dist"));
let installed = (conf.is_file() || dist.is_file()) && (e.id != "vanilla-classes"
|| [&conf, &dist].iter().filter_map(|path| read(path)).any(|file| file.get(&e.enable_key).is_some()));
let installed = conf.is_file() || dist.is_file();
let has_settings = installed && settings_in(cat, root, &e.id)
.map(|settings| settings.iter().any(|s| s.key != e.enable_key))
.unwrap_or(false);
@@ -253,9 +252,6 @@ fn set_enabled_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, on: bool) -
if !e.switchable || e.enable_key.is_empty() {
return Err(Error::Invalid("This part cannot be switched off.".into()));
}
if id == "vanilla-classes" && !list_in(cat, root).iter().any(|module| module.id == id && module.installed) {
return Err(Error::Invalid("Update the server to enable classic classes independently.".into()));
}
if on && matches!(id, "companions" | "playerbots") {
let other = if id == "companions" { "playerbots" } else { "companions" };
if let Some(other) = cat.iter().find(|e| e.id == other) {
@@ -292,7 +288,6 @@ pub fn settings(root: &Path, id: &str) -> Result<Vec<Setting>> {
fn settings_in(cat: &[Entry], root: &Path, id: &str) -> Result<Vec<Setting>> {
let e = entry_in(cat, id)?;
let name = conf_name(root, &e);
if id == "vanilla-classes" { return Ok(Vec::new()); }
let conf = dir(root).join(&name);
let dist = read(&dir(root).join(format!("{name}.dist")));
let active = read(&conf).or_else(|| dist.clone()).ok_or_else(|| Error::Invalid("This module is not part of this server.".into()))?;
@@ -346,14 +341,6 @@ fn save_settings_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, changes:
for (key, value) in changes {
let value = value.trim();
if let Some(field) = fields.get(key) { crate::squid::validate(field, value)?; }
if key == "CoACustomRaces.EnabledRaces" {
let selected = value.trim().trim_matches('"');
if selected != "*" && !selected.is_empty() && selected.split(',').any(|id| {
id.parse::<u8>().map_or(true, |race| race == 0)
}) {
return Err(Error::Invalid("Race IDs must be comma-separated numbers from 1 to 255, or *.".into()));
}
}
if id == "time-is-time" {
let bounds = match key.as_str() {
"TimeIsTime.SpeedRate" => Some((0.01, 60.0)),
@@ -396,13 +383,19 @@ fn save_settings_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, changes:
return Err(Error::Invalid(format!("{key} is not a setting of this module.")));
}
let documented_empty = dist.as_ref().and_then(|d| d.get(key)).map(str::trim) == Some("");
if (value.is_empty() && !documented_empty && key != "CoACustomRaces.EnabledRaces") || value.len() > 500 || value.chars().any(char::is_control) {
if (value.is_empty() && !documented_empty) || value.len() > 500 || value.chars().any(char::is_control) {
return Err(Error::Invalid(format!("The value of {key} must be one line of text.")));
}
if file.get(key).map(str::trim) != Some(value) {
changed.push((key.clone(), value.to_string()));
}
}
if id == "custom-races" {
if let Some(bots_enable) = changes.get("CoACustomRaces.BotsEnable") {
let allow = truthy(bots_enable);
crate::custom_races::sync_bot_races_config(root, allow)?;
}
}
if changed.is_empty() {
return Ok(Vec::new());
}
@@ -411,11 +404,6 @@ fn save_settings_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, changes:
file.set(k, v, &[]);
}
fsx::atomic_write(&conf, file.to_text().as_bytes())?;
if id == "custom-races" {
let allow = file.get("CoACustomRaces.BotsEnable").is_some_and(truthy)
&& file.get("CoACustomRaces.Enable").is_some_and(truthy);
crate::custom_races::sync_bot_races_config(root, allow)?;
}
Ok(changed.into_iter().map(|(k, _)| k).collect())
}
@@ -424,23 +412,12 @@ mod tests {
use super::*;
#[test]
fn custom_race_ids_and_time_settings_are_validated_before_writing() {
fn time_settings_are_validated_before_writing() {
let d = tempfile::tempdir().unwrap();
let root = d.path();
fs::create_dir_all(dir(root)).unwrap();
fs::write(dir(root).join("coa_custom_races.conf.dist"), "CoACustomRaces.Enable = 0\nCoACustomRaces.EnabledRaces = \"*\"\n").unwrap();
fs::write(dir(root).join("mod-time_is_time.conf.dist"), "TimeIsTime.Enable = 0\nTimeIsTime.SpeedRate = 1\nTimeIsTime.HourOffset = 0\nTimeIsTime.TimeStart = 0\n").unwrap();
let cat = catalog();
for value in ["12", "12,14", "*", ""] {
assert!(save_settings_in(&cat, root, root, "custom-races", &BTreeMap::from([
("CoACustomRaces.EnabledRaces".into(), value.into())
])).is_ok());
}
for value in ["0", "256", "12,no", "12,,14"] {
assert!(save_settings_in(&cat, root, root, "custom-races", &BTreeMap::from([
("CoACustomRaces.EnabledRaces".into(), value.into())
])).is_err());
}
for (key, value) in [("TimeIsTime.SpeedRate", "NaN"), ("TimeIsTime.SpeedRate", "0"),
("TimeIsTime.HourOffset", "25"), ("TimeIsTime.TimeStart", "1.5")] {
assert!(save_settings_in(&cat, root, root, "time-is-time", &BTreeMap::from([
@@ -784,11 +761,7 @@ mod tests {
let change_off = BTreeMap::from([("CoACustomRaces.BotsEnable".into(), "0".into())]);
assert_eq!(save_settings_in(&cat, &root, &meta, "custom-races", &change_off).unwrap(), ["CoACustomRaces.BotsEnable"]);
let pb = fs::read_to_string(dir(&root).join("playerbots.conf")).unwrap();
let conf = ConfFile::parse_bytes(pb.as_bytes()).unwrap();
let excluded: std::collections::BTreeSet<u8> = conf.get("AiPlayerbot.ExcludedBotRaces").unwrap()
.trim_matches('"').split(',').map(|id| id.parse().unwrap()).collect();
assert!(excluded.contains(&12) && excluded.contains(&128));
assert!(!excluded.contains(&1) && !excluded.contains(&11));
assert!(pb.contains(crate::custom_races::EXCLUDED_BOT_RACES_RECOMMENDED));
// Settings view now sees "0"
let s = settings_in(&cat, &root, "custom-races").unwrap();