diff --git a/src/client.rs b/src/client.rs index cefe23f..f37c30e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -41,10 +41,12 @@ pub struct Client { pub connection_reader: Mutex, pub connection_writer: Mutex, pub client_packets_queue: Arc>>, + // Its read-only and not needs AtomicBool + realistic: bool } impl Client { - pub fn new(stream: TcpStream) -> Self { + pub fn new(stream: TcpStream, realistic: bool) -> Self { let (connection_reader, connection_writer) = stream.into_split(); Self { connection_state: AtomicCell::new(ConnectionState::HandShake), @@ -54,6 +56,7 @@ impl Client { connection_reader: Mutex::new(connection_reader), connection_writer: Mutex::new(connection_writer), client_packets_queue: Arc::new(Mutex::new(VecDeque::new())), + realistic, } } diff --git a/src/main.rs b/src/main.rs index a2f1593..f305b90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,35 +10,35 @@ mod client; #[command(version, about, long_about = None)] struct Args { #[arg(short, long)] - ip: String, + address: Arc, #[arg(short, long, default_value_t = 25565)] port: u16, #[arg(short, long, default_value_t = 1)] count: u32, + #[arg(short, long, default_value_t = false)] + realistic: bool, } #[tokio::main] async fn main() { simple_logger::init_with_level(log::Level::Info).unwrap(); let args = Args::parse(); - let address = Arc::new(args.ip); - let port = args.port; - log::info!("{} Bots will Join {}", args.count, address); + log::info!("{} Bots will Join {}", args.count, args.address); let counter = Arc::new(AtomicUsize::new(0)); for _ in 0..args.count { let counter = counter.clone(); - let address = address.clone(); + let address = args.address.clone(); tokio::spawn(async move { - let stream = TcpStream::connect(address.to_string() + ":" + &port.to_string()) + let stream = TcpStream::connect(address.to_string() + ":" + &args.port.to_string()) .await .expect("Failed to connect to Ip"); - let client = Client::new(stream); + let client = Client::new(stream, args.realistic); let i = counter.fetch_add(1, Ordering::Relaxed); - client.join_server(address.to_string(), port, format!("BOT_{i}")).await; + client.join_server(address.to_string(), args.port, format!("BOT_{i}")).await; log::info!("{}/{} Bots Joined", i + 1, args.count); loop {