From 79479ba8babfc40a0d0731fec41b2e8426fbe7f2 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 15 Oct 2022 23:58:52 +0200 Subject: only show bot stderr to its owner --- planetwars-server/src/routes/matches.rs | 2 ++ web/pw-server/src/routes/matches/[match_id].svelte | 23 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index 24d0b7e..10f5c5d 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -32,6 +32,7 @@ pub struct ApiMatchPlayer { bot_version_id: Option, bot_id: Option, bot_name: Option, + owner_id: Option, had_errors: Option, } @@ -124,6 +125,7 @@ pub fn match_data_to_api(data: matches::FullMatchData) -> ApiMatch { 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()), + owner_id: p.bot.as_ref().and_then(|b| b.owner_id), had_errors: p.base.had_errors, }) .collect(), diff --git a/web/pw-server/src/routes/matches/[match_id].svelte b/web/pw-server/src/routes/matches/[match_id].svelte index 25438ad..b3d9f01 100644 --- a/web/pw-server/src/routes/matches/[match_id].svelte +++ b/web/pw-server/src/routes/matches/[match_id].svelte @@ -25,6 +25,7 @@ import PlayerLog from "$lib/components/PlayerLog.svelte"; import Select from "svelte-select"; import { PLAYER_COLORS } from "$lib/constants"; + import { currentUser } from "$lib/stores/current_user"; export let matchLog: string | undefined; export let matchData: object; @@ -42,20 +43,38 @@ playerId: index + 1, // stoopid player number + 1 label: player["bot_name"], })); + + // TODO: refactor match logs so that users can no longer get match logs for other players. + function currentUserCanSeeStdErr(matchPlayer: object): boolean { + if (!matchPlayer["owner_id"]) { + return true; + } + + console.log(matchPlayer, $currentUser); + return matchPlayer["owner_id"] === $currentUser?.["user_id"]; + } + + $: showStdErr = + !!selectedPlayer && currentUserCanSeeStdErr(matchData["players"][selectedPlayer["value"]]);
-
{item.label}
- +
-- cgit v1.2.3