1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Use elimination config from file instead of hardcoded #30

This commit is contained in:
NG (Graham)
2025-07-22 22:39:38 -04:00
parent fd11b8746b
commit a904423a83
5 changed files with 23 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ async fn main() -> std::io::Result<()> {
let users = std::sync::Arc::new(oj_rc_core::persist::user::UserImpl::load(&args.data, &config).await.expect("Bad user data"));
users.multiplayer_init().await.expect("Multiplayer init task failed");
let parsers = oj_rc_core::cubes::CubeParsers::new(&config);
let matches = matches::GameMatches::new();
let matches = matches::GameMatches::new(&config);
let matches_chann = matches.spawn();
let init_ctx = InitConfig {

View File

@@ -1,13 +1,15 @@
pub struct GameMatches {
matches: std::collections::HashMap<String, tokio::sync::mpsc::Sender<super::GameMessage>>,
routing: std::collections::HashMap<i32, String>, // user id to game guid
mode_configs: oj_rc_core::data::game_mode::GameModeConfigs,
}
impl GameMatches {
pub fn new() -> Self {
pub fn new(conf: &oj_rc_core::persist::config::ConfigImpl) -> Self {
Self {
matches: std::collections::HashMap::new(),
routing: std::collections::HashMap::new(),
mode_configs: <oj_rc_core::persist::config::ConfigImpl as oj_rc_core::ConfigProvider<()>>::gamemodes(conf),
}
}
@@ -19,7 +21,10 @@ impl GameMatches {
async fn start_new_match_engine(&self, _user: &Box<dyn oj_rc_core::persist::user::MultiplayerUser + Send + Sync + 'static>, guid: &str) -> tokio::sync::mpsc::Sender<super::GameMessage> {
// TODO figure out gamemode and act accordingly
let engine = super::GenericGamemodeEngine::new(guid.to_owned(), super::modes::EliminationLogic::new());
let engine = super::GenericGamemodeEngine::new(
guid.to_owned(),
super::modes::EliminationLogic::new(&self.mode_configs.elimination)
);
engine.spawn()
}

View File

@@ -49,19 +49,23 @@ impl PlayerTracker {
pub struct EliminationLogic {
tracked: PlayerTracker,
game_duration: std::time::Duration,
respawn_full_heal_duration: f32,
respawn_heal_duration: f32,
game_end: std::sync::atomic::AtomicI64,
timer_task: tokio::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
}
impl EliminationLogic {
pub fn new() -> Self {
let dur = std::time::Duration::from_secs(300);
pub fn new(config: &oj_rc_core::data::game_mode::GameModeConfig) -> Self {
let dur = std::time::Duration::from_secs((config.game_time_minutes as u64) * 60);
let fake_end = (chrono::Utc::now() + dur).timestamp();
Self {
tracked: PlayerTracker {
alive: tokio::sync::Mutex::new(std::collections::HashMap::new()),
},
game_duration: dur,
respawn_full_heal_duration: config.respawn_full_heal_duration,
respawn_heal_duration: config.respawn_heal_duration,
game_end: std::sync::atomic::AtomicI64::new(fake_end),
timer_task: tokio::sync::Mutex::new(None),
}
@@ -186,15 +190,15 @@ impl CustomGameLogic for EliminationLogic {
crate::matches::RlnlPacket {
event: rlnl::event_code::NetworkEvent::GameModeSettings,
property: literustlib::packet::Property::ReliableOrdered,
data: Box::new(rlnl::events::sync::UpdateGameModeSettings { // FIXME use value from config
respawn_heal_duration: 10.0,
respawn_full_heal_duration: 10.0,
data: Box::new(rlnl::events::sync::UpdateGameModeSettings {
respawn_heal_duration: self.respawn_heal_duration,
respawn_full_heal_duration: self.respawn_full_heal_duration,
}),
},
crate::matches::RlnlPacket {
event: rlnl::event_code::NetworkEvent::CurrentGameTime,
property: literustlib::packet::Property::ReliableOrdered,
data: Box::new(rlnl::events::GameTime(self.game_duration.as_millis() as f32 / 1000.0)), // FIXME use value from config
data: Box::new(rlnl::events::GameTime(self.game_duration.as_millis() as f32 / 1000.0)),
},
]
}