mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-22 19:25:56 +00:00
Companions: stop creating, take all offline, delete all (with a recovery point); bot module gets spawncancel and despawnall
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dd066f2094
commit
8686990a30
10 files changed
+222
No files matched your search
@@ -26,6 +26,8 @@ pub enum Error {
|
||||
NetworkUnreachable(String),
|
||||
#[error("the bot module found no level 80 template characters")]
|
||||
CompanionTemplatesMissing,
|
||||
#[error("this server's bot module does not have that command yet")]
|
||||
CompanionCommandUnsupported,
|
||||
#[error("invalid values: {}", .0.iter().map(|f| format!("{}: {}", f.key, f.message)).collect::<Vec<_>>().join("; "))]
|
||||
Validation(Vec<FieldError>),
|
||||
}
|
||||
@@ -55,6 +57,7 @@ pub enum ErrorCode {
|
||||
PackageNotPublished,
|
||||
NetworkUnreachable,
|
||||
CompanionTemplatesMissing,
|
||||
CompanionCommandUnsupported,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
@@ -150,6 +153,11 @@ impl ErrorCode {
|
||||
"New companions are copied from level 80 characters of each class. Create one level 80 character per class on any account except the console account, then try again.",
|
||||
&[ShowDetails],
|
||||
),
|
||||
ErrorCode::CompanionCommandUnsupported => (
|
||||
"This server version can not do that yet",
|
||||
"The bot module of this server build has no such command. Update the server, or restart it to stop what is running.",
|
||||
&[ShowDetails],
|
||||
),
|
||||
ErrorCode::Unknown => ("Something went wrong", "See the technical details.", &[ShowDetails]),
|
||||
};
|
||||
Human { code: self, title, message, actions }
|
||||
@@ -166,6 +174,7 @@ impl Error {
|
||||
Error::PackageNotPublished(_) => ErrorCode::PackageNotPublished,
|
||||
Error::NetworkUnreachable(_) => ErrorCode::NetworkUnreachable,
|
||||
Error::CompanionTemplatesMissing => ErrorCode::CompanionTemplatesMissing,
|
||||
Error::CompanionCommandUnsupported => ErrorCode::CompanionCommandUnsupported,
|
||||
_ => ErrorCode::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,30 @@ impl Ra {
|
||||
Ok(parse_server_info(&out))
|
||||
}
|
||||
|
||||
fn bot_command(&mut self, cmd: &str) -> Result<String> {
|
||||
let out = self.command(cmd)?;
|
||||
if is_unsupported_command(&out) {
|
||||
return Err(Error::CompanionCommandUnsupported);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Drop every bot still waiting to be created. Returns how many were waiting.
|
||||
pub fn cancel_spawning(&mut self) -> Result<u32> {
|
||||
Ok(first_number(&self.bot_command("botcmd spawncancel")?))
|
||||
}
|
||||
|
||||
/// Log every bot out without deleting anything. Returns how many were online.
|
||||
pub fn despawn_all(&mut self) -> Result<u32> {
|
||||
Ok(first_number(&self.bot_command("botcmd despawnall")?))
|
||||
}
|
||||
|
||||
/// Log every bot out and delete every bot character for good (the caller saves a recovery point first).
|
||||
pub fn purge_all(&mut self) -> Result<String> {
|
||||
let out = self.bot_command("botcmd purgeall")?;
|
||||
Ok(out.lines().last().unwrap_or("").to_string())
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
@@ -121,6 +145,16 @@ impl Ra {
|
||||
}
|
||||
}
|
||||
|
||||
/// The console answers an unknown sub-command with the list of the ones it knows.
|
||||
fn is_unsupported_command(out: &str) -> bool {
|
||||
let l = out.to_lowercase();
|
||||
l.contains("possible subcommands") || l.contains("### usage") || l.contains("no such command") || l.contains("unknown command")
|
||||
}
|
||||
|
||||
fn first_number(text: &str) -> u32 {
|
||||
text.split(|c: char| !c.is_ascii_digit()).find(|t| !t.is_empty()).and_then(|t| t.parse().ok()).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// How fast the world loop is running, read from `server info`.
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
pub struct Performance {
|
||||
@@ -213,6 +247,16 @@ mod tests {
|
||||
(port, h)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_bot_subcommand_is_recognised_and_numbers_are_read_from_replies() {
|
||||
assert!(is_unsupported_command("### USAGE: .botcmd ...
|
||||
Possible subcommands:
|
||||
|- botcmd despawn"));
|
||||
assert!(!is_unsupported_command("BotMgr: cancelled 35 queued bot spawn(s)."));
|
||||
assert_eq!(first_number("BotMgr: cancelled 35 queued bot spawn(s)."), 35);
|
||||
assert_eq!(first_number("nothing"), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn server_info_timing_is_parsed_and_unrelated_text_is_ignored() {
|
||||
let text = "AzerothCore rev. x
|
||||
|
||||
Reference in new issue
Block a user