aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/modules/matches.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-08-26 19:21:30 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-08-26 19:21:30 +0200
commite26f13c8bba24e6f966888d5909f2803665c55a0 (patch)
tree6d156e0dd18d695103d00d12111ee26e73e8d3a0 /planetwars-server/src/modules/matches.rs
parent624fa99fad0d41bfbd0f249ab054745a990a5d8c (diff)
downloadplanetwars.dev-e26f13c8bba24e6f966888d5909f2803665c55a0.tar.xz
planetwars.dev-e26f13c8bba24e6f966888d5909f2803665c55a0.zip
add maps to matches api
Diffstat (limited to 'planetwars-server/src/modules/matches.rs')
-rw-r--r--planetwars-server/src/modules/matches.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs
index 3826abd..ecc7976 100644
--- a/planetwars-server/src/modules/matches.rs
+++ b/planetwars-server/src/modules/matches.rs
@@ -7,6 +7,7 @@ use tokio::task::JoinHandle;
use crate::{
db::{
self,
+ maps::Map,
matches::{MatchData, MatchResult},
},
util::gen_alphanumeric,
@@ -18,6 +19,10 @@ pub struct RunMatch {
players: Vec<MatchPlayer>,
config: Arc<GlobalConfig>,
is_public: bool,
+ // Map is mandatory for now.
+ // It would be nice to allow "anonymous" (eg. randomly generated) maps
+ // in the future, too.
+ map: Map,
}
pub enum MatchPlayer {
@@ -32,9 +37,10 @@ pub enum MatchPlayer {
impl RunMatch {
// TODO: create a MatchParams struct
- pub fn from_players(
+ pub fn new(
config: Arc<GlobalConfig>,
is_public: bool,
+ map: Map,
players: Vec<MatchPlayer>,
) -> Self {
let log_file_name = format!("{}.log", gen_alphanumeric(16));
@@ -43,13 +49,14 @@ impl RunMatch {
log_file_name,
players,
is_public,
+ map,
}
}
fn into_runner_config(self) -> runner::MatchConfig {
runner::MatchConfig {
- map_path: PathBuf::from(&self.config.maps_directory).join("hex.json"),
- map_name: "hex".to_string(),
+ map_path: PathBuf::from(&self.config.maps_directory).join(self.map.file_path),
+ map_name: self.map.name,
log_path: PathBuf::from(&self.config.match_logs_directory).join(&self.log_file_name),
players: self
.players
@@ -88,6 +95,7 @@ impl RunMatch {
state: db::matches::MatchState::Playing,
log_path: &self.log_file_name,
is_public: self.is_public,
+ map_id: Some(self.map.id),
};
let new_match_players = self
.players