mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 05:28:02 +03:00
try to merge
This commit is contained in:
commit
173b5bd217
100
README.md
100
README.md
@ -1,4 +1,4 @@
|
||||
# bRAC
|
||||
# 
|
||||
<!--
|
||||
[<img src="https://github.com/user-attachments/assets/f2be5caa-6246-4a6a-9bee-2b53086f9afb" height="30">]()
|
||||
[<img src="https://github.com/user-attachments/assets/4d35191d-1dbc-4391-a761-6ae7f76ba7af" height="30">]()
|
||||
@ -10,13 +10,14 @@ better RAC client
|
||||
## features
|
||||
|
||||
- gtk4 GUI
|
||||
- cheat commands (type /help)
|
||||
- no ip and date visible
|
||||
- uses TOR proxy server by default (meex.lol:11234)
|
||||
- plays sound when users receive your messages
|
||||
- coloring usernames by their clients (CRAB, clRAC, Mefidroniy, etc)
|
||||
- configurable message format
|
||||
- fancy TUI version
|
||||
- RACv1.99.x and RACv2.0 compatible
|
||||
- chat commands (type /help)
|
||||
- no ip and date visible for anyone
|
||||
- uses TOR proxy server by default (meex.lol:11234)
|
||||
- coloring usernames by their clients (CRAB, clRAC, Mefidroniy, etc)
|
||||
- many command-line options (--help)
|
||||
- rich configuration (--config-path to get file path and --configure to edit)
|
||||
- RACS compatible (--enable-ssl or in --configure enable SSL)
|
||||
- chunked reading messages
|
||||
|
||||
@ -38,24 +39,13 @@ git clone https://github.com/MeexReay/bRAC.git
|
||||
cd bRAC
|
||||
```
|
||||
|
||||
3. Build or run with Cargo
|
||||
3. Run with Cargo
|
||||
```bash
|
||||
cargo build -r # build release (target/release/bRAC)
|
||||
cargo run -r # run (builds and runs bRAC itself)
|
||||
```
|
||||
cargo run -r # run GUI version
|
||||
cargo run -r --no-default-features -F tui # run TUI version
|
||||
cargo run -r --no-default-features # run minimal version
|
||||
|
||||
TUI version:
|
||||
|
||||
```bash
|
||||
cargo build -r --no-default-features -F tui
|
||||
cargo run -r --no-default-features -F tui
|
||||
```
|
||||
|
||||
Minimal version:
|
||||
|
||||
```bash
|
||||
cargo build -r --no-default-features
|
||||
cargo run -r --no-default-features
|
||||
# change "cargo run" to "cargo build" to just build (target/release/bRAC)
|
||||
```
|
||||
|
||||
### nix package
|
||||
@ -63,69 +53,21 @@ cargo run -r --no-default-features
|
||||
If you have Nix package manager installed, you can use:
|
||||
|
||||
```bash
|
||||
nix build github:MeexReay/bRAC # build binary (result/bin/bRAC)
|
||||
nix run github:MeexReay/bRAC # run (builds and runs bRAC)
|
||||
nix run github:MeexReay/bRAC # run GUI version
|
||||
nix run github:MeexReay/bRAC#bRAC-tui # run TUI version
|
||||
nix run github:MeexReay/bRAC#bRAC-minimal # run minimal version
|
||||
|
||||
# change "nix run" to "nix build" to just build (result/bin/bRAC)
|
||||
```
|
||||
|
||||
Minimal version:
|
||||
|
||||
```bash
|
||||
nix build github:MeexReay/bRAC#bRAC-minimal
|
||||
nix run github:MeexReay/bRAC#bRAC-minimal
|
||||
```
|
||||
|
||||
TUI version:
|
||||
|
||||
```bash
|
||||
nix build github:MeexReay/bRAC#bRAC-tui
|
||||
nix run github:MeexReay/bRAC#bRAC-tui
|
||||
```
|
||||
|
||||
## default config
|
||||
|
||||
get config path - `bRAC --config-path` \
|
||||
reconfigure client - `bRAC --configure`
|
||||
|
||||
```yml
|
||||
host: meex.lol:11234 # server host
|
||||
name: null # user name (null - ask every time)
|
||||
message_format: 리㹰<{name}> {text} # message format
|
||||
update_time: 50 # update chat interval
|
||||
max_messages: 200 # chat messages limit
|
||||
enable_ip_viewing: true # enable users' ip viewing
|
||||
disable_ip_hiding: false # disable your ip hiding
|
||||
enable_auth: true # enable auth-mode
|
||||
enable_ssl: false # enable ssl connection
|
||||
enable_chunked: true # enable chunked reading
|
||||
```
|
||||
|
||||
## command-line options
|
||||
|
||||
```
|
||||
-p, --config-path Print config path
|
||||
-H, --host <HOST> Use specified host
|
||||
-n, --name <NAME> Use specified name
|
||||
-F, --message-format <MESSAGE_FORMAT> Use specified message format
|
||||
-r, --read-messages Print unformatted messages from chat and exit
|
||||
-s, --send-message <MESSAGE> Send unformatted message to chat and exit
|
||||
-f, --disable-formatting Disable message formatting and sanitizing
|
||||
-c, --disable-commands Disable slash commands
|
||||
-i, --disable-ip-hiding Disable ip hiding
|
||||
-v, --enable-users-ip-viewing Enable users IP viewing
|
||||
-C, --configure Configure client
|
||||
-a, --enable-auth Enable authentication
|
||||
-S, --enable-ssl Enable SSL
|
||||
-u, --enable-chunked Enable chunked reading
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
```
|
||||
|
||||
## cheat commands
|
||||
## chat commands
|
||||
|
||||
commands are any messages that start with a slash `/` \
|
||||
messages starting with a slash are sent to chat only if the `--disable-commands` option is specified
|
||||
|
||||
- `/help` - show help message
|
||||
- `/register password` - try to register account
|
||||
- `/login password` - login to account
|
||||
- `/clear` - clear chat
|
||||
- `/spam *args` - spam with text
|
||||
- `/ping` - get server ping (send + read)
|
||||
|
502
src/config.rs
502
src/config.rs
@ -1,252 +1,252 @@
|
||||
use std::{str::FromStr, sync::{Arc, RwLock}};
|
||||
#[allow(unused_imports)]
|
||||
use std::{env, fs, path::{Path, PathBuf}, thread, time::Duration};
|
||||
use colored::Colorize;
|
||||
use rand::random;
|
||||
use serde_yml;
|
||||
use clap::Parser;
|
||||
|
||||
use crate::chat::ChatContext;
|
||||
|
||||
use super::util::get_input;
|
||||
|
||||
const MESSAGE_FORMAT: &str = "\u{B9AC}\u{3E70}<{name}> {text}";
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Config {
|
||||
#[serde(default = "default_host")]
|
||||
pub host: String,
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
#[serde(default = "default_message_format")]
|
||||
pub message_format: String,
|
||||
#[serde(default = "default_update_time")]
|
||||
pub update_time: usize,
|
||||
#[serde(default = "default_max_messages")]
|
||||
pub max_messages: usize,
|
||||
#[serde(default)]
|
||||
pub enable_ip_viewing: bool,
|
||||
#[serde(default)]
|
||||
pub disable_ip_hiding: bool,
|
||||
#[serde(default)]
|
||||
pub enable_auth: bool,
|
||||
#[serde(default)]
|
||||
pub enable_ssl: bool,
|
||||
#[serde(default)]
|
||||
pub enable_chunked: bool,
|
||||
}
|
||||
|
||||
fn default_max_messages() -> usize { 200 }
|
||||
fn default_update_time() -> usize { 50 }
|
||||
fn default_host() -> String { "meex.lol:11234".to_string() }
|
||||
fn default_message_format() -> String { MESSAGE_FORMAT.to_string() }
|
||||
|
||||
fn ask_usize(name: impl ToString, default: usize) -> usize {
|
||||
get_input(format!("{} (default: {}) {} ", name.to_string().bold(), default, ">".bold()).bright_yellow())
|
||||
.and_then(|o| o.parse().ok()).unwrap_or(default)
|
||||
}
|
||||
|
||||
fn ask_string(name: impl ToString, default: impl ToString + Clone) -> String {
|
||||
ask_string_option(name, default.clone()).unwrap_or(default.to_string())
|
||||
}
|
||||
|
||||
fn ask_string_option(name: impl ToString, default: impl ToString) -> Option<String> {
|
||||
let default = default.to_string();
|
||||
get_input(format!("{} (default: {}) {} ", name.to_string().bold(), default, ">".bold()).bright_yellow())
|
||||
}
|
||||
|
||||
fn ask_bool(name: impl ToString, default: bool) -> bool {
|
||||
get_input(format!("{} (Y/N, default: {}) {} ", name.to_string().bold(), if default { "Y" } else { "N" }, ">".bold()).bright_yellow())
|
||||
.map(|o| o.to_lowercase() != "n")
|
||||
.unwrap_or(default)
|
||||
}
|
||||
|
||||
pub fn configure(path: PathBuf) -> Config {
|
||||
println!("{}", "To configure the client, please answer a few questions. It won't take long.".yellow());
|
||||
println!("{}", "You can reconfigure client in any moment via `bRAC --configure`".yellow());
|
||||
println!("{}", format!("Config stores in path `{}`", path.to_string_lossy()).yellow());
|
||||
println!();
|
||||
|
||||
let host = ask_string("Host", default_host());
|
||||
let name = ask_string_option("Name", "ask every time");
|
||||
let update_time = ask_usize("Update interval", default_update_time());
|
||||
let max_messages = ask_usize("Max messages", default_max_messages());
|
||||
let message_format = ask_string("Message format", default_message_format());
|
||||
let enable_ip_viewing = ask_bool("Enable users IP viewing?", true);
|
||||
let disable_ip_hiding = ask_bool("Enable your IP viewing?", false);
|
||||
let enable_auth = ask_bool("Enable auth-mode?", false);
|
||||
let enable_ssl = ask_bool("Enable SSL?", false);
|
||||
let enable_chunked = ask_bool("Enable chunked reading?", true);
|
||||
|
||||
let config = Config {
|
||||
host,
|
||||
name,
|
||||
message_format,
|
||||
update_time,
|
||||
max_messages,
|
||||
enable_ip_viewing,
|
||||
disable_ip_hiding,
|
||||
enable_auth,
|
||||
enable_ssl,
|
||||
enable_chunked
|
||||
};
|
||||
|
||||
let config_text = serde_yml::to_string(&config).expect("Config save error");
|
||||
fs::create_dir_all(&path.parent().expect("Config save error")).expect("Config save error");
|
||||
fs::write(&path, config_text).expect("Config save error");
|
||||
|
||||
println!();
|
||||
println!("{}", "Config saved! You can reconfigure it in any moment via `bRAC --configure`".yellow());
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub fn load_config(path: PathBuf) -> Config {
|
||||
if !fs::exists(&path).unwrap_or_default() {
|
||||
let config = configure(path.clone());
|
||||
thread::sleep(Duration::from_secs(4));
|
||||
config
|
||||
} else {
|
||||
let config = &fs::read_to_string(&path).expect("Config load error");
|
||||
serde_yml::from_str(config).expect("Config load error")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_path() -> PathBuf {
|
||||
let mut config_dir = PathBuf::from_str(".").unwrap();
|
||||
|
||||
#[cfg(all(feature = "homedir", not(target_os = "windows")))]
|
||||
if let Some(dir) = {
|
||||
let home_dir = {
|
||||
use homedir::my_home;
|
||||
my_home().ok().flatten()
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
let config_dir = {
|
||||
let home_dir = home_dir.map(|o| o.join("bRAC"));
|
||||
home_dir.map(|o| o.join(".config"))
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let config_dir = {
|
||||
let home_dir = home_dir.map(|o| o.join("bRAC"));
|
||||
home_dir.map(|o| o.join(".config"))
|
||||
};
|
||||
|
||||
config_dir
|
||||
} {
|
||||
config_dir = dir;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
if let Some(dir) = {
|
||||
env::var("APPDATA")
|
||||
.ok()
|
||||
.and_then(|o| Some(PathBuf::from_str(&o).ok()?.join("bRAC")))
|
||||
} {
|
||||
config_dir = dir;
|
||||
}
|
||||
|
||||
config_dir.join("config.yml")
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
/// Print config path
|
||||
#[arg(short='p', long)]
|
||||
pub config_path: bool,
|
||||
|
||||
/// Use specified host
|
||||
#[arg(short='H', long)]
|
||||
pub host: Option<String>,
|
||||
|
||||
/// Use specified name
|
||||
#[arg(short='n', long)]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// Use specified message format
|
||||
#[arg(short='F', long)]
|
||||
pub message_format: Option<String>,
|
||||
|
||||
/// Print unformatted messages from chat and exit
|
||||
#[arg(short='r', long)]
|
||||
pub read_messages: bool,
|
||||
|
||||
/// Send unformatted message to chat and exit
|
||||
#[arg(short='s', long, value_name="MESSAGE")]
|
||||
pub send_message: Option<String>,
|
||||
|
||||
/// Disable message formatting and sanitizing
|
||||
#[arg(short='f', long)]
|
||||
pub disable_formatting: bool,
|
||||
|
||||
/// Disable slash commands
|
||||
#[arg(short='c', long)]
|
||||
pub disable_commands: bool,
|
||||
|
||||
/// Disable ip hiding
|
||||
#[arg(short='i', long)]
|
||||
pub disable_ip_hiding: bool,
|
||||
|
||||
/// Enable users IP viewing
|
||||
#[arg(short='v', long)]
|
||||
pub enable_users_ip_viewing: bool,
|
||||
|
||||
/// Configure client
|
||||
#[arg(short='C', long)]
|
||||
pub configure: bool,
|
||||
|
||||
/// Enable authentication
|
||||
#[arg(short='a', long)]
|
||||
pub enable_auth: bool,
|
||||
|
||||
/// Enable SSL
|
||||
#[arg(short='S', long)]
|
||||
pub enable_ssl: bool,
|
||||
|
||||
/// Enable chunked reading
|
||||
#[arg(short='u', long)]
|
||||
pub enable_chunked: bool,
|
||||
}
|
||||
|
||||
pub struct Context {
|
||||
pub chat: Arc<RwLock<Option<Arc<ChatContext>>>>,
|
||||
pub host: String,
|
||||
pub name: String,
|
||||
pub disable_formatting: bool,
|
||||
pub disable_commands: bool,
|
||||
pub disable_hiding_ip: bool,
|
||||
pub message_format: String,
|
||||
pub update_time: usize,
|
||||
pub max_messages: usize,
|
||||
pub enable_ip_viewing: bool,
|
||||
pub enable_auth: bool,
|
||||
pub enable_ssl: bool,
|
||||
pub enable_chunked: bool,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new(config: &Config, args: &Args) -> Context {
|
||||
Context {
|
||||
chat: Arc::new(RwLock::new(None)),
|
||||
message_format: args.message_format.clone().unwrap_or(config.message_format.clone()),
|
||||
host: args.host.clone().unwrap_or(config.host.clone()),
|
||||
name: args.name.clone().or(config.name.clone()).unwrap_or_else(|| ask_string("Name", format!("Anon#{:X}", random::<u16>()))),
|
||||
disable_formatting: args.disable_formatting,
|
||||
disable_commands: args.disable_commands,
|
||||
disable_hiding_ip: args.disable_ip_hiding,
|
||||
update_time: config.update_time,
|
||||
max_messages: config.max_messages,
|
||||
enable_ip_viewing: args.enable_users_ip_viewing || config.enable_ip_viewing,
|
||||
enable_auth: args.enable_auth || config.enable_auth,
|
||||
enable_ssl: args.enable_ssl || config.enable_ssl,
|
||||
enable_chunked: args.enable_chunked || config.enable_chunked,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat(&self) -> Arc<ChatContext> {
|
||||
self.chat.read().unwrap().clone().unwrap()
|
||||
}
|
||||
use std::{str::FromStr, sync::{Arc, RwLock}};
|
||||
#[allow(unused_imports)]
|
||||
use std::{env, fs, path::{Path, PathBuf}, thread, time::Duration};
|
||||
use colored::Colorize;
|
||||
use rand::random;
|
||||
use serde_yml;
|
||||
use clap::Parser;
|
||||
|
||||
use crate::chat::ChatContext;
|
||||
|
||||
use super::util::get_input;
|
||||
|
||||
const MESSAGE_FORMAT: &str = "\u{B9AC}\u{3E70}<{name}> {text}";
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Config {
|
||||
#[serde(default = "default_host")]
|
||||
pub host: String,
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
#[serde(default = "default_message_format")]
|
||||
pub message_format: String,
|
||||
#[serde(default = "default_update_time")]
|
||||
pub update_time: usize,
|
||||
#[serde(default = "default_max_messages")]
|
||||
pub max_messages: usize,
|
||||
#[serde(default)]
|
||||
pub enable_ip_viewing: bool,
|
||||
#[serde(default)]
|
||||
pub disable_ip_hiding: bool,
|
||||
#[serde(default)]
|
||||
pub enable_auth: bool,
|
||||
#[serde(default)]
|
||||
pub enable_ssl: bool,
|
||||
#[serde(default)]
|
||||
pub enable_chunked: bool,
|
||||
}
|
||||
|
||||
fn default_max_messages() -> usize { 200 }
|
||||
fn default_update_time() -> usize { 50 }
|
||||
fn default_host() -> String { "meex.lol:11234".to_string() }
|
||||
fn default_message_format() -> String { MESSAGE_FORMAT.to_string() }
|
||||
|
||||
fn ask_usize(name: impl ToString, default: usize) -> usize {
|
||||
get_input(format!("{} (default: {}) {} ", name.to_string().bold(), default, ">".bold()).bright_yellow())
|
||||
.and_then(|o| o.parse().ok()).unwrap_or(default)
|
||||
}
|
||||
|
||||
fn ask_string(name: impl ToString, default: impl ToString + Clone) -> String {
|
||||
ask_string_option(name, default.clone()).unwrap_or(default.to_string())
|
||||
}
|
||||
|
||||
fn ask_string_option(name: impl ToString, default: impl ToString) -> Option<String> {
|
||||
let default = default.to_string();
|
||||
get_input(format!("{} (default: {}) {} ", name.to_string().bold(), default, ">".bold()).bright_yellow())
|
||||
}
|
||||
|
||||
fn ask_bool(name: impl ToString, default: bool) -> bool {
|
||||
get_input(format!("{} (Y/N, default: {}) {} ", name.to_string().bold(), if default { "Y" } else { "N" }, ">".bold()).bright_yellow())
|
||||
.map(|o| o.to_lowercase() != "n")
|
||||
.unwrap_or(default)
|
||||
}
|
||||
|
||||
pub fn configure(path: PathBuf) -> Config {
|
||||
println!("{}", "To configure the client, please answer a few questions. It won't take long.".yellow());
|
||||
println!("{}", "You can reconfigure client in any moment via `bRAC --configure`".yellow());
|
||||
println!("{}", format!("Config stores in path `{}`", path.to_string_lossy()).yellow());
|
||||
println!();
|
||||
|
||||
let host = ask_string("Host", default_host());
|
||||
let name = ask_string_option("Name", "ask every time");
|
||||
let update_time = ask_usize("Update interval", default_update_time());
|
||||
let max_messages = ask_usize("Max messages", default_max_messages());
|
||||
let message_format = ask_string("Message format", default_message_format());
|
||||
let enable_ip_viewing = ask_bool("Enable users IP viewing?", true);
|
||||
let disable_ip_hiding = ask_bool("Enable your IP viewing?", false);
|
||||
let enable_auth = ask_bool("Enable auth-mode?", false);
|
||||
let enable_ssl = ask_bool("Enable SSL?", false);
|
||||
let enable_chunked = ask_bool("Enable chunked reading?", true);
|
||||
|
||||
let config = Config {
|
||||
host,
|
||||
name,
|
||||
message_format,
|
||||
update_time,
|
||||
max_messages,
|
||||
enable_ip_viewing,
|
||||
disable_ip_hiding,
|
||||
enable_auth,
|
||||
enable_ssl,
|
||||
enable_chunked
|
||||
};
|
||||
|
||||
let config_text = serde_yml::to_string(&config).expect("Config save error");
|
||||
fs::create_dir_all(&path.parent().expect("Config save error")).expect("Config save error");
|
||||
fs::write(&path, config_text).expect("Config save error");
|
||||
|
||||
println!();
|
||||
println!("{}", "Config saved! You can reconfigure it in any moment via `bRAC --configure`".yellow());
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub fn load_config(path: PathBuf) -> Config {
|
||||
if !fs::exists(&path).unwrap_or_default() {
|
||||
let config = configure(path.clone());
|
||||
thread::sleep(Duration::from_secs(4));
|
||||
config
|
||||
} else {
|
||||
let config = &fs::read_to_string(&path).expect("Config load error");
|
||||
serde_yml::from_str(config).expect("Config load error")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_path() -> PathBuf {
|
||||
let mut config_dir = PathBuf::from_str(".").unwrap();
|
||||
|
||||
#[cfg(all(feature = "homedir", not(target_os = "windows")))]
|
||||
if let Some(dir) = {
|
||||
let home_dir = {
|
||||
use homedir::my_home;
|
||||
my_home().ok().flatten()
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
let config_dir = {
|
||||
let home_dir = home_dir.map(|o| o.join("bRAC"));
|
||||
home_dir.map(|o| o.join(".config"))
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let config_dir = {
|
||||
let home_dir = home_dir.map(|o| o.join("bRAC"));
|
||||
home_dir.map(|o| o.join(".config"))
|
||||
};
|
||||
|
||||
config_dir
|
||||
} {
|
||||
config_dir = dir;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
if let Some(dir) = {
|
||||
env::var("APPDATA")
|
||||
.ok()
|
||||
.and_then(|o| Some(PathBuf::from_str(&o).ok()?.join("bRAC")))
|
||||
} {
|
||||
config_dir = dir;
|
||||
}
|
||||
|
||||
config_dir.join("config.yml")
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
/// Print config path
|
||||
#[arg(short='p', long)]
|
||||
pub config_path: bool,
|
||||
|
||||
/// Use specified host
|
||||
#[arg(short='H', long)]
|
||||
pub host: Option<String>,
|
||||
|
||||
/// Use specified name
|
||||
#[arg(short='n', long)]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// Use specified message format
|
||||
#[arg(short='F', long)]
|
||||
pub message_format: Option<String>,
|
||||
|
||||
/// Print unformatted messages from chat and exit
|
||||
#[arg(short='r', long)]
|
||||
pub read_messages: bool,
|
||||
|
||||
/// Send unformatted message to chat and exit
|
||||
#[arg(short='s', long, value_name="MESSAGE")]
|
||||
pub send_message: Option<String>,
|
||||
|
||||
/// Disable message formatting and sanitizing
|
||||
#[arg(short='f', long)]
|
||||
pub disable_formatting: bool,
|
||||
|
||||
/// Disable slash commands
|
||||
#[arg(short='c', long)]
|
||||
pub disable_commands: bool,
|
||||
|
||||
/// Disable ip hiding
|
||||
#[arg(short='i', long)]
|
||||
pub disable_ip_hiding: bool,
|
||||
|
||||
/// Enable users IP viewing
|
||||
#[arg(short='v', long)]
|
||||
pub enable_users_ip_viewing: bool,
|
||||
|
||||
/// Configure client
|
||||
#[arg(short='C', long)]
|
||||
pub configure: bool,
|
||||
|
||||
/// Enable authentication
|
||||
#[arg(short='a', long)]
|
||||
pub enable_auth: bool,
|
||||
|
||||
/// Enable SSL
|
||||
#[arg(short='S', long)]
|
||||
pub enable_ssl: bool,
|
||||
|
||||
/// Enable chunked reading
|
||||
#[arg(short='u', long)]
|
||||
pub enable_chunked: bool,
|
||||
}
|
||||
|
||||
pub struct Context {
|
||||
pub chat: Arc<RwLock<Option<Arc<ChatContext>>>>,
|
||||
pub host: String,
|
||||
pub name: String,
|
||||
pub disable_formatting: bool,
|
||||
pub disable_commands: bool,
|
||||
pub disable_hiding_ip: bool,
|
||||
pub message_format: String,
|
||||
pub update_time: usize,
|
||||
pub max_messages: usize,
|
||||
pub enable_ip_viewing: bool,
|
||||
pub enable_auth: bool,
|
||||
pub enable_ssl: bool,
|
||||
pub enable_chunked: bool,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new(config: &Config, args: &Args) -> Context {
|
||||
Context {
|
||||
chat: Arc::new(RwLock::new(None)),
|
||||
message_format: args.message_format.clone().unwrap_or(config.message_format.clone()),
|
||||
host: args.host.clone().unwrap_or(config.host.clone()),
|
||||
name: args.name.clone().or(config.name.clone()).unwrap_or_else(|| ask_string("Name", format!("Anon#{:X}", random::<u16>()))),
|
||||
disable_formatting: args.disable_formatting,
|
||||
disable_commands: args.disable_commands,
|
||||
disable_hiding_ip: args.disable_ip_hiding,
|
||||
update_time: config.update_time,
|
||||
max_messages: config.max_messages,
|
||||
enable_ip_viewing: args.enable_users_ip_viewing || config.enable_ip_viewing,
|
||||
enable_auth: args.enable_auth || config.enable_auth,
|
||||
enable_ssl: args.enable_ssl || config.enable_ssl,
|
||||
enable_chunked: args.enable_chunked || config.enable_chunked,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat(&self) -> Arc<ChatContext> {
|
||||
self.chat.read().unwrap().clone().unwrap()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user