Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update develop #39

Merged
merged 5 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GZCTF/ClientApp/src/components/WithNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const WithNavBar: FC<WithNavBarProps> = ({ children, width, padding, isLoading,
rotate={-9}
textSize={15}
gutter={20}
opacity={theme.colorScheme == 'dark' ? 0.004 : 0.010}
opacity={theme.colorScheme == 'dark' ? 0.004 : 0.01}
fontFamily="JetBrains Mono"
>
<Center style={{ width: '100%' }}>
Expand Down
13 changes: 9 additions & 4 deletions GZCTF/ClientApp/src/pages/admin/games/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,23 @@ const Games: FC = () => {
/>
</td>
<td>
<Group position="apart">
<Group position="left">
<Group noWrap position="apart">
<Group
noWrap
position="left"
onClick={() => navigate(`/games/${game.id}`)}
sx={{ cursor: 'pointer' }}
>
<Avatar src={game.poster} radius={0}>
{game.title?.at(0)}
</Avatar>
<Text weight={700}>{game.title}</Text>
<Text weight={700} lineClamp={1}>{game.title}</Text>
</Group>
<Badge color={color}>{status}</Badge>
</Group>
</td>
<td>
<Group spacing="xs">
<Group noWrap spacing="xs">
<Badge size="xs" color={color} variant="dot">
{dayjs(startTime).format('YYYY-MM-DD HH:mm')}
</Badge>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ const OneAttachmentWithFlags: FC<FlagEditProps> = ({ onDelete }) => {
}}
/>
<Stack spacing={6} pb={8}>
<Text size="xs">
请输入 flag 模版字符串,留空以生成随机 UUID 作为 flag
</Text>
<Text size="xs">请输入 flag 模版字符串,留空以生成随机 UUID 作为 flag</Text>
<Text size="xs">
若指定 <Code>[TEAM_HASH]</Code> 则它将会被自动替换为队伍 Token
与相关信息所生成的哈希值
Expand Down
13 changes: 11 additions & 2 deletions GZCTF/ClientApp/src/utils/ThemeOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export const ThemeOverride: MantineThemeOverride = {
fontFamily: "'IBM Plex Sans', sans-serif",
},
loader: 'bars',
components: {
Switch: {
styles: {
body: {
alignItems: 'center',
},
},
},
},
}

export const useTableStyles = createStyles((theme) => ({
Expand Down Expand Up @@ -108,8 +117,8 @@ export const ACCEPT_IMAGE_MIME_TYPE = [
]

interface FixedButtonProps {
right?: string,
bottom?: string,
right?: string
bottom?: string
}

export const useFixedButtonStyles = createStyles((theme, { right, bottom }: FixedButtonProps) => ({
Expand Down
2 changes: 1 addition & 1 deletion GZCTF/Controllers/EditController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ await gameNoticeRepository.AddNotice(new()
/// <param name="id">比赛Id</param>
/// <param name="cId">题目Id</param>
/// <param name="token"></param>
/// <response code="200">成功添加比赛题目</response>
/// <response code="200">成功开启比赛题目容器</response>
[HttpPost("Games/{id}/Challenges/{cId}/Container")]
[ProducesResponseType(typeof(ContainerInfoModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RequestResponse), StatusCodes.Status404NotFound)]
Expand Down
14 changes: 9 additions & 5 deletions GZCTF/Repositories/GameRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private async Task<ScoreboardModel> GenScoreboard(Game game, CancellationToken t
{
var data = await FetchData(game, token);
var bloods = GenBloods(data);
var items = GenScoreboardItems(data, bloods);
var items = GenScoreboardItems(data, game, bloods);
return new()
{
Organizations = game.Organizations,
Expand Down Expand Up @@ -153,7 +153,7 @@ private static IDictionary<ChallengeTag, IEnumerable<ChallengeInfo>> GenChalleng
.OrderBy(i => i.Key)
.ToDictionary(c => c.Key, c => c.AsEnumerable());

private static IEnumerable<ScoreboardItem> GenScoreboardItems(Data[] data, IDictionary<int, Blood?[]> bloods)
private static IEnumerable<ScoreboardItem> GenScoreboardItems(Data[] data, Game game, IDictionary<int, Blood?[]> bloods)
=> data.GroupBy(j => j.Instance.Participation)
.Select(j =>
{
Expand All @@ -167,9 +167,13 @@ private static IEnumerable<ScoreboardItem> GenScoreboardItems(Data[] data, IDict
Organization = j.Key.Organization,
Rank = 0,
Team = TeamInfoModel.FromTeam(j.Key.Team, true),
LastSubmissionTime = j.Select(s => s.Submission?.SubmitTimeUTC ?? DateTimeOffset.UtcNow)
.OrderByDescending(t => t).FirstOrDefault(),
SolvedCount = challengeGroup.Count(c => c.Any(s => s.Submission?.Status == AnswerResult.Accepted)),
LastSubmissionTime = j
.Where(s => s.Submission?.SubmitTimeUTC < game.EndTimeUTC)
.Select(s => s.Submission?.SubmitTimeUTC ?? DateTimeOffset.UtcNow)
.OrderBy(t => t).LastOrDefault(),
SolvedCount = challengeGroup.Count(c => c.Any(
s => s.Submission?.Status == AnswerResult.Accepted
&& s.Submission?.SubmitTimeUTC < game.EndTimeUTC)),
Challenges = challengeGroup
.Select(c =>
{
Expand Down
16 changes: 12 additions & 4 deletions GZCTF/Services/DockerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private ServiceCreateParameters GetServiceCreateParameters(ContainerConfig confi
Limits = new()
{
MemoryBytes = config.MemoryLimit * 1024 * 1024,
NanoCPUs = config.CPUCount * 10_0000_0000, // do some math here?
NanoCPUs = config.CPUCount * 10_0000_0000,
}
},
}
Expand All @@ -143,9 +143,17 @@ private ServiceCreateParameters GetServiceCreateParameters(ContainerConfig confi
}
catch (DockerApiException e)
{
logger.SystemLog($"容器 {parameters.Service.Name} 创建失败, 状态:{e.StatusCode.ToString()}", TaskStatus.Fail, LogLevel.Warning);
logger.SystemLog($"容器 {parameters.Service.Name} 创建失败, 响应:{e.ResponseBody}", TaskStatus.Fail, LogLevel.Error);
return null;
if(e.StatusCode == HttpStatusCode.Conflict)
{
await dockerClient.Swarm.RemoveServiceAsync(parameters.Service.Name, token);
serviceRes = await dockerClient.Swarm.CreateServiceAsync(parameters, token);
}
else
{
logger.SystemLog($"容器 {parameters.Service.Name} 创建失败, 状态:{e.StatusCode.ToString()}", TaskStatus.Fail, LogLevel.Warning);
logger.SystemLog($"容器 {parameters.Service.Name} 创建失败, 响应:{e.ResponseBody}", TaskStatus.Fail, LogLevel.Error);
return null;
}
}
catch (Exception e)
{
Expand Down
4 changes: 3 additions & 1 deletion GZCTF/Services/FlagChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ await eventRepository.AddEvent(new()
}
}

if (type != SubmissionType.Unaccepted && type != SubmissionType.Normal)
if (item.Game.EndTimeUTC > DateTimeOffset.UtcNow
&& type != SubmissionType.Unaccepted
&& type != SubmissionType.Normal)
await gameNoticeRepository.AddNotice(GameNotice.FromSubmission(item, type), token);

item.Status = ans;
Expand Down