mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-18 19:25:56 +00:00
Settings, Startup lists every realm of the server with its name. The choice is kept in Settings/realm-names.json of the main folder; the launcher, the realm-list setup and the client's Config.wtf use it, and a running database gets it at once. Names are 1-32 characters without quotation marks or control characters, written as escaped SQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
20d4c3351e
commit
d1534ebc92
18 files changed
+396
-26
No files matched your search
@@ -0,0 +1,7 @@
|
||||
---
|
||||
area: manager
|
||||
type: added
|
||||
audience: admins
|
||||
title: Rename your realms in the Manager
|
||||
---
|
||||
Settings, Startup has a name for every realm. A running server shows it at once, the game client picks it on the next Play, and it stays after restarts and updates. Before, the launcher wrote the default name back at every start.
|
||||
@@ -72,13 +72,23 @@ fn realm_config(old: &[u8], realm: &str) -> Vec<u8> {
|
||||
}
|
||||
|
||||
pub fn sync_realm(client: &Path, meta: &Path, mode: crate::realms::Mode) -> Result<bool> {
|
||||
sync_realm_when_closed(client, meta, mode, is_running(client))
|
||||
let realm = match mode {
|
||||
crate::realms::Mode::Coa => "Conquest of Azeroth",
|
||||
crate::realms::Mode::Wildcard => "Wildcard",
|
||||
crate::realms::Mode::Reborn => "Warcraft Reborn",
|
||||
};
|
||||
sync_realm_when_closed(client, meta, realm, is_running(client))
|
||||
}
|
||||
|
||||
/// [`sync_realm`] with the realm's name as the server shows it (the owner may have renamed it).
|
||||
pub fn sync_realm_named(client: &Path, meta: &Path, realm: &str) -> Result<bool> {
|
||||
sync_realm_when_closed(client, meta, realm, is_running(client))
|
||||
}
|
||||
|
||||
fn sync_realm_when_closed(
|
||||
client: &Path,
|
||||
meta: &Path,
|
||||
mode: crate::realms::Mode,
|
||||
realm: &str,
|
||||
running: bool,
|
||||
) -> Result<bool> {
|
||||
if running {
|
||||
@@ -90,11 +100,6 @@ fn sync_realm_when_closed(
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Vec::new(),
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
let realm = match mode {
|
||||
crate::realms::Mode::Coa => "Conquest of Azeroth",
|
||||
crate::realms::Mode::Wildcard => "Wildcard",
|
||||
crate::realms::Mode::Reborn => "Warcraft Reborn",
|
||||
};
|
||||
let new = realm_config(&old, realm);
|
||||
if new == old {
|
||||
return Ok(true);
|
||||
@@ -678,10 +683,10 @@ mod tests {
|
||||
let meta = d.path().join("meta");
|
||||
let original = b"SET realmName \"Wildcard\"\n";
|
||||
fs::write(c.join("WTF/Config.wtf"), original).unwrap();
|
||||
assert!(!sync_realm_when_closed(&c, &meta, crate::realms::Mode::Coa, true).unwrap());
|
||||
assert!(!sync_realm_when_closed(&c, &meta, "Conquest of Azeroth", true).unwrap());
|
||||
assert_eq!(fs::read(c.join("WTF/Config.wtf")).unwrap(), original);
|
||||
assert!(!backup_dir(&meta).exists());
|
||||
assert!(sync_realm_when_closed(&c, &meta, crate::realms::Mode::Coa, false).unwrap());
|
||||
assert!(sync_realm_when_closed(&c, &meta, "Conquest of Azeroth", false).unwrap());
|
||||
assert_eq!(
|
||||
fs::read(c.join("WTF/Config.wtf")).unwrap(),
|
||||
b"SET realmName \"Conquest of Azeroth\"\n"
|
||||
|
||||
@@ -335,8 +335,8 @@ pub fn start_mysql(root: &Path, cfg: &Settings, progress: Progress) -> Result<()
|
||||
mysql(
|
||||
root,
|
||||
Some(&format!(
|
||||
"UPDATE acore_auth.realmlist SET name='{}',address='127.0.0.1',localAddress='127.0.0.1',port={} WHERE id={};",
|
||||
cfg.realm.name, cfg.world_port, cfg.realm.id
|
||||
"UPDATE acore_auth.realmlist SET name={},address='127.0.0.1',localAddress='127.0.0.1',port={} WHERE id={};",
|
||||
crate::realm_names::sql_literal(&cfg.realm.name), cfg.world_port, cfg.realm.id
|
||||
)),
|
||||
None,
|
||||
)?;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub const PORT_KEYS: [&str; 4] = ["mysqlPort", "authPort", "worldPort", "raPort"
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Realm {
|
||||
pub id: u32,
|
||||
pub name: &'static str,
|
||||
pub name: String,
|
||||
pub world_db: &'static str,
|
||||
pub characters_db: &'static str,
|
||||
}
|
||||
@@ -22,15 +22,19 @@ pub struct Realm {
|
||||
impl Realm {
|
||||
pub fn load(root: &Path) -> Result<Realm> {
|
||||
let path = root.join("Settings/realm-profile.json");
|
||||
if !path.exists() {
|
||||
return Ok(Realm { id: 1, name: "AzerothCore", world_db: "acore_world", characters_db: "acore_characters" });
|
||||
}
|
||||
let v: serde_json::Value = crate::fsx::read_json(&path)?;
|
||||
Ok(match v.get("active").and_then(|a| a.as_str()).unwrap_or("coa") {
|
||||
"wildcard" => Realm { id: 2, name: "Wildcard", world_db: "acore_world_wildcard", characters_db: "acore_characters_wildcard" },
|
||||
"reborn" => Realm { id: 3, name: "Warcraft Reborn", world_db: "acore_world_reborn", characters_db: "acore_characters_reborn" },
|
||||
_ => Realm { id: 1, name: "Conquest of Azeroth", world_db: "acore_world", characters_db: "acore_characters" },
|
||||
})
|
||||
let (id, name, world_db, characters_db) = if !path.exists() {
|
||||
(1, "AzerothCore", "acore_world", "acore_characters")
|
||||
} else {
|
||||
let v: serde_json::Value = crate::fsx::read_json(&path)?;
|
||||
match v.get("active").and_then(|a| a.as_str()).unwrap_or("coa") {
|
||||
"wildcard" => (2, "Wildcard", "acore_world_wildcard", "acore_characters_wildcard"),
|
||||
"reborn" => (3, "Warcraft Reborn", "acore_world_reborn", "acore_characters_reborn"),
|
||||
_ => (1, "Conquest of Azeroth", "acore_world", "acore_characters"),
|
||||
}
|
||||
};
|
||||
// The owner's own name for this realm, when one was chosen in the Manager.
|
||||
let name = crate::realm_names::name_or(root, id, name);
|
||||
Ok(Realm { id, name, world_db, characters_db })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ pub mod ra;
|
||||
pub mod race_availability;
|
||||
pub mod realm_registry;
|
||||
pub mod realmlist;
|
||||
pub mod realm_names;
|
||||
pub mod realms;
|
||||
pub mod registry;
|
||||
pub mod release;
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
//! The names players see in the realm list, chosen by the server owner.
|
||||
//!
|
||||
//! The launcher writes `acore_auth.realmlist.name` at every start, so a name typed into the database (or into
|
||||
//! an old `manage.py`) did not last. The owner's choice lives in `Settings/realm-names.json` of the server's main
|
||||
//! folder, keyed by realm id, and every start and every realm-list setup uses it; extra worlds read their main
|
||||
//! folder's file.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::fsx;
|
||||
|
||||
const FILE: &str = "Settings/realm-names.json";
|
||||
|
||||
/// `acore_auth.realmlist.name` is `varchar(32)`.
|
||||
pub const MAX_CHARS: usize = 32;
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
struct Names {
|
||||
#[serde(default)]
|
||||
names: BTreeMap<u32, String>,
|
||||
}
|
||||
|
||||
/// The folder that owns the names: an extra world (`<server>/.realms/<name>`) belongs to `<server>`.
|
||||
fn main_folder(root: &Path) -> PathBuf {
|
||||
if crate::launcher::settings::is_extra_world(root) {
|
||||
if let Some(main) = root.parent().and_then(Path::parent) {
|
||||
return main.to_path_buf();
|
||||
}
|
||||
}
|
||||
root.to_path_buf()
|
||||
}
|
||||
|
||||
fn read(root: &Path) -> Names {
|
||||
let path = main_folder(root).join(FILE);
|
||||
if !path.is_file() {
|
||||
return Names::default();
|
||||
}
|
||||
match fsx::read_json(&path) {
|
||||
Ok(names) => names,
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "realm names could not be read; the default names are used");
|
||||
Names::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A trimmed name the realm list can hold: 1 to 32 characters, no control characters.
|
||||
pub fn validate(name: &str) -> Result<String> {
|
||||
let name = name.trim();
|
||||
if name.is_empty() {
|
||||
return Err(Error::Invalid("The realm name cannot be empty.".into()));
|
||||
}
|
||||
if name.chars().count() > MAX_CHARS {
|
||||
return Err(Error::Invalid(format!(
|
||||
"The realm name can have at most {MAX_CHARS} characters."
|
||||
)));
|
||||
}
|
||||
// The game client stores the realm as `SET realmName "<name>"` in Config.wtf.
|
||||
if name.chars().any(|c| c.is_control() || c == '"') {
|
||||
return Err(Error::Invalid(
|
||||
"The realm name cannot contain quotation marks or control characters.".into(),
|
||||
));
|
||||
}
|
||||
Ok(name.to_string())
|
||||
}
|
||||
|
||||
/// The owner's name for realm `id`, if one was chosen.
|
||||
pub fn custom(root: &Path, id: u32) -> Option<String> {
|
||||
read(root)
|
||||
.names
|
||||
.remove(&id)
|
||||
.and_then(|name| validate(&name).ok())
|
||||
}
|
||||
|
||||
/// The name realm `id` shows: the owner's choice, or `default`.
|
||||
pub fn name_or(root: &Path, id: u32, default: &str) -> String {
|
||||
custom(root, id).unwrap_or_else(|| default.to_string())
|
||||
}
|
||||
|
||||
/// The name the realm of `mode` shows.
|
||||
pub fn for_mode(root: &Path, mode: crate::realms::Mode) -> String {
|
||||
name_or(root, mode.realm_id(), mode.label())
|
||||
}
|
||||
|
||||
/// Every chosen name.
|
||||
pub fn all(root: &Path) -> BTreeMap<u32, String> {
|
||||
read(root)
|
||||
.names
|
||||
.into_iter()
|
||||
.filter_map(|(id, name)| validate(&name).ok().map(|name| (id, name)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Choose a name for realm `id`; `None` (or an empty name) returns it to its default.
|
||||
pub fn set(root: &Path, id: u32, name: Option<&str>) -> Result<Option<String>> {
|
||||
let mut names = read(root);
|
||||
let chosen = match name.map(str::trim).filter(|n| !n.is_empty()) {
|
||||
Some(name) => Some(validate(name)?),
|
||||
None => None,
|
||||
};
|
||||
match &chosen {
|
||||
Some(name) => names.names.insert(id, name.clone()),
|
||||
None => names.names.remove(&id),
|
||||
};
|
||||
fsx::atomic_write_json(&main_folder(root).join(FILE), &names)?;
|
||||
Ok(chosen)
|
||||
}
|
||||
|
||||
/// A realm of this server and the name it shows.
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RealmName {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
pub default_name: String,
|
||||
pub custom: bool,
|
||||
}
|
||||
|
||||
/// The realms of a server with their names: Conquest of Azeroth (or the plain repack's "AzerothCore") and the
|
||||
/// Wildcard and Warcraft Reborn realms that were created.
|
||||
pub fn list(root: &Path) -> Result<Vec<RealmName>> {
|
||||
let main = main_folder(root);
|
||||
let mut realms: Vec<(u32, &'static str)> = Vec::new();
|
||||
if main.join("Settings/realm-profile.json").exists() {
|
||||
let state = crate::realms::state(&main)?;
|
||||
realms.extend(state.modes().into_iter().map(|m| (m.realm_id(), m.label())));
|
||||
} else {
|
||||
realms.push((1, "AzerothCore"));
|
||||
}
|
||||
realms.sort_unstable();
|
||||
realms.dedup();
|
||||
Ok(realms
|
||||
.into_iter()
|
||||
.map(|(id, default)| {
|
||||
let custom = custom(&main, id);
|
||||
RealmName {
|
||||
id,
|
||||
name: custom.clone().unwrap_or_else(|| default.to_string()),
|
||||
default_name: default.to_string(),
|
||||
custom: custom.is_some(),
|
||||
}
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Choose a name and, when the database runs, write it to the realm list at once (the auth server shows it
|
||||
/// within its realm refresh interval). Returns the realms with their names.
|
||||
pub fn rename(root: &Path, id: u32, name: Option<&str>) -> Result<Vec<RealmName>> {
|
||||
let main = main_folder(root);
|
||||
let known = list(&main)?;
|
||||
let realm = known
|
||||
.iter()
|
||||
.find(|r| r.id == id)
|
||||
.ok_or_else(|| Error::Invalid(format!("This server has no realm {id}.")))?;
|
||||
let shown = set(&main, id, name)?.unwrap_or_else(|| realm.default_name.clone());
|
||||
crate::backup::with_running_database(&main, |db| {
|
||||
db.query(&format!(
|
||||
"UPDATE acore_auth.realmlist SET name={} WHERE id={id};",
|
||||
sql_literal(&shown)
|
||||
))
|
||||
.map(|_| ())
|
||||
})?;
|
||||
list(&main)
|
||||
}
|
||||
|
||||
/// `text` as a MySQL string literal (quotes and backslashes escaped).
|
||||
pub fn sql_literal(text: &str) -> String {
|
||||
let mut out = String::with_capacity(text.len() + 2);
|
||||
out.push('\'');
|
||||
for c in text.chars() {
|
||||
match c {
|
||||
'\'' => out.push_str("''"),
|
||||
'\\' => out.push_str("\\\\"),
|
||||
c => out.push(c),
|
||||
}
|
||||
}
|
||||
out.push('\'');
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn names_are_validated_trimmed_and_reset() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
assert_eq!(name_or(d.path(), 1, "Conquest of Azeroth"), "Conquest of Azeroth");
|
||||
assert_eq!(set(d.path(), 1, Some(" Owner's Realm ")).unwrap().as_deref(), Some("Owner's Realm"));
|
||||
assert_eq!(name_or(d.path(), 1, "x"), "Owner's Realm");
|
||||
assert!(set(d.path(), 2, Some(&"a".repeat(33))).is_err());
|
||||
assert!(set(d.path(), 2, Some("bad\nname")).is_err());
|
||||
assert_eq!(set(d.path(), 2, Some("Царство")).unwrap().as_deref(), Some("Царство"));
|
||||
assert_eq!(all(d.path()).len(), 2);
|
||||
assert_eq!(set(d.path(), 1, Some(" ")).unwrap(), None);
|
||||
assert_eq!(name_or(d.path(), 1, "Conquest of Azeroth"), "Conquest of Azeroth");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_extra_world_reads_its_main_folders_names() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
set(d.path(), 2, Some("Wild Side")).unwrap();
|
||||
let extra = d.path().join(".realms/secondary");
|
||||
std::fs::create_dir_all(&extra).unwrap();
|
||||
assert_eq!(custom(&extra, 2).as_deref(), Some("Wild Side"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn names_are_safe_in_sql() {
|
||||
assert_eq!(sql_literal(r"O'Neil \ realm"), r"'O''Neil \\ realm'");
|
||||
}
|
||||
}
|
||||
@@ -707,8 +707,8 @@ pub fn setup_realmlist(root: &Path) -> Result<()> {
|
||||
let port = layout::read_ports(root).world;
|
||||
for mode in s.modes().into_iter().filter(|m| *m != Mode::Coa) {
|
||||
let id = mode.realm_id();
|
||||
let name = mode.label();
|
||||
db.query(&format!("INSERT INTO acore_auth.realmlist (id,name,address,localAddress,localSubnetMask,port,icon,flag,timezone,gamebuild) SELECT {id},'{name}',address,localAddress,localSubnetMask,{port},icon,2,timezone,gamebuild FROM acore_auth.realmlist WHERE id=1 ON DUPLICATE KEY UPDATE port={port};"))?;
|
||||
let name = crate::realm_names::sql_literal(&crate::realm_names::name_or(root, id, mode.label()));
|
||||
db.query(&format!("INSERT INTO acore_auth.realmlist (id,name,address,localAddress,localSubnetMask,port,icon,flag,timezone,gamebuild) SELECT {id},{name},address,localAddress,localSubnetMask,{port},icon,2,timezone,gamebuild FROM acore_auth.realmlist WHERE id=1 ON DUPLICATE KEY UPDATE port={port},name={name};"))?;
|
||||
}
|
||||
let ids = s
|
||||
.modes()
|
||||
|
||||
+32
-2
@@ -1217,7 +1217,11 @@ async fn realm_select(
|
||||
let view = coa_core::realms::select(&root, mode)?;
|
||||
let (dir, meta) = install_meta(&root)?;
|
||||
if let Some(client) = meta.client_path {
|
||||
coa_core::client::sync_realm(std::path::Path::new(&client), &dir, view.active)?;
|
||||
coa_core::client::sync_realm_named(
|
||||
std::path::Path::new(&client),
|
||||
&dir,
|
||||
&coa_core::realm_names::for_mode(&root, view.active),
|
||||
)?;
|
||||
}
|
||||
if restart {
|
||||
let out = driver::run(&root, Verb::StartAll)?;
|
||||
@@ -1234,6 +1238,29 @@ async fn realm_select(
|
||||
result
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn realm_names(
|
||||
state: State<'_, AppState>,
|
||||
id: String,
|
||||
) -> std::result::Result<Vec<coa_core::realm_names::RealmName>, UiError> {
|
||||
let root = path_of(&state, &id)?;
|
||||
blocking(move || coa_core::realm_names::list(&root)).await
|
||||
}
|
||||
|
||||
/// Rename a realm (`None` brings back its default name). The realm list changes at once when the database runs,
|
||||
/// and the linked game client selects the new name on the next Play.
|
||||
#[tauri::command]
|
||||
async fn realm_rename(
|
||||
state: State<'_, AppState>,
|
||||
id: String,
|
||||
realm_id: u32,
|
||||
name: Option<String>,
|
||||
) -> std::result::Result<Vec<coa_core::realm_names::RealmName>, UiError> {
|
||||
let root = path_of(&state, &id)?;
|
||||
let _guard = BusyGuard::acquire(&state, &id)?;
|
||||
blocking(move || coa_core::realm_names::rename(&root, realm_id, name.as_deref())).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn realm_simultaneous(
|
||||
state: State<'_, AppState>,
|
||||
@@ -2427,7 +2454,8 @@ async fn play(
|
||||
}
|
||||
blocking(move || {
|
||||
let mode = coa_core::realms::state(&root)?.active;
|
||||
if !coa_core::client::sync_realm(&client, &dir, mode)? {
|
||||
let realm = coa_core::realm_names::for_mode(&root, mode);
|
||||
if !coa_core::client::sync_realm_named(&client, &dir, &realm)? {
|
||||
return Err(Error::Invalid(
|
||||
"Close the game client before pressing Play so its selected realm can be updated."
|
||||
.into(),
|
||||
@@ -2981,6 +3009,8 @@ pub fn run() {
|
||||
realm_select,
|
||||
realm_simultaneous,
|
||||
realm_with_reborn,
|
||||
realm_names,
|
||||
realm_rename,
|
||||
check_database,
|
||||
repair_server,
|
||||
module_set_enabled,
|
||||
|
||||
@@ -39,6 +39,7 @@ export {};
|
||||
if(cmd==="pending_update") return null;
|
||||
if(cmd==="plugin:app|version") return "0.8.2";
|
||||
if(cmd==="release_history") throw new Error("Offline demo: using bundled notes");
|
||||
if(cmd==="realm_names"||cmd==="realm_rename"){const w=window as any;w.__rn=w.__rn??{};const defs:[number,string][]=[[1,"Conquest of Azeroth"],[2,"Wildcard"]];if(cmd==="realm_rename"){await new Promise(r=>setTimeout(r,300));const n=(args.name??"").trim();if(n.length>32||n.includes('"'))throw new Error("The realm name can have at most 32 characters.");if(n)w.__rn[args.realmId]=n;else delete w.__rn[args.realmId];}return defs.map(([id,d])=>({id,name:w.__rn[id]??d,defaultName:d,custom:id in w.__rn}));}
|
||||
if(cmd==="realm_profiles") return {active:realm,wildcard_created:wildcardCreated,reborn_created:rebornCreated,reborn_supported:true,supported:true,recovery_pending:false,simultaneous,secondary_world_port:simultaneous?8086:null,secondary_running:simultaneous&&running,with_reborn:withReborn,reborn_world_port:withReborn?8087:null,reborn_running:withReborn&&running};
|
||||
if(cmd==="realm_simultaneous") { if(running) throw new Error("Stop both realms before changing simultaneous startup."); simultaneous=args.enabled; wildcardCreated ||= simultaneous; return {active:realm,wildcard_created:wildcardCreated,reborn_created:rebornCreated,reborn_supported:true,supported:true,recovery_pending:false,simultaneous,secondary_world_port:simultaneous?8086:null,secondary_running:false,with_reborn:withReborn,reborn_world_port:withReborn?8087:null,reborn_running:false}; }
|
||||
if(cmd==="realm_with_reborn") { if(running) throw new Error("Stop all realms before changing which realms start together."); withReborn=args.enabled; rebornCreated ||= withReborn; return {active:realm,wildcard_created:wildcardCreated,reborn_created:rebornCreated,reborn_supported:true,supported:true,recovery_pending:false,simultaneous,secondary_world_port:simultaneous?8086:null,secondary_running:false,with_reborn:withReborn,reborn_world_port:withReborn?8087:null,reborn_running:false}; }
|
||||
|
||||
@@ -773,6 +773,13 @@ const de: Partial<Record<keyof typeof en, string>> = {
|
||||
"overview.reportBtn": "Diagnose sammeln und melden",
|
||||
|
||||
// Realmlist switcher and modules page
|
||||
"realm.namesTitle": "Realmnamen",
|
||||
"realm.namesHint": "So heißt der Realm in der Realmliste der Spieler. Ein laufender Server zeigt den Namen sofort, und er bleibt nach Updates erhalten.",
|
||||
"realm.nameSave": "Speichern",
|
||||
"realm.nameReset": "Standardname",
|
||||
"realm.nameDefault": "Standard: {name}",
|
||||
"realm.nameSaved": "Gespeichert.",
|
||||
"realm.nameQuotes": "Anführungszeichen sind nicht erlaubt: Der Spielclient speichert den Namen in Anführungszeichen.",
|
||||
"realm.profileLabel": "Realm",
|
||||
"realm.switching": "Realm wird gewechselt…",
|
||||
"realm.rebornCreate": "Warcraft-Reborn-Realm erstellen",
|
||||
|
||||
@@ -57,6 +57,13 @@ const en = {
|
||||
"remote.hostInstead": "Host my own server",
|
||||
"welcome.roleSubtitle": "How would you like to play?",
|
||||
|
||||
"realm.namesTitle": "Realm names",
|
||||
"realm.namesHint": "The name players see in the realm list. A running server shows it at once, and it stays after updates.",
|
||||
"realm.nameSave": "Save",
|
||||
"realm.nameReset": "Default name",
|
||||
"realm.nameDefault": "Default: {name}",
|
||||
"realm.nameSaved": "Saved.",
|
||||
"realm.nameQuotes": "Quotation marks are not allowed: the game client stores the name in quotes.",
|
||||
"realm.profileLabel": "Realm",
|
||||
"realm.startupTitle": "Realm startup",
|
||||
"realm.secondWorld": "Second world",
|
||||
|
||||
@@ -773,6 +773,13 @@ const es: Partial<Record<keyof typeof en, string>> = {
|
||||
"overview.reportBtn": "Reunir el diagnóstico y avisar",
|
||||
|
||||
// Realmlist switcher and modules page
|
||||
"realm.namesTitle": "Nombres de los reinos",
|
||||
"realm.namesHint": "El nombre que ven los jugadores en la lista de reinos. Un servidor en marcha lo muestra al instante y se mantiene tras las actualizaciones.",
|
||||
"realm.nameSave": "Guardar",
|
||||
"realm.nameReset": "Nombre predeterminado",
|
||||
"realm.nameDefault": "Predeterminado: {name}",
|
||||
"realm.nameSaved": "Guardado.",
|
||||
"realm.nameQuotes": "No se permiten comillas: el cliente del juego guarda el nombre entre comillas.",
|
||||
"realm.profileLabel": "Reino",
|
||||
"realm.switching": "Cambiando de reino…",
|
||||
"realm.rebornCreate": "Crear reino Warcraft Reborn",
|
||||
|
||||
@@ -773,6 +773,13 @@ const fr: Partial<Record<keyof typeof en, string>> = {
|
||||
"overview.reportBtn": "Rassembler le diagnostic et signaler",
|
||||
|
||||
// Realmlist switcher and modules page
|
||||
"realm.namesTitle": "Noms des royaumes",
|
||||
"realm.namesHint": "Le nom que les joueurs voient dans la liste des royaumes. Un serveur en marche l'affiche aussitôt, et il reste après les mises à jour.",
|
||||
"realm.nameSave": "Enregistrer",
|
||||
"realm.nameReset": "Nom par défaut",
|
||||
"realm.nameDefault": "Par défaut : {name}",
|
||||
"realm.nameSaved": "Enregistré.",
|
||||
"realm.nameQuotes": "Les guillemets ne sont pas autorisés : le client du jeu enregistre le nom entre guillemets.",
|
||||
"realm.profileLabel": "Royaume",
|
||||
"realm.switching": "Changement de royaume…",
|
||||
"realm.rebornCreate": "Créer le royaume Warcraft Reborn",
|
||||
|
||||
@@ -60,6 +60,13 @@ const ru: Partial<Record<keyof typeof en, string>> = {
|
||||
"remote.hostInstead": "Создать свой сервер",
|
||||
"welcome.roleSubtitle": "Как вы хотите играть?",
|
||||
|
||||
"realm.namesTitle": "Названия реалмов",
|
||||
"realm.namesHint": "Так реалм называется в списке реалмов у игроков. Работающий сервер показывает новое название сразу, и оно сохраняется после обновлений.",
|
||||
"realm.nameSave": "Сохранить",
|
||||
"realm.nameReset": "Стандартное название",
|
||||
"realm.nameDefault": "По умолчанию: {name}",
|
||||
"realm.nameSaved": "Сохранено.",
|
||||
"realm.nameQuotes": "Кавычки нельзя: клиент игры хранит название в кавычках.",
|
||||
"realm.profileLabel": "Реалм",
|
||||
"realm.startupTitle": "Запуск реалмов",
|
||||
"realm.secondWorld": "Второй мир",
|
||||
|
||||
@@ -58,6 +58,13 @@ const zh = {
|
||||
"remote.hostInstead": "搭建自己的服务器",
|
||||
"welcome.roleSubtitle": "你想如何游玩?",
|
||||
|
||||
"realm.namesTitle": "服务器名称",
|
||||
"realm.namesHint": "玩家在服务器列表中看到的名称。运行中的服务器会立即显示新名称,更新后也会保留。",
|
||||
"realm.nameSave": "保存",
|
||||
"realm.nameReset": "默认名称",
|
||||
"realm.nameDefault": "默认:{name}",
|
||||
"realm.nameSaved": "已保存。",
|
||||
"realm.nameQuotes": "不能使用引号:游戏客户端用引号保存名称。",
|
||||
"realm.profileLabel": "服务器",
|
||||
"realm.switching": "正在切换服务器…",
|
||||
"realm.rebornCreate": "创建 Warcraft Reborn 服务器",
|
||||
|
||||
@@ -57,6 +57,7 @@ export interface StatusView {
|
||||
}
|
||||
|
||||
export type RealmMode = "coa" | "wildcard" | "reborn";
|
||||
export interface RealmName { id: number; name: string; defaultName: string; custom: boolean }
|
||||
export interface RealmProfiles { active: RealmMode; wildcard_created: boolean; reborn_created: boolean; reborn_supported: boolean; supported: boolean; recovery_pending: boolean; simultaneous: boolean; secondary_world_port: number | null; secondary_running: boolean; with_reborn: boolean; reborn_world_port: number | null; reborn_running: boolean }
|
||||
export interface DatabaseCheck {
|
||||
realm: RealmMode;
|
||||
@@ -486,6 +487,8 @@ export const api = {
|
||||
realmProfiles: (id: string) => invoke<RealmProfiles>("realm_profiles", { id }),
|
||||
realmSelect: (id: string, mode: RealmMode, restart: boolean) => invoke<RealmProfiles>("realm_select", { id, mode, restart }),
|
||||
realmSimultaneous: (id: string, enabled: boolean) => invoke<RealmProfiles>("realm_simultaneous", { id, enabled }),
|
||||
realmNames: (id: string) => invoke<RealmName[]>("realm_names", { id }),
|
||||
realmRename: (id: string, realmId: number, name: string | null) => invoke<RealmName[]>("realm_rename", { id, realmId, name }),
|
||||
realmWithReborn: (id: string, enabled: boolean) => invoke<RealmProfiles>("realm_with_reborn", { id, enabled }),
|
||||
checkDatabase: (id: string) => invoke<DatabaseCheck[]>("check_database", { id }),
|
||||
repairServer: (id: string) => invoke<RepairReport>("repair_server", { id }),
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, asUiError, type RealmName } from "@/lib/api";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useT } from "@/i18n";
|
||||
|
||||
const MAX_CHARS = 32;
|
||||
|
||||
export function RealmNameSettings({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const [realms, setRealms] = useState<RealmName[] | null>(null);
|
||||
const [drafts, setDrafts] = useState<Record<number, string>>({});
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [saved, setSaved] = useState<number | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
function show(list: RealmName[]) {
|
||||
setRealms(list);
|
||||
setDrafts(Object.fromEntries(list.map(r => [r.id, r.name])));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
void api.realmNames(serverId).then(list => { if (alive) show(list); }).catch(e => { if (alive) setError(asUiError(e).technical); });
|
||||
return () => { alive = false; };
|
||||
}, [serverId]);
|
||||
|
||||
async function rename(id: number, name: string | null) {
|
||||
setBusy(true); setError(null); setSaved(null);
|
||||
try { show(await api.realmRename(serverId, id, name)); setSaved(id); }
|
||||
catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
|
||||
return <Card className="mt-6 p-6" aria-busy={busy}>
|
||||
<h2 className="font-semibold">{t("realm.namesTitle")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("realm.namesHint")}</p>
|
||||
{realms?.map(r => {
|
||||
const draft = drafts[r.id] ?? r.name;
|
||||
const invalid = draft.trim().length === 0 || draft.trim().length > MAX_CHARS || draft.includes('"');
|
||||
return <div key={r.id} className="mt-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
className="min-w-0 flex-1 rounded border border-line bg-bg px-3 py-1.5 text-sm text-ink outline-none focus:border-gold"
|
||||
value={draft}
|
||||
maxLength={MAX_CHARS}
|
||||
aria-label={t("realm.nameDefault", { name: r.defaultName })}
|
||||
disabled={busy}
|
||||
onChange={e => setDrafts(d => ({ ...d, [r.id]: e.target.value }))}
|
||||
/>
|
||||
<Button size="sm" disabled={busy || invalid || draft.trim() === r.name} onClick={() => void rename(r.id, draft)}>{t("realm.nameSave")}</Button>
|
||||
{r.custom && <Button size="sm" variant="ghost" disabled={busy} onClick={() => void rename(r.id, null)}>{t("realm.nameReset")}</Button>}
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-muted">{t("realm.nameDefault", { name: r.defaultName })}{saved === r.id ? ` · ${t("realm.nameSaved")}` : ""}</p>
|
||||
{draft.includes('"') && <p className="mt-1 text-xs text-warn">{t("realm.nameQuotes")}</p>}
|
||||
</div>;
|
||||
})}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
|
||||
</Card>;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { ReleaseHistory, type HistorySelection } from "./ReleaseHistory";
|
||||
import { ClientCard } from "./ClientCard";
|
||||
import { GameDataCard } from "./GameDataCard";
|
||||
import { RealmStartupSettings } from "./RealmStartupSettings";
|
||||
import { RealmNameSettings } from "./RealmNameSettings";
|
||||
import { AutoRestartSettings } from "./AutoRestartSettings";
|
||||
import { DiagnosticsCard } from "./DiagnosticsCard";
|
||||
import { RepairCard } from "./RepairCard";
|
||||
@@ -50,7 +51,7 @@ export function SettingsHome({ serverId, path, onForget }: { serverId: string; s
|
||||
<button onClick={() => setSection("client")} className="mt-5 flex w-full cursor-pointer items-center justify-between gap-3 rounded-lg border border-line px-5 py-4 text-left text-sm hover:bg-white/5"><span>{t("settings.clientLink")}</span><span aria-hidden>→</span></button>
|
||||
<ReleaseHistory selection={history} onSelect={setHistory} />
|
||||
</div>
|
||||
<div hidden={section !== "startup"} className="max-w-3xl"><RealmStartupSettings serverId={serverId} /><AutoRestartSettings serverId={serverId} /></div>
|
||||
<div hidden={section !== "startup"} className="max-w-3xl"><RealmNameSettings serverId={serverId} /><RealmStartupSettings serverId={serverId} /><AutoRestartSettings serverId={serverId} /></div>
|
||||
<div hidden={section !== "client"} className="max-w-3xl"><ClientCard serverId={serverId} /><GameDataCard serverId={serverId} /></div>
|
||||
<div hidden={section !== "service"} className="max-w-3xl"><ServerLoggingSettings serverId={serverId} /><DiagnosticsCard serverId={serverId} /><RepairCard serverId={serverId} /><RemoveServerCard serverId={serverId} path={path} onForget={onForget} /></div>
|
||||
<div hidden={section !== "interface"} className="max-w-3xl"><Card className="mt-6 p-6"><h2 className="font-semibold">{t("settings.language")}</h2><p className="mt-1 text-sm text-muted">{t("settings.languageHint")}</p><LanguagePicker className="mt-4" /></Card><WindowSettings /><PublicServerSettings /></div>
|
||||
|
||||
Reference in new issue
Block a user