mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Implement factory in main database, close #80
This commit is contained in:
@@ -149,8 +149,8 @@ impl std::convert::From<oj_rc_factory::VehicleQueryInfo> for ItemResult {
|
||||
combat_rating: value.combat_rating,
|
||||
cpu: value.cpu as i32,
|
||||
total_robot_ranking: value.total_robot_ranking as i32,
|
||||
//expiry_date: ticks_from_now(&value.expiry_date),
|
||||
expiry_date: i32::MAX as _,
|
||||
expiry_date: ticks_from_now(&value.expiry_date),
|
||||
//expiry_date: i32::MAX as _,
|
||||
buyable: value.buyable,
|
||||
added_by: value.added_by,
|
||||
added_by_display_name: value.added_by_display_name,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub enum Factory {
|
||||
Arc(oj_rc_factory::arc::ArcAdapter),
|
||||
Primary(oj_rc_database::FactoryDatabase),
|
||||
Custom(Box<dyn oj_rc_factory::VehicleFactoryAdapter + Send + Sync + 'static>),
|
||||
None,
|
||||
}
|
||||
@@ -9,6 +10,7 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn vehicle(&self, id: i32) -> Result<Option<(oj_rc_factory::VehicleInfo, oj_rc_factory::VehicleQueryInfo)>, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.vehicle(id).await,
|
||||
Self::Primary(x) => x.vehicle(id).await,
|
||||
Self::Custom(x) => x.vehicle(id).await,
|
||||
Self::None => Ok(None),
|
||||
}
|
||||
@@ -17,6 +19,7 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn list(&self, query: libfj::robocraft::ListQuery) -> Result<Vec<oj_rc_factory::VehicleQueryInfo>, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.list(query).await,
|
||||
Self::Primary(x) => x.list(query).await,
|
||||
Self::Custom(x) => x.list(query).await,
|
||||
Self::None => Ok(Vec::default()),
|
||||
}
|
||||
@@ -25,6 +28,7 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn upload(&self, vehicle: oj_rc_factory::VehicleUploadInfo) -> Result<oj_rc_factory::VehicleThumbnailInfo, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.upload(vehicle).await,
|
||||
Self::Primary(x) => x.upload(vehicle).await,
|
||||
Self::Custom(x) => x.upload(vehicle).await,
|
||||
Self::None => Ok(oj_rc_factory::VehicleThumbnailInfo {
|
||||
id: i32::MIN,
|
||||
@@ -37,6 +41,7 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn rate_vehicle(&self, id: i32, combat: i32, cosmetic: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.rate_vehicle(id, combat, cosmetic).await,
|
||||
Self::Primary(x) => x.rate_vehicle(id, combat, cosmetic).await,
|
||||
Self::Custom(x) => x.rate_vehicle(id, combat, cosmetic).await,
|
||||
Self::None => Ok(()),
|
||||
}
|
||||
@@ -45,6 +50,7 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn purchase(&self, id: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.purchase(id).await,
|
||||
Self::Primary(x) => x.purchase(id).await,
|
||||
Self::Custom(x) => x.purchase(id).await,
|
||||
Self::None => Ok(()),
|
||||
}
|
||||
@@ -53,14 +59,25 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn update_vehicle(&self, id: i32, cube_data: Option<Vec<u8>>, colour_data: Option<Vec<u8>>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.update_vehicle(id, cube_data, colour_data).await,
|
||||
Self::Primary(x) => x.update_vehicle(id, cube_data, colour_data).await,
|
||||
Self::Custom(x) => x.update_vehicle(id, cube_data, colour_data).await,
|
||||
Self::None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn remove_vehicle(&self, id: i32, user_id: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.remove_vehicle(id, user_id).await,
|
||||
Self::Primary(x) => x.remove_vehicle(id, user_id).await,
|
||||
Self::Custom(x) => x.remove_vehicle(id, user_id).await,
|
||||
Self::None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_featured(&self, id: i32, is_featured: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.set_featured(id, is_featured).await,
|
||||
Self::Primary(x) => x.set_featured(id, is_featured).await,
|
||||
Self::Custom(x) => x.set_featured(id, is_featured).await,
|
||||
Self::None => Ok(()),
|
||||
}
|
||||
@@ -68,9 +85,10 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
||||
}
|
||||
|
||||
impl Factory {
|
||||
pub async fn from_config(conf: &crate::persist::FactoryConfig, settings: &crate::persist::config::ServerConfig) -> Result<Self, Box<dyn std::error::Error + 'static>> {
|
||||
pub async fn from_config(conf: &crate::persist::FactoryConfig, settings: &crate::persist::config::ServerConfig, builtin_factory_provider: &(dyn (Fn() -> oj_rc_database::FactoryDatabase) + Sync)) -> Result<Self, Box<dyn std::error::Error + 'static>> {
|
||||
Ok(match &conf.adapter {
|
||||
crate::persist::AdapterSettings::Arc(x) => Self::Arc(oj_rc_factory::arc::ArcAdapter::init(&x.uri, x.show_expired, settings.cdn_url.to_owned(), x.override_cdn, x.spoof_username).await?),
|
||||
crate::persist::AdapterSettings::BuiltIn => Self::Primary(builtin_factory_provider()),
|
||||
crate::persist::AdapterSettings::None => Self::None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -310,8 +310,8 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
async fn factory(&self) -> Result<crate::factory::Factory, Box<dyn std::error::Error + 'static>> {
|
||||
crate::factory::Factory::from_config(&self.factory, &<Self as super::ConfigProvider<()>>::server_config(self)).await
|
||||
async fn factory(&self, builtin_factory_provider: &(dyn (Fn() -> oj_rc_database::FactoryDatabase) + Sync)) -> Result<crate::factory::Factory, Box<dyn std::error::Error + 'static>> {
|
||||
crate::factory::Factory::from_config(&self.factory, &<Self as super::ConfigProvider<()>>::server_config(self), builtin_factory_provider).await
|
||||
}
|
||||
|
||||
fn cubes(&self) -> &'_ indexmap::IndexMap<String, crate::persist::Cube> {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub trait ConfigProvider<C: Clone> {
|
||||
fn public_channels(&self) -> Typed<C>;
|
||||
fn server_config(&self) -> ServerConfig;
|
||||
fn garage_upgrades(&self) -> GarageUpgrades;
|
||||
async fn factory(&self) -> Result<crate::factory::Factory, Box<dyn std::error::Error + 'static>>;
|
||||
async fn factory(&self, builtin_factory_provider: &(dyn (Fn() -> oj_rc_database::FactoryDatabase) + Sync)) -> Result<crate::factory::Factory, Box<dyn std::error::Error + 'static>>;
|
||||
fn cubes(&self) -> &'_ indexmap::IndexMap<String, crate::persist::Cube>;
|
||||
fn chat_system_config(&self) -> ChatSystemConfig;
|
||||
fn gamemode_events(&self) -> GameEventSequence;
|
||||
|
||||
@@ -41,6 +41,10 @@ impl AccountProvider {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn factory_impl(&self) -> oj_rc_database::FactoryDatabase {
|
||||
self.db.vehicle_factory(self.cdn.clone())
|
||||
}
|
||||
|
||||
pub async fn multiplayer_init(&self) -> Result<(), oj_rc_database::sea_orm::DbErr> {
|
||||
self.db.complete_all_games().await
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ fn u64_negative_on_err<E>(result: Result<u64, E>) -> i64 {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl super::CommonUser for UserData {
|
||||
fn account_id(&self) -> i32 {
|
||||
self.account.id
|
||||
}
|
||||
|
||||
fn public_id(&self) -> &'_ str {
|
||||
&self.account.public_id
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ impl super::FactoryUser for UserData {
|
||||
thumbnail: vehicle.thumbnail,
|
||||
added_by: self.account.public_id.clone(),
|
||||
added_by_display_name: self.account.display_name.clone(),
|
||||
added_by_id: self.account.id,
|
||||
garage_id: slot.id,
|
||||
cpu: slot.total_robot_cpu as u32,
|
||||
total_robot_ranking: slot.total_robot_ranking as u32,
|
||||
build_version: vehicle.version,
|
||||
|
||||
@@ -410,6 +410,7 @@ pub struct ResolvedVehicle {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait CommonUser: Send + Sync {
|
||||
fn account_id(&self) -> i32;
|
||||
async fn resolve_config_vehicle(&self, vehicle: &crate::persist::config::VehicleInfo, factory: &dyn oj_rc_factory::VehicleFactoryAdapter, weapon_order: &crate::cubes::WeaponListParser, cpu_counter: &crate::cubes::CpuListParser) -> Result<ResolvedVehicle, polariton_server::operations::SimpleOpError>;
|
||||
fn public_id(&self) -> &'_ str;
|
||||
fn is_mod(&self) -> bool;
|
||||
|
||||
@@ -23,6 +23,8 @@ fn default_variant() -> AdapterSettings {
|
||||
pub enum AdapterSettings {
|
||||
#[serde(alias = "sqlite")]
|
||||
Arc(ArcFactorySettings),
|
||||
#[serde(alias = "integrated")]
|
||||
BuiltIn,
|
||||
None,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user