diff options
Diffstat (limited to 'planetwars-server/src')
-rw-r--r-- | planetwars-server/src/db/bots.rs | 8 | ||||
-rw-r--r-- | planetwars-server/src/db/matches.rs | 12 | ||||
-rw-r--r-- | planetwars-server/src/modules/bot_api.rs | 2 | ||||
-rw-r--r-- | planetwars-server/src/modules/bots.rs | 2 | ||||
-rw-r--r-- | planetwars-server/src/modules/matches.rs | 4 | ||||
-rw-r--r-- | planetwars-server/src/modules/ranking.rs | 2 | ||||
-rw-r--r-- | planetwars-server/src/routes/bots.rs | 8 | ||||
-rw-r--r-- | planetwars-server/src/routes/demo.rs | 14 | ||||
-rw-r--r-- | planetwars-server/src/routes/matches.rs | 4 | ||||
-rw-r--r-- | planetwars-server/src/schema.rs | 4 |
10 files changed, 30 insertions, 30 deletions
diff --git a/planetwars-server/src/db/bots.rs b/planetwars-server/src/db/bots.rs index 964deaa..53c11b1 100644 --- a/planetwars-server/src/db/bots.rs +++ b/planetwars-server/src/db/bots.rs @@ -51,7 +51,7 @@ pub struct NewCodeBundle<'a> { } #[derive(Queryable, Serialize, Deserialize, Debug)] -pub struct CodeBundle { +pub struct BotVersion { pub id: i32, pub bot_id: Option<i32>, pub code_bundle_path: Option<String>, @@ -62,19 +62,19 @@ pub struct CodeBundle { pub fn create_code_bundle( new_code_bundle: &NewCodeBundle, conn: &PgConnection, -) -> QueryResult<CodeBundle> { +) -> QueryResult<BotVersion> { diesel::insert_into(bot_versions::table) .values(new_code_bundle) .get_result(conn) } -pub fn find_bot_code_bundles(bot_id: i32, conn: &PgConnection) -> QueryResult<Vec<CodeBundle>> { +pub fn find_bot_versions(bot_id: i32, conn: &PgConnection) -> QueryResult<Vec<BotVersion>> { bot_versions::table .filter(bot_versions::bot_id.eq(bot_id)) .get_results(conn) } -pub fn active_code_bundle(bot_id: i32, conn: &PgConnection) -> QueryResult<CodeBundle> { +pub fn active_bot_version(bot_id: i32, conn: &PgConnection) -> QueryResult<BotVersion> { bot_versions::table .filter(bot_versions::bot_id.eq(bot_id)) .order(bot_versions::created_at.desc()) diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index d9d893c..6590a37 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -8,7 +8,7 @@ use diesel::{Connection, GroupedBy, PgConnection, QueryResult}; use crate::schema::{bot_versions, bots, match_players, matches}; -use super::bots::{Bot, CodeBundle}; +use super::bots::{Bot, BotVersion}; #[derive(Insertable)] #[table_name = "matches"] @@ -25,7 +25,7 @@ pub struct NewMatchPlayer { /// player id within the match pub player_id: i32, /// id of the bot behind this player - pub code_bundle_id: Option<i32>, + pub bot_version_id: Option<i32>, } #[derive(Queryable, Identifiable)] @@ -67,7 +67,7 @@ pub fn create_match( .map(|(num, player_data)| NewMatchPlayer { match_id: match_base.id, player_id: num as i32, - code_bundle_id: player_data.code_bundle_id, + bot_version_id: player_data.code_bundle_id, }) .collect::<Vec<_>>(); @@ -94,7 +94,7 @@ pub fn list_matches(conn: &PgConnection) -> QueryResult<Vec<FullMatchData>> { let match_players = MatchPlayer::belonging_to(&matches) .left_join( bot_versions::table - .on(match_players::code_bundle_id.eq(bot_versions::id.nullable())), + .on(match_players::bot_version_id.eq(bot_versions::id.nullable())), ) .left_join(bots::table.on(bot_versions::bot_id.eq(bots::id.nullable()))) .load::<FullMatchPlayerData>(conn)? @@ -123,7 +123,7 @@ pub struct FullMatchData { // #[primary_key(base.match_id, base::player_id)] pub struct FullMatchPlayerData { pub base: MatchPlayer, - pub code_bundle: Option<CodeBundle>, + pub bot_version: Option<BotVersion>, pub bot: Option<Bot>, } @@ -147,7 +147,7 @@ pub fn find_match(id: i32, conn: &PgConnection) -> QueryResult<FullMatchData> { let match_players = MatchPlayer::belonging_to(&match_base) .left_join( bot_versions::table - .on(match_players::code_bundle_id.eq(bot_versions::id.nullable())), + .on(match_players::bot_version_id.eq(bot_versions::id.nullable())), ) .left_join(bots::table.on(bot_versions::bot_id.eq(bots::id.nullable()))) .load::<FullMatchPlayerData>(conn)?; diff --git a/planetwars-server/src/modules/bot_api.rs b/planetwars-server/src/modules/bot_api.rs index 0ecbf71..6324010 100644 --- a/planetwars-server/src/modules/bot_api.rs +++ b/planetwars-server/src/modules/bot_api.rs @@ -104,7 +104,7 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer { let opponent = db::bots::find_bot_by_name(&match_request.opponent_name, &conn) .map_err(|_| Status::not_found("opponent not found"))?; - let opponent_code_bundle = db::bots::active_code_bundle(opponent.id, &conn) + let opponent_code_bundle = db::bots::active_bot_version(opponent.id, &conn) .map_err(|_| Status::not_found("opponent has no code"))?; let player_key = gen_alphanumeric(32); diff --git a/planetwars-server/src/modules/bots.rs b/planetwars-server/src/modules/bots.rs index ddc1589..cd26ee0 100644 --- a/planetwars-server/src/modules/bots.rs +++ b/planetwars-server/src/modules/bots.rs @@ -8,7 +8,7 @@ pub fn save_code_bundle( bot_code: &str, bot_id: Option<i32>, conn: &PgConnection, -) -> QueryResult<db::bots::CodeBundle> { +) -> QueryResult<db::bots::BotVersion> { let bundle_name = gen_alphanumeric(16); let code_bundle_dir = PathBuf::from(BOTS_DIR).join(&bundle_name); diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs index 7d6a1dc..4a5a980 100644 --- a/planetwars-server/src/modules/matches.rs +++ b/planetwars-server/src/modules/matches.rs @@ -29,7 +29,7 @@ pub struct MatchPlayer { } impl MatchPlayer { - pub fn from_code_bundle(code_bundle: &db::bots::CodeBundle) -> Self { + pub fn from_code_bundle(code_bundle: &db::bots::BotVersion) -> Self { MatchPlayer { bot_spec: code_bundle_to_botspec(code_bundle), code_bundle_id: Some(code_bundle.id), @@ -97,7 +97,7 @@ impl RunMatch { } } -pub fn code_bundle_to_botspec(code_bundle: &db::bots::CodeBundle) -> Box<dyn BotSpec> { +pub fn code_bundle_to_botspec(code_bundle: &db::bots::BotVersion) -> Box<dyn BotSpec> { // TODO: get rid of this unwrap let bundle_path = PathBuf::from(BOTS_DIR).join(code_bundle.code_bundle_path.as_ref().unwrap()); diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index b1ad0da..751c35e 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -39,7 +39,7 @@ async fn play_ranking_match(selected_bots: Vec<Bot>, db_pool: DbPool) { let db_conn = db_pool.get().await.expect("could not get db pool"); let mut code_bundles = Vec::new(); for bot in &selected_bots { - let code_bundle = db::bots::active_code_bundle(bot.id, &db_conn) + let code_bundle = db::bots::active_bot_version(bot.id, &db_conn) .expect("could not get active code bundle"); code_bundles.push(code_bundle); } diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs index 6d5d7df..1ffedef 100644 --- a/planetwars-server/src/routes/bots.rs +++ b/planetwars-server/src/routes/bots.rs @@ -11,7 +11,7 @@ use std::io::Cursor; use std::path::PathBuf; use thiserror; -use crate::db::bots::{self, CodeBundle}; +use crate::db::bots::{self, BotVersion}; use crate::db::ratings::{self, RankedBot}; use crate::db::users::User; use crate::modules::bots::save_code_bundle; @@ -148,8 +148,8 @@ pub async fn get_bot( Path(bot_id): Path<i32>, ) -> Result<Json<JsonValue>, StatusCode> { let bot = bots::find_bot(bot_id, &conn).map_err(|_| StatusCode::NOT_FOUND)?; - let bundles = bots::find_bot_code_bundles(bot.id, &conn) - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + let bundles = + bots::find_bot_versions(bot.id, &conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; Ok(Json(json!({ "bot": bot, "bundles": bundles, @@ -183,7 +183,7 @@ pub async fn upload_code_multipart( user: User, Path(bot_id): Path<i32>, mut multipart: Multipart, -) -> Result<Json<CodeBundle>, StatusCode> { +) -> Result<Json<BotVersion>, StatusCode> { let bots_dir = PathBuf::from(BOTS_DIR); let bot = bots::find_bot(bot_id, &conn).map_err(|_| StatusCode::NOT_FOUND)?; diff --git a/planetwars-server/src/routes/demo.rs b/planetwars-server/src/routes/demo.rs index 33dc02d..1747bfe 100644 --- a/planetwars-server/src/routes/demo.rs +++ b/planetwars-server/src/routes/demo.rs @@ -39,16 +39,16 @@ pub async fn submit_bot( let opponent = db::bots::find_bot_by_name(&opponent_name, &conn).map_err(|_| StatusCode::BAD_REQUEST)?; - let opponent_code_bundle = - db::bots::active_code_bundle(opponent.id, &conn).map_err(|_| StatusCode::BAD_REQUEST)?; + let opponent_bot_version = + db::bots::active_bot_version(opponent.id, &conn).map_err(|_| StatusCode::BAD_REQUEST)?; - let player_code_bundle = save_code_bundle(¶ms.code, None, &conn) + let player_bot_version = save_code_bundle(¶ms.code, None, &conn) // TODO: can we recover from this? .expect("could not save bot code"); let mut run_match = RunMatch::from_players(vec![ - MatchPlayer::from_code_bundle(&player_code_bundle), - MatchPlayer::from_code_bundle(&opponent_code_bundle), + MatchPlayer::from_code_bundle(&player_bot_version), + MatchPlayer::from_code_bundle(&opponent_bot_version), ]); let match_data = run_match .store_in_database(&conn) @@ -61,12 +61,12 @@ pub async fn submit_bot( match_players: vec![ FullMatchPlayerData { base: match_data.match_players[0].clone(), - code_bundle: Some(player_code_bundle), + bot_version: Some(player_bot_version), bot: None, }, FullMatchPlayerData { base: match_data.match_players[1].clone(), - code_bundle: Some(opponent_code_bundle), + bot_version: Some(opponent_bot_version), bot: Some(opponent), }, ], diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index 0c1bee4..f33a5f1 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -18,7 +18,7 @@ pub struct ApiMatch { #[derive(Serialize, Deserialize)] pub struct ApiMatchPlayer { - code_bundle_id: Option<i32>, + bot_version_id: Option<i32>, bot_id: Option<i32>, bot_name: Option<String>, } @@ -38,7 +38,7 @@ pub fn match_data_to_api(data: matches::FullMatchData) -> ApiMatch { .match_players .iter() .map(|_p| ApiMatchPlayer { - code_bundle_id: _p.code_bundle.as_ref().map(|cb| cb.id), + bot_version_id: _p.bot_version.as_ref().map(|cb| cb.id), bot_id: _p.bot.as_ref().map(|b| b.id), bot_name: _p.bot.as_ref().map(|b| b.name.clone()), }) diff --git a/planetwars-server/src/schema.rs b/planetwars-server/src/schema.rs index d632a32..0606ac4 100644 --- a/planetwars-server/src/schema.rs +++ b/planetwars-server/src/schema.rs @@ -32,7 +32,7 @@ table! { match_players (match_id, player_id) { match_id -> Int4, player_id -> Int4, - code_bundle_id -> Nullable<Int4>, + bot_version_id -> Nullable<Int4>, } } @@ -84,7 +84,7 @@ table! { joinable!(bot_versions -> bots (bot_id)); joinable!(bots -> users (owner_id)); -joinable!(match_players -> bot_versions (code_bundle_id)); +joinable!(match_players -> bot_versions (bot_version_id)); joinable!(match_players -> matches (match_id)); joinable!(ratings -> bots (bot_id)); joinable!(sessions -> users (user_id)); |