让代码变得好看,允许玩家自定生成的用户名长度(随机字母部分)

This commit is contained in:
2025-01-26 16:01:40 +08:00
parent 347ec4590d
commit 5d3cb90d4a
4 changed files with 5 additions and 73 deletions

View File

@@ -20,31 +20,11 @@ pub struct BotMessage {
pub last_keepalive_sec: u64, pub last_keepalive_sec: u64,
} }
// impl Clone for BotVariable {
// fn clone(&self) -> Self {
// Self { spam_file: self.spam_file.clone() }
// }
// }
// 定义一个StreamType的特性,要求实现Read和Write,且含有connect函数 // 定义一个StreamType的特性,要求实现Read和Write,且含有connect函数
pub trait StreamType: Read + Write { pub trait StreamType: Read + Write {
fn connect(server_addr: &str,proxy_addr: &str) -> Result<Self, Error> where Self: Sized; fn connect(server_addr: &str,proxy_addr: &str) -> Result<Self, Error> where Self: Sized;
} }
// *由于下面的Stream已经实现过connect了,所以这里没必要重复一遍
// // 然后让Socks5Stream实现StreamType
// impl StreamType for Socks5Stream{
// fn connect(server_addr: &str,proxy_addr: &str) -> Result<Self, Error> where Self: Sized {
// return Socks5Stream::connect(proxy_addr, server_addr);
// }
// }
// // 再让TcpStream实现StreamType
// impl StreamType for TcpStream {
// fn connect(server_addr: &str,_: &str) -> Result<Self, Error> where Self: Sized {
// return TcpStream::connect(server_addr);
// }
// }
// Bot泛型版 // Bot泛型版
pub struct Bot<T: StreamType> { pub struct Bot<T: StreamType> {
pub username: String, pub username: String,
@@ -307,7 +287,7 @@ impl<T: StreamType> Bot<T> {
&& !login_command_flag { // 登录3s后且未执行过登录命令 && !login_command_flag { // 登录3s后且未执行过登录命令
let commands = self.config.login_commands().clone(); let commands = self.config.login_commands().clone();
for i in commands{ for i in commands{
self.send_command(i.to_string()).await.unwrap(); self.send_command(i.to_string()).await.unwrap_or(());
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(1));
} }
info!("[{}/WORKER] Login commands executed!",self.username); info!("[{}/WORKER] Login commands executed!",self.username);

View File

@@ -8,6 +8,7 @@ pub struct Configuration {
server_ip: String, server_ip: String,
server_port: String, server_port: String,
username_prefix: String, username_prefix: String,
pub name_len_limit: Vec<i64>,
count: i32, count: i32,
proxy_url: String, proxy_url: String,
reco_words: Vec<String>, reco_words: Vec<String>,
@@ -58,6 +59,7 @@ impl Configuration {
server_ip: "m.earthvillage.top".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(),
name_len_limit: vec![4,8],
count: 300, count: 300,
proxy_url: "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json".to_string(), proxy_url: "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json".to_string(),
reco_words: vec!["AntiAttack".to_string()], reco_words: vec!["AntiAttack".to_string()],
@@ -102,21 +104,4 @@ impl Configuration {
pub fn random_prefix(&self) -> bool { pub fn random_prefix(&self) -> bool {
self.random_prefix self.random_prefix
} }
} }
// impl Clone for Configuration {
// fn clone(&self) -> Self {
// Configuration {
// server_ip: self.server_ip.clone(),
// server_port: self.server_port.clone(),
// username_prefix: self.username_prefix.clone(),
// count: self.count,
// proxy_url: self.proxy_url.clone(),
// reco_words: self.reco_words.clone(),
// login_commands:self.login_commands.clone(),
// random_prefix: self.random_prefix,
// spam_file: self.spam_file.clone(),
// spam_delay_ms: self.spam_delay_ms,
// }
// }
// }

View File

@@ -16,26 +16,10 @@ use tokio::sync::Mutex;
use crate::utils::generate_username; use crate::utils::generate_username;
use crate::configuration::Configuration; use crate::configuration::Configuration;
// 暂且保留一下
// // 目标的ip地址(暂时不能解析dns)
// // 理论上你可以把它改成任何支持1.20.1的服务器
// const SERVER_ADDR: &str = "49.70.3.146:33009";
// // uu代理的api(用来实时获取代理)
// const UU_URL: &str = "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json";
// // 用户名的开头
// // 这很不错了
// const USERNAME_PREFIX: &str = "Nikke_"; // 2 3 3
// // 假人数量
// const COUNT :i32 = 300;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let mut logger_builder = env_logger::Builder::from_default_env(); let mut logger_builder = env_logger::Builder::from_default_env();
logger_builder.filter_level(log::LevelFilter::Info); logger_builder.filter_level(log::LevelFilter::Info);
// logger_builder.format(|buf,record| {
// buf.write(format!("[{}/{}] {}\n", record.target(),record.level(),record.args()).as_bytes()).unwrap();
// Ok(())
// });
logger_builder.init(); logger_builder.init();
// 一个互斥锁,防止有多个线程同时请求uuproxy // 一个互斥锁,防止有多个线程同时请求uuproxy
let thread_lock = Arc::new(Mutex::new(())); let thread_lock = Arc::new(Mutex::new(()));
@@ -44,10 +28,6 @@ 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 {
error!("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());
} }
@@ -75,13 +55,6 @@ async fn main() {
let configuration_rc_clone = configuration_rc.clone(); let configuration_rc_clone = configuration_rc.clone();
let variables_clone = variables.clone(); let variables_clone = variables.clone();
let rt_update_clone = rt_update.clone(); let rt_update_clone = rt_update.clone();
// let handle = tokio::spawn(async move {
// attack_thread(lock_clone).await;
// println!("[MAIN] Thread {} created", i);
// });
// 生成一个线程
// let handle = tokio::task::spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
// let handle;
if configuration_rc.use_thread_pool { if configuration_rc.use_thread_pool {
rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone,rt_update_clone)); rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone,rt_update_clone));
}else{ }else{
@@ -97,13 +70,7 @@ async fn main() {
}); });
}); });
} }
// handles.push(handle);
// println!("[MAIN] Thread {} created", i) // 这个太吵了(
} }
// 等待所有任务完成(虽然大概也许可能这辈子都等不到)
// for _ in handles {
// }
let lock_clone = thread_lock.clone(); let lock_clone = thread_lock.clone();
let configuration_rc_clone = configuration_rc.clone(); let configuration_rc_clone = configuration_rc.clone();
let variables_clone = variables.clone(); let variables_clone = variables.clone();

View File

@@ -57,6 +57,6 @@ pub fn generate_string(len_min: i64, len_max: i64) -> String {
pub fn generate_username(config: &Arc<Configuration>) -> String { pub fn generate_username(config: &Arc<Configuration>) -> String {
config.username_prefix().to_string() + generate_string( config.username_prefix().to_string() + generate_string(
2,16-config.username_prefix().len() as i64 config.name_len_limit[0], config.name_len_limit[1]
).to_string().as_str() ).to_string().as_str()
} }