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

@@ -105,6 +105,19 @@ impl ItemTier {
ItemTier::T5 => "T5",
}
}
pub fn from_u32(num: u32) -> Option<Self> {
match num {
0 => Some(Self::NoTier),
100 => Some(Self::T0),
200 => Some(Self::T1),
300 => Some(Self::T2),
400 => Some(Self::T3),
500 => Some(Self::T4),
600 => Some(Self::T5),
_ => None,
}
}
}
#[derive(Clone, Copy)]

View File

@@ -361,7 +361,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Neptune3,
visibility: GameVisibility::Poor,
mode: GameType::BattleArena,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60, // 5 minutes
@@ -376,7 +376,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Mars1,
visibility: GameVisibility::Poor,
mode: GameType::Pit,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,
@@ -391,7 +391,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Mars1,
visibility: GameVisibility::Poor,
mode: GameType::TestMode,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,
@@ -406,7 +406,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Neptune3,
visibility: GameVisibility::Poor,
mode: GameType::BattleArena,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,
@@ -421,7 +421,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Mars1,
visibility: GameVisibility::Poor,
mode: GameType::Pit,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,
@@ -436,7 +436,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Mars1,
visibility: GameVisibility::Poor,
mode: GameType::TestMode,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,
@@ -451,7 +451,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Mars1,
visibility: GameVisibility::Poor,
mode: GameType::Pit,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,
@@ -466,7 +466,7 @@ fn default_rotation() -> GameEventSequence {
multiplayer: GameEvent {
map: GameMap::Mars1,
visibility: GameVisibility::Poor,
mode: GameType::TestMode,
mode: GameType::SuddenDeath,
auto_heal: true,
},
duration_s: 5*60,

View File

@@ -59,7 +59,7 @@ impl AccountProvider {
#[async_trait::async_trait]
impl <C: Clone> super::UserProvider<C> for AccountProvider {
async fn authenticate(&self, token: super::UserToken, ext: std::collections::HashMap<std::any::TypeId, Box<dyn std::any::Any + Send + Sync + 'static>>) -> Result<Box<dyn super::User<C> + Send + Sync>, String> {
async fn authenticate(&self, token: super::UserToken) -> Result<Box<dyn super::User<C> + Send + Sync>, String> {
//let new_root = self.root.join(&token.uuid);
let secret = jsonwebtoken::DecodingKey::from_secret(&self.secret);
let mut validation = jsonwebtoken::Validation::new(jsonwebtoken::Algorithm::HS256);
@@ -77,16 +77,34 @@ impl <C: Clone> super::UserProvider<C> for AccountProvider {
};
//let account_info = AccountInfo::load(&new_root).map_err(|e| e.to_string())?;
Ok(Box::new(UserData {
token,
account: user_info,
perms: user_perms,
cubes: self.cubes.clone(),
garage_upgrades: self.garage_upgrades.clone(),
extensions: ext,
db: self.db.clone(),
}))
//Err("Unable to authenticate".to_string())
}
async fn multiplayer_authenticate(&self, user: String) -> Result<Box<dyn super::User<C> + Send + Sync>, String> {
let user_info = if let Some(user_info) = self.db.user_by_display_name(user).await.map_err(|e| e.to_string())? {
user_info
} else {
return Err("User not found".to_owned());
};
let user_perms = if let Some(user_perms) = self.db.perms_by_user_id(user_info.id).await.map_err(|e| e.to_string())? {
user_perms
} else {
return Err("User permissions not found".to_owned());
};
Ok(Box::new(UserData {
account: user_info,
perms: user_perms,
cubes: self.cubes.clone(),
garage_upgrades: self.garage_upgrades.clone(),
db: self.db.clone(),
}))
}
}
#[async_trait::async_trait]
@@ -193,12 +211,10 @@ impl super::UserAuthenticator for AccountProvider {
#[allow(dead_code)]
struct UserData {
token: super::UserToken,
account: oj_rc_database::schema::user::Model,
perms: oj_rc_database::schema::permissions::Model,
cubes: std::sync::Arc<Vec<u32>>,
garage_upgrades: std::sync::Arc<crate::persist::config::GarageUpgrades>,
extensions: std::collections::HashMap<std::any::TypeId, Box<dyn std::any::Any + Send + Sync + 'static>>,
db: std::sync::Arc<oj_rc_database::Database>,
}
@@ -270,7 +286,7 @@ impl UserData {
log::error!("Failed to find selected vehicle for user_id {} (user_player_data)", self.account.id);
polariton_server::operations::SimpleOpError::with_message(INVALID_ROBOT_ERR, "No selected garage".to_owned())
})?;
let user_uuid = self.token.uuid.clone();
let user_uuid = self.account.public_id.clone();
let weapon_order = oj_rc_database::schema::parse_int_csv(&current_slot.weapon_order).into_iter().map(|x| x as i32).collect::<Vec<_>>();
let user_avatar_aux = self.db.user_aux_by_user_id_and_descriptor(self.account.id, oj_rc_database::schema::user_aux::Descriptor::AvatarId).await.map_err(|e| {
log::error!("Failed to retrieve avatar for user_id {} (user_player_data): {}", self.account.id, e);
@@ -442,12 +458,8 @@ const UNEXPECTED_ERR: i16 = crate::data::error_codes::WebServicesError::Unexpect
#[async_trait::async_trait]
impl <C: Clone> super::User<C> for UserData {
fn ext(&self, ty: std::any::TypeId) -> Option<&'_ (dyn std::any::Any + Send + Sync + 'static)> {
self.extensions.get(&ty).map(|x| x.as_ref())
}
fn token(&self) -> &'_ super::UserToken {
&self.token
fn public_id(&self) -> &'_ str {
&self.account.public_id
}
fn is_mod(&self) -> bool {
@@ -1108,3 +1120,19 @@ impl super::LobbyUser for UserData {
})
}
}
#[async_trait::async_trait]
impl super::MultiplayerUser for UserData {
// TODO
fn user_id(&self) -> i32 {
self.account.id
}
fn user_name(&self) -> &'_ str {
&self.account.public_id
}
fn display_name(&self) -> &'_ str {
&self.account.display_name
}
}

