mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'xMAC94x/bots' into 'master'
bots: add option to join the world via ingame cmd See merge request veloren/veloren!1923
This commit is contained in:
@ -103,6 +103,7 @@ impl BotClient {
|
|||||||
count,
|
count,
|
||||||
} => self.handle_register(&prefix, &password, count),
|
} => self.handle_register(&prefix, &password, count),
|
||||||
Cmd::Login { prefix } => self.handle_login(&prefix),
|
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()),
|
Some("common.items.weapons.sword.starter".to_string()),
|
||||||
body.into(),
|
body.into(),
|
||||||
);
|
);
|
||||||
|
client.load_character_list();
|
||||||
//client.create_character(cred.username.clone(),
|
//client.create_character(cred.username.clone(),
|
||||||
// Some("common.items.debug.admin_stick".to_string()), body.into());
|
// Some("common.items.debug.admin_stick".to_string()), body.into());
|
||||||
}
|
}
|
||||||
info!("login done");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ pub enum Cmd {
|
|||||||
Login {
|
Login {
|
||||||
prefix: String,
|
prefix: String,
|
||||||
},
|
},
|
||||||
|
InGame {
|
||||||
|
prefix: String,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Tui {
|
pub struct Tui {
|
||||||
@ -76,7 +79,11 @@ impl Tui {
|
|||||||
.about("Login all registered bots whose username starts with a prefix")
|
.about("Login all registered bots whose username starts with a prefix")
|
||||||
.args(&[Arg::with_name("prefix").required(true)]),
|
.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(" "));
|
.get_matches_from_safe(cmd.split(" "));
|
||||||
use clap::ErrorKind::*;
|
use clap::ErrorKind::*;
|
||||||
match matches {
|
match matches {
|
||||||
@ -92,6 +99,9 @@ impl Tui {
|
|||||||
("login", Some(matches)) => command_s.try_send(Cmd::Login {
|
("login", Some(matches)) => command_s.try_send(Cmd::Login {
|
||||||
prefix: matches.value_of("prefix").unwrap().to_string(),
|
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(()),
|
_ => Ok(()),
|
||||||
}
|
}
|
||||||
.is_err()
|
.is_err()
|
||||||
|
Reference in New Issue
Block a user