Add realitic initial

This commit is contained in:
suprohub 2025-02-25 16:09:14 +04:00
parent dcdc2f544e
commit fe29d292c8
2 changed files with 12 additions and 9 deletions

View File

@ -41,10 +41,12 @@ pub struct Client {
pub connection_reader: Mutex<OwnedReadHalf>, pub connection_reader: Mutex<OwnedReadHalf>,
pub connection_writer: Mutex<OwnedWriteHalf>, pub connection_writer: Mutex<OwnedWriteHalf>,
pub client_packets_queue: Arc<Mutex<VecDeque<RawPacket>>>, pub client_packets_queue: Arc<Mutex<VecDeque<RawPacket>>>,
// Its read-only and not needs AtomicBool
realistic: bool
} }
impl Client { impl Client {
pub fn new(stream: TcpStream) -> Self { pub fn new(stream: TcpStream, realistic: bool) -> Self {
let (connection_reader, connection_writer) = stream.into_split(); let (connection_reader, connection_writer) = stream.into_split();
Self { Self {
connection_state: AtomicCell::new(ConnectionState::HandShake), connection_state: AtomicCell::new(ConnectionState::HandShake),
@ -54,6 +56,7 @@ impl Client {
connection_reader: Mutex::new(connection_reader), connection_reader: Mutex::new(connection_reader),
connection_writer: Mutex::new(connection_writer), connection_writer: Mutex::new(connection_writer),
client_packets_queue: Arc::new(Mutex::new(VecDeque::new())), client_packets_queue: Arc::new(Mutex::new(VecDeque::new())),
realistic,
} }
} }

View File

@ -10,35 +10,35 @@ mod client;
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
struct Args { struct Args {
#[arg(short, long)] #[arg(short, long)]
ip: String, address: Arc<String>,
#[arg(short, long, default_value_t = 25565)] #[arg(short, long, default_value_t = 25565)]
port: u16, port: u16,
#[arg(short, long, default_value_t = 1)] #[arg(short, long, default_value_t = 1)]
count: u32, count: u32,
#[arg(short, long, default_value_t = false)]
realistic: bool,
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap(); simple_logger::init_with_level(log::Level::Info).unwrap();
let args = Args::parse(); 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)); let counter = Arc::new(AtomicUsize::new(0));
for _ in 0..args.count { for _ in 0..args.count {
let counter = counter.clone(); let counter = counter.clone();
let address = address.clone(); let address = args.address.clone();
tokio::spawn(async move { 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 .await
.expect("Failed to connect to Ip"); .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); 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); log::info!("{}/{} Bots Joined", i + 1, args.count);
loop { loop {