View File

@@ -11,7 +11,7 @@ mod inventory;
pub use inventory::UnlockedParts;
mod traits;
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData, ChatUser, AvatarInfo, GetAvatarInfo, ControlData, ControlType, CustomisationData, GetCustomisationData, SetSanction, SanctionType, LobbyUser};
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData, ChatUser, AvatarInfo, GetAvatarInfo, ControlData, ControlType, CustomisationData, GetCustomisationData, SetSanction, SanctionType, LobbyUser, MultiplayerUser};
pub const TOKEN_SECRET_FILENAME: &str = "token_secret.key";

View File

@@ -43,7 +43,9 @@ pub struct RegistrationInfo {
#[async_trait::async_trait]
pub trait UserProvider<C> {
async fn authenticate(&self, user: UserToken, ext: std::collections::HashMap<std::any::TypeId, Box<dyn std::any::Any + Send + Sync + 'static>>) -> Result<Box<dyn User<C> + Send + Sync>, String>;
async fn authenticate(&self, user: UserToken) -> Result<Box<dyn User<C> + Send + Sync>, String>;
async fn multiplayer_authenticate(&self, user: String) -> Result<Box<dyn User<C> + Send + Sync>, String>;
}
#[async_trait::async_trait]
@@ -54,9 +56,8 @@ pub trait UserAuthenticator {
}
#[async_trait::async_trait]
pub trait User<C>: ChatUser + LobbyUser {
fn ext(&self, ty: std::any::TypeId) -> Option<&'_ (dyn std::any::Any + Send + Sync + 'static)>;
fn token(&self) -> &'_ super::UserToken;
pub trait User<C>: ChatUser + LobbyUser + MultiplayerUser {
fn public_id(&self) -> &'_ str;
fn is_mod(&self) -> bool;
fn is_admin(&self) -> bool;
fn is_dev(&self) -> bool;
@@ -230,3 +231,11 @@ impl SanctionType {
pub trait LobbyUser {
async fn player_data(&self) -> Result<crate::data::player_data::PlayerData, polariton_server::operations::SimpleOpError>;
}
#[async_trait::async_trait]
pub trait MultiplayerUser {
// TODO
fn user_id(&self) -> i32;
fn user_name(&self) -> &'_ str;
fn display_name(&self) -> &'_ str;
}

View File

@@ -27,12 +27,12 @@ impl <C: Clone + Send + 'static> UserState<C> {
token: splits[1].to_owned(),
refresh_token: splits[2].to_owned(),
};
let ext = if let Some(ext) = ext_f(&token) {
ext
if let Some(ext) = ext_f(&token) {
log::debug!("Ignoring extra auth info: {:?}", ext);
} else {
return false;
};
match auth.authenticate(token, ext).await {
}
match auth.authenticate(token).await {
Ok(user) => {
let mut lock = self.state.write().unwrap();
*lock = InitState::Authenticated(std::sync::Arc::new(user));