mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Make enemy and teammate count customizable
This commit is contained in:
@@ -11,7 +11,7 @@ use polariton::packet::{Data, Message, Packet, StandardMessage};
|
||||
use polariton::operation::{OperationResponse, Typed};
|
||||
|
||||
pub struct InitConfig {
|
||||
pub cubes: rc_core::persist::config::ConfigImpl,
|
||||
pub config: rc_core::persist::config::ConfigImpl,
|
||||
pub users: std::sync::Arc<rc_core::persist::user::UserImpl>,
|
||||
pub factory: std::sync::Arc<rc_core::factory::Factory>,
|
||||
pub parsers: rc_core::cubes::CubeParsers,
|
||||
@@ -25,13 +25,13 @@ async fn main() -> std::io::Result<()> {
|
||||
let args = cli::CliArgs::get();
|
||||
log::debug!("Got cli args {:?}", args);
|
||||
|
||||
let cubes = rc_core::persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(rc_core::persist::user::UserImpl::load(&args.data, &cubes).await.expect("Bad user data"));
|
||||
let factory = std::sync::Arc::new(<rc_core::persist::config::ConfigImpl as rc_core::ConfigProvider<()>>::factory::<'_, '_>(&cubes).await.expect("Bad vehicle factory (CRF) config"));
|
||||
let parsers = rc_core::cubes::CubeParsers::new(&cubes);
|
||||
let config = rc_core::persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(rc_core::persist::user::UserImpl::load(&args.data, &config).await.expect("Bad user data"));
|
||||
let factory = std::sync::Arc::new(<rc_core::persist::config::ConfigImpl as rc_core::ConfigProvider<()>>::factory::<'_, '_>(&config).await.expect("Bad vehicle factory (CRF) config"));
|
||||
let parsers = rc_core::cubes::CubeParsers::new(&config);
|
||||
|
||||
let init_ctx = InitConfig {
|
||||
cubes,
|
||||
config,
|
||||
users,
|
||||
factory,
|
||||
parsers,
|
||||
|
||||
@@ -4,23 +4,25 @@ const CODE: u8 = 1;
|
||||
|
||||
const PARAM_KEY: u8 = 8;
|
||||
|
||||
pub(super) fn tdm_machines_provider(factory: &std::sync::Arc<rc_core::factory::Factory>, weapon_order: std::sync::Arc<rc_core::cubes::WeaponListParser>) -> AiRobots {
|
||||
pub(super) fn tdm_machines_provider(factory: &std::sync::Arc<rc_core::factory::Factory>, weapon_order: std::sync::Arc<rc_core::cubes::WeaponListParser>, conf: &rc_core::ConfigImpl) -> AiRobots {
|
||||
AiRobots {
|
||||
factory: factory.to_owned(),
|
||||
weapon_parser: weapon_order,
|
||||
singleplayer_config: <rc_core::ConfigImpl as rc_core::ConfigProvider<()>>::singleplayer_details(conf),
|
||||
}
|
||||
}
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory: &rc_core::factory::Factory, weapon_order: &rc_core::cubes::WeaponListParser) -> Result<ParameterTable<()>, i16> {
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory: &rc_core::factory::Factory, weapon_order: &rc_core::cubes::WeaponListParser, singleplayer_conf: &rc_core::persist::config::SingleplayerConfig) -> Result<ParameterTable<()>, i16> {
|
||||
let ulock = user.user()?;
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, ulock.singleplayer_robots(factory, weapon_order).await?);
|
||||
params.insert(PARAM_KEY, ulock.singleplayer_robots(factory, weapon_order, singleplayer_conf).await?);
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct AiRobots {
|
||||
factory: std::sync::Arc<rc_core::factory::Factory>,
|
||||
weapon_parser: std::sync::Arc<rc_core::cubes::WeaponListParser>,
|
||||
singleplayer_config: rc_core::persist::config::SingleplayerConfig,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -28,7 +30,7 @@ impl polariton_server::operations::Operation<()> for AiRobots {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_handling(params, user, self.factory.as_ref(), self.weapon_parser.as_ref()).await)
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_handling(params, user, self.factory.as_ref(), self.weapon_parser.as_ref(), &self.singleplayer_config).await)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.modify(rc_core::polariton::OpIdCopy)
|
||||
.add(more_auth::MoreLobbyAuth)
|
||||
.add(eac::EacChallengeIgnorer)
|
||||
.add(load_ai_robots::tdm_machines_provider(&init_ctx.factory, init_ctx.parsers.weapon_order()))
|
||||
.add(load_ai_robots::tdm_machines_provider(&init_ctx.factory, init_ctx.parsers.weapon_order(), &init_ctx.config))
|
||||
//.add(polariton_server::operations::Ack::<33, _>::default()) // get user clan info (this is equivalent to not being in a clan)
|
||||
.add(polariton_server::operations::Ack::<2, _>::default()) // Save singleplayer result (parameter-less response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user