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) // 这个太吵了( }