WIP: hellfire #1

Draft
sad wants to merge 19 commits from hellfire into main
2 changed files with 46 additions and 25 deletions
Showing only changes of commit 6bf609c162 - Show all commits

View File

@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use colored::*; use colored::*;
use tokio_socks::tcp::Socks5Stream; use tokio_socks::tcp::Socks5Stream;
#[derive(Deserialize)] #[derive(Deserialize, Clone)]
struct Config { struct Config {
server: String, server: String,
port: u16, port: u16,
@ -22,6 +22,9 @@ struct Config {
sasl_password: Option<String>, sasl_password: Option<String>,
capabilities: Option<Vec<String>>, capabilities: Option<Vec<String>>,
reconnect_delay: u64,
reconnect_attempts: u64,
// Proxy // Proxy
use_proxy: bool, use_proxy: bool,
proxy_type: Option<String>, proxy_type: Option<String>,
@ -45,13 +48,18 @@ use mods::ascii::handle_ascii_command;
#[tokio::main(flavor = "multi_thread", worker_threads = 12)] #[tokio::main(flavor = "multi_thread", worker_threads = 12)]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::spawn(async move { //tokio::spawn(async move {
println!("Loading Config..."); println!("Loading Config...");
let config = loaded_config().expect("Error parsing config.toml"); let config = loaded_config().expect("Error parsing config.toml");
println!("Config loaded!"); println!("Config loaded!");
let mut reconnect_attempts = 0;
let server = format!("{}:{}", config.server, config.port); while reconnect_attempts < config.reconnect_attempts {
let configc = config.clone();
let server = format!("{}:{}", configc.server, configc.port);
let connection_result = tokio::spawn(async move {
let config = configc.clone();
if config.use_ssl { if config.use_ssl {
if config.use_proxy { if config.use_proxy {
let tcp_stream = proxy_exec(&config).await; let tcp_stream = proxy_exec(&config).await;
@ -81,7 +89,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else { } else {
println!("Non-SSL connection not implemented."); println!("Non-SSL connection not implemented.");
} }
Ok::<(), Box<dyn std::error::Error + Send>>(())
}).await.unwrap(); }).await.unwrap();
match connection_result {
Ok(_) => {
println!("Connection established successfully!");
reconnect_attempts = 0;
},
Err(e) => {
println!("Error handling connection: {}", e);
reconnect_attempts += 1;
tokio::time::sleep(tokio::time::Duration::from_secs(config.reconnect_delay)).await;
}
}
}
println!("Reconnect attempts exceeded. Exiting...");
Ok(()) Ok(())
} }

View File

@ -27,7 +27,6 @@ async fn send_ansi_art<W: AsyncWriteExt + Unpin>(writer: &mut W, file_path: &str
let reader = BufReader::new(file); let reader = BufReader::new(file);
let mut lines = reader.lines(); let mut lines = reader.lines();
while let Some(line) = lines.next_line().await? { while let Some(line) = lines.next_line().await? {
if line.len() > CHUNK_SIZE { if line.len() > CHUNK_SIZE {