@@ -40,8 +40,7 @@ def flags():
40
40
if not submitted_flag .isascii (): # make sure its ascii only and not invalid
41
41
flash ("Invalid flag. Please try again." , "danger" )
42
42
return redirect (url_for ("ctf.flags" ))
43
- # everything before the first { can be case insensitive
44
-
43
+
45
44
46
45
if submitted_flag in submitted_flags :
47
46
flash ("You already submitted this flag." , "info" )
@@ -55,49 +54,44 @@ def flags():
55
54
current_stage += 1
56
55
hint_index = 0
57
56
elif current_stage == len (stages ):
58
- flash (
57
+ flash ( # if the user has completed all the stages, then flash a message
59
58
"You have completed all the stages. Congratulations!" ,
60
59
"success" )
61
60
return render_template (
62
61
"error.html" ,
63
62
title = "Congratulations!" ,
64
63
message = "You have completed all the stages of the CTF. " ,
65
64
)
66
- # if the user has completed all the stages, then flash a
67
- # message
68
65
session ["current_stage" ] = current_stage
69
66
else :
70
67
found = False
71
- # if the flag is for a different stage, then put them on their
72
- # stage
68
+ # if the flag is for a different stage, then warn them
73
69
for stage , stage_data in stages .items ():
74
- if submitted_flag == stage_data ["flag" ]:
70
+ if submitted_flag == stage_data ["flag" ]: # out of order
75
71
flash (
76
- f"That's the flag for stage { stage } , but in the wrong order" , "info" )
77
- current_stage = stage
72
+ f"That's the flag for stage { stage } , but in the wrong order, try to go back and find the right one " , "info" )
73
+ # current_stage = stage
78
74
hint_index = 0
79
75
found = True
80
76
81
- if submitted_flag not in submitted_flags :
77
+ if submitted_flag not in submitted_flags : # no duplicates
82
78
submitted_flags .append (submitted_flag )
83
79
session ["submitted_flags" ] = submitted_flags
84
80
85
- # check if they got all the flags (even if they are out
86
- # of order)
81
+ # check if they got all the flags (even if they are out of order)
87
82
if sorted (submitted_flags ) == sorted (
88
83
[stage_data ["flag" ] for stage_data in stages .values ()]
89
84
):
90
85
flash (
91
86
"You have completed all the stages. Congratulations!" , "success" , )
92
87
return render_template (
93
- "error.html" ,
88
+ "error.html" , #not really an error, but a message
94
89
title = "Congratulations!" ,
95
90
message = "You have completed all the stages of the CTF. " ,
96
- )
97
- # if the user has completed all the stages, then flash a
98
- # message
91
+ ),200
92
+ # if the user has completed all the stages, then flash a message
99
93
break
100
- # else:
94
+ # after going through all stages, flag isn't there
101
95
if not found :
102
96
flash ("Incorrect flag. Try again." , "danger" )
103
97
@@ -115,17 +109,17 @@ def flags():
115
109
flash (
116
110
"Exhausted all hints for this stage :( Try harder!" , "warning" )
117
111
# hide the button till they get to next stage
118
- session ["hint_index" ] = hint_index
119
- hints = stages [current_stage ]["hints" ][:hint_index ]
120
- notes = stages [current_stage ].get ("notes" )
112
+ session ["hint_index" ] = hint_index # update the hint index
113
+ hints = stages [current_stage ]["hints" ][:hint_index ] # get the hints based on the hint index
114
+ notes = stages [current_stage ].get ("notes" ) # get the notes if they exist
121
115
return render_template (
122
116
"flags.html" ,
123
117
title = f"CTFlask - Stage { current_stage } " ,
124
118
stage = current_stage ,
125
- hints = hints ,
126
- hint_index = hint_index ,
127
- submitted_flags = submitted_flags ,
128
- num_hints = len (stages [current_stage ]["hints" ]),
119
+ hints = hints , # hints to display
120
+ hint_index = hint_index , # current hint index
121
+ submitted_flags = submitted_flags ,
122
+ num_hints = len (stages [current_stage ]["hints" ]), # total number of hints
129
123
notes = notes ,
130
124
)
131
125
0 commit comments