From ee5c67c092acc57a6ef2b8f7934ba827df43add6 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 30 Jul 2022 17:03:32 +0200 Subject: [PATCH] add is_public to matches --- .../2022-07-30-145155_add_public_to_matches/down.sql | 1 + .../2022-07-30-145155_add_public_to_matches/up.sql | 1 + planetwars-server/src/db/matches.rs | 2 ++ planetwars-server/src/modules/client_api.rs | 1 + planetwars-server/src/modules/matches.rs | 10 +++++++++- planetwars-server/src/modules/ranking.rs | 2 +- planetwars-server/src/routes/demo.rs | 1 + planetwars-server/src/schema.rs | 1 + 8 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/down.sql create mode 100644 planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/up.sql diff --git a/planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/down.sql b/planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/down.sql new file mode 100644 index 0000000..7a0c0bf --- /dev/null +++ b/planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/down.sql @@ -0,0 +1 @@ +ALTER TABLE matches DROP COLUMN is_public; diff --git a/planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/up.sql b/planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/up.sql new file mode 100644 index 0000000..714de8c --- /dev/null +++ b/planetwars-server/migrations/2022-07-30-145155_add_public_to_matches/up.sql @@ -0,0 +1 @@ +ALTER TABLE matches ADD COLUMN is_public boolean NOT NULL DEFAULT false; diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index 061e2ea..be2a8be 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -15,6 +15,7 @@ use super::bots::{Bot, BotVersion}; pub struct NewMatch<'a> { pub state: MatchState, pub log_path: &'a str, + pub is_public: bool, } #[derive(Insertable)] @@ -36,6 +37,7 @@ pub struct MatchBase { pub log_path: String, pub created_at: NaiveDateTime, pub winner: Option, + pub is_public: bool, } #[derive(Queryable, Identifiable, Associations, Clone)] diff --git a/planetwars-server/src/modules/client_api.rs b/planetwars-server/src/modules/client_api.rs index 7026671..f960e1b 100644 --- a/planetwars-server/src/modules/client_api.rs +++ b/planetwars-server/src/modules/client_api.rs @@ -119,6 +119,7 @@ impl pb::client_api_service_server::ClientApiService for ClientApiServer { }); let run_match = RunMatch::from_players( self.runner_config.clone(), + false, vec![ MatchPlayer::BotSpec { spec: remote_bot_spec, diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs index 4f538ed..3826abd 100644 --- a/planetwars-server/src/modules/matches.rs +++ b/planetwars-server/src/modules/matches.rs @@ -17,6 +17,7 @@ pub struct RunMatch { log_file_name: String, players: Vec, config: Arc, + is_public: bool, } pub enum MatchPlayer { @@ -30,12 +31,18 @@ pub enum MatchPlayer { } impl RunMatch { - pub fn from_players(config: Arc, players: Vec) -> Self { + // TODO: create a MatchParams struct + pub fn from_players( + config: Arc, + is_public: bool, + players: Vec, + ) -> Self { let log_file_name = format!("{}.log", gen_alphanumeric(16)); RunMatch { config, log_file_name, players, + is_public, } } @@ -80,6 +87,7 @@ impl RunMatch { let new_match_data = db::matches::NewMatch { state: db::matches::MatchState::Playing, log_path: &self.log_file_name, + is_public: self.is_public, }; let new_match_players = self .players diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index cb699fe..dff3a72 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -53,7 +53,7 @@ async fn play_ranking_match( players.push(player); } - let (_, handle) = RunMatch::from_players(config, players) + let (_, handle) = RunMatch::from_players(config, true, players) .run(db_pool.clone()) .await .expect("failed to run match"); diff --git a/planetwars-server/src/routes/demo.rs b/planetwars-server/src/routes/demo.rs index dad9453..82a9082 100644 --- a/planetwars-server/src/routes/demo.rs +++ b/planetwars-server/src/routes/demo.rs @@ -50,6 +50,7 @@ pub async fn submit_bot( let run_match = RunMatch::from_players( config, + false, vec![ MatchPlayer::BotVersion { bot: None, diff --git a/planetwars-server/src/schema.rs b/planetwars-server/src/schema.rs index 5993115..70889b1 100644 --- a/planetwars-server/src/schema.rs +++ b/planetwars-server/src/schema.rs @@ -47,6 +47,7 @@ table! { log_path -> Text, created_at -> Timestamp, winner -> Nullable, + is_public -> Bool, } }