From 594437b2745dd7ac17843d04e3c513ce1a66d1e3 Mon Sep 17 00:00:00 2001 From: 0akarma Date: Sun, 15 Dec 2019 17:20:39 +0800 Subject: [PATCH] Adapt diffrent mode for ctfd-matrix-scoreboard plugin & fix bugs (#3) --- CTFd/plugins/ctfd-matrix-scoreboard/__init__.py | 14 +++++++++----- .../static/scoreboard-matrix.js | 9 +++++++-- .../templates/scoreboard-matrix.html | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CTFd/plugins/ctfd-matrix-scoreboard/__init__.py b/CTFd/plugins/ctfd-matrix-scoreboard/__init__.py index c773d7d1..c920b230 100644 --- a/CTFd/plugins/ctfd-matrix-scoreboard/__init__.py +++ b/CTFd/plugins/ctfd-matrix-scoreboard/__init__.py @@ -36,10 +36,15 @@ def get_standings(): jstandings = [] # print(standings) for team in standings: - print(team) - teamid = team[0] - # To do 区分模式 - solves = db.session.query(Solves.challenge_id.label('chalid'), Solves.date.label('date')).filter(Solves.team_id==teamid) + mode = utils.get_config("user_mode") + if mode == "teams": + teamid = Users.query.filter_by(id=team[0]).first_or_404().team_id + solves = db.session.query(Solves.challenge_id.label('chalid'), Solves.date.label('date')).filter( + Solves.team_id == teamid) + else: + teamid = team[0] + solves = db.session.query(Solves.challenge_id.label('chalid'), Solves.date.label('date')).filter( + Solves.user_id == teamid) freeze = utils.get_config('freeze') if freeze: @@ -67,7 +72,6 @@ def get_standings(): score = score + int(cvalue * 1) jsolves.append(solve) - mode = utils.get_config("user_mode") if mode == "teams": jstandings.append({'userid':"", 'teamid':team[0], 'score':score, 'name':team[2],'solves':jsolves}) else: diff --git a/CTFd/plugins/ctfd-matrix-scoreboard/static/scoreboard-matrix.js b/CTFd/plugins/ctfd-matrix-scoreboard/static/scoreboard-matrix.js index 26943014..6a0c034a 100644 --- a/CTFd/plugins/ctfd-matrix-scoreboard/static/scoreboard-matrix.js +++ b/CTFd/plugins/ctfd-matrix-scoreboard/static/scoreboard-matrix.js @@ -1,10 +1,15 @@ function updatescores () { - $.get(script_root + '/scores', function( data ) { + $.get(script_root + '/matrix/scores', function( data ) { teams = $.parseJSON(JSON.stringify(data)); console.log(teams); $('#scoreboard > tbody').empty() for (var i = 0; i < teams.length; i++) { - row = "{0}{2}{3}".format(i+1, teams[i].userid, htmlentities(teams[i]['name']), teams[i].score, teams[i].username); + if (teams[i].userid !== "") { + row = "{0}{2}{3}{4}".format(i+1, teams[i].userid, htmlentities(teams[i]['name']), teams[i].affiliation, teams[i].score, teams[i].username); + } + else { + row = "{0}{2}{3}{4}".format(i+1, teams[i].teamid, htmlentities(teams[i]['name']), teams[i].affiliation, teams[i].score, teams[i].username); + } chalids = new Array(); tops = new Array(); for(var k = 0; k < teams[i].solves.length; k++) { diff --git a/CTFd/plugins/ctfd-matrix-scoreboard/templates/scoreboard-matrix.html b/CTFd/plugins/ctfd-matrix-scoreboard/templates/scoreboard-matrix.html index 32db7d42..d110d32b 100644 --- a/CTFd/plugins/ctfd-matrix-scoreboard/templates/scoreboard-matrix.html +++ b/CTFd/plugins/ctfd-matrix-scoreboard/templates/scoreboard-matrix.html @@ -99,6 +99,7 @@

Scoreboard has been frozen.

Score + {% for chal in challenges %}
{{ chal.name }}
{% endfor %}