mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
44 lines
1.0 KiB
Rust
44 lines
1.0 KiB
Rust
use std::sync::{Arc, RwLock};
|
|
|
|
pub struct State {
|
|
pub crypto: Box<Arc<dyn polariton::packet::Cryptographer>>,
|
|
}
|
|
|
|
impl State {
|
|
pub fn new(c: Box<Arc<dyn polariton::packet::Cryptographer>>) -> Self {
|
|
Self {
|
|
crypto: c,
|
|
}
|
|
}
|
|
|
|
pub fn binrw_args(&self) -> polariton::packet::WriteArgs {
|
|
Some(self.crypto.clone())
|
|
}
|
|
|
|
pub fn user(&self) -> crate::UserTy {
|
|
RwLock::new(UserState::default())
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Debug)]
|
|
pub struct UserState {
|
|
pub uuid: String,
|
|
pub token: String,
|
|
pub refresh_token: String,
|
|
}
|
|
|
|
impl UserState {
|
|
pub fn update_with_auth(&mut self, auth_str: &str) -> bool {
|
|
let splits: Vec<&str> = auth_str.split(';').collect();
|
|
if splits.len() != 3 {
|
|
log::warn!("Invalid auth payload: {}", auth_str);
|
|
false
|
|
} else {
|
|
self.uuid = splits[0].to_owned();
|
|
self.token = splits[1].to_owned();
|
|
self.refresh_token = splits[2].to_owned();
|
|
true
|
|
}
|
|
}
|
|
}
|