From b170844fc4bc016e6fd8e33d8c832603cbeb5c69 Mon Sep 17 00:00:00 2001 From: Zihaoxu2008 Date: Sat, 25 Jan 2025 19:54:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BA=BF=E7=A8=8B=E6=B1=A0?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=BA=BF=E7=A8=8B=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?worker=5Fthreads=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 1 + src/configuration.rs | 2 ++ src/main.rs | 39 ++++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/config.json b/config.json index 7b3323d..b571202 100644 --- a/config.json +++ b/config.json @@ -3,6 +3,7 @@ "server_port": "25565", "proxy_url": "", "username_prefix": "test", + "worker_threads": 100, "count": 300, "reco_words": ["验证程序已启用","AntiAttack"], "login_commands": ["reg helloa helloa"], diff --git a/src/configuration.rs b/src/configuration.rs index 6becb51..1a76988 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -14,6 +14,7 @@ pub struct Configuration { spam_file: String, spam_delay_ms: i32, random_prefix: bool, + pub worker_threads: i32 } impl Configuration { @@ -56,6 +57,7 @@ impl Configuration { spam_file: "".to_string(), spam_delay_ms: 0, random_prefix: false, + worker_threads: 100 } } diff --git a/src/main.rs b/src/main.rs index cbefd43..77cb15a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use reqwest; use serde_json::Value; // use tokio::task; use std::sync::Arc; -use std::thread; +// use std::thread; use tokio::sync::Mutex; use crate::utils::generate_username; use crate::configuration::Configuration; @@ -43,12 +43,12 @@ async fn main() { spam_cursor: Arc::new(Mutex::new(0)) }); - // let rt = tokio::runtime::Builder::new_multi_thread() - // .enable_all() - // .thread_stack_size(8 * 1024 * 1024) - // .worker_threads((configuration_rc.count()-1) as usize) - // .build() - // .unwrap(); + let rt = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .thread_stack_size(8 * 1024 * 1024) + .worker_threads(configuration_rc.worker_threads as usize) + .build() + .unwrap(); for _ in 0..configuration_rc.count() -1 { let lock_clone = thread_lock.clone(); @@ -59,18 +59,19 @@ async fn main() { // println!("[MAIN] Thread {} created", i); // }); // 生成一个线程 - // let handle = rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone)); - let handle = thread::spawn(move || { - tokio::runtime::Builder::new_current_thread() - .enable_all() - .thread_stack_size(8 * 1024 * 1024) - .build() - .unwrap() - .block_on(async move { - attack_thread(lock_clone,configuration_rc_clone,variables_clone).await; - // println!("[MAIN] Thread {} created", i); - }); - }); + // let handle = tokio::task::spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone)); + let handle = rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone)); + // let handle = thread::spawn(move || { + // tokio::runtime::Builder::new_current_thread() + // .enable_all() + // .thread_stack_size(8 * 1024 * 1024) + // .build() + // .unwrap() + // .block_on(async move { + // attack_thread(lock_clone,configuration_rc_clone,variables_clone).await; + // // println!("[MAIN] Thread {} created", i); + // }); + //}); handles.push(handle); // println!("[MAIN] Thread {} created", i) // 这个太吵了( }