Merge commit '15d6ce138b9d6a0bb8bc0b70abf1a4c1f522046c'
This commit is contained in:
24
config.json
24
config.json
@@ -1,14 +1,16 @@
|
|||||||
{
|
{
|
||||||
"server_ip": "127.0.0.1",
|
"server_ip": "m.earthvillage.top",
|
||||||
"server_port": "25565",
|
"server_port": "33009",
|
||||||
"proxy_url": "",
|
"username_prefix": "",
|
||||||
"username_prefix": "test",
|
|
||||||
"worker_threads": 100,
|
|
||||||
"use_thread_pool": false,
|
|
||||||
"count": 300,
|
"count": 300,
|
||||||
"reco_words": ["验证程序已启用","AntiAttack"],
|
"proxy_url": "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json",
|
||||||
"login_commands": ["reg helloa helloa"],
|
"reco_words": [
|
||||||
"spam_file": "test.txt",
|
"AntiAttack"
|
||||||
"spam_delay_ms": 1000,
|
],
|
||||||
"random_prefix": true
|
"login_commands": [],
|
||||||
|
"spam_file": "",
|
||||||
|
"spam_delay_ms": 0,
|
||||||
|
"random_prefix": false,
|
||||||
|
"worker_threads": 100,
|
||||||
|
"use_thread_pool": true
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,7 @@ impl<T: StreamType> Bot<T> {
|
|||||||
if !self.config.spam_file().is_empty() && iter % self.config.spam_delay_ms() == 0{
|
if !self.config.spam_file().is_empty() && iter % self.config.spam_delay_ms() == 0{
|
||||||
let mut msg = String::new();
|
let mut msg = String::new();
|
||||||
if self.config.random_prefix(){
|
if self.config.random_prefix(){
|
||||||
msg += &utils::generate_string();
|
msg += &utils::generate_string(2,10);
|
||||||
}
|
}
|
||||||
{ // TODO 优化这里
|
{ // TODO 优化这里
|
||||||
let var = self.var.clone();
|
let var = self.var.clone();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::fs::File;
|
use std::{fs::File, io::BufWriter};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
|
||||||
@@ -41,6 +41,11 @@ impl Configuration {
|
|||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("[MAIN/CONF] Unable to read config file, will use default values: {}", 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()
|
Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +53,7 @@ impl Configuration {
|
|||||||
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Configuration {
|
Configuration {
|
||||||
server_ip: "49.70.3.146".to_string(),
|
server_ip: "m.earthvillage.top".to_string(),
|
||||||
server_port: "33009".to_string(),
|
server_port: "33009".to_string(),
|
||||||
username_prefix: "".to_string(),
|
username_prefix: "".to_string(),
|
||||||
count: 300,
|
count: 300,
|
||||||
@@ -59,7 +64,7 @@ impl Configuration {
|
|||||||
spam_delay_ms: 0,
|
spam_delay_ms: 0,
|
||||||
random_prefix: false,
|
random_prefix: false,
|
||||||
worker_threads: 100,
|
worker_threads: 100,
|
||||||
use_thread_pool: true
|
use_thread_pool: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/main.rs
23
src/main.rs
@@ -35,6 +35,10 @@ async fn main() {
|
|||||||
let configuration = Configuration::new("config.json");
|
let configuration = Configuration::new("config.json");
|
||||||
let configuration_rc = Arc::new(configuration);
|
let configuration_rc = Arc::new(configuration);
|
||||||
let mut spam_file = None;
|
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() {
|
if !configuration_rc.clone().spam_file().is_empty() {
|
||||||
spam_file = Some(tokio::fs::File::open(configuration_rc.clone().spam_file()).await.unwrap());
|
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线程的代码
|
// 插入生成update_worker线程的代码
|
||||||
let mut bot_clone = bot.clone();
|
let mut bot_clone = bot.clone();
|
||||||
let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<u8>();
|
let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<u8>();
|
||||||
if config.use_thread_pool {
|
tokio::spawn(async move {
|
||||||
tokio::spawn(async move {
|
bot_clone.update_worker(rx).await;
|
||||||
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 {
|
match bot.run(tx).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if bot.should_restart() {
|
if bot.should_restart() {
|
||||||
|
|||||||
10
src/utils.rs
10
src/utils.rs
@@ -46,15 +46,17 @@ pub fn parse_json_component(json: &str) -> String {
|
|||||||
|
|
||||||
// 生成一个随机的用户名
|
// 生成一个随机的用户名
|
||||||
// author: 通义
|
// author: 通义
|
||||||
pub fn generate_string() -> String {
|
pub fn generate_string(len_min: i64, len_max: i64) -> String {
|
||||||
let mut rng = rand::thread_rng();
|
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)
|
rng.sample_iter(&Alphanumeric)
|
||||||
.take(len)
|
.take(len as usize)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_username(config: &Arc<Configuration>) -> String {
|
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()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user