18
18
SolvedProblem ,
19
19
Team ,
20
20
ViewedHint ,
21
+ AttackDefProblem ,
22
+ AttackDefTeam
21
23
)
22
24
from pwncore .models .ctf import Problem_Pydantic
23
25
from pwncore .routes .auth import RequireJwt
@@ -62,11 +64,7 @@ async def completed_problem_get(jwt: RequireJwt):
62
64
)
63
65
return problems
64
66
65
-
66
- @router .get ("/list" )
67
- async def ctf_list (jwt : RequireJwt ):
68
- team_id = jwt ["team_id" ]
69
- problems = await Problem_Pydantic .from_queryset (Problem .filter (visible = True ))
67
+ async def calculate_problem_points (problems : [Problem_Pydantic ], team_id : int ) -> [Problem_Pydantic ]:
70
68
acc : dict [int , float ] = defaultdict (lambda : 1.0 )
71
69
for k , v in map (
72
70
lambda x : (x .hint .problem_id , HINTPENALTY [x .hint .order ]), # type: ignore[attr-defined]
@@ -79,6 +77,20 @@ async def ctf_list(jwt: RequireJwt):
79
77
i .points = int (acc [i .id ] * i .points ) # type: ignore[attr-defined]
80
78
return problems
81
79
80
+ @router .get ("/list" )
81
+ async def ctf_list (jwt : RequireJwt ):
82
+ team_id = jwt ["team_id" ]
83
+ problems = await Problem_Pydantic .from_queryset (Problem .filter (visible = True ))
84
+ return await calculate_problem_points (problems , team_id )
85
+
86
+ @router .get ("/round2/list" )
87
+ async def ctf_list (jwt : RequireJwt ):
88
+ team_id = jwt ["team_id" ]
89
+ attack_def_team = await AttackDefTeam .get (team_id = team_id )
90
+ if (attack_def_team is None ):
91
+ return {"msg_code" : config .msg_codes ["attack_def_team_not_found" ]}
92
+ problems = await Problem_Pydantic .from_queryset (Problem .filter (attackdefproblem__attack_def_team__id = attack_def_team .id ))
93
+ return await calculate_problem_points (problems , team_id )
82
94
83
95
async def update_points (req : Request , ctf_id : int ):
84
96
try :
@@ -88,6 +100,9 @@ async def update_points(req: Request, ctf_id: int):
88
100
except Exception :
89
101
logger .exception ("An error occured while updating points" )
90
102
103
+ @router .get ("/round2/list_all" )
104
+ async def ctf_list ():
105
+ return await Problem_Pydantic .from_queryset (Problem .all ())
91
106
92
107
@atomic ()
93
108
@router .post ("/{ctf_id}/flag" )
0 commit comments