Skip to content

Commit e096cfd

Browse files
committed
Add account name field to server management; update main.ts and Tauri backend to handle account name in server data and configuration files.
1 parent 2412297 commit e096cfd

5 files changed

Lines changed: 49 additions & 27 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ <h2 id="server-modal-title" class="modal-title">Add server</h2>
4848
<label>Name <input type="text" id="form-name" required /></label>
4949
<label>Realmlist host <input type="text" id="form-host" placeholder="logon.example.com" required /></label>
5050
<label>Port <input type="number" id="form-port" placeholder="3724" min="1" max="65535" /></label>
51+
<label>Account name <input type="text" id="form-account" placeholder="Optional" /></label>
5152
<label>Start program <input type="text" id="form-wow-exe" placeholder="Wow.exe" /></label>
5253
<label>WoW path
5354
<span class="input-with-btn">

src-tauri/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn update_server(
6868
} else {
6969
server.wow_exe
7070
};
71+
s.account_name = server.account_name;
7172
}
7273
save_servers(&dir, &list)?;
7374
Ok(list)
@@ -99,9 +100,10 @@ fn write_realmlist_cmd(
99100
wow_path: String,
100101
host: String,
101102
locale: Option<String>,
103+
account_name: Option<String>,
102104
) -> Result<(), String> {
103105
let locale = locale.unwrap_or_else(|| "enUS".to_string());
104-
write_realmlist(&wow_path, &host, &locale)
106+
write_realmlist(&wow_path, &host, &locale, account_name.as_deref())
105107
}
106108

107109
#[derive(serde::Deserialize)]
@@ -145,7 +147,7 @@ fn play_wow(app: tauri::AppHandle, args: PlayWowArgs) -> Result<(), String> {
145147
} else {
146148
settings.realmlist_locale.clone()
147149
};
148-
write_realmlist(wow_path, &server.realmlist_host, &locale)?;
150+
write_realmlist(wow_path, &server.realmlist_host, &locale, server.account_name.as_deref())?;
149151
std::process::Command::new(&wow_exe)
150152
.current_dir(wow_path_buf.parent().unwrap_or(Path::new(".")))
151153
.spawn()

