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:
@@ -304,6 +304,10 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gamemodes(&self) -> crate::data::game_mode::GameModeConfigs {
|
||||||
|
self.battle.games.clone().into()
|
||||||
|
}
|
||||||
|
|
||||||
fn singleplayer_details(&self) -> super::SingleplayerConfig {
|
fn singleplayer_details(&self) -> super::SingleplayerConfig {
|
||||||
self.battle.singleplayer.into_singleplayer_conf()
|
self.battle.singleplayer.into_singleplayer_conf()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub trait ConfigProvider<C: Clone> {
|
|||||||
fn cubes(&self) -> &'_ std::collections::HashMap<String, crate::persist::Cube>;
|
fn cubes(&self) -> &'_ std::collections::HashMap<String, crate::persist::Cube>;
|
||||||
fn chat_system_config(&self) -> ChatSystemConfig;
|
fn chat_system_config(&self) -> ChatSystemConfig;
|
||||||
fn gamemode_events(&self) -> GameEventSequence;
|
fn gamemode_events(&self) -> GameEventSequence;
|
||||||
|
fn gamemodes(&self) -> crate::data::game_mode::GameModeConfigs; // FIXME
|
||||||
fn singleplayer_details(&self) -> SingleplayerConfig;
|
fn singleplayer_details(&self) -> SingleplayerConfig;
|
||||||
fn players_per_game(&self) -> usize;
|
fn players_per_game(&self) -> usize;
|
||||||
fn is_multiplayer_enabled(&self) -> bool;
|
fn is_multiplayer_enabled(&self) -> bool;
|
||||||
|
|||||||
@@ -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"));
|
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");
|
users.multiplayer_init().await.expect("Multiplayer init task failed");
|
||||||
let parsers = oj_rc_core::cubes::CubeParsers::new(&config);
|
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 matches_chann = matches.spawn();
|
||||||
|
|
||||||
let init_ctx = InitConfig {
|
let init_ctx = InitConfig {
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
pub struct GameMatches {
|
pub struct GameMatches {
|
||||||
matches: std::collections::HashMap<String, tokio::sync::mpsc::Sender<super::GameMessage>>,
|
matches: std::collections::HashMap<String, tokio::sync::mpsc::Sender<super::GameMessage>>,
|
||||||
routing: std::collections::HashMap<i32, String>, // user id to game guid
|
routing: std::collections::HashMap<i32, String>, // user id to game guid
|
||||||
|
mode_configs: oj_rc_core::data::game_mode::GameModeConfigs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameMatches {
|
impl GameMatches {
|
||||||
pub fn new() -> Self {
|
pub fn new(conf: &oj_rc_core::persist::config::ConfigImpl) -> Self {
|
||||||
Self {
|
Self {
|
||||||
matches: std::collections::HashMap::new(),
|
matches: std::collections::HashMap::new(),
|
||||||
routing: 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> {
|
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
|
// 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()
|
engine.spawn()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,19 +49,23 @@ impl PlayerTracker {
|
|||||||
pub struct EliminationLogic {
|
pub struct EliminationLogic {
|
||||||
tracked: PlayerTracker,
|
tracked: PlayerTracker,
|
||||||
game_duration: std::time::Duration,
|
game_duration: std::time::Duration,
|
||||||
|
respawn_full_heal_duration: f32,
|
||||||
|
respawn_heal_duration: f32,
|
||||||
game_end: std::sync::atomic::AtomicI64,
|
game_end: std::sync::atomic::AtomicI64,
|
||||||
timer_task: tokio::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
|
timer_task: tokio::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EliminationLogic {
|
impl EliminationLogic {
|
||||||
pub fn new() -> Self {
|
pub fn new(config: &oj_rc_core::data::game_mode::GameModeConfig) -> Self {
|
||||||
let dur = std::time::Duration::from_secs(300);
|
let dur = std::time::Duration::from_secs((config.game_time_minutes as u64) * 60);
|
||||||
let fake_end = (chrono::Utc::now() + dur).timestamp();
|
let fake_end = (chrono::Utc::now() + dur).timestamp();
|
||||||
Self {
|
Self {
|
||||||
tracked: PlayerTracker {
|
tracked: PlayerTracker {
|
||||||
alive: tokio::sync::Mutex::new(std::collections::HashMap::new()),
|
alive: tokio::sync::Mutex::new(std::collections::HashMap::new()),
|
||||||
},
|
},
|
||||||
game_duration: dur,
|
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),
|
game_end: std::sync::atomic::AtomicI64::new(fake_end),
|
||||||
timer_task: tokio::sync::Mutex::new(None),
|
timer_task: tokio::sync::Mutex::new(None),
|
||||||
}
|
}
|
||||||
@@ -186,15 +190,15 @@ impl CustomGameLogic for EliminationLogic {
|
|||||||
crate::matches::RlnlPacket {
|
crate::matches::RlnlPacket {
|
||||||
event: rlnl::event_code::NetworkEvent::GameModeSettings,
|
event: rlnl::event_code::NetworkEvent::GameModeSettings,
|
||||||
property: literustlib::packet::Property::ReliableOrdered,
|
property: literustlib::packet::Property::ReliableOrdered,
|
||||||
data: Box::new(rlnl::events::sync::UpdateGameModeSettings { // FIXME use value from config
|
data: Box::new(rlnl::events::sync::UpdateGameModeSettings {
|
||||||
respawn_heal_duration: 10.0,
|
respawn_heal_duration: self.respawn_heal_duration,
|
||||||
respawn_full_heal_duration: 10.0,
|
respawn_full_heal_duration: self.respawn_full_heal_duration,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
crate::matches::RlnlPacket {
|
crate::matches::RlnlPacket {
|
||||||
event: rlnl::event_code::NetworkEvent::CurrentGameTime,
|
event: rlnl::event_code::NetworkEvent::CurrentGameTime,
|
||||||
property: literustlib::packet::Property::ReliableOrdered,
|
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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user