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:
@@ -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