src-tauri/src/realmlist.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn write_realmlist(
1010
wow_path: &str,
1111
host: &str,
1212
locale: &str,
13+
account_name: Option<&str>,
1314
) -> Result<(), String> {
1415
let base = Path::new(wow_path);
1516
let host = host.trim();
@@ -25,46 +26,59 @@ pub fn write_realmlist(
2526
let realmlist_wtf = data_dir.join("realmlist.wtf");
2627
std::fs::write(&realmlist_wtf, &content).map_err(|e| e.to_string())?;
2728

28-
// 3. WTF/Config.wtf (some clients read realmlist from here)
29+
// 3. WTF/Config.wtf (realmlist + accountName)
2930
let wtf_dir = base.join("WTF");
3031
let config_wtf = wtf_dir.join("Config.wtf");
31-
write_realmlist_into_config(&config_wtf, host)?;
32+
write_realmlist_into_config(&config_wtf, host, account_name)?;
3233

3334
Ok(())
3435
}
3536

36-
/// Updates or adds the realmlist line in WTF/Config.wtf.
37-
/// Preserves all other lines; replaces any existing "set realmlist" or "SET portal" line.
38-
fn write_realmlist_into_config(config_path: &std::path::Path, host: &str) -> Result<(), String> {
39-
let new_line = format!("{}{}", REALMLIST_LINE_PREFIX, host);
37+
/// Updates or adds the realmlist and accountName lines in WTF/Config.wtf.
38+
/// Preserves all other lines.
39+
fn write_realmlist_into_config(
40+
config_path: &std::path::Path,
41+
host: &str,
42+
account_name: Option<&str>,
43+
) -> Result<(), String> {
44+
let new_realmlist = format!("{}{}", REALMLIST_LINE_PREFIX, host);
45+
let new_account = account_name
46+
.filter(|n| !n.is_empty())
47+
.map(|n| format!("SET accountName \"{}\"", n));
48+
49+
let mut had_realmlist = false;
50+
let mut had_account = false;
4051

41-
let (lines, had_realmlist) = if config_path.exists() {
52+
let mut lines: Vec<String> = if config_path.exists() {
4253
let s = std::fs::read_to_string(config_path).map_err(|e| e.to_string())?;
43-
let lines: Vec<String> = s.lines().map(String::from).collect();
44-
let mut had = false;
45-
let updated: Vec<String> = lines
46-
.into_iter()
54+
s.lines()
4755
.map(|line| {
48-
let trimmed = line.trim();
49-
if trimmed.to_uppercase().starts_with("SET REALMLIST ")
50-
|| trimmed.to_uppercase().starts_with("SET PORTAL ")
51-
{
52-
had = true;
53-
new_line.clone()
56+
let upper = line.trim().to_uppercase();
57+
if upper.starts_with("SET REALMLIST ") || upper.starts_with("SET PORTAL ") {
58+
had_realmlist = true;
59+
new_realmlist.clone()
60+
} else if upper.starts_with("SET ACCOUNTNAME ") {
61+
had_account = true;
62+
new_account.clone().unwrap_or_default()
5463
} else {
55-
line
64+
line.to_string()
5665
}
5766
})
58-
.collect();
59-
(updated, had)
67+
.collect()
6068
} else {
61-
(Vec::new(), false)
69+
Vec::new()
6270
};
6371

64-
let mut lines = lines;
6572
if !had_realmlist {
66-
lines.push(new_line);
73+
lines.push(new_realmlist);
6774
}
75+
if !had_account {
76+
if let Some(acct) = &new_account {
77+
lines.push(acct.clone());
78+
}
79+
}
80+
81+
lines.retain(|l| !l.is_empty());
6882

6983
std::fs::create_dir_all(config_path.parent().unwrap_or(Path::new(".")))
7084
.map_err(|e| e.to_string())?;

src-tauri/src/store.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub struct Server {
1313
/// Executable to launch (e.g. Wow.exe). Default: Wow.exe
1414
#[serde(default = "default_wow_exe")]
1515
pub wow_exe: String,
16+
#[serde(default)]
17+
pub account_name: Option<String>,
1618
}
1719

1820
fn default_port() -> u16 {

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface Server {
1010
port: number;
1111
wow_path?: string | null;
1212
wow_exe?: string;
13+
account_name?: string | null;
1314
}
1415

1516
interface ServerList {
@@ -164,6 +165,7 @@ function openServerModal(server: Server | null) {
164165
(document.getElementById("form-name") as HTMLInputElement).value = server?.name ?? "";
165166
(document.getElementById("form-host") as HTMLInputElement).value = server?.realmlist_host ?? "";
166167
(document.getElementById("form-port") as HTMLInputElement).value = server?.port ? String(server.port) : "3724";
168+
(document.getElementById("form-account") as HTMLInputElement).value = server?.account_name ?? "";
167169
(document.getElementById("form-wow-exe") as HTMLInputElement).value = server?.wow_exe?.trim() || "Wow.exe";
168170
(document.getElementById("form-wow-path") as HTMLInputElement).value = server?.wow_path ?? "";
169171
modal.hidden = false;
@@ -180,6 +182,7 @@ async function saveServerFromForm() {
180182
const host = (document.getElementById("form-host") as HTMLInputElement).value.trim();
181183
const portVal = (document.getElementById("form-port") as HTMLInputElement).value.trim();
182184
const port = portVal ? parseInt(portVal, 10) : 3724;
185+
const accountName = (document.getElementById("form-account") as HTMLInputElement).value.trim() || null;
183186
const wowExe = (document.getElementById("form-wow-exe") as HTMLInputElement).value.trim() || "Wow.exe";
184187
const wowPath = (document.getElementById("form-wow-path") as HTMLInputElement).value.trim() || null;
185188

@@ -192,12 +195,12 @@ async function saveServerFromForm() {
192195
if (editingId) {
193196
await invoke("update_server", {
194197
id: editingId,
195-
server: { id: editingId, name, realmlist_host: host, port: port || 3724, wow_path: wowPath, wow_exe: wowExe },
198+
server: { id: editingId, name, realmlist_host: host, port: port || 3724, wow_path: wowPath, wow_exe: wowExe, account_name: accountName },
196199
});
197200
showToast("Server updated.");
198201
} else {
199202
await invoke("add_server", {
200-
server: { id: "", name, realmlist_host: host, port: port || 3724, wow_path: wowPath, wow_exe: wowExe },
203+
server: { id: "", name, realmlist_host: host, port: port || 3724, wow_path: wowPath, wow_exe: wowExe, account_name: accountName },
201204
});
202205
showToast("Server added.");
203206
}

0 commit comments

Comments
 (0)