Skip to content

Commit b0f14a4

Browse files
committed
feat: add Powerup, UsedPowerup model and routes
1 parent f7e1baf commit b0f14a4

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

src/pwncore/models/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
AttackDefTeam
3030
)
3131

32+
from pwncore.models.powerups import (
33+
Powerup,
34+
PowerupType,
35+
UsedPowerup,
36+
Powerup_Pydantic,
37+
)
3238
from pwncore.models.pre_event import (
3339
PreEventProblem,
3440
PreEventSolvedProblem,
@@ -58,6 +64,9 @@
5864
"BaseProblem",
5965
"AttackDefProblem",
6066
"AttackDefTeam",
67+
"Powerup",
68+
"UsedPowerup",
69+
"Powerup_Pydantic",
6170
)
6271

6372

src/pwncore/models/round2.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from __future__ import annotations
22
from tortoise import fields
33
from tortoise.models import Model
4+
from tortoise.expressions import F
5+
46
__all__ = (
57
"AttackDefProblem",
68
"AttackDefTeam",
79
"Problem",
10+
"Powerup",
811
)
912
#TODO: Actually implement this.
1013
# For now this is a dummy class for testing AttackDefTeam.
@@ -21,3 +24,5 @@ class AttackDefTeam(Model):
2124
"models.Team", null=False
2225
)
2326
assigned_attack_def_problem: fields.ReverseRelation(AttackDefProblem)
27+
async def remaining_powerups(self):
28+
return self.powerups.filter(used_count__lt=F('max_uses'))

src/pwncore/routes/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from fastapi import APIRouter
22

3-
from pwncore.routes import ctf, team, auth, admin, leaderboard
3+
from pwncore.routes import ctf, team, auth, admin, leaderboard, powerups
44

55
# from pwncore.config import config
66

@@ -13,5 +13,6 @@
1313
router.include_router(team.router)
1414
router.include_router(leaderboard.router)
1515
router.include_router(admin.router)
16+
router.include_router(powerups.router)
1617
# if config.development:
1718
# router.include_router(admin.router)

src/pwncore/routes/admin.py

+18
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
User,
1717
AttackDefTeam,
1818
AttackDefProblem,
19+
Powerup,
20+
UsedPowerup
1921
)
2022
from pwncore.models.ctf import SolvedProblem
2123
from pwncore.models.pre_event import PreEventUser
24+
from pwncore.models.powerups import (
25+
Sabotage,
26+
Shield
27+
)
2228

2329
metadata = {
2430
"name": "admin",
@@ -173,6 +179,18 @@ async def init_db(
173179
problem_id=(await Problem.get(name="GitGood2")).id,
174180
attack_def_team_id=(await AttackDefTeam.get(team_id=triple_b_battery.id)).id
175181
)
182+
await Powerup.create(
183+
attack_def_team = (await AttackDefTeam.get(team__id=triple_b_battery.id)),
184+
powerup_type = Sabotage
185+
)
186+
shield = await Powerup.create(
187+
attack_def_team = (await AttackDefTeam.get(team__id=triple_b_battery.id)),
188+
powerup_type = Shield
189+
)
190+
await UsedPowerup.create(
191+
powerup = shield
192+
)
193+
176194
await PreEventUser.create(tag="23BCE1000", email="[email protected]")
177195
await PreEventUser.create(tag="23BRS1000", email="[email protected]")
178196
await PreEventSolvedProblem.create(user_id="23BCE1000", problem_id="1")

0 commit comments

Comments
 (0)