From d7f400f682bf9133af265262cf7858b745496f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 16 Mar 2021 18:45:38 +0100 Subject: [PATCH] bots: add option to join the world via ingame cmd --- client/src/bin/bot/main.rs | 39 ++++++++++++++++++++++++++++++++++++++ client/src/bin/bot/tui.rs | 12 +++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/client/src/bin/bot/main.rs b/client/src/bin/bot/main.rs index 5882a03ba6..95ad2e2ad2 100644 --- a/client/src/bin/bot/main.rs +++ b/client/src/bin/bot/main.rs @@ -103,6 +103,7 @@ impl BotClient { count, } => self.handle_register(&prefix, &password, count), Cmd::Login { prefix } => self.handle_login(&prefix), + Cmd::InGame { prefix } => self.handle_ingame_join(&prefix), } } @@ -199,9 +200,47 @@ impl BotClient { Some("common.items.weapons.sword.starter".to_string()), body.into(), ); + client.load_character_list(); //client.create_character(cred.username.clone(), // Some("common.items.debug.admin_stick".to_string()), body.into()); } info!("login done"); } + + + pub fn handle_ingame_join(&mut self, prefix: &str) { + let creds: Vec<_> = self + .settings + .bot_logins + .iter() + .filter(|x| x.username.starts_with(prefix)) + .cloned() + .collect(); + for cred in creds.iter() { + let runtime = Arc::clone(&self.runtime); + + let server = self.settings.server.clone(); + let client = match self + .bot_clients + .get_mut(&cred.username) { + Some(c) => c, + None => { + tracing::trace!(?cred.username, "skip not logged in client"); + continue + }, + }; + + let list = client.character_list(); + if list.loading || list.characters.is_empty() { + tracing::trace!(?cred.username, "skip client as it has no character"); + continue; + } + + let c = list.characters.get(0).unwrap(); + if let Some(id) = c.character.id { + client.request_character(id); + } + } + info!("ingame done"); + } } diff --git a/client/src/bin/bot/tui.rs b/client/src/bin/bot/tui.rs index 98ed6c4102..7f77e80754 100644 --- a/client/src/bin/bot/tui.rs +++ b/client/src/bin/bot/tui.rs @@ -26,6 +26,9 @@ pub enum Cmd { Login { prefix: String, }, + InGame { + prefix: String, + } } pub struct Tui { @@ -76,7 +79,11 @@ impl Tui { .about("Login all registered bots whose username starts with a prefix") .args(&[Arg::with_name("prefix").required(true)]), ) - .subcommand(SubCommand::with_name("tick").about("Handle ticks for all logged in bots")) + .subcommand( + SubCommand::with_name("ingame") + .about("Join the world with some random character") + .args(&[Arg::with_name("prefix").required(true)]), + ) .get_matches_from_safe(cmd.split(" ")); use clap::ErrorKind::*; match matches { @@ -92,6 +99,9 @@ impl Tui { ("login", Some(matches)) => command_s.try_send(Cmd::Login { prefix: matches.value_of("prefix").unwrap().to_string(), }), + ("ingame", Some(matches)) => command_s.try_send(Cmd::InGame { + prefix: matches.value_of("prefix").unwrap().to_string(), + }), _ => Ok(()), } .is_err()