Skip to content

Commit

Permalink
feat(monitor/event): hide flags in events
Browse files Browse the repository at this point in the history
  • Loading branch information
kengwang committed Aug 21, 2024
1 parent 79faf5f commit 6fa369e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/GZCTF/ClientApp/src/locales/en_US/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"description": "Hide container creation/destroying events",
"label": "Hide container events"
},
"hide_flag": {
"description": "Don't show Flag in events",
"label": "Hide Flag"
},
"join": {
"confirm": "Confirm Registration",
"content": [
Expand Down Expand Up @@ -146,14 +150,14 @@
"score": "Score",
"score_formatter": "{value} pts",
"score_table": {
"rank_nopub": "No Public",
"rank_organization": "Rank",
"rank_total": "Overall",
"rank_nopub": "No Public",
"tag_all": "All",
"tag_empty": "Nothing found",
"score": "Score",
"score_total": "Score",
"solved_count": "Solved",
"tag_all": "All",
"tag_empty": "Nothing found",
"team": "Team",
"type": "Type"
},
Expand Down
6 changes: 5 additions & 1 deletion src/GZCTF/ClientApp/src/locales/ja_JP/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"description": "コンテナ開始/破棄イベントを非表示にする",
"label": "コンテナイベントを非表示にする"
},
"hide_flag": {
"description": "イベント中にフラグを表示しない",
"label": "フラグを隠す"
},
"join": {
"confirm": "申請確認",
"content": [
Expand Down Expand Up @@ -146,9 +150,9 @@
"score": "点数",
"score_formatter": "{value} 点",
"score_table": {
"rank_nopub": "非公開順位",
"rank_organization": "順位",
"rank_total": "総合順位",
"rank_nopub": "非公開順位",
"score": "得点",
"score_total": "合計得点",
"solved_count": "解答数",
Expand Down
6 changes: 5 additions & 1 deletion src/GZCTF/ClientApp/src/locales/zh_CN/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"description": "隐藏容器启动/销毁事件",
"label": "隐藏容器事件"
},
"hide_flag": {
"description": "不在事件中显示 Flag",
"label": "隐藏 Flag"
},
"join": {
"confirm": "确认报名",
"content": [
Expand Down Expand Up @@ -146,9 +150,9 @@
"score": "分数",
"score_formatter": "{value} 分",
"score_table": {
"rank_nopub": "全部校内赛道",
"rank_organization": "排名",
"rank_total": "总排名",
"rank_nopub": "全部校内赛道",
"score": "得分",
"score_total": "总分",
"solved_count": "解题数量",
Expand Down
20 changes: 17 additions & 3 deletions src/GZCTF/ClientApp/src/pages/games/[id]/monitor/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ const formatAnswer = (t: TFunction, res: AnswerResult) => {
}
}

const formatEvent = (t: TFunction, event: GameEvent) => {
const formatEvent = (t: TFunction, event: GameEvent, hideFlag: boolean) => {
switch (event.type) {
case EventType.Normal:
return event.values.at(-1) || ''
case EventType.FlagSubmit:
return t('game.event.flag_submit', {
status: formatAnswer(t, event.values.at(0) as AnswerResult),
flag: event.values.at(1),
flag: hideFlag ? "******" : event.values.at(1),
chal: event.values.at(2),
id: event.values.at(3),
})
Expand Down Expand Up @@ -121,6 +121,12 @@ const Events: FC = () => {
getInitialValueInEffect: false,
})

const [hideFlagInEvents, setHideFlagInEvents] = useLocalStorage({
key: 'hide-flag-events',
defaultValue: false,
getInitialValueInEffect: false,
})

const [activePage, setPage] = useState(1)

const [, update] = useState(new Date())
Expand Down Expand Up @@ -216,6 +222,14 @@ const Events: FC = () => {
checked={hideContainerEvents}
onChange={(e) => setHideContainerEvents(e.currentTarget.checked)}
/>
<Switch
label={SwitchLabel(
t('game.content.hide_flag.label'),
t('game.content.hide_flag.description')
)}
checked={hideFlagInEvents}
onChange={(e) => setHideFlagInEvents(e.currentTarget.checked)}
/>
<Group justify="right">
<ActionIcon size="lg" disabled={activePage <= 1} onClick={() => setPage(activePage - 1)}>
<Icon path={mdiArrowLeftBold} size={1} />
Expand Down Expand Up @@ -248,7 +262,7 @@ const Events: FC = () => {
<Stack gap={2} w="100%">
<Input
variant="unstyled"
value={formatEvent(t, event)}
value={formatEvent(t, event, hideFlagInEvents)}
readOnly
size="md"
classNames={inputClasses}
Expand Down

0 comments on commit 6fa369e

Please sign in to comment.