Skip to content

Commit a3cf774

Browse files
committed
chore: use HasGameAsync for signalr
1 parent 3d4e4ff commit a3cf774

9 files changed

Lines changed: 198 additions & 193 deletions

File tree

src/GZCTF/ClientApp/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
"dependencies": {
1515
"@babel/core": "^7.28.0",
1616
"@emotion/react": "^11.14.0",
17-
"@mantine/carousel": "^8.2.3",
18-
"@mantine/colors-generator": "^8.2.3",
19-
"@mantine/core": "^8.2.3",
20-
"@mantine/dates": "^8.2.3",
21-
"@mantine/dropzone": "^8.2.3",
22-
"@mantine/emotion": "^8.2.3",
23-
"@mantine/form": "^8.2.3",
24-
"@mantine/hooks": "^8.2.3",
25-
"@mantine/modals": "^8.2.3",
26-
"@mantine/notifications": "^8.2.3",
17+
"@mantine/carousel": "^8.2.4",
18+
"@mantine/colors-generator": "^8.2.4",
19+
"@mantine/core": "^8.2.4",
20+
"@mantine/dates": "^8.2.4",
21+
"@mantine/dropzone": "^8.2.4",
22+
"@mantine/emotion": "^8.2.4",
23+
"@mantine/form": "^8.2.4",
24+
"@mantine/hooks": "^8.2.4",
25+
"@mantine/modals": "^8.2.4",
26+
"@mantine/notifications": "^8.2.4",
2727
"@marsidev/react-turnstile": "^1.3.0",
2828
"@mdi/js": "^7.4.47",
2929
"@mdi/react": "^1.6.1",
@@ -75,7 +75,7 @@
7575
"swagger-typescript-api": "^13.2.7",
7676
"tslib": "^2.8.1",
7777
"typescript": "5.8.3",
78-
"vite": "npm:rolldown-vite@^7.0.12",
78+
"vite": "npm:rolldown-vite@^7.1.0",
7979
"vite-plugin-banner": "^0.8.1",
8080
"vite-plugin-optimize-css-modules": "^1.2.0",
8181
"vite-plugin-pages": "^0.33.1",

src/GZCTF/ClientApp/pnpm-lock.yaml

Lines changed: 171 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GZCTF/Hubs/AdminHub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public override async Task OnConnectedAsync()
99
{
1010
var context = Context.GetHttpContext();
1111

12-
if (context is null || (!await ContextHelper.HasAdmin(context) && !await ContextHelper.HasValidToken(context)))
12+
if (context is null || !await ContextHelper.HasAdmin(context))
1313
{
1414
Context.Abort();
1515
return;

src/GZCTF/Hubs/MonitorHub.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public override async Task OnConnectedAsync()
2020
}
2121

2222
var gameRepository = context.RequestServices.GetRequiredService<IGameRepository>();
23-
var game = await gameRepository.GetGameById(gId);
24-
25-
if (game is null)
23+
if (!await gameRepository.HasGameAsync(gId))
2624
{
2725
Context.Abort();
2826
return;

src/GZCTF/Hubs/UserHub.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public override async Task OnConnectedAsync()
1919
}
2020

2121
var gameRepository = context.RequestServices.GetRequiredService<IGameRepository>();
22-
var game = await gameRepository.GetGameById(gId);
23-
24-
if (game is null)
22+
if (!await gameRepository.HasGameAsync(gId))
2523
{
2624
Context.Abort();
2725
return;

src/GZCTF/Repositories/GameEventRepository.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public async Task<GameEvent> AddEvent(GameEvent gameEvent, CancellationToken tok
1717

1818
gameEvent = await Context.GameEvents.SingleAsync(s => s.Id == gameEvent.Id, token);
1919

20-
await hub.Clients.Group($"Game_{gameEvent.GameId}")
21-
.ReceivedGameEvent(gameEvent);
20+
await hub.Clients.Group($"Game_{gameEvent.GameId}").ReceivedGameEvent(gameEvent);
2221

2322
return gameEvent;
2423
}

src/GZCTF/Repositories/GameNoticeRepository.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public async Task<GameNotice> AddNotice(GameNotice notice, CancellationToken tok
2222

2323
await cache.RemoveAsync(CacheKey.GameNotice(notice.GameId), token);
2424

25-
await hub.Clients.Group($"Game_{notice.GameId}")
26-
.ReceivedGameNotice(notice);
25+
await hub.Clients.Group($"Game_{notice.GameId}").ReceivedGameNotice(notice);
2726

2827
return notice;
2928
}

src/GZCTF/Repositories/GameRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class GameRepository(
2222

2323
public override Task<int> CountAsync(CancellationToken token = default) => Context.Games.CountAsync(token);
2424

25+
public Task<bool> HasGameAsync(int id, CancellationToken token = default)
26+
=> Context.Games.AnyAsync(g => g.Id == id, token);
27+
2528
public async Task<Game?> CreateGame(Game game, CancellationToken token = default)
2629
{
2730
game.GenerateKeyPair(_xorKey);

src/GZCTF/Repositories/Interface/IGameRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public Task<ArrayResponse<BasicGameInfoModel>> GetGameInfo(int count = 10, int s
4747
/// <returns></returns>
4848
public Task<Game?> GetGameById(int id, CancellationToken token = default);
4949

50+
/// <summary>
51+
/// Check if the game is exists by Id
52+
/// </summary>
53+
/// <param name="id">Game Id</param>
54+
/// <param name="token"></param>
55+
/// <returns></returns>
56+
public Task<bool> HasGameAsync(int id, CancellationToken token = default);
57+
5058
/// <summary>
5159
/// 创建比赛对象
5260
/// </summary>

0 commit comments

Comments
 (0)