mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Enable premium, add custom avatar saving support to complete #10
This commit is contained in:
@@ -263,6 +263,7 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
|
||||
database: self.settings.server.database.clone(),
|
||||
auto_signup: self.settings.server.auto_signup,
|
||||
queue_mode: super::QueueChangeMode::from_persist(self.settings.server.queue_mode.clone()),
|
||||
cdn_url: self.settings.server.cdn_url.trim_end_matches('/').to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ pub struct ServerConfig {
|
||||
pub database: String,
|
||||
pub auto_signup: bool,
|
||||
pub queue_mode: QueueChangeMode,
|
||||
pub cdn_url: String,
|
||||
}
|
||||
|
||||
pub enum QueueChangeMode {
|
||||
|
||||
@@ -76,6 +76,8 @@ pub struct ServerSettings {
|
||||
pub auto_signup: bool,
|
||||
#[serde(default)]
|
||||
pub queue_mode: QueueMode,
|
||||
#[serde(default = "default_cdn_root_url")]
|
||||
pub cdn_url: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
@@ -95,5 +97,10 @@ fn default_server_conf() -> ServerSettings {
|
||||
database: default_db_conn(),
|
||||
auto_signup: false,
|
||||
queue_mode: QueueMode::Notify,
|
||||
cdn_url: default_cdn_root_url(),
|
||||
}
|
||||
}
|
||||
|
||||
fn default_cdn_root_url() -> String {
|
||||
"http://127.0.0.1:8010".to_owned()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ pub struct AccountProvider {
|
||||
cubes: std::sync::Arc<Vec<u32>>,
|
||||
garage_upgrades: std::sync::Arc<crate::persist::config::GarageUpgrades>,
|
||||
auto_signups: bool,
|
||||
secret: Vec<u8>,
|
||||
cdn: std::sync::Arc<String>,
|
||||
secret: std::sync::Arc<Vec<u8>>,
|
||||
db: std::sync::Arc<oj_rc_database::Database>,
|
||||
}
|
||||
|
||||
@@ -22,7 +23,8 @@ impl AccountProvider {
|
||||
cubes: std::sync::Arc::new(<crate::persist::config::ConfigImpl as ConfigProvider<()>>::ids(conf)),
|
||||
garage_upgrades: std::sync::Arc::new(<crate::persist::config::ConfigImpl as ConfigProvider<()>>::garage_upgrades(conf)),
|
||||
auto_signups: server_settings.auto_signup,
|
||||
secret: std::fs::read(&token_path)?,
|
||||
cdn: std::sync::Arc::new(server_settings.cdn_url),
|
||||
secret: std::sync::Arc::new(std::fs::read(&token_path)?),
|
||||
db: std::sync::Arc::new(db),
|
||||
})
|
||||
}
|
||||
@@ -100,7 +102,9 @@ impl <C: Clone> super::UserProvider<C> for AccountProvider {
|
||||
perms: user_perms,
|
||||
cubes: self.cubes.clone(),
|
||||
garage_upgrades: self.garage_upgrades.clone(),
|
||||
cdn: self.cdn.clone(),
|
||||
db: self.db.clone(),
|
||||
secret: self.secret.clone(),
|
||||
}))
|
||||
//Err("Unable to authenticate".to_string())
|
||||
}
|
||||
@@ -133,7 +137,9 @@ impl <C: Clone> super::UserProvider<C> for AccountProvider {
|
||||
perms: user_perms,
|
||||
cubes: self.cubes.clone(),
|
||||
garage_upgrades: self.garage_upgrades.clone(),
|
||||
cdn: self.cdn.clone(),
|
||||
db: self.db.clone(),
|
||||
secret: self.secret.clone(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -287,13 +293,14 @@ impl super::UserAuthenticator for AccountProvider {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct UserData {
|
||||
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>,
|
||||
db: std::sync::Arc<oj_rc_database::Database>,
|
||||
pub(super) struct UserData {
|
||||
pub(super) account: oj_rc_database::schema::user::Model,
|
||||
pub(super) perms: oj_rc_database::schema::permissions::Model,
|
||||
pub(super) cubes: std::sync::Arc<Vec<u32>>,
|
||||
pub(super) garage_upgrades: std::sync::Arc<crate::persist::config::GarageUpgrades>,
|
||||
pub(super) cdn: std::sync::Arc<String>,
|
||||
pub(super) db: std::sync::Arc<oj_rc_database::Database>,
|
||||
pub(super) secret: std::sync::Arc<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl UserData {
|
||||
@@ -1365,7 +1372,6 @@ impl super::LobbyUser for UserData {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl super::MultiplayerUser for UserData {
|
||||
// TODO
|
||||
fn user_id(&self) -> i32 {
|
||||
self.account.id
|
||||
}
|
||||
|
||||
28
rc_core/src/persist/user/intercom.rs
Normal file
28
rc_core/src/persist/user/intercom.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#[async_trait::async_trait]
|
||||
impl super::IntercomUser for super::account_json::UserData {
|
||||
async fn save_custom_avatar(&self, image: Vec<u8>) -> Result<(), polariton_server::operations::SimpleOpError> {
|
||||
// seems to always be jpg
|
||||
let token = generate_token(self.account.public_id.as_bytes(), &self.secret);
|
||||
let auth_header_val = format!("Internal {}", token);
|
||||
let url = format!("{}/customavatar/Live/{}", self.cdn, self.account.public_id);
|
||||
if let Err(e) = reqwest::Client::new().post(url)
|
||||
.header("Authorization", auth_header_val)
|
||||
.body(image)
|
||||
.send()
|
||||
.await {
|
||||
log::error!("Failed to update custom avatar for {} ({}): {}", self.account.public_id, self.account.id, e);
|
||||
return Err((crate::data::error_codes::WebServicesError::UnexpectedError as i16).into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_token(salt: &[u8], key: &[u8]) -> String {
|
||||
use sha2::{Digest, Sha512};
|
||||
let mut hasher = Sha512::new();
|
||||
hasher.update(salt);
|
||||
hasher.update(key);
|
||||
let token_bytes = hasher.finalize();
|
||||
hex::encode(&token_bytes[..])
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ 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, GameDescriptor, PlayerLobbyDescriptor, MultiplayerUser, MultiplayerError, MultiplayerErrorCode, PlayerDescriptor, GameEventSetter, CurrentGameEvent, AuthError};
|
||||
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, GameDescriptor, PlayerLobbyDescriptor, MultiplayerUser, MultiplayerError, MultiplayerErrorCode, PlayerDescriptor, GameEventSetter, CurrentGameEvent, AuthError, IntercomUser};
|
||||
|
||||
mod intercom;
|
||||
pub use intercom::generate_token as generate_intercom_token;
|
||||
|
||||
pub const TOKEN_SECRET_FILENAME: &str = "token_secret.key";
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ pub trait UserAuthenticator {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait User<C>: ChatUser + LobbyUser + MultiplayerUser {
|
||||
pub trait User<C>: ChatUser + LobbyUser + MultiplayerUser + IntercomUser {
|
||||
fn public_id(&self) -> &'_ str;
|
||||
fn is_mod(&self) -> bool;
|
||||
fn is_admin(&self) -> bool;
|
||||
@@ -328,3 +328,8 @@ pub trait MultiplayerUser {
|
||||
async fn complete_game(&self, guid: &str) -> Result<(), MultiplayerError>;
|
||||
async fn game_info(&self, guid: &str) -> Result<Option<GameDescriptor>, MultiplayerError>;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait IntercomUser {
|
||||
async fn save_custom_avatar(&self, image: Vec<u8>) -> Result<(), polariton_server::operations::SimpleOpError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user