Custom races off: count the characters kept out, delete their companion bots

A client without the races patch crashes on a unit of race 12+, so the server now keeps
those characters out while custom races are off. The Custom Races card shows how many
player characters and bots that are (active realm, read only while the database runs) and
offers botcmd purgecustomraces for the companion bots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Opus 5.5 committed 2026-11-16 00:36:18 +05:00
1 parent 2fd42f2acd
commit f9839ba369
13 files changed
+121 -1

No files matched your search

+40
View File
@@ -515,6 +515,46 @@ fn is_switched(client: &Path, file: &PatchFile) -> bool {
entry_point || suffix(&client.join(&file.path), "original").is_file()
}
/// Characters of custom races (RaceID above 11) on the active realm: a game client without the client patch
/// crashes when one of them comes into view, so the server keeps them out of the world while custom races are
/// off. `None` when the database is not running.
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct CustomRaceCharacters {
pub players: u32,
pub companion_bots: u32,
pub squid_bots: u32,
}
pub fn custom_race_characters(root: &Path) -> Result<Option<CustomRaceCharacters>> {
let squid = crate::accounts::squid_bot_prefix(root);
let characters = crate::realms::state(root)
.map(|s| s.active)
.unwrap_or_default()
.schema("characters")?;
crate::backup::with_running_database(root, |db| {
let out = db.query(&format!(
"SELECT \
IFNULL(SUM(a.username NOT LIKE 'COABOTHOST%' AND a.username NOT LIKE '{squid}%'), 0), \
IFNULL(SUM(a.username LIKE 'COABOTHOST%'), 0), \
IFNULL(SUM(a.username LIKE '{squid}%'), 0) \
FROM {characters}.characters c JOIN acore_auth.account a ON a.id = c.account WHERE c.race > 11;"
))?;
let numbers: Vec<u32> = out
.lines()
.last()
.unwrap_or("")
.split('\t')
.map(|n| n.trim().parse().unwrap_or(0))
.collect();
Ok(CustomRaceCharacters {
players: numbers.first().copied().unwrap_or(0),
companion_bots: numbers.get(1).copied().unwrap_or(0),
squid_bots: numbers.get(2).copied().unwrap_or(0),
})
})
}
/// Only complete, verified payloads are reported as enabled or disabled.
pub fn client_patch_status(client_path: &Path) -> ClientPatchStatus {
let data = client_path.join("Data");
+5
View File
@@ -258,6 +258,11 @@ impl Ra {
Ok(out.lines().last().unwrap_or("").to_string())
}
/// Delete the companion bots of custom races (RaceID above 11), every other bot stays. Returns how many.
pub fn purge_custom_race_bots(&mut self) -> Result<u32> {
Ok(first_number(&self.bot_command("botcmd purgecustomraces")?))
}
/// Ask the bot module to create `count` leveling bots (throttled by the module itself). Only a number is sent.
pub fn spawn_bots(&mut self, count: u32) -> Result<String> {
if !(1..=2000).contains(&count) {