1use zeroize::Zeroizing;
20
21use std::sync::atomic::{ AtomicBool, Ordering };
22
23#[cfg(feature = "client")]
24use std::sync::
25{
26 Arc,
27 Mutex,
28 RwLock,
29 LazyLock,
30 OnceLock,
31 atomic::AtomicUsize,
32};
33
34pub const METADATA_URL: &str = "https://crates.io/api/v1/crates/why2"; pub const USER_CONFIG_DIR: &str = "{HOME}/.config"; pub const CONFIG_DIR: &str = "/WHY2"; pub const SERVER_CONFIG: &str = "/server.toml"; pub const CLIENT_CONFIG: &str = "/client.toml"; pub const SERVER_USERS_CONFIG: &str = "/server_users.toml"; pub const CONFIG_URL: &str = "https://git.satan.red/ENGO150/WHY2/-/raw/development/chat/src/config"; pub const SERVER_KEYS_CONFIG: &str = "/server_keys.toml"; pub const SERVER_KEYS_DIR: &str = "/server_keys"; pub const SERVER_SKEY: &str = "/private"; pub const SERVER_PKEY: &str = "/public"; pub const SERVER_PQ_SKEY: &str = "/private_pq"; pub const SERVER_PQ_PKEY: &str = "/public_pq"; pub const FETCH_TIMEOUT: u64 = 5000; pub const REKEY_INTERVAL: u64 = 600; pub const OBFUSCATION_KEY: &[u8; 32] = &[
58 0x9A, 0xF7, 0x1C, 0xD4, 0x62, 0x3E, 0x8B, 0x5A,
59 0x0F, 0x2D, 0xE1, 0x79, 0x4C, 0xB8, 0x63, 0x90,
60 0x21, 0x55, 0xAE, 0xD6, 0x04, 0x7F, 0x33, 0x82,
61 0xBC, 0x19, 0x40, 0xE7, 0x95, 0x2A, 0x6B, 0xF8,
62];
63
64pub type SharedKeys = (Zeroizing<Vec<i64>>, Zeroizing<Vec<u8>>);
66
67#[cfg(feature = "server")]
69static VOICE_CHAT: AtomicBool = AtomicBool::new(false);
70
71#[cfg(feature = "client")]
72static KEYS: LazyLock<RwLock<Option<SharedKeys>>> = LazyLock::new(|| {
74 RwLock::new(None)
75});
76
77#[cfg(feature = "client")]
78static ASKING_PASSWORD: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
81static EXTRA_SPACE: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
84static SENDING_MESSAGES: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
87pub static INPUT_READ: LazyLock<Arc<Mutex<Vec<char>>>> = LazyLock::new(|| {
89 Arc::new(Mutex::new(Vec::new()))
90});
91
92#[cfg(feature = "client")]
93static SEQ: AtomicUsize = AtomicUsize::new(0); #[cfg(feature = "client")]
96static SERVER_SEQ: AtomicUsize = AtomicUsize::new(0); #[cfg(feature = "client")]
99static SERVER_ADDRESS: OnceLock<String> = OnceLock::new();
100
101#[cfg(feature = "client")]
102static SOCKS5: AtomicBool = AtomicBool::new(false); #[cfg(feature = "server")]
107pub fn enable_voice_chat() {
109 VOICE_CHAT.store(true, Ordering::Relaxed);
110}
111
112#[cfg(feature = "server")]
113pub fn voice_chat_enabled() -> bool {
115 VOICE_CHAT.load(Ordering::Relaxed)
116}
117
118#[cfg(feature = "client")]
120pub fn set_keys(keys: SharedKeys) {
122 let mut shared_key = KEYS.write().unwrap();
123 *shared_key = Some(keys);
124}
125
126#[cfg(feature = "client")]
127pub fn get_keys() -> Option<SharedKeys> {
129 let shared_key = KEYS.read().unwrap();
130 shared_key.clone()
131}
132
133#[cfg(feature = "client")]
135pub fn set_asking_password(value: bool) {
137 ASKING_PASSWORD.store(value, Ordering::Relaxed);
138}
139
140#[cfg(feature = "client")]
141pub fn get_asking_password() -> bool {
143 ASKING_PASSWORD.load(Ordering::Relaxed)
144}
145
146#[cfg(feature = "client")]
148pub fn set_extra_space(value: bool) {
150 EXTRA_SPACE.store(value, Ordering::Relaxed);
151}
152
153#[cfg(feature = "client")]
154pub fn get_extra_space() -> bool {
156 EXTRA_SPACE.load(Ordering::Relaxed)
157}
158
159#[cfg(feature = "client")]
161pub fn get_sending_messages() -> bool {
163 SENDING_MESSAGES.load(Ordering::Relaxed)
164}
165
166#[cfg(feature = "client")]
167pub fn set_sending_messages(value: bool) {
169 SENDING_MESSAGES.store(value, Ordering::Relaxed);
170}
171
172#[cfg(feature = "client")]
173pub fn get_seq() -> usize {
175 SEQ.load(Ordering::Relaxed)
176}
177
178#[cfg(feature = "client")]
179pub fn set_seq(value: usize) {
181 SEQ.store(value, Ordering::Relaxed)
182}
183
184#[cfg(feature = "client")]
185pub fn get_server_seq() -> usize {
187 SERVER_SEQ.load(Ordering::Relaxed)
188}
189
190#[cfg(feature = "client")]
191pub fn set_server_seq(value: usize) {
193 SERVER_SEQ.store(value, Ordering::Relaxed)
194}
195
196#[cfg(feature = "client")]
198pub fn get_server_address() -> String {
200 SERVER_ADDRESS.get().unwrap().to_owned()
201}
202
203#[cfg(feature = "client")]
204pub fn set_server_address(address: &str) {
206 SERVER_ADDRESS.set(address.to_owned()).unwrap();
207}
208
209#[cfg(feature = "client")]
211pub fn enable_socks5() {
213 SOCKS5.store(true, Ordering::Relaxed);
214}
215
216#[cfg(feature = "client")]
217pub fn socks5_enabled() -> bool {
219 SOCKS5.load(Ordering::Relaxed)
220}