mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
move botclient to client/src/bin/bot
start it with: - (cd client && RUST_BACKTRACE=full RUST_LOG=trace VELOREN_USERDATA_STRATEGY=executable cargo run --bin bot --features="bin_bot")
This commit is contained in:
parent
7301182695
commit
e001b2cac2
32
Cargo.lock
generated
32
Cargo.lock
generated
@ -5522,48 +5522,32 @@ dependencies = [
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-botclient"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"authc",
|
||||
"clap",
|
||||
"hashbrown",
|
||||
"ron",
|
||||
"rustyline",
|
||||
"serde",
|
||||
"termcolor",
|
||||
"tokio 1.3.0",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-log",
|
||||
"tracing-subscriber",
|
||||
"veloren-client",
|
||||
"veloren-common",
|
||||
"veloren-common-base",
|
||||
"veloren-common-ecs",
|
||||
"veloren-common-net",
|
||||
"veloren-common-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-client"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"authc",
|
||||
"byteorder",
|
||||
"clap",
|
||||
"futures-util",
|
||||
"hashbrown",
|
||||
"image",
|
||||
"num 0.4.0",
|
||||
"rayon",
|
||||
"ron",
|
||||
"rustyline",
|
||||
"serde",
|
||||
"specs",
|
||||
"termcolor",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-log",
|
||||
"tracing-subscriber",
|
||||
"vek 0.14.1",
|
||||
"veloren-common",
|
||||
"veloren-common-base",
|
||||
"veloren-common-ecs",
|
||||
"veloren-common-net",
|
||||
"veloren-common-sys",
|
||||
"veloren-network",
|
||||
|
@ -8,7 +8,6 @@ members = [
|
||||
"common/net",
|
||||
"common/sys",
|
||||
"client",
|
||||
"botclient",
|
||||
"plugin/api",
|
||||
"plugin/derive",
|
||||
"plugin/rt",
|
||||
|
@ -1,29 +0,0 @@
|
||||
[package]
|
||||
authors = ["Avi Weinstock <aweinstock314@gmail.com>"]
|
||||
edition = "2018"
|
||||
name = "veloren-botclient"
|
||||
version = "0.8.0"
|
||||
|
||||
[dependencies]
|
||||
authc = { git = "https://gitlab.com/veloren/auth.git", rev = "bffb5181a35c19ddfd33ee0b4aedba741aafb68d" }
|
||||
client = { package = "veloren-client", path = "../client" }
|
||||
common = { package = "veloren-common", path = "../common", features = ["no-assets"] }
|
||||
common-base = { package = "veloren-common-base", path = "../common/base" }
|
||||
common-ecs = {package = "veloren-common-ecs", path = "../common/ecs"}
|
||||
common-net = { package = "veloren-common-net", path = "../common/net" }
|
||||
common-sys = { package = "veloren-common-sys", path = "../common/sys", default-features = false }
|
||||
|
||||
hashbrown = {version = "0.9", features = ["rayon", "serde", "nightly"]}
|
||||
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
|
||||
serde = {version = "1.0", features = [ "rc", "derive" ]}
|
||||
ron = {version = "0.6", default-features = false}
|
||||
|
||||
clap = "2.33"
|
||||
rustyline = "8.0.0"
|
||||
|
||||
# logging
|
||||
termcolor = "1.1"
|
||||
tracing = "0.1"
|
||||
tracing-appender = "0.1"
|
||||
tracing-log = "0.1.1"
|
||||
tracing-subscriber = {version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "tracing-log"]}
|
@ -7,6 +7,7 @@ edition = "2018"
|
||||
[features]
|
||||
simd = ["vek/platform_intrinsics"]
|
||||
plugins = ["common-sys/plugins"]
|
||||
bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "termcolor", "tracing-appender", "tracing-log", "tracing-subscriber"]
|
||||
|
||||
default = ["simd"]
|
||||
|
||||
@ -29,8 +30,25 @@ vek = { version = "=0.14.1", features = ["serde"] }
|
||||
hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] }
|
||||
authc = { git = "https://gitlab.com/veloren/auth.git", rev = "fb3dcbc4962b367253f8f2f92760ef44d2679c9a" }
|
||||
|
||||
#bot only
|
||||
common-ecs = { package = "veloren-common-ecs", path = "../common/ecs", optional = true }
|
||||
serde = { version = "1.0", features = [ "rc", "derive" ], optional = true }
|
||||
ron = { version = "0.6", default-features = false, optional = true }
|
||||
clap = { version = "2.33", optional = true }
|
||||
rustyline = { version = "8.0.0", optional = true }
|
||||
## logging
|
||||
termcolor = { version = "1.1", optional = true }
|
||||
tracing-appender = { version = "0.1", optional = true }
|
||||
tracing-log = { version = "0.1.1", optional = true }
|
||||
tracing-subscriber = {version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "tracing-log"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] }
|
||||
|
||||
[[example]]
|
||||
name = "chat-cli"
|
||||
|
||||
[[bin]]
|
||||
name = "bot"
|
||||
#authors = ["Avi Weinstock <aweinstock314@gmail.com>"]
|
||||
required-features = ["bin_bot"]
|
||||
|
@ -1,18 +1,16 @@
|
||||
#![feature(str_split_once)]
|
||||
|
||||
#[macro_use] extern crate serde;
|
||||
|
||||
use authc::AuthClient;
|
||||
use clap::{App, AppSettings, Arg, SubCommand};
|
||||
use client::{addr::ConnectionArgs, Client};
|
||||
use common::{
|
||||
comp,
|
||||
clock::Clock,
|
||||
};
|
||||
use common::{clock::Clock, comp};
|
||||
use hashbrown::HashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tokio::runtime::Runtime;
|
||||
use tracing::{error, info, warn};
|
||||
use veloren_client::{addr::ConnectionArgs, Client};
|
||||
|
||||
mod settings;
|
||||
|
||||
@ -122,10 +120,7 @@ impl BotClient {
|
||||
.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("tick").about("Handle ticks for all logged in bots"))
|
||||
.get_matches_from_safe(cmd.split(" "));
|
||||
use clap::ErrorKind::*;
|
||||
match matches {
|
||||
@ -164,7 +159,15 @@ impl BotClient {
|
||||
};
|
||||
info!("usernames: {:?}", usernames);
|
||||
if let Some(auth_addr) = self.menu_client.server_info().auth_provider.as_ref() {
|
||||
let authc = AuthClient::new(&*auth_addr).expect("couldn't connect to auth_addr");
|
||||
let (scheme, authority) = auth_addr.split_once("://").expect("invalid auth url");
|
||||
let scheme = scheme
|
||||
.parse::<authc::Scheme>()
|
||||
.expect("invalid auth url scheme");
|
||||
let authority = authority
|
||||
.parse::<authc::Authority>()
|
||||
.expect("invalid auth url authority");
|
||||
|
||||
let authc = AuthClient::new(scheme, authority).expect("couldn't connect to , insecure");
|
||||
for username in usernames.iter() {
|
||||
if self
|
||||
.settings
|
||||
@ -174,7 +177,7 @@ impl BotClient {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
match authc.register(username, password) {
|
||||
match self.runtime.block_on(authc.register(username, password)) {
|
||||
Ok(()) => {
|
||||
self.settings.bot_logins.push(BotCreds {
|
||||
username: username.to_string(),
|
||||
@ -196,16 +199,28 @@ impl BotClient {
|
||||
pub fn client_for_bot(&mut self, username: &str) -> &mut Client {
|
||||
let runtime = Arc::clone(&self.runtime);
|
||||
let server = self.settings.server.clone();
|
||||
self.bot_clients.entry(username.to_string()).or_insert_with(|| make_client(&runtime, &server))
|
||||
self.bot_clients
|
||||
.entry(username.to_string())
|
||||
.or_insert_with(|| make_client(&runtime, &server))
|
||||
}
|
||||
|
||||
pub fn handle_login(&mut self, prefix: &str) {
|
||||
let creds: Vec<_> = self.settings.bot_logins.iter().filter(|x| x.username.starts_with(prefix)).cloned().collect();
|
||||
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 client = self.client_for_bot(&cred.username);
|
||||
// TODO: log the clients in in parallel instead of in series
|
||||
if let Err(e) = runtime.block_on(client.register(cred.username.clone(), cred.password.clone(), |_| true)) {
|
||||
if let Err(e) = runtime.block_on(client.register(
|
||||
cred.username.clone(),
|
||||
cred.password.clone(),
|
||||
|_| true,
|
||||
)) {
|
||||
warn!("error logging in {:?}: {:?}", cred.username, e);
|
||||
}
|
||||
/*let body = comp::body::biped_large::Body {
|
||||
@ -223,8 +238,13 @@ impl BotClient {
|
||||
skin: 0,
|
||||
eye_color: 0,
|
||||
};
|
||||
client.create_character(cred.username.clone(), Some("common.items.weapons.sword.starter".to_string()), body.into());
|
||||
//client.create_character(cred.username.clone(), Some("common.items.debug.admin_stick".to_string()), body.into());
|
||||
client.create_character(
|
||||
cred.username.clone(),
|
||||
Some("common.items.weapons.sword.starter".to_string()),
|
||||
body.into(),
|
||||
);
|
||||
//client.create_character(cred.username.clone(),
|
||||
// Some("common.items.debug.admin_stick".to_string()), body.into());
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,9 +253,14 @@ impl BotClient {
|
||||
self.clock.tick();
|
||||
for (username, client) in self.bot_clients.iter_mut() {
|
||||
info!("cl {:?}: {:?}", username, client.character_list());
|
||||
let msgs: Result<Vec<client::Event>, client::Error> =
|
||||
let msgs: Result<Vec<veloren_client::Event>, veloren_client::Error> =
|
||||
client.tick(comp::ControllerInputs::default(), self.clock.dt(), |_| {});
|
||||
info!("msgs {:?}: {:?} {:?}", username, msgs, client.character_list());
|
||||
info!(
|
||||
"msgs {:?}: {:?} {:?}",
|
||||
username,
|
||||
msgs,
|
||||
client.character_list()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user