1use std::sync::
20{
21 OnceLock,
22 atomic::{ AtomicBool, Ordering },
23};
24
25#[cfg(feature = "client")]
26use std::
27{
28 collections::HashSet,
29 sync::
30 {
31 Arc,
32 Mutex,
33 RwLock,
34 LazyLock,
35 atomic::AtomicUsize,
36 },
37};
38
39#[cfg(feature = "client")]
40use crate::consts::SharedKeys;
41
42static SERVER_USERNAME: OnceLock<String> = OnceLock::new();
44
45#[cfg(feature = "server")]
46static VOICE_CHAT: AtomicBool = AtomicBool::new(false);
47
48#[cfg(feature = "client")]
49static KEYS: LazyLock<RwLock<Option<SharedKeys>>> = LazyLock::new(|| {
51 RwLock::new(None)
52});
53
54#[cfg(feature = "client")]
55static ASKING_PASSWORD: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
58static EXTRA_SPACE: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
61static SENDING_MESSAGES: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
64pub static INPUT_READ: LazyLock<Arc<Mutex<Vec<char>>>> = LazyLock::new(|| {
66 Arc::new(Mutex::new(Vec::new()))
67});
68
69#[cfg(feature = "client")]
70static SEQ: AtomicUsize = AtomicUsize::new(0); #[cfg(feature = "client")]
73static SERVER_SEQ: AtomicUsize = AtomicUsize::new(0); #[cfg(feature = "client")]
76static SERVER_ADDRESS: OnceLock<String> = OnceLock::new();
77
78#[cfg(feature = "client")]
79static MUTE: AtomicBool = AtomicBool::new(false); #[cfg(feature = "client")]
81static MUTED: LazyLock<Mutex<HashSet<usize>>> = LazyLock::new(|| Mutex::new(HashSet::new())); #[cfg(feature = "client")]
84static SOCKS5: AtomicBool = AtomicBool::new(false); pub fn get_server_username() -> String {
90 SERVER_USERNAME.get().unwrap().to_owned()
91}
92
93pub fn set_server_username(username: &str) {
95 SERVER_USERNAME.set(username.to_owned()).unwrap();
96}
97
98#[cfg(feature = "server")]
100pub fn enable_voice_chat() {
102 VOICE_CHAT.store(true, Ordering::Relaxed);
103}
104
105#[cfg(feature = "server")]
106pub fn voice_chat_enabled() -> bool {
108 VOICE_CHAT.load(Ordering::Relaxed)
109}
110
111#[cfg(feature = "client")]
113pub fn set_keys(keys: SharedKeys) {
115 let mut shared_key = KEYS.write().unwrap();
116 *shared_key = Some(keys);
117}
118
119#[cfg(feature = "client")]
120pub fn get_keys() -> Option<SharedKeys> {
122 let shared_key = KEYS.read().unwrap();
123 shared_key.clone()
124}
125
126#[cfg(feature = "client")]
128pub fn set_asking_password(value: bool) {
130 ASKING_PASSWORD.store(value, Ordering::Relaxed);
131}
132
133#[cfg(feature = "client")]
134pub fn get_asking_password() -> bool {
136 ASKING_PASSWORD.load(Ordering::Relaxed)
137}
138
139#[cfg(feature = "client")]
141pub fn set_extra_space(value: bool) {
143 EXTRA_SPACE.store(value, Ordering::Relaxed);
144}
145
146#[cfg(feature = "client")]
147pub fn get_extra_space() -> bool {
149 EXTRA_SPACE.load(Ordering::Relaxed)
150}
151
152#[cfg(feature = "client")]
154pub fn get_sending_messages() -> bool {
156 SENDING_MESSAGES.load(Ordering::Relaxed)
157}
158
159#[cfg(feature = "client")]
160pub fn set_sending_messages(value: bool) {
162 SENDING_MESSAGES.store(value, Ordering::Relaxed);
163}
164
165#[cfg(feature = "client")]
166pub fn get_seq() -> usize {
168 SEQ.load(Ordering::Relaxed)
169}
170
171#[cfg(feature = "client")]
172pub fn set_seq(value: usize) {
174 SEQ.store(value, Ordering::Relaxed)
175}
176
177#[cfg(feature = "client")]
178pub fn get_server_seq() -> usize {
180 SERVER_SEQ.load(Ordering::Relaxed)
181}
182
183#[cfg(feature = "client")]
184pub fn set_server_seq(value: usize) {
186 SERVER_SEQ.store(value, Ordering::Relaxed)
187}
188
189#[cfg(feature = "client")]
191pub fn get_server_address() -> String {
193 SERVER_ADDRESS.get().unwrap().to_owned()
194}
195
196#[cfg(feature = "client")]
197pub fn set_server_address(address: &str) {
199 SERVER_ADDRESS.set(address.to_owned()).unwrap();
200}
201
202#[cfg(feature = "client")]
204pub fn toggle_mute(id: Option<usize>) -> bool {
206 if let Some(id) = id {
208 let mut muted = MUTED.lock().unwrap();
209
210 if muted.remove(&id)
211 {
212 false
213 } else
214 {
215 muted.insert(id);
216 true
217 }
218
219 } else {
221 !MUTE.fetch_xor(true, Ordering::Relaxed)
222 }
223}
224
225#[cfg(feature = "client")]
226pub fn is_muted(id: Option<usize>) -> bool {
228 if let Some(id) = id
229 {
230 MUTED.lock().unwrap().contains(&id)
231 } else
232 {
233 MUTE.load(Ordering::Relaxed)
234 }
235}
236
237#[cfg(feature = "client")]
239pub fn enable_socks5() {
241 SOCKS5.store(true, Ordering::Relaxed);
242}
243
244#[cfg(feature = "client")]
245pub fn socks5_enabled() -> bool {
247 SOCKS5.load(Ordering::Relaxed)
248}