Skip to content

Commit b6bb72a

Browse files
hintpoint display on challenges
1 parent a39f814 commit b6bb72a

11 files changed

Lines changed: 520 additions & 22 deletions

File tree

CTFd/plugins/hintpointdelay/__init__.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

2+
from pathlib import Path
3+
24
from flask import Blueprint, render_template, request
35

46
from CTFd.cache import clear_standings
57
from CTFd.constants.languages import SELECT_LANGUAGE_LIST
6-
from CTFd.models import Awards, Hints, Unlocks, db, get_class_by_tablename
8+
from CTFd.models import Awards, Challenges, Hints, Unlocks, db, get_class_by_tablename
79
from CTFd.plugins.LuaUtils import ConfigPanel, _LuaAsset, run_after_route
810
from CTFd.schemas.awards import AwardSchema
911
from CTFd.schemas.unlocks import UnlockSchema
@@ -15,9 +17,15 @@
1517
require_verified_emails,
1618
)
1719
from CTFd.utils.logging import log
20+
from CTFd.utils.plugins import override_template
1821
from CTFd.utils.user import get_current_user
1922

2023

24+
def registerTemplate(old_path, new_path):
25+
dir_path = Path(__file__).parent.resolve()
26+
template_path = dir_path / "templates" / new_path
27+
override_template(old_path, open(template_path).read())
28+
2129
class DelayedHints(db.Model):
2230
__tablename__ = "delayedhints"
2331
id = db.Column(db.Integer, primary_key=True)
@@ -36,16 +44,19 @@ def __init__(self, user, hint):
3644

3745
def get_modified_challenge_points(challenge_id,challenge_value):
3846
user = get_current_user()
39-
hintids = DelayedHints.query.filter(
40-
DelayedHints.challenge == challenge_id,
41-
DelayedHints.user == user.id,
42-
).all()
47+
try:
48+
hintids = DelayedHints.query.filter(
49+
DelayedHints.challenge == challenge_id,
50+
DelayedHints.user == user.id,
51+
).all()
52+
except():
53+
hintids = False
4354

4455
score = challenge_value
4556
if hintids:
4657
for hid in hintids:
4758
hint = Hints.query.filter(
48-
Hints.id== hid,
59+
Hints.id== hid.hint,
4960
).first()
5061
score -= hint.cost
5162

@@ -64,7 +75,7 @@ def apply_delayed_hints(challenge_id):
6475
for hid in hintids:
6576

6677
hint = Hints.query.filter(
67-
Hints.id == hid.id,
78+
Hints.id == hid.hint,
6879
).first()
6980
if hint:
7081
name = hint.name
@@ -114,6 +125,9 @@ def load(app):
114125
app.jinja_env.globals.update(hintpointassets=_LuaAsset("hintpointdelay"))
115126
app.register_blueprint(hintpoint, url_prefix="/hintpointdelay")
116127

128+
registerTemplate("challenge.html","hintchallenge.html")
129+
registerTemplate("challenges.html","hintchallenges.html")
130+
117131
#config page
118132
@app.route("/admin/hintpointdelay")
119133
@admins_only
@@ -134,6 +148,17 @@ def hintpoint_config():
134148
]
135149
return render_template("hintconfig.html", configs=configs)
136150

151+
@app.route("/api/hintpoint/challengevalue/<challenge_id>",methods=['GET'])
152+
def getValues(challenge_id):
153+
try:
154+
challenge = Challenges.query.filter(
155+
Challenges.id == challenge_id
156+
).first()
157+
except():
158+
return {"success": False, "status":500}
159+
res = get_modified_challenge_points(challenge_id,challenge.value)
160+
return {"success": True, "data":res}
161+
137162
#modified award unlock
138163
def modify_award(res):
139164
req = request.get_json()

CTFd/plugins/hintpointdelay/assets/js/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ $("select").on('change',function(){
2525
body: JSON.stringify({
2626
value: this.value
2727
}),
28-
})
28+
})
2929
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import $ from "jquery";
2+
3+
window.Alpine.data("Hintpoints",()=>({
4+
5+
challengevalue: '---',
6+
async hintpointvalue(id){
7+
const url = `/api/hintpoint/challengevalue/${id}`;
8+
const res = await $.get(url)
9+
this.challengevalue = res.data
10+
}
11+
12+
}))
13+
14+
window.Alpine.start()

CTFd/plugins/hintpointdelay/staticAssets/assets/jquery-D6y97aCn.js

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

CTFd/plugins/hintpointdelay/staticAssets/assets/js/config-Cc5_SaG4.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

CTFd/plugins/hintpointdelay/staticAssets/assets/js/config-DY9reIum.js

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

CTFd/plugins/hintpointdelay/staticAssets/assets/js/hintpoint-BqN4BGW8.js

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

CTFd/plugins/hintpointdelay/staticAssets/manifest.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,26 @@
33
"file": "assets/echarts-l0sNRNKZ.js",
44
"name": "echarts"
55
},
6+
"_jquery-D6y97aCn.js": {
7+
"file": "assets/jquery-D6y97aCn.js",
8+
"name": "jquery"
9+
},
610
"assets/js/config.js": {
7-
"file": "assets/js/config-Cc5_SaG4.js",
11+
"file": "assets/js/config-DY9reIum.js",
812
"name": "js/config",
913
"src": "assets/js/config.js",
10-
"isEntry": true
14+
"isEntry": true,
15+
"imports": [
16+
"_jquery-D6y97aCn.js"
17+
]
18+
},
19+
"assets/js/hintpoint.js": {
20+
"file": "assets/js/hintpoint-BqN4BGW8.js",
21+
"name": "js/hintpoint",
22+
"src": "assets/js/hintpoint.js",
23+
"isEntry": true,
24+
"imports": [
25+
"_jquery-D6y97aCn.js"
26+
]
1127
}
1228
}

0 commit comments

Comments
 (0)