mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
feat(manager): multi-realm character database routing, RA dispatch & extended bot manager UI
This commit is contained in:
1 parent
ca2514c790
commit
e4edb7cbdd
5 files changed
+203
-92
No files matched your search
@@ -97,6 +97,58 @@ pub fn world_root(main: &Path, mode: Mode) -> PathBuf {
|
||||
.map_or_else(|| main.to_path_buf(), |t| tree_root(main, t))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BotOperationTarget {
|
||||
pub world_root: PathBuf,
|
||||
pub chars_db: &'static str,
|
||||
pub ra_port: u16,
|
||||
pub running: bool,
|
||||
pub realm: Mode,
|
||||
}
|
||||
|
||||
pub fn resolve_bot_operation_target(main: &Path, realm: Mode) -> Result<BotOperationTarget> {
|
||||
let state = realms::state(main)?;
|
||||
let chars_db = realm.schema("characters")?;
|
||||
|
||||
if realm == state.active {
|
||||
let ports = crate::layout::read_ports(main);
|
||||
let ra_port = ports.ra;
|
||||
let status = process::observe(main, &ports);
|
||||
let running = status.world.state != ServiceState::Stopped;
|
||||
return Ok(BotOperationTarget {
|
||||
world_root: main.to_path_buf(),
|
||||
chars_db,
|
||||
ra_port,
|
||||
running,
|
||||
realm,
|
||||
});
|
||||
}
|
||||
|
||||
let tree = Tree::ALL
|
||||
.into_iter()
|
||||
.find(|t| t.enabled(&state) && t.mode(state.active) == realm)
|
||||
.ok_or_else(|| Error::Invalid(format!("Realm {} is not enabled in multiworld configuration.", realm.label())))?;
|
||||
|
||||
let root = tree_root(main, tree);
|
||||
if !root.exists() {
|
||||
return Err(Error::Invalid(format!("Multiworld directory for {} does not exist: {}", realm.label(), root.display())));
|
||||
}
|
||||
|
||||
let ports = crate::layout::read_ports(&root);
|
||||
let (_, default_ra) = tree.ports(&state);
|
||||
let ra_port = if ports.ra != 0 { ports.ra } else { default_ra.unwrap_or(3444) };
|
||||
let status = process::observe(&root, &ports);
|
||||
let running = status.world.state != ServiceState::Stopped;
|
||||
|
||||
Ok(BotOperationTarget {
|
||||
world_root: root,
|
||||
chars_db,
|
||||
ra_port,
|
||||
running,
|
||||
realm,
|
||||
})
|
||||
}
|
||||
|
||||
/// Any of the extra worlds is running or still stopping.
|
||||
pub fn is_running(main: &Path) -> bool {
|
||||
Tree::ALL.into_iter().any(|t| tree_running(main, t))
|
||||
|
||||
@@ -58,6 +58,23 @@ impl Ra {
|
||||
Self::connect_to(read_ports(root).ra, &cfg.ra_username, &cfg.ra_password)
|
||||
}
|
||||
|
||||
/// Connect to the loopback RA port of the target realm world server.
|
||||
pub fn connect_target(main: &Path, realm: Option<crate::realms::Mode>) -> Result<Ra> {
|
||||
let mode = realm.unwrap_or_else(|| {
|
||||
crate::realms::view(main).map(|v| v.active).unwrap_or_default()
|
||||
});
|
||||
let target = crate::multiworld::resolve_bot_operation_target(main, mode)?;
|
||||
if !target.running {
|
||||
return Err(Error::Invalid(format!(
|
||||
"Realm {} worldserver is stopped; cannot execute online bot operation.",
|
||||
target.realm.label()
|
||||
)));
|
||||
}
|
||||
let cfg: RaSettings = fsx::read_json(&main.join("Settings/repack.json"))
|
||||
.map_err(|_| Error::Invalid("The server console settings could not be read.".into()))?;
|
||||
Self::connect_to(target.ra_port, &cfg.ra_username, &cfg.ra_password)
|
||||
}
|
||||
|
||||
pub fn connect_to(port: u16, user: &str, password: &str) -> Result<Ra> {
|
||||
let addr: SocketAddr = ([127, 0, 0, 1], port).into();
|
||||
let mut stream =
|
||||
@@ -278,6 +295,30 @@ impl Ra {
|
||||
Ok(out.lines().last().unwrap_or("").to_string())
|
||||
}
|
||||
|
||||
pub fn spawn_custom(
|
||||
&mut self,
|
||||
count: u32,
|
||||
level: u8,
|
||||
class_id: Option<u8>,
|
||||
spec_id: Option<u32>,
|
||||
archetype: Option<&str>,
|
||||
) -> Result<String> {
|
||||
let mut cmd = format!("botcmd spawncustom {count} {level}");
|
||||
if let Some(c) = class_id {
|
||||
cmd.push_str(&format!(" {c}"));
|
||||
if let Some(s) = spec_id {
|
||||
cmd.push_str(&format!(" {s}"));
|
||||
if let Some(a) = archetype {
|
||||
if !a.is_empty() {
|
||||
cmd.push_str(&format!(" {a}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let out = self.bot_command(&cmd)?;
|
||||
Ok(out.lines().last().unwrap_or("").to_string())
|
||||
}
|
||||
|
||||
/// Bring all offline bots online gradually (.botcmd loginall).
|
||||
pub fn login_all(&mut self) -> Result<String> {
|
||||
let out = self.bot_command("botcmd loginall")?;
|
||||
|
||||
Reference in new issue
Block a user