1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Get part way through loading (to sync) #30

This commit is contained in:
NG (Graham)
2025-07-06 17:36:52 -04:00
parent 38ab4ba799
commit 1d404db209
31 changed files with 1049 additions and 100 deletions

View File

@@ -3,27 +3,61 @@ pub struct User {
}
impl User {
pub fn new() -> Self {
pub fn new(provider: std::sync::Arc<oj_rc_core::persist::user::UserImpl>) -> Self {
Self {
state: tokio::sync::RwLock::new(UserState::Connecting),
state: tokio::sync::RwLock::new(UserState::Unauthenticated(provider)),
}
}
pub async fn authenticate(&self, info: rlnl::events::loading::GameGuidInfo) -> bool {
*self.state.write().await = UserState::Authenticated(UserInfo {
game: info.game_guid.0,
username: info.player_name.0,
});
true
let init_state_clone = self.state.read().await.clone();
match init_state_clone {
UserState::Unauthenticated(auth) => {
let result = <oj_rc_core::persist::user::UserImpl as oj_rc_core::UserProvider<()>>::multiplayer_authenticate::<'_, '_>(&auth, info.player_name.0.clone()).await;
match result {
Ok(user) => {
*self.state.write().await = UserState::Authenticated(UserInfo {
game: info.game_guid.0,
user: std::sync::Arc::new(user),
});
true
},
Err(e) => {
log::error!("Failed to authenticate {}: {}", info.player_name.0, e);
false
}
}
},
UserState::Authenticated(_) => {
log::warn!("User already authenticated, ignoring");
true
}
}
}
pub async fn user(&self) -> Option<std::sync::Arc<Box<dyn oj_rc_core::persist::user::MultiplayerUser + Send + Sync>>> {
match &*self.state.read().await {
UserState::Unauthenticated(_) => None,
UserState::Authenticated(user) => Some(user.user.clone()),
}
}
pub async fn game_guid(&self) -> Option<String> {
match &*self.state.read().await {
UserState::Unauthenticated(_) => None,
UserState::Authenticated(user) => Some(user.game.clone()),
}
}
}
#[derive(Clone)]
enum UserState {
Connecting,
Unauthenticated(std::sync::Arc<oj_rc_core::persist::user::UserImpl>),
Authenticated(UserInfo),
}
#[derive(Clone)]
pub struct UserInfo {
pub game: String,
pub username: String,
pub user: std::sync::Arc<Box<dyn oj_rc_core::persist::user::MultiplayerUser + Send + Sync>>,